@codeany/open-agent-sdk 0.2.2 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent.d.ts +113 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +453 -0
- package/dist/agent.js.map +1 -0
- package/dist/engine.d.ts +62 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +496 -0
- package/dist/engine.js.map +1 -0
- package/dist/hooks.d.ts +111 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +179 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +66 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/client.d.ts +19 -0
- package/dist/mcp/client.d.ts.map +1 -0
- package/dist/mcp/client.js +126 -0
- package/dist/mcp/client.js.map +1 -0
- package/dist/providers/anthropic.d.ts +17 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +47 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +20 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +26 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/openai.d.ts +26 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +212 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/types.d.ts +84 -0
- package/dist/providers/types.d.ts.map +1 -0
- package/dist/providers/types.js +11 -0
- package/dist/providers/types.js.map +1 -0
- package/dist/sdk-mcp-server.d.ts +52 -0
- package/dist/sdk-mcp-server.d.ts.map +1 -0
- package/dist/sdk-mcp-server.js +57 -0
- package/dist/sdk-mcp-server.js.map +1 -0
- package/dist/session.d.ts +73 -0
- package/dist/session.d.ts.map +1 -0
- package/dist/session.js +159 -0
- package/dist/session.js.map +1 -0
- package/dist/skills/bundled/commit.d.ts +7 -0
- package/dist/skills/bundled/commit.d.ts.map +1 -0
- package/dist/skills/bundled/commit.js +35 -0
- package/dist/skills/bundled/commit.js.map +1 -0
- package/dist/skills/bundled/debug.d.ts +7 -0
- package/dist/skills/bundled/debug.d.ts.map +1 -0
- package/{src/skills/bundled/debug.ts → dist/skills/bundled/debug.js} +20 -22
- package/dist/skills/bundled/debug.js.map +1 -0
- package/dist/skills/bundled/index.d.ts +11 -0
- package/dist/skills/bundled/index.d.ts.map +1 -0
- package/dist/skills/bundled/index.js +26 -0
- package/dist/skills/bundled/index.js.map +1 -0
- package/dist/skills/bundled/review.d.ts +7 -0
- package/dist/skills/bundled/review.d.ts.map +1 -0
- package/{src/skills/bundled/review.ts → dist/skills/bundled/review.js} +18 -21
- package/dist/skills/bundled/review.js.map +1 -0
- package/dist/skills/bundled/simplify.d.ts +8 -0
- package/dist/skills/bundled/simplify.d.ts.map +1 -0
- package/{src/skills/bundled/simplify.ts → dist/skills/bundled/simplify.js} +16 -19
- package/dist/skills/bundled/simplify.js.map +1 -0
- package/dist/skills/bundled/test.d.ts +7 -0
- package/dist/skills/bundled/test.d.ts.map +1 -0
- package/{src/skills/bundled/test.ts → dist/skills/bundled/test.js} +18 -21
- package/dist/skills/bundled/test.js.map +1 -0
- package/dist/skills/index.d.ts +7 -0
- package/dist/skills/index.d.ts.map +1 -0
- package/dist/skills/index.js +8 -0
- package/dist/skills/index.js.map +1 -0
- package/dist/skills/registry.d.ts +43 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +111 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/types.d.ts +83 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +8 -0
- package/dist/skills/types.js.map +1 -0
- package/dist/tool-helper.d.ts +73 -0
- package/dist/tool-helper.d.ts.map +1 -0
- package/dist/tool-helper.js +86 -0
- package/dist/tool-helper.js.map +1 -0
- package/dist/tools/agent-tool.d.ts +17 -0
- package/dist/tools/agent-tool.d.ts.map +1 -0
- package/dist/tools/agent-tool.js +146 -0
- package/dist/tools/agent-tool.js.map +1 -0
- package/dist/tools/ask-user.d.ts +18 -0
- package/dist/tools/ask-user.d.ts.map +1 -0
- package/dist/tools/ask-user.js +72 -0
- package/dist/tools/ask-user.js.map +1 -0
- package/dist/tools/bash.d.ts +5 -0
- package/dist/tools/bash.d.ts.map +1 -0
- package/dist/tools/bash.js +67 -0
- package/dist/tools/bash.js.map +1 -0
- package/dist/tools/config-tool.d.ts +20 -0
- package/dist/tools/config-tool.d.ts.map +1 -0
- package/dist/tools/config-tool.js +83 -0
- package/dist/tools/config-tool.js.map +1 -0
- package/dist/tools/cron-tools.d.ts +33 -0
- package/dist/tools/cron-tools.d.ts.map +1 -0
- package/dist/tools/cron-tools.js +128 -0
- package/dist/tools/cron-tools.js.map +1 -0
- package/dist/tools/edit.d.ts +5 -0
- package/dist/tools/edit.d.ts.map +1 -0
- package/dist/tools/edit.js +70 -0
- package/dist/tools/edit.js.map +1 -0
- package/dist/tools/glob.d.ts +5 -0
- package/dist/tools/glob.d.ts.map +1 -0
- package/dist/tools/glob.js +75 -0
- package/dist/tools/glob.js.map +1 -0
- package/dist/tools/grep.d.ts +5 -0
- package/dist/tools/grep.d.ts.map +1 -0
- package/dist/tools/grep.js +168 -0
- package/dist/tools/grep.js.map +1 -0
- package/dist/tools/index.d.ts +45 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +162 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/lsp-tool.d.ts +9 -0
- package/dist/tools/lsp-tool.d.ts.map +1 -0
- package/dist/tools/lsp-tool.js +137 -0
- package/dist/tools/lsp-tool.js.map +1 -0
- package/dist/tools/mcp-resource-tools.d.ts +14 -0
- package/dist/tools/mcp-resource-tools.d.ts.map +1 -0
- package/dist/tools/mcp-resource-tools.js +117 -0
- package/dist/tools/mcp-resource-tools.js.map +1 -0
- package/dist/tools/notebook-edit.d.ts +5 -0
- package/dist/tools/notebook-edit.d.ts.map +1 -0
- package/dist/tools/notebook-edit.js +85 -0
- package/dist/tools/notebook-edit.js.map +1 -0
- package/dist/tools/plan-tools.d.ts +12 -0
- package/dist/tools/plan-tools.d.ts.map +1 -0
- package/dist/tools/plan-tools.js +77 -0
- package/dist/tools/plan-tools.js.map +1 -0
- package/dist/tools/read.d.ts +5 -0
- package/dist/tools/read.d.ts.map +1 -0
- package/dist/tools/read.js +66 -0
- package/dist/tools/read.js.map +1 -0
- package/dist/tools/send-message.d.ts +31 -0
- package/dist/tools/send-message.d.ts.map +1 -0
- package/dist/tools/send-message.js +77 -0
- package/dist/tools/send-message.js.map +1 -0
- package/dist/tools/skill-tool.d.ts +9 -0
- package/dist/tools/skill-tool.d.ts.map +1 -0
- package/dist/tools/skill-tool.js +115 -0
- package/dist/tools/skill-tool.js.map +1 -0
- package/dist/tools/task-tools.d.ts +48 -0
- package/dist/tools/task-tools.d.ts.map +1 -0
- package/dist/tools/task-tools.js +242 -0
- package/dist/tools/task-tools.js.map +1 -0
- package/dist/tools/team-tools.d.ts +34 -0
- package/dist/tools/team-tools.d.ts.map +1 -0
- package/dist/tools/team-tools.js +103 -0
- package/dist/tools/team-tools.js.map +1 -0
- package/dist/tools/todo-tool.d.ts +22 -0
- package/dist/tools/todo-tool.d.ts.map +1 -0
- package/dist/tools/todo-tool.js +93 -0
- package/dist/tools/todo-tool.js.map +1 -0
- package/dist/tools/tool-search.d.ts +13 -0
- package/dist/tools/tool-search.d.ts.map +1 -0
- package/dist/tools/tool-search.js +76 -0
- package/dist/tools/tool-search.js.map +1 -0
- package/dist/tools/types.d.ts +29 -0
- package/dist/tools/types.d.ts.map +1 -0
- package/dist/tools/types.js +52 -0
- package/dist/tools/types.js.map +1 -0
- package/dist/tools/web-fetch.d.ts +5 -0
- package/dist/tools/web-fetch.d.ts.map +1 -0
- package/dist/tools/web-fetch.js +60 -0
- package/dist/tools/web-fetch.js.map +1 -0
- package/dist/tools/web-search.d.ts +5 -0
- package/dist/tools/web-search.d.ts.map +1 -0
- package/dist/tools/web-search.js +77 -0
- package/dist/tools/web-search.js.map +1 -0
- package/dist/tools/worktree-tools.d.ts +10 -0
- package/dist/tools/worktree-tools.d.ts.map +1 -0
- package/dist/tools/worktree-tools.js +130 -0
- package/dist/tools/worktree-tools.js.map +1 -0
- package/dist/tools/write.d.ts +5 -0
- package/dist/tools/write.d.ts.map +1 -0
- package/dist/tools/write.js +40 -0
- package/dist/tools/write.js.map +1 -0
- package/dist/types.d.ts +432 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/compact.d.ts +44 -0
- package/dist/utils/compact.d.ts.map +1 -0
- package/dist/utils/compact.js +162 -0
- package/dist/utils/compact.js.map +1 -0
- package/dist/utils/context.d.ts +35 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +174 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/fileCache.d.ts +64 -0
- package/dist/utils/fileCache.d.ts.map +1 -0
- package/dist/utils/fileCache.js +117 -0
- package/dist/utils/fileCache.js.map +1 -0
- package/dist/utils/messages.d.ts +57 -0
- package/dist/utils/messages.d.ts.map +1 -0
- package/dist/utils/messages.js +152 -0
- package/dist/utils/messages.js.map +1 -0
- package/dist/utils/retry.d.ts +48 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +111 -0
- package/dist/utils/retry.js.map +1 -0
- package/dist/utils/tokens.d.ts +57 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +134 -0
- package/dist/utils/tokens.js.map +1 -0
- package/package.json +6 -1
- package/.env.example +0 -8
- package/examples/01-simple-query.ts +0 -43
- package/examples/02-multi-tool.ts +0 -44
- package/examples/03-multi-turn.ts +0 -39
- package/examples/04-prompt-api.ts +0 -29
- package/examples/05-custom-system-prompt.ts +0 -26
- package/examples/06-mcp-server.ts +0 -49
- package/examples/07-custom-tools.ts +0 -87
- package/examples/08-official-api-compat.ts +0 -38
- package/examples/09-subagents.ts +0 -48
- package/examples/10-permissions.ts +0 -40
- package/examples/11-custom-mcp-tools.ts +0 -101
- package/examples/12-skills.ts +0 -88
- package/examples/13-hooks.ts +0 -88
- package/examples/14-openai-compat.ts +0 -71
- package/examples/web/index.html +0 -365
- package/examples/web/server.ts +0 -157
- package/src/agent.ts +0 -516
- package/src/engine.ts +0 -633
- package/src/hooks.ts +0 -261
- package/src/index.ts +0 -426
- package/src/mcp/client.ts +0 -150
- package/src/providers/anthropic.ts +0 -60
- package/src/providers/index.ts +0 -34
- package/src/providers/openai.ts +0 -315
- package/src/providers/types.ts +0 -85
- package/src/sdk-mcp-server.ts +0 -78
- package/src/session.ts +0 -227
- package/src/skills/bundled/commit.ts +0 -38
- package/src/skills/bundled/index.ts +0 -28
- package/src/skills/index.ts +0 -25
- package/src/skills/registry.ts +0 -133
- package/src/skills/types.ts +0 -99
- package/src/tool-helper.ts +0 -127
- package/src/tools/agent-tool.ts +0 -164
- package/src/tools/ask-user.ts +0 -79
- package/src/tools/bash.ts +0 -75
- package/src/tools/config-tool.ts +0 -89
- package/src/tools/cron-tools.ts +0 -153
- package/src/tools/edit.ts +0 -74
- package/src/tools/glob.ts +0 -77
- package/src/tools/grep.ts +0 -168
- package/src/tools/index.ts +0 -240
- package/src/tools/lsp-tool.ts +0 -163
- package/src/tools/mcp-resource-tools.ts +0 -125
- package/src/tools/notebook-edit.ts +0 -93
- package/src/tools/plan-tools.ts +0 -88
- package/src/tools/read.ts +0 -73
- package/src/tools/send-message.ts +0 -96
- package/src/tools/skill-tool.ts +0 -133
- package/src/tools/task-tools.ts +0 -290
- package/src/tools/team-tools.ts +0 -128
- package/src/tools/todo-tool.ts +0 -112
- package/src/tools/tool-search.ts +0 -87
- package/src/tools/types.ts +0 -66
- package/src/tools/web-fetch.ts +0 -66
- package/src/tools/web-search.ts +0 -86
- package/src/tools/worktree-tools.ts +0 -140
- package/src/tools/write.ts +0 -42
- package/src/types.ts +0 -486
- package/src/utils/compact.ts +0 -207
- package/src/utils/context.ts +0 -191
- package/src/utils/fileCache.ts +0 -148
- package/src/utils/messages.ts +0 -195
- package/src/utils/retry.ts +0 -140
- package/src/utils/tokens.ts +0 -145
- package/tsconfig.json +0 -19
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill Registry
|
|
3
|
+
*
|
|
4
|
+
* Central registry for managing skill definitions.
|
|
5
|
+
* Skills can be registered programmatically or loaded from bundled definitions.
|
|
6
|
+
*/
|
|
7
|
+
/** Internal skill store */
|
|
8
|
+
const skills = new Map();
|
|
9
|
+
/** Alias -> skill name mapping */
|
|
10
|
+
const aliases = new Map();
|
|
11
|
+
/**
|
|
12
|
+
* Register a skill definition.
|
|
13
|
+
*/
|
|
14
|
+
export function registerSkill(definition) {
|
|
15
|
+
skills.set(definition.name, definition);
|
|
16
|
+
// Register aliases
|
|
17
|
+
if (definition.aliases) {
|
|
18
|
+
for (const alias of definition.aliases) {
|
|
19
|
+
aliases.set(alias, definition.name);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Get a skill by name or alias.
|
|
25
|
+
*/
|
|
26
|
+
export function getSkill(name) {
|
|
27
|
+
// Direct lookup
|
|
28
|
+
const direct = skills.get(name);
|
|
29
|
+
if (direct)
|
|
30
|
+
return direct;
|
|
31
|
+
// Alias lookup
|
|
32
|
+
const resolved = aliases.get(name);
|
|
33
|
+
if (resolved)
|
|
34
|
+
return skills.get(resolved);
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Get all registered skills.
|
|
39
|
+
*/
|
|
40
|
+
export function getAllSkills() {
|
|
41
|
+
return Array.from(skills.values());
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Get all user-invocable skills (for /command listing).
|
|
45
|
+
*/
|
|
46
|
+
export function getUserInvocableSkills() {
|
|
47
|
+
return getAllSkills().filter((s) => s.userInvocable !== false && (!s.isEnabled || s.isEnabled()));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if a skill exists.
|
|
51
|
+
*/
|
|
52
|
+
export function hasSkill(name) {
|
|
53
|
+
return skills.has(name) || aliases.has(name);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Remove a skill.
|
|
57
|
+
*/
|
|
58
|
+
export function unregisterSkill(name) {
|
|
59
|
+
const skill = skills.get(name);
|
|
60
|
+
if (!skill)
|
|
61
|
+
return false;
|
|
62
|
+
// Remove aliases
|
|
63
|
+
if (skill.aliases) {
|
|
64
|
+
for (const alias of skill.aliases) {
|
|
65
|
+
aliases.delete(alias);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return skills.delete(name);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Clear all skills (for testing).
|
|
72
|
+
*/
|
|
73
|
+
export function clearSkills() {
|
|
74
|
+
skills.clear();
|
|
75
|
+
aliases.clear();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Format skills listing for system prompt injection.
|
|
79
|
+
*
|
|
80
|
+
* Uses a budget system: skills listing gets a limited character budget
|
|
81
|
+
* to avoid bloating the context window.
|
|
82
|
+
*/
|
|
83
|
+
export function formatSkillsForPrompt(contextWindowTokens) {
|
|
84
|
+
const invocable = getUserInvocableSkills();
|
|
85
|
+
if (invocable.length === 0)
|
|
86
|
+
return '';
|
|
87
|
+
// Budget: 1% of context window in characters (4 chars per token)
|
|
88
|
+
const CHARS_PER_TOKEN = 4;
|
|
89
|
+
const DEFAULT_BUDGET = 8000;
|
|
90
|
+
const MAX_DESC_CHARS = 250;
|
|
91
|
+
const budget = contextWindowTokens
|
|
92
|
+
? Math.floor(contextWindowTokens * 0.01 * CHARS_PER_TOKEN)
|
|
93
|
+
: DEFAULT_BUDGET;
|
|
94
|
+
const lines = [];
|
|
95
|
+
let used = 0;
|
|
96
|
+
for (const skill of invocable) {
|
|
97
|
+
const desc = skill.description.length > MAX_DESC_CHARS
|
|
98
|
+
? skill.description.slice(0, MAX_DESC_CHARS) + '...'
|
|
99
|
+
: skill.description;
|
|
100
|
+
const trigger = skill.whenToUse
|
|
101
|
+
? ` TRIGGER when: ${skill.whenToUse}`
|
|
102
|
+
: '';
|
|
103
|
+
const line = `- ${skill.name}: ${desc}${trigger}`;
|
|
104
|
+
if (used + line.length > budget)
|
|
105
|
+
break;
|
|
106
|
+
lines.push(line);
|
|
107
|
+
used += line.length;
|
|
108
|
+
}
|
|
109
|
+
return lines.join('\n');
|
|
110
|
+
}
|
|
111
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/skills/registry.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,2BAA2B;AAC3B,MAAM,MAAM,GAAiC,IAAI,GAAG,EAAE,CAAA;AAEtD,kCAAkC;AAClC,MAAM,OAAO,GAAwB,IAAI,GAAG,EAAE,CAAA;AAE9C;;GAEG;AACH,MAAM,UAAU,aAAa,CAAC,UAA2B;IACvD,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;IAEvC,mBAAmB;IACnB,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;QACvB,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,OAAO,EAAE,CAAC;YACvC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,IAAI,CAAC,CAAA;QACrC,CAAC;IACH,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,gBAAgB;IAChB,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,MAAM;QAAE,OAAO,MAAM,CAAA;IAEzB,eAAe;IACf,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,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|
+
* Skills are reusable prompt templates that extend agent capabilities.
|
|
5
|
+
* They can be invoked by the model via the Skill tool or by users via /skillname.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolContext } from '../types.js';
|
|
8
|
+
import type { HookConfig } from '../hooks.js';
|
|
9
|
+
/**
|
|
10
|
+
* Content block for skill prompts (compatible with Anthropic API).
|
|
11
|
+
*/
|
|
12
|
+
export type SkillContentBlock = {
|
|
13
|
+
type: 'text';
|
|
14
|
+
text: string;
|
|
15
|
+
} | {
|
|
16
|
+
type: 'image';
|
|
17
|
+
source: {
|
|
18
|
+
type: 'base64';
|
|
19
|
+
media_type: string;
|
|
20
|
+
data: string;
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Bundled skill definition.
|
|
25
|
+
*
|
|
26
|
+
* Inspired by Claude Code's skill system. Skills provide specialized
|
|
27
|
+
* capabilities by injecting context-specific prompts with optional
|
|
28
|
+
* tool restrictions and model overrides.
|
|
29
|
+
*/
|
|
30
|
+
export interface SkillDefinition {
|
|
31
|
+
/** Unique skill name (e.g., 'simplify', 'commit') */
|
|
32
|
+
name: string;
|
|
33
|
+
/** Human-readable description */
|
|
34
|
+
description: string;
|
|
35
|
+
/** Alternative names for the skill */
|
|
36
|
+
aliases?: string[];
|
|
37
|
+
/** When the model should invoke this skill (used in system prompt) */
|
|
38
|
+
whenToUse?: string;
|
|
39
|
+
/** Hint for expected arguments */
|
|
40
|
+
argumentHint?: string;
|
|
41
|
+
/** Tools the skill is allowed to use (empty = all tools) */
|
|
42
|
+
allowedTools?: string[];
|
|
43
|
+
/** Model override for this skill */
|
|
44
|
+
model?: string;
|
|
45
|
+
/** Whether the skill can be invoked by users via /command */
|
|
46
|
+
userInvocable?: boolean;
|
|
47
|
+
/** Runtime check for availability */
|
|
48
|
+
isEnabled?: () => boolean;
|
|
49
|
+
/** Hook overrides while skill is active */
|
|
50
|
+
hooks?: HookConfig;
|
|
51
|
+
/** Execution context: 'inline' runs in current context, 'fork' spawns a subagent */
|
|
52
|
+
context?: 'inline' | 'fork';
|
|
53
|
+
/** Subagent type for forked execution */
|
|
54
|
+
agent?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Generate the prompt content blocks for this skill.
|
|
57
|
+
*
|
|
58
|
+
* @param args - User-provided arguments (e.g., from "/simplify focus on error handling")
|
|
59
|
+
* @param context - Tool execution context (cwd, etc.)
|
|
60
|
+
* @returns Content blocks to inject into the conversation
|
|
61
|
+
*/
|
|
62
|
+
getPrompt: (args: string, context: ToolContext) => Promise<SkillContentBlock[]>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Result of executing a skill.
|
|
66
|
+
*/
|
|
67
|
+
export interface SkillResult {
|
|
68
|
+
/** Whether execution succeeded */
|
|
69
|
+
success: boolean;
|
|
70
|
+
/** Skill name that was executed */
|
|
71
|
+
skillName: string;
|
|
72
|
+
/** Execution status */
|
|
73
|
+
status: 'inline' | 'forked';
|
|
74
|
+
/** Allowed tools override (for inline execution) */
|
|
75
|
+
allowedTools?: string[];
|
|
76
|
+
/** Model override */
|
|
77
|
+
model?: string;
|
|
78
|
+
/** Result text (for forked execution) */
|
|
79
|
+
result?: string;
|
|
80
|
+
/** Error message */
|
|
81
|
+
error?: string;
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/skills/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE7C;;GAEG;AACH,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE;QAAE,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IACzC,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,oBAAoB;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/skills/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tool() helper - Create tools using Zod schemas
|
|
3
|
+
*
|
|
4
|
+
* Compatible with open-agent-sdk's tool() function.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { tool } from 'open-agent-sdk'
|
|
8
|
+
* import { z } from 'zod'
|
|
9
|
+
*
|
|
10
|
+
* const weatherTool = tool(
|
|
11
|
+
* 'get_weather',
|
|
12
|
+
* 'Get weather for a city',
|
|
13
|
+
* { city: z.string().describe('City name') },
|
|
14
|
+
* async ({ city }) => {
|
|
15
|
+
* return { content: [{ type: 'text', text: `Weather in ${city}: 22°C` }] }
|
|
16
|
+
* }
|
|
17
|
+
* )
|
|
18
|
+
*/
|
|
19
|
+
import { z, type ZodRawShape, type ZodObject } from 'zod';
|
|
20
|
+
import type { ToolDefinition } from './types.js';
|
|
21
|
+
/**
|
|
22
|
+
* Tool annotations (MCP standard).
|
|
23
|
+
*/
|
|
24
|
+
export interface ToolAnnotations {
|
|
25
|
+
readOnlyHint?: boolean;
|
|
26
|
+
destructiveHint?: boolean;
|
|
27
|
+
idempotentHint?: boolean;
|
|
28
|
+
openWorldHint?: boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Tool call result (MCP-compatible).
|
|
32
|
+
*/
|
|
33
|
+
export interface CallToolResult {
|
|
34
|
+
content: Array<{
|
|
35
|
+
type: 'text';
|
|
36
|
+
text: string;
|
|
37
|
+
} | {
|
|
38
|
+
type: 'image';
|
|
39
|
+
data: string;
|
|
40
|
+
mimeType: string;
|
|
41
|
+
} | {
|
|
42
|
+
type: 'resource';
|
|
43
|
+
resource: {
|
|
44
|
+
uri: string;
|
|
45
|
+
text?: string;
|
|
46
|
+
blob?: string;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
isError?: boolean;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* SDK MCP tool definition.
|
|
53
|
+
*/
|
|
54
|
+
export interface SdkMcpToolDefinition<T extends ZodRawShape = ZodRawShape> {
|
|
55
|
+
name: string;
|
|
56
|
+
description: string;
|
|
57
|
+
inputSchema: ZodObject<T>;
|
|
58
|
+
handler: (args: z.infer<ZodObject<T>>, extra: unknown) => Promise<CallToolResult>;
|
|
59
|
+
annotations?: ToolAnnotations;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a tool using Zod schema.
|
|
63
|
+
*
|
|
64
|
+
* Compatible with open-agent-sdk's tool() function.
|
|
65
|
+
*/
|
|
66
|
+
export declare function tool<T extends ZodRawShape>(name: string, description: string, inputSchema: T, handler: (args: z.infer<ZodObject<T>>, extra: unknown) => Promise<CallToolResult>, extras?: {
|
|
67
|
+
annotations?: ToolAnnotations;
|
|
68
|
+
}): SdkMcpToolDefinition<T>;
|
|
69
|
+
/**
|
|
70
|
+
* Convert an SdkMcpToolDefinition to a ToolDefinition for the engine.
|
|
71
|
+
*/
|
|
72
|
+
export declare function sdkToolToToolDefinition(sdkTool: SdkMcpToolDefinition<any>): ToolDefinition;
|
|
73
|
+
//# sourceMappingURL=tool-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-helper.d.ts","sourceRoot":"","sources":["../src/tool-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,CAAC,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,MAAM,KAAK,CAAA;AAEzD,OAAO,KAAK,EAAE,cAAc,EAA2B,MAAM,YAAY,CAAA;AAEzE;;GAEG;AACH,MAAM,WAAW,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E,OAAO,KAAK,OAAO,CAAC,cAAc,CAAC,EACjF,MAAM,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,eAAe,CAAA;CAAE,GACzC,oBAAoB,CAAC,CAAC,CAAC,CAQzB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,oBAAoB,CAAC,GAAG,CAAC,GAAG,cAAc,CA8C1F"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* tool() helper - Create tools using Zod schemas
|
|
3
|
+
*
|
|
4
|
+
* Compatible with open-agent-sdk's tool() function.
|
|
5
|
+
*
|
|
6
|
+
* Usage:
|
|
7
|
+
* import { tool } from 'open-agent-sdk'
|
|
8
|
+
* import { z } from 'zod'
|
|
9
|
+
*
|
|
10
|
+
* const weatherTool = tool(
|
|
11
|
+
* 'get_weather',
|
|
12
|
+
* 'Get weather for a city',
|
|
13
|
+
* { city: z.string().describe('City name') },
|
|
14
|
+
* async ({ city }) => {
|
|
15
|
+
* return { content: [{ type: 'text', text: `Weather in ${city}: 22°C` }] }
|
|
16
|
+
* }
|
|
17
|
+
* )
|
|
18
|
+
*/
|
|
19
|
+
import { z } from 'zod';
|
|
20
|
+
import { zodToJsonSchema } from 'zod-to-json-schema';
|
|
21
|
+
/**
|
|
22
|
+
* Create a tool using Zod schema.
|
|
23
|
+
*
|
|
24
|
+
* Compatible with open-agent-sdk's tool() function.
|
|
25
|
+
*/
|
|
26
|
+
export function tool(name, description, inputSchema, handler, extras) {
|
|
27
|
+
return {
|
|
28
|
+
name,
|
|
29
|
+
description,
|
|
30
|
+
inputSchema: z.object(inputSchema),
|
|
31
|
+
handler,
|
|
32
|
+
annotations: extras?.annotations,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Convert an SdkMcpToolDefinition to a ToolDefinition for the engine.
|
|
37
|
+
*/
|
|
38
|
+
export function sdkToolToToolDefinition(sdkTool) {
|
|
39
|
+
const jsonSchema = zodToJsonSchema(sdkTool.inputSchema, { target: 'openApi3' });
|
|
40
|
+
return {
|
|
41
|
+
name: sdkTool.name,
|
|
42
|
+
description: sdkTool.description,
|
|
43
|
+
inputSchema: {
|
|
44
|
+
type: 'object',
|
|
45
|
+
properties: jsonSchema.properties || {},
|
|
46
|
+
required: jsonSchema.required || [],
|
|
47
|
+
},
|
|
48
|
+
isReadOnly: () => sdkTool.annotations?.readOnlyHint ?? false,
|
|
49
|
+
isConcurrencySafe: () => sdkTool.annotations?.readOnlyHint ?? false,
|
|
50
|
+
isEnabled: () => true,
|
|
51
|
+
async prompt() { return sdkTool.description; },
|
|
52
|
+
async call(input, _context) {
|
|
53
|
+
try {
|
|
54
|
+
const parsed = sdkTool.inputSchema.parse(input);
|
|
55
|
+
const result = await sdkTool.handler(parsed, {});
|
|
56
|
+
// Convert MCP content blocks to string
|
|
57
|
+
const text = result.content
|
|
58
|
+
.map((block) => {
|
|
59
|
+
if (block.type === 'text')
|
|
60
|
+
return block.text;
|
|
61
|
+
if (block.type === 'image')
|
|
62
|
+
return `[Image: ${block.mimeType}]`;
|
|
63
|
+
if (block.type === 'resource')
|
|
64
|
+
return block.resource.text || `[Resource: ${block.resource.uri}]`;
|
|
65
|
+
return JSON.stringify(block);
|
|
66
|
+
})
|
|
67
|
+
.join('\n');
|
|
68
|
+
return {
|
|
69
|
+
type: 'tool_result',
|
|
70
|
+
tool_use_id: '',
|
|
71
|
+
content: text,
|
|
72
|
+
is_error: result.isError || false,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
return {
|
|
77
|
+
type: 'tool_result',
|
|
78
|
+
tool_use_id: '',
|
|
79
|
+
content: `Error: ${err.message}`,
|
|
80
|
+
is_error: true,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=tool-helper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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AC,KAAK,CAAC,KAAK,CAAC,CAAA;gBAC/C,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAA;gBAEhD,uCAAuC;gBACvC,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO;qBACxB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;oBACb,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;wBAAE,OAAO,KAAK,CAAC,IAAI,CAAA;oBAC5C,IAAI,KAAK,CAAC,IAAI,KAAK,OAAO;wBAAE,OAAO,WAAW,KAAK,CAAC,QAAQ,GAAG,CAAA;oBAC/D,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU;wBAAE,OAAO,KAAK,CAAC,QAAQ,CAAC,IAAI,IAAI,cAAc,KAAK,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAA;oBAChG,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;gBAC9B,CAAC,CAAC;qBACD,IAAI,CAAC,IAAI,CAAC,CAAA;gBAEb,OAAO;oBACL,IAAI,EAAE,aAAa;oBACnB,WAAW,EAAE,EAAE;oBACf,OAAO,EAAE,IAAI;oBACb,QAAQ,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK;iBAClC,CAAA;YACH,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,OAAO;oBACL,IAAI,EAAE,aAAa;oBACnB,WAAW,EAAE,EAAE;oBACf,OAAO,EAAE,UAAU,GAAG,CAAC,OAAO,EAAE;oBAChC,QAAQ,EAAE,IAAI;iBACf,CAAA;YACH,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentTool - Spawn subagents for parallel/delegated work
|
|
3
|
+
*
|
|
4
|
+
* Supports built-in agents (Explore, Plan) and custom agent definitions.
|
|
5
|
+
* Agents run as nested query loops with their own context and tool sets.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolDefinition, AgentDefinition } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Register agent definitions for the AgentTool to use.
|
|
10
|
+
*/
|
|
11
|
+
export declare function registerAgents(agents: Record<string, AgentDefinition>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Clear registered agents.
|
|
14
|
+
*/
|
|
15
|
+
export declare function clearAgents(): void;
|
|
16
|
+
export declare const AgentTool: ToolDefinition;
|
|
17
|
+
//# sourceMappingURL=agent-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tool.d.ts","sourceRoot":"","sources":["../../src/tools/agent-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAA2B,eAAe,EAAE,MAAM,aAAa,CAAA;AAQ3F;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GAAG,IAAI,CAE5E;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,IAAI,CAElC;AAkBD,eAAO,MAAM,SAAS,EAAE,cAsHvB,CAAA"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentTool - Spawn subagents for parallel/delegated work
|
|
3
|
+
*
|
|
4
|
+
* Supports built-in agents (Explore, Plan) and custom agent definitions.
|
|
5
|
+
* Agents run as nested query loops with their own context and tool sets.
|
|
6
|
+
*/
|
|
7
|
+
import { QueryEngine } from '../engine.js';
|
|
8
|
+
import { getAllBaseTools, filterTools } from './index.js';
|
|
9
|
+
import { createProvider } from '../providers/index.js';
|
|
10
|
+
// Store for registered agent definitions
|
|
11
|
+
let registeredAgents = {};
|
|
12
|
+
/**
|
|
13
|
+
* Register agent definitions for the AgentTool to use.
|
|
14
|
+
*/
|
|
15
|
+
export function registerAgents(agents) {
|
|
16
|
+
registeredAgents = { ...registeredAgents, ...agents };
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Clear registered agents.
|
|
20
|
+
*/
|
|
21
|
+
export function clearAgents() {
|
|
22
|
+
registeredAgents = {};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Built-in agent definitions.
|
|
26
|
+
*/
|
|
27
|
+
const BUILTIN_AGENTS = {
|
|
28
|
+
Explore: {
|
|
29
|
+
description: 'Fast agent for exploring codebases. Use for finding files, searching code, and answering questions about the codebase.',
|
|
30
|
+
prompt: 'You are a codebase exploration agent. Search through files and code to answer questions. Be thorough but efficient. Use Glob to find files, Grep to search content, and Read to examine files.',
|
|
31
|
+
tools: ['Read', 'Glob', 'Grep', 'Bash'],
|
|
32
|
+
},
|
|
33
|
+
Plan: {
|
|
34
|
+
description: 'Software architect agent for designing implementation plans. Returns step-by-step plans and identifies critical files.',
|
|
35
|
+
prompt: 'You are a software architect. Design implementation plans for the given task. Identify critical files, consider trade-offs, and provide step-by-step plans. Use search tools to understand the codebase before planning.',
|
|
36
|
+
tools: ['Read', 'Glob', 'Grep', 'Bash'],
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
export const AgentTool = {
|
|
40
|
+
name: 'Agent',
|
|
41
|
+
description: 'Launch a subagent to handle complex, multi-step tasks autonomously. Subagents have their own context and can run specialized tool sets.',
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
prompt: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
description: 'The task for the agent to perform',
|
|
48
|
+
},
|
|
49
|
+
description: {
|
|
50
|
+
type: 'string',
|
|
51
|
+
description: 'A short (3-5 word) description of the task',
|
|
52
|
+
},
|
|
53
|
+
subagent_type: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
description: 'The type of agent to use (e.g., "Explore", "Plan", or a custom agent name)',
|
|
56
|
+
},
|
|
57
|
+
model: {
|
|
58
|
+
type: 'string',
|
|
59
|
+
description: 'Optional model override for this agent',
|
|
60
|
+
},
|
|
61
|
+
name: {
|
|
62
|
+
type: 'string',
|
|
63
|
+
description: 'Name for the spawned agent',
|
|
64
|
+
},
|
|
65
|
+
run_in_background: {
|
|
66
|
+
type: 'boolean',
|
|
67
|
+
description: 'Whether to run in background',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ['prompt', 'description'],
|
|
71
|
+
},
|
|
72
|
+
isReadOnly: () => false,
|
|
73
|
+
isConcurrencySafe: () => false,
|
|
74
|
+
isEnabled: () => true,
|
|
75
|
+
async prompt() {
|
|
76
|
+
return 'Launch a subagent to handle complex tasks autonomously.';
|
|
77
|
+
},
|
|
78
|
+
async call(input, context) {
|
|
79
|
+
const agentType = input.subagent_type || 'general-purpose';
|
|
80
|
+
// Find agent definition
|
|
81
|
+
const agentDef = registeredAgents[agentType] || BUILTIN_AGENTS[agentType];
|
|
82
|
+
// Determine tools for subagent
|
|
83
|
+
let tools = getAllBaseTools();
|
|
84
|
+
if (agentDef?.tools) {
|
|
85
|
+
tools = filterTools(tools, agentDef.tools);
|
|
86
|
+
}
|
|
87
|
+
// Remove AgentTool from subagent to prevent infinite recursion
|
|
88
|
+
tools = tools.filter(t => t.name !== 'Agent');
|
|
89
|
+
// Build system prompt
|
|
90
|
+
const systemPrompt = agentDef?.prompt ||
|
|
91
|
+
'You are a helpful assistant. Complete the given task using the available tools.';
|
|
92
|
+
// Inherit provider and model from parent agent context, fall back to env vars
|
|
93
|
+
const subModel = input.model || context.model || process.env.CODEANY_MODEL || 'claude-sonnet-4-6';
|
|
94
|
+
const provider = context.provider ?? createProvider((context.apiType || process.env.CODEANY_API_TYPE) || 'anthropic-messages', {
|
|
95
|
+
apiKey: process.env.CODEANY_API_KEY,
|
|
96
|
+
baseURL: process.env.CODEANY_BASE_URL,
|
|
97
|
+
});
|
|
98
|
+
// Create subagent engine
|
|
99
|
+
const engine = new QueryEngine({
|
|
100
|
+
cwd: context.cwd,
|
|
101
|
+
model: subModel,
|
|
102
|
+
provider,
|
|
103
|
+
tools,
|
|
104
|
+
systemPrompt,
|
|
105
|
+
maxTurns: agentDef?.maxTurns || 10,
|
|
106
|
+
maxTokens: 16384,
|
|
107
|
+
canUseTool: async () => ({ behavior: 'allow' }),
|
|
108
|
+
includePartialMessages: false,
|
|
109
|
+
});
|
|
110
|
+
// Run the subagent
|
|
111
|
+
let resultText = '';
|
|
112
|
+
let toolCalls = [];
|
|
113
|
+
try {
|
|
114
|
+
for await (const event of engine.submitMessage(input.prompt)) {
|
|
115
|
+
if (event.type === 'assistant') {
|
|
116
|
+
for (const block of event.message.content) {
|
|
117
|
+
if ('text' in block && block.text) {
|
|
118
|
+
resultText = block.text;
|
|
119
|
+
}
|
|
120
|
+
if ('name' in block) {
|
|
121
|
+
toolCalls.push(block.name);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (err) {
|
|
128
|
+
return {
|
|
129
|
+
type: 'tool_result',
|
|
130
|
+
tool_use_id: '',
|
|
131
|
+
content: `Subagent error: ${err.message}`,
|
|
132
|
+
is_error: true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
const output = resultText || '(Subagent completed with no text output)';
|
|
136
|
+
const toolSummary = toolCalls.length > 0
|
|
137
|
+
? `\n[Tools used: ${toolCalls.join(', ')}]`
|
|
138
|
+
: '';
|
|
139
|
+
return {
|
|
140
|
+
type: 'tool_result',
|
|
141
|
+
tool_use_id: '',
|
|
142
|
+
content: output + toolSummary,
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=agent-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agent-tool.js","sourceRoot":"","sources":["../../src/tools/agent-tool.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,Y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f,CAAA;QACH,CAAC;QAED,MAAM,MAAM,GAAG,UAAU,IAAI,0CAA0C,CAAA;QACvE,MAAM,WAAW,GAAG,SAAS,CAAC,MAAM,GAAG,CAAC;YACtC,CAAC,CAAC,kBAAkB,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC3C,CAAC,CAAC,EAAE,CAAA;QAEN,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,EAAE;YACf,OAAO,EAAE,MAAM,GAAG,WAAW;SAC9B,CAAA;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AskUserQuestionTool - Interactive user questions
|
|
3
|
+
*
|
|
4
|
+
* In SDK mode, returns a permission_request event and waits
|
|
5
|
+
* for the consumer to provide an answer.
|
|
6
|
+
* In non-interactive mode, returns a default or denies.
|
|
7
|
+
*/
|
|
8
|
+
import type { ToolDefinition } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Set the question handler for AskUserQuestion.
|
|
11
|
+
*/
|
|
12
|
+
export declare function setQuestionHandler(handler: (question: string, options?: string[]) => Promise<string>): void;
|
|
13
|
+
/**
|
|
14
|
+
* Clear the question handler.
|
|
15
|
+
*/
|
|
16
|
+
export declare function clearQuestionHandler(): void;
|
|
17
|
+
export declare const AskUserQuestionTool: ToolDefinition;
|
|
18
|
+
//# sourceMappingURL=ask-user.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-user.d.ts","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,aAAa,CAAA;AAK7D;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,MAAM,CAAC,GACjE,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAE3C;AAED,eAAO,MAAM,mBAAmB,EAAE,cAiDjC,CAAA"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AskUserQuestionTool - Interactive user questions
|
|
3
|
+
*
|
|
4
|
+
* In SDK mode, returns a permission_request event and waits
|
|
5
|
+
* for the consumer to provide an answer.
|
|
6
|
+
* In non-interactive mode, returns a default or denies.
|
|
7
|
+
*/
|
|
8
|
+
// Callback for handling user questions (set by the agent)
|
|
9
|
+
let questionHandler = null;
|
|
10
|
+
/**
|
|
11
|
+
* Set the question handler for AskUserQuestion.
|
|
12
|
+
*/
|
|
13
|
+
export function setQuestionHandler(handler) {
|
|
14
|
+
questionHandler = handler;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Clear the question handler.
|
|
18
|
+
*/
|
|
19
|
+
export function clearQuestionHandler() {
|
|
20
|
+
questionHandler = null;
|
|
21
|
+
}
|
|
22
|
+
export const AskUserQuestionTool = {
|
|
23
|
+
name: 'AskUserQuestion',
|
|
24
|
+
description: 'Ask the user a question and wait for their response. Use when you need clarification or input from the user.',
|
|
25
|
+
inputSchema: {
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
question: { type: 'string', description: 'The question to ask the user' },
|
|
29
|
+
options: {
|
|
30
|
+
type: 'array',
|
|
31
|
+
items: { type: 'string' },
|
|
32
|
+
description: 'Optional list of choices for the user',
|
|
33
|
+
},
|
|
34
|
+
allow_multiselect: {
|
|
35
|
+
type: 'boolean',
|
|
36
|
+
description: 'Whether to allow multiple selections (for options)',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
required: ['question'],
|
|
40
|
+
},
|
|
41
|
+
isReadOnly: () => true,
|
|
42
|
+
isConcurrencySafe: () => false,
|
|
43
|
+
isEnabled: () => true,
|
|
44
|
+
async prompt() { return 'Ask the user a question.'; },
|
|
45
|
+
async call(input) {
|
|
46
|
+
if (questionHandler) {
|
|
47
|
+
try {
|
|
48
|
+
const answer = await questionHandler(input.question, input.options);
|
|
49
|
+
return {
|
|
50
|
+
type: 'tool_result',
|
|
51
|
+
tool_use_id: '',
|
|
52
|
+
content: answer,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return {
|
|
57
|
+
type: 'tool_result',
|
|
58
|
+
tool_use_id: '',
|
|
59
|
+
content: `User declined to answer: ${err.message}`,
|
|
60
|
+
is_error: true,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Non-interactive: return informative message
|
|
65
|
+
return {
|
|
66
|
+
type: 'tool_result',
|
|
67
|
+
tool_use_id: '',
|
|
68
|
+
content: `[Non-interactive mode] Question: ${input.question}${input.options ? `\nOptions: ${input.options.join(', ')}` : ''}\n\nNo user available to answer. Proceeding with best judgment.`,
|
|
69
|
+
};
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=ask-user.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ask-user.js","sourceRoot":"","sources":["../../src/tools/ask-user.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,0DAA0D;AAC1D,IAAI,eAAe,GAAuE,IAAI,CAAA;AAE9F;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAChC,OAAkE;IAElE,eAAe,GAAG,OAAO,CAAA;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB;IAClC,eAAe,GAAG,IAAI,CAAA;AACxB,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAmB;IACjD,IAAI,EAAE,iBAAiB;IACvB,WAAW,EAAE,8GAA8G;IAC3H,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,8BAA8B,EAAE;YACz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