@codeany/open-agent-sdk 0.2.2 → 0.2.3

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 +446 -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 +423 -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
package/dist/hooks.js ADDED
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Hook System
3
+ *
4
+ * Lifecycle hooks for intercepting agent behavior.
5
+ * Supports pre/post tool use, session lifecycle, and custom events.
6
+ *
7
+ * Hook events:
8
+ * - PreToolUse: before tool execution
9
+ * - PostToolUse: after tool execution
10
+ * - PostToolUseFailure: after tool failure
11
+ * - SessionStart: session initialization
12
+ * - SessionEnd: session cleanup
13
+ * - Stop: when turn completes
14
+ * - SubagentStart: subagent spawned
15
+ * - SubagentStop: subagent completed
16
+ * - UserPromptSubmit: user sends message
17
+ * - PermissionRequest: permission check triggered
18
+ * - TaskCreated: task created
19
+ * - TaskCompleted: task finished
20
+ * - ConfigChange: settings changed
21
+ * - CwdChanged: working directory changed
22
+ * - FileChanged: file modified
23
+ * - Notification: system notification
24
+ */
25
+ import { spawn } from 'child_process';
26
+ /**
27
+ * All supported hook events.
28
+ */
29
+ export const HOOK_EVENTS = [
30
+ 'PreToolUse',
31
+ 'PostToolUse',
32
+ 'PostToolUseFailure',
33
+ 'SessionStart',
34
+ 'SessionEnd',
35
+ 'Stop',
36
+ 'SubagentStart',
37
+ 'SubagentStop',
38
+ 'UserPromptSubmit',
39
+ 'PermissionRequest',
40
+ 'PermissionDenied',
41
+ 'TaskCreated',
42
+ 'TaskCompleted',
43
+ 'ConfigChange',
44
+ 'CwdChanged',
45
+ 'FileChanged',
46
+ 'Notification',
47
+ 'PreCompact',
48
+ 'PostCompact',
49
+ 'TeammateIdle',
50
+ ];
51
+ /**
52
+ * Hook registry for managing and executing hooks.
53
+ */
54
+ export class HookRegistry {
55
+ hooks = new Map();
56
+ /**
57
+ * Register hooks from configuration.
58
+ */
59
+ registerFromConfig(config) {
60
+ for (const [event, definitions] of Object.entries(config)) {
61
+ const hookEvent = event;
62
+ if (!HOOK_EVENTS.includes(hookEvent))
63
+ continue;
64
+ const existing = this.hooks.get(hookEvent) || [];
65
+ this.hooks.set(hookEvent, [...existing, ...definitions]);
66
+ }
67
+ }
68
+ /**
69
+ * Register a single hook.
70
+ */
71
+ register(event, definition) {
72
+ const existing = this.hooks.get(event) || [];
73
+ existing.push(definition);
74
+ this.hooks.set(event, existing);
75
+ }
76
+ /**
77
+ * Execute hooks for an event.
78
+ */
79
+ async execute(event, input) {
80
+ const definitions = this.hooks.get(event) || [];
81
+ const results = [];
82
+ for (const def of definitions) {
83
+ // Check matcher for tool-specific hooks
84
+ if (def.matcher && input.toolName) {
85
+ const regex = new RegExp(def.matcher);
86
+ if (!regex.test(input.toolName))
87
+ continue;
88
+ }
89
+ try {
90
+ let output = undefined;
91
+ if (def.handler) {
92
+ // Function handler
93
+ output = await Promise.race([
94
+ def.handler(input),
95
+ new Promise((_, reject) => setTimeout(() => reject(new Error('Hook timeout')), def.timeout || 30000)),
96
+ ]);
97
+ }
98
+ else if (def.command) {
99
+ // Shell command handler
100
+ output = await executeShellHook(def.command, input, def.timeout || 30000);
101
+ }
102
+ if (output) {
103
+ results.push(output);
104
+ }
105
+ }
106
+ catch (err) {
107
+ // Log but don't fail on hook errors
108
+ console.error(`[Hook] ${event} hook failed: ${err.message}`);
109
+ }
110
+ }
111
+ return results;
112
+ }
113
+ /**
114
+ * Check if any hooks are registered for an event.
115
+ */
116
+ hasHooks(event) {
117
+ return (this.hooks.get(event)?.length || 0) > 0;
118
+ }
119
+ /**
120
+ * Clear all hooks.
121
+ */
122
+ clear() {
123
+ this.hooks.clear();
124
+ }
125
+ }
126
+ /**
127
+ * Execute a shell command as a hook.
128
+ */
129
+ async function executeShellHook(command, input, timeout) {
130
+ return new Promise((resolve) => {
131
+ const proc = spawn('bash', ['-c', command], {
132
+ timeout,
133
+ env: {
134
+ ...process.env,
135
+ HOOK_EVENT: input.event,
136
+ HOOK_TOOL_NAME: input.toolName || '',
137
+ HOOK_SESSION_ID: input.sessionId || '',
138
+ HOOK_CWD: input.cwd || '',
139
+ },
140
+ stdio: ['pipe', 'pipe', 'pipe'],
141
+ });
142
+ // Send input as JSON on stdin
143
+ proc.stdin?.write(JSON.stringify(input));
144
+ proc.stdin?.end();
145
+ const chunks = [];
146
+ proc.stdout?.on('data', (d) => chunks.push(d));
147
+ proc.on('close', (code) => {
148
+ if (code !== 0) {
149
+ resolve(undefined);
150
+ return;
151
+ }
152
+ const stdout = Buffer.concat(chunks).toString('utf-8').trim();
153
+ if (!stdout) {
154
+ resolve(undefined);
155
+ return;
156
+ }
157
+ try {
158
+ const output = JSON.parse(stdout);
159
+ resolve(output);
160
+ }
161
+ catch {
162
+ // Non-JSON output treated as message
163
+ resolve({ message: stdout });
164
+ }
165
+ });
166
+ proc.on('error', () => resolve(undefined));
167
+ });
168
+ }
169
+ /**
170
+ * Create a default hook registry.
171
+ */
172
+ export function createHookRegistry(config) {
173
+ const registry = new HookRegistry();
174
+ if (config) {
175
+ registry.registerFromConfig(config);
176
+ }
177
+ return registry;
178
+ }
179
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,KAAK,EAAqB,MAAM,eAAe,CAAA;AAExD;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,YAAY;IACZ,aAAa;IACb,oBAAoB;IACpB,cAAc;IACd,YAAY;IACZ,MAAM;IACN,eAAe;IACf,cAAc;IACd,kBAAkB;IAClB,mBAAmB;IACnB,kBAAkB;IAClB,aAAa;IACb,eAAe;IACf,cAAc;IACd,YAAY;IACZ,aAAa;IACb,cAAc;IACd,YAAY;IACZ,aAAa;IACb,cAAc;CACN,CAAA;AA2DV;;GAEG;AACH,MAAM,OAAO,YAAY;IACf,KAAK,GAAqC,IAAI,GAAG,EAAE,CAAA;IAE3D;;OAEG;IACH,kBAAkB,CAAC,MAAkB;QACnC,KAAK,MAAM,CAAC,KAAK,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1D,MAAM,SAAS,GAAG,KAAkB,CAAA;YACpC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAAE,SAAQ;YAE9C,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,EAAE,CAAA;YAChD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,GAAG,QAAQ,EAAE,GAAG,WAAW,CAAC,CAAC,CAAA;QAC1D,CAAC;IACH,CAAC;IAED;;OAEG;IACH,QAAQ,CAAC,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,QAAQ,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAA;IACrC,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
@@ -0,0 +1,66 @@
1
+ /**
2
+ * @codeany/open-agent-sdk
3
+ *
4
+ * Open-source Agent SDK by CodeAny (https://codeany.ai).
5
+ * Runs the full agent loop in-process without spawning subprocesses.
6
+ *
7
+ * Features:
8
+ * - 30+ built-in tools (file I/O, shell, web, agents, tasks, teams, etc.)
9
+ * - Skill system (reusable prompt templates with bundled skills)
10
+ * - MCP server integration (stdio, SSE, HTTP)
11
+ * - Context compression (auto-compact, micro-compact)
12
+ * - Retry with exponential backoff
13
+ * - Git status & project context injection
14
+ * - Multi-turn session persistence
15
+ * - Permission system (allow/deny/bypass modes)
16
+ * - Subagent spawning & team coordination
17
+ * - Task management & scheduling
18
+ * - Hook system with lifecycle integration (pre/post tool use, session, compact)
19
+ * - Token estimation & cost tracking
20
+ * - File state LRU caching
21
+ * - Plan mode for structured workflows
22
+ */
23
+ export { Agent, createAgent, query } from './agent.js';
24
+ export { tool, sdkToolToToolDefinition } from './tool-helper.js';
25
+ export type { ToolAnnotations, CallToolResult, SdkMcpToolDefinition, } from './tool-helper.js';
26
+ export { createSdkMcpServer, isSdkServerConfig } from './sdk-mcp-server.js';
27
+ export type { McpSdkServerConfig } from './sdk-mcp-server.js';
28
+ export { QueryEngine } from './engine.js';
29
+ export { createProvider, AnthropicProvider, OpenAIProvider, } from './providers/index.js';
30
+ export type { ApiType, LLMProvider, CreateMessageParams, CreateMessageResponse, NormalizedMessageParam, NormalizedContentBlock, NormalizedTool, NormalizedResponseBlock, } from './providers/index.js';
31
+ export { getAllBaseTools, filterTools, assembleToolPool, defineTool, toApiTool, BashTool, FileReadTool, FileWriteTool, FileEditTool, GlobTool, GrepTool, NotebookEditTool, WebFetchTool, WebSearchTool, AgentTool, SendMessageTool, TeamCreateTool, TeamDeleteTool, TaskCreateTool, TaskListTool, TaskUpdateTool, TaskGetTool, TaskStopTool, TaskOutputTool, EnterWorktreeTool, ExitWorktreeTool, EnterPlanModeTool, ExitPlanModeTool, AskUserQuestionTool, ToolSearchTool, ListMcpResourcesTool, ReadMcpResourceTool, CronCreateTool, CronDeleteTool, CronListTool, RemoteTriggerTool, LSPTool, ConfigTool, TodoWriteTool, SkillTool, } from './tools/index.js';
32
+ export { connectMCPServer, closeAllConnections } from './mcp/client.js';
33
+ export type { MCPConnection } from './mcp/client.js';
34
+ export { registerSkill, getSkill, getAllSkills, getUserInvocableSkills, hasSkill, unregisterSkill, clearSkills, formatSkillsForPrompt, initBundledSkills, } from './skills/index.js';
35
+ export type { SkillDefinition, SkillContentBlock, SkillResult, } from './skills/index.js';
36
+ export { HookRegistry, createHookRegistry, HOOK_EVENTS, } from './hooks.js';
37
+ export type { HookEvent, HookDefinition, HookInput, HookOutput, HookConfig, } from './hooks.js';
38
+ export { saveSession, loadSession, listSessions, forkSession, getSessionMessages, getSessionInfo, renameSession, tagSession, appendToSession, deleteSession, } from './session.js';
39
+ export type { SessionMetadata, SessionData } from './session.js';
40
+ export { getSystemContext, getUserContext, getGitStatus, readProjectContextContent, discoverProjectContextFiles, clearContextCache, } from './utils/context.js';
41
+ export { createUserMessage, createAssistantMessage, normalizeMessagesForAPI, stripImagesFromMessages, extractTextFromContent, createCompactBoundaryMessage, truncateText, } from './utils/messages.js';
42
+ export { estimateTokens, estimateMessagesTokens, estimateSystemPromptTokens, getTokenCountFromUsage, getContextWindowSize, getAutoCompactThreshold, estimateCost, MODEL_PRICING, AUTOCOMPACT_BUFFER_TOKENS, } from './utils/tokens.js';
43
+ export { shouldAutoCompact, compactConversation, microCompactMessages, createAutoCompactState, } from './utils/compact.js';
44
+ export type { AutoCompactState } from './utils/compact.js';
45
+ export { withRetry, isRetryableError, isPromptTooLongError, isAuthError, isRateLimitError, formatApiError, getRetryDelay, DEFAULT_RETRY_CONFIG, } from './utils/retry.js';
46
+ export type { RetryConfig } from './utils/retry.js';
47
+ export { FileStateCache, createFileStateCache, } from './utils/fileCache.js';
48
+ export type { FileState } from './utils/fileCache.js';
49
+ export { getAllTasks, getTask, clearTasks, } from './tools/task-tools.js';
50
+ export type { Task, TaskStatus } from './tools/task-tools.js';
51
+ export { getAllTeams, getTeam, clearTeams, } from './tools/team-tools.js';
52
+ export type { Team } from './tools/team-tools.js';
53
+ export { readMailbox, writeToMailbox, clearMailboxes, } from './tools/send-message.js';
54
+ export type { AgentMessage } from './tools/send-message.js';
55
+ export { isPlanModeActive, getCurrentPlan, } from './tools/plan-tools.js';
56
+ export { registerAgents, clearAgents, } from './tools/agent-tool.js';
57
+ export { setQuestionHandler, clearQuestionHandler, } from './tools/ask-user.js';
58
+ export { setDeferredTools, } from './tools/tool-search.js';
59
+ export { setMcpConnections, } from './tools/mcp-resource-tools.js';
60
+ export { getAllCronJobs, clearCronJobs, } from './tools/cron-tools.js';
61
+ export type { CronJob } from './tools/cron-tools.js';
62
+ export { getConfig, setConfig, clearConfig, } from './tools/config-tool.js';
63
+ export { getTodos, clearTodos, } from './tools/todo-tool.js';
64
+ export type { TodoItem } from './tools/todo-tool.js';
65
+ export type { Message, UserMessage, AssistantMessage, ConversationMessage, MessageRole, SDKMessage, SDKAssistantMessage, SDKToolResultMessage, SDKResultMessage, SDKPartialMessage, ToolDefinition, ToolInputSchema, ToolContext, ToolResult, PermissionMode, PermissionBehavior, CanUseToolFn, CanUseToolResult, McpServerConfig, McpStdioConfig, McpSseConfig, McpHttpConfig, AgentOptions, AgentDefinition, QueryResult, ThinkingConfig, TokenUsage, QueryEngineConfig, ContentBlockParam, ContentBlock, SandboxSettings, SandboxNetworkConfig, SandboxFilesystemConfig, OutputFormat, SettingSource, ModelInfo, } from './types.js';
66
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAMH,OAAO,EAAE,KAAK,EAAE,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,OAAO,EACP,WAAW,EACX,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EAGX,UAAU,EACV,mBAAmB,EACnB,oBAAoB,EACpB,gBAAgB,EAChB,iBAAiB,EAGjB,cAAc,EACd,eAAe,EACf,WAAW,EACX,UAAU,EAGV,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,gBAAgB,EAGhB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EAGb,YAAY,EACZ,eAAe,EACf,WAAW,EACX,cAAc,EACd,UAAU,EAGV,iBAAiB,EAGjB,iBAAiB,EACjB,YAAY,EAGZ,eAAe,EACf,oBAAoB,EACpB,uBAAuB,EAGvB,YAAY,EAGZ,aAAa,EAGb,SAAS,GACV,MAAM,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,133 @@
1
+ /**
2
+ * @codeany/open-agent-sdk
3
+ *
4
+ * Open-source Agent SDK by CodeAny (https://codeany.ai).
5
+ * Runs the full agent loop in-process without spawning subprocesses.
6
+ *
7
+ * Features:
8
+ * - 30+ built-in tools (file I/O, shell, web, agents, tasks, teams, etc.)
9
+ * - Skill system (reusable prompt templates with bundled skills)
10
+ * - MCP server integration (stdio, SSE, HTTP)
11
+ * - Context compression (auto-compact, micro-compact)
12
+ * - Retry with exponential backoff
13
+ * - Git status & project context injection
14
+ * - Multi-turn session persistence
15
+ * - Permission system (allow/deny/bypass modes)
16
+ * - Subagent spawning & team coordination
17
+ * - Task management & scheduling
18
+ * - Hook system with lifecycle integration (pre/post tool use, session, compact)
19
+ * - Token estimation & cost tracking
20
+ * - File state LRU caching
21
+ * - Plan mode for structured workflows
22
+ */
23
+ // --------------------------------------------------------------------------
24
+ // High-level Agent API
25
+ // --------------------------------------------------------------------------
26
+ export { Agent, createAgent, query } from './agent.js';
27
+ // --------------------------------------------------------------------------
28
+ // Tool Helper (Zod-based tool creation, compatible with official SDK)
29
+ // --------------------------------------------------------------------------
30
+ export { tool, sdkToolToToolDefinition } from './tool-helper.js';
31
+ // --------------------------------------------------------------------------
32
+ // In-Process MCP Server
33
+ // --------------------------------------------------------------------------
34
+ export { createSdkMcpServer, isSdkServerConfig } from './sdk-mcp-server.js';
35
+ // --------------------------------------------------------------------------
36
+ // Core Engine
37
+ // --------------------------------------------------------------------------
38
+ export { QueryEngine } from './engine.js';
39
+ // --------------------------------------------------------------------------
40
+ // LLM Providers (Anthropic + OpenAI)
41
+ // --------------------------------------------------------------------------
42
+ export { createProvider, AnthropicProvider, OpenAIProvider, } from './providers/index.js';
43
+ // --------------------------------------------------------------------------
44
+ // Tool System (30+ tools)
45
+ // --------------------------------------------------------------------------
46
+ export {
47
+ // Registry
48
+ getAllBaseTools, filterTools, assembleToolPool,
49
+ // Helpers
50
+ defineTool, toApiTool,
51
+ // Core file I/O & execution
52
+ BashTool, FileReadTool, FileWriteTool, FileEditTool, GlobTool, GrepTool, NotebookEditTool,
53
+ // Web
54
+ WebFetchTool, WebSearchTool,
55
+ // Agent & Multi-agent
56
+ AgentTool, SendMessageTool, TeamCreateTool, TeamDeleteTool,
57
+ // Tasks
58
+ TaskCreateTool, TaskListTool, TaskUpdateTool, TaskGetTool, TaskStopTool, TaskOutputTool,
59
+ // Worktree
60
+ EnterWorktreeTool, ExitWorktreeTool,
61
+ // Planning
62
+ EnterPlanModeTool, ExitPlanModeTool,
63
+ // User interaction
64
+ AskUserQuestionTool,
65
+ // Discovery
66
+ ToolSearchTool,
67
+ // MCP Resources
68
+ ListMcpResourcesTool, ReadMcpResourceTool,
69
+ // Scheduling
70
+ CronCreateTool, CronDeleteTool, CronListTool, RemoteTriggerTool,
71
+ // LSP
72
+ LSPTool,
73
+ // Config
74
+ ConfigTool,
75
+ // Todo
76
+ TodoWriteTool,
77
+ // Skill
78
+ SkillTool, } from './tools/index.js';
79
+ // --------------------------------------------------------------------------
80
+ // MCP Client
81
+ // --------------------------------------------------------------------------
82
+ export { connectMCPServer, closeAllConnections } from './mcp/client.js';
83
+ // --------------------------------------------------------------------------
84
+ // Skill System
85
+ // --------------------------------------------------------------------------
86
+ export { registerSkill, getSkill, getAllSkills, getUserInvocableSkills, hasSkill, unregisterSkill, clearSkills, formatSkillsForPrompt, initBundledSkills, } from './skills/index.js';
87
+ // --------------------------------------------------------------------------
88
+ // Hook System
89
+ // --------------------------------------------------------------------------
90
+ export { HookRegistry, createHookRegistry, HOOK_EVENTS, } from './hooks.js';
91
+ // --------------------------------------------------------------------------
92
+ // Session Management
93
+ // --------------------------------------------------------------------------
94
+ export { saveSession, loadSession, listSessions, forkSession, getSessionMessages, getSessionInfo, renameSession, tagSession, appendToSession, deleteSession, } from './session.js';
95
+ // --------------------------------------------------------------------------
96
+ // Context Utilities
97
+ // --------------------------------------------------------------------------
98
+ export { getSystemContext, getUserContext, getGitStatus, readProjectContextContent, discoverProjectContextFiles, clearContextCache, } from './utils/context.js';
99
+ // --------------------------------------------------------------------------
100
+ // Message Utilities
101
+ // --------------------------------------------------------------------------
102
+ export { createUserMessage, createAssistantMessage, normalizeMessagesForAPI, stripImagesFromMessages, extractTextFromContent, createCompactBoundaryMessage, truncateText, } from './utils/messages.js';
103
+ // --------------------------------------------------------------------------
104
+ // Token Estimation & Cost
105
+ // --------------------------------------------------------------------------
106
+ export { estimateTokens, estimateMessagesTokens, estimateSystemPromptTokens, getTokenCountFromUsage, getContextWindowSize, getAutoCompactThreshold, estimateCost, MODEL_PRICING, AUTOCOMPACT_BUFFER_TOKENS, } from './utils/tokens.js';
107
+ // --------------------------------------------------------------------------
108
+ // Context Compression
109
+ // --------------------------------------------------------------------------
110
+ export { shouldAutoCompact, compactConversation, microCompactMessages, createAutoCompactState, } from './utils/compact.js';
111
+ // --------------------------------------------------------------------------
112
+ // Retry Logic
113
+ // --------------------------------------------------------------------------
114
+ export { withRetry, isRetryableError, isPromptTooLongError, isAuthError, isRateLimitError, formatApiError, getRetryDelay, DEFAULT_RETRY_CONFIG, } from './utils/retry.js';
115
+ // --------------------------------------------------------------------------
116
+ // File State Cache
117
+ // --------------------------------------------------------------------------
118
+ export { FileStateCache, createFileStateCache, } from './utils/fileCache.js';
119
+ // --------------------------------------------------------------------------
120
+ // Task & Team State (for advanced usage)
121
+ // --------------------------------------------------------------------------
122
+ export { getAllTasks, getTask, clearTasks, } from './tools/task-tools.js';
123
+ export { getAllTeams, getTeam, clearTeams, } from './tools/team-tools.js';
124
+ export { readMailbox, writeToMailbox, clearMailboxes, } from './tools/send-message.js';
125
+ export { isPlanModeActive, getCurrentPlan, } from './tools/plan-tools.js';
126
+ export { registerAgents, clearAgents, } from './tools/agent-tool.js';
127
+ export { setQuestionHandler, clearQuestionHandler, } from './tools/ask-user.js';
128
+ export { setDeferredTools, } from './tools/tool-search.js';
129
+ export { setMcpConnections, } from './tools/mcp-resource-tools.js';
130
+ export { getAllCronJobs, clearCronJobs, } from './tools/cron-tools.js';
131
+ export { getConfig, setConfig, clearConfig, } from './tools/config-tool.js';
132
+ export { getTodos, clearTodos, } from './tools/todo-tool.js';
133
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,6EAA6E;AAC7E,uBAAuB;AACvB,6EAA6E;AAE7E,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAEtD,6EAA6E;AAC7E,sEAAsE;AACtE,6EAA6E;AAE7E,OAAO,EAAE,IAAI,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAA;AAOhE,6EAA6E;AAC7E,wBAAwB;AACxB,6EAA6E;AAE7E,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAA;AAG3E,6EAA6E;AAC7E,cAAc;AACd,6EAA6E;AAE7E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzC,6EAA6E;AAC7E,qCAAqC;AACrC,6EAA6E;AAE7E,OAAO,EACL,c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;AACzC,6EAA6E;AAE7E,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,GACX,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EACL,WAAW,EACX,OAAO,EACP,UAAU,GACX,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EACL,WAAW,EACX,cAAc,EACd,cAAc,GACf,MAAM,yBAAyB,CAAA;AAGhC,OAAO,EACL,gBAAgB,EAChB,cAAc,GACf,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,cAAc,EACd,WAAW,GACZ,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,qBAAqB,CAAA;AAE5B,OAAO,EACL,gBAAgB,GACjB,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,iBAAiB,GAClB,MAAM,+BAA+B,CAAA;AAEtC,OAAO,EACL,cAAc,EACd,aAAa,GACd,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EACL,SAAS,EACT,SAAS,EACT,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAE/B,OAAO,EACL,QAAQ,EACR,UAAU,GACX,MAAM,sBAAsB,CAAA"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * MCP Client - Connect to Model Context Protocol servers
3
+ */
4
+ import type { ToolDefinition, McpServerConfig } from '../types.js';
5
+ export interface MCPConnection {
6
+ name: string;
7
+ status: 'connected' | 'disconnected' | 'error';
8
+ tools: ToolDefinition[];
9
+ close: () => Promise<void>;
10
+ }
11
+ /**
12
+ * Connect to an MCP server and fetch its tools.
13
+ */
14
+ export declare function connectMCPServer(name: string, config: McpServerConfig): Promise<MCPConnection>;
15
+ /**
16
+ * Close all MCP connections.
17
+ */
18
+ export declare function closeAllConnections(connections: MCPConnection[]): Promise<void>;
19
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAA2B,MAAM,aAAa,CAAA;AAE3F,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,WAAW,GAAG,cAAc,GAAG,OAAO,CAAA;IAC9C,KAAK,EAAE,cAAc,EAAE,CAAA;IACvB,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;CAC3B;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,aAAa,CAAC,CAgExB;AA6DD;;GAEG;AACH,wBAAsB,mBAAmB,CAAC,WAAW,EAAE,aAAa,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * MCP Client - Connect to Model Context Protocol servers
3
+ */
4
+ /**
5
+ * Connect to an MCP server and fetch its tools.
6
+ */
7
+ export async function connectMCPServer(name, config) {
8
+ try {
9
+ const { Client } = await import('@modelcontextprotocol/sdk/client/index.js');
10
+ let transport;
11
+ if (!config.type || config.type === 'stdio') {
12
+ const stdioConfig = config;
13
+ const { StdioClientTransport } = await import('@modelcontextprotocol/sdk/client/stdio.js');
14
+ transport = new StdioClientTransport({
15
+ command: stdioConfig.command,
16
+ args: stdioConfig.args || [],
17
+ env: { ...process.env, ...stdioConfig.env },
18
+ });
19
+ }
20
+ else if (config.type === 'sse') {
21
+ const sseConfig = config;
22
+ const { SSEClientTransport } = await import('@modelcontextprotocol/sdk/client/sse.js');
23
+ transport = new SSEClientTransport(new URL(sseConfig.url), {
24
+ requestInit: sseConfig.headers ? { headers: sseConfig.headers } : undefined,
25
+ });
26
+ }
27
+ else if (config.type === 'http') {
28
+ const httpConfig = config;
29
+ const { StreamableHTTPClientTransport } = await import('@modelcontextprotocol/sdk/client/streamableHttp.js');
30
+ transport = new StreamableHTTPClientTransport(new URL(httpConfig.url), {
31
+ requestInit: httpConfig.headers ? { headers: httpConfig.headers } : undefined,
32
+ });
33
+ }
34
+ else {
35
+ throw new Error(`Unsupported MCP transport type: ${config.type}`);
36
+ }
37
+ const client = new Client({ name: `agent-sdk-${name}`, version: '1.0.0' }, { capabilities: {} });
38
+ await client.connect(transport);
39
+ // Fetch available tools
40
+ const toolList = await client.listTools();
41
+ const tools = (toolList.tools || []).map((mcpTool) => createMCPToolDefinition(name, mcpTool, client));
42
+ return {
43
+ name,
44
+ status: 'connected',
45
+ tools,
46
+ async close() {
47
+ try {
48
+ await client.close();
49
+ }
50
+ catch {
51
+ // ignore close errors
52
+ }
53
+ },
54
+ };
55
+ }
56
+ catch (err) {
57
+ console.error(`[MCP] Failed to connect to "${name}": ${err.message}`);
58
+ return {
59
+ name,
60
+ status: 'error',
61
+ tools: [],
62
+ async close() { },
63
+ };
64
+ }
65
+ }
66
+ /**
67
+ * Create a ToolDefinition wrapping an MCP server tool.
68
+ */
69
+ function createMCPToolDefinition(serverName, mcpTool, client) {
70
+ const toolName = `mcp__${serverName}__${mcpTool.name}`;
71
+ return {
72
+ name: toolName,
73
+ description: mcpTool.description || `MCP tool: ${mcpTool.name} from ${serverName}`,
74
+ inputSchema: mcpTool.inputSchema || { type: 'object', properties: {} },
75
+ isReadOnly: () => false,
76
+ isConcurrencySafe: () => false,
77
+ isEnabled: () => true,
78
+ async prompt() {
79
+ return mcpTool.description || '';
80
+ },
81
+ async call(input) {
82
+ try {
83
+ const result = await client.callTool({
84
+ name: mcpTool.name,
85
+ arguments: input,
86
+ });
87
+ // Extract text content from MCP result
88
+ let output = '';
89
+ if (result.content) {
90
+ for (const block of result.content) {
91
+ if (block.type === 'text') {
92
+ output += block.text;
93
+ }
94
+ else {
95
+ output += JSON.stringify(block);
96
+ }
97
+ }
98
+ }
99
+ else {
100
+ output = JSON.stringify(result);
101
+ }
102
+ return {
103
+ type: 'tool_result',
104
+ tool_use_id: '',
105
+ content: output,
106
+ is_error: result.isError || false,
107
+ };
108
+ }
109
+ catch (err) {
110
+ return {
111
+ type: 'tool_result',
112
+ tool_use_id: '',
113
+ content: `MCP tool error: ${err.message}`,
114
+ is_error: true,
115
+ };
116
+ }
117
+ },
118
+ };
119
+ }
120
+ /**
121
+ * Close all MCP connections.
122
+ */
123
+ export async function closeAllConnections(connections) {
124
+ await Promise.allSettled(connections.map((c) => c.close()));
125
+ }
126
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/mcp/client.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,MAAuB;IAEvB,IAAI,CAAC;QACH,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,2CAA2C,CAAC,CAAA;QAE5E,IAAI,SAAc,CAAA;QAElB,IAAI,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC5C,MAAM,WAAW,GAAG,MAA4E,CAAA;YAChG,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAAC,2CAA2C,CAAC,CAAA;YAC1F,SAAS,GAAG,IAAI,oBAAoB,CAAC;gBACnC,OAAO,EAAE,WAAW,CAAC,OAAO;gBAC5B,IAAI,EAAE,WAAW,CAAC,IAAI,IAAI,EAAE;gBAC5B,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,GAAG,WAAW,CAAC,GAAG,EAA4B;aACtE,CAAC,CAAA;QACJ,CAAC;aAAM,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,EAAE,CAAC;YACjC,MAAM,SAAS,GAAG,MAA2D,CAAA;YAC7E,MAAM,EAAE,kBAAkB,EAAE,GAAG,MAAM,MAAM,CAAC,yCAAyC,CAAC,CAAA;YACtF,SAAS,GAAG,IAAI,kBAAkB,CAAC,IAAI,GAAG,CAAC,SAAS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,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;oBACnB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;wBACnC,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;4BAC1B,MAAM,IAAI,KAAK,CAAC,IAAI,CAAA;wBACtB,CAAC;6BAAM,CAAC;4BACN,MAAM,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;wBACjC,CAAC;oBACH,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;gBACjC,CAAC;gBAED,OAAO;oBACL,IAAI,EAAE,aAAa;oBACnB,WAAW,EAAE,EAAE;oBACf,OAAO,EAAE,MAAM;oBACf,QAAQ,EAAE,MAAM,CAAC,OAAO,IAAI,KAAK;iBAClC,CAAA;YACH,CAAC;YAAC,OAAO,GAAQ,EAAE,CAAC;gBAClB,OAAO;oBACL,IAAI,EAAE,aAAa;oBACnB,WAAW,EAAE,EAAE;oBACf,OAAO,EAAE,mBAAmB,GAAG,CAAC,OAAO,EAAE;oBACzC,QAAQ,EAAE,IAAI;iBACf,CAAA;YACH,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAA4B;IACpE,MAAM,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;AAC7D,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Anthropic Messages API Provider
3
+ *
4
+ * Wraps the @anthropic-ai/sdk client. Since our internal format is
5
+ * Anthropic-like, this is mostly a thin pass-through.
6
+ */
7
+ import type { LLMProvider, CreateMessageParams, CreateMessageResponse } from './types.js';
8
+ export declare class AnthropicProvider implements LLMProvider {
9
+ readonly apiType: "anthropic-messages";
10
+ private client;
11
+ constructor(opts: {
12
+ apiKey?: string;
13
+ baseURL?: string;
14
+ });
15
+ createMessage(params: CreateMessageParams): Promise<CreateMessageResponse>;
16
+ }
17
+ //# sourceMappingURL=anthropic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EACV,WAAW,EACX,mBAAmB,EACnB,qBAAqB,EACtB,MAAM,YAAY,CAAA;AAEnB,qBAAa,iBAAkB,YAAW,WAAW;IACnD,QAAQ,CAAC,OAAO,EAAG,oBAAoB,CAAS;IAChD,OAAO,CAAC,MAAM,CAAW;gBAEb,IAAI,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE;IAOjD,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAkCjF"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Anthropic Messages API Provider
3
+ *
4
+ * Wraps the @anthropic-ai/sdk client. Since our internal format is
5
+ * Anthropic-like, this is mostly a thin pass-through.
6
+ */
7
+ import Anthropic from '@anthropic-ai/sdk';
8
+ export class AnthropicProvider {
9
+ apiType = 'anthropic-messages';
10
+ client;
11
+ constructor(opts) {
12
+ this.client = new Anthropic({
13
+ apiKey: opts.apiKey,
14
+ baseURL: opts.baseURL,
15
+ });
16
+ }
17
+ async createMessage(params) {
18
+ const requestParams = {
19
+ model: params.model,
20
+ max_tokens: params.maxTokens,
21
+ system: params.system,
22
+ messages: params.messages,
23
+ tools: params.tools
24
+ ? params.tools
25
+ : undefined,
26
+ };
27
+ // Add extended thinking if configured
28
+ if (params.thinking?.type === 'enabled' && params.thinking.budget_tokens) {
29
+ requestParams.thinking = {
30
+ type: 'enabled',
31
+ budget_tokens: params.thinking.budget_tokens,
32
+ };
33
+ }
34
+ const response = await this.client.messages.create(requestParams);
35
+ return {
36
+ content: response.content,
37
+ stopReason: response.stop_reason || 'end_turn',
38
+ usage: {
39
+ input_tokens: response.usage.input_tokens,
40
+ output_tokens: response.usage.output_tokens,
41
+ cache_creation_input_tokens: response.usage.cache_creation_input_tokens,
42
+ cache_read_input_tokens: response.usage.cache_read_input_tokens,
43
+ },
44
+ };
45
+ }
46
+ }
47
+ //# sourceMappingURL=anthropic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.js","sourceRoot":"","sources":["../../src/providers/anthropic.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,SAAS,MAAM,mBAAmB,CAAA;AAOzC,MAAM,OAAO,iBAAiB;IACnB,OAAO,GAAG,oBAA6B,CAAA;IACxC,MAAM,CAAW;IAEzB,YAAY,IAA2C;QACrD,IAAI,CAAC,MAAM,GAAG,IAAI,SAAS,CAAC;YAC1B,MAAM,EAAE,IAAI,CAAC,MAAM;YACnB,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAA;IACJ,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAA2B;QAC7C,MAAM,aAAa,GAA8C;YAC/D,KAAK,EAAE,MAAM,CAAC,KAAK;YACnB,UAAU,EAAE,MAAM,CAAC,SAAS;YAC5B,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,QAAQ,EAAE,MAAM,CAAC,QAAoC;YACrD,KAAK,EAAE,MAAM,CAAC,KAAK;gBACjB,CAAC,CAAE,MAAM,CAAC,KAA0B;gBACpC,CAAC,CAAC,SAAS;SACd,CAAA;QAED,sCAAsC;QACtC,IAAI,MAAM,CAAC,QAAQ,EAAE,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC;YACxE,aAAqB,CAAC,QAAQ,GAAG;gBAChC,IAAI,EAAE,SAAS;gBACf,aAAa,EAAE,MAAM,CAAC,QAAQ,CAAC,aAAa;aAC7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