@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
@@ -0,0 +1,479 @@
1
+ import type { LanguageModelRequest } from "../models/language-model"
2
+ import type { AgentRunRecord } from "../storage/agents"
3
+ import { AgentExecutionLostError, AgentRunRefusedError } from "./run-fence"
4
+ import { agentRunLeaseLapsed, endInterruptedAgentRun } from "./run-liveness"
5
+ import {
6
+ type AgentRunSession,
7
+ type AgentRunSessionHost,
8
+ claimAgentRun,
9
+ openAgentRunSession,
10
+ } from "./run-session"
11
+ import {
12
+ AGENT_RUN_STOPPED_HEADER,
13
+ decodeWireValue,
14
+ encodeWireError,
15
+ encodeWireValue,
16
+ parseAgentRunSessionPath,
17
+ wireErrorStatus,
18
+ } from "./run-session-wire"
19
+ import { agentRunnerTokenRunId, createAgentRunnerToken, isValidAgentRunnerToken } from "./run-token"
20
+
21
+ // The server side of a session a runner reaches over HTTP. Each request names the run and carries
22
+ // its runner token, issued under the run's current execution: the request opens the run's session,
23
+ // runs one operation of it, and closes it. Every operation is the in-process session's own, so
24
+ // what it checks, fences and records is the same wherever the runner is.
25
+ //
26
+ // The run token its sandbox's commands call the API with never reaches it: they would finish the
27
+ // run, write its messages and call its models as its runner.
28
+
29
+ type Operation = (
30
+ session: AgentRunSession,
31
+ args: readonly unknown[],
32
+ signal: AbortSignal
33
+ ) => unknown
34
+
35
+ /**
36
+ * The session's operations a runner calls, by name; nothing else is reachable. Neither
37
+ * `authorization` nor `workspace` is: only a runner in the worker's process binds the project or
38
+ * moves a persistent workspace.
39
+ */
40
+ const OPERATIONS: Readonly<Record<string, Operation>> = {
41
+ plan: (session) => session.plan(),
42
+ memory: (session, [input]) => session.memory(input as { asOf: Date }),
43
+ context: (session) => session.context(),
44
+ checkpoint: (session, [input]) =>
45
+ session.checkpoint(input as Parameters<AgentRunSession["checkpoint"]>[0]),
46
+ finish: (session, [outcome, messages]) =>
47
+ finish(
48
+ session,
49
+ outcome as Parameters<AgentRunSession["finish"]>[0],
50
+ ownMessages(session.run, messages as Parameters<AgentRunSession["finish"]>[1])
51
+ ),
52
+ assertOwned: (session) => session.assertOwned(),
53
+ renewLease: (session, [leaseExpiresAt]) => renew(session, capLease(leaseExpiresAt as string)),
54
+ "heldCalls.holdsRun": (session) => session.heldCalls.holdsRun(),
55
+ "heldCalls.pausesAfterStep": (session) => session.heldCalls.pausesAfterStep(),
56
+ "children.get": (session, [runId]) => session.children.get(runId as string),
57
+ "children.getMany": (session, [runIds]) => session.children.getMany(runIds as string[]),
58
+ "children.inConversation": (session, [input]) =>
59
+ session.children.inConversation(
60
+ input as Parameters<AgentRunSession["children"]["inConversation"]>[0]
61
+ ),
62
+ "children.threadRuns": (session, [threadId]) => session.children.threadRuns(threadId as string),
63
+ "children.approvals": (session, [runId]) => session.children.approvals(runId as string),
64
+ "children.holdsRun": (session, [runId]) => session.children.holdsRun(runId as string),
65
+ "children.awaitingApproval": (session, [runIds]) =>
66
+ session.children.awaitingApproval(runIds as string[]),
67
+ "children.activeCount": (session) => session.children.activeCount(),
68
+ "children.spawn": (session, [draft]) =>
69
+ session.children.spawn(draft as Parameters<AgentRunSession["children"]["spawn"]>[0]),
70
+ "children.clearAttempt": (session, [input]) =>
71
+ session.children.clearAttempt(
72
+ input as Parameters<AgentRunSession["children"]["clearAttempt"]>[0]
73
+ ),
74
+ "threads.message": (session, [messageId]) => session.threads.message(messageId as string),
75
+ "threads.messages": (session, [input]) =>
76
+ session.threads.messages(input as Parameters<AgentRunSession["threads"]["messages"]>[0]),
77
+ "artifacts.list": (session, [input]) =>
78
+ session.artifacts.list(input as Parameters<AgentRunSession["artifacts"]["list"]>[0]),
79
+ "artifacts.getVersion": (session, args) =>
80
+ session.artifacts.getVersion(
81
+ ...(args as Parameters<AgentRunSession["artifacts"]["getVersion"]>)
82
+ ),
83
+ "artifacts.listVersions": (session, args) =>
84
+ session.artifacts.listVersions(
85
+ ...(args as Parameters<AgentRunSession["artifacts"]["listVersions"]>)
86
+ ),
87
+ "artifacts.query": (session, args) =>
88
+ session.artifacts.query(...(args as Parameters<AgentRunSession["artifacts"]["query"]>)),
89
+ "artifacts.updatable": (session, [artifactId]) =>
90
+ session.artifacts.updatable(artifactId as string),
91
+ "artifacts.publish": (session, [input]) =>
92
+ session.artifacts.publish(input as Parameters<AgentRunSession["artifacts"]["publish"]>[0]),
93
+ callTool: (session, [call, options], signal) =>
94
+ session.callTool(call as Parameters<AgentRunSession["callTool"]>[0], {
95
+ ...((options ?? {}) as { maxFileBytes?: number }),
96
+ signal,
97
+ }),
98
+ "models.describe": async (session, [ref]) => {
99
+ const model = await session.models.language(
100
+ ref as Parameters<AgentRunSession["models"]["language"]>[0]
101
+ )
102
+ const { providerId, modelId, definition, rateCard, defaultReasoning, maxOutputTokens } = model
103
+ return { providerId, modelId, definition, rateCard, defaultReasoning, maxOutputTokens }
104
+ },
105
+ "files.stat": (session, [blobId]) => session.files.stat(blobId as string),
106
+ }
107
+
108
+ /**
109
+ * Answer a request a runner sends its run's session. Returns null for a path that is none of the
110
+ * session's, for the host to route as it would.
111
+ */
112
+ export async function serveAgentRunSession(
113
+ host: AgentRunSessionHost,
114
+ request: Request
115
+ ): Promise<Response | null> {
116
+ const target = parseAgentRunSessionPath(new URL(request.url).pathname)
117
+ if (!target) return null
118
+
119
+ const admitted = await admitRunner(host, request, target.runId)
120
+ if (admitted instanceof Response) return admitted
121
+ if (!(await stopRecorded(host, admitted))) {
122
+ return serveOperation(host, admitted, target.operation, request)
123
+ }
124
+
125
+ // Once a Stop is recorded, its runner only ends the run, keeping what it wrote: nothing more
126
+ // runs, writes or bills. Its lease is not renewed either, so the sweep ends a runner that ignores
127
+ // the Stop. Every answer says so, for the runner to stop at once.
128
+ let response: Response
129
+ if (target.operation === "renewLease") {
130
+ response = json({ result: { cancelled: true } })
131
+ } else if (STOPPING_OPERATIONS.has(target.operation)) {
132
+ response = await serveOperation(host, admitted, target.operation, request)
133
+ } else {
134
+ response = stopped(admitted)
135
+ }
136
+ response.headers.set(AGENT_RUN_STOPPED_HEADER, "true")
137
+ return response
138
+ }
139
+
140
+ /**
141
+ * What a stopped run's runner still needs besides `renewLease`: the reads between a model step and
142
+ * its end, which decide whether it pauses and wait for its children, then the end itself.
143
+ */
144
+ const STOPPING_OPERATIONS = new Set([
145
+ "heldCalls.holdsRun",
146
+ "heldCalls.pausesAfterStep",
147
+ "children.getMany",
148
+ "children.activeCount",
149
+ "finish",
150
+ ])
151
+
152
+ /** One operation of the run's session, in a session opened for it. */
153
+ async function serveOperation(
154
+ host: AgentRunSessionHost,
155
+ admitted: AgentRunRecord,
156
+ operation: string,
157
+ request: Request
158
+ ): Promise<Response> {
159
+ // A child's session hears its parent's cancel too, as the runner's own claim does.
160
+ const session = await openAgentRunSession(
161
+ host,
162
+ admitted,
163
+ admitted.kind === "subagent" ? [admitted.parentRunId] : []
164
+ )
165
+ let streaming = false
166
+ try {
167
+ if (operation === "models.stream") {
168
+ streaming = true
169
+ return await streamModelCall(session, request)
170
+ }
171
+ if (operation === "events") return await publishEvents(session, request)
172
+ if (operation === "files.put") return await putFile(session, request)
173
+ if (operation === "files.open") return await openFile(session, request)
174
+ if (operation === "children.claim") return await claimChild(host, session, request)
175
+
176
+ const run = OPERATIONS[operation]
177
+ if (!run || request.method !== "POST") {
178
+ return json(
179
+ { error: { kind: "Error", message: `[Sixb] No session operation '${operation}'.` } },
180
+ 404
181
+ )
182
+ }
183
+ const { args } = decodeWireValue(await request.text()) as { args?: readonly unknown[] }
184
+ return json({ result: await run(session, args ?? [], request.signal) })
185
+ } catch (error) {
186
+ const wire = encodeWireError(error)
187
+ return json({ error: wire }, wireErrorStatus(wire))
188
+ } finally {
189
+ if (!streaming) await session.close()
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Claim a queued run for a runner that reaches it over HTTP: the caller decides who may. Returns
195
+ * the claimed run and the runner token its runner sends with every session request, or null when
196
+ * the run ended or another runner holds it. The run token its commands get comes from the run's
197
+ * execution token, as the worker's does.
198
+ *
199
+ * A running run is never taken over: it already streamed and billed what it did. Once its lease
200
+ * lapsed, it ends interrupted here, as the lapsed-run sweep would end it, and the claim is refused.
201
+ */
202
+ export async function claimAgentRunForRunner(
203
+ host: AgentRunSessionHost,
204
+ input: { readonly run: AgentRunRecord; readonly leaseExpiresAt: string }
205
+ ): Promise<{ readonly run: AgentRunRecord; readonly runnerToken: string } | null> {
206
+ if (input.run.status === "running") {
207
+ const ended =
208
+ agentRunLeaseLapsed(input.run) &&
209
+ (await endInterruptedAgentRun(host, input.run, MAX_RUNNER_LEASE_MS))
210
+ if (!ended) return null
211
+
212
+ throw new AgentRunRefusedError(
213
+ input.run.kind === "subagent"
214
+ ? "[Sixb] This child stopped when its runner did; spawn it again with a new key."
215
+ : "[Sixb] This turn stopped when its runner did; send your message again."
216
+ )
217
+ }
218
+
219
+ const session = await claimAgentRun(host, {
220
+ run: input.run,
221
+ leaseExpiresAt: capLease(input.leaseExpiresAt),
222
+ ...(input.run.kind === "subagent" ? { cancelWith: [input.run.parentRunId] } : {}),
223
+ })
224
+ if (!session) return null
225
+ await session.close()
226
+ return {
227
+ run: session.run,
228
+ runnerToken: createAgentRunnerToken({
229
+ projectId: host.projectId,
230
+ runId: session.run.id,
231
+ executionToken: session.executionToken,
232
+ }),
233
+ }
234
+ }
235
+
236
+ /**
237
+ * The furthest ahead a runner over HTTP holds its run: it renews well before, and one that stops
238
+ * renewing lets the run go within this, for the repair pass to end it.
239
+ */
240
+ const MAX_RUNNER_LEASE_MS = 2 * 60_000
241
+
242
+ function capLease(leaseExpiresAt: string): string {
243
+ const latest = Date.now() + MAX_RUNNER_LEASE_MS
244
+ const requested = new Date(leaseExpiresAt).getTime()
245
+ return new Date(Number.isFinite(requested) ? Math.min(requested, latest) : latest).toISOString()
246
+ }
247
+
248
+ /**
249
+ * A runner runs its turn's children itself, so it claims them with the turn's runner token: only a
250
+ * child of that turn, which the turn spawned.
251
+ */
252
+ async function claimChild(
253
+ host: AgentRunSessionHost,
254
+ session: AgentRunSession,
255
+ request: Request
256
+ ): Promise<Response> {
257
+ const { args } = decodeWireValue(await request.text()) as { args?: readonly unknown[] }
258
+ const [childRunId, leaseExpiresAt] = (args ?? []) as [string, string]
259
+ const child = await session.children.get(childRunId)
260
+ if (child?.kind !== "subagent" || child.parentRunId !== session.run.id) {
261
+ const wire = encodeWireError(
262
+ new AgentRunRefusedError(
263
+ `[Sixb] Agent run '${session.run.id}' claims only its own children, not '${childRunId}'.`
264
+ )
265
+ )
266
+ return json({ error: wire }, wireErrorStatus(wire))
267
+ }
268
+ return json({ result: await claimAgentRunForRunner(host, { run: child, leaseExpiresAt }) })
269
+ }
270
+
271
+ /**
272
+ * The run a request's runner token holds now: the run it names, still running under that
273
+ * execution. A run token is refused: it is what the run's own commands hold.
274
+ */
275
+ async function admitRunner(
276
+ host: AgentRunSessionHost,
277
+ request: Request,
278
+ runId: string
279
+ ): Promise<AgentRunRecord | Response> {
280
+ const token = request.headers.get("authorization")?.match(/^Bearer\s+(\S+)$/i)?.[1]
281
+ if (!token || agentRunnerTokenRunId(token) !== runId) {
282
+ return json(
283
+ {
284
+ error: {
285
+ kind: "Error",
286
+ message: "[Sixb] A run's session takes the runner token its claim returned.",
287
+ },
288
+ },
289
+ 401
290
+ )
291
+ }
292
+ const run = await host.storage.agents.runs.getById({ projectId: host.projectId, id: runId })
293
+ const executionToken = run?.execution?.token
294
+ if (
295
+ !run ||
296
+ run.status !== "running" ||
297
+ !executionToken ||
298
+ !isValidAgentRunnerToken({ projectId: host.projectId, runId, executionToken, token })
299
+ ) {
300
+ // Its execution ended or moved to another runner: what the runner reads as lost ownership.
301
+ const wire = encodeWireError(new AgentExecutionLostError(runId))
302
+ return json({ error: wire }, wireErrorStatus(wire))
303
+ }
304
+ return run
305
+ }
306
+
307
+ /** Whether a Stop is recorded on the run, or on the turn a child stops with. */
308
+ async function stopRecorded(host: AgentRunSessionHost, run: AgentRunRecord): Promise<boolean> {
309
+ if (run.cancelRequestedAt) return true
310
+ if (run.kind !== "subagent") return false
311
+
312
+ const parent = await host.storage.agents.runs.getById({
313
+ projectId: host.projectId,
314
+ id: run.parentRunId,
315
+ })
316
+ return Boolean(parent?.cancelRequestedAt)
317
+ }
318
+
319
+ /**
320
+ * What a stopped run's runner hears for anything else: the aborted call a stopped run's session
321
+ * gives in process, which a runner already reads as the run stopping.
322
+ */
323
+ function stopped(run: AgentRunRecord): Response {
324
+ const wire = {
325
+ kind: "AbortError",
326
+ message: `[Sixb] Agent run '${run.id}' was stopped: its runner only finishes it now.`,
327
+ }
328
+ return json({ error: wire }, wireErrorStatus(wire))
329
+ }
330
+
331
+ /**
332
+ * Renew the lease, and say whether the run should stop: a cancel recorded on it, or on the run it
333
+ * stops with, since its request was admitted. One recorded before never renews it.
334
+ */
335
+ async function renew(
336
+ session: AgentRunSession,
337
+ leaseExpiresAt: string
338
+ ): Promise<{ readonly cancelled: boolean }> {
339
+ await session.renewLease(leaseExpiresAt)
340
+ return { cancelled: session.cancelled.aborted }
341
+ }
342
+
343
+ /**
344
+ * End the run, and say so live: once it ended, its runner token no longer reaches its session,
345
+ * so the server that recorded the end announces it, its answer first.
346
+ */
347
+ async function finish(
348
+ session: AgentRunSession,
349
+ outcome: Parameters<AgentRunSession["finish"]>[0],
350
+ messages: Parameters<AgentRunSession["finish"]>[1]
351
+ ): Promise<AgentRunRecord> {
352
+ const finished = await session.finish(outcome, messages)
353
+ const answer = [...(messages ?? [])].reverse().find((message) => message.role === "assistant")
354
+ if (finished.kind === "conversation" && answer) {
355
+ await session.events.publishMessageFinalized({ run: finished, messageId: answer.id })
356
+ }
357
+ await session.events.publishRunFinished(finished)
358
+ return finished
359
+ }
360
+
361
+ /**
362
+ * A runner's work, as its run's: in its run's thread, and authored by no one. Turns and children
363
+ * never name an author: only a workflow step, which runs in the cloud, writes as its agent.
364
+ */
365
+ function ownMessages(
366
+ run: AgentRunRecord,
367
+ messages: Parameters<AgentRunSession["finish"]>[1]
368
+ ): Parameters<AgentRunSession["finish"]>[1] {
369
+ return messages?.map(({ authorPrincipal: _author, ...message }) => ({
370
+ ...message,
371
+ projectId: run.projectId,
372
+ threadId: run.threadId,
373
+ runId: run.id,
374
+ }))
375
+ }
376
+
377
+ /** One model call, its events streamed back as lines of JSON as the provider sends them. */
378
+ async function streamModelCall(session: AgentRunSession, request: Request): Promise<Response> {
379
+ const { ref, call } = decodeWireValue(await request.text()) as {
380
+ ref: Parameters<AgentRunSession["models"]["language"]>[0]
381
+ call: Omit<LanguageModelRequest, "signal">
382
+ }
383
+ const model = await session.models.language(ref)
384
+ const opened = await model.stream({ ...call, signal: request.signal })
385
+ const encoder = new TextEncoder()
386
+ const iterator = opened.events[Symbol.asyncIterator]()
387
+ const body = new ReadableStream<Uint8Array>({
388
+ async pull(controller) {
389
+ try {
390
+ const next = await iterator.next()
391
+ if (next.done) {
392
+ controller.close()
393
+ await session.close()
394
+ return
395
+ }
396
+ controller.enqueue(encoder.encode(`${encodeWireValue({ event: next.value })}\n`))
397
+ } catch (error) {
398
+ controller.enqueue(
399
+ encoder.encode(`${encodeWireValue({ error: encodeWireError(error) })}\n`)
400
+ )
401
+ controller.close()
402
+ await session.close()
403
+ }
404
+ },
405
+ async cancel() {
406
+ // The runner let the call go: the model reports it, unfinished.
407
+ await iterator.return?.()
408
+ await session.close()
409
+ },
410
+ })
411
+ return new Response(body, { headers: { "content-type": "application/x-ndjson" } })
412
+ }
413
+
414
+ /** Live records, in the order the runner sent them. Best effort, as in process. */
415
+ async function publishEvents(session: AgentRunSession, request: Request): Promise<Response> {
416
+ const { events } = decodeWireValue(await request.text()) as {
417
+ events: readonly { readonly method: string; readonly input: unknown }[]
418
+ }
419
+ const sink = session.events as unknown as Record<string, (input: unknown) => Promise<void>>
420
+ for (const { method, input } of events) {
421
+ if (!EVENT_METHODS.has(method)) continue
422
+ // A record about another run is not this runner's to publish.
423
+ if (!aboutRun(session.run, method, input)) continue
424
+ await sink[method]?.(input)
425
+ }
426
+ return json({ result: null })
427
+ }
428
+
429
+ const EVENT_METHODS = new Set([
430
+ "publishStarted",
431
+ "publishCompactionStarted",
432
+ "publishCompactionCompleted",
433
+ "publishCompactionFailed",
434
+ "publishUiChunk",
435
+ "publishMessageFinalized",
436
+ "publishRunFinished",
437
+ ])
438
+
439
+ function aboutRun(run: AgentRunRecord, method: string, input: unknown): boolean {
440
+ const named =
441
+ method === "publishStarted" || method === "publishRunFinished"
442
+ ? (input as AgentRunRecord | undefined)
443
+ : (input as { readonly run?: AgentRunRecord } | undefined)?.run
444
+ return named?.id === run.id
445
+ }
446
+
447
+ async function putFile(session: AgentRunSession, request: Request): Promise<Response> {
448
+ const url = new URL(request.url)
449
+ const size = url.searchParams.get("size")
450
+ const fileRef = await session.files.put({
451
+ body: new Uint8Array(await request.arrayBuffer()),
452
+ ...(size === null ? {} : { expectedSizeBytes: Number(size) }),
453
+ ...optionalParam(url, "fileName"),
454
+ ...optionalParam(url, "mediaType"),
455
+ ...optionalParam(url, "logicalPath"),
456
+ signal: request.signal,
457
+ })
458
+ return json({ result: fileRef })
459
+ }
460
+
461
+ /** A file's bytes. Its id is its content's digest: a runner names only files it read of. */
462
+ async function openFile(session: AgentRunSession, request: Request): Promise<Response> {
463
+ const blobId = new URL(request.url).searchParams.get("blobId") ?? ""
464
+ return new Response(await session.files.open(blobId), {
465
+ headers: { "content-type": "application/octet-stream" },
466
+ })
467
+ }
468
+
469
+ function optionalParam(url: URL, name: string): Record<string, string> {
470
+ const value = url.searchParams.get(name)
471
+ return value === null ? {} : { [name]: value }
472
+ }
473
+
474
+ function json(body: unknown, status = 200): Response {
475
+ return new Response(encodeWireValue(body), {
476
+ status,
477
+ headers: { "content-type": "application/json" },
478
+ })
479
+ }
@@ -0,0 +1,189 @@
1
+ import { ArtifactRequestError } from "../artifacts/errors"
2
+ import { createSixbError, isSixbError } from "../errors/internal"
3
+ import { ModelUsageRecordingError } from "../models/execution/errors"
4
+ import { AgentStorageError } from "../storage/agents/errors"
5
+ import { AgentToolPublicError, AgentToolResultValidationError } from "./errors"
6
+ import { AgentExecutionLostError, AgentRunRefusedError } from "./run-fence"
7
+ import { AgentFinalizationError } from "./run-session"
8
+
9
+ // How a run session crosses HTTP: one route per operation, under the run's path, each request a
10
+ // JSON body and each answer a JSON body. Records carry dates, model messages carry bytes and some
11
+ // answers are maps, so values are tagged JSON. Errors cross as their kind, so the runner throws
12
+ // the same classes it would in process.
13
+
14
+ /** Set on every answer of a run's session once a Stop is recorded on the run. */
15
+ export const AGENT_RUN_STOPPED_HEADER = "x-sixb-agent-run-stopped"
16
+
17
+ /** Where a runner reaches its run's session. */
18
+ export function agentRunSessionPath(runId: string, operation: string): string {
19
+ return `/api/agent-runs/${encodeURIComponent(runId)}/session/${operation}`
20
+ }
21
+
22
+ /** The run and operation a session request names, or null for a path that is not one. */
23
+ export function parseAgentRunSessionPath(
24
+ pathname: string
25
+ ): { readonly runId: string; readonly operation: string } | null {
26
+ const match = /^\/api\/agent-runs\/([^/]+)\/session\/(.+)$/.exec(pathname)
27
+ if (!match?.[1] || !match[2]) return null
28
+ return { runId: decodeURIComponent(match[1]), operation: match[2] }
29
+ }
30
+
31
+ const TAG = "$sixb"
32
+
33
+ /** JSON that keeps dates, bytes and maps. */
34
+ export function encodeWireValue(value: unknown): string {
35
+ return JSON.stringify(value, function (key, current: unknown) {
36
+ // `toJSON` already turned a date into a string: read it from the holder.
37
+ const raw: unknown = (this as Record<string, unknown>)[key]
38
+ if (raw instanceof Date) return { [TAG]: "date", value: raw.toISOString() }
39
+ if (raw instanceof Uint8Array) {
40
+ return { [TAG]: "bytes", value: Buffer.from(raw).toString("base64") }
41
+ }
42
+ if (raw instanceof Map) return { [TAG]: "map", value: [...raw.entries()] }
43
+ return current
44
+ })
45
+ }
46
+
47
+ export function decodeWireValue(text: string): unknown {
48
+ return JSON.parse(text, (_key, value: unknown) => {
49
+ if (!isTagged(value)) return value
50
+ if (value[TAG] === "date") return new Date(value.value as string)
51
+ if (value[TAG] === "bytes") return new Uint8Array(Buffer.from(value.value as string, "base64"))
52
+ return new Map(value.value as [unknown, unknown][])
53
+ })
54
+ }
55
+
56
+ function isTagged(value: unknown): value is { readonly [TAG]: string; readonly value: unknown } {
57
+ return (
58
+ typeof value === "object" &&
59
+ value !== null &&
60
+ TAG in value &&
61
+ ["date", "bytes", "map"].includes((value as Record<string, unknown>)[TAG] as string)
62
+ )
63
+ }
64
+
65
+ /** An error as it crosses: its kind, and what rebuilding it needs. */
66
+ export interface WireError {
67
+ readonly kind: string
68
+ readonly message: string
69
+ readonly code?: string
70
+ readonly runId?: string
71
+ readonly toolName?: string
72
+ readonly reason?: string
73
+ readonly executionId?: string
74
+ readonly callId?: string
75
+ readonly recoveryScheduled?: boolean
76
+ readonly details?: unknown
77
+ readonly latest?: unknown
78
+ }
79
+
80
+ export function encodeWireError(error: unknown): WireError {
81
+ if (error instanceof AgentExecutionLostError) {
82
+ return { kind: error.name, message: error.message, runId: error.runId }
83
+ }
84
+ if (error instanceof AgentFinalizationError) {
85
+ return { kind: error.name, message: error.message, runId: error.runId }
86
+ }
87
+ if (error instanceof AgentToolResultValidationError) {
88
+ return {
89
+ kind: error.name,
90
+ message: error.message,
91
+ toolName: error.toolName,
92
+ reason: error.reason,
93
+ }
94
+ }
95
+ if (error instanceof AgentRunRefusedError) return { kind: error.name, message: error.message }
96
+ if (error instanceof AgentToolPublicError)
97
+ return { kind: "AgentToolPublicError", message: error.message }
98
+ if (error instanceof ModelUsageRecordingError) {
99
+ return {
100
+ kind: error.name,
101
+ message: error.message,
102
+ executionId: error.executionId,
103
+ callId: error.callId,
104
+ recoveryScheduled: error.recoveryScheduled,
105
+ }
106
+ }
107
+ if (error instanceof ArtifactRequestError) {
108
+ return {
109
+ kind: error.name,
110
+ message: error.message,
111
+ code: error.code,
112
+ ...(error.latest === undefined ? {} : { latest: error.latest }),
113
+ }
114
+ }
115
+ if (error instanceof AgentStorageError) {
116
+ return { kind: error.name, message: error.message, code: error.code }
117
+ }
118
+ if (isSixbError(error)) {
119
+ return {
120
+ kind: "SixbError",
121
+ message: error.message,
122
+ code: error.code,
123
+ ...(error.details === undefined ? {} : { details: error.details }),
124
+ }
125
+ }
126
+ if (error instanceof Error && error.name === "AbortError") {
127
+ return { kind: "AbortError", message: error.message }
128
+ }
129
+ // Anything else stays on the server: the runner learns only that the operation failed.
130
+ console.error("[Sixb] A run session operation failed.", error)
131
+ return { kind: "Error", message: "[Sixb] The run session operation failed on the server." }
132
+ }
133
+
134
+ /** The HTTP status an error answers with. */
135
+ export function wireErrorStatus(error: WireError): number {
136
+ if (error.kind === "AgentExecutionLostError") return 409
137
+ if (error.kind === "AbortError") return 499
138
+ if (error.kind === "Error" || error.kind === "AgentFinalizationError") return 500
139
+ return 400
140
+ }
141
+
142
+ export function decodeWireError(error: WireError): Error {
143
+ switch (error.kind) {
144
+ case "AgentExecutionLostError":
145
+ return new AgentExecutionLostError(error.runId ?? "")
146
+ case "AgentFinalizationError":
147
+ return new AgentFinalizationError(error.runId ?? "")
148
+ case "AgentToolResultValidationError":
149
+ return new AgentToolResultValidationError(error.toolName ?? "", error.reason ?? "")
150
+ case "AgentRunRefusedError":
151
+ return new AgentRunRefusedError(error.message)
152
+ case "AgentToolPublicError":
153
+ case "AgentToolOutputError":
154
+ return new AgentToolPublicError(error.message)
155
+ case "ModelUsageRecordingError":
156
+ return new ModelUsageRecordingError(
157
+ error.executionId ?? "",
158
+ error.callId ?? "",
159
+ error.recoveryScheduled ?? false
160
+ )
161
+ case "ArtifactRequestError":
162
+ return new ArtifactRequestError(
163
+ error.code as ConstructorParameters<typeof ArtifactRequestError>[0],
164
+ error.message,
165
+ error.latest as ConstructorParameters<typeof ArtifactRequestError>[2]
166
+ )
167
+ case "AgentStorageError":
168
+ return new AgentStorageError(
169
+ error.code as ConstructorParameters<typeof AgentStorageError>[0],
170
+ error.message
171
+ )
172
+ case "SixbError":
173
+ return createSixbError(
174
+ error.code as Parameters<typeof createSixbError>[0],
175
+ error.message,
176
+ error.details === undefined
177
+ ? {}
178
+ : {
179
+ details: error.details as NonNullable<
180
+ Parameters<typeof createSixbError>[2]
181
+ >["details"],
182
+ }
183
+ )
184
+ case "AbortError":
185
+ return new DOMException(error.message, "AbortError")
186
+ default:
187
+ return new Error(error.message)
188
+ }
189
+ }