@puku-ai/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (336) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +251 -0
  3. package/dist/index.cjs +7 -0
  4. package/dist/index.d.ts +23 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +26 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/vendor/_vendor/partial-json-parser/parser.d.ts +3 -0
  9. package/dist/vendor/_vendor/partial-json-parser/parser.d.ts.map +1 -0
  10. package/dist/vendor/_vendor/partial-json-parser/parser.js +223 -0
  11. package/dist/vendor/_vendor/partial-json-parser/parser.js.map +1 -0
  12. package/dist/vendor/api-promise.d.ts +3 -0
  13. package/dist/vendor/api-promise.d.ts.map +1 -0
  14. package/dist/vendor/api-promise.js +3 -0
  15. package/dist/vendor/api-promise.js.map +1 -0
  16. package/dist/vendor/client.d.ts +248 -0
  17. package/dist/vendor/client.d.ts.map +1 -0
  18. package/dist/vendor/client.js +567 -0
  19. package/dist/vendor/client.js.map +1 -0
  20. package/dist/vendor/core/api-promise.d.ts +49 -0
  21. package/dist/vendor/core/api-promise.d.ts.map +1 -0
  22. package/dist/vendor/core/api-promise.js +72 -0
  23. package/dist/vendor/core/api-promise.js.map +1 -0
  24. package/dist/vendor/core/error.d.ts +50 -0
  25. package/dist/vendor/core/error.d.ts.map +1 -0
  26. package/dist/vendor/core/error.js +109 -0
  27. package/dist/vendor/core/error.js.map +1 -0
  28. package/dist/vendor/core/pagination.d.ts +105 -0
  29. package/dist/vendor/core/pagination.d.ts.map +1 -0
  30. package/dist/vendor/core/pagination.js +188 -0
  31. package/dist/vendor/core/pagination.js.map +1 -0
  32. package/dist/vendor/core/resource.d.ts +6 -0
  33. package/dist/vendor/core/resource.d.ts.map +1 -0
  34. package/dist/vendor/core/resource.js +8 -0
  35. package/dist/vendor/core/resource.js.map +1 -0
  36. package/dist/vendor/core/streaming.d.ts +33 -0
  37. package/dist/vendor/core/streaming.d.ts.map +1 -0
  38. package/dist/vendor/core/streaming.js +288 -0
  39. package/dist/vendor/core/streaming.js.map +1 -0
  40. package/dist/vendor/core/uploads.d.ts +3 -0
  41. package/dist/vendor/core/uploads.d.ts.map +1 -0
  42. package/dist/vendor/core/uploads.js +2 -0
  43. package/dist/vendor/core/uploads.js.map +1 -0
  44. package/dist/vendor/error.d.ts +3 -0
  45. package/dist/vendor/error.d.ts.map +1 -0
  46. package/dist/vendor/error.js +3 -0
  47. package/dist/vendor/error.js.map +1 -0
  48. package/dist/vendor/helpers/beta/json-schema.d.ts +31 -0
  49. package/dist/vendor/helpers/beta/json-schema.d.ts.map +1 -0
  50. package/dist/vendor/helpers/beta/json-schema.js +52 -0
  51. package/dist/vendor/helpers/beta/json-schema.js.map +1 -0
  52. package/dist/vendor/helpers/beta/mcp.d.ts +303 -0
  53. package/dist/vendor/helpers/beta/mcp.d.ts.map +1 -0
  54. package/dist/vendor/helpers/beta/mcp.js +406 -0
  55. package/dist/vendor/helpers/beta/mcp.js.map +1 -0
  56. package/dist/vendor/helpers/beta/memory.d.ts +11 -0
  57. package/dist/vendor/helpers/beta/memory.d.ts.map +1 -0
  58. package/dist/vendor/helpers/beta/memory.js +15 -0
  59. package/dist/vendor/helpers/beta/memory.js.map +1 -0
  60. package/dist/vendor/helpers/beta/zod.d.ts +7 -0
  61. package/dist/vendor/helpers/beta/zod.d.ts.map +1 -0
  62. package/dist/vendor/helpers/beta/zod.js +15 -0
  63. package/dist/vendor/helpers/beta/zod.js.map +1 -0
  64. package/dist/vendor/helpers/index.d.ts +3 -0
  65. package/dist/vendor/helpers/index.d.ts.map +1 -0
  66. package/dist/vendor/helpers/index.js +3 -0
  67. package/dist/vendor/helpers/index.js.map +1 -0
  68. package/dist/vendor/helpers/json-schema.d.ts +18 -0
  69. package/dist/vendor/helpers/json-schema.d.ts.map +1 -0
  70. package/dist/vendor/helpers/json-schema.js +34 -0
  71. package/dist/vendor/helpers/json-schema.js.map +1 -0
  72. package/dist/vendor/helpers/zod.d.ts +13 -0
  73. package/dist/vendor/helpers/zod.d.ts.map +1 -0
  74. package/dist/vendor/helpers/zod.js +21 -0
  75. package/dist/vendor/helpers/zod.js.map +1 -0
  76. package/dist/vendor/index.d.ts +8 -0
  77. package/dist/vendor/index.d.ts.map +1 -0
  78. package/dist/vendor/index.js +8 -0
  79. package/dist/vendor/index.js.map +1 -0
  80. package/dist/vendor/internal/builtin-types.d.ts +73 -0
  81. package/dist/vendor/internal/builtin-types.d.ts.map +1 -0
  82. package/dist/vendor/internal/builtin-types.js +3 -0
  83. package/dist/vendor/internal/builtin-types.js.map +1 -0
  84. package/dist/vendor/internal/constants.d.ts +5 -0
  85. package/dist/vendor/internal/constants.d.ts.map +1 -0
  86. package/dist/vendor/internal/constants.js +15 -0
  87. package/dist/vendor/internal/constants.js.map +1 -0
  88. package/dist/vendor/internal/decoders/jsonl.d.ts +10 -0
  89. package/dist/vendor/internal/decoders/jsonl.d.ts.map +1 -0
  90. package/dist/vendor/internal/decoders/jsonl.js +37 -0
  91. package/dist/vendor/internal/decoders/jsonl.js.map +1 -0
  92. package/dist/vendor/internal/decoders/line.d.ts +17 -0
  93. package/dist/vendor/internal/decoders/line.d.ts.map +1 -0
  94. package/dist/vendor/internal/decoders/line.js +105 -0
  95. package/dist/vendor/internal/decoders/line.js.map +1 -0
  96. package/dist/vendor/internal/detect-platform.d.ts +15 -0
  97. package/dist/vendor/internal/detect-platform.d.ts.map +1 -0
  98. package/dist/vendor/internal/detect-platform.js +157 -0
  99. package/dist/vendor/internal/detect-platform.js.map +1 -0
  100. package/dist/vendor/internal/errors.d.ts +3 -0
  101. package/dist/vendor/internal/errors.d.ts.map +1 -0
  102. package/dist/vendor/internal/errors.js +36 -0
  103. package/dist/vendor/internal/errors.js.map +1 -0
  104. package/dist/vendor/internal/headers.d.ts +22 -0
  105. package/dist/vendor/internal/headers.d.ts.map +1 -0
  106. package/dist/vendor/internal/headers.js +74 -0
  107. package/dist/vendor/internal/headers.js.map +1 -0
  108. package/dist/vendor/internal/parse.d.ts +17 -0
  109. package/dist/vendor/internal/parse.d.ts.map +1 -0
  110. package/dist/vendor/internal/parse.js +56 -0
  111. package/dist/vendor/internal/parse.js.map +1 -0
  112. package/dist/vendor/internal/request-options.d.ts +77 -0
  113. package/dist/vendor/internal/request-options.d.ts.map +1 -0
  114. package/dist/vendor/internal/request-options.js +10 -0
  115. package/dist/vendor/internal/request-options.js.map +1 -0
  116. package/dist/vendor/internal/shim-types.d.ts +17 -0
  117. package/dist/vendor/internal/shim-types.d.ts.map +1 -0
  118. package/dist/vendor/internal/shim-types.js +3 -0
  119. package/dist/vendor/internal/shim-types.js.map +1 -0
  120. package/dist/vendor/internal/shims.d.ts +26 -0
  121. package/dist/vendor/internal/shims.d.ts.map +1 -0
  122. package/dist/vendor/internal/shims.js +85 -0
  123. package/dist/vendor/internal/shims.js.map +1 -0
  124. package/dist/vendor/internal/stream-utils.d.ts +8 -0
  125. package/dist/vendor/internal/stream-utils.d.ts.map +1 -0
  126. package/dist/vendor/internal/stream-utils.js +35 -0
  127. package/dist/vendor/internal/stream-utils.js.map +1 -0
  128. package/dist/vendor/internal/to-file.d.ts +45 -0
  129. package/dist/vendor/internal/to-file.d.ts.map +1 -0
  130. package/dist/vendor/internal/to-file.js +93 -0
  131. package/dist/vendor/internal/to-file.js.map +1 -0
  132. package/dist/vendor/internal/types.d.ts +69 -0
  133. package/dist/vendor/internal/types.d.ts.map +1 -0
  134. package/dist/vendor/internal/types.js +3 -0
  135. package/dist/vendor/internal/types.js.map +1 -0
  136. package/dist/vendor/internal/uploads.d.ts +42 -0
  137. package/dist/vendor/internal/uploads.d.ts.map +1 -0
  138. package/dist/vendor/internal/uploads.js +135 -0
  139. package/dist/vendor/internal/uploads.js.map +1 -0
  140. package/dist/vendor/internal/utils/base64.d.ts +3 -0
  141. package/dist/vendor/internal/utils/base64.d.ts.map +1 -0
  142. package/dist/vendor/internal/utils/base64.js +33 -0
  143. package/dist/vendor/internal/utils/base64.js.map +1 -0
  144. package/dist/vendor/internal/utils/bytes.d.ts +4 -0
  145. package/dist/vendor/internal/utils/bytes.d.ts.map +1 -0
  146. package/dist/vendor/internal/utils/bytes.js +26 -0
  147. package/dist/vendor/internal/utils/bytes.js.map +1 -0
  148. package/dist/vendor/internal/utils/env.d.ts +9 -0
  149. package/dist/vendor/internal/utils/env.d.ts.map +1 -0
  150. package/dist/vendor/internal/utils/env.js +18 -0
  151. package/dist/vendor/internal/utils/env.js.map +1 -0
  152. package/dist/vendor/internal/utils/log.d.ts +37 -0
  153. package/dist/vendor/internal/utils/log.d.ts.map +1 -0
  154. package/dist/vendor/internal/utils/log.js +80 -0
  155. package/dist/vendor/internal/utils/log.js.map +1 -0
  156. package/dist/vendor/internal/utils/path.d.ts +15 -0
  157. package/dist/vendor/internal/utils/path.d.ts.map +1 -0
  158. package/dist/vendor/internal/utils/path.js +74 -0
  159. package/dist/vendor/internal/utils/path.js.map +1 -0
  160. package/dist/vendor/internal/utils/query.d.ts +5 -0
  161. package/dist/vendor/internal/utils/query.d.ts.map +1 -0
  162. package/dist/vendor/internal/utils/query.js +20 -0
  163. package/dist/vendor/internal/utils/query.js.map +1 -0
  164. package/dist/vendor/internal/utils/sleep.d.ts +2 -0
  165. package/dist/vendor/internal/utils/sleep.d.ts.map +1 -0
  166. package/dist/vendor/internal/utils/sleep.js +3 -0
  167. package/dist/vendor/internal/utils/sleep.js.map +1 -0
  168. package/dist/vendor/internal/utils/uuid.d.ts +5 -0
  169. package/dist/vendor/internal/utils/uuid.d.ts.map +1 -0
  170. package/dist/vendor/internal/utils/uuid.js +15 -0
  171. package/dist/vendor/internal/utils/uuid.js.map +1 -0
  172. package/dist/vendor/internal/utils/values.d.ts +19 -0
  173. package/dist/vendor/internal/utils/values.d.ts.map +1 -0
  174. package/dist/vendor/internal/utils/values.js +100 -0
  175. package/dist/vendor/internal/utils/values.js.map +1 -0
  176. package/dist/vendor/internal/utils.d.ts +8 -0
  177. package/dist/vendor/internal/utils.d.ts.map +1 -0
  178. package/dist/vendor/internal/utils.js +9 -0
  179. package/dist/vendor/internal/utils.js.map +1 -0
  180. package/dist/vendor/lib/BetaMessageStream.d.ts +122 -0
  181. package/dist/vendor/lib/BetaMessageStream.d.ts.map +1 -0
  182. package/dist/vendor/lib/BetaMessageStream.js +624 -0
  183. package/dist/vendor/lib/BetaMessageStream.js.map +1 -0
  184. package/dist/vendor/lib/MessageStream.d.ts +121 -0
  185. package/dist/vendor/lib/MessageStream.d.ts.map +1 -0
  186. package/dist/vendor/lib/MessageStream.js +599 -0
  187. package/dist/vendor/lib/MessageStream.js.map +1 -0
  188. package/dist/vendor/lib/beta-parser.d.ts +37 -0
  189. package/dist/vendor/lib/beta-parser.d.ts.map +1 -0
  190. package/dist/vendor/lib/beta-parser.js +75 -0
  191. package/dist/vendor/lib/beta-parser.js.map +1 -0
  192. package/dist/vendor/lib/parser.d.ts +32 -0
  193. package/dist/vendor/lib/parser.d.ts.map +1 -0
  194. package/dist/vendor/lib/parser.js +62 -0
  195. package/dist/vendor/lib/parser.js.map +1 -0
  196. package/dist/vendor/lib/stainless-helper-header.d.ts +34 -0
  197. package/dist/vendor/lib/stainless-helper-header.d.ts.map +1 -0
  198. package/dist/vendor/lib/stainless-helper-header.js +63 -0
  199. package/dist/vendor/lib/stainless-helper-header.js.map +1 -0
  200. package/dist/vendor/lib/tools/BetaRunnableTool.d.ts +12 -0
  201. package/dist/vendor/lib/tools/BetaRunnableTool.d.ts.map +1 -0
  202. package/dist/vendor/lib/tools/BetaRunnableTool.js +2 -0
  203. package/dist/vendor/lib/tools/BetaRunnableTool.js.map +1 -0
  204. package/dist/vendor/lib/tools/BetaToolRunner.d.ts +136 -0
  205. package/dist/vendor/lib/tools/BetaToolRunner.d.ts.map +1 -0
  206. package/dist/vendor/lib/tools/BetaToolRunner.js +370 -0
  207. package/dist/vendor/lib/tools/BetaToolRunner.js.map +1 -0
  208. package/dist/vendor/lib/tools/CompactionControl.d.ts +25 -0
  209. package/dist/vendor/lib/tools/CompactionControl.d.ts.map +1 -0
  210. package/dist/vendor/lib/tools/CompactionControl.js +25 -0
  211. package/dist/vendor/lib/tools/CompactionControl.js.map +1 -0
  212. package/dist/vendor/lib/tools/ToolError.d.ts +33 -0
  213. package/dist/vendor/lib/tools/ToolError.d.ts.map +1 -0
  214. package/dist/vendor/lib/tools/ToolError.js +43 -0
  215. package/dist/vendor/lib/tools/ToolError.js.map +1 -0
  216. package/dist/vendor/lib/tools/ToolRunner.d.ts +132 -0
  217. package/dist/vendor/lib/tools/ToolRunner.d.ts.map +1 -0
  218. package/dist/vendor/lib/tools/ToolRunner.js +287 -0
  219. package/dist/vendor/lib/tools/ToolRunner.js.map +1 -0
  220. package/dist/vendor/lib/transform-json-schema.d.ts +3 -0
  221. package/dist/vendor/lib/transform-json-schema.d.ts.map +1 -0
  222. package/dist/vendor/lib/transform-json-schema.js +111 -0
  223. package/dist/vendor/lib/transform-json-schema.js.map +1 -0
  224. package/dist/vendor/pagination.d.ts +3 -0
  225. package/dist/vendor/pagination.d.ts.map +1 -0
  226. package/dist/vendor/pagination.js +3 -0
  227. package/dist/vendor/pagination.js.map +1 -0
  228. package/dist/vendor/resource.d.ts +3 -0
  229. package/dist/vendor/resource.d.ts.map +1 -0
  230. package/dist/vendor/resource.js +3 -0
  231. package/dist/vendor/resource.js.map +1 -0
  232. package/dist/vendor/resources/beta/beta.d.ts +66 -0
  233. package/dist/vendor/resources/beta/beta.d.ts.map +1 -0
  234. package/dist/vendor/resources/beta/beta.js +21 -0
  235. package/dist/vendor/resources/beta/beta.js.map +1 -0
  236. package/dist/vendor/resources/beta/files.d.ts +151 -0
  237. package/dist/vendor/resources/beta/files.d.ts.map +1 -0
  238. package/dist/vendor/resources/beta/files.js +120 -0
  239. package/dist/vendor/resources/beta/files.js.map +1 -0
  240. package/dist/vendor/resources/beta/index.d.ts +6 -0
  241. package/dist/vendor/resources/beta/index.d.ts.map +1 -0
  242. package/dist/vendor/resources/beta/index.js +7 -0
  243. package/dist/vendor/resources/beta/index.js.map +1 -0
  244. package/dist/vendor/resources/beta/messages/batches.d.ts +646 -0
  245. package/dist/vendor/resources/beta/messages/batches.d.ts.map +1 -0
  246. package/dist/vendor/resources/beta/messages/batches.js +200 -0
  247. package/dist/vendor/resources/beta/messages/batches.js.map +1 -0
  248. package/dist/vendor/resources/beta/messages/index.d.ts +4 -0
  249. package/dist/vendor/resources/beta/messages/index.d.ts.map +1 -0
  250. package/dist/vendor/resources/beta/messages/index.js +5 -0
  251. package/dist/vendor/resources/beta/messages/index.js.map +1 -0
  252. package/dist/vendor/resources/beta/messages/messages.d.ts +2966 -0
  253. package/dist/vendor/resources/beta/messages/messages.d.ts.map +1 -0
  254. package/dist/vendor/resources/beta/messages/messages.js +153 -0
  255. package/dist/vendor/resources/beta/messages/messages.js.map +1 -0
  256. package/dist/vendor/resources/beta/messages.d.ts +2 -0
  257. package/dist/vendor/resources/beta/messages.d.ts.map +1 -0
  258. package/dist/vendor/resources/beta/messages.js +3 -0
  259. package/dist/vendor/resources/beta/messages.js.map +1 -0
  260. package/dist/vendor/resources/beta/models.d.ts +208 -0
  261. package/dist/vendor/resources/beta/models.d.ts.map +1 -0
  262. package/dist/vendor/resources/beta/models.js +56 -0
  263. package/dist/vendor/resources/beta/models.js.map +1 -0
  264. package/dist/vendor/resources/beta/skills/index.d.ts +3 -0
  265. package/dist/vendor/resources/beta/skills/index.d.ts.map +1 -0
  266. package/dist/vendor/resources/beta/skills/index.js +4 -0
  267. package/dist/vendor/resources/beta/skills/index.js.map +1 -0
  268. package/dist/vendor/resources/beta/skills/skills.d.ts +249 -0
  269. package/dist/vendor/resources/beta/skills/skills.d.ts.map +1 -0
  270. package/dist/vendor/resources/beta/skills/skills.js +90 -0
  271. package/dist/vendor/resources/beta/skills/skills.js.map +1 -0
  272. package/dist/vendor/resources/beta/skills/versions.d.ts +257 -0
  273. package/dist/vendor/resources/beta/skills/versions.d.ts.map +1 -0
  274. package/dist/vendor/resources/beta/skills/versions.js +96 -0
  275. package/dist/vendor/resources/beta/skills/versions.js.map +1 -0
  276. package/dist/vendor/resources/beta/skills.d.ts +2 -0
  277. package/dist/vendor/resources/beta/skills.d.ts.map +1 -0
  278. package/dist/vendor/resources/beta/skills.js +3 -0
  279. package/dist/vendor/resources/beta/skills.js.map +1 -0
  280. package/dist/vendor/resources/beta.d.ts +2 -0
  281. package/dist/vendor/resources/beta.d.ts.map +1 -0
  282. package/dist/vendor/resources/beta.js +3 -0
  283. package/dist/vendor/resources/beta.js.map +1 -0
  284. package/dist/vendor/resources/completions.d.ts +182 -0
  285. package/dist/vendor/resources/completions.d.ts.map +1 -0
  286. package/dist/vendor/resources/completions.js +19 -0
  287. package/dist/vendor/resources/completions.js.map +1 -0
  288. package/dist/vendor/resources/index.d.ts +6 -0
  289. package/dist/vendor/resources/index.d.ts.map +1 -0
  290. package/dist/vendor/resources/index.js +7 -0
  291. package/dist/vendor/resources/index.js.map +1 -0
  292. package/dist/vendor/resources/messages/batches.d.ts +304 -0
  293. package/dist/vendor/resources/messages/batches.d.ts.map +1 -0
  294. package/dist/vendor/resources/messages/batches.js +149 -0
  295. package/dist/vendor/resources/messages/batches.js.map +1 -0
  296. package/dist/vendor/resources/messages/index.d.ts +3 -0
  297. package/dist/vendor/resources/messages/index.d.ts.map +1 -0
  298. package/dist/vendor/resources/messages/index.js +4 -0
  299. package/dist/vendor/resources/messages/index.js.map +1 -0
  300. package/dist/vendor/resources/messages/messages.d.ts +2258 -0
  301. package/dist/vendor/resources/messages/messages.d.ts.map +1 -0
  302. package/dist/vendor/resources/messages/messages.js +120 -0
  303. package/dist/vendor/resources/messages/messages.js.map +1 -0
  304. package/dist/vendor/resources/messages.d.ts +2 -0
  305. package/dist/vendor/resources/messages.d.ts.map +1 -0
  306. package/dist/vendor/resources/messages.js +3 -0
  307. package/dist/vendor/resources/messages.js.map +1 -0
  308. package/dist/vendor/resources/models.d.ts +193 -0
  309. package/dist/vendor/resources/models.d.ts.map +1 -0
  310. package/dist/vendor/resources/models.js +41 -0
  311. package/dist/vendor/resources/models.js.map +1 -0
  312. package/dist/vendor/resources/shared.d.ts +44 -0
  313. package/dist/vendor/resources/shared.d.ts.map +1 -0
  314. package/dist/vendor/resources/shared.js +3 -0
  315. package/dist/vendor/resources/shared.js.map +1 -0
  316. package/dist/vendor/resources/top-level.d.ts +2 -0
  317. package/dist/vendor/resources/top-level.d.ts.map +1 -0
  318. package/dist/vendor/resources/top-level.js +3 -0
  319. package/dist/vendor/resources/top-level.js.map +1 -0
  320. package/dist/vendor/streaming.d.ts +3 -0
  321. package/dist/vendor/streaming.d.ts.map +1 -0
  322. package/dist/vendor/streaming.js +3 -0
  323. package/dist/vendor/streaming.js.map +1 -0
  324. package/dist/vendor/tools/memory/node.d.ts +18 -0
  325. package/dist/vendor/tools/memory/node.d.ts.map +1 -0
  326. package/dist/vendor/tools/memory/node.js +320 -0
  327. package/dist/vendor/tools/memory/node.js.map +1 -0
  328. package/dist/vendor/uploads.d.ts +3 -0
  329. package/dist/vendor/uploads.d.ts.map +1 -0
  330. package/dist/vendor/uploads.js +3 -0
  331. package/dist/vendor/uploads.js.map +1 -0
  332. package/dist/vendor/version.d.ts +2 -0
  333. package/dist/vendor/version.d.ts.map +1 -0
  334. package/dist/vendor/version.js +2 -0
  335. package/dist/vendor/version.js.map +1 -0
  336. package/package.json +66 -0
