@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.
Files changed (280) hide show
  1. package/dist/agent.d.ts +113 -0
  2. package/dist/agent.d.ts.map +1 -0
  3. package/dist/agent.js +453 -0
  4. package/dist/agent.js.map +1 -0
  5. package/dist/engine.d.ts +62 -0
  6. package/dist/engine.d.ts.map +1 -0
  7. package/dist/engine.js +496 -0
  8. package/dist/engine.js.map +1 -0
  9. package/dist/hooks.d.ts +111 -0
  10. package/dist/hooks.d.ts.map +1 -0
  11. package/dist/hooks.js +179 -0
  12. package/dist/hooks.js.map +1 -0
  13. package/dist/index.d.ts +66 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +133 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/mcp/client.d.ts +19 -0
  18. package/dist/mcp/client.d.ts.map +1 -0
  19. package/dist/mcp/client.js +126 -0
  20. package/dist/mcp/client.js.map +1 -0
  21. package/dist/providers/anthropic.d.ts +17 -0
  22. package/dist/providers/anthropic.d.ts.map +1 -0
  23. package/dist/providers/anthropic.js +47 -0
  24. package/dist/providers/anthropic.js.map +1 -0
  25. package/dist/providers/index.d.ts +20 -0
  26. package/dist/providers/index.d.ts.map +1 -0
  27. package/dist/providers/index.js +26 -0
  28. package/dist/providers/index.js.map +1 -0
  29. package/dist/providers/openai.d.ts +26 -0
  30. package/dist/providers/openai.d.ts.map +1 -0
  31. package/dist/providers/openai.js +212 -0
  32. package/dist/providers/openai.js.map +1 -0
  33. package/dist/providers/types.d.ts +84 -0
  34. package/dist/providers/types.d.ts.map +1 -0
  35. package/dist/providers/types.js +11 -0
  36. package/dist/providers/types.js.map +1 -0
  37. package/dist/sdk-mcp-server.d.ts +52 -0
  38. package/dist/sdk-mcp-server.d.ts.map +1 -0
  39. package/dist/sdk-mcp-server.js +57 -0
  40. package/dist/sdk-mcp-server.js.map +1 -0
  41. package/dist/session.d.ts +73 -0
  42. package/dist/session.d.ts.map +1 -0
  43. package/dist/session.js +159 -0
  44. package/dist/session.js.map +1 -0
  45. package/dist/skills/bundled/commit.d.ts +7 -0
  46. package/dist/skills/bundled/commit.d.ts.map +1 -0
  47. package/dist/skills/bundled/commit.js +35 -0
  48. package/dist/skills/bundled/commit.js.map +1 -0
  49. package/dist/skills/bundled/debug.d.ts +7 -0
  50. package/dist/skills/bundled/debug.d.ts.map +1 -0
  51. package/{src/skills/bundled/debug.ts → dist/skills/bundled/debug.js} +20 -22
  52. package/dist/skills/bundled/debug.js.map +1 -0
  53. package/dist/skills/bundled/index.d.ts +11 -0
  54. package/dist/skills/bundled/index.d.ts.map +1 -0
  55. package/dist/skills/bundled/index.js +26 -0
  56. package/dist/skills/bundled/index.js.map +1 -0
  57. package/dist/skills/bundled/review.d.ts +7 -0
  58. package/dist/skills/bundled/review.d.ts.map +1 -0
  59. package/{src/skills/bundled/review.ts → dist/skills/bundled/review.js} +18 -21
  60. package/dist/skills/bundled/review.js.map +1 -0
  61. package/dist/skills/bundled/simplify.d.ts +8 -0
  62. package/dist/skills/bundled/simplify.d.ts.map +1 -0
  63. package/{src/skills/bundled/simplify.ts → dist/skills/bundled/simplify.js} +16 -19
  64. package/dist/skills/bundled/simplify.js.map +1 -0
  65. package/dist/skills/bundled/test.d.ts +7 -0
  66. package/dist/skills/bundled/test.d.ts.map +1 -0
  67. package/{src/skills/bundled/test.ts → dist/skills/bundled/test.js} +18 -21
  68. package/dist/skills/bundled/test.js.map +1 -0
  69. package/dist/skills/index.d.ts +7 -0
  70. package/dist/skills/index.d.ts.map +1 -0
  71. package/dist/skills/index.js +8 -0
  72. package/dist/skills/index.js.map +1 -0
  73. package/dist/skills/registry.d.ts +43 -0
  74. package/dist/skills/registry.d.ts.map +1 -0
  75. package/dist/skills/registry.js +111 -0
  76. package/dist/skills/registry.js.map +1 -0
  77. package/dist/skills/types.d.ts +83 -0
  78. package/dist/skills/types.d.ts.map +1 -0
  79. package/dist/skills/types.js +8 -0
  80. package/dist/skills/types.js.map +1 -0
  81. package/dist/tool-helper.d.ts +73 -0
  82. package/dist/tool-helper.d.ts.map +1 -0
  83. package/dist/tool-helper.js +86 -0
  84. package/dist/tool-helper.js.map +1 -0
  85. package/dist/tools/agent-tool.d.ts +17 -0
  86. package/dist/tools/agent-tool.d.ts.map +1 -0
  87. package/dist/tools/agent-tool.js +146 -0
  88. package/dist/tools/agent-tool.js.map +1 -0
  89. package/dist/tools/ask-user.d.ts +18 -0
  90. package/dist/tools/ask-user.d.ts.map +1 -0
  91. package/dist/tools/ask-user.js +72 -0
  92. package/dist/tools/ask-user.js.map +1 -0
  93. package/dist/tools/bash.d.ts +5 -0
  94. package/dist/tools/bash.d.ts.map +1 -0
  95. package/dist/tools/bash.js +67 -0
  96. package/dist/tools/bash.js.map +1 -0
  97. package/dist/tools/config-tool.d.ts +20 -0
  98. package/dist/tools/config-tool.d.ts.map +1 -0
  99. package/dist/tools/config-tool.js +83 -0
  100. package/dist/tools/config-tool.js.map +1 -0
  101. package/dist/tools/cron-tools.d.ts +33 -0
  102. package/dist/tools/cron-tools.d.ts.map +1 -0
  103. package/dist/tools/cron-tools.js +128 -0
  104. package/dist/tools/cron-tools.js.map +1 -0
  105. package/dist/tools/edit.d.ts +5 -0
  106. package/dist/tools/edit.d.ts.map +1 -0
  107. package/dist/tools/edit.js +70 -0
  108. package/dist/tools/edit.js.map +1 -0
  109. package/dist/tools/glob.d.ts +5 -0
  110. package/dist/tools/glob.d.ts.map +1 -0
  111. package/dist/tools/glob.js +75 -0
  112. package/dist/tools/glob.js.map +1 -0
  113. package/dist/tools/grep.d.ts +5 -0
  114. package/dist/tools/grep.d.ts.map +1 -0
  115. package/dist/tools/grep.js +168 -0
  116. package/dist/tools/grep.js.map +1 -0
  117. package/dist/tools/index.d.ts +45 -0
  118. package/dist/tools/index.d.ts.map +1 -0
  119. package/dist/tools/index.js +162 -0
  120. package/dist/tools/index.js.map +1 -0
  121. package/dist/tools/lsp-tool.d.ts +9 -0
  122. package/dist/tools/lsp-tool.d.ts.map +1 -0
  123. package/dist/tools/lsp-tool.js +137 -0
  124. package/dist/tools/lsp-tool.js.map +1 -0
  125. package/dist/tools/mcp-resource-tools.d.ts +14 -0
  126. package/dist/tools/mcp-resource-tools.d.ts.map +1 -0
  127. package/dist/tools/mcp-resource-tools.js +117 -0
  128. package/dist/tools/mcp-resource-tools.js.map +1 -0
  129. package/dist/tools/notebook-edit.d.ts +5 -0
  130. package/dist/tools/notebook-edit.d.ts.map +1 -0
  131. package/dist/tools/notebook-edit.js +85 -0
  132. package/dist/tools/notebook-edit.js.map +1 -0
  133. package/dist/tools/plan-tools.d.ts +12 -0
  134. package/dist/tools/plan-tools.d.ts.map +1 -0
  135. package/dist/tools/plan-tools.js +77 -0
  136. package/dist/tools/plan-tools.js.map +1 -0
  137. package/dist/tools/read.d.ts +5 -0
  138. package/dist/tools/read.d.ts.map +1 -0
  139. package/dist/tools/read.js +66 -0
  140. package/dist/tools/read.js.map +1 -0
  141. package/dist/tools/send-message.d.ts +31 -0
  142. package/dist/tools/send-message.d.ts.map +1 -0
  143. package/dist/tools/send-message.js +77 -0
  144. package/dist/tools/send-message.js.map +1 -0
  145. package/dist/tools/skill-tool.d.ts +9 -0
  146. package/dist/tools/skill-tool.d.ts.map +1 -0
  147. package/dist/tools/skill-tool.js +115 -0
  148. package/dist/tools/skill-tool.js.map +1 -0
  149. package/dist/tools/task-tools.d.ts +48 -0
  150. package/dist/tools/task-tools.d.ts.map +1 -0
  151. package/dist/tools/task-tools.js +242 -0
  152. package/dist/tools/task-tools.js.map +1 -0
  153. package/dist/tools/team-tools.d.ts +34 -0
  154. package/dist/tools/team-tools.d.ts.map +1 -0
  155. package/dist/tools/team-tools.js +103 -0
  156. package/dist/tools/team-tools.js.map +1 -0
  157. package/dist/tools/todo-tool.d.ts +22 -0
  158. package/dist/tools/todo-tool.d.ts.map +1 -0
  159. package/dist/tools/todo-tool.js +93 -0
  160. package/dist/tools/todo-tool.js.map +1 -0
  161. package/dist/tools/tool-search.d.ts +13 -0
  162. package/dist/tools/tool-search.d.ts.map +1 -0
  163. package/dist/tools/tool-search.js +76 -0
  164. package/dist/tools/tool-search.js.map +1 -0
  165. package/dist/tools/types.d.ts +29 -0
  166. package/dist/tools/types.d.ts.map +1 -0
  167. package/dist/tools/types.js +52 -0
  168. package/dist/tools/types.js.map +1 -0
  169. package/dist/tools/web-fetch.d.ts +5 -0
  170. package/dist/tools/web-fetch.d.ts.map +1 -0
  171. package/dist/tools/web-fetch.js +60 -0
  172. package/dist/tools/web-fetch.js.map +1 -0
  173. package/dist/tools/web-search.d.ts +5 -0
  174. package/dist/tools/web-search.d.ts.map +1 -0
  175. package/dist/tools/web-search.js +77 -0
  176. package/dist/tools/web-search.js.map +1 -0
  177. package/dist/tools/worktree-tools.d.ts +10 -0
  178. package/dist/tools/worktree-tools.d.ts.map +1 -0
  179. package/dist/tools/worktree-tools.js +130 -0
  180. package/dist/tools/worktree-tools.js.map +1 -0
  181. package/dist/tools/write.d.ts +5 -0
  182. package/dist/tools/write.d.ts.map +1 -0
  183. package/dist/tools/write.js +40 -0
  184. package/dist/tools/write.js.map +1 -0
  185. package/dist/types.d.ts +432 -0
  186. package/dist/types.d.ts.map +1 -0
  187. package/dist/types.js +5 -0
  188. package/dist/types.js.map +1 -0
  189. package/dist/utils/compact.d.ts +44 -0
  190. package/dist/utils/compact.d.ts.map +1 -0
  191. package/dist/utils/compact.js +162 -0
  192. package/dist/utils/compact.js.map +1 -0
  193. package/dist/utils/context.d.ts +35 -0
  194. package/dist/utils/context.d.ts.map +1 -0
  195. package/dist/utils/context.js +174 -0
  196. package/dist/utils/context.js.map +1 -0
  197. package/dist/utils/fileCache.d.ts +64 -0
  198. package/dist/utils/fileCache.d.ts.map +1 -0
  199. package/dist/utils/fileCache.js +117 -0
  200. package/dist/utils/fileCache.js.map +1 -0
  201. package/dist/utils/messages.d.ts +57 -0
  202. package/dist/utils/messages.d.ts.map +1 -0
  203. package/dist/utils/messages.js +152 -0
  204. package/dist/utils/messages.js.map +1 -0
  205. package/dist/utils/retry.d.ts +48 -0
  206. package/dist/utils/retry.d.ts.map +1 -0
  207. package/dist/utils/retry.js +111 -0
  208. package/dist/utils/retry.js.map +1 -0
  209. package/dist/utils/tokens.d.ts +57 -0
  210. package/dist/utils/tokens.d.ts.map +1 -0
  211. package/dist/utils/tokens.js +134 -0
  212. package/dist/utils/tokens.js.map +1 -0
  213. package/package.json +6 -1
  214. package/.env.example +0 -8
  215. package/examples/01-simple-query.ts +0 -43
  216. package/examples/02-multi-tool.ts +0 -44
  217. package/examples/03-multi-turn.ts +0 -39
  218. package/examples/04-prompt-api.ts +0 -29
  219. package/examples/05-custom-system-prompt.ts +0 -26
  220. package/examples/06-mcp-server.ts +0 -49
  221. package/examples/07-custom-tools.ts +0 -87
  222. package/examples/08-official-api-compat.ts +0 -38
  223. package/examples/09-subagents.ts +0 -48
  224. package/examples/10-permissions.ts +0 -40
  225. package/examples/11-custom-mcp-tools.ts +0 -101
  226. package/examples/12-skills.ts +0 -88
  227. package/examples/13-hooks.ts +0 -88
  228. package/examples/14-openai-compat.ts +0 -71
  229. package/examples/web/index.html +0 -365
  230. package/examples/web/server.ts +0 -157
  231. package/src/agent.ts +0 -516
  232. package/src/engine.ts +0 -633
  233. package/src/hooks.ts +0 -261
  234. package/src/index.ts +0 -426
  235. package/src/mcp/client.ts +0 -150
  236. package/src/providers/anthropic.ts +0 -60
  237. package/src/providers/index.ts +0 -34
  238. package/src/providers/openai.ts +0 -315
  239. package/src/providers/types.ts +0 -85
  240. package/src/sdk-mcp-server.ts +0 -78
  241. package/src/session.ts +0 -227
  242. package/src/skills/bundled/commit.ts +0 -38
  243. package/src/skills/bundled/index.ts +0 -28
  244. package/src/skills/index.ts +0 -25
  245. package/src/skills/registry.ts +0 -133
  246. package/src/skills/types.ts +0 -99
  247. package/src/tool-helper.ts +0 -127
  248. package/src/tools/agent-tool.ts +0 -164
  249. package/src/tools/ask-user.ts +0 -79
  250. package/src/tools/bash.ts +0 -75
  251. package/src/tools/config-tool.ts +0 -89
  252. package/src/tools/cron-tools.ts +0 -153
  253. package/src/tools/edit.ts +0 -74
  254. package/src/tools/glob.ts +0 -77
  255. package/src/tools/grep.ts +0 -168
  256. package/src/tools/index.ts +0 -240
  257. package/src/tools/lsp-tool.ts +0 -163
  258. package/src/tools/mcp-resource-tools.ts +0 -125
  259. package/src/tools/notebook-edit.ts +0 -93
  260. package/src/tools/plan-tools.ts +0 -88
  261. package/src/tools/read.ts +0 -73
  262. package/src/tools/send-message.ts +0 -96
  263. package/src/tools/skill-tool.ts +0 -133
  264. package/src/tools/task-tools.ts +0 -290
  265. package/src/tools/team-tools.ts +0 -128
  266. package/src/tools/todo-tool.ts +0 -112
  267. package/src/tools/tool-search.ts +0 -87
  268. package/src/tools/types.ts +0 -66
  269. package/src/tools/web-fetch.ts +0 -66
  270. package/src/tools/web-search.ts +0 -86
  271. package/src/tools/worktree-tools.ts +0 -140
  272. package/src/tools/write.ts +0 -42
  273. package/src/types.ts +0 -486
  274. package/src/utils/compact.ts +0 -207
  275. package/src/utils/context.ts +0 -191
  276. package/src/utils/fileCache.ts +0 -148
  277. package/src/utils/messages.ts +0 -195
  278. package/src/utils/retry.ts +0 -140
  279. package/src/utils/tokens.ts +0 -145
  280. package/tsconfig.json +0 -19
