kode-sdk 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 +201 -0
- package/README.md +74 -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 +47 -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 +271 -0
- package/dist/core/agent.js +2334 -0
- package/dist/core/checkpointer.d.ts +96 -0
- package/dist/core/checkpointer.js +57 -0
- package/dist/core/checkpointers/file.d.ts +20 -0
- package/dist/core/checkpointers/file.js +153 -0
- package/dist/core/checkpointers/index.d.ts +3 -0
- package/dist/core/checkpointers/index.js +9 -0
- package/dist/core/checkpointers/redis.d.ts +35 -0
- package/dist/core/checkpointers/redis.js +113 -0
- package/dist/core/compression/ai-strategy.d.ts +53 -0
- package/dist/core/compression/ai-strategy.js +298 -0
- package/dist/core/compression/index.d.ts +12 -0
- package/dist/core/compression/index.js +27 -0
- package/dist/core/compression/prompts.d.ts +35 -0
- package/dist/core/compression/prompts.js +114 -0
- package/dist/core/compression/simple-strategy.d.ts +44 -0
- package/dist/core/compression/simple-strategy.js +240 -0
- package/dist/core/compression/token-estimator.d.ts +42 -0
- package/dist/core/compression/token-estimator.js +121 -0
- package/dist/core/compression/types.d.ts +140 -0
- package/dist/core/compression/types.js +9 -0
- package/dist/core/config.d.ts +10 -0
- package/dist/core/config.js +2 -0
- package/dist/core/context-manager.d.ts +115 -0
- package/dist/core/context-manager.js +107 -0
- package/dist/core/errors.d.ts +6 -0
- package/dist/core/errors.js +17 -0
- package/dist/core/events.d.ts +49 -0
- package/dist/core/events.js +312 -0
- package/dist/core/file-pool.d.ts +43 -0
- package/dist/core/file-pool.js +120 -0
- package/dist/core/hooks.d.ts +23 -0
- package/dist/core/hooks.js +71 -0
- package/dist/core/permission-modes.d.ts +31 -0
- package/dist/core/permission-modes.js +61 -0
- package/dist/core/pool.d.ts +31 -0
- package/dist/core/pool.js +87 -0
- package/dist/core/room.d.ts +15 -0
- package/dist/core/room.js +57 -0
- package/dist/core/scheduler.d.ts +33 -0
- package/dist/core/scheduler.js +58 -0
- package/dist/core/template.d.ts +69 -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 +380 -0
- package/dist/core/types.js +3 -0
- package/dist/index.d.ts +51 -0
- package/dist/index.js +147 -0
- package/dist/infra/provider.d.ts +144 -0
- package/dist/infra/provider.js +294 -0
- package/dist/infra/sandbox-factory.d.ts +10 -0
- package/dist/infra/sandbox-factory.js +21 -0
- package/dist/infra/sandbox.d.ts +87 -0
- package/dist/infra/sandbox.js +255 -0
- package/dist/infra/store.d.ts +154 -0
- package/dist/infra/store.js +584 -0
- package/dist/skills/index.d.ts +12 -0
- package/dist/skills/index.js +36 -0
- package/dist/skills/injector.d.ts +29 -0
- package/dist/skills/injector.js +96 -0
- package/dist/skills/loader.d.ts +59 -0
- package/dist/skills/loader.js +215 -0
- package/dist/skills/manager.d.ts +85 -0
- package/dist/skills/manager.js +221 -0
- package/dist/skills/parser.d.ts +40 -0
- package/dist/skills/parser.js +107 -0
- package/dist/skills/types.d.ts +107 -0
- package/dist/skills/types.js +7 -0
- package/dist/skills/validator.d.ts +30 -0
- package/dist/skills/validator.js +121 -0
- package/dist/store.d.ts +1 -0
- package/dist/store.js +5 -0
- 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 +9 -0
- package/dist/tools/builtin.js +27 -0
- 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 +60 -0
- package/dist/tools/fs_glob/prompt.d.ts +2 -0
- package/dist/tools/fs_glob/prompt.js +18 -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_rm/index.d.ts +1 -0
- package/dist/tools/fs_rm/index.js +41 -0
- package/dist/tools/fs_rm/prompt.d.ts +2 -0
- package/dist/tools/fs_rm/prompt.js +14 -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 +9 -0
- package/dist/tools/index.js +56 -0
- package/dist/tools/mcp.d.ts +73 -0
- package/dist/tools/mcp.js +198 -0
- package/dist/tools/registry.d.ts +29 -0
- package/dist/tools/registry.js +26 -0
- package/dist/tools/skill_activate/index.d.ts +5 -0
- package/dist/tools/skill_activate/index.js +63 -0
- package/dist/tools/skill_list/index.d.ts +5 -0
- package/dist/tools/skill_list/index.js +48 -0
- package/dist/tools/skill_resource/index.d.ts +5 -0
- package/dist/tools/skill_resource/index.js +82 -0
- package/dist/tools/task_run/index.d.ts +7 -0
- package/dist/tools/task_run/index.js +60 -0
- package/dist/tools/task_run/prompt.d.ts +5 -0
- package/dist/tools/task_run/prompt.js +29 -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 +104 -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/session-id.d.ts +21 -0
- package/dist/utils/session-id.js +64 -0
- package/dist/utils/unicode.d.ts +17 -0
- package/dist/utils/unicode.js +62 -0
- package/package.json +117 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Hooks } from '../core/hooks';
|
|
2
|
+
import { ToolContext } from '../core/types';
|
|
3
|
+
export type ToolSource = 'builtin' | 'registered' | 'mcp';
|
|
4
|
+
export interface ToolDescriptor {
|
|
5
|
+
source: ToolSource;
|
|
6
|
+
name: string;
|
|
7
|
+
registryId?: string;
|
|
8
|
+
config?: Record<string, any>;
|
|
9
|
+
metadata?: Record<string, any>;
|
|
10
|
+
}
|
|
11
|
+
export interface ToolInstance {
|
|
12
|
+
name: string;
|
|
13
|
+
description: string;
|
|
14
|
+
input_schema: any;
|
|
15
|
+
hooks?: Hooks;
|
|
16
|
+
permissionDetails?: (call: any, ctx: ToolContext) => any;
|
|
17
|
+
exec(args: any, ctx: ToolContext): Promise<any>;
|
|
18
|
+
prompt?: string | ((ctx: ToolContext) => string | Promise<string>);
|
|
19
|
+
toDescriptor(): ToolDescriptor;
|
|
20
|
+
}
|
|
21
|
+
export type ToolFactory = (config?: Record<string, any>) => ToolInstance;
|
|
22
|
+
export declare class ToolRegistry {
|
|
23
|
+
private factories;
|
|
24
|
+
register(id: string, factory: ToolFactory): void;
|
|
25
|
+
has(id: string): boolean;
|
|
26
|
+
create(id: string, config?: Record<string, any>): ToolInstance;
|
|
27
|
+
list(): string[];
|
|
28
|
+
}
|
|
29
|
+
export declare const globalToolRegistry: ToolRegistry;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.globalToolRegistry = exports.ToolRegistry = void 0;
|
|
4
|
+
class ToolRegistry {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.factories = new Map();
|
|
7
|
+
}
|
|
8
|
+
register(id, factory) {
|
|
9
|
+
this.factories.set(id, factory);
|
|
10
|
+
}
|
|
11
|
+
has(id) {
|
|
12
|
+
return this.factories.has(id);
|
|
13
|
+
}
|
|
14
|
+
create(id, config) {
|
|
15
|
+
const factory = this.factories.get(id);
|
|
16
|
+
if (!factory) {
|
|
17
|
+
throw new Error(`Tool not registered: ${id}`);
|
|
18
|
+
}
|
|
19
|
+
return factory(config);
|
|
20
|
+
}
|
|
21
|
+
list() {
|
|
22
|
+
return Array.from(this.factories.keys());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.ToolRegistry = ToolRegistry;
|
|
26
|
+
exports.globalToolRegistry = new ToolRegistry();
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const PROMPT = "\n### skill_activate\n\n\u6FC0\u6D3B\u4E00\u4E2A Skill\uFF0C\u5C06\u5176\u5B8C\u6574\u6307\u4EE4\u52A0\u8F7D\u5230\u4E0A\u4E0B\u6587\u4E2D\u3002\n\n\u4F7F\u7528\u573A\u666F\uFF1A\n- \u5F53\u4EFB\u52A1\u9700\u8981\u7279\u5B9A Skill \u7684\u4E13\u4E1A\u77E5\u8BC6\u65F6\n- \u5728 skill_list \u67E5\u770B\u53EF\u7528 Skills \u540E\u9009\u62E9\u6FC0\u6D3B\n- \u9700\u8981\u9075\u5FAA\u7279\u5B9A\u5F00\u53D1\u89C4\u8303\u6216\u6D41\u7A0B\u65F6\n\n\u6CE8\u610F\uFF1A\n- \u6FC0\u6D3B\u540E Skill \u7684\u5B8C\u6574\u6307\u4EE4\u4F1A\u6CE8\u5165\u5230\u4E0A\u4E0B\u6587\n- \u5982\u679C Skill \u5305\u542B scripts/\uFF0C\u53EF\u4EE5\u4F7F\u7528 skill_resource \u52A0\u8F7D\n- \u6FC0\u6D3B\u4F1A\u6301\u4E45\u5316\uFF0CResume \u65F6\u81EA\u52A8\u6062\u590D\n";
|
|
2
|
+
/**
|
|
3
|
+
* skill_activate 工具 - 激活 Skill 并加载完整指令
|
|
4
|
+
*/
|
|
5
|
+
export declare const SkillActivate: import("..").ToolInstance;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkillActivate = exports.PROMPT = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const tool_1 = require("../tool");
|
|
6
|
+
exports.PROMPT = `
|
|
7
|
+
### skill_activate
|
|
8
|
+
|
|
9
|
+
激活一个 Skill,将其完整指令加载到上下文中。
|
|
10
|
+
|
|
11
|
+
使用场景:
|
|
12
|
+
- 当任务需要特定 Skill 的专业知识时
|
|
13
|
+
- 在 skill_list 查看可用 Skills 后选择激活
|
|
14
|
+
- 需要遵循特定开发规范或流程时
|
|
15
|
+
|
|
16
|
+
注意:
|
|
17
|
+
- 激活后 Skill 的完整指令会注入到上下文
|
|
18
|
+
- 如果 Skill 包含 scripts/,可以使用 skill_resource 加载
|
|
19
|
+
- 激活会持久化,Resume 时自动恢复
|
|
20
|
+
`;
|
|
21
|
+
/**
|
|
22
|
+
* skill_activate 工具 - 激活 Skill 并加载完整指令
|
|
23
|
+
*/
|
|
24
|
+
exports.SkillActivate = (0, tool_1.tool)({
|
|
25
|
+
name: 'skill_activate',
|
|
26
|
+
description: 'Activate a skill and load its full instructions into context',
|
|
27
|
+
parameters: zod_1.z.object({
|
|
28
|
+
name: zod_1.z.string().describe('Name of the skill to activate'),
|
|
29
|
+
}),
|
|
30
|
+
async execute(args, ctx) {
|
|
31
|
+
const manager = ctx.agent?.getSkillsManager?.();
|
|
32
|
+
if (!manager) {
|
|
33
|
+
return {
|
|
34
|
+
ok: false,
|
|
35
|
+
error: 'Skills not configured for this agent',
|
|
36
|
+
recommendations: ['确认 Agent 配置中启用了 skills'],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
const skill = await ctx.agent.activateSkill(args.name);
|
|
41
|
+
return {
|
|
42
|
+
ok: true,
|
|
43
|
+
message: `Skill "${skill.name}" activated`,
|
|
44
|
+
description: skill.description,
|
|
45
|
+
hasScripts: (skill.resources?.scripts?.length || 0) > 0,
|
|
46
|
+
hasReferences: (skill.resources?.references?.length || 0) > 0,
|
|
47
|
+
hasAssets: (skill.resources?.assets?.length || 0) > 0,
|
|
48
|
+
resources: skill.resources,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
error: error.message || String(error),
|
|
55
|
+
recommendations: [
|
|
56
|
+
'使用 skill_list 查看可用的 Skills',
|
|
57
|
+
'确认 Skill 名称拼写正确',
|
|
58
|
+
],
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
metadata: { readonly: true },
|
|
63
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const PROMPT = "\n### skill_list\n\n\u5217\u51FA\u5F53\u524D\u53EF\u7528\u7684 Skills\u3002\u8FD4\u56DE\u6BCF\u4E2A Skill \u7684\u540D\u79F0\u3001\u63CF\u8FF0\u548C\u6FC0\u6D3B\u72B6\u6001\u3002\n\n\u4F7F\u7528\u573A\u666F\uFF1A\n- \u5F53\u9700\u8981\u4E86\u89E3\u6709\u54EA\u4E9B Skills \u53EF\u7528\u65F6\n- \u5728\u9009\u62E9\u6FC0\u6D3B\u54EA\u4E2A Skill \u4E4B\u524D\n- \u68C0\u67E5 Skill \u7684\u6FC0\u6D3B\u72B6\u6001\n";
|
|
2
|
+
/**
|
|
3
|
+
* skill_list 工具 - 列出可用的 Skills
|
|
4
|
+
*/
|
|
5
|
+
export declare const SkillList: import("..").ToolInstance;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkillList = exports.PROMPT = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const tool_1 = require("../tool");
|
|
6
|
+
exports.PROMPT = `
|
|
7
|
+
### skill_list
|
|
8
|
+
|
|
9
|
+
列出当前可用的 Skills。返回每个 Skill 的名称、描述和激活状态。
|
|
10
|
+
|
|
11
|
+
使用场景:
|
|
12
|
+
- 当需要了解有哪些 Skills 可用时
|
|
13
|
+
- 在选择激活哪个 Skill 之前
|
|
14
|
+
- 检查 Skill 的激活状态
|
|
15
|
+
`;
|
|
16
|
+
/**
|
|
17
|
+
* skill_list 工具 - 列出可用的 Skills
|
|
18
|
+
*/
|
|
19
|
+
exports.SkillList = (0, tool_1.tool)({
|
|
20
|
+
name: 'skill_list',
|
|
21
|
+
description: 'List available skills with their names, descriptions, and activation status',
|
|
22
|
+
parameters: zod_1.z.object({}),
|
|
23
|
+
async execute(_args, ctx) {
|
|
24
|
+
const manager = ctx.agent?.getSkillsManager?.();
|
|
25
|
+
if (!manager) {
|
|
26
|
+
return {
|
|
27
|
+
ok: false,
|
|
28
|
+
error: 'Skills not configured for this agent',
|
|
29
|
+
recommendations: ['确认 Agent 配置中启用了 skills'],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const skills = manager.list();
|
|
33
|
+
return {
|
|
34
|
+
ok: true,
|
|
35
|
+
skills: skills.map((s) => ({
|
|
36
|
+
name: s.name,
|
|
37
|
+
description: s.description,
|
|
38
|
+
activated: manager.isActivated(s.name),
|
|
39
|
+
hasScripts: (s.resources?.scripts?.length || 0) > 0,
|
|
40
|
+
hasReferences: (s.resources?.references?.length || 0) > 0,
|
|
41
|
+
hasAssets: (s.resources?.assets?.length || 0) > 0,
|
|
42
|
+
})),
|
|
43
|
+
count: skills.length,
|
|
44
|
+
activatedCount: skills.filter((s) => manager.isActivated(s.name)).length,
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
metadata: { readonly: true },
|
|
48
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const PROMPT = "\n### skill_resource\n\n\u52A0\u8F7D\u5DF2\u6FC0\u6D3B Skill \u7684\u8D44\u6E90\u6587\u4EF6\u5185\u5BB9\uFF08scripts/\u3001references/\u3001assets/ \u76EE\u5F55\u4E0B\u7684\u6587\u4EF6\uFF09\u3002\n\n\u4F7F\u7528\u573A\u666F\uFF1A\n- \u9700\u8981\u8BFB\u53D6 Skill \u63D0\u4F9B\u7684\u53C2\u8003\u6587\u6863\n- \u9700\u8981\u52A0\u8F7D Skill \u7684\u6A21\u677F\u6216\u8D44\u6E90\u6587\u4EF6\n- \u67E5\u770B Skill \u7684\u793A\u4F8B\u4EE3\u7801\n\n\u6CE8\u610F\uFF1A\n- \u53EA\u80FD\u52A0\u8F7D\u5DF2\u6FC0\u6D3B Skill \u7684\u8D44\u6E90\n- resourcePath \u662F\u76F8\u5BF9\u4E8E Skill \u76EE\u5F55\u7684\u8DEF\u5F84\n- \u652F\u6301 scripts/\u3001references/\u3001assets/ \u76EE\u5F55\u4E0B\u7684\u6587\u4EF6\n";
|
|
2
|
+
/**
|
|
3
|
+
* skill_resource 工具 - 加载 Skill 资源文件
|
|
4
|
+
*/
|
|
5
|
+
export declare const SkillResource: import("..").ToolInstance;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SkillResource = exports.PROMPT = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const tool_1 = require("../tool");
|
|
6
|
+
exports.PROMPT = `
|
|
7
|
+
### skill_resource
|
|
8
|
+
|
|
9
|
+
加载已激活 Skill 的资源文件内容(scripts/、references/、assets/ 目录下的文件)。
|
|
10
|
+
|
|
11
|
+
使用场景:
|
|
12
|
+
- 需要读取 Skill 提供的参考文档
|
|
13
|
+
- 需要加载 Skill 的模板或资源文件
|
|
14
|
+
- 查看 Skill 的示例代码
|
|
15
|
+
|
|
16
|
+
注意:
|
|
17
|
+
- 只能加载已激活 Skill 的资源
|
|
18
|
+
- resourcePath 是相对于 Skill 目录的路径
|
|
19
|
+
- 支持 scripts/、references/、assets/ 目录下的文件
|
|
20
|
+
`;
|
|
21
|
+
/**
|
|
22
|
+
* skill_resource 工具 - 加载 Skill 资源文件
|
|
23
|
+
*/
|
|
24
|
+
exports.SkillResource = (0, tool_1.tool)({
|
|
25
|
+
name: 'skill_resource',
|
|
26
|
+
description: 'Load a resource file from an activated skill (scripts, references, assets)',
|
|
27
|
+
parameters: zod_1.z.object({
|
|
28
|
+
skillName: zod_1.z.string().describe('Name of the skill'),
|
|
29
|
+
resourcePath: zod_1.z.string().describe('Path relative to skill directory (e.g., "references/guide.md")'),
|
|
30
|
+
}),
|
|
31
|
+
async execute(args, ctx) {
|
|
32
|
+
const manager = ctx.agent?.getSkillsManager?.();
|
|
33
|
+
if (!manager) {
|
|
34
|
+
return {
|
|
35
|
+
ok: false,
|
|
36
|
+
error: 'Skills not configured for this agent',
|
|
37
|
+
recommendations: ['确认 Agent 配置中启用了 skills'],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const skill = manager.get(args.skillName);
|
|
41
|
+
if (!skill) {
|
|
42
|
+
return {
|
|
43
|
+
ok: false,
|
|
44
|
+
error: `Skill not found: ${args.skillName}`,
|
|
45
|
+
recommendations: [
|
|
46
|
+
'使用 skill_list 查看可用的 Skills',
|
|
47
|
+
'确认 Skill 名称拼写正确',
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
if (!manager.isActivated(args.skillName)) {
|
|
52
|
+
return {
|
|
53
|
+
ok: false,
|
|
54
|
+
error: `Skill "${args.skillName}" is not activated`,
|
|
55
|
+
recommendations: [
|
|
56
|
+
`使用 skill_activate 激活 "${args.skillName}"`,
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const content = await manager.loadResource(args.skillName, args.resourcePath);
|
|
62
|
+
return {
|
|
63
|
+
ok: true,
|
|
64
|
+
skillName: args.skillName,
|
|
65
|
+
resourcePath: args.resourcePath,
|
|
66
|
+
content,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
error: error.message || String(error),
|
|
73
|
+
recommendations: [
|
|
74
|
+
'检查资源路径是否正确',
|
|
75
|
+
'确认文件存在于 Skill 目录中',
|
|
76
|
+
`可用资源: ${JSON.stringify(skill.resources || {})}`,
|
|
77
|
+
],
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
metadata: { readonly: true },
|
|
82
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTaskRunTool = createTaskRunTool;
|
|
4
|
+
const tool_1 = require("../tool");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
function createTaskRunTool(templates) {
|
|
8
|
+
if (!templates || templates.length === 0) {
|
|
9
|
+
throw new Error('Cannot create task_run tool: no agent templates provided');
|
|
10
|
+
}
|
|
11
|
+
const TaskRun = (0, tool_1.tool)({
|
|
12
|
+
name: 'task_run',
|
|
13
|
+
description: prompt_1.DESCRIPTION,
|
|
14
|
+
parameters: zod_1.z.object({
|
|
15
|
+
description: zod_1.z.string().describe('Short description of the task (3-5 words)'),
|
|
16
|
+
prompt: zod_1.z.string().describe('Detailed instructions for the sub-agent'),
|
|
17
|
+
agentTemplateId: zod_1.z.string().describe('Agent template ID to use for this task'),
|
|
18
|
+
context: zod_1.z.string().optional().describe('Additional context to append'),
|
|
19
|
+
}),
|
|
20
|
+
async execute(args, ctx) {
|
|
21
|
+
const { description, prompt, agentTemplateId, context } = args;
|
|
22
|
+
const template = templates.find((tpl) => tpl.id === agentTemplateId);
|
|
23
|
+
if (!template) {
|
|
24
|
+
const availableTemplates = templates
|
|
25
|
+
.map((tpl) => ` - ${tpl.id}: ${tpl.whenToUse || 'General purpose agent'}`)
|
|
26
|
+
.join('\n');
|
|
27
|
+
throw new Error(`Agent template '${agentTemplateId}' not found.\n\nAvailable templates:\n${availableTemplates}\n\nPlease choose one of the available template IDs.`);
|
|
28
|
+
}
|
|
29
|
+
const detailedPrompt = [
|
|
30
|
+
`# Task: ${description}`,
|
|
31
|
+
prompt,
|
|
32
|
+
context ? `\n# Additional Context\n${context}` : undefined,
|
|
33
|
+
]
|
|
34
|
+
.filter(Boolean)
|
|
35
|
+
.join('\n\n');
|
|
36
|
+
if (!ctx.agent?.delegateTask) {
|
|
37
|
+
throw new Error('Task delegation not supported by this agent version');
|
|
38
|
+
}
|
|
39
|
+
const result = await ctx.agent.delegateTask({
|
|
40
|
+
templateId: template.id,
|
|
41
|
+
prompt: detailedPrompt,
|
|
42
|
+
tools: template.tools,
|
|
43
|
+
callId: ctx.callId,
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
status: result.status,
|
|
47
|
+
template: template.id,
|
|
48
|
+
text: result.text,
|
|
49
|
+
permissionIds: result.permissionIds,
|
|
50
|
+
agentId: result.agentId,
|
|
51
|
+
};
|
|
52
|
+
},
|
|
53
|
+
metadata: {
|
|
54
|
+
readonly: false,
|
|
55
|
+
version: '1.0',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
TaskRun.prompt = (0, prompt_1.generatePrompt)(templates);
|
|
59
|
+
return TaskRun;
|
|
60
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DESCRIPTION = void 0;
|
|
4
|
+
exports.generatePrompt = generatePrompt;
|
|
5
|
+
exports.DESCRIPTION = 'Delegate a task to a specialized sub-agent';
|
|
6
|
+
function generatePrompt(templates) {
|
|
7
|
+
const templateList = templates
|
|
8
|
+
.map((tpl) => `- agentTemplateId: ${tpl.id}\n whenToUse: ${tpl.whenToUse || 'General purpose tasks'}`)
|
|
9
|
+
.join('\n');
|
|
10
|
+
return `Delegate complex, multi-step work to specialized sub-agents.
|
|
11
|
+
|
|
12
|
+
Instructions:
|
|
13
|
+
- Always provide a concise "description" (3-5 words) and a detailed "prompt" outlining deliverables.
|
|
14
|
+
- REQUIRED: Set "agentTemplateId" to one of the available template IDs below.
|
|
15
|
+
- Optionally supply "context" for extra background information.
|
|
16
|
+
- The tool returns the sub-agent's final text and any pending permissions.
|
|
17
|
+
|
|
18
|
+
Parallel Execution:
|
|
19
|
+
- Multiple task_run calls in the same response will execute in parallel.
|
|
20
|
+
- Use this for independent tasks that don't depend on each other's output.
|
|
21
|
+
|
|
22
|
+
Available agent templates:
|
|
23
|
+
${templateList}
|
|
24
|
+
|
|
25
|
+
Safety/Limitations:
|
|
26
|
+
- Sub-agents inherit the same sandbox and tool restrictions.
|
|
27
|
+
- Task delegation depth may be limited to prevent infinite recursion.
|
|
28
|
+
- Sub-agents cannot access parent agent state or context directly.`;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TodoRead: import("..").ToolInstance;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TodoRead = void 0;
|
|
4
|
+
const tool_1 = require("../tool");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
exports.TodoRead = (0, tool_1.tool)({
|
|
8
|
+
name: 'todo_read',
|
|
9
|
+
description: prompt_1.DESCRIPTION,
|
|
10
|
+
parameters: zod_1.z.object({}),
|
|
11
|
+
async execute(_args, ctx) {
|
|
12
|
+
if (ctx.agent?.getTodos) {
|
|
13
|
+
return { todos: ctx.agent.getTodos() };
|
|
14
|
+
}
|
|
15
|
+
const service = ctx.services?.todo;
|
|
16
|
+
if (!service) {
|
|
17
|
+
return {
|
|
18
|
+
todos: [],
|
|
19
|
+
note: 'Todo service not enabled for this agent'
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
return { todos: service.list() };
|
|
23
|
+
},
|
|
24
|
+
metadata: {
|
|
25
|
+
readonly: true,
|
|
26
|
+
version: '1.0',
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
exports.TodoRead.prompt = prompt_1.PROMPT;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const DESCRIPTION = "Read the current todo list managed by the agent";
|
|
2
|
+
export declare const PROMPT = "Retrieve the canonical list of todos that this agent maintains.\n\nGuidelines:\n- Use this before planning or reprioritizing work\n- The returned list reflects the current state of all tracked tasks\n- Each todo includes: id, title, status, and optional assignee/notes\n\nTodo Status Values:\n- pending: Not yet started\n- in_progress: Currently being worked on\n- completed: Finished\n\nLimitations:\n- Returns empty list if todo service is not enabled for this agent";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROMPT = exports.DESCRIPTION = void 0;
|
|
4
|
+
exports.DESCRIPTION = 'Read the current todo list managed by the agent';
|
|
5
|
+
exports.PROMPT = `Retrieve the canonical list of todos that this agent maintains.
|
|
6
|
+
|
|
7
|
+
Guidelines:
|
|
8
|
+
- Use this before planning or reprioritizing work
|
|
9
|
+
- The returned list reflects the current state of all tracked tasks
|
|
10
|
+
- Each todo includes: id, title, status, and optional assignee/notes
|
|
11
|
+
|
|
12
|
+
Todo Status Values:
|
|
13
|
+
- pending: Not yet started
|
|
14
|
+
- in_progress: Currently being worked on
|
|
15
|
+
- completed: Finished
|
|
16
|
+
|
|
17
|
+
Limitations:
|
|
18
|
+
- Returns empty list if todo service is not enabled for this agent`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TodoWrite: import("..").ToolInstance;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TodoWrite = void 0;
|
|
4
|
+
const tool_1 = require("../tool");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const prompt_1 = require("./prompt");
|
|
7
|
+
const todoItemSchema = zod_1.z.object({
|
|
8
|
+
id: zod_1.z.string().describe('Unique identifier for the todo'),
|
|
9
|
+
title: zod_1.z.string().describe('Clear description of the task'),
|
|
10
|
+
status: zod_1.z.enum(['pending', 'in_progress', 'completed']).describe('Current status'),
|
|
11
|
+
assignee: zod_1.z.string().optional().describe('Who is responsible'),
|
|
12
|
+
notes: zod_1.z.string().optional().describe('Additional context'),
|
|
13
|
+
});
|
|
14
|
+
exports.TodoWrite = (0, tool_1.tool)({
|
|
15
|
+
name: 'todo_write',
|
|
16
|
+
description: prompt_1.DESCRIPTION,
|
|
17
|
+
parameters: zod_1.z.object({
|
|
18
|
+
todos: zod_1.z.array(todoItemSchema).describe('Array of todo items'),
|
|
19
|
+
}),
|
|
20
|
+
async execute(args, ctx) {
|
|
21
|
+
const { todos } = args;
|
|
22
|
+
const inProgressCount = todos.filter((t) => t.status === 'in_progress').length;
|
|
23
|
+
if (inProgressCount > 1) {
|
|
24
|
+
throw new Error(`Only one todo can be "in_progress" at a time. Found ${inProgressCount} in_progress todos.`);
|
|
25
|
+
}
|
|
26
|
+
if (!ctx.agent?.setTodos) {
|
|
27
|
+
const service = ctx.services?.todo;
|
|
28
|
+
if (!service) {
|
|
29
|
+
throw new Error('Todo service not enabled for this agent');
|
|
30
|
+
}
|
|
31
|
+
await service.setTodos(todos);
|
|
32
|
+
return { ok: true, count: todos.length };
|
|
33
|
+
}
|
|
34
|
+
await ctx.agent.setTodos(todos);
|
|
35
|
+
return { ok: true, count: todos.length };
|
|
36
|
+
},
|
|
37
|
+
metadata: {
|
|
38
|
+
readonly: false,
|
|
39
|
+
version: '1.0',
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
exports.TodoWrite.prompt = prompt_1.PROMPT;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export declare const DESCRIPTION = "Replace the todo list managed by the agent";
|
|
2
|
+
export declare const PROMPT = "Replace the agent-managed todo list with a new array of todos.\n\nGuidelines:\n- Always provide structured IDs, titles, and statuses\n- Only ONE item may have \"in_progress\" status at any time\n- IDs should be unique and descriptive\n- Titles should be clear and actionable\n\nTodo Structure:\n- id (required): Unique identifier for the todo\n- title (required): Clear description of the task\n- status (required): \"pending\" | \"in_progress\" | \"completed\"\n- assignee (optional): Who is responsible\n- notes (optional): Additional context or details\n\nSafety/Limitations:\n- This operation replaces the entire todo list\n- Previous todos not included in the new list will be removed\n- Returns error if todo service is not enabled";
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PROMPT = exports.DESCRIPTION = void 0;
|
|
4
|
+
exports.DESCRIPTION = 'Replace the todo list managed by the agent';
|
|
5
|
+
exports.PROMPT = `Replace the agent-managed todo list with a new array of todos.
|
|
6
|
+
|
|
7
|
+
Guidelines:
|
|
8
|
+
- Always provide structured IDs, titles, and statuses
|
|
9
|
+
- Only ONE item may have "in_progress" status at any time
|
|
10
|
+
- IDs should be unique and descriptive
|
|
11
|
+
- Titles should be clear and actionable
|
|
12
|
+
|
|
13
|
+
Todo Structure:
|
|
14
|
+
- id (required): Unique identifier for the todo
|
|
15
|
+
- title (required): Clear description of the task
|
|
16
|
+
- status (required): "pending" | "in_progress" | "completed"
|
|
17
|
+
- assignee (optional): Who is responsible
|
|
18
|
+
- notes (optional): Additional context or details
|
|
19
|
+
|
|
20
|
+
Safety/Limitations:
|
|
21
|
+
- This operation replaces the entire todo list
|
|
22
|
+
- Previous todos not included in the new list will be removed
|
|
23
|
+
- Returns error if todo service is not enabled`;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { ZodType } from 'zod';
|
|
2
|
+
import { ToolInstance } from './registry';
|
|
3
|
+
import { ToolContext } from '../core/types';
|
|
4
|
+
import { Hooks } from '../core/hooks';
|
|
5
|
+
/**
|
|
6
|
+
* 工具定义接口
|
|
7
|
+
*/
|
|
8
|
+
export interface ToolDefinition<TArgs = any, TResult = any> {
|
|
9
|
+
name: string;
|
|
10
|
+
description?: string;
|
|
11
|
+
parameters?: ZodType<TArgs>;
|
|
12
|
+
execute: (args: TArgs, ctx: EnhancedToolContext) => Promise<TResult> | TResult;
|
|
13
|
+
metadata?: {
|
|
14
|
+
version?: string;
|
|
15
|
+
tags?: string[];
|
|
16
|
+
cacheable?: boolean;
|
|
17
|
+
cacheTTL?: number;
|
|
18
|
+
timeout?: number;
|
|
19
|
+
concurrent?: boolean;
|
|
20
|
+
readonly?: boolean;
|
|
21
|
+
};
|
|
22
|
+
hooks?: Hooks;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 工具上下文增强接口
|
|
26
|
+
*/
|
|
27
|
+
export interface EnhancedToolContext extends ToolContext {
|
|
28
|
+
emit(eventType: string, data?: any): void;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 重载 1: tool(name, executeFn)
|
|
32
|
+
* 零配置模式,自动推断类型
|
|
33
|
+
*/
|
|
34
|
+
export declare function tool<TArgs = any, TResult = any>(name: string, executeFn: (args: TArgs, ctx?: EnhancedToolContext) => Promise<TResult> | TResult): ToolInstance;
|
|
35
|
+
/**
|
|
36
|
+
* 重载 2: tool(definition)
|
|
37
|
+
* 完整配置模式
|
|
38
|
+
*/
|
|
39
|
+
export declare function tool<TArgs = any, TResult = any>(definition: ToolDefinition<TArgs, TResult>): ToolInstance;
|
|
40
|
+
/**
|
|
41
|
+
* 批量定义工具
|
|
42
|
+
*/
|
|
43
|
+
export declare function tools(definitions: ToolDefinition[]): ToolInstance[];
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tool = tool;
|
|
4
|
+
exports.tools = tools;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const zod_to_json_schema_1 = require("zod-to-json-schema");
|
|
7
|
+
const registry_1 = require("./registry");
|
|
8
|
+
/**
|
|
9
|
+
* 实现
|
|
10
|
+
*/
|
|
11
|
+
function tool(nameOrDef, executeFn) {
|
|
12
|
+
// 解析参数
|
|
13
|
+
const def = typeof nameOrDef === 'string'
|
|
14
|
+
? {
|
|
15
|
+
name: nameOrDef,
|
|
16
|
+
description: `Execute ${nameOrDef}`,
|
|
17
|
+
parameters: zod_1.z.any(),
|
|
18
|
+
execute: executeFn,
|
|
19
|
+
}
|
|
20
|
+
: nameOrDef;
|
|
21
|
+
// 生成 JSON Schema
|
|
22
|
+
const input_schema = def.parameters
|
|
23
|
+
? (0, zod_to_json_schema_1.zodToJsonSchema)(def.parameters, { target: 'openApi3', $refStrategy: 'none' })
|
|
24
|
+
: { type: 'object', properties: {} };
|
|
25
|
+
// 创建工具实例
|
|
26
|
+
const toolInstance = {
|
|
27
|
+
name: def.name,
|
|
28
|
+
description: def.description || `Execute ${def.name}`,
|
|
29
|
+
input_schema,
|
|
30
|
+
hooks: def.hooks,
|
|
31
|
+
async exec(args, ctx) {
|
|
32
|
+
try {
|
|
33
|
+
// 参数验证
|
|
34
|
+
if (def.parameters) {
|
|
35
|
+
const parseResult = def.parameters.safeParse(args);
|
|
36
|
+
if (!parseResult.success) {
|
|
37
|
+
return {
|
|
38
|
+
ok: false,
|
|
39
|
+
error: `Invalid parameters: ${parseResult.error.message}`,
|
|
40
|
+
_validationError: true,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
args = parseResult.data;
|
|
44
|
+
}
|
|
45
|
+
// 增强上下文
|
|
46
|
+
const enhancedCtx = {
|
|
47
|
+
...ctx,
|
|
48
|
+
emit(eventType, data) {
|
|
49
|
+
ctx.agent?.events?.emitMonitor({
|
|
50
|
+
type: 'tool_custom_event',
|
|
51
|
+
toolName: def.name,
|
|
52
|
+
eventType,
|
|
53
|
+
data,
|
|
54
|
+
callId: ctx.callId,
|
|
55
|
+
timestamp: Date.now(),
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
// 执行工具
|
|
60
|
+
const result = await def.execute(args, enhancedCtx);
|
|
61
|
+
// 如果工具返回 {ok: false},保持原样
|
|
62
|
+
if (result && typeof result === 'object' && 'ok' in result && result.ok === false) {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
// 正常结果
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
// 捕获工具执行中的所有错误,统一返回格式
|
|
70
|
+
return {
|
|
71
|
+
ok: false,
|
|
72
|
+
error: error?.message || String(error),
|
|
73
|
+
_thrownError: true,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
toDescriptor() {
|
|
78
|
+
return {
|
|
79
|
+
source: 'registered',
|
|
80
|
+
name: def.name,
|
|
81
|
+
registryId: def.name,
|
|
82
|
+
metadata: {
|
|
83
|
+
version: def.metadata?.version,
|
|
84
|
+
tags: def.metadata?.tags,
|
|
85
|
+
cacheable: def.metadata?.cacheable,
|
|
86
|
+
cacheTTL: def.metadata?.cacheTTL,
|
|
87
|
+
timeout: def.metadata?.timeout,
|
|
88
|
+
concurrent: def.metadata?.concurrent,
|
|
89
|
+
access: def.metadata?.readonly ? 'read' : 'write',
|
|
90
|
+
mutates: !def.metadata?.readonly,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
// 自动注册到全局 registry
|
|
96
|
+
registry_1.globalToolRegistry.register(def.name, () => toolInstance);
|
|
97
|
+
return toolInstance;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 批量定义工具
|
|
101
|
+
*/
|
|
102
|
+
function tools(definitions) {
|
|
103
|
+
return definitions.map((def) => tool(def));
|
|
104
|
+
}
|