@louloulinx/metagpt 0.1.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/.eslintrc.json +23 -0
- package/.prettierrc +7 -0
- package/LICENSE +21 -0
- package/README-CN.md +754 -0
- package/README.md +238 -0
- package/bun.lock +1023 -0
- package/doc/TutorialAssistant.md +114 -0
- package/doc/VercelLLMProvider.md +164 -0
- package/eslint.config.js +55 -0
- package/examples/data-interpreter-example.ts +173 -0
- package/examples/qwen-direct-example.ts +60 -0
- package/examples/qwen-example.ts +62 -0
- package/examples/tutorial-assistant-example.ts +97 -0
- package/jest.config.ts +22 -0
- package/output/tutorials/Go/350/257/255/350/250/200/347/274/226/347/250/213/346/225/231/347/250/213_2025-02-25T09-35-15-436Z.md +2208 -0
- package/output/tutorials/Rust/346/225/231/347/250/213_2025-02-25T08-27-27-632Z.md +1967 -0
- package/output/tutorials//345/246/202/344/275/225/344/275/277/347/224/250TypeScript/345/274/200/345/217/221Node.js/345/272/224/347/224/250_2025-02-25T08-14-39-605Z.md +1721 -0
- package/output/tutorials//346/225/260/345/255/227/347/273/217/346/265/216/345/255/246/346/225/231/347/250/213_2025-02-25T10-45-03-605Z.md +902 -0
- package/output/tutorials//346/232/250/345/215/227/345/244/247/345/255/246/346/225/260/345/255/227/347/273/217/346/265/216/345/255/246/345/244/215/350/257/225/350/265/204/346/226/231_2025-02-25T11-16-59-133Z.md +719 -0
- package/package.json +58 -0
- package/plan-cn.md +321 -0
- package/plan.md +154 -0
- package/src/actions/analyze-task.ts +65 -0
- package/src/actions/base-action.ts +103 -0
- package/src/actions/di/execute-nb-code.ts +247 -0
- package/src/actions/di/write-analysis-code.ts +234 -0
- package/src/actions/write-tutorial.ts +232 -0
- package/src/config/browser.ts +33 -0
- package/src/config/config.ts +345 -0
- package/src/config/embedding.ts +26 -0
- package/src/config/llm.ts +36 -0
- package/src/config/mermaid.ts +37 -0
- package/src/config/omniparse.ts +25 -0
- package/src/config/redis.ts +34 -0
- package/src/config/s3.ts +33 -0
- package/src/config/search.ts +30 -0
- package/src/config/workspace.ts +20 -0
- package/src/index.ts +40 -0
- package/src/management/team.ts +168 -0
- package/src/memory/longterm.ts +218 -0
- package/src/memory/manager.ts +160 -0
- package/src/memory/types.ts +100 -0
- package/src/memory/working.ts +154 -0
- package/src/monitoring/system.ts +413 -0
- package/src/monitoring/types.ts +230 -0
- package/src/plugin/manager.ts +79 -0
- package/src/plugin/types.ts +114 -0
- package/src/provider/vercel-llm.ts +314 -0
- package/src/rag/base-rag.ts +194 -0
- package/src/rag/document-qa.ts +102 -0
- package/src/roles/base-role.ts +155 -0
- package/src/roles/data-interpreter.ts +360 -0
- package/src/roles/engineer.ts +1 -0
- package/src/roles/tutorial-assistant.ts +217 -0
- package/src/skills/base-skill.ts +144 -0
- package/src/skills/code-review.ts +120 -0
- package/src/tools/base-tool.ts +155 -0
- package/src/tools/file-system.ts +204 -0
- package/src/tools/tool-recommend.d.ts +14 -0
- package/src/tools/tool-recommend.ts +31 -0
- package/src/types/action.ts +38 -0
- package/src/types/config.ts +129 -0
- package/src/types/document.ts +354 -0
- package/src/types/llm.ts +64 -0
- package/src/types/memory.ts +36 -0
- package/src/types/message.ts +193 -0
- package/src/types/rag.ts +86 -0
- package/src/types/role.ts +67 -0
- package/src/types/skill.ts +71 -0
- package/src/types/task.ts +32 -0
- package/src/types/team.ts +55 -0
- package/src/types/tool.ts +77 -0
- package/src/types/workflow.ts +133 -0
- package/src/utils/common.ts +73 -0
- package/src/utils/yaml.ts +67 -0
- package/src/websocket/browser-client.ts +187 -0
- package/src/websocket/client.ts +186 -0
- package/src/websocket/server.ts +169 -0
- package/src/websocket/types.ts +125 -0
- package/src/workflow/executor.ts +193 -0
- package/src/workflow/executors/action-executor.ts +72 -0
- package/src/workflow/executors/condition-executor.ts +118 -0
- package/src/workflow/executors/parallel-executor.ts +201 -0
- package/src/workflow/executors/role-executor.ts +76 -0
- package/src/workflow/executors/sequence-executor.ts +196 -0
- package/tests/actions.test.ts +105 -0
- package/tests/benchmark/performance.test.ts +147 -0
- package/tests/config/config.test.ts +115 -0
- package/tests/config.test.ts +106 -0
- package/tests/e2e/setup.ts +74 -0
- package/tests/e2e/workflow.test.ts +88 -0
- package/tests/llm.test.ts +84 -0
- package/tests/memory/memory.test.ts +164 -0
- package/tests/memory.test.ts +63 -0
- package/tests/monitoring/monitoring.test.ts +225 -0
- package/tests/plugin/plugin.test.ts +183 -0
- package/tests/provider/bailian-llm.test.ts +98 -0
- package/tests/rag.test.ts +162 -0
- package/tests/roles.test.ts +88 -0
- package/tests/skills.test.ts +166 -0
- package/tests/team.test.ts +143 -0
- package/tests/tools.test.ts +170 -0
- package/tests/types/document.test.ts +181 -0
- package/tests/types/message.test.ts +122 -0
- package/tests/utils/yaml.test.ts +110 -0
- package/tests/utils.test.ts +74 -0
- package/tests/websocket/browser-client.test.ts +1 -0
- package/tests/websocket/websocket.test.ts +42 -0
- package/tests/workflow/parallel-executor.test.ts +224 -0
- package/tests/workflow/sequence-executor.test.ts +207 -0
- package/tests/workflow.test.ts +290 -0
- package/tsconfig.json +27 -0
- package/typedoc.json +25 -0
package/package.json
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
{
|
2
|
+
"name": "@louloulinx/metagpt",
|
3
|
+
"version": "0.1.3",
|
4
|
+
"description": "A TypeScript implementation of MetaGPT",
|
5
|
+
"module": "src/index.ts",
|
6
|
+
"type": "module",
|
7
|
+
"scripts": {
|
8
|
+
"dev": "bun run --watch src/index.ts",
|
9
|
+
"start": "bun run src/index.ts",
|
10
|
+
"build": "bun build ./src/index.ts --outdir ./dist",
|
11
|
+
"test": "bun test",
|
12
|
+
"lint": "eslint . --ext .ts",
|
13
|
+
"format": "prettier --write \"src/**/*.ts\"",
|
14
|
+
"type-check": "tsc --noEmit",
|
15
|
+
"docs": "typedoc",
|
16
|
+
"docs:watch": "typedoc --watch",
|
17
|
+
"prepublishOnly": "bun run lint && bun run build",
|
18
|
+
"publish": "npm publish"
|
19
|
+
},
|
20
|
+
"devDependencies": {
|
21
|
+
"@eslint/js": "^9.21.0",
|
22
|
+
"@types/bun": "latest",
|
23
|
+
"@types/js-yaml": "^4.0.9",
|
24
|
+
"@types/node": "^22.13.5",
|
25
|
+
"@typescript-eslint/eslint-plugin": "8.25.0",
|
26
|
+
"@typescript-eslint/parser": "8.25.0",
|
27
|
+
"bun-types": "latest",
|
28
|
+
"eslint": "^9.21.0",
|
29
|
+
"prettier": "^3.5.2",
|
30
|
+
"typedoc": "0.27.9",
|
31
|
+
"typescript": "^5.7.3"
|
32
|
+
},
|
33
|
+
"peerDependencies": {
|
34
|
+
"typescript": "^5.7.3"
|
35
|
+
},
|
36
|
+
"dependencies": {
|
37
|
+
"@ai-sdk/anthropic": "^1.1.10",
|
38
|
+
"@ai-sdk/google": "^1.1.17",
|
39
|
+
"@ai-sdk/mistral": "^1.1.13",
|
40
|
+
"@ai-sdk/openai": "^1.1.14",
|
41
|
+
"@jest/types": "^29.6.3",
|
42
|
+
"@qdrant/js-client-rest": "^1.13.0",
|
43
|
+
"@types/jest": "^29.5.14",
|
44
|
+
"@types/lodash": "^4.17.15",
|
45
|
+
"@types/uuid": "^10.0.0",
|
46
|
+
"ai": "^4.1.46",
|
47
|
+
"axios": "^1.7.9",
|
48
|
+
"lodash": "^4.17.21",
|
49
|
+
"openai": "^4.85.4",
|
50
|
+
"qwen-ai-provider": "^0.1.0",
|
51
|
+
"rxjs": "^7.8.2",
|
52
|
+
"ts-jest": "^29.2.6",
|
53
|
+
"uuid": "^11.1.0",
|
54
|
+
"winston": "^3.17.0",
|
55
|
+
"xstate": "^5.19.2",
|
56
|
+
"zod": "^3.24.2"
|
57
|
+
}
|
58
|
+
}
|
package/plan-cn.md
ADDED
@@ -0,0 +1,321 @@
|
|
1
|
+
# MetaGPT TypeScript
|
2
|
+
|
3
|
+
## 1. 项目结构 ✅
|
4
|
+
|
5
|
+
```
|
6
|
+
metagpt-ts/
|
7
|
+
├── src/
|
8
|
+
│ ├── actions/ # 动作定义和实现 ✅
|
9
|
+
│ ├── roles/ # 角色定义和行为 ✅
|
10
|
+
│ ├── utils/ # 工具函数和辅助类 ✅
|
11
|
+
│ ├── config/ # 配置管理 ✅
|
12
|
+
│ ├── memory/ # 记忆和状态管理 ✅
|
13
|
+
│ ├── provider/ # LLM提供商集成 ✅
|
14
|
+
│ ├── tools/ # 外部工具集成 ✅
|
15
|
+
│ ├── skills/ # 技能实现 ✅
|
16
|
+
│ ├── rag/ # 检索增强生成 ✅
|
17
|
+
│ ├── document/ # 文档处理和管理 ✅
|
18
|
+
│ └── types/ # TypeScript类型定义 ✅
|
19
|
+
├── tests/ # 测试文件 ✅
|
20
|
+
├── examples/ # 示例实现
|
21
|
+
└── package.json # 项目依赖和脚本 ✅
|
22
|
+
```
|
23
|
+
|
24
|
+
## 2. 技术选型 ✅
|
25
|
+
|
26
|
+
### 核心技术栈 ✅
|
27
|
+
1. Runtime & Package Manager
|
28
|
+
- Bun.js: 高性能 JavaScript runtime,内置包管理器 ✅
|
29
|
+
- Node.js 18+ 兼容性支持 ✅
|
30
|
+
|
31
|
+
2. 开发语言与框架
|
32
|
+
- TypeScript 5.0+:强类型支持 ✅
|
33
|
+
- Zod:运行时类型验证 ✅
|
34
|
+
- XState:状态机管理 ✅
|
35
|
+
- RxJS:响应式编程 ✅
|
36
|
+
|
37
|
+
3. 测试与开发工具
|
38
|
+
- bun:test:单元测试框架 ✅
|
39
|
+
- ESLint + Prettier:代码规范 ✅
|
40
|
+
- TypeDoc:API 文档生成 ✅
|
41
|
+
|
42
|
+
4. 核心依赖
|
43
|
+
- Vercel AI SDK ✅
|
44
|
+
- Qdrant Node Client:向量存储 ✅
|
45
|
+
- Winston:日志管理 ✅
|
46
|
+
|
47
|
+
### 技术特性
|
48
|
+
1. 状态管理
|
49
|
+
- 使用 XState 实现角色状态机 ✅
|
50
|
+
- RxJS 处理异步消息流 ✅
|
51
|
+
- 响应式的内存管理 ✅
|
52
|
+
|
53
|
+
2. 类型系统
|
54
|
+
- 严格的 TypeScript 类型 ✅
|
55
|
+
- Zod schema 验证 ✅
|
56
|
+
- 运行时类型检查 ✅
|
57
|
+
|
58
|
+
3. 异步处理
|
59
|
+
- 基于 Promise 和 async/await ✅
|
60
|
+
- RxJS Observable 消息流 ✅
|
61
|
+
- 事件驱动架构 ✅
|
62
|
+
|
63
|
+
## 3. 核心接口设计 ✅
|
64
|
+
|
65
|
+
### 基础消息系统 ✅
|
66
|
+
```typescript
|
67
|
+
interface Message {
|
68
|
+
id: string;
|
69
|
+
content: string;
|
70
|
+
role: string;
|
71
|
+
causedBy: string;
|
72
|
+
sentFrom: string;
|
73
|
+
sendTo: Set<string>;
|
74
|
+
instructContent?: any;
|
75
|
+
}
|
76
|
+
|
77
|
+
interface MessageQueue {
|
78
|
+
push(msg: Message): void;
|
79
|
+
pop(): Promise<Message | null>;
|
80
|
+
popAll(): Promise<Message[]>;
|
81
|
+
empty(): boolean;
|
82
|
+
}
|
83
|
+
```
|
84
|
+
|
85
|
+
### 角色系统 ✅
|
86
|
+
```typescript
|
87
|
+
interface Role {
|
88
|
+
name: string;
|
89
|
+
profile: string;
|
90
|
+
goal: string;
|
91
|
+
constraints: string;
|
92
|
+
actions: Action[];
|
93
|
+
|
94
|
+
// 核心方法
|
95
|
+
observe(): Promise<number>;
|
96
|
+
think(): Promise<boolean>;
|
97
|
+
act(): Promise<Message>;
|
98
|
+
react(): Promise<Message>;
|
99
|
+
|
100
|
+
// 状态管理
|
101
|
+
state: number;
|
102
|
+
context: RoleContext;
|
103
|
+
}
|
104
|
+
|
105
|
+
interface RoleContext {
|
106
|
+
memory: Memory;
|
107
|
+
workingMemory: Memory;
|
108
|
+
state: number;
|
109
|
+
todo: Action | null;
|
110
|
+
watch: Set<string>;
|
111
|
+
reactMode: RoleReactMode;
|
112
|
+
}
|
113
|
+
```
|
114
|
+
|
115
|
+
### 动作系统 ✅
|
116
|
+
```typescript
|
117
|
+
interface Action {
|
118
|
+
name: string;
|
119
|
+
context: ActionContext;
|
120
|
+
llm: LLMProvider;
|
121
|
+
|
122
|
+
run(): Promise<ActionOutput>;
|
123
|
+
handleException(error: Error): Promise<void>;
|
124
|
+
}
|
125
|
+
|
126
|
+
interface ActionOutput {
|
127
|
+
content: string;
|
128
|
+
status: ActionStatus;
|
129
|
+
instruct_content?: any;
|
130
|
+
}
|
131
|
+
```
|
132
|
+
|
133
|
+
### 状态机定义 ✅
|
134
|
+
```typescript
|
135
|
+
interface RoleStateMachine {
|
136
|
+
states: {
|
137
|
+
idle: {};
|
138
|
+
observing: {};
|
139
|
+
thinking: {};
|
140
|
+
acting: {};
|
141
|
+
reacting: {};
|
142
|
+
};
|
143
|
+
|
144
|
+
events: {
|
145
|
+
OBSERVE: {};
|
146
|
+
THINK: {};
|
147
|
+
ACT: {};
|
148
|
+
REACT: {};
|
149
|
+
COMPLETE: {};
|
150
|
+
};
|
151
|
+
}
|
152
|
+
```
|
153
|
+
|
154
|
+
## 4. 核心组件迁移优先级
|
155
|
+
|
156
|
+
### 第一阶段:基础框架 ✅
|
157
|
+
1. 基本项目设置 ✅
|
158
|
+
- 初始化TypeScript项目 ✅
|
159
|
+
- 设置开发环境(ESLint, Prettier, Jest) ✅
|
160
|
+
- 定义基础接口和类型 ✅
|
161
|
+
- 实现核心工具类 ✅
|
162
|
+
|
163
|
+
2. 基础组件 ✅
|
164
|
+
- 上下文和配置管理 ✅
|
165
|
+
- 基本LLM提供商集成 ✅
|
166
|
+
- 文档和记忆管理基础 ✅
|
167
|
+
|
168
|
+
### 第二阶段:核心功能 ✅
|
169
|
+
1. 角色系统 ✅
|
170
|
+
- 基础角色类实现 ✅
|
171
|
+
- 角色生命周期管理 ✅
|
172
|
+
- 消息处理系统 ✅
|
173
|
+
|
174
|
+
2. 动作系统 ✅
|
175
|
+
- 动作基类 ✅
|
176
|
+
- 动作执行框架 ✅
|
177
|
+
- 消息和状态管理 ✅
|
178
|
+
|
179
|
+
3. 记忆系统 ✅
|
180
|
+
- 工作记忆实现 ✅
|
181
|
+
- 长期记忆实现 ✅
|
182
|
+
- 记忆管理器 ✅
|
183
|
+
- 记忆整合和遗忘 ✅
|
184
|
+
- 单元测试覆盖 ✅
|
185
|
+
|
186
|
+
### 第三阶段:高级功能 ✅
|
187
|
+
1. 技能和工具 ✅
|
188
|
+
- 技能系统实现 ✅
|
189
|
+
- 工具集成框架 ✅
|
190
|
+
- RAG实现 ✅
|
191
|
+
|
192
|
+
2. 团队和管理 ✅
|
193
|
+
- 团队协调 ✅
|
194
|
+
- 任务管理 ✅
|
195
|
+
- 工作流编排 ✅
|
196
|
+
|
197
|
+
### 第四阶段:完善和优化
|
198
|
+
1. WebSocket支持 ✅
|
199
|
+
- WebSocket服务器实现 ✅
|
200
|
+
- WebSocket客户端实现 ✅
|
201
|
+
- 消息类型和验证 ✅
|
202
|
+
- 流式传输支持 ✅
|
203
|
+
- 错误处理和重连 ✅
|
204
|
+
- 单元测试覆盖 ✅
|
205
|
+
2. 浏览器兼容性 ✅
|
206
|
+
- 浏览器WebSocket客户端 ✅
|
207
|
+
- 原生WebSocket API支持 ✅
|
208
|
+
- 跨浏览器兼容性测试 ✅
|
209
|
+
- 单元测试覆盖 ✅
|
210
|
+
3. 插件系统 ✅
|
211
|
+
- 插件接口定义 ✅
|
212
|
+
- 插件生命周期管理 ✅
|
213
|
+
- 插件依赖管理 ✅
|
214
|
+
- 插件配置管理 ✅
|
215
|
+
- 钩子系统实现 ✅
|
216
|
+
- 错误处理机制 ✅
|
217
|
+
- 单元测试覆盖 ✅
|
218
|
+
4. 监控和可观测性 ✅
|
219
|
+
- [x] 指标收集(计数器、仪表盘、直方图、摘要)
|
220
|
+
- [x] 分布式追踪(跨度、事件、错误跟踪)
|
221
|
+
- [x] 结构化日志(级别、上下文)
|
222
|
+
- [x] 单元测试覆盖
|
223
|
+
|
224
|
+
## 5. 技术决策 ✅
|
225
|
+
|
226
|
+
### TypeScript配置 ✅
|
227
|
+
- 目标: ES2020+ ✅
|
228
|
+
- 启用严格类型检查 ✅
|
229
|
+
- ESM模块 ✅
|
230
|
+
- Node.js 18+支持 ✅
|
231
|
+
|
232
|
+
### 依赖 ✅
|
233
|
+
- OpenAI API客户端 ✅
|
234
|
+
- 向量存储(Milvus/Qdrant客户端) ✅
|
235
|
+
- 文档处理库 ✅
|
236
|
+
- 测试框架(Jest) ✅
|
237
|
+
- 日志(Winston/Pino) ✅
|
238
|
+
|
239
|
+
### 架构改进 ✅
|
240
|
+
1. 增强类型安全 ✅
|
241
|
+
- 严格类型定义 ✅
|
242
|
+
- 运行时类型验证 ✅
|
243
|
+
- 接口优先设计 ✅
|
244
|
+
|
245
|
+
2. 现代JavaScript特性 ✅
|
246
|
+
- 全面使用async/await ✅
|
247
|
+
- ES模块 ✅
|
248
|
+
- 装饰器用于角色和动作定义 ✅
|
249
|
+
|
250
|
+
3. 开发者体验 ✅
|
251
|
+
- 更好的IDE集成 ✅
|
252
|
+
- 改进的错误消息 ✅
|
253
|
+
- 完整的文档 ✅
|
254
|
+
|
255
|
+
## 6. 实现策略 ✅
|
256
|
+
|
257
|
+
### 步骤1:项目设置 ✅
|
258
|
+
1. 初始化package.json ✅
|
259
|
+
2. 配置TypeScript ✅
|
260
|
+
3. 设置开发工具 ✅
|
261
|
+
4. 创建基本项目结构 ✅
|
262
|
+
|
263
|
+
### 步骤2:核心实现 ✅
|
264
|
+
1. 移植基础工具和辅助函数 ✅
|
265
|
+
2. 实现配置系统 ✅
|
266
|
+
3. 创建基类和接口 ✅
|
267
|
+
4. 设置LLM提供商集成 ✅
|
268
|
+
|
269
|
+
### 步骤3:角色系统 ✅
|
270
|
+
1. 实现角色基类 ✅
|
271
|
+
2. 移植基本角色 ✅
|
272
|
+
3. 设置消息处理 ✅
|
273
|
+
4. 实现状态管理 ✅
|
274
|
+
|
275
|
+
### 步骤4:动作和技能 ✅
|
276
|
+
1. 创建动作框架 ✅
|
277
|
+
2. 移植基本动作 ✅
|
278
|
+
3. 实现技能系统 ✅
|
279
|
+
4. 添加工具集成 ✅
|
280
|
+
|
281
|
+
### 步骤5:高级功能 ✅
|
282
|
+
1. 实现RAG系统 ✅
|
283
|
+
2. 添加团队管理 ✅
|
284
|
+
3. 创建工作流编排 ✅
|
285
|
+
4. 移植剩余功能 ✅
|
286
|
+
|
287
|
+
## 7. 测试策略 ✅
|
288
|
+
1. 单元测试(Vitest) ✅
|
289
|
+
2. 集成测试 ✅
|
290
|
+
3. E2E测试 ✅
|
291
|
+
4. 性能基准测试 ✅
|
292
|
+
|
293
|
+
## 8. 文档
|
294
|
+
1. API文档 ✅
|
295
|
+
- TypeDoc配置 ✅
|
296
|
+
- JSDoc注释 ✅
|
297
|
+
- API参考文档生成 ✅
|
298
|
+
2. 使用示例
|
299
|
+
3. 迁移指南
|
300
|
+
4. 最佳实践
|
301
|
+
|
302
|
+
## 9. 兼容性考虑
|
303
|
+
1. 尽可能保持API兼容性 ✅
|
304
|
+
2. 记录破坏性变更 ✅
|
305
|
+
3. 提供迁移工具
|
306
|
+
4. 支持渐进式采用
|
307
|
+
|
308
|
+
## 10. 未来增强
|
309
|
+
1. WebSocket支持 ✅
|
310
|
+
2. 浏览器兼容性 ✅
|
311
|
+
3. 插件系统 ✅
|
312
|
+
4. 增强监控和可观察性
|
313
|
+
|
314
|
+
## 时间线
|
315
|
+
- 第一阶段: 2周 ✅
|
316
|
+
- 第二阶段: 2周 ✅
|
317
|
+
- 第三阶段: 2周 ✅
|
318
|
+
- 测试和文档: 1周
|
319
|
+
- 缓冲和完善: 1周
|
320
|
+
|
321
|
+
总计预估时间: 8周
|
package/plan.md
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
# MetaGPT TypeScript Migration Plan
|
2
|
+
|
3
|
+
## 1. Project Structure
|
4
|
+
|
5
|
+
```
|
6
|
+
metagpt-ts/
|
7
|
+
├── src/
|
8
|
+
│ ├── actions/ # Action definitions and implementations
|
9
|
+
│ ├── roles/ # Role definitions and behaviors
|
10
|
+
│ ├── utils/ # Utility functions and helpers
|
11
|
+
│ ├── config/ # Configuration management
|
12
|
+
│ ├── memory/ # Memory and state management
|
13
|
+
│ ├── provider/ # LLM providers integration
|
14
|
+
│ ├── tools/ # External tools integration
|
15
|
+
│ ├── skills/ # Skill implementations
|
16
|
+
│ ├── rag/ # Retrieval-augmented generation
|
17
|
+
│ ├── document/ # Document processing and management
|
18
|
+
│ └── types/ # TypeScript type definitions
|
19
|
+
├── tests/ # Test files
|
20
|
+
├── examples/ # Example implementations
|
21
|
+
└── package.json # Project dependencies and scripts
|
22
|
+
```
|
23
|
+
|
24
|
+
## 2. Core Components Migration Priority
|
25
|
+
|
26
|
+
### Phase 1: Foundation (Week 1-2)
|
27
|
+
1. Basic project setup
|
28
|
+
- Initialize TypeScript project
|
29
|
+
- Setup development environment (ESLint, Prettier, Jest)
|
30
|
+
- Define base interfaces and types
|
31
|
+
- Implement core utilities
|
32
|
+
|
33
|
+
2. Essential Components
|
34
|
+
- Context and Configuration management
|
35
|
+
- Basic LLM provider integration
|
36
|
+
- Document and memory management foundation
|
37
|
+
|
38
|
+
### Phase 2: Core Functionality (Week 3-4)
|
39
|
+
1. Role System
|
40
|
+
- Base Role class implementation
|
41
|
+
- Role lifecycle management
|
42
|
+
- Message handling system
|
43
|
+
|
44
|
+
2. Action System
|
45
|
+
- Action base classes
|
46
|
+
- Action execution framework
|
47
|
+
- Message and state management
|
48
|
+
|
49
|
+
### Phase 3: Advanced Features (Week 5-6)
|
50
|
+
1. Skills and Tools
|
51
|
+
- Skill system implementation
|
52
|
+
- Tool integration framework
|
53
|
+
- RAG implementation
|
54
|
+
|
55
|
+
2. Team and Management
|
56
|
+
- Team coordination
|
57
|
+
- Task management
|
58
|
+
- Workflow orchestration
|
59
|
+
|
60
|
+
## 3. Technical Decisions
|
61
|
+
|
62
|
+
### TypeScript Configuration
|
63
|
+
- Target: ES2020+
|
64
|
+
- Strict type checking enabled
|
65
|
+
- ESM modules
|
66
|
+
- Node.js 18+ support
|
67
|
+
|
68
|
+
### Dependencies
|
69
|
+
- OpenAI API client
|
70
|
+
- Vector storage (e.g., Milvus/Qdrant client)
|
71
|
+
- Document processing libraries
|
72
|
+
- Testing framework (Jest)
|
73
|
+
- Logging (Winston/Pino)
|
74
|
+
|
75
|
+
### Architecture Improvements
|
76
|
+
1. Enhanced Type Safety
|
77
|
+
- Strict typing for all components
|
78
|
+
- Runtime type validation
|
79
|
+
- Interface-first design
|
80
|
+
|
81
|
+
2. Modern JavaScript Features
|
82
|
+
- Async/await throughout
|
83
|
+
- ES modules
|
84
|
+
- Decorators for role and action definitions
|
85
|
+
|
86
|
+
3. Developer Experience
|
87
|
+
- Better IDE integration
|
88
|
+
- Improved error messages
|
89
|
+
- Comprehensive documentation
|
90
|
+
|
91
|
+
## 4. Implementation Strategy
|
92
|
+
|
93
|
+
### Step 1: Project Setup
|
94
|
+
1. Initialize project with `package.json`
|
95
|
+
2. Configure TypeScript
|
96
|
+
3. Setup development tools
|
97
|
+
4. Create basic project structure
|
98
|
+
|
99
|
+
### Step 2: Core Implementation
|
100
|
+
1. Port basic utilities and helpers
|
101
|
+
2. Implement configuration system
|
102
|
+
3. Create base classes and interfaces
|
103
|
+
4. Setup LLM provider integration
|
104
|
+
|
105
|
+
### Step 3: Role System
|
106
|
+
1. Implement Role base class
|
107
|
+
2. Port essential roles
|
108
|
+
3. Setup message handling
|
109
|
+
4. Implement state management
|
110
|
+
|
111
|
+
### Step 4: Actions and Skills
|
112
|
+
1. Create action framework
|
113
|
+
2. Port basic actions
|
114
|
+
3. Implement skill system
|
115
|
+
4. Add tool integration
|
116
|
+
|
117
|
+
### Step 5: Advanced Features
|
118
|
+
1. Implement RAG system
|
119
|
+
2. Add team management
|
120
|
+
3. Create workflow orchestration
|
121
|
+
4. Port remaining features
|
122
|
+
|
123
|
+
## 5. Testing Strategy
|
124
|
+
1. Unit tests for all components
|
125
|
+
2. Integration tests for workflows
|
126
|
+
3. E2E tests for complete scenarios
|
127
|
+
4. Performance benchmarking
|
128
|
+
|
129
|
+
## 6. Documentation
|
130
|
+
1. API documentation
|
131
|
+
2. Usage examples
|
132
|
+
3. Migration guide
|
133
|
+
4. Best practices
|
134
|
+
|
135
|
+
## 7. Compatibility Considerations
|
136
|
+
1. Maintain API compatibility where possible
|
137
|
+
2. Document breaking changes
|
138
|
+
3. Provide migration utilities
|
139
|
+
4. Support gradual adoption
|
140
|
+
|
141
|
+
## 8. Future Enhancements
|
142
|
+
1. WebSocket support for real-time interactions
|
143
|
+
2. Browser compatibility
|
144
|
+
3. Plugin system
|
145
|
+
4. Enhanced monitoring and observability
|
146
|
+
|
147
|
+
## Timeline
|
148
|
+
- Phase 1: 2 weeks
|
149
|
+
- Phase 2: 2 weeks
|
150
|
+
- Phase 3: 2 weeks
|
151
|
+
- Testing & Documentation: 1 week
|
152
|
+
- Buffer & Polish: 1 week
|
153
|
+
|
154
|
+
Total estimated time: 8 weeks
|
@@ -0,0 +1,65 @@
|
|
1
|
+
import { BaseAction } from './base-action';
|
2
|
+
import type { ActionOutput, ActionConfig } from '../types/action';
|
3
|
+
|
4
|
+
/**
|
5
|
+
* 任务分析动作
|
6
|
+
* 使用 LLM 分析任务需求并生成结构化输出
|
7
|
+
*/
|
8
|
+
export class AnalyzeTask extends BaseAction {
|
9
|
+
constructor(config: ActionConfig) {
|
10
|
+
super({
|
11
|
+
...config,
|
12
|
+
name: 'analyze_task',
|
13
|
+
description: 'Analyze task requirements and generate structured output',
|
14
|
+
});
|
15
|
+
}
|
16
|
+
|
17
|
+
/**
|
18
|
+
* 执行任务分析
|
19
|
+
* @returns 分析结果
|
20
|
+
*/
|
21
|
+
async run(): Promise<ActionOutput> {
|
22
|
+
try {
|
23
|
+
// 获取任务内容
|
24
|
+
const task = this.getArg<string>('task');
|
25
|
+
if (!task) {
|
26
|
+
return this.createOutput('No task provided', 'failed');
|
27
|
+
}
|
28
|
+
|
29
|
+
// 构建提示词
|
30
|
+
const prompt = `
|
31
|
+
Please analyze the following task and provide a structured response:
|
32
|
+
Task: ${task}
|
33
|
+
|
34
|
+
Please provide:
|
35
|
+
1. Task objective
|
36
|
+
2. Key requirements
|
37
|
+
3. Potential challenges
|
38
|
+
4. Suggested approach
|
39
|
+
5. Required resources
|
40
|
+
|
41
|
+
Format your response in a clear, structured manner.
|
42
|
+
`;
|
43
|
+
|
44
|
+
// 调用 LLM 进行分析
|
45
|
+
const analysis = await this.llm.generate(prompt);
|
46
|
+
|
47
|
+
return this.createOutput(analysis);
|
48
|
+
} catch (error) {
|
49
|
+
await this.handleException(error as Error);
|
50
|
+
return this.createOutput(
|
51
|
+
`Failed to analyze task: ${(error as Error).message}`,
|
52
|
+
'failed'
|
53
|
+
);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* 自定义错误处理
|
59
|
+
*/
|
60
|
+
async handleException(error: Error): Promise<void> {
|
61
|
+
await super.handleException(error);
|
62
|
+
// 可以添加特定的错误处理逻辑
|
63
|
+
this.setArg('lastError', error.message);
|
64
|
+
}
|
65
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
import type { Action, ActionContext, ActionOutput, ActionConfig } from '../types/action';
|
3
|
+
import type { LLMProvider } from '../types/llm';
|
4
|
+
import { ActionContextSchema, ActionOutputSchema } from '../types/action';
|
5
|
+
|
6
|
+
/**
|
7
|
+
* 动作基类
|
8
|
+
* 提供动作系统的基础功能实现
|
9
|
+
*/
|
10
|
+
export abstract class BaseAction implements Action {
|
11
|
+
name: string;
|
12
|
+
context: ActionContext;
|
13
|
+
llm: LLMProvider;
|
14
|
+
|
15
|
+
constructor(config: ActionConfig) {
|
16
|
+
// 验证配置
|
17
|
+
const validConfig = z.object({
|
18
|
+
name: z.string(),
|
19
|
+
description: z.string().optional(),
|
20
|
+
args: z.record(z.any()).optional(),
|
21
|
+
llm: z.any(),
|
22
|
+
memory: z.any().optional(),
|
23
|
+
workingMemory: z.any().optional(),
|
24
|
+
}).parse(config);
|
25
|
+
|
26
|
+
this.name = validConfig.name;
|
27
|
+
this.llm = validConfig.llm;
|
28
|
+
|
29
|
+
// 构建上下文
|
30
|
+
this.context = ActionContextSchema.parse({
|
31
|
+
name: validConfig.name,
|
32
|
+
description: validConfig.description || '',
|
33
|
+
args: validConfig.args || {},
|
34
|
+
llm: validConfig.llm,
|
35
|
+
memory: validConfig.memory,
|
36
|
+
workingMemory: validConfig.workingMemory,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
|
40
|
+
/**
|
41
|
+
* 执行动作
|
42
|
+
* 子类必须实现此方法
|
43
|
+
*/
|
44
|
+
abstract run(): Promise<ActionOutput>;
|
45
|
+
|
46
|
+
/**
|
47
|
+
* 处理异常
|
48
|
+
* @param error 错误对象
|
49
|
+
*/
|
50
|
+
async handleException(error: Error): Promise<void> {
|
51
|
+
console.error(`Action ${this.name} failed:`, error);
|
52
|
+
// 子类可以覆盖此方法以提供自定义错误处理
|
53
|
+
}
|
54
|
+
|
55
|
+
/**
|
56
|
+
* 验证动作输出
|
57
|
+
* @param output 动作输出
|
58
|
+
* @returns 验证后的输出
|
59
|
+
*/
|
60
|
+
protected validateOutput(output: ActionOutput): ActionOutput {
|
61
|
+
return ActionOutputSchema.parse(output);
|
62
|
+
}
|
63
|
+
|
64
|
+
/**
|
65
|
+
* 生成动作输出
|
66
|
+
* @param content 输出内容
|
67
|
+
* @param status 动作状态
|
68
|
+
* @param instructContent 指令内容(可选)
|
69
|
+
* @returns 动作输出
|
70
|
+
*/
|
71
|
+
protected createOutput(
|
72
|
+
content: string,
|
73
|
+
status: 'completed' | 'failed' | 'blocked' = 'completed',
|
74
|
+
instructContent?: any
|
75
|
+
): ActionOutput {
|
76
|
+
return this.validateOutput({
|
77
|
+
content,
|
78
|
+
status,
|
79
|
+
instructContent,
|
80
|
+
});
|
81
|
+
}
|
82
|
+
|
83
|
+
/**
|
84
|
+
* 获取动作参数
|
85
|
+
* @param key 参数键
|
86
|
+
* @returns 参数值
|
87
|
+
*/
|
88
|
+
protected getArg<T>(key: string): T | undefined {
|
89
|
+
return this.context.args?.[key] as T;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* 设置动作参数
|
94
|
+
* @param key 参数键
|
95
|
+
* @param value 参数值
|
96
|
+
*/
|
97
|
+
protected setArg<T>(key: string, value: T): void {
|
98
|
+
if (!this.context.args) {
|
99
|
+
this.context.args = {};
|
100
|
+
}
|
101
|
+
this.context.args[key] = value;
|
102
|
+
}
|
103
|
+
}
|