diff --git a/smarttools/artifact-ai/config.yaml b/smarttools/artifact-ai/config.yaml index 4f51825..6e63573 100644 --- a/smarttools/artifact-ai/config.yaml +++ b/smarttools/artifact-ai/config.yaml @@ -16,6 +16,8 @@ arguments: required: true description: Natural language instruction for generating or modifying the artifact +output: "{result}" + steps: # Step 1: Build format-specific prompt and call AI - type: code @@ -120,7 +122,7 @@ steps: - type: prompt prompt: "{prompt}" - provider: claude + provider: opencode-deepseek output_var: ai_output # Step 2: Clean up output based on format @@ -156,10 +158,23 @@ steps: code = json_match.group(0) elif format == 'plantuml': - # Ensure proper tags - if not code.strip().startswith('@start'): - code = '@startuml\n' + code - if not code.strip().endswith('@enduml') and '@enduml' not in code: - code = code + '\n@enduml' + # Extract first complete @startuml...@enduml block (handles AI outputting duplicates) + puml_match = re.search(r'(@start\w+.*?@end\w+)', code, re.DOTALL) + if puml_match: + code = puml_match.group(1) + else: + # No complete block found - ensure proper tags + if not code.strip().startswith('@start'): + code = '@startuml\n' + code + if not code.strip().endswith('@enduml') and '@enduml' not in code: + code = code + '\n@enduml' - print(code.strip()) + elif format == 'mermaid': + # Extract first complete mermaid diagram (handles duplicates) + # Mermaid starts with diagram type declaration + mermaid_types = r'(graph|flowchart|sequenceDiagram|classDiagram|stateDiagram|erDiagram|gantt|pie|journey)' + mermaid_match = re.search(rf'({mermaid_types}[\s\S]*?)(?={mermaid_types}|\Z)', code) + if mermaid_match: + code = mermaid_match.group(1).strip() + + result = code.strip()