@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
package/src/agents/common.ts
DELETED
|
@@ -1,471 +0,0 @@
|
|
|
1
|
-
import { context } from './../context';
|
|
2
|
-
import { MYBRICKS_TOOLS } from "./../tools"
|
|
3
|
-
|
|
4
|
-
import { WorkSpace } from './workspace/workspace'
|
|
5
|
-
import { FocusOutlineInfoManager, FocusInfo } from './workspace/outline-focus'
|
|
6
|
-
|
|
7
|
-
import { ComponentsManager } from './workspace/components-manager'
|
|
8
|
-
import { getAgentConfigs } from './utils/config'
|
|
9
|
-
|
|
10
|
-
import { CodingManager } from './workspace/coding-manager'
|
|
11
|
-
|
|
12
|
-
const getFocusInfo = (focus: any) => {
|
|
13
|
-
const focusInfo: FocusInfo = {
|
|
14
|
-
pageId: focus?.pageId,
|
|
15
|
-
comId: focus?.comId,
|
|
16
|
-
title: focus?.title,
|
|
17
|
-
type: focus?.type,
|
|
18
|
-
focusArea: focus?.focusArea
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
if (focus.type === "logicCom") {
|
|
22
|
-
focusInfo.pageId = focus.rootFrameId;
|
|
23
|
-
focusInfo.diagramId = focus.diagramId;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return focusInfo;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const getTargetId = (focus: FocusInfo) => {
|
|
30
|
-
if (['uiCom', 'logicCom'].includes(focus.type!)) {
|
|
31
|
-
return focus.comId
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return focus.pageId;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export const requestCommonAgent = (params: any) => {
|
|
38
|
-
|
|
39
|
-
return new Promise((resolve, reject) => {
|
|
40
|
-
// 从 agents 配置中获取提示词配置,优先使用参数传入的,否则使用 context 中的
|
|
41
|
-
const agents = params.agents || context.agents;
|
|
42
|
-
const agentConfig = getAgentConfigs(agents, 'page');
|
|
43
|
-
|
|
44
|
-
const currentFocus = params.focus || context.currentFocus;
|
|
45
|
-
const focusInfo = getFocusInfo(currentFocus);
|
|
46
|
-
|
|
47
|
-
const targetType = focusInfo.type;
|
|
48
|
-
const targetId = getTargetId(focusInfo);
|
|
49
|
-
const targetPageId = focusInfo.pageId;
|
|
50
|
-
|
|
51
|
-
if (!targetPageId) {
|
|
52
|
-
return reject('缺少聚焦页面id')
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const outlineInfoManager = new FocusOutlineInfoManager({
|
|
56
|
-
api: context.api,
|
|
57
|
-
focusInfo
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const componentIdToTitleMap = targetPageId
|
|
61
|
-
? outlineInfoManager.getComponentIdToTitleMap(targetPageId)
|
|
62
|
-
: new Map<string, string>();
|
|
63
|
-
|
|
64
|
-
const workspace = new WorkSpace({ currentFocus: focusInfo } as any, {
|
|
65
|
-
getAllPageInfo() {
|
|
66
|
-
return (context.api.global.api as any).getAllPageInfo()
|
|
67
|
-
},
|
|
68
|
-
getComponentDoc(namespace: string) {
|
|
69
|
-
return (context.api?.global?.api?.getComEditorPrompts ?? context.api?.uiCom?.api?.getComEditorPrompts)?.(namespace)
|
|
70
|
-
}
|
|
71
|
-
} as any, outlineInfoManager)
|
|
72
|
-
|
|
73
|
-
const codingManager = new CodingManager({
|
|
74
|
-
pageId: targetPageId,
|
|
75
|
-
attachments: params.attachments,
|
|
76
|
-
getJsxById: (id: string) => workspace.getJsxById(id),
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
let onProgress = params.onProgress;
|
|
80
|
-
|
|
81
|
-
const historyFocusDesc = generateHistoryFocusDescription(focusInfo);
|
|
82
|
-
const focusEleDesc = generateFocusTargetDescription(focusInfo);
|
|
83
|
-
if (targetType === "uiCom") {
|
|
84
|
-
onProgress = context.api.uiCom.api.getComOnProcess(targetId)?.onProgress
|
|
85
|
-
} else if (targetType === "page") {
|
|
86
|
-
onProgress = context.api.page.api.getPageOnProcess(targetId)?.onProgress
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
onProgress?.('start')
|
|
90
|
-
|
|
91
|
-
const hasAttachment = typeof params?.message !== 'string';
|
|
92
|
-
|
|
93
|
-
// workspace.openDocument('u_qLciw]')
|
|
94
|
-
|
|
95
|
-
// workspace.openDocument('u_ADKKC')
|
|
96
|
-
|
|
97
|
-
// workspace.openDocument('u_ZJ_bn')
|
|
98
|
-
|
|
99
|
-
// workspace.openDocument('u_ADKKC')
|
|
100
|
-
// workspace.openDocument('u_XZL9q')
|
|
101
|
-
|
|
102
|
-
// workspace.openDocument('u_k_1dW')
|
|
103
|
-
// workspace.openDocument('u_ADKKC')
|
|
104
|
-
|
|
105
|
-
// // 页面
|
|
106
|
-
// workspace.openDocument('u_yjFHf')
|
|
107
|
-
// workspace.openDocument('u_tycgh')
|
|
108
|
-
|
|
109
|
-
// // 页面 + 组件
|
|
110
|
-
// workspace.openDocument('u_yjFHf')
|
|
111
|
-
// workspace.openDocument('u_ADKKC')
|
|
112
|
-
|
|
113
|
-
// return console.log(workspace.getProjectStruct())
|
|
114
|
-
|
|
115
|
-
// try {
|
|
116
|
-
// workspace.openDocument(targetPageId)
|
|
117
|
-
|
|
118
|
-
// return console.log(workspace.getProjectStruct())
|
|
119
|
-
|
|
120
|
-
// workspace.openComponentDoc('mybricks.normal-pc.antd5.form-container')
|
|
121
|
-
// return console.log(workspace.getComponentsDocs());
|
|
122
|
-
// } catch (error) {
|
|
123
|
-
// console.error(error)
|
|
124
|
-
// }
|
|
125
|
-
// return
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
context.rxai.requestAI({
|
|
129
|
-
...params,
|
|
130
|
-
message: params?.message,
|
|
131
|
-
blockId: targetId,
|
|
132
|
-
// enableLog: true,
|
|
133
|
-
emits: {
|
|
134
|
-
write: () => { },
|
|
135
|
-
complete: () => {
|
|
136
|
-
resolve('complete')
|
|
137
|
-
onProgress?.("complete");
|
|
138
|
-
console.log('common complete')
|
|
139
|
-
},
|
|
140
|
-
error: () => {
|
|
141
|
-
reject('error')
|
|
142
|
-
onProgress?.("error");
|
|
143
|
-
console.log('common error')
|
|
144
|
-
},
|
|
145
|
-
cancel: () => {},
|
|
146
|
-
},
|
|
147
|
-
tools: [
|
|
148
|
-
MYBRICKS_TOOLS.OpenDsl({
|
|
149
|
-
onOpen(id) {
|
|
150
|
-
workspace.openDocument(id)
|
|
151
|
-
},
|
|
152
|
-
}),
|
|
153
|
-
MYBRICKS_TOOLS.AnalyzeRequirementAndComponents({
|
|
154
|
-
allowComponents: context.designer?.getAllComDefPrompts?.() || "",
|
|
155
|
-
...agentConfig?.getToolParams(MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName),
|
|
156
|
-
onComponentDocOpen: (namespace) => {
|
|
157
|
-
workspace.openComponentDoc(namespace)
|
|
158
|
-
},
|
|
159
|
-
appendPrompt: agentConfig?.attentions,
|
|
160
|
-
deviceType: context.deviceType,
|
|
161
|
-
}),
|
|
162
|
-
MYBRICKS_TOOLS.GenerateUiContent({
|
|
163
|
-
getRootComponentDoc: () => context.api?.page?.api?.getPageContainerPrompts?.(targetPageId) as string,
|
|
164
|
-
getTargetId: () => targetPageId as string,
|
|
165
|
-
getRootIdByPageId(pageId: string) {
|
|
166
|
-
return outlineInfoManager.getPageMetaInfo(pageId)?.rootId
|
|
167
|
-
},
|
|
168
|
-
componentIdToTitleMap,
|
|
169
|
-
appendPrompt: agentConfig?.attentions,
|
|
170
|
-
...agentConfig?.getToolParams(MYBRICKS_TOOLS.GenerateUiContent.toolName),
|
|
171
|
-
onActions: (actions, status) => {
|
|
172
|
-
return context.designer?.updatePage?.(targetPageId, actions, status)
|
|
173
|
-
},
|
|
174
|
-
onClearPage: () => {
|
|
175
|
-
context.api?.page?.api?.clearPageContent?.(targetPageId)
|
|
176
|
-
},
|
|
177
|
-
onAddCodingBlock(com) {
|
|
178
|
-
codingManager.addCodingCom(com);
|
|
179
|
-
},
|
|
180
|
-
}),
|
|
181
|
-
// MYBRICKS_TOOLS.GenerateUiContent({
|
|
182
|
-
// getRootComponentDoc: () => context.api?.page?.api?.getPageContainerPrompts?.(targetPageId) as string,
|
|
183
|
-
// getTargetId: () => targetPageId as string,
|
|
184
|
-
// getRootIdByPageId(pageId: string) {
|
|
185
|
-
// return outlineInfoManager.getPageMetaInfo(pageId)?.rootId
|
|
186
|
-
// },
|
|
187
|
-
// componentIdToTitleMap,
|
|
188
|
-
// appendPrompt: `<对于当前搭建有以下特殊上下文>
|
|
189
|
-
// <搭建画布信息>
|
|
190
|
-
// 当前正在搭建各类智能穿戴设备的表盘,画布的宽度和高度我们限制为466*466,所有内容必须使用*绝对定位*布局绘制到画布上。
|
|
191
|
-
|
|
192
|
-
// 注意:根组件的布局必须设置position=absolute(绝对定位)和具体的宽高。
|
|
193
|
-
// </搭建画布信息>
|
|
194
|
-
// </对于当前搭建有以下特殊上下文>`,
|
|
195
|
-
// examples: `<example>
|
|
196
|
-
// <user_query>搭建一个科技风表盘</user_query>
|
|
197
|
-
// <assistant_response>
|
|
198
|
-
// 好的,我们来实现一个科技风的表盘,搭建过程如下:
|
|
199
|
-
// 1. 首先,必须配置合理的表盘宽度和高度、标题、布局以及样式;
|
|
200
|
-
// 2. 其次搭建各类元素,将各类表盘元素放置到合适的位置;
|
|
201
|
-
|
|
202
|
-
// ${fileFormat({
|
|
203
|
-
// content: `["_root_",":root","setLayout",{"height": 466, "width": "466"}]
|
|
204
|
-
// ["_root_",":root","doConfig",{"path":"root/标题","value":"科技风表盘"}]
|
|
205
|
-
// ["_root_",":root","doConfig",{"path":"root/布局","value":{"position": "absolute"}}]
|
|
206
|
-
// ["_root_",":root","doConfig",{"path":"root/样式","value":{"background":"linear-gradient(135deg, #0c0c0c 0%, #1a1a2e 50%, #16213e 100%)"}}]
|
|
207
|
-
// ["_root_","_rootSlot_","addChild",{"title":"电池图标显示","ns":"somelib.battery","comId":"u_digital_time","layout":{"position":"absolute","top":10,"left":300},"configs":[]}]
|
|
208
|
-
// `,
|
|
209
|
-
// fileName: '生成科技风表盘操作步骤.json'
|
|
210
|
-
// })}
|
|
211
|
-
|
|
212
|
-
// 注意:
|
|
213
|
-
// - 表盘所有元素必须由自由布局绘制而成
|
|
214
|
-
// </assistant_response>
|
|
215
|
-
// </example>`,
|
|
216
|
-
// onActions: (actions, status) => {
|
|
217
|
-
// context.api?.page?.api?.updatePage?.(targetPageId, actions, status)
|
|
218
|
-
// },
|
|
219
|
-
// onClearPage: () => {
|
|
220
|
-
// context.api?.page?.api?.clearPageContent?.(targetPageId)
|
|
221
|
-
// }
|
|
222
|
-
// }),
|
|
223
|
-
MYBRICKS_TOOLS.RefactorUiContent({
|
|
224
|
-
onActions: (actions, status, type) => {
|
|
225
|
-
if (!status) {
|
|
226
|
-
return
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
// 只有聚焦到组件上,且第一个操作ID是组件ID,且父组件不为页面ID,才会触发组件级更新
|
|
230
|
-
if (targetType === 'uiCom' && targetId && type === 'uiCom') {
|
|
231
|
-
const parentId = workspace.focusPageOutlineInfo
|
|
232
|
-
? outlineInfoManager.findParentNodeByComId(
|
|
233
|
-
workspace.focusPageOutlineInfo,
|
|
234
|
-
targetId as string
|
|
235
|
-
)?.id
|
|
236
|
-
: undefined;
|
|
237
|
-
|
|
238
|
-
if (parentId && parentId !== targetPageId) {
|
|
239
|
-
return context.designer?.updateUiCom?.(parentId, actions, status)
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return context.designer?.updatePage?.(targetPageId, actions, status)
|
|
244
|
-
},
|
|
245
|
-
componentIdToTitleMap,
|
|
246
|
-
appendPrompt: agentConfig?.attentions,
|
|
247
|
-
getRootComponentDoc: () => context.api?.page?.api?.getPageContainerPrompts?.(targetPageId) as string,
|
|
248
|
-
getTargetId: () => targetPageId as string,
|
|
249
|
-
getFocusElementHasChildren() {
|
|
250
|
-
if (!['page', 'logicCom', 'section'].includes(currentFocus?.type) && targetId) {
|
|
251
|
-
const json = outlineInfoManager.getUiComOutline(targetId)
|
|
252
|
-
if (!json.slots || (Array.isArray(json.slots) && json.slots.length === 0)) {
|
|
253
|
-
return false
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return true
|
|
257
|
-
},
|
|
258
|
-
getFocusElementAiRole() {
|
|
259
|
-
if (focusInfo?.type === "uiCom") {
|
|
260
|
-
const comInfo = context.api.uiCom.api.getOutlineInfo(focusInfo.comId);
|
|
261
|
-
const aiComponent = ComponentsManager.getAiComponent(comInfo.def.namespace);
|
|
262
|
-
return aiComponent?.prompts?.aiRole;
|
|
263
|
-
}
|
|
264
|
-
return null
|
|
265
|
-
},
|
|
266
|
-
getComIds() {
|
|
267
|
-
const comIds: string[] = [];
|
|
268
|
-
|
|
269
|
-
outlineInfoManager.getComponentIdToTitleMap(targetPageId).forEach((value, key) => {
|
|
270
|
-
comIds.push(key);
|
|
271
|
-
})
|
|
272
|
-
|
|
273
|
-
return comIds;
|
|
274
|
-
}
|
|
275
|
-
}),
|
|
276
|
-
MYBRICKS_TOOLS.Answer({}),
|
|
277
|
-
MYBRICKS_TOOLS.CodingSubagentAsTool({
|
|
278
|
-
codingManager,
|
|
279
|
-
onStart: () => {
|
|
280
|
-
context.designer?.updatePage?.(targetPageId, [], 'start')
|
|
281
|
-
},
|
|
282
|
-
onComplete: () => {
|
|
283
|
-
context.designer?.updatePage?.(targetPageId, [], 'complete')
|
|
284
|
-
},
|
|
285
|
-
onError: () => {
|
|
286
|
-
context.designer?.updatePage?.(targetPageId, [], 'complete')
|
|
287
|
-
},
|
|
288
|
-
}),
|
|
289
|
-
MYBRICKS_TOOLS.BuildProcess({
|
|
290
|
-
// getComId: () => focusInfo.comId,
|
|
291
|
-
getPageId: () => focusInfo.pageId,
|
|
292
|
-
getComponentOutlineInfo: () => {
|
|
293
|
-
const { type, comId } = focusInfo
|
|
294
|
-
if (type === "uiCom") {
|
|
295
|
-
return {
|
|
296
|
-
type,
|
|
297
|
-
outlineInfo: context.api?.uiCom?.api?.getOutlineInfo(comId)
|
|
298
|
-
}
|
|
299
|
-
} else if (type === "logicCom") {
|
|
300
|
-
return {
|
|
301
|
-
type,
|
|
302
|
-
outlineInfo: context.api?.logicCom?.api?.getOutlineInfo(comId)
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
},
|
|
306
|
-
getPageOutlineInfo: () => context.api?.page?.api?.getOutlineInfo(focusInfo.pageId),
|
|
307
|
-
getAllPageInfo() {
|
|
308
|
-
return context.api?.global?.api?.getAllPageInfo()
|
|
309
|
-
},
|
|
310
|
-
createDiagram: (...args: any) => {
|
|
311
|
-
// console.log("[createDiagram - args]", args)
|
|
312
|
-
return context.designer?.createDiagram?.(...args)
|
|
313
|
-
},
|
|
314
|
-
updateDiagram: (...args: any) => {
|
|
315
|
-
// console.log("[updateDiagram - args]", args)
|
|
316
|
-
return context.designer?.updateDiagram?.(...args)
|
|
317
|
-
},
|
|
318
|
-
getDiagramInfo: (...args: any) => {
|
|
319
|
-
if (!args[0]) {
|
|
320
|
-
if (focusInfo.diagramId) {
|
|
321
|
-
return {
|
|
322
|
-
id: focusInfo.diagramId
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
return null
|
|
327
|
-
}
|
|
328
|
-
return context.designer?.getDiagramInfo?.(...args)
|
|
329
|
-
},
|
|
330
|
-
updatePage: (...args: any) => {
|
|
331
|
-
return context.designer?.updatePage?.(focusInfo.pageId, ...args)
|
|
332
|
-
},
|
|
333
|
-
updateCom: (...args: any) => {
|
|
334
|
-
return context.designer?.updateLogicCom?.(...args)
|
|
335
|
-
},
|
|
336
|
-
}),
|
|
337
|
-
],
|
|
338
|
-
planningCheck: (tools: any[]) => {
|
|
339
|
-
const toolNames = tools.map(tool => tool[1]);
|
|
340
|
-
const resultTools = [...tools];
|
|
341
|
-
|
|
342
|
-
// 规则1: 如果 信息获取类 在最后一个,则添加一个 answer
|
|
343
|
-
const infoToolNames = [MYBRICKS_TOOLS.OpenDsl.toolName, MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName];
|
|
344
|
-
if (toolNames.length > 0 && infoToolNames.includes(toolNames[toolNames.length - 1])) {
|
|
345
|
-
resultTools.push(['node', MYBRICKS_TOOLS.Answer.toolName]);
|
|
346
|
-
return resultTools
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
// 规则2: 如果 生成页面 前面没有获取需求,则添加一个需求分析
|
|
350
|
-
const generatePageIndex = toolNames.indexOf(MYBRICKS_TOOLS.GenerateUiContent.toolName);
|
|
351
|
-
if (generatePageIndex > -1) {
|
|
352
|
-
const requirementTools = [MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName, MYBRICKS_TOOLS.OpenDsl.toolName];
|
|
353
|
-
const hasRequirement = toolNames.slice(0, generatePageIndex).some(name => requirementTools.includes(name));
|
|
354
|
-
|
|
355
|
-
if (!hasRequirement) {
|
|
356
|
-
resultTools.splice(generatePageIndex, 0, ['node', MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName]);
|
|
357
|
-
return resultTools
|
|
358
|
-
}
|
|
359
|
-
// 规则2b: 生成页面后添加「代码开发」步骤(由 planningCheck 注入)
|
|
360
|
-
const hasCodingSubagent = resultTools.some((t: any) => t[1] === MYBRICKS_TOOLS.CodingSubagentAsTool.toolName);
|
|
361
|
-
if (!hasCodingSubagent) {
|
|
362
|
-
const insertIndex = resultTools.findIndex((t: any) => t[1] === MYBRICKS_TOOLS.GenerateUiContent.toolName) + 1;
|
|
363
|
-
resultTools.splice(insertIndex, 0, ['node', MYBRICKS_TOOLS.CodingSubagentAsTool.toolName]);
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
// 规则3: 如果 修改 前面没有 open-dsl-document,则添加一个
|
|
368
|
-
const refactorIndex = toolNames.indexOf(MYBRICKS_TOOLS.RefactorUiContent.toolName);
|
|
369
|
-
if (refactorIndex > -1) {
|
|
370
|
-
const hasOpenDsl = toolNames.slice(0, refactorIndex).includes(MYBRICKS_TOOLS.OpenDsl.toolName);
|
|
371
|
-
|
|
372
|
-
if (!hasOpenDsl) {
|
|
373
|
-
resultTools.splice(refactorIndex, 0, ['node', MYBRICKS_TOOLS.OpenDsl.toolName, { ids: targetPageId }]);
|
|
374
|
-
return resultTools
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
const buildProcessIndex = toolNames.indexOf(MYBRICKS_TOOLS.BuildProcess.toolName);
|
|
379
|
-
if (buildProcessIndex > -1) {
|
|
380
|
-
// 搭建流程前需要需求分析和组件选型
|
|
381
|
-
const requirementTools = [MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName];
|
|
382
|
-
const hasRequirement = toolNames.slice(0, generatePageIndex).some(name => requirementTools.includes(name));
|
|
383
|
-
|
|
384
|
-
if (!hasRequirement) {
|
|
385
|
-
resultTools.splice(generatePageIndex, 0, ['node', MYBRICKS_TOOLS.AnalyzeRequirementAndComponents.toolName, {mode: "refactor"}]);
|
|
386
|
-
return resultTools
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return resultTools
|
|
391
|
-
},
|
|
392
|
-
formatUserMessage: (text: string) => {
|
|
393
|
-
return `对于聚焦元素${focusEleDesc},用户提出的消息为:
|
|
394
|
-
<用户消息>
|
|
395
|
-
${text}
|
|
396
|
-
</用户消息>`
|
|
397
|
-
},
|
|
398
|
-
presetHistoryMessages: [
|
|
399
|
-
{
|
|
400
|
-
role: 'assistant',
|
|
401
|
-
content: historyFocusDesc
|
|
402
|
-
}
|
|
403
|
-
],
|
|
404
|
-
presetMessages: () => {
|
|
405
|
-
const projectStruct = workspace.getProjectStruct();
|
|
406
|
-
const componentsDocs = workspace.getComponentsDocs();
|
|
407
|
-
const hasComponentsDocs = workspace.hasComponentsDocs();
|
|
408
|
-
|
|
409
|
-
// 合并内容
|
|
410
|
-
let projectInfo = projectStruct;
|
|
411
|
-
if (hasComponentsDocs) {
|
|
412
|
-
projectInfo = `${projectStruct}\n\n${componentsDocs}`;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return [
|
|
416
|
-
{
|
|
417
|
-
role: 'user',
|
|
418
|
-
content: `<当前项目信息>\n${projectInfo}\n</当前项目信息>`
|
|
419
|
-
},
|
|
420
|
-
{
|
|
421
|
-
role: 'assistant',
|
|
422
|
-
content: hasComponentsDocs
|
|
423
|
-
? '收到,谢谢你提供的项目信息和组件文档,我会根据这些信息完成任务~'
|
|
424
|
-
: '收到,谢谢你提供的项目信息,我会根据这些信息完成任务~'
|
|
425
|
-
},
|
|
426
|
-
]
|
|
427
|
-
},
|
|
428
|
-
});
|
|
429
|
-
})
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
function generateHistoryFocusDescription(currentFocus: Partial<FocusInfo> = {}) {
|
|
434
|
-
const { pageId, comId, title, type } = currentFocus ?? {}
|
|
435
|
-
|
|
436
|
-
// 定义聚焦元素的描述部分
|
|
437
|
-
let focusDesc = '';
|
|
438
|
-
|
|
439
|
-
// 判断当前聚焦元素类型
|
|
440
|
-
if (type === 'uiCom') {
|
|
441
|
-
focusDesc = `组件(title=${title},组件id=${comId})`;
|
|
442
|
-
} else if (type === 'page') {
|
|
443
|
-
focusDesc = `画布(title=${title},画布id=${pageId})`;
|
|
444
|
-
} else if (type === 'section') {
|
|
445
|
-
focusDesc = `画布(title=${title},画布id=${pageId})`;
|
|
446
|
-
} else if (type === "logicCom") {
|
|
447
|
-
focusDesc = `计算组件(title=${title},组件id=${comId})`;
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
return `对于${focusDesc}`;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function generateFocusTargetDescription(currentFocus: Partial<FocusInfo> = {}) {
|
|
454
|
-
const { pageId, comId, title, type, focusArea } = currentFocus ?? {}
|
|
455
|
-
|
|
456
|
-
// 定义聚焦元素的描述部分
|
|
457
|
-
let focusDesc = '';
|
|
458
|
-
|
|
459
|
-
// 判断当前聚焦元素类型
|
|
460
|
-
if (type === 'uiCom') {
|
|
461
|
-
focusDesc = `组件(title=${title},组件id=${comId},选中区域=${focusArea ? focusArea.selector : ":root"})`;
|
|
462
|
-
} else if (type === 'page') {
|
|
463
|
-
focusDesc = `画布(title=${title},画布id=${pageId})`;
|
|
464
|
-
} else if (type === 'section') {
|
|
465
|
-
focusDesc = `画布(title=${title},画布id=${pageId})`;
|
|
466
|
-
} else if (type === "logicCom") {
|
|
467
|
-
focusDesc = `计算组件(title=${title},组件id=${comId})`;
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
return focusDesc;
|
|
471
|
-
}
|
package/src/agents/custom.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { context } from '../context'
|
|
3
|
-
import { AbstractAgent } from "./utils/config"
|
|
4
|
-
|
|
5
|
-
export function requestVibeCodingAgent(params: any, focus: any) {
|
|
6
|
-
const agent = context.agents!.find((agent) => agent instanceof AbstractAgent && agent.type === "vibeCoding");
|
|
7
|
-
if (agent) {
|
|
8
|
-
return (agent as AbstractAgent).request({
|
|
9
|
-
key: params.key,
|
|
10
|
-
params,
|
|
11
|
-
focus
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
}
|
package/src/agents/index.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { requestGenerateCanvasAgent } from './app'
|
|
2
|
-
import { requestCommonAgent } from './common'
|
|
3
|
-
import { requestVibeCodingAgent } from './custom'
|
|
4
|
-
import { getAgentInstance } from './utils/config'
|
|
5
|
-
import { context } from '../context'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* 统一的 agent 请求入口
|
|
9
|
-
* 根据 focus 类型自动选择使用自定义 agent 或默认的 requestCommonAgent
|
|
10
|
-
*/
|
|
11
|
-
export const requestAgent = (params: any) => {
|
|
12
|
-
const type = context.currentFocus?.type;
|
|
13
|
-
|
|
14
|
-
if (context.currentFocus?.vibeCoding) {
|
|
15
|
-
return requestVibeCodingAgent({
|
|
16
|
-
...params,
|
|
17
|
-
key: `${context.pluginParams.key}_${context.currentFocus!.pageId}_${context.currentFocus!.comId}`,
|
|
18
|
-
}, {...context.currentFocus});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// 检查是否有匹配的自定义 agent
|
|
22
|
-
const customAgent = type ? getAgentInstance(context.agents, type) : null;
|
|
23
|
-
|
|
24
|
-
if (customAgent) {
|
|
25
|
-
// 如果找到匹配的自定义 agent,调用其 request 方法
|
|
26
|
-
return customAgent.request(params);
|
|
27
|
-
} else {
|
|
28
|
-
// 否则使用默认的 requestCommonAgent
|
|
29
|
-
return requestCommonAgent(params);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const Agents = {
|
|
34
|
-
requestGenerateCanvasAgent,
|
|
35
|
-
requestCommonAgent,
|
|
36
|
-
requestAgent
|
|
37
|
-
}
|