@andrewyang/ai-workflow-editor 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/.nuxt/app.config.mjs +18 -0
  2. package/.nuxt/components.d.ts +910 -0
  3. package/.nuxt/dev/index.mjs +4103 -0
  4. package/.nuxt/dev/index.mjs.map +1 -0
  5. package/.nuxt/dist/server/client.manifest.mjs +4 -0
  6. package/.nuxt/dist/server/client.precomputed.mjs +1 -0
  7. package/.nuxt/dist/server/server.mjs +1 -0
  8. package/.nuxt/i18n-route-resources.mjs +3 -0
  9. package/.nuxt/imports.d.ts +43 -0
  10. package/.nuxt/manifest/latest.json +1 -0
  11. package/.nuxt/manifest/meta/dev.json +1 -0
  12. package/.nuxt/nitro.json +17 -0
  13. package/.nuxt/nuxt.d.ts +24 -0
  14. package/.nuxt/nuxt.json +9 -0
  15. package/.nuxt/schema/nuxt.schema.d.ts +17 -0
  16. package/.nuxt/schema/nuxt.schema.json +3 -0
  17. package/.nuxt/tsconfig.json +234 -0
  18. package/.nuxt/tsconfig.server.json +185 -0
  19. package/.nuxt/types/app-defaults.d.ts +7 -0
  20. package/.nuxt/types/app.config.d.ts +31 -0
  21. package/.nuxt/types/build.d.ts +29 -0
  22. package/.nuxt/types/builder-env.d.ts +1 -0
  23. package/.nuxt/types/components.d.ts +915 -0
  24. package/.nuxt/types/i18n-plugin.d.ts +123 -0
  25. package/.nuxt/types/imports.d.ts +993 -0
  26. package/.nuxt/types/middleware.d.ts +17 -0
  27. package/.nuxt/types/nitro-config.d.ts +14 -0
  28. package/.nuxt/types/nitro-imports.d.ts +170 -0
  29. package/.nuxt/types/nitro-layouts.d.ts +17 -0
  30. package/.nuxt/types/nitro-nuxt.d.ts +39 -0
  31. package/.nuxt/types/nitro-routes.d.ts +17 -0
  32. package/.nuxt/types/nitro.d.ts +3 -0
  33. package/.nuxt/types/plugins.d.ts +43 -0
  34. package/.nuxt/types/schema.d.ts +213 -0
  35. package/.nuxt/types/vue-shim.d.ts +0 -0
  36. package/.trae/rules/rule.md +38 -0
  37. package/.vscode/settings.json +5 -0
  38. package/nuxt.config.ts +38 -0
  39. package/package.json +42 -0
  40. package/pnpm-lock.yaml +24 -0
  41. package/src/app.vue +46 -0
  42. package/src/components/AiWorkflowEditor.vue +142 -0
  43. package/src/components/ai/AiChatPanel.vue +135 -0
  44. package/src/components/ai/AiGenerator.vue +62 -0
  45. package/src/components/editor/Canvas.vue +175 -0
  46. package/src/components/editor/FormatPanel.vue +327 -0
  47. package/src/components/editor/NodePanel.vue +240 -0
  48. package/src/components/editor/PropertyPanel.vue +348 -0
  49. package/src/components/editor/Toolbar.vue +49 -0
  50. package/src/components/editor/nodes/AiNode.vue +77 -0
  51. package/src/components/editor/nodes/NormalNode.vue +75 -0
  52. package/src/components/editor/nodes/SysmlBlockNode.vue +72 -0
  53. package/src/components/editor/nodes/SysmlRequirementNode.vue +72 -0
  54. package/src/components/editor/nodes/SysmlUseCaseNode.vue +62 -0
  55. package/src/composables/useAi.ts +82 -0
  56. package/src/i18n.config.ts +5 -0
  57. package/src/locales/en.json +106 -0
  58. package/src/locales/zh.json +106 -0
  59. package/src/plugins/aiWorkflowEditor.ts +6 -0
  60. package/src/types/ai.ts +7 -0
  61. package/src/types/workflow.ts +25 -0
  62. package/src/utils/llmAdapter.ts +46 -0
  63. package/tsconfig.json +3 -0
  64. package/uno.config.ts +15 -0
  65. package//345/211/215/347/253/257/345/256/232/345/210/266/345/274/200/345/217/221/357/274/232ai-workflow-editor/345/274/200/345/217/221/350/256/241/345/210/222.md +655 -0
