@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,802 @@
1
+ import type { BlobStorage } from "../blob-storage"
2
+ import type { Broker } from "../broker"
3
+ import { createSixbError } from "../errors/internal"
4
+ import type { AuthorizationRef } from "../execution"
5
+ import {
6
+ type AgentExecutionHost,
7
+ bindAgentModelExecution,
8
+ bindDurableAgentExecution,
9
+ } from "../execution/agent"
10
+ import type { RunLogSession } from "../logging/run-logger"
11
+ import { type LoggingService, resolveLoggingService } from "../logging/service"
12
+ import type { LogFields } from "../logging/types"
13
+ import type { LanguageModelRef } from "../models/catalog"
14
+ import {
15
+ AiModelCallRecorder,
16
+ createAiModelCallLimitController,
17
+ type ModelCallAccountingStorage,
18
+ type RecoverAiModelCall,
19
+ } from "../models/execution/index"
20
+ import type { LanguageModel } from "../models/language-model"
21
+ import { resolveLanguageModel } from "../models/resolve"
22
+ import type { Sixb } from "../runtime/sixb"
23
+ import type { SecurityDefinitionCatalog } from "../security"
24
+ import type { Storage } from "../storage"
25
+ import {
26
+ type AgentRunRecord,
27
+ type AgentStorage,
28
+ AgentStorageError,
29
+ type AgentThreadSandboxState,
30
+ type AppendAgentMessageInput,
31
+ type ConversationAgentRunRecord,
32
+ type CreateAgentContextCheckpointInput,
33
+ type FinishAgentRunInput,
34
+ type SubagentRunFile,
35
+ type SubagentRunRecord,
36
+ type TransitionAgentThreadSandboxInput,
37
+ } from "../storage/agents"
38
+ import type { AuthStorage, UserRecord } from "../storage/auth"
39
+ import { turnPausesOnHeldCalls } from "./approvals"
40
+ import {
41
+ type AgentExecutionAuthorization,
42
+ resolveAgentPropertyClearance,
43
+ resolveInheritedAgentExecutionAuthorization,
44
+ userCanRunAgent,
45
+ } from "./authority"
46
+ import { AgentToolPublicError } from "./errors"
47
+ import { createAgentRunExecutionToken } from "./ids"
48
+ import { type AgentRunArtifacts, agentRunArtifacts } from "./run-artifacts"
49
+ import type { StreamSink } from "./run-events"
50
+ import {
51
+ AgentExecutionLostError,
52
+ AgentRunRefusedError,
53
+ assertAgentRunOwned,
54
+ fenced,
55
+ isTerminalOrExecutionGone,
56
+ } from "./run-fence"
57
+ import {
58
+ type AgentRunMemory,
59
+ type AgentRunPlan,
60
+ type AgentRunPlanDefinitions,
61
+ readAgentRunMemory,
62
+ readAgentRunPlan,
63
+ } from "./run-plan"
64
+ import {
65
+ type AgentRunChildren,
66
+ type AgentRunChildrenHost,
67
+ type AgentRunThreads,
68
+ agentRunChildren,
69
+ agentRunScope,
70
+ agentRunThreads,
71
+ } from "./run-session-children"
72
+ import {
73
+ type AgentToolCall,
74
+ type AgentToolCallOptions,
75
+ type AgentToolCallResult,
76
+ handedToolAttachments,
77
+ runAgentTool,
78
+ threadToolAttachments,
79
+ } from "./run-tools"
80
+ import {
81
+ type AgentRunContext,
82
+ type AgentTurnContext,
83
+ type AgentTurnHistory,
84
+ readAgentRunContext,
85
+ readAgentTurnHistory,
86
+ } from "./run-turn"
87
+ import { subscribeAgentRunCancel } from "./streams/protocol"
88
+ import { subagentSandboxFiles } from "./subagent-runs"
89
+ import { conversationThreadId } from "./thread-access"
90
+ import type { AgentToolRunInfo } from "./types"
91
+
92
+ /**
93
+ * A run's session: the one way its runner reads and writes shared state for it. Claiming the run
94
+ * creates it, with a fresh execution token, and every write it makes is fenced by that token: once
95
+ * another delivery reclaims the run, this session's writes fail with
96
+ * {@link AgentExecutionLostError} and the runner stops touching the run.
97
+ *
98
+ * The worker uses an in-process session. A runner elsewhere will reach the same operations over
99
+ * HTTP, so nothing here may assume it shares a process with storage.
100
+ */
101
+ export interface AgentRunSession<TRun extends AgentRunRecord = AgentRunRecord> {
102
+ /** The run as the claim left it: `running`, with this session's execution. */
103
+ readonly run: TRun
104
+ readonly executionToken: string
105
+ /**
106
+ * Aborts once the run, or any run named in `cancelWith`, is cancelled: when the broker's cancel
107
+ * arrives, or at the claim or a lease renewal that reads a cancel recorded on the run. Also aborts,
108
+ * with an {@link AgentExecutionLostError}, once a renewal finds the run ended or taken over.
109
+ */
110
+ readonly cancelled: AbortSignal
111
+ /**
112
+ * The models the run calls. Each call is admitted against the AI limits of whoever the run works
113
+ * for, and records itself before its reader sees it finish (see
114
+ * AiModelCallRecorder.wrapModel): the runner never reports what a call used.
115
+ */
116
+ readonly models: AgentRunModels
117
+ /**
118
+ * Live records for whoever watches the run: its start, chunks, compaction, finalized message and
119
+ * end. Best effort: a record that cannot be delivered never fails the run, whose finish is the
120
+ * durable record.
121
+ */
122
+ readonly events: StreamSink
123
+ /** Approvals that hold the run: they are created by the API its commands call, never here. */
124
+ readonly heldCalls: AgentRunHeldCalls
125
+ /** A conversation turn's children: spawning them, and reading them and their threads. */
126
+ readonly children: AgentRunChildren
127
+ /**
128
+ * Record that the runner still holds the run until `leaseExpiresAt`. A run token fails closed
129
+ * once the last lease recorded lapses, so the session renews it as the queue does. A renewal that
130
+ * reads a recorded cancel aborts `cancelled`.
131
+ */
132
+ renewLease(leaseExpiresAt: string): Promise<void>
133
+ /**
134
+ * End the run, with what it did appended first in the same transaction. Absorbs a transient
135
+ * storage failure with a few short retries; see {@link AgentExecutionLostError} and
136
+ * {@link AgentFinalizationError} for what it throws.
137
+ */
138
+ finish(
139
+ outcome: AgentRunOutcome,
140
+ messages?: readonly AppendAgentMessageInput[]
141
+ ): Promise<AgentRunRecord>
142
+ /**
143
+ * Throws {@link AgentExecutionLostError} unless the run still runs under this session, within
144
+ * its lease. Run it right before a side effect the run must not make once another delivery owns
145
+ * it.
146
+ */
147
+ assertOwned(): Promise<void>
148
+ /**
149
+ * What the run is set up with: its model, the project's instructions, skills and tools, and the
150
+ * ontology docs its requester's view gives.
151
+ */
152
+ plan(): Promise<AgentRunPlan>
153
+ /**
154
+ * The memory its requester reads, now and as of `asOf`: the start of the conversation, or its
155
+ * latest compaction, which the prompt shows.
156
+ */
157
+ memory(input: { readonly asOf: Date }): Promise<AgentRunMemory>
158
+ /**
159
+ * What the run starts from, in one read: a turn's thread, the people it names and its history,
160
+ * or a child's parent, threads and messages.
161
+ */
162
+ context(): Promise<TRun extends ConversationAgentRunRecord ? AgentTurnContext : AgentRunContext>
163
+ /**
164
+ * Summarize the conversation up to a point, and answer its history from the new checkpoint on.
165
+ * Refused with {@link AgentExecutionLostError} once the run is no longer this session's.
166
+ */
167
+ checkpoint(input: AgentRunCheckpoint): Promise<AgentTurnHistory>
168
+ /** A conversation's persistent workspace, as this run holds it. */
169
+ readonly workspace: AgentRunWorkspace
170
+ /** The messages of the run's conversation, its children's threads included. */
171
+ readonly threads: AgentRunThreads
172
+ /**
173
+ * Run one call of a project tool the run offers, as the run (see runAgentTool): with the run's
174
+ * SDK, its attachments and its logger, its model calls billed to the run. The files it puts are
175
+ * stored and returned, for the runner to copy into its sandbox.
176
+ */
177
+ callTool(call: AgentToolCall, options: AgentToolCallOptions): Promise<AgentToolCallResult>
178
+ /** Its conversation's artifacts: what it reads of them as its requester, and what it publishes. */
179
+ readonly artifacts: AgentRunArtifacts
180
+ /**
181
+ * The files it stores and reads: its attachments, what its tools and children write, its
182
+ * artifacts' files. Through the run's SDK, as an API request with the run's token stores them.
183
+ */
184
+ readonly files: AgentRunFileStore
185
+ /**
186
+ * The authority the run's execution carries now: its requester's groups, as they are today. A
187
+ * runner that binds the project in its own process needs it; a runner over HTTP never holds it.
188
+ */
189
+ authorization(ref: AuthorizationRef): Promise<AgentExecutionAuthorization>
190
+ /**
191
+ * Stop watching for cancellation, stop its tools' model calls, and flush their logs. The run
192
+ * itself is unaffected.
193
+ */
194
+ close(): Promise<void>
195
+ }
196
+
197
+ /** The models a run calls, by the ref its plan names. */
198
+ export interface AgentRunModels {
199
+ /** A language model of the project, resolved once for the session. */
200
+ language(ref: LanguageModelRef): Promise<LanguageModel>
201
+ }
202
+
203
+ /** Where a run's files are stored: put one, open or stat one by its blob id. */
204
+ export type AgentRunFileStore = Pick<BlobStorage, "put" | "open" | "stat">
205
+
206
+ /** A context checkpoint a turn writes; the session adds which run, and its token. */
207
+ export type AgentRunCheckpoint = Omit<
208
+ CreateAgentContextCheckpointInput,
209
+ "projectId" | "createdByRunId" | "executionToken"
210
+ >
211
+
212
+ /** The project's members as a workflow step needs them, and the authority its execution carries. */
213
+ export interface AgentRunPeople {
214
+ /** A member: a message's author, or whoever the run works for. */
215
+ user(userId: string): Promise<UserRecord | null>
216
+ /** Whether a member may run the Agent now: a shared conversation's readers are those who may. */
217
+ canRunAgent(userId: string): Promise<boolean>
218
+ /** The authority a run's execution carries now: its requester's groups, as they are today. */
219
+ authorization(ref: AuthorizationRef): Promise<AgentExecutionAuthorization>
220
+ }
221
+
222
+ /** A thread's persistent workspace state, moved only by the run that holds the thread. */
223
+ export interface AgentRunWorkspace {
224
+ /** Acquire, replace or settle the thread's workspace; refused once the run lost its execution. */
225
+ transition(input: AgentRunWorkspaceTransition): Promise<AgentThreadSandboxState>
226
+ }
227
+
228
+ /** A workspace transition a run makes; the session adds which run, and its token. */
229
+ export type AgentRunWorkspaceTransition = TransitionAgentThreadSandboxInput extends infer T
230
+ ? T extends { readonly runId: string }
231
+ ? Omit<T, "projectId" | "runId" | "executionToken">
232
+ : never
233
+ : never
234
+
235
+ export interface AgentRunHeldCalls {
236
+ /** Whether a call of this run, or of one of its children, waits for an approval. */
237
+ holdsRun(): Promise<boolean>
238
+ /**
239
+ * Whether a conversation turn pauses after the step it just took: a call of its own is held, or
240
+ * a child's is and no child is still at work.
241
+ */
242
+ pausesAfterStep(): Promise<boolean>
243
+ }
244
+
245
+ /** How a run ended; the session supplies which run, and its token. */
246
+ export type AgentRunOutcome = FinishAgentRunInput extends infer Finish
247
+ ? Finish extends FinishAgentRunInput
248
+ ? Omit<Finish, "projectId" | "id" | "executionToken">
249
+ : never
250
+ : never
251
+
252
+ /** What an in-process session works against. */
253
+ export interface AgentRunSessionHost extends AgentRunChildrenHost {
254
+ readonly projectId: string
255
+ readonly storage: Storage & {
256
+ readonly agents: AgentStorage
257
+ readonly auth: AuthStorage
258
+ } & ModelCallAccountingStorage
259
+ readonly broker: Broker
260
+ /** Queues a model call's record when storage cannot take it while the run goes on. */
261
+ readonly recoverAiModelCall: RecoverAiModelCall
262
+ /** Where live records go; the host keeps them best effort (see isolateStreamSink). */
263
+ readonly events: StreamSink
264
+ /** The project's security definitions, which decide a run's authority. */
265
+ readonly security: SecurityDefinitionCatalog
266
+ /** Where a project tool's logs go; the project's logging service when absent. */
267
+ readonly logging?: LoggingService
268
+ /**
269
+ * Binds the run's SDK as its requester, as the API binds a request with the run's token: what
270
+ * the run reads and publishes through its session goes through it.
271
+ */
272
+ readonly sdk: AgentExecutionHost
273
+ /** The definitions a run's plan is read from. */
274
+ readonly definitions: AgentRunPlanDefinitions
275
+ /**
276
+ * What follows a run's end, once `finish` recorded it: a turn's children still at work are
277
+ * stopped, and a turn paused on calls already decided goes on. Best effort: a failure is logged,
278
+ * and the host's repair passes catch up.
279
+ */
280
+ readonly afterFinish?: (run: AgentRunRecord) => Promise<void>
281
+ }
282
+
283
+ export interface ClaimAgentRunInput<TRun extends AgentRunRecord> {
284
+ /** A queued run, or a running one whose last delivery's lease lapsed. */
285
+ readonly run: TRun
286
+ readonly modelId?: string
287
+ /** When the queue delivery that claims the run expires unless renewed. */
288
+ readonly leaseExpiresAt: string
289
+ /** Other runs whose cancellation cancels this one: a child's parent. */
290
+ readonly cancelWith?: readonly string[]
291
+ /**
292
+ * The runner's own stop: its process shutting down, or its delivery lost. The calls its project
293
+ * tools make stop with it, as the run's own do.
294
+ */
295
+ readonly stop?: AbortSignal
296
+ }
297
+
298
+ /**
299
+ * Start a queued run, or reclaim a running one, and open its session. Returns null when the run
300
+ * ended meanwhile, so there is nothing to claim.
301
+ */
302
+ export async function claimAgentRun<TRun extends AgentRunRecord>(
303
+ host: AgentRunSessionHost,
304
+ input: ClaimAgentRunInput<TRun>
305
+ ): Promise<AgentRunSession<TRun> | null> {
306
+ const run = await startOrReclaim(host.storage.agents, host.projectId, input)
307
+ if (!run) return null
308
+ return openAgentRunSession(host, run, input.cancelWith, input.stop)
309
+ }
310
+
311
+ /**
312
+ * The session of a run already claimed: the one its execution token names. A server answering a
313
+ * remote runner opens it per request; the worker opens it once, when it claims the run.
314
+ */
315
+ export async function openAgentRunSession<TRun extends AgentRunRecord>(
316
+ host: AgentRunSessionHost,
317
+ run: TRun,
318
+ cancelWith: readonly string[] = [],
319
+ stop?: AbortSignal
320
+ ): Promise<AgentRunSession<TRun>> {
321
+ const executionToken = run.execution?.token
322
+ if (!executionToken) {
323
+ throw new Error(`[Sixb] Agent run '${run.id}' has no execution token, so it was never claimed.`)
324
+ }
325
+
326
+ let modelCalls: Promise<AiModelCallRecorder> | undefined
327
+ const openedModelCalls = () => {
328
+ modelCalls ??= openModelCalls(host, run).catch((error: unknown) => {
329
+ modelCalls = undefined
330
+ throw error
331
+ })
332
+ return modelCalls
333
+ }
334
+ // Each model is pinned once per session: a later catalog refresh does not change a run's model.
335
+ const languageModels = new Map<string, Promise<LanguageModel>>()
336
+ let bound: Promise<BoundRun> | undefined
337
+ const bind = () => {
338
+ bound ??= bindRun(host, run).catch((error: unknown) => {
339
+ bound = undefined
340
+ throw error
341
+ })
342
+ return bound
343
+ }
344
+ const runSdk = async () => (await bind()).sixb
345
+ const cancel = await watchAgentRunCancel(host, [run.id, ...cancelWith])
346
+ // A cancel recorded on the run reaches a runner the broker's cancel did not: at the claim, and at
347
+ // each renewal of its lease.
348
+ const recordedCancel = new AbortController()
349
+ const readCancel = (current: AgentRunRecord) => {
350
+ if (current.cancelRequestedAt) recordedCancel.abort()
351
+ }
352
+ readCancel(run)
353
+ const cancelled = AbortSignal.any([cancel.signal, recordedCancel.signal])
354
+ const scope = agentRunScope(host, run)
355
+ const threads = agentRunThreads(host, run, scope)
356
+ const files: AgentRunFileStore = {
357
+ put: async (input) => (await runSdk()).blobs.put(input),
358
+ open: async (blobId) => (await runSdk()).blobs.open(blobId),
359
+ stat: async (blobId) => (await runSdk()).blobs.stat(blobId),
360
+ }
361
+ // Ends with the session: a tool call that outlived its run stops calling models.
362
+ const ended = new AbortController()
363
+ let toolsBound: Promise<Sixb> | undefined
364
+ // A project tool's own model calls bill to the run, admitted and recorded with its own.
365
+ const toolSdk = () => {
366
+ toolsBound ??= (async () => {
367
+ const sixb = await runSdk()
368
+ bindAgentModelExecution(sixb, {
369
+ signal: AbortSignal.any([cancelled, ended.signal, ...(stop ? [stop] : [])]),
370
+ accounting: await openedModelCalls(),
371
+ })
372
+ return sixb
373
+ })().catch((error: unknown) => {
374
+ toolsBound = undefined
375
+ throw error
376
+ })
377
+ return toolsBound
378
+ }
379
+ let logs: RunLogSession | undefined
380
+ // Labeled with the conversation its run works in: a child's is its parent's.
381
+ let toolLabels: Promise<LogFields> | undefined
382
+ const toolLogger = async () => {
383
+ toolLabels ??= (async (): Promise<LogFields> => {
384
+ if (run.kind !== "subagent") return { threadId: run.threadId }
385
+ const thread = await host.storage.agents.threads.getById({
386
+ projectId: host.projectId,
387
+ id: run.threadId,
388
+ })
389
+ return {
390
+ parentRunId: run.parentRunId,
391
+ threadId: thread ? conversationThreadId(thread) : run.threadId,
392
+ }
393
+ })().catch((error: unknown) => {
394
+ toolLabels = undefined
395
+ throw error
396
+ })
397
+ const labels = await toolLabels
398
+ logs ??= resolveLoggingService(host.projectId, host.logging).startExecution({
399
+ kind: "agent",
400
+ id: run.id,
401
+ })
402
+ return logs.logger.child(labels)
403
+ }
404
+ const fence = { projectId: host.projectId, id: run.id, executionToken }
405
+ const agents = host.storage.agents
406
+ // What a child's sandbox holds: what it was handed, and what a paused run it continues left in
407
+ // out/. Its tools open those, by the paths $SIXB_ATTACHMENTS lists.
408
+ let handed: Promise<readonly SubagentRunFile[]> | undefined
409
+ const childFiles = (child: SubagentRunRecord) => {
410
+ handed ??= readAgentRunContext(host, child)
411
+ .then((context) =>
412
+ subagentSandboxFiles(child, context.kind === "subagent" ? context.paused : undefined)
413
+ )
414
+ .catch((error: unknown) => {
415
+ handed = undefined
416
+ throw error
417
+ })
418
+ return handed
419
+ }
420
+
421
+ return {
422
+ run,
423
+ executionToken,
424
+ cancelled,
425
+ events: host.events,
426
+ children: agentRunChildren(host, run, executionToken, scope, () => ({
427
+ tools: host.definitions.tools.list().map((tool) => tool.name),
428
+ models: host.definitions.models?.language?.list() ?? [],
429
+ })),
430
+ heldCalls: {
431
+ holdsRun: () =>
432
+ host.storage.agents.approvals.holdsRun({ projectId: host.projectId, runId: run.id }),
433
+ pausesAfterStep: () => turnPausesOnHeldCalls(host.storage.agents, run),
434
+ },
435
+ models: {
436
+ async language(ref) {
437
+ const key = `${ref.provider}/${ref.modelId}`
438
+ let resolved = languageModels.get(key)
439
+ if (!resolved) {
440
+ const entry = host.definitions.models?.language?.getByRef(ref)
441
+ if (!entry) {
442
+ throw createSixbError(
443
+ "agent.execution_failed",
444
+ `[Sixb] Language model '${key}' is not available in models.language.`
445
+ )
446
+ }
447
+ resolved = resolveLanguageModel(entry.model)
448
+ languageModels.set(key, resolved)
449
+ resolved.catch(() => languageModels.delete(key))
450
+ }
451
+ return (await openedModelCalls()).wrapModel(await resolved)
452
+ },
453
+ },
454
+ async renewLease(leaseExpiresAt) {
455
+ try {
456
+ readCancel(
457
+ await fenced(
458
+ run.id,
459
+ () =>
460
+ host.storage.agents.runs.confirmExecutionOwnership({
461
+ ...fence,
462
+ queueLeaseExpiresAt: new Date(leaseExpiresAt),
463
+ }),
464
+ { ended: true }
465
+ )
466
+ )
467
+ // A child stops with its parent: a cancel recorded on it too.
468
+ if (cancelWith.length > 0) {
469
+ const others = await agents.runs.getByIds({ projectId: host.projectId, ids: cancelWith })
470
+ for (const other of others) readCancel(other)
471
+ }
472
+ } catch (error) {
473
+ // A repair pass ended the run, or another runner took it over: this one stops now rather
474
+ // than at its next write, as it does when its queue lease is lost.
475
+ if (error instanceof AgentExecutionLostError) cancel.abort(error)
476
+ throw error
477
+ }
478
+ },
479
+ async finish(outcome, messages) {
480
+ const finished = await finishWithRetries(
481
+ host.storage,
482
+ { ...outcome, ...fence },
483
+ messages ?? []
484
+ )
485
+ await host.afterFinish?.(finished).catch((error: unknown) => {
486
+ console.error(`[Sixb] What follows agent run '${run.id}' failed; repair retries it.`, error)
487
+ })
488
+ return finished
489
+ },
490
+ assertOwned: () => assertAgentRunOwned(agents, fence),
491
+ threads,
492
+ artifacts: agentRunArtifacts(host, run, executionToken, runSdk),
493
+ files,
494
+ async callTool(call, { signal, maxFileBytes }) {
495
+ // Only a tool the run offers: a child's are the ones its parent chose.
496
+ const offered = run.kind === "subagent" ? run.spec.toolNames : undefined
497
+ const definition =
498
+ offered === undefined || offered.includes(call.toolName)
499
+ ? host.definitions.tools.getByName(call.toolName)
500
+ : null
501
+ if (!definition) {
502
+ throw new AgentToolPublicError(`[Sixb] Tool '${call.toolName}' is not available.`)
503
+ }
504
+ // A tool acts on the project: only for the runner that still holds the run.
505
+ await assertAgentRunOwned(agents, fence)
506
+ return runAgentTool({
507
+ definition,
508
+ valueTypesById: host.definitions.ontology.getValueTypesById(),
509
+ call,
510
+ signal,
511
+ run: toolRunInfo(run),
512
+ sixb: await toolSdk(),
513
+ logger: await toolLogger(),
514
+ attachments:
515
+ run.kind === "subagent"
516
+ ? handedToolAttachments({ files: await childFiles(run), store: files })
517
+ : threadToolAttachments({
518
+ threadId: run.threadId,
519
+ message: (messageId) => threads.message(messageId),
520
+ files,
521
+ }),
522
+ files,
523
+ ...(maxFileBytes === undefined ? {} : { maxFileBytes }),
524
+ })
525
+ },
526
+ authorization: (ref) =>
527
+ resolveInheritedAgentExecutionAuthorization({
528
+ auth: host.storage.auth,
529
+ projectId: host.projectId,
530
+ authorizationRef: ref,
531
+ security: host.security,
532
+ }),
533
+ async plan() {
534
+ const { sixb, authorization } = await bind()
535
+ const propertyClearance = resolveAgentPropertyClearance(
536
+ host.definitions.ontology,
537
+ authorization
538
+ )
539
+ return readAgentRunPlan(host.definitions, run, {
540
+ sixb,
541
+ ...(propertyClearance === undefined ? {} : { propertyClearance }),
542
+ })
543
+ },
544
+ async memory({ asOf }) {
545
+ // Others read a shared conversation, so its runs reach no one's own memory.
546
+ const participants =
547
+ run.kind === "conversation"
548
+ ? await agents.threads.listParticipants({
549
+ projectId: host.projectId,
550
+ threadIds: [run.threadId],
551
+ })
552
+ : []
553
+ return readAgentRunMemory(await runSdk(), { shared: participants.length > 0, asOf })
554
+ },
555
+ context: async () => {
556
+ const context = await readAgentRunContext(host, run)
557
+ if (run.kind === "conversation" && context.kind !== "conversation") {
558
+ throw new Error(`[Sixb] Agent run '${run.id}' changed kind.`)
559
+ }
560
+ return context as Awaited<ReturnType<AgentRunSession<TRun>["context"]>>
561
+ },
562
+ async checkpoint(input) {
563
+ await fenced(run.id, () =>
564
+ agents.checkpoints.create({
565
+ ...input,
566
+ projectId: host.projectId,
567
+ createdByRunId: run.id,
568
+ executionToken,
569
+ })
570
+ )
571
+ return readAgentTurnHistory(host, input.threadId)
572
+ },
573
+ workspace: {
574
+ async transition(input) {
575
+ // A run moves its own thread's workspace, never another's.
576
+ if (input.id !== run.threadId) {
577
+ throw new AgentRunRefusedError(
578
+ `[Sixb] Agent run '${run.id}' moves only its own thread's workspace, not '${input.id}'.`
579
+ )
580
+ }
581
+ return fenced(run.id, () =>
582
+ host.storage.agents.threads.transitionSandbox({
583
+ ...input,
584
+ projectId: host.projectId,
585
+ runId: run.id,
586
+ executionToken,
587
+ })
588
+ )
589
+ },
590
+ },
591
+ async close() {
592
+ cancel.stop()
593
+ ended.abort(new DOMException("The Agent run's session has closed.", "AbortError"))
594
+ await logs?.flush().catch((error: unknown) => {
595
+ console.error(`[Sixb] Agent run '${run.id}' could not flush its tools' logs.`, error)
596
+ })
597
+ },
598
+ }
599
+ }
600
+
601
+ /** The run a project tool is told it runs in. */
602
+ function toolRunInfo(run: AgentRunRecord): AgentToolRunInfo {
603
+ return run.kind === "subagent"
604
+ ? { kind: "subagent", id: run.id, parentRunId: run.parentRunId }
605
+ : { kind: "conversation", id: run.id, threadId: run.threadId }
606
+ }
607
+
608
+ interface BoundRun {
609
+ readonly sixb: Sixb
610
+ readonly authorization: AgentExecutionAuthorization
611
+ }
612
+
613
+ /** The run's SDK, bound to its execution with the authority its requester holds now. */
614
+ async function bindRun(host: AgentRunSessionHost, run: AgentRunRecord): Promise<BoundRun> {
615
+ const execution = await host.storage.executions.getById({
616
+ projectId: host.projectId,
617
+ id: run.executionId,
618
+ })
619
+ if (!execution) {
620
+ throw new Error(
621
+ `[Sixb] Agent run '${run.id}' references missing execution '${run.executionId}'.`
622
+ )
623
+ }
624
+ const authorization = await resolveInheritedAgentExecutionAuthorization({
625
+ auth: host.storage.auth,
626
+ projectId: host.projectId,
627
+ authorizationRef: execution.authorizationRef,
628
+ security: host.security,
629
+ })
630
+ return {
631
+ sixb: bindDurableAgentExecution(host.sdk, { execution, runId: run.id, authorization }),
632
+ authorization,
633
+ }
634
+ }
635
+
636
+ async function openModelCalls(
637
+ host: AgentRunSessionHost,
638
+ run: AgentRunRecord
639
+ ): Promise<AiModelCallRecorder> {
640
+ const execution = await host.storage.executions.getById({
641
+ projectId: host.projectId,
642
+ id: run.executionId,
643
+ })
644
+ if (!execution) {
645
+ throw new Error(
646
+ `[Sixb] Agent run '${run.id}' references missing execution '${run.executionId}'.`
647
+ )
648
+ }
649
+ return new AiModelCallRecorder({
650
+ storage: host.storage,
651
+ projectId: host.projectId,
652
+ executionId: run.executionId,
653
+ attempt: run.attempt,
654
+ requesterGroupIds: execution.requesterGroupIds,
655
+ limits: createAiModelCallLimitController({
656
+ storage: host.storage,
657
+ projectId: host.projectId,
658
+ requestedBy: execution.requestedBy,
659
+ requesterGroupIds: execution.requesterGroupIds,
660
+ }),
661
+ recoverAiModelCall: host.recoverAiModelCall,
662
+ })
663
+ }
664
+
665
+ /** A project's members and a run's authority, as the in-process session reads them. */
666
+ export function agentRunPeople(
667
+ host: Pick<AgentRunSessionHost, "projectId" | "security"> & {
668
+ readonly storage: { readonly auth: AuthStorage }
669
+ }
670
+ ): AgentRunPeople {
671
+ return {
672
+ user: (userId) => host.storage.auth.users.getById({ projectId: host.projectId, id: userId }),
673
+ canRunAgent: (userId) =>
674
+ userCanRunAgent({
675
+ auth: host.storage.auth,
676
+ projectId: host.projectId,
677
+ userId,
678
+ security: host.security,
679
+ }),
680
+ authorization: (ref) =>
681
+ resolveInheritedAgentExecutionAuthorization({
682
+ auth: host.storage.auth,
683
+ projectId: host.projectId,
684
+ authorizationRef: ref,
685
+ security: host.security,
686
+ }),
687
+ }
688
+ }
689
+
690
+ /**
691
+ * Watch runs for a cancel, best effort: failing to attach a watch costs that run its
692
+ * cancellability, never the run itself. `stop` unsubscribes.
693
+ */
694
+ export async function watchAgentRunCancel(
695
+ host: Pick<AgentRunSessionHost, "projectId" | "broker">,
696
+ runIds: readonly string[]
697
+ ): Promise<{
698
+ readonly signal: AbortSignal
699
+ abort(reason: unknown): void
700
+ readonly stop: () => void
701
+ }> {
702
+ const controller = new AbortController()
703
+ const unsubscribes = await Promise.all(
704
+ runIds.map((runId) =>
705
+ subscribeAgentRunCancel(host.broker, { projectId: host.projectId, runId }, () =>
706
+ controller.abort()
707
+ ).catch((error: unknown) => {
708
+ console.error(`[Sixb] Agent run '${runId}' cancel watch failed to start:`, error)
709
+ return undefined
710
+ })
711
+ )
712
+ )
713
+ return {
714
+ signal: controller.signal,
715
+ abort: (reason) => controller.abort(reason),
716
+ stop: () => {
717
+ for (const unsubscribe of unsubscribes) unsubscribe?.()
718
+ },
719
+ }
720
+ }
721
+
722
+ /**
723
+ * The run's end could not be recorded: storage stayed unavailable across the retries. The runner
724
+ * leaves the delivery for another attempt rather than acknowledging a run that never ended.
725
+ */
726
+ export class AgentFinalizationError extends Error {
727
+ readonly name = "AgentFinalizationError"
728
+ constructor(
729
+ readonly runId: string,
730
+ options?: ErrorOptions
731
+ ) {
732
+ super(`[Sixb] Could not finalize agent execution '${runId}'; storage is unavailable.`, options)
733
+ }
734
+ }
735
+
736
+ async function startOrReclaim<TRun extends AgentRunRecord>(
737
+ agents: AgentStorage,
738
+ projectId: string,
739
+ input: ClaimAgentRunInput<TRun>
740
+ ): Promise<TRun | null> {
741
+ const { run } = input
742
+ const execution = {
743
+ token: createAgentRunExecutionToken(),
744
+ queueLeaseExpiresAt: new Date(input.leaseExpiresAt),
745
+ }
746
+ if (run.status !== "queued" && run.status !== "running") return null
747
+ // The read the caller made is already old: a run that ended since, or that another worker
748
+ // started, is not this caller's.
749
+ try {
750
+ return run.status === "queued"
751
+ ? sameKind(
752
+ run,
753
+ await agents.runs.start({ projectId, id: run.id, modelId: input.modelId, execution }),
754
+ "starting"
755
+ )
756
+ : sameKind(
757
+ run,
758
+ await agents.runs.reclaim({ projectId, id: run.id, execution, ifLapsedBy: new Date() }),
759
+ "reclaiming"
760
+ )
761
+ } catch (error) {
762
+ if (error instanceof AgentStorageError && error.code === "invalid_state") return null
763
+ throw error
764
+ }
765
+ }
766
+
767
+ function sameKind<TRun extends AgentRunRecord>(
768
+ run: TRun,
769
+ claimed: AgentRunRecord,
770
+ while_: string
771
+ ): TRun {
772
+ if (claimed.kind !== run.kind) {
773
+ throw new Error(`[Sixb] Agent run '${run.id}' changed kind while ${while_}.`)
774
+ }
775
+ return claimed as TRun
776
+ }
777
+
778
+ /** Short in-place retries that absorb a transient storage blip without re-running the model. */
779
+ const FINISH_BACKOFF_MS = [50, 200, 600] as const
780
+
781
+ async function finishWithRetries(
782
+ storage: AgentRunSessionHost["storage"],
783
+ finish: FinishAgentRunInput,
784
+ messages: readonly AppendAgentMessageInput[]
785
+ ): Promise<AgentRunRecord> {
786
+ for (let attempt = 0; ; attempt += 1) {
787
+ try {
788
+ if (messages.length === 0) return await storage.agents.runs.finish(finish)
789
+ return await storage.transaction(async (tx) => {
790
+ const agents = tx.agents
791
+ if (!agents) throw new Error("[Sixb] Agent storage is not configured.")
792
+ for (const message of messages) await agents.messages.append(message)
793
+ return agents.runs.finish(finish)
794
+ })
795
+ } catch (error) {
796
+ if (isTerminalOrExecutionGone(error)) throw new AgentExecutionLostError(finish.id)
797
+ const delay = FINISH_BACKOFF_MS[attempt]
798
+ if (delay === undefined) throw new AgentFinalizationError(finish.id, { cause: error })
799
+ await new Promise((resolve) => setTimeout(resolve, delay))
800
+ }
801
+ }
802
+ }