@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
@@ -0,0 +1,33 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Browser type enumeration
|
5
|
+
*/
|
6
|
+
export enum BrowserType {
|
7
|
+
PLAYWRIGHT = 'playwright',
|
8
|
+
PUPPETEER = 'puppeteer',
|
9
|
+
SELENIUM = 'selenium',
|
10
|
+
}
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Browser configuration schema
|
14
|
+
*/
|
15
|
+
export const BrowserConfigSchema = z.object({
|
16
|
+
browserType: z.nativeEnum(BrowserType).default(BrowserType.PLAYWRIGHT),
|
17
|
+
headless: z.boolean().default(true),
|
18
|
+
timeout: z.number().default(30000),
|
19
|
+
waitUntil: z.enum(['load', 'domcontentloaded', 'networkidle', 'commit']).default('networkidle'),
|
20
|
+
proxy: z.string().optional(),
|
21
|
+
userAgent: z.string().optional(),
|
22
|
+
viewport: z.object({
|
23
|
+
width: z.number().default(1280),
|
24
|
+
height: z.number().default(800),
|
25
|
+
}).optional(),
|
26
|
+
ignoreHTTPSErrors: z.boolean().default(true),
|
27
|
+
maxConcurrency: z.number().default(10),
|
28
|
+
retryCount: z.number().default(3),
|
29
|
+
downloadPath: z.string().optional(),
|
30
|
+
extraHeaders: z.record(z.string()).default({}),
|
31
|
+
});
|
32
|
+
|
33
|
+
export type BrowserConfig = z.infer<typeof BrowserConfigSchema>;
|
@@ -0,0 +1,345 @@
|
|
1
|
+
/**
|
2
|
+
* @module Config
|
3
|
+
* @category Core
|
4
|
+
*/
|
5
|
+
|
6
|
+
import { z } from 'zod';
|
7
|
+
import path from 'path';
|
8
|
+
import fs from 'fs/promises';
|
9
|
+
import { readFileSync } from 'fs';
|
10
|
+
import { merge } from 'lodash';
|
11
|
+
import { LLMType, LLMConfigSchema } from './llm';
|
12
|
+
import type { LLMConfig } from './llm';
|
13
|
+
import type { EmbeddingConfig } from './embedding';
|
14
|
+
import { EmbeddingConfigSchema } from './embedding';
|
15
|
+
import type { OmniParseConfig } from './omniparse';
|
16
|
+
import { OmniParseConfigSchema } from './omniparse';
|
17
|
+
import type { SearchConfig } from './search';
|
18
|
+
import { SearchConfigSchema } from './search';
|
19
|
+
import type { BrowserConfig } from './browser';
|
20
|
+
import { BrowserConfigSchema } from './browser';
|
21
|
+
import type { MermaidConfig } from './mermaid';
|
22
|
+
import { MermaidConfigSchema } from './mermaid';
|
23
|
+
import type { S3Config } from './s3';
|
24
|
+
import { S3ConfigSchema } from './s3';
|
25
|
+
import type { RedisConfig } from './redis';
|
26
|
+
import { RedisConfigSchema } from './redis';
|
27
|
+
import type { WorkspaceConfig } from './workspace';
|
28
|
+
import { WorkspaceConfigSchema } from './workspace';
|
29
|
+
import { YamlModel } from '../utils/yaml';
|
30
|
+
|
31
|
+
/**
|
32
|
+
* CLI parameters schema
|
33
|
+
*/
|
34
|
+
export const CLIParamsSchema = z.object({
|
35
|
+
projectPath: z.string().default(''),
|
36
|
+
projectName: z.string().default(''),
|
37
|
+
inc: z.boolean().default(false),
|
38
|
+
reqaFile: z.string().default(''),
|
39
|
+
maxAutoSummarizeCode: z.number().default(0),
|
40
|
+
gitReinit: z.boolean().default(false),
|
41
|
+
}).transform((data) => {
|
42
|
+
if (data.projectPath) {
|
43
|
+
data.inc = true;
|
44
|
+
data.projectName = data.projectName || path.basename(data.projectPath);
|
45
|
+
}
|
46
|
+
return data;
|
47
|
+
});
|
48
|
+
|
49
|
+
/**
|
50
|
+
* Main configuration schema for MetaGPT
|
51
|
+
*/
|
52
|
+
export const ConfigSchema = z.object({
|
53
|
+
// CLI Parameters
|
54
|
+
projectPath: z.string().default(''),
|
55
|
+
projectName: z.string().default(''),
|
56
|
+
inc: z.boolean().default(false),
|
57
|
+
reqaFile: z.string().default(''),
|
58
|
+
maxAutoSummarizeCode: z.number().default(0),
|
59
|
+
gitReinit: z.boolean().default(false),
|
60
|
+
|
61
|
+
// Key Parameters
|
62
|
+
llm: LLMConfigSchema.default({
|
63
|
+
apiType: LLMType.OPENAI,
|
64
|
+
apiKey: '',
|
65
|
+
model: 'gpt-4',
|
66
|
+
maxTokens: 4096,
|
67
|
+
temperature: 0.7,
|
68
|
+
topP: 1,
|
69
|
+
n: 1,
|
70
|
+
presencePenalty: 0,
|
71
|
+
frequencyPenalty: 0,
|
72
|
+
maxRetries: 3,
|
73
|
+
timeout: 60000,
|
74
|
+
}),
|
75
|
+
|
76
|
+
// RAG Embedding
|
77
|
+
embedding: EmbeddingConfigSchema.default({}),
|
78
|
+
|
79
|
+
// Omniparse
|
80
|
+
omniparse: OmniParseConfigSchema.default({}),
|
81
|
+
|
82
|
+
// Global Proxy
|
83
|
+
proxy: z.string().default(''),
|
84
|
+
|
85
|
+
// Tool Parameters
|
86
|
+
search: SearchConfigSchema.default({}),
|
87
|
+
browser: BrowserConfigSchema.default({}),
|
88
|
+
mermaid: MermaidConfigSchema.default({}),
|
89
|
+
|
90
|
+
// Storage Parameters
|
91
|
+
s3: S3ConfigSchema.optional(),
|
92
|
+
redis: RedisConfigSchema.optional(),
|
93
|
+
|
94
|
+
// Misc Parameters
|
95
|
+
repairLlmOutput: z.boolean().default(false),
|
96
|
+
promptSchema: z.enum(['json', 'markdown', 'raw']).default('json'),
|
97
|
+
workspace: WorkspaceConfigSchema.default({}),
|
98
|
+
enableLongtermMemory: z.boolean().default(false),
|
99
|
+
codeReviewKTimes: z.number().default(2),
|
100
|
+
agentopsApiKey: z.string().default(''),
|
101
|
+
|
102
|
+
// Legacy Parameters (to be removed)
|
103
|
+
metagptTtiUrl: z.string().default(''),
|
104
|
+
language: z.string().default('English'),
|
105
|
+
redisKey: z.string().default('placeholder'),
|
106
|
+
iflytekAppId: z.string().default(''),
|
107
|
+
iflytekApiSecret: z.string().default(''),
|
108
|
+
iflytekApiKey: z.string().default(''),
|
109
|
+
azureTtsSubscriptionKey: z.string().default(''),
|
110
|
+
azureTtsRegion: z.string().default(''),
|
111
|
+
extra: z.record(z.any()).default({}),
|
112
|
+
});
|
113
|
+
|
114
|
+
export type Config = z.infer<typeof ConfigSchema>;
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Configuration manager class for MetaGPT
|
118
|
+
*/
|
119
|
+
export class ConfigManager {
|
120
|
+
private config: Config;
|
121
|
+
private static instance: ConfigManager;
|
122
|
+
|
123
|
+
private constructor(config: Config) {
|
124
|
+
this.config = config;
|
125
|
+
}
|
126
|
+
|
127
|
+
/**
|
128
|
+
* Get singleton instance of ConfigManager
|
129
|
+
*/
|
130
|
+
public static getInstance(options: { configPath?: string; loadEnv?: boolean; useDefaults?: boolean } = {}): ConfigManager {
|
131
|
+
if (!ConfigManager.instance) {
|
132
|
+
const config = ConfigSchema.parse({});
|
133
|
+
ConfigManager.instance = new ConfigManager(config);
|
134
|
+
|
135
|
+
if (options.loadEnv) {
|
136
|
+
ConfigManager.instance.updateConfig(process.env as Partial<Config>);
|
137
|
+
}
|
138
|
+
|
139
|
+
if (options.configPath) {
|
140
|
+
try {
|
141
|
+
const content = readFileSync(options.configPath, 'utf-8');
|
142
|
+
const fileConfig = YamlModel.parse(content) as Partial<Config>;
|
143
|
+
ConfigManager.instance.updateConfig(fileConfig);
|
144
|
+
} catch (e) {
|
145
|
+
// Ignore file read errors
|
146
|
+
}
|
147
|
+
}
|
148
|
+
}
|
149
|
+
return ConfigManager.instance;
|
150
|
+
}
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Get current configuration
|
154
|
+
*/
|
155
|
+
public getConfig(): Config {
|
156
|
+
return this.config;
|
157
|
+
}
|
158
|
+
|
159
|
+
/**
|
160
|
+
* Update configuration
|
161
|
+
*/
|
162
|
+
public updateConfig(config: Partial<Config>): void {
|
163
|
+
this.config = ConfigSchema.parse({
|
164
|
+
...this.config,
|
165
|
+
...config,
|
166
|
+
});
|
167
|
+
}
|
168
|
+
|
169
|
+
/**
|
170
|
+
* Load configuration from home directory
|
171
|
+
*/
|
172
|
+
public static async fromHome(configPath: string): Promise<ConfigManager | null> {
|
173
|
+
const homePath = process.env.HOME || process.env.USERPROFILE;
|
174
|
+
if (!homePath) return null;
|
175
|
+
|
176
|
+
const configFile = path.join(homePath, '.metagpt', configPath);
|
177
|
+
try {
|
178
|
+
const content = await fs.readFile(configFile, 'utf-8');
|
179
|
+
const config = YamlModel.parse(content);
|
180
|
+
return new ConfigManager(ConfigSchema.parse(config));
|
181
|
+
} catch {
|
182
|
+
return null;
|
183
|
+
}
|
184
|
+
}
|
185
|
+
|
186
|
+
/**
|
187
|
+
* Load default configuration
|
188
|
+
*/
|
189
|
+
public static async default(): Promise<ConfigManager> {
|
190
|
+
const defaultPaths = [
|
191
|
+
path.join(process.cwd(), 'config/config.yaml'),
|
192
|
+
path.join(process.env.HOME || '', '.metagpt/config.yaml'),
|
193
|
+
];
|
194
|
+
|
195
|
+
const configs = [process.env];
|
196
|
+
for (const configPath of defaultPaths) {
|
197
|
+
try {
|
198
|
+
const content = await fs.readFile(configPath, 'utf-8');
|
199
|
+
configs.push(YamlModel.parse(content));
|
200
|
+
} catch {
|
201
|
+
continue;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
const mergedConfig = merge({}, ...configs);
|
206
|
+
return new ConfigManager(ConfigSchema.parse(mergedConfig));
|
207
|
+
}
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Create configuration from LLM config
|
211
|
+
*/
|
212
|
+
public static fromLLMConfig(llmConfig: Partial<LLMConfig>): ConfigManager {
|
213
|
+
const config = merge({}, process.env, { llm: llmConfig });
|
214
|
+
return new ConfigManager(ConfigSchema.parse(config));
|
215
|
+
}
|
216
|
+
|
217
|
+
/**
|
218
|
+
* Create configuration from environment variables
|
219
|
+
*/
|
220
|
+
public static fromEnvironment(): ConfigManager {
|
221
|
+
const envConfig: Partial<Config> = {};
|
222
|
+
|
223
|
+
// Parse OpenAI configuration from environment
|
224
|
+
if (process.env.OPENAI_API_KEY) {
|
225
|
+
envConfig.llm = {
|
226
|
+
apiType: LLMType.OPENAI,
|
227
|
+
apiKey: process.env.OPENAI_API_KEY || '',
|
228
|
+
model: process.env.OPENAI_MODEL || 'gpt-4',
|
229
|
+
maxTokens: 4096,
|
230
|
+
temperature: 0.7,
|
231
|
+
topP: 1,
|
232
|
+
n: 1,
|
233
|
+
presencePenalty: 0,
|
234
|
+
frequencyPenalty: 0,
|
235
|
+
maxRetries: 3,
|
236
|
+
timeout: 60000,
|
237
|
+
};
|
238
|
+
}
|
239
|
+
|
240
|
+
// Parse Azure configuration from environment
|
241
|
+
if (process.env.AZURE_API_KEY) {
|
242
|
+
envConfig.llm = {
|
243
|
+
apiType: LLMType.AZURE,
|
244
|
+
apiKey: process.env.AZURE_API_KEY || '',
|
245
|
+
model: process.env.AZURE_MODEL || 'gpt-4',
|
246
|
+
maxTokens: 4096,
|
247
|
+
temperature: 0.7,
|
248
|
+
topP: 1,
|
249
|
+
n: 1,
|
250
|
+
presencePenalty: 0,
|
251
|
+
frequencyPenalty: 0,
|
252
|
+
maxRetries: 3,
|
253
|
+
timeout: 60000,
|
254
|
+
endpoint: process.env.AZURE_ENDPOINT,
|
255
|
+
apiVersion: process.env.AZURE_API_VERSION,
|
256
|
+
deploymentName: process.env.AZURE_DEPLOYMENT_NAME,
|
257
|
+
};
|
258
|
+
}
|
259
|
+
|
260
|
+
// Parse proxy configuration
|
261
|
+
if (process.env.METAGPT_PROXY) {
|
262
|
+
envConfig.proxy = process.env.METAGPT_PROXY;
|
263
|
+
}
|
264
|
+
|
265
|
+
// Parse other common environment variables
|
266
|
+
if (process.env.METAGPT_PROJECT_PATH) {
|
267
|
+
envConfig.projectPath = process.env.METAGPT_PROJECT_PATH;
|
268
|
+
}
|
269
|
+
|
270
|
+
if (process.env.METAGPT_PROJECT_NAME) {
|
271
|
+
envConfig.projectName = process.env.METAGPT_PROJECT_NAME;
|
272
|
+
}
|
273
|
+
|
274
|
+
return new ConfigManager(ConfigSchema.parse(envConfig));
|
275
|
+
}
|
276
|
+
|
277
|
+
/**
|
278
|
+
* Merge configurations according to priority
|
279
|
+
*/
|
280
|
+
public static async mergeConfigs(fileConfig: ConfigManager, cliConfig: Partial<Config>): Promise<ConfigManager> {
|
281
|
+
// Priority: CLI > File config > Environment variables
|
282
|
+
const envConfig = ConfigManager.fromEnvironment();
|
283
|
+
|
284
|
+
// Merge in order of priority
|
285
|
+
const mergedConfig = merge(
|
286
|
+
{},
|
287
|
+
envConfig.getConfig(),
|
288
|
+
fileConfig.getConfig(),
|
289
|
+
cliConfig as Record<string, unknown>
|
290
|
+
);
|
291
|
+
|
292
|
+
return new ConfigManager(ConfigSchema.parse(mergedConfig));
|
293
|
+
}
|
294
|
+
|
295
|
+
/**
|
296
|
+
* Update configuration via CLI parameters
|
297
|
+
*/
|
298
|
+
public updateViaCLI(params: Partial<z.infer<typeof CLIParamsSchema>>): void {
|
299
|
+
const { projectPath, projectName, inc, reqaFile, maxAutoSummarizeCode } = params;
|
300
|
+
|
301
|
+
this.config = ConfigSchema.parse({
|
302
|
+
...this.config,
|
303
|
+
projectPath,
|
304
|
+
projectName: projectName || (projectPath ? path.basename(projectPath) : ''),
|
305
|
+
inc: inc || !!projectPath,
|
306
|
+
reqaFile,
|
307
|
+
maxAutoSummarizeCode,
|
308
|
+
});
|
309
|
+
}
|
310
|
+
|
311
|
+
/**
|
312
|
+
* Get OpenAI LLM configuration
|
313
|
+
*/
|
314
|
+
public getOpenAILLM(): LLMConfig | null {
|
315
|
+
return this.config.llm.apiType === LLMType.OPENAI ? this.config.llm as LLMConfig : null;
|
316
|
+
}
|
317
|
+
|
318
|
+
/**
|
319
|
+
* Get Azure LLM configuration
|
320
|
+
*/
|
321
|
+
public getAzureLLM(): LLMConfig | null {
|
322
|
+
return this.config.llm.apiType === LLMType.AZURE ? this.config.llm as LLMConfig : null;
|
323
|
+
}
|
324
|
+
|
325
|
+
/**
|
326
|
+
* Get extra configuration
|
327
|
+
*/
|
328
|
+
public get extra(): Record<string, any> {
|
329
|
+
return this.config.extra as Record<string, any>;
|
330
|
+
}
|
331
|
+
|
332
|
+
/**
|
333
|
+
* Set extra configuration
|
334
|
+
*/
|
335
|
+
public set extra(value: Record<string, any>) {
|
336
|
+
this.config.extra = value;
|
337
|
+
}
|
338
|
+
}
|
339
|
+
|
340
|
+
/**
|
341
|
+
* Get default configuration instance
|
342
|
+
*/
|
343
|
+
export async function getConfig(): Promise<ConfigManager> {
|
344
|
+
return ConfigManager.default();
|
345
|
+
}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Embedding model types
|
5
|
+
*/
|
6
|
+
export enum EmbeddingModelType {
|
7
|
+
OPENAI = 'text-embedding-ada-002',
|
8
|
+
HUGGINGFACE = 'sentence-transformers/all-mpnet-base-v2',
|
9
|
+
CUSTOM = 'custom',
|
10
|
+
}
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Embedding configuration schema
|
14
|
+
*/
|
15
|
+
export const EmbeddingConfigSchema = z.object({
|
16
|
+
modelType: z.nativeEnum(EmbeddingModelType).default(EmbeddingModelType.OPENAI),
|
17
|
+
modelName: z.string().optional(),
|
18
|
+
dimensions: z.number().default(1536),
|
19
|
+
apiKey: z.string().optional(),
|
20
|
+
apiBase: z.string().optional(),
|
21
|
+
batchSize: z.number().default(512),
|
22
|
+
timeout: z.number().default(60),
|
23
|
+
maxRetries: z.number().default(3),
|
24
|
+
});
|
25
|
+
|
26
|
+
export type EmbeddingConfig = z.infer<typeof EmbeddingConfigSchema>;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* LLM API types
|
5
|
+
*/
|
6
|
+
export enum LLMType {
|
7
|
+
OPENAI = 'openai',
|
8
|
+
AZURE = 'azure',
|
9
|
+
ANTHROPIC = 'anthropic',
|
10
|
+
HUGGINGFACE = 'huggingface',
|
11
|
+
CUSTOM = 'custom',
|
12
|
+
}
|
13
|
+
|
14
|
+
/**
|
15
|
+
* LLM configuration schema
|
16
|
+
*/
|
17
|
+
export const LLMConfigSchema = z.object({
|
18
|
+
apiType: z.nativeEnum(LLMType).default(LLMType.OPENAI),
|
19
|
+
apiKey: z.string().default(''),
|
20
|
+
apiBase: z.string().optional(),
|
21
|
+
apiVersion: z.string().optional(),
|
22
|
+
model: z.string().default('gpt-4'),
|
23
|
+
maxTokens: z.number().default(2000),
|
24
|
+
temperature: z.number().default(0.7),
|
25
|
+
topP: z.number().default(0.95),
|
26
|
+
n: z.number().default(1),
|
27
|
+
stop: z.array(z.string()).optional(),
|
28
|
+
presencePenalty: z.number().default(0.0),
|
29
|
+
frequencyPenalty: z.number().default(0.0),
|
30
|
+
logitBias: z.record(z.number()).optional(),
|
31
|
+
proxy: z.string().optional(),
|
32
|
+
timeout: z.number().default(60),
|
33
|
+
maxRetries: z.number().default(3),
|
34
|
+
});
|
35
|
+
|
36
|
+
export type LLMConfig = z.infer<typeof LLMConfigSchema>;
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Mermaid theme types
|
5
|
+
*/
|
6
|
+
export enum MermaidTheme {
|
7
|
+
DEFAULT = 'default',
|
8
|
+
FOREST = 'forest',
|
9
|
+
DARK = 'dark',
|
10
|
+
NEUTRAL = 'neutral',
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Mermaid configuration schema
|
15
|
+
*/
|
16
|
+
export const MermaidConfigSchema = z.object({
|
17
|
+
theme: z.nativeEnum(MermaidTheme).default(MermaidTheme.DEFAULT),
|
18
|
+
startOnLoad: z.boolean().default(true),
|
19
|
+
securityLevel: z.enum(['strict', 'loose', 'antiscript']).default('strict'),
|
20
|
+
logLevel: z.enum(['debug', 'info', 'warn', 'error', 'fatal']).default('info'),
|
21
|
+
arrowMarkerAbsolute: z.boolean().default(false),
|
22
|
+
flowchart: z.object({
|
23
|
+
htmlLabels: z.boolean().default(true),
|
24
|
+
curve: z.enum(['basis', 'linear', 'cardinal']).default('linear'),
|
25
|
+
}).default({}),
|
26
|
+
sequence: z.object({
|
27
|
+
diagramMarginX: z.number().default(50),
|
28
|
+
diagramMarginY: z.number().default(10),
|
29
|
+
actorMargin: z.number().default(50),
|
30
|
+
width: z.number().default(150),
|
31
|
+
height: z.number().default(65),
|
32
|
+
}).default({}),
|
33
|
+
fontSize: z.number().default(16),
|
34
|
+
fontFamily: z.string().default('trebuchet ms'),
|
35
|
+
});
|
36
|
+
|
37
|
+
export type MermaidConfig = z.infer<typeof MermaidConfigSchema>;
|
@@ -0,0 +1,25 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Omniparse configuration schema for file parsing settings
|
5
|
+
*/
|
6
|
+
export const OmniParseConfigSchema = z.object({
|
7
|
+
maxFileSize: z.number().default(10 * 1024 * 1024), // 10MB
|
8
|
+
supportedFormats: z.array(z.string()).default([
|
9
|
+
'.txt', '.md', '.pdf', '.doc', '.docx',
|
10
|
+
'.xls', '.xlsx', '.csv', '.json', '.xml',
|
11
|
+
'.html', '.htm', '.py', '.js', '.ts',
|
12
|
+
'.jsx', '.tsx', '.java', '.cpp', '.c',
|
13
|
+
'.h', '.cs', '.go', '.rs', '.php',
|
14
|
+
'.rb', '.swift', '.kt', '.scala', '.sql',
|
15
|
+
]),
|
16
|
+
extractImages: z.boolean().default(false),
|
17
|
+
extractTables: z.boolean().default(true),
|
18
|
+
preserveFormatting: z.boolean().default(true),
|
19
|
+
chunkSize: z.number().default(1000),
|
20
|
+
overlapSize: z.number().default(100),
|
21
|
+
timeout: z.number().default(30),
|
22
|
+
maxRetries: z.number().default(3),
|
23
|
+
});
|
24
|
+
|
25
|
+
export type OmniParseConfig = z.infer<typeof OmniParseConfigSchema>;
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Redis configuration schema
|
5
|
+
*/
|
6
|
+
export const RedisConfigSchema = z.object({
|
7
|
+
host: z.string().default('localhost'),
|
8
|
+
port: z.number().default(6379),
|
9
|
+
db: z.number().default(0),
|
10
|
+
password: z.string().optional(),
|
11
|
+
username: z.string().optional(),
|
12
|
+
tls: z.boolean().default(false),
|
13
|
+
sentinel: z.object({
|
14
|
+
enabled: z.boolean().default(false),
|
15
|
+
masterName: z.string().optional(),
|
16
|
+
nodes: z.array(z.object({
|
17
|
+
host: z.string(),
|
18
|
+
port: z.number(),
|
19
|
+
})).optional(),
|
20
|
+
}).default({}),
|
21
|
+
cluster: z.object({
|
22
|
+
enabled: z.boolean().default(false),
|
23
|
+
nodes: z.array(z.object({
|
24
|
+
host: z.string(),
|
25
|
+
port: z.number(),
|
26
|
+
})).optional(),
|
27
|
+
}).default({}),
|
28
|
+
maxRetries: z.number().default(3),
|
29
|
+
retryDelay: z.number().default(1000),
|
30
|
+
connectTimeout: z.number().default(10000),
|
31
|
+
keyPrefix: z.string().default('metagpt:'),
|
32
|
+
});
|
33
|
+
|
34
|
+
export type RedisConfig = z.infer<typeof RedisConfigSchema>;
|
package/src/config/s3.ts
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* S3 provider types
|
5
|
+
*/
|
6
|
+
export enum S3ProviderType {
|
7
|
+
AWS = 'aws',
|
8
|
+
MINIO = 'minio',
|
9
|
+
CUSTOM = 'custom',
|
10
|
+
}
|
11
|
+
|
12
|
+
/**
|
13
|
+
* S3 configuration schema
|
14
|
+
*/
|
15
|
+
export const S3ConfigSchema = z.object({
|
16
|
+
provider: z.nativeEnum(S3ProviderType).default(S3ProviderType.AWS),
|
17
|
+
accessKeyId: z.string(),
|
18
|
+
secretAccessKey: z.string(),
|
19
|
+
region: z.string().default('us-east-1'),
|
20
|
+
bucket: z.string(),
|
21
|
+
endpoint: z.string().optional(),
|
22
|
+
forcePathStyle: z.boolean().default(false),
|
23
|
+
sslEnabled: z.boolean().default(true),
|
24
|
+
maxRetries: z.number().default(3),
|
25
|
+
timeout: z.number().default(60),
|
26
|
+
uploadOptions: z.object({
|
27
|
+
partSize: z.number().default(5 * 1024 * 1024), // 5MB
|
28
|
+
queueSize: z.number().default(4),
|
29
|
+
}).default({}),
|
30
|
+
presignedUrlExpiry: z.number().default(3600), // 1 hour
|
31
|
+
});
|
32
|
+
|
33
|
+
export type S3Config = z.infer<typeof S3ConfigSchema>;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { z } from 'zod';
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Search provider types
|
5
|
+
*/
|
6
|
+
export enum SearchProviderType {
|
7
|
+
SERPAPI = 'serpapi',
|
8
|
+
GOOGLE = 'google',
|
9
|
+
BING = 'bing',
|
10
|
+
CUSTOM = 'custom',
|
11
|
+
}
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Search configuration schema
|
15
|
+
*/
|
16
|
+
export const SearchConfigSchema = z.object({
|
17
|
+
provider: z.nativeEnum(SearchProviderType).default(SearchProviderType.SERPAPI),
|
18
|
+
apiKey: z.string().default(''),
|
19
|
+
customSearchId: z.string().optional(),
|
20
|
+
maxResults: z.number().default(10),
|
21
|
+
timeout: z.number().default(30),
|
22
|
+
maxRetries: z.number().default(3),
|
23
|
+
proxy: z.string().optional(),
|
24
|
+
safeSearch: z.boolean().default(true),
|
25
|
+
language: z.string().default('en'),
|
26
|
+
region: z.string().default('us'),
|
27
|
+
includeParams: z.record(z.any()).default({}),
|
28
|
+
});
|
29
|
+
|
30
|
+
export type SearchConfig = z.infer<typeof SearchConfigSchema>;
|
@@ -0,0 +1,20 @@
|
|
1
|
+
/**
|
2
|
+
* @module Config
|
3
|
+
* @category Core
|
4
|
+
*/
|
5
|
+
|
6
|
+
import { z } from 'zod';
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Workspace configuration schema
|
10
|
+
*/
|
11
|
+
export const WorkspaceConfigSchema = z.object({
|
12
|
+
root: z.string().default('./workspace'),
|
13
|
+
autoClean: z.boolean().default(false),
|
14
|
+
storagePath: z.string().default('./storage'),
|
15
|
+
});
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Workspace configuration type
|
19
|
+
*/
|
20
|
+
export type WorkspaceConfig = z.infer<typeof WorkspaceConfigSchema>;
|
package/src/index.ts
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
// 基础类型定义
|
2
|
+
export * from './types/message';
|
3
|
+
export * from './types/role';
|
4
|
+
export * from './types/action';
|
5
|
+
export * from './types/memory';
|
6
|
+
export * from './types/llm';
|
7
|
+
export * from './types/skill';
|
8
|
+
export * from './types/tool';
|
9
|
+
export * from './types/rag';
|
10
|
+
|
11
|
+
// 角色实现
|
12
|
+
export * from './roles/base-role';
|
13
|
+
export * from './roles/engineer';
|
14
|
+
export * from './roles/tutorial-assistant';
|
15
|
+
|
16
|
+
// 动作实现
|
17
|
+
export * from './actions/base-action';
|
18
|
+
export * from './actions/analyze-task';
|
19
|
+
export * from './actions/write-tutorial';
|
20
|
+
|
21
|
+
// 技能实现
|
22
|
+
export * from './skills/base-skill';
|
23
|
+
export * from './skills/code-review';
|
24
|
+
|
25
|
+
// 工具实现
|
26
|
+
export * from './tools/base-tool';
|
27
|
+
export * from './tools/file-system';
|
28
|
+
|
29
|
+
// RAG 实现
|
30
|
+
export * from './rag/base-rag';
|
31
|
+
export * from './rag/document-qa';
|
32
|
+
|
33
|
+
// 提供商实现
|
34
|
+
export * from './provider/vercel-llm';
|
35
|
+
|
36
|
+
// 工具函数
|
37
|
+
export * from './utils/common';
|
38
|
+
|
39
|
+
// 版本信息
|
40
|
+
export const VERSION = '0.1.0';
|