This commit is contained in:
史悦
2026-01-27 17:19:43 +08:00
parent 19afa19462
commit 69a177b85a
4 changed files with 180 additions and 0 deletions

View File

@@ -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:

98
js/modules/thinksvg.js Normal file
View File

@@ -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*<svg/i,
// 内容解析器
parser: parseResponse
},
// 生命周期钩子(预留扩展)
hooks: {},
// 导出功能配置
exports: {
// 允许导出为 SVG 文件
allowSvg: true,
// 允许导出为 PNG 图片
allowPng: true,
// 允许复制到剪贴板
allowClipboard: true,
// 允许查看源代码
allowCode: true
},
// UI 配置
ui: {
// 预览区占位文本
placeholderText: '生成的思维导图将在此处显示'
}
});
})(window);