@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.
- package/dist/actions/index.js +35 -35
- package/dist/agents/attachment-keys.d.ts +25 -0
- package/dist/agents/attachment-keys.d.ts.map +1 -0
- package/dist/agents/cancel.d.ts +12 -0
- package/dist/agents/cancel.d.ts.map +1 -1
- package/dist/agents/children.d.ts.map +1 -1
- package/dist/agents/dispatch.d.ts +1 -9
- package/dist/agents/dispatch.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +5 -0
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/index.d.ts +31 -6
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +154 -66
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-loop.d.ts +3 -5
- package/dist/agents/model-loop.d.ts.map +1 -1
- package/dist/agents/model-routing.d.ts +4 -1
- package/dist/agents/model-routing.d.ts.map +1 -1
- package/dist/agents/request.d.ts +9 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-after-finish.d.ts +11 -0
- package/dist/agents/run-after-finish.d.ts.map +1 -0
- package/dist/agents/run-artifacts.d.ts +56 -0
- package/dist/agents/run-artifacts.d.ts.map +1 -0
- package/dist/agents/run-events.d.ts +49 -0
- package/dist/agents/run-events.d.ts.map +1 -0
- package/dist/agents/run-fence.d.ts +38 -0
- package/dist/agents/run-fence.d.ts.map +1 -0
- package/dist/agents/run-liveness.d.ts +36 -0
- package/dist/agents/run-liveness.d.ts.map +1 -0
- package/dist/agents/run-plan.d.ts +110 -0
- package/dist/agents/run-plan.d.ts.map +1 -0
- package/dist/agents/run-session-children.d.ts +89 -0
- package/dist/agents/run-session-children.d.ts.map +1 -0
- package/dist/agents/run-session-http.d.ts +37 -0
- package/dist/agents/run-session-http.d.ts.map +1 -0
- package/dist/agents/run-session-serve.d.ts +24 -0
- package/dist/agents/run-session-serve.d.ts.map +1 -0
- package/dist/agents/run-session-wire.d.ts +31 -0
- package/dist/agents/run-session-wire.d.ts.map +1 -0
- package/dist/agents/run-session.d.ts +239 -0
- package/dist/agents/run-session.d.ts.map +1 -0
- package/dist/agents/run-token.d.ts +40 -0
- package/dist/agents/run-token.d.ts.map +1 -0
- package/dist/agents/run-tools.d.ts +68 -0
- package/dist/agents/run-tools.d.ts.map +1 -0
- package/dist/agents/run-turn.d.ts +59 -0
- package/dist/agents/run-turn.d.ts.map +1 -0
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.d.ts +1 -1
- package/dist/agents/streams/internal.d.ts.map +1 -1
- package/dist/agents/streams/internal.js +2 -4
- package/dist/agents/streams/internal.js.map +1 -1
- package/dist/agents/streams/protocol.d.ts +1 -96
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/subagent-runs.d.ts +7 -1
- package/dist/agents/subagent-runs.d.ts.map +1 -1
- package/dist/agents/tool-files.d.ts +34 -0
- package/dist/agents/tool-files.d.ts.map +1 -0
- package/dist/agents/workflow-node-session.d.ts +99 -0
- package/dist/agents/workflow-node-session.d.ts.map +1 -0
- package/dist/artifacts/frames/index.js +6 -3
- package/dist/artifacts/frames/index.js.map +3 -3
- package/dist/artifacts/frames/probe.d.ts.map +1 -1
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/publish/index.d.ts +1 -1
- package/dist/artifacts/publish/index.d.ts.map +1 -1
- package/dist/artifacts/publish/index.js +19 -19
- package/dist/auth/index.js +8 -8
- package/dist/authorization/index.js +4 -4
- package/dist/bootstrap/index.js +45 -43
- package/dist/bootstrap/index.js.map +2 -2
- package/dist/{chunk-2fn60nvs.js → chunk-06sg8s4z.js} +2 -2
- package/dist/{chunk-2fn60nvs.js.map → chunk-06sg8s4z.js.map} +1 -1
- package/dist/chunk-07kkp2e1.js.map +1 -1
- package/dist/{chunk-9ntbsnke.js → chunk-0bc3w0zq.js} +7 -7
- package/dist/{chunk-9ntbsnke.js.map → chunk-0bc3w0zq.js.map} +2 -2
- package/dist/{chunk-d2m879s4.js → chunk-0kk2wt0h.js} +27 -27
- package/dist/chunk-0kk2wt0h.js.map +12 -0
- package/dist/chunk-16a9dmfy.js.map +1 -1
- package/dist/chunk-18sk89cg.js.map +2 -2
- package/dist/{chunk-3qms4nax.js → chunk-1vg43g9q.js} +20 -20
- package/dist/{chunk-3qms4nax.js.map → chunk-1vg43g9q.js.map} +4 -4
- package/dist/{chunk-hqsp2sx4.js → chunk-1xvqgg88.js} +31 -33
- package/dist/{chunk-hqsp2sx4.js.map → chunk-1xvqgg88.js.map} +6 -6
- package/dist/chunk-2adz0h75.js.map +1 -1
- package/dist/{chunk-fm62y49k.js → chunk-2pk5hjj9.js} +5 -3
- package/dist/{chunk-fm62y49k.js.map → chunk-2pk5hjj9.js.map} +5 -5
- package/dist/{chunk-vrf90dkv.js → chunk-2vjnyz1s.js} +1 -1
- package/dist/{chunk-vrf90dkv.js.map → chunk-2vjnyz1s.js.map} +1 -1
- package/dist/{chunk-4f3ydv7t.js → chunk-315qye3g.js} +1 -1
- package/dist/{chunk-4f3ydv7t.js.map → chunk-315qye3g.js.map} +1 -1
- package/dist/{chunk-rap5w0x0.js → chunk-31khg3g0.js} +1 -1
- package/dist/{chunk-rap5w0x0.js.map → chunk-31khg3g0.js.map} +1 -1
- package/dist/chunk-45ngkxkp.js.map +1 -1
- package/dist/chunk-48jezz3j.js.map +1 -1
- package/dist/{chunk-vr3j63jq.js → chunk-4jq2bg8t.js} +78 -78
- package/dist/{chunk-vr3j63jq.js.map → chunk-4jq2bg8t.js.map} +4 -4
- package/dist/chunk-4ymrcdbm.js.map +1 -1
- package/dist/chunk-58geavnf.js.map +1 -1
- package/dist/{chunk-6y0mkhex.js → chunk-59kf345w.js} +2 -2
- package/dist/{chunk-6y0mkhex.js.map → chunk-59kf345w.js.map} +1 -1
- package/dist/{chunk-3p93tb91.js → chunk-6qn7nmd3.js} +102 -102
- package/dist/{chunk-3p93tb91.js.map → chunk-6qn7nmd3.js.map} +4 -4
- package/dist/chunk-73j0v4qv.js +355 -0
- package/dist/chunk-73j0v4qv.js.map +13 -0
- package/dist/{chunk-2gjj5dx3.js → chunk-78ymxrn0.js} +1 -1
- package/dist/{chunk-6bkbyer5.js → chunk-7ex2p3zp.js} +3 -3
- package/dist/{chunk-6bkbyer5.js.map → chunk-7ex2p3zp.js.map} +1 -1
- package/dist/{chunk-5tfev0fv.js → chunk-7hf6tkgs.js} +167 -167
- package/dist/{chunk-5tfev0fv.js.map → chunk-7hf6tkgs.js.map} +4 -4
- package/dist/{chunk-8z4726jz.js → chunk-7wn5z7mq.js} +10 -10
- package/dist/{chunk-8z4726jz.js.map → chunk-7wn5z7mq.js.map} +2 -2
- package/dist/{chunk-6n69k945.js → chunk-8mb7mt8n.js} +2 -2
- package/dist/chunk-8ncg20rd.js.map +1 -1
- package/dist/{chunk-68wghpdf.js → chunk-8v5a54qz.js} +50 -11
- package/dist/{chunk-68wghpdf.js.map → chunk-8v5a54qz.js.map} +3 -3
- package/dist/{chunk-gqm0b7vd.js → chunk-8v6xzwgr.js} +92 -76
- package/dist/{chunk-gqm0b7vd.js.map → chunk-8v6xzwgr.js.map} +6 -6
- package/dist/{chunk-m36fw8ft.js → chunk-8wsjr52f.js} +1 -1
- package/dist/{chunk-vd1rk42q.js → chunk-8xnz9vvp.js} +4 -4
- package/dist/{chunk-vd1rk42q.js.map → chunk-8xnz9vvp.js.map} +1 -1
- package/dist/chunk-9mab3dvg.js.map +1 -1
- package/dist/chunk-9tc8dxmn.js.map +1 -1
- package/dist/chunk-9x8dybsb.js.map +2 -2
- package/dist/chunk-a3faa34j.js.map +1 -1
- package/dist/{chunk-62a63pr6.js → chunk-axb4ss9a.js} +7 -7
- package/dist/{chunk-62a63pr6.js.map → chunk-axb4ss9a.js.map} +2 -2
- package/dist/{chunk-z3ryd53f.js → chunk-b6ghvap7.js} +35 -11
- package/dist/{chunk-z3ryd53f.js.map → chunk-b6ghvap7.js.map} +3 -3
- package/dist/{chunk-sqfvnvqj.js → chunk-c14ap3s9.js} +2 -2
- package/dist/{chunk-sqfvnvqj.js.map → chunk-c14ap3s9.js.map} +1 -1
- package/dist/{chunk-661ezhks.js → chunk-cbcgs9f7.js} +87 -8
- package/dist/chunk-cbcgs9f7.js.map +11 -0
- package/dist/chunk-cwdzcv37.js.map +1 -1
- package/dist/{chunk-bab05bhg.js → chunk-dgtd0836.js} +1 -1
- package/dist/{chunk-1j6j0rht.js → chunk-e24fvw8g.js} +1 -1
- package/dist/{chunk-1j6j0rht.js.map → chunk-e24fvw8g.js.map} +1 -1
- package/dist/chunk-e5wf5vz0.js.map +1 -1
- package/dist/chunk-eptrvnby.js.map +1 -1
- package/dist/chunk-ey1nk510.js.map +1 -1
- package/dist/{chunk-j936th07.js → chunk-fakrpfy3.js} +58 -58
- package/dist/{chunk-j936th07.js.map → chunk-fakrpfy3.js.map} +5 -5
- package/dist/chunk-fb3feg1e.js.map +1 -1
- package/dist/chunk-ff5xkv0p.js.map +1 -1
- package/dist/chunk-fntqb7qy.js.map +1 -1
- package/dist/{chunk-7ny9mjgm.js → chunk-ft3w5ahs.js} +1 -1
- package/dist/chunk-g663fahq.js.map +1 -1
- package/dist/{chunk-cdk3egjj.js → chunk-h1na2cxc.js} +1 -1
- package/dist/{chunk-cdk3egjj.js.map → chunk-h1na2cxc.js.map} +1 -1
- package/dist/chunk-hn2r7z41.js.map +1 -1
- package/dist/{chunk-24bqx0dx.js → chunk-hn76sanm.js} +1 -1
- package/dist/{chunk-24bqx0dx.js.map → chunk-hn76sanm.js.map} +1 -1
- package/dist/chunk-jmfet9r4.js.map +1 -1
- package/dist/{chunk-bnr4a734.js → chunk-jn3ysaf2.js} +24 -22
- package/dist/{chunk-bnr4a734.js.map → chunk-jn3ysaf2.js.map} +5 -5
- package/dist/{chunk-4y26vs3v.js → chunk-jspskey0.js} +16 -3
- package/dist/chunk-jspskey0.js.map +10 -0
- package/dist/{chunk-r6szek0x.js → chunk-jt3r6thp.js} +2 -135
- package/dist/chunk-jt3r6thp.js.map +10 -0
- package/dist/chunk-kfee1h52.js.map +1 -1
- package/dist/{chunk-qx00vjrj.js → chunk-kwfhd1g0.js} +23 -23
- package/dist/{chunk-qx00vjrj.js.map → chunk-kwfhd1g0.js.map} +4 -4
- package/dist/chunk-m427qgq0.js.map +1 -1
- package/dist/chunk-mbsbxarb.js.map +1 -1
- package/dist/{chunk-et017krg.js → chunk-mdxmt0n3.js} +8657 -8704
- package/dist/{chunk-et017krg.js.map → chunk-mdxmt0n3.js.map} +37 -37
- package/dist/chunk-mmagke4x.js.map +1 -1
- package/dist/{chunk-2x19q6k6.js → chunk-mqx25wwh.js} +319 -154
- package/dist/chunk-mqx25wwh.js.map +18 -0
- package/dist/chunk-mzx71snp.js.map +1 -1
- package/dist/chunk-n8q5j6y5.js.map +1 -1
- package/dist/chunk-npcr0228.js.map +1 -1
- package/dist/{chunk-m2nevja0.js → chunk-phm3c7b9.js} +1 -1
- package/dist/{chunk-m2nevja0.js.map → chunk-phm3c7b9.js.map} +1 -1
- package/dist/chunk-qf954wje.js.map +1 -1
- package/dist/{chunk-65pyhyas.js → chunk-qgvbxfqv.js} +6 -8
- package/dist/{chunk-65pyhyas.js.map → chunk-qgvbxfqv.js.map} +2 -2
- package/dist/{chunk-hk38wahh.js → chunk-qst145py.js} +4 -4
- package/dist/{chunk-hk38wahh.js.map → chunk-qst145py.js.map} +1 -1
- package/dist/{chunk-c844dkwd.js → chunk-qtzftvxa.js} +4 -5
- package/dist/{chunk-c844dkwd.js.map → chunk-qtzftvxa.js.map} +2 -2
- package/dist/chunk-ratkv4zc.js +3 -0
- package/dist/chunk-ratkv4zc.js.map +9 -0
- package/dist/{chunk-nzapm6p0.js → chunk-s3we74h8.js} +1 -2
- package/dist/chunk-s3we74h8.js.map +12 -0
- package/dist/{chunk-0xmt5p5y.js → chunk-t3brw0wd.js} +1 -2
- package/dist/{chunk-0xmt5p5y.js.map → chunk-t3brw0wd.js.map} +2 -2
- package/dist/chunk-t5608tkq.js.map +1 -1
- package/dist/chunk-tdxfsg1c.js.map +1 -1
- package/dist/{chunk-1t6k1avb.js → chunk-tnhqtfea.js} +1 -1
- package/dist/chunk-vhbw5sqm.js.map +1 -1
- package/dist/{chunk-rp9wwk7b.js → chunk-vx4e4zv4.js} +30 -30
- package/dist/{chunk-rp9wwk7b.js.map → chunk-vx4e4zv4.js.map} +4 -4
- package/dist/chunk-waqk73p1.js.map +1 -1
- package/dist/chunk-x0v3jd47.js.map +1 -1
- package/dist/{chunk-yecwnwpq.js → chunk-xm8qgbqm.js} +58 -29
- package/dist/{chunk-yecwnwpq.js.map → chunk-xm8qgbqm.js.map} +7 -7
- package/dist/{chunk-97wr6p2g.js → chunk-y7j6x4h0.js} +8 -8
- package/dist/{chunk-97wr6p2g.js.map → chunk-y7j6x4h0.js.map} +4 -4
- package/dist/{chunk-xe0732g0.js → chunk-yavhtnac.js} +12 -8
- package/dist/{chunk-xe0732g0.js.map → chunk-yavhtnac.js.map} +4 -4
- package/dist/chunk-yd00vzqr.js +3394 -0
- package/dist/chunk-yd00vzqr.js.map +37 -0
- package/dist/{chunk-n9w3n38q.js → chunk-ye5c8016.js} +54 -8
- package/dist/chunk-ye5c8016.js.map +23 -0
- package/dist/chunk-yw9pyg66.js.map +1 -1
- package/dist/{chunk-nydf3dbe.js → chunk-z9mg7wya.js} +37 -20
- package/dist/chunk-z9mg7wya.js.map +13 -0
- package/dist/chunk-zbc929zg.js.map +1 -1
- package/dist/chunk-zhh1jd89.js +290 -0
- package/dist/chunk-zhh1jd89.js.map +10 -0
- package/dist/connectors/connections/authorizations.d.ts +2 -2
- package/dist/connectors/connections/authorizations.d.ts.map +1 -1
- package/dist/connectors/connections/service.d.ts.map +1 -1
- package/dist/connectors/connections/tokens.d.ts +2 -2
- package/dist/connectors/connections/tokens.d.ts.map +1 -1
- package/dist/connectors/connections/validation.d.ts +5 -0
- package/dist/connectors/connections/validation.d.ts.map +1 -1
- package/dist/connectors/types.d.ts +9 -2
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/datasets/write.js +3 -3
- package/dist/deploy/internal.js +2 -5
- package/dist/deploy/internal.js.map +3 -3
- package/dist/deploy/types.d.ts +0 -2
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/execution/agent.d.ts +2 -2
- package/dist/execution/agent.d.ts.map +1 -1
- package/dist/execution/agent.js +38 -38
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/primitive.js +35 -35
- package/dist/execution/request.js +37 -37
- package/dist/execution/request.js.map +2 -2
- package/dist/http/api-routes.d.ts +12 -11
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -51
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/index.js +3 -3
- package/dist/logging/internal.js +1 -1
- package/dist/materializer/index.js +17 -17
- package/dist/models/execution/errors.d.ts +5 -0
- package/dist/models/execution/errors.d.ts.map +1 -1
- package/dist/models/execution/index.d.ts +2 -1
- package/dist/models/execution/index.d.ts.map +1 -1
- package/dist/models/execution/index.js +55 -50
- package/dist/models/execution/index.js.map +1 -1
- package/dist/models/execution/model-call-recorder.d.ts +7 -2
- package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
- package/dist/models/execution.d.ts.map +1 -1
- package/dist/models/language-call.d.ts +51 -0
- package/dist/models/language-call.d.ts.map +1 -0
- package/dist/objects/index.js +35 -35
- package/dist/objects/query/index.js +17 -17
- package/dist/ontology/docs-markdown.d.ts.map +1 -1
- package/dist/ontology/index.d.ts +1 -1
- package/dist/ontology/index.d.ts.map +1 -1
- package/dist/ontology/index.js +4 -4
- package/dist/ontology/internal.js +8 -275
- package/dist/ontology/internal.js.map +3 -4
- package/dist/ontology/user-ref.d.ts +21 -3
- package/dist/ontology/user-ref.d.ts.map +1 -1
- package/dist/pipelines/index.js +19 -19
- package/dist/projections/builders.d.ts +13 -2
- package/dist/projections/builders.d.ts.map +1 -1
- package/dist/projections/index.d.ts +1 -1
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/internal.js +17 -17
- package/dist/projections/types.d.ts +7 -0
- package/dist/projections/types.d.ts.map +1 -1
- package/dist/projections/validation.d.ts +2 -0
- package/dist/projections/validation.d.ts.map +1 -1
- package/dist/query.js +2 -2
- package/dist/queues/in-memory.d.ts +0 -1
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/types.d.ts +0 -8
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/internal.js +23 -23
- package/dist/runtime/internal.js.map +1 -1
- package/dist/sandboxes/configuration.d.ts +4 -6
- package/dist/sandboxes/configuration.d.ts.map +1 -1
- package/dist/sandboxes/environment.d.ts.map +1 -1
- package/dist/sandboxes/exec.d.ts +5 -3
- package/dist/sandboxes/exec.d.ts.map +1 -1
- package/dist/sandboxes/guest-credentials.d.ts +61 -0
- package/dist/sandboxes/guest-credentials.d.ts.map +1 -0
- package/dist/sandboxes/index.d.ts +2 -0
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +23 -9
- package/dist/sandboxes/index.js.map +1 -1
- package/dist/sandboxes/sandbox.d.ts +18 -4
- package/dist/sandboxes/sandbox.d.ts.map +1 -1
- package/dist/security/internal.js +1 -1
- package/dist/security/internal.js.map +1 -1
- package/dist/shares/internal.js +17 -17
- package/dist/shares/internal.js.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +3 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +1 -1
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +6 -0
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +8 -2
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +63 -7
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +2 -2
- package/dist/storage/connector-connections/provider.js.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +9 -9
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +15 -15
- package/dist/storage/ontology/provider.js +1 -1
- package/dist/storage/share-grants/provider.js +3 -3
- package/dist/storage/types.d.ts +1 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +9 -9
- package/dist/syncs/index.js +20 -20
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +677 -352
- package/dist/testing/index.js.map +9 -7
- package/dist/testing/queues-contract.d.ts.map +1 -1
- package/dist/testing/sandbox-credentials-contract.d.ts +27 -0
- package/dist/testing/sandbox-credentials-contract.d.ts.map +1 -0
- package/dist/testing/sandboxes-contract.d.ts.map +1 -1
- package/dist/testing/users.d.ts +20 -0
- package/dist/testing/users.d.ts.map +1 -0
- package/dist/users/execution.d.ts +6 -2
- package/dist/users/execution.d.ts.map +1 -1
- package/dist/users/index.d.ts +1 -1
- package/dist/users/index.d.ts.map +1 -1
- package/dist/webhooks/internal.js +17 -17
- package/dist/webhooks/internal.js.map +1 -1
- package/dist/workers/index.js.map +1 -1
- package/dist/workflows/index.js +41 -39
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/README.md +136 -0
- package/src/agents/attachment-keys.ts +83 -0
- package/src/agents/cancel.ts +16 -1
- package/src/agents/children.ts +5 -3
- package/src/agents/dispatch.ts +6 -58
- package/src/agents/execution.ts +18 -0
- package/src/agents/index.ts +127 -21
- package/src/agents/model-loop.ts +23 -73
- package/src/agents/model-routing.ts +7 -2
- package/src/agents/request.ts +69 -20
- package/src/agents/run-after-finish.ts +133 -0
- package/src/agents/run-artifacts.ts +257 -0
- package/src/agents/run-events.ts +302 -0
- package/src/agents/run-fence.ts +71 -0
- package/src/agents/run-liveness.ts +122 -0
- package/src/agents/run-plan.ts +316 -0
- package/src/agents/run-session-children.ts +303 -0
- package/src/agents/run-session-http.ts +397 -0
- package/src/agents/run-session-serve.ts +479 -0
- package/src/agents/run-session-wire.ts +189 -0
- package/src/agents/run-session.ts +802 -0
- package/src/agents/run-token.ts +124 -0
- package/src/agents/run-tools.ts +180 -0
- package/src/agents/run-turn.ts +265 -0
- package/src/agents/streams/internal.ts +0 -1
- package/src/agents/streams/protocol.ts +0 -292
- package/src/agents/subagent-runs.ts +19 -1
- package/src/agents/tool-files.ts +225 -0
- package/src/agents/workflow-node-session.ts +387 -0
- package/src/artifacts/frames/probe.ts +14 -1
- package/src/artifacts/publish/index.ts +1 -0
- package/src/connectors/connections/authorizations.ts +3 -2
- package/src/connectors/connections/service.ts +5 -1
- package/src/connectors/connections/tokens.ts +41 -5
- package/src/connectors/connections/validation.ts +21 -0
- package/src/connectors/types.ts +12 -2
- package/src/deploy/types.ts +0 -2
- package/src/deploy/validation.ts +1 -4
- package/src/execution/agent.ts +2 -2
- package/src/execution/authorized-object-reader.ts +28 -1
- package/src/http/api-routes.ts +114 -27
- package/src/index.ts +3 -1
- package/src/models/execution/README.md +15 -1
- package/src/models/execution/errors.ts +14 -0
- package/src/models/execution/index.ts +2 -1
- package/src/models/execution/model-call-recorder.ts +12 -10
- package/src/models/execution.ts +9 -11
- package/src/models/language-call.ts +247 -0
- package/src/ontology/docs-markdown.ts +14 -0
- package/src/ontology/index.ts +1 -1
- package/src/ontology/user-ref.ts +40 -6
- package/src/projections/builders.ts +48 -4
- package/src/projections/index.ts +1 -0
- package/src/projections/registry.ts +1 -0
- package/src/projections/revision.ts +10 -0
- package/src/projections/types.ts +8 -0
- package/src/projections/validation.ts +52 -6
- package/src/queues/in-memory.ts +0 -5
- package/src/queues/index.ts +0 -2
- package/src/queues/types.ts +0 -13
- package/src/runtime/host.ts +1 -1
- package/src/sandboxes/README.md +17 -6
- package/src/sandboxes/configuration.ts +7 -9
- package/src/sandboxes/environment.ts +1 -0
- package/src/sandboxes/exec.ts +17 -9
- package/src/sandboxes/guest-credentials.ts +262 -0
- package/src/sandboxes/index.ts +14 -0
- package/src/sandboxes/sandbox.ts +19 -4
- package/src/storage/agents/in-memory.ts +53 -0
- package/src/storage/agents/index.ts +2 -0
- package/src/storage/agents/provider.ts +56 -11
- package/src/storage/agents/types.ts +59 -7
- package/src/storage/index.ts +2 -0
- package/src/storage/types.ts +1 -0
- package/src/testing/agent-storage-contract.ts +175 -2
- package/src/testing/ai-model-call-groups-contract.ts +0 -1
- package/src/testing/index.ts +5 -0
- package/src/testing/queues-contract.ts +0 -16
- package/src/testing/sandbox-credentials-contract.ts +284 -0
- package/src/testing/sandboxes-contract.ts +21 -0
- package/src/testing/users.ts +39 -0
- package/src/users/execution.ts +33 -7
- package/src/users/index.ts +7 -1
- package/dist/agents/api-gateway.d.ts +0 -26
- package/dist/agents/api-gateway.d.ts.map +0 -1
- package/dist/chunk-2x19q6k6.js.map +0 -17
- package/dist/chunk-4y26vs3v.js.map +0 -10
- package/dist/chunk-661ezhks.js.map +0 -11
- package/dist/chunk-d2m879s4.js.map +0 -12
- package/dist/chunk-n9w3n38q.js.map +0 -23
- package/dist/chunk-nydf3dbe.js.map +0 -13
- package/dist/chunk-nzapm6p0.js.map +0 -12
- package/dist/chunk-r6szek0x.js.map +0 -10
- package/dist/chunk-vabga7fk.js +0 -176
- package/dist/chunk-vabga7fk.js.map +0 -12
- package/dist/chunk-vpgwq5nf.js +0 -810
- package/dist/chunk-vpgwq5nf.js.map +0 -21
- package/src/agents/api-gateway.ts +0 -68
- /package/dist/{chunk-2gjj5dx3.js.map → chunk-78ymxrn0.js.map} +0 -0
- /package/dist/{chunk-6n69k945.js.map → chunk-8mb7mt8n.js.map} +0 -0
- /package/dist/{chunk-m36fw8ft.js.map → chunk-8wsjr52f.js.map} +0 -0
- /package/dist/{chunk-bab05bhg.js.map → chunk-dgtd0836.js.map} +0 -0
- /package/dist/{chunk-7ny9mjgm.js.map → chunk-ft3w5ahs.js.map} +0 -0
- /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
|
+
}
|