@alvin0/ai-agent-sdk-core 0.1.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 (623) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/dist/agent/accounting/common.js +2 -0
  4. package/dist/agent/accounting/common.js.map +1 -0
  5. package/dist/agent/accounting/config.js +2 -0
  6. package/dist/agent/accounting/config.js.map +1 -0
  7. package/dist/agent/accounting/contracts.d.ts +36 -0
  8. package/dist/agent/accounting/contracts.d.ts.map +1 -0
  9. package/dist/agent/accounting/delivery/accounting-data.js +2 -0
  10. package/dist/agent/accounting/delivery/accounting-data.js.map +1 -0
  11. package/dist/agent/accounting/delivery/config.js +2 -0
  12. package/dist/agent/accounting/delivery/config.js.map +1 -0
  13. package/dist/agent/accounting/delivery/data.js +2 -0
  14. package/dist/agent/accounting/delivery/data.js.map +1 -0
  15. package/dist/agent/accounting/delivery/support-errors.js +2 -0
  16. package/dist/agent/accounting/delivery/support-errors.js.map +1 -0
  17. package/dist/agent/accounting/delivery/terminal.js +2 -0
  18. package/dist/agent/accounting/delivery/terminal.js.map +1 -0
  19. package/dist/agent/accounting/delivery-types.d.ts +43 -0
  20. package/dist/agent/accounting/delivery-types.d.ts.map +1 -0
  21. package/dist/agent/accounting/error.d.ts +18 -0
  22. package/dist/agent/accounting/error.d.ts.map +1 -0
  23. package/dist/agent/accounting/error.js +2 -0
  24. package/dist/agent/accounting/error.js.map +1 -0
  25. package/dist/agent/accounting/estimate.js +2 -0
  26. package/dist/agent/accounting/estimate.js.map +1 -0
  27. package/dist/agent/accounting/event-buffer.js +2 -0
  28. package/dist/agent/accounting/event-buffer.js.map +1 -0
  29. package/dist/agent/accounting/ledger.js +2 -0
  30. package/dist/agent/accounting/ledger.js.map +1 -0
  31. package/dist/agent/accounting/report.d.ts +70 -0
  32. package/dist/agent/accounting/report.d.ts.map +1 -0
  33. package/dist/agent/accounting/usage.d.ts +13 -0
  34. package/dist/agent/accounting/usage.d.ts.map +1 -0
  35. package/dist/agent/accounting/usage.js +2 -0
  36. package/dist/agent/accounting/usage.js.map +1 -0
  37. package/dist/agent/context/section.d.ts +15 -0
  38. package/dist/agent/context/section.d.ts.map +1 -0
  39. package/dist/agent/context/section.js +2 -0
  40. package/dist/agent/context/section.js.map +1 -0
  41. package/dist/agent/context/types.d.ts +98 -0
  42. package/dist/agent/context/types.d.ts.map +1 -0
  43. package/dist/agent/define/definition.d.ts +110 -0
  44. package/dist/agent/define/definition.d.ts.map +1 -0
  45. package/dist/agent/define/definition.js +2 -0
  46. package/dist/agent/define/definition.js.map +1 -0
  47. package/dist/agent/define/instructions.js +2 -0
  48. package/dist/agent/define/instructions.js.map +1 -0
  49. package/dist/agent/define/output-format.js +2 -0
  50. package/dist/agent/define/output-format.js.map +1 -0
  51. package/dist/agent/define/session/accounting.js +2 -0
  52. package/dist/agent/define/session/accounting.js.map +1 -0
  53. package/dist/agent/define/session/common.js +2 -0
  54. package/dist/agent/define/session/common.js.map +1 -0
  55. package/dist/agent/define/session/config.js +2 -0
  56. package/dist/agent/define/session/config.js.map +1 -0
  57. package/dist/agent/define/session/model-config.js +2 -0
  58. package/dist/agent/define/session/model-config.js.map +1 -0
  59. package/dist/agent/define/session/observer.js +2 -0
  60. package/dist/agent/define/session/observer.js.map +1 -0
  61. package/dist/agent/define/session/run-seal.js +2 -0
  62. package/dist/agent/define/session/run-seal.js.map +1 -0
  63. package/dist/agent/define/session/runtime-binding.js +2 -0
  64. package/dist/agent/define/session/runtime-binding.js.map +1 -0
  65. package/dist/agent/define/session/runtime-compaction.js +2 -0
  66. package/dist/agent/define/session/runtime-compaction.js.map +1 -0
  67. package/dist/agent/define/session/runtime-memory.js +2 -0
  68. package/dist/agent/define/session/runtime-memory.js.map +1 -0
  69. package/dist/agent/define/session/skills.js +2 -0
  70. package/dist/agent/define/session/skills.js.map +1 -0
  71. package/dist/agent/define/session/trace-accounting.js +2 -0
  72. package/dist/agent/define/session/trace-accounting.js.map +1 -0
  73. package/dist/agent/define/session/types.d.ts +217 -0
  74. package/dist/agent/define/session/types.d.ts.map +1 -0
  75. package/dist/agent/define/session/validation.js +2 -0
  76. package/dist/agent/define/session/validation.js.map +1 -0
  77. package/dist/agent/define/session.d.ts +77 -0
  78. package/dist/agent/define/session.d.ts.map +1 -0
  79. package/dist/agent/define/session.js +2 -0
  80. package/dist/agent/define/session.js.map +1 -0
  81. package/dist/agent/history/config.js +2 -0
  82. package/dist/agent/history/config.js.map +1 -0
  83. package/dist/agent/history/history.d.ts +33 -0
  84. package/dist/agent/history/history.d.ts.map +1 -0
  85. package/dist/agent/history/history.js +2 -0
  86. package/dist/agent/history/history.js.map +1 -0
  87. package/dist/agent/history/normalize.d.ts +7 -0
  88. package/dist/agent/history/normalize.d.ts.map +1 -0
  89. package/dist/agent/history/normalize.js +2 -0
  90. package/dist/agent/history/normalize.js.map +1 -0
  91. package/dist/agent/history/project.d.ts +14 -0
  92. package/dist/agent/history/project.d.ts.map +1 -0
  93. package/dist/agent/history/project.js +2 -0
  94. package/dist/agent/history/project.js.map +1 -0
  95. package/dist/agent/history/types.d.ts +85 -0
  96. package/dist/agent/history/types.d.ts.map +1 -0
  97. package/dist/agent/history/validation.js +2 -0
  98. package/dist/agent/history/validation.js.map +1 -0
  99. package/dist/agent/loop/events.d.ts +213 -0
  100. package/dist/agent/loop/events.d.ts.map +1 -0
  101. package/dist/agent/loop/queue.js +2 -0
  102. package/dist/agent/loop/queue.js.map +1 -0
  103. package/dist/agent/loop/run-turn.d.ts +8 -0
  104. package/dist/agent/loop/run-turn.d.ts.map +1 -0
  105. package/dist/agent/loop/run-turn.js +2 -0
  106. package/dist/agent/loop/run-turn.js.map +1 -0
  107. package/dist/agent/loop/schedule.d.ts +62 -0
  108. package/dist/agent/loop/schedule.d.ts.map +1 -0
  109. package/dist/agent/loop/schedule.js +3 -0
  110. package/dist/agent/loop/schedule.js.map +1 -0
  111. package/dist/agent/loop/turn/cancellation.js +2 -0
  112. package/dist/agent/loop/turn/cancellation.js.map +1 -0
  113. package/dist/agent/loop/turn/common.js +2 -0
  114. package/dist/agent/loop/turn/common.js.map +1 -0
  115. package/dist/agent/loop/turn/config.js +2 -0
  116. package/dist/agent/loop/turn/config.js.map +1 -0
  117. package/dist/agent/loop/turn/content.js +4 -0
  118. package/dist/agent/loop/turn/content.js.map +1 -0
  119. package/dist/agent/loop/turn/hooks.js +2 -0
  120. package/dist/agent/loop/turn/hooks.js.map +1 -0
  121. package/dist/agent/loop/turn/model-round.js +2 -0
  122. package/dist/agent/loop/turn/model-round.js.map +1 -0
  123. package/dist/agent/loop/turn/repetition.js +2 -0
  124. package/dist/agent/loop/turn/repetition.js.map +1 -0
  125. package/dist/agent/loop/turn/types.d.ts +82 -0
  126. package/dist/agent/loop/turn/types.d.ts.map +1 -0
  127. package/dist/agent/loop/turn/usage-stop.js +2 -0
  128. package/dist/agent/loop/turn/usage-stop.js.map +1 -0
  129. package/dist/agent/loop/turn/validation.js +2 -0
  130. package/dist/agent/loop/turn/validation.js.map +1 -0
  131. package/dist/agent/loop/types.d.ts +82 -0
  132. package/dist/agent/loop/types.d.ts.map +1 -0
  133. package/dist/agent/memory/accounting-binding.js +2 -0
  134. package/dist/agent/memory/accounting-binding.js.map +1 -0
  135. package/dist/agent/memory/compaction-config.d.ts +63 -0
  136. package/dist/agent/memory/compaction-config.d.ts.map +1 -0
  137. package/dist/agent/memory/compaction-config.js +2 -0
  138. package/dist/agent/memory/compaction-config.js.map +1 -0
  139. package/dist/agent/memory/compaction.d.ts +62 -0
  140. package/dist/agent/memory/compaction.d.ts.map +1 -0
  141. package/dist/agent/memory/compaction.js +6 -0
  142. package/dist/agent/memory/compaction.js.map +1 -0
  143. package/dist/agent/memory/memory.d.ts +61 -0
  144. package/dist/agent/memory/memory.d.ts.map +1 -0
  145. package/dist/agent/memory/memory.js +5 -0
  146. package/dist/agent/memory/memory.js.map +1 -0
  147. package/dist/agent/memory/persistence-types.d.ts +44 -0
  148. package/dist/agent/memory/persistence-types.d.ts.map +1 -0
  149. package/dist/agent/memory/surface-compaction.d.ts +6 -0
  150. package/dist/agent/memory/surface-compaction.d.ts.map +1 -0
  151. package/dist/agent/memory/surface-compaction.js +4 -0
  152. package/dist/agent/memory/surface-compaction.js.map +1 -0
  153. package/dist/agent/memory/token-estimator.d.ts +12 -0
  154. package/dist/agent/memory/token-estimator.d.ts.map +1 -0
  155. package/dist/agent/memory/token-estimator.js +2 -0
  156. package/dist/agent/memory/token-estimator.js.map +1 -0
  157. package/dist/agent/mode/run-agent.d.ts +79 -0
  158. package/dist/agent/mode/run-agent.d.ts.map +1 -0
  159. package/dist/agent/mode/run-agent.js +4 -0
  160. package/dist/agent/mode/run-agent.js.map +1 -0
  161. package/dist/agent/mode/user-input.d.ts +61 -0
  162. package/dist/agent/mode/user-input.d.ts.map +1 -0
  163. package/dist/agent/mode/user-input.js +2 -0
  164. package/dist/agent/mode/user-input.js.map +1 -0
  165. package/dist/agent/skill/catalog.d.ts +53 -0
  166. package/dist/agent/skill/catalog.d.ts.map +1 -0
  167. package/dist/agent/skill/catalog.js +2 -0
  168. package/dist/agent/skill/catalog.js.map +1 -0
  169. package/dist/agent/skill/definition.d.ts +106 -0
  170. package/dist/agent/skill/definition.d.ts.map +1 -0
  171. package/dist/agent/skill/definition.js +2 -0
  172. package/dist/agent/skill/definition.js.map +1 -0
  173. package/dist/agent/skill/provider/config.d.ts +11 -0
  174. package/dist/agent/skill/provider/config.d.ts.map +1 -0
  175. package/dist/agent/skill/provider/config.js +2 -0
  176. package/dist/agent/skill/provider/config.js.map +1 -0
  177. package/dist/agent/skill/provider/context.js +2 -0
  178. package/dist/agent/skill/provider/context.js.map +1 -0
  179. package/dist/agent/skill/provider/definition.d.ts +6 -0
  180. package/dist/agent/skill/provider/definition.d.ts.map +1 -0
  181. package/dist/agent/skill/provider/definition.js +2 -0
  182. package/dist/agent/skill/provider/definition.js.map +1 -0
  183. package/dist/agent/skill/provider/snapshot.js +2 -0
  184. package/dist/agent/skill/provider/snapshot.js.map +1 -0
  185. package/dist/agent/skill/provider/types.d.ts +49 -0
  186. package/dist/agent/skill/provider/types.d.ts.map +1 -0
  187. package/dist/agent/skill/tools.d.ts +45 -0
  188. package/dist/agent/skill/tools.d.ts.map +1 -0
  189. package/dist/agent/skill/tools.js +14 -0
  190. package/dist/agent/skill/tools.js.map +1 -0
  191. package/dist/agent/team/common.d.ts +26 -0
  192. package/dist/agent/team/common.d.ts.map +1 -0
  193. package/dist/agent/team/common.js +2 -0
  194. package/dist/agent/team/common.js.map +1 -0
  195. package/dist/agent/team/composed.d.ts +45 -0
  196. package/dist/agent/team/composed.d.ts.map +1 -0
  197. package/dist/agent/team/composed.js +2 -0
  198. package/dist/agent/team/composed.js.map +1 -0
  199. package/dist/agent/team/contracts.d.ts +54 -0
  200. package/dist/agent/team/contracts.d.ts.map +1 -0
  201. package/dist/agent/team/managed.d.ts +527 -0
  202. package/dist/agent/team/managed.d.ts.map +1 -0
  203. package/dist/agent/team/managed.js +4 -0
  204. package/dist/agent/team/managed.js.map +1 -0
  205. package/dist/agent/team/team.d.ts +142 -0
  206. package/dist/agent/team/team.d.ts.map +1 -0
  207. package/dist/agent/team/team.js +2 -0
  208. package/dist/agent/team/team.js.map +1 -0
  209. package/dist/agent/team/types.d.ts +170 -0
  210. package/dist/agent/team/types.d.ts.map +1 -0
  211. package/dist/agent/tool/approval.d.ts +106 -0
  212. package/dist/agent/tool/approval.d.ts.map +1 -0
  213. package/dist/agent/tool/approval.js +2 -0
  214. package/dist/agent/tool/approval.js.map +1 -0
  215. package/dist/agent/tool/capture.js +2 -0
  216. package/dist/agent/tool/capture.js.map +1 -0
  217. package/dist/agent/tool/config.js +2 -0
  218. package/dist/agent/tool/config.js.map +1 -0
  219. package/dist/agent/tool/definition.d.ts +227 -0
  220. package/dist/agent/tool/definition.d.ts.map +1 -0
  221. package/dist/agent/tool/definition.js +2 -0
  222. package/dist/agent/tool/definition.js.map +1 -0
  223. package/dist/agent/tool/errors.d.ts +82 -0
  224. package/dist/agent/tool/errors.d.ts.map +1 -0
  225. package/dist/agent/tool/errors.js +2 -0
  226. package/dist/agent/tool/errors.js.map +1 -0
  227. package/dist/agent/tool/execution.d.ts +60 -0
  228. package/dist/agent/tool/execution.d.ts.map +1 -0
  229. package/dist/agent/tool/execution.js +2 -0
  230. package/dist/agent/tool/execution.js.map +1 -0
  231. package/dist/agent/tool/output-budget.d.ts +159 -0
  232. package/dist/agent/tool/output-budget.d.ts.map +1 -0
  233. package/dist/agent/tool/output-budget.js +3 -0
  234. package/dist/agent/tool/output-budget.js.map +1 -0
  235. package/dist/agent/tool/pipeline.d.ts +98 -0
  236. package/dist/agent/tool/pipeline.d.ts.map +1 -0
  237. package/dist/agent/tool/pipeline.js +4 -0
  238. package/dist/agent/tool/pipeline.js.map +1 -0
  239. package/dist/agent/tool/registry.d.ts +70 -0
  240. package/dist/agent/tool/registry.d.ts.map +1 -0
  241. package/dist/agent/tool/registry.js +2 -0
  242. package/dist/agent/tool/registry.js.map +1 -0
  243. package/dist/agent/tool/schema.d.ts +12 -0
  244. package/dist/agent/tool/schema.d.ts.map +1 -0
  245. package/dist/agent/tool/schema.js +2 -0
  246. package/dist/agent/tool/schema.js.map +1 -0
  247. package/dist/agent/tool/source-types.d.ts +25 -0
  248. package/dist/agent/tool/source-types.d.ts.map +1 -0
  249. package/dist/agent/trace/trace.d.ts +63 -0
  250. package/dist/agent/trace/trace.d.ts.map +1 -0
  251. package/dist/agent/trace/trace.js +2 -0
  252. package/dist/agent/trace/trace.js.map +1 -0
  253. package/dist/agent.d.ts +52 -0
  254. package/dist/agent.js +1 -0
  255. package/dist/async/settlement.d.ts +6 -0
  256. package/dist/async/settlement.d.ts.map +1 -0
  257. package/dist/async/settlement.js +2 -0
  258. package/dist/async/settlement.js.map +1 -0
  259. package/dist/capability/common/config.js +2 -0
  260. package/dist/capability/common/config.js.map +1 -0
  261. package/dist/capability/common/data.js +2 -0
  262. package/dist/capability/common/data.js.map +1 -0
  263. package/dist/composition/agent/author.d.ts +12 -0
  264. package/dist/composition/agent/author.d.ts.map +1 -0
  265. package/dist/composition/agent/author.js +2 -0
  266. package/dist/composition/agent/author.js.map +1 -0
  267. package/dist/composition/agent/definition.js +2 -0
  268. package/dist/composition/agent/definition.js.map +1 -0
  269. package/dist/composition/agent/native-event.js +2 -0
  270. package/dist/composition/agent/native-event.js.map +1 -0
  271. package/dist/composition/agent/native-tools.js +2 -0
  272. package/dist/composition/agent/native-tools.js.map +1 -0
  273. package/dist/composition/agent/options.js +2 -0
  274. package/dist/composition/agent/options.js.map +1 -0
  275. package/dist/composition/agent/policy.js +2 -0
  276. package/dist/composition/agent/policy.js.map +1 -0
  277. package/dist/composition/agent/public-message.js +2 -0
  278. package/dist/composition/agent/public-message.js.map +1 -0
  279. package/dist/composition/agent/session.js +2 -0
  280. package/dist/composition/agent/session.js.map +1 -0
  281. package/dist/composition/agent/types.d.ts +218 -0
  282. package/dist/composition/agent/types.d.ts.map +1 -0
  283. package/dist/composition/common/counter.js +2 -0
  284. package/dist/composition/common/counter.js.map +1 -0
  285. package/dist/composition/common/errors.d.ts +15 -0
  286. package/dist/composition/common/errors.d.ts.map +1 -0
  287. package/dist/composition/common/errors.js +2 -0
  288. package/dist/composition/common/errors.js.map +1 -0
  289. package/dist/composition/common/json-data.js +2 -0
  290. package/dist/composition/common/json-data.js.map +1 -0
  291. package/dist/composition/credential/config.d.ts +5 -0
  292. package/dist/composition/credential/config.d.ts.map +1 -0
  293. package/dist/composition/credential/config.js +2 -0
  294. package/dist/composition/credential/config.js.map +1 -0
  295. package/dist/composition/credential/definition.d.ts +9 -0
  296. package/dist/composition/credential/definition.d.ts.map +1 -0
  297. package/dist/composition/credential/definition.js +2 -0
  298. package/dist/composition/credential/definition.js.map +1 -0
  299. package/dist/composition/credential/types.d.ts +38 -0
  300. package/dist/composition/credential/types.d.ts.map +1 -0
  301. package/dist/composition/delivery/ack.js +2 -0
  302. package/dist/composition/delivery/ack.js.map +1 -0
  303. package/dist/composition/delivery/attempt.js +2 -0
  304. package/dist/composition/delivery/attempt.js.map +1 -0
  305. package/dist/composition/delivery/batch.js +2 -0
  306. package/dist/composition/delivery/batch.js.map +1 -0
  307. package/dist/composition/delivery/checkpoint.js +2 -0
  308. package/dist/composition/delivery/checkpoint.js.map +1 -0
  309. package/dist/composition/delivery/event.js +2 -0
  310. package/dist/composition/delivery/event.js.map +1 -0
  311. package/dist/composition/delivery/resource.d.ts +11 -0
  312. package/dist/composition/delivery/resource.d.ts.map +1 -0
  313. package/dist/composition/delivery/resource.js +2 -0
  314. package/dist/composition/delivery/resource.js.map +1 -0
  315. package/dist/composition/delivery/staging.js +2 -0
  316. package/dist/composition/delivery/staging.js.map +1 -0
  317. package/dist/composition/diagnostics/config.js +2 -0
  318. package/dist/composition/diagnostics/config.js.map +1 -0
  319. package/dist/composition/diagnostics/ring.d.ts +12 -0
  320. package/dist/composition/diagnostics/ring.d.ts.map +1 -0
  321. package/dist/composition/diagnostics/ring.js +2 -0
  322. package/dist/composition/diagnostics/ring.js.map +1 -0
  323. package/dist/composition/exporter/definition.d.ts +7 -0
  324. package/dist/composition/exporter/definition.d.ts.map +1 -0
  325. package/dist/composition/exporter/definition.js +2 -0
  326. package/dist/composition/exporter/definition.js.map +1 -0
  327. package/dist/composition/exporter/lifecycle.js +2 -0
  328. package/dist/composition/exporter/lifecycle.js.map +1 -0
  329. package/dist/composition/exporter/preflight.js +2 -0
  330. package/dist/composition/exporter/preflight.js.map +1 -0
  331. package/dist/composition/exporter/types.d.ts +25 -0
  332. package/dist/composition/exporter/types.d.ts.map +1 -0
  333. package/dist/composition/exporter/types.js +2 -0
  334. package/dist/composition/exporter/types.js.map +1 -0
  335. package/dist/composition/identity/agent.js +2 -0
  336. package/dist/composition/identity/agent.js.map +1 -0
  337. package/dist/composition/lifecycle/bounded.js +2 -0
  338. package/dist/composition/lifecycle/bounded.js.map +1 -0
  339. package/dist/composition/lifecycle/operations.js +2 -0
  340. package/dist/composition/lifecycle/operations.js.map +1 -0
  341. package/dist/composition/lifecycle/types.d.ts +13 -0
  342. package/dist/composition/lifecycle/types.d.ts.map +1 -0
  343. package/dist/composition/lifecycle/types.js +2 -0
  344. package/dist/composition/lifecycle/types.js.map +1 -0
  345. package/dist/composition/logging/config.js +2 -0
  346. package/dist/composition/logging/config.js.map +1 -0
  347. package/dist/composition/logging/integration.js +2 -0
  348. package/dist/composition/logging/integration.js.map +1 -0
  349. package/dist/composition/logging/logger.d.ts +9 -0
  350. package/dist/composition/logging/logger.d.ts.map +1 -0
  351. package/dist/composition/logging/logger.js +2 -0
  352. package/dist/composition/logging/logger.js.map +1 -0
  353. package/dist/composition/memory/config.d.ts +10 -0
  354. package/dist/composition/memory/config.d.ts.map +1 -0
  355. package/dist/composition/memory/config.js +2 -0
  356. package/dist/composition/memory/config.js.map +1 -0
  357. package/dist/composition/memory/definition.d.ts +7 -0
  358. package/dist/composition/memory/definition.d.ts.map +1 -0
  359. package/dist/composition/memory/definition.js +2 -0
  360. package/dist/composition/memory/definition.js.map +1 -0
  361. package/dist/composition/memory/key.js +2 -0
  362. package/dist/composition/memory/key.js.map +1 -0
  363. package/dist/composition/memory/resume.js +2 -0
  364. package/dist/composition/memory/resume.js.map +1 -0
  365. package/dist/composition/memory/run.js +2 -0
  366. package/dist/composition/memory/run.js.map +1 -0
  367. package/dist/composition/model-catalog/config.js +2 -0
  368. package/dist/composition/model-catalog/config.js.map +1 -0
  369. package/dist/composition/model-catalog/manager.js +2 -0
  370. package/dist/composition/model-catalog/manager.js.map +1 -0
  371. package/dist/composition/model-catalog/options.js +2 -0
  372. package/dist/composition/model-catalog/options.js.map +1 -0
  373. package/dist/composition/model-catalog/types.d.ts +9 -0
  374. package/dist/composition/model-catalog/types.d.ts.map +1 -0
  375. package/dist/composition/observation/config.js +2 -0
  376. package/dist/composition/observation/config.js.map +1 -0
  377. package/dist/composition/observation/extensions.js +2 -0
  378. package/dist/composition/observation/extensions.js.map +1 -0
  379. package/dist/composition/observation/final-report.d.ts +6 -0
  380. package/dist/composition/observation/final-report.d.ts.map +1 -0
  381. package/dist/composition/observation/final-report.js +2 -0
  382. package/dist/composition/observation/final-report.js.map +1 -0
  383. package/dist/composition/observation/health.d.ts +13 -0
  384. package/dist/composition/observation/health.d.ts.map +1 -0
  385. package/dist/composition/observation/port.d.ts +11 -0
  386. package/dist/composition/observation/port.d.ts.map +1 -0
  387. package/dist/composition/observation/port.js +2 -0
  388. package/dist/composition/observation/port.js.map +1 -0
  389. package/dist/composition/preflight.js +2 -0
  390. package/dist/composition/preflight.js.map +1 -0
  391. package/dist/composition/provider/activation.js +2 -0
  392. package/dist/composition/provider/activation.js.map +1 -0
  393. package/dist/composition/provider/definition.d.ts +7 -0
  394. package/dist/composition/provider/definition.d.ts.map +1 -0
  395. package/dist/composition/provider/definition.js +2 -0
  396. package/dist/composition/provider/definition.js.map +1 -0
  397. package/dist/composition/provider/model-selection.js +2 -0
  398. package/dist/composition/provider/model-selection.js.map +1 -0
  399. package/dist/composition/provider/preflight.js +2 -0
  400. package/dist/composition/provider/preflight.js.map +1 -0
  401. package/dist/composition/provider/types.d.ts +38 -0
  402. package/dist/composition/provider/types.d.ts.map +1 -0
  403. package/dist/composition/provider/types.js +2 -0
  404. package/dist/composition/provider/types.js.map +1 -0
  405. package/dist/composition/queue/config.js +2 -0
  406. package/dist/composition/queue/config.js.map +1 -0
  407. package/dist/composition/queue/scheduler.js +2 -0
  408. package/dist/composition/queue/scheduler.js.map +1 -0
  409. package/dist/composition/queue/store.js +2 -0
  410. package/dist/composition/queue/store.js.map +1 -0
  411. package/dist/composition/runtime/config.js +2 -0
  412. package/dist/composition/runtime/config.js.map +1 -0
  413. package/dist/composition/runtime/owner.js +2 -0
  414. package/dist/composition/runtime/owner.js.map +1 -0
  415. package/dist/composition/runtime/public.d.ts +7 -0
  416. package/dist/composition/runtime/public.d.ts.map +1 -0
  417. package/dist/composition/runtime/public.js +2 -0
  418. package/dist/composition/runtime/public.js.map +1 -0
  419. package/dist/composition/runtime/types.d.ts +76 -0
  420. package/dist/composition/runtime/types.d.ts.map +1 -0
  421. package/dist/composition/startup.js +2 -0
  422. package/dist/composition/startup.js.map +1 -0
  423. package/dist/composition/team/config.js +2 -0
  424. package/dist/composition/team/config.js.map +1 -0
  425. package/dist/composition/team/options.js +2 -0
  426. package/dist/composition/team/options.js.map +1 -0
  427. package/dist/composition/team/runtime.js +2 -0
  428. package/dist/composition/team/runtime.js.map +1 -0
  429. package/dist/composition/team/types.d.ts +63 -0
  430. package/dist/composition/team/types.d.ts.map +1 -0
  431. package/dist/composition/tool-source/config.d.ts +5 -0
  432. package/dist/composition/tool-source/config.d.ts.map +1 -0
  433. package/dist/composition/tool-source/config.js +2 -0
  434. package/dist/composition/tool-source/config.js.map +1 -0
  435. package/dist/composition/tool-source/definition.d.ts +7 -0
  436. package/dist/composition/tool-source/definition.d.ts.map +1 -0
  437. package/dist/composition/tool-source/definition.js +2 -0
  438. package/dist/composition/tool-source/definition.js.map +1 -0
  439. package/dist/composition/tool-source/snapshot.js +2 -0
  440. package/dist/composition/tool-source/snapshot.js.map +1 -0
  441. package/dist/contract/adapter.d.ts +91 -0
  442. package/dist/contract/adapter.d.ts.map +1 -0
  443. package/dist/contract/adapter.js +2 -0
  444. package/dist/contract/adapter.js.map +1 -0
  445. package/dist/contract/call-config.d.ts +36 -0
  446. package/dist/contract/call-config.d.ts.map +1 -0
  447. package/dist/contract/call-config.js +2 -0
  448. package/dist/contract/call-config.js.map +1 -0
  449. package/dist/contract/generate-options.d.ts +41 -0
  450. package/dist/contract/generate-options.d.ts.map +1 -0
  451. package/dist/contract/model-info.d.ts +99 -0
  452. package/dist/contract/model-info.d.ts.map +1 -0
  453. package/dist/contract/output-format.d.ts +18 -0
  454. package/dist/contract/output-format.d.ts.map +1 -0
  455. package/dist/contract/retry-policy.d.ts +104 -0
  456. package/dist/contract/retry-policy.d.ts.map +1 -0
  457. package/dist/contract/retry-policy.js +2 -0
  458. package/dist/contract/retry-policy.js.map +1 -0
  459. package/dist/contract/tool.d.ts +65 -0
  460. package/dist/contract/tool.d.ts.map +1 -0
  461. package/dist/contract/tool.js +2 -0
  462. package/dist/contract/tool.js.map +1 -0
  463. package/dist/errors/agent-sdk-error.d.ts +88 -0
  464. package/dist/errors/agent-sdk-error.d.ts.map +1 -0
  465. package/dist/errors/agent-sdk-error.js +2 -0
  466. package/dist/errors/agent-sdk-error.js.map +1 -0
  467. package/dist/errors/capability-identity.d.ts +10 -0
  468. package/dist/errors/capability-identity.d.ts.map +1 -0
  469. package/dist/errors/capability-identity.js +2 -0
  470. package/dist/errors/capability-identity.js.map +1 -0
  471. package/dist/errors/failure.d.ts +33 -0
  472. package/dist/errors/failure.d.ts.map +1 -0
  473. package/dist/errors/failure.js +2 -0
  474. package/dist/errors/failure.js.map +1 -0
  475. package/dist/errors/model-error.d.ts +83 -0
  476. package/dist/errors/model-error.d.ts.map +1 -0
  477. package/dist/errors/model-error.js +2 -0
  478. package/dist/errors/model-error.js.map +1 -0
  479. package/dist/http/api-key.d.ts +47 -0
  480. package/dist/http/api-key.d.ts.map +1 -0
  481. package/dist/http/api-key.js +2 -0
  482. package/dist/http/api-key.js.map +1 -0
  483. package/dist/http/attribution.d.ts +51 -0
  484. package/dist/http/attribution.d.ts.map +1 -0
  485. package/dist/http/attribution.js +2 -0
  486. package/dist/http/attribution.js.map +1 -0
  487. package/dist/index.d.ts +70 -0
  488. package/dist/index.js +1 -0
  489. package/dist/logging/types.d.ts +53 -0
  490. package/dist/logging/types.d.ts.map +1 -0
  491. package/dist/logging/types.js +2 -0
  492. package/dist/logging/types.js.map +1 -0
  493. package/dist/memory.d.ts +10 -0
  494. package/dist/memory.js +1 -0
  495. package/dist/message/content.d.ts +125 -0
  496. package/dist/message/content.d.ts.map +1 -0
  497. package/dist/message/message.d.ts +154 -0
  498. package/dist/message/message.d.ts.map +1 -0
  499. package/dist/message/message.js +2 -0
  500. package/dist/message/message.js.map +1 -0
  501. package/dist/message/projection.d.ts +34 -0
  502. package/dist/message/projection.d.ts.map +1 -0
  503. package/dist/message/projection.js +2 -0
  504. package/dist/message/projection.js.map +1 -0
  505. package/dist/observability/bus.d.ts +7 -0
  506. package/dist/observability/bus.d.ts.map +1 -0
  507. package/dist/observability/bus.js +2 -0
  508. package/dist/observability/bus.js.map +1 -0
  509. package/dist/observability/exporters.d.ts +39 -0
  510. package/dist/observability/exporters.d.ts.map +1 -0
  511. package/dist/observability/exporters.js +2 -0
  512. package/dist/observability/exporters.js.map +1 -0
  513. package/dist/observability/logger.js +2 -0
  514. package/dist/observability/logger.js.map +1 -0
  515. package/dist/observability/projections.d.ts +12 -0
  516. package/dist/observability/projections.d.ts.map +1 -0
  517. package/dist/observability/projections.js +2 -0
  518. package/dist/observability/projections.js.map +1 -0
  519. package/dist/observability/types.d.ts +103 -0
  520. package/dist/observability/types.d.ts.map +1 -0
  521. package/dist/observability.d.ts +20 -0
  522. package/dist/observability.js +1 -0
  523. package/dist/observation/boundaries.js +2 -0
  524. package/dist/observation/boundaries.js.map +1 -0
  525. package/dist/observation/context.d.ts +39 -0
  526. package/dist/observation/context.d.ts.map +1 -0
  527. package/dist/observation/context.js +2 -0
  528. package/dist/observation/context.js.map +1 -0
  529. package/dist/observation/event.d.ts +50 -0
  530. package/dist/observation/event.d.ts.map +1 -0
  531. package/dist/observation/event.js +2 -0
  532. package/dist/observation/event.js.map +1 -0
  533. package/dist/observation/port.d.ts +56 -0
  534. package/dist/observation/port.d.ts.map +1 -0
  535. package/dist/observation/port.js +2 -0
  536. package/dist/observation/port.js.map +1 -0
  537. package/dist/observation/privacy.js +2 -0
  538. package/dist/observation/privacy.js.map +1 -0
  539. package/dist/observation/report.d.ts +117 -0
  540. package/dist/observation/report.d.ts.map +1 -0
  541. package/dist/observation/report.js +2 -0
  542. package/dist/observation/report.js.map +1 -0
  543. package/dist/observation/telemetry-types.d.ts +29 -0
  544. package/dist/observation/telemetry-types.d.ts.map +1 -0
  545. package/dist/observation/usage.d.ts +52 -0
  546. package/dist/observation/usage.d.ts.map +1 -0
  547. package/dist/observation/usage.js +2 -0
  548. package/dist/observation/usage.js.map +1 -0
  549. package/dist/platform/adapter.js +2 -0
  550. package/dist/platform/adapter.js.map +1 -0
  551. package/dist/platform/capability-operation.js +2 -0
  552. package/dist/platform/capability-operation.js.map +1 -0
  553. package/dist/platform/config.js +2 -0
  554. package/dist/platform/config.js.map +1 -0
  555. package/dist/platform/logger-platform.js +2 -0
  556. package/dist/platform/logger-platform.js.map +1 -0
  557. package/dist/platform/resources.js +2 -0
  558. package/dist/platform/resources.js.map +1 -0
  559. package/dist/plugin/provider-plugin.d.ts +37 -0
  560. package/dist/plugin/provider-plugin.d.ts.map +1 -0
  561. package/dist/plugin/provider-plugin.js +2 -0
  562. package/dist/plugin/provider-plugin.js.map +1 -0
  563. package/dist/primitives/brand.d.ts +61 -0
  564. package/dist/primitives/brand.d.ts.map +1 -0
  565. package/dist/primitives/brand.js +2 -0
  566. package/dist/primitives/brand.js.map +1 -0
  567. package/dist/primitives/freeze.d.ts +20 -0
  568. package/dist/primitives/freeze.d.ts.map +1 -0
  569. package/dist/primitives/freeze.js +2 -0
  570. package/dist/primitives/freeze.js.map +1 -0
  571. package/dist/primitives/json-snapshot.js +2 -0
  572. package/dist/primitives/json-snapshot.js.map +1 -0
  573. package/dist/primitives/json.d.ts +32 -0
  574. package/dist/primitives/json.d.ts.map +1 -0
  575. package/dist/primitives/json.js +2 -0
  576. package/dist/primitives/json.js.map +1 -0
  577. package/dist/primitives/never.d.ts +22 -0
  578. package/dist/primitives/never.d.ts.map +1 -0
  579. package/dist/primitives/never.js +2 -0
  580. package/dist/primitives/never.js.map +1 -0
  581. package/dist/primitives/snapshot.d.ts +10 -0
  582. package/dist/primitives/snapshot.d.ts.map +1 -0
  583. package/dist/primitives/snapshot.js +2 -0
  584. package/dist/primitives/snapshot.js.map +1 -0
  585. package/dist/primitives/version.d.ts +6 -0
  586. package/dist/primitives/version.d.ts.map +1 -0
  587. package/dist/primitives/version.js +2 -0
  588. package/dist/primitives/version.js.map +1 -0
  589. package/dist/provider.d.ts +19 -0
  590. package/dist/provider.js +1 -0
  591. package/dist/runtime/model-call-handle.js +2 -0
  592. package/dist/runtime/model-call-handle.js.map +1 -0
  593. package/dist/runtime/model-metadata.js +2 -0
  594. package/dist/runtime/model-metadata.js.map +1 -0
  595. package/dist/runtime/model-stream.js +2 -0
  596. package/dist/runtime/model-stream.js.map +1 -0
  597. package/dist/runtime/registry.d.ts +171 -0
  598. package/dist/runtime/registry.d.ts.map +1 -0
  599. package/dist/runtime/registry.js +2 -0
  600. package/dist/runtime/registry.js.map +1 -0
  601. package/dist/runtime/with-retry.d.ts +45 -0
  602. package/dist/runtime/with-retry.d.ts.map +1 -0
  603. package/dist/runtime/with-retry.js +2 -0
  604. package/dist/runtime/with-retry.js.map +1 -0
  605. package/dist/skills.d.ts +8 -0
  606. package/dist/skills.js +1 -0
  607. package/dist/stream/assembler.d.ts +86 -0
  608. package/dist/stream/assembler.d.ts.map +1 -0
  609. package/dist/stream/assembler.js +2 -0
  610. package/dist/stream/assembler.js.map +1 -0
  611. package/dist/stream/chunk.d.ts +135 -0
  612. package/dist/stream/chunk.d.ts.map +1 -0
  613. package/dist/stream/idle-timeout.d.ts +30 -0
  614. package/dist/stream/idle-timeout.d.ts.map +1 -0
  615. package/dist/stream/idle-timeout.js +2 -0
  616. package/dist/stream/idle-timeout.js.map +1 -0
  617. package/dist/support-safe/error.d.ts +29 -0
  618. package/dist/support-safe/error.d.ts.map +1 -0
  619. package/dist/support-safe/error.js +2 -0
  620. package/dist/support-safe/error.js.map +1 -0
  621. package/dist/tools.d.ts +15 -0
  622. package/dist/tools.js +1 -0
  623. package/package.json +96 -0
