@mybricks/plugin-ai 0.0.2 → 0.0.3
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.
- package/dist/_virtual/_rollupPluginBabelHelpers.js +164 -0
- package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
- package/dist/agents/app.js +335 -0
- package/dist/agents/app.js.map +1 -0
- package/dist/agents/common.js +483 -0
- package/dist/agents/common.js.map +1 -0
- package/dist/agents/custom.js +16 -0
- package/dist/agents/custom.js.map +1 -0
- package/dist/agents/index.js +38 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/knowledges/knowledge-base.js +579 -0
- package/dist/agents/knowledges/knowledge-base.js.map +1 -0
- package/dist/agents/knowledges/knowledge-node.js +228 -0
- package/dist/agents/knowledges/knowledge-node.js.map +1 -0
- package/dist/agents/knowledges/types.js +105 -0
- package/dist/agents/knowledges/types.js.map +1 -0
- package/dist/agents/utils/config.js +229 -0
- package/dist/agents/utils/config.js.map +1 -0
- package/dist/agents/workspace/coding-manager.js +20 -0
- package/dist/agents/workspace/coding-manager.js.map +1 -0
- package/dist/agents/workspace/components-manager.js +113 -0
- package/dist/agents/workspace/components-manager.js.map +1 -0
- package/dist/agents/workspace/outline-focus.js +167 -0
- package/dist/agents/workspace/outline-focus.js.map +1 -0
- package/dist/agents/workspace/outline-info.js +430 -0
- package/dist/agents/workspace/outline-info.js.map +1 -0
- package/dist/agents/workspace/page-tree-generator.js +70 -0
- package/dist/agents/workspace/page-tree-generator.js.map +1 -0
- package/dist/agents/workspace/workspace.js +251 -0
- package/dist/agents/workspace/workspace.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js +100 -0
- package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js +120 -0
- package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js +146 -0
- package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/test.js +242 -0
- package/dist/agents/workspace-by-knowledges/test.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/utils/components-manager.js +132 -0
- package/dist/agents/workspace-by-knowledges/utils/components-manager.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-focus.js +167 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-focus.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-info.js +430 -0
- package/dist/agents/workspace-by-knowledges/utils/outline-info.js.map +1 -0
- package/dist/agents/workspace-by-knowledges/workspace.js +169 -0
- package/dist/agents/workspace-by-knowledges/workspace.js.map +1 -0
- package/dist/api/cloud-components.js +85 -0
- package/dist/api/cloud-components.js.map +1 -0
- package/dist/api-record-replay/manager.js +168 -0
- package/dist/api-record-replay/manager.js.map +1 -0
- package/{src/api-record-replay/recorder.ts → dist/api-record-replay/recorder.js} +22 -32
- package/dist/api-record-replay/recorder.js.map +1 -0
- package/dist/api-record-replay/replayer.js +136 -0
- package/dist/api-record-replay/replayer.js.map +1 -0
- package/dist/components/attachments/index.js +124 -0
- package/dist/components/attachments/index.js.map +1 -0
- package/dist/components/attachments/index.less.js +8 -0
- package/dist/components/attachments/index.less.js.map +1 -0
- package/dist/components/icons/index.js +112 -0
- package/dist/components/icons/index.js.map +1 -0
- package/dist/components/icons/index.less.js +8 -0
- package/dist/components/icons/index.less.js.map +1 -0
- package/dist/components/mention/index.js +19 -0
- package/dist/components/mention/index.js.map +1 -0
- package/dist/components/mention/index.less.js +8 -0
- package/dist/components/mention/index.less.js.map +1 -0
- package/dist/components/messages/index.js +429 -0
- package/dist/components/messages/index.js.map +1 -0
- package/dist/components/messages/index.less.js +8 -0
- package/dist/components/messages/index.less.js.map +1 -0
- package/dist/components/sender/index.js +244 -0
- package/dist/components/sender/index.js.map +1 -0
- package/dist/components/sender/index.less.js +8 -0
- package/dist/components/sender/index.less.js.map +1 -0
- package/dist/context/RequestStatusTracker.js +44 -0
- package/dist/context/RequestStatusTracker.js.map +1 -0
- package/dist/context/index.js +45 -0
- package/dist/context/index.js.map +1 -0
- package/dist/data.js +4 -0
- package/dist/data.js.map +1 -0
- package/dist/index.js +306 -0
- package/dist/index.js.map +1 -0
- package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js +27 -0
- package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js.map +1 -0
- package/dist/plugin-ai/package.json.js +8 -0
- package/dist/plugin-ai/package.json.js.map +1 -0
- package/dist/plugin-ai/test/index.js +206 -0
- package/dist/plugin-ai/test/index.js.map +1 -0
- package/dist/preset/createTemplates.js +29 -0
- package/dist/preset/createTemplates.js.map +1 -0
- package/dist/preset/index.js +13 -0
- package/dist/preset/index.js.map +1 -0
- package/dist/preset/prompts.js +34 -0
- package/dist/preset/prompts.js.map +1 -0
- package/{src/preset/user.ts → dist/preset/user.js} +4 -3
- package/dist/preset/user.js.map +1 -0
- package/dist/requestAsStream.js +269 -0
- package/dist/requestAsStream.js.map +1 -0
- package/dist/rxai/node_modules/idb/build/index.js +277 -0
- package/dist/rxai/node_modules/idb/build/index.js.map +1 -0
- package/dist/rxai/src/agent/base.js +16 -0
- package/dist/rxai/src/agent/base.js.map +1 -0
- package/dist/rxai/src/agent/planning.js +1076 -0
- package/dist/rxai/src/agent/planning.js.map +1 -0
- package/dist/rxai/src/agent/rxai.js +254 -0
- package/dist/rxai/src/agent/rxai.js.map +1 -0
- package/dist/rxai/src/error/base.js +39 -0
- package/dist/rxai/src/error/base.js.map +1 -0
- package/dist/rxai/src/prompt/base.js +11 -0
- package/dist/rxai/src/prompt/base.js.map +1 -0
- package/dist/rxai/src/prompt/planning.js +23 -0
- package/dist/rxai/src/prompt/planning.js.map +1 -0
- package/dist/rxai/src/prompt/tool.js +14 -0
- package/dist/rxai/src/prompt/tool.js.map +1 -0
- package/dist/rxai/src/request/request.js +123 -0
- package/dist/rxai/src/request/request.js.map +1 -0
- package/dist/rxai/src/tool/getHistoryRecords.js +65 -0
- package/dist/rxai/src/tool/getHistoryRecords.js.map +1 -0
- package/dist/rxai/src/tool/util.js +424 -0
- package/dist/rxai/src/tool/util.js.map +1 -0
- package/dist/rxai/src/utils/events.js +43 -0
- package/dist/rxai/src/utils/events.js.map +1 -0
- package/dist/rxai/src/utils/idb.js +240 -0
- package/dist/rxai/src/utils/idb.js.map +1 -0
- package/dist/rxai/src/utils/retry.js +32 -0
- package/dist/rxai/src/utils/retry.js.map +1 -0
- package/dist/rxai/src/utils/uuid.js +7 -0
- package/dist/rxai/src/utils/uuid.js.map +1 -0
- package/dist/startView/components/header/header.js +12 -0
- package/dist/startView/components/header/header.js.map +1 -0
- package/dist/startView/components/header/header.less.js +8 -0
- package/dist/startView/components/header/header.less.js.map +1 -0
- package/dist/startView/index.js +62 -0
- package/dist/startView/index.js.map +1 -0
- package/dist/startView/index.less.js +8 -0
- package/dist/startView/index.less.js.map +1 -0
- package/dist/tools/analyze-and-expand-prd.js +116 -0
- package/dist/tools/analyze-and-expand-prd.js.map +1 -0
- package/dist/tools/analyze-requirement-and-components.js +208 -0
- package/dist/tools/analyze-requirement-and-components.js.map +1 -0
- package/dist/tools/answer.js +33 -0
- package/dist/tools/answer.js.map +1 -0
- package/dist/tools/build-process.js +550 -0
- package/dist/tools/build-process.js.map +1 -0
- package/dist/tools/coding-subagent-as-tool.js +101 -0
- package/dist/tools/coding-subagent-as-tool.js.map +1 -0
- package/dist/tools/generate-ui-content.js +528 -0
- package/dist/tools/generate-ui-content.js.map +1 -0
- package/dist/tools/index.js +31 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/open-dsl.js +49 -0
- package/dist/tools/open-dsl.js.map +1 -0
- package/dist/tools/refactor-ui-content.js +292 -0
- package/dist/tools/refactor-ui-content.js.map +1 -0
- package/dist/tools/utils.js +832 -0
- package/dist/tools/utils.js.map +1 -0
- package/dist/types/index.js +8 -0
- package/dist/types/index.js.map +1 -0
- package/dist/view/components/header/header.js +59 -0
- package/dist/view/components/header/header.js.map +1 -0
- package/dist/view/components/header/header.less.js +8 -0
- package/dist/view/components/header/header.less.js.map +1 -0
- package/dist/view/index.js +184 -0
- package/dist/view/index.js.map +1 -0
- package/dist/view/index.less.js +8 -0
- package/dist/view/index.less.js.map +1 -0
- package/package.json +28 -6
- package/src/agents/app.ts +0 -301
- package/src/agents/common.ts +0 -471
- package/src/agents/custom.ts +0 -14
- package/src/agents/index.ts +0 -37
- package/src/agents/knowledges/README.md +0 -614
- package/src/agents/knowledges/SUMMARY.md +0 -527
- package/src/agents/knowledges/index.ts +0 -8
- package/src/agents/knowledges/knowledge-base.ts +0 -565
- package/src/agents/knowledges/knowledge-node.ts +0 -266
- package/src/agents/knowledges/types.ts +0 -208
- package/src/agents/utils/config.ts +0 -427
- package/src/agents/workspace/coding-manager.ts +0 -31
- package/src/agents/workspace/components-manager.ts +0 -124
- package/src/agents/workspace/outline-focus.ts +0 -188
- package/src/agents/workspace/outline-info.ts +0 -520
- package/src/agents/workspace/page-tree-generator.ts +0 -83
- package/src/agents/workspace/workspace.ts +0 -319
- package/src/agents/workspace-by-knowledges/MIGRATION.md +0 -568
- package/src/agents/workspace-by-knowledges/README.md +0 -521
- package/src/agents/workspace-by-knowledges/index.ts +0 -11
- package/src/agents/workspace-by-knowledges/providers/component-docs-provider.ts +0 -92
- package/src/agents/workspace-by-knowledges/providers/focus-info-provider.ts +0 -131
- package/src/agents/workspace-by-knowledges/providers/index.ts +0 -8
- package/src/agents/workspace-by-knowledges/providers/project-info-provider.ts +0 -151
- package/src/agents/workspace-by-knowledges/test.ts +0 -240
- package/src/agents/workspace-by-knowledges/types.ts +0 -56
- package/src/agents/workspace-by-knowledges/utils/components-manager.ts +0 -145
- package/src/agents/workspace-by-knowledges/utils/index.ts +0 -8
- package/src/agents/workspace-by-knowledges/utils/outline-focus.ts +0 -178
- package/src/agents/workspace-by-knowledges/utils/outline-info.ts +0 -521
- package/src/agents/workspace-by-knowledges/workspace.ts +0 -166
- package/src/api/cloud-components.ts +0 -129
- package/src/api-record-replay/README.md +0 -187
- package/src/api-record-replay/index.ts +0 -11
- package/src/api-record-replay/manager.ts +0 -168
- package/src/api-record-replay/replayer.ts +0 -148
- package/src/components/attachments/index.less +0 -117
- package/src/components/attachments/index.tsx +0 -136
- package/src/components/icons/index.less +0 -8
- package/src/components/icons/index.tsx +0 -44
- package/src/components/index.less +0 -34
- package/src/components/mention/index.less +0 -23
- package/src/components/mention/index.tsx +0 -19
- package/src/components/messages/index.less +0 -1013
- package/src/components/messages/index.tsx +0 -519
- package/src/components/sender/index.less +0 -203
- package/src/components/sender/index.tsx +0 -298
- package/src/components/types.ts +0 -31
- package/src/constants/index.ts +0 -8
- package/src/context/RequestStatusTracker.ts +0 -50
- package/src/context/index.ts +0 -83
- package/src/data.ts +0 -5
- package/src/global.d.ts +0 -100
- package/src/index.tsx +0 -264
- package/src/mock.ts +0 -1267
- package/src/preset/agents.ts +0 -380
- package/src/preset/createTemplates.ts +0 -25
- package/src/preset/index.ts +0 -12
- package/src/preset/prompts.ts +0 -235
- package/src/preset/requestAsStream.ts +0 -246
- package/src/startView/components/header/header.less +0 -17
- package/src/startView/components/header/header.tsx +0 -15
- package/src/startView/components/index.ts +0 -1
- package/src/startView/index.less +0 -34
- package/src/startView/index.tsx +0 -61
- package/src/tools/analyze-and-expand-prd.ts +0 -272
- package/src/tools/analyze-requirement-and-components.ts +0 -589
- package/src/tools/answer.ts +0 -59
- package/src/tools/build-process.ts +0 -1174
- package/src/tools/coding-subagent-as-tool.ts +0 -119
- package/src/tools/generate-ui-content.ts +0 -1083
- package/src/tools/index.ts +0 -28
- package/src/tools/open-dsl.ts +0 -69
- package/src/tools/refactor-ui-content.ts +0 -801
- package/src/tools/type.d.ts +0 -12
- package/src/tools/utils.ts +0 -914
- package/src/types/index.ts +0 -4
- package/src/view/components/header/header.less +0 -51
- package/src/view/components/header/header.tsx +0 -60
- package/src/view/components/index.ts +0 -1
- package/src/view/index.less +0 -5
- package/src/view/index.tsx +0 -168
|
@@ -1,568 +0,0 @@
|
|
|
1
|
-
# 从旧 Workspace 迁移到新 Workspace 指南
|
|
2
|
-
|
|
3
|
-
## 快速对比
|
|
4
|
-
|
|
5
|
-
### 旧 Workspace
|
|
6
|
-
|
|
7
|
-
```typescript
|
|
8
|
-
import { WorkSpace } from '../workspace/workspace';
|
|
9
|
-
|
|
10
|
-
const workspace = new WorkSpace(config, api, outlineInfoManager);
|
|
11
|
-
workspace.openDocument('page1');
|
|
12
|
-
const struct = workspace.getProjectStruct();
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
### 新 Workspace
|
|
16
|
-
|
|
17
|
-
```typescript
|
|
18
|
-
import { Workspace } from '../workspace-by-knowledges';
|
|
19
|
-
|
|
20
|
-
const workspace = new Workspace({ ...config, api });
|
|
21
|
-
await workspace.openFile('画布索引/首页.dsl');
|
|
22
|
-
const content = await workspace.export();
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## 核心概念变化
|
|
26
|
-
|
|
27
|
-
### 1. 从"文档"到"文件"
|
|
28
|
-
|
|
29
|
-
**旧方式:** 操作抽象的"文档"
|
|
30
|
-
```typescript
|
|
31
|
-
workspace.openDocument(id);
|
|
32
|
-
workspace.closeDocument(id);
|
|
33
|
-
workspace.checkDocumentStatus(id);
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
**新方式:** 操作具体的"文件路径"
|
|
37
|
-
```typescript
|
|
38
|
-
await workspace.openFile('画布索引/首页.dsl');
|
|
39
|
-
workspace.closeFile('画布索引/首页.dsl');
|
|
40
|
-
workspace.isFileOpened('画布索引/首页.dsl');
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
### 2. 从"结构化输出"到"知识库导出"
|
|
44
|
-
|
|
45
|
-
**旧方式:** 获取预定义的结构化文本
|
|
46
|
-
```typescript
|
|
47
|
-
const struct = workspace.getProjectStruct();
|
|
48
|
-
// 返回固定格式的字符串
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
**新方式:** 导出知识库内容
|
|
52
|
-
```typescript
|
|
53
|
-
const content = await workspace.export({ includeTree: true });
|
|
54
|
-
// 返回动态的、包含目录树和文件内容的完整知识库
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### 3. 从"组件文档管理"到"文件系统视图"
|
|
58
|
-
|
|
59
|
-
**旧方式:** 单独管理组件文档
|
|
60
|
-
```typescript
|
|
61
|
-
workspace.openComponentDoc('mybricks.normal-pc.button');
|
|
62
|
-
workspace.closeComponentDoc('mybricks.normal-pc.button');
|
|
63
|
-
const hasDocs = workspace.hasComponentsDocs();
|
|
64
|
-
const docs = workspace.getComponentsDocs();
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
**新方式:** 统一的文件系统
|
|
68
|
-
```typescript
|
|
69
|
-
await workspace.openFile('可用组件/pc.button.md');
|
|
70
|
-
workspace.closeFile('可用组件/pc.button.md');
|
|
71
|
-
const opened = workspace.getOpenedFilePaths();
|
|
72
|
-
const content = await workspace.export(); // 包含所有已打开的文件
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
## API 迁移对照表
|
|
76
|
-
|
|
77
|
-
| 旧 API | 新 API | 说明 |
|
|
78
|
-
|--------|--------|------|
|
|
79
|
-
| `openDocument(id)` | `openFile(path)` | 通过文件路径打开 |
|
|
80
|
-
| `closeDocument(id)` | `closeFile(path)` | 通过文件路径关闭 |
|
|
81
|
-
| `checkDocumentStatus(id)` | `isFileOpened(path)` | 检查文件是否打开 |
|
|
82
|
-
| `getProjectStruct()` | `export()` | 获取完整内容 |
|
|
83
|
-
| `openComponentDoc(ns)` | `openFile('可用组件/xxx.md')` | 打开组件文档 |
|
|
84
|
-
| `closeComponentDoc(ns)` | `closeFile('可用组件/xxx.md')` | 关闭组件文档 |
|
|
85
|
-
| `hasComponentsDocs()` | `getOpenedFilePaths().length > 0` | 检查是否有打开的文件 |
|
|
86
|
-
| `getComponentsDocs()` | `export()` | 导出时包含所有文档 |
|
|
87
|
-
| - | `getDirectoryTree()` | 新增:获取目录树 |
|
|
88
|
-
| - | `findNode(path)` | 新增:查找节点 |
|
|
89
|
-
| - | `clearOpenedFiles()` | 新增:清空已打开文件 |
|
|
90
|
-
|
|
91
|
-
## 详细迁移步骤
|
|
92
|
-
|
|
93
|
-
### 步骤 1:更新构造函数
|
|
94
|
-
|
|
95
|
-
**旧代码:**
|
|
96
|
-
```typescript
|
|
97
|
-
import { WorkSpace } from '../workspace/workspace';
|
|
98
|
-
import { FocusOutlineInfoManager } from '../workspace/outline-focus';
|
|
99
|
-
|
|
100
|
-
const outlineInfoManager = new FocusOutlineInfoManager({
|
|
101
|
-
api: designerAPI,
|
|
102
|
-
focusInfo: currentFocus
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const workspace = new WorkSpace(
|
|
106
|
-
{ currentFocus },
|
|
107
|
-
workspaceAPI,
|
|
108
|
-
outlineInfoManager
|
|
109
|
-
);
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
**新代码:**
|
|
113
|
-
```typescript
|
|
114
|
-
import { Workspace } from '../workspace-by-knowledges';
|
|
115
|
-
|
|
116
|
-
// 从 context 获取所有依赖,无需手动传入
|
|
117
|
-
const workspace = new Workspace({
|
|
118
|
-
name: 'Workspace',
|
|
119
|
-
description: '工作空间'
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
// 等待默认文件打开完成
|
|
123
|
-
await workspace.waitForReady();
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
**说明:**
|
|
127
|
-
- 不再需要手动传入 API、focusInfo 和 outlineInfoManager
|
|
128
|
-
- 所有依赖从 context 获取
|
|
129
|
-
- 项目信息和聚焦信息默认自动打开
|
|
130
|
-
|
|
131
|
-
### 步骤 2:更新文档打开逻辑
|
|
132
|
-
|
|
133
|
-
**旧代码:**
|
|
134
|
-
```typescript
|
|
135
|
-
// 打开页面文档
|
|
136
|
-
workspace.openDocument(pageId);
|
|
137
|
-
|
|
138
|
-
// 打开组件文档
|
|
139
|
-
workspace.openDocument(componentId);
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
**新代码:**
|
|
143
|
-
```typescript
|
|
144
|
-
// 项目信息和聚焦信息已经默认打开,无需手动打开
|
|
145
|
-
|
|
146
|
-
// 打开组件文档(通过 namespace)
|
|
147
|
-
await workspace.openComponentDocByNamespace('mybricks.normal-pc.antd5.button');
|
|
148
|
-
|
|
149
|
-
// 或通过路径
|
|
150
|
-
await workspace.openComponentDoc('组件配置文档/mybricks.normal-pc.antd5.button.md');
|
|
151
|
-
|
|
152
|
-
// 打开动态文档(如页面内容)
|
|
153
|
-
await workspace.openDocument('page_u_abc123', {
|
|
154
|
-
type: '画布',
|
|
155
|
-
content: '<页面内容>',
|
|
156
|
-
title: '首页',
|
|
157
|
-
directoryId: 'opened-pages' // 需要先注册动态文档目录
|
|
158
|
-
});
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### 步骤 3:更新内容获取逻辑
|
|
162
|
-
|
|
163
|
-
**旧代码:**
|
|
164
|
-
```typescript
|
|
165
|
-
// 获取项目结构
|
|
166
|
-
const projectStruct = workspace.getProjectStruct();
|
|
167
|
-
|
|
168
|
-
// 获取组件文档
|
|
169
|
-
let componentDocs = '';
|
|
170
|
-
if (workspace.hasComponentsDocs()) {
|
|
171
|
-
componentDocs = workspace.getComponentsDocs();
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
// 拼接发送给 AI
|
|
175
|
-
const message = `${projectStruct}\n\n${componentDocs}\n\n用户提问:${userInput}`;
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
**新代码:**
|
|
179
|
-
```typescript
|
|
180
|
-
// 直接导出工作空间内容
|
|
181
|
-
const workspaceContent = await workspace.export({ includeTree: true });
|
|
182
|
-
|
|
183
|
-
// 发送给 AI
|
|
184
|
-
const message = `${workspaceContent}\n\n用户提问:${userInput}`;
|
|
185
|
-
```
|
|
186
|
-
|
|
187
|
-
**优势:** 更简洁,自动包含目录树、聚焦信息、已打开文件等所有内容。
|
|
188
|
-
|
|
189
|
-
### 步骤 4:更新组件文档管理
|
|
190
|
-
|
|
191
|
-
**旧代码:**
|
|
192
|
-
```typescript
|
|
193
|
-
// 打开组件文档
|
|
194
|
-
workspace.openComponentDoc('mybricks.normal-pc.button');
|
|
195
|
-
workspace.openComponentDoc('mybricks.normal-pc.input');
|
|
196
|
-
|
|
197
|
-
// 关闭组件文档
|
|
198
|
-
workspace.closeComponentDoc('mybricks.normal-pc.button');
|
|
199
|
-
|
|
200
|
-
// 检查是否有文档
|
|
201
|
-
if (workspace.hasComponentsDocs()) {
|
|
202
|
-
const docs = workspace.getComponentsDocs();
|
|
203
|
-
// 使用文档
|
|
204
|
-
}
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
**新代码:**
|
|
208
|
-
```typescript
|
|
209
|
-
// 打开组件文档(自动打开依赖)
|
|
210
|
-
await workspace.openComponentByNamespace('mybricks.normal-pc.button');
|
|
211
|
-
await workspace.openComponentByNamespace('mybricks.normal-pc.input');
|
|
212
|
-
|
|
213
|
-
// 关闭组件文档
|
|
214
|
-
const abbreviation = ComponentsManager.getAbbreviation('mybricks.normal-pc.button');
|
|
215
|
-
workspace.closeFile(`可用组件/${abbreviation}.md`);
|
|
216
|
-
|
|
217
|
-
// 检查已打开的文件
|
|
218
|
-
const openedFiles = workspace.getOpenedFilePaths();
|
|
219
|
-
if (openedFiles.length > 0) {
|
|
220
|
-
const content = await workspace.export();
|
|
221
|
-
// 使用内容
|
|
222
|
-
}
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### 步骤 5:更新聚焦信息处理
|
|
226
|
-
|
|
227
|
-
**旧代码:**
|
|
228
|
-
```typescript
|
|
229
|
-
// 聚焦信息在构造时传入,之后无法更新
|
|
230
|
-
const workspace = new WorkSpace(
|
|
231
|
-
{ currentFocus: { pageId: 'page1' } },
|
|
232
|
-
api,
|
|
233
|
-
outlineInfoManager
|
|
234
|
-
);
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
**新代码:**
|
|
238
|
-
```typescript
|
|
239
|
-
// 从 context 获取聚焦信息,无需手动传入
|
|
240
|
-
const workspace = new Workspace({
|
|
241
|
-
name: 'Workspace'
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
// 聚焦信息文件已经默认打开
|
|
245
|
-
await workspace.waitForReady();
|
|
246
|
-
|
|
247
|
-
// 当 context.currentFocus 变化时,刷新工作空间
|
|
248
|
-
await workspace.refresh();
|
|
249
|
-
|
|
250
|
-
// refresh 会:
|
|
251
|
-
// 1. 清空所有已打开的文件
|
|
252
|
-
// 2. 清空所有动态文档
|
|
253
|
-
// 3. 重新初始化 providers
|
|
254
|
-
// 4. 重新打开默认文件(项目信息和聚焦信息)
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
## 实际案例:重构 AI 对话处理函数
|
|
258
|
-
|
|
259
|
-
### 旧实现
|
|
260
|
-
|
|
261
|
-
```typescript
|
|
262
|
-
async function handleAIChat(userMessage: string) {
|
|
263
|
-
// 创建 workspace
|
|
264
|
-
const outlineInfoManager = new FocusOutlineInfoManager({
|
|
265
|
-
api: designerAPI,
|
|
266
|
-
focusInfo: getCurrentFocus()
|
|
267
|
-
});
|
|
268
|
-
|
|
269
|
-
const workspace = new WorkSpace(
|
|
270
|
-
{ currentFocus: getCurrentFocus() },
|
|
271
|
-
workspaceAPI,
|
|
272
|
-
outlineInfoManager
|
|
273
|
-
);
|
|
274
|
-
|
|
275
|
-
// 根据用户消息打开相关文档
|
|
276
|
-
if (userMessage.includes('按钮')) {
|
|
277
|
-
workspace.openComponentDoc('mybricks.normal-pc.button');
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
if (userMessage.includes('页面')) {
|
|
281
|
-
workspace.openDocument(getCurrentFocus().pageId);
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
// 构建消息
|
|
285
|
-
const projectStruct = workspace.getProjectStruct();
|
|
286
|
-
const componentDocs = workspace.hasComponentsDocs()
|
|
287
|
-
? workspace.getComponentsDocs()
|
|
288
|
-
: '';
|
|
289
|
-
|
|
290
|
-
const fullMessage = `${projectStruct}\n\n${componentDocs}\n\n用户:${userMessage}`;
|
|
291
|
-
|
|
292
|
-
// 发送给 AI
|
|
293
|
-
return await aiAPI.chat(fullMessage);
|
|
294
|
-
}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
### 新实现
|
|
298
|
-
|
|
299
|
-
```typescript
|
|
300
|
-
async function handleAIChat(userMessage: string) {
|
|
301
|
-
// 创建 workspace(从 context 获取所有依赖)
|
|
302
|
-
const workspace = new Workspace({
|
|
303
|
-
name: 'Workspace'
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
// 等待默认文件打开(项目信息和聚焦信息)
|
|
307
|
-
await workspace.waitForReady();
|
|
308
|
-
|
|
309
|
-
// 根据用户消息打开相关文档
|
|
310
|
-
if (userMessage.includes('按钮')) {
|
|
311
|
-
await workspace.openComponentDocByNamespace('mybricks.normal-pc.antd5.button');
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
// 如果需要添加页面内容,使用动态文档
|
|
315
|
-
if (userMessage.includes('页面')) {
|
|
316
|
-
const pageContent = await fetchPageContent(context.currentFocus?.pageId);
|
|
317
|
-
await workspace.openDocument(context.currentFocus?.pageId || '', {
|
|
318
|
-
type: '画布',
|
|
319
|
-
content: pageContent,
|
|
320
|
-
title: '当前页面'
|
|
321
|
-
});
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// 导出完整内容(包含默认打开的项目信息和聚焦信息)
|
|
325
|
-
const workspaceContent = await workspace.export({ includeTree: true });
|
|
326
|
-
|
|
327
|
-
// 构建消息
|
|
328
|
-
const fullMessage = `${workspaceContent}\n\n用户:${userMessage}`;
|
|
329
|
-
|
|
330
|
-
// 发送给 AI
|
|
331
|
-
return await aiAPI.chat(fullMessage);
|
|
332
|
-
}
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
**改进点:**
|
|
336
|
-
1. 代码更简洁(减少约 40%)
|
|
337
|
-
2. 从 context 获取所有依赖,无需手动传入
|
|
338
|
-
3. 不需要手动管理 outlineInfoManager
|
|
339
|
-
4. 不需要分别获取和拼接不同部分的内容
|
|
340
|
-
5. 项目信息和聚焦信息默认自动打开
|
|
341
|
-
6. 支持动态文档
|
|
342
|
-
7. 自动处理组件依赖
|
|
343
|
-
|
|
344
|
-
## 类型迁移
|
|
345
|
-
|
|
346
|
-
### WorkspaceConfig
|
|
347
|
-
|
|
348
|
-
**旧定义:**
|
|
349
|
-
```typescript
|
|
350
|
-
interface WorkSpaceConfig {
|
|
351
|
-
currentFocus: FocusInfo;
|
|
352
|
-
}
|
|
353
|
-
```
|
|
354
|
-
|
|
355
|
-
**新定义:**
|
|
356
|
-
```typescript
|
|
357
|
-
interface WorkspaceConfig extends KnowledgeBaseConfig {
|
|
358
|
-
// 所有依赖从 context 获取,无需传入
|
|
359
|
-
// 只需要 name 和 description(可选)
|
|
360
|
-
}
|
|
361
|
-
```
|
|
362
|
-
|
|
363
|
-
### API 获取方式
|
|
364
|
-
|
|
365
|
-
**旧方式:**
|
|
366
|
-
```typescript
|
|
367
|
-
// 需要手动传入 API
|
|
368
|
-
const workspaceAPI: WorkspaceAPI = {
|
|
369
|
-
getAllPageInfo: () => { /* ... */ },
|
|
370
|
-
getPageOutline: (pageId) => { /* ... */ },
|
|
371
|
-
getComponentDoc: (namespace) => { /* ... */ },
|
|
372
|
-
getAvailableComponents: () => { /* ... */ }
|
|
373
|
-
};
|
|
374
|
-
|
|
375
|
-
const workspace = new WorkSpace(config, workspaceAPI, outlineInfoManager);
|
|
376
|
-
```
|
|
377
|
-
|
|
378
|
-
**新方式:**
|
|
379
|
-
```typescript
|
|
380
|
-
// 从 context 获取所有 API,无需手动传入
|
|
381
|
-
// 确保 context.api 已经初始化
|
|
382
|
-
|
|
383
|
-
const workspace = new Workspace({
|
|
384
|
-
name: 'Workspace'
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
// Workspace 内部会从 context 获取:
|
|
388
|
-
// - context.api.global.api.getAllPageInfo()
|
|
389
|
-
// - context.api.global.api.getComEditorPrompts() 或 context.api.uiCom.api.getComEditorPrompts()
|
|
390
|
-
// - context.currentFocus
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
## 注意事项
|
|
394
|
-
|
|
395
|
-
### 1. Context 依赖
|
|
396
|
-
|
|
397
|
-
新 Workspace 从 context 获取所有依赖:
|
|
398
|
-
```typescript
|
|
399
|
-
// ❌ 错误:在 context 未初始化时创建
|
|
400
|
-
const workspace = new Workspace({ name: 'Workspace' });
|
|
401
|
-
|
|
402
|
-
// ✅ 正确:确保在设计器环境中运行
|
|
403
|
-
if (context.api) {
|
|
404
|
-
const workspace = new Workspace({ name: 'Workspace' });
|
|
405
|
-
}
|
|
406
|
-
```
|
|
407
|
-
|
|
408
|
-
### 2. 异步操作
|
|
409
|
-
|
|
410
|
-
新 Workspace 的很多操作都是异步的:
|
|
411
|
-
```typescript
|
|
412
|
-
// ❌ 错误:忘记 await
|
|
413
|
-
workspace.waitForReady();
|
|
414
|
-
workspace.openComponentDocByNamespace('mybricks.normal-pc.antd5.button');
|
|
415
|
-
|
|
416
|
-
// ✅ 正确
|
|
417
|
-
await workspace.waitForReady();
|
|
418
|
-
await workspace.openComponentDocByNamespace('mybricks.normal-pc.antd5.button');
|
|
419
|
-
```
|
|
420
|
-
|
|
421
|
-
### 3. 路径格式
|
|
422
|
-
|
|
423
|
-
新 Workspace 使用文件路径,需要注意格式:
|
|
424
|
-
```typescript
|
|
425
|
-
// ✅ 正确的路径格式
|
|
426
|
-
'项目信息.md'
|
|
427
|
-
'聚焦信息.md'
|
|
428
|
-
'组件配置文档/mybricks.normal-pc.antd5.button.md'
|
|
429
|
-
|
|
430
|
-
// ❌ 错误的路径格式
|
|
431
|
-
'项目信息\\首页.dsl' // 不要用反斜杠
|
|
432
|
-
'/项目信息.md' // 不要以斜杠开头
|
|
433
|
-
'项目信息' // 缺少扩展名
|
|
434
|
-
```
|
|
435
|
-
|
|
436
|
-
### 4. 默认打开的文件
|
|
437
|
-
|
|
438
|
-
新 Workspace 默认打开项目信息和聚焦信息:
|
|
439
|
-
```typescript
|
|
440
|
-
const workspace = new Workspace({ name: 'Workspace' });
|
|
441
|
-
|
|
442
|
-
// 等待默认文件打开
|
|
443
|
-
await workspace.waitForReady();
|
|
444
|
-
|
|
445
|
-
// 此时已经打开了:
|
|
446
|
-
// - 项目信息.md
|
|
447
|
-
// - 聚焦信息.md
|
|
448
|
-
|
|
449
|
-
console.log(workspace.getOpenedFilePaths());
|
|
450
|
-
// ['项目信息.md', '聚焦信息.md']
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
### 5. 刷新机制
|
|
454
|
-
|
|
455
|
-
当 context.currentFocus 变化时,需要刷新工作空间:
|
|
456
|
-
```typescript
|
|
457
|
-
// 监听聚焦变化
|
|
458
|
-
context.on('focusChange', async () => {
|
|
459
|
-
await workspace.refresh();
|
|
460
|
-
|
|
461
|
-
// refresh 会重新打开默认文件
|
|
462
|
-
// 并清空所有动态文档
|
|
463
|
-
});
|
|
464
|
-
```
|
|
465
|
-
|
|
466
|
-
## 渐进式迁移策略
|
|
467
|
-
|
|
468
|
-
如果项目较大,可以采用渐进式迁移:
|
|
469
|
-
|
|
470
|
-
### 阶段 1:并行运行
|
|
471
|
-
|
|
472
|
-
```typescript
|
|
473
|
-
import { WorkSpace as OldWorkspace } from '../workspace/workspace';
|
|
474
|
-
import { Workspace as NewWorkspace } from '../workspace-by-knowledges';
|
|
475
|
-
|
|
476
|
-
// 同时创建新旧两个实例
|
|
477
|
-
const oldWorkspace = new OldWorkspace(config, api, outlineInfo);
|
|
478
|
-
const newWorkspace = new NewWorkspace({ ...config, api });
|
|
479
|
-
|
|
480
|
-
// 对比输出
|
|
481
|
-
console.log('旧输出:', oldWorkspace.getProjectStruct());
|
|
482
|
-
console.log('新输出:', await newWorkspace.export());
|
|
483
|
-
```
|
|
484
|
-
|
|
485
|
-
### 阶段 2:部分功能切换
|
|
486
|
-
|
|
487
|
-
```typescript
|
|
488
|
-
// 创建适配器
|
|
489
|
-
class WorkspaceAdapter {
|
|
490
|
-
private newWorkspace: Workspace;
|
|
491
|
-
|
|
492
|
-
constructor(config) {
|
|
493
|
-
this.newWorkspace = new Workspace(config);
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// 保持旧 API,内部调用新实现
|
|
497
|
-
async openDocument(id: string) {
|
|
498
|
-
// 判断是页面还是组件
|
|
499
|
-
if (this.isPageId(id)) {
|
|
500
|
-
await this.newWorkspace.openCanvasByPageId(id);
|
|
501
|
-
} else {
|
|
502
|
-
// 处理组件
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
async getProjectStruct() {
|
|
507
|
-
return await this.newWorkspace.export();
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// ... 其他适配方法
|
|
511
|
-
}
|
|
512
|
-
```
|
|
513
|
-
|
|
514
|
-
### 阶段 3:完全切换
|
|
515
|
-
|
|
516
|
-
全部功能验证无误后,完全切换到新实现。
|
|
517
|
-
|
|
518
|
-
## 测试建议
|
|
519
|
-
|
|
520
|
-
### 单元测试示例
|
|
521
|
-
|
|
522
|
-
```typescript
|
|
523
|
-
describe('Workspace Migration', () => {
|
|
524
|
-
it('should produce similar output', async () => {
|
|
525
|
-
const oldWorkspace = new OldWorkspace(config, api, outlineInfo);
|
|
526
|
-
const newWorkspace = new Workspace({ ...config, api });
|
|
527
|
-
|
|
528
|
-
// 执行相同操作
|
|
529
|
-
oldWorkspace.openDocument('page1');
|
|
530
|
-
await newWorkspace.openCanvasByPageId('page1');
|
|
531
|
-
|
|
532
|
-
const oldOutput = oldWorkspace.getProjectStruct();
|
|
533
|
-
const newOutput = await newWorkspace.export();
|
|
534
|
-
|
|
535
|
-
// 对比关键信息是否一致
|
|
536
|
-
expect(newOutput).toContain('page1');
|
|
537
|
-
expect(newOutput).toContain('首页');
|
|
538
|
-
});
|
|
539
|
-
});
|
|
540
|
-
```
|
|
541
|
-
|
|
542
|
-
## 总结
|
|
543
|
-
|
|
544
|
-
迁移到新 Workspace 的主要好处:
|
|
545
|
-
|
|
546
|
-
1. **从 context 获取依赖** - 无需手动传入 API 和 focusInfo,代码更简洁
|
|
547
|
-
2. **默认自动打开** - 项目信息和聚焦信息默认打开,减少手动操作
|
|
548
|
-
3. **更清晰的概念模型** - 文件系统视图更直观
|
|
549
|
-
4. **更灵活的扩展能力** - 继承自 KnowledgeBase,基于 Provider 模式
|
|
550
|
-
5. **更好的维护性** - 代码结构更清晰
|
|
551
|
-
6. **更强的功能** - 动态文档、权重排序、隐藏节点、自动依赖等
|
|
552
|
-
7. **统一的接口** - 基于知识库架构
|
|
553
|
-
|
|
554
|
-
### 迁移检查清单
|
|
555
|
-
|
|
556
|
-
- [ ] 确保代码运行在设计器环境中(context 已初始化)
|
|
557
|
-
- [ ] 移除手动传入的 API、focusInfo 和 outlineInfoManager
|
|
558
|
-
- [ ] 更新构造函数调用
|
|
559
|
-
- [ ] 添加 `await workspace.waitForReady()` 等待默认文件打开
|
|
560
|
-
- [ ] 将 `workspace.openComponentDoc(namespace)` 改为 `workspace.openComponentDocByNamespace(namespace)`
|
|
561
|
-
- [ ] 将 `workspace.getProjectStruct()` 改为 `await workspace.export()`
|
|
562
|
-
- [ ] 如需动态添加页面/组件内容,使用 `workspace.openDocument()` 和动态文档功能
|
|
563
|
-
- [ ] 添加聚焦变化监听,调用 `workspace.refresh()`
|
|
564
|
-
- [ ] 更新路径格式(如果有直接使用路径的地方)
|
|
565
|
-
- [ ] 测试所有功能是否正常工作
|
|
566
|
-
|
|
567
|
-
建议采用渐进式迁移策略,确保平稳过渡。
|
|
568
|
-
|