@codeany/open-agent-sdk 0.1.0 → 0.2.1

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.
Files changed (254) hide show
  1. package/README.md +144 -31
  2. package/dist/agent.d.ts +113 -0
  3. package/dist/agent.d.ts.map +1 -0
  4. package/dist/agent.js +446 -0
  5. package/dist/agent.js.map +1 -0
  6. package/dist/engine.d.ts +62 -0
  7. package/dist/engine.d.ts.map +1 -0
  8. package/dist/engine.js +494 -0
  9. package/dist/engine.js.map +1 -0
  10. package/dist/hooks.d.ts +111 -0
  11. package/dist/hooks.d.ts.map +1 -0
  12. package/dist/hooks.js +179 -0
  13. package/dist/hooks.js.map +1 -0
  14. package/dist/index.d.ts +66 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +133 -0
  17. package/dist/index.js.map +1 -0
  18. package/dist/mcp/client.d.ts +19 -0
  19. package/dist/mcp/client.d.ts.map +1 -0
  20. package/dist/mcp/client.js +126 -0
  21. package/dist/mcp/client.js.map +1 -0
  22. package/dist/providers/anthropic.d.ts +17 -0
  23. package/dist/providers/anthropic.d.ts.map +1 -0
  24. package/dist/providers/anthropic.js +47 -0
  25. package/dist/providers/anthropic.js.map +1 -0
  26. package/dist/providers/index.d.ts +20 -0
  27. package/dist/providers/index.d.ts.map +1 -0
  28. package/dist/providers/index.js +26 -0
  29. package/dist/providers/index.js.map +1 -0
  30. package/dist/providers/openai.d.ts +26 -0
  31. package/dist/providers/openai.d.ts.map +1 -0
  32. package/dist/providers/openai.js +212 -0
  33. package/dist/providers/openai.js.map +1 -0
  34. package/dist/providers/types.d.ts +84 -0
  35. package/dist/providers/types.d.ts.map +1 -0
  36. package/dist/providers/types.js +11 -0
  37. package/dist/providers/types.js.map +1 -0
  38. package/dist/sdk-mcp-server.d.ts +52 -0
  39. package/dist/sdk-mcp-server.d.ts.map +1 -0
  40. package/dist/sdk-mcp-server.js +57 -0
  41. package/dist/sdk-mcp-server.js.map +1 -0
  42. package/dist/session.d.ts +73 -0
  43. package/dist/session.d.ts.map +1 -0
  44. package/dist/session.js +159 -0
  45. package/dist/session.js.map +1 -0
  46. package/dist/skills/bundled/commit.d.ts +7 -0
  47. package/dist/skills/bundled/commit.d.ts.map +1 -0
  48. package/dist/skills/bundled/commit.js +35 -0
  49. package/dist/skills/bundled/commit.js.map +1 -0
  50. package/dist/skills/bundled/debug.d.ts +7 -0
  51. package/dist/skills/bundled/debug.d.ts.map +1 -0
  52. package/dist/skills/bundled/debug.js +46 -0
  53. package/dist/skills/bundled/debug.js.map +1 -0
  54. package/dist/skills/bundled/index.d.ts +11 -0
  55. package/dist/skills/bundled/index.d.ts.map +1 -0
  56. package/dist/skills/bundled/index.js +26 -0
  57. package/dist/skills/bundled/index.js.map +1 -0
  58. package/dist/skills/bundled/review.d.ts +7 -0
  59. package/dist/skills/bundled/review.d.ts.map +1 -0
  60. package/dist/skills/bundled/review.js +38 -0
  61. package/dist/skills/bundled/review.js.map +1 -0
  62. package/dist/skills/bundled/simplify.d.ts +8 -0
  63. package/dist/skills/bundled/simplify.d.ts.map +1 -0
  64. package/dist/skills/bundled/simplify.js +48 -0
  65. package/dist/skills/bundled/simplify.js.map +1 -0
  66. package/dist/skills/bundled/test.d.ts +7 -0
  67. package/dist/skills/bundled/test.d.ts.map +1 -0
  68. package/dist/skills/bundled/test.js +40 -0
  69. package/dist/skills/bundled/test.js.map +1 -0
  70. package/dist/skills/index.d.ts +7 -0
  71. package/dist/skills/index.d.ts.map +1 -0
  72. package/dist/skills/index.js +8 -0
  73. package/dist/skills/index.js.map +1 -0
  74. package/dist/skills/registry.d.ts +43 -0
  75. package/dist/skills/registry.d.ts.map +1 -0
  76. package/dist/skills/registry.js +111 -0
  77. package/dist/skills/registry.js.map +1 -0
  78. package/dist/skills/types.d.ts +83 -0
  79. package/dist/skills/types.d.ts.map +1 -0
  80. package/dist/skills/types.js +8 -0
  81. package/dist/skills/types.js.map +1 -0
  82. package/dist/tool-helper.d.ts +73 -0
  83. package/dist/tool-helper.d.ts.map +1 -0
  84. package/dist/tool-helper.js +86 -0
  85. package/dist/tool-helper.js.map +1 -0
  86. package/dist/tools/agent-tool.d.ts +17 -0
  87. package/dist/tools/agent-tool.d.ts.map +1 -0
  88. package/dist/tools/agent-tool.js +146 -0
  89. package/dist/tools/agent-tool.js.map +1 -0
  90. package/dist/tools/ask-user.d.ts +18 -0
  91. package/dist/tools/ask-user.d.ts.map +1 -0
  92. package/dist/tools/ask-user.js +72 -0
  93. package/dist/tools/ask-user.js.map +1 -0
  94. package/dist/tools/bash.d.ts +5 -0
  95. package/dist/tools/bash.d.ts.map +1 -0
  96. package/dist/tools/bash.js +67 -0
  97. package/dist/tools/bash.js.map +1 -0
  98. package/dist/tools/config-tool.d.ts +20 -0
  99. package/dist/tools/config-tool.d.ts.map +1 -0
  100. package/dist/tools/config-tool.js +83 -0
  101. package/dist/tools/config-tool.js.map +1 -0
  102. package/dist/tools/cron-tools.d.ts +33 -0
  103. package/dist/tools/cron-tools.d.ts.map +1 -0
  104. package/dist/tools/cron-tools.js +128 -0
  105. package/dist/tools/cron-tools.js.map +1 -0
  106. package/dist/tools/edit.d.ts +5 -0
  107. package/dist/tools/edit.d.ts.map +1 -0
  108. package/dist/tools/edit.js +70 -0
  109. package/dist/tools/edit.js.map +1 -0
  110. package/dist/tools/glob.d.ts +5 -0
  111. package/dist/tools/glob.d.ts.map +1 -0
  112. package/dist/tools/glob.js +75 -0
  113. package/dist/tools/glob.js.map +1 -0
  114. package/dist/tools/grep.d.ts +5 -0
  115. package/dist/tools/grep.d.ts.map +1 -0
  116. package/dist/tools/grep.js +168 -0
  117. package/dist/tools/grep.js.map +1 -0
  118. package/dist/tools/index.d.ts +45 -0
  119. package/dist/tools/index.d.ts.map +1 -0
  120. package/dist/tools/index.js +162 -0
  121. package/dist/tools/index.js.map +1 -0
  122. package/dist/tools/lsp-tool.d.ts +9 -0
  123. package/dist/tools/lsp-tool.d.ts.map +1 -0
  124. package/dist/tools/lsp-tool.js +137 -0
  125. package/dist/tools/lsp-tool.js.map +1 -0
  126. package/dist/tools/mcp-resource-tools.d.ts +14 -0
  127. package/dist/tools/mcp-resource-tools.d.ts.map +1 -0
  128. package/dist/tools/mcp-resource-tools.js +117 -0
  129. package/dist/tools/mcp-resource-tools.js.map +1 -0
  130. package/dist/tools/notebook-edit.d.ts +5 -0
  131. package/dist/tools/notebook-edit.d.ts.map +1 -0
  132. package/dist/tools/notebook-edit.js +85 -0
  133. package/dist/tools/notebook-edit.js.map +1 -0
  134. package/dist/tools/plan-tools.d.ts +12 -0
  135. package/dist/tools/plan-tools.d.ts.map +1 -0
  136. package/dist/tools/plan-tools.js +77 -0
  137. package/dist/tools/plan-tools.js.map +1 -0
  138. package/dist/tools/read.d.ts +5 -0
  139. package/dist/tools/read.d.ts.map +1 -0
  140. package/dist/tools/read.js +66 -0
  141. package/dist/tools/read.js.map +1 -0
  142. package/dist/tools/send-message.d.ts +31 -0
  143. package/dist/tools/send-message.d.ts.map +1 -0
  144. package/dist/tools/send-message.js +77 -0
  145. package/dist/tools/send-message.js.map +1 -0
  146. package/dist/tools/skill-tool.d.ts +9 -0
  147. package/dist/tools/skill-tool.d.ts.map +1 -0
  148. package/dist/tools/skill-tool.js +115 -0
  149. package/dist/tools/skill-tool.js.map +1 -0
  150. package/dist/tools/task-tools.d.ts +48 -0
  151. package/dist/tools/task-tools.d.ts.map +1 -0
  152. package/dist/tools/task-tools.js +242 -0
  153. package/dist/tools/task-tools.js.map +1 -0
  154. package/dist/tools/team-tools.d.ts +34 -0
  155. package/dist/tools/team-tools.d.ts.map +1 -0
  156. package/dist/tools/team-tools.js +103 -0
  157. package/dist/tools/team-tools.js.map +1 -0
  158. package/dist/tools/todo-tool.d.ts +22 -0
  159. package/dist/tools/todo-tool.d.ts.map +1 -0
  160. package/dist/tools/todo-tool.js +93 -0
  161. package/dist/tools/todo-tool.js.map +1 -0
  162. package/dist/tools/tool-search.d.ts +13 -0
  163. package/dist/tools/tool-search.d.ts.map +1 -0
  164. package/dist/tools/tool-search.js +76 -0
  165. package/dist/tools/tool-search.js.map +1 -0
  166. package/dist/tools/types.d.ts +29 -0
  167. package/dist/tools/types.d.ts.map +1 -0
  168. package/dist/tools/types.js +52 -0
  169. package/dist/tools/types.js.map +1 -0
  170. package/dist/tools/web-fetch.d.ts +5 -0
  171. package/dist/tools/web-fetch.d.ts.map +1 -0
  172. package/dist/tools/web-fetch.js +60 -0
  173. package/dist/tools/web-fetch.js.map +1 -0
  174. package/dist/tools/web-search.d.ts +5 -0
  175. package/dist/tools/web-search.d.ts.map +1 -0
  176. package/dist/tools/web-search.js +77 -0
  177. package/dist/tools/web-search.js.map +1 -0
  178. package/dist/tools/worktree-tools.d.ts +10 -0
  179. package/dist/tools/worktree-tools.d.ts.map +1 -0
  180. package/dist/tools/worktree-tools.js +130 -0
  181. package/dist/tools/worktree-tools.js.map +1 -0
  182. package/dist/tools/write.d.ts +5 -0
  183. package/dist/tools/write.d.ts.map +1 -0
  184. package/dist/tools/write.js +40 -0
  185. package/dist/tools/write.js.map +1 -0
  186. package/dist/types.d.ts +423 -0
  187. package/dist/types.d.ts.map +1 -0
  188. package/dist/types.js +5 -0
  189. package/dist/types.js.map +1 -0
  190. package/dist/utils/compact.d.ts +44 -0
  191. package/dist/utils/compact.d.ts.map +1 -0
  192. package/dist/utils/compact.js +162 -0
  193. package/dist/utils/compact.js.map +1 -0
  194. package/dist/utils/context.d.ts +35 -0
  195. package/dist/utils/context.d.ts.map +1 -0
  196. package/dist/utils/context.js +174 -0
  197. package/dist/utils/context.js.map +1 -0
  198. package/dist/utils/fileCache.d.ts +64 -0
  199. package/dist/utils/fileCache.d.ts.map +1 -0
  200. package/dist/utils/fileCache.js +117 -0
  201. package/dist/utils/fileCache.js.map +1 -0
  202. package/dist/utils/messages.d.ts +57 -0
  203. package/dist/utils/messages.d.ts.map +1 -0
  204. package/dist/utils/messages.js +152 -0
  205. package/dist/utils/messages.js.map +1 -0
  206. package/dist/utils/retry.d.ts +48 -0
  207. package/dist/utils/retry.d.ts.map +1 -0
  208. package/dist/utils/retry.js +111 -0
  209. package/dist/utils/retry.js.map +1 -0
  210. package/dist/utils/tokens.d.ts +57 -0
  211. package/dist/utils/tokens.d.ts.map +1 -0
  212. package/dist/utils/tokens.js +134 -0
  213. package/dist/utils/tokens.js.map +1 -0
  214. package/package.json +7 -1
  215. package/src/agent.ts +106 -15
  216. package/src/engine.ts +169 -59
  217. package/src/index.ts +51 -1
  218. package/src/providers/anthropic.ts +60 -0
  219. package/src/providers/index.ts +34 -0
  220. package/src/providers/openai.ts +315 -0
  221. package/src/providers/types.ts +85 -0
  222. package/src/session.ts +5 -5
  223. package/src/skills/bundled/commit.ts +38 -0
  224. package/src/skills/bundled/debug.ts +48 -0
  225. package/src/skills/bundled/index.ts +28 -0
  226. package/src/skills/bundled/review.ts +41 -0
  227. package/src/skills/bundled/simplify.ts +51 -0
  228. package/src/skills/bundled/test.ts +43 -0
  229. package/src/skills/index.ts +25 -0
  230. package/src/skills/registry.ts +133 -0
  231. package/src/skills/types.ts +99 -0
  232. package/src/tools/agent-tool.ts +13 -2
  233. package/src/tools/index.ts +8 -0
  234. package/src/tools/skill-tool.ts +133 -0
  235. package/src/tools/types.ts +7 -3
  236. package/src/types.ts +35 -8
  237. package/src/utils/compact.ts +18 -17
  238. package/src/utils/messages.ts +12 -13
  239. package/src/utils/tokens.ts +29 -6
  240. package/.env.example +0 -8
  241. package/examples/01-simple-query.ts +0 -43
  242. package/examples/02-multi-tool.ts +0 -44
  243. package/examples/03-multi-turn.ts +0 -39
  244. package/examples/04-prompt-api.ts +0 -29
  245. package/examples/05-custom-system-prompt.ts +0 -26
  246. package/examples/06-mcp-server.ts +0 -49
  247. package/examples/07-custom-tools.ts +0 -87
  248. package/examples/08-official-api-compat.ts +0 -38
  249. package/examples/09-subagents.ts +0 -48
  250. package/examples/10-permissions.ts +0 -40
  251. package/examples/11-custom-mcp-tools.ts +0 -101
  252. package/examples/web/index.html +0 -365
  253. package/examples/web/server.ts +0 -157
  254. package/tsconfig.json +0 -19