@@ -1,127 +0,0 @@
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
-
20
- import { z, type ZodRawShape, type ZodObject } from 'zod'
21
- import { zodToJsonSchema } from 'zod-to-json-schema'
22
- import type { ToolDefinition, ToolResult, ToolContext } from './types.js'
23
-
24
- /**
25
- * Tool annotations (MCP standard).
26
- */
27
- export interface ToolAnnotations {
28
- readOnlyHint?: boolean
29
- destructiveHint?: boolean
30
- idempotentHint?: boolean
31
- openWorldHint?: boolean
32
- }
33
-
34
- /**
35
- * Tool call result (MCP-compatible).
36
- */
37
- export interface CallToolResult {
38
- content: Array<
39
- | { type: 'text'; text: string }
40
- | { type: 'image'; data: string; mimeType: string }
41
- | { type: 'resource'; resource: { uri: string; text?: string; blob?: string } }
42
- >
43
- isError?: boolean
44
- }
45
-
46
- /**
47
- * SDK MCP tool definition.
48
- */
49
- export interface SdkMcpToolDefinition<T extends ZodRawShape = ZodRawShape> {
50
- name: string
51
- description: string
52
- inputSchema: ZodObject<T>
53
- handler: (args: z.infer<ZodObject<T>>, extra: unknown) => Promise<CallToolResult>
54
- annotations?: ToolAnnotations
55
- }
56
-
57
- /**
58
- * Create a tool using Zod schema.
59
- *
60
- * Compatible with open-agent-sdk's tool() function.
61
- */
62
- export function tool<T extends ZodRawShape>(
63
- name: string,
64
- description: string,
65
- inputSchema: T,
66
- handler: (args: z.infer<ZodObject<T>>, extra: unknown) => Promise<CallToolResult>,
67
- extras?: { annotations?: ToolAnnotations },
68
- ): SdkMcpToolDefinition<T> {
69
- return {
70
- name,
71
- description,
72
- inputSchema: z.object(inputSchema),
73
- handler,
74
- annotations: extras?.annotations,
75
- }
76
- }
77
-
78
- /**
79
- * Convert an SdkMcpToolDefinition to a ToolDefinition for the engine.
80
- */
81
- export function sdkToolToToolDefinition(sdkTool: SdkMcpToolDefinition<any>): ToolDefinition {
82
- const jsonSchema = zodToJsonSchema(sdkTool.inputSchema, { target: 'openApi3' }) as any
83
-
84
- return {
85
- name: sdkTool.name,
86
- description: sdkTool.description,
87
- inputSchema: {
88
- type: 'object',
89
- properties: jsonSchema.properties || {},
90
- required: jsonSchema.required || [],
91
- },
92
- isReadOnly: () => sdkTool.annotations?.readOnlyHint ?? false,
93
- isConcurrencySafe: () => sdkTool.annotations?.readOnlyHint ?? false,
94
- isEnabled: () => true,
95
- async prompt() { return sdkTool.description },
96
- async call(input: any, _context: ToolContext): Promise<ToolResult> {
97
- try {
98
- const parsed = sdkTool.inputSchema.parse(input)
99
- const result = await sdkTool.handler(parsed, {})
100
-
101
- // Convert MCP content blocks to string
102
- const text = result.content
103
- .map((block) => {
104
- if (block.type === 'text') return block.text
105
- if (block.type === 'image') return `[Image: ${block.mimeType}]`
106
- if (block.type === 'resource') return block.resource.text || `[Resource: ${block.resource.uri}]`
107
- return JSON.stringify(block)
108
- })
109
- .join('\n')
110
-
111
- return {
112
- type: 'tool_result',
113
- tool_use_id: '',
114
- content: text,
115
- is_error: result.isError || false,
116
- }
117
- } catch (err: any) {
118
- return {
119
- type: 'tool_result',
120
- tool_use_id: '',
121
- content: `Error: ${err.message}`,
122
- is_error: true,
123
- }
124
- }
125
- },
126
- }
127
- }
@@ -1,164 +0,0 @@
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
-
8
- import type { ToolDefinition, ToolContext, ToolResult, AgentDefinition } from '../types.js'
9
- import { QueryEngine } from '../engine.js'
10
- import { getAllBaseTools, filterTools } from './index.js'
11
- import { createProvider, type ApiType } from '../providers/index.js'
12
-
13
- // Store for registered agent definitions
14
- let registeredAgents: Record<string, AgentDefinition> = {}
15
-
16
- /**
17
- * Register agent definitions for the AgentTool to use.
18
- */
19
- export function registerAgents(agents: Record<string, AgentDefinition>): void {
20
- registeredAgents = { ...registeredAgents, ...agents }
21
- }
22
-
23
- /**
24
- * Clear registered agents.
25
- */
26
- export function clearAgents(): void {
27
- registeredAgents = {}
28
- }
29
-
30
- /**
31
- * Built-in agent definitions.
32
- */
33
- const BUILTIN_AGENTS: Record<string, AgentDefinition> = {
34
- Explore: {
35
- description: 'Fast agent for exploring codebases. Use for finding files, searching code, and answering questions about the codebase.',
36
- 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.',
37
- tools: ['Read', 'Glob', 'Grep', 'Bash'],
38
- },
39
- Plan: {
40
- description: 'Software architect agent for designing implementation plans. Returns step-by-step plans and identifies critical files.',
41
- 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.',
42
- tools: ['Read', 'Glob', 'Grep', 'Bash'],
43
- },
44
- }
45
-
46
- export const AgentTool: ToolDefinition = {
47
- name: 'Agent',
48
- description: 'Launch a subagent to handle complex, multi-step tasks autonomously. Subagents have their own context and can run specialized tool sets.',
49
- inputSchema: {
50
- type: 'object',
51
- properties: {
52
- prompt: {
53
- type: 'string',
54
- description: 'The task for the agent to perform',
55
- },
56
- description: {
57
- type: 'string',
58
- description: 'A short (3-5 word) description of the task',
59
- },
60
- subagent_type: {
61
- type: 'string',
62
- description: 'The type of agent to use (e.g., "Explore", "Plan", or a custom agent name)',
63
- },
64
- model: {
65
- type: 'string',
66
- description: 'Optional model override for this agent',
67
- },
68
- name: {
69
- type: 'string',
70
- description: 'Name for the spawned agent',
71
- },
72
- run_in_background: {
73
- type: 'boolean',
74
- description: 'Whether to run in background',
75
- },
76
- },
77
- required: ['prompt', 'description'],
78
- },
79
- isReadOnly: () => false,
80
- isConcurrencySafe: () => false,
81
- isEnabled: () => true,
82
- async prompt() {
83
- return 'Launch a subagent to handle complex tasks autonomously.'
84
- },
85
- async call(input: any, context: ToolContext): Promise<ToolResult> {
86
- const agentType = input.subagent_type || 'general-purpose'
87
-
88
- // Find agent definition
89
- const agentDef = registeredAgents[agentType] || BUILTIN_AGENTS[agentType]
90
-
91
- // Determine tools for subagent
92
- let tools = getAllBaseTools()
93
- if (agentDef?.tools) {
94
- tools = filterTools(tools, agentDef.tools)
95
- }
96
-
97
- // Remove AgentTool from subagent to prevent infinite recursion
98
- tools = tools.filter(t => t.name !== 'Agent')
99
-
100
- // Build system prompt
101
- const systemPrompt = agentDef?.prompt ||
102
- 'You are a helpful assistant. Complete the given task using the available tools.'
103
-
104
- // Inherit provider and model from parent agent context, fall back to env vars
105
- const subModel = input.model || context.model || process.env.CODEANY_MODEL || 'claude-sonnet-4-6'
106
- const provider = context.provider ?? createProvider(
107
- (context.apiType || process.env.CODEANY_API_TYPE as ApiType) || 'anthropic-messages',
108
- {
109
- apiKey: process.env.CODEANY_API_KEY,
110
- baseURL: process.env.CODEANY_BASE_URL,
111
- },
112
- )
113
-
114
- // Create subagent engine
115
- const engine = new QueryEngine({
116
- cwd: context.cwd,
117
- model: subModel,
118
- provider,
119
- tools,
120
- systemPrompt,
121
- maxTurns: agentDef?.maxTurns || 10,
122
- maxTokens: 16384,
123
- canUseTool: async () => ({ behavior: 'allow' }),
124
- includePartialMessages: false,
125
- })
126
-
127
- // Run the subagent
128
- let resultText = ''
129
- let toolCalls: string[] = []
130
-
131
- try {
132
- for await (const event of engine.submitMessage(input.prompt)) {
133
- if (event.type === 'assistant') {
134
- for (const block of event.message.content) {
135
- if ('text' in block && block.text) {
136
- resultText = block.text
137
- }
138
- if ('name' in block) {
139
- toolCalls.push(block.name as string)
140
- }
141
- }
142
- }
143
- }
144
- } catch (err: any) {
145
- return {
146
- type: 'tool_result',
147
- tool_use_id: '',
148
- content: `Subagent error: ${err.message}`,
149
- is_error: true,
150
- }
151
- }
152
-
153
- const output = resultText || '(Subagent completed with no text output)'
154
- const toolSummary = toolCalls.length > 0
155
- ? `\n[Tools used: ${toolCalls.join(', ')}]`
156
- : ''
157
-
158
- return {
159
- type: 'tool_result',
160
- tool_use_id: '',
161
- content: output + toolSummary,
162
- }
163
- },
164
- }
@@ -1,79 +0,0 @@
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
-
9
- import type { ToolDefinition, ToolResult } from '../types.js'
10
-
11
- // Callback for handling user questions (set by the agent)
12
- let questionHandler: ((question: string, options?: string[]) => Promise<string>) | null = null
13
-
14
- /**
15
- * Set the question handler for AskUserQuestion.
16
- */
17
- export function setQuestionHandler(
18
- handler: (question: string, options?: string[]) => Promise<string>,
19
- ): void {
20
- questionHandler = handler
21
- }
22
-
23
- /**
24
- * Clear the question handler.
25
- */
26
- export function clearQuestionHandler(): void {
27
- questionHandler = null
28
- }
29
-
30
- export const AskUserQuestionTool: ToolDefinition = {
31
- name: 'AskUserQuestion',
32
- description: 'Ask the user a question and wait for their response. Use when you need clarification or input from the user.',
33
- inputSchema: {
34
- type: 'object',
35
- properties: {
36
- question: { type: 'string', description: 'The question to ask the user' },
37
- options: {
38
- type: 'array',
39
- items: { type: 'string' },
40
- description: 'Optional list of choices for the user',
41
- },
42
- allow_multiselect: {
43
- type: 'boolean',
44
- description: 'Whether to allow multiple selections (for options)',
45
- },
46
- },
47
- required: ['question'],
48
- },
49
- isReadOnly: () => true,
50
- isConcurrencySafe: () => false,
51
- isEnabled: () => true,
52
- async prompt() { return 'Ask the user a question.' },
53
- async call(input: any): Promise<ToolResult> {
54
- if (questionHandler) {
55
- try {
56
- const answer = await questionHandler(input.question, input.options)
57
- return {
58
- type: 'tool_result',
59
- tool_use_id: '',
60
- content: answer,
61
- }
62
- } catch (err: any) {
63
- return {
64
- type: 'tool_result',
65
- tool_use_id: '',
66
- content: `User declined to answer: ${err.message}`,
67
- is_error: true,
68
- }
69
- }
70
- }
71
-
72
- // Non-interactive: return informative message
73
- return {
74
- type: 'tool_result',
75
- tool_use_id: '',
76
- content: `[Non-interactive mode] Question: ${input.question}${input.options ? `\nOptions: ${input.options.join(', ')}` : ''}\n\nNo user available to answer. Proceeding with best judgment.`,
77
- }
78
- },
79
- }
package/src/tools/bash.ts DELETED
@@ -1,75 +0,0 @@
1
- /**
2
- * BashTool - Execute shell commands
3
- */
4
-
5
- import { spawn } from 'child_process'
6
- import { defineTool } from './types.js'
7
-
8
- export const BashTool = defineTool({
9
- name: 'Bash',
10
- description: 'Execute a bash command and return its output. Use for running shell commands, scripts, and system operations.',
11
- inputSchema: {
12
- type: 'object',
13
- properties: {
14
- command: {
15
- type: 'string',
16
- description: 'The bash command to execute',
17
- },
18
- timeout: {
19
- type: 'number',
20
- description: 'Optional timeout in milliseconds (max 600000, default 120000)',
21
- },
22
- },
23
- required: ['command'],
24
- },
25
- isReadOnly: false,
26
- isConcurrencySafe: false,
27
- async call(input, context) {
28
- const { command, timeout: userTimeout } = input
29
- const timeoutMs = Math.min(userTimeout || 120000, 600000)
30
-
31
- return new Promise<string>((resolve) => {
32
- const chunks: Buffer[] = []
33
- const errChunks: Buffer[] = []
34
-
35
- const proc = spawn('bash', ['-c', command], {
36
- cwd: context.cwd,
37
- env: { ...process.env },
38
- timeout: timeoutMs,
39
- stdio: ['pipe', 'pipe', 'pipe'],
40
- })
41
-
42
- proc.stdout?.on('data', (data: Buffer) => chunks.push(data))
43
- proc.stderr?.on('data', (data: Buffer) => errChunks.push(data))
44
-
45
- if (context.abortSignal) {
46
- context.abortSignal.addEventListener('abort', () => {
47
- proc.kill('SIGTERM')
48
- }, { once: true })
49
- }
50
-
51
- proc.on('close', (code) => {
52
- const stdout = Buffer.concat(chunks).toString('utf-8')
53
- const stderr = Buffer.concat(errChunks).toString('utf-8')
54
-
55
- let output = ''
56
- if (stdout) output += stdout
57
- if (stderr) output += (output ? '\n' : '') + stderr
58
- if (code !== 0 && code !== null) {
59
- output += `\nExit code: ${code}`
60
- }
61
-
62
- // Truncate very large outputs
63
- if (output.length > 100000) {
64
- output = output.slice(0, 50000) + '\n...(truncated)...\n' + output.slice(-50000)
65
- }
66
-
67
- resolve(output || '(no output)')
68
- })
69
-
70
- proc.on('error', (err) => {
71
- resolve(`Error executing command: ${err.message}`)
72
- })
73
- })
74
- },
75
- })
@@ -1,89 +0,0 @@
1
- /**
2
- * ConfigTool - Dynamic configuration management
3
- *
4
- * Get/set global configuration and session settings.
5
- */
6
-
7
- import type { ToolDefinition, ToolResult } from '../types.js'
8
-
9
- // In-memory config store
10
- const configStore = new Map<string, unknown>()
11
-
12
- /**
13
- * Get a config value.
14
- */
15
- export function getConfig(key: string): unknown {
16
- return configStore.get(key)
17
- }
18
-
19
- /**
20
- * Set a config value.
21
- */
22
- export function setConfig(key: string, value: unknown): void {
23
- configStore.set(key, value)
24
- }
25
-
26
- /**
27
- * Clear all config.
28
- */
29
- export function clearConfig(): void {
30
- configStore.clear()
31
- }
32
-
33
- export const ConfigTool: ToolDefinition = {
34
- name: 'Config',
35
- description: 'Get or set configuration values. Supports session-scoped settings.',
36
- inputSchema: {
37
- type: 'object',
38
- properties: {
39
- action: {
40
- type: 'string',
41
- enum: ['get', 'set', 'list'],
42
- description: 'Operation to perform',
43
- },
44
- key: { type: 'string', description: 'Config key' },
45
- value: { description: 'Config value (for set)' },
46
- },
47
- required: ['action'],
48
- },
49
- isReadOnly: () => false,
50
- isConcurrencySafe: () => true,
51
- isEnabled: () => true,
52
- async prompt() { return 'Manage configuration settings.' },
53
- async call(input: any): Promise<ToolResult> {
54
- switch (input.action) {
55
- case 'get': {
56
- if (!input.key) {
57
- return { type: 'tool_result', tool_use_id: '', content: 'key required for get', is_error: true }
58
- }
59
- const value = configStore.get(input.key)
60
- return {
61
- type: 'tool_result',
62
- tool_use_id: '',
63
- content: value !== undefined ? JSON.stringify(value) : `Config key "${input.key}" not found`,
64
- }
65
- }
66
- case 'set': {
67
- if (!input.key) {
68
- return { type: 'tool_result', tool_use_id: '', content: 'key required for set', is_error: true }
69
- }
70
- configStore.set(input.key, input.value)
71
- return {
72
- type: 'tool_result',
73
- tool_use_id: '',
74
- content: `Config set: ${input.key} = ${JSON.stringify(input.value)}`,
75
- }
76
- }
77
- case 'list': {
78
- const entries = Array.from(configStore.entries())
79
- if (entries.length === 0) {
80
- return { type: 'tool_result', tool_use_id: '', content: 'No config values set.' }
81
- }
82
- const lines = entries.map(([k, v]) => `${k} = ${JSON.stringify(v)}`)
83
- return { type: 'tool_result', tool_use_id: '', content: lines.join('\n') }
84
- }
85
- default:
86
- return { type: 'tool_result', tool_use_id: '', content: `Unknown action: ${input.action}`, is_error: true }
87
- }
88
- },
89
- }
@@ -1,153 +0,0 @@
1
- /**
2
- * Cron/Scheduling Tools
3
- *
4
- * CronCreate, CronDelete, CronList - Schedule recurring tasks.
5
- * RemoteTrigger - Manage remote scheduled agent triggers.
6
- */
7
-
8
- import type { ToolDefinition, ToolResult } from '../types.js'
9
-
10
- /**
11
- * Cron job definition.
12
- */
13
- export interface CronJob {
14
- id: string
15
- name: string
16
- schedule: string // cron expression
17
- command: string
18
- enabled: boolean
19
- createdAt: string
20
- lastRunAt?: string
21
- nextRunAt?: string
22
- }
23
-
24
- // In-memory cron store
25
- const cronStore = new Map<string, CronJob>()
26
- let cronCounter = 0
27
-
28
- /**
29
- * Get all cron jobs.
30
- */
31
- export function getAllCronJobs(): CronJob[] {
32
- return Array.from(cronStore.values())
33
- }
34
-
35
- /**
36
- * Clear all cron jobs.
37
- */
38
- export function clearCronJobs(): void {
39
- cronStore.clear()
40
- cronCounter = 0
41
- }
42
-
43
- export const CronCreateTool: ToolDefinition = {
44
- name: 'CronCreate',
45
- description: 'Create a scheduled recurring task (cron job). Supports cron expressions for scheduling.',
46
- inputSchema: {
47
- type: 'object',
48
- properties: {
49
- name: { type: 'string', description: 'Job name' },
50
- schedule: { type: 'string', description: 'Cron expression (e.g., "*/5 * * * *" for every 5 minutes)' },
51
- command: { type: 'string', description: 'Command or prompt to execute' },
52
- },
53
- required: ['name', 'schedule', 'command'],
54
- },
55
- isReadOnly: () => false,
56
- isConcurrencySafe: () => true,
57
- isEnabled: () => true,
58
- async prompt() { return 'Create a scheduled cron job.' },
59
- async call(input: any): Promise<ToolResult> {
60
- const id = `cron_${++cronCounter}`
61
- const job: CronJob = {
62
- id,
63
- name: input.name,
64
- schedule: input.schedule,
65
- command: input.command,
66
- enabled: true,
67
- createdAt: new Date().toISOString(),
68
- }
69
- cronStore.set(id, job)
70
-
71
- return {
72
- type: 'tool_result',
73
- tool_use_id: '',
74
- content: `Cron job created: ${id} "${job.name}" schedule="${job.schedule}"`,
75
- }
76
- },
77
- }
78
-
79
- export const CronDeleteTool: ToolDefinition = {
80
- name: 'CronDelete',
81
- description: 'Delete a scheduled cron job.',
82
- inputSchema: {
83
- type: 'object',
84
- properties: {
85
- id: { type: 'string', description: 'Cron job ID to delete' },
86
- },
87
- required: ['id'],
88
- },
89
- isReadOnly: () => false,
90
- isConcurrencySafe: () => true,
91
- isEnabled: () => true,
92
- async prompt() { return 'Delete a cron job.' },
93
- async call(input: any): Promise<ToolResult> {
94
- if (!cronStore.has(input.id)) {
95
- return { type: 'tool_result', tool_use_id: '', content: `Cron job not found: ${input.id}`, is_error: true }
96
- }
97
- cronStore.delete(input.id)
98
- return { type: 'tool_result', tool_use_id: '', content: `Cron job deleted: ${input.id}` }
99
- },
100
- }
101
-
102
- export const CronListTool: ToolDefinition = {
103
- name: 'CronList',
104
- description: 'List all scheduled cron jobs.',
105
- inputSchema: { type: 'object', properties: {} },
106
- isReadOnly: () => true,
107
- isConcurrencySafe: () => true,
108
- isEnabled: () => true,
109
- async prompt() { return 'List cron jobs.' },
110
- async call(): Promise<ToolResult> {
111
- const jobs = getAllCronJobs()
112
- if (jobs.length === 0) {
113
- return { type: 'tool_result', tool_use_id: '', content: 'No cron jobs scheduled.' }
114
- }
115
- const lines = jobs.map(j =>
116
- `[${j.id}] ${j.enabled ? '✓' : '✗'} "${j.name}" schedule="${j.schedule}" command="${j.command.slice(0, 50)}"`
117
- )
118
- return { type: 'tool_result', tool_use_id: '', content: lines.join('\n') }
119
- },
120
- }
121
-
122
- export const RemoteTriggerTool: ToolDefinition = {
123
- name: 'RemoteTrigger',
124
- description: 'Manage remote scheduled agent triggers. Supports list, get, create, update, and run operations.',
125
- inputSchema: {
126
- type: 'object',
127
- properties: {
128
- action: {
129
- type: 'string',
130
- enum: ['list', 'get', 'create', 'update', 'run'],
131
- description: 'Operation to perform',
132
- },
133
- id: { type: 'string', description: 'Trigger ID (for get/update/run)' },
134
- name: { type: 'string', description: 'Trigger name (for create)' },
135
- schedule: { type: 'string', description: 'Cron schedule (for create/update)' },
136
- prompt: { type: 'string', description: 'Agent prompt (for create/update)' },
137
- },
138
- required: ['action'],
139
- },
140
- isReadOnly: () => false,
141
- isConcurrencySafe: () => true,
142
- isEnabled: () => true,
143
- async prompt() { return 'Manage remote agent triggers.' },
144
- async call(input: any): Promise<ToolResult> {
145
- // RemoteTrigger operations are typically handled by the remote backend
146
- // In standalone SDK mode, we provide a stub implementation
147
- return {
148
- type: 'tool_result',
149
- tool_use_id: '',
150
- content: `RemoteTrigger ${input.action}: This feature requires a connected remote backend. In standalone SDK mode, use CronCreate/CronList/CronDelete for local scheduling.`,
151
- }
152
- },
153
- }