@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.
Files changed (249) hide show
  1. package/dist/_virtual/_rollupPluginBabelHelpers.js +164 -0
  2. package/dist/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  3. package/dist/agents/app.js +335 -0
  4. package/dist/agents/app.js.map +1 -0
  5. package/dist/agents/common.js +483 -0
  6. package/dist/agents/common.js.map +1 -0
  7. package/dist/agents/custom.js +16 -0
  8. package/dist/agents/custom.js.map +1 -0
  9. package/dist/agents/index.js +38 -0
  10. package/dist/agents/index.js.map +1 -0
  11. package/dist/agents/knowledges/knowledge-base.js +579 -0
  12. package/dist/agents/knowledges/knowledge-base.js.map +1 -0
  13. package/dist/agents/knowledges/knowledge-node.js +228 -0
  14. package/dist/agents/knowledges/knowledge-node.js.map +1 -0
  15. package/dist/agents/knowledges/types.js +105 -0
  16. package/dist/agents/knowledges/types.js.map +1 -0
  17. package/dist/agents/utils/config.js +229 -0
  18. package/dist/agents/utils/config.js.map +1 -0
  19. package/dist/agents/workspace/coding-manager.js +20 -0
  20. package/dist/agents/workspace/coding-manager.js.map +1 -0
  21. package/dist/agents/workspace/components-manager.js +113 -0
  22. package/dist/agents/workspace/components-manager.js.map +1 -0
  23. package/dist/agents/workspace/outline-focus.js +167 -0
  24. package/dist/agents/workspace/outline-focus.js.map +1 -0
  25. package/dist/agents/workspace/outline-info.js +430 -0
  26. package/dist/agents/workspace/outline-info.js.map +1 -0
  27. package/dist/agents/workspace/page-tree-generator.js +70 -0
  28. package/dist/agents/workspace/page-tree-generator.js.map +1 -0
  29. package/dist/agents/workspace/workspace.js +251 -0
  30. package/dist/agents/workspace/workspace.js.map +1 -0
  31. package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js +100 -0
  32. package/dist/agents/workspace-by-knowledges/providers/component-docs-provider.js.map +1 -0
  33. package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js +120 -0
  34. package/dist/agents/workspace-by-knowledges/providers/focus-info-provider.js.map +1 -0
  35. package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js +146 -0
  36. package/dist/agents/workspace-by-knowledges/providers/project-info-provider.js.map +1 -0
  37. package/dist/agents/workspace-by-knowledges/test.js +242 -0
  38. package/dist/agents/workspace-by-knowledges/test.js.map +1 -0
  39. package/dist/agents/workspace-by-knowledges/utils/components-manager.js +132 -0
  40. package/dist/agents/workspace-by-knowledges/utils/components-manager.js.map +1 -0
  41. package/dist/agents/workspace-by-knowledges/utils/outline-focus.js +167 -0
  42. package/dist/agents/workspace-by-knowledges/utils/outline-focus.js.map +1 -0
  43. package/dist/agents/workspace-by-knowledges/utils/outline-info.js +430 -0
  44. package/dist/agents/workspace-by-knowledges/utils/outline-info.js.map +1 -0
  45. package/dist/agents/workspace-by-knowledges/workspace.js +169 -0
  46. package/dist/agents/workspace-by-knowledges/workspace.js.map +1 -0
  47. package/dist/api/cloud-components.js +85 -0
  48. package/dist/api/cloud-components.js.map +1 -0
  49. package/dist/api-record-replay/manager.js +168 -0
  50. package/dist/api-record-replay/manager.js.map +1 -0
  51. package/{src/api-record-replay/recorder.ts → dist/api-record-replay/recorder.js} +22 -32
  52. package/dist/api-record-replay/recorder.js.map +1 -0
  53. package/dist/api-record-replay/replayer.js +136 -0
  54. package/dist/api-record-replay/replayer.js.map +1 -0
  55. package/dist/components/attachments/index.js +124 -0
  56. package/dist/components/attachments/index.js.map +1 -0
  57. package/dist/components/attachments/index.less.js +8 -0
  58. package/dist/components/attachments/index.less.js.map +1 -0
  59. package/dist/components/icons/index.js +112 -0
  60. package/dist/components/icons/index.js.map +1 -0
  61. package/dist/components/icons/index.less.js +8 -0
  62. package/dist/components/icons/index.less.js.map +1 -0
  63. package/dist/components/mention/index.js +19 -0
  64. package/dist/components/mention/index.js.map +1 -0
  65. package/dist/components/mention/index.less.js +8 -0
  66. package/dist/components/mention/index.less.js.map +1 -0
  67. package/dist/components/messages/index.js +429 -0
  68. package/dist/components/messages/index.js.map +1 -0
  69. package/dist/components/messages/index.less.js +8 -0
  70. package/dist/components/messages/index.less.js.map +1 -0
  71. package/dist/components/sender/index.js +244 -0
  72. package/dist/components/sender/index.js.map +1 -0
  73. package/dist/components/sender/index.less.js +8 -0
  74. package/dist/components/sender/index.less.js.map +1 -0
  75. package/dist/context/RequestStatusTracker.js +44 -0
  76. package/dist/context/RequestStatusTracker.js.map +1 -0
  77. package/dist/context/index.js +45 -0
  78. package/dist/context/index.js.map +1 -0
  79. package/dist/data.js +4 -0
  80. package/dist/data.js.map +1 -0
  81. package/dist/index.js +306 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js +27 -0
  84. package/dist/plugin-ai/node_modules/style-inject/dist/style-inject.es.js.map +1 -0
  85. package/dist/plugin-ai/package.json.js +8 -0
  86. package/dist/plugin-ai/package.json.js.map +1 -0
  87. package/dist/plugin-ai/test/index.js +206 -0
  88. package/dist/plugin-ai/test/index.js.map +1 -0
  89. package/dist/preset/createTemplates.js +29 -0
  90. package/dist/preset/createTemplates.js.map +1 -0
  91. package/dist/preset/index.js +13 -0
  92. package/dist/preset/index.js.map +1 -0
  93. package/dist/preset/prompts.js +34 -0
  94. package/dist/preset/prompts.js.map +1 -0
  95. package/{src/preset/user.ts → dist/preset/user.js} +4 -3
  96. package/dist/preset/user.js.map +1 -0
  97. package/dist/requestAsStream.js +269 -0
  98. package/dist/requestAsStream.js.map +1 -0
  99. package/dist/rxai/node_modules/idb/build/index.js +277 -0
  100. package/dist/rxai/node_modules/idb/build/index.js.map +1 -0
  101. package/dist/rxai/src/agent/base.js +16 -0
  102. package/dist/rxai/src/agent/base.js.map +1 -0
  103. package/dist/rxai/src/agent/planning.js +1076 -0
  104. package/dist/rxai/src/agent/planning.js.map +1 -0
  105. package/dist/rxai/src/agent/rxai.js +254 -0
  106. package/dist/rxai/src/agent/rxai.js.map +1 -0
  107. package/dist/rxai/src/error/base.js +39 -0
  108. package/dist/rxai/src/error/base.js.map +1 -0
  109. package/dist/rxai/src/prompt/base.js +11 -0
  110. package/dist/rxai/src/prompt/base.js.map +1 -0
  111. package/dist/rxai/src/prompt/planning.js +23 -0
  112. package/dist/rxai/src/prompt/planning.js.map +1 -0
  113. package/dist/rxai/src/prompt/tool.js +14 -0
  114. package/dist/rxai/src/prompt/tool.js.map +1 -0
  115. package/dist/rxai/src/request/request.js +123 -0
  116. package/dist/rxai/src/request/request.js.map +1 -0
  117. package/dist/rxai/src/tool/getHistoryRecords.js +65 -0
  118. package/dist/rxai/src/tool/getHistoryRecords.js.map +1 -0
  119. package/dist/rxai/src/tool/util.js +424 -0
  120. package/dist/rxai/src/tool/util.js.map +1 -0
  121. package/dist/rxai/src/utils/events.js +43 -0
  122. package/dist/rxai/src/utils/events.js.map +1 -0
  123. package/dist/rxai/src/utils/idb.js +240 -0
  124. package/dist/rxai/src/utils/idb.js.map +1 -0
  125. package/dist/rxai/src/utils/retry.js +32 -0
  126. package/dist/rxai/src/utils/retry.js.map +1 -0
  127. package/dist/rxai/src/utils/uuid.js +7 -0
  128. package/dist/rxai/src/utils/uuid.js.map +1 -0
  129. package/dist/startView/components/header/header.js +12 -0
  130. package/dist/startView/components/header/header.js.map +1 -0
  131. package/dist/startView/components/header/header.less.js +8 -0
  132. package/dist/startView/components/header/header.less.js.map +1 -0
  133. package/dist/startView/index.js +62 -0
  134. package/dist/startView/index.js.map +1 -0
  135. package/dist/startView/index.less.js +8 -0
  136. package/dist/startView/index.less.js.map +1 -0
  137. package/dist/tools/analyze-and-expand-prd.js +116 -0
  138. package/dist/tools/analyze-and-expand-prd.js.map +1 -0
  139. package/dist/tools/analyze-requirement-and-components.js +208 -0
  140. package/dist/tools/analyze-requirement-and-components.js.map +1 -0
  141. package/dist/tools/answer.js +33 -0
  142. package/dist/tools/answer.js.map +1 -0
  143. package/dist/tools/build-process.js +550 -0
  144. package/dist/tools/build-process.js.map +1 -0
  145. package/dist/tools/coding-subagent-as-tool.js +101 -0
  146. package/dist/tools/coding-subagent-as-tool.js.map +1 -0
  147. package/dist/tools/generate-ui-content.js +528 -0
  148. package/dist/tools/generate-ui-content.js.map +1 -0
  149. package/dist/tools/index.js +31 -0
  150. package/dist/tools/index.js.map +1 -0
  151. package/dist/tools/open-dsl.js +49 -0
  152. package/dist/tools/open-dsl.js.map +1 -0
  153. package/dist/tools/refactor-ui-content.js +292 -0
  154. package/dist/tools/refactor-ui-content.js.map +1 -0
  155. package/dist/tools/utils.js +832 -0
  156. package/dist/tools/utils.js.map +1 -0
  157. package/dist/types/index.js +8 -0
  158. package/dist/types/index.js.map +1 -0
  159. package/dist/view/components/header/header.js +59 -0
  160. package/dist/view/components/header/header.js.map +1 -0
  161. package/dist/view/components/header/header.less.js +8 -0
  162. package/dist/view/components/header/header.less.js.map +1 -0
  163. package/dist/view/index.js +184 -0
  164. package/dist/view/index.js.map +1 -0
  165. package/dist/view/index.less.js +8 -0
  166. package/dist/view/index.less.js.map +1 -0
  167. package/package.json +28 -6
  168. package/src/agents/app.ts +0 -301
  169. package/src/agents/common.ts +0 -471
  170. package/src/agents/custom.ts +0 -14
  171. package/src/agents/index.ts +0 -37
  172. package/src/agents/knowledges/README.md +0 -614
  173. package/src/agents/knowledges/SUMMARY.md +0 -527
  174. package/src/agents/knowledges/index.ts +0 -8
  175. package/src/agents/knowledges/knowledge-base.ts +0 -565
  176. package/src/agents/knowledges/knowledge-node.ts +0 -266
  177. package/src/agents/knowledges/types.ts +0 -208
  178. package/src/agents/utils/config.ts +0 -427
  179. package/src/agents/workspace/coding-manager.ts +0 -31
  180. package/src/agents/workspace/components-manager.ts +0 -124
  181. package/src/agents/workspace/outline-focus.ts +0 -188
  182. package/src/agents/workspace/outline-info.ts +0 -520
  183. package/src/agents/workspace/page-tree-generator.ts +0 -83
  184. package/src/agents/workspace/workspace.ts +0 -319
  185. package/src/agents/workspace-by-knowledges/MIGRATION.md +0 -568
  186. package/src/agents/workspace-by-knowledges/README.md +0 -521
  187. package/src/agents/workspace-by-knowledges/index.ts +0 -11
  188. package/src/agents/workspace-by-knowledges/providers/component-docs-provider.ts +0 -92
  189. package/src/agents/workspace-by-knowledges/providers/focus-info-provider.ts +0 -131
  190. package/src/agents/workspace-by-knowledges/providers/index.ts +0 -8
  191. package/src/agents/workspace-by-knowledges/providers/project-info-provider.ts +0 -151
  192. package/src/agents/workspace-by-knowledges/test.ts +0 -240
  193. package/src/agents/workspace-by-knowledges/types.ts +0 -56
  194. package/src/agents/workspace-by-knowledges/utils/components-manager.ts +0 -145
  195. package/src/agents/workspace-by-knowledges/utils/index.ts +0 -8
  196. package/src/agents/workspace-by-knowledges/utils/outline-focus.ts +0 -178
  197. package/src/agents/workspace-by-knowledges/utils/outline-info.ts +0 -521
  198. package/src/agents/workspace-by-knowledges/workspace.ts +0 -166
  199. package/src/api/cloud-components.ts +0 -129
  200. package/src/api-record-replay/README.md +0 -187
  201. package/src/api-record-replay/index.ts +0 -11
  202. package/src/api-record-replay/manager.ts +0 -168
  203. package/src/api-record-replay/replayer.ts +0 -148
  204. package/src/components/attachments/index.less +0 -117
  205. package/src/components/attachments/index.tsx +0 -136
  206. package/src/components/icons/index.less +0 -8
  207. package/src/components/icons/index.tsx +0 -44
  208. package/src/components/index.less +0 -34
  209. package/src/components/mention/index.less +0 -23
  210. package/src/components/mention/index.tsx +0 -19
  211. package/src/components/messages/index.less +0 -1013
  212. package/src/components/messages/index.tsx +0 -519
  213. package/src/components/sender/index.less +0 -203
  214. package/src/components/sender/index.tsx +0 -298
  215. package/src/components/types.ts +0 -31
  216. package/src/constants/index.ts +0 -8
  217. package/src/context/RequestStatusTracker.ts +0 -50
  218. package/src/context/index.ts +0 -83
  219. package/src/data.ts +0 -5
  220. package/src/global.d.ts +0 -100
  221. package/src/index.tsx +0 -264
  222. package/src/mock.ts +0 -1267
  223. package/src/preset/agents.ts +0 -380
  224. package/src/preset/createTemplates.ts +0 -25
  225. package/src/preset/index.ts +0 -12
  226. package/src/preset/prompts.ts +0 -235
  227. package/src/preset/requestAsStream.ts +0 -246
  228. package/src/startView/components/header/header.less +0 -17
  229. package/src/startView/components/header/header.tsx +0 -15
  230. package/src/startView/components/index.ts +0 -1
  231. package/src/startView/index.less +0 -34
  232. package/src/startView/index.tsx +0 -61
  233. package/src/tools/analyze-and-expand-prd.ts +0 -272
  234. package/src/tools/analyze-requirement-and-components.ts +0 -589
  235. package/src/tools/answer.ts +0 -59
  236. package/src/tools/build-process.ts +0 -1174
  237. package/src/tools/coding-subagent-as-tool.ts +0 -119
  238. package/src/tools/generate-ui-content.ts +0 -1083
  239. package/src/tools/index.ts +0 -28
  240. package/src/tools/open-dsl.ts +0 -69
  241. package/src/tools/refactor-ui-content.ts +0 -801
  242. package/src/tools/type.d.ts +0 -12
  243. package/src/tools/utils.ts +0 -914
  244. package/src/types/index.ts +0 -4
  245. package/src/view/components/header/header.less +0 -51
  246. package/src/view/components/header/header.tsx +0 -60
  247. package/src/view/components/index.ts +0 -1
  248. package/src/view/index.less +0 -5
  249. package/src/view/index.tsx +0 -168
