@sixb/core 0.1.24 → 0.1.26

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 (448) hide show
  1. package/dist/actions/index.js +35 -35
  2. package/dist/agents/attachment-keys.d.ts +25 -0
  3. package/dist/agents/attachment-keys.d.ts.map +1 -0
  4. package/dist/agents/cancel.d.ts +12 -0
  5. package/dist/agents/cancel.d.ts.map +1 -1
  6. package/dist/agents/children.d.ts.map +1 -1
  7. package/dist/agents/dispatch.d.ts +1 -9
  8. package/dist/agents/dispatch.d.ts.map +1 -1
  9. package/dist/agents/execution.d.ts +5 -0
  10. package/dist/agents/execution.d.ts.map +1 -1
  11. package/dist/agents/index.d.ts +31 -6
  12. package/dist/agents/index.d.ts.map +1 -1
  13. package/dist/agents/index.js +154 -66
  14. package/dist/agents/index.js.map +1 -1
  15. package/dist/agents/model-loop.d.ts +3 -5
  16. package/dist/agents/model-loop.d.ts.map +1 -1
  17. package/dist/agents/model-routing.d.ts +4 -1
  18. package/dist/agents/model-routing.d.ts.map +1 -1
  19. package/dist/agents/request.d.ts +9 -1
  20. package/dist/agents/request.d.ts.map +1 -1
  21. package/dist/agents/run-after-finish.d.ts +11 -0
  22. package/dist/agents/run-after-finish.d.ts.map +1 -0
  23. package/dist/agents/run-artifacts.d.ts +56 -0
  24. package/dist/agents/run-artifacts.d.ts.map +1 -0
  25. package/dist/agents/run-events.d.ts +49 -0
  26. package/dist/agents/run-events.d.ts.map +1 -0
  27. package/dist/agents/run-fence.d.ts +38 -0
  28. package/dist/agents/run-fence.d.ts.map +1 -0
  29. package/dist/agents/run-liveness.d.ts +36 -0
  30. package/dist/agents/run-liveness.d.ts.map +1 -0
  31. package/dist/agents/run-plan.d.ts +110 -0
  32. package/dist/agents/run-plan.d.ts.map +1 -0
  33. package/dist/agents/run-session-children.d.ts +89 -0
  34. package/dist/agents/run-session-children.d.ts.map +1 -0
  35. package/dist/agents/run-session-http.d.ts +37 -0
  36. package/dist/agents/run-session-http.d.ts.map +1 -0
  37. package/dist/agents/run-session-serve.d.ts +24 -0
  38. package/dist/agents/run-session-serve.d.ts.map +1 -0
  39. package/dist/agents/run-session-wire.d.ts +31 -0
  40. package/dist/agents/run-session-wire.d.ts.map +1 -0
  41. package/dist/agents/run-session.d.ts +239 -0
  42. package/dist/agents/run-session.d.ts.map +1 -0
  43. package/dist/agents/run-token.d.ts +40 -0
  44. package/dist/agents/run-token.d.ts.map +1 -0
  45. package/dist/agents/run-tools.d.ts +68 -0
  46. package/dist/agents/run-tools.d.ts.map +1 -0
  47. package/dist/agents/run-turn.d.ts +59 -0
  48. package/dist/agents/run-turn.d.ts.map +1 -0
  49. package/dist/agents/streams/index.js +1 -1
  50. package/dist/agents/streams/internal.d.ts +1 -1
  51. package/dist/agents/streams/internal.d.ts.map +1 -1
  52. package/dist/agents/streams/internal.js +2 -4
  53. package/dist/agents/streams/internal.js.map +1 -1
  54. package/dist/agents/streams/protocol.d.ts +1 -96
  55. package/dist/agents/streams/protocol.d.ts.map +1 -1
  56. package/dist/agents/subagent-runs.d.ts +7 -1
  57. package/dist/agents/subagent-runs.d.ts.map +1 -1
  58. package/dist/agents/tool-files.d.ts +34 -0
  59. package/dist/agents/tool-files.d.ts.map +1 -0
  60. package/dist/agents/workflow-node-session.d.ts +99 -0
  61. package/dist/agents/workflow-node-session.d.ts.map +1 -0
  62. package/dist/artifacts/frames/index.js +6 -3
  63. package/dist/artifacts/frames/index.js.map +3 -3
  64. package/dist/artifacts/frames/probe.d.ts.map +1 -1
  65. package/dist/artifacts/index.js.map +1 -1
  66. package/dist/artifacts/publish/index.d.ts +1 -1
  67. package/dist/artifacts/publish/index.d.ts.map +1 -1
  68. package/dist/artifacts/publish/index.js +19 -19
  69. package/dist/auth/index.js +8 -8
  70. package/dist/authorization/index.js +4 -4
  71. package/dist/bootstrap/index.js +45 -43
  72. package/dist/bootstrap/index.js.map +2 -2
  73. package/dist/{chunk-2fn60nvs.js → chunk-06sg8s4z.js} +2 -2
  74. package/dist/{chunk-2fn60nvs.js.map → chunk-06sg8s4z.js.map} +1 -1
  75. package/dist/chunk-07kkp2e1.js.map +1 -1
  76. package/dist/{chunk-9ntbsnke.js → chunk-0bc3w0zq.js} +7 -7
  77. package/dist/{chunk-9ntbsnke.js.map → chunk-0bc3w0zq.js.map} +2 -2
  78. package/dist/{chunk-d2m879s4.js → chunk-0kk2wt0h.js} +27 -27
  79. package/dist/chunk-0kk2wt0h.js.map +12 -0
  80. package/dist/chunk-16a9dmfy.js.map +1 -1
  81. package/dist/chunk-18sk89cg.js.map +2 -2
  82. package/dist/{chunk-3qms4nax.js → chunk-1vg43g9q.js} +20 -20
  83. package/dist/{chunk-3qms4nax.js.map → chunk-1vg43g9q.js.map} +4 -4
  84. package/dist/{chunk-hqsp2sx4.js → chunk-1xvqgg88.js} +31 -33
  85. package/dist/{chunk-hqsp2sx4.js.map → chunk-1xvqgg88.js.map} +6 -6
  86. package/dist/chunk-2adz0h75.js.map +1 -1
  87. package/dist/{chunk-fm62y49k.js → chunk-2pk5hjj9.js} +5 -3
  88. package/dist/{chunk-fm62y49k.js.map → chunk-2pk5hjj9.js.map} +5 -5
  89. package/dist/{chunk-vrf90dkv.js → chunk-2vjnyz1s.js} +1 -1
  90. package/dist/{chunk-vrf90dkv.js.map → chunk-2vjnyz1s.js.map} +1 -1
  91. package/dist/{chunk-4f3ydv7t.js → chunk-315qye3g.js} +1 -1
  92. package/dist/{chunk-4f3ydv7t.js.map → chunk-315qye3g.js.map} +1 -1
  93. package/dist/{chunk-rap5w0x0.js → chunk-31khg3g0.js} +1 -1
  94. package/dist/{chunk-rap5w0x0.js.map → chunk-31khg3g0.js.map} +1 -1
  95. package/dist/chunk-45ngkxkp.js.map +1 -1
  96. package/dist/chunk-48jezz3j.js.map +1 -1
  97. package/dist/{chunk-vr3j63jq.js → chunk-4jq2bg8t.js} +78 -78
  98. package/dist/{chunk-vr3j63jq.js.map → chunk-4jq2bg8t.js.map} +4 -4
  99. package/dist/chunk-4ymrcdbm.js.map +1 -1
  100. package/dist/chunk-58geavnf.js.map +1 -1
  101. package/dist/{chunk-6y0mkhex.js → chunk-59kf345w.js} +2 -2
  102. package/dist/{chunk-6y0mkhex.js.map → chunk-59kf345w.js.map} +1 -1
  103. package/dist/{chunk-3p93tb91.js → chunk-6qn7nmd3.js} +102 -102
  104. package/dist/{chunk-3p93tb91.js.map → chunk-6qn7nmd3.js.map} +4 -4
  105. package/dist/chunk-73j0v4qv.js +355 -0
  106. package/dist/chunk-73j0v4qv.js.map +13 -0
  107. package/dist/{chunk-2gjj5dx3.js → chunk-78ymxrn0.js} +1 -1
  108. package/dist/{chunk-6bkbyer5.js → chunk-7ex2p3zp.js} +3 -3
  109. package/dist/{chunk-6bkbyer5.js.map → chunk-7ex2p3zp.js.map} +1 -1
  110. package/dist/{chunk-5tfev0fv.js → chunk-7hf6tkgs.js} +167 -167
  111. package/dist/{chunk-5tfev0fv.js.map → chunk-7hf6tkgs.js.map} +4 -4
  112. package/dist/{chunk-8z4726jz.js → chunk-7wn5z7mq.js} +10 -10
  113. package/dist/{chunk-8z4726jz.js.map → chunk-7wn5z7mq.js.map} +2 -2
  114. package/dist/{chunk-6n69k945.js → chunk-8mb7mt8n.js} +2 -2
  115. package/dist/chunk-8ncg20rd.js.map +1 -1
  116. package/dist/{chunk-68wghpdf.js → chunk-8v5a54qz.js} +50 -11
  117. package/dist/{chunk-68wghpdf.js.map → chunk-8v5a54qz.js.map} +3 -3
  118. package/dist/{chunk-gqm0b7vd.js → chunk-8v6xzwgr.js} +92 -76
  119. package/dist/{chunk-gqm0b7vd.js.map → chunk-8v6xzwgr.js.map} +6 -6
  120. package/dist/{chunk-m36fw8ft.js → chunk-8wsjr52f.js} +1 -1
  121. package/dist/{chunk-vd1rk42q.js → chunk-8xnz9vvp.js} +4 -4
  122. package/dist/{chunk-vd1rk42q.js.map → chunk-8xnz9vvp.js.map} +1 -1
  123. package/dist/chunk-9mab3dvg.js.map +1 -1
  124. package/dist/chunk-9tc8dxmn.js.map +1 -1
  125. package/dist/chunk-9x8dybsb.js.map +2 -2
  126. package/dist/chunk-a3faa34j.js.map +1 -1
  127. package/dist/{chunk-62a63pr6.js → chunk-axb4ss9a.js} +7 -7
  128. package/dist/{chunk-62a63pr6.js.map → chunk-axb4ss9a.js.map} +2 -2
  129. package/dist/{chunk-z3ryd53f.js → chunk-b6ghvap7.js} +35 -11
  130. package/dist/{chunk-z3ryd53f.js.map → chunk-b6ghvap7.js.map} +3 -3
  131. package/dist/{chunk-sqfvnvqj.js → chunk-c14ap3s9.js} +2 -2
  132. package/dist/{chunk-sqfvnvqj.js.map → chunk-c14ap3s9.js.map} +1 -1
  133. package/dist/{chunk-661ezhks.js → chunk-cbcgs9f7.js} +87 -8
  134. package/dist/chunk-cbcgs9f7.js.map +11 -0
  135. package/dist/chunk-cwdzcv37.js.map +1 -1
  136. package/dist/{chunk-bab05bhg.js → chunk-dgtd0836.js} +1 -1
  137. package/dist/{chunk-1j6j0rht.js → chunk-e24fvw8g.js} +1 -1
  138. package/dist/{chunk-1j6j0rht.js.map → chunk-e24fvw8g.js.map} +1 -1
  139. package/dist/chunk-e5wf5vz0.js.map +1 -1
  140. package/dist/chunk-eptrvnby.js.map +1 -1
  141. package/dist/chunk-ey1nk510.js.map +1 -1
  142. package/dist/{chunk-j936th07.js → chunk-fakrpfy3.js} +58 -58
  143. package/dist/{chunk-j936th07.js.map → chunk-fakrpfy3.js.map} +5 -5
  144. package/dist/chunk-fb3feg1e.js.map +1 -1
  145. package/dist/chunk-ff5xkv0p.js.map +1 -1
  146. package/dist/chunk-fntqb7qy.js.map +1 -1
  147. package/dist/{chunk-7ny9mjgm.js → chunk-ft3w5ahs.js} +1 -1
  148. package/dist/chunk-g663fahq.js.map +1 -1
  149. package/dist/{chunk-cdk3egjj.js → chunk-h1na2cxc.js} +1 -1
  150. package/dist/{chunk-cdk3egjj.js.map → chunk-h1na2cxc.js.map} +1 -1
  151. package/dist/chunk-hn2r7z41.js.map +1 -1
  152. package/dist/{chunk-24bqx0dx.js → chunk-hn76sanm.js} +1 -1
  153. package/dist/{chunk-24bqx0dx.js.map → chunk-hn76sanm.js.map} +1 -1
  154. package/dist/chunk-jmfet9r4.js.map +1 -1
  155. package/dist/{chunk-bnr4a734.js → chunk-jn3ysaf2.js} +24 -22
  156. package/dist/{chunk-bnr4a734.js.map → chunk-jn3ysaf2.js.map} +5 -5
  157. package/dist/{chunk-4y26vs3v.js → chunk-jspskey0.js} +16 -3
  158. package/dist/chunk-jspskey0.js.map +10 -0
  159. package/dist/{chunk-r6szek0x.js → chunk-jt3r6thp.js} +2 -135
  160. package/dist/chunk-jt3r6thp.js.map +10 -0
  161. package/dist/chunk-kfee1h52.js.map +1 -1
  162. package/dist/{chunk-qx00vjrj.js → chunk-kwfhd1g0.js} +23 -23
  163. package/dist/{chunk-qx00vjrj.js.map → chunk-kwfhd1g0.js.map} +4 -4
  164. package/dist/chunk-m427qgq0.js.map +1 -1
  165. package/dist/chunk-mbsbxarb.js.map +1 -1
  166. package/dist/{chunk-et017krg.js → chunk-mdxmt0n3.js} +8657 -8704
  167. package/dist/{chunk-et017krg.js.map → chunk-mdxmt0n3.js.map} +37 -37
  168. package/dist/chunk-mmagke4x.js.map +1 -1
  169. package/dist/{chunk-2x19q6k6.js → chunk-mqx25wwh.js} +319 -154
  170. package/dist/chunk-mqx25wwh.js.map +18 -0
  171. package/dist/chunk-mzx71snp.js.map +1 -1
  172. package/dist/chunk-n8q5j6y5.js.map +1 -1
  173. package/dist/chunk-npcr0228.js.map +1 -1
  174. package/dist/{chunk-m2nevja0.js → chunk-phm3c7b9.js} +1 -1
  175. package/dist/{chunk-m2nevja0.js.map → chunk-phm3c7b9.js.map} +1 -1
  176. package/dist/chunk-qf954wje.js.map +1 -1
  177. package/dist/{chunk-65pyhyas.js → chunk-qgvbxfqv.js} +6 -8
  178. package/dist/{chunk-65pyhyas.js.map → chunk-qgvbxfqv.js.map} +2 -2
  179. package/dist/{chunk-hk38wahh.js → chunk-qst145py.js} +4 -4
  180. package/dist/{chunk-hk38wahh.js.map → chunk-qst145py.js.map} +1 -1
  181. package/dist/{chunk-c844dkwd.js → chunk-qtzftvxa.js} +4 -5
  182. package/dist/{chunk-c844dkwd.js.map → chunk-qtzftvxa.js.map} +2 -2
  183. package/dist/chunk-ratkv4zc.js +3 -0
  184. package/dist/chunk-ratkv4zc.js.map +9 -0
  185. package/dist/{chunk-nzapm6p0.js → chunk-s3we74h8.js} +1 -2
  186. package/dist/chunk-s3we74h8.js.map +12 -0
  187. package/dist/{chunk-0xmt5p5y.js → chunk-t3brw0wd.js} +1 -2
  188. package/dist/{chunk-0xmt5p5y.js.map → chunk-t3brw0wd.js.map} +2 -2
  189. package/dist/chunk-t5608tkq.js.map +1 -1
  190. package/dist/chunk-tdxfsg1c.js.map +1 -1
  191. package/dist/{chunk-1t6k1avb.js → chunk-tnhqtfea.js} +1 -1
  192. package/dist/chunk-vhbw5sqm.js.map +1 -1
  193. package/dist/{chunk-rp9wwk7b.js → chunk-vx4e4zv4.js} +30 -30
  194. package/dist/{chunk-rp9wwk7b.js.map → chunk-vx4e4zv4.js.map} +4 -4
  195. package/dist/chunk-waqk73p1.js.map +1 -1
  196. package/dist/chunk-x0v3jd47.js.map +1 -1
  197. package/dist/{chunk-yecwnwpq.js → chunk-xm8qgbqm.js} +58 -29
  198. package/dist/{chunk-yecwnwpq.js.map → chunk-xm8qgbqm.js.map} +7 -7
  199. package/dist/{chunk-97wr6p2g.js → chunk-y7j6x4h0.js} +8 -8
  200. package/dist/{chunk-97wr6p2g.js.map → chunk-y7j6x4h0.js.map} +4 -4
  201. package/dist/{chunk-xe0732g0.js → chunk-yavhtnac.js} +12 -8
  202. package/dist/{chunk-xe0732g0.js.map → chunk-yavhtnac.js.map} +4 -4
  203. package/dist/chunk-yd00vzqr.js +3394 -0
  204. package/dist/chunk-yd00vzqr.js.map +37 -0
  205. package/dist/{chunk-n9w3n38q.js → chunk-ye5c8016.js} +54 -8
  206. package/dist/chunk-ye5c8016.js.map +23 -0
  207. package/dist/chunk-yw9pyg66.js.map +1 -1
  208. package/dist/{chunk-nydf3dbe.js → chunk-z9mg7wya.js} +37 -20
  209. package/dist/chunk-z9mg7wya.js.map +13 -0
  210. package/dist/chunk-zbc929zg.js.map +1 -1
  211. package/dist/chunk-zhh1jd89.js +290 -0
  212. package/dist/chunk-zhh1jd89.js.map +10 -0
  213. package/dist/connectors/connections/authorizations.d.ts +2 -2
  214. package/dist/connectors/connections/authorizations.d.ts.map +1 -1
  215. package/dist/connectors/connections/service.d.ts.map +1 -1
  216. package/dist/connectors/connections/tokens.d.ts +2 -2
  217. package/dist/connectors/connections/tokens.d.ts.map +1 -1
  218. package/dist/connectors/connections/validation.d.ts +5 -0
  219. package/dist/connectors/connections/validation.d.ts.map +1 -1
  220. package/dist/connectors/types.d.ts +9 -2
  221. package/dist/connectors/types.d.ts.map +1 -1
  222. package/dist/datasets/write.js +3 -3
  223. package/dist/deploy/internal.js +2 -5
  224. package/dist/deploy/internal.js.map +3 -3
  225. package/dist/deploy/types.d.ts +0 -2
  226. package/dist/deploy/types.d.ts.map +1 -1
  227. package/dist/execution/agent.d.ts +2 -2
  228. package/dist/execution/agent.d.ts.map +1 -1
  229. package/dist/execution/agent.js +38 -38
  230. package/dist/execution/agent.js.map +1 -1
  231. package/dist/execution/primitive.js +35 -35
  232. package/dist/execution/request.js +37 -37
  233. package/dist/execution/request.js.map +2 -2
  234. package/dist/http/api-routes.d.ts +12 -11
  235. package/dist/http/api-routes.d.ts.map +1 -1
  236. package/dist/http/index.js +1 -1
  237. package/dist/index.d.ts +3 -3
  238. package/dist/index.d.ts.map +1 -1
  239. package/dist/index.js +53 -51
  240. package/dist/index.js.map +1 -1
  241. package/dist/lake-storage/index.js +3 -3
  242. package/dist/logging/internal.js +1 -1
  243. package/dist/materializer/index.js +17 -17
  244. package/dist/models/execution/errors.d.ts +5 -0
  245. package/dist/models/execution/errors.d.ts.map +1 -1
  246. package/dist/models/execution/index.d.ts +2 -1
  247. package/dist/models/execution/index.d.ts.map +1 -1
  248. package/dist/models/execution/index.js +55 -50
  249. package/dist/models/execution/index.js.map +1 -1
  250. package/dist/models/execution/model-call-recorder.d.ts +7 -2
  251. package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
  252. package/dist/models/execution.d.ts.map +1 -1
  253. package/dist/models/language-call.d.ts +51 -0
  254. package/dist/models/language-call.d.ts.map +1 -0
  255. package/dist/objects/index.js +35 -35
  256. package/dist/objects/query/index.js +17 -17
  257. package/dist/ontology/docs-markdown.d.ts.map +1 -1
  258. package/dist/ontology/index.d.ts +1 -1
  259. package/dist/ontology/index.d.ts.map +1 -1
  260. package/dist/ontology/index.js +4 -4
  261. package/dist/ontology/internal.js +8 -275
  262. package/dist/ontology/internal.js.map +3 -4
  263. package/dist/ontology/user-ref.d.ts +21 -3
  264. package/dist/ontology/user-ref.d.ts.map +1 -1
  265. package/dist/pipelines/index.js +19 -19
  266. package/dist/projections/builders.d.ts +13 -2
  267. package/dist/projections/builders.d.ts.map +1 -1
  268. package/dist/projections/index.d.ts +1 -1
  269. package/dist/projections/index.d.ts.map +1 -1
  270. package/dist/projections/internal.js +17 -17
  271. package/dist/projections/types.d.ts +7 -0
  272. package/dist/projections/types.d.ts.map +1 -1
  273. package/dist/projections/validation.d.ts +2 -0
  274. package/dist/projections/validation.d.ts.map +1 -1
  275. package/dist/query.js +2 -2
  276. package/dist/queues/in-memory.d.ts +0 -1
  277. package/dist/queues/in-memory.d.ts.map +1 -1
  278. package/dist/queues/index.d.ts +1 -1
  279. package/dist/queues/index.d.ts.map +1 -1
  280. package/dist/queues/index.js +1 -1
  281. package/dist/queues/types.d.ts +0 -8
  282. package/dist/queues/types.d.ts.map +1 -1
  283. package/dist/runtime/internal.js +23 -23
  284. package/dist/runtime/internal.js.map +1 -1
  285. package/dist/sandboxes/configuration.d.ts +4 -6
  286. package/dist/sandboxes/configuration.d.ts.map +1 -1
  287. package/dist/sandboxes/environment.d.ts.map +1 -1
  288. package/dist/sandboxes/exec.d.ts +5 -3
  289. package/dist/sandboxes/exec.d.ts.map +1 -1
  290. package/dist/sandboxes/guest-credentials.d.ts +61 -0
  291. package/dist/sandboxes/guest-credentials.d.ts.map +1 -0
  292. package/dist/sandboxes/index.d.ts +2 -0
  293. package/dist/sandboxes/index.d.ts.map +1 -1
  294. package/dist/sandboxes/index.js +23 -9
  295. package/dist/sandboxes/index.js.map +1 -1
  296. package/dist/sandboxes/sandbox.d.ts +18 -4
  297. package/dist/sandboxes/sandbox.d.ts.map +1 -1
  298. package/dist/security/internal.js +1 -1
  299. package/dist/security/internal.js.map +1 -1
  300. package/dist/shares/internal.js +17 -17
  301. package/dist/shares/internal.js.map +1 -1
  302. package/dist/storage/agents/in-memory.d.ts +3 -1
  303. package/dist/storage/agents/in-memory.d.ts.map +1 -1
  304. package/dist/storage/agents/index.d.ts +1 -1
  305. package/dist/storage/agents/index.d.ts.map +1 -1
  306. package/dist/storage/agents/provider.d.ts +6 -0
  307. package/dist/storage/agents/provider.d.ts.map +1 -1
  308. package/dist/storage/agents/provider.js +8 -2
  309. package/dist/storage/agents/provider.js.map +1 -1
  310. package/dist/storage/agents/types.d.ts +63 -7
  311. package/dist/storage/agents/types.d.ts.map +1 -1
  312. package/dist/storage/ai-cost/provider.js +2 -2
  313. package/dist/storage/connector-connections/provider.js.map +1 -1
  314. package/dist/storage/file-upload-sessions/provider.js +9 -9
  315. package/dist/storage/index.d.ts +1 -1
  316. package/dist/storage/index.d.ts.map +1 -1
  317. package/dist/storage/index.js +15 -15
  318. package/dist/storage/ontology/provider.js +1 -1
  319. package/dist/storage/share-grants/provider.js +3 -3
  320. package/dist/storage/types.d.ts +1 -1
  321. package/dist/storage/types.d.ts.map +1 -1
  322. package/dist/storage/workflow-runs/provider.js +9 -9
  323. package/dist/syncs/index.js +20 -20
  324. package/dist/testing/agent-storage-contract.d.ts.map +1 -1
  325. package/dist/testing/index.d.ts +2 -0
  326. package/dist/testing/index.d.ts.map +1 -1
  327. package/dist/testing/index.js +677 -352
  328. package/dist/testing/index.js.map +9 -7
  329. package/dist/testing/queues-contract.d.ts.map +1 -1
  330. package/dist/testing/sandbox-credentials-contract.d.ts +27 -0
  331. package/dist/testing/sandbox-credentials-contract.d.ts.map +1 -0
  332. package/dist/testing/sandboxes-contract.d.ts.map +1 -1
  333. package/dist/testing/users.d.ts +20 -0
  334. package/dist/testing/users.d.ts.map +1 -0
  335. package/dist/users/execution.d.ts +6 -2
  336. package/dist/users/execution.d.ts.map +1 -1
  337. package/dist/users/index.d.ts +1 -1
  338. package/dist/users/index.d.ts.map +1 -1
  339. package/dist/webhooks/internal.js +17 -17
  340. package/dist/webhooks/internal.js.map +1 -1
  341. package/dist/workers/index.js.map +1 -1
  342. package/dist/workflows/index.js +41 -39
  343. package/dist/workflows/index.js.map +1 -1
  344. package/package.json +1 -1
  345. package/src/agents/README.md +136 -0
  346. package/src/agents/attachment-keys.ts +83 -0
  347. package/src/agents/cancel.ts +16 -1
  348. package/src/agents/children.ts +5 -3
  349. package/src/agents/dispatch.ts +6 -58
  350. package/src/agents/execution.ts +18 -0
  351. package/src/agents/index.ts +127 -21
  352. package/src/agents/model-loop.ts +23 -73
  353. package/src/agents/model-routing.ts +7 -2
  354. package/src/agents/request.ts +69 -20
  355. package/src/agents/run-after-finish.ts +133 -0
  356. package/src/agents/run-artifacts.ts +257 -0
  357. package/src/agents/run-events.ts +302 -0
  358. package/src/agents/run-fence.ts +71 -0
  359. package/src/agents/run-liveness.ts +122 -0
  360. package/src/agents/run-plan.ts +316 -0
  361. package/src/agents/run-session-children.ts +303 -0
  362. package/src/agents/run-session-http.ts +397 -0
  363. package/src/agents/run-session-serve.ts +479 -0
  364. package/src/agents/run-session-wire.ts +189 -0
  365. package/src/agents/run-session.ts +802 -0
  366. package/src/agents/run-token.ts +124 -0
  367. package/src/agents/run-tools.ts +180 -0
  368. package/src/agents/run-turn.ts +265 -0
  369. package/src/agents/streams/internal.ts +0 -1
  370. package/src/agents/streams/protocol.ts +0 -292
  371. package/src/agents/subagent-runs.ts +19 -1
  372. package/src/agents/tool-files.ts +225 -0
  373. package/src/agents/workflow-node-session.ts +387 -0
  374. package/src/artifacts/frames/probe.ts +14 -1
  375. package/src/artifacts/publish/index.ts +1 -0
  376. package/src/connectors/connections/authorizations.ts +3 -2
  377. package/src/connectors/connections/service.ts +5 -1
  378. package/src/connectors/connections/tokens.ts +41 -5
  379. package/src/connectors/connections/validation.ts +21 -0
  380. package/src/connectors/types.ts +12 -2
  381. package/src/deploy/types.ts +0 -2
  382. package/src/deploy/validation.ts +1 -4
  383. package/src/execution/agent.ts +2 -2
  384. package/src/execution/authorized-object-reader.ts +28 -1
  385. package/src/http/api-routes.ts +114 -27
  386. package/src/index.ts +3 -1
  387. package/src/models/execution/README.md +15 -1
  388. package/src/models/execution/errors.ts +14 -0
  389. package/src/models/execution/index.ts +2 -1
  390. package/src/models/execution/model-call-recorder.ts +12 -10
  391. package/src/models/execution.ts +9 -11
  392. package/src/models/language-call.ts +247 -0
  393. package/src/ontology/docs-markdown.ts +14 -0
  394. package/src/ontology/index.ts +1 -1
  395. package/src/ontology/user-ref.ts +40 -6
  396. package/src/projections/builders.ts +48 -4
  397. package/src/projections/index.ts +1 -0
  398. package/src/projections/registry.ts +1 -0
  399. package/src/projections/revision.ts +10 -0
  400. package/src/projections/types.ts +8 -0
  401. package/src/projections/validation.ts +52 -6
  402. package/src/queues/in-memory.ts +0 -5
  403. package/src/queues/index.ts +0 -2
  404. package/src/queues/types.ts +0 -13
  405. package/src/runtime/host.ts +1 -1
  406. package/src/sandboxes/README.md +17 -6
  407. package/src/sandboxes/configuration.ts +7 -9
  408. package/src/sandboxes/environment.ts +1 -0
  409. package/src/sandboxes/exec.ts +17 -9
  410. package/src/sandboxes/guest-credentials.ts +262 -0
  411. package/src/sandboxes/index.ts +14 -0
  412. package/src/sandboxes/sandbox.ts +19 -4
  413. package/src/storage/agents/in-memory.ts +53 -0
  414. package/src/storage/agents/index.ts +2 -0
  415. package/src/storage/agents/provider.ts +56 -11
  416. package/src/storage/agents/types.ts +59 -7
  417. package/src/storage/index.ts +2 -0
  418. package/src/storage/types.ts +1 -0
  419. package/src/testing/agent-storage-contract.ts +175 -2
  420. package/src/testing/ai-model-call-groups-contract.ts +0 -1
  421. package/src/testing/index.ts +5 -0
  422. package/src/testing/queues-contract.ts +0 -16
  423. package/src/testing/sandbox-credentials-contract.ts +284 -0
  424. package/src/testing/sandboxes-contract.ts +21 -0
  425. package/src/testing/users.ts +39 -0
  426. package/src/users/execution.ts +33 -7
  427. package/src/users/index.ts +7 -1
  428. package/dist/agents/api-gateway.d.ts +0 -26
  429. package/dist/agents/api-gateway.d.ts.map +0 -1
  430. package/dist/chunk-2x19q6k6.js.map +0 -17
  431. package/dist/chunk-4y26vs3v.js.map +0 -10
  432. package/dist/chunk-661ezhks.js.map +0 -11
  433. package/dist/chunk-d2m879s4.js.map +0 -12
  434. package/dist/chunk-n9w3n38q.js.map +0 -23
  435. package/dist/chunk-nydf3dbe.js.map +0 -13
  436. package/dist/chunk-nzapm6p0.js.map +0 -12
  437. package/dist/chunk-r6szek0x.js.map +0 -10
  438. package/dist/chunk-vabga7fk.js +0 -176
  439. package/dist/chunk-vabga7fk.js.map +0 -12
  440. package/dist/chunk-vpgwq5nf.js +0 -810
  441. package/dist/chunk-vpgwq5nf.js.map +0 -21
  442. package/src/agents/api-gateway.ts +0 -68
  443. /package/dist/{chunk-2gjj5dx3.js.map → chunk-78ymxrn0.js.map} +0 -0
  444. /package/dist/{chunk-6n69k945.js.map → chunk-8mb7mt8n.js.map} +0 -0
  445. /package/dist/{chunk-m36fw8ft.js.map → chunk-8wsjr52f.js.map} +0 -0
  446. /package/dist/{chunk-bab05bhg.js.map → chunk-dgtd0836.js.map} +0 -0
  447. /package/dist/{chunk-7ny9mjgm.js.map → chunk-ft3w5ahs.js.map} +0 -0
  448. /package/dist/{chunk-1t6k1avb.js.map → chunk-tnhqtfea.js.map} +0 -0
