From 69a177b85a5bb90ba4200640e2be8e077898d8cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=82=A6?= Date: Tue, 27 Jan 2026 17:19:43 +0800 Subject: [PATCH] thinksvg --- index.html | 1 + js/apiclient.js | 2 + js/modules/thinksvg.js | 98 +++++++++++++++++++++++++++++++++++++ prompts/thinksvg-prompt.txt | 79 ++++++++++++++++++++++++++++++ 4 files changed, 180 insertions(+) create mode 100644 js/modules/thinksvg.js create mode 100644 prompts/thinksvg-prompt.txt diff --git a/index.html b/index.html index 3b3c5c4..d320da1 100644 --- a/index.html +++ b/index.html @@ -258,6 +258,7 @@ + diff --git a/js/apiclient.js b/js/apiclient.js index 94bd403..b29ab68 100644 --- a/js/apiclient.js +++ b/js/apiclient.js @@ -13,6 +13,7 @@ class APIClient { this.promptFiles = { canvas: 'prompts/canvas-prompt.txt', swot: 'prompts/swot-prompt.txt', + thinksvg: 'prompts/thinksvg-prompt.txt', echarts: 'prompts/echarts-prompt.txt', mermaid: 'prompts/mermaid-prompt.txt', onepage: 'prompts/onepage-prompt.txt' @@ -20,6 +21,7 @@ class APIClient { this.promptFallbacks = { canvas: '你是一个专业的产品战略分析师,擅长创建产品画布。', swot: '你是一个专业的商业战略分析师,擅长进行SWOT分析。', + thinksvg: '你是一名思维导图专家,擅长使用 SVG 生成清晰的思维导图。', echarts: '你是一个资深的数据可视化专家,精通将自然语言需求转化为 ECharts 配置对象,请输出结构化 JSON option。', mermaid: diff --git a/js/modules/thinksvg.js b/js/modules/thinksvg.js new file mode 100644 index 0000000..a6fe297 --- /dev/null +++ b/js/modules/thinksvg.js @@ -0,0 +1,98 @@ +/** + * 思维导图模块 + * + * 功能:基于用户输入生成 SVG 格式的思维导图 + * 特性: + * - 支持多层级树形结构展示 + * - 通过提示词引导 AI 生成布局和样式 + * - 支持 SVG/PNG 导出 + * - 历史记录持久化 + */ + +(function registerThinkSvgModule(global) { + 'use strict'; + + // 确保 ModuleRegistry 已初始化 + if (!global.ModuleRegistry) { + throw new Error('ModuleRegistry 未初始化'); + } + + /** + * 解析 AI 响应,提取 SVG 内容 + * @param {string} content - AI 返回的原始内容 + * @returns {Object} 解析结果对象,包含 svgContent、beforeText、afterText 等字段 + */ + const parseResponse = (content) => Utils.parseSVGResponse(content); + + // 注册思维导图模块 + global.ModuleRegistry.register({ + // 模块标识 + id: 'thinksvg', + + // 显示名称 + label: '思维导图', + + // 图标(使用 Phosphor Icons 的树形结构图标) + icon: 'ph:tree-structure-duotone', + + // 渲染器类型 + renderer: 'svg', + + // 提示词键名(对应 prompts/thinksvg-prompt.txt) + promptKey: 'thinksvg', + + // 本地存储命名空间 + storageNamespace: 'module:thinksvg', + + // 聊天配置 + chat: { + // 输入框占位符 + placeholder: '输入要梳理的主题或问题,我来生成思维导图…', + + // 流式响应开始标记 + streamStartToken: '```svg', + + // 上下文窗口大小(保留最近 10 条消息) + contextWindow: 10 + }, + + // 产物配置 + artifact: { + // 产物类型 + type: 'svg', + + // 代码围栏标识 + fence: 'svg', + + // SVG 开始模式匹配 + startPattern: /```(?:svg)?\s* + + + + + + + + + + + + + + + + + + + + + + + + 软件架构风格 + 必会考点 + + + + + + + 1 + 数据流风格 + 包括 批处理序列管道/过滤器 + + + + + 2 + 调用/返回风格 + 包括 主程序/子程序面向对象层次结构 + + + + + 3 + 独立构件风格 + 包括 进程通信事件驱动 系统 + + + + + 4 + 虚拟机风格 + 包括 解释器基于规则的系统 + + + + + 5 + 仓库风格 + 包括 数据库黑板超文本 + + + + +``` \ No newline at end of file