@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,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 知识节点实现
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { IKnowledgeNode, KnowledgeNodeType, IDirectoryProvider } from './types';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Provider 管理器接口
|
|
9
|
-
*/
|
|
10
|
-
export interface IProviderManager {
|
|
11
|
-
getProvider(providerId: string): IDirectoryProvider | undefined;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* 知识节点类
|
|
16
|
-
*/
|
|
17
|
-
export class KnowledgeNode implements IKnowledgeNode {
|
|
18
|
-
id: string;
|
|
19
|
-
name: string;
|
|
20
|
-
type: KnowledgeNodeType;
|
|
21
|
-
description?: string;
|
|
22
|
-
extname?: string;
|
|
23
|
-
ellipsis?: boolean;
|
|
24
|
-
hidden?: boolean;
|
|
25
|
-
children?: KnowledgeNode[];
|
|
26
|
-
metadata?: Record<string, any>;
|
|
27
|
-
|
|
28
|
-
private providerManager: IProviderManager;
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
id: string,
|
|
32
|
-
name: string,
|
|
33
|
-
type: KnowledgeNodeType,
|
|
34
|
-
providerManager: IProviderManager,
|
|
35
|
-
options?: {
|
|
36
|
-
description?: string;
|
|
37
|
-
extname?: string;
|
|
38
|
-
ellipsis?: boolean;
|
|
39
|
-
hidden?: boolean;
|
|
40
|
-
metadata?: Record<string, any>;
|
|
41
|
-
children?: KnowledgeNode[];
|
|
42
|
-
}
|
|
43
|
-
) {
|
|
44
|
-
this.id = id;
|
|
45
|
-
this.name = name;
|
|
46
|
-
this.type = type;
|
|
47
|
-
this.providerManager = providerManager;
|
|
48
|
-
this.description = options?.description;
|
|
49
|
-
this.extname = options?.extname;
|
|
50
|
-
this.ellipsis = options?.ellipsis;
|
|
51
|
-
this.hidden = options?.hidden;
|
|
52
|
-
this.metadata = options?.metadata;
|
|
53
|
-
this.children = options?.children;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 是否为目录
|
|
58
|
-
*/
|
|
59
|
-
get isDirectory(): boolean {
|
|
60
|
-
return this.type === KnowledgeNodeType.DIRECTORY;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 是否为文件
|
|
65
|
-
*/
|
|
66
|
-
get isFile(): boolean {
|
|
67
|
-
return this.type === KnowledgeNodeType.FILE;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 获取文件内容(每次都重新读取)
|
|
72
|
-
*/
|
|
73
|
-
async getContent(): Promise<string> {
|
|
74
|
-
console.log('[KnowledgeNode.getContent] 节点:', this.name, '类型:', this.type, 'ID:', this.id);
|
|
75
|
-
|
|
76
|
-
if (!this.isFile) {
|
|
77
|
-
throw new Error('Cannot get content from a directory node');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const providerId = this.metadata?.providerId;
|
|
81
|
-
console.log('[KnowledgeNode.getContent] providerId:', providerId);
|
|
82
|
-
|
|
83
|
-
if (!providerId) {
|
|
84
|
-
throw new Error(`No provider found for file ${this.id}`);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const provider = this.providerManager.getProvider(providerId);
|
|
88
|
-
console.log('[KnowledgeNode.getContent] provider:', provider ? provider.name : 'null');
|
|
89
|
-
|
|
90
|
-
if (!provider) {
|
|
91
|
-
throw new Error(`Provider ${providerId} not registered`);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
try {
|
|
95
|
-
console.log('[KnowledgeNode.getContent] 调用 provider.readFile...');
|
|
96
|
-
|
|
97
|
-
// 如果有 parentPath,拼接完整路径;否则直接使用 id
|
|
98
|
-
const parentPath = this.metadata?.parentPath;
|
|
99
|
-
const fullPath = parentPath ? `${parentPath}/${this.id}` : this.id;
|
|
100
|
-
console.log('[KnowledgeNode.getContent] fullPath:', fullPath, 'parentPath:', parentPath, 'id:', this.id);
|
|
101
|
-
|
|
102
|
-
const content = await provider.readFile(fullPath);
|
|
103
|
-
console.log('[KnowledgeNode.getContent] 读取成功,内容长度:', content.length);
|
|
104
|
-
return content;
|
|
105
|
-
} catch (error) {
|
|
106
|
-
console.error(`Failed to load file ${this.id}:`, error);
|
|
107
|
-
throw error;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* 获取目录的子节点列表(每次都动态重新查询)
|
|
113
|
-
*/
|
|
114
|
-
async getChildren(): Promise<KnowledgeNode[]> {
|
|
115
|
-
if (!this.isDirectory) {
|
|
116
|
-
throw new Error('Cannot get children from a file node');
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const providerId = this.metadata?.providerId;
|
|
120
|
-
if (!providerId) {
|
|
121
|
-
throw new Error(`No provider found for directory ${this.id}`);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
const provider = this.providerManager.getProvider(providerId);
|
|
125
|
-
if (!provider) {
|
|
126
|
-
throw new Error(`Provider ${providerId} not registered`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
try {
|
|
130
|
-
const nodes = await provider.getChildren(this.id);
|
|
131
|
-
return nodes.map(node =>
|
|
132
|
-
new KnowledgeNode(
|
|
133
|
-
node.id,
|
|
134
|
-
node.name,
|
|
135
|
-
node.type,
|
|
136
|
-
this.providerManager,
|
|
137
|
-
{
|
|
138
|
-
description: node.description,
|
|
139
|
-
extname: node.extname,
|
|
140
|
-
ellipsis: node.ellipsis,
|
|
141
|
-
hidden: node.hidden,
|
|
142
|
-
// 传递父路径到子节点,用于 readFile 时拼接完整路径
|
|
143
|
-
metadata: {
|
|
144
|
-
providerId,
|
|
145
|
-
parentPath: this.id === '__root__' ? '' : this.id, // 根节点的 parentPath 为空
|
|
146
|
-
...node.metadata
|
|
147
|
-
},
|
|
148
|
-
children: node.children as KnowledgeNode[]
|
|
149
|
-
}
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
} catch (error) {
|
|
153
|
-
console.error(`Failed to load directory ${this.id}:`, error);
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* 添加子节点
|
|
160
|
-
*/
|
|
161
|
-
addChild(child: KnowledgeNode): void {
|
|
162
|
-
if (!this.isDirectory) {
|
|
163
|
-
throw new Error('Cannot add child to a file node');
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (!this.children) {
|
|
167
|
-
this.children = [];
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
this.children.push(child);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* 根据路径查找节点(动态获取子节点)
|
|
175
|
-
* @param path 路径,如 "dsl/page1"
|
|
176
|
-
*/
|
|
177
|
-
async findByPath(path: string): Promise<KnowledgeNode | null> {
|
|
178
|
-
const parts = path.split('/').filter(Boolean);
|
|
179
|
-
return await this._findByParts(parts);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
private async _findByParts(parts: string[]): Promise<KnowledgeNode | null> {
|
|
183
|
-
console.log('[KnowledgeNode._findByParts] 当前节点:', this.name, '查找parts:', parts);
|
|
184
|
-
|
|
185
|
-
if (parts.length === 0) {
|
|
186
|
-
return this;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const [first, ...rest] = parts;
|
|
190
|
-
|
|
191
|
-
if (!this.isDirectory) {
|
|
192
|
-
console.log('[KnowledgeNode._findByParts] 当前节点不是目录,返回null');
|
|
193
|
-
return null;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// 动态获取子节点
|
|
197
|
-
const children = await this.getChildren();
|
|
198
|
-
console.log('[KnowledgeNode._findByParts] 子节点列表:', children.map(c => c.extname ? `${c.id}${c.extname}` : c.id));
|
|
199
|
-
|
|
200
|
-
// 直接使用 id 匹配路径段
|
|
201
|
-
const child = children.find(c => {
|
|
202
|
-
const fullId = c.extname ? `${c.id}${c.extname}` : c.id;
|
|
203
|
-
return fullId === first || c.id === first;
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
console.log('[KnowledgeNode._findByParts] 查找', first, '结果:', child ? `${child.id}${child.extname || ''}` : 'null');
|
|
207
|
-
|
|
208
|
-
if (!child) {
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (rest.length === 0) {
|
|
213
|
-
return child;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return await child._findByParts(rest);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
* 获取节点的完整路径(动态获取子节点)
|
|
221
|
-
*/
|
|
222
|
-
async getPath(root: KnowledgeNode): Promise<string> {
|
|
223
|
-
const path = await this._buildPath(root);
|
|
224
|
-
return path.join('/');
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
private async _buildPath(root: KnowledgeNode, currentPath: string[] = []): Promise<string[]> {
|
|
228
|
-
if (root === this) {
|
|
229
|
-
return currentPath;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (!root.isDirectory) {
|
|
233
|
-
return [];
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// 动态获取子节点
|
|
237
|
-
const children = await root.getChildren();
|
|
238
|
-
|
|
239
|
-
for (const child of children) {
|
|
240
|
-
const path = await this._buildPath(child, [...currentPath, child.name]);
|
|
241
|
-
if (path.length > 0) {
|
|
242
|
-
return path;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return [];
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* 转换为普通对象
|
|
251
|
-
*/
|
|
252
|
-
toJSON(): IKnowledgeNode {
|
|
253
|
-
return {
|
|
254
|
-
id: this.id,
|
|
255
|
-
name: this.name,
|
|
256
|
-
type: this.type,
|
|
257
|
-
description: this.description,
|
|
258
|
-
extname: this.extname,
|
|
259
|
-
ellipsis: this.ellipsis,
|
|
260
|
-
hidden: this.hidden,
|
|
261
|
-
metadata: this.metadata,
|
|
262
|
-
children: this.children?.map(c => c.toJSON())
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 知识库类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 知识节点类型
|
|
7
|
-
*/
|
|
8
|
-
export enum KnowledgeNodeType {
|
|
9
|
-
/** 目录 */
|
|
10
|
-
DIRECTORY = 'directory',
|
|
11
|
-
/** 文件 */
|
|
12
|
-
FILE = 'file'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 知识节点接口
|
|
17
|
-
*/
|
|
18
|
-
export interface IKnowledgeNode {
|
|
19
|
-
/** 节点ID */
|
|
20
|
-
id: string;
|
|
21
|
-
/** 节点名称 */
|
|
22
|
-
name: string;
|
|
23
|
-
/** 节点类型 */
|
|
24
|
-
type: KnowledgeNodeType;
|
|
25
|
-
/** 节点描述 */
|
|
26
|
-
description?: string;
|
|
27
|
-
/** 文件扩展名(如 .dsl, .md 等;目录也可以有扩展名) */
|
|
28
|
-
extname?: string;
|
|
29
|
-
/** 是否显示省略号(表示不完整的树) */
|
|
30
|
-
ellipsis?: boolean;
|
|
31
|
-
/** 是否隐藏(隐藏的节点不在目录树中显示,但可以打开) */
|
|
32
|
-
hidden?: boolean;
|
|
33
|
-
/** 子节点(仅目录类型) */
|
|
34
|
-
children?: IKnowledgeNode[];
|
|
35
|
-
/** 元数据 */
|
|
36
|
-
metadata?: Record<string, any>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* 目录提供者接口
|
|
41
|
-
* 定义目录提供者需要实现的方法
|
|
42
|
-
*/
|
|
43
|
-
export interface IDirectoryProvider {
|
|
44
|
-
/** 目录ID */
|
|
45
|
-
readonly id: string;
|
|
46
|
-
/** 目录名称 */
|
|
47
|
-
readonly name: string;
|
|
48
|
-
/** 目录描述 */
|
|
49
|
-
readonly description?: string;
|
|
50
|
-
/** 权重(数字越大优先级越高,影响目录顺序和打开文件的顺序),默认为 0 */
|
|
51
|
-
readonly weight?: number;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 获取根目录节点信息
|
|
55
|
-
*/
|
|
56
|
-
getRootNode(): IKnowledgeNode;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 获取子节点列表(动态获取最新数据)
|
|
60
|
-
* @param parentId 父节点ID
|
|
61
|
-
* @returns 子节点列表
|
|
62
|
-
*/
|
|
63
|
-
getChildren(parentId: string): Promise<IKnowledgeNode[]>;
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* 读取文件内容(动态获取最新内容)
|
|
67
|
-
* @param fileId 文件ID
|
|
68
|
-
* @returns 文件内容
|
|
69
|
-
*/
|
|
70
|
-
readFile(fileId: string): Promise<string>;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* 目录提供者配置
|
|
75
|
-
*/
|
|
76
|
-
export interface DirectoryProviderConfig {
|
|
77
|
-
/** 目录ID */
|
|
78
|
-
id: string;
|
|
79
|
-
/** 目录名称 */
|
|
80
|
-
name: string;
|
|
81
|
-
/** 目录描述 */
|
|
82
|
-
description?: string;
|
|
83
|
-
/** 权重(数字越大优先级越高) */
|
|
84
|
-
weight?: number;
|
|
85
|
-
/** 是否隐藏 */
|
|
86
|
-
hidden?: boolean;
|
|
87
|
-
/** 获取子节点的函数 */
|
|
88
|
-
getChildren: (parentId: string) => Promise<IKnowledgeNode[]>;
|
|
89
|
-
/** 读取文件内容的函数 */
|
|
90
|
-
readFile: (fileId: string) => Promise<string>;
|
|
91
|
-
/** 自定义根节点(可选,如果不提供则使用默认的目录节点) */
|
|
92
|
-
customRootNode?: IKnowledgeNode;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* DirectoryProvider 类
|
|
97
|
-
* 使用 new DirectoryProvider(config) 创建,而不是继承
|
|
98
|
-
*/
|
|
99
|
-
export class DirectoryProvider implements IDirectoryProvider {
|
|
100
|
-
readonly id: string;
|
|
101
|
-
readonly name: string;
|
|
102
|
-
readonly description?: string;
|
|
103
|
-
readonly weight: number;
|
|
104
|
-
readonly hidden: boolean;
|
|
105
|
-
|
|
106
|
-
private _getChildren: (parentId: string) => Promise<IKnowledgeNode[]>;
|
|
107
|
-
private _readFile: (fileId: string) => Promise<string>;
|
|
108
|
-
private _customRootNode?: IKnowledgeNode;
|
|
109
|
-
|
|
110
|
-
constructor(config: DirectoryProviderConfig) {
|
|
111
|
-
this.id = config.id;
|
|
112
|
-
this.name = config.name;
|
|
113
|
-
this.description = config.description;
|
|
114
|
-
this.weight = config.weight ?? 0;
|
|
115
|
-
this.hidden = config.hidden ?? false;
|
|
116
|
-
this._getChildren = config.getChildren;
|
|
117
|
-
this._readFile = config.readFile;
|
|
118
|
-
this._customRootNode = config.customRootNode;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* 获取根目录节点信息
|
|
123
|
-
*/
|
|
124
|
-
getRootNode(): IKnowledgeNode {
|
|
125
|
-
if (this._customRootNode) {
|
|
126
|
-
return this._customRootNode;
|
|
127
|
-
}
|
|
128
|
-
return {
|
|
129
|
-
id: this.id,
|
|
130
|
-
name: this.name,
|
|
131
|
-
type: KnowledgeNodeType.DIRECTORY,
|
|
132
|
-
description: this.description,
|
|
133
|
-
hidden: this.hidden,
|
|
134
|
-
metadata: { providerId: this.id }
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 获取子节点列表
|
|
140
|
-
*/
|
|
141
|
-
async getChildren(parentId: string): Promise<IKnowledgeNode[]> {
|
|
142
|
-
return await this._getChildren(parentId);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* 读取文件内容
|
|
147
|
-
*/
|
|
148
|
-
async readFile(fileId: string): Promise<string> {
|
|
149
|
-
return await this._readFile(fileId);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* 动态文档接口
|
|
155
|
-
*/
|
|
156
|
-
export interface DynamicDocument {
|
|
157
|
-
/** 文档唯一ID */
|
|
158
|
-
id: string;
|
|
159
|
-
/** 文档标题 */
|
|
160
|
-
title?: string;
|
|
161
|
-
/** 文档描述 */
|
|
162
|
-
description?: string;
|
|
163
|
-
/** 文档内容 */
|
|
164
|
-
content: string;
|
|
165
|
-
/** 文档类型(如:画布、组件等,用于分类) */
|
|
166
|
-
docType?: string;
|
|
167
|
-
/** 文件扩展名,默认为 .md */
|
|
168
|
-
extname?: string;
|
|
169
|
-
/** 所属目录的ID(如果不指定则使用默认动态文档目录) */
|
|
170
|
-
directoryId?: string;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* 动态文档目录配置
|
|
175
|
-
*/
|
|
176
|
-
export interface DynamicDocDirectoryConfig {
|
|
177
|
-
/** 目录ID */
|
|
178
|
-
id: string;
|
|
179
|
-
/** 目录名称 */
|
|
180
|
-
name: string;
|
|
181
|
-
/** 目录描述 */
|
|
182
|
-
description?: string;
|
|
183
|
-
/** 权重(数字越大优先级越高) */
|
|
184
|
-
weight?: number;
|
|
185
|
-
/** 是否隐藏(隐藏的目录不在目录树中显示,但可以打开文件) */
|
|
186
|
-
hidden?: boolean;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* 知识库配置
|
|
191
|
-
*/
|
|
192
|
-
export interface KnowledgeBaseConfig {
|
|
193
|
-
/** 知识库名称 */
|
|
194
|
-
name: string;
|
|
195
|
-
/** 知识库描述 */
|
|
196
|
-
description?: string;
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* 知识库导出选项
|
|
201
|
-
*/
|
|
202
|
-
export interface ExportOptions {
|
|
203
|
-
/** 是否包含目录树 */
|
|
204
|
-
includeTree?: boolean;
|
|
205
|
-
/** 是否包含动态文档 */
|
|
206
|
-
includeDynamicDocs?: boolean;
|
|
207
|
-
}
|
|
208
|
-
|