@mybricks/plugin-ai 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/package.json +7 -2
  2. package/src/agents/app.ts +188 -60
  3. package/src/agents/common.ts +428 -68
  4. package/src/agents/custom.ts +14 -0
  5. package/src/agents/index.ts +31 -1
  6. package/src/agents/knowledges/README.md +614 -0
  7. package/src/agents/knowledges/SUMMARY.md +527 -0
  8. package/src/agents/knowledges/index.ts +8 -0
  9. package/src/agents/knowledges/knowledge-base.ts +565 -0
  10. package/src/agents/knowledges/knowledge-node.ts +266 -0
  11. package/src/agents/knowledges/types.ts +208 -0
  12. package/src/agents/utils/config.ts +427 -0
  13. package/src/agents/workspace/coding-manager.ts +31 -0
  14. package/src/agents/workspace/components-manager.ts +124 -0
  15. package/src/agents/workspace/outline-focus.ts +188 -0
  16. package/src/agents/workspace/outline-info.ts +520 -0
  17. package/src/agents/workspace/page-tree-generator.ts +83 -0
  18. package/src/agents/workspace/workspace.ts +319 -0
  19. package/src/agents/workspace-by-knowledges/MIGRATION.md +568 -0
  20. package/src/agents/workspace-by-knowledges/README.md +521 -0
  21. package/src/agents/workspace-by-knowledges/index.ts +11 -0
  22. package/src/agents/workspace-by-knowledges/providers/component-docs-provider.ts +92 -0
  23. package/src/agents/workspace-by-knowledges/providers/focus-info-provider.ts +131 -0
  24. package/src/agents/workspace-by-knowledges/providers/index.ts +8 -0
  25. package/src/agents/workspace-by-knowledges/providers/project-info-provider.ts +151 -0
  26. package/src/agents/workspace-by-knowledges/test.ts +240 -0
  27. package/src/agents/workspace-by-knowledges/types.ts +56 -0
  28. package/src/agents/workspace-by-knowledges/utils/components-manager.ts +145 -0
  29. package/src/agents/workspace-by-knowledges/utils/index.ts +8 -0
  30. package/src/agents/workspace-by-knowledges/utils/outline-focus.ts +178 -0
  31. package/src/agents/workspace-by-knowledges/utils/outline-info.ts +521 -0
  32. package/src/agents/workspace-by-knowledges/workspace.ts +166 -0
  33. package/src/api/cloud-components.ts +129 -0
  34. package/src/api-record-replay/README.md +187 -0
  35. package/src/api-record-replay/index.ts +11 -0
  36. package/src/api-record-replay/manager.ts +168 -0
  37. package/src/api-record-replay/recorder.ts +117 -0
  38. package/src/api-record-replay/replayer.ts +148 -0
  39. package/src/components/attachments/index.less +117 -0
  40. package/src/components/attachments/index.tsx +136 -0
  41. package/src/components/icons/index.tsx +21 -1
  42. package/src/components/index.less +34 -0
  43. package/src/components/mention/index.less +23 -0
  44. package/src/components/mention/index.tsx +19 -0
  45. package/src/components/messages/index.less +444 -237
  46. package/src/components/messages/index.tsx +371 -88
  47. package/src/components/sender/index.less +203 -0
  48. package/src/components/sender/index.tsx +298 -0
  49. package/src/components/types.ts +31 -0
  50. package/src/constants/index.ts +8 -0
  51. package/src/context/RequestStatusTracker.ts +50 -0
  52. package/src/context/index.ts +68 -6
  53. package/src/{types.d.ts → global.d.ts} +40 -5
  54. package/src/index.tsx +212 -32
  55. package/src/preset/agents.ts +380 -0
  56. package/src/preset/createTemplates.ts +25 -0
  57. package/src/preset/index.ts +12 -0
  58. package/src/preset/prompts.ts +235 -0
  59. package/src/preset/requestAsStream.ts +246 -0
  60. package/src/preset/user.ts +6 -0
  61. package/src/startView/components/header/header.less +17 -0
  62. package/src/startView/components/header/header.tsx +15 -0
  63. package/src/startView/components/index.ts +1 -0
  64. package/src/startView/index.less +22 -204
  65. package/src/startView/index.tsx +35 -203
  66. package/src/tools/analyze-and-expand-prd.ts +192 -86
  67. package/src/tools/analyze-requirement-and-components.ts +589 -0
  68. package/src/tools/answer.ts +59 -0
  69. package/src/tools/build-process.ts +1174 -0
  70. package/src/tools/coding-subagent-as-tool.ts +119 -0
  71. package/src/tools/generate-ui-content.ts +1083 -0
  72. package/src/tools/index.ts +22 -19
  73. package/src/tools/open-dsl.ts +69 -0
  74. package/src/tools/refactor-ui-content.ts +801 -0
  75. package/src/tools/utils.ts +880 -28
  76. package/src/types/index.ts +4 -0
  77. package/src/view/components/header/header.less +36 -2
  78. package/src/view/components/header/header.tsx +47 -2
  79. package/src/view/components/index.ts +0 -2
  80. package/src/view/index.tsx +158 -8
  81. package/src/tools/answer-user.ts +0 -35
  82. package/src/tools/focus-element.ts +0 -47
  83. package/src/tools/generate-page.ts +0 -750
  84. package/src/tools/get-component-info-by-ids.ts +0 -166
  85. package/src/tools/get-component-info.ts +0 -53
  86. package/src/tools/get-components-doc-and-prd.ts +0 -137
  87. package/src/tools/get-focus-mybricks-dsl.ts +0 -26
  88. package/src/tools/get-mybricks-dsl.ts +0 -73
  89. package/src/tools/modify-component.ts +0 -385
  90. package/src/view/components/messages/messages.less +0 -228
  91. package/src/view/components/messages/messages.tsx +0 -172
  92. package/src/view/components/sender/sender.less +0 -44
  93. package/src/view/components/sender/sender.tsx +0 -62
