# Daily Workflow 1 — `illustrated_slides`: Topic Research -> Outline -> Expanded Content -> AI Illustrations & D2 Diagram -> Keynote HTML + PPTX + PDF.
#
#   yanshi workflow run examples/generators/illustrated_slides.yml \
#     --input subject "Rust 异步运行时 Tokio 调度器与工作窃取原理" --output-dir out
name: illustrated_slides
description: "根据主题联网搜集资料、规划 PPT 大纲、按讲解风格扩写内容，自动生成精美插图与 D2 架构图，输出交互式 HTML 演示、可编辑 PPTX 与 PDF 讲义"

inputs:
  subject:
    description: "PPT 演讲主题"
    default: "Rust 异步运行时 Tokio 调度器与工作窃取原理"
  audience:
    description: "目标听众群体"
    default: "后端研发工程师与系统架构师"
  narration_style:
    description: "讲解风格与表达基调（如深入浅出、工程实战、学术严谨、产品路演）"
    default: "深入浅出、类比直观、结合真实高并发工程案例"
  slide_count:
    description: "幻灯片章节页数（4-10）"
    default: 6
  enable_web_search:
    description: "是否联网检索最新权威技术资料支撑论点"
    default: true
  slide_theme:
    description: "幻灯片视觉配色主题：'dark' 或 'light'"
    default: "dark"
  style_preset:
    description: "插图艺术指导预设：'editorial_tech' | 'isometric_3d' | 'flat_vector' | 'blueprint_schematic' | 'scientific_diagram' | 'cinematic_keynote'"
    default: "editorial_tech"
  visual_style:
    description: "补充视觉风格细节（与 style_preset 叠加生效）"
    default: "subtle isometric depth, harmonious sapphire and warm amber accents, crisp studio lighting"
  refine_prompt:
    description: "是否先经艺术总监模型精炼视觉隐喻提示词"
    default: true
  enable_illustrations:
    description: "是否调用精美插图节点生成定制配图（设为 false 时仅使用 D2 矢量架构图与结构化面板）"
    default: true
  image_model:
    description: "文生图模型名称（需在 models.yml 配置对应厂商密钥）"
    default: "gemini-3.1-flash-image"
  image_size:
    description: "生成插图尺寸或画幅比例（自动跨厂商归一化）"
    default: "16:9"
  export_pptx:
    description: "导出原生 Office OpenXML 可编辑 PowerPoint (.pptx)"
    default: true
  export_pdf:
    description: "导出 16:9 宽屏高清排版讲义 (.pdf)"
    default: true

