@shareai-lab/kode-sdk 1.0.0-beta.9 → 2.7.0
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/LICENSE +21 -0
- package/README.md +115 -273
- package/README.zh-CN.md +114 -0
- package/dist/core/agent/breakpoint-manager.d.ts +16 -0
- package/dist/core/agent/breakpoint-manager.js +36 -0
- package/dist/core/agent/message-queue.d.ts +26 -0
- package/dist/core/agent/message-queue.js +57 -0
- package/dist/core/agent/permission-manager.d.ts +9 -0
- package/dist/core/agent/permission-manager.js +32 -0
- package/dist/core/agent/todo-manager.d.ts +26 -0
- package/dist/core/agent/todo-manager.js +91 -0
- package/dist/core/agent/tool-runner.d.ts +9 -0
- package/dist/core/agent/tool-runner.js +45 -0
- package/dist/core/agent.d.ts +228 -62
- package/dist/core/agent.js +1890 -615
- package/dist/core/config.d.ts +10 -0
- package/dist/core/config.js +2 -0
- package/dist/core/context-manager.d.ts +82 -0
- package/dist/core/context-manager.js +241 -0
- package/dist/core/errors.d.ts +22 -0
- package/dist/core/errors.js +49 -0
- package/dist/core/events.d.ts +41 -10
- package/dist/core/events.js +270 -68
- package/dist/core/file-pool.d.ts +41 -0
- package/dist/core/file-pool.js +102 -0
- package/dist/core/hooks.d.ts +3 -3
- package/dist/core/hooks.js +1 -1
- package/dist/core/permission-modes.d.ts +31 -0
- package/dist/core/permission-modes.js +61 -0
- package/dist/core/pool.d.ts +56 -13
- package/dist/core/pool.js +244 -34
- package/dist/core/room.d.ts +2 -2
- package/dist/core/room.js +10 -10
- package/dist/core/scheduler.d.ts +30 -23
- package/dist/core/scheduler.js +42 -168
- package/dist/core/skills/index.d.ts +10 -0
- package/dist/core/skills/index.js +20 -0
- package/dist/core/skills/management-manager.d.ts +130 -0
- package/dist/core/skills/management-manager.js +557 -0
- package/dist/core/skills/manager.d.ts +47 -0
- package/dist/core/skills/manager.js +243 -0
- package/dist/core/skills/operation-queue.d.ts +87 -0
- package/dist/core/skills/operation-queue.js +113 -0
- package/dist/core/skills/sandbox-file-manager.d.ts +82 -0
- package/dist/core/skills/sandbox-file-manager.js +183 -0
- package/dist/core/skills/types.d.ts +120 -0
- package/dist/core/skills/types.js +9 -0
- package/dist/core/skills/xml-generator.d.ts +13 -0
- package/dist/core/skills/xml-generator.js +70 -0
- package/dist/core/template.d.ts +57 -0
- package/dist/core/template.js +35 -0
- package/dist/core/time-bridge.d.ts +18 -0
- package/dist/core/time-bridge.js +100 -0
- package/dist/core/todo.d.ts +34 -0
- package/dist/core/todo.js +89 -0
- package/dist/core/types.d.ts +311 -114
- package/dist/core/types.js +1 -12
- package/dist/index.d.ts +47 -9
- package/dist/index.js +108 -15
- package/dist/infra/db/postgres/postgres-store.d.ts +97 -0
- package/dist/infra/db/postgres/postgres-store.js +1073 -0
- package/dist/infra/db/sqlite/sqlite-store.d.ts +84 -0
- package/dist/infra/db/sqlite/sqlite-store.js +800 -0
- package/dist/infra/e2b/e2b-fs.d.ts +29 -0
- package/dist/infra/e2b/e2b-fs.js +128 -0
- package/dist/infra/e2b/e2b-sandbox.d.ts +37 -0
- package/dist/infra/e2b/e2b-sandbox.js +156 -0
- package/dist/infra/e2b/e2b-template.d.ts +24 -0
- package/dist/infra/e2b/e2b-template.js +105 -0
- package/dist/infra/e2b/index.d.ts +4 -0
- package/dist/infra/e2b/index.js +9 -0
- package/dist/infra/e2b/types.d.ts +46 -0
- package/dist/infra/e2b/types.js +2 -0
- package/dist/infra/provider.d.ts +17 -58
- package/dist/infra/provider.js +65 -116
- package/dist/infra/providers/anthropic.d.ts +42 -0
- package/dist/infra/providers/anthropic.js +308 -0
- package/dist/infra/providers/core/errors.d.ts +230 -0
- package/dist/infra/providers/core/errors.js +353 -0
- package/dist/infra/providers/core/fork.d.ts +106 -0
- package/dist/infra/providers/core/fork.js +418 -0
- package/dist/infra/providers/core/index.d.ts +10 -0
- package/dist/infra/providers/core/index.js +76 -0
- package/dist/infra/providers/core/logger.d.ts +186 -0
- package/dist/infra/providers/core/logger.js +191 -0
- package/dist/infra/providers/core/retry.d.ts +62 -0
- package/dist/infra/providers/core/retry.js +189 -0
- package/dist/infra/providers/core/usage.d.ts +151 -0
- package/dist/infra/providers/core/usage.js +376 -0
- package/dist/infra/providers/gemini.d.ts +49 -0
- package/dist/infra/providers/gemini.js +493 -0
- package/dist/infra/providers/index.d.ts +25 -0
- package/dist/infra/providers/index.js +83 -0
- package/dist/infra/providers/openai.d.ts +123 -0
- package/dist/infra/providers/openai.js +662 -0
- package/dist/infra/providers/types.d.ts +334 -0
- package/dist/infra/providers/types.js +20 -0
- package/dist/infra/providers/utils.d.ts +53 -0
- package/dist/infra/providers/utils.js +400 -0
- package/dist/infra/sandbox-factory.d.ts +13 -0
- package/dist/infra/sandbox-factory.js +30 -0
- package/dist/infra/sandbox.d.ts +35 -6
- package/dist/infra/sandbox.js +174 -8
- package/dist/infra/store/factory.d.ts +45 -0
- package/dist/infra/store/factory.js +80 -0
- package/dist/infra/store/index.d.ts +3 -0
- package/dist/infra/store/index.js +26 -0
- package/dist/infra/store/json-store.d.ts +67 -0
- package/dist/infra/store/json-store.js +606 -0
- package/dist/infra/store/types.d.ts +342 -0
- package/dist/infra/store/types.js +2 -0
- package/dist/infra/store.d.ts +12 -32
- package/dist/infra/store.js +27 -130
- package/dist/tools/bash_kill/index.d.ts +1 -0
- package/dist/tools/bash_kill/index.js +35 -0
- package/dist/tools/bash_kill/prompt.d.ts +2 -0
- package/dist/tools/bash_kill/prompt.js +14 -0
- package/dist/tools/bash_logs/index.d.ts +1 -0
- package/dist/tools/bash_logs/index.js +40 -0
- package/dist/tools/bash_logs/prompt.d.ts +2 -0
- package/dist/tools/bash_logs/prompt.js +14 -0
- package/dist/tools/bash_run/index.d.ts +16 -0
- package/dist/tools/bash_run/index.js +61 -0
- package/dist/tools/bash_run/prompt.d.ts +2 -0
- package/dist/tools/bash_run/prompt.js +18 -0
- package/dist/tools/builtin.d.ts +7 -13
- package/dist/tools/builtin.js +19 -90
- package/dist/tools/define.d.ts +101 -0
- package/dist/tools/define.js +214 -0
- package/dist/tools/fs_edit/index.d.ts +1 -0
- package/dist/tools/fs_edit/index.js +62 -0
- package/dist/tools/fs_edit/prompt.d.ts +2 -0
- package/dist/tools/fs_edit/prompt.js +15 -0
- package/dist/tools/fs_glob/index.d.ts +1 -0
- package/dist/tools/fs_glob/index.js +40 -0
- package/dist/tools/fs_glob/prompt.d.ts +2 -0
- package/dist/tools/fs_glob/prompt.js +15 -0
- package/dist/tools/fs_grep/index.d.ts +1 -0
- package/dist/tools/fs_grep/index.js +66 -0
- package/dist/tools/fs_grep/prompt.d.ts +2 -0
- package/dist/tools/fs_grep/prompt.js +16 -0
- package/dist/tools/fs_multi_edit/index.d.ts +1 -0
- package/dist/tools/fs_multi_edit/index.js +106 -0
- package/dist/tools/fs_multi_edit/prompt.d.ts +2 -0
- package/dist/tools/fs_multi_edit/prompt.js +16 -0
- package/dist/tools/fs_read/index.d.ts +1 -0
- package/dist/tools/fs_read/index.js +40 -0
- package/dist/tools/fs_read/prompt.d.ts +2 -0
- package/dist/tools/fs_read/prompt.js +16 -0
- package/dist/tools/fs_write/index.d.ts +1 -0
- package/dist/tools/fs_write/index.js +40 -0
- package/dist/tools/fs_write/prompt.d.ts +2 -0
- package/dist/tools/fs_write/prompt.js +15 -0
- package/dist/tools/index.d.ts +11 -0
- package/dist/tools/index.js +61 -0
- package/dist/tools/mcp.d.ts +69 -0
- package/dist/tools/mcp.js +185 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/scripts.d.ts +22 -0
- package/dist/tools/scripts.js +205 -0
- package/dist/tools/skills.d.ts +20 -0
- package/dist/tools/skills.js +115 -0
- package/dist/tools/task_run/index.d.ts +7 -0
- package/dist/tools/task_run/index.js +58 -0
- package/dist/tools/task_run/prompt.d.ts +5 -0
- package/dist/tools/task_run/prompt.js +25 -0
- package/dist/tools/todo_read/index.d.ts +1 -0
- package/dist/tools/todo_read/index.js +29 -0
- package/dist/tools/todo_read/prompt.d.ts +2 -0
- package/dist/tools/todo_read/prompt.js +18 -0
- package/dist/tools/todo_write/index.d.ts +1 -0
- package/dist/tools/todo_write/index.js +42 -0
- package/dist/tools/todo_write/prompt.d.ts +2 -0
- package/dist/tools/todo_write/prompt.js +23 -0
- package/dist/tools/tool.d.ts +43 -0
- package/dist/tools/tool.js +211 -0
- package/dist/tools/toolkit.d.ts +69 -0
- package/dist/tools/toolkit.js +98 -0
- package/dist/tools/type-inference.d.ts +127 -0
- package/dist/tools/type-inference.js +207 -0
- package/dist/utils/agent-id.d.ts +1 -0
- package/dist/utils/agent-id.js +28 -0
- package/dist/utils/logger.d.ts +15 -0
- package/dist/utils/logger.js +44 -0
- package/dist/utils/session-id.js +16 -16
- package/package.json +35 -11
- package/dist/tools/bash.d.ts +0 -63
- package/dist/tools/bash.js +0 -92
- package/dist/tools/fs.d.ts +0 -96
- package/dist/tools/fs.js +0 -100
- package/dist/tools/task.d.ts +0 -38
- package/dist/tools/task.js +0 -45
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { z, ZodType, ZodTypeAny } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* TypeScript 类型到 Zod schema 的自动推断
|
|
4
|
+
*
|
|
5
|
+
* 注意:由于 TypeScript 类型在运行时被擦除,我们无法直接从类型生成 schema。
|
|
6
|
+
* 这个模块提供了一些辅助函数来简化 schema 定义。
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 从示例对象推断 Zod schema
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const schema = inferFromExample({
|
|
14
|
+
* name: 'string',
|
|
15
|
+
* age: 0,
|
|
16
|
+
* active: true,
|
|
17
|
+
* tags: ['string']
|
|
18
|
+
* });
|
|
19
|
+
* // 等价于:
|
|
20
|
+
* z.object({
|
|
21
|
+
* name: z.string(),
|
|
22
|
+
* age: z.number(),
|
|
23
|
+
* active: z.boolean(),
|
|
24
|
+
* tags: z.array(z.string())
|
|
25
|
+
* })
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function inferFromExample<T extends Record<string, any>>(example: T): ZodType<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Schema 构建器 - 提供流畅的 API
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const schema = schema()
|
|
35
|
+
* .string('name', 'User name')
|
|
36
|
+
* .number('age', 'User age').optional()
|
|
37
|
+
* .boolean('active').default(true)
|
|
38
|
+
* .array('tags', z.string())
|
|
39
|
+
* .build();
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare class SchemaBuilder {
|
|
43
|
+
private fields;
|
|
44
|
+
string(name: string, description?: string): this;
|
|
45
|
+
number(name: string, description?: string): this;
|
|
46
|
+
boolean(name: string, description?: string): this;
|
|
47
|
+
array(name: string, itemSchema: ZodTypeAny, description?: string): this;
|
|
48
|
+
object(name: string, shape: Record<string, ZodTypeAny>, description?: string): this;
|
|
49
|
+
enum(name: string, values: readonly [string, ...string[]], description?: string): this;
|
|
50
|
+
optional(name: string): this;
|
|
51
|
+
default(name: string, defaultValue: any): this;
|
|
52
|
+
custom(name: string, schema: ZodTypeAny): this;
|
|
53
|
+
build(): ZodType<any>;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 创建 schema 构建器
|
|
57
|
+
*/
|
|
58
|
+
export declare function schema(): SchemaBuilder;
|
|
59
|
+
/**
|
|
60
|
+
* 快速定义常用的 schema 模式
|
|
61
|
+
*/
|
|
62
|
+
export declare const patterns: {
|
|
63
|
+
/**
|
|
64
|
+
* 文件路径
|
|
65
|
+
*/
|
|
66
|
+
filePath: (description?: string) => z.ZodString;
|
|
67
|
+
/**
|
|
68
|
+
* 目录路径
|
|
69
|
+
*/
|
|
70
|
+
dirPath: (description?: string) => z.ZodString;
|
|
71
|
+
/**
|
|
72
|
+
* URL
|
|
73
|
+
*/
|
|
74
|
+
url: (description?: string) => z.ZodString;
|
|
75
|
+
/**
|
|
76
|
+
* Email
|
|
77
|
+
*/
|
|
78
|
+
email: (description?: string) => z.ZodString;
|
|
79
|
+
/**
|
|
80
|
+
* 正整数
|
|
81
|
+
*/
|
|
82
|
+
positiveInt: (description?: string) => z.ZodNumber;
|
|
83
|
+
/**
|
|
84
|
+
* 非负整数
|
|
85
|
+
*/
|
|
86
|
+
nonNegativeInt: (description?: string) => z.ZodNumber;
|
|
87
|
+
/**
|
|
88
|
+
* 字符串数组
|
|
89
|
+
*/
|
|
90
|
+
stringArray: (description?: string) => z.ZodArray<z.ZodString, "many">;
|
|
91
|
+
/**
|
|
92
|
+
* 可选字符串
|
|
93
|
+
*/
|
|
94
|
+
optionalString: (description?: string) => z.ZodOptional<z.ZodString>;
|
|
95
|
+
/**
|
|
96
|
+
* 可选数字
|
|
97
|
+
*/
|
|
98
|
+
optionalNumber: (description?: string) => z.ZodOptional<z.ZodNumber>;
|
|
99
|
+
/**
|
|
100
|
+
* JSON 对象
|
|
101
|
+
*/
|
|
102
|
+
json: (description?: string) => z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* 从 JSDoc 注释推断 schema(实验性)
|
|
106
|
+
*
|
|
107
|
+
* 这需要在构建时使用 TypeScript Compiler API 解析
|
|
108
|
+
* 当前仅提供接口,实际实现需要编译时支持
|
|
109
|
+
*/
|
|
110
|
+
export interface JSDocSchema {
|
|
111
|
+
/**
|
|
112
|
+
* @param name - Parameter name
|
|
113
|
+
* @param type - TypeScript type string (e.g., 'string', 'number', 'Array<string>')
|
|
114
|
+
* @param description - Parameter description
|
|
115
|
+
* @param optional - Whether parameter is optional
|
|
116
|
+
*/
|
|
117
|
+
param(name: string, type: string, description?: string, optional?: boolean): this;
|
|
118
|
+
build(): ZodType<any>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* 辅助函数:合并多个 schema
|
|
122
|
+
*/
|
|
123
|
+
export declare function mergeSchemas(...schemas: ZodType<any>[]): ZodType<any>;
|
|
124
|
+
/**
|
|
125
|
+
* 辅助函数:扩展 schema
|
|
126
|
+
*/
|
|
127
|
+
export declare function extendSchema<T extends ZodType<any>>(base: T, extension: Record<string, ZodTypeAny>): ZodType<any>;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.patterns = exports.SchemaBuilder = void 0;
|
|
4
|
+
exports.inferFromExample = inferFromExample;
|
|
5
|
+
exports.schema = schema;
|
|
6
|
+
exports.mergeSchemas = mergeSchemas;
|
|
7
|
+
exports.extendSchema = extendSchema;
|
|
8
|
+
const zod_1 = require("zod");
|
|
9
|
+
/**
|
|
10
|
+
* TypeScript 类型到 Zod schema 的自动推断
|
|
11
|
+
*
|
|
12
|
+
* 注意:由于 TypeScript 类型在运行时被擦除,我们无法直接从类型生成 schema。
|
|
13
|
+
* 这个模块提供了一些辅助函数来简化 schema 定义。
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* 从示例对象推断 Zod schema
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* const schema = inferFromExample({
|
|
21
|
+
* name: 'string',
|
|
22
|
+
* age: 0,
|
|
23
|
+
* active: true,
|
|
24
|
+
* tags: ['string']
|
|
25
|
+
* });
|
|
26
|
+
* // 等价于:
|
|
27
|
+
* z.object({
|
|
28
|
+
* name: z.string(),
|
|
29
|
+
* age: z.number(),
|
|
30
|
+
* active: z.boolean(),
|
|
31
|
+
* tags: z.array(z.string())
|
|
32
|
+
* })
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
function inferFromExample(example) {
|
|
36
|
+
const shape = {};
|
|
37
|
+
for (const [key, value] of Object.entries(example)) {
|
|
38
|
+
shape[key] = inferValueType(value);
|
|
39
|
+
}
|
|
40
|
+
return zod_1.z.object(shape);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* 推断单个值的类型
|
|
44
|
+
*/
|
|
45
|
+
function inferValueType(value) {
|
|
46
|
+
if (value === null || value === undefined) {
|
|
47
|
+
return zod_1.z.any();
|
|
48
|
+
}
|
|
49
|
+
const type = typeof value;
|
|
50
|
+
switch (type) {
|
|
51
|
+
case 'string':
|
|
52
|
+
return zod_1.z.string();
|
|
53
|
+
case 'number':
|
|
54
|
+
return zod_1.z.number();
|
|
55
|
+
case 'boolean':
|
|
56
|
+
return zod_1.z.boolean();
|
|
57
|
+
case 'object':
|
|
58
|
+
if (Array.isArray(value)) {
|
|
59
|
+
if (value.length === 0) {
|
|
60
|
+
return zod_1.z.array(zod_1.z.any());
|
|
61
|
+
}
|
|
62
|
+
return zod_1.z.array(inferValueType(value[0]));
|
|
63
|
+
}
|
|
64
|
+
return inferFromExample(value);
|
|
65
|
+
default:
|
|
66
|
+
return zod_1.z.any();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Schema 构建器 - 提供流畅的 API
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```ts
|
|
74
|
+
* const schema = schema()
|
|
75
|
+
* .string('name', 'User name')
|
|
76
|
+
* .number('age', 'User age').optional()
|
|
77
|
+
* .boolean('active').default(true)
|
|
78
|
+
* .array('tags', z.string())
|
|
79
|
+
* .build();
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
class SchemaBuilder {
|
|
83
|
+
constructor() {
|
|
84
|
+
this.fields = {};
|
|
85
|
+
}
|
|
86
|
+
string(name, description) {
|
|
87
|
+
this.fields[name] = description ? zod_1.z.string().describe(description) : zod_1.z.string();
|
|
88
|
+
return this;
|
|
89
|
+
}
|
|
90
|
+
number(name, description) {
|
|
91
|
+
this.fields[name] = description ? zod_1.z.number().describe(description) : zod_1.z.number();
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
boolean(name, description) {
|
|
95
|
+
this.fields[name] = description ? zod_1.z.boolean().describe(description) : zod_1.z.boolean();
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
array(name, itemSchema, description) {
|
|
99
|
+
const schema = zod_1.z.array(itemSchema);
|
|
100
|
+
this.fields[name] = description ? schema.describe(description) : schema;
|
|
101
|
+
return this;
|
|
102
|
+
}
|
|
103
|
+
object(name, shape, description) {
|
|
104
|
+
const schema = zod_1.z.object(shape);
|
|
105
|
+
this.fields[name] = description ? schema.describe(description) : schema;
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
enum(name, values, description) {
|
|
109
|
+
const schema = zod_1.z.enum(values);
|
|
110
|
+
this.fields[name] = description ? schema.describe(description) : schema;
|
|
111
|
+
return this;
|
|
112
|
+
}
|
|
113
|
+
optional(name) {
|
|
114
|
+
if (this.fields[name]) {
|
|
115
|
+
this.fields[name] = this.fields[name].optional();
|
|
116
|
+
}
|
|
117
|
+
return this;
|
|
118
|
+
}
|
|
119
|
+
default(name, defaultValue) {
|
|
120
|
+
if (this.fields[name]) {
|
|
121
|
+
this.fields[name] = this.fields[name].default(defaultValue);
|
|
122
|
+
}
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
custom(name, schema) {
|
|
126
|
+
this.fields[name] = schema;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
build() {
|
|
130
|
+
return zod_1.z.object(this.fields);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.SchemaBuilder = SchemaBuilder;
|
|
134
|
+
/**
|
|
135
|
+
* 创建 schema 构建器
|
|
136
|
+
*/
|
|
137
|
+
function schema() {
|
|
138
|
+
return new SchemaBuilder();
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 快速定义常用的 schema 模式
|
|
142
|
+
*/
|
|
143
|
+
exports.patterns = {
|
|
144
|
+
/**
|
|
145
|
+
* 文件路径
|
|
146
|
+
*/
|
|
147
|
+
filePath: (description = 'File path') => zod_1.z.string().describe(description),
|
|
148
|
+
/**
|
|
149
|
+
* 目录路径
|
|
150
|
+
*/
|
|
151
|
+
dirPath: (description = 'Directory path') => zod_1.z.string().describe(description),
|
|
152
|
+
/**
|
|
153
|
+
* URL
|
|
154
|
+
*/
|
|
155
|
+
url: (description = 'URL') => zod_1.z.string().url().describe(description),
|
|
156
|
+
/**
|
|
157
|
+
* Email
|
|
158
|
+
*/
|
|
159
|
+
email: (description = 'Email address') => zod_1.z.string().email().describe(description),
|
|
160
|
+
/**
|
|
161
|
+
* 正整数
|
|
162
|
+
*/
|
|
163
|
+
positiveInt: (description = 'Positive integer') => zod_1.z.number().int().positive().describe(description),
|
|
164
|
+
/**
|
|
165
|
+
* 非负整数
|
|
166
|
+
*/
|
|
167
|
+
nonNegativeInt: (description = 'Non-negative integer') => zod_1.z.number().int().nonnegative().describe(description),
|
|
168
|
+
/**
|
|
169
|
+
* 字符串数组
|
|
170
|
+
*/
|
|
171
|
+
stringArray: (description = 'Array of strings') => zod_1.z.array(zod_1.z.string()).describe(description),
|
|
172
|
+
/**
|
|
173
|
+
* 可选字符串
|
|
174
|
+
*/
|
|
175
|
+
optionalString: (description) => zod_1.z.string().optional().describe(description || 'Optional string'),
|
|
176
|
+
/**
|
|
177
|
+
* 可选数字
|
|
178
|
+
*/
|
|
179
|
+
optionalNumber: (description) => zod_1.z.number().optional().describe(description || 'Optional number'),
|
|
180
|
+
/**
|
|
181
|
+
* JSON 对象
|
|
182
|
+
*/
|
|
183
|
+
json: (description = 'JSON object') => zod_1.z.record(zod_1.z.string(), zod_1.z.any()).describe(description),
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* 辅助函数:合并多个 schema
|
|
187
|
+
*/
|
|
188
|
+
function mergeSchemas(...schemas) {
|
|
189
|
+
if (schemas.length === 0) {
|
|
190
|
+
return zod_1.z.object({});
|
|
191
|
+
}
|
|
192
|
+
if (schemas.length === 1) {
|
|
193
|
+
return schemas[0];
|
|
194
|
+
}
|
|
195
|
+
// 使用 z.intersection 合并
|
|
196
|
+
return schemas.reduce((acc, schema) => acc.and(schema));
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* 辅助函数:扩展 schema
|
|
200
|
+
*/
|
|
201
|
+
function extendSchema(base, extension) {
|
|
202
|
+
if (base instanceof zod_1.z.ZodObject) {
|
|
203
|
+
return base.extend(extension);
|
|
204
|
+
}
|
|
205
|
+
// 如果不是 object schema,创建新的 object schema
|
|
206
|
+
return zod_1.z.object(extension);
|
|
207
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateAgentId(): string;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateAgentId = generateAgentId;
|
|
4
|
+
const CROCKFORD32 = '0123456789ABCDEFGHJKMNPQRSTVWXYZ';
|
|
5
|
+
function encodeTime(time, length) {
|
|
6
|
+
let remaining = time;
|
|
7
|
+
const chars = Array(length);
|
|
8
|
+
for (let i = length - 1; i >= 0; i--) {
|
|
9
|
+
const mod = remaining % 32;
|
|
10
|
+
chars[i] = CROCKFORD32.charAt(mod);
|
|
11
|
+
remaining = Math.floor(remaining / 32);
|
|
12
|
+
}
|
|
13
|
+
return chars.join('');
|
|
14
|
+
}
|
|
15
|
+
function encodeRandom(length) {
|
|
16
|
+
const chars = Array(length);
|
|
17
|
+
for (let i = 0; i < length; i++) {
|
|
18
|
+
const rand = Math.floor(Math.random() * 32);
|
|
19
|
+
chars[i] = CROCKFORD32.charAt(rand);
|
|
20
|
+
}
|
|
21
|
+
return chars.join('');
|
|
22
|
+
}
|
|
23
|
+
function generateAgentId() {
|
|
24
|
+
const time = Date.now();
|
|
25
|
+
const timePart = encodeTime(time, 10);
|
|
26
|
+
const randomPart = encodeRandom(16);
|
|
27
|
+
return `agt-${timePart}${randomPart}`;
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日志工具模块
|
|
3
|
+
*
|
|
4
|
+
* 仅在 NODE_ENV=local 时输出日志,生产环境静默
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 日志输出(仅在 NODE_ENV=local 时输出)
|
|
8
|
+
*/
|
|
9
|
+
export declare const logger: {
|
|
10
|
+
log: (...args: any[]) => void;
|
|
11
|
+
info: (...args: any[]) => void;
|
|
12
|
+
warn: (...args: any[]) => void;
|
|
13
|
+
error: (...args: any[]) => void;
|
|
14
|
+
debug: (...args: any[]) => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 日志工具模块
|
|
4
|
+
*
|
|
5
|
+
* 仅在 NODE_ENV=local 时输出日志,生产环境静默
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.logger = void 0;
|
|
9
|
+
/**
|
|
10
|
+
* 检查是否启用日志(仅在本地开发环境)
|
|
11
|
+
*/
|
|
12
|
+
function isLoggingEnabled() {
|
|
13
|
+
return process.env.NODE_ENV === 'local';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 日志输出(仅在 NODE_ENV=local 时输出)
|
|
17
|
+
*/
|
|
18
|
+
exports.logger = {
|
|
19
|
+
log: (...args) => {
|
|
20
|
+
if (isLoggingEnabled()) {
|
|
21
|
+
console.log(...args);
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
info: (...args) => {
|
|
25
|
+
if (isLoggingEnabled()) {
|
|
26
|
+
console.info(...args);
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
warn: (...args) => {
|
|
30
|
+
if (isLoggingEnabled()) {
|
|
31
|
+
console.warn(...args);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
error: (...args) => {
|
|
35
|
+
if (isLoggingEnabled()) {
|
|
36
|
+
console.error(...args);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
debug: (...args) => {
|
|
40
|
+
if (isLoggingEnabled()) {
|
|
41
|
+
console.debug(...args);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
};
|
package/dist/utils/session-id.js
CHANGED
|
@@ -10,22 +10,22 @@ class SessionId {
|
|
|
10
10
|
forkIds: [],
|
|
11
11
|
};
|
|
12
12
|
for (const part of parts) {
|
|
13
|
-
if (part.startsWith('org
|
|
13
|
+
if (part.startsWith('org-')) {
|
|
14
14
|
components.orgId = part.slice(4);
|
|
15
15
|
}
|
|
16
|
-
else if (part.startsWith('team
|
|
16
|
+
else if (part.startsWith('team-')) {
|
|
17
17
|
components.teamId = part.slice(5);
|
|
18
18
|
}
|
|
19
|
-
else if (part.startsWith('user
|
|
19
|
+
else if (part.startsWith('user-')) {
|
|
20
20
|
components.userId = part.slice(5);
|
|
21
21
|
}
|
|
22
|
-
else if (part.startsWith('agent
|
|
22
|
+
else if (part.startsWith('agent-')) {
|
|
23
23
|
components.agentTemplate = part.slice(6);
|
|
24
24
|
}
|
|
25
|
-
else if (part.startsWith('session
|
|
25
|
+
else if (part.startsWith('session-')) {
|
|
26
26
|
components.rootId = part.slice(8);
|
|
27
27
|
}
|
|
28
|
-
else if (part.startsWith('fork
|
|
28
|
+
else if (part.startsWith('fork-')) {
|
|
29
29
|
components.forkIds.push(part.slice(5));
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -34,28 +34,28 @@ class SessionId {
|
|
|
34
34
|
static generate(opts) {
|
|
35
35
|
const parts = [];
|
|
36
36
|
if (opts.orgId)
|
|
37
|
-
parts.push(`org
|
|
37
|
+
parts.push(`org-${opts.orgId}`);
|
|
38
38
|
if (opts.teamId)
|
|
39
|
-
parts.push(`team
|
|
39
|
+
parts.push(`team-${opts.teamId}`);
|
|
40
40
|
if (opts.userId)
|
|
41
|
-
parts.push(`user
|
|
42
|
-
parts.push(`agent
|
|
41
|
+
parts.push(`user-${opts.userId}`);
|
|
42
|
+
parts.push(`agent-${opts.agentTemplate}`);
|
|
43
43
|
if (opts.parentSessionId) {
|
|
44
44
|
const parent = SessionId.parse(opts.parentSessionId);
|
|
45
|
-
parts.push(`session
|
|
46
|
-
parts.push(...parent.forkIds.map((id) => `fork
|
|
47
|
-
parts.push(`fork
|
|
45
|
+
parts.push(`session-${parent.rootId}`);
|
|
46
|
+
parts.push(...parent.forkIds.map((id) => `fork-${id}`));
|
|
47
|
+
parts.push(`fork-${this.randomId()}`);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
parts.push(`session
|
|
50
|
+
parts.push(`session-${this.randomId()}`);
|
|
51
51
|
}
|
|
52
52
|
return parts.join('/');
|
|
53
53
|
}
|
|
54
54
|
static snapshot(sessionId, sfpIndex) {
|
|
55
|
-
return `${sessionId}@sfp
|
|
55
|
+
return `${sessionId}@sfp-${sfpIndex}`;
|
|
56
56
|
}
|
|
57
57
|
static label(sessionId, label) {
|
|
58
|
-
return `${sessionId}@label
|
|
58
|
+
return `${sessionId}@label-${label}`;
|
|
59
59
|
}
|
|
60
60
|
static randomId() {
|
|
61
61
|
return Math.random().toString(36).slice(2, 8);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shareai-lab/kode-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Event-driven
|
|
3
|
+
"version": "2.7.0",
|
|
4
|
+
"description": "Event-driven, long-running AI Agent development framework with enterprise-grade persistence and context management",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
@@ -9,14 +9,24 @@
|
|
|
9
9
|
"dev": "tsc --watch",
|
|
10
10
|
"clean": "rm -rf dist",
|
|
11
11
|
"prepare": "npm run build",
|
|
12
|
-
"test
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"example:
|
|
18
|
-
"example:
|
|
19
|
-
"example:
|
|
12
|
+
"test": "npm run test:unit",
|
|
13
|
+
"test:unit": "ts-node --project tsconfig.json ./tests/run-unit.ts",
|
|
14
|
+
"test:integration": "ts-node --project tsconfig.json ./tests/run-integration.ts",
|
|
15
|
+
"test:e2e": "ts-node --project tsconfig.json ./tests/run-e2e.ts",
|
|
16
|
+
"test:all": "ts-node --project tsconfig.json ./tests/run-all.ts",
|
|
17
|
+
"example:getting-started": "ts-node examples/getting-started.ts",
|
|
18
|
+
"example:openai": "ts-node examples/openai-usage.ts",
|
|
19
|
+
"example:gemini": "ts-node examples/gemini-usage.ts",
|
|
20
|
+
"example:agent-inbox": "ts-node examples/01-agent-inbox.ts",
|
|
21
|
+
"example:approval": "ts-node examples/02-approval-control.ts",
|
|
22
|
+
"example:room": "ts-node examples/03-room-collab.ts",
|
|
23
|
+
"example:scheduler": "ts-node examples/04-scheduler-watch.ts",
|
|
24
|
+
"example:nextjs": "ts-node examples/nextjs-api-route.ts",
|
|
25
|
+
"example:openrouter": "ts-node examples/05-openrouter-complete.ts",
|
|
26
|
+
"example:openrouter-stream": "ts-node examples/06-openrouter-stream.ts",
|
|
27
|
+
"example:openrouter-agent": "ts-node examples/07-openrouter-agent.ts",
|
|
28
|
+
"example:db-sqlite": "ts-node examples/db-sqlite.ts",
|
|
29
|
+
"example:db-postgres": "ts-node examples/db-postgres.ts"
|
|
20
30
|
},
|
|
21
31
|
"keywords": [
|
|
22
32
|
"agent",
|
|
@@ -31,9 +41,23 @@
|
|
|
31
41
|
],
|
|
32
42
|
"author": "",
|
|
33
43
|
"license": "MIT",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"@modelcontextprotocol/sdk": "~1.22.0",
|
|
46
|
+
"ajv": "^8.17.1",
|
|
47
|
+
"better-sqlite3": "^12.6.2",
|
|
48
|
+
"dotenv": "^16.4.5",
|
|
49
|
+
"e2b": "^2.10.3",
|
|
50
|
+
"fast-glob": "^3.3.2",
|
|
51
|
+
"pg": "^8.17.2",
|
|
52
|
+
"undici": "^7.18.2",
|
|
53
|
+
"zod": "~3.23.8",
|
|
54
|
+
"zod-to-json-schema": "~3.23.0"
|
|
55
|
+
},
|
|
34
56
|
"devDependencies": {
|
|
35
|
-
"@shareai-lab/kode-sdk": "
|
|
57
|
+
"@shareai-lab/kode-sdk": "file:.",
|
|
58
|
+
"@types/better-sqlite3": "^7.6.13",
|
|
36
59
|
"@types/node": "^20.0.0",
|
|
60
|
+
"@types/pg": "^8.16.0",
|
|
37
61
|
"ts-node": "^10.9.0",
|
|
38
62
|
"typescript": "^5.3.0"
|
|
39
63
|
},
|
package/dist/tools/bash.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { ToolContext } from '../core/types';
|
|
2
|
-
import { Tool } from './fs';
|
|
3
|
-
export declare class BashRun implements Tool {
|
|
4
|
-
name: string;
|
|
5
|
-
description: string;
|
|
6
|
-
input_schema: {
|
|
7
|
-
type: string;
|
|
8
|
-
properties: {
|
|
9
|
-
cmd: {
|
|
10
|
-
type: string;
|
|
11
|
-
description: string;
|
|
12
|
-
};
|
|
13
|
-
timeout_ms: {
|
|
14
|
-
type: string;
|
|
15
|
-
description: string;
|
|
16
|
-
};
|
|
17
|
-
background: {
|
|
18
|
-
type: string;
|
|
19
|
-
description: string;
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
required: string[];
|
|
23
|
-
};
|
|
24
|
-
exec(args: {
|
|
25
|
-
cmd: string;
|
|
26
|
-
timeout_ms?: number;
|
|
27
|
-
background?: boolean;
|
|
28
|
-
}, ctx: ToolContext): Promise<any>;
|
|
29
|
-
}
|
|
30
|
-
export declare class BashLogs implements Tool {
|
|
31
|
-
name: string;
|
|
32
|
-
description: string;
|
|
33
|
-
input_schema: {
|
|
34
|
-
type: string;
|
|
35
|
-
properties: {
|
|
36
|
-
shell_id: {
|
|
37
|
-
type: string;
|
|
38
|
-
description: string;
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
required: string[];
|
|
42
|
-
};
|
|
43
|
-
exec(args: {
|
|
44
|
-
shell_id: string;
|
|
45
|
-
}, ctx: ToolContext): Promise<any>;
|
|
46
|
-
}
|
|
47
|
-
export declare class BashKill implements Tool {
|
|
48
|
-
name: string;
|
|
49
|
-
description: string;
|
|
50
|
-
input_schema: {
|
|
51
|
-
type: string;
|
|
52
|
-
properties: {
|
|
53
|
-
shell_id: {
|
|
54
|
-
type: string;
|
|
55
|
-
description: string;
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
required: string[];
|
|
59
|
-
};
|
|
60
|
-
exec(args: {
|
|
61
|
-
shell_id: string;
|
|
62
|
-
}, ctx: ToolContext): Promise<any>;
|
|
63
|
-
}
|