@mybricks/plugin-ai 0.0.1 → 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 (203) 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/dist/api-record-replay/recorder.js +107 -0
  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/dist/preset/user.js +7 -0
  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 +33 -6
  168. package/src/agents/app.ts +0 -173
  169. package/src/agents/common.ts +0 -111
  170. package/src/agents/index.ts +0 -7
  171. package/src/components/icons/index.less +0 -8
  172. package/src/components/icons/index.tsx +0 -24
  173. package/src/components/messages/index.less +0 -806
  174. package/src/components/messages/index.tsx +0 -236
  175. package/src/context/index.ts +0 -21
  176. package/src/data.ts +0 -5
  177. package/src/index.tsx +0 -84
  178. package/src/mock.ts +0 -1267
  179. package/src/startView/index.less +0 -216
  180. package/src/startView/index.tsx +0 -229
  181. package/src/tools/analyze-and-expand-prd.ts +0 -166
  182. package/src/tools/answer-user.ts +0 -35
  183. package/src/tools/focus-element.ts +0 -47
  184. package/src/tools/generate-page.ts +0 -750
  185. package/src/tools/get-component-info-by-ids.ts +0 -166
  186. package/src/tools/get-component-info.ts +0 -53
  187. package/src/tools/get-components-doc-and-prd.ts +0 -137
  188. package/src/tools/get-focus-mybricks-dsl.ts +0 -26
  189. package/src/tools/get-mybricks-dsl.ts +0 -73
  190. package/src/tools/index.ts +0 -25
  191. package/src/tools/modify-component.ts +0 -385
  192. package/src/tools/type.d.ts +0 -12
  193. package/src/tools/utils.ts +0 -62
  194. package/src/types.d.ts +0 -65
  195. package/src/view/components/header/header.less +0 -17
  196. package/src/view/components/header/header.tsx +0 -15
  197. package/src/view/components/index.ts +0 -3
  198. package/src/view/components/messages/messages.less +0 -228
  199. package/src/view/components/messages/messages.tsx +0 -172
  200. package/src/view/components/sender/sender.less +0 -44
  201. package/src/view/components/sender/sender.tsx +0 -62
  202. package/src/view/index.less +0 -5
  203. package/src/view/index.tsx +0 -18
