@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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mybricks/plugin-ai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"main": "src/index.tsx",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -20,8 +20,13 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@ant-design/icons": "^6.1.0",
|
|
22
22
|
"@mybricks/rxai": "0.0.2",
|
|
23
|
+
"antd": "^4.24.16",
|
|
23
24
|
"classnames": "^2.5.1",
|
|
24
25
|
"jsonrepair": "^3.13.1",
|
|
25
|
-
"
|
|
26
|
+
"markdown-it": "^14.1.0",
|
|
27
|
+
"node-forge": "^1.3.2"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/markdown-it": "^14.1.2"
|
|
26
31
|
}
|
|
27
32
|
}
|
package/src/agents/app.ts
CHANGED
|
@@ -1,22 +1,52 @@
|
|
|
1
1
|
import { context } from './../context';
|
|
2
2
|
import { MYBRICKS_TOOLS } from "./../tools"
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
import { WorkSpace } from './workspace/workspace'
|
|
5
|
+
import { FocusOutlineInfoManager, FocusInfo } from './workspace/outline-focus'
|
|
6
|
+
import { getAgentConfigs } from './utils/config'
|
|
5
7
|
|
|
6
8
|
export const requestGeneratePageAgent = (pageId: string, pageTitle: string, params: any) => {
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
// 从 agents 配置中获取提示词配置,优先使用参数传入的,否则使用 context 中的
|
|
11
|
+
const agents = params.agents || context.agents;
|
|
12
|
+
const agentConfig = getAgentConfigs(agents, 'page');
|
|
13
|
+
|
|
14
|
+
const focusInfo: FocusInfo = {
|
|
15
|
+
pageId,
|
|
16
|
+
comId: undefined,
|
|
17
|
+
title: pageTitle,
|
|
18
|
+
type: 'page'
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const outlineInfoManager = new FocusOutlineInfoManager({
|
|
22
|
+
api: context.api,
|
|
23
|
+
focusInfo
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
const componentIdToTitleMap = outlineInfoManager.getComponentIdToTitleMap(pageId);
|
|
27
|
+
|
|
28
|
+
const workspace = new WorkSpace({ currentFocus: focusInfo } as any, {
|
|
29
|
+
getAllPageInfo() {
|
|
30
|
+
return []
|
|
31
|
+
},
|
|
32
|
+
getComponentDoc(namespace: string) {
|
|
33
|
+
return (context.api?.global?.api?.getComEditorPrompts ?? context.api?.uiCom?.api?.getComEditorPrompts)?.(namespace)
|
|
34
|
+
}
|
|
35
|
+
} as any, outlineInfoManager)
|
|
9
36
|
|
|
10
37
|
params?.onProgress?.('start')
|
|
11
38
|
|
|
12
39
|
context.rxai.requestAI({
|
|
13
40
|
...params,
|
|
41
|
+
extension: {
|
|
42
|
+
mentions: [focusInfo]
|
|
43
|
+
},
|
|
14
44
|
message: params?.message,
|
|
15
45
|
key: pageId,
|
|
16
46
|
emits: {
|
|
17
47
|
write: () => { },
|
|
18
48
|
complete: () => {
|
|
19
|
-
|
|
49
|
+
params?.onProgress?.("complete");
|
|
20
50
|
},
|
|
21
51
|
error: () => {
|
|
22
52
|
params?.onProgress?.("error");
|
|
@@ -25,35 +55,117 @@ export const requestGeneratePageAgent = (pageId: string, pageTitle: string, para
|
|
|
25
55
|
// params?.onProgress?.("complete");
|
|
26
56
|
},
|
|
27
57
|
},
|
|
28
|
-
planList: [
|
|
58
|
+
planList: [`${MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName} -mode generate`, MYBRICKS_TOOLS.GenerateUiContent.toolName, MYBRICKS_TOOLS.BuildProcess.toolName],
|
|
29
59
|
tools: [
|
|
30
|
-
MYBRICKS_TOOLS.
|
|
31
|
-
allowComponents: context.
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
60
|
+
MYBRICKS_TOOLS.AnalyzeRequirementAndComponents({
|
|
61
|
+
allowComponents: context.designer?.getAllComDefPrompts?.() || "",
|
|
62
|
+
...agentConfig?.getToolParams(MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName),
|
|
63
|
+
onComponentDocOpen: (namespace) => {
|
|
64
|
+
workspace.openComponentDoc(namespace)
|
|
65
|
+
},
|
|
66
|
+
appendPrompt: agentConfig?.attentions,
|
|
67
|
+
shouldUseExpert: true,
|
|
68
|
+
deviceType: context.deviceType,
|
|
39
69
|
}),
|
|
40
|
-
MYBRICKS_TOOLS.
|
|
41
|
-
|
|
70
|
+
MYBRICKS_TOOLS.GenerateUiContent({
|
|
71
|
+
getRootComponentDoc: () => context.api?.page?.api?.getPageContainerPrompts?.(pageId) as string,
|
|
42
72
|
getTargetId: () => pageId as string,
|
|
43
|
-
|
|
44
|
-
|
|
73
|
+
getRootIdByPageId(pageId: string) {
|
|
74
|
+
return outlineInfoManager.getPageMetaInfo(pageId)?.rootId
|
|
75
|
+
},
|
|
76
|
+
componentIdToTitleMap,
|
|
77
|
+
appendPrompt: agentConfig?.attentions,
|
|
78
|
+
...agentConfig?.getToolParams(MYBRICKS_TOOLS.GenerateUiContent.toolName),
|
|
45
79
|
onActions: (actions, status) => {
|
|
46
|
-
context.
|
|
47
|
-
|
|
48
|
-
if (status === 'complete') {
|
|
49
|
-
params?.onProgress?.("complete");
|
|
50
|
-
}
|
|
80
|
+
return context.designer?.updatePage?.(pageId, actions, status)
|
|
51
81
|
},
|
|
52
82
|
onClearPage: () => {
|
|
53
83
|
context.api?.page?.api?.clearPageContent?.(pageId)
|
|
54
84
|
}
|
|
55
85
|
}),
|
|
86
|
+
MYBRICKS_TOOLS.BuildProcess({
|
|
87
|
+
getPageId: () => focusInfo.pageId,
|
|
88
|
+
getPageOutlineInfo: () => {
|
|
89
|
+
workspace.openDocument(focusInfo.pageId!);
|
|
90
|
+
return context.api?.page?.api?.getOutlineInfo(focusInfo.pageId)
|
|
91
|
+
},
|
|
92
|
+
getComponentOutlineInfo: () => {
|
|
93
|
+
const { type, comId } = focusInfo
|
|
94
|
+
if (type === "uiCom") {
|
|
95
|
+
return {
|
|
96
|
+
type,
|
|
97
|
+
outlineInfo: context.api?.uiCom?.api?.getOutlineInfo(comId)
|
|
98
|
+
}
|
|
99
|
+
} else if (type === "logicCom") {
|
|
100
|
+
return {
|
|
101
|
+
type,
|
|
102
|
+
outlineInfo: context.api?.logicCom?.api?.getOutlineInfo(comId)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
getAllPageInfo() {
|
|
107
|
+
return context.api?.global?.api?.getAllPageInfo()
|
|
108
|
+
},
|
|
109
|
+
createDiagram: (...args: any) => {
|
|
110
|
+
// console.log("[createDiagram - args]", args)
|
|
111
|
+
return context.designer?.createDiagram?.(...args)
|
|
112
|
+
},
|
|
113
|
+
updateDiagram: (...args: any) => {
|
|
114
|
+
// console.log("[updateDiagram - args]", args)
|
|
115
|
+
return context.designer?.updateDiagram?.(...args)
|
|
116
|
+
},
|
|
117
|
+
getDiagramInfo: (...args: any) => {
|
|
118
|
+
if (!args[0]) {
|
|
119
|
+
if (focusInfo.diagramId) {
|
|
120
|
+
return {
|
|
121
|
+
id: focusInfo.diagramId
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return null
|
|
126
|
+
}
|
|
127
|
+
return context.designer?.getDiagramInfo?.(...args)
|
|
128
|
+
},
|
|
129
|
+
updatePage: (...args: any) => {
|
|
130
|
+
// console.log("[updatePage]", args)
|
|
131
|
+
return context.designer?.updatePage?.(focusInfo.pageId, ...args)
|
|
132
|
+
},
|
|
133
|
+
updateCom: (...args: any) => {
|
|
134
|
+
// console.log("[updateCom]", args)
|
|
135
|
+
return context.designer?.updateLogicCom?.(...args)
|
|
136
|
+
},
|
|
137
|
+
}),,
|
|
56
138
|
],
|
|
139
|
+
// presetMessages: () => [
|
|
140
|
+
// {
|
|
141
|
+
// role: 'user',
|
|
142
|
+
// content: workspace.getComponentsDocs()
|
|
143
|
+
// }
|
|
144
|
+
// ],
|
|
145
|
+
presetMessages: () => {
|
|
146
|
+
const projectStruct = `# 工作空间 \n 当前为空项目`;;
|
|
147
|
+
const componentsDocs = workspace.getComponentsDocs();
|
|
148
|
+
const hasComponentsDocs = workspace.hasComponentsDocs();
|
|
149
|
+
|
|
150
|
+
// 合并内容
|
|
151
|
+
let projectInfo = projectStruct;
|
|
152
|
+
if (hasComponentsDocs) {
|
|
153
|
+
projectInfo = `${projectStruct}\n\n${componentsDocs}`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return [
|
|
157
|
+
{
|
|
158
|
+
role: 'user',
|
|
159
|
+
content: `<当前项目信息>\n${projectInfo}\n</当前项目信息>`
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
role: 'assistant',
|
|
163
|
+
content: hasComponentsDocs
|
|
164
|
+
? '收到,谢谢你提供的项目信息和组件文档,我会根据这些信息完成任务~'
|
|
165
|
+
: '收到,谢谢你提供的项目信息,我会根据这些信息完成任务~'
|
|
166
|
+
},
|
|
167
|
+
]
|
|
168
|
+
}
|
|
57
169
|
// presetMessages: [
|
|
58
170
|
// {
|
|
59
171
|
// role: 'user',
|
|
@@ -71,7 +183,7 @@ export const requestGeneratePageAgent = (pageId: string, pageTitle: string, para
|
|
|
71
183
|
});
|
|
72
184
|
}
|
|
73
185
|
|
|
74
|
-
async function createCanvasByAICanvas(canvasId: string, aiCanvas: any) {
|
|
186
|
+
async function createCanvasByAICanvas(canvasId: string, aiCanvas: any, originParams: any[]) {
|
|
75
187
|
|
|
76
188
|
function sleep(ms: number) {
|
|
77
189
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
@@ -80,46 +192,46 @@ async function createCanvasByAICanvas(canvasId: string, aiCanvas: any) {
|
|
|
80
192
|
// TOOD,之前不去掉设计器会有报错
|
|
81
193
|
await sleep(1000)
|
|
82
194
|
|
|
83
|
-
const pageArray = [];
|
|
195
|
+
const pageArray: Array<{ page: any; pageRef: { id: string; onProgress: Function } }> = [];
|
|
84
196
|
|
|
85
197
|
for (let index = 0; index < aiCanvas.pages.length; index++) {
|
|
86
198
|
const page = aiCanvas.pages[index];
|
|
87
199
|
|
|
88
|
-
const pageRef = await context.
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
namespace: 'mybricks.harmony.systemPage',
|
|
93
|
-
deletable: false,
|
|
94
|
-
asRoot: true,
|
|
95
|
-
data: {
|
|
96
|
-
useTabBar: false,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
inputs: [
|
|
100
|
-
{
|
|
101
|
-
id: "open",
|
|
102
|
-
title: "打开",
|
|
103
|
-
schema: {
|
|
104
|
-
type: "object",
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
],
|
|
108
|
-
})
|
|
109
|
-
pageArray.push({ page, pageRef })
|
|
200
|
+
const pageRef = await context.designer?.createPage?.(canvasId, page.title, context.createTemplates?.page?.({ title: page.title }))
|
|
201
|
+
if (pageRef) {
|
|
202
|
+
pageArray.push({ page, pageRef })
|
|
203
|
+
}
|
|
110
204
|
}
|
|
111
205
|
|
|
112
|
-
pageArray.forEach(async ({ page, pageRef }) => {
|
|
206
|
+
pageArray.forEach(async ({ page, pageRef }, index) => {
|
|
207
|
+
const otherPage = pageArray.slice(0, index).concat(pageArray.slice(index + 1))
|
|
113
208
|
await requestGeneratePageAgent(pageRef.id, page.title, {
|
|
114
|
-
message:
|
|
115
|
-
|
|
209
|
+
message: `帮忙实现项目「${aiCanvas.title}」的其中一个页面,页面为${page.title}。
|
|
210
|
+
<可供参考的需求>
|
|
116
211
|
${page.prd}
|
|
117
|
-
|
|
212
|
+
</可供参考的需求>
|
|
118
213
|
|
|
119
214
|
<样式风格>
|
|
120
215
|
${aiCanvas.style}
|
|
121
216
|
</样式风格>
|
|
217
|
+
|
|
218
|
+
<正在实现的页面列表>
|
|
219
|
+
${(pageArray ?? []).map(p => `- ${p.page.title}`).join('\n')}
|
|
220
|
+
</正在实现的页面列表>
|
|
221
|
+
|
|
222
|
+
<事件流程>
|
|
223
|
+
当前项目有以下${otherPage.length}张页面可以跳转
|
|
224
|
+
${otherPage.reduce((pre: string, { page, pageRef }: any) => {
|
|
225
|
+
return pre + `- ${page.title}(${pageRef.id})\n`
|
|
226
|
+
}, "")}
|
|
227
|
+
|
|
228
|
+
基于页面的名称、事实,分析页面间的关联性、组件事件中可能的页面跳转流程,例如某个按钮的点击事件跳转一个正确的页面。
|
|
229
|
+
|
|
230
|
+
注意:
|
|
231
|
+
1. 除页面跳转外,禁止一切其它形式的事件流程和变量。
|
|
232
|
+
</事件流程>
|
|
122
233
|
`,
|
|
234
|
+
attachments: originParams?.attachments ?? [],
|
|
123
235
|
onProgress: pageRef.onProgress,
|
|
124
236
|
id: pageRef.id,
|
|
125
237
|
})
|
|
@@ -128,9 +240,22 @@ ${aiCanvas.style}
|
|
|
128
240
|
|
|
129
241
|
export const requestGenerateCanvasAgent = (params: any) => {
|
|
130
242
|
return new Promise((resolve, reject) => {
|
|
131
|
-
params?.onProgress?.('start')
|
|
243
|
+
params?.onProgress?.('start');
|
|
132
244
|
|
|
133
|
-
|
|
245
|
+
|
|
246
|
+
const createTargetContainer = async () => {
|
|
247
|
+
if (!context.isMutiCanvas) {
|
|
248
|
+
return { id: '_root_' };
|
|
249
|
+
}
|
|
250
|
+
return await context.designer?.createCanvas?.() || { id: '_root_' };
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const originParams = {
|
|
254
|
+
message: params?.message,
|
|
255
|
+
attachments: params?.attachments ?? [],
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
(params.rxai || context.rxai).requestAI({
|
|
134
259
|
...params,
|
|
135
260
|
message: params?.message,
|
|
136
261
|
key: params.id,
|
|
@@ -147,25 +272,28 @@ export const requestGenerateCanvasAgent = (params: any) => {
|
|
|
147
272
|
params?.onProgress?.("complete");
|
|
148
273
|
},
|
|
149
274
|
},
|
|
150
|
-
planList: [
|
|
275
|
+
planList: [MYBRICKS_TOOLS.AnalyzeAndExpandPrd.toolName],
|
|
151
276
|
tools: [
|
|
152
277
|
MYBRICKS_TOOLS.AnalyzeAndExpandPrd({
|
|
153
|
-
onProjectCreate: (projectJson) => {
|
|
278
|
+
onProjectCreate: async (projectJson) => {
|
|
154
279
|
if (!projectJson || !projectJson.title) {
|
|
155
|
-
return
|
|
280
|
+
return resolve("complete");
|
|
281
|
+
// return reject('不合法的项目文件')
|
|
156
282
|
}
|
|
157
283
|
let canvasId
|
|
158
284
|
try {
|
|
159
|
-
const
|
|
160
|
-
canvasId = id
|
|
285
|
+
const canvas = await createTargetContainer()
|
|
286
|
+
canvasId = canvas?.id
|
|
161
287
|
} catch (error) {
|
|
162
|
-
reject(error)
|
|
288
|
+
return reject(error)
|
|
163
289
|
}
|
|
164
290
|
resolve('complete')
|
|
165
291
|
if (canvasId) {
|
|
166
|
-
|
|
292
|
+
params?.onProgress?.('ing');
|
|
293
|
+
createCanvasByAICanvas(canvasId, projectJson, originParams);
|
|
167
294
|
}
|
|
168
|
-
}
|
|
295
|
+
},
|
|
296
|
+
deviceType: context.deviceType
|
|
169
297
|
})
|
|
170
298
|
],
|
|
171
299
|
});
|