@anthropic-ai/sdk 0.96.0 → 0.97.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 (570) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/api-promise.d.mts +1 -0
  3. package/api-promise.d.mts.map +1 -1
  4. package/api-promise.d.ts +1 -0
  5. package/api-promise.d.ts.map +1 -1
  6. package/api-promise.mjs +1 -0
  7. package/api-promise.mjs.map +1 -1
  8. package/bin/migration-config.json +222 -0
  9. package/client.d.mts.map +1 -1
  10. package/client.d.ts.map +1 -1
  11. package/client.mjs.map +1 -1
  12. package/core/api-promise.d.mts.map +1 -1
  13. package/core/api-promise.d.ts.map +1 -1
  14. package/core/api-promise.mjs.map +1 -1
  15. package/core/credentials.mjs.map +1 -1
  16. package/core/error.d.mts.map +1 -1
  17. package/core/error.d.ts.map +1 -1
  18. package/core/error.mjs.map +1 -1
  19. package/core/pagination.d.mts.map +1 -1
  20. package/core/pagination.d.ts.map +1 -1
  21. package/core/pagination.mjs.map +1 -1
  22. package/core/resource.d.mts.map +1 -1
  23. package/core/resource.d.ts.map +1 -1
  24. package/core/streaming.d.mts.map +1 -1
  25. package/core/streaming.d.ts.map +1 -1
  26. package/core/streaming.js +2 -0
  27. package/core/streaming.js.map +1 -1
  28. package/core/streaming.mjs +2 -0
  29. package/core/streaming.mjs.map +1 -1
  30. package/core/uploads.d.mts.map +1 -1
  31. package/core/uploads.d.ts.map +1 -1
  32. package/core/uploads.mjs.map +1 -1
  33. package/error.d.mts +1 -0
  34. package/error.d.mts.map +1 -1
  35. package/error.d.ts +1 -0
  36. package/error.d.ts.map +1 -1
  37. package/error.mjs +1 -0
  38. package/error.mjs.map +1 -1
  39. package/helpers/beta/environments.d.mts +22 -0
  40. package/helpers/beta/environments.d.mts.map +1 -0
  41. package/helpers/beta/environments.d.ts +22 -0
  42. package/helpers/beta/environments.d.ts.map +1 -0
  43. package/helpers/beta/environments.js +30 -0
  44. package/helpers/beta/environments.js.map +1 -0
  45. package/helpers/beta/environments.mjs +22 -0
  46. package/helpers/beta/environments.mjs.map +1 -0
  47. package/helpers/beta/json-schema.d.mts +6 -0
  48. package/helpers/beta/json-schema.d.mts.map +1 -1
  49. package/helpers/beta/json-schema.d.ts +6 -0
  50. package/helpers/beta/json-schema.d.ts.map +1 -1
  51. package/helpers/beta/json-schema.js +1 -0
  52. package/helpers/beta/json-schema.js.map +1 -1
  53. package/helpers/beta/json-schema.mjs +1 -0
  54. package/helpers/beta/json-schema.mjs.map +1 -1
  55. package/helpers/beta/mcp.d.mts.map +1 -1
  56. package/helpers/beta/mcp.d.ts.map +1 -1
  57. package/helpers/beta/mcp.mjs.map +1 -1
  58. package/helpers/beta/memory.d.mts.map +1 -1
  59. package/helpers/beta/memory.d.ts.map +1 -1
  60. package/helpers/beta/zod.d.mts +6 -0
  61. package/helpers/beta/zod.d.mts.map +1 -1
  62. package/helpers/beta/zod.d.ts +6 -0
  63. package/helpers/beta/zod.d.ts.map +1 -1
  64. package/helpers/beta/zod.js +1 -0
  65. package/helpers/beta/zod.js.map +1 -1
  66. package/helpers/beta/zod.mjs +1 -0
  67. package/helpers/beta/zod.mjs.map +1 -1
  68. package/helpers/index.d.mts.map +1 -1
  69. package/helpers/index.d.ts.map +1 -1
  70. package/helpers/index.mjs.map +1 -1
  71. package/helpers/json-schema.d.mts.map +1 -1
  72. package/helpers/json-schema.d.ts.map +1 -1
  73. package/helpers/json-schema.mjs.map +1 -1
  74. package/helpers/zod.d.mts.map +1 -1
  75. package/helpers/zod.d.ts.map +1 -1
  76. package/helpers/zod.mjs.map +1 -1
  77. package/index.d.mts.map +1 -1
  78. package/index.d.ts.map +1 -1
  79. package/index.mjs.map +1 -1
  80. package/internal/decoders/jsonl.d.mts.map +1 -1
  81. package/internal/decoders/jsonl.d.ts.map +1 -1
  82. package/internal/decoders/jsonl.mjs.map +1 -1
  83. package/internal/decoders/line.mjs.map +1 -1
  84. package/internal/detect-platform.mjs.map +1 -1
  85. package/internal/headers.mjs.map +1 -1
  86. package/internal/parse.d.mts.map +1 -1
  87. package/internal/parse.d.ts.map +1 -1
  88. package/internal/parse.mjs.map +1 -1
  89. package/internal/qs/formats.d.mts.map +1 -1
  90. package/internal/qs/formats.d.ts.map +1 -1
  91. package/internal/qs/index.d.mts +2 -2
  92. package/internal/qs/index.d.mts.map +1 -1
  93. package/internal/qs/index.d.ts +2 -2
  94. package/internal/qs/index.d.ts.map +1 -1
  95. package/internal/qs/index.mjs.map +1 -1
  96. package/internal/qs/stringify.d.mts.map +1 -1
  97. package/internal/qs/stringify.d.ts.map +1 -1
  98. package/internal/qs/stringify.mjs.map +1 -1
  99. package/internal/qs/utils.d.mts.map +1 -1
  100. package/internal/qs/utils.d.ts.map +1 -1
  101. package/internal/qs/utils.mjs.map +1 -1
  102. package/internal/request-options.d.mts.map +1 -1
  103. package/internal/request-options.d.ts.map +1 -1
  104. package/internal/shims.d.mts +6 -0
  105. package/internal/shims.d.mts.map +1 -1
  106. package/internal/shims.d.ts +6 -0
  107. package/internal/shims.d.ts.map +1 -1
  108. package/internal/to-file.d.mts.map +1 -1
  109. package/internal/to-file.d.ts.map +1 -1
  110. package/internal/to-file.mjs.map +1 -1
  111. package/internal/types.d.mts +4 -4
  112. package/internal/types.d.mts.map +1 -1
  113. package/internal/types.d.ts +4 -4
  114. package/internal/types.d.ts.map +1 -1
  115. package/internal/uploads.d.mts.map +1 -1
  116. package/internal/uploads.d.ts.map +1 -1
  117. package/internal/uploads.mjs.map +1 -1
  118. package/internal/utils/abort.d.mts +13 -0
  119. package/internal/utils/abort.d.mts.map +1 -0
  120. package/internal/utils/abort.d.ts +13 -0
  121. package/internal/utils/abort.d.ts.map +1 -0
  122. package/internal/utils/abort.js +26 -0
  123. package/internal/utils/abort.js.map +1 -0
  124. package/internal/utils/abort.mjs +23 -0
  125. package/internal/utils/abort.mjs.map +1 -0
  126. package/internal/utils/async-queue.d.mts +31 -0
  127. package/internal/utils/async-queue.d.mts.map +1 -0
  128. package/internal/utils/async-queue.d.ts +31 -0
  129. package/internal/utils/async-queue.d.ts.map +1 -0
  130. package/internal/utils/async-queue.js +75 -0
  131. package/internal/utils/async-queue.js.map +1 -0
  132. package/internal/utils/async-queue.mjs +71 -0
  133. package/internal/utils/async-queue.mjs.map +1 -0
  134. package/internal/utils/backoff.d.mts +23 -0
  135. package/internal/utils/backoff.d.mts.map +1 -0
  136. package/internal/utils/backoff.d.ts +23 -0
  137. package/internal/utils/backoff.d.ts.map +1 -0
  138. package/internal/utils/backoff.js +44 -0
  139. package/internal/utils/backoff.js.map +1 -0
  140. package/internal/utils/backoff.mjs +36 -0
  141. package/internal/utils/backoff.mjs.map +1 -0
  142. package/internal/utils/base64.mjs.map +1 -1
  143. package/internal/utils/log.d.mts.map +1 -1
  144. package/internal/utils/log.d.ts.map +1 -1
  145. package/internal/utils/log.mjs.map +1 -1
  146. package/internal/utils/path.mjs.map +1 -1
  147. package/internal/utils/promise.d.mts +11 -0
  148. package/internal/utils/promise.d.mts.map +1 -0
  149. package/internal/utils/promise.d.ts +11 -0
  150. package/internal/utils/promise.d.ts.map +1 -0
  151. package/internal/utils/promise.js +18 -0
  152. package/internal/utils/promise.js.map +1 -0
  153. package/internal/utils/promise.mjs +15 -0
  154. package/internal/utils/promise.mjs.map +1 -0
  155. package/internal/utils/query.mjs.map +1 -1
  156. package/internal/utils/sleep.d.mts +9 -1
  157. package/internal/utils/sleep.d.mts.map +1 -1
  158. package/internal/utils/sleep.d.ts +9 -1
  159. package/internal/utils/sleep.d.ts.map +1 -1
  160. package/internal/utils/sleep.js +23 -2
  161. package/internal/utils/sleep.js.map +1 -1
  162. package/internal/utils/sleep.mjs +23 -2
  163. package/internal/utils/sleep.mjs.map +1 -1
  164. package/internal/utils/values.mjs.map +1 -1
  165. package/internal/utils.d.mts.map +1 -1
  166. package/internal/utils.d.ts.map +1 -1
  167. package/internal/utils.mjs.map +1 -1
  168. package/lib/BetaMessageStream.d.mts.map +1 -1
  169. package/lib/BetaMessageStream.d.ts.map +1 -1
  170. package/lib/BetaMessageStream.mjs.map +1 -1
  171. package/lib/MessageStream.d.mts.map +1 -1
  172. package/lib/MessageStream.d.ts.map +1 -1
  173. package/lib/MessageStream.mjs.map +1 -1
  174. package/lib/beta-parser.d.mts.map +1 -1
  175. package/lib/beta-parser.d.ts.map +1 -1
  176. package/lib/beta-parser.mjs.map +1 -1
  177. package/lib/credentials/credential-chain.d.mts.map +1 -1
  178. package/lib/credentials/credential-chain.d.ts.map +1 -1
  179. package/lib/credentials/credential-chain.mjs.map +1 -1
  180. package/lib/credentials/identity-token.d.mts.map +1 -1
  181. package/lib/credentials/identity-token.d.ts.map +1 -1
  182. package/lib/credentials/identity-token.mjs.map +1 -1
  183. package/lib/credentials/oidc-federation.d.mts.map +1 -1
  184. package/lib/credentials/oidc-federation.d.ts.map +1 -1
  185. package/lib/credentials/oidc-federation.mjs.map +1 -1
  186. package/lib/credentials/token-cache.d.mts.map +1 -1
  187. package/lib/credentials/token-cache.d.ts.map +1 -1
  188. package/lib/credentials/token-cache.mjs.map +1 -1
  189. package/lib/credentials/types.d.mts.map +1 -1
  190. package/lib/credentials/types.d.ts.map +1 -1
  191. package/lib/credentials/types.mjs.map +1 -1
  192. package/lib/credentials/user-oauth.d.mts.map +1 -1
  193. package/lib/credentials/user-oauth.d.ts.map +1 -1
  194. package/lib/credentials/user-oauth.mjs.map +1 -1
  195. package/lib/credentials.d.mts.map +1 -1
  196. package/lib/credentials.d.ts.map +1 -1
  197. package/lib/credentials.mjs.map +1 -1
  198. package/lib/environments/index.d.mts +4 -0
  199. package/lib/environments/index.d.mts.map +1 -0
  200. package/lib/environments/index.d.ts +4 -0
  201. package/lib/environments/index.d.ts.map +1 -0
  202. package/lib/environments/index.js +18 -0
  203. package/lib/environments/index.js.map +1 -0
  204. package/lib/environments/index.mjs +4 -0
  205. package/lib/environments/index.mjs.map +1 -0
  206. package/lib/environments/poller.d.mts +89 -0
  207. package/lib/environments/poller.d.mts.map +1 -0
  208. package/lib/environments/poller.d.ts +89 -0
  209. package/lib/environments/poller.d.ts.map +1 -0
  210. package/lib/environments/poller.js +181 -0
  211. package/lib/environments/poller.js.map +1 -0
  212. package/lib/environments/poller.mjs +172 -0
  213. package/lib/environments/poller.mjs.map +1 -0
  214. package/lib/environments/worker.d.mts +143 -0
  215. package/lib/environments/worker.d.mts.map +1 -0
  216. package/lib/environments/worker.d.ts +143 -0
  217. package/lib/environments/worker.d.ts.map +1 -0
  218. package/lib/environments/worker.js +265 -0
  219. package/lib/environments/worker.js.map +1 -0
  220. package/lib/environments/worker.mjs +261 -0
  221. package/lib/environments/worker.mjs.map +1 -0
  222. package/lib/helper-client.d.mts +49 -0
  223. package/lib/helper-client.d.mts.map +1 -0
  224. package/lib/helper-client.d.ts +49 -0
  225. package/lib/helper-client.d.ts.map +1 -0
  226. package/lib/helper-client.js +57 -0
  227. package/lib/helper-client.js.map +1 -0
  228. package/lib/helper-client.mjs +54 -0
  229. package/lib/helper-client.mjs.map +1 -0
  230. package/lib/parser.d.mts.map +1 -1
  231. package/lib/parser.d.ts.map +1 -1
  232. package/lib/parser.mjs.map +1 -1
  233. package/lib/stainless-helper-header.d.mts.map +1 -1
  234. package/lib/stainless-helper-header.d.ts.map +1 -1
  235. package/lib/tools/BetaRunnableTool.d.mts +54 -2
  236. package/lib/tools/BetaRunnableTool.d.mts.map +1 -1
  237. package/lib/tools/BetaRunnableTool.d.ts +54 -2
  238. package/lib/tools/BetaRunnableTool.d.ts.map +1 -1
  239. package/lib/tools/BetaRunnableTool.js +37 -0
  240. package/lib/tools/BetaRunnableTool.js.map +1 -1
  241. package/lib/tools/BetaRunnableTool.mjs +34 -1
  242. package/lib/tools/BetaRunnableTool.mjs.map +1 -1
  243. package/lib/tools/BetaToolRunner.d.mts.map +1 -1
  244. package/lib/tools/BetaToolRunner.d.ts.map +1 -1
  245. package/lib/tools/BetaToolRunner.js +4 -14
  246. package/lib/tools/BetaToolRunner.js.map +1 -1
  247. package/lib/tools/BetaToolRunner.mjs +2 -12
  248. package/lib/tools/BetaToolRunner.mjs.map +1 -1
  249. package/lib/tools/CompactionControl.d.mts.map +1 -1
  250. package/lib/tools/CompactionControl.d.ts.map +1 -1
  251. package/lib/tools/SessionToolRunner.d.mts +140 -0
  252. package/lib/tools/SessionToolRunner.d.mts.map +1 -0
  253. package/lib/tools/SessionToolRunner.d.ts +140 -0
  254. package/lib/tools/SessionToolRunner.d.ts.map +1 -0
  255. package/lib/tools/SessionToolRunner.js +459 -0
  256. package/lib/tools/SessionToolRunner.js.map +1 -0
  257. package/lib/tools/SessionToolRunner.mjs +455 -0
  258. package/lib/tools/SessionToolRunner.mjs.map +1 -0
  259. package/lib/tools/ToolError.d.mts.map +1 -1
  260. package/lib/tools/ToolError.d.ts.map +1 -1
  261. package/lib/tools/ToolRunner.d.mts.map +1 -1
  262. package/lib/tools/ToolRunner.d.ts.map +1 -1
  263. package/lib/tools/ToolRunner.mjs.map +1 -1
  264. package/lib/transform-json-schema.mjs.map +1 -1
  265. package/package.json +1 -1
  266. package/pagination.d.mts +1 -0
  267. package/pagination.d.mts.map +1 -1
  268. package/pagination.d.ts +1 -0
  269. package/pagination.d.ts.map +1 -1
  270. package/pagination.mjs +1 -0
  271. package/pagination.mjs.map +1 -1
  272. package/resource.d.mts +1 -0
  273. package/resource.d.mts.map +1 -1
  274. package/resource.d.ts +1 -0
  275. package/resource.d.ts.map +1 -1
  276. package/resource.mjs +1 -0
  277. package/resource.mjs.map +1 -1
  278. package/resources/beta/agents/agents.d.mts +125 -1
  279. package/resources/beta/agents/agents.d.mts.map +1 -1
  280. package/resources/beta/agents/agents.d.ts +125 -1
  281. package/resources/beta/agents/agents.d.ts.map +1 -1
  282. package/resources/beta/agents/agents.js.map +1 -1
  283. package/resources/beta/agents/agents.mjs.map +1 -1
  284. package/resources/beta/agents/index.d.mts +1 -1
  285. package/resources/beta/agents/index.d.mts.map +1 -1
  286. package/resources/beta/agents/index.d.ts +1 -1
  287. package/resources/beta/agents/index.d.ts.map +1 -1
  288. package/resources/beta/agents/index.js.map +1 -1
  289. package/resources/beta/agents/index.mjs.map +1 -1
  290. package/resources/beta/agents/versions.d.mts.map +1 -1
  291. package/resources/beta/agents/versions.d.ts.map +1 -1
  292. package/resources/beta/agents/versions.mjs.map +1 -1
  293. package/resources/beta/agents.d.mts.map +1 -1
  294. package/resources/beta/agents.d.ts.map +1 -1
  295. package/resources/beta/agents.mjs.map +1 -1
  296. package/resources/beta/beta.d.mts +7 -7
  297. package/resources/beta/beta.d.mts.map +1 -1
  298. package/resources/beta/beta.d.ts +7 -7
  299. package/resources/beta/beta.d.ts.map +1 -1
  300. package/resources/beta/beta.js +2 -2
  301. package/resources/beta/beta.js.map +1 -1
  302. package/resources/beta/beta.mjs +2 -2
  303. package/resources/beta/beta.mjs.map +1 -1
  304. package/resources/beta/environments/environments.d.mts +425 -0
  305. package/resources/beta/environments/environments.d.mts.map +1 -0
  306. package/resources/beta/environments/environments.d.ts +425 -0
  307. package/resources/beta/environments/environments.d.ts.map +1 -0
  308. package/resources/beta/environments/environments.js +150 -0
  309. package/resources/beta/environments/environments.js.map +1 -0
  310. package/resources/beta/environments/environments.mjs +145 -0
  311. package/resources/beta/environments/environments.mjs.map +1 -0
  312. package/resources/beta/environments/index.d.mts +3 -0
  313. package/resources/beta/environments/index.d.mts.map +1 -0
  314. package/resources/beta/environments/index.d.ts +3 -0
  315. package/resources/beta/environments/index.d.ts.map +1 -0
  316. package/resources/beta/environments/index.js +9 -0
  317. package/resources/beta/environments/index.js.map +1 -0
  318. package/resources/beta/environments/index.mjs +4 -0
  319. package/resources/beta/environments/index.mjs.map +1 -0
  320. package/resources/beta/environments/work.d.mts +496 -0
  321. package/resources/beta/environments/work.d.mts.map +1 -0
  322. package/resources/beta/environments/work.d.ts +496 -0
  323. package/resources/beta/environments/work.d.ts.map +1 -0
  324. package/resources/beta/environments/work.js +274 -0
  325. package/resources/beta/environments/work.js.map +1 -0
  326. package/resources/beta/environments/work.mjs +268 -0
  327. package/resources/beta/environments/work.mjs.map +1 -0
  328. package/resources/beta/environments.d.mts +1 -388
  329. package/resources/beta/environments.d.mts.map +1 -1
  330. package/resources/beta/environments.d.ts +1 -388
  331. package/resources/beta/environments.d.ts.map +1 -1
  332. package/resources/beta/environments.js +2 -138
  333. package/resources/beta/environments.js.map +1 -1
  334. package/resources/beta/environments.mjs +1 -136
  335. package/resources/beta/environments.mjs.map +1 -1
  336. package/resources/beta/files.d.mts.map +1 -1
  337. package/resources/beta/files.d.ts.map +1 -1
  338. package/resources/beta/files.mjs.map +1 -1
  339. package/resources/beta/index.d.mts +3 -3
  340. package/resources/beta/index.d.mts.map +1 -1
  341. package/resources/beta/index.d.ts +3 -3
  342. package/resources/beta/index.d.ts.map +1 -1
  343. package/resources/beta/index.js +12 -12
  344. package/resources/beta/index.js.map +1 -1
  345. package/resources/beta/index.mjs +1 -1
  346. package/resources/beta/index.mjs.map +1 -1
  347. package/resources/beta/memory-stores/index.d.mts.map +1 -1
  348. package/resources/beta/memory-stores/index.d.ts.map +1 -1
  349. package/resources/beta/memory-stores/index.mjs.map +1 -1
  350. package/resources/beta/memory-stores/memories.d.mts.map +1 -1
  351. package/resources/beta/memory-stores/memories.d.ts.map +1 -1
  352. package/resources/beta/memory-stores/memories.mjs.map +1 -1
  353. package/resources/beta/memory-stores/memory-stores.d.mts.map +1 -1
  354. package/resources/beta/memory-stores/memory-stores.d.ts.map +1 -1
  355. package/resources/beta/memory-stores/memory-stores.mjs.map +1 -1
  356. package/resources/beta/memory-stores/memory-versions.d.mts.map +1 -1
  357. package/resources/beta/memory-stores/memory-versions.d.ts.map +1 -1
  358. package/resources/beta/memory-stores/memory-versions.mjs.map +1 -1
  359. package/resources/beta/memory-stores.d.mts.map +1 -1
  360. package/resources/beta/memory-stores.d.ts.map +1 -1
  361. package/resources/beta/memory-stores.mjs.map +1 -1
  362. package/resources/beta/messages/batches.d.mts.map +1 -1
  363. package/resources/beta/messages/batches.d.ts.map +1 -1
  364. package/resources/beta/messages/batches.mjs.map +1 -1
  365. package/resources/beta/messages/index.d.mts.map +1 -1
  366. package/resources/beta/messages/index.d.ts.map +1 -1
  367. package/resources/beta/messages/index.mjs.map +1 -1
  368. package/resources/beta/messages/messages.d.mts +4 -4
  369. package/resources/beta/messages/messages.d.mts.map +1 -1
  370. package/resources/beta/messages/messages.d.ts +4 -4
  371. package/resources/beta/messages/messages.d.ts.map +1 -1
  372. package/resources/beta/messages/messages.mjs.map +1 -1
  373. package/resources/beta/messages.d.mts.map +1 -1
  374. package/resources/beta/messages.d.ts.map +1 -1
  375. package/resources/beta/messages.mjs.map +1 -1
  376. package/resources/beta/models.d.mts.map +1 -1
  377. package/resources/beta/models.d.ts.map +1 -1
  378. package/resources/beta/models.mjs.map +1 -1
  379. package/resources/beta/sessions/events.d.mts +52 -5
  380. package/resources/beta/sessions/events.d.mts.map +1 -1
  381. package/resources/beta/sessions/events.d.ts +52 -5
  382. package/resources/beta/sessions/events.d.ts.map +1 -1
  383. package/resources/beta/sessions/events.js +27 -1
  384. package/resources/beta/sessions/events.js.map +1 -1
  385. package/resources/beta/sessions/events.mjs +25 -0
  386. package/resources/beta/sessions/events.mjs.map +1 -1
  387. package/resources/beta/sessions/index.d.mts +3 -3
  388. package/resources/beta/sessions/index.d.mts.map +1 -1
  389. package/resources/beta/sessions/index.d.ts +3 -3
  390. package/resources/beta/sessions/index.d.ts.map +1 -1
  391. package/resources/beta/sessions/index.js.map +1 -1
  392. package/resources/beta/sessions/index.mjs.map +1 -1
  393. package/resources/beta/sessions/resources.d.mts.map +1 -1
  394. package/resources/beta/sessions/resources.d.ts.map +1 -1
  395. package/resources/beta/sessions/resources.mjs.map +1 -1
  396. package/resources/beta/sessions/sessions.d.mts +98 -6
  397. package/resources/beta/sessions/sessions.d.mts.map +1 -1
  398. package/resources/beta/sessions/sessions.d.ts +98 -6
  399. package/resources/beta/sessions/sessions.d.ts.map +1 -1
  400. package/resources/beta/sessions/sessions.js.map +1 -1
  401. package/resources/beta/sessions/sessions.mjs.map +1 -1
  402. package/resources/beta/sessions/threads/events.d.mts.map +1 -1
  403. package/resources/beta/sessions/threads/events.d.ts.map +1 -1
  404. package/resources/beta/sessions/threads/events.mjs.map +1 -1
  405. package/resources/beta/sessions/threads/index.d.mts +1 -1
  406. package/resources/beta/sessions/threads/index.d.mts.map +1 -1
  407. package/resources/beta/sessions/threads/index.d.ts +1 -1
  408. package/resources/beta/sessions/threads/index.d.ts.map +1 -1
  409. package/resources/beta/sessions/threads/index.js.map +1 -1
  410. package/resources/beta/sessions/threads/index.mjs.map +1 -1
  411. package/resources/beta/sessions/threads/threads.d.mts +3 -23
  412. package/resources/beta/sessions/threads/threads.d.mts.map +1 -1
  413. package/resources/beta/sessions/threads/threads.d.ts +3 -23
  414. package/resources/beta/sessions/threads/threads.d.ts.map +1 -1
  415. package/resources/beta/sessions/threads/threads.js.map +1 -1
  416. package/resources/beta/sessions/threads/threads.mjs.map +1 -1
  417. package/resources/beta/sessions/threads.d.mts.map +1 -1
  418. package/resources/beta/sessions/threads.d.ts.map +1 -1
  419. package/resources/beta/sessions/threads.mjs.map +1 -1
  420. package/resources/beta/sessions.d.mts.map +1 -1
  421. package/resources/beta/sessions.d.ts.map +1 -1
  422. package/resources/beta/sessions.mjs.map +1 -1
  423. package/resources/beta/skills/index.d.mts +1 -1
  424. package/resources/beta/skills/index.d.mts.map +1 -1
  425. package/resources/beta/skills/index.d.ts +1 -1
  426. package/resources/beta/skills/index.d.ts.map +1 -1
  427. package/resources/beta/skills/index.js.map +1 -1
  428. package/resources/beta/skills/index.mjs.map +1 -1
  429. package/resources/beta/skills/skills.d.mts +2 -2
  430. package/resources/beta/skills/skills.d.mts.map +1 -1
  431. package/resources/beta/skills/skills.d.ts +2 -2
  432. package/resources/beta/skills/skills.d.ts.map +1 -1
  433. package/resources/beta/skills/skills.js.map +1 -1
  434. package/resources/beta/skills/skills.mjs.map +1 -1
  435. package/resources/beta/skills/versions.d.mts +28 -1
  436. package/resources/beta/skills/versions.d.mts.map +1 -1
  437. package/resources/beta/skills/versions.d.ts +28 -1
  438. package/resources/beta/skills/versions.d.ts.map +1 -1
  439. package/resources/beta/skills/versions.js +28 -0
  440. package/resources/beta/skills/versions.js.map +1 -1
  441. package/resources/beta/skills/versions.mjs +28 -0
  442. package/resources/beta/skills/versions.mjs.map +1 -1
  443. package/resources/beta/skills.d.mts.map +1 -1
  444. package/resources/beta/skills.d.ts.map +1 -1
  445. package/resources/beta/skills.mjs.map +1 -1
  446. package/resources/beta/user-profiles.d.mts.map +1 -1
  447. package/resources/beta/user-profiles.d.ts.map +1 -1
  448. package/resources/beta/user-profiles.mjs.map +1 -1
  449. package/resources/beta/vaults/credentials.d.mts.map +1 -1
  450. package/resources/beta/vaults/credentials.d.ts.map +1 -1
  451. package/resources/beta/vaults/credentials.mjs.map +1 -1
  452. package/resources/beta/vaults/index.d.mts.map +1 -1
  453. package/resources/beta/vaults/index.d.ts.map +1 -1
  454. package/resources/beta/vaults/index.mjs.map +1 -1
  455. package/resources/beta/vaults/vaults.d.mts.map +1 -1
  456. package/resources/beta/vaults/vaults.d.ts.map +1 -1
  457. package/resources/beta/vaults/vaults.mjs.map +1 -1
  458. package/resources/beta/vaults.d.mts.map +1 -1
  459. package/resources/beta/vaults.d.ts.map +1 -1
  460. package/resources/beta/vaults.mjs.map +1 -1
  461. package/resources/beta/webhooks.d.mts.map +1 -1
  462. package/resources/beta/webhooks.d.ts.map +1 -1
  463. package/resources/beta/webhooks.mjs.map +1 -1
  464. package/resources/beta.d.mts.map +1 -1
  465. package/resources/beta.d.ts.map +1 -1
  466. package/resources/beta.mjs.map +1 -1
  467. package/resources/completions.d.mts.map +1 -1
  468. package/resources/completions.d.ts.map +1 -1
  469. package/resources/completions.mjs.map +1 -1
  470. package/resources/index.d.mts.map +1 -1
  471. package/resources/index.d.ts.map +1 -1
  472. package/resources/index.mjs.map +1 -1
  473. package/resources/messages/batches.d.mts.map +1 -1
  474. package/resources/messages/batches.d.ts.map +1 -1
  475. package/resources/messages/batches.mjs.map +1 -1
  476. package/resources/messages/index.d.mts.map +1 -1
  477. package/resources/messages/index.d.ts.map +1 -1
  478. package/resources/messages/index.mjs.map +1 -1
  479. package/resources/messages/messages.d.mts.map +1 -1
  480. package/resources/messages/messages.d.ts.map +1 -1
  481. package/resources/messages/messages.mjs.map +1 -1
  482. package/resources/messages.d.mts.map +1 -1
  483. package/resources/messages.d.ts.map +1 -1
  484. package/resources/messages.mjs.map +1 -1
  485. package/resources/models.d.mts.map +1 -1
  486. package/resources/models.d.ts.map +1 -1
  487. package/resources/models.mjs.map +1 -1
  488. package/resources.d.mts.map +1 -1
  489. package/resources.d.ts.map +1 -1
  490. package/resources.mjs.map +1 -1
  491. package/src/core/streaming.ts +2 -0
  492. package/src/helpers/beta/environments.ts +33 -0
  493. package/src/helpers/beta/json-schema.ts +7 -0
  494. package/src/helpers/beta/zod.ts +7 -0
  495. package/src/internal/utils/abort.ts +21 -0
  496. package/src/internal/utils/async-queue.ts +66 -0
  497. package/src/internal/utils/backoff.ts +41 -0
  498. package/src/internal/utils/promise.ts +18 -0
  499. package/src/internal/utils/sleep.ts +25 -2
  500. package/src/lib/environments/index.ts +23 -0
  501. package/src/lib/environments/poller.ts +253 -0
  502. package/src/lib/environments/worker.ts +395 -0
  503. package/src/lib/helper-client.ts +89 -0
  504. package/src/lib/tools/BetaRunnableTool.ts +82 -1
  505. package/src/lib/tools/BetaToolRunner.ts +2 -17
  506. package/src/lib/tools/SessionToolRunner.ts +591 -0
  507. package/src/resources/beta/agents/agents.ts +158 -0
  508. package/src/resources/beta/agents/index.ts +7 -0
  509. package/src/resources/beta/beta.ts +44 -20
  510. package/src/resources/beta/environments/environments.ts +625 -0
  511. package/src/resources/beta/environments/index.ts +42 -0
  512. package/src/resources/beta/environments/work.ts +697 -0
  513. package/src/resources/beta/environments.ts +1 -540
  514. package/src/resources/beta/index.ts +13 -1
  515. package/src/resources/beta/messages/messages.ts +5 -5
  516. package/src/resources/beta/sessions/events.ts +77 -3
  517. package/src/resources/beta/sessions/index.ts +4 -1
  518. package/src/resources/beta/sessions/sessions.ts +121 -3
  519. package/src/resources/beta/sessions/threads/index.ts +0 -1
  520. package/src/resources/beta/sessions/threads/threads.ts +4 -37
  521. package/src/resources/beta/skills/index.ts +1 -0
  522. package/src/resources/beta/skills/skills.ts +2 -0
  523. package/src/resources/beta/skills/versions.ts +44 -0
  524. package/src/tools/agent-toolset/fs-util.ts +154 -0
  525. package/src/tools/agent-toolset/node.ts +787 -0
  526. package/src/tools/agent-toolset/skills.ts +256 -0
  527. package/src/version.ts +1 -1
  528. package/streaming.d.mts +1 -0
  529. package/streaming.d.mts.map +1 -1
  530. package/streaming.d.ts +1 -0
  531. package/streaming.d.ts.map +1 -1
  532. package/streaming.mjs +1 -0
  533. package/streaming.mjs.map +1 -1
  534. package/tools/agent-toolset/fs-util.d.mts +49 -0
  535. package/tools/agent-toolset/fs-util.d.mts.map +1 -0
  536. package/tools/agent-toolset/fs-util.d.ts +49 -0
  537. package/tools/agent-toolset/fs-util.d.ts.map +1 -0
  538. package/tools/agent-toolset/fs-util.js +159 -0
  539. package/tools/agent-toolset/fs-util.js.map +1 -0
  540. package/tools/agent-toolset/fs-util.mjs +151 -0
  541. package/tools/agent-toolset/fs-util.mjs.map +1 -0
  542. package/tools/agent-toolset/node.d.mts +139 -0
  543. package/tools/agent-toolset/node.d.mts.map +1 -0
  544. package/tools/agent-toolset/node.d.ts +139 -0
  545. package/tools/agent-toolset/node.d.ts.map +1 -0
  546. package/tools/agent-toolset/node.js +746 -0
  547. package/tools/agent-toolset/node.js.map +1 -0
  548. package/tools/agent-toolset/node.mjs +731 -0
  549. package/tools/agent-toolset/node.mjs.map +1 -0
  550. package/tools/agent-toolset/skills.d.mts +50 -0
  551. package/tools/agent-toolset/skills.d.mts.map +1 -0
  552. package/tools/agent-toolset/skills.d.ts +50 -0
  553. package/tools/agent-toolset/skills.d.ts.map +1 -0
  554. package/tools/agent-toolset/skills.js +249 -0
  555. package/tools/agent-toolset/skills.js.map +1 -0
  556. package/tools/agent-toolset/skills.mjs +243 -0
  557. package/tools/agent-toolset/skills.mjs.map +1 -0
  558. package/tools/memory/node.d.mts.map +1 -1
  559. package/tools/memory/node.d.ts.map +1 -1
  560. package/tools/memory/node.mjs.map +1 -1
  561. package/uploads.d.mts +1 -0
  562. package/uploads.d.mts.map +1 -1
  563. package/uploads.d.ts +1 -0
  564. package/uploads.d.ts.map +1 -1
  565. package/uploads.mjs +1 -0
  566. package/uploads.mjs.map +1 -1
  567. package/version.d.mts +1 -1
  568. package/version.d.ts +1 -1
  569. package/version.js +1 -1
  570. package/version.mjs +1 -1