@@ -0,0 +1,655 @@
1
+ # 前端定制开发:基于 Vue-Nuxt-TypeScript 的 AI 工作流编辑器
2
+
3
+ 你希望开发一款基于 Vue 3+Nuxt 4+TypeScript 的在线绘图组件,核心是 AI 智能体与工作流可视化编辑器(支持拖拽连接节点、自定义工作流),要求组件可通过 npm 安装使用,原生集成 Ollama、OpenAI 等 LLM 并支持 LangChain 扩展,适用于 AI 工作流构建、智能体开发且可扩展为架构图/流程图工具。以下是一份**可落地、分阶段的前端定制开发规划**,覆盖从技术选型到发布维护的全流程:
4
+
5
+ ---
6
+
7
+ ## 一、前期准备阶段(1-2 周)
8
+
9
+ ### 1.1 需求精细化拆解
10
+
11
+ |核心模块|子功能|详细要求|
12
+ |---|---|---|
13
+ |可视化编辑器|画布基础|缩放、平移、居中、全屏;支持网格/吸附;多画布切换|
14
+ ||节点管理|拖拽创建节点;自定义节点样式(图标、颜色、尺寸);节点增删改查;支持分组节点|
15
+ ||连线管理|拖拽连线;自定义连线样式(实线/虚线、颜色、箭头);连线标签;自动避障|
16
+ ||工作流操作|工作流保存/导入/导出(JSON/YAML);撤销/重做;历史版本管理|
17
+ |AI 集成模块|LLM 适配|原生对接 OpenAI(API)、Ollama(本地/远程);统一调用接口;支持模型切换|
18
+ ||AI 能力|自然语言生成工作流;节点智能推荐;工作流逻辑校验;AI 解释工作流意图|
19
+ ||LangChain 扩展|集成 LangChain.js;支持 Prompt 模板、Chain、Agent 封装为可视化节点|
20
+ |组件化封装|接入方式|支持 Vue 3 组件引入、Nuxt 4 自动导入;支持全局注册/局部引入|
21
+ ||配置化|通过 Props 配置画布、节点、AI 服务;支持自定义事件(节点点击/连线变化)|
22
+ |扩展能力|扩展类型|支持架构图、流程图、时序图等图表类型;可自定义节点库|
23
+ ### 1.2 技术选型最终确认
24
+
25
+ |技术点|选型结果|选型理由|
26
+ |---|---|---|
27
+ |可视化核心|Vue Flow(优先)|基于 Vue 3+TS 开发,生态更贴合 Nuxt 4;API 简洁,自定义节点/连线成本低;支持组合式 API;社区维护活跃|
28
+ |备选:LogicFlow|适配 Vue 3,专注流程图,但 Nuxt 4 适配文档较少,自定义扩展稍复杂||
29
+ |AI 集成核心|LangChain.js + llm-client|LangChain.js 统一封装 LLM 调用逻辑;llm-client 适配 OpenAI/Ollama 等多模型|
30
+ |状态管理|Pinia(Nuxt 4 内置)|管理画布状态、AI 服务配置、工作流数据;支持 SSR 适配|
31
+ |构建工具|Vite(Nuxt 4 内置)|快速构建、热更新;支持库模式打包(适配 npm 发布)|
32
+ |类型校验|TypeScript + Zod|强类型约束;校验 AI 接口返回、工作流 JSON 结构|
33
+ |样式方案|UnoCSS/Tailwind CSS|原子化 CSS,适配自定义节点样式;支持主题定制|
34
+ ### 1.3 环境搭建
35
+
36
+ 1. 初始化 Nuxt 4 项目(组件库模式):
37
+
38
+ ```Bash
39
+
40
+ npx nuxi init ai-workflow-editor -t module
41
+ cd ai-workflow-editor
42
+ npm install @vue-flow/core @vue-flow/controls @langchain/openai @langchain/community zod
43
+ ```
44
+
45
+ 2. 配置开发环境:
46
+
47
+ - 开启 TypeScript 严格模式(`tsconfig.json` 中 `strict: true`);
48
+
49
+ - 配置 Nuxt 4 插件目录,预注册 Vue Flow 全局组件;
50
+
51
+ - 搭建本地 Ollama 环境(用于 AI 功能测试)。
52
+
53
+ ---
54
+
55
+ ## 二、架构设计阶段(1 周)
56
+
57
+ ### 2.1 整体架构
58
+
59
+ ```mermaid
60
+ graph TD
61
+ A[核心组件层] --> B[可视化编辑器核心]
62
+ A --> C[AI 集成模块]
63
+ A --> D[扩展能力模块]
64
+ B --> B1[画布管理]
65
+ B --> B2[节点/连线管理]
66
+ B --> B3[工作流操作]
67
+ C --> C1[LLM 适配器]
68
+ C --> C2[AI 工作流生成]
69
+ C --> C3[LangChain 扩展]
70
+ D --> D1[自定义节点库]
71
+ D --> D2[图表类型扩展]
72
+ E[基础封装层] --> A
73
+ E --> E1[Props/事件封装]
74
+ E --> E2[Nuxt 4 适配]
75
+ E --> E3[样式主题]
76
+ F[对外接口层] --> E
77
+ F --> F1[npm 发布包]
78
+ F --> F2[使用文档]
79
+ F --> F3[示例工程]
80
+ ```
81
+ ### 2.2 项目目录结构(组件库模式)
82
+
83
+ ```Plain Text
84
+
85
+ ai-workflow-editor/
86
+ ├── src/
87
+ │ ├── components/ # 核心组件
88
+ │ │ ├── AiWorkflowEditor.vue # 根组件(对外暴露)
89
+ │ │ ├── editor/ # 编辑器子组件
90
+ │ │ │ ├── Canvas.vue # 画布容器
91
+ │ │ │ ├── NodePanel.vue # 节点面板
92
+ │ │ │ └── Toolbar.vue # 工具栏
93
+ │ │ └── ai/ # AI 相关组件
94
+ │ │ ├── LlmClient.vue # LLM 客户端封装
95
+ │ │ └── AiGenerator.vue # AI 生成工作流组件
96
+ │ ├── composables/ # 组合式函数
97
+ │ │ ├── useEditor.ts # 编辑器核心逻辑
98
+ │ │ ├── useNodes.ts # 节点管理
99
+ │ │ ├── useAi.ts # AI 能力封装
100
+ │ │ └── useLangChain.ts # LangChain 扩展
101
+ │ ├── types/ # 类型定义
102
+ │ │ ├── editor.ts # 编辑器类型
103
+ │ │ ├── ai.ts # AI 相关类型
104
+ │ │ └── workflow.ts # 工作流数据类型
105
+ │ ├── utils/ # 工具函数
106
+ │ │ ├── workflowParser.ts # 工作流解析/导出
107
+ │ │ └── llmAdapter.ts # LLM 适配工具
108
+ │ └── plugins/ # Nuxt 插件
109
+ │ └── aiWorkflowEditor.ts # 组件注册插件
110
+ ├── package.json # 包配置(npm 发布)
111
+ ├── tsconfig.json # TS 配置
112
+ └── nuxt.config.ts # Nuxt 配置
113
+ ```
114
+
115
+ ### 2.3 核心接口设计(TypeScript)
116
+
117
+ ```TypeScript
118
+
119
+ // src/types/workflow.ts
120
+ export interface WorkflowNode {
121
+ id: string;
122
+ type: string; // 节点类型(AI 节点/普通节点/分支节点)
123
+ data: {
124
+ label: string;
125
+ props?: Record<string, any>; // 节点自定义属性
126
+ llmConfig?: LlmConfig; // AI 节点配置
127
+ };
128
+ position: { x: number; y: number };
129
+ }
130
+
131
+ export interface WorkflowEdge {
132
+ id: string;
133
+ source: string; // 源节点 ID
134
+ target: string; // 目标节点 ID
135
+ label?: string; // 连线标签
136
+ }
137
+
138
+ export interface LlmConfig {
139
+ provider: 'openai' | 'ollama'; // LLM 提供商
140
+ model: string; // 模型名称(如 gpt-3.5-turbo、llama3)
141
+ temperature: number; // 温度系数
142
+ apiKey?: string; // OpenAI API Key
143
+ baseUrl?: string; // Ollama/OpenAI 自定义地址
144
+ }
145
+
146
+ // AI 生成工作流入参
147
+ export interface AiGenerateWorkflowParams {
148
+ prompt: string; // 自然语言描述
149
+ llmConfig: LlmConfig;
150
+ nodeTypes?: string[]; // 可选节点类型
151
+ }
152
+ ```
153
+
154
+ ---
155
+
156
+ ## 三、核心功能开发阶段(4-6 周)
157
+
158
+ ### 3.1 可视化编辑器核心开发(2 周)
159
+
160
+ #### 3.1.1 画布基础功能
161
+
162
+ 基于 Vue Flow 实现画布核心能力:
163
+
164
+ ```Plain Text
165
+
166
+ <!-- src/components/editor/Canvas.vue -->
167
+ <template>
168
+ <VueFlow
169
+ v-model:nodes="nodes"
170
+ v-model:edges="edges"
171
+ :zoom-on-scroll="true"
172
+ :pan-on-drag="true"
173
+ @node-click="handleNodeClick"
174
+ @edge-click="handleEdgeClick"
175
+ >
176
+ <!-- 内置控制组件(缩放、居中) -->
177
+ <VueFlowControls />
178
+ <!-- 自定义节点渲染 -->
179
+ <template #node-custom-ai="props">
180
+ <AiNode :data="props.data" />
181
+ </template>
182
+ <template #node-custom-normal="props">
183
+ <NormalNode :data="props.data" />
184
+ </template>
185
+ </VueFlow>
186
+ </template>
187
+
188
+ <script setup lang="ts">
189
+ import { ref } from 'vue';
190
+ import { VueFlow, VueFlowControls, type Node, type Edge } from '@vue-flow/core';
191
+ import AiNode from './nodes/AiNode.vue';
192
+ import NormalNode from './nodes/NormalNode.vue';
193
+ import '@vue-flow/core/dist/style.css';
194
+ import '@vue-flow/controls/dist/style.css';
195
+
196
+ const nodes = ref<Node[]>([]);
197
+ const edges = ref<Edge[]>([]);
198
+
199
+ // 节点/连线点击事件
200
+ const handleNodeClick = (event: MouseEvent, node: Node) => {
201
+ emit('node-click', node);
202
+ };
203
+ const handleEdgeClick = (event: MouseEvent, edge: Edge) => {
204
+ emit('edge-click', edge);
205
+ };
206
+
207
+ // 对外暴露画布方法(如添加节点、导出工作流)
208
+ defineExpose({
209
+ addNode: (node: Node) => nodes.value.push(node),
210
+ exportWorkflow: () => ({ nodes: nodes.value, edges: edges.value }),
211
+ importWorkflow: (data: { nodes: Node[]; edges: Edge[] }) => {
212
+ nodes.value = data.nodes;
213
+ edges.value = data.edges;
214
+ }
215
+ });
216
+ </script>
217
+ ```
218
+
219
+ #### 3.1.2 自定义节点/连线
220
+
221
+ - 设计 3 类基础节点:AI 执行节点(对接 LLM)、普通执行节点、分支节点;
222
+
223
+ - 支持通过 Props 传入自定义节点模板,实现节点扩展;
224
+
225
+ - 自定义连线样式(支持箭头、标签、状态色)。
226
+
227
+ #### 3.1.3 工作流操作
228
+
229
+ - 实现保存/导入/导出(JSON/YAML 格式);
230
+
231
+ - 基于 `history` 模块实现撤销/重做;
232
+
233
+ - 画布状态持久化(localStorage/自定义存储)。
234
+
235
+ ### 3.2 AI 集成模块开发(2 周)
236
+
237
+ #### 3.2.1 LLM 统一适配器
238
+
239
+ 封装支持 OpenAI/Ollama 的统一调用接口,屏蔽不同提供商的差异:
240
+
241
+ ```TypeScript
242
+
243
+ // src/utils/llmAdapter.ts
244
+ import { ChatOpenAI } from '@langchain/openai';
245
+ import { ChatOllama } from '@langchain/community/chat_models/ollama';
246
+ import type { LlmConfig } from '@/types/ai';
247
+
248
+ export class LlmClient {
249
+ private client: ChatOpenAI | ChatOllama;
250
+
251
+ constructor(config: LlmConfig) {
252
+ if (config.provider === 'openai') {
253
+ this.client = new ChatOpenAI({
254
+ apiKey: config.apiKey,
255
+ modelName: config.model,
256
+ temperature: config.temperature,
257
+ baseURL: config.baseUrl,
258
+ });
259
+ } else if (config.provider === 'ollama') {
260
+ this.client = new ChatOllama({
261
+ model: config.model,
262
+ temperature: config.temperature,
263
+ baseUrl: config.baseUrl || 'http://localhost:11434',
264
+ });
265
+ } else {
266
+ throw new Error('Unsupported LLM provider');
267
+ }
268
+ }
269
+
270
+ // 统一调用方法
271
+ async invoke(prompt: string): Promise<string> {
272
+ const response = await this.client.invoke(prompt);
273
+ return response.content;
274
+ }
275
+ }
276
+ ```
277
+
278
+ #### 3.2.2 AI 生成工作流
279
+
280
+ 通过自然语言描述生成结构化工作流节点/连线:
281
+
282
+ ```TypeScript
283
+
284
+ // src/composables/useAi.ts
285
+ import { ref } from 'vue';
286
+ import type { AiGenerateWorkflowParams, WorkflowNode, WorkflowEdge } from '@/types/workflow';
287
+ import { LlmClient } from '@/utils/llmAdapter';
288
+ import { z } from 'zod';
289
+
290
+ // 定义 AI 返回结构的校验 Schema
291
+ const WorkflowSchema = z.object({
292
+ nodes: z.array(z.object({
293
+ id: z.string(),
294
+ type: z.string(),
295
+ data: z.object({
296
+ label: z.string(),
297
+ }),
298
+ position: z.object({
299
+ x: z.number(),
300
+ y: z.number(),
301
+ }),
302
+ })),
303
+ edges: z.array(z.object({
304
+ id: z.string(),
305
+ source: z.string(),
306
+ target: z.string(),
307
+ })),
308
+ });
309
+
310
+ export const useAi = () => {
311
+ const loading = ref(false);
312
+ const error = ref<string | null>(null);
313
+
314
+ // AI 生成工作流
315
+ const generateWorkflow = async (params: AiGenerateWorkflowParams): Promise<{ nodes: WorkflowNode[]; edges: WorkflowEdge[] }> => {
316
+ loading.value = true;
317
+ error.value = null;
318
+ try {
319
+ const llmClient = new LlmClient(params.llmConfig);
320
+ // 构造 Prompt(引导 AI 返回结构化 JSON)
321
+ const prompt = `
322
+ 根据以下描述生成工作流的 JSON 结构:${params.prompt}
323
+ 要求:
324
+ 1. 仅返回 JSON,不要其他文字;
325
+ 2. JSON 包含 nodes 和 edges 两个数组;
326
+ 3. nodes 中每个节点包含 id、type(可选:ai、normal、branch)、data(包含 label)、position(x/y 为数字);
327
+ 4. edges 中每个连线包含 id、source(源节点 ID)、target(目标节点 ID);
328
+ 5. 节点 position 分布合理,避免重叠;
329
+ `;
330
+ const response = await llmClient.invoke(prompt);
331
+ // 解析并校验返回结果
332
+ const workflow = JSON.parse(response);
333
+ const validatedWorkflow = WorkflowSchema.parse(workflow);
334
+ return validatedWorkflow;
335
+ } catch (err) {
336
+ error.value = (err as Error).message;
337
+ throw err;
338
+ } finally {
339
+ loading.value = false;
340
+ }
341
+ };
342
+
343
+ return {
344
+ loading,
345
+ error,
346
+ generateWorkflow,
347
+ };
348
+ };
349
+ ```
350
+
351
+ #### 3.2.3 LangChain 扩展
352
+
353
+ 封装 LangChain 的 Chain/Agent 为可视化节点,支持拖拽组合 AI 流程:
354
+
355
+ ```TypeScript
356
+
357
+ // src/composables/useLangChain.ts
358
+ import { PromptTemplate } from '@langchain/core/prompts';
359
+ import { LLMChain } from 'langchain/chains';
360
+ import { LlmClient } from '@/utils/llmAdapter';
361
+ import type { LlmConfig } from '@/types/ai';
362
+
363
+ export const useLangChain = () => {
364
+ // 创建 LLM Chain 节点逻辑
365
+ const createLlmChain = (llmConfig: LlmConfig, promptTemplate: string, inputVariables: string[]) => {
366
+ const llmClient = new LlmClient(llmConfig);
367
+ const prompt = PromptTemplate.fromTemplate(promptTemplate);
368
+ const chain = new LLMChain({
369
+ llm: llmClient.client,
370
+ prompt,
371
+ });
372
+ // 执行 Chain
373
+ const run = async (inputs: Record<string, string>) => {
374
+ return await chain.run(inputs);
375
+ };
376
+ return { run };
377
+ };
378
+
379
+ return {
380
+ createLlmChain,
381
+ };
382
+ };
383
+ ```
384
+
385
+ ### 3.3 组件化封装(1 周)
386
+
387
+ #### 3.3.1 根组件封装(对外暴露)
388
+
389
+ ```Plain Text
390
+
391
+ <!-- src/components/AiWorkflowEditor.vue -->
392
+ <template>
393
+ <div class="ai-workflow-editor">
394
+ <!-- 工具栏 -->
395
+ <Toolbar
396
+ @save="handleSave"
397
+ @import="handleImport"
398
+ @ai-generate="handleAiGenerate"
399
+ />
400
+ <!-- 节点面板 -->
401
+ <NodePanel @add-node="handleAddNode" />
402
+ <!-- 画布 -->
403
+ <Canvas
404
+ ref="canvasRef"
405
+ @node-click="emit('node-click')"
406
+ @edge-click="emit('edge-click')"
407
+ />
408
+ <!-- AI 生成弹窗 -->
409
+ <AiGenerator
410
+ v-model:visible="aiGenerateVisible"
411
+ @confirm="handleAiGenerateConfirm"
412
+ />
413
+ </div>
414
+ </template>
415
+
416
+ <script setup lang="ts">
417
+ import { ref } from 'vue';
418
+ import Canvas from './editor/Canvas.vue';
419
+ import Toolbar from './editor/Toolbar.vue';
420
+ import NodePanel from './editor/NodePanel.vue';
421
+ import AiGenerator from './ai/AiGenerator.vue';
422
+ import { useAi } from '@/composables/useAi';
423
+ import type { LlmConfig } from '@/types/ai';
424
+
425
+ // 定义 Props
426
+ const props = defineProps<{
427
+ // 初始工作流数据
428
+ initialWorkflow?: { nodes: any[]; edges: any[] };
429
+ // LLM 默认配置
430
+ defaultLlmConfig?: LlmConfig;
431
+ // 自定义节点类型
432
+ customNodeTypes?: Record<string, any>;
433
+ }>();
434
+
435
+ // 定义事件
436
+ const emit = defineEmits<{
437
+ (e: 'save', workflow: { nodes: any[]; edges: any[] }): void;
438
+ (e: 'node-click', node: any): void;
439
+ (e: 'edge-click', edge: any): void;
440
+ (e: 'ai-generate-success', workflow: { nodes: any[]; edges: any[] }): void;
441
+ }>();
442
+
443
+ const canvasRef = ref<InstanceType<typeof Canvas>>();
444
+ const aiGenerateVisible = ref(false);
445
+ const { generateWorkflow } = useAi();
446
+
447
+ // 初始化工作流
448
+ if (props.initialWorkflow) {
449
+ canvasRef.value?.importWorkflow(props.initialWorkflow);
450
+ }
451
+
452
+ // AI 生成工作流确认
453
+ const handleAiGenerateConfirm = async (prompt: string) => {
454
+ if (!props.defaultLlmConfig) return;
455
+ const workflow = await generateWorkflow({
456
+ prompt,
457
+ llmConfig: props.defaultLlmConfig,
458
+ });
459
+ canvasRef.value?.importWorkflow(workflow);
460
+ emit('ai-generate-success', workflow);
461
+ };
462
+
463
+ // 保存工作流
464
+ const handleSave = () => {
465
+ const workflow = canvasRef.value?.exportWorkflow();
466
+ if (workflow) emit('save', workflow);
467
+ };
468
+
469
+ // 暴露对外方法
470
+ defineExpose({
471
+ exportWorkflow: () => canvasRef.value?.exportWorkflow(),
472
+ importWorkflow: (data: any) => canvasRef.value?.importWorkflow(data),
473
+ generateWorkflow: (prompt: string) => handleAiGenerateConfirm(prompt),
474
+ });
475
+ </script>
476
+ ```
477
+
478
+ #### 3.3.2 Nuxt 4 适配
479
+
480
+ 编写 Nuxt 插件,支持自动导入和全局注册:
481
+
482
+ ```TypeScript
483
+
484
+ // src/plugins/aiWorkflowEditor.ts
485
+ import { defineNuxtPlugin } from '#app';
486
+ import AiWorkflowEditor from '@/components/AiWorkflowEditor.vue';
487
+
488
+ export default defineNuxtPlugin((nuxtApp) => {
489
+ // 全局注册组件
490
+ nuxtApp.vueApp.component('AiWorkflowEditor', AiWorkflowEditor);
491
+ });
492
+ ```
493
+
494
+ ---
495
+
496
+ ## 四、组件化发布阶段(1 周)
497
+
498
+ ### 4.1 打包配置
499
+
500
+ 修改 `package.json` 和 `nuxt.config.ts`,配置库模式打包:
501
+
502
+ ```JSON
503
+
504
+ // package.json
505
+ {
506
+ "name": "ai-workflow-editor",
507
+ "version": "0.1.0",
508
+ "type": "module",
509
+ "main": "./dist/module/index.js",
510
+ "types": "./dist/module/index.d.ts",
511
+ "files": [
512
+ "dist"
513
+ ],
514
+ "scripts": {
515
+ "build": "nuxt build --preset module",
516
+ "publish:npm": "npm publish --access public"
517
+ },
518
+ "peerDependencies": {
519
+ "vue": "^3.4.0",
520
+ "nuxt": "^4.0.0"
521
+ }
522
+ }
523
+ ```
524
+
525
+ ### 4.2 npm 发布流程
526
+
527
+ 1. 构建组件库:`npm run build`;
528
+
529
+ 2. 登录 npm 账号:`npm login`;
530
+
531
+ 3. 发布包:`npm run publish:npm`;
532
+
533
+ 4. 发布后验证:在测试项目中安装 `npm install ai-workflow-editor`,验证引入是否正常。
534
+
535
+ ---
536
+
537
+ ## 五、测试验证阶段(1-2 周)
538
+
539
+ ### 5.1 测试类型
540
+
541
+ |测试类型|测试内容|测试工具|
542
+ |---|---|---|
543
+ |单元测试|核心函数(LLM 适配器、工作流解析)、组件逻辑|Vitest|
544
+ |集成测试|组件间交互(节点添加-连线-AI 生成)|Vitest + Vue Test Utils|
545
+ |E2E 测试|完整流程(打开编辑器-拖拽节点-AI 生成-导出)|Playwright|
546
+ |AI 功能测试|验证 OpenAI/Ollama 对接、LangChain 扩展|手动测试 + 接口模拟|
547
+ |兼容性测试|Nuxt 4 适配、不同浏览器(Chrome/Firefox)|手动测试|
548
+ ### 5.2 测试用例示例
549
+
550
+ ```TypeScript
551
+
552
+ // src/utils/__tests__/llmAdapter.test.ts
553
+ import { describe, it, expect } from 'vitest';
554
+ import { LlmClient } from '../llmAdapter';
555
+
556
+ describe('LLM Adapter', () => {
557
+ it('should create OpenAI client correctly', () => {
558
+ const client = new LlmClient({
559
+ provider: 'openai',
560
+ model: 'gpt-3.5-turbo',
561
+ apiKey: 'test-key',
562
+ temperature: 0.7,
563
+ });
564
+ expect(client).toBeInstanceOf(LlmClient);
565
+ });
566
+
567
+ it('should throw error for unsupported provider', () => {
568
+ expect(() => {
569
+ // @ts-ignore 故意传入不支持的 provider
570
+ new LlmClient({ provider: 'test', model: 'test' });
571
+ }).toThrow('Unsupported LLM provider');
572
+ });
573
+ });
574
+ ```
575
+
576
+ ---
577
+
578
+ ## 六、文档与示例阶段(1 周)
579
+
580
+ ### 6.1 文档内容
581
+
582
+ - 快速开始:安装、基本使用、Nuxt 4 集成;
583
+
584
+ - API 文档:Props、事件、暴露方法、类型定义;
585
+
586
+ - AI 集成:OpenAI/Ollama 配置、LangChain 扩展示例;
587
+
588
+ - 自定义扩展:自定义节点、自定义 LLM 提供商;
589
+
590
+ - 常见问题:部署 Ollama、跨域处理、性能优化。
591
+
592
+ ### 6.2 示例工程
593
+
594
+ 提供 2 个示例工程:
595
+
596
+ 1. Vue 3 + Vite 示例:展示纯前端使用方式;
597
+
598
+ 2. Nuxt 4 示例:展示 SSR 环境下的使用方式。
599
+
600
+ ---
601
+
602
+ ## 七、迭代与维护阶段(长期)
603
+
604
+ ### 7.1 短期迭代(1-3 个月)
605
+
606
+ - 支持更多图表类型(架构图、时序图);
607
+
608
+ - 优化 AI 生成工作流的准确性(Prompt 优化、结果校验);
609
+
610
+ - 支持实时协作(基于 Yjs 集成);
611
+
612
+ - 性能优化(大工作流的渲染/操作性能)。
613
+
614
+ ### 7.2 长期维护
615
+
616
+ - 跟进 Vue Flow/LogicFlow、LangChain.js 的版本更新;
617
+
618
+ - 适配新的 LLM 提供商(如 Claude、Gemini);
619
+
620
+ - 修复 Bug、响应社区反馈;
621
+
622
+ - 完善文档和示例。
623
+
624
+ ---
625
+
626
+ ## 总结
627
+
628
+ ### 核心开发要点
629
+
630
+ 1. **技术核心**:基于 Vue Flow 构建可视化编辑器,通过 LangChain.js 统一封装 LLM 调用,确保 OpenAI/Ollama 原生适配;
631
+
632
+ 2. **组件化关键**:遵循 Vue 3 组件规范,适配 Nuxt 4 插件机制,通过库模式打包实现 npm 发布;
633
+
634
+ 3. **AI 能力核心**:通过 Prompt 引导 + Zod 校验确保 AI 生成的工作流结构合法,支持 LangChain 扩展复杂 AI 逻辑。
635
+
636
+ ### 开发节奏
637
+
638
+ - 前期准备 + 架构设计:2-3 周;
639
+
640
+ - 核心功能开发:4-6 周;
641
+
642
+ - 发布 + 测试 + 文档:2-3 周;
643
+
644
+ - 整体周期:8-12 周(可根据功能优先级调整)。
645
+
646
+ ### 风险与应对
647
+
648
+ - AI 生成结果不稳定:增加结果校验、Prompt 模板优化、支持手动调整;
649
+
650
+ - 性能问题(大工作流):实现节点懒加载、画布虚拟滚动;
651
+
652
+ - Nuxt 4 适配问题:优先兼容 Vue 3 核心功能,Nuxt 4 适配作为扩展。
653
+
654
+ 你可根据实际团队规模、开发周期调整各阶段的时间分配,优先完成核心的可视化编辑器 + AI 集成功能,再逐步扩展高级特性。
655
+ > (注:文档部分内容可能由 AI 生成)