@claudebuddy/claudebuddy-agent-sdk 0.4.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 +501 -0
- package/dist/agent.d.ts +137 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +573 -0
- package/dist/agent.js.map +1 -0
- package/dist/engine.d.ts +70 -0
- package/dist/engine.d.ts.map +1 -0
- package/dist/engine.js +552 -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 +70 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +141 -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 +243 -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/dist/skills/bundled/debug.js +46 -0
- 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/dist/skills/bundled/review.js +38 -0
- 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/dist/skills/bundled/simplify.js +48 -0
- 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/dist/skills/bundled/test.js +40 -0
- 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 +150 -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/update-goal.d.ts +38 -0
- package/dist/tools/update-goal.d.ts.map +1 -0
- package/dist/tools/update-goal.js +109 -0
- package/dist/tools/update-goal.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 +485 -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/spill.d.ts +100 -0
- package/dist/utils/spill.d.ts.map +1 -0
- package/dist/utils/spill.js +126 -0
- package/dist/utils/spill.js.map +1 -0
- package/dist/utils/tokens.d.ts +60 -0
- package/dist/utils/tokens.d.ts.map +1 -0
- package/dist/utils/tokens.js +140 -0
- package/dist/utils/tokens.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"team-tools.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,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,mBAAmB,KAAK,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;QACzG,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,WAAW,CAAA;QACzB,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAE1B,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,EAAE;YACf,OAAO,EAAE,mBAAmB,IAAI,CAAC,IAAI,EAAE;SACxC,CAAA;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TodoWriteTool - Session todo/checklist management
|
|
3
|
+
*
|
|
4
|
+
* Manages a session-scoped todo list for tracking work items.
|
|
5
|
+
*/
|
|
6
|
+
import type { ToolDefinition } from '../types.js';
|
|
7
|
+
export interface TodoItem {
|
|
8
|
+
id: number;
|
|
9
|
+
text: string;
|
|
10
|
+
done: boolean;
|
|
11
|
+
priority?: 'high' | 'medium' | 'low';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Get all todos.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getTodos(): TodoItem[];
|
|
17
|
+
/**
|
|
18
|
+
* Clear all todos.
|
|
19
|
+
*/
|
|
20
|
+
export declare function clearTodos(): void;
|
|
21
|
+
export declare const TodoWriteTool: ToolDefinition;
|
|
22
|
+
//# sourceMappingURL=todo-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo-tool.d.ts","sourceRoot":"","sources":["../../src/tools/todo-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,aAAa,CAAA;AAE7D,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,CAAA;IACb,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAA;CACrC;AAKD;;GAEG;AACH,wBAAgB,QAAQ,IAAI,QAAQ,EAAE,CAErC;AAED;;GAEG;AACH,wBAAgB,UAAU,IAAI,IAAI,CAGjC;AAED,eAAO,MAAM,aAAa,EAAE,cA8E3B,CAAA"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TodoWriteTool - Session todo/checklist management
|
|
3
|
+
*
|
|
4
|
+
* Manages a session-scoped todo list for tracking work items.
|
|
5
|
+
*/
|
|
6
|
+
const todoList = [];
|
|
7
|
+
let todoCounter = 0;
|
|
8
|
+
/**
|
|
9
|
+
* Get all todos.
|
|
10
|
+
*/
|
|
11
|
+
export function getTodos() {
|
|
12
|
+
return [...todoList];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Clear all todos.
|
|
16
|
+
*/
|
|
17
|
+
export function clearTodos() {
|
|
18
|
+
todoList.length = 0;
|
|
19
|
+
todoCounter = 0;
|
|
20
|
+
}
|
|
21
|
+
export const TodoWriteTool = {
|
|
22
|
+
name: 'TodoWrite',
|
|
23
|
+
description: 'Manage a session todo/checklist. Supports add, toggle, remove, and list operations.',
|
|
24
|
+
inputSchema: {
|
|
25
|
+
type: 'object',
|
|
26
|
+
properties: {
|
|
27
|
+
action: {
|
|
28
|
+
type: 'string',
|
|
29
|
+
enum: ['add', 'toggle', 'remove', 'list', 'clear'],
|
|
30
|
+
description: 'Operation to perform',
|
|
31
|
+
},
|
|
32
|
+
text: { type: 'string', description: 'Todo item text (for add)' },
|
|
33
|
+
id: { type: 'number', description: 'Todo item ID (for toggle/remove)' },
|
|
34
|
+
priority: {
|
|
35
|
+
type: 'string',
|
|
36
|
+
enum: ['high', 'medium', 'low'],
|
|
37
|
+
description: 'Priority level (for add)',
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
required: ['action'],
|
|
41
|
+
},
|
|
42
|
+
isReadOnly: () => false,
|
|
43
|
+
isConcurrencySafe: () => true,
|
|
44
|
+
isEnabled: () => true,
|
|
45
|
+
async prompt() { return 'Manage session todo list.'; },
|
|
46
|
+
async call(input) {
|
|
47
|
+
switch (input.action) {
|
|
48
|
+
case 'add': {
|
|
49
|
+
if (!input.text) {
|
|
50
|
+
return { type: 'tool_result', tool_use_id: '', content: 'text required', is_error: true };
|
|
51
|
+
}
|
|
52
|
+
const item = {
|
|
53
|
+
id: ++todoCounter,
|
|
54
|
+
text: input.text,
|
|
55
|
+
done: false,
|
|
56
|
+
priority: input.priority,
|
|
57
|
+
};
|
|
58
|
+
todoList.push(item);
|
|
59
|
+
return { type: 'tool_result', tool_use_id: '', content: `Todo added: #${item.id} "${item.text}"` };
|
|
60
|
+
}
|
|
61
|
+
case 'toggle': {
|
|
62
|
+
const item = todoList.find(t => t.id === input.id);
|
|
63
|
+
if (!item) {
|
|
64
|
+
return { type: 'tool_result', tool_use_id: '', content: `Todo #${input.id} not found`, is_error: true };
|
|
65
|
+
}
|
|
66
|
+
item.done = !item.done;
|
|
67
|
+
return { type: 'tool_result', tool_use_id: '', content: `Todo #${item.id} ${item.done ? 'completed' : 'reopened'}` };
|
|
68
|
+
}
|
|
69
|
+
case 'remove': {
|
|
70
|
+
const idx = todoList.findIndex(t => t.id === input.id);
|
|
71
|
+
if (idx === -1) {
|
|
72
|
+
return { type: 'tool_result', tool_use_id: '', content: `Todo #${input.id} not found`, is_error: true };
|
|
73
|
+
}
|
|
74
|
+
todoList.splice(idx, 1);
|
|
75
|
+
return { type: 'tool_result', tool_use_id: '', content: `Todo #${input.id} removed` };
|
|
76
|
+
}
|
|
77
|
+
case 'list': {
|
|
78
|
+
if (todoList.length === 0) {
|
|
79
|
+
return { type: 'tool_result', tool_use_id: '', content: 'No todos.' };
|
|
80
|
+
}
|
|
81
|
+
const lines = todoList.map(t => `${t.done ? '[x]' : '[ ]'} #${t.id} ${t.text}${t.priority ? ` (${t.priority})` : ''}`);
|
|
82
|
+
return { type: 'tool_result', tool_use_id: '', content: lines.join('\n') };
|
|
83
|
+
}
|
|
84
|
+
case 'clear': {
|
|
85
|
+
todoList.length = 0;
|
|
86
|
+
return { type: 'tool_result', tool_use_id: '', content: 'All todos cleared.' };
|
|
87
|
+
}
|
|
88
|
+
default:
|
|
89
|
+
return { type: 'tool_result', tool_use_id: '', content: `Unknown action: ${input.action}`, is_error: true };
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
//# sourceMappingURL=todo-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"todo-tool.js","sourceRoot":"","sources":["../../src/tools/todo-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH,MAAM,QAAQ,GAAe,EAAE,CAAA;AAC/B,IAAI,WAAW,GAAG,CAAC,CAAA;AAEnB;;GAEG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAA;AACtB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU;IACxB,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAA;IACnB,WAAW,GAAG,CAAC,CAAA;AACjB,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAmB;IAC3C,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,qFAAqF;IAClG,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE;gBACN,IAAI,EAAE,QAAQ;gBACd,IAAI,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC;gBAClD,WAAW,EAAE,sBAAsB;aACpC;YACD,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,0BAA0B,EAAE;YACjE,EAAE,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kCAAkC,EAAE;Y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M,KAAK,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAC7B,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CACtF,CAAA;gBACD,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAA;YAC5E,CAAC;YAED,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAA;gBACnB,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE,CAAA;YAChF,CAAC;YAED;gBACE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,EAAE,EAAE,OAAO,EAAE,mBAAmB,KAAK,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;QAC/G,CAAC;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolSearchTool - Discover deferred/lazy-loaded tools
|
|
3
|
+
*
|
|
4
|
+
* Allows the model to search for tools that haven't been loaded yet.
|
|
5
|
+
* Supports keyword search and exact name selection.
|
|
6
|
+
*/
|
|
7
|
+
import type { ToolDefinition } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Set deferred tools available for search.
|
|
10
|
+
*/
|
|
11
|
+
export declare function setDeferredTools(tools: ToolDefinition[]): void;
|
|
12
|
+
export declare const ToolSearchTool: ToolDefinition;
|
|
13
|
+
//# sourceMappingURL=tool-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-search.d.ts","sourceRoot":"","sources":["../../src/tools/tool-search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,aAAa,CAAA;AAK7D;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,IAAI,CAE9D;AAED,eAAO,MAAM,cAAc,EAAE,cAmE5B,CAAA"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ToolSearchTool - Discover deferred/lazy-loaded tools
|
|
3
|
+
*
|
|
4
|
+
* Allows the model to search for tools that haven't been loaded yet.
|
|
5
|
+
* Supports keyword search and exact name selection.
|
|
6
|
+
*/
|
|
7
|
+
// Registry of deferred tools (set by the agent)
|
|
8
|
+
let deferredTools = [];
|
|
9
|
+
/**
|
|
10
|
+
* Set deferred tools available for search.
|
|
11
|
+
*/
|
|
12
|
+
export function setDeferredTools(tools) {
|
|
13
|
+
deferredTools = tools;
|
|
14
|
+
}
|
|
15
|
+
export const ToolSearchTool = {
|
|
16
|
+
name: 'ToolSearch',
|
|
17
|
+
description: 'Search for additional tools that may be available but not yet loaded. Use keyword search or exact name selection.',
|
|
18
|
+
inputSchema: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: {
|
|
21
|
+
query: {
|
|
22
|
+
type: 'string',
|
|
23
|
+
description: 'Search query. Use "select:ToolName" for exact match or keywords for search.',
|
|
24
|
+
},
|
|
25
|
+
max_results: {
|
|
26
|
+
type: 'number',
|
|
27
|
+
description: 'Maximum results to return (default: 5)',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
required: ['query'],
|
|
31
|
+
},
|
|
32
|
+
isReadOnly: () => true,
|
|
33
|
+
isConcurrencySafe: () => true,
|
|
34
|
+
isEnabled: () => true,
|
|
35
|
+
async prompt() { return 'Search for available tools.'; },
|
|
36
|
+
async call(input) {
|
|
37
|
+
const { query, max_results = 5 } = input;
|
|
38
|
+
if (deferredTools.length === 0) {
|
|
39
|
+
return {
|
|
40
|
+
type: 'tool_result',
|
|
41
|
+
tool_use_id: '',
|
|
42
|
+
content: 'No deferred tools available.',
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
let matches;
|
|
46
|
+
if (query.startsWith('select:')) {
|
|
47
|
+
// Exact name selection
|
|
48
|
+
const names = query.slice(7).split(',').map((n) => n.trim());
|
|
49
|
+
matches = deferredTools.filter(t => names.includes(t.name));
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
// Keyword search
|
|
53
|
+
const keywords = query.toLowerCase().split(/\s+/);
|
|
54
|
+
matches = deferredTools
|
|
55
|
+
.filter(t => {
|
|
56
|
+
const searchText = `${t.name} ${t.description}`.toLowerCase();
|
|
57
|
+
return keywords.some((kw) => searchText.includes(kw));
|
|
58
|
+
})
|
|
59
|
+
.slice(0, max_results);
|
|
60
|
+
}
|
|
61
|
+
if (matches.length === 0) {
|
|
62
|
+
return {
|
|
63
|
+
type: 'tool_result',
|
|
64
|
+
tool_use_id: '',
|
|
65
|
+
content: `No tools found matching "${query}"`,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
const lines = matches.map(t => `- ${t.name}: ${t.description.slice(0, 200)}`);
|
|
69
|
+
return {
|
|
70
|
+
type: 'tool_result',
|
|
71
|
+
tool_use_id: '',
|
|
72
|
+
content: `Found ${matches.length} tool(s):\n${lines.join('\n')}`,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
//# sourceMappingURL=tool-search.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-search.js","sourceRoot":"","sources":["../../src/tools/tool-search.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,gDAAgD;AAChD,IAAI,aAAa,GAAqB,EAAE,CAAA;AAExC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAuB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AAI,CAAC,CAAC,CAAA;QAC7D,CAAC;aAAM,CAAC;YACN,iBAAiB;YACjB,MAAM,QAAQ,GAAa,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;YAC3D,OAAO,GAAG,aAAa;iBACpB,MAAM,CAAC,CAAC,CAAC,EAAE;gBACV,MAAM,UAAU,GAAG,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,WAAW,EAAE,CAAA;gBAC7D,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAU,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;YAC/D,CAAC,CAAC;iBACD,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAA;QAC1B,CAAC;QAED,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACzB,OAAO;gBACL,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE,EAAE;gBACf,OAAO,EAAE,4BAA4B,KAAK,GAAG;aAC9C,CAAA;QACH,CAAC;QAED,MAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAC5B,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAC9C,CAAA;QAED,OAAO;YACL,IAAI,EAAE,aAAa;YACnB,WAAW,EAAE,EAAE;YACf,OAAO,EAAE,SAAS,OAAO,CAAC,MAAM,cAAc,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;SACjE,CAAA;IACH,CAAC;CACF,CAAA"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool interface and helper utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { ToolDefinition, ToolInputSchema, ToolContext } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Helper to create a tool definition with sensible defaults.
|
|
7
|
+
*/
|
|
8
|
+
export declare function defineTool(config: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
inputSchema: ToolInputSchema;
|
|
12
|
+
call: (input: any, context: ToolContext) => Promise<string | {
|
|
13
|
+
data: string;
|
|
14
|
+
is_error?: boolean;
|
|
15
|
+
}>;
|
|
16
|
+
isReadOnly?: boolean;
|
|
17
|
+
isConcurrencySafe?: boolean;
|
|
18
|
+
prompt?: string | ((context: ToolContext) => Promise<string>);
|
|
19
|
+
}): ToolDefinition;
|
|
20
|
+
/**
|
|
21
|
+
* Convert a ToolDefinition to API-compatible tool format.
|
|
22
|
+
* Returns the normalized tool format used by providers.
|
|
23
|
+
*/
|
|
24
|
+
export declare function toApiTool(tool: ToolDefinition): {
|
|
25
|
+
name: string;
|
|
26
|
+
description: string;
|
|
27
|
+
input_schema: ToolInputSchema;
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,WAAW,EAAc,MAAM,aAAa,CAAA;AAE3F;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE;IACjC,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,WAAW,EAAE,eAAe,CAAA;IAC5B,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC,CAAA;IAClG,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,iBAAiB,CAAC,EAAE,OAAO,CAAA;IAC3B,MAAM,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC,CAAA;CAC9D,GAAG,cAAc,CAgCjB;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,cAAc,GAAG;IAC/C,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE,eAAe,CAAA;CAC9B,CAMA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tool interface and helper utilities
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Helper to create a tool definition with sensible defaults.
|
|
6
|
+
*/
|
|
7
|
+
export function defineTool(config) {
|
|
8
|
+
return {
|
|
9
|
+
name: config.name,
|
|
10
|
+
description: config.description,
|
|
11
|
+
inputSchema: config.inputSchema,
|
|
12
|
+
isReadOnly: () => config.isReadOnly ?? false,
|
|
13
|
+
isConcurrencySafe: () => config.isConcurrencySafe ?? false,
|
|
14
|
+
isEnabled: () => true,
|
|
15
|
+
prompt: typeof config.prompt === 'function'
|
|
16
|
+
? config.prompt
|
|
17
|
+
: async (_context) => config.prompt ?? config.description,
|
|
18
|
+
async call(input, context) {
|
|
19
|
+
try {
|
|
20
|
+
const result = await config.call(input, context);
|
|
21
|
+
const output = typeof result === 'string' ? result : result.data;
|
|
22
|
+
const isError = typeof result === 'object' && result.is_error;
|
|
23
|
+
return {
|
|
24
|
+
type: 'tool_result',
|
|
25
|
+
tool_use_id: '', // filled by engine
|
|
26
|
+
content: output,
|
|
27
|
+
is_error: isError || false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
return {
|
|
32
|
+
type: 'tool_result',
|
|
33
|
+
tool_use_id: '',
|
|
34
|
+
content: `Error: ${err.message}`,
|
|
35
|
+
is_error: true,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Convert a ToolDefinition to API-compatible tool format.
|
|
43
|
+
* Returns the normalized tool format used by providers.
|
|
44
|
+
*/
|
|
45
|
+
export function toApiTool(tool) {
|
|
46
|
+
return {
|
|
47
|
+
name: tool.name,
|
|
48
|
+
description: tool.description,
|
|
49
|
+
input_schema: tool.inputSchema,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,MAQ1B;IACC,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,WAAW,EAAE,MAAM,CAAC,WAAW;QAC/B,UAAU,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,IAAI,KAAK;QAC5C,iBAAiB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,iBAAiB,IAAI,KAAK;QAC1D,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;QACrB,MAAM,EAAE,OAAO,MAAM,CAAC,MAAM,KAAK,UAAU;YACzC,CAAC,CAAC,MAAM,CAAC,MAAM;YACf,CAAC,CAAC,KAAK,EAAE,QAAqB,EAAE,EAAE,CAAE,MAAM,CAAC,MAAiB,IAAI,MAAM,CAAC,WAAW;QACpF,KAAK,CAAC,IAAI,CAAC,KAAU,EAAE,OAAoB;YACzC,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;gBAChD,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAA;gBAChE,MAAM,OAAO,GAAG,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAA;gBAC7D,OAAO;oBACL,IAAI,EAAE,aAAa;oBACnB,WAAW,EAAE,EAAE,EAAE,mBAAmB;oBACpC,OAAO,EAAE,MAAM;oBACf,QAAQ,EAAE,OAAO,IAAI,KAAK;iBAC3B,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;AAED;;;GAGG;AACH,MAAM,UAAU,SAAS,CAAC,IAAoB;IAK5C,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,YAAY,EAAE,IAAI,CAAC,WAAW;KAC/B,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* update_goal — internal tool for the goal-driven loop
|
|
3
|
+
*
|
|
4
|
+
* The model calls this tool to report whether the goal is complete, blocked,
|
|
5
|
+
* or still in progress. It does NOT perform any real action; it only records
|
|
6
|
+
* the reported status so the goal driver in agent.ts can decide whether to
|
|
7
|
+
* keep running another round.
|
|
8
|
+
*
|
|
9
|
+
* Because the engine faithfully executes tools and feeds the tool_result back
|
|
10
|
+
* to the model, calling this tool both (a) gives the model a structured way to
|
|
11
|
+
* declare task state, and (b) lets the driver read that state from the shared
|
|
12
|
+
* module-level record below.
|
|
13
|
+
*/
|
|
14
|
+
import type { ToolDefinition } from '../types.js';
|
|
15
|
+
/** Reported goal status by the latest update_goal call. */
|
|
16
|
+
export interface GoalReport {
|
|
17
|
+
status: 'complete' | 'blocked' | 'in_progress';
|
|
18
|
+
summary?: string;
|
|
19
|
+
/** Increments on every report so callers can detect "no new report". */
|
|
20
|
+
revision: number;
|
|
21
|
+
}
|
|
22
|
+
/** Reset the goal record (call at the start of a runGoal). */
|
|
23
|
+
export declare function resetGoalState(revision?: number): void;
|
|
24
|
+
/** Read the latest reported goal state without consuming it. */
|
|
25
|
+
export declare function getGoalState(): Readonly<GoalReport>;
|
|
26
|
+
/** Whether a report with this revision has been recorded (i.e. model spoke). */
|
|
27
|
+
export declare function hasGoalReport(revision: number): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The internal update_goal tool definition.
|
|
30
|
+
* Schema: { goal_status, summary?, error? }
|
|
31
|
+
*/
|
|
32
|
+
export declare function createUpdateGoalTool(): ToolDefinition;
|
|
33
|
+
/**
|
|
34
|
+
* Build the system-prompt appendix that instructs the model to work toward a
|
|
35
|
+
* goal and to call update_goal when finished or blocked.
|
|
36
|
+
*/
|
|
37
|
+
export declare function buildGoalSystemPrompt(goal: string, maxRounds: number): string;
|
|
38
|
+
//# sourceMappingURL=update-goal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-goal.d.ts","sourceRoot":"","sources":["../../src/tools/update-goal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,2DAA2D;AAC3D,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,UAAU,GAAG,SAAS,GAAG,aAAa,CAAA;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAA;CACjB;AASD,8DAA8D;AAC9D,wBAAgB,cAAc,CAAC,QAAQ,SAAI,GAAG,IAAI,CAIjD;AAED,gEAAgE;AAChE,wBAAgB,YAAY,IAAI,QAAQ,CAAC,UAAU,CAAC,CAEnD;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAEvD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAmDrD;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CAgB7E"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* update_goal — internal tool for the goal-driven loop
|
|
3
|
+
*
|
|
4
|
+
* The model calls this tool to report whether the goal is complete, blocked,
|
|
5
|
+
* or still in progress. It does NOT perform any real action; it only records
|
|
6
|
+
* the reported status so the goal driver in agent.ts can decide whether to
|
|
7
|
+
* keep running another round.
|
|
8
|
+
*
|
|
9
|
+
* Because the engine faithfully executes tools and feeds the tool_result back
|
|
10
|
+
* to the model, calling this tool both (a) gives the model a structured way to
|
|
11
|
+
* declare task state, and (b) lets the driver read that state from the shared
|
|
12
|
+
* module-level record below.
|
|
13
|
+
*/
|
|
14
|
+
/** Module-level recorded goal state shared with the driver. */
|
|
15
|
+
const goalState = {
|
|
16
|
+
status: 'in_progress',
|
|
17
|
+
summary: undefined,
|
|
18
|
+
revision: 0,
|
|
19
|
+
};
|
|
20
|
+
/** Reset the goal record (call at the start of a runGoal). */
|
|
21
|
+
export function resetGoalState(revision = 0) {
|
|
22
|
+
goalState.status = 'in_progress';
|
|
23
|
+
goalState.summary = undefined;
|
|
24
|
+
goalState.revision = revision;
|
|
25
|
+
}
|
|
26
|
+
/** Read the latest reported goal state without consuming it. */
|
|
27
|
+
export function getGoalState() {
|
|
28
|
+
return { ...goalState };
|
|
29
|
+
}
|
|
30
|
+
/** Whether a report with this revision has been recorded (i.e. model spoke). */
|
|
31
|
+
export function hasGoalReport(revision) {
|
|
32
|
+
return goalState.revision > revision;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The internal update_goal tool definition.
|
|
36
|
+
* Schema: { goal_status, summary?, error? }
|
|
37
|
+
*/
|
|
38
|
+
export function createUpdateGoalTool() {
|
|
39
|
+
return {
|
|
40
|
+
name: 'update_goal',
|
|
41
|
+
description: 'Report the status of the goal you are working toward. Call this when the goal is COMPLETED (goal_status=complete), when you are BLOCKED and cannot make further progress (goal_status=blocked), or to record progress. You should call this at least once before stopping. Provide a concise summary of what was accomplished.',
|
|
42
|
+
inputSchema: {
|
|
43
|
+
type: 'object',
|
|
44
|
+
properties: {
|
|
45
|
+
goal_status: {
|
|
46
|
+
type: 'string',
|
|
47
|
+
enum: ['complete', 'blocked', 'in_progress'],
|
|
48
|
+
description: 'Whether the goal is complete, blocked, or still in progress.',
|
|
49
|
+
},
|
|
50
|
+
summary: {
|
|
51
|
+
type: 'string',
|
|
52
|
+
description: 'Concise summary of what was accomplished or why blocked.',
|
|
53
|
+
},
|
|
54
|
+
error: {
|
|
55
|
+
type: 'string',
|
|
56
|
+
description: 'Optional error description when blocked.',
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
required: ['goal_status'],
|
|
60
|
+
},
|
|
61
|
+
isReadOnly: () => false,
|
|
62
|
+
isEnabled: () => true,
|
|
63
|
+
async prompt() {
|
|
64
|
+
return 'Call update_goal with goal_status=complete when the goal is done, blocked when stuck. Always include a brief summary.';
|
|
65
|
+
},
|
|
66
|
+
async call(input) {
|
|
67
|
+
const status = input?.goal_status === 'complete'
|
|
68
|
+
? 'complete'
|
|
69
|
+
: input?.goal_status === 'blocked'
|
|
70
|
+
? 'blocked'
|
|
71
|
+
: 'in_progress';
|
|
72
|
+
goalState.status = status;
|
|
73
|
+
goalState.summary = input?.summary ?? input?.error ?? input?.summary ?? undefined;
|
|
74
|
+
goalState.revision++;
|
|
75
|
+
const ack = status === 'complete'
|
|
76
|
+
? 'Goal reported complete. Well done.'
|
|
77
|
+
: status === 'blocked'
|
|
78
|
+
? 'Goal reported blocked. Stopping current round.'
|
|
79
|
+
: 'Goal progress noted.';
|
|
80
|
+
return {
|
|
81
|
+
type: 'tool_result',
|
|
82
|
+
tool_use_id: '',
|
|
83
|
+
content: ack,
|
|
84
|
+
};
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Build the system-prompt appendix that instructs the model to work toward a
|
|
90
|
+
* goal and to call update_goal when finished or blocked.
|
|
91
|
+
*/
|
|
92
|
+
export function buildGoalSystemPrompt(goal, maxRounds) {
|
|
93
|
+
return [
|
|
94
|
+
'',
|
|
95
|
+
'# Goal-Driven Mode',
|
|
96
|
+
`You are working toward the following goal:`,
|
|
97
|
+
``,
|
|
98
|
+
`"""`,
|
|
99
|
+
goal,
|
|
100
|
+
`"""`,
|
|
101
|
+
``,
|
|
102
|
+
`- Work autonomously toward this goal using your tools. Do not stop early.`,
|
|
103
|
+
`- When you believe the goal is FULLY achieved, call the update_goal tool with goal_status="complete" and a summary.`,
|
|
104
|
+
`- If you are truly blocked and cannot proceed, call update_goal with goal_status="blocked".`,
|
|
105
|
+
`- You may have up to ${maxRounds} rounds to achieve this goal. Use your turns efficiently.`,
|
|
106
|
+
``,
|
|
107
|
+
].join('\n');
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=update-goal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-goal.js","sourceRoot":"","sources":["../../src/tools/update-goal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,+DAA+D;AAC/D,MAAM,SAAS,GAAe;IAC5B,MAAM,EAAE,aAAa;IACrB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,CAAC;CACZ,CAAA;AAED,8DAA8D;AAC9D,MAAM,UAAU,cAAc,CAAC,QAAQ,GAAG,CAAC;IACzC,SAAS,CAAC,MAAM,GAAG,aAAa,CAAA;IAChC,SAAS,CAAC,OAAO,GAAG,SAAS,CAAA;IAC7B,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAA;AAC/B,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,GAAG,SAAS,EAAE,CAAA;AACzB,CAAC;AAED,gFAAgF;AAChF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AAC,CAAC,MAAM,KAAK,SAAS;oBACpB,CAAC,CAAC,gDAAgD;oBAClD,CAAC,CAAC,sBAAsB,CAAA;YAC9B,OAAO;gBACL,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE,EAAE;gBACf,OAAO,EAAE,GAAG;aACb,CAAA;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAY,EAAE,SAAiB;IACnE,OAAO;QACL,EAAE;QACF,oBAAoB;QACpB,4CAA4C;QAC5C,EAAE;QACF,KAAK;QACL,IAAI;QACJ,KAAK;QACL,EAAE;QACF,2EAA2E;QAC3E,qHAAqH;QACrH,6FAA6F;QAC7F,wBAAwB,SAAS,2DAA2D;QAC5F,EAAE;KACH,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../src/tools/web-fetch.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,eAAO,MAAM,YAAY,sCA2DvB,CAAA"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebFetchTool - Fetch web content
|
|
3
|
+
*/
|
|
4
|
+
import { defineTool } from './types.js';
|
|
5
|
+
export const WebFetchTool = defineTool({
|
|
6
|
+
name: 'WebFetch',
|
|
7
|
+
description: 'Fetch content from a URL and return it as text. Supports HTML pages, JSON APIs, and plain text. Strips HTML tags for readability.',
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
url: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
description: 'The URL to fetch content from',
|
|
14
|
+
},
|
|
15
|
+
headers: {
|
|
16
|
+
type: 'object',
|
|
17
|
+
description: 'Optional HTTP headers',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ['url'],
|
|
21
|
+
},
|
|
22
|
+
isReadOnly: true,
|
|
23
|
+
isConcurrencySafe: true,
|
|
24
|
+
async call(input, _context) {
|
|
25
|
+
const { url, headers } = input;
|
|
26
|
+
try {
|
|
27
|
+
const response = await fetch(url, {
|
|
28
|
+
headers: {
|
|
29
|
+
'User-Agent': 'Mozilla/5.0 (compatible; AgentSDK/1.0)',
|
|
30
|
+
...headers,
|
|
31
|
+
},
|
|
32
|
+
signal: AbortSignal.timeout(30000),
|
|
33
|
+
});
|
|
34
|
+
if (!response.ok) {
|
|
35
|
+
return { data: `HTTP ${response.status}: ${response.statusText}`, is_error: true };
|
|
36
|
+
}
|
|
37
|
+
const contentType = response.headers.get('content-type') || '';
|
|
38
|
+
let text = await response.text();
|
|
39
|
+
// Strip HTML tags for readability
|
|
40
|
+
if (contentType.includes('text/html')) {
|
|
41
|
+
// Remove script and style blocks
|
|
42
|
+
text = text.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
|
|
43
|
+
text = text.replace(/<style[^>]*>[\s\S]*?<\/style>/gi, '');
|
|
44
|
+
// Remove HTML tags
|
|
45
|
+
text = text.replace(/<[^>]+>/g, ' ');
|
|
46
|
+
// Clean up whitespace
|
|
47
|
+
text = text.replace(/\s+/g, ' ').trim();
|
|
48
|
+
}
|
|
49
|
+
// Truncate very large responses
|
|
50
|
+
if (text.length > 100000) {
|
|
51
|
+
text = text.slice(0, 100000) + '\n...(truncated)';
|
|
52
|
+
}
|
|
53
|
+
return text || '(empty response)';
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return { data: `Error fetching ${url}: ${err.message}`, is_error: true };
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=web-fetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-fetch.js","sourceRoot":"","sources":["../../src/tools/web-fetch.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YA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,EAAE,CAAC,CAAA;gBAC5D,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,iCAAiC,EAAE,EAAE,CAAC,CAAA;gBAC1D,mBAAmB;gBACnB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;gBACpC,sBAAsB;gBACtB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;YACzC,CAAC;YAED,gCAAgC;YAChC,IAAI,IAAI,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC;gBACzB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,kBAAkB,CAAA;YACnD,CAAC;YAED,OAAO,IAAI,IAAI,kBAAkB,CAAA;QACnC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,EAAE,IAAI,EAAE,kBAAkB,GAAG,KAAK,GAAG,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;QAC1E,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-search.d.ts","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,eAAO,MAAM,aAAa,sCA+ExB,CAAA"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WebSearchTool - Web search (via web fetch of search engines)
|
|
3
|
+
*/
|
|
4
|
+
import { defineTool } from './types.js';
|
|
5
|
+
export const WebSearchTool = defineTool({
|
|
6
|
+
name: 'WebSearch',
|
|
7
|
+
description: 'Search the web for information. Returns search results with titles, URLs, and snippets.',
|
|
8
|
+
inputSchema: {
|
|
9
|
+
type: 'object',
|
|
10
|
+
properties: {
|
|
11
|
+
query: {
|
|
12
|
+
type: 'string',
|
|
13
|
+
description: 'The search query',
|
|
14
|
+
},
|
|
15
|
+
num_results: {
|
|
16
|
+
type: 'number',
|
|
17
|
+
description: 'Number of results to return (default: 5)',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
required: ['query'],
|
|
21
|
+
},
|
|
22
|
+
isReadOnly: true,
|
|
23
|
+
isConcurrencySafe: true,
|
|
24
|
+
async call(input, _context) {
|
|
25
|
+
const { query } = input;
|
|
26
|
+
try {
|
|
27
|
+
// Use DuckDuckGo HTML search as a free fallback
|
|
28
|
+
const encoded = encodeURIComponent(query);
|
|
29
|
+
const url = `https://html.duckduckgo.com/html/?q=${encoded}`;
|
|
30
|
+
const response = await fetch(url, {
|
|
31
|
+
headers: {
|
|
32
|
+
'User-Agent': 'Mozilla/5.0 (compatible; AgentSDK/1.0)',
|
|
33
|
+
},
|
|
34
|
+
signal: AbortSignal.timeout(15000),
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
return { data: `Search failed: HTTP ${response.status}`, is_error: true };
|
|
38
|
+
}
|
|
39
|
+
const html = await response.text();
|
|
40
|
+
// Parse search results from DuckDuckGo HTML
|
|
41
|
+
const results = [];
|
|
42
|
+
const resultRegex = /<a rel="nofollow" class="result__a" href="([^"]*)"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
43
|
+
const snippetRegex = /<a class="result__snippet"[^>]*>([\s\S]*?)<\/a>/gi;
|
|
44
|
+
let match;
|
|
45
|
+
const links = [];
|
|
46
|
+
while ((match = resultRegex.exec(html)) !== null) {
|
|
47
|
+
const href = match[1];
|
|
48
|
+
const title = match[2].replace(/<[^>]+>/g, '').trim();
|
|
49
|
+
if (href && title && !href.includes('duckduckgo.com')) {
|
|
50
|
+
links.push({ title, url: href });
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const snippets = [];
|
|
54
|
+
while ((match = snippetRegex.exec(html)) !== null) {
|
|
55
|
+
snippets.push(match[1].replace(/<[^>]+>/g, '').trim());
|
|
56
|
+
}
|
|
57
|
+
const numResults = Math.min(input.num_results || 5, links.length);
|
|
58
|
+
for (let i = 0; i < numResults; i++) {
|
|
59
|
+
const link = links[i];
|
|
60
|
+
if (!link)
|
|
61
|
+
continue;
|
|
62
|
+
let entry = `${i + 1}. ${link.title}\n ${link.url}`;
|
|
63
|
+
if (snippets[i]) {
|
|
64
|
+
entry += `\n ${snippets[i]}`;
|
|
65
|
+
}
|
|
66
|
+
results.push(entry);
|
|
67
|
+
}
|
|
68
|
+
return results.length > 0
|
|
69
|
+
? results.join('\n\n')
|
|
70
|
+
: `No results found for "${query}"`;
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
return { data: `Search error: ${err.message}`, is_error: true };
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
});
|
|
77
|
+
//# sourceMappingURL=web-search.js.map
|