nodes:
  - id: options
    type: template
    parameters:
      output_format: json
      template: |
        {
          "do_search": {{ enable_web_search }},
          "slide_theme": {{ slide_theme | json_encode() }},
          "d2_theme": {% if slide_theme == "dark" %}"200"{% else %}"0"{% endif %},
          "visual_style": {{ visual_style | json_encode() }},
          "enable_illustrations": {{ enable_illustrations }},
          "image_model": {{ image_model | json_encode() }},
          "image_size": {{ image_size | json_encode() }}
        }

  - id: search_query
    type: template
    parameters:
      template: "{{ subject }} 核心原理 架构设计 关键指标 最佳实践"

  - id: research
    type: web_search
    dependencies: ["options", "search_query"]
    run_if: "{{ nodes.options.outputs.do_search }}"
    input_mapping:
      query: "{{ nodes.search_query.outputs.output }}"
    parameters:
      max_results: 6

  - id: outline_prompt
    type: template
    dependencies: ["options"]
    input_mapping:
      search_notes: "{{ nodes.research.outputs.markdown }}"
    parameters:
      template: |
        你是一位兼具系统深度与视觉审美力的首席演讲策划师。请围绕主题「{{ subject }}」，面向「{{ audience }}」，按照「{{ narration_style }}」的讲解方式，规划一份共 {{ slide_count }} 页的精品 PPT 大纲。

        大纲规划要求：
        1. 叙事弧线清晰：第 1 页破题立意与痛点引入，中间页层层递进拆解核心架构/机制/工程权衡，最后 1 页给出落地最佳实践总结。
        2. 为每一页明确规划右侧视觉呈现模式 `visual_mode`：
           - `"illustration"`：适合概念隐喻、开篇引入、场景故事或总结升华页（预计安排 2-3 页），需提供精确的英文纯视觉画面描述 `illustration_prompt`（严禁出现任何文字、字母、标语）；
           - `"arch_diagram"`：全套课件安排恰好 1 页最核心的系统架构或数据流机制页，由 D2 编译器绘制高精度工程矢量架构图；
           - `"structured_panel"`：其余硬核拆解页使用双栏工程可视化对照（代码批注、对比矩阵表格、内存布局或思维导图）。
        3. 充分利用以下联网检索到的背景资料与真实技术细节支撑论点：

        {{ search_notes | default(value="（已启用离线领域知识模式）") | truncate(length=14000) }}

  - id: plan_outline
    type: llm
    dependencies: ["outline_prompt"]
    input_mapping:
      prompt: "{{ nodes.outline_prompt.outputs.output }}"
    parameters:
      max_tokens: 8192
      system: "你是严谨的 PPT 大纲架构师，仅输出符合 JSON Schema 的有效 JSON。"
      json_schema:
        type: object
        required: [title, subtitle, arch_diagram_spec, chapters]
        properties:
          title: { type: string }
          subtitle: { type: string }
          arch_diagram_spec:
            type: string
            description: "用自然语言列出核心架构图的 2 个分层与 5-7 个核心组件及其调用流向（切勿在此处写 D2 代码语法）"
          chapters:
            type: array
            minItems: 3
            maxItems: 12
            items:
              type: object
              required: [section, title, key_points, narration_angle, visual_mode]
              properties:
                section: { type: string }
                title: { type: string }
                key_points:
                  type: array
                  items: { type: string }
                narration_angle: { type: string }
                visual_mode:
                  type: string
                  enum: [illustration, arch_diagram, structured_panel]
                illustration_prompt: { type: string }

  - id: arch_figure_desc
    type: template
    dependencies: ["plan_outline"]
    input_mapping:
      outline: "{{ nodes.plan_outline.outputs.output }}"
    parameters:
      template: |
        为主题「{{ outline.title }}」绘制一张紧凑清晰的 D2 系统架构图（`direction: right`，总计 5-8 个核心节点；若需分组容器请直接写 `group_id: "分组标题" { node_a: "组件名" }`，严禁使用不存在的 `container` 关键字；跨容器连线必须写在所有 `{}` 之外的顶层并带完整路径，如 `user_space.app -> kernel_space.ring: "提交 SQE"`）：
        {{ outline.arch_diagram_spec }}

  - id: arch_figure
    type: figure
    dependencies: ["arch_figure_desc", "options"]
    input_mapping:
      description: "{{ nodes.arch_figure_desc.outputs.output }}"
      d2_theme: "{{ nodes.options.outputs.d2_theme }}"
    parameters:
      language: d2
      png: true
      png_width: 1600
      max_attempts: 4

  - id: expand_prompt
    type: template
    dependencies: ["plan_outline"]
    input_mapping:
      outline: "{{ nodes.plan_outline.outputs.output }}"
      search_notes: "{{ nodes.research.outputs.markdown }}"
    parameters:
      template: |
        请基于以下已确认的 PPT 大纲与检索资料，将每一章扩写为完整、可直接渲染的结构化幻灯片内容（目标听众：{{ audience }}；讲解方式：{{ narration_style }}；配色主题：{{ slide_theme }}）。

        填充规范（极其重要）：
        1. 保持与大纲完全一致的页数与章节顺序，每页必须包含：
           - `section`（如 "01 痛点破局"）、`title`、`subtitle`
           - `left`：左侧主内容面板，必须符合 `SlideDeck` 面板结构之一：
             * `{"kind": "bullets", "title": "...", "grid": false, "items": [{"badge": "核心", "heading": "...", "body": "...", "tone": "accent"}]}`（每页 3-4 条干货要点，避免空话）
             * `{"kind": "code", "title": "...", "language": "rust", "code": "...", "callouts": [{"line": 3, "text": "...", "tone": "cyan"}]}`（8-14 行精炼代码）
             * `{"kind": "table", "title": "...", "highlight_col": 1, "columns": [...], "rows": [[...]]}`
             * `{"kind": "flowchart", "title": "...", "direction": "TB", "nodes": [{"id": "n1", "label": "..."}], "edges": [{"from": "n1", "to": "n2", "label": "..."}]}`
           - `fallback_right`：右侧结构化备选面板（同样仅使用 `bullets` / `table` / `code` / `flowchart` 四种之一，严禁使用 `mindmap`；当该页为 `structured_panel` 或未启用文生图时直接展示在右栏）。
           - `visual_mode`：保持大纲设定的 `"illustration"` / `"arch_diagram"` / `"structured_panel"`。
           - `illustration_prompt`：若 `visual_mode == "illustration"`，给出 1-2 句精细英文画面提示词（纯视觉构图与隐喻物体，严禁文字与字母）及一句简短中文图注 `illustration_caption`。
           - `notes`：2-3 句贴合「{{ narration_style }}」的精炼讲师口播逐字稿。
           - `takeaway`：页面底部一句凝练的工程结论。

        已确认大纲 JSON：
        {{ outline | json_encode() }}

        参考检索资料：
        {{ search_notes | default(value="（已启用离线领域知识模式）") | truncate(length=10000) }}

  - id: expand_slides
    type: llm
    dependencies: ["expand_prompt"]
    input_mapping:
      prompt: "{{ nodes.expand_prompt.outputs.output }}"
    parameters:
      max_tokens: 8192
      system: "你是资深演示文稿内容主笔，严格输出符合 SlideDeck 扩写 Schema 的合法 JSON。"
      json_schema:
        type: object
        required: [title, slides]
        properties:
          title: { type: string }
          subtitle: { type: string }
          author: { type: string }
          slides:
            type: array
            minItems: 3
            maxItems: 10
            items:
              type: object
              required: [title, left, fallback_right, visual_mode, notes, takeaway]
              properties:
                section: { type: string }
                title: { type: string }
                subtitle: { type: string }
                left:
                  type: object
                  required: [kind]
                  properties:
                    kind:
                      type: string
                      enum: [bullets, code, table, flowchart]
                    title: { type: string }
                    grid: { type: boolean }
                    items:
                      type: array
                      items:
                        type: object
                        required: [heading, body]
                        properties:
                          badge: { type: string }
                          heading: { type: string }
                          body: { type: string }
                          tone: { type: string }
                    language: { type: string }
                    code: { type: string }
                    callouts:
                      type: array
                      items:
                        type: object
                        required: [line, text]
                        properties:
                          line: { type: integer }
                          text: { type: string }
                          tone: { type: string }
                    highlight_col: { type: integer }
                    columns:
                      type: array
                      items: { type: string }
                    rows:
                      type: array
                      items:
                        type: array
                        items: { type: string }
                    direction: { type: string }
                    nodes:
                      type: array
                      items:
                        type: object
                        required: [id, label]
                        properties:
                          id: { type: string }
                          label: { type: string }
                          sublabel: { type: string }
                          tone: { type: string }
                    edges:
                      type: array
                      items:
                        type: object
                        required: [from, to]
                        properties:
                          from: { type: string }
                          to: { type: string }
                          label: { type: string }
                          dashed: { type: boolean }
                fallback_right:
                  type: object
                  required: [kind]
                  properties:
                    kind:
                      type: string
                      enum: [bullets, code, table, flowchart]
                    title: { type: string }
                    grid: { type: boolean }
                    items:
                      type: array
                      items:
                        type: object
                        required: [heading, body]
                        properties:
                          badge: { type: string }
                          heading: { type: string }
                          body: { type: string }
                          tone: { type: string }
                    language: { type: string }
                    code: { type: string }
                    callouts:
                      type: array
                      items:
                        type: object
                        required: [line, text]
                        properties:
                          line: { type: integer }
                          text: { type: string }
                          tone: { type: string }
                    highlight_col: { type: integer }
                    columns:
                      type: array
                      items: { type: string }
                    rows:
                      type: array
                      items:
                        type: array
                        items: { type: string }
                    direction: { type: string }
                    nodes:
                      type: array
                      items:
                        type: object
                        required: [id, label]
                        properties:
                          id: { type: string }
                          label: { type: string }
                          sublabel: { type: string }
                          tone: { type: string }
                    edges:
                      type: array
                      items:
                        type: object
                        required: [from, to]
                        properties:
                          from: { type: string }
                          to: { type: string }
                          label: { type: string }
                          dashed: { type: boolean }
                visual_mode:
                  type: string
                  enum: [illustration, arch_diagram, structured_panel]
                illustration_prompt: { type: string }
                illustration_caption: { type: string }
                takeaway: { type: string }
                notes: { type: string }

  - id: illustrate
    type: illustration
    dependencies: ["expand_slides", "arch_figure", "options"]
    input_mapping:
      deck: "{{ nodes.expand_slides.outputs.output }}"
      arch_image: "{{ nodes.arch_figure.outputs.arch_figure_svg }}"
      model: "{{ nodes.options.outputs.image_model }}"
      size: "{{ nodes.options.outputs.image_size }}"
      style: "{{ nodes.options.outputs.visual_style }}"
      theme: "{{ nodes.options.outputs.slide_theme }}"
      enabled: "{{ nodes.options.outputs.enable_illustrations }}"
    parameters:
      max_images: 4
      max_concurrent: 3
      graceful_fallback: true

  - id: slides_render
    type: render_slides
    dependencies: ["illustrate"]
    input_mapping:
      deck: "{{ nodes.illustrate.outputs.illustrate_deck }}"
    parameters:
      width: 1920
      progressive: false

  - id: deliverable
    type: template
    dependencies: ["illustrate", "slides_render", "arch_figure"]
    input_mapping:
      deck: "{{ nodes.illustrate.outputs.illustrate_deck }}"
      painted: "{{ nodes.illustrate.outputs.illustrate_images }}"
      html: "{{ nodes.slides_render.outputs.slides_render_html }}"
      arch_svg: "{{ nodes.arch_figure.outputs.arch_figure_svg }}"
      pptx: "{{ nodes.slides_render.outputs.slides_render_pptx }}"
      pdf: "{{ nodes.slides_render.outputs.slides_render_pdf }}"
    parameters:
      output_format: json
      template: |
        {"deliverable": {
          "kind": "slides",
          "title": {{ deck.title | json_encode() }},
          "content": {"slides": {{ deck.slides | json_encode() }}},
          "citations": [],
          "files": [
            {"node_id": "slides_render", "name": {{ html | split(pat="/") | last | json_encode() }}, "mime_type": "text/html", "role": "preview"},
            {"node_id": "arch_figure", "name": {{ arch_svg | split(pat="/") | last | json_encode() }}, "mime_type": "image/svg+xml", "role": "asset"}{% for img in painted %},
            {"node_id": "illustrate", "name": {{ img.path | split(pat="/") | last | json_encode() }}, "mime_type": {{ img.mime_type | default(value="image/png") | json_encode() }}, "role": "asset"}{% endfor %}{% if pptx is defined and pptx %},
            {"node_id": "slides_render", "name": {{ pptx | split(pat="/") | last | json_encode() }}, "mime_type": "application/vnd.openxmlformats-officedocument.presentationml.presentation", "role": "primary"}{% endif %}{% if pdf is defined and pdf %},
            {"node_id": "slides_render", "name": {{ pdf | split(pat="/") | last | json_encode() }}, "mime_type": "application/pdf", "role": "primary"}{% endif %}
          ]
        }}