@@ -0,0 +1,119 @@
1
+ import type { CodingManager } from '../agents/workspace/coding-manager'
2
+ import { requestVibeCodingAgent } from '../agents/custom'
3
+
4
+ const NAME = 'coding-subagent-as-tool'
5
+ codingSubagentAsTool.toolName = NAME
6
+
7
+ interface Config {
8
+ codingManager: CodingManager,
9
+ onStart: () => void,
10
+ onComplete: () => void,
11
+ onError: () => void,
12
+ }
13
+
14
+ function getBatchCodingPayload(codingManager: CodingManager, getUserMessage: () => string | any) {
15
+ const codings = [...codingManager.waitForCoding]
16
+ const userMessageContent = getUserMessage?.()?.content
17
+
18
+ const userText = Array.isArray(userMessageContent) ? userMessageContent?.find(m => m.type === 'text')?.text : userMessageContent
19
+ const message = `
20
+ <用户需求>
21
+ ${userText}
22
+ </用户需求>
23
+ # 批量组件代码开发任务
24
+
25
+ ## 当前页面结构
26
+ ${codingManager.getJsxById(codingManager.pageId)}
27
+
28
+ ## 任务说明
29
+ 需要按顺序和用户需求开发以下 ${codings.length} 个组件。
30
+
31
+ ## 待开发组件
32
+
33
+ ${codings
34
+ .map(
35
+ (coding, index) =>
36
+ `### 组件 ${index + 1}: ${coding.comId}
37
+ **需求描述:**
38
+ ${coding.requirement}`
39
+ )
40
+ .join('\n\n')}
41
+ `
42
+ return {
43
+ key: `vibe_coding_${codingManager.pageId}_${Math.random().toString(36).substring(2, 15)}`,
44
+ message,
45
+ attachments: codingManager.attachments,
46
+ pageId: codingManager.pageId,
47
+ }
48
+ }
49
+
50
+ function onDevelopModule(
51
+ p: { files: Array<{ fileName: string; content: string }> },
52
+ updateComponent: (comId: string, files: Array<{ fileName: string; content: string }>) => void
53
+ ) {
54
+ const { files } = p
55
+ const filesByUuid = files.reduce(
56
+ (acc, file) => {
57
+ const match = file.fileName.match(/^(.+)@([^.]+)(\..+)$/)
58
+ if (match) {
59
+ const [, name, uuid, ext] = match
60
+ if (!acc[uuid]) acc[uuid] = []
61
+ acc[uuid].push({ fileName: `${name}${ext}`, content: file.content })
62
+ }
63
+ return acc
64
+ },
65
+ {} as Record<string, Array<{ fileName: string; content: string }>>
66
+ )
67
+ Object.entries(filesByUuid).forEach(([uuid, componentFiles]) => {
68
+ updateComponent(uuid, componentFiles)
69
+ })
70
+ }
71
+
72
+ export default function codingSubagentAsTool(config: Config): any {
73
+ return {
74
+ name: NAME,
75
+ displayName: '代码开发',
76
+ description: `执行「AI区域开发」:当生成页面时添加了需要开发代码的AI组件时,调用智能组件助手批量开发/还原这些组件的代码。无需规划此工具,此工具会自行调用。`,
77
+ async execute({ getUserMessage }) {
78
+ const { codingManager, onStart, onComplete, onError } = config
79
+ if (!codingManager.waitForCoding.length) {
80
+ return {
81
+ llmContent: '当前没有需要开发的组件。',
82
+ displayContent: '当前没有需要开发的组件。',
83
+ }
84
+ }
85
+ onStart?.();
86
+ const payload = getBatchCodingPayload(codingManager, getUserMessage)
87
+ return new Promise<{ llmContent: string; displayContent: string }>((resolve, reject) => {
88
+ const onProgress = (status: string) => {
89
+ if (status === 'complete') {
90
+ onComplete?.();
91
+ resolve({ llmContent: '代码开发已完成。', displayContent: '代码开发已完成。' })
92
+ }
93
+ if (status === 'error') {
94
+ onError?.();
95
+ reject(new Error('开发出问题了'))
96
+ }
97
+ }
98
+ const promise = requestVibeCodingAgent(
99
+ {
100
+ ...payload,
101
+ onProgress,
102
+ onDevelopModule,
103
+ asTool: true,
104
+ },
105
+ { pageId: payload.pageId }
106
+ )
107
+ if (!promise) {
108
+ onError?.();
109
+ reject(new Error('此工具暂不支持调用'))
110
+ return
111
+ }
112
+ promise.catch((error) => {
113
+ onError?.();
114
+ reject(error);
115
+ })
116
+ })
117
+ },
118
+ }
119
+ }