@@ -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;IACtD,aAAa,GAAG,KAAK,CAAA;AACvB,CAAC;AAED,MAAM,CAAC,MAAM,cAAc,GAAmB;IAC5C,IAAI,EAAE,YAAY;IAClB,WAAW,EAAE,mHAAmH;IAChI,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,6EAA6E;aAC3F;YACD,WAAW,EAAE;gBACX,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,wCAAwC;aACtD;SACF;QACD,QAAQ,EAAE,CAAC,OAAO,CAAC;KACpB;IACD,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI;IACtB,iBAAiB,EAAE,GAAG,EAAE,CAAC,IAAI;IAC7B,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI;IACrB,KAAK,CAAC,MAAM,KAAK,OAAO,6BAA6B,CAAA,CAAC,CAAC;IACvD,KAAK,CAAC,IAAI,CAAC,KAAU;QACnB,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,CAAC,EAAE,GAAG,KAAK,CAAA;QAExC,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC/B,OAAO;gBACL,IAAI,EAAE,aAAa;gBACnB,WAAW,EAAE,EAAE;gBACf,OAAO,EAA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,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,5 @@
1
+ /**
2
+ * WebFetchTool - Fetch web content
3
+ */
4
+ export declare const WebFetchTool: import("../types.js").ToolDefinition;
5
+ //# sourceMappingURL=web-fetch.d.ts.map
@@ -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,YAAY,CAAA;AAEvC,MAAM,CAAC,MAAM,YAAY,GAAG,UAAU,CAAC;IACrC,IAAI,EAAE,UAAU;IAChB,WAAW,EAAE,mIAAmI;IAChJ,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,GAAG,EAAE;gBACH,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,+BAA+B;aAC7C;YACD,OAAO,EAAE;gBACP,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,uBAAuB;aACrC;SACF;QACD,QAAQ,EAAE,CAAC,KAAK,CAAC;KAClB;IACD,UAAU,EAAE,IAAI;IAChB,iBAAiB,EAAE,IAAI;IACvB,KAAK,CAAC,IAAI,CAAC,KAAK,EA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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,5 @@
1
+ /**
2
+ * WebSearchTool - Web search (via web fetch of search engines)
3
+ */
4
+ export declare const WebSearchTool: import("../types.js").ToolDefinition;
5
+ //# sourceMappingURL=web-search.d.ts.map
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-search.js","sourceRoot":"","sources":["../../src/tools/web-search.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,CAAC,MAAM,aAAa,GAAG,UAAU,CAAC;IACtC,IAAI,EAAE,WAAW;IACjB,WAAW,EAAE,yFAAyF;IACtG,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,KAAK,EAAE;gBACL,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,kBAAkB;aAChC;YACD,WAAW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KAAK,GAAG,CAAA;QACvC,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO,EAAE,IAAI,EAAE,iBAAiB,GAAG,CAAC,OAAO,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAA;QACjE,CAAC;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Git Worktree Tools
3
+ *
4
+ * EnterWorktree / ExitWorktree - Isolated git worktree environments
5
+ * for parallel work without affecting the main working tree.
6
+ */
7
+ import type { ToolDefinition } from '../types.js';
8
+ export declare const EnterWorktreeTool: ToolDefinition;
9
+ export declare const ExitWorktreeTool: ToolDefinition;
10
+ //# sourceMappingURL=worktree-tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktree-tools.d.ts","sourceRoot":"","sources":["../../src/tools/worktree-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,aAAa,CAAA;AAK7D,eAAO,MAAM,iBAAiB,EAAE,cAwD/B,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,cAkE9B,CAAA"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Git Worktree Tools
3
+ *
4
+ * EnterWorktree / ExitWorktree - Isolated git worktree environments
5
+ * for parallel work without affecting the main working tree.
6
+ */
7
+ import { execSync } from 'child_process';
8
+ import { join } from 'path';
9
+ // Track active worktrees
10
+ const activeWorktrees = new Map();
11
+ export const EnterWorktreeTool = {
12
+ name: 'EnterWorktree',
13
+ description: 'Create an isolated git worktree for parallel work. The agent will work in the worktree without affecting the main working tree.',
14
+ inputSchema: {
15
+ type: 'object',
16
+ properties: {
17
+ branch: { type: 'string', description: 'Branch name for the worktree (auto-generated if not provided)' },
18
+ path: { type: 'string', description: 'Path for the worktree (auto-generated if not provided)' },
19
+ },
20
+ },
21
+ isReadOnly: () => false,
22
+ isConcurrencySafe: () => false,
23
+ isEnabled: () => true,
24
+ async prompt() { return 'Create an isolated git worktree for parallel work.'; },
25
+ async call(input, context) {
26
+ try {
27
+ // Check if we're in a git repo
28
+ execSync('git rev-parse --git-dir', { cwd: context.cwd, encoding: 'utf-8' });
29
+ const branch = input.branch || `worktree-${Date.now()}`;
30
+ const worktreePath = input.path || join(context.cwd, '..', `.worktree-${branch}`);
31
+ // Create the branch if it doesn't exist
32
+ try {
33
+ execSync(`git branch ${branch}`, { cwd: context.cwd, encoding: 'utf-8', stdio: 'pipe' });
34
+ }
35
+ catch {
36
+ // Branch might already exist
37
+ }
38
+ // Create worktree
39
+ execSync(`git worktree add ${JSON.stringify(worktreePath)} ${branch}`, {
40
+ cwd: context.cwd,
41
+ encoding: 'utf-8',
42
+ });
43
+ const id = crypto.randomUUID();
44
+ activeWorktrees.set(id, {
45
+ path: worktreePath,
46
+ branch,
47
+ originalCwd: context.cwd,
48
+ });
49
+ return {
50
+ type: 'tool_result',
51
+ tool_use_id: '',
52
+ content: `Worktree created:\n ID: ${id}\n Path: ${worktreePath}\n Branch: ${branch}\n\nYou are now working in the isolated worktree.`,
53
+ };
54
+ }
55
+ catch (err) {
56
+ return {
57
+ type: 'tool_result',
58
+ tool_use_id: '',
59
+ content: `Error creating worktree: ${err.message}`,
60
+ is_error: true,
61
+ };
62
+ }
63
+ },
64
+ };
65
+ export const ExitWorktreeTool = {
66
+ name: 'ExitWorktree',
67
+ description: 'Exit and optionally remove a git worktree. Use "keep" to preserve changes or "remove" to clean up.',
68
+ inputSchema: {
69
+ type: 'object',
70
+ properties: {
71
+ id: { type: 'string', description: 'Worktree ID' },
72
+ action: {
73
+ type: 'string',
74
+ enum: ['keep', 'remove'],
75
+ description: 'Whether to keep or remove the worktree (default: remove)',
76
+ },
77
+ },
78
+ required: ['id'],
79
+ },
80
+ isReadOnly: () => false,
81
+ isConcurrencySafe: () => false,
82
+ isEnabled: () => true,
83
+ async prompt() { return 'Exit a git worktree.'; },
84
+ async call(input) {
85
+ const worktree = activeWorktrees.get(input.id);
86
+ if (!worktree) {
87
+ return {
88
+ type: 'tool_result',
89
+ tool_use_id: '',
90
+ content: `Worktree not found: ${input.id}`,
91
+ is_error: true,
92
+ };
93
+ }
94
+ const action = input.action || 'remove';
95
+ try {
96
+ if (action === 'remove') {
97
+ execSync(`git worktree remove ${JSON.stringify(worktree.path)} --force`, {
98
+ cwd: worktree.originalCwd,
99
+ encoding: 'utf-8',
100
+ });
101
+ // Clean up branch
102
+ try {
103
+ execSync(`git branch -D ${worktree.branch}`, {
104
+ cwd: worktree.originalCwd,
105
+ encoding: 'utf-8',
106
+ stdio: 'pipe',
107
+ });
108
+ }
109
+ catch {
110
+ // Branch might have commits
111
+ }
112
+ }
113
+ activeWorktrees.delete(input.id);
114
+ return {
115
+ type: 'tool_result',
116
+ tool_use_id: '',
117
+ content: `Worktree ${action === 'remove' ? 'removed' : 'kept'}: ${worktree.path}`,
118
+ };
119
+ }
120
+ catch (err) {
121
+ return {
122
+ type: 'tool_result',
123
+ tool_use_id: '',
124
+ content: `Error: ${err.message}`,
125
+ is_error: true,
126
+ };
127
+ }
128
+ },
129
+ };
130
+ //# sourceMappingURL=worktree-tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"worktree-tools.js","sourceRoot":"","sources":["../../src/tools/worktree-tools.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAG3B,yBAAyB;AACzB,MAAM,eAAe,GAAG,IAAI,GAAG,EAAiE,CAAA;AAEhG,MAAM,CAAC,MAAM,iBAAiB,GAAmB;IAC/C,IAAI,EAAE,eAAe;IACrB,WAAW,EAAE,iIAAiI;IAC9I,WAAW,EAAE;QACX,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACV,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,+DAA+D,EAAE;YACxG,IAAI,EAA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;
5
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../src/tools/write.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,eAAO,MAAM,aAAa,sCAiCxB,CAAA"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * FileWriteTool - Write/create files
3
+ */
4
+ import { writeFile, mkdir } from 'fs/promises';
5
+ import { resolve, dirname } from 'path';
6
+ import { defineTool } from './types.js';
7
+ export const FileWriteTool = defineTool({
8
+ name: 'Write',
9
+ description: 'Write content to a file. Creates the file if it does not exist, or overwrites if it does. Creates parent directories as needed.',
10
+ inputSchema: {
11
+ type: 'object',
12
+ properties: {
13
+ file_path: {
14
+ type: 'string',
15
+ description: 'The absolute path to the file to write',
16
+ },
17
+ content: {
18
+ type: 'string',
19
+ description: 'The content to write to the file',
20
+ },
21
+ },
22
+ required: ['file_path', 'content'],
23
+ },
24
+ isReadOnly: false,
25
+ isConcurrencySafe: false,
26
+ async call(input, context) {
27
+ const filePath = resolve(context.cwd, input.file_path);
28
+ try {
29
+ await mkdir(dirname(filePath), { recursive: true });
30
+ await writeFile(filePath, input.content, 'utf-8');
31
+ const lines = input.content.split('\n').length;
32
+ const bytes = Buffer.byteLength(input.content, 'utf-8');
33
+ return `File written: ${filePath} (${lines} lines, ${bytes} bytes)`;
34
+ }
35
+ catch (err) {
36
+ return { data: `Error writing file: ${err.message}`, is_error: true };
37
+ }
38
+ },
39
+ });
40
+ //# sourceMappingURL=write.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.js","sourceRoot":"","sources":["../../src/tools/write.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAEvC,MAAM,CA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