@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,83 +0,0 @@
|
|
|
1
|
-
interface PageInfo {
|
|
2
|
-
id: string;
|
|
3
|
-
title: string;
|
|
4
|
-
type: string;
|
|
5
|
-
componentType?: string;
|
|
6
|
-
children?: PageInfo[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
interface PagesData {
|
|
10
|
-
pageAry: PageInfo[];
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 页面树生成器
|
|
16
|
-
*/
|
|
17
|
-
export class PageTreeGenerator {
|
|
18
|
-
static generate(pagesInfo: PagesData | PagesData[], options: { pageId?: string } = {}): string {
|
|
19
|
-
const { pageId: focusedPageId } = options;
|
|
20
|
-
|
|
21
|
-
const processedPages = this.processRawData(pagesInfo);
|
|
22
|
-
return this.generateTreeText(processedPages, focusedPageId);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
private static processRawData(rawData: PagesData | PagesData[]): PageInfo[] {
|
|
26
|
-
// 如果 rawData 是数组
|
|
27
|
-
if (Array.isArray(rawData)) {
|
|
28
|
-
const allPages: PageInfo[] = [];
|
|
29
|
-
rawData.forEach((canvas: any) => {
|
|
30
|
-
if (canvas.pageAry && Array.isArray(canvas.pageAry)) { // 多画布
|
|
31
|
-
allPages.push(...canvas.pageAry.map((page: any) => ({
|
|
32
|
-
id: page.id,
|
|
33
|
-
title: page.title,
|
|
34
|
-
type: page.type,
|
|
35
|
-
componentType: page.componentType || undefined,
|
|
36
|
-
children: page.children || []
|
|
37
|
-
})));
|
|
38
|
-
} else if (canvas.id) {
|
|
39
|
-
allPages.push({ ...canvas })
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return allPages;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 如果不是数组
|
|
46
|
-
if (!rawData?.pageAry) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return rawData.pageAry.map((page: PageInfo) => ({
|
|
51
|
-
id: page.id,
|
|
52
|
-
title: page.title,
|
|
53
|
-
type: page.type,
|
|
54
|
-
componentType: page.componentType || undefined,
|
|
55
|
-
children: page.children || []
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
private static generateTreeText(pages: PageInfo[], focusedPageId?: string, level = 0): string {
|
|
60
|
-
let result = '';
|
|
61
|
-
const indent = ' '.repeat(level);
|
|
62
|
-
|
|
63
|
-
pages.forEach(page => {
|
|
64
|
-
let line = `${indent}- ${page.title}[id=${page.id}]`;
|
|
65
|
-
|
|
66
|
-
if (page.componentType) {
|
|
67
|
-
line += `(${page.componentType})`;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (focusedPageId && page.id === focusedPageId) {
|
|
71
|
-
line += ' 【当前聚焦】';
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
result += line + '\n';
|
|
75
|
-
|
|
76
|
-
if (page.children && page.children.length > 0) {
|
|
77
|
-
result += this.generateTreeText(page.children, focusedPageId, level + 1);
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
return result;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
import { OutlineNode } from './outline-info'
|
|
2
|
-
import { FocusOutlineInfoManager, FocusInfo } from './outline-focus'
|
|
3
|
-
import { ComponentsManager } from './components-manager'
|
|
4
|
-
import { PageTreeGenerator } from './page-tree-generator';
|
|
5
|
-
|
|
6
|
-
// 类型定义
|
|
7
|
-
interface DocumentInfo {
|
|
8
|
-
id: string;
|
|
9
|
-
type: string;
|
|
10
|
-
title: string;
|
|
11
|
-
desc: string;
|
|
12
|
-
content: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
interface PageInfo {
|
|
16
|
-
id: string;
|
|
17
|
-
title: string;
|
|
18
|
-
type: string;
|
|
19
|
-
componentType?: string;
|
|
20
|
-
children?: PageInfo[];
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
interface PagesData {
|
|
24
|
-
pageAry: PageInfo[];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
interface WorkSpaceConfig {
|
|
28
|
-
currentFocus: FocusInfo;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
interface WorkSpaceAPI {
|
|
32
|
-
getAllPageInfo(): PagesData | PagesData[];
|
|
33
|
-
getComponentDoc(ns: string): string
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
class WorkSpace {
|
|
37
|
-
private openedDocuments: DocumentInfo[] = [];
|
|
38
|
-
|
|
39
|
-
private api: WorkSpaceAPI;
|
|
40
|
-
private focusInfo: FocusInfo;
|
|
41
|
-
private outlineInfoManager: FocusOutlineInfoManager;
|
|
42
|
-
private openedComponentDocs: string[] = []
|
|
43
|
-
|
|
44
|
-
/** 当前聚焦页面的大纲 */
|
|
45
|
-
focusPageOutlineInfo: OutlineNode
|
|
46
|
-
|
|
47
|
-
constructor(config: WorkSpaceConfig, api: WorkSpaceAPI, outlineInfo: FocusOutlineInfoManager) {
|
|
48
|
-
this.api = api;
|
|
49
|
-
this.focusInfo = { ...(config.currentFocus ?? {}) };
|
|
50
|
-
this.outlineInfoManager = outlineInfo;
|
|
51
|
-
|
|
52
|
-
this.focusPageOutlineInfo = this.outlineInfoManager.getFocusPageOutline();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 获取所有页面信息
|
|
58
|
-
*/
|
|
59
|
-
private getAllPageInfo(): PagesData | PagesData[] {
|
|
60
|
-
return this.api.getAllPageInfo();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 根据ID查找页面信息
|
|
65
|
-
*/
|
|
66
|
-
private findPageById(id: string): PageInfo | null {
|
|
67
|
-
const allPageInfo = this.getAllPageInfo();
|
|
68
|
-
let pages: PageInfo[] = [];
|
|
69
|
-
|
|
70
|
-
// 兼容两种返回类型
|
|
71
|
-
if (Array.isArray(allPageInfo)) {
|
|
72
|
-
// 如果是 PagesData[] 类型
|
|
73
|
-
allPageInfo.forEach(pagesData => {
|
|
74
|
-
if (pagesData.pageAry && Array.isArray(pagesData.pageAry)) { // 多画布
|
|
75
|
-
pages.push(...pagesData.pageAry);
|
|
76
|
-
} else {
|
|
77
|
-
pages.push({ ...pagesData } as any as PageInfo) // 单画布
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
} else {
|
|
81
|
-
// 如果是 PagesData 类型
|
|
82
|
-
pages = allPageInfo.pageAry || [];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return this.searchPageInArray(id, pages);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 在页面数组中递归查找页面
|
|
90
|
-
*/
|
|
91
|
-
private searchPageInArray(id: string, pages: PageInfo[]): PageInfo | null {
|
|
92
|
-
for (const page of pages) {
|
|
93
|
-
if (page.id === id) {
|
|
94
|
-
return page;
|
|
95
|
-
}
|
|
96
|
-
if (page.children) {
|
|
97
|
-
const found = this.searchPageInArray(id, page.children);
|
|
98
|
-
if (found) return found;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
getJsxById = (id: string): string => {
|
|
105
|
-
const isPage = this.focusInfo.pageId === id || !!this.findPageById(id);
|
|
106
|
-
if (isPage) {
|
|
107
|
-
return this.outlineInfoManager.generateJSXByPageId(id)?.jsx ?? '';
|
|
108
|
-
} else {
|
|
109
|
-
return this.outlineInfoManager.generateJSXByOutline(this.focusPageOutlineInfo, [id])?.jsx ?? '';
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 打开文档
|
|
115
|
-
*/
|
|
116
|
-
openDocument(id: string): void {
|
|
117
|
-
|
|
118
|
-
// 检查是否已经打开
|
|
119
|
-
if (this.openedDocuments.some(doc => doc.id === id)) {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const isPage = this.focusInfo.pageId === id || !!this.findPageById(id);
|
|
124
|
-
const typeDesc = isPage ? '画布' : '组件'
|
|
125
|
-
|
|
126
|
-
let outlineInfo: OutlineNode;
|
|
127
|
-
let targetComponentIds: string[] = [];
|
|
128
|
-
|
|
129
|
-
if (isPage) {
|
|
130
|
-
// 如果是页面,直接获取页面信息
|
|
131
|
-
outlineInfo = this.outlineInfoManager.getPageOutline(id);
|
|
132
|
-
targetComponentIds = [];
|
|
133
|
-
} else {
|
|
134
|
-
// 如果是组件,需要获取包含该组件的页面信息
|
|
135
|
-
outlineInfo = this.focusPageOutlineInfo;
|
|
136
|
-
|
|
137
|
-
// 获取所有已打开的组件ID(排除页面ID)
|
|
138
|
-
const openedComponentIds = this.openedDocuments
|
|
139
|
-
.filter(doc => doc.type === '组件')
|
|
140
|
-
.map(doc => doc.id);
|
|
141
|
-
|
|
142
|
-
// 添加当前要打开的组件ID
|
|
143
|
-
targetComponentIds = [...openedComponentIds, id];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
const componentsInfo = this.outlineInfoManager.generateJSXByOutline(outlineInfo, targetComponentIds);
|
|
147
|
-
|
|
148
|
-
// 将已经打开文档的组件配置文档拿出来
|
|
149
|
-
componentsInfo.namespaces.forEach(ns => this.openComponentDoc(ns));
|
|
150
|
-
|
|
151
|
-
if (isPage) {
|
|
152
|
-
// 页面类型:直接添加新文档
|
|
153
|
-
this.openedDocuments.push({
|
|
154
|
-
id,
|
|
155
|
-
type: typeDesc,
|
|
156
|
-
title: '',
|
|
157
|
-
desc: '',
|
|
158
|
-
content: componentsInfo.jsx
|
|
159
|
-
});
|
|
160
|
-
} else {
|
|
161
|
-
// 组件类型:检查是否需要更新现有文档或创建新文档
|
|
162
|
-
const existingComponentDocs = this.openedDocuments.filter(doc => doc.type === '组件');
|
|
163
|
-
|
|
164
|
-
if (existingComponentDocs.length > 0) {
|
|
165
|
-
// 如果已经有组件文档,更新第一个组件文档的内容
|
|
166
|
-
existingComponentDocs[0].content = componentsInfo.jsx;
|
|
167
|
-
existingComponentDocs[0].id = componentsInfo.id;
|
|
168
|
-
// 可以选择更新ID为组合ID,比如:
|
|
169
|
-
// existingComponentDocs[0].id = targetComponentIds.join(',');
|
|
170
|
-
} else {
|
|
171
|
-
// 如果没有组件文档,创建新的
|
|
172
|
-
this.openedDocuments.push({
|
|
173
|
-
id: componentsInfo.id,
|
|
174
|
-
type: typeDesc,
|
|
175
|
-
title: '',
|
|
176
|
-
desc: '',
|
|
177
|
-
content: componentsInfo.jsx
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 关闭文档
|
|
185
|
-
*/
|
|
186
|
-
closeDocument(id: string): void {
|
|
187
|
-
this.openedDocuments = this.openedDocuments.filter(doc => doc.id !== id);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* 检查文档状态
|
|
192
|
-
*/
|
|
193
|
-
checkDocumentStatus(id: string) {
|
|
194
|
-
if (this.openedDocuments.some(doc => doc.id === id)) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* 获取项目结构描述
|
|
202
|
-
*/
|
|
203
|
-
getProjectStruct(): string {
|
|
204
|
-
const pageTree = PageTreeGenerator.generate(this.getAllPageInfo(), {
|
|
205
|
-
pageId: this.focusInfo.pageId
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
const focusDescription = this.outlineInfoManager.generateFocusDescription();
|
|
209
|
-
|
|
210
|
-
const contentHierarchy = this.outlineInfoManager.generateFocusHierarchy();
|
|
211
|
-
|
|
212
|
-
const openedDocumentsList = this.generateOpenedDocumentsList();
|
|
213
|
-
|
|
214
|
-
return `# 工作空间(Workspace)
|
|
215
|
-
工作空间包含整个项目的「画布索引」「聚焦信息」「已打开的文档」,提供的始终都是最新的项目信息。
|
|
216
|
-
|
|
217
|
-
WARNING: 如果「历史记录」的信息和工作空间冲突,始终以工作空间的信息为准,因为「历史记录」的操作很有可能没保存,且不是最新的。
|
|
218
|
-
|
|
219
|
-
## 画布索引
|
|
220
|
-
${pageTree}
|
|
221
|
-
|
|
222
|
-
## 聚焦信息
|
|
223
|
-
以下是当前聚焦组件的简略树结构,展示了聚焦元素的父级、兄弟、子级元素的关系。
|
|
224
|
-
注意:此树结构并不完整,折叠了无关元素信息,如需详细信息请打开DSL文档获取。
|
|
225
|
-
|
|
226
|
-
${contentHierarchy}
|
|
227
|
-
|
|
228
|
-
${focusDescription}
|
|
229
|
-
|
|
230
|
-
## 已打开的文档
|
|
231
|
-
${openedDocumentsList}
|
|
232
|
-
`;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
openComponentDoc(namespace: string) {
|
|
236
|
-
// 校验,保证传入的是完整namespace
|
|
237
|
-
const fullNamespace = ComponentsManager.getFullNamespace(namespace)
|
|
238
|
-
|
|
239
|
-
// 检查是否已经打开
|
|
240
|
-
if (this.openedComponentDocs.some(ns => ns === fullNamespace)) {
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
this.openedComponentDocs.push(fullNamespace)
|
|
245
|
-
|
|
246
|
-
// 加载依赖
|
|
247
|
-
const requires = ComponentsManager.getRequireComponents(fullNamespace)
|
|
248
|
-
if (Array.isArray(requires) && requires.length) {
|
|
249
|
-
requires.forEach(ns => this.openComponentDoc(ns))
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
closeComponentDoc(namespace: string) {
|
|
254
|
-
// 校验,保证传入的是完整namespace
|
|
255
|
-
const fullNamespace = ComponentsManager.getFullNamespace(namespace)
|
|
256
|
-
this.openedComponentDocs = this.openedComponentDocs.filter(ns => ns !== fullNamespace)
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
hasComponentsDocs(): boolean {
|
|
260
|
-
return this.openedComponentDocs.length > 0
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* 获取组件文档
|
|
265
|
-
*/
|
|
266
|
-
getComponentsDocs(): string {
|
|
267
|
-
const layoutComponentsNs = ComponentsManager.getLayoutComponentsAbbreviationNs()
|
|
268
|
-
return `# 组件使用文档
|
|
269
|
-
${layoutComponentsNs.length ? `在以下所有组件中,特别的,${layoutComponentsNs.map(ns => ns).join('、')} 是用于基础布局的组件,辅助标记也仅可以用于这些组件` : ''}
|
|
270
|
-
|
|
271
|
-
${this.openedComponentDocs.map(namespace => {
|
|
272
|
-
// 校验,保证传入的是完整namespace
|
|
273
|
-
const fullNamespace = ComponentsManager.getFullNamespace(namespace)
|
|
274
|
-
|
|
275
|
-
const abbreviationNs = ComponentsManager.getAbbreviation(fullNamespace);
|
|
276
|
-
const componentInfo = ComponentsManager.getAiComponent(fullNamespace)
|
|
277
|
-
const componentAll = componentInfo?.all ?? {}
|
|
278
|
-
const inputs = componentAll?.inputs?.reduce?.((pre: string, { id, title, schema }: any) => {
|
|
279
|
-
let schemaStr = "";
|
|
280
|
-
try {
|
|
281
|
-
schemaStr = ` - schema: ${JSON.stringify(schema)}\n`
|
|
282
|
-
} catch {}
|
|
283
|
-
return pre + ` - ${title} → inputId: \`${id}\`\n` +
|
|
284
|
-
schemaStr
|
|
285
|
-
}, "")
|
|
286
|
-
const isUI = !componentAll.rtType;
|
|
287
|
-
const slots = componentAll?.slots?.reduce?.((pre: string, { id, title, type, description, inputs }: any) => {
|
|
288
|
-
const isScope = type === "scope" && inputs?.length;
|
|
289
|
-
return pre + ` - ${id}(${title}${description ? ` - ${description}` : ""})${type === "scope" ? "- 作用域插槽" : ""}\n` +
|
|
290
|
-
(isScope ? inputs.reduce((pre: string, { id, title, desc }: any) => {
|
|
291
|
-
return pre + ` - ${id}(${title})${desc ? ` - ${desc}` : ""}\n`
|
|
292
|
-
}, ""): "")
|
|
293
|
-
}, "")
|
|
294
|
-
|
|
295
|
-
return this.api.getComponentDoc(fullNamespace)
|
|
296
|
-
.replace("</type>", '</type>' + (isUI ? `\n<slots>
|
|
297
|
-
${slots || "无\n"}</slots>\n\n` : ""))
|
|
298
|
-
.replace("</type>", '</type>' + (isUI ? `\n<inputs>
|
|
299
|
-
${inputs || "无\n"}</inputs>\n\n` : ""))
|
|
300
|
-
.replace('<component>', `<${abbreviationNs}文档>`).replace('</component>', `</${abbreviationNs}文档>`).replace(new RegExp(`${fullNamespace}`, 'g'), abbreviationNs)
|
|
301
|
-
}).join('')}
|
|
302
|
-
`
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/**
|
|
306
|
-
* 生成已打开文档列表
|
|
307
|
-
*/
|
|
308
|
-
private generateOpenedDocumentsList(): string {
|
|
309
|
-
if (this.openedDocuments.length === 0) {
|
|
310
|
-
return '暂无打开的文档';
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
return this.openedDocuments.map(doc =>
|
|
314
|
-
`- ${doc.title}[id=${doc.id}](${doc.type})\n 描述:${doc.desc}\n 内容:${doc.content}`
|
|
315
|
-
).join('\n\n');
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
export { WorkSpace, type WorkSpaceConfig, type WorkSpaceAPI };
|