@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,145 +0,0 @@
|
|
|
1
|
-
export class ComponentsManager {
|
|
2
|
-
private static isLoaded = false
|
|
3
|
-
private static aiComponentMap = new Map<string, any>()
|
|
4
|
-
private static namespaceAbbrevMap = new Map<string, string>() // 缩写 -> 完整namespace
|
|
5
|
-
private static abbreviationMap = new Map<string, string>() // 完整namespace -> 缩写
|
|
6
|
-
|
|
7
|
-
private static init = () => {
|
|
8
|
-
if (this.isLoaded) {
|
|
9
|
-
return
|
|
10
|
-
}
|
|
11
|
-
if (!window.__comlibs_edit_) {
|
|
12
|
-
return
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
const forEachComponent = (com: any, callback: (com: any) => void) => {
|
|
16
|
-
if (com?.namespace) {
|
|
17
|
-
callback?.(com)
|
|
18
|
-
}
|
|
19
|
-
if (Array.isArray(com?.comAray)) {
|
|
20
|
-
com?.comAray.forEach((child: any) => {
|
|
21
|
-
forEachComponent(child, callback)
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
window.__comlibs_edit_.forEach((comlib: any) => {
|
|
27
|
-
forEachComponent(comlib, (com) => {
|
|
28
|
-
if (com?.ai) {
|
|
29
|
-
this.aiComponentMap.set(com.namespace, {
|
|
30
|
-
...com.ai,
|
|
31
|
-
all: com
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
const abbreviation = com.namespace
|
|
35
|
-
.replace('mybricks.normal-pc.antd5.', 'pc.')
|
|
36
|
-
.replace('mybricks.normal-pc.', 'pc.')
|
|
37
|
-
.replace('mybricks.harmony.', 'mb.')
|
|
38
|
-
.replace('mybricks.taro.', 'mb.')
|
|
39
|
-
|
|
40
|
-
// 收集缩写映射关系
|
|
41
|
-
if (abbreviation !== com.namespace) {
|
|
42
|
-
this.namespaceAbbrevMap.set(abbreviation, com.namespace)
|
|
43
|
-
this.abbreviationMap.set(com.namespace, abbreviation)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
this.isLoaded = true
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
static getRequireComponents = (ns: string): any[] => {
|
|
53
|
-
this.init()
|
|
54
|
-
|
|
55
|
-
let res: any[] = []
|
|
56
|
-
if (this.aiComponentMap.has(ns)) {
|
|
57
|
-
const ai = this.aiComponentMap.get(ns)
|
|
58
|
-
if (Array.isArray(ai.requires)) {
|
|
59
|
-
res = res.concat(ai.requires)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return res
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 判断是否为布局组件(asLayout)
|
|
67
|
-
*/
|
|
68
|
-
static isLayoutComponent = (namespace: string): boolean => {
|
|
69
|
-
this.init()
|
|
70
|
-
const ai = this.aiComponentMap.get(this.getFullNamespace(namespace))
|
|
71
|
-
return !!ai?.asLayout
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 获取所有布局组件的 namespace 缩写数组
|
|
76
|
-
*/
|
|
77
|
-
static getLayoutComponentsAbbreviationNs = (): string[] => {
|
|
78
|
-
this.init()
|
|
79
|
-
const res: string[] = []
|
|
80
|
-
|
|
81
|
-
this.aiComponentMap.forEach((ai, namespace) => {
|
|
82
|
-
if (ai?.asLayout) {
|
|
83
|
-
res.push(this.getAbbreviation(namespace))
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
return res
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 根据完整namespace获取缩写
|
|
92
|
-
* @param namespace 完整的namespace
|
|
93
|
-
* @returns 缩写namespace,如果没有缩写则返回原namespace
|
|
94
|
-
*/
|
|
95
|
-
static getAbbreviation = (namespace: string): string => {
|
|
96
|
-
this.init()
|
|
97
|
-
return this.abbreviationMap.get(namespace) || namespace
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* 根据缩写获取完整namespace
|
|
102
|
-
* @param abbreviation 缩写
|
|
103
|
-
* @returns 完整namespace,如果没有对应的完整namespace则返回原缩写
|
|
104
|
-
*/
|
|
105
|
-
static getFullNamespace = (abbreviation: string): string => {
|
|
106
|
-
this.init()
|
|
107
|
-
return this.namespaceAbbrevMap.get(abbreviation) || abbreviation
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* 重置加载状态(用于测试或重新初始化)
|
|
112
|
-
*/
|
|
113
|
-
static reset = () => {
|
|
114
|
-
this.isLoaded = false
|
|
115
|
-
this.aiComponentMap.clear()
|
|
116
|
-
this.namespaceAbbrevMap.clear()
|
|
117
|
-
this.abbreviationMap.clear()
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
static getAiComponent(namespace: string) {
|
|
121
|
-
this.init()
|
|
122
|
-
return this.aiComponentMap.get(namespace)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 获取所有可用的AI组件列表
|
|
127
|
-
* @returns 组件列表,包含 namespace, name, abbreviation, description
|
|
128
|
-
*/
|
|
129
|
-
static getAllComponents(): Array<{ namespace: string; name: string; abbreviation: string; description: string }> {
|
|
130
|
-
this.init()
|
|
131
|
-
const components: Array<{ namespace: string; name: string; abbreviation: string; description: string }> = []
|
|
132
|
-
|
|
133
|
-
this.aiComponentMap.forEach((ai, namespace) => {
|
|
134
|
-
components.push({
|
|
135
|
-
namespace: namespace,
|
|
136
|
-
name: ai.all?.title || namespace,
|
|
137
|
-
abbreviation: this.getAbbreviation(namespace),
|
|
138
|
-
description: ai.all?.description || ''
|
|
139
|
-
})
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
return components
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
import { OutlineInfoManager, type OutlineNode, type SlotInfo } from './outline-info';
|
|
2
|
-
import { ComponentsManager } from './components-manager';
|
|
3
|
-
import { FocusInfo } from '../types';
|
|
4
|
-
|
|
5
|
-
class PageHierarchyGenerator {
|
|
6
|
-
static generate(outlineInfo: OutlineNode, currentFocus: FocusInfo): string {
|
|
7
|
-
const processedData = currentFocus.type === 'uiCom'
|
|
8
|
-
? this.filterToFocusedComponent(outlineInfo, currentFocus.comId!)
|
|
9
|
-
: outlineInfo;
|
|
10
|
-
|
|
11
|
-
return this.generateTreeDescription(processedData as OutlineNode, {
|
|
12
|
-
pageId: currentFocus.pageId,
|
|
13
|
-
comId: currentFocus.comId,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
private static containsComponent(data: OutlineNode, targetId: string): boolean {
|
|
18
|
-
if (!data) return false;
|
|
19
|
-
if (data.id === targetId) return true;
|
|
20
|
-
|
|
21
|
-
if (data.slots && Array.isArray(data.slots)) {
|
|
22
|
-
return data.slots.some(slot => {
|
|
23
|
-
if (slot.components && Array.isArray(slot.components)) {
|
|
24
|
-
return slot.components.some(component => this.containsComponent(component, targetId));
|
|
25
|
-
}
|
|
26
|
-
return false;
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private static hasChildren(data: OutlineNode): boolean {
|
|
33
|
-
if (!data?.slots || !Array.isArray(data.slots)) {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
return data.slots.some(slot => {
|
|
37
|
-
return slot.components && Array.isArray(slot.components) && slot.components.length > 0;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
private static filterToFocusedComponent(data: OutlineNode, targetId: string): OutlineNode | null {
|
|
42
|
-
if (!data) return null;
|
|
43
|
-
|
|
44
|
-
if (data.id === targetId) {
|
|
45
|
-
return data;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (data.slots && Array.isArray(data.slots)) {
|
|
49
|
-
const filteredSlots = data.slots.map(slot => {
|
|
50
|
-
if (slot.components && Array.isArray(slot.components)) {
|
|
51
|
-
const filteredComponents = slot.components.map(component => {
|
|
52
|
-
if (this.containsComponent(component, targetId)) {
|
|
53
|
-
return this.filterToFocusedComponent(component, targetId);
|
|
54
|
-
} else {
|
|
55
|
-
const hasChildComponents = this.hasChildren(component);
|
|
56
|
-
return {
|
|
57
|
-
...component,
|
|
58
|
-
slots: undefined,
|
|
59
|
-
_hasCollapsedChildren: hasChildComponents
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
}).filter(Boolean) as OutlineNode[];
|
|
63
|
-
|
|
64
|
-
return filteredComponents.length > 0 ? { ...slot, components: filteredComponents } : null;
|
|
65
|
-
}
|
|
66
|
-
return null;
|
|
67
|
-
}).filter(Boolean) as SlotInfo[];
|
|
68
|
-
|
|
69
|
-
if (filteredSlots.length > 0) {
|
|
70
|
-
return { ...data, slots: filteredSlots };
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
private static generateTreeDescription(data: OutlineNode | OutlineNode[], focusInfo: FocusInfo, level = 0): string {
|
|
77
|
-
const indent = ' '.repeat(level);
|
|
78
|
-
let result = '';
|
|
79
|
-
|
|
80
|
-
if (!data) {
|
|
81
|
-
return '无内容,代表内容为空';
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (Array.isArray(data)) {
|
|
85
|
-
if (data.length === 0) {
|
|
86
|
-
return '无内容,代表内容为空';
|
|
87
|
-
}
|
|
88
|
-
data.forEach(item => {
|
|
89
|
-
result += this.generateTreeDescription(item, focusInfo, level);
|
|
90
|
-
});
|
|
91
|
-
return result;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (data.asRoot) {
|
|
95
|
-
if (Array.isArray(data.slots?.[0]?.components)) {
|
|
96
|
-
data.slots?.[0]?.components.forEach(component => {
|
|
97
|
-
result += this.generateTreeDescription(component, focusInfo, level);
|
|
98
|
-
});
|
|
99
|
-
return result;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
if (data.title) {
|
|
104
|
-
const namespace = data.def?.namespace;
|
|
105
|
-
const isFocused = data.id === focusInfo.comId ||
|
|
106
|
-
data.id === focusInfo.pageId;
|
|
107
|
-
const focusMarker = isFocused ? ' 【当前聚焦】' : '';
|
|
108
|
-
const collapsedMarker = data._hasCollapsedChildren ? ' 【子组件已折叠】' : '';
|
|
109
|
-
|
|
110
|
-
result += `${indent}- ${data.title}[id=${data.id}]${namespace ? `(${ComponentsManager.getAbbreviation(namespace)})` : ''}${focusMarker}${collapsedMarker}\n`;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
if (data.slots && Array.isArray(data.slots)) {
|
|
114
|
-
data.slots.forEach(slot => {
|
|
115
|
-
if (slot.components && Array.isArray(slot.components)) {
|
|
116
|
-
slot.components.forEach(component => {
|
|
117
|
-
result += this.generateTreeDescription(component, focusInfo, level + 1);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return result;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
class FocusDescriptionGenerator {
|
|
128
|
-
static generate(currentFocus: FocusInfo): string {
|
|
129
|
-
const { pageId, comId, title, type } = currentFocus ?? {};
|
|
130
|
-
|
|
131
|
-
if (!currentFocus || (!currentFocus.pageId && !currentFocus.comId)) {
|
|
132
|
-
return '当前没有聚焦到任何页面或组件。';
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
let focusDesc = '';
|
|
136
|
-
|
|
137
|
-
switch (type) {
|
|
138
|
-
case 'uiCom':
|
|
139
|
-
focusDesc = `组件(title=${title},组件id=${comId})`;
|
|
140
|
-
break;
|
|
141
|
-
case 'page':
|
|
142
|
-
case 'section':
|
|
143
|
-
focusDesc = `页面(title=${title},页面id=${pageId})`;
|
|
144
|
-
break;
|
|
145
|
-
default:
|
|
146
|
-
focusDesc = `未知类型(title=${title})`;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return `当前已聚焦到${focusDesc}中,后续用户的提问,关于"这个"、"此"、"整体",甚至不提主语,都是指代此元素及其子组件内容。`;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
export class FocusOutlineInfoManager extends OutlineInfoManager {
|
|
154
|
-
private focusInfo: FocusInfo;
|
|
155
|
-
private focusPageOutlineInfo: OutlineNode | null;
|
|
156
|
-
|
|
157
|
-
constructor({ api, focusInfo }: { api: any, focusInfo: FocusInfo }) {
|
|
158
|
-
super({ api });
|
|
159
|
-
this.focusInfo = { ...focusInfo };
|
|
160
|
-
this.focusPageOutlineInfo = focusInfo?.pageId ? this.getPageOutline(focusInfo.pageId) : null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
getFocusPageOutline(): OutlineNode | null {
|
|
164
|
-
return this.focusPageOutlineInfo;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
generateFocusHierarchy(): string {
|
|
168
|
-
if (!this.focusPageOutlineInfo || !this.focusInfo?.pageId) {
|
|
169
|
-
return '无内容,代表内容为空';
|
|
170
|
-
}
|
|
171
|
-
return PageHierarchyGenerator.generate(this.focusPageOutlineInfo, this.focusInfo);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
generateFocusDescription(): string {
|
|
175
|
-
return FocusDescriptionGenerator.generate(this.focusInfo);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|