@@ -0,0 +1,170 @@
1
+ import { ContentBlock } from "../../message/content.js";
2
+ import { SdkLogger } from "../../logging/types.js";
3
+ import { AgentMessageSource } from "../../message/message.js";
4
+ import { AgentRunEvent } from "../mode/run-agent.js";
5
+ import { AgentTeamMemberOptions } from "../define/session/types.js";
6
+ //#region src/agent/team/types.d.ts
7
+ /** A quiet delivery adds context; a wakeup delivery also schedules a turn. */
8
+ type AgentMessageDelivery = 'quiet' | 'wakeup';
9
+ /**
10
+ * How a member's last run ended.
11
+ *
12
+ * Carries the member's own answer, which is what a coordinator needs once it no
13
+ * longer receives that answer as a tool return value: an agent started
14
+ * concurrently reports here instead.
15
+ */
16
+ type AgentMemberOutcome = {
17
+ readonly kind: 'completed';
18
+ readonly text: string;
19
+ } | {
20
+ readonly kind: 'failed';
21
+ readonly message: string;
22
+ };
23
+ /** Detached runtime view of one addressable member. */
24
+ interface AgentTeamMember {
25
+ readonly name: string;
26
+ readonly agentId: string;
27
+ readonly kind: 'local' | 'remote';
28
+ readonly conversationId?: string;
29
+ readonly role: 'lead' | 'peer';
30
+ /**
31
+ * `pending` is a member the host has created but deliberately not started
32
+ * yet — it is waiting on another member. Reporting it as `idle` would tell a
33
+ * coordinator its work was over before it had begun.
34
+ */
35
+ readonly status: 'pending' | 'running' | 'idle' | 'failed';
36
+ readonly protocol?: string;
37
+ readonly deliveries: readonly AgentMessageDelivery[];
38
+ readonly description?: string;
39
+ readonly error?: string;
40
+ /** Absent until the member has finished a run at least once. */
41
+ readonly outcome?: AgentMemberOutcome;
42
+ }
43
+ /** Transport-neutral result returned by an externally linked agent. */
44
+ interface LinkedAgentResult {
45
+ readonly kind: 'message' | 'task';
46
+ readonly succeeded: boolean;
47
+ readonly text: string;
48
+ readonly contextId: string;
49
+ readonly taskId?: string;
50
+ readonly state?: string;
51
+ }
52
+ interface LinkedAgentSendInput {
53
+ readonly teamId: string;
54
+ readonly messageId: string;
55
+ readonly sender: string;
56
+ readonly senderAgentId: string;
57
+ readonly content: readonly ContentBlock[];
58
+ readonly signal?: AbortSignal;
59
+ /** Runtime-bound integration logger when the link is used through AgentRuntime. */
60
+ readonly logger?: SdkLogger;
61
+ }
62
+ /** A remote protocol transport that can be linked into an AgentTeam roster. */
63
+ interface LinkedAgentTransport {
64
+ readonly protocol: string;
65
+ readonly agentId: string;
66
+ send(input: LinkedAgentSendInput): Promise<LinkedAgentResult>;
67
+ }
68
+ interface LinkAgentOptions {
69
+ readonly name: string;
70
+ readonly description?: string;
71
+ readonly transport: LinkedAgentTransport;
72
+ }
73
+ interface SendAgentMessageRequest {
74
+ /** Sender name registered in the same team. */
75
+ readonly from: string;
76
+ /** Target member name. */
77
+ readonly target: string;
78
+ readonly message: string | readonly ContentBlock[];
79
+ readonly delivery?: AgentMessageDelivery;
80
+ readonly signal?: AbortSignal;
81
+ }
82
+ /** Immutable mailbox record retained by the control plane. */
83
+ interface AgentMessageRecord {
84
+ readonly id: string;
85
+ readonly teamId: string;
86
+ readonly sender: string;
87
+ readonly senderAgentId: string;
88
+ readonly target: string;
89
+ readonly targetAgentId: string;
90
+ readonly delivery: AgentMessageDelivery;
91
+ readonly content: readonly ContentBlock[];
92
+ readonly status: 'accepted';
93
+ readonly createdAt: string;
94
+ readonly result?: LinkedAgentResult;
95
+ }
96
+ interface SendAgentMessageResult {
97
+ readonly messageId: string;
98
+ /** Local history owns the message, or the remote protocol call returned successfully. */
99
+ readonly status: 'accepted';
100
+ readonly delivery: AgentMessageDelivery;
101
+ readonly target: string;
102
+ readonly result?: LinkedAgentResult;
103
+ }
104
+ type AgentTeamEvent = {
105
+ readonly type: 'member-attached';
106
+ readonly member: AgentTeamMember;
107
+ } | {
108
+ readonly type: 'member-linked';
109
+ readonly member: AgentTeamMember;
110
+ } | {
111
+ readonly type: 'message-accepted';
112
+ readonly message: AgentMessageRecord;
113
+ } | {
114
+ readonly type: 'member-run-start';
115
+ readonly member: string;
116
+ } | {
117
+ readonly type: 'member-run-end';
118
+ readonly member: string;
119
+ } | {
120
+ readonly type: 'member-run-cancelled';
121
+ readonly member: string;
122
+ } | {
123
+ readonly type: 'member-run-error';
124
+ readonly member: string;
125
+ readonly error: string;
126
+ } | {
127
+ readonly type: 'team-disposed';
128
+ readonly teamId: string;
129
+ };
130
+ interface AgentTeamOptions {
131
+ readonly id?: string;
132
+ readonly maxMembers?: number;
133
+ /** Maximum number of accepted messages retained for audit. Defaults to 10,000. */
134
+ readonly maxMessages?: number;
135
+ readonly maxMessageBytes?: number;
136
+ /** Maximum serialized result retained from one linked transport. Defaults to 1 MiB. */
137
+ readonly maxLinkedResultBytes?: number;
138
+ /** Maximum cumulative serialized content/result bytes retained by the mailbox. Defaults to 64 MiB. */
139
+ readonly maxMailboxBytes?: number;
140
+ /** Maximum serialized bytes for descriptions and collaboration instructions. Defaults to 8 KiB. */
141
+ readonly maxMetadataBytes?: number;
142
+ /** Maximum time dispose waits for cooperative transports/providers. Defaults to 30 seconds. */
143
+ readonly disposeTimeoutMs?: number;
144
+ /** End-to-end bound for one remote dispatch or local wake-up batch. Defaults to 10 minutes. */
145
+ readonly operationTimeoutMs?: number;
146
+ /** Maximum wait per asynchronous agent-event observer. Defaults to 1 second. */
147
+ readonly observerTimeoutMs?: number;
148
+ /**
149
+ * How long `wait_agents` waits before reporting back. Defaults to 30 seconds.
150
+ *
151
+ * The tool call can ask for less. It cannot wait forever, because a
152
+ * coordinator that never regains control cannot tell a slow agent from a
153
+ * stuck one, and neither can the person watching it.
154
+ */
155
+ readonly waitTimeoutMs?: number;
156
+ /**
157
+ * Shortest wait one `wait_agents` call may ask for. Defaults to 5 seconds.
158
+ *
159
+ * A lead that asks for a second gets the roster back unchanged and has spent
160
+ * a model round learning nothing. A request below the floor is raised to it,
161
+ * not rejected, and the response reports the budget actually used.
162
+ */
163
+ readonly minWaitTimeoutMs?: number;
164
+ readonly onEvent?: (event: AgentTeamEvent) => void;
165
+ /** Observe model/tool/compaction events from local wake-up runs. */
166
+ readonly onAgentEvent?: (member: string, event: AgentRunEvent) => void | Promise<void>;
167
+ }
168
+ //#endregion
169
+ export { AgentMemberOutcome, AgentMessageDelivery, AgentMessageRecord, type AgentMessageSource, AgentTeamEvent, AgentTeamMember, type AgentTeamMemberOptions, AgentTeamOptions, LinkAgentOptions, LinkedAgentResult, LinkedAgentSendInput, LinkedAgentTransport, SendAgentMessageRequest, SendAgentMessageResult };
170
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/agent/team/types.ts"],"mappings":";;;;;;;KAWY;;;;;;;;KASA;WACG;WAA4B;;WAC5B;WAAyB;;;UAGvB;WACN;WACA;WACA;WACA;WACA;;;;;;WAMA;WACA;WACA,qBAAqB;WACrB;WACA;;WAEA,UAAU;;;UAIJ;WACN;WACA;WACA;WACA;WACA;WACA;;UAGM;WACN;WACA;WACA;WACA;WACA,kBAAkB;WAClB,SAAS;;WAET,SAAS;;;UAIH;WACN;WACA;EACT,KAAK,OAAO,uBAAuB,QAAQ;;UAG5B;WACN;WACA;WACA,WAAW;;UAGL;;WAEN;;WAEA;WACA,2BAA2B;WAC3B,WAAW;WACX,SAAS;;;UAIH;WACN;WACA;WACA;WACA;WACA;WACA;WACA,UAAU;WACV,kBAAkB;WAClB;WACA;WACA,SAAS;;UAGH;WACN;;WAEA;WACA,UAAU;WACV;WACA,SAAS;;KAGR;WACG;WAAkC,QAAQ;;WAC1C;WAAgC,QAAQ;;WACxC;WAAmC,SAAS;;WAC5C;WAAmC;;WACnC;WAAiC;;WACjC;WAAuC;;WACvC;WAAmC;WAAyB;;WAC5D;WAAgC;;UAE9B;WACN;WACA;;WAEA;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;;;;;;WAQA;;;;;;;;WAQA;WACA,WAAW,OAAO;;WAElB,gBAAgB,gBAAgB,OAAO,yBAAyB"}
@@ -0,0 +1,106 @@
1
+ import { ToolCallId } from "../../primitives/brand.js";
2
+ //#region src/agent/tool/approval.d.ts
3
+ declare function createApprovalRequest(input: Omit<ApprovalRequest, 'approvalRequestId' | 'providerCallId'>): ApprovalRequest;
4
+ /** What the approver decided. */
5
+ type ApprovalDecision =
6
+ /** Run it. */
7
+ 'allow' |
8
+ /** Refuse this call; the model is told and may try something else. */
9
+ 'deny' |
10
+ /** Withdraw the turn entirely. */
11
+ 'abort';
12
+ /** One request for permission. */
13
+ interface ApprovalRequest {
14
+ /** SDK-generated, single-use identity. Never resolve using the provider call id. */
15
+ readonly approvalRequestId: string;
16
+ readonly providerCallId: ToolCallId;
17
+ readonly runId?: string;
18
+ readonly conversationId?: string;
19
+ /** Provider-issued id of the call awaiting a decision. */
20
+ readonly callId: ToolCallId;
21
+ readonly toolName: string;
22
+ /** Parsed arguments, so an approver can show what is about to happen. */
23
+ readonly args: unknown;
24
+ /** Why permission is being asked, when an interceptor said. */
25
+ readonly reason?: string;
26
+ readonly turn: number;
27
+ readonly step: number;
28
+ }
29
+ /** Decides whether a call may proceed. */
30
+ interface ApprovalBroker {
31
+ /**
32
+ * Ask for permission.
33
+ * @param request - what is about to run.
34
+ * @param signal - cancellation; an abort must settle the promise, not leak it.
35
+ * @returns the decision.
36
+ */
37
+ readonly request: (request: ApprovalRequest, signal?: AbortSignal) => Promise<ApprovalDecision>;
38
+ }
39
+ /**
40
+ * A broker that answers every request the same way, without asking anyone.
41
+ *
42
+ * For headless runs and tests. `deny` is a useful default for a sandbox that wants
43
+ * approval-requiring tools reported to the model as unavailable rather than
44
+ * silently executed.
45
+ * @param decision - the fixed answer.
46
+ * @returns the broker.
47
+ */
48
+ declare function fixedApprovalBroker(decision: ApprovalDecision): ApprovalBroker;
49
+ /**
50
+ * A broker that publishes requests and waits to be answered by approval request id.
51
+ *
52
+ * This is the interactive one. Wire {@link InteractiveApprovalBroker.onRequest} to
53
+ * a UI, and call {@link InteractiveApprovalBroker.resolve} when the human answers.
54
+ */
55
+ interface InteractiveApprovalBroker extends ApprovalBroker {
56
+ /** Requests still awaiting an answer, in the order they were asked. */
57
+ pending(): readonly ApprovalRequest[];
58
+ /**
59
+ * Observe requests.
60
+ *
61
+ * Listeners are invoked AFTER the waiter is registered, so resolving
62
+ * synchronously from inside a listener is safe.
63
+ * @param listener - receives each request.
64
+ * @returns a disposer.
65
+ */
66
+ onRequest(listener: (request: ApprovalRequest) => void): () => void;
67
+ /**
68
+ * Answer a pending request.
69
+ * @param approvalRequestId - the SDK-issued request identity to answer.
70
+ * @param decision - the answer.
71
+ * @returns true when a pending request was answered; false when the id is
72
+ * unknown, which happens legitimately if the turn was already cancelled.
73
+ */
74
+ resolve(approvalRequestId: string, decision: ApprovalDecision): boolean;
75
+ /** Abort only pending requests belonging to this run. */
76
+ abortRun(runId: string): void;
77
+ /** Abort only pending requests belonging to this conversation. */
78
+ abortSession(conversationId: string): void;
79
+ /**
80
+ * Answer every outstanding request with `abort`.
81
+ *
82
+ * Call this when a turn is torn down: a parked promise with no answer coming
83
+ * would keep the run alive forever.
84
+ */
85
+ abortAll(): void;
86
+ }
87
+ interface InteractiveApprovalBrokerOptions {
88
+ /** Maximum requests parked across concurrent sessions. Defaults to 1,024. */
89
+ readonly maxPending?: number;
90
+ }
91
+ /**
92
+ * Create an interactive approval broker.
93
+ * @returns the broker.
94
+ */
95
+ declare function createApprovalBroker(options?: InteractiveApprovalBrokerOptions): InteractiveApprovalBroker;
96
+ /** Optional durable approval journal, separate from conversation snapshots.
97
+ * The host owns loading pending records and reissuing a fresh approval on recovery;
98
+ * saved decisions are never automatically applied to a new request. */
99
+ interface ApprovalStateStore {
100
+ savePending(request: ApprovalRequest, signal?: AbortSignal): Promise<void>;
101
+ saveDecision(request: ApprovalRequest, decision: ApprovalDecision, signal?: AbortSignal): Promise<void>;
102
+ }
103
+ declare function withApprovalPersistence(broker: ApprovalBroker, store: ApprovalStateStore): ApprovalBroker;
104
+ //#endregion
105
+ export { ApprovalBroker, ApprovalDecision, ApprovalRequest, ApprovalStateStore, InteractiveApprovalBroker, InteractiveApprovalBrokerOptions, createApprovalBroker, createApprovalRequest, fixedApprovalBroker, withApprovalPersistence };
106
+ //# sourceMappingURL=approval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.d.ts","names":[],"sources":["../../../src/agent/tool/approval.ts"],"mappings":";;iBA4BgB,sBAAsB,OAAO,KAAK,2DAA2D;;KAOjG;;;;;;;;UASK;;WAEN;WACA,gBAAgB;WAChB;WACA;;WAEA,QAAQ;WACR;;WAEA;;WAEA;WACA;WACA;;;UAIM;;;;;;;WAON,UAAU,SAAS,iBAAiB,SAAS,gBAAgB,QAAQ;;;;;;;;;;;iBAYhE,oBAAoB,UAAU,mBAAmB;;;;;;;UAUhD,kCAAkC;;EAEjD,oBAAoB;;;;;;;;;EASpB,UAAU,WAAW,SAAS;;;;;;;;EAQ9B,QAAQ,2BAA2B,UAAU;;EAE7C,SAAS;;EAET,aAAa;;;;;;;EAOb;;UAGe;;WAEN;;;;;;iBAYK,qBAAqB,UAAS,mCAAwC;;;;UAmFrE;EACf,YAAY,SAAS,iBAAiB,SAAS,cAAc;EAC7D,aAAa,SAAS,iBAAiB,UAAU,kBAAkB,SAAS,cAAc;;iBAG5E,wBAAwB,QAAQ,gBAAgB,OAAO,qBAAqB"}
@@ -0,0 +1,2 @@
1
+ import{detachedFrozen as e}from"../../primitives/snapshot.js";import{systemRandomId as t}from"../../platform/adapter.js";const n=new WeakSet;function r(r){let i=e({...r,approvalRequestId:t(),providerCallId:r.callId});return n.add(i),i}function i(e){return{request:()=>Promise.resolve(e)}}function a(t={}){let r=o(t.maxPending??1024,`approval maxPending`),i=new Map,a=new Set;return{request(t,o){if(!n.delete(t))return Promise.reject(Error(`approval request must be fresh and SDK-issued`));if(o?.aborted===!0)return Promise.resolve(`abort`);if(i.has(t.approvalRequestId))return Promise.reject(Error(`approval request '${t.approvalRequestId}' is already pending`));if(i.size>=r)return Promise.reject(Error(`approval broker reached its ${r}-request limit`));let s=e(t);return new Promise(e=>{let n=!1,r=r=>{n||(n=!0,i.delete(t.approvalRequestId),o?.removeEventListener(`abort`,c),e(r))};function c(){r(`abort`)}i.set(t.approvalRequestId,{request:s,settle:r}),o?.addEventListener(`abort`,c,{once:!0});for(let e of[...a])try{e(s)}catch{}})},pending(){return[...i.values()].map(e=>e.request)},onRequest(e){return a.add(e),()=>void a.delete(e)},resolve(e,t){if(t!==`allow`&&t!==`deny`&&t!==`abort`)return!1;let n=i.get(e);return n!==void 0&&(n.settle(t),!0)},abortRun(e){for(let t of[...i.values()])t.request.runId===e&&t.settle(`abort`)},abortSession(e){for(let t of[...i.values()])t.request.conversationId===e&&t.settle(`abort`)},abortAll(){for(let e of[...i.values()])e.settle(`abort`)}}}function o(e,t){if(!Number.isSafeInteger(e)||e<1)throw RangeError(`${t} must be a positive safe integer`);return e}function s(e,t){let n=e.request.bind(e),r=t.savePending.bind(t),i=t.saveDecision.bind(t);return Object.freeze({async request(e,t){let a=new AbortController,o=t===void 0?a.signal:AbortSignal.any([t,a.signal]),s=n(e,o);s.catch(()=>void 0);try{await r(e,o);let t=await s;return await i(e,t,o),t}catch(e){throw a.abort(e),e}}})}export{a as createApprovalBroker,r as createApprovalRequest,i as fixedApprovalBroker,s as withApprovalPersistence};
2
+ //# sourceMappingURL=approval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"approval.js","names":[],"sources":["../../../src/agent/tool/approval.ts"],"sourcesContent":["/**\n * Asking permission before a tool runs.\n *\n * The shape is the one both reference implementations arrived at: the loop does\n * not pause, the *tool call* pauses. A pending promise is parked in a map keyed by\n * approval request id, a request is published, and whoever is watching resolves it later by\n * that id. Everything else in the turn — other tool calls in the same batch,\n * streaming, cancellation — keeps working.\n *\n * Two details are load-bearing and easy to get wrong:\n *\n * 1. **The waiter is registered BEFORE the request is published.** A listener that\n * resolves synchronously (a policy engine, a test) would otherwise answer a\n * question nobody is holding, and the call would hang forever.\n * 2. **`deny` and `abort` are different outcomes.** Denial is a normal answer that\n * the model should see and can work around. Abort is the user withdrawing the\n * whole turn. Collapsing them either strands a cancelled run waiting for the\n * model to react, or teaches the model that \"no\" means \"stop everything\".\n *\n * @module ai-agent-sdk/agent/tool/approval\n */\n\nimport { systemRandomId } from '../../platform/adapter.ts'\nimport type { ToolCallId } from '../../primitives/index.ts'\nimport { detachedFrozen } from '../../primitives/index.ts'\n\nconst issuedRequests = new WeakSet<object>()\n\nexport function createApprovalRequest(input: Omit<ApprovalRequest, 'approvalRequestId' | 'providerCallId'>): ApprovalRequest {\n const request = detachedFrozen({ ...input, approvalRequestId: systemRandomId(), providerCallId: input.callId })\n issuedRequests.add(request)\n return request\n}\n\n/** What the approver decided. */\nexport type ApprovalDecision =\n /** Run it. */\n | 'allow'\n /** Refuse this call; the model is told and may try something else. */\n | 'deny'\n /** Withdraw the turn entirely. */\n | 'abort'\n\n/** One request for permission. */\nexport interface ApprovalRequest {\n /** SDK-generated, single-use identity. Never resolve using the provider call id. */\n readonly approvalRequestId: string\n readonly providerCallId: ToolCallId\n readonly runId?: string\n readonly conversationId?: string\n /** Provider-issued id of the call awaiting a decision. */\n readonly callId: ToolCallId\n readonly toolName: string\n /** Parsed arguments, so an approver can show what is about to happen. */\n readonly args: unknown\n /** Why permission is being asked, when an interceptor said. */\n readonly reason?: string\n readonly turn: number\n readonly step: number\n}\n\n/** Decides whether a call may proceed. */\nexport interface ApprovalBroker {\n /**\n * Ask for permission.\n * @param request - what is about to run.\n * @param signal - cancellation; an abort must settle the promise, not leak it.\n * @returns the decision.\n */\n readonly request: (request: ApprovalRequest, signal?: AbortSignal) => Promise<ApprovalDecision>\n}\n\n/**\n * A broker that answers every request the same way, without asking anyone.\n *\n * For headless runs and tests. `deny` is a useful default for a sandbox that wants\n * approval-requiring tools reported to the model as unavailable rather than\n * silently executed.\n * @param decision - the fixed answer.\n * @returns the broker.\n */\nexport function fixedApprovalBroker(decision: ApprovalDecision): ApprovalBroker {\n return { request: () => Promise.resolve(decision) }\n}\n\n/**\n * A broker that publishes requests and waits to be answered by approval request id.\n *\n * This is the interactive one. Wire {@link InteractiveApprovalBroker.onRequest} to\n * a UI, and call {@link InteractiveApprovalBroker.resolve} when the human answers.\n */\nexport interface InteractiveApprovalBroker extends ApprovalBroker {\n /** Requests still awaiting an answer, in the order they were asked. */\n pending(): readonly ApprovalRequest[]\n /**\n * Observe requests.\n *\n * Listeners are invoked AFTER the waiter is registered, so resolving\n * synchronously from inside a listener is safe.\n * @param listener - receives each request.\n * @returns a disposer.\n */\n onRequest(listener: (request: ApprovalRequest) => void): () => void\n /**\n * Answer a pending request.\n * @param approvalRequestId - the SDK-issued request identity to answer.\n * @param decision - the answer.\n * @returns true when a pending request was answered; false when the id is\n * unknown, which happens legitimately if the turn was already cancelled.\n */\n resolve(approvalRequestId: string, decision: ApprovalDecision): boolean\n /** Abort only pending requests belonging to this run. */\n abortRun(runId: string): void\n /** Abort only pending requests belonging to this conversation. */\n abortSession(conversationId: string): void\n /**\n * Answer every outstanding request with `abort`.\n *\n * Call this when a turn is torn down: a parked promise with no answer coming\n * would keep the run alive forever.\n */\n abortAll(): void\n}\n\nexport interface InteractiveApprovalBrokerOptions {\n /** Maximum requests parked across concurrent sessions. Defaults to 1,024. */\n readonly maxPending?: number\n}\n\ninterface Waiter {\n readonly request: ApprovalRequest\n readonly settle: (decision: ApprovalDecision) => void\n}\n\n/**\n * Create an interactive approval broker.\n * @returns the broker.\n */\nexport function createApprovalBroker(options: InteractiveApprovalBrokerOptions = {}): InteractiveApprovalBroker {\n const maxPending = positiveSafeInteger(options.maxPending ?? 1_024, 'approval maxPending')\n const waiters = new Map<string, Waiter>()\n const listeners = new Set<(request: ApprovalRequest) => void>()\n\n return {\n request(request, signal) {\n if (!issuedRequests.delete(request)) return Promise.reject(new Error('approval request must be fresh and SDK-issued'))\n if (signal?.aborted === true) return Promise.resolve('abort')\n if (waiters.has(request.approvalRequestId)) {\n return Promise.reject(new Error(`approval request '${request.approvalRequestId}' is already pending`))\n }\n if (waiters.size >= maxPending) {\n return Promise.reject(new Error(`approval broker reached its ${maxPending}-request limit`))\n }\n const published = detachedFrozen(request)\n\n return new Promise<ApprovalDecision>((resolve) => {\n let settled = false\n const settle = (decision: ApprovalDecision): void => {\n if (settled) return\n settled = true\n waiters.delete(request.approvalRequestId)\n signal?.removeEventListener('abort', onAbort)\n resolve(decision)\n }\n function onAbort(): void {\n settle('abort')\n }\n\n // Registered first, deliberately: a listener below may answer\n // synchronously, and there has to be somewhere for that answer to land.\n waiters.set(request.approvalRequestId, { request: published, settle })\n signal?.addEventListener('abort', onAbort, { once: true })\n\n for (const listener of [...listeners]) {\n try {\n listener(published)\n } catch {\n // A broken observer must not strand the call. If nobody else answers,\n // cancellation or `abortAll` still settles it.\n }\n }\n })\n },\n\n pending() {\n return [...waiters.values()].map(waiter => waiter.request)\n },\n\n onRequest(listener) {\n listeners.add(listener)\n return () => void listeners.delete(listener)\n },\n\n resolve(callId, decision) {\n if (decision !== 'allow' && decision !== 'deny' && decision !== 'abort') return false\n const waiter = waiters.get(callId)\n if (waiter === undefined) return false\n waiter.settle(decision)\n return true\n },\n\n abortRun(runId) {\n for (const waiter of [...waiters.values()]) if (waiter.request.runId === runId) waiter.settle('abort')\n },\n abortSession(conversationId) {\n for (const waiter of [...waiters.values()]) if (waiter.request.conversationId === conversationId) waiter.settle('abort')\n },\n abortAll() {\n for (const waiter of [...waiters.values()]) waiter.settle('abort')\n },\n }\n}\n\nfunction positiveSafeInteger(value: number, label: string): number {\n if (!Number.isSafeInteger(value) || value < 1) throw new RangeError(`${label} must be a positive safe integer`)\n return value\n}\n\n/** Optional durable approval journal, separate from conversation snapshots.\n * The host owns loading pending records and reissuing a fresh approval on recovery;\n * saved decisions are never automatically applied to a new request. */\nexport interface ApprovalStateStore {\n savePending(request: ApprovalRequest, signal?: AbortSignal): Promise<void>\n saveDecision(request: ApprovalRequest, decision: ApprovalDecision, signal?: AbortSignal): Promise<void>\n}\n\nexport function withApprovalPersistence(broker: ApprovalBroker, store: ApprovalStateStore): ApprovalBroker {\n const request = broker.request.bind(broker)\n const pendingRecord = store.savePending.bind(store), decisionRecord = store.saveDecision.bind(store)\n return Object.freeze({\n async request(value: ApprovalRequest, signal?: AbortSignal): Promise<ApprovalDecision> {\n const owned = new AbortController()\n const combined = signal === undefined ? owned.signal : AbortSignal.any([signal, owned.signal])\n // Install the interactive waiter before any asynchronous storage operation.\n const pending = request(value, combined)\n void pending.catch(() => undefined)\n try {\n await pendingRecord(value, combined)\n const decision = await pending\n await decisionRecord(value, decision, combined)\n return decision\n } catch (error) {\n owned.abort(error)\n throw error\n }\n },\n })\n}\n"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ import{AgentSdkError as e}from"../../errors/agent-sdk-error.js";import{snapshotJsonObject as t}from"../../primitives/json-snapshot.js";import{TOOL_DEFINITION_LIMITS as n,TOOL_REGISTRY_ERROR_CODES as r}from"./config.js";function i(i){try{(typeof i!=`object`&&typeof i!=`function`||i===null)&&u();let e=i,r=c(e,`name`,n.nameBytes),a=c(e,`description`,n.descriptionBytes),d=t(o(e,`parameters`),{maxObjectFields:n.schemaFields,maxArrayItems:n.schemaArrayItems,maxDepth:n.schemaDepth,maxNodes:n.schemaNodes,maxKeyBytes:n.schemaKeyBytes,maxBytes:n.schemaBytes}),f=l(e,`execute`,!0),p=l(e,`parse`,!1),m=l(e,`render`,!1),h=l(e,`meta`,!1),g=l(e,`isConcurrencySafe`,!1),_=s(e,`timeoutMs`);_!==void 0&&(typeof _!=`number`||!Number.isFinite(_)||_<=0)&&u();let v=s(e,`budgetExempt`);v!==void 0&&v!==!0&&u();let y=s(e,`completionExempt`);y!==void 0&&y!==!0&&u();let b=s(e,`maxOutputTokens`);return b!==void 0&&(!Number.isSafeInteger(b)||Number(b)<1)&&u(),Object.freeze({name:r,description:a,parameters:d,...p===void 0?{}:{parse:p},execute:f,...m===void 0?{}:{render:m},...h===void 0?{}:{meta:h},..._===void 0?{}:{timeoutMs:Number(_)},...g===void 0?{}:{isConcurrencySafe:g},...v===void 0?{}:{budgetExempt:!0},...y===void 0?{}:{completionExempt:!0},...b===void 0?{}:{maxOutputTokens:Number(b)}})}catch(t){throw t instanceof e&&t.code===r.INVALID_TOOL?t:new e(`tool definition is invalid`,r.INVALID_TOOL,{cause:t})}}function a(t){try{Array.isArray(t)||u();let e=o(t,`length`);(!Number.isSafeInteger(e)||Number(e)<0||Number(e)>n.tools)&&u();let r=[];for(let n=0;n<Number(e);n++)r.push(i(o(t,String(n))));return Object.freeze(r)}catch(t){throw t instanceof e&&t.code===r.INVALID_TOOL?t:new e(`tool definition list is invalid`,r.INVALID_TOOL,{cause:t})}}function o(e,t){let n=Object.getOwnPropertyDescriptor(e,t);return(n===void 0||!(`value`in n))&&u(),n.value}function s(e,t){let n=Object.getOwnPropertyDescriptor(e,t);if(n!==void 0)return`value`in n||u(),n.value}function c(e,t,n){let r=o(e,t);return(typeof r!=`string`||r.length===0||r.trim()!==r||new TextEncoder().encode(r).byteLength>n)&&u(),r}function l(e,t,n){let r=Reflect.get(e,t);if(!(r===void 0&&!n))return typeof r!=`function`&&u(),(...t)=>Reflect.apply(r,e,t)}function u(){throw new e(`tool definition is invalid`,r.INVALID_TOOL)}export{i as captureToolDefinition,a as captureToolDefinitions};
2
+ //# sourceMappingURL=capture.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capture.js","names":[],"sources":["../../../src/agent/tool/capture.ts"],"sourcesContent":["import { AgentSdkError } from '../../errors/agent-sdk-error.ts'\nimport { snapshotJsonObject } from '../../primitives/json-snapshot.ts'\nimport type { JsonObject, JsonValue } from '../../primitives/json.ts'\nimport type { ContentBlock } from '../../message/content.ts'\nimport type { ToolRunContext, ToolDefinition } from './definition.ts'\nimport { TOOL_DEFINITION_LIMITS, TOOL_REGISTRY_ERROR_CODES } from './config.ts'\n\ntype ToolMethod<Args extends readonly unknown[], Result> = (...args: Args) => Result\n\n/** Capture one stable tool generation while preserving the caller object's receiver. */\nexport function captureToolDefinition<Args>(input: ToolDefinition<Args>): ToolDefinition<Args> {\n try {\n if ((typeof input !== 'object' && typeof input !== 'function') || input === null) invalid()\n const receiver = input as object\n const name = boundedOwnText(receiver, 'name', TOOL_DEFINITION_LIMITS.nameBytes)\n const description = boundedOwnText(receiver, 'description', TOOL_DEFINITION_LIMITS.descriptionBytes)\n const parameters = snapshotJsonObject(ownData(receiver, 'parameters'), {\n maxObjectFields: TOOL_DEFINITION_LIMITS.schemaFields,\n maxArrayItems: TOOL_DEFINITION_LIMITS.schemaArrayItems,\n maxDepth: TOOL_DEFINITION_LIMITS.schemaDepth,\n maxNodes: TOOL_DEFINITION_LIMITS.schemaNodes,\n maxKeyBytes: TOOL_DEFINITION_LIMITS.schemaKeyBytes,\n maxBytes: TOOL_DEFINITION_LIMITS.schemaBytes,\n })\n const execute = method<[Args, ToolRunContext], Promise<JsonValue | void> | JsonValue | void>(receiver, 'execute', true)!\n const parse = method<[unknown], Args>(receiver, 'parse', false)\n const render = method<[JsonValue | undefined, Args], readonly ContentBlock[]>(receiver, 'render', false)\n const meta = method<[JsonValue | undefined, Args], JsonObject | undefined>(receiver, 'meta', false)\n const isConcurrencySafe = method<[Args], boolean>(receiver, 'isConcurrencySafe', false)\n const timeoutMs = optionalOwnData(receiver, 'timeoutMs')\n if (timeoutMs !== undefined && (typeof timeoutMs !== 'number' || !Number.isFinite(timeoutMs) || timeoutMs <= 0)) invalid()\n // Fail-closed like every other flag here: only an exact `true` exempts a\n // tool from the turn budget, so a truthy accident cannot quietly widen it.\n const budgetExempt = optionalOwnData(receiver, 'budgetExempt')\n if (budgetExempt !== undefined && budgetExempt !== true) invalid()\n const completionExempt = optionalOwnData(receiver, 'completionExempt')\n if (completionExempt !== undefined && completionExempt !== true) invalid()\n const maxOutputTokens = optionalOwnData(receiver, 'maxOutputTokens')\n if (maxOutputTokens !== undefined\n && (!Number.isSafeInteger(maxOutputTokens) || Number(maxOutputTokens) < 1)) invalid()\n return Object.freeze({ name, description, parameters,\n ...(parse === undefined ? {} : { parse }), execute,\n ...(render === undefined ? {} : { render }),\n ...(meta === undefined ? {} : { meta }),\n ...(timeoutMs === undefined ? {} : { timeoutMs: Number(timeoutMs) }),\n ...(isConcurrencySafe === undefined ? {} : { isConcurrencySafe }),\n ...(budgetExempt === undefined ? {} : { budgetExempt: true as const }),\n ...(completionExempt === undefined ? {} : { completionExempt: true as const }),\n ...(maxOutputTokens === undefined ? {} : { maxOutputTokens: Number(maxOutputTokens) }),\n })\n } catch (error) {\n if (error instanceof AgentSdkError && error.code === TOOL_REGISTRY_ERROR_CODES.INVALID_TOOL) throw error\n throw new AgentSdkError('tool definition is invalid', TOOL_REGISTRY_ERROR_CODES.INVALID_TOOL, { cause: error })\n }\n}\n\n/** Capture a dense bounded tool list atomically. */\nexport function captureToolDefinitions(value: unknown): readonly ToolDefinition[] {\n try {\n if (!Array.isArray(value)) invalid()\n const length = ownData(value, 'length')\n if (!Number.isSafeInteger(length) || Number(length) < 0 || Number(length) > TOOL_DEFINITION_LIMITS.tools) invalid()\n const captured: ToolDefinition[] = []\n for (let index = 0; index < Number(length); index++) {\n captured.push(captureToolDefinition(ownData(value, String(index)) as ToolDefinition))\n }\n return Object.freeze(captured)\n } catch (error) {\n if (error instanceof AgentSdkError && error.code === TOOL_REGISTRY_ERROR_CODES.INVALID_TOOL) throw error\n throw new AgentSdkError('tool definition list is invalid', TOOL_REGISTRY_ERROR_CODES.INVALID_TOOL, { cause: error })\n }\n}\n\nfunction ownData(source: object, key: string): unknown {\n const descriptor = Object.getOwnPropertyDescriptor(source, key)\n if (descriptor === undefined || !('value' in descriptor)) invalid()\n return descriptor.value\n}\n\nfunction optionalOwnData(source: object, key: string): unknown {\n const descriptor = Object.getOwnPropertyDescriptor(source, key)\n if (descriptor === undefined) return undefined\n if (!('value' in descriptor)) invalid()\n return descriptor.value\n}\n\nfunction boundedOwnText(source: object, key: string, maxBytes: number): string {\n const value = ownData(source, key)\n if (typeof value !== 'string' || value.length === 0 || value.trim() !== value\n || new TextEncoder().encode(value).byteLength > maxBytes) invalid()\n return value\n}\n\nfunction method<Args extends readonly unknown[], Result>(\n receiver: object,\n key: string,\n required: boolean,\n): ToolMethod<Args, Result> | undefined {\n const value: unknown = Reflect.get(receiver, key)\n if (value === undefined && !required) return undefined\n if (typeof value !== 'function') invalid()\n return (...args: Args): Result => Reflect.apply(value, receiver, args) as Result\n}\n\nfunction invalid(): never {\n throw new AgentSdkError('tool definition is invalid', TOOL_REGISTRY_ERROR_CODES.INVALID_TOOL)\n}\n"],"mappings":"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"}
@@ -0,0 +1,2 @@
1
+ const e=Object.freeze({tools:1024,nameBytes:256,descriptionBytes:16384,schemaBytes:262144,schemaDepth:32,schemaNodes:16384,schemaFields:512,schemaArrayItems:1024,schemaKeyBytes:256}),t=Object.freeze({DUPLICATE_TOOL:`DUPLICATE_TOOL`,INVALID_TOOL:`INVALID_TOOL`,UNKNOWN_TOOL_FILTER:`UNKNOWN_TOOL_FILTER`});export{e as TOOL_DEFINITION_LIMITS,t as TOOL_REGISTRY_ERROR_CODES};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","names":[],"sources":["../../../src/agent/tool/config.ts"],"sourcesContent":["export const TOOL_DEFINITION_LIMITS = Object.freeze({\n tools: 1_024,\n nameBytes: 256,\n descriptionBytes: 16 * 1024,\n schemaBytes: 256 * 1024,\n schemaDepth: 32,\n schemaNodes: 16_384,\n schemaFields: 512,\n schemaArrayItems: 1_024,\n schemaKeyBytes: 256,\n})\n\nexport const TOOL_REGISTRY_ERROR_CODES = Object.freeze({\n DUPLICATE_TOOL: 'DUPLICATE_TOOL',\n INVALID_TOOL: 'INVALID_TOOL',\n UNKNOWN_TOOL_FILTER: 'UNKNOWN_TOOL_FILTER',\n} as const)\n"],"mappings":"AAAA,MAAa,EAAyB,OAAO,OAAO,CAClD,MAAO,KACP,UAAW,IACX,iBAAkB,MAClB,YAAa,OACb,YAAa,GACb,YAAa,MACb,aAAc,IACd,iBAAkB,KAClB,eAAgB,GAClB,CAAC,EAEY,EAA4B,OAAO,OAAO,CACrD,eAAgB,iBAChB,aAAc,eACd,oBAAqB,qBACvB,CAAU"}
@@ -0,0 +1,227 @@
1
+ import { ToolCallId } from "../../primitives/brand.js";
2
+ import { JsonObject, JsonValue } from "../../primitives/json.js";
3
+ import { ContentBlock } from "../../message/content.js";
4
+ import { SdkLogger } from "../../logging/types.js";
5
+ import { ToolSchema } from "../../contract/tool.js";
6
+ //#region src/agent/tool/definition.d.ts
7
+ type ReadonlyToolBehavior<Args extends readonly unknown[], Result> = {
8
+ bivarianceHack(...args: Args): Result;
9
+ }['bivarianceHack'];
10
+ /** Where a tool call sits in the run, for logging and diagnostics. */
11
+ interface ToolCallPosition {
12
+ readonly runId?: string;
13
+ readonly conversationId?: string;
14
+ /** 1-based turn number within the conversation. */
15
+ readonly turn: number;
16
+ /** 1-based step number within the turn. */
17
+ readonly step: number;
18
+ }
19
+ /** What a tool body receives besides its arguments. */
20
+ interface ToolRunContext extends ToolCallPosition {
21
+ /** Provider-issued id of this call. */
22
+ readonly callId: ToolCallId;
23
+ /** The tool's own name, so shared helpers can report which tool called them. */
24
+ readonly toolName: string;
25
+ /**
26
+ * Cancellation for this call.
27
+ *
28
+ * A tool that declares `timeoutMs` is ASSERTING that it forwards this signal;
29
+ * the timeout is cooperative and cannot interrupt code that ignores it.
30
+ */
31
+ readonly signal: AbortSignal;
32
+ /** Always present on AgentRuntime execution paths; optional for legacy callers. */
33
+ readonly logger?: SdkLogger;
34
+ /**
35
+ * End the turn after this batch of tool calls commits.
36
+ *
37
+ * For a tool that IS the answer — submitting a final result, handing off to a
38
+ * human. The loop still commits every call in the current batch first, so a
39
+ * parallel sibling's work is never discarded.
40
+ */
41
+ concludeTurn(): void;
42
+ /**
43
+ * Inject extra context for the next step, beyond this call's result.
44
+ *
45
+ * The blocks become a user message the model sees on the following request. Use
46
+ * it for information the model needs but did not ask for — a reminder that it
47
+ * has repeated itself, a warning that a file changed underneath it.
48
+ */
49
+ addContext(content: string | readonly ContentBlock[]): void;
50
+ }
51
+ /**
52
+ * How a tool call may be scheduled relative to its siblings.
53
+ *
54
+ * Both reference implementations default to `exclusive` and require an explicit
55
+ * opt-in, because the failure mode of guessing wrong is silent data corruption
56
+ * from two tools mutating the same state, not a visible error.
57
+ */
58
+ type ToolExecutionMode = 'parallel' | 'exclusive';
59
+ /** A tool the model can call. */
60
+ interface ToolDefinition<Args = unknown> extends ToolSchema {
61
+ /**
62
+ * Validate and narrow raw arguments before {@link execute} sees them.
63
+ *
64
+ * The hook exists so this package needs no schema library of its own: plug in
65
+ * zod, valibot, ajv, or hand-written checks. Throwing here produces an
66
+ * `INVALID_ARGUMENTS` result the model can correct.
67
+ *
68
+ * Omitting it means `execute` receives the parsed JSON UNVALIDATED, typed as
69
+ * `Args` on trust. That is fine for a tool whose body checks its own inputs.
70
+ */
71
+ readonly parse?: ReadonlyToolBehavior<[raw: unknown], Args>;
72
+ /**
73
+ * Do the work.
74
+ * @param args - validated arguments.
75
+ * @param ctx - call identity, cancellation, and the side channels.
76
+ * @returns a lossless-JSON value, or nothing.
77
+ */
78
+ readonly execute: ReadonlyToolBehavior<[args: Args, ctx: ToolRunContext], Promise<JsonValue | void> | JsonValue | void>;
79
+ /**
80
+ * Turn the returned value into what the model reads.
81
+ *
82
+ * Defaults to {@link renderJsonValue}: a string is passed through verbatim,
83
+ * anything else is pretty-printed JSON. Override to give the model prose, or to
84
+ * return an image block.
85
+ */
86
+ readonly render?: ReadonlyToolBehavior<[value: JsonValue | undefined, args: Args], readonly ContentBlock[]>;
87
+ /**
88
+ * Metadata for a UI, kept out of what the model sees.
89
+ *
90
+ * Must be lossless JSON — it is persisted with the result.
91
+ */
92
+ readonly meta?: ReadonlyToolBehavior<[value: JsonValue | undefined, args: Args], JsonObject | undefined>;
93
+ /**
94
+ * Wall-clock bound for one call, enforced cooperatively.
95
+ *
96
+ * NEVER sent to the model. Declaring it is a promise that {@link execute}
97
+ * forwards `ctx.signal`, because the pipeline aborts the signal and waits — it
98
+ * does not abandon the promise, since an orphaned tool would keep mutating state
99
+ * behind the loop's back.
100
+ */
101
+ readonly timeoutMs?: number;
102
+ /**
103
+ * Whether this call may run alongside its siblings.
104
+ *
105
+ * Fail-closed: only an exact `true` opts in. A throwing or absent classifier
106
+ * means `exclusive`. Return `true` only when the call cannot observe or mutate
107
+ * state another concurrent call touches — a pure read of an immutable source
108
+ * qualifies, "probably fine" does not.
109
+ */
110
+ readonly isConcurrencySafe?: ReadonlyToolBehavior<[args: Args], boolean>;
111
+ /**
112
+ * Exempt this tool from the turn's tool-call budget and its loop guards.
113
+ *
114
+ * For the calls that END work rather than do it: submitting a final result,
115
+ * asking the user a blocking question, handing a task to another agent. A
116
+ * budget exists to stop exploration, and a spent budget that also blocks the
117
+ * only remaining useful action leaves the model with no legal move — the run
118
+ * then dies mid-plan instead of finishing. Both reference harnesses avoid
119
+ * that by never failing a call for a limit at all; this flag is the narrow
120
+ * version of the same rule.
121
+ *
122
+ * Exempt calls still count toward the RUN-level ledger limits, so this
123
+ * cannot be used to escape accounting — only to reach a terminal action.
124
+ */
125
+ readonly budgetExempt?: true;
126
+ /**
127
+ * Progress/reporting only: calling this tool does not invalidate an accepted
128
+ * deep-mode completion submission. Examples include updating a visible todo
129
+ * list after the work has been verified. Never set this for tools that edit
130
+ * work, obtain new evidence, delegate, or change the user's requirements.
131
+ * This is independent of budgetExempt and is never sent to the model.
132
+ */
133
+ readonly completionExempt?: true;
134
+ /**
135
+ * Estimated tokens of text this tool's result may put in front of the model.
136
+ *
137
+ * For a tool that knows its own shape: a file reader can ask for room a
138
+ * one-line status check has no use for. The turn's budget still applies, and
139
+ * the STRICTER of the two wins — Codex resolves a model-requested
140
+ * `max_output_tokens` against its deployment policy the same way — so this
141
+ * can lower a tool's share but never raise it past what the host allows.
142
+ *
143
+ * Never sent to the model.
144
+ */
145
+ readonly maxOutputTokens?: number;
146
+ }
147
+ /** A tool call that succeeded. */
148
+ interface ToolSuccess {
149
+ readonly isError: false;
150
+ /** The raw value the body returned; omitted when post-policy replaces the result. */
151
+ readonly value: JsonValue | undefined;
152
+ /** What the model reads. */
153
+ readonly content: readonly ContentBlock[];
154
+ /** UI metadata, never shown to the model. */
155
+ readonly meta?: JsonObject;
156
+ /** Extra context requested via `ctx.addContext`. */
157
+ readonly additionalContext?: readonly ContentBlock[];
158
+ /** Set when the tool called `ctx.concludeTurn()`. */
159
+ readonly concludesTurn?: true;
160
+ }
161
+ /** A tool call that failed. */
162
+ interface ToolFailure {
163
+ readonly isError: true;
164
+ readonly error: {
165
+ readonly message: string;
166
+ readonly code: string;
167
+ };
168
+ /** What the model reads — the failure, phrased for the model. */
169
+ readonly content: readonly ContentBlock[];
170
+ readonly meta?: JsonObject;
171
+ readonly additionalContext?: readonly ContentBlock[];
172
+ /**
173
+ * Typed `never`: a failure must not be able to end the turn.
174
+ *
175
+ * Otherwise a denied or crashed tool could silently stop work the user asked
176
+ * for, which is the opposite of what a failure should do.
177
+ */
178
+ readonly concludesTurn?: never;
179
+ }
180
+ /** The outcome of one tool call. */
181
+ type ToolExecutionResult = ToolSuccess | ToolFailure;
182
+ /**
183
+ * The default {@link ToolDefinition.render}.
184
+ *
185
+ * A string is passed through as-is, because a tool that returns prose meant it.
186
+ * Everything else is indented JSON, which models parse reliably and humans can
187
+ * read in a transcript.
188
+ * @param value - the value the body returned.
189
+ * @returns model-facing blocks.
190
+ */
191
+ declare function renderJsonValue(value: JsonValue | undefined): readonly ContentBlock[];
192
+ /**
193
+ * Author a tool with argument types inferred from `parse`.
194
+ *
195
+ * Returns a detached frozen execution view. Schema and method references are
196
+ * captured once while method calls retain the caller object's receiver.
197
+ *
198
+ * ```ts
199
+ * const getWeather = defineTool({
200
+ * name: 'get_weather',
201
+ * description: 'Current weather for a city.',
202
+ * parameters: {
203
+ * type: 'object',
204
+ * properties: { city: { type: 'string' } },
205
+ * required: ['city'],
206
+ * },
207
+ * parse: raw => WeatherArgs.parse(raw),
208
+ * execute: async ({ city }) => ({ tempC: await lookup(city) }),
209
+ * })
210
+ * ```
211
+ * @param definition - the tool.
212
+ * @returns a new immutable definition, typed.
213
+ */
214
+ declare function defineTool<Args>(definition: ToolDefinition<Args>): ToolDefinition<Args>;
215
+ /**
216
+ * Decide how one call may be scheduled.
217
+ *
218
+ * Fail-closed on every uncertainty, including a classifier that throws: a tool
219
+ * whose safety check is broken is not a tool whose safety can be assumed.
220
+ * @param tool - the definition, or `undefined` for an unknown tool.
221
+ * @param args - the parsed arguments.
222
+ * @returns the scheduling mode.
223
+ */
224
+ declare function executionModeOf(tool: ToolDefinition | undefined, args: unknown): ToolExecutionMode;
225
+ //#endregion
226
+ export { ToolCallPosition, ToolDefinition, ToolExecutionMode, ToolExecutionResult, ToolFailure, ToolRunContext, ToolSuccess, defineTool, executionModeOf, renderJsonValue };
227
+ //# sourceMappingURL=definition.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition.d.ts","names":[],"sources":["../../../src/agent/tool/definition.ts"],"mappings":";;;;;;KA2BK,qBAAqB,iCAAiC;EACzD,kBAAkB,MAAM,OAAO;;;UAIhB;WACN;WACA;;WAEA;;WAEA;;;UAIM,uBAAuB;;WAE7B,QAAQ;;WAER;;;;;;;WAOA,QAAQ;;WAER,SAAS;;;;;;;;EASlB;;;;;;;;EASA,WAAW,2BAA2B;;;;;;;;;KAU5B;;UAGK,eAAe,wBAAwB;;;;;;;;;;;WAW7C,QAAQ,sBAAsB,eAAe;;;;;;;WAQ7C,SAAS,sBACf,MAAM,MAAM,KAAK,iBAClB,QAAQ,oBAAoB;;;;;;;;WAUrB,SAAS,sBACf,OAAO,uBAAuB,MAAM,gBAC5B;;;;;;WAQF,OAAO,sBACb,OAAO,uBAAuB,MAAM,OACrC;;;;;;;;;WAWO;;;;;;;;;WAUA,oBAAoB,sBAAsB,MAAM;;;;;;;;;;;;;;;WAgBhD;;;;;;;;WASA;;;;;;;;;;;;WAaA;;;UAIM;WACN;;WAEA,OAAO;;WAEP,kBAAkB;;WAElB,OAAO;;WAEP,6BAA6B;;WAE7B;;;UAIM;WACN;WACA;aACE;aACA;;;WAGF,kBAAkB;WAClB,OAAO;WACP,6BAA6B;;;;;;;WAO7B;;;KAIC,sBAAsB,cAAc;;;;;;;;;;iBAWhC,gBAAgB,OAAO,iCAAiC;;;;;;;;;;;;;;;;;;;;;;;iBA8BxD,WAAW,MAAM,YAAY,eAAe,QAAQ,eAAe;;;;;;;;;;iBAanE,gBACd,MAAM,4BACN,gBACC"}
@@ -0,0 +1,2 @@
1
+ import{captureToolDefinition as e}from"./capture.js";function t(e){return e===void 0?[{type:`text`,text:`(no output)`}]:typeof e==`string`?[{type:`text`,text:e.length===0?`(empty)`:e}]:[{type:`text`,text:JSON.stringify(e,null,2)}]}function n(t){return e(t)}function r(e,t){if(e?.isConcurrencySafe===void 0)return`exclusive`;try{return e.isConcurrencySafe(t)===!0?`parallel`:`exclusive`}catch{return`exclusive`}}export{n as defineTool,r as executionModeOf,t as renderJsonValue};
2
+ //# sourceMappingURL=definition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"definition.js","names":[],"sources":["../../../src/agent/tool/definition.ts"],"sourcesContent":["/**\n * What a tool is, what it receives, and what it produces.\n *\n * Two shape decisions worth stating up front.\n *\n * **The body returns a value, not model-facing text.** `execute` produces a\n * lossless-JSON value; `render` turns it into the blocks the model reads. Keeping\n * them apart means the value can be logged, replayed, asserted on in tests, and\n * handed to a UI, while the model-facing wording stays free to change without\n * invalidating any of that. Simple tools ignore `render` entirely and get a\n * sensible default.\n *\n * **Side channels live on the context, not in the return type.** A tool that wants\n * to end the turn or inject extra context calls `ctx.concludeTurn()` /\n * `ctx.addContext()`. That keeps the common return type trivial — a string or an\n * object — instead of forcing every tool to wrap its result in an envelope.\n *\n * @module ai-agent-sdk/agent/tool/definition\n */\n\nimport type { ToolSchema } from '../../contract/index.ts'\nimport type { ContentBlock } from '../../message/index.ts'\nimport type { ToolCallId } from '../../primitives/index.ts'\nimport type { JsonObject, JsonValue } from '../../primitives/index.ts'\nimport type { SdkLogger } from '../../logging/types.ts'\nimport { captureToolDefinition } from './capture.ts'\n\ntype ReadonlyToolBehavior<Args extends readonly unknown[], Result> = {\n bivarianceHack(...args: Args): Result\n}['bivarianceHack']\n\n/** Where a tool call sits in the run, for logging and diagnostics. */\nexport interface ToolCallPosition {\n readonly runId?: string\n readonly conversationId?: string\n /** 1-based turn number within the conversation. */\n readonly turn: number\n /** 1-based step number within the turn. */\n readonly step: number\n}\n\n/** What a tool body receives besides its arguments. */\nexport interface ToolRunContext extends ToolCallPosition {\n /** Provider-issued id of this call. */\n readonly callId: ToolCallId\n /** The tool's own name, so shared helpers can report which tool called them. */\n readonly toolName: string\n /**\n * Cancellation for this call.\n *\n * A tool that declares `timeoutMs` is ASSERTING that it forwards this signal;\n * the timeout is cooperative and cannot interrupt code that ignores it.\n */\n readonly signal: AbortSignal\n /** Always present on AgentRuntime execution paths; optional for legacy callers. */\n readonly logger?: SdkLogger\n\n /**\n * End the turn after this batch of tool calls commits.\n *\n * For a tool that IS the answer — submitting a final result, handing off to a\n * human. The loop still commits every call in the current batch first, so a\n * parallel sibling's work is never discarded.\n */\n concludeTurn(): void\n\n /**\n * Inject extra context for the next step, beyond this call's result.\n *\n * The blocks become a user message the model sees on the following request. Use\n * it for information the model needs but did not ask for — a reminder that it\n * has repeated itself, a warning that a file changed underneath it.\n */\n addContext(content: string | readonly ContentBlock[]): void\n}\n\n/**\n * How a tool call may be scheduled relative to its siblings.\n *\n * Both reference implementations default to `exclusive` and require an explicit\n * opt-in, because the failure mode of guessing wrong is silent data corruption\n * from two tools mutating the same state, not a visible error.\n */\nexport type ToolExecutionMode = 'parallel' | 'exclusive'\n\n/** A tool the model can call. */\nexport interface ToolDefinition<Args = unknown> extends ToolSchema {\n /**\n * Validate and narrow raw arguments before {@link execute} sees them.\n *\n * The hook exists so this package needs no schema library of its own: plug in\n * zod, valibot, ajv, or hand-written checks. Throwing here produces an\n * `INVALID_ARGUMENTS` result the model can correct.\n *\n * Omitting it means `execute` receives the parsed JSON UNVALIDATED, typed as\n * `Args` on trust. That is fine for a tool whose body checks its own inputs.\n */\n readonly parse?: ReadonlyToolBehavior<[raw: unknown], Args>\n\n /**\n * Do the work.\n * @param args - validated arguments.\n * @param ctx - call identity, cancellation, and the side channels.\n * @returns a lossless-JSON value, or nothing.\n */\n readonly execute: ReadonlyToolBehavior<\n [args: Args, ctx: ToolRunContext],\n Promise<JsonValue | void> | JsonValue | void\n >\n\n /**\n * Turn the returned value into what the model reads.\n *\n * Defaults to {@link renderJsonValue}: a string is passed through verbatim,\n * anything else is pretty-printed JSON. Override to give the model prose, or to\n * return an image block.\n */\n readonly render?: ReadonlyToolBehavior<\n [value: JsonValue | undefined, args: Args],\n readonly ContentBlock[]\n >\n\n /**\n * Metadata for a UI, kept out of what the model sees.\n *\n * Must be lossless JSON — it is persisted with the result.\n */\n readonly meta?: ReadonlyToolBehavior<\n [value: JsonValue | undefined, args: Args],\n JsonObject | undefined\n >\n\n /**\n * Wall-clock bound for one call, enforced cooperatively.\n *\n * NEVER sent to the model. Declaring it is a promise that {@link execute}\n * forwards `ctx.signal`, because the pipeline aborts the signal and waits — it\n * does not abandon the promise, since an orphaned tool would keep mutating state\n * behind the loop's back.\n */\n readonly timeoutMs?: number\n\n /**\n * Whether this call may run alongside its siblings.\n *\n * Fail-closed: only an exact `true` opts in. A throwing or absent classifier\n * means `exclusive`. Return `true` only when the call cannot observe or mutate\n * state another concurrent call touches — a pure read of an immutable source\n * qualifies, \"probably fine\" does not.\n */\n readonly isConcurrencySafe?: ReadonlyToolBehavior<[args: Args], boolean>\n\n /**\n * Exempt this tool from the turn's tool-call budget and its loop guards.\n *\n * For the calls that END work rather than do it: submitting a final result,\n * asking the user a blocking question, handing a task to another agent. A\n * budget exists to stop exploration, and a spent budget that also blocks the\n * only remaining useful action leaves the model with no legal move — the run\n * then dies mid-plan instead of finishing. Both reference harnesses avoid\n * that by never failing a call for a limit at all; this flag is the narrow\n * version of the same rule.\n *\n * Exempt calls still count toward the RUN-level ledger limits, so this\n * cannot be used to escape accounting — only to reach a terminal action.\n */\n readonly budgetExempt?: true\n\n /**\n * Progress/reporting only: calling this tool does not invalidate an accepted\n * deep-mode completion submission. Examples include updating a visible todo\n * list after the work has been verified. Never set this for tools that edit\n * work, obtain new evidence, delegate, or change the user's requirements.\n * This is independent of budgetExempt and is never sent to the model.\n */\n readonly completionExempt?: true\n\n /**\n * Estimated tokens of text this tool's result may put in front of the model.\n *\n * For a tool that knows its own shape: a file reader can ask for room a\n * one-line status check has no use for. The turn's budget still applies, and\n * the STRICTER of the two wins — Codex resolves a model-requested\n * `max_output_tokens` against its deployment policy the same way — so this\n * can lower a tool's share but never raise it past what the host allows.\n *\n * Never sent to the model.\n */\n readonly maxOutputTokens?: number\n}\n\n/** A tool call that succeeded. */\nexport interface ToolSuccess {\n readonly isError: false\n /** The raw value the body returned; omitted when post-policy replaces the result. */\n readonly value: JsonValue | undefined\n /** What the model reads. */\n readonly content: readonly ContentBlock[]\n /** UI metadata, never shown to the model. */\n readonly meta?: JsonObject\n /** Extra context requested via `ctx.addContext`. */\n readonly additionalContext?: readonly ContentBlock[]\n /** Set when the tool called `ctx.concludeTurn()`. */\n readonly concludesTurn?: true\n}\n\n/** A tool call that failed. */\nexport interface ToolFailure {\n readonly isError: true\n readonly error: {\n readonly message: string\n readonly code: string\n }\n /** What the model reads — the failure, phrased for the model. */\n readonly content: readonly ContentBlock[]\n readonly meta?: JsonObject\n readonly additionalContext?: readonly ContentBlock[]\n /**\n * Typed `never`: a failure must not be able to end the turn.\n *\n * Otherwise a denied or crashed tool could silently stop work the user asked\n * for, which is the opposite of what a failure should do.\n */\n readonly concludesTurn?: never\n}\n\n/** The outcome of one tool call. */\nexport type ToolExecutionResult = ToolSuccess | ToolFailure\n\n/**\n * The default {@link ToolDefinition.render}.\n *\n * A string is passed through as-is, because a tool that returns prose meant it.\n * Everything else is indented JSON, which models parse reliably and humans can\n * read in a transcript.\n * @param value - the value the body returned.\n * @returns model-facing blocks.\n */\nexport function renderJsonValue(value: JsonValue | undefined): readonly ContentBlock[] {\n if (value === undefined) return [{ type: 'text', text: '(no output)' }]\n if (typeof value === 'string') {\n return [{ type: 'text', text: value.length === 0 ? '(empty)' : value }]\n }\n return [{ type: 'text', text: JSON.stringify(value, null, 2) }]\n}\n\n/**\n * Author a tool with argument types inferred from `parse`.\n *\n * Returns a detached frozen execution view. Schema and method references are\n * captured once while method calls retain the caller object's receiver.\n *\n * ```ts\n * const getWeather = defineTool({\n * name: 'get_weather',\n * description: 'Current weather for a city.',\n * parameters: {\n * type: 'object',\n * properties: { city: { type: 'string' } },\n * required: ['city'],\n * },\n * parse: raw => WeatherArgs.parse(raw),\n * execute: async ({ city }) => ({ tempC: await lookup(city) }),\n * })\n * ```\n * @param definition - the tool.\n * @returns a new immutable definition, typed.\n */\nexport function defineTool<Args>(definition: ToolDefinition<Args>): ToolDefinition<Args> {\n return captureToolDefinition(definition)\n}\n\n/**\n * Decide how one call may be scheduled.\n *\n * Fail-closed on every uncertainty, including a classifier that throws: a tool\n * whose safety check is broken is not a tool whose safety can be assumed.\n * @param tool - the definition, or `undefined` for an unknown tool.\n * @param args - the parsed arguments.\n * @returns the scheduling mode.\n */\nexport function executionModeOf(\n tool: ToolDefinition | undefined,\n args: unknown,\n): ToolExecutionMode {\n if (tool?.isConcurrencySafe === undefined) return 'exclusive'\n try {\n return tool.isConcurrencySafe(args) === true ? 'parallel' : 'exclusive'\n } catch {\n return 'exclusive'\n }\n}\n"],"mappings":"qDA8OA,SAAgB,EAAgB,EAAuD,CAKrF,OAJI,IAAU,IAAA,GAAkB,CAAC,CAAE,KAAM,OAAQ,KAAM,aAAc,CAAC,EAClE,OAAO,GAAU,SACZ,CAAC,CAAE,KAAM,OAAQ,KAAM,EAAM,SAAW,EAAI,UAAY,CAAM,CAAC,EAEjE,CAAC,CAAE,KAAM,OAAQ,KAAM,KAAK,UAAU,EAAO,KAAM,CAAC,CAAE,CAAC,CAChE,CAwBA,SAAgB,EAAiB,EAAwD,CACvF,OAAO,EAAsB,CAAU,CACzC,CAWA,SAAgB,EACd,EACA,EACmB,CACnB,GAAI,GAAM,oBAAsB,IAAA,GAAW,MAAO,YAClD,GAAI,CACF,OAAO,EAAK,kBAAkB,CAAI,IAAM,GAAO,WAAa,WAC9D,MAAQ,CACN,MAAO,WACT,CACF"}