@@ -12,7 +12,6 @@ import {
12
12
  type AgentRunFailureCode,
13
13
  type AgentRunRecord,
14
14
  type ConversationAgentRunRecord,
15
- type SubagentRunRecord,
16
15
  } from "../../storage/agents/types"
17
16
 
18
17
  export const AGENT_RUN_STREAM_SCHEMA_VERSION = 1 as const
@@ -290,296 +289,6 @@ export async function subscribeAgentRunCancel(
290
289
  )
291
290
  }
292
291
 
293
- // ── Inbox streams (mail between a turn and its sub-agents) ──────────────────────────────────────
294
- //
295
- // A sub-agent's thread has an inbox its runs read at each step boundary: its parent steering it,
296
- // and the parent's reply to its question. Every run of the child reads the same one. A turn has
297
- // one too, where its children ask it. Its durable record is the sender's tool call and the
298
- // reader's thread, which keeps each `mail` part where it was read, or the tool result. An answer
299
- // the parent could only give in a later turn starts the run that continues the child, never through
300
- // these streams. A thread's inbox outlives the turn only so that a child paused on a held call,
301
- // which a later turn continues once the user decides, can still be given what it did not read: it
302
- // keeps mail as long as an approval waits, and a day more.
303
- //
304
- // A turn's inbox also hears when each of its children finishes, so one subscription per turn wakes
305
- // its waits for questions and for children alike.
306
-
307
- export type AgentThreadInboxStreamId = `agents.threads.${string}.inbox`
308
- export type AgentRunInboxStreamId = `agents.runs.${string}.inbox`
309
-
310
- export function agentThreadInboxStreamId(threadId: string): AgentThreadInboxStreamId {
311
- return `agents.threads.${threadId}.inbox`
312
- }
313
-
314
- export function agentRunInboxStreamId(runId: string): AgentRunInboxStreamId {
315
- return `agents.runs.${runId}.inbox`
316
- }
317
-
318
- const AGENT_MAIL_RECORD = "agent.mail"
319
-
320
- const AGENT_INBOX_RETENTION = {
321
- // An approval waits at most 7 days (`AGENT_APPROVAL_TTL_MS`).
322
- maxAgeMs: 8 * 24 * 60 * 60 * 1000,
323
- maxRecords: 1_000,
324
- } as const
325
-
326
- /** Whose inbox: a sub-agent's thread, or a turn its children ask. */
327
- export type AgentInbox = { readonly threadId: string } | { readonly runId: string }
328
-
329
- function inboxStreamDefinition(inbox: AgentInbox): BrokerStreamDefinition {
330
- return { id: inboxStreamId(inbox), retention: AGENT_INBOX_RETENTION }
331
- }
332
-
333
- function inboxStreamId(inbox: AgentInbox): AgentThreadInboxStreamId | AgentRunInboxStreamId {
334
- return "threadId" in inbox
335
- ? agentThreadInboxStreamId(inbox.threadId)
336
- : agentRunInboxStreamId(inbox.runId)
337
- }
338
-
339
- /**
340
- * The kinds of mail this version writes and understands:
341
- *
342
- * - `message`: the parent steers its child;
343
- * - `question`: the child asks its parent, and waits;
344
- * - `answer`: the parent's reply to a question, `inReplyTo`;
345
- * - `deferred`: the parent's turn ended without one, so the child pauses on its question.
346
- */
347
- export const AGENT_MAIL_KINDS = ["message", "question", "answer", "deferred"] as const
348
- export type AgentMailKind = (typeof AGENT_MAIL_KINDS)[number]
349
-
350
- /**
351
- * One message between a turn and its sub-agent: to the child's thread, or, a question, from the
352
- * child's thread to the turn.
353
- */
354
- export type AgentMail = {
355
- /** Unique per message: a sender writing it again, or the broker redelivering it, is the same. */
356
- readonly id: string
357
- readonly fromRunId: string
358
- readonly kind: AgentMailKind
359
- /** The question an `answer` or `deferred` replies to. */
360
- readonly inReplyTo?: string
361
- /** What the reader's model reads, whatever the kind: a reader that does not know it reads this. */
362
- readonly text: string
363
- readonly sentAt: string
364
- } & (
365
- | { readonly toThreadId: string }
366
- | {
367
- readonly toRunId: string
368
- /** The sub-agent's thread that asks. */
369
- readonly fromThreadId: string
370
- }
371
- )
372
-
373
- /**
374
- * Mail as a reader finds it. Its kind may be one a newer sender writes: the reader delivers its
375
- * text as a message rather than skipping it, so no reader's cursor passes mail it never delivered.
376
- */
377
- export type ReceivedAgentMail = Omit<AgentMail, "kind"> & { readonly kind: string }
378
-
379
- export function isKnownAgentMailKind(kind: string): kind is AgentMailKind {
380
- return (AGENT_MAIL_KINDS as readonly string[]).includes(kind)
381
- }
382
-
383
- function isReceivedAgentMail(value: unknown): value is ReceivedAgentMail {
384
- return (
385
- isPlainRecord(value) &&
386
- typeof value.id === "string" &&
387
- typeof value.fromRunId === "string" &&
388
- (typeof value.toThreadId === "string" ||
389
- (typeof value.toRunId === "string" && typeof value.fromThreadId === "string")) &&
390
- typeof value.kind === "string" &&
391
- value.kind.length > 0 &&
392
- (value.inReplyTo === undefined || typeof value.inReplyTo === "string") &&
393
- typeof value.text === "string" &&
394
- typeof value.sentAt === "string"
395
- )
396
- }
397
-
398
- /** Whether mail is addressed to this inbox. */
399
- function isFor(mail: ReceivedAgentMail, inbox: AgentInbox): boolean {
400
- return "threadId" in inbox
401
- ? "toThreadId" in mail && mail.toThreadId === inbox.threadId
402
- : "toRunId" in mail && mail.toRunId === inbox.runId
403
- }
404
-
405
- function recipientOf(mail: AgentMail): AgentInbox {
406
- return "toThreadId" in mail ? { threadId: mail.toThreadId } : { runId: mail.toRunId }
407
- }
408
-
409
- /** Write a message to its recipient's inbox. Idempotent by its id where the broker dedupes. */
410
- export async function publishAgentMail(
411
- broker: Broker,
412
- params: { readonly projectId: string; readonly mail: AgentMail }
413
- ): Promise<void> {
414
- const { projectId, mail } = params
415
- const inbox = recipientOf(mail)
416
- await broker.ensureStream({ projectId, stream: inboxStreamDefinition(inbox) })
417
- await broker.append({
418
- projectId,
419
- streamId: inboxStreamId(inbox),
420
- records: [
421
- {
422
- name: AGENT_MAIL_RECORD,
423
- key: "threadId" in inbox ? inbox.threadId : inbox.runId,
424
- // The mail is composed only of validated JSON primitives.
425
- payload: mail as unknown as JsonValue,
426
- idempotencyKey: mail.id,
427
- },
428
- ],
429
- })
430
- }
431
-
432
- /**
433
- * Call `onMail` with each page of mail to an inbox as it arrives, from its start. It is a wake: a
434
- * broker may deliver a record again, so the reader keeps each mail once by its id. Returns the
435
- * unsubscribe handle.
436
- */
437
- export function subscribeAgentMail(
438
- broker: Broker,
439
- params: { readonly projectId: string; readonly inbox: AgentInbox },
440
- onMail: (mail: readonly ReceivedAgentMail[]) => void
441
- ): Promise<() => void> {
442
- return subscribeAgentInbox(broker, params, { mail: onMail })
443
- }
444
-
445
- /**
446
- * Hear an inbox from its start: its mail, and, for a turn's with `childFinished`, the ids of its
447
- * children as each finishes. Both are wakes: a broker may deliver a record again, and a finish says
448
- * only that the child's run is worth reading. Returns the unsubscribe handle.
449
- */
450
- export async function subscribeAgentInbox(
451
- broker: Broker,
452
- params: { readonly projectId: string; readonly inbox: AgentInbox },
453
- on: {
454
- readonly mail: (mail: readonly ReceivedAgentMail[]) => void
455
- readonly childFinished?: (runIds: readonly string[]) => void
456
- }
457
- ): Promise<() => void> {
458
- const { inbox } = params
459
- await broker.ensureStream({
460
- projectId: params.projectId,
461
- stream: inboxStreamDefinition(inbox),
462
- })
463
- return broker.subscribe(
464
- {
465
- projectId: params.projectId,
466
- streamId: inboxStreamId(inbox),
467
- from: "earliest",
468
- names: on.childFinished
469
- ? [AGENT_MAIL_RECORD, AGENT_CHILD_FINISHED_RECORD]
470
- : [AGENT_MAIL_RECORD],
471
- },
472
- (records) => {
473
- const mail: ReceivedAgentMail[] = []
474
- const finished: string[] = []
475
- for (const { name, payload } of records) {
476
- if (name === AGENT_MAIL_RECORD) {
477
- if (isReceivedAgentMail(payload) && isFor(payload, inbox)) mail.push(payload)
478
- } else if (
479
- "runId" in inbox &&
480
- isAgentChildFinished(payload) &&
481
- payload.parentRunId === inbox.runId
482
- ) {
483
- finished.push(payload.runId)
484
- }
485
- }
486
-
487
- if (mail.length > 0) on.mail(mail)
488
- if (finished.length > 0) on.childFinished?.(finished)
489
- }
490
- )
491
- }
492
-
493
- const AGENT_CHILD_FINISHED_RECORD = "agent.child.finished"
494
-
495
- /** A child stopped being at work: it ended, or paused on a held call or on its question. */
496
- interface AgentChildFinished {
497
- readonly runId: string
498
- readonly parentRunId: string
499
- readonly status: "succeeded" | "failed" | "cancelled"
500
- }
501
-
502
- function isAgentChildFinished(value: unknown): value is AgentChildFinished {
503
- return (
504
- isPlainRecord(value) &&
505
- typeof value.runId === "string" &&
506
- typeof value.parentRunId === "string" &&
507
- isTerminalAgentRunStatus(value.status)
508
- )
509
- }
510
-
511
- /**
512
- * Tell the turn a child works under, on the turn's inbox, that the child finished. Its run stream
513
- * says so too, but that stream belongs to the transcript sink, which a worker may replace, and
514
- * hearing it would take one subscription per child, each carrying every chunk the child streams.
515
- * This record is the platform's, and one subscription per turn hears every child.
516
- */
517
- export async function publishAgentChildFinished(
518
- broker: Broker,
519
- run: SubagentRunRecord
520
- ): Promise<void> {
521
- if (run.status === "queued" || run.status === "running") return
522
-
523
- const finished: AgentChildFinished = {
524
- runId: run.id,
525
- parentRunId: run.parentRunId,
526
- status: run.status,
527
- }
528
- const inbox = { runId: run.parentRunId }
529
- await broker.ensureStream({ projectId: run.projectId, stream: inboxStreamDefinition(inbox) })
530
- await broker.append({
531
- projectId: run.projectId,
532
- streamId: inboxStreamId(inbox),
533
- records: [
534
- {
535
- name: AGENT_CHILD_FINISHED_RECORD,
536
- key: run.parentRunId,
537
- // The record is composed only of validated JSON primitives.
538
- payload: finished as unknown as JsonValue,
539
- idempotencyKey: `${run.id}:${run.attempt}:finished:${run.status}`,
540
- },
541
- ],
542
- })
543
- }
544
-
545
- /**
546
- * Read an inbox's mail after `afterCursor`, or from the start, every page of it. Carry the returned
547
- * cursor to the next read. A record that is not mail at all (no envelope, no text) cannot be
548
- * delivered: it is reported and passed, never silently.
549
- */
550
- export async function readAgentMail(
551
- broker: Broker,
552
- params: { readonly projectId: string; readonly inbox: AgentInbox; readonly afterCursor?: string }
553
- ): Promise<{ readonly mail: readonly ReceivedAgentMail[]; readonly cursor?: string }> {
554
- const mail: ReceivedAgentMail[] = []
555
- const streamId = inboxStreamId(params.inbox)
556
- let cursor = params.afterCursor
557
-
558
- for (;;) {
559
- const page = await broker.read({
560
- projectId: params.projectId,
561
- streamId,
562
- names: [AGENT_MAIL_RECORD],
563
- ...(cursor === undefined ? {} : { afterCursor: cursor }),
564
- })
565
- for (const record of page.records) {
566
- if (!isReceivedAgentMail(record.payload)) {
567
- console.error(
568
- `[Sixb] Agent inbox '${streamId}' record '${record.cursor}' is not mail; it is skipped.`
569
- )
570
- continue
571
- }
572
- if (isFor(record.payload, params.inbox)) mail.push(record.payload)
573
- }
574
-
575
- const previous = cursor
576
- cursor = page.cursor ?? cursor
577
- if (!page.hasMore || cursor === previous) break
578
- }
579
-
580
- return { mail, ...(cursor === undefined ? {} : { cursor }) }
581
- }
582
-
583
292
  /** Exact portable failure exposed by a terminal Agent run stream event. */