@@ -0,0 +1,38 @@
1
+ import { objectSpread2 as _objectSpread2 } from '../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { requestGenerateCanvasAgent } from './app.js';
3
+ import { requestCommonAgent } from './common.js';
4
+ import { requestVibeCodingAgent } from './custom.js';
5
+ import { getAgentInstance } from './utils/config.js';
6
+ import { context } from '../context/index.js';
7
+
8
+ /**
9
+ * 统一的 agent 请求入口
10
+ * 根据 focus 类型自动选择使用自定义 agent 或默认的 requestCommonAgent
11
+ */
12
+ var requestAgent = params => {
13
+ var _context$currentFocus, _context$currentFocus2;
14
+ var type = (_context$currentFocus = context.currentFocus) === null || _context$currentFocus === void 0 ? void 0 : _context$currentFocus.type;
15
+ if ((_context$currentFocus2 = context.currentFocus) !== null && _context$currentFocus2 !== void 0 && _context$currentFocus2.vibeCoding) {
16
+ return requestVibeCodingAgent(_objectSpread2(_objectSpread2({}, params), {}, {
17
+ key: "".concat(context.pluginParams.key, "_").concat(context.currentFocus.pageId, "_").concat(context.currentFocus.comId)
18
+ }), _objectSpread2({}, context.currentFocus));
19
+ }
20
+
21
+ // 检查是否有匹配的自定义 agent
22
+ var customAgent = type ? getAgentInstance(context.agents, type) : null;
23
+ if (customAgent) {
24
+ // 如果找到匹配的自定义 agent,调用其 request 方法
25
+ return customAgent.request(params);
26
+ } else {
27
+ // 否则使用默认的 requestCommonAgent
28
+ return requestCommonAgent(params);
29
+ }
30
+ };
31
+ var Agents = {
32
+ requestGenerateCanvasAgent,
33
+ requestCommonAgent,
34
+ requestAgent
35
+ };
36
+
37
+ export { Agents, requestAgent };
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../src/agents/index.ts"],"sourcesContent":["import { requestGenerateCanvasAgent } from './app'\nimport { requestCommonAgent } from './common'\nimport { requestVibeCodingAgent } from './custom'\nimport { getAgentInstance } from './utils/config'\nimport { context } from '../context'\n\n/**\n * 统一的 agent 请求入口\n * 根据 focus 类型自动选择使用自定义 agent 或默认的 requestCommonAgent\n */\nexport const requestAgent = (params: any) => {\n const type = context.currentFocus?.type;\n\n if (context.currentFocus?.vibeCoding) {\n return requestVibeCodingAgent({\n ...params,\n key: `${context.pluginParams.key}_${context.currentFocus!.pageId}_${context.currentFocus!.comId}`,\n }, {...context.currentFocus});\n }\n\n // 检查是否有匹配的自定义 agent\n const customAgent = type ? getAgentInstance(context.agents, type) : null;\n\n if (customAgent) {\n // 如果找到匹配的自定义 agent,调用其 request 方法\n return customAgent.request(params);\n } else {\n // 否则使用默认的 requestCommonAgent\n return requestCommonAgent(params);\n }\n}\n\nexport const Agents = {\n requestGenerateCanvasAgent,\n requestCommonAgent,\n requestAgent\n}"],"names":["requestAgent","params","_context$currentFocus","_context$currentFocus2","type","context","currentFocus","vibeCoding","requestVibeCodingAgent","_objectSpread","key","concat","pluginParams","pageId","comId","customAgent","getAgentInstance","agents","request","requestCommonAgent","Agents","requestGenerateCanvasAgent"],"mappings":";;;;;;;AAMA;AACA;AACA;AACA;AACO,IAAMA,YAAY,GAAIC,MAAW,IAAK;EAAA,IAAAC,qBAAA,EAAAC,sBAAA;AAC3C,EAAA,IAAMC,IAAI,GAAA,CAAAF,qBAAA,GAAGG,OAAO,CAACC,YAAY,MAAA,IAAA,IAAAJ,qBAAA,KAAA,MAAA,GAAA,MAAA,GAApBA,qBAAA,CAAsBE,IAAI;EAEvC,IAAA,CAAAD,sBAAA,GAAIE,OAAO,CAACC,YAAY,MAAA,IAAA,IAAAH,sBAAA,KAAA,MAAA,IAApBA,sBAAA,CAAsBI,UAAU,EAAE;AACpC,IAAA,OAAOC,sBAAsB,CAAAC,cAAA,CAAAA,cAAA,KACxBR,MAAM,CAAA,EAAA,EAAA,EAAA;MACTS,GAAG,EAAA,EAAA,CAAAC,MAAA,CAAKN,OAAO,CAACO,YAAY,CAACF,GAAG,EAAA,GAAA,CAAA,CAAAC,MAAA,CAAIN,OAAO,CAACC,YAAY,CAAEO,MAAM,EAAA,GAAA,CAAA,CAAAF,MAAA,CAAIN,OAAO,CAACC,YAAY,CAAEQ,KAAK;AAAE,KAAA,CAAA,EAAAL,cAAA,CAAA,EAAA,EAC5FJ,OAAO,CAACC,YAAY,CAAC,CAAC;AAC/B,EAAA;;AAEA;AACA,EAAA,IAAMS,WAAW,GAAGX,IAAI,GAAGY,gBAAgB,CAACX,OAAO,CAACY,MAAM,EAAEb,IAAI,CAAC,GAAG,IAAI;AAExE,EAAA,IAAIW,WAAW,EAAE;AACf;AACA,IAAA,OAAOA,WAAW,CAACG,OAAO,CAACjB,MAAM,CAAC;AACpC,EAAA,CAAC,MAAM;AACL;IACA,OAAOkB,kBAAkB,CAAClB,MAAM,CAAC;AACnC,EAAA;AACF;AAEO,IAAMmB,MAAM,GAAG;EACpBC,0BAA0B;EAC1BF,kBAAkB;AAClBnB,EAAAA;AACF;;;;"}
@@ -0,0 +1,579 @@
1
+ import { defineProperty as _defineProperty, asyncToGenerator as _asyncToGenerator } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
+ import { KnowledgeNode } from './knowledge-node.js';
3
+ import { KnowledgeNodeType } from './types.js';
4
+
5
+ /**
6
+ * 知识库类
7
+ * 本质上是对一条大模型消息的生成和管理
8
+ */
9
+ class KnowledgeBase {
10
+ constructor(config) {
11
+ /** 知识库名称 */
12
+ /** 知识库描述 */
13
+ /** 根节点 */
14
+ /** 已打开的文件路径列表 */
15
+ _defineProperty(this, "openedFilePaths", new Set());
16
+ /** 注册的 Provider 映射 */
17
+ _defineProperty(this, "providers", new Map());
18
+ /** 动态文档目录配置映射 */
19
+ _defineProperty(this, "dynamicDirectories", new Map());
20
+ /** 动态文档存储(按目录ID分组) */
21
+ _defineProperty(this, "dynamicDocuments", new Map());
22
+ /** 默认动态文档目录ID */
23
+ _defineProperty(this, "DEFAULT_DYNAMIC_DIR_ID", '__dynamic_docs__');
24
+ this.name = config.name;
25
+ this.description = config.description;
26
+
27
+ // 初始化根节点
28
+ this.root = new KnowledgeNode('__root__', this.name, KnowledgeNodeType.DIRECTORY, this, {
29
+ description: this.description,
30
+ metadata: {
31
+ providerId: '__root__'
32
+ }
33
+ });
34
+ }
35
+
36
+ /**
37
+ * 注册目录提供者
38
+ */
39
+ registerProvider(provider) {
40
+ this.providers.set(provider.id, provider);
41
+ }
42
+
43
+ /**
44
+ * 注册动态文档目录
45
+ */
46
+ registerDynamicDirectory(config) {
47
+ this.dynamicDirectories.set(config.id, config);
48
+ // 为这个目录初始化文档存储
49
+ if (!this.dynamicDocuments.has(config.id)) {
50
+ this.dynamicDocuments.set(config.id, new Map());
51
+ }
52
+ }
53
+
54
+ /**
55
+ * 获取 Provider(实现 IProviderManager 接口)
56
+ */
57
+ getProvider(providerId) {
58
+ var _this = this;
59
+ // 根节点特殊处理
60
+ if (providerId === '__root__') {
61
+ return {
62
+ id: '__root__',
63
+ name: this.name,
64
+ description: this.description,
65
+ weight: 0,
66
+ getRootNode: () => ({
67
+ id: '__root__',
68
+ name: this.name,
69
+ type: KnowledgeNodeType.DIRECTORY
70
+ }),
71
+ getChildren: function () {
72
+ var _getChildren = _asyncToGenerator(function* () {
73
+ // 返回所有注册的 provider 和动态文档目录的根节点,按权重排序(从大到小)
74
+ var allNodes = [];
75
+
76
+ // 添加 provider 节点
77
+ var providers = Array.from(_this.providers.values());
78
+ allNodes.push(...providers.map(p => p.getRootNode()));
79
+
80
+ // 添加动态文档目录节点
81
+ var dynamicDirs = Array.from(_this.dynamicDirectories.values());
82
+ allNodes.push(...dynamicDirs.map(dir => ({
83
+ id: dir.id,
84
+ name: dir.name,
85
+ // 直接使用 name 作为展示名称
86
+ type: KnowledgeNodeType.DIRECTORY,
87
+ description: dir.description,
88
+ hidden: dir.hidden,
89
+ metadata: {
90
+ providerId: dir.id,
91
+ // 使用自己的 ID 作为 providerId,确保子节点查找正确
92
+ isDynamicDirectory: true
93
+ }
94
+ })));
95
+
96
+ // 按权重排序(从大到小)
97
+ allNodes.sort((a, b) => {
98
+ var weightA = _this.getNodeWeight(a.id);
99
+ var weightB = _this.getNodeWeight(b.id);
100
+ return weightB - weightA;
101
+ });
102
+ return allNodes;
103
+ });
104
+ function getChildren() {
105
+ return _getChildren.apply(this, arguments);
106
+ }
107
+ return getChildren;
108
+ }(),
109
+ readFile: function () {
110
+ var _readFile = _asyncToGenerator(function* () {
111
+ throw new Error('Cannot read file from root');
112
+ });
113
+ function readFile() {
114
+ return _readFile.apply(this, arguments);
115
+ }
116
+ return readFile;
117
+ }()
118
+ };
119
+ }
120
+
121
+ // 检查是否是动态文档目录
122
+ if (this.dynamicDirectories.has(providerId)) {
123
+ return this.createDynamicDirectoryProvider(providerId);
124
+ }
125
+ return this.providers.get(providerId);
126
+ }
127
+
128
+ /**
129
+ * 获取节点的权重
130
+ */
131
+ getNodeWeight(nodeId) {
132
+ var provider = this.providers.get(nodeId);
133
+ if (provider) {
134
+ var _provider$weight;
135
+ return (_provider$weight = provider.weight) !== null && _provider$weight !== void 0 ? _provider$weight : 0;
136
+ }
137
+ var dynamicDir = this.dynamicDirectories.get(nodeId);
138
+ if (dynamicDir) {
139
+ var _dynamicDir$weight;
140
+ return (_dynamicDir$weight = dynamicDir.weight) !== null && _dynamicDir$weight !== void 0 ? _dynamicDir$weight : 0;
141
+ }
142
+ return 0;
143
+ }
144
+
145
+ /**
146
+ * 为动态文档目录创建 Provider
147
+ */
148
+ createDynamicDirectoryProvider(directoryId) {
149
+ var _dirConfig$weight,
150
+ _this2 = this;
151
+ var dirConfig = this.dynamicDirectories.get(directoryId);
152
+ if (!dirConfig) {
153
+ throw new Error("Dynamic directory not found: ".concat(directoryId));
154
+ }
155
+ return {
156
+ id: dirConfig.id,
157
+ name: dirConfig.name,
158
+ description: dirConfig.description,
159
+ weight: (_dirConfig$weight = dirConfig.weight) !== null && _dirConfig$weight !== void 0 ? _dirConfig$weight : 0,
160
+ getRootNode: () => ({
161
+ id: dirConfig.id,
162
+ name: dirConfig.name,
163
+ // 直接使用 name 作为展示名称
164
+ type: KnowledgeNodeType.DIRECTORY,
165
+ description: dirConfig.description,
166
+ hidden: dirConfig.hidden,
167
+ metadata: {
168
+ isDynamicDirectory: true
169
+ }
170
+ }),
171
+ getChildren: function () {
172
+ var _getChildren2 = _asyncToGenerator(function* (parentId) {
173
+ if (parentId !== dirConfig.id) {
174
+ return [];
175
+ }
176
+ // 返回该目录下的所有动态文档
177
+ var docs = _this2.dynamicDocuments.get(directoryId);
178
+ if (!docs) {
179
+ return [];
180
+ }
181
+ return Array.from(docs.values()).map(doc => ({
182
+ id: doc.id,
183
+ // 简单的 id,用于路径匹配
184
+ name: doc.title || doc.id,
185
+ // 使用 title 作为展示名称
186
+ type: KnowledgeNodeType.FILE,
187
+ extname: doc.extname || '.md',
188
+ description: doc.description,
189
+ // description 就是描述
190
+ hidden: dirConfig.hidden,
191
+ metadata: {
192
+ isDynamicDocument: true,
193
+ directoryId,
194
+ docId: doc.id
195
+ // parentPath 会由 getChildren() 自动传递
196
+ }
197
+ }));
198
+ });
199
+ function getChildren(_x) {
200
+ return _getChildren2.apply(this, arguments);
201
+ }
202
+ return getChildren;
203
+ }(),
204
+ readFile: function () {
205
+ var _readFile2 = _asyncToGenerator(function* (fileId) {
206
+ // fileId 格式: directoryId/docId
207
+ var match = fileId.match(/^(.+)\/(.+)$/);
208
+ if (!match) {
209
+ throw new Error("Invalid dynamic document file ID: ".concat(fileId));
210
+ }
211
+ var [, dirId, docId] = match;
212
+ var docs = _this2.dynamicDocuments.get(dirId);
213
+ var doc = docs === null || docs === void 0 ? void 0 : docs.get(docId);
214
+ if (!doc) {
215
+ throw new Error("Dynamic document not found: ".concat(fileId));
216
+ }
217
+ var result = '';
218
+ if (doc.title) {
219
+ result += "## ".concat(doc.title, "\n");
220
+ }
221
+ if (doc.description) {
222
+ result += "> ".concat(doc.description, "\n\n");
223
+ }
224
+ result += doc.content;
225
+ return result;
226
+ });
227
+ function readFile(_x2) {
228
+ return _readFile2.apply(this, arguments);
229
+ }
230
+ return readFile;
231
+ }()
232
+ };
233
+ }
234
+
235
+ /**
236
+ * 添加动态文档
237
+ * @param doc 动态文档
238
+ */
239
+ addDynamicDocument(doc) {
240
+ var directoryId = doc.directoryId || this.DEFAULT_DYNAMIC_DIR_ID;
241
+
242
+ // 确保目录存在
243
+ if (!this.dynamicDirectories.has(directoryId)) {
244
+ // 如果是默认目录且不存在,自动创建
245
+ if (directoryId === this.DEFAULT_DYNAMIC_DIR_ID) {
246
+ this.registerDynamicDirectory({
247
+ id: this.DEFAULT_DYNAMIC_DIR_ID,
248
+ name: '动态文档',
249
+ description: '动态生成的文档',
250
+ weight: -100,
251
+ hidden: true
252
+ });
253
+ } else {
254
+ throw new Error("Dynamic directory not found: ".concat(directoryId));
255
+ }
256
+ }
257
+
258
+ // 获取或创建该目录的文档存储
259
+ var docs = this.dynamicDocuments.get(directoryId);
260
+ if (!docs) {
261
+ docs = new Map();
262
+ this.dynamicDocuments.set(directoryId, docs);
263
+ }
264
+
265
+ // 添加文档
266
+ docs.set(doc.id, doc);
267
+ }
268
+
269
+ /**
270
+ * 删除动态文档
271
+ * @param docId 文档ID
272
+ * @param directoryId 目录ID(可选,如果不指定则搜索所有目录)
273
+ */
274
+ removeDynamicDocument(docId, directoryId) {
275
+ if (directoryId) {
276
+ // 从指定目录删除
277
+ var docs = this.dynamicDocuments.get(directoryId);
278
+ if (docs) {
279
+ docs.delete(docId);
280
+ // 同时关闭该文档(如果已打开)
281
+ var path = "".concat(directoryId, "/").concat(docId);
282
+ this.closeFile(path);
283
+ }
284
+ } else {
285
+ // 从所有目录中搜索并删除
286
+ for (var [dirId, _docs] of this.dynamicDocuments.entries()) {
287
+ if (_docs.has(docId)) {
288
+ _docs.delete(docId);
289
+ var _path = "".concat(dirId, "/").concat(docId);
290
+ this.closeFile(_path);
291
+ }
292
+ }
293
+ }
294
+ }
295
+
296
+ /**
297
+ * 获取动态文档
298
+ * @param docId 文档ID
299
+ * @param directoryId 目录ID(可选)
300
+ */
301
+ getDynamicDocument(docId, directoryId) {
302
+ if (directoryId) {
303
+ var _this$dynamicDocument;
304
+ return (_this$dynamicDocument = this.dynamicDocuments.get(directoryId)) === null || _this$dynamicDocument === void 0 ? void 0 : _this$dynamicDocument.get(docId);
305
+ } else {
306
+ // 搜索所有目录
307
+ for (var docs of this.dynamicDocuments.values()) {
308
+ var doc = docs.get(docId);
309
+ if (doc) {
310
+ return doc;
311
+ }
312
+ }
313
+ }
314
+ return undefined;
315
+ }
316
+
317
+ /**
318
+ * 清空动态文档目录中的所有文档
319
+ * @param directoryId 目录ID(可选,如果不指定则清空所有动态文档)
320
+ */
321
+ clearDynamicDocuments(directoryId) {
322
+ if (directoryId) {
323
+ // 清空指定目录
324
+ var docs = this.dynamicDocuments.get(directoryId);
325
+ if (docs) {
326
+ // 关闭所有已打开的文档
327
+ docs.forEach((_, docId) => {
328
+ var path = "".concat(directoryId, "/").concat(docId);
329
+ this.closeFile(path);
330
+ });
331
+ docs.clear();
332
+ }
333
+ } else {
334
+ // 清空所有动态文档
335
+ this.dynamicDocuments.forEach((docs, dirId) => {
336
+ docs.forEach((_, docId) => {
337
+ var path = "".concat(dirId, "/").concat(docId);
338
+ this.closeFile(path);
339
+ });
340
+ docs.clear();
341
+ });
342
+ }
343
+ }
344
+
345
+ /**
346
+ * 打开动态文档(简化方法)
347
+ * @param doc 动态文档
348
+ */
349
+ openDynamicDocument(doc) {
350
+ var _this3 = this;
351
+ return _asyncToGenerator(function* () {
352
+ // 添加到动态文档存储
353
+ _this3.addDynamicDocument(doc);
354
+
355
+ // 打开文档
356
+ var directoryId = doc.directoryId || _this3.DEFAULT_DYNAMIC_DIR_ID;
357
+ var path = "".concat(directoryId, "/").concat(doc.id);
358
+ yield _this3.openFile(path);
359
+ })();
360
+ }
361
+
362
+ /**
363
+ * 打开文件(标记文件为已打开)
364
+ * @param path 文件路径,如 "dsl/page1.json"
365
+ */
366
+ openFile(path) {
367
+ var _this4 = this;
368
+ return _asyncToGenerator(function* () {
369
+ console.log('[KnowledgeBase.openFile] 尝试打开文件:', path);
370
+ var node = yield _this4.root.findByPath(path);
371
+ console.log('[KnowledgeBase.openFile] 找到节点:', node);
372
+ if (!node) {
373
+ throw new Error("File not found: ".concat(path));
374
+ }
375
+ if (!node.isFile) {
376
+ throw new Error("Path is not a file: ".concat(path));
377
+ }
378
+ _this4.openedFilePaths.add(path);
379
+ console.log('[KnowledgeBase.openFile] 文件已添加到已打开列表,当前已打开文件数:', _this4.openedFilePaths.size);
380
+ })();
381
+ }
382
+
383
+ /**
384
+ * 关闭文件
385
+ * @param path 文件路径
386
+ */
387
+ closeFile(path) {
388
+ this.openedFilePaths.delete(path);
389
+ }
390
+
391
+ /**
392
+ * 检查文件是否已打开
393
+ * @param path 文件路径
394
+ */
395
+ isFileOpened(path) {
396
+ return this.openedFilePaths.has(path);
397
+ }
398
+
399
+ /**
400
+ * 获取目录树结构(文本格式)
401
+ * 每次调用都会动态获取最新的文件树
402
+ */
403
+ getDirectoryTree(options) {
404
+ var _this5 = this;
405
+ return _asyncToGenerator(function* () {
406
+ var {
407
+ maxDepth = Infinity,
408
+ showDescription = false
409
+ } = options || {};
410
+ return yield _this5._buildTreeText(_this5.root, 0, maxDepth, showDescription);
411
+ })();
412
+ }
413
+
414
+ /**
415
+ * 导出知识库内容(用于发送给大模型)
416
+ * 每次导出都会动态重新获取文件树和文件内容
417
+ */
418
+ export(options) {
419
+ var _this6 = this;
420
+ return _asyncToGenerator(function* () {
421
+ var {
422
+ includeTree = true
423
+ } = options || {};
424
+ var result = "# ".concat(_this6.name, "\n");
425
+ if (_this6.description) {
426
+ result += "".concat(_this6.description, "\n\n");
427
+ }
428
+
429
+ // 导出目录结构树(动态获取)
430
+ if (includeTree) {
431
+ result += "## \u76EE\u5F55\u7ED3\u6784\n";
432
+ result += yield _this6.getDirectoryTree({
433
+ showDescription: true
434
+ });
435
+ result += '\n\n';
436
+ }
437
+
438
+ // 导出已打开的文件内容(每次都重新读取)
439
+ console.log('[KnowledgeBase.export] 已打开的文件数:', _this6.openedFilePaths.size);
440
+ console.log('[KnowledgeBase.export] 已打开的文件列表:', Array.from(_this6.openedFilePaths));
441
+ console.log('[KnowledgeBase.export] openedFilePaths 类型:', typeof _this6.openedFilePaths, _this6.openedFilePaths);
442
+ console.log('[KnowledgeBase.export] 是否是 Set:', _this6.openedFilePaths instanceof Set);
443
+ if (_this6.openedFilePaths.size > 0) {
444
+ result += "## \u5DF2\u6253\u5F00\u7684\u6587\u4EF6\n\n";
445
+ console.log('[KnowledgeBase.export] ===== 开始遍历已打开的文件 =====');
446
+
447
+ // 测试:使用 Array.from 转换后遍历
448
+ var pathsArray = Array.from(_this6.openedFilePaths);
449
+ console.log('[KnowledgeBase.export] 转换为数组:', pathsArray);
450
+ var iterationCount = 0;
451
+ for (var path of pathsArray) {
452
+ iterationCount++;
453
+ console.log('[KnowledgeBase.export] 正在导出文件 #' + iterationCount + ':', path);
454
+ // 动态查找文件节点
455
+ var node = yield _this6.root.findByPath(path);
456
+ console.log('[KnowledgeBase.export] 找到节点:', node ? "".concat(node.name).concat(node.extname || '') : 'null');
457
+ if (node && node.isFile) {
458
+ try {
459
+ console.log('[KnowledgeBase.export] 开始读取文件内容...');
460
+ var content = yield node.getContent();
461
+ console.log('[KnowledgeBase.export] 文件内容长度:', content.length);
462
+
463
+ // 使用 name 作为展示标题(如果是动态文档,name 就是 title)
464
+ var displayTitle = node.name + (node.extname || '');
465
+ result += "### ".concat(displayTitle, "\n");
466
+ if (node.description) {
467
+ result += "> ".concat(node.description, "\n\n");
468
+ }
469
+ result += '--BEGIN--\n';
470
+ result += content;
471
+ result += '\n--END--\n\n';
472
+ } catch (error) {
473
+ console.error("Failed to export file ".concat(path, ":"), error);
474
+ var _displayTitle = node.name + (node.extname || '');
475
+ result += "### ".concat(_displayTitle, " [\u5DF2\u5220\u9664]\n");
476
+ result += "> \u8BFB\u53D6\u5931\u8D25: ".concat(error, "\n\n");
477
+ }
478
+ } else {
479
+ // 文件不存在或被删除
480
+ console.log('[KnowledgeBase.export] 节点不存在或不是文件');
481
+ result += "### ".concat(path, " [\u5DF2\u5220\u9664]\n");
482
+ result += "> \u8BE5\u6587\u4EF6\u5DF2\u88AB\u5220\u9664\u6216\u4E0D\u5B58\u5728\n\n";
483
+ }
484
+ }
485
+ console.log('[KnowledgeBase.export] ===== 遍历完成,共处理', iterationCount, '个文件 =====');
486
+ } else {
487
+ console.log('[KnowledgeBase.export] 没有已打开的文件');
488
+ result += "## \u5DF2\u6253\u5F00\u7684\u6587\u4EF6\n\u6682\u65E0\u6253\u5F00\u7684\u6587\u4EF6\n\n";
489
+ }
490
+ console.log('[KnowledgeBase.export] 导出完成,总长度:', result.length);
491
+ return result;
492
+ })();
493
+ }
494
+
495
+ /**
496
+ * 获取根节点
497
+ */
498
+ getRoot() {
499
+ return this.root;
500
+ }
501
+
502
+ /**
503
+ * 根据路径查找节点(动态查找)
504
+ */
505
+ findNode(path) {
506
+ var _this7 = this;
507
+ return _asyncToGenerator(function* () {
508
+ return yield _this7.root.findByPath(path);
509
+ })();
510
+ }
511
+
512
+ /**
513
+ * 清空所有已打开的文件
514
+ */
515
+ clearOpenedFiles() {
516
+ this.openedFilePaths.clear();
517
+ }
518
+
519
+ /**
520
+ * 获取已打开的文件路径列表
521
+ */
522
+ getOpenedFilePaths() {
523
+ return Array.from(this.openedFilePaths);
524
+ }
525
+
526
+ /**
527
+ * 构建树形文本(动态获取子节点)
528
+ */
529
+ _buildTreeText(node, depth, maxDepth, showDescription) {
530
+ var _arguments = arguments,
531
+ _this8 = this;
532
+ return _asyncToGenerator(function* () {
533
+ var currentPath = _arguments.length > 4 && _arguments[4] !== undefined ? _arguments[4] : '';
534
+ if (depth > maxDepth) {
535
+ return '';
536
+ }
537
+ var prefix = depth > 0 ? '-'.repeat(depth) + ' ' : '';
538
+ var text = '';
539
+
540
+ // 根节点不显示
541
+ if (depth > 0) {
542
+ // 隐藏的节点不显示
543
+ if (node.hidden) {
544
+ return '';
545
+ }
546
+ var path = currentPath;
547
+ var openedMark = _this8.openedFilePaths.has(path) ? ' [已打开]' : '';
548
+ // 直接使用 name 作为展示名称
549
+ var displayName = node.extname ? "".concat(node.name).concat(node.extname) : node.name;
550
+ var folderMark = node.isDirectory ? '/' : '';
551
+ var ellipsisMark = node.ellipsis ? ' ...' : '';
552
+ text += "".concat(prefix).concat(displayName).concat(folderMark).concat(openedMark).concat(ellipsisMark);
553
+ if (showDescription && node.description && node.description !== 'undefined') {
554
+ text += " \uFF08".concat(node.description, "\uFF09");
555
+ }
556
+ text += '\n';
557
+ }
558
+
559
+ // 动态获取子节点
560
+ if (node.isDirectory) {
561
+ try {
562
+ var children = yield node.getChildren();
563
+ for (var child of children) {
564
+ // 直接使用 id 构建路径
565
+ var childId = child.extname ? "".concat(child.id).concat(child.extname) : child.id;
566
+ var childPath = currentPath ? "".concat(currentPath, "/").concat(childId) : childId;
567
+ text += yield _this8._buildTreeText(child, depth + 1, maxDepth, showDescription, childPath);
568
+ }
569
+ } catch (error) {
570
+ console.error("Failed to load children of ".concat(node.name, ":"), error);
571
+ }
572
+ }
573
+ return text;
574
+ })();
575
+ }
576
+ }
577
+
578
+ export { KnowledgeBase };
579
+ //# sourceMappingURL=knowledge-base.js.map