type: team
name: generateStructure
description: Generate the structure and organization of your documentation
skills:
  - type: team
    name: generateStructureWorker
    iterate_on: dataSources
    skills:
      - type: ai
        instructions:
          - role: system
            url: ../../prompts/structure/generate/system-prompt.md
          - role: user
            url: ../../prompts/structure/generate/user-prompt.md
        task_render_mode: collapse
        task_title: Generate the structure of the documentation
        tool_calls_concurrency: 5
        input_schema:
          type: object
          properties:
            rules:
              type: string
              description: Your specific requirements for documentation structure
            locale:
              type: string
              description: Primary language for documentation (e.g., zh, en, ja)
            dataSourceChunk:
              type: string
              description: Project content and context to help generate documentation structure
            targetAudience:
              type: string
              description: Target audience for the documentation
            nodeName:
              type: string
              description: Specific section or page name to focus on
            glossary:
              type: string
              description: Glossary for consistent terminology
            feedback:
              type: string
              description: Tell us how to improve the documentation structure
            userPreferences:
              type: string
              description: Your saved preferences for structure and documentation style
            docsType:
              type: string
              description: "Documentation type (options: general, getting-started, reference, faq)"
              default: general
          required:
            - rules
            - dataSourceChunk
        output_schema:
          type: object
          properties:
            projectName:
              type: string
              description: Project name identified from your content sources. Max 40 characters (any language, each character = 1). Leading/trailing spaces removed. Generate complete name within limit.
            projectDesc:
              type: string
              description: Brief project description from content analysis. Max 160 characters (any language, each character = 1). Leading/trailing spaces removed. Generate complete description within limit.
            structures:
              type: array
              description: List of document structure items to add or update
              items: ../schema/document-structure-item.yaml

      - ./utils/merge-document-structures.mjs

  - ./aggregate-document-structure.mjs

  - type: ai
    name: refineStructure
    instructions:
      - role: system
        url: ../../prompts/structure/review/structure-review-system.md
    output_schema:
      type: object
      properties:
        structures:
          type: array
          description: Document structure items that need to be updated or changed
          items: ../schema/document-structure-refine-item.yaml
      required:
        - structures

  - type: function
    name: finalizeDocumentStructure
    process: |
      return {
        projectName: input.projectName,
        projectDesc: input.projectDesc,
        documentStructure: input.structures.map(refinedItem => {
          // Find original item to get sourceIds and other fields
          const originalItem = input.documentStructure.find(orig => orig.id === refinedItem.id)

          const newItem = {
            title: refinedItem.title,
            description: refinedItem.description,
            path: refinedItem.path,
            parentId: refinedItem.parentPath || null,  // Convert parentPath to parentId
            sourceIds: originalItem?.sourceIds || [],
            ...(refinedItem.icon && { icon: refinedItem.icon }), // Preserve icon if updated during refinement
          }

          return newItem
        })
      }