584
293
  export type AgentRunFailure = SixbFailure<AgentRunFailureCode>
585
294
 
@@ -797,5 +506,4 @@ export async function publishAgentRunFinished(broker: Broker, run: AgentRunRecor
797
506
  ],
798
507
  })
799
508
  if (run.kind === "conversation") await publishAgentRunActivity(broker, run)
800
- else await publishAgentChildFinished(broker, run)
801
509
  }
@@ -1,4 +1,4 @@
1
- import type { AgentStorage, SubagentRunRecord } from "../storage/agents"
1
+ import type { AgentStorage, SubagentRunFile, SubagentRunRecord } from "../storage/agents"
2
2
 
3
3
  const PAGE = 100
4
4
 
@@ -39,3 +39,21 @@ export async function listSubagentThreadRuns(
39
39
  a.id.localeCompare(b.id)
40
40
  )
41
41
  }
42
+
43
+ /**
44
+ * The files a child finds in its sandbox: those its parent handed over, and for a continuation
45
+ * what the paused run left in `out/`, given back there. An output wins over a handed file at its
46
+ * path, as the paused run's copy was the latest.
47
+ */
48
+ export function subagentSandboxFiles(
49
+ run: SubagentRunRecord,
50
+ paused: SubagentRunRecord | undefined
51
+ ): readonly SubagentRunFile[] {
52
+ const outputs = (paused?.result?.files ?? []).map((file) => ({
53
+ ...file,
54
+ path: `out/${file.path}`,
55
+ }))
56
+ const restored = new Set(outputs.map((file) => file.path))
57
+
58
+ return [...(run.spec.files ?? []).filter((file) => !restored.has(file.path)), ...outputs]
59
+ }
@@ -0,0 +1,225 @@
1
+ import { createHash } from "node:crypto"
2
+ import { posix } from "node:path"
3
+ import { ARTIFACT_LIMITS } from "../artifacts/limits"
4
+ import { sniffFileMediaType } from "../blob-storage/media-type"
5
+ import type { BlobBody, FileRef } from "../blob-storage/types"
6
+ import { AgentToolPublicError } from "./errors"
7
+ import type { AgentRunFileStore } from "./run-session"
8
+ import type { AgentToolFilePutInput } from "./types"
9
+
10
+ // The files a tool stores for its run: checked and stored where the tool runs, then copied into the
11
+ // run's sandbox by its runner, at the path the tool was told. A tool that runs on the server and
12
+ // one in the runner's process store the same way.
13
+
14
+ /** Where a run's sandbox keeps its files, relative to its working directory. */
15
+ export const SANDBOX_CONTEXT_DIRECTORY = ".sixb/agent"
16
+ /** The most a file a tool stores, or one `view_file` reads, may hold: an artifact's file limit. */
17
+ export const AGENT_FILE_MAX_BYTES = ARTIFACT_LIMITS.maxFileBytes
18
+ const MAX_FILE_NAME_BYTES = 255
19
+ const MAX_MEDIA_TYPE_LENGTH = 255
20
+ const MEDIA_TYPE_PATTERN = /^[!#$&^_.+A-Za-z0-9-]+\/[!#$&^_.+A-Za-z0-9-]+$/
21
+ const CONTROL_CHARACTER_PATTERN = /[\u0000-\u001f\u007f]/
22
+
23
+ /** A file a tool stored, and where its runner copies it in the run's sandbox. */
24
+ export interface AgentToolCallFile {
25
+ readonly fileRef: FileRef
26
+ /** Relative to the sandbox's context directory, wherever the runner keeps it. */
27
+ readonly path: string
28
+ }
29
+
30
+ /** A file a tool just stored, with its bytes, which its runner copies; the blob holds the same. */
31
+ export interface StoredAgentToolFile extends AgentToolCallFile {
32
+ readonly bytes: Uint8Array
33
+ }
34
+
35
+ /**
36
+ * Check one file a tool puts and store it: a single safe name, a media type its bytes match, at most
37
+ * `fileMaxBytes`. Its `path` in the sandbox's context directory is where the runner copies it: one
38
+ * directory per tool call, and the content's digest in its name.
39
+ */
40
+ export async function storeAgentToolFile(input: {
41
+ readonly toolName: string
42
+ readonly toolCallId: string
43
+ readonly file: AgentToolFilePutInput
44
+ readonly store: Pick<AgentRunFileStore, "put">
45
+ readonly signal: AbortSignal
46
+ /** Called with each file's size as it is read, before it is stored; throws to refuse it. */
47
+ readonly onBytes?: (sizeBytes: number) => void
48
+ /** Test seam; production allows {@link AGENT_FILE_MAX_BYTES}. */
49
+ readonly fileMaxBytes?: number
50
+ }): Promise<StoredAgentToolFile> {
51
+ const { toolName, signal } = input
52
+ signal.throwIfAborted()
53
+ const fileName = validateFileName(input.file.fileName, toolName)
54
+ const declaredMediaType = normalizeMediaType(
55
+ input.file.mediaType ?? blobMediaType(input.file.body),
56
+ toolName
57
+ )
58
+ const bytes = await readFileBody({
59
+ body: input.file.body,
60
+ fileMaxBytes: input.fileMaxBytes ?? AGENT_FILE_MAX_BYTES,
61
+ signal,
62
+ toolName,
63
+ onBytes: input.onBytes ?? (() => {}),
64
+ })
65
+ const mediaType = validatedMediaType(bytes, declaredMediaType, toolName)
66
+ signal.throwIfAborted()
67
+ const fileRef = await input.store.put({
68
+ body: bytes,
69
+ expectedSizeBytes: bytes.byteLength,
70
+ signal,
71
+ fileName,
72
+ mediaType,
73
+ })
74
+ signal.throwIfAborted()
75
+ return { fileRef, path: toolFilePath(input.toolCallId, fileRef, fileName), bytes }
76
+ }
77
+
78
+ async function readFileBody(input: {
79
+ readonly body: BlobBody
80
+ readonly fileMaxBytes: number
81
+ readonly signal: AbortSignal
82
+ readonly toolName: string
83
+ readonly onBytes: (sizeBytes: number) => void
84
+ }): Promise<Uint8Array> {
85
+ const { body, signal } = input
86
+ const knownSize = knownBodySize(body)
87
+ if (knownSize !== undefined) {
88
+ assertWithinFileLimit(knownSize, input.fileMaxBytes, input.toolName)
89
+ input.onBytes(knownSize)
90
+ }
91
+ signal.throwIfAborted()
92
+
93
+ if (body instanceof Uint8Array) return new Uint8Array(body)
94
+ if (body instanceof ArrayBuffer) return new Uint8Array(body.slice(0))
95
+ if (body instanceof Blob) {
96
+ const bytes = new Uint8Array(await body.arrayBuffer())
97
+ signal.throwIfAborted()
98
+ return bytes
99
+ }
100
+ if (!(body instanceof ReadableStream)) {
101
+ throw toolFileError(input.toolName, "file body must be binary data or a byte stream")
102
+ }
103
+
104
+ const reader = body.getReader()
105
+ const chunks: Uint8Array[] = []
106
+ let totalBytes = 0
107
+ const cancelOnAbort = () => {
108
+ void reader.cancel(signal.reason)
109
+ }
110
+ signal.addEventListener("abort", cancelOnAbort, { once: true })
111
+ try {
112
+ while (true) {
113
+ const { done, value } = await reader.read()
114
+ signal.throwIfAborted()
115
+ if (done) break
116
+ const chunk = new Uint8Array(value)
117
+ totalBytes += chunk.byteLength
118
+ if (totalBytes > input.fileMaxBytes) {
119
+ await reader.cancel("agent tool file exceeded its file limit").catch(() => {})
120
+ assertWithinFileLimit(totalBytes, input.fileMaxBytes, input.toolName)
121
+ }
122
+ input.onBytes(chunk.byteLength)
123
+ chunks.push(chunk)
124
+ }
125
+ } finally {
126
+ signal.removeEventListener("abort", cancelOnAbort)
127
+ reader.releaseLock()
128
+ }
129
+
130
+ const bytes = new Uint8Array(totalBytes)
131
+ let offset = 0
132
+ for (const chunk of chunks) {
133
+ bytes.set(chunk, offset)
134
+ offset += chunk.byteLength
135
+ }
136
+ return bytes
137
+ }
138
+
139
+ function knownBodySize(body: BlobBody): number | undefined {
140
+ if (body instanceof Uint8Array) return body.byteLength
141
+ if (body instanceof ArrayBuffer) return body.byteLength
142
+ if (body instanceof Blob) return body.size
143
+ return undefined
144
+ }
145
+
146
+ function assertWithinFileLimit(sizeBytes: number, limit: number, toolName: string): void {
147
+ if (sizeBytes <= limit) return
148
+ throw toolFileError(
149
+ toolName,
150
+ `file is ${sizeBytes} bytes and exceeds the ${limit}-byte file limit`
151
+ )
152
+ }
153
+
154
+ function validateFileName(value: string, toolName: string): string {
155
+ if (
156
+ typeof value !== "string" ||
157
+ value.trim().length === 0 ||
158
+ value === "." ||
159
+ value === ".." ||
160
+ value.includes("/") ||
161
+ value.includes("\\") ||
162
+ CONTROL_CHARACTER_PATTERN.test(value)
163
+ ) {
164
+ throw toolFileError(toolName, "fileName must be a single safe file name")
165
+ }
166
+ const sizeBytes = new TextEncoder().encode(value).byteLength
167
+ if (sizeBytes > MAX_FILE_NAME_BYTES) {
168
+ throw toolFileError(toolName, `fileName exceeds the ${MAX_FILE_NAME_BYTES}-byte limit`)
169
+ }
170
+ return value
171
+ }
172
+
173
+ function blobMediaType(body: BlobBody): string | undefined {
174
+ return body instanceof Blob ? body.type : undefined
175
+ }
176
+
177
+ function normalizeMediaType(value: string | undefined, toolName: string): string | undefined {
178
+ if (value === undefined || value === "") return undefined
179
+ const normalized = value.trim().toLowerCase()
180
+ if (
181
+ normalized.length === 0 ||
182
+ normalized.length > MAX_MEDIA_TYPE_LENGTH ||
183
+ !MEDIA_TYPE_PATTERN.test(normalized)
184
+ ) {
185
+ throw toolFileError(toolName, "mediaType must be a valid type/subtype value")
186
+ }
187
+ return normalized === "image/jpg" ? "image/jpeg" : normalized
188
+ }
189
+
190
+ function validatedMediaType(
191
+ bytes: Uint8Array,
192
+ declared: string | undefined,
193
+ toolName: string
194
+ ): string {
195
+ const detected = sniffFileMediaType(bytes)
196
+ if (detected && declared && declared !== "application/octet-stream" && detected !== declared) {
197
+ throw toolFileError(
198
+ toolName,
199
+ `file bytes are ${detected}, not the declared media type ${declared}`
200
+ )
201
+ }
202
+ if (declared && SIGNATURE_REQUIRED_MEDIA_TYPES.has(declared) && detected !== declared) {
203
+ throw toolFileError(toolName, `file bytes do not match the declared media type ${declared}`)
204
+ }
205
+ return detected ?? declared ?? "application/octet-stream"
206
+ }
207
+
208
+ const SIGNATURE_REQUIRED_MEDIA_TYPES = new Set([
209
+ "application/pdf",
210
+ "image/gif",
211
+ "image/jpeg",
212
+ "image/png",
213
+ "image/webp",
214
+ ])
215
+
216
+ /** Where a tool's file goes in the context directory, as the agent names it. */
217
+ function toolFilePath(toolCallId: string, fileRef: FileRef, fileName: string): string {
218
+ const callKey = createHash("sha256").update(toolCallId).digest("hex").slice(0, 16)
219
+ const digestKey = fileRef.digest.slice("sha256:".length, "sha256:".length + 12)
220
+ return posix.join("tool-files", callKey, `${digestKey}-${fileName}`)
221
+ }
222
+
223
+ function toolFileError(toolName: string, message: string): AgentToolPublicError {
224
+ return new AgentToolPublicError(`[SixbAgent] Agent tool '${toolName}' ${message}.`)
225
+ }