type: team
name: handleDocumentUpdate
description: Update a document in a batch
skills:
  - ../utils/transform-detail-data-sources.mjs
  # Check if document generation should be skipped (if content already exists)
  # If intentType is diagram-related and content exists, mark skipGenerateDocument so generation can be short-circuited
  - url: ../utils/skip-if-content-exists.mjs
  # Generate document content (skipped when skipGenerateDocument is true and content exists)
  - type: team
    task_render_mode: collapse
    name: generateDocumentContent
    skills:
      - url: ../utils/find-user-preferences-by-path.mjs
        default_input:
          scope: document
      - ../utils/generate-document-or-skip.mjs
    reflection:
      reviewer: ../utils/check-detail-result.mjs
      is_approved: isApproved
      max_iterations: 5
      return_last_on_max_iterations: true
    task_title: Generate document for '{{ title }}'
  # Ensure content, documentContent, and originalContent are set
  - type: transform
    jsonata: |
      $merge([
        $,
        { 
          "documentContent": content,
          "originalContent": content
        }
      ])
  - ./check-generate-diagram.mjs
  # - ../generate/merge-diagram.yaml
  - ../utils/save-doc.mjs
input_schema:
  type: object
  properties:
    nodeName:
      type: string
      description: Node name
      default: Section
    locale:
      type: string
      description: Language
    targetAudience:
      type: string
      description: Target audience
    glossary:
      type: string
      description: Glossary
    doc-path:
      type: string
      description: Current path
    feedback:
      type: string
      description: Feedback
    sources:
      type: array
      items:
        type: string
        description: Source code path
    sourcesPath:
      type: array
      items:
        type: string
        description: Source code path
      default:
        - ./
    includePatterns:
      type: array
      items:
        type: string
        description: Included file name patterns
    excludePatterns:
      type: array
      items:
        type: string
        description: Excluded file name patterns
    outputDir:
      type: string
      description: Output directory
      default: ./aigne-docs/output
    docsDir:
      type: string
      description: Documentation directory
      default: ./aigne-docs/docs
    additionalInformation:
      type: string
      description: Additional information
output_schema:
  type: object
  properties:
    title:
      type: string
    description:
      type: string
    path:
      type: string
    content:
      type: string
mode: sequential