@@ -0,0 +1,140 @@
1
+ import type { Anthropic } from "../../client.js";
2
+ import type { BetaManagedAgentsAgentCustomToolUseEvent, BetaManagedAgentsAgentToolUseEvent, BetaManagedAgentsUserCustomToolResultEventParams, BetaManagedAgentsUserToolResultEventParams } from "../../resources/beta/sessions/events.js";
3
+ import { type BetaRunnableTool } from "./BetaRunnableTool.js";
4
+ import type { BetaToolRunnerRequestOptions } from "./BetaToolRunner.js";
5
+ /** Beta header for the managed-agents API. */
6
+ export declare const MANAGED_AGENTS_BETA = "managed-agents-2026-04-01";
7
+ /**
8
+ * A tool-call event the runner dispatches against the local registry: either a
9
+ * builtin `agent.tool_use` (answered with `user.tool_result`) or a custom
10
+ * `agent.custom_tool_use` (answered with `user.custom_tool_result`). Server-side
11
+ * `agent.mcp_tool_use` calls are intentionally excluded — the runner does not
12
+ * handle them.
13
+ */
14
+ type DispatchedToolUseEvent = BetaManagedAgentsAgentToolUseEvent | BetaManagedAgentsAgentCustomToolUseEvent;
15
+ /**
16
+ * The result-event params paired with a {@link DispatchedToolUseEvent}: a
17
+ * `user.tool_result` answers an `agent.tool_use`, a `user.custom_tool_result`
18
+ * answers an `agent.custom_tool_use`. The two pairs must be matched exactly.
19
+ */
20
+ type DispatchedToolResultParams = BetaManagedAgentsUserToolResultEventParams | BetaManagedAgentsUserCustomToolResultEventParams;
21
+ export interface SessionToolRunnerOptions {
22
+ client: Anthropic;
23
+ /**
24
+ * Tools to expose to the session, in the same {@link BetaRunnableTool} shape
25
+ * `client.beta.messages.toolRunner` accepts. Use
26
+ * `betaAgentToolset20260401({ workdir })` from
27
+ * `@anthropic-ai/sdk/tools/agent-toolset/node` for the standard
28
+ * `agent_toolset_20260401` set; filter or extend the array to customise.
29
+ */
30
+ tools: Array<BetaRunnableTool>;
31
+ /**
32
+ * Once the session goes idle with `stop_reason.type === "end_turn"`, the
33
+ * runner keeps running for this many milliseconds before stopping; any new
34
+ * event resets the countdown and it re-arms on the next `end_turn` idle.
35
+ * Defaults to {@link DEFAULT_MAX_IDLE_MS} (60s). `0` (or negative) disables
36
+ * it — the runner then only stops on session termination or the consumer
37
+ * breaking out / aborting.
38
+ */
39
+ maxIdleMs?: number;
40
+ /** External abort signal. Aborting it ends the iteration. */
41
+ signal?: AbortSignal;
42
+ /**
43
+ * Extra per-request options merged into every call this runner issues
44
+ * (event stream / list / send). Mirrors what `client.beta.messages.toolRunner`
45
+ * accepts: custom `headers` (e.g. a proxy's auth/routing headers) reach the
46
+ * poll/heartbeat/stop/stream/list/send calls. The runner always owns the abort
47
+ * signal, so a `signal` here is ignored — pass {@link SessionToolRunnerOptions.signal}
48
+ * to abort externally.
49
+ */
50
+ requestOptions?: BetaToolRunnerRequestOptions;
51
+ }
52
+ /** Default {@link SessionToolRunnerOptions.maxIdleMs}: 60 seconds. */
53
+ export declare const DEFAULT_MAX_IDLE_MS = 60000;
54
+ /**
55
+ * Outcome of a single tool execution dispatched by {@link SessionToolRunner}.
56
+ *
57
+ * Yielded after the tool ran (or failed) and after the result was posted back
58
+ * to the session as a `user.tool_result` event. Consumers can read either the
59
+ * embedded {@link DispatchedToolCall.event} / {@link DispatchedToolCall.result}
60
+ * blocks or the flat top-level convenience fields.
61
+ */
62
+ export interface DispatchedToolCall {
63
+ /**
64
+ * The `agent.tool_use` or `agent.custom_tool_use` event that triggered this
65
+ * dispatch. Read `event.input` for the raw tool input and `event.name` for the
66
+ * tool name; `event.type` distinguishes a builtin tool call from a custom one.
67
+ */
68
+ readonly event: DispatchedToolUseEvent;
69
+ /**
70
+ * The result event posted (or attempted) back to the session for this call: a
71
+ * `user.tool_result` for an `agent.tool_use`, a `user.custom_tool_result` for
72
+ * an `agent.custom_tool_use`. Read `result.content` for the tool's output
73
+ * blocks and `result.is_error` for the error flag.
74
+ */
75
+ readonly result: DispatchedToolResultParams;
76
+ /**
77
+ * Flat convenience for `event.id` — the id of the tool-use event this result
78
+ * answers (echoed back as `tool_use_id` / `custom_tool_use_id` on the result).
79
+ */
80
+ readonly toolUseId: string;
81
+ /** Flat convenience for `event.name` — the dispatched tool's name. */
82
+ readonly name: string;
83
+ /**
84
+ * Flat convenience for `result.is_error` — `true` when the tool threw or was
85
+ * not found, `false` on success.
86
+ */
87
+ readonly isError: boolean;
88
+ /**
89
+ * Whether the `user.tool_result` was successfully posted back to the session.
90
+ * `false` when the post itself failed — typically a permanent 4xx or
91
+ * send-retry exhaustion.
92
+ */
93
+ readonly posted: boolean;
94
+ }
95
+ /**
96
+ * The sessions-side counterpart to `client.beta.messages.toolRunner`: an
97
+ * async-iterable that attaches to a managed-agents session, executes every
98
+ * incoming `agent.tool_use` and `agent.custom_tool_use` event against a local
99
+ * tool registry, posts the matching result back (`user.tool_result` for the
100
+ * former, `user.custom_tool_result` for the latter), and yields one
101
+ * {@link DispatchedToolCall} per completed call. Server-side `agent.mcp_tool_use`
102
+ * calls are not dispatched. Internally drives event-stream reconnect and result
103
+ * posting.
104
+ *
105
+ * Iteration ends when the session terminates (`session.status_terminated` /
106
+ * `session.deleted`), when the consumer `break`s out of the loop or aborts the
107
+ * supplied signal, or — once the session has gone idle with
108
+ * `stop_reason.type === "end_turn"` — when `maxIdleMs` elapses with no new
109
+ * event (any new event resets that countdown; it re-arms on the next `end_turn`
110
+ * idle; `maxIdleMs <= 0` disables it). The `finally` branch drains any in-flight
111
+ * tool calls and runs each tool's `close()` cleanup hook. It does *not* touch
112
+ * the work-item lease — wrap it in an `EnvironmentWorker` if you need
113
+ * heartbeating / force-stop.
114
+ *
115
+ * @example
116
+ * ```ts
117
+ * import { betaAgentToolset20260401 } from '@anthropic-ai/sdk/tools/agent-toolset/node';
118
+ *
119
+ * for await (const call of client.beta.sessions.events.toolRunner(work.data.id, {
120
+ * tools: [...betaAgentToolset20260401({ workdir }), myTool],
121
+ * })) {
122
+ * console.log(`${call.name} -> ${call.isError ? 'error' : 'ok'}`);
123
+ * }
124
+ * ```
125
+ */
126
+ export declare class SessionToolRunner implements AsyncIterable<DispatchedToolCall> {
127
+ #private;
128
+ readonly client: Anthropic;
129
+ readonly sessionId: string;
130
+ readonly tools: ReadonlyArray<BetaRunnableTool>;
131
+ readonly maxIdleMs: number;
132
+ constructor(sessionId: string, opts: SessionToolRunnerOptions);
133
+ /** Read-only view of this runner's abort signal. */
134
+ get signal(): AbortSignal;
135
+ /** Abort the runner. Background tasks will wind down and `for await` will exit cleanly. */
136
+ abort(): void;
137
+ [Symbol.asyncIterator](): AsyncIterator<DispatchedToolCall>;
138
+ }
139
+ export {};
140
+ //# sourceMappingURL=SessionToolRunner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionToolRunner.d.ts","sourceRoot":"","sources":["../../src/lib/tools/SessionToolRunner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,wBAAqB;AAC9C,OAAO,KAAK,EACV,wCAAwC,EACxC,kCAAkC,EAGlC,gDAAgD,EAChD,0CAA0C,EAC3C,gDAA6C;AAS9C,OAAO,EAA6B,KAAK,gBAAgB,EAAE,8BAA2B;AACtF,OAAO,KAAK,EAAE,4BAA4B,EAAE,4BAAyB;AAErE,8CAA8C;AAC9C,eAAO,MAAM,mBAAmB,8BAA8B,CAAC;AAc/D;;;;;;GAMG;AACH,KAAK,sBAAsB,GAAG,kCAAkC,GAAG,wCAAwC,CAAC;AAE5G;;;;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IAC3F,KAAK,IAAI,IAAI;IAIN,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,kBAAkB,CAAC;CA8UnE"}
@@ -0,0 +1,459 @@
1
+ "use strict";
2
+ var _SessionToolRunner_instances, _SessionToolRunner_consumed, _SessionToolRunner_controller, _SessionToolRunner_detachExternal, _SessionToolRunner_requestOpts, _SessionToolRunner_toolByName, _SessionToolRunner_logger, _SessionToolRunner_seen, _SessionToolRunner_answered, _SessionToolRunner_results, _SessionToolRunner_inFlightCount, _SessionToolRunner_onIdle, _SessionToolRunner_idleTimer, _SessionToolRunner_requestOptions, _SessionToolRunner_streamLoop, _SessionToolRunner_reconcile, _SessionToolRunner_ingestHistory, _SessionToolRunner_handleStreamEvent, _SessionToolRunner_armIdleTimer, _SessionToolRunner_disarmIdleTimer, _SessionToolRunner_execute, _SessionToolRunner_sendResult, _SessionToolRunner_drain;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.SessionToolRunner = exports.DEFAULT_MAX_IDLE_MS = exports.MANAGED_AGENTS_BETA = void 0;
5
+ const tslib_1 = require("../../internal/tslib.js");
6
+ const error_1 = require("../../core/error.js");
7
+ const log_1 = require("../../internal/utils/log.js");
8
+ const sleep_1 = require("../../internal/utils/sleep.js");
9
+ const backoff_1 = require("../../internal/utils/backoff.js");
10
+ const abort_1 = require("../../internal/utils/abort.js");
11
+ const async_queue_1 = require("../../internal/utils/async-queue.js");
12
+ const headers_1 = require("../../internal/headers.js");
13
+ const BetaRunnableTool_1 = require("./BetaRunnableTool.js");
14
+ /** Beta header for the managed-agents API. */
15
+ exports.MANAGED_AGENTS_BETA = 'managed-agents-2026-04-01';
16
+ /** `x-stainless-helper` value identifying this helper in SDK telemetry. */
17
+ const HELPER_NAME = 'SessionToolRunner';
18
+ const STREAM_BACKOFF_START_MS = 500;
19
+ const STREAM_BACKOFF_CAP_MS = 10000;
20
+ const TOOL_TIMEOUT_MS = 120000;
21
+ const DRAIN_TIMEOUT_MS = 30000;
22
+ const SEND_RETRIES = 3;
23
+ /** Default {@link SessionToolRunnerOptions.maxIdleMs}: 60 seconds. */
24
+ exports.DEFAULT_MAX_IDLE_MS = 60000;
25
+ /** Returns true if `ev` is a `session.status_idle` with `stop_reason` `end_turn`. */
26
+ function isEndTurnIdle(ev) {
27
+ return ev.type === 'session.status_idle' && ev.stop_reason?.type === 'end_turn';
28
+ }
29
+ /**
30
+ * The sessions-side counterpart to `client.beta.messages.toolRunner`: an
31
+ * async-iterable that attaches to a managed-agents session, executes every
32
+ * incoming `agent.tool_use` and `agent.custom_tool_use` event against a local
33
+ * tool registry, posts the matching result back (`user.tool_result` for the
34
+ * former, `user.custom_tool_result` for the latter), and yields one
35
+ * {@link DispatchedToolCall} per completed call. Server-side `agent.mcp_tool_use`
36
+ * calls are not dispatched. Internally drives event-stream reconnect and result
37
+ * posting.
38
+ *
39
+ * Iteration ends when the session terminates (`session.status_terminated` /
40
+ * `session.deleted`), when the consumer `break`s out of the loop or aborts the
41
+ * supplied signal, or — once the session has gone idle with
42
+ * `stop_reason.type === "end_turn"` — when `maxIdleMs` elapses with no new
43
+ * event (any new event resets that countdown; it re-arms on the next `end_turn`
44
+ * idle; `maxIdleMs <= 0` disables it). The `finally` branch drains any in-flight
45
+ * tool calls and runs each tool's `close()` cleanup hook. It does *not* touch
46
+ * the work-item lease — wrap it in an `EnvironmentWorker` if you need
47
+ * heartbeating / force-stop.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { betaAgentToolset20260401 } from '@anthropic-ai/sdk/tools/agent-toolset/node';
52
+ *
53
+ * for await (const call of client.beta.sessions.events.toolRunner(work.data.id, {
54
+ * tools: [...betaAgentToolset20260401({ workdir }), myTool],
55
+ * })) {
56
+ * console.log(`${call.name} -> ${call.isError ? 'error' : 'ok'}`);
57
+ * }
58
+ * ```
59
+ */
60
+ class SessionToolRunner {
61
+ constructor(sessionId, opts) {
62
+ _SessionToolRunner_instances.add(this);
63
+ _SessionToolRunner_consumed.set(this, false);
64
+ _SessionToolRunner_controller.set(this, void 0);
65
+ _SessionToolRunner_detachExternal.set(this, void 0);
66
+ _SessionToolRunner_requestOpts.set(this, void 0);
67
+ _SessionToolRunner_toolByName.set(this, void 0);
68
+ _SessionToolRunner_logger.set(this, void 0);
69
+ _SessionToolRunner_seen.set(this, new Set());
70
+ _SessionToolRunner_answered.set(this, new Set());
71
+ _SessionToolRunner_results.set(this, new async_queue_1.AsyncQueue());
72
+ _SessionToolRunner_inFlightCount.set(this, 0);
73
+ _SessionToolRunner_onIdle.set(this, null);
74
+ // When the session is idle past an `end_turn`, the pending stop timer; cleared
75
+ // by any new event. Event-driven — there is no polling watchdog.
76
+ _SessionToolRunner_idleTimer.set(this, void 0);
77
+ this.client = opts.client;
78
+ this.sessionId = sessionId;
79
+ this.tools = opts.tools;
80
+ this.maxIdleMs = opts.maxIdleMs ?? exports.DEFAULT_MAX_IDLE_MS;
81
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_logger, (0, log_1.loggerFor)(opts.client), "f");
82
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_toolByName, new Map(opts.tools.map((t) => [(0, BetaRunnableTool_1.toolName)(t), t])), "f");
83
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_controller, new AbortController(), "f");
84
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_detachExternal, (0, abort_1.linkAbort)(opts.signal, tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f")), "f");
85
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_requestOpts, opts.requestOptions, "f");
86
+ }
87
+ /** Read-only view of this runner's abort signal. */
88
+ get signal() {
89
+ return tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").signal;
90
+ }
91
+ /** Abort the runner. Background tasks will wind down and `for await` will exit cleanly. */
92
+ abort() {
93
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
94
+ }
95
+ async *[(_SessionToolRunner_consumed = new WeakMap(), _SessionToolRunner_controller = new WeakMap(), _SessionToolRunner_detachExternal = new WeakMap(), _SessionToolRunner_requestOpts = new WeakMap(), _SessionToolRunner_toolByName = new WeakMap(), _SessionToolRunner_logger = new WeakMap(), _SessionToolRunner_seen = new WeakMap(), _SessionToolRunner_answered = new WeakMap(), _SessionToolRunner_results = new WeakMap(), _SessionToolRunner_inFlightCount = new WeakMap(), _SessionToolRunner_onIdle = new WeakMap(), _SessionToolRunner_idleTimer = new WeakMap(), _SessionToolRunner_instances = new WeakSet(), Symbol.asyncIterator)]() {
96
+ if (tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_consumed, "f")) {
97
+ throw new error_1.AnthropicError('Cannot iterate over a consumed SessionToolRunner');
98
+ }
99
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_consumed, true, "f");
100
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info('session tool runner starting', {
101
+ component: 'session-tool-runner',
102
+ session_id: this.sessionId,
103
+ });
104
+ // The one background promise: drives the event stream and dispatches tools.
105
+ // Its `.catch` aborts the controller so the main loop unwinds.
106
+ const streamPromise = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_streamLoop).call(this).catch((e) => {
107
+ if (!tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").signal.aborted) {
108
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").error('stream loop failed', { error: String(e) });
109
+ }
110
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
111
+ });
112
+ try {
113
+ // Phase 1: yield results as they arrive. `next(signal)` resolves
114
+ // `done: true` when the controller aborts — cancellation is handled in
115
+ // the queue read, no outer `Promise.race` needed.
116
+ while (true) {
117
+ const next = await tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_results, "f").next(tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").signal);
118
+ if (next.done)
119
+ break;
120
+ yield next.value;
121
+ }
122
+ // Phase 2: let the stream loop settle (and push any final results), then
123
+ // drain whatever is still queued before closing.
124
+ await streamPromise;
125
+ let pending;
126
+ while ((pending = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_results, "f").tryShift()) !== undefined) {
127
+ yield pending;
128
+ }
129
+ }
130
+ finally {
131
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
132
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_disarmIdleTimer).call(this);
133
+ // Re-await defensively in case the consumer broke out of phase 1 before
134
+ // phase 2 ran — a no-op if it already settled.
135
+ await streamPromise;
136
+ try {
137
+ await tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_drain).call(this);
138
+ }
139
+ catch (e) {
140
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").warn('drain failed', { error: String(e) });
141
+ }
142
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_results, "f").close();
143
+ for (const t of this.tools) {
144
+ try {
145
+ // `close` is typed `() => Promisable<void>`, so a single `await`
146
+ // covers both the sync and async return.
147
+ await t.close?.();
148
+ }
149
+ catch (e) {
150
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").warn('tool.close failed', { tool: (0, BetaRunnableTool_1.toolName)(t), error: String(e) });
151
+ }
152
+ }
153
+ // Detach from the external signal so the consumer can drop their signal
154
+ // reference without leaking this iterator instance.
155
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_detachExternal, "f").call(this);
156
+ }
157
+ }
158
+ }
159
+ exports.SessionToolRunner = SessionToolRunner;
160
+ _SessionToolRunner_requestOptions = function _SessionToolRunner_requestOptions() {
161
+ return {
162
+ ...tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_requestOpts, "f"),
163
+ headers: (0, headers_1.buildHeaders)([{ 'x-stainless-helper': HELPER_NAME }, tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_requestOpts, "f")?.headers]),
164
+ signal: tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").signal,
165
+ };
166
+ }, _SessionToolRunner_streamLoop =
167
+ // ===== event stream =====
168
+ async function _SessionToolRunner_streamLoop() {
169
+ const ctrl = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f");
170
+ let backoff = STREAM_BACKOFF_START_MS;
171
+ while (!ctrl.signal.aborted) {
172
+ try {
173
+ // Establish the event stream *before* reconciling history, so an event
174
+ // emitted in the gap between listing and attaching is buffered on the
175
+ // stream rather than lost. `seen`/`answered` dedup any event that shows
176
+ // up both in the reconcile pass and on the live stream.
177
+ const stream = await this.client.beta.sessions.events.stream(this.sessionId, {}, tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_requestOptions).call(this));
178
+ await tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_reconcile).call(this);
179
+ for await (const ev of stream) {
180
+ backoff = STREAM_BACKOFF_START_MS;
181
+ if (await tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_handleStreamEvent).call(this, ev))
182
+ return;
183
+ }
184
+ }
185
+ catch (e) {
186
+ // An abort throws to unwind the caller (the iterator's `streamPromise`
187
+ // `.catch`) rather than returning early and letting it carry on.
188
+ ctrl.signal.throwIfAborted();
189
+ if ((0, backoff_1.isFatal4xx)(e)) {
190
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").error('permanent stream failure, shutting down', { error: String(e) });
191
+ ctrl.abort();
192
+ throw e;
193
+ }
194
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").warn('stream disconnected, reconnecting', {
195
+ error: String(e),
196
+ backoff_ms: backoff,
197
+ });
198
+ }
199
+ ctrl.signal.throwIfAborted();
200
+ await (0, sleep_1.sleep)(backoff, ctrl.signal);
201
+ backoff = Math.min(backoff * 2, STREAM_BACKOFF_CAP_MS);
202
+ }
203
+ }, _SessionToolRunner_reconcile =
204
+ /**
205
+ * Read full history before dispatching so a `tool_use` whose result appears
206
+ * later in the same history is not re-executed. Runs after the live stream is
207
+ * already attached (see {@link SessionToolRunner.#streamLoop}).
208
+ */
209
+ async function _SessionToolRunner_reconcile() {
210
+ const ctrl = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f");
211
+ const pending = [];
212
+ let lastWasEndTurn = false;
213
+ try {
214
+ for await (const ev of this.client.beta.sessions.events.list(this.sessionId, { limit: 1000 }, tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_requestOptions).call(this))) {
215
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_ingestHistory).call(this, ev, pending);
216
+ lastWasEndTurn = isEndTurnIdle(ev);
217
+ }
218
+ }
219
+ catch (e) {
220
+ // An abort throws to unwind the caller; a real list failure is
221
+ // non-fatal — undo the speculative `seen` entries and let `#streamLoop`
222
+ // carry on with the live stream.
223
+ ctrl.signal.throwIfAborted();
224
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").warn('reconcile list failed', { error: String(e) });
225
+ // If list itself failed, undo the speculative `seen` entries so the next
226
+ // reconcile pass (or the live stream) can pick them up. Leave the idle
227
+ // timer untouched — the history we read may be incomplete.
228
+ for (const ev of pending)
229
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_seen, "f").delete(ev.id);
230
+ return;
231
+ }
232
+ const unanswered = pending.filter((ev) => !tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").has(ev.id));
233
+ // If the most recent event in history is an `end_turn` idle and there's no
234
+ // outstanding tool work, the session is done — arm the idle timer so the
235
+ // runner stops even if that `end_turn` arrived during a disconnect.
236
+ if (lastWasEndTurn && unanswered.length === 0)
237
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_armIdleTimer).call(this);
238
+ else
239
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_disarmIdleTimer).call(this);
240
+ for (const ev of unanswered)
241
+ await tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_execute).call(this, ev);
242
+ }, _SessionToolRunner_ingestHistory = function _SessionToolRunner_ingestHistory(ev, pending) {
243
+ if (ev.type === 'agent.tool_use' || ev.type === 'agent.custom_tool_use') {
244
+ // Mark the event seen so a replay on the live stream is not dispatched
245
+ // twice, but decide whether it still needs executing from `answered`, not
246
+ // `seen`: a call whose result post failed is seen-but-unanswered, and must
247
+ // be retried on the next reconcile pass rather than silently dropped.
248
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_seen, "f").add(ev.id);
249
+ if (!tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").has(ev.id))
250
+ pending.push(ev);
251
+ }
252
+ else if (ev.type === 'user.tool_result') {
253
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.tool_use_id);
254
+ }
255
+ else if (ev.type === 'user.custom_tool_result') {
256
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.custom_tool_use_id);
257
+ }
258
+ }, _SessionToolRunner_handleStreamEvent =
259
+ /** Returns true when the runner should exit. */
260
+ async function _SessionToolRunner_handleStreamEvent(ev) {
261
+ // Arm/disarm the idle timer: an `end_turn` idle starts the grace countdown;
262
+ // any other event cancels it.
263
+ if (isEndTurnIdle(ev))
264
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_armIdleTimer).call(this);
265
+ else
266
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_disarmIdleTimer).call(this);
267
+ switch (ev.type) {
268
+ case 'agent.tool_use':
269
+ case 'agent.custom_tool_use':
270
+ if (!tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_seen, "f").has(ev.id)) {
271
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_seen, "f").add(ev.id);
272
+ await tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_execute).call(this, ev);
273
+ }
274
+ return false;
275
+ case 'user.tool_result':
276
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.tool_use_id);
277
+ return false;
278
+ case 'user.custom_tool_result':
279
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(ev.custom_tool_use_id);
280
+ return false;
281
+ case 'session.status_terminated':
282
+ case 'session.deleted':
283
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info('session terminated', {
284
+ component: 'session-tool-runner',
285
+ session_id: this.sessionId,
286
+ });
287
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
288
+ return true;
289
+ default:
290
+ return false;
291
+ }
292
+ }, _SessionToolRunner_armIdleTimer = function _SessionToolRunner_armIdleTimer() {
293
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_disarmIdleTimer).call(this);
294
+ if (this.maxIdleMs <= 0)
295
+ return;
296
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_idleTimer, setTimeout(() => {
297
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info('session idle after end_turn; stopping', {
298
+ component: 'session-tool-runner',
299
+ session_id: this.sessionId,
300
+ max_idle_ms: this.maxIdleMs,
301
+ });
302
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").abort();
303
+ }, this.maxIdleMs), "f");
304
+ }, _SessionToolRunner_disarmIdleTimer = function _SessionToolRunner_disarmIdleTimer() {
305
+ if (tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_idleTimer, "f") !== undefined) {
306
+ clearTimeout(tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_idleTimer, "f"));
307
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_idleTimer, undefined, "f");
308
+ }
309
+ }, _SessionToolRunner_execute =
310
+ // ===== tool execution =====
311
+ async function _SessionToolRunner_execute(ev) {
312
+ var _a, _b;
313
+ if (tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").has(ev.id))
314
+ return;
315
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").info('executing tool', {
316
+ component: 'session-tool-runner',
317
+ session_id: this.sessionId,
318
+ tool: ev.name,
319
+ tool_use_id: ev.id,
320
+ });
321
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_inFlightCount, (_a = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_inFlightCount, "f"), _a++, _a), "f");
322
+ try {
323
+ const tool = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_toolByName, "f").get(ev.name);
324
+ let content;
325
+ let isError;
326
+ if (!tool) {
327
+ // Match `BetaToolRunner`'s wording — the string lands in the model's
328
+ // context, so the two `toolRunner()` surfaces should agree.
329
+ content = `Error: Tool '${ev.name}' not found`;
330
+ isError = true;
331
+ }
332
+ else {
333
+ // Per-tool controller: aborts on the runner's own signal *or* the
334
+ // per-tool timeout, so an in-flight tool stops promptly when the runner
335
+ // is aborted instead of running until the timeout.
336
+ const toolCtrl = new AbortController();
337
+ const detachTool = (0, abort_1.linkAbort)(tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f").signal, toolCtrl);
338
+ const timer = setTimeout(() => toolCtrl.abort(), TOOL_TIMEOUT_MS);
339
+ try {
340
+ // Pass the source `agent.tool_use` / `agent.custom_tool_use` event
341
+ // straight through as the run context's `toolUse` — it is a union
342
+ // member of `BetaToolUse`, no Messages-block adapter needed.
343
+ const outcome = await (0, BetaRunnableTool_1.runRunnableTool)(tool, ev.input, {
344
+ toolUse: ev,
345
+ toolUseBlock: ev,
346
+ signal: toolCtrl.signal,
347
+ });
348
+ content = outcome.content;
349
+ isError = outcome.isError;
350
+ }
351
+ finally {
352
+ clearTimeout(timer);
353
+ detachTool();
354
+ }
355
+ }
356
+ // Answer with the result event that matches the call kind: a
357
+ // `user.tool_result` for an `agent.tool_use`, a `user.custom_tool_result`
358
+ // for an `agent.custom_tool_use`. Posting the wrong one leaves the call
359
+ // unanswered and the session stuck.
360
+ const result = buildResultEvent(ev, isError, toSessionContent(content));
361
+ const posted = await tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_sendResult).call(this, result, ev.id);
362
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_results, "f").push({
363
+ event: ev,
364
+ result,
365
+ toolUseId: ev.id,
366
+ name: ev.name,
367
+ isError,
368
+ posted,
369
+ });
370
+ }
371
+ finally {
372
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_inFlightCount, (_b = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_inFlightCount, "f"), _b--, _b), "f");
373
+ if (tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_inFlightCount, "f") === 0)
374
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_onIdle, "f")?.call(this);
375
+ }
376
+ }, _SessionToolRunner_sendResult = async function _SessionToolRunner_sendResult(result, toolUseId) {
377
+ const ctrl = tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_controller, "f");
378
+ let lastErr;
379
+ for (let i = 0; i < SEND_RETRIES; i++) {
380
+ // An abort throws to unwind the caller rather than returning a
381
+ // `posted: false` result the iterator would carry on past.
382
+ ctrl.signal.throwIfAborted();
383
+ try {
384
+ await this.client.beta.sessions.events.send(this.sessionId, { events: [result] }, tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_instances, "m", _SessionToolRunner_requestOptions).call(this));
385
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_answered, "f").add(toolUseId);
386
+ return true;
387
+ }
388
+ catch (e) {
389
+ lastErr = e;
390
+ // Only short-circuit on a permanent 4xx; 408/409/429 deserve the
391
+ // remaining retries (aligned with the core client's retry policy).
392
+ if ((0, backoff_1.isFatal4xx)(e))
393
+ break;
394
+ // Back off only *between* attempts — never after the final one, since
395
+ // there is no further try left to wait for.
396
+ if (i < SEND_RETRIES - 1)
397
+ await (0, sleep_1.sleep)((i + 1) * 1000, ctrl.signal);
398
+ }
399
+ }
400
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").error('failed to send tool result', {
401
+ tool_use_id: toolUseId,
402
+ error: String(lastErr),
403
+ });
404
+ return false;
405
+ }, _SessionToolRunner_drain =
406
+ /** Wait (bounded) for in-flight tool executions to finish during teardown. */
407
+ async function _SessionToolRunner_drain() {
408
+ if (tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_inFlightCount, "f") === 0)
409
+ return;
410
+ await Promise.race([new Promise((r) => (tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_onIdle, r, "f"))), (0, sleep_1.sleep)(DRAIN_TIMEOUT_MS)]);
411
+ tslib_1.__classPrivateFieldSet(this, _SessionToolRunner_onIdle, null, "f");
412
+ if (tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_inFlightCount, "f") > 0) {
413
+ tslib_1.__classPrivateFieldGet(this, _SessionToolRunner_logger, "f").warn('drain timeout exceeded');
414
+ }
415
+ };
416
+ /**
417
+ * Build the result event that answers `ev`: a `user.tool_result` for a builtin
418
+ * `agent.tool_use`, a `user.custom_tool_result` for a custom
419
+ * `agent.custom_tool_use`. The two `(use, result)` pairs are distinct API event
420
+ * types and must be matched exactly — a `user.tool_result` does not answer a
421
+ * custom tool call.
422
+ */
423
+ function buildResultEvent(ev, isError, content) {
424
+ if (ev.type === 'agent.custom_tool_use') {
425
+ return { type: 'user.custom_tool_result', custom_tool_use_id: ev.id, is_error: isError, content };
426
+ }
427
+ return { type: 'user.tool_result', tool_use_id: ev.id, is_error: isError, content };
428
+ }
429
+ // The Messages-API tool-result block union is wider than the Sessions-API
430
+ // tool_result content union; pass through text/image/document and stringify
431
+ // anything else so a BetaRunnableTool authored for toolRunner still works here.
432
+ function toSessionContent(content) {
433
+ if (typeof content === 'string')
434
+ return [{ type: 'text', text: content || '(no output)' }];
435
+ const out = content.map((b) => {
436
+ if (b.type === 'text')
437
+ return { type: 'text', text: b.text || '(no output)' };
438
+ if (b.type === 'image' || b.type === 'document')
439
+ return b;
440
+ if (b.type === 'search_result') {
441
+ // The Messages `search_result` block param maps field-for-field onto the
442
+ // Sessions `BetaManagedAgentsSearchResultBlock`; map it explicitly rather
443
+ // than letting it fall through to the JSON.stringify branch (which would
444
+ // bury a structured result inside a text block). `citations` is required
445
+ // on the Sessions side and optional on the Messages side — default the
446
+ // flag to `false` when the producer left it unset.
447
+ return {
448
+ type: 'search_result',
449
+ source: b.source,
450
+ title: b.title,
451
+ content: b.content.map((c) => ({ type: 'text', text: c.text })),
452
+ citations: { enabled: b.citations?.enabled ?? false },
453
+ };
454
+ }
455
+ return { type: 'text', text: JSON.stringify(b) };
456
+ });
457
+ return out.length > 0 ? out : [{ type: 'text', text: '(no output)' }];
458
+ }
459
+ //# sourceMappingURL=SessionToolRunner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SessionToolRunner.js","sourceRoot":"","sources":["../../src/lib/tools/SessionToolRunner.ts"],"names":[],"mappings":";;;;;AAAA,+CAAkD;AAWlD,qDAAkE;AAClE,yDAAmD;AACnD,6DAA0D;AAC1D,yDAAuD;AACvD,qEAA8D;AAC9D,uDAAsD;AAEtD,4DAAsF;AAGtF,8CAA8C;AACjC,QAAA,mBAAmB,GAAG,2BAA2B,CAAC;AAE/D,2EAA2E;AAC3E,MAAM,WAAW,GAAG,mBAAmB,CAAC;AAExC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,qBAAqB,GAAG,KAAM,CAAC;AACrC,MAAM,eAAe,GAAG,MAAO,CAAC;AAChC,MAAM,gBAAgB,GAAG,KAAM,CAAC;AAChC,MAAM,YAAY,GAAG,CAAC,CAAC;AAuDvB,sEAAsE;AACzD,QAAA,mBAAmB,GAAG,KAAM,CAAC;AA4C1C,qFAAq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