@mybricks/plugin-ai 0.0.1 → 0.0.2
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/package.json +7 -2
- package/src/agents/app.ts +188 -60
- package/src/agents/common.ts +428 -68
- package/src/agents/custom.ts +14 -0
- package/src/agents/index.ts +31 -1
- package/src/agents/knowledges/README.md +614 -0
- package/src/agents/knowledges/SUMMARY.md +527 -0
- package/src/agents/knowledges/index.ts +8 -0
- package/src/agents/knowledges/knowledge-base.ts +565 -0
- package/src/agents/knowledges/knowledge-node.ts +266 -0
- package/src/agents/knowledges/types.ts +208 -0
- package/src/agents/utils/config.ts +427 -0
- package/src/agents/workspace/coding-manager.ts +31 -0
- package/src/agents/workspace/components-manager.ts +124 -0
- package/src/agents/workspace/outline-focus.ts +188 -0
- package/src/agents/workspace/outline-info.ts +520 -0
- package/src/agents/workspace/page-tree-generator.ts +83 -0
- package/src/agents/workspace/workspace.ts +319 -0
- package/src/agents/workspace-by-knowledges/MIGRATION.md +568 -0
- package/src/agents/workspace-by-knowledges/README.md +521 -0
- package/src/agents/workspace-by-knowledges/index.ts +11 -0
- package/src/agents/workspace-by-knowledges/providers/component-docs-provider.ts +92 -0
- package/src/agents/workspace-by-knowledges/providers/focus-info-provider.ts +131 -0
- package/src/agents/workspace-by-knowledges/providers/index.ts +8 -0
- package/src/agents/workspace-by-knowledges/providers/project-info-provider.ts +151 -0
- package/src/agents/workspace-by-knowledges/test.ts +240 -0
- package/src/agents/workspace-by-knowledges/types.ts +56 -0
- package/src/agents/workspace-by-knowledges/utils/components-manager.ts +145 -0
- package/src/agents/workspace-by-knowledges/utils/index.ts +8 -0
- package/src/agents/workspace-by-knowledges/utils/outline-focus.ts +178 -0
- package/src/agents/workspace-by-knowledges/utils/outline-info.ts +521 -0
- package/src/agents/workspace-by-knowledges/workspace.ts +166 -0
- package/src/api/cloud-components.ts +129 -0
- package/src/api-record-replay/README.md +187 -0
- package/src/api-record-replay/index.ts +11 -0
- package/src/api-record-replay/manager.ts +168 -0
- package/src/api-record-replay/recorder.ts +117 -0
- package/src/api-record-replay/replayer.ts +148 -0
- package/src/components/attachments/index.less +117 -0
- package/src/components/attachments/index.tsx +136 -0
- package/src/components/icons/index.tsx +21 -1
- package/src/components/index.less +34 -0
- package/src/components/mention/index.less +23 -0
- package/src/components/mention/index.tsx +19 -0
- package/src/components/messages/index.less +444 -237
- package/src/components/messages/index.tsx +371 -88
- package/src/components/sender/index.less +203 -0
- package/src/components/sender/index.tsx +298 -0
- package/src/components/types.ts +31 -0
- package/src/constants/index.ts +8 -0
- package/src/context/RequestStatusTracker.ts +50 -0
- package/src/context/index.ts +68 -6
- package/src/{types.d.ts → global.d.ts} +40 -5
- package/src/index.tsx +212 -32
- package/src/preset/agents.ts +380 -0
- package/src/preset/createTemplates.ts +25 -0
- package/src/preset/index.ts +12 -0
- package/src/preset/prompts.ts +235 -0
- package/src/preset/requestAsStream.ts +246 -0
- package/src/preset/user.ts +6 -0
- package/src/startView/components/header/header.less +17 -0
- package/src/startView/components/header/header.tsx +15 -0
- package/src/startView/components/index.ts +1 -0
- package/src/startView/index.less +22 -204
- package/src/startView/index.tsx +35 -203
- package/src/tools/analyze-and-expand-prd.ts +192 -86
- package/src/tools/analyze-requirement-and-components.ts +589 -0
- package/src/tools/answer.ts +59 -0
- package/src/tools/build-process.ts +1174 -0
- package/src/tools/coding-subagent-as-tool.ts +119 -0
- package/src/tools/generate-ui-content.ts +1083 -0
- package/src/tools/index.ts +22 -19
- package/src/tools/open-dsl.ts +69 -0
- package/src/tools/refactor-ui-content.ts +801 -0
- package/src/tools/utils.ts +880 -28
- package/src/types/index.ts +4 -0
- package/src/view/components/header/header.less +36 -2
- package/src/view/components/header/header.tsx +47 -2
- package/src/view/components/index.ts +0 -2
- package/src/view/index.tsx +158 -8
- package/src/tools/answer-user.ts +0 -35
- package/src/tools/focus-element.ts +0 -47
- package/src/tools/generate-page.ts +0 -750
- package/src/tools/get-component-info-by-ids.ts +0 -166
- package/src/tools/get-component-info.ts +0 -53
- package/src/tools/get-components-doc-and-prd.ts +0 -137
- package/src/tools/get-focus-mybricks-dsl.ts +0 -26
- package/src/tools/get-mybricks-dsl.ts +0 -73
- package/src/tools/modify-component.ts +0 -385
- package/src/view/components/messages/messages.less +0 -228
- package/src/view/components/messages/messages.tsx +0 -172
- package/src/view/components/sender/sender.less +0 -44
- package/src/view/components/sender/sender.tsx +0 -62
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 聚焦信息 Provider
|
|
3
|
+
* 提供当前聚焦组件的树结构和描述信息
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DirectoryProvider, IKnowledgeNode, KnowledgeNodeType } from '../../knowledges/types';
|
|
7
|
+
import { context } from '../../../context';
|
|
8
|
+
import { FocusOutlineInfoManager } from '../utils';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 聚焦信息
|
|
12
|
+
*/
|
|
13
|
+
interface FocusInfo {
|
|
14
|
+
pageId?: string;
|
|
15
|
+
comId?: string;
|
|
16
|
+
title?: string;
|
|
17
|
+
type?: 'page' | 'uiCom' | 'section' | 'logicCom';
|
|
18
|
+
focusArea?: {
|
|
19
|
+
selector: string;
|
|
20
|
+
title: string;
|
|
21
|
+
};
|
|
22
|
+
diagramId?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 获取聚焦信息
|
|
27
|
+
*/
|
|
28
|
+
function getFocusInfo(): FocusInfo {
|
|
29
|
+
return (context.currentFocus || {}) as FocusInfo;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 创建聚焦信息 Provider
|
|
34
|
+
* 将当前聚焦的页面和组件信息作为单个文件呈现
|
|
35
|
+
*/
|
|
36
|
+
export function createFocusInfoProvider(): DirectoryProvider {
|
|
37
|
+
const providerId = 'focus-info';
|
|
38
|
+
const providerName = '聚焦信息';
|
|
39
|
+
let outlineInfoManager: FocusOutlineInfoManager | null = null;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 初始化 outline info manager
|
|
43
|
+
*/
|
|
44
|
+
function initializeManager(): void {
|
|
45
|
+
if (outlineInfoManager) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const focusInfo = getFocusInfo();
|
|
50
|
+
if (focusInfo?.pageId) {
|
|
51
|
+
outlineInfoManager = new FocusOutlineInfoManager({
|
|
52
|
+
api: context.api,
|
|
53
|
+
focusInfo
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 获取聚焦描述
|
|
60
|
+
*/
|
|
61
|
+
function getFocusDescription(): string {
|
|
62
|
+
initializeManager();
|
|
63
|
+
|
|
64
|
+
if (!outlineInfoManager) {
|
|
65
|
+
return '当前没有聚焦到任何页面或组件。';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return outlineInfoManager.generateFocusDescription();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 获取聚焦层级结构
|
|
73
|
+
*/
|
|
74
|
+
function getFocusHierarchy(): string {
|
|
75
|
+
initializeManager();
|
|
76
|
+
|
|
77
|
+
if (!outlineInfoManager) {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return outlineInfoManager.generateFocusHierarchy();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return new DirectoryProvider({
|
|
85
|
+
id: providerId,
|
|
86
|
+
name: providerName,
|
|
87
|
+
description: '当前聚焦组件的树结构和描述',
|
|
88
|
+
weight: 90, // 高权重,排在项目信息之后
|
|
89
|
+
|
|
90
|
+
// 自定义根节点为文件而不是目录
|
|
91
|
+
customRootNode: {
|
|
92
|
+
id: providerId,
|
|
93
|
+
name: providerName,
|
|
94
|
+
type: KnowledgeNodeType.FILE,
|
|
95
|
+
extname: '.md',
|
|
96
|
+
description: '当前聚焦组件的树结构和描述',
|
|
97
|
+
metadata: { providerId }
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
// 因为根节点是文件,所以没有子节点
|
|
101
|
+
getChildren: async (parentId: string) => {
|
|
102
|
+
return [];
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
// 读取文件内容
|
|
106
|
+
readFile: async (fileId: string) => {
|
|
107
|
+
if (fileId !== providerId) {
|
|
108
|
+
throw new Error(`Invalid file ID: ${fileId}`);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const focusInfo = getFocusInfo();
|
|
112
|
+
|
|
113
|
+
// 如果没有聚焦信息
|
|
114
|
+
if (!focusInfo.pageId && !focusInfo.comId) {
|
|
115
|
+
return '当前未聚焦任何页面或组件';
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// 获取聚焦的层级结构和描述
|
|
119
|
+
const contentHierarchy = getFocusHierarchy();
|
|
120
|
+
const focusDescription = getFocusDescription();
|
|
121
|
+
|
|
122
|
+
return `## 聚焦信息
|
|
123
|
+
以下是当前聚焦组件的简略树结构,展示了聚焦元素的父级、兄弟、子级元素的关系。
|
|
124
|
+
注意:此树结构并不完整,折叠了无关元素信息,如需详细信息请打开DSL文档获取。
|
|
125
|
+
|
|
126
|
+
${contentHierarchy}
|
|
127
|
+
|
|
128
|
+
${focusDescription}`;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace Providers
|
|
3
|
+
* 导出所有 provider 创建函数
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export { createProjectInfoProvider } from './project-info-provider';
|
|
7
|
+
export { createFocusInfoProvider } from './focus-info-provider';
|
|
8
|
+
export { createComponentDocsProvider } from './component-docs-provider';
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 项目信息 Provider
|
|
3
|
+
* 提供项目的画布索引信息
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { DirectoryProvider, IKnowledgeNode, KnowledgeNodeType } from '../../knowledges/types';
|
|
7
|
+
import { context } from '../../../context';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 页面信息
|
|
11
|
+
*/
|
|
12
|
+
interface PageInfo {
|
|
13
|
+
id: string;
|
|
14
|
+
title: string;
|
|
15
|
+
type: string;
|
|
16
|
+
componentType?: string;
|
|
17
|
+
children?: PageInfo[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 画布数据
|
|
22
|
+
*/
|
|
23
|
+
interface PagesData {
|
|
24
|
+
pageAry: PageInfo[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 获取所有页面信息
|
|
29
|
+
*/
|
|
30
|
+
function getAllPages(): PagesData | PagesData[] {
|
|
31
|
+
const result = context.api?.global?.api?.getAllPageInfo?.();
|
|
32
|
+
return result || [];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* 获取当前聚焦的页面ID
|
|
37
|
+
*/
|
|
38
|
+
function getFocusedPageId(): string | undefined {
|
|
39
|
+
return context.currentFocus?.pageId;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* 处理原始数据
|
|
44
|
+
*/
|
|
45
|
+
function processRawData(rawData: PagesData | PagesData[]): PageInfo[] {
|
|
46
|
+
// 如果 rawData 是数组
|
|
47
|
+
if (Array.isArray(rawData)) {
|
|
48
|
+
const allPages: PageInfo[] = [];
|
|
49
|
+
rawData.forEach((canvas: any) => {
|
|
50
|
+
if (canvas.pageAry && Array.isArray(canvas.pageAry)) { // 多画布
|
|
51
|
+
allPages.push(...canvas.pageAry.map((page: any) => ({
|
|
52
|
+
id: page.id,
|
|
53
|
+
title: page.title,
|
|
54
|
+
type: page.type,
|
|
55
|
+
componentType: page.componentType || undefined,
|
|
56
|
+
children: page.children || []
|
|
57
|
+
})));
|
|
58
|
+
} else if (canvas.id) {
|
|
59
|
+
allPages.push({ ...canvas })
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return allPages;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// 如果不是数组
|
|
66
|
+
if (!rawData?.pageAry) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return rawData.pageAry.map((page: PageInfo) => ({
|
|
71
|
+
id: page.id,
|
|
72
|
+
title: page.title,
|
|
73
|
+
type: page.type,
|
|
74
|
+
componentType: page.componentType || undefined,
|
|
75
|
+
children: page.children || []
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* 生成树形文本
|
|
81
|
+
*/
|
|
82
|
+
function generateTreeText(pages: PageInfo[], focusedPageId?: string, level = 0): string {
|
|
83
|
+
let result = '';
|
|
84
|
+
const indent = ' '.repeat(level);
|
|
85
|
+
|
|
86
|
+
pages.forEach(page => {
|
|
87
|
+
let line = `${indent}- ${page.title}[id=${page.id}]`;
|
|
88
|
+
|
|
89
|
+
if (page.componentType) {
|
|
90
|
+
line += `(${page.componentType})`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (focusedPageId && page.id === focusedPageId) {
|
|
94
|
+
line += ' 【当前聚焦】';
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
result += line + '\n';
|
|
98
|
+
|
|
99
|
+
if (page.children && page.children.length > 0) {
|
|
100
|
+
result += generateTreeText(page.children, focusedPageId, level + 1);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* 创建项目信息 Provider
|
|
109
|
+
* 作为单个文件呈现,包含画布索引
|
|
110
|
+
*/
|
|
111
|
+
export function createProjectInfoProvider(): DirectoryProvider {
|
|
112
|
+
const providerId = 'project-info';
|
|
113
|
+
const providerName = '项目信息';
|
|
114
|
+
|
|
115
|
+
return new DirectoryProvider({
|
|
116
|
+
id: providerId,
|
|
117
|
+
name: providerName,
|
|
118
|
+
description: '包含项目的画布索引',
|
|
119
|
+
weight: 100, // 高权重,排在最前面
|
|
120
|
+
|
|
121
|
+
// 自定义根节点为文件而不是目录
|
|
122
|
+
customRootNode: {
|
|
123
|
+
id: providerId,
|
|
124
|
+
name: providerName,
|
|
125
|
+
type: KnowledgeNodeType.FILE,
|
|
126
|
+
extname: '.md',
|
|
127
|
+
description: '包含项目的画布索引',
|
|
128
|
+
metadata: { providerId }
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
// 因为根节点是文件,所以没有子节点
|
|
132
|
+
getChildren: async (parentId: string) => {
|
|
133
|
+
return [];
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
// 读取文件内容
|
|
137
|
+
readFile: async (fileId: string) => {
|
|
138
|
+
if (fileId !== providerId) {
|
|
139
|
+
throw new Error(`Invalid file ID: ${fileId}`);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const pagesInfo = getAllPages();
|
|
143
|
+
const focusedPageId = getFocusedPageId();
|
|
144
|
+
const processedPages = processRawData(pagesInfo);
|
|
145
|
+
const pageTree = generateTreeText(processedPages, focusedPageId);
|
|
146
|
+
|
|
147
|
+
return `## 画布索引
|
|
148
|
+
${pageTree}`;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace 测试文件
|
|
3
|
+
* 使用真实的 context API,测试函数注入到 window 供浏览器控制台使用
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { Workspace } from './workspace';
|
|
7
|
+
import { context } from '../../context';
|
|
8
|
+
|
|
9
|
+
// 测试函数
|
|
10
|
+
async function runWorkspaceTests() {
|
|
11
|
+
console.log('='.repeat(60));
|
|
12
|
+
console.log('开始测试 Workspace');
|
|
13
|
+
console.log('='.repeat(60));
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// 检查 context 是否有必要的 API
|
|
17
|
+
if (!context.api) {
|
|
18
|
+
throw new Error('context.api 未初始化,请确保在设计器环境中运行此测试');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// 1. 创建 Workspace
|
|
22
|
+
console.log('\n[测试 1] 创建 Workspace');
|
|
23
|
+
const workspace = new Workspace({
|
|
24
|
+
name: '测试工作空间',
|
|
25
|
+
description: '这是一个测试工作空间'
|
|
26
|
+
});
|
|
27
|
+
console.log('[SUCCESS] Workspace 创建成功');
|
|
28
|
+
|
|
29
|
+
// 2. 获取目录树
|
|
30
|
+
console.log('\n[测试 2] 获取目录树');
|
|
31
|
+
const tree = await workspace.getDirectoryTree({ showDescription: true });
|
|
32
|
+
console.log('目录树:\n', tree);
|
|
33
|
+
|
|
34
|
+
// 3. 检查默认打开的文件
|
|
35
|
+
console.log('\n[测试 3] 检查默认打开的文件');
|
|
36
|
+
const defaultFiles = workspace.getOpenedFilePaths();
|
|
37
|
+
console.log('默认打开的文件:', defaultFiles);
|
|
38
|
+
if (defaultFiles.includes('项目信息.md') && defaultFiles.includes('聚焦信息.md')) {
|
|
39
|
+
console.log('[SUCCESS] 项目信息和聚焦信息已默认打开');
|
|
40
|
+
} else {
|
|
41
|
+
console.log('[WARN] 默认文件未完全打开');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 4. 测试打开组件文档(如果有组件的话)
|
|
45
|
+
console.log('\n[测试 4] 测试打开组件文档');
|
|
46
|
+
try {
|
|
47
|
+
// 尝试打开一个常见的组件文档
|
|
48
|
+
await workspace.openComponentDoc('组件配置文档/mybricks.normal-pc.antd5.icon.md');
|
|
49
|
+
console.log('[SUCCESS] 组件文档已打开');
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.log('[INFO] 无法打开组件文档(可能组件不存在):', (error as Error).message);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 5. 测试动态文档功能
|
|
55
|
+
console.log('\n[测试 5] 测试动态文档功能');
|
|
56
|
+
|
|
57
|
+
// 注册一个自定义动态文档目录
|
|
58
|
+
workspace.registerDynamicDirectory({
|
|
59
|
+
id: 'custom-docs',
|
|
60
|
+
name: '自定义文档',
|
|
61
|
+
description: '用户自定义的文档',
|
|
62
|
+
weight: 50,
|
|
63
|
+
hidden: false // 不隐藏,在目录树中显示
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// 添加动态文档到自定义目录
|
|
67
|
+
await workspace.openDocument('doc1', {
|
|
68
|
+
type: '组件',
|
|
69
|
+
content: '这是第一个动态文档的内容\n包含一些测试数据',
|
|
70
|
+
title: '动态文档1',
|
|
71
|
+
description: '这是一个测试用的动态文档',
|
|
72
|
+
directoryId: 'custom-docs'
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// 添加另一个动态文档到默认目录
|
|
76
|
+
await workspace.openDocument('doc2', {
|
|
77
|
+
type: '画布',
|
|
78
|
+
content: '这是第二个动态文档的内容',
|
|
79
|
+
title: '动态文档2',
|
|
80
|
+
description: '使用默认动态文档目录'
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
console.log('[SUCCESS] 动态文档已添加');
|
|
84
|
+
|
|
85
|
+
// 6. 获取已打开的文件列表
|
|
86
|
+
console.log('\n[测试 6] 获取已打开的文件列表');
|
|
87
|
+
const openedFiles = workspace.getOpenedFilePaths();
|
|
88
|
+
console.log('已打开的文件:', openedFiles);
|
|
89
|
+
|
|
90
|
+
// 7. 再次获取目录树(应该包含自定义文档目录)
|
|
91
|
+
console.log('\n[测试 7] 获取包含动态文档目录的目录树');
|
|
92
|
+
const treeWithDynamic = await workspace.getDirectoryTree({ showDescription: true });
|
|
93
|
+
console.log('目录树(包含动态文档):\n', treeWithDynamic);
|
|
94
|
+
|
|
95
|
+
// 8. 导出工作空间内容
|
|
96
|
+
console.log('\n[测试 8] 导出工作空间内容');
|
|
97
|
+
const exportedContent = await workspace.export({ includeTree: true });
|
|
98
|
+
console.log('导出的内容长度:', exportedContent.length);
|
|
99
|
+
console.log('导出的内容(前500字符):\n', exportedContent.substring(0, 500));
|
|
100
|
+
|
|
101
|
+
console.log('\n' + '='.repeat(60));
|
|
102
|
+
console.log('[SUCCESS] 所有测试通过!');
|
|
103
|
+
console.log('='.repeat(60));
|
|
104
|
+
|
|
105
|
+
return workspace;
|
|
106
|
+
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error('\n[ERROR] 测试失败:', error);
|
|
109
|
+
console.error('错误堆栈:', (error as Error).stack);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// 快捷测试函数
|
|
115
|
+
async function quickTest() {
|
|
116
|
+
const workspace = new Workspace({
|
|
117
|
+
name: '快速测试工作空间'
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
console.log('[INIT] 快速测试工作空间已创建');
|
|
121
|
+
console.log('使用方法:');
|
|
122
|
+
console.log(' - workspace.getDirectoryTree() - 获取目录树');
|
|
123
|
+
console.log(' - workspace.openComponentDoc(path) - 打开组件文档');
|
|
124
|
+
console.log(' - workspace.openComponentDocByNamespace(namespace) - 根据 namespace 打开组件文档');
|
|
125
|
+
console.log(' - workspace.openDocument(id, options) - 打开动态文档');
|
|
126
|
+
console.log(' - workspace.registerDynamicDirectory(config) - 注册动态文档目录');
|
|
127
|
+
console.log(' - workspace.export() - 导出工作空间内容');
|
|
128
|
+
console.log(' - workspace.refresh() - 刷新工作空间');
|
|
129
|
+
|
|
130
|
+
try {
|
|
131
|
+
// 先看看目录树
|
|
132
|
+
console.log('\n[步骤1] 获取目录树');
|
|
133
|
+
const tree = await workspace.getDirectoryTree({ showDescription: true });
|
|
134
|
+
console.log(tree);
|
|
135
|
+
|
|
136
|
+
console.log('\n[步骤2] 检查默认打开的文件');
|
|
137
|
+
const openedFiles = workspace.getOpenedFilePaths();
|
|
138
|
+
console.log('已打开的文件列表:', openedFiles);
|
|
139
|
+
console.log('项目信息和聚焦信息应该已默认打开');
|
|
140
|
+
|
|
141
|
+
console.log('\n[步骤3] 开始导出...');
|
|
142
|
+
const result = await workspace.export();
|
|
143
|
+
console.log('导出完成!');
|
|
144
|
+
console.log('导出内容长度:', result.length);
|
|
145
|
+
console.log('\n导出内容(前500字符):\n', result.substring(0, 500));
|
|
146
|
+
return workspace;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
console.error('[ERROR] 测试失败:', error);
|
|
149
|
+
console.error('错误堆栈:', (error as Error).stack);
|
|
150
|
+
throw error;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 动态文档功能演示
|
|
155
|
+
async function testDynamicDocs() {
|
|
156
|
+
console.log('='.repeat(60));
|
|
157
|
+
console.log('测试动态文档功能');
|
|
158
|
+
console.log('='.repeat(60));
|
|
159
|
+
|
|
160
|
+
const workspace = new Workspace({
|
|
161
|
+
name: '动态文档测试工作空间'
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// 1. 注册多个动态文档目录
|
|
165
|
+
console.log('\n[步骤1] 注册多个动态文档目录');
|
|
166
|
+
|
|
167
|
+
workspace.registerDynamicDirectory({
|
|
168
|
+
id: 'opened-pages',
|
|
169
|
+
name: '已打开的页面',
|
|
170
|
+
description: '用户打开的页面文档',
|
|
171
|
+
weight: 80,
|
|
172
|
+
hidden: false
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
workspace.registerDynamicDirectory({
|
|
176
|
+
id: 'opened-components',
|
|
177
|
+
name: '已打开的组件',
|
|
178
|
+
description: '用户打开的组件文档',
|
|
179
|
+
weight: 70,
|
|
180
|
+
hidden: false
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
console.log('[SUCCESS] 已注册 2 个动态文档目录');
|
|
184
|
+
|
|
185
|
+
// 2. 添加文档到不同的目录
|
|
186
|
+
console.log('\n[步骤2] 添加文档到不同的目录');
|
|
187
|
+
|
|
188
|
+
await workspace.openDocument('page_u_abc123', {
|
|
189
|
+
type: '画布',
|
|
190
|
+
content: '<页面1[id=u_abc123]>\n <容器[id=u_def456]>\n <按钮[id=u_ghi789]>',
|
|
191
|
+
title: '页面1',
|
|
192
|
+
description: '这是第一个页面',
|
|
193
|
+
directoryId: 'opened-pages'
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
await workspace.openDocument('component_u_xyz999', {
|
|
197
|
+
type: '组件',
|
|
198
|
+
content: '<按钮组件[id=u_xyz999]>\n 属性: { text: "点击我" }',
|
|
199
|
+
title: '按钮组件',
|
|
200
|
+
description: '一个普通按钮',
|
|
201
|
+
directoryId: 'opened-components'
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
console.log('[SUCCESS] 已添加文档到不同目录');
|
|
205
|
+
|
|
206
|
+
// 3. 查看目录树
|
|
207
|
+
console.log('\n[步骤3] 查看目录树');
|
|
208
|
+
const tree = await workspace.getDirectoryTree({ showDescription: true });
|
|
209
|
+
console.log(tree);
|
|
210
|
+
|
|
211
|
+
// 4. 导出内容
|
|
212
|
+
console.log('\n[步骤4] 导出内容');
|
|
213
|
+
const exported = await workspace.export({ includeTree: true });
|
|
214
|
+
console.log('导出内容长度:', exported.length);
|
|
215
|
+
console.log('\n完整导出内容:\n', exported);
|
|
216
|
+
|
|
217
|
+
console.log('\n' + '='.repeat(60));
|
|
218
|
+
console.log('[SUCCESS] 动态文档功能测试完成!');
|
|
219
|
+
console.log('='.repeat(60));
|
|
220
|
+
|
|
221
|
+
return workspace;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// 注入到 window 对象供浏览器控制台使用
|
|
225
|
+
if (typeof window !== 'undefined') {
|
|
226
|
+
(window as any).workspaceTest = {
|
|
227
|
+
runTests: runWorkspaceTests,
|
|
228
|
+
quickTest,
|
|
229
|
+
testDynamicDocs,
|
|
230
|
+
Workspace,
|
|
231
|
+
context
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
console.log('[READY] 测试函数已注入到 window.workspaceTest');
|
|
235
|
+
console.log('使用方法:');
|
|
236
|
+
console.log(' - window.workspaceTest.runTests() - 运行完整测试');
|
|
237
|
+
console.log(' - window.workspaceTest.quickTest() - 快速创建测试实例');
|
|
238
|
+
console.log(' - window.workspaceTest.testDynamicDocs() - 测试动态文档功能');
|
|
239
|
+
console.log(' - window.workspaceTest.context - 查看 context 对象');
|
|
240
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workspace 类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { KnowledgeBaseConfig } from '../knowledges/types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 页面信息
|
|
9
|
+
*/
|
|
10
|
+
export interface PageInfo {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
type: string;
|
|
14
|
+
componentType?: string;
|
|
15
|
+
children?: PageInfo[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 画布数据
|
|
20
|
+
*/
|
|
21
|
+
export interface PagesData {
|
|
22
|
+
pageAry: PageInfo[];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 聚焦信息
|
|
27
|
+
*/
|
|
28
|
+
export interface FocusInfo {
|
|
29
|
+
pageId?: string;
|
|
30
|
+
comId?: string;
|
|
31
|
+
title?: string;
|
|
32
|
+
type?: 'page' | 'uiCom' | 'section' | 'logicCom';
|
|
33
|
+
focusArea?: {
|
|
34
|
+
selector: string;
|
|
35
|
+
title: string;
|
|
36
|
+
};
|
|
37
|
+
diagramId?: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 组件信息
|
|
42
|
+
*/
|
|
43
|
+
export interface ComponentInfo {
|
|
44
|
+
namespace: string;
|
|
45
|
+
name: string;
|
|
46
|
+
abbreviation: string;
|
|
47
|
+
description?: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Workspace 配置(简化版,从 context 获取所有依赖)
|
|
52
|
+
*/
|
|
53
|
+
export interface WorkspaceConfig extends KnowledgeBaseConfig {
|
|
54
|
+
// 所有依赖从 context 获取,无需传入
|
|
55
|
+
}
|
|
56
|
+
|