@@ -0,0 +1,370 @@
1
+ import { ToolError } from './ToolError.js';
2
+ import { AnthropicError } from '../../core/error.js';
3
+ import { buildHeaders } from '../../internal/headers.js';
4
+ import { DEFAULT_SUMMARY_PROMPT, DEFAULT_TOKEN_THRESHOLD } from './CompactionControl.js';
5
+ import { collectStainlessHelpers } from '../stainless-helper-header.js';
6
+ /**
7
+ * Just Promise.withResolvers(), which is not available in all environments.
8
+ */
9
+ function promiseWithResolvers() {
10
+ let resolve;
11
+ let reject;
12
+ const promise = new Promise((res, rej) => {
13
+ resolve = res;
14
+ reject = rej;
15
+ });
16
+ return { promise, resolve: resolve, reject: reject };
17
+ }
18
+ /**
19
+ * A ToolRunner handles the automatic conversation loop between the assistant and tools.
20
+ *
21
+ * A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
22
+ * depending on the streaming configuration.
23
+ */
24
+ export class BetaToolRunner {
25
+ client;
26
+ /** Whether the async iterator has been consumed */
27
+ #consumed = false;
28
+ /** Whether parameters have been mutated since the last API call */
29
+ #mutated = false;
30
+ /** Current state containing the request parameters */
31
+ #state;
32
+ #options;
33
+ /** Promise for the last message received from the assistant */
34
+ #message;
35
+ /** Cached tool response to avoid redundant executions */
36
+ #toolResponse;
37
+ /** Promise resolvers for waiting on completion */
38
+ #completion;
39
+ /** Number of iterations (API requests) made so far */
40
+ #iterationCount = 0;
41
+ constructor(client, params, options) {
42
+ this.client = client;
43
+ this.#state = {
44
+ params: {
45
+ // You can't clone the entire params since there are functions as handlers.
46
+ // You also don't really need to clone params.messages, but it probably will prevent a foot gun
47
+ // somewhere.
48
+ ...params,
49
+ messages: structuredClone(params.messages),
50
+ },
51
+ };
52
+ const helpers = collectStainlessHelpers(params.tools, params.messages);
53
+ const helperValue = ['BetaToolRunner', ...helpers].join(', ');
54
+ this.#options = {
55
+ ...options,
56
+ headers: buildHeaders([{ 'x-stainless-helper': helperValue }, options?.headers]),
57
+ };
58
+ this.#completion = promiseWithResolvers();
59
+ }
60
+ async #checkAndCompact() {
61
+ const compactionControl = this.#state.params.compactionControl;
62
+ if (!compactionControl || !compactionControl.enabled) {
63
+ return false;
64
+ }
65
+ let tokensUsed = 0;
66
+ if (this.#message !== undefined) {
67
+ try {
68
+ const message = await this.#message;
69
+ const totalInputTokens = message.usage.input_tokens +
70
+ (message.usage.cache_creation_input_tokens ?? 0) +
71
+ (message.usage.cache_read_input_tokens ?? 0);
72
+ tokensUsed = totalInputTokens + message.usage.output_tokens;
73
+ }
74
+ catch {
75
+ // If we can't get the message, skip compaction
76
+ return false;
77
+ }
78
+ }
79
+ const threshold = compactionControl.contextTokenThreshold ?? DEFAULT_TOKEN_THRESHOLD;
80
+ if (tokensUsed < threshold) {
81
+ return false;
82
+ }
83
+ const model = compactionControl.model ?? this.#state.params.model;
84
+ const summaryPrompt = compactionControl.summaryPrompt ?? DEFAULT_SUMMARY_PROMPT;
85
+ const messages = this.#state.params.messages;
86
+ if (messages[messages.length - 1].role === 'assistant') {
87
+ // Remove tool_use blocks from the last message to avoid 400 error
88
+ // (tool_use requires tool_result, which we don't have yet)
89
+ const lastMessage = messages[messages.length - 1];
90
+ if (Array.isArray(lastMessage.content)) {
91
+ const nonToolBlocks = lastMessage.content.filter((block) => block.type !== 'tool_use');
92
+ if (nonToolBlocks.length === 0) {
93
+ // If all blocks were tool_use, just remove the message entirely
94
+ messages.pop();
95
+ }
96
+ else {
97
+ lastMessage.content = nonToolBlocks;
98
+ }
99
+ }
100
+ }
101
+ const response = await this.client.beta.messages.create({
102
+ model,
103
+ messages: [
104
+ ...messages,
105
+ {
106
+ role: 'user',
107
+ content: [
108
+ {
109
+ type: 'text',
110
+ text: summaryPrompt,
111
+ },
112
+ ],
113
+ },
114
+ ],
115
+ max_tokens: this.#state.params.max_tokens,
116
+ }, {
117
+ headers: { 'x-stainless-helper': 'compaction' },
118
+ });
119
+ if (response.content[0]?.type !== 'text') {
120
+ throw new AnthropicError('Expected text response for compaction');
121
+ }
122
+ this.#state.params.messages = [
123
+ {
124
+ role: 'user',
125
+ content: response.content,
126
+ },
127
+ ];
128
+ return true;
129
+ }
130
+ async *[Symbol.asyncIterator]() {
131
+ if (this.#consumed) {
132
+ throw new AnthropicError('Cannot iterate over a consumed stream');
133
+ }
134
+ this.#consumed = true;
135
+ this.#mutated = true;
136
+ this.#toolResponse = undefined;
137
+ try {
138
+ while (true) {
139
+ let stream;
140
+ try {
141
+ if (this.#state.params.max_iterations &&
142
+ this.#iterationCount >= this.#state.params.max_iterations) {
143
+ break;
144
+ }
145
+ this.#mutated = false;
146
+ this.#toolResponse = undefined;
147
+ this.#iterationCount++;
148
+ this.#message = undefined;
149
+ const { max_iterations, compactionControl, ...params } = this.#state.params;
150
+ if (params.stream) {
151
+ stream = this.client.beta.messages.stream({ ...params }, this.#options);
152
+ this.#message = stream.finalMessage();
153
+ // Make sure that this promise doesn't throw before we get the option to do something about it.
154
+ // Error will be caught when we call await this.#message ultimately
155
+ this.#message.catch(() => { });
156
+ yield stream;
157
+ }
158
+ else {
159
+ this.#message = this.client.beta.messages.create({ ...params, stream: false }, this.#options);
160
+ yield this.#message;
161
+ }
162
+ const isCompacted = await this.#checkAndCompact();
163
+ if (!isCompacted) {
164
+ if (!this.#mutated) {
165
+ const { role, content } = await this.#message;
166
+ this.#state.params.messages.push({ role, content });
167
+ }
168
+ const toolMessage = await this.#generateToolResponse(this.#state.params.messages.at(-1));
169
+ if (toolMessage) {
170
+ this.#state.params.messages.push(toolMessage);
171
+ }
172
+ else if (!this.#mutated) {
173
+ break;
174
+ }
175
+ }
176
+ }
177
+ finally {
178
+ if (stream) {
179
+ stream.abort();
180
+ }
181
+ }
182
+ }
183
+ if (!this.#message) {
184
+ throw new AnthropicError('ToolRunner concluded without a message from the server');
185
+ }
186
+ this.#completion.resolve(await this.#message);
187
+ }
188
+ catch (error) {
189
+ this.#consumed = false;
190
+ // Silence unhandled promise errors
191
+ this.#completion.promise.catch(() => { });
192
+ this.#completion.reject(error);
193
+ this.#completion = promiseWithResolvers();
194
+ throw error;
195
+ }
196
+ }
197
+ setMessagesParams(paramsOrMutator) {
198
+ if (typeof paramsOrMutator === 'function') {
199
+ this.#state.params = paramsOrMutator(this.#state.params);
200
+ }
201
+ else {
202
+ this.#state.params = paramsOrMutator;
203
+ }
204
+ this.#mutated = true;
205
+ // Invalidate cached tool response since parameters changed
206
+ this.#toolResponse = undefined;
207
+ }
208
+ /**
209
+ * Get the tool response for the last message from the assistant.
210
+ * Avoids redundant tool executions by caching results.
211
+ *
212
+ * @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
213
+ *
214
+ * @example
215
+ * const toolResponse = await runner.generateToolResponse();
216
+ * if (toolResponse) {
217
+ * console.log('Tool results:', toolResponse.content);
218
+ * }
219
+ */
220
+ async generateToolResponse() {
221
+ const message = (await this.#message) ?? this.params.messages.at(-1);
222
+ if (!message) {
223
+ return null;
224
+ }
225
+ return this.#generateToolResponse(message);
226
+ }
227
+ async #generateToolResponse(lastMessage) {
228
+ if (this.#toolResponse !== undefined) {
229
+ return this.#toolResponse;
230
+ }
231
+ this.#toolResponse = generateToolResponse(this.#state.params, lastMessage);
232
+ return this.#toolResponse;
233
+ }
234
+ /**
235
+ * Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
236
+ * will wait for an instance to start and go to completion.
237
+ *
238
+ * @returns A promise that resolves to the final BetaMessage when the iterator completes
239
+ *
240
+ * @example
241
+ * // Start consuming the iterator
242
+ * for await (const message of runner) {
243
+ * console.log('Message:', message.content);
244
+ * }
245
+ *
246
+ * // Meanwhile, wait for completion from another part of the code
247
+ * const finalMessage = await runner.done();
248
+ * console.log('Final response:', finalMessage.content);
249
+ */
250
+ done() {
251
+ return this.#completion.promise;
252
+ }
253
+ /**
254
+ * Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
255
+ * * If the iterator has not been consumed, consume the entire iterator and return the final message from the
256
+ * assistant.
257
+ * * If the iterator has been consumed, waits for it to complete and returns the final message.
258
+ *
259
+ * @returns A promise that resolves to the final BetaMessage from the conversation
260
+ * @throws {AnthropicError} If no messages were processed during the conversation
261
+ *
262
+ * @example
263
+ * const finalMessage = await runner.runUntilDone();
264
+ * console.log('Final response:', finalMessage.content);
265
+ */
266
+ async runUntilDone() {
267
+ // If not yet consumed, start consuming and wait for completion
268
+ if (!this.#consumed) {
269
+ for await (const _ of this) {
270
+ // Iterator naturally populates this.#message
271
+ }
272
+ }
273
+ // If consumed but not completed, wait for completion
274
+ return this.done();
275
+ }
276
+ /**
277
+ * Get the current parameters being used by the ToolRunner.
278
+ *
279
+ * @returns A readonly view of the current ToolRunnerParams
280
+ *
281
+ * @example
282
+ * const currentParams = runner.params;
283
+ * console.log('Current model:', currentParams.model);
284
+ * console.log('Message count:', currentParams.messages.length);
285
+ */
286
+ get params() {
287
+ return this.#state.params;
288
+ }
289
+ /**
290
+ * Add one or more messages to the conversation history.
291
+ *
292
+ * @param messages - One or more BetaMessageParam objects to add to the conversation
293
+ *
294
+ * @example
295
+ * runner.pushMessages(
296
+ * { role: 'user', content: 'Also, what about the weather in NYC?' }
297
+ * );
298
+ *
299
+ * @example
300
+ * // Adding multiple messages
301
+ * runner.pushMessages(
302
+ * { role: 'user', content: 'What about NYC?' },
303
+ * { role: 'user', content: 'And Boston?' }
304
+ * );
305
+ */
306
+ pushMessages(...messages) {
307
+ this.setMessagesParams((params) => ({
308
+ ...params,
309
+ messages: [...params.messages, ...messages],
310
+ }));
311
+ }
312
+ /**
313
+ * Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
314
+ * This allows using `await runner` instead of `await runner.runUntilDone()`
315
+ */
316
+ then(onfulfilled, onrejected) {
317
+ return this.runUntilDone().then(onfulfilled, onrejected);
318
+ }
319
+ }
320
+ async function generateToolResponse(params, lastMessage = params.messages.at(-1)) {
321
+ // Only process if the last message is from the assistant and has tool use blocks
322
+ if (!lastMessage ||
323
+ lastMessage.role !== 'assistant' ||
324
+ !lastMessage.content ||
325
+ typeof lastMessage.content === 'string') {
326
+ return null;
327
+ }
328
+ const toolUseBlocks = lastMessage.content.filter((content) => content.type === 'tool_use');
329
+ if (toolUseBlocks.length === 0) {
330
+ return null;
331
+ }
332
+ const toolResults = await Promise.all(toolUseBlocks.map(async (toolUse) => {
333
+ const tool = params.tools.find((t) => ('name' in t ? t.name : t.mcp_server_name) === toolUse.name);
334
+ if (!tool || !('run' in tool)) {
335
+ return {
336
+ type: 'tool_result',
337
+ tool_use_id: toolUse.id,
338
+ content: `Error: Tool '${toolUse.name}' not found`,
339
+ is_error: true,
340
+ };
341
+ }
342
+ try {
343
+ let input = toolUse.input;
344
+ if ('parse' in tool && tool.parse) {
345
+ input = tool.parse(input);
346
+ }
347
+ const result = await tool.run(input);
348
+ return {
349
+ type: 'tool_result',
350
+ tool_use_id: toolUse.id,
351
+ content: result,
352
+ };
353
+ }
354
+ catch (error) {
355
+ return {
356
+ type: 'tool_result',
357
+ tool_use_id: toolUse.id,
358
+ content: error instanceof ToolError ?
359
+ error.content
360
+ : `Error: ${error instanceof Error ? error.message : String(error)}`,
361
+ is_error: true,
362
+ };
363
+ }
364
+ }));
365
+ return {
366
+ role: 'user',
367
+ content: toolResults,
368
+ };
369
+ }
370
+ //# sourceMappingURL=BetaToolRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BetaToolRunner.js","sourceRoot":"","sources":["../../../../src/vendor/lib/tools/BetaToolRunner.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAIrD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAqB,sBAAsB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAC5G,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAExE;;GAEG;AACH,SAAS,oBAAoB;IAK3B,IAAI,OAA2B,CAAC;IAChC,IAAI,MAA8B,CAAC;IACnC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAI,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE;QAC1C,OAAO,GAAG,GAAG,CAAC;QACd,MAAM,GAAG,GAAG,CAAC;IACf,CAAC,CAAC,CAAC;IACH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAQ,EAAE,MAAM,EAAE,MAAO,EAAE,CAAC;AACzD,CAAC;AAED;;;;;GAKG;AACH,MAAM,OAAO,cAAc;IAsBf;IArBV,mDAAmD;IACnD,SAAS,GAAG,KAAK,CAAC;IAClB,mEA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AAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;gBACtE,QAAQ,EAAE,IAAI;aACf,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,OAAO;QACL,IAAI,EAAE,MAAe;QACrB,OAAO,EAAE,WAAW;KACrB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { Model } from '../../resources/index.js';
2
+ export declare const DEFAULT_TOKEN_THRESHOLD = 100000;
3
+ export declare const DEFAULT_SUMMARY_PROMPT = "You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:\n1. Task Overview\nThe user's core request and success criteria\nAny clarifications or constraints they specified\n2. Current State\nWhat has been completed so far\nFiles created, modified, or analyzed (with paths if relevant)\nKey outputs or artifacts produced\n3. Important Discoveries\nTechnical constraints or requirements uncovered\nDecisions made and their rationale\nErrors encountered and how they were resolved\nWhat approaches were tried that didn't work (and why)\n4. Next Steps\nSpecific actions needed to complete the task\nAny blockers or open questions to resolve\nPriority order if multiple steps remain\n5. Context to Preserve\nUser preferences or style requirements\nDomain-specific details that aren't obvious\nAny promises made to the user\nBe concise but complete\u2014err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.\nWrap your summary in <summary></summary> tags.";
4
+ export interface CompactionControl {
5
+ /**
6
+ * The context token threshold at which to trigger compaction.
7
+ *
8
+ * When the cumulative token count (input + output) across all messages exceeds this threshold,
9
+ * the message history will be automatically summarized and compressed.
10
+ *
11
+ * @default 100000
12
+ */
13
+ contextTokenThreshold?: number;
14
+ /**
15
+ * The model to use for generating the compaction summary.
16
+ * If not specified, defaults to the same model used for the tool runner.
17
+ */
18
+ model?: Model;
19
+ /**
20
+ * The prompt used to instruct the model on how to generate the summary.
21
+ */
22
+ summaryPrompt?: string;
23
+ enabled: boolean;
24
+ }
25
+ //# sourceMappingURL=CompactionControl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompactionControl.d.ts","sourceRoot":"","sources":["../../../../src/vendor/lib/tools/CompactionControl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAEjD,eAAO,MAAM,uBAAuB,SAAU,CAAC;AAE/C,eAAO,MAAM,sBAAsB,20CAsBY,CAAC;AAEhD,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,OAAO,EAAE,OAAO,CAAC;CAClB"}
@@ -0,0 +1,25 @@
1
+ export const DEFAULT_TOKEN_THRESHOLD = 100_000;
2
+ export const DEFAULT_SUMMARY_PROMPT = `You have been working on the task described above but have not yet completed it. Write a continuation summary that will allow you (or another instance of yourself) to resume work efficiently in a future context window where the conversation history will be replaced with this summary. Your summary should be structured, concise, and actionable. Include:
3
+ 1. Task Overview
4
+ The user's core request and success criteria
5
+ Any clarifications or constraints they specified
6
+ 2. Current State
7
+ What has been completed so far
8
+ Files created, modified, or analyzed (with paths if relevant)
9
+ Key outputs or artifacts produced
10
+ 3. Important Discoveries
11
+ Technical constraints or requirements uncovered
12
+ Decisions made and their rationale
13
+ Errors encountered and how they were resolved
14
+ What approaches were tried that didn't work (and why)
15
+ 4. Next Steps
16
+ Specific actions needed to complete the task
17
+ Any blockers or open questions to resolve
18
+ Priority order if multiple steps remain
19
+ 5. Context to Preserve
20
+ User preferences or style requirements
21
+ Domain-specific details that aren't obvious
22
+ Any promises made to the user
23
+ Be concise but complete—err on the side of including information that would prevent duplicate work or repeated mistakes. Write in a way that enables immediate resumption of the task.
24
+ Wrap your summary in <summary></summary> tags.`;
25
+ //# sourceMappingURL=CompactionControl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompactionControl.js","sourceRoot":"","sources":["../../../../src/vendor/lib/tools/CompactionControl.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAAG,OAAO,CAAC;AAE/C,MAAM,CAAC,MAAM,sBAAsB,GAAG;;;;;;;;;;;;;;;;;;;;;;+CAsBS,CAAC"}
@@ -0,0 +1,33 @@
1
+ import { BetaToolResultContentBlockParam } from '../../resources/beta.js';
2
+ /**
3
+ * An error that can be thrown from a tool's `run` method to return structured
4
+ * content blocks as the error result, rather than just a string message.
5
+ *
6
+ * When the ToolRunner catches this error, it will use the `content` property
7
+ * as the tool result with `is_error: true`.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const tool = {
12
+ * name: 'my_tool',
13
+ * run: async (input) => {
14
+ * if (somethingWentWrong) {
15
+ * throw new ToolError([
16
+ * { type: 'text', text: 'Error details here' },
17
+ * { type: 'image', source: { type: 'base64', data: '...', media_type: 'image/png' } },
18
+ * ]);
19
+ * }
20
+ * return 'success';
21
+ * },
22
+ * };
23
+ * ```
24
+ */
25
+ export declare class ToolError extends Error {
26
+ /**
27
+ * The content to return as the tool result. This will be sent back to the model
28
+ * with `is_error: true`.
29
+ */
30
+ readonly content: string | Array<BetaToolResultContentBlockParam>;
31
+ constructor(content: string | Array<BetaToolResultContentBlockParam>);
32
+ }
33
+ //# sourceMappingURL=ToolError.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolError.d.ts","sourceRoot":"","sources":["../../../../src/vendor/lib/tools/ToolError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,+BAA+B,EAAE,MAAM,yBAAyB,CAAC;AAE1E;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC;;;OAGG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC,CAAC;gBAEtD,OAAO,EAAE,MAAM,GAAG,KAAK,CAAC,+BAA+B,CAAC;CAcrE"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * An error that can be thrown from a tool's `run` method to return structured
3
+ * content blocks as the error result, rather than just a string message.
4
+ *
5
+ * When the ToolRunner catches this error, it will use the `content` property
6
+ * as the tool result with `is_error: true`.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * const tool = {
11
+ * name: 'my_tool',
12
+ * run: async (input) => {
13
+ * if (somethingWentWrong) {
14
+ * throw new ToolError([
15
+ * { type: 'text', text: 'Error details here' },
16
+ * { type: 'image', source: { type: 'base64', data: '...', media_type: 'image/png' } },
17
+ * ]);
18
+ * }
19
+ * return 'success';
20
+ * },
21
+ * };
22
+ * ```
23
+ */
24
+ export class ToolError extends Error {
25
+ /**
26
+ * The content to return as the tool result. This will be sent back to the model
27
+ * with `is_error: true`.
28
+ */
29
+ content;
30
+ constructor(content) {
31
+ const message = typeof content === 'string' ? content : (content
32
+ .map((block) => {
33
+ if (block.type === 'text')
34
+ return block.text;
35
+ return `[${block.type}]`;
36
+ })
37
+ .join(' '));
38
+ super(message);
39
+ this.name = 'ToolError';
40
+ this.content = content;
41
+ }
42
+ }
43
+ //# sourceMappingURL=ToolError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ToolError.js","sourceRoot":"","sources":["../../../../src/vendor/lib/tools/ToolError.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,SAAU,SAAQ,KAAK;IAClC;;;OAGG;IACM,OAAO,CAAkD;IAElE,YAAY,OAAwD;QAClE,MAAM,OAAO,GACX,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CACtC,OAAO;aACJ,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YACb,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;gBAAE,OAAO,KAAK,CAAC,IAAI,CAAC;YAC7C,OAAO,IAAI,KAAK,CAAC,IAAI,GAAG,CAAC;QAC3B,CAAC,CAAC;aACD,IAAI,CAAC,GAAG,CAAC,CACb,CAAC;QACJ,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,WAAW,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,132 @@
1
+ import { BetaRunnableTool } from './BetaRunnableTool.js';
2
+ import { PukuAI } from '../../index.js';
3
+ import { BetaMessage, BetaMessageParam, BetaToolUnion, MessageCreateParams } from '../../resources/beta.js';
4
+ import { BetaMessageStream } from '../BetaMessageStream.js';
5
+ /**
6
+ * A ToolRunner handles the automatic conversation loop between the assistant and tools.
7
+ *
8
+ * A ToolRunner is an async iterable that yields either BetaMessage or BetaMessageStream objects
9
+ * depending on the streaming configuration.
10
+ */
11
+ export declare class BetaToolRunner<Stream extends boolean> {
12
+ #private;
13
+ private client;
14
+ constructor(client: PukuAI, params: BetaToolRunnerParams);
15
+ [Symbol.asyncIterator](): AsyncIterator<Stream extends true ? BetaMessageStream : Stream extends false ? BetaMessage : BetaMessage | BetaMessageStream>;
16
+ /**
17
+ * Update the parameters for the next API call. This invalidates any cached tool responses.
18
+ *
19
+ * @param paramsOrMutator - Either new parameters or a function to mutate existing parameters
20
+ *
21
+ * @example
22
+ * // Direct parameter update
23
+ * runner.setMessagesParams({
24
+ * model: 'claude-haiku-4-5',
25
+ * max_tokens: 500,
26
+ * });
27
+ *
28
+ * @example
29
+ * // Using a mutator function
30
+ * runner.setMessagesParams((params) => ({
31
+ * ...params,
32
+ * max_tokens: 100,
33
+ * }));
34
+ */
35
+ setMessagesParams(params: BetaToolRunnerParams): void;
36
+ setMessagesParams(mutator: (prevParams: BetaToolRunnerParams) => BetaToolRunnerParams): void;
37
+ /**
38
+ * Get the tool response for the last message from the assistant.
39
+ * Avoids redundant tool executions by caching results.
40
+ *
41
+ * @returns A promise that resolves to a BetaMessageParam containing tool results, or null if no tools need to be executed
42
+ *
43
+ * @example
44
+ * const toolResponse = await runner.generateToolResponse();
45
+ * if (toolResponse) {
46
+ * console.log('Tool results:', toolResponse.content);
47
+ * }
48
+ */
49
+ generateToolResponse(): Promise<PukuAI.Beta.Messages.BetaMessageParam | null>;
50
+ /**
51
+ * Wait for the async iterator to complete. This works even if the async iterator hasn't yet started, and
52
+ * will wait for an instance to start and go to completion.
53
+ *
54
+ * @returns A promise that resolves to the final BetaMessage when the iterator completes
55
+ *
56
+ * @example
57
+ * // Start consuming the iterator
58
+ * for await (const message of runner) {
59
+ * console.log('Message:', message.content);
60
+ * }
61
+ *
62
+ * // Meanwhile, wait for completion from another part of the code
63
+ * const finalMessage = await runner.done();
64
+ * console.log('Final response:', finalMessage.content);
65
+ */
66
+ done(): Promise<BetaMessage>;
67
+ /**
68
+ * Returns a promise indicating that the stream is done. Unlike .done(), this will eagerly read the stream:
69
+ * * If the iterator has not been consumed, consume the entire iterator and return the final message from the
70
+ * assistant.
71
+ * * If the iterator has been consumed, waits for it to complete and returns the final message.
72
+ *
73
+ * @returns A promise that resolves to the final BetaMessage from the conversation
74
+ * @throws {AnthropicError} If no messages were processed during the conversation
75
+ *
76
+ * @example
77
+ * const finalMessage = await runner.runUntilDone();
78
+ * console.log('Final response:', finalMessage.content);
79
+ */
80
+ runUntilDone(): Promise<BetaMessage>;
81
+ /**
82
+ * Get the current parameters being used by the ToolRunner.
83
+ *
84
+ * @returns A readonly view of the current ToolRunnerParams
85
+ *
86
+ * @example
87
+ * const currentParams = runner.params;
88
+ * console.log('Current model:', currentParams.model);
89
+ * console.log('Message count:', currentParams.messages.length);
90
+ */
91
+ get params(): Readonly<BetaToolRunnerParams>;
92
+ /**
93
+ * Add one or more messages to the conversation history.
94
+ *
95
+ * @param messages - One or more BetaMessageParam objects to add to the conversation
96
+ *
97
+ * @example
98
+ * runner.pushMessages(
99
+ * { role: 'user', content: 'Also, what about the weather in NYC?' }
100
+ * );
101
+ *
102
+ * @example
103
+ * // Adding multiple messages
104
+ * runner.pushMessages(
105
+ * { role: 'user', content: 'What about NYC?' },
106
+ * { role: 'user', content: 'And Boston?' }
107
+ * );
108
+ */
109
+ pushMessages(...messages: BetaMessageParam[]): void;
110
+ /**
111
+ * Makes the ToolRunner directly awaitable, equivalent to calling .runUntilDone()
112
+ * This allows using `await runner` instead of `await runner.runUntilDone()`
113
+ */
114
+ then<TResult1 = BetaMessage, TResult2 = never>(onfulfilled?: ((value: BetaMessage) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: any) => TResult2 | PromiseLike<TResult2>) | undefined | null): Promise<TResult1 | TResult2>;
115
+ }
116
+ type Simplify<T> = {
117
+ [KeyType in keyof T]: T[KeyType];
118
+ } & {};
119
+ /**
120
+ * Parameters for creating a ToolRunner, extending MessageCreateParams with runnable tools.
121
+ */
122
+ export type BetaToolRunnerParams = Simplify<Omit<MessageCreateParams, 'tools'> & {
123
+ tools: (BetaToolUnion | BetaRunnableTool<any>)[];
124
+ /**
125
+ * Maximum number of iterations (API requests) to make in the tool execution loop.
126
+ * Each iteration consists of: assistant response → tool execution → tool results.
127
+ * When exceeded, the loop will terminate even if tools are still being requested.
128
+ */
129
+ max_iterations?: number;
130
+ }>;
131
+ export {};
132
+ //# sourceMappingURL=ToolRunner.d.ts.map