type: team
task_render_mode: collapse
name: generateDiagram
skills:
  # Step 1: Analyze document content to determine diagram type and style
  - ../create/analyze-diagram-type.mjs
  # Step 2: Transform output for image generation agent (map aspectRatio to ratio, add size, pass existingImage and feedback)
  - type: transform
    jsonata: |
      $merge([
        $,
        {
          "ratio": aspectRatio,
          "size": "1K",
          "existingImage": existingImage,
          "useImageToImage": useImageToImage,
          "feedback": feedback
        }
      ])
  # Step 3: Generate diagram image directly with unified agent
  - ../create/generate-diagram-image.yaml
  # Step 4: Replace placeholder with generated image
  - ../create/replace-d2-with-image.mjs
input_schema:
  type: object
  properties:
    documentContent:
      type: string
      description: The **raw text content** of the current document. (**Note:** This is the original document and **does not include** any diagram source code.)
    locale:
      type: string
      description: Language for diagram labels and text
      default: en
    diagramming:
      type: object
      description: Diagramming configuration
      properties:
        style:
          type: string
          description: Default diagram style to use when no style is specified in feedback
    feedback:
      type: string
      description: User feedback that may contain style or type preferences, or diagram index (e.g., 'use anthropomorphic style', 'update the second diagram')
      default: ""
    path:
      type: string
      description: Document path (e.g., "guides/getting-started.md") used for generating image filename
    docsDir:
      type: string
      description: Documentation directory where assets will be saved (relative to project root)
    intentAnalysis:
      type: object
      description: Analysis results from analyzeFeedbackIntent containing intentType, diagramInfo, generationMode, and changes
      properties:
        intentType:
          type: string
          enum: ["addDiagram", "updateDiagram", "deleteDiagram", "updateDocument"]
        diagramInfo:
          type: object
          nullable: true
          properties:
            path: { type: "string" }
            index: { type: "number" }
            markdown: { type: "string" }
        generationMode:
          type: string
          enum: ["image-to-image", "text-only", "add-new", "remove-image"]
        changes:
          type: array
          items: { type: "string" }
  required:
    - documentContent
output_schema:
  type: object
  properties:
    content:
      type: string
      description: The document content with D2 code blocks replaced by generated diagram image.
  required:
    - content