@@ -1,801 +0,0 @@
1
- import { fileFormat, RxaiError } from '@mybricks/rxai'
2
- import { getFiles, createActionsParser, getComponentOperationSummary, stripFileBlocks, ComIdTransform, PromiseStack } from './utils'
3
- import { context } from './../context'
4
-
5
- interface RefactorUiContentToolParams {
6
- appendPrompt: any;
7
- /** 当前根组件信息 */
8
- getRootComponentDoc: () => string;
9
- getTargetId: () => string;
10
- componentIdToTitleMap: Map<string, string>;
11
- getFocusElementHasChildren: () => boolean
12
- /** 当所有actions返回时 */
13
- onActions: (actions: any[], status: string, type: string) => void
14
- getFocusElementAiRole?: () => boolean;
15
- getComIds: () => any;
16
- }
17
-
18
- const NAME = 'refactor-components-in-canvas'
19
- refactorUiContent.toolName = NAME;
20
-
21
- export default function refactorUiContent(config: RefactorUiContentToolParams): any {
22
- const streamActionsParser = createActionsParser({ enabledActionTags: context.enabledActionTags });
23
- const excuteActionsParser = createActionsParser({ enabledActionTags: context.enabledActionTags });
24
- const hasChildren = config.getFocusElementHasChildren() !== false
25
-
26
- let fileNameToContent: Record<string, string> = {};
27
- let displayContent = "";
28
-
29
- // TODO,因为updateCom不支持修改_root_,所以在聚焦组件时修改页面使用updatePage,目前是用第一个action的ID来判断是修改页面还是修改组件
30
- let firstActionId: string
31
- let actionType = 'page'
32
-
33
- const pageId = config?.getTargetId();
34
- const comIdTransform = new ComIdTransform(config.getComIds());
35
- const promiseStack = new PromiseStack();
36
-
37
- return {
38
- name: NAME,
39
- displayName: "局部修改/重构",
40
- description: `根据用户需求/附件图片对画布中的UI内容进行局部修改/重构/移动/删除。
41
- 参数:无
42
- 工具分类:操作执行类
43
- 作用:
44
- 1. 局部修改组件配置;
45
- 2. 通过添加/删除组件来重构整个组件插槽中的UI内容;
46
- 3. 对组件进行移动和删除;
47
- 前置依赖:
48
- - 必须确保之前进行过「获取DSL」;
49
- - 如果需要修改组件配置,确保之前有执行过「获取DSL」,这个工具都会自动获取组件使用文档,组件的修改必须严格参考组件使用文档;
50
- - 如果需要添加组件,确保之前有进行过「组件选型」,添加组件必须通过组件选型来获取组件配置文档;
51
- 注意:此工具只能对UI内容进行操作。
52
-
53
- 使用场景示例:
54
- - 这个卡片改成美团购物卡片
55
- 分析:由于卡片内容完全变化,可能涉及新增组件,并且需要修改卡片组件的配置,所以需要「获取DSL」->「组件选型分析」-> 「局部重构」的规划
56
- - 内容不符合要求,修改里面的内容
57
- 分析:由于需要修改里面的内容可能涉及新增组件,所以需要「获取DSL」->「组件选型分析」->「局部重构」的规划
58
- - 修改XX组件的样式/配置
59
- 分析:由于仅修改组件配置,所以仅需要「获取DSL」->「局部重构」的规划
60
- - 图片换个链接
61
- 分析:由于仅修改组件配置,所以仅需要「获取DSL」->「局部重构」的规划
62
- - 添加一个XX组件
63
- 分析:由于需要新增组件,所以需要「获取DSL」->「组件选型分析」->「局部重构」的规划
64
- - 删除组件
65
- 分析:由于仅删除组件,所以仅需要「局部重构」的规划
66
- - 和某某交换位置
67
- 分析:由于移动组件需要指导插槽id及其子组件情况,所以仅需要「获取DSL」->「局部重构」的规划
68
- `,
69
- getPrompts() {
70
- return `<工具总览>
71
- 你是一个修改UI区域搭建效果的工具,你作为MyBricks低代码平台(以下简称MyBricks平台或MyBricks)的资深搭建助手,及客服专家,经验丰富、实事求是、逻辑严谨。
72
-
73
- <任务目标>
74
- 你的任务是通过 actions 序列完成用户的目标。
75
- !IMPORTANT: 当前工具只能完成UI界面搭建,也就是只能搭建UI部分,只能修改/配置UI组件,逻辑部分请留到后续的逻辑搭建工具中完成。
76
- </任务目标>
77
- </工具总览>
78
-
79
- <当前画布根组件信息>
80
- ${config.getRootComponentDoc()}
81
-
82
- IMPORTANT: 如果要修改UI根组件,请使用此文档。
83
- </当前画布根组件信息>
84
-
85
- <如何搭建UI以及修改>
86
- 通过一系列的action来分步骤完成对组件的修改,请返回以下格式以驱动MyBricks对组件进行修改:
87
-
88
- <关于actions>
89
- actions.json文件由多个action构成,每个 action 在结构上都严格遵循以下格式:[comId, target, type, params];
90
- - comId 代表要操作的目标组件的id(对于需要生成的新的id,必须采用u_xxxxx,xxxxx是3-7位唯一的字母数字组合);
91
- - target 指的是组件的整体或某个部分,以选择器的形式表示
92
- - 当type=addChild时,target为插槽id;
93
- - 当type=move时,target为:root或插槽id;
94
- - type action的类型,包括了 setLayout、doConfig、addChild、move、delete 动作;
95
- - params 为不同type类型对应的参数;
96
-
97
- 综合而言,每个action的语义是:对某个组件(comId)的整体或某个部分(target),执行某个动作(type),并传入参数(params)。
98
-
99
- 注意:
100
- - 在返回多个步骤时,务必注意其逻辑顺序,例如有些action需要先完成,后续的action(可能受控于ifVisible,只有ifVislble返回true才能使用)才能进行;
101
- - 有些修改需要先完成整体、再进行局部的修改;
102
-
103
- 各action详细说明如下:
104
-
105
- <setLayout>
106
- - 设置组件的布局和尺寸信息,params的格式以Typescript的形式说明如下:
107
-
108
- \`\`\`typescript
109
- /**
110
- * 宽高尺寸
111
- * number - 具体的px值
112
- * fit-content - 适应内容
113
- * 100% - 填充,仅允许100%,不允许其他百分比宽度
114
- * auto - 自动填充,等同于flex=1
115
- * 只能是三者其一,明确不允许使用其他属性,比如calc等方法
116
- */
117
- type Size = number | "fit-content" | "100%" | "auto"
118
-
119
- /** flex中子组件定位,可配置如下layout */
120
- type setLayout_flex_params = {
121
- width?: Size;
122
- height?: Size;
123
- /** 上外边距 */
124
- marginTop?: number;
125
- /** 右外边距 */
126
- marginRight?: number;
127
- /** 下外边距 */
128
- marginBottom?: number;
129
- /** 左外边距 */
130
- marginLeft?: number;
131
- }
132
- \`\`\`
133
-
134
- 注意:
135
- - 1. 只有在flex布局中的组件,可以在layout中使用margin相关配置;
136
-
137
- \`\`\`typescript
138
- /** 对于flex布局的插槽,我们可以添加absolute定位的组件 */
139
- type setLayout_absolute_params = {
140
- position: 'absolute';
141
- width?: Size;
142
- height?: Size;
143
- /** 距离左侧 */
144
- left?: number;
145
- /** 距离右侧 */
146
- right?: number;
147
- /** 距离上方 */
148
- top?: number;
149
- /** 距离下方 */
150
- bottom?: number;
151
- }
152
- \`\`\`
153
-
154
- \`\`\`typescript
155
- /** 如果组件本身是fixed类型定位,可配置如下layout */
156
- type setLayout_fixed_params = {
157
- position: 'fixed';
158
- width?: Size;
159
- height?: Size;
160
- /** 距离左侧 */
161
- left?: number;
162
- /** 距离右侧 */
163
- right?: number;
164
- /** 距离上方 */
165
- top?: number;
166
- /** 距离下方 */
167
- bottom?: number;
168
- }
169
- \`\`\`
170
-
171
- 例如,当用户要求将当前组件的宽度设置为200px,可以返回以下内容:
172
- ${fileFormat({
173
- content: `["u_ou1rs",":root","setLayout",{"width":200}]`,
174
- fileName: '样式配置步骤.json'
175
- })}
176
-
177
- 注意:当需要修改布局和尺寸信息时,仅返回用户要求的内容即可,无需返回所有的布局和尺寸信息属性。
178
- </setLayout>
179
-
180
- <doConfig>
181
- - 配置组件,使用<组件可配置的内容/>的配置项,对组件的属性或样式进行配置;
182
- - 如果配置项的type在 <常见editType的使用 /> 中有说明,务必遵守其中的说明及注意事项;
183
-
184
- - params的格式以Typescript的形式说明如下:
185
-
186
- \`\`\`typescript
187
- //配置样式
188
- type configStyle_params = {
189
- path:string,//在<当前组件可配置的内容/>中对应的配置项path
190
- style: {
191
- [key: string]: propertyValue; //元素的内联样式对象,仅能配置style编辑器description中声明的属性,不要超出范围。
192
- }
193
- }
194
-
195
- //配置属性
196
- type configProperty_params = {
197
- path:string,//在<当前组件可配置的内容/>中对应的配置项path
198
- value: any//需要配置的value
199
- }
200
- \`\`\`
201
-
202
- 例如:
203
- - 属性的配置:
204
- ${fileFormat({
205
- content: `["u_ou1rs",":root","doConfig",{"path":"常规/标题","value":"标题内容"}]`,
206
- fileName: '样式配置步骤.json'
207
- })}
208
-
209
- - 样式的配置:
210
- ${fileFormat({
211
- content: `["u_ou1rs",":root","doConfig",{"path":"常规/banner样式","style":{"backgroundColor":"red"}}]`,
212
- fileName: '样式配置步骤.json'
213
- })}
214
-
215
- 注意:
216
- - 当需要修改组件的样式时,只允许修改style编辑器description中声明的属性;
217
- - 当需要修改组件的样式时,背景统一使用background,而非backgroundColor等属性;
218
- </doConfig>
219
-
220
- <addChild>
221
- - addChild代表向目标组件的插槽中添加UI组件,需要满足两个条件:
222
- 1. 目标组件中目前有定义插槽,且已知插槽的id是什么;
223
- 2. 被添加的组件只能使用 <允许添加的组件/> 中声明的*UI组件*;
224
- - params的格式以Typescript的形式说明如下:
225
-
226
- \`\`\`typescript
227
- type add_params = {
228
- title:string //被添加组件的标题
229
- ns:string //在 <允许添加的组件 /> 中声明的UI组件namespace
230
- comId:string // 新添加的组件5位uuid,禁止重复,在所有UI组件中唯一
231
- index?: number | 'last' = 'last' // 添加到插槽的位置,index=0表示第一位,index=1表示第二位。不指定时默认为last,添加到末尾
232
- layout?: setLayout_flex_params | setLayout_fixed_params | setLayout_absolute_params //可选,添加组件时可以指定位置和尺寸信息
233
- configs?: Array<configStyle_params | configProperty_params> // 添加组件可以配置的信息
234
- // 渲染优化
235
- ignore?: boolean //可选,是否添加ignore标记
236
- enhance?: boolean //可选,是否添加enhance标记
237
- }
238
- \`\`\`
239
-
240
- 例如:
241
- - 添加文本组件到插槽末尾:
242
- ${fileFormat({
243
- content: `["u_ou1rs","content","addChild",{"title":"添加的文本组件","ns":"namespace占位","comId":"u_iiusd7"}]`,
244
- fileName: '添加文本组件步骤.json'
245
- })}
246
-
247
- - 添加组件带有配置属性,同时指定位置:
248
- ${fileFormat({
249
- content: `["u_ou1rs","content","addChild",{"title":"背景图","ns":"namespace占位","comId":"u_iiusd7","index":2,"layout":{"width":"100%","height":200,"marginTop":8,"marginLeft":12,"marginRight":12},"configs":[{"path":"常规/图片地址","value":"https://ai.mybricks.world/image-search?term=风景"},{"path":"样式/图片","style":{"borderRadius":"8px"}}]}]`,
250
- fileName: '添加带配置属性的步骤.json'
251
- })}
252
-
253
- - 添加组件带index指定位置:
254
- ${fileFormat({
255
- content: `["u_ou1rs","content","addChild",{"title":"添加的文本组件","ns":"namespace占位","comId":"u_iiusd7","index":2}]`,
256
- fileName: '添加带index指定位置的步骤.json'
257
- })}
258
-
259
- - 添加组件带ignore标记:
260
- ${fileFormat({
261
- content: `["u_ou1rs","content","addChild",{"title":"添加的布局组件","ns":"namespace占位","comId":"u_iiusd7","ignore": true}]`,
262
- fileName: '添加带ignore标记的步骤.json'
263
- })}
264
-
265
- 注意:
266
- - 新添加的组件ID必须使用5位唯一的字母数字组合,禁止重复,在所有UI组件中唯一;
267
- - index参数控制组件在插槽中的顺序位置。执行addChild前,需明确目标位置;
268
- </addChild>
269
-
270
- <move>
271
- - 移动组件,或者移动组件某个插槽下的所有组件
272
- - index为目标插槽的具体位置
273
- - 由于被添加的组件永远在最后一位,如果有位置要求,可以添加一个move操作来移动位置
274
-
275
- - params的格式以Typescript的形式说明如下:
276
- \`\`\`typescript
277
- type moveToComParams = {
278
- comId:string, // 移动到目标组件
279
- slotId:string, // 需要移动的目标插槽
280
- index:number, // 移动到的位置,index=0表示放到第一位,index=1表示放到第二位
281
- }
282
- \`\`\`
283
-
284
- 例如,当用户要求将组件u_ou1rs移动到组件u_iek32的某个插槽中,并且放到第一位,可以返回以下内容:
285
- ${fileFormat({
286
- content: `["u_ou1rs",":root","move",{"comId":"u_iek32","slotId":"插槽id","index":0}]`,
287
- fileName: '移动组件步骤.json'
288
- })}
289
- </move>
290
-
291
- <delete>
292
- - 删除组件
293
-
294
- 例如,当用户要求删除组件u_o21rs,可以返回以下内容:
295
- ${fileFormat({
296
- content: `["u_o21rs",":root","delete"]`,
297
- fileName: '删除组件整体.json'
298
- })}
299
-
300
- 注意:
301
- - 删除时,必须删除组件的整体,不能删除组件的某个部分,所以使用:root选择器。
302
- - 在规划多个action时,需要考虑delete对后续addChild、move操作中index参数的影响
303
- </delete>
304
-
305
- 注意:actions文件每一行遵循 JSON 语法,禁止非法代码,禁止出现内容省略提示、单行注释、省略字符。
306
- - actions返回的内容格式需要一行一个action,每一个action需要压缩,不要包含缩进等多余的空白字符;
307
- - 禁止包含任何注释(包括单行//和多行/* */)
308
- - 禁止出现省略号(...)或任何占位符
309
- - 确保所有代码都是完整可执行的,不包含示例片段
310
- - 禁止使用{}、{{}}这类变量绑定语法,并不支持此语法
311
- - 禁止使用非法字符或特殊符号
312
- - 所有内容均为静态数据,禁止解构,禁止使用变量
313
-
314
-
315
- 注意:
316
- - 返回actions文件内容时,务必注意操作步骤的先后顺序;
317
- - 有些操作需要在前面操作完成后才能进行;
318
- - 有些操作需要在其他操作开启(布尔类型的配置项)后才能进行;
319
- - 禁止重复使用相同的action;
320
- </关于actions>
321
-
322
- <UI搭建原则>
323
- 界面只有两类基本要素:组件、以及组件的插槽,组件的插槽可以嵌套其他组件。
324
-
325
- <组件的定位原则>
326
- 组件的定位有三种方式:flex定位、absolute定位、fixed定位。
327
-
328
- **flex定位**
329
- - 组件会相对于所在的插槽进行定位;
330
- - 通过尺寸(width、height) + 外间距(margin)来进行定位;
331
- - flex布局下的组件不允许使用left、top、right、bottom等定位属性;
332
-
333
- **absolute定位**
334
- - 组件会相对于当前组件的插槽进行定位,且脱离文档流;
335
- - 通过尺寸(width、height) + 位置(left、top、right、bottom)来进行定位;
336
- - absolute定位的组件不允许使用margin;
337
-
338
- 使用absolute定位的例子:
339
- ${fileFormat({
340
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个绝对定位组件","comId":"u_fixed","ns":"组件","layout":{"position":"absolute","width":"100%","height":84,"top":12,"left":0},"configs":[]}]`,
341
- fileName: '添加一个absolute定位组件.json'
342
- })}
343
-
344
- **fixed定位**
345
- - 组件会相对于整个画布进行定位,且脱离文档流;
346
- - 通过尺寸(width、height) + 位置(left、top、right、bottom)来进行定位;
347
- - fixed定位的组件不允许使用margin;
348
-
349
- 使用fixed定位的例子:
350
- ${fileFormat({
351
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个固定定位组件","comId":"u_fixed","ns":"组件","layout":{"position":"fixed","width":"100%","height":84,"bottom":0,"left":0},"configs":[]}]`,
352
- fileName: '添加一个fixed定位组件.json'
353
- })}
354
-
355
- 在插槽的不同布局下,组件的定位由所在插槽的布局方式决定:
356
- - 在当前组件的插槽中,可以添加fixed定位的组件,禁止在其他插槽中添加fixed定位的组件;
357
- - 如果插槽是flex布局,则子组件只能使用flex定位 或者 absolute定位;
358
- - 如果插槽是relative布局,则子组件只能使用absolute定位;
359
- </组件的定位原则>
360
-
361
- <布局原则>
362
- 插槽的布局(display=flex)指的是对于内部组件(仅对其直接子组件,对于子组件插槽中的子组件无影响)的布局约束:
363
-
364
- **flex布局**
365
- (基本等同于CSS3规范中的flex布局)插槽中的所有子组件通过宽高和margin进行布局。
366
-
367
- <辅助标记使用>
368
- 在mybricks中,组件最终会绘制到搭建画布上,确定所有组件的尺寸和位置,可以将多余的嵌套布局组件优化掉,所以需要通过辅助标记ignore来忽略多余的嵌套布局。
369
- 配置流程如下:
370
- 当布局组件的父组件也为布局组件时,观察当前组件是否配置样式(边框、背景、内间距等),是否可能需要支持事件(点击),父组件是否也是布局组件?
371
- - 1. 如果布局组件不配置样式也不需要点击功能,可以添加ignore标记,表示该布局组件仅承担布局功能,可以被优化掉;
372
- - 2. 如果布局组件配置了样式或者有可能需要点击功能,不能添加ignore标记,表示该布局组件承担样式功能,不能被优化掉;
373
- - 2.1 如何判断有没有可能需要支持事件?
374
- - 2.1.1 如果当前布局为图标+文本等常见的导航入口,猜测该布局组件后续需要支持点击功能,不能添加ignore标记;
375
- - 3. 如果布局组件的父组件不是布局组件,或者是根组件,不能添加ignore标记,不能被优化掉;
376
-
377
- 例子:第一个布局组件仅承担布局功能,可以添加ignore标记;第二个布局组件承担样式功能,不能添加ignore标记。
378
- ${fileFormat({
379
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_layout","ignore":true,"ns":"组件","layout":{"width":"100%","height":120},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","alignItems":"center"}}]}]
380
- ["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_layout","ns":"组件","layout":{"width":"100%","height":120},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","alignItems":"center"}},{"path":"样式/样式","style":{"background":"#FFFFFF"}}]}]
381
- `,
382
- fileName: '辅助标记.json'
383
- })}
384
-
385
- </辅助标记使用>
386
-
387
- <布局使用示例>
388
- **flex布局**
389
- 子组件通过嵌套来搭建,无需考虑子组件的宽度和高度。
390
-
391
- 下面的例子使用flex实现左侧固定宽度,右侧自适应布局:
392
- ${fileFormat({
393
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_flex1","ns":"布局组件","layout":{"width":"100%","height":60},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","alignItems":"center"}}]}]
394
- ["u_flex1","插槽id占位","addChild",{"title":"左侧固定宽度组件","comId":"u_leftFixed","ns":"组件","layout":{"width":60,"height":40,"marginRight":8},"configs":[]}]
395
- ["u_flex1","插槽id占位","addChild",{"title":"右侧自适应组件","comId":"u_rightFlex","ns":"组件","layout":{"width":'100%',"height":40},"configs":[]}]
396
- `,
397
- fileName: '左侧固定右侧自适应.json'
398
- })}
399
- 在上例中:
400
- - 声明布局编辑器的值,注意布局编辑器必须声明,其中flexDirection也必须声明,关注justifyContent效果,默认为flex-start;
401
- - 左侧组件使用固定宽度,右侧组件使用width=100%(效果等同于flex=1)实现自适应宽度;
402
- - 通过marginRight配置左侧组件与右侧组件的间距;
403
-
404
-
405
- 下面的例子使用flex进行嵌套,来实现左侧图标+文本,右侧箭头的布局:
406
- ${fileFormat({
407
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_flex1","ns":"布局组件","layout":{"width":"100%","height":60},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","justifyContent":"space-between","alignItems":"center"}}]}]
408
- ["u_flex1","插槽id占位","addChild",{"title":"左侧布局组件","comId":"u_leftLayout","ignore": true,"ns":"布局组件","layout":{"width":"fit-content","height":"fit-content"},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","alignItems":"center", "justifyContent": "flex-start"}}]}]
409
- ["u_leftLayout","插槽id占位","addChild",{"title":"图标组件","comId":"u_icon","ns":"图标组件","layout":{"width":24,"height":24,"marginRight":8},"configs":[]}]
410
- ["u_leftLayout","插槽id占位","addChild",{"title":"文本组件","comId":"u_text","ns":"文本组件","layout":{"width":"fit-content","height":"fit-content"},"configs":[]}]
411
- ["u_flex1","插槽id占位","addChild",{"title":"箭头图标组件","comId":"u_arrowIcon","ns":"图标组件","layout":{"width":24,"height":24},"configs":[]}]
412
- `,
413
- fileName: 'flex嵌套实现左右布局.json'
414
- })}
415
- 在上例中:
416
- - 声明布局编辑器的值,注意布局编辑器必须声明,其中flexDirection也必须声明;
417
- - 使用嵌套布局来完成左侧多元素 + 右侧单元素的布局,默认justifyContent=flex-start,所以左侧布局无需设置;
418
- - 左侧的图标+文本使用嵌套布局实现,且添加ignore标记,表示仅承担布局功能;
419
-
420
- 下面的例子使用flex实现垂直居中布局:
421
- ${fileFormat({
422
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_flex2","ns":"布局组件","layout":{"width":"100%","height":120},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"column","alignItems":"center"}}]}]
423
- ["u_flex2","插槽id占位","addChild",{"title":"子组件","comId":"u_child","ns":"组件","layout":{"width":80,"height":80},"configs":[]}]
424
- `,
425
- fileName: '垂直居中布局.json'
426
- })}
427
- 在上例中:
428
- - 声明布局编辑器的值,注意布局编辑器必须声明,其中flexDirection声明成column;
429
- - 通过alignItems来实现子组件的垂直居中;
430
-
431
- 下面的例子使用flex进行横向左右均分布局,实现各占一半的效果:
432
- ${fileFormat({
433
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_flex3","ignore": true,"ns":"布局组件","layout":{"width":"100%","height":120},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","justifyContent":"space-between","alignItems":"center"}}]}]
434
- ["u_flex3","插槽id占位","addChild",{"title":"A组件","comId":"u_a321s","ns":"组件","layout":{"width":"auto","height":40,"marginRight":8},"configs":[]}]
435
- ["u_flex3","插槽id占位","addChild",{"title":"B组件","comId":"u_b321s","ns":"组件","layout":{"width":"auto","height":40},"configs":[]}]
436
- `,
437
- fileName: '左右各占一半布局.json'
438
- })}
439
- 在上例中:
440
- - 为了实现各占一半,配置A组件和B组件的宽度都为自适应auto(效果等同于flex=1),实现各占一半的效果;
441
- - 注意:不允许配置百分比宽度;
442
- - 判断仅布局,添加ignore标记,优化搭建内容。
443
- - 通过marginRight配置左侧组件与右侧组件的间距;
444
-
445
- 下面的例子使用flex进行横向均分或等分布局,实现一行N列的效果:
446
- ${fileFormat({
447
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_flex4","ignore": true,"ns":"布局组件","layout":{"width":"100%","height":120},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","justifyContent":"space-between","alignItems":"center"}}]}]
448
- ["u_flex4","插槽id占位","addChild",{"title":"A组件","comId":"u_aksi","ns":"组件","layout":{"width":40,"height":40},"configs":[]}]
449
- ["u_flex4","插槽id占位","addChild",{"title":"B组件","comId":"u_b293e","ns":"组件","layout":{"width":40,"height":40},"configs":[]}]
450
- ["u_flex4","插槽id占位","addChild",{"title":"C组件","comId":"u_csim2","ns":"组件","layout":{"width":40,"height":40},"configs":[]}]
451
- `,
452
- fileName: '一行N列布局.json'
453
- })}
454
- 在上例中:
455
- - 声明布局编辑器的值,注意布局编辑器必须声明,其中flexDirection也必须声明;
456
- - 针对内容元素的尺寸,配置合理的高度,防止内容溢出;
457
- - 为了实现均分,保证卡片之间存在间距,配置卡片宽度和高度都为固定值
458
- - 注意:不允许配置百分比宽度;
459
- - 判断仅布局,添加ignore标记,优化搭建内容。
460
-
461
- 下面的例子展示flex布局中负margin的妙用,通过负margin实现背景层+内容层重叠的效果:
462
- ${fileFormat({
463
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_flex6","ns":"布局组件","layout":{"width":"100%","height":"fit-content"},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"column"}}]}]
464
- ["u_flex6","插槽id占位","addChild",{"title":"背景层","comId":"u_asds6","ns":"组件","layout":{"width":"100%","height":60},"configs":[]}]
465
- ["u_flex6","插槽id占位","addChild",{"title":"内容层","comId":"u_csdt6","ns":"组件","layout":{"width":"100%","height":100, "marginTop": -30},"configs":[]}]
466
- `,
467
- fileName: '负margin实现背景层+内容层重叠.json'
468
- })}
469
- 在上例中:
470
- - 声明布局编辑器的值,注意布局编辑器必须声明,其中flexDirection也必须声明;
471
- - 通过负margin实现背景层+内容层重叠的效果;
472
-
473
- 特殊地,在flex布局中的元素还可以配置position=absolute,用于实现绝对定位效果:
474
- ${fileFormat({
475
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_flex5","ns":"布局组件","layout":{"width":"100%","height":200},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row","alignItems":"center"}}]}]
476
- ["u_flex5","插槽id占位","addChild",{"title":"绝对定位组件","comId":"u_abs12","ns":"组件","layout":{"position":"absolute","width":100,"height":40,"top":20,"left":20},"configs":[]}]
477
- ["u_flex5","插槽id占位","addChild",{"title":"普通组件","comId":"u_nor12","ns":"组件","layout":{"width":80,"height":80},"configs":[]}]
478
- `,
479
- fileName: '绝对定位效果.json'
480
- })}
481
- 在上例中:
482
- - 声明布局编辑器的值,注意布局编辑器必须声明,其中flexDirection也必须声明;
483
- - 通过layout中的属性,设置成绝对定位效果,在一些特殊的角标等场景下很有效果;
484
-
485
- **自由定位布局**
486
- 子组件通过自由定位来布局,无需考虑其他组件的布局影响。
487
- 下面的例子使用absolute实现自由定位布局:
488
- ${fileFormat({
489
- content: `["目标组件id","插槽id占位","addChild",{"title":"添加一个布局组件","comId":"u_absoluteLayout","ns":"布局组件","layout":{"width":"100%","height":300},"configs":[{"path":"常规/布局","value":{"position":"relative"}}]}]
490
- ["u_absoluteLayout","插槽id占位","addChild",{"title":"绝对定位组件A","comId":"u_absA","ns":"组件","layout":{"position":"absolute","width":100,"height":40,"top":20,"left":20},"configs":[]}]
491
- ["u_absoluteLayout","插槽id占位","addChild",{"title":"绝对定位组件B","comId":"u_absB","ns":"组件","layout":{"position":"absolute","width":80,"height":80,"top":100,"left":150},"configs":[]}]
492
- `,
493
- fileName: 'absolute自由定位布局.json'
494
- })}
495
- 在上例中:
496
- - 宽高不可以配置fit-content,防止内容塌陷;
497
- - 声明布局编辑器的值,注意布局编辑器必须声明,其中position声明成relative;
498
- - 通过layout中的属性,设置成绝对定位效果,实现自由定位布局;
499
- </布局使用示例>
500
-
501
- <布局的选用:重要>
502
- 由于是修改组件,优先参考*原有组件的布局*进行搭建,除非用户有明确要求,否则不建议更改布局方式。
503
- - 如果当前组件使用的是flex布局,优先使用flex布局进行搭建;
504
- - 如果当前组件使用的是absolute布局,优先使用absolute布局进行搭建;
505
- </布局的选用:重要>
506
-
507
- <布局注意事项>
508
- - 布局相关组件在添加时必须配置布局编辑器的值,尤其需要配置flexDirection和justifyContent;
509
- - 对于flexDirection,必须配置,仅允许配置row或column;
510
- - 优先考虑fit-content,如果要使用固定宽高,必须考虑到固定宽高会不会溢出导出布局错乱的问题;
511
- <布局注意事项>
512
-
513
- </布局原则>
514
-
515
- <最佳实践>
516
- 1. 对每一个组件,都仔细考虑是否要使用<辅助标记 />,按照<辅助标记使用 />来配置标记;
517
- 2. 对于文本、图片、图标、按钮等基础组件,任何情况下都可以优先使用,即使不在允许使用的组件里;
518
- 3. 对于图标,图标禁止使用emoji或者特殊符号,必须使用图标组件来搭建;
519
- 4. 关于图片
520
- 4.1 如果是常规图片,使用https://ai.mybricks.world/image-search?term=dog&w=100&h=200,其中term代表搜索词,w和h可以配置图片宽高;
521
- 4.2 如果是Logo,可以使用https://placehold.co来配置一个带文本和颜色的图标,其中text需要为图标的英文搜索词,禁止使用emoji或者特殊符号;
522
- 5. 对于文本,尺寸的计算
523
- - 宽度和高度要根据fontSize等样式来计算,预留更多的空间;
524
- - 尽量配置文本省略参数,防止一行换行后变多行带来的布局变化;
525
- - 文本最小大小可以配置到fontSize=10,在一些文字内容特别多的场景可以配置小文字;
526
- 8. 子组件计算尺寸(宽度与高度)的时候,需要向上考虑父元素(插槽、父组件或祖先插槽及组件)所有的尺寸与间距等样式,否则容易计算错误;
527
- 9. 对于横向排列或者竖向排列的多个相似元素,考虑如下情况:
528
- - 如果猜测是动态项,使用列表类组件来搭建;
529
- - 如果猜测是静态内容,优先使用布局,N行M列来搭建;
530
- - 如果是属于某个组件的内容,使用组件来搭建;
531
- </最佳实践>
532
- </UI搭建原则>
533
- </如何搭建UI以及修改>
534
-
535
- ${config.appendPrompt ? `<对于项目环境的说明>
536
- ${config.appendPrompt}
537
- </对于项目环境的说明>` : ''}
538
-
539
- <examples>
540
- <example>
541
- <user_query>文本组件替换成图片</user_query>
542
- <assistant_response>
543
- 好的,我将文本组件替换成图片组件。当前文本组件在插槽的第一位(index=0),删除后我需要在相同位置添加图片组件,所以指定index=0。
544
-
545
- ${fileFormat({
546
- content: `["u_24uiu",":root","delete"]
547
- ["u_parent","slotId","addChild",{"title":"添加一个图片组件","comId":"u_image1","index":0,"ns":"图片组件","layout":{"width":100,"height":100}}]`,
548
- fileName: '将文本组件替换成图片.json'
549
- })}
550
- </assistant_response>
551
- </example>
552
-
553
- <example>
554
- <user_query>宽度改成适应内容</user_query>
555
- <assistant_response>
556
- 好的,我将当前组件的宽度做适应内容的调整
557
-
558
- ${fileFormat({
559
- content: `["u_908", ":root", "setLayout", {"width":"fit-content"}]`,
560
- fileName: '修改宽度.json'
561
- })}
562
- </assistant_response>
563
- </example>
564
-
565
- <example>
566
- <user_query>改成蓝色风格</user_query>
567
- <assistant_response>
568
- 好的,我将当前组件的配色以及子组件统一修改为蓝色风格
569
-
570
- ${fileFormat({
571
- content: `["u_222", ":root", "doConfig", {"path":"样式/背景色","style":{"background": "blue"}}]
572
- ["u_child2", ":root", "doConfig", {"path":"样式/背景色","style":{"background": "blue"}}]`,
573
- fileName: '修改颜色.json'
574
- })}
575
- </assistant_response>
576
- </example>
577
-
578
- <example>
579
- <user_query>查看我的效果图,重构这个区域</user_query>
580
- <assistant_response>
581
- 根据图片效果,主要执行以下修改:
582
- 1. 容器原来是均分布局,为了实现效果图中的效果,需要修改为左右布局,左侧为图标+文本,右侧为箭头;
583
- 2. 删除容器中原有的按钮,替换成图标+文本,替换可以使用指定位置的addChild来完成,先添加左侧容器,再添加图标和文本;
584
- 3. 中间有一个装饰图片 ,flex布局下不好实现,用绝对定位实现;
585
-
586
- ${fileFormat({
587
- content: `["u_24uiu", ":root", "doConfig", {"path":"样式/布局","style":{"display": "flex", "flexDirection": "row", "justifyContent": "space-between", "alignItems": "center"}}]
588
- ["u_iobtn", ":root", "delete"]
589
- ["u_24uiu", "slotId", "addChild", {"title":"左侧容器","comId":"u_sdflx","index":0,"ns":"布局组件","layout":{"width":"fit-content","height":60, "marginLeft": 12},"configs":[{"path":"常规/布局","value":{"display":"flex","flexDirection":"row"}}]}]
590
- ["u_sdflex", "addChild", {"title":"图标组件","comId":"u_icon","index":0,"ns":"图标组件","layout":{"width":24,"height":24,"marginLeft":8},"configs":[]}]
591
- ["u_sdflex", "addChild", {"title":"文本组件","comId":"u_text","index":1,"ns":"文本组件","layout":{"width":"fit-content","height":"fit-content", "marginLeft": 8},"configs":[]}]
592
- ["u_sdflex", "addChild", {"title":"箭头图标组件","comId":"u_rso0c","index":2,"ns":"图标组件","layout":{"width":24,"height":24},"configs":[]}]
593
- ["u_24uiu", "slotId", "addChild", {"title":"装饰组件","comId":"u_abs1","ns":"布局组件","layout":{"position": "absolute", "width": 100, "height": 30, "bottom": 0, "left": 360},"configs":[]}]
594
- `,
595
- fileName: '重构区域.json'
596
- })}
597
- </assistant_response>
598
- </example>
599
-
600
- <example>
601
- <user_query>优化下这个排版</user_query>
602
- <assistant_response>
603
- 好的,我们分析下目前的搭建内容,排版上来看,当前原有组件的是绝对定位处理的,可以看出来有几个问题:
604
- 1. 元素之间没有对齐,显得比较杂乱;
605
- 2. 作为头像来说,图片大小不合适,改成宽高一致并左边垂直居中;
606
- 3. 元素之间位置有问题,看起来有几处重叠。
607
-
608
- 我们优先使用当前布局,然后通过调整各个组件的位置和尺寸信息完成需求。
609
-
610
- 我们调整下看看效果
611
- ${fileFormat({
612
- content: `["u_text1", ":root", "setLayout", {"position": "absolute", "width": 200, "height": 40, "top": 20, "left": 20}]
613
- ["u_image1", ":root", "setLayout", {"position": "absolute", "width": 100, "height": 100, "top": 80, "left": 20}]
614
- ["u_button1", ":root", "setLayout", {"position": "absolute", "width": 80, "height": 40, "top": 200, "left": 20}]`,
615
- fileName: '优化排版.json'
616
- })}
617
-
618
- 注意:父组件有内间距,插槽才是实际可布局区域,根据插槽宽度来计算居中。
619
- </assistant_response>
620
- </example>
621
- </examples>`
622
- },
623
- aiRole: config.getFocusElementAiRole?.() || (hasChildren ? 'expert' : 'architect'),
624
- stream({ files, status, replaceContent }) {
625
- let actions: any = [];
626
- const actionsFile = getFiles(files, { extName: 'json' })
627
-
628
- if (actionsFile) {
629
- actions = streamActionsParser(actionsFile.content ?? "", actionsFile?.isComplete);
630
- actions = fixActions(actions, {
631
- pageId
632
- })
633
- if (!fileNameToContent[actionsFile!.fileName]) {
634
- fileNameToContent[actionsFile!.fileName] = "";
635
- }
636
-
637
- if (actions?.[0]?.comId && !firstActionId) {
638
- firstActionId = actions?.[0]?.comId;
639
-
640
- if (firstActionId !== "_root_" && firstActionId !== pageId) {
641
- actionType = 'uiCom'
642
- }
643
-
644
- promiseStack.add(() => config.onActions([], 'start', actionType))
645
- }
646
- }
647
-
648
- if (actions.length > 0 || status === 'complete') {
649
- const currentStatus = status === 'complete' ? "ing" : status;
650
- try {
651
- const copiedActions = JSON.parse(JSON.stringify(actions));
652
- try {
653
- actions.forEach((action: any) => {
654
- if (action.type === "addChild") {
655
- const childComId = action.params.comId;
656
- // 对于 addChild,每次添加都生成新的 UUID 映射
657
- action.params.comId = comIdTransform.addComId(childComId);
658
-
659
- // 目标组件ID需要映射
660
- const parentComId = action.comId;
661
- if (parentComId !== "_root_") {
662
- // 父组件 id 使用最近一次的映射
663
- action.comId = comIdTransform.getComId(parentComId);
664
- }
665
- } else if (action.type === "move") {
666
- const comId = action.comId;
667
- if (comId !== "_root_") {
668
- // 获取组件时,使用最近添加的comId
669
- action.comId = comIdTransform.getComId(comId);
670
- }
671
-
672
- // 目标组件ID需要映射
673
- const toParams = action.params?.to ?? {};
674
- const targetId = toParams.comId;
675
- if (targetId && targetId !== "_root_") {
676
- action.params.to.comId = comIdTransform.getComId(targetId);
677
- }
678
- } else if (action.type === "doConfig") {
679
- const comId = action.comId;
680
- if (comId !== "_root_") {
681
- // 获取组件时,使用最近添加的comId
682
- action.comId = comIdTransform.getComId(comId);
683
- }
684
- }
685
- })
686
- actions.forEach((action: any) => {
687
- promiseStack.add(() => config.onActions([action], currentStatus, actionType))
688
- })
689
- } catch (error) {
690
- console.error('refactor-component onActions error', error);
691
- }
692
- const actionsContent = getComponentOperationSummary(copiedActions, config.componentIdToTitleMap)
693
-
694
- if (actionsFile) {
695
- if (!fileNameToContent[actionsFile!.fileName]) {
696
- fileNameToContent[actionsFile!.fileName] = actionsContent.trim();
697
- } else {
698
- fileNameToContent[actionsFile!.fileName] += `\n${actionsContent.trim()}`;
699
- }
700
- }
701
- } catch (error) {}
702
-
703
- if (status === "complete") {
704
- promiseStack.add(() => config.onActions([], status, actionType))
705
- }
706
- }
707
-
708
- return displayContent = Object.entries(fileNameToContent).reduce((pre, [fileName, content]) => {
709
- return pre.replace(fileName, content);
710
- }, replaceContent)
711
- },
712
- execute({ files, content }) {
713
- let errorContent;
714
- try {
715
- errorContent = JSON.parse(content)
716
- } catch (error) { }
717
- if (errorContent && errorContent?.message) {
718
- throw new RxaiError(`网络错误,${errorContent?.message}`, "request")
719
- }
720
-
721
- let actions: any = [];
722
- const actionsFile = getFiles(files, { extName: 'json' })
723
-
724
- if (!actionsFile) {
725
- return {
726
- llmContent: content,
727
- displayContent: content
728
- }
729
- }
730
-
731
- return {
732
- llmContent: displayContent,
733
- displayContent: displayContent
734
- }
735
-
736
- // actions = excuteActionsParser(actionsFile.content ?? "");
737
-
738
- // // console.log('actions', actions)
739
-
740
- // // const actionsGroupById = actions.reduce((acc, item) => {
741
- // // const id = item.comId;
742
- // // if (!acc[id]) {
743
- // // acc[id] = [];
744
- // // }
745
- // // acc[id].push(item);
746
- // // return acc;
747
- // // }, {});
748
-
749
- // try {
750
- // const llmContent = stripFileBlocks(content);
751
- // const actionsContent = actions?.length ? getComponentOperationSummary(actions, OutlineInfo.getComponentIdToTitleMap(config?.getPageJson(), pageId)) : ""
752
- // const summary = (llmContent ? `${llmContent}\n\n` : "") + (actionsContent ? `修改内容如下\n${actionsContent}` : "当前没有内容修改");
753
-
754
- // return {
755
- // llmContent: summary,
756
- // displayContent: summary
757
- // }
758
-
759
- // // const summary = getComponentOperationSummary(actions, OutlineInfo.getComponentIdToTitleMap(config?.getPageJson(), pageId))
760
-
761
- // // return {
762
- // // llmContent: `根据需求,我们进行如下修改
763
- // // ${summary}`,
764
- // // displayContent: `根据需求,我们进行如下修改
765
- // // ${summary}`
766
- // // }
767
- // } catch (error) {
768
-
769
- // }
770
-
771
- // return {
772
- // llmContent: '已执行所有修改操作',
773
- // displayContent: '已执行所有修改操作'
774
- // }
775
- },
776
- }
777
- }
778
-
779
- function fixActions(actions: any[], {
780
- pageId
781
- }: {
782
- pageId?: string
783
- }) {
784
- return (actions ?? []).map(action => {
785
- if (action.comId === pageId) {
786
- action.comId = '_root_'
787
- }
788
- return action;
789
- })
790
- }
791
-
792
- export interface RefactorUiContentConfigParams {
793
- fewShots: string;
794
- }
795
-
796
- export function RefactorUiContent(params?: RefactorUiContentConfigParams) {
797
- return {
798
- name: NAME,
799
- params: params,
800
- }
801
- }