@sixb/core 0.1.25 → 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 +1 -1
- package/dist/artifacts/frames/index.js.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/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,303 @@
|
|
|
1
|
+
import { createInheritedAgentExecutionRecord } from "../execution/agent"
|
|
2
|
+
import { ensureExecutionRecord } from "../execution/durable"
|
|
3
|
+
import type { Storage } from "../storage"
|
|
4
|
+
import type {
|
|
5
|
+
AgentApprovalRecord,
|
|
6
|
+
AgentMessageRecord,
|
|
7
|
+
AgentRunRecord,
|
|
8
|
+
AgentStorage,
|
|
9
|
+
CreateSubagentRunInput,
|
|
10
|
+
ListAgentMessagesInput,
|
|
11
|
+
ListAgentMessagesResult,
|
|
12
|
+
ListThreadSubagentsInput,
|
|
13
|
+
SubagentRunRecord,
|
|
14
|
+
} from "../storage/agents"
|
|
15
|
+
import { type AgentChildApprovalAwaiting, listChildApprovalsAwaiting } from "./approvals"
|
|
16
|
+
import { createSubagentExecutionId, createSubagentRunId, createSubagentThreadId } from "./ids"
|
|
17
|
+
import { AgentRunRefusedError, fenced } from "./run-fence"
|
|
18
|
+
import { listSubagentThreadRuns } from "./subagent-runs"
|
|
19
|
+
import { conversationThreadId } from "./thread-access"
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A conversation turn's children, as its session reaches them: the runs it spawned, and those of
|
|
23
|
+
* earlier turns of its conversation, with their threads and the approvals that hold them. Every
|
|
24
|
+
* read answers only for runs of the run's own conversation, and every write is fenced by the
|
|
25
|
+
* turn's execution token.
|
|
26
|
+
*/
|
|
27
|
+
export interface AgentRunChildren {
|
|
28
|
+
/** A run of this conversation: one of its turns, or a child of one; null for any other. */
|
|
29
|
+
get(runId: string): Promise<AgentRunRecord | null>
|
|
30
|
+
getMany(runIds: readonly string[]): Promise<readonly AgentRunRecord[]>
|
|
31
|
+
/** The children of this conversation's turns, by spawn key or by how they paused. */
|
|
32
|
+
inConversation(
|
|
33
|
+
input: Omit<ListThreadSubagentsInput, "projectId" | "threadId">
|
|
34
|
+
): Promise<readonly SubagentRunRecord[]>
|
|
35
|
+
/** One child thread's runs, oldest first: a child and its continuations. */
|
|
36
|
+
threadRuns(threadId: string): Promise<readonly SubagentRunRecord[]>
|
|
37
|
+
/** The approvals a run's calls asked for, its children's included. */
|
|
38
|
+
approvals(runId: string): Promise<readonly AgentApprovalRecord[]>
|
|
39
|
+
holdsRun(runId: string): Promise<boolean>
|
|
40
|
+
/** This turn's children's calls that wait for an approval, by child. */
|
|
41
|
+
awaitingApproval(
|
|
42
|
+
childRunIds: readonly string[]
|
|
43
|
+
): Promise<ReadonlyMap<string, readonly AgentChildApprovalAwaiting[]>>
|
|
44
|
+
/** How many of this turn's children are queued or running. */
|
|
45
|
+
activeCount(): Promise<number>
|
|
46
|
+
/**
|
|
47
|
+
* Create a child run of this turn, with its execution, in one transaction that refuses once the
|
|
48
|
+
* turn no longer owns its run. The session decides what the runner may not: the child's id and
|
|
49
|
+
* thread from its key, its authority from the turn's, and how many children may be at work.
|
|
50
|
+
*/
|
|
51
|
+
spawn(child: AgentChildDraft): Promise<SubagentRunRecord>
|
|
52
|
+
/**
|
|
53
|
+
* Remove what a run left in a child thread under an earlier attempt of this turn, which failed,
|
|
54
|
+
* so the turn can continue the child again. Refused once the turn no longer owns its run.
|
|
55
|
+
*/
|
|
56
|
+
clearAttempt(input: { readonly threadId: string; readonly runId: string }): Promise<void>
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* A child as the turn asks for it: under its key, with its task, either in a thread of its own or
|
|
61
|
+
* continuing one of the conversation's child threads.
|
|
62
|
+
*/
|
|
63
|
+
export type AgentChildDraft = Pick<CreateSubagentRunInput, "spawnKey" | "spec" | "trigger"> & {
|
|
64
|
+
readonly thread: { readonly create: true } | { readonly id: string; readonly create: false }
|
|
65
|
+
readonly createdAt?: Date
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** How many children one turn may have queued or running at once, unless its host says. */
|
|
69
|
+
export const DEFAULT_MAX_ACTIVE_CHILDREN = 4
|
|
70
|
+
|
|
71
|
+
/** The messages of the run's conversation: its threads, and its children's. */
|
|
72
|
+
export interface AgentRunThreads {
|
|
73
|
+
/** A message of the conversation; null for one anywhere else. */
|
|
74
|
+
message(messageId: string): Promise<AgentMessageRecord | null>
|
|
75
|
+
/** A thread of the conversation's messages; any other thread is refused. */
|
|
76
|
+
messages(input: Omit<ListAgentMessagesInput, "projectId">): Promise<ListAgentMessagesResult>
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Which threads a run may read: its conversation's own, and the threads of its children. A runner
|
|
81
|
+
* over HTTP can name any id, so the session answers for these alone. A thread's place never
|
|
82
|
+
* changes, so each is looked up once.
|
|
83
|
+
*/
|
|
84
|
+
export interface AgentRunScope {
|
|
85
|
+
includes(threadId: string): Promise<boolean>
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function agentRunScope(host: AgentRunChildrenHost, run: AgentRunRecord): AgentRunScope {
|
|
89
|
+
const conversations = new Map<string, Promise<string | null>>()
|
|
90
|
+
const conversationOf = (threadId: string) => {
|
|
91
|
+
let conversation = conversations.get(threadId)
|
|
92
|
+
if (!conversation) {
|
|
93
|
+
conversation = host.storage.agents.threads
|
|
94
|
+
.getById({ projectId: host.projectId, id: threadId })
|
|
95
|
+
.then((thread) => (thread ? conversationThreadId(thread) : null))
|
|
96
|
+
// A failed read is read again next time.
|
|
97
|
+
conversation.catch(() => conversations.delete(threadId))
|
|
98
|
+
conversations.set(threadId, conversation)
|
|
99
|
+
}
|
|
100
|
+
return conversation
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
async includes(threadId) {
|
|
104
|
+
const [own, theirs] = await Promise.all([
|
|
105
|
+
conversationOf(run.threadId),
|
|
106
|
+
conversationOf(threadId),
|
|
107
|
+
])
|
|
108
|
+
return own !== null && own === theirs
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function agentRunThreads(
|
|
114
|
+
host: AgentRunChildrenHost,
|
|
115
|
+
run: AgentRunRecord,
|
|
116
|
+
scope: AgentRunScope
|
|
117
|
+
): AgentRunThreads {
|
|
118
|
+
const { projectId } = host
|
|
119
|
+
const agents = host.storage.agents
|
|
120
|
+
return {
|
|
121
|
+
async message(messageId) {
|
|
122
|
+
const message = await agents.messages.getById({ projectId, id: messageId })
|
|
123
|
+
return message && (await scope.includes(message.threadId)) ? message : null
|
|
124
|
+
},
|
|
125
|
+
async messages(input) {
|
|
126
|
+
if (!(await scope.includes(input.threadId))) {
|
|
127
|
+
throw new AgentRunRefusedError(
|
|
128
|
+
`[Sixb] Agent run '${run.id}' reads only its conversation's threads, not '${input.threadId}'.`
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
return agents.messages.list({ ...input, projectId })
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export interface AgentRunChildrenHost {
|
|
137
|
+
readonly projectId: string
|
|
138
|
+
readonly storage: Storage & { readonly agents: AgentStorage }
|
|
139
|
+
/** How many children one turn may have queued or running at once. */
|
|
140
|
+
readonly maxActiveChildren?: number
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** What a turn may hand its children: the project's tools, and the models it delegates to. */
|
|
144
|
+
export interface AgentRunDelegable {
|
|
145
|
+
readonly tools: readonly string[]
|
|
146
|
+
readonly models: readonly { readonly provider: string; readonly modelId: string }[]
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export function agentRunChildren(
|
|
150
|
+
host: AgentRunChildrenHost,
|
|
151
|
+
run: AgentRunRecord,
|
|
152
|
+
executionToken: string,
|
|
153
|
+
scope: AgentRunScope,
|
|
154
|
+
delegable: () => AgentRunDelegable
|
|
155
|
+
): AgentRunChildren {
|
|
156
|
+
const { projectId } = host
|
|
157
|
+
const agents = host.storage.agents
|
|
158
|
+
const get = async (runId: string) => {
|
|
159
|
+
const found = await agents.runs.getById({ projectId, id: runId })
|
|
160
|
+
return found && (await scope.includes(found.threadId)) ? found : null
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return {
|
|
164
|
+
get,
|
|
165
|
+
async getMany(runIds) {
|
|
166
|
+
const found = await agents.runs.getByIds({ projectId, ids: runIds })
|
|
167
|
+
const included = await Promise.all(found.map((each) => scope.includes(each.threadId)))
|
|
168
|
+
return found.filter((_, index) => included[index])
|
|
169
|
+
},
|
|
170
|
+
inConversation: (input) =>
|
|
171
|
+
agents.runs.listThreadSubagents({ ...input, projectId, threadId: run.threadId }),
|
|
172
|
+
async threadRuns(threadId) {
|
|
173
|
+
if (!(await scope.includes(threadId))) return []
|
|
174
|
+
return listSubagentThreadRuns(agents, { projectId, threadId })
|
|
175
|
+
},
|
|
176
|
+
async approvals(runId) {
|
|
177
|
+
if (!(await get(runId))) return []
|
|
178
|
+
return (await agents.approvals.list({ projectId, runId })).approvals
|
|
179
|
+
},
|
|
180
|
+
async holdsRun(runId) {
|
|
181
|
+
return (await get(runId)) !== null && agents.approvals.holdsRun({ projectId, runId })
|
|
182
|
+
},
|
|
183
|
+
awaitingApproval: (childRunIds) =>
|
|
184
|
+
listChildApprovalsAwaiting(agents, { projectId, parentRunId: run.id, childRunIds }),
|
|
185
|
+
async activeCount() {
|
|
186
|
+
const active = await agents.runs.list({
|
|
187
|
+
projectId,
|
|
188
|
+
kinds: ["subagent"],
|
|
189
|
+
parentRunId: run.id,
|
|
190
|
+
statuses: ["queued", "running"],
|
|
191
|
+
limit: 1,
|
|
192
|
+
})
|
|
193
|
+
return active.total
|
|
194
|
+
},
|
|
195
|
+
async spawn(child) {
|
|
196
|
+
assertDelegable(run, child, delegable())
|
|
197
|
+
const id = createSubagentRunId(run.id, child.spawnKey)
|
|
198
|
+
const executionId = createSubagentExecutionId(id)
|
|
199
|
+
const [parentExecution, maxActiveChildren] = await Promise.all([
|
|
200
|
+
host.storage.executions.getById({ projectId, id: run.executionId }),
|
|
201
|
+
childLimit(host, run, child),
|
|
202
|
+
])
|
|
203
|
+
if (!parentExecution) {
|
|
204
|
+
throw new Error(`[Sixb] Agent run '${run.id}' has no execution to hand its children.`)
|
|
205
|
+
}
|
|
206
|
+
const execution = createInheritedAgentExecutionRecord({
|
|
207
|
+
id: executionId,
|
|
208
|
+
parent: parentExecution,
|
|
209
|
+
runId: id,
|
|
210
|
+
})
|
|
211
|
+
return fenced(run.id, () =>
|
|
212
|
+
host.storage.transaction(async (tx) => {
|
|
213
|
+
if (!tx.agents)
|
|
214
|
+
throw new Error("[Sixb] Agent storage disappeared during child admission.")
|
|
215
|
+
await ensureExecutionRecord(tx.executions, execution)
|
|
216
|
+
return tx.agents.runs.createSubagent({
|
|
217
|
+
id,
|
|
218
|
+
projectId,
|
|
219
|
+
executionId,
|
|
220
|
+
parentRunId: run.id,
|
|
221
|
+
parentExecutionToken: executionToken,
|
|
222
|
+
spawnKey: child.spawnKey,
|
|
223
|
+
spec: child.spec,
|
|
224
|
+
thread: child.thread.create
|
|
225
|
+
? { id: createSubagentThreadId(run.id, child.spawnKey), create: true }
|
|
226
|
+
: child.thread,
|
|
227
|
+
trigger: child.trigger,
|
|
228
|
+
maxActiveChildren,
|
|
229
|
+
...(child.createdAt === undefined ? {} : { createdAt: child.createdAt }),
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
)
|
|
233
|
+
},
|
|
234
|
+
async clearAttempt({ threadId, runId }) {
|
|
235
|
+
// Only an attempt that ended, of a child of this conversation, in that child's thread.
|
|
236
|
+
const attempt = await get(runId)
|
|
237
|
+
if (
|
|
238
|
+
attempt?.kind !== "subagent" ||
|
|
239
|
+
attempt.threadId !== threadId ||
|
|
240
|
+
attempt.status === "queued" ||
|
|
241
|
+
attempt.status === "running"
|
|
242
|
+
) {
|
|
243
|
+
throw new AgentRunRefusedError(
|
|
244
|
+
`[Sixb] Agent run '${run.id}' clears only an ended attempt of its conversation's children, not '${runId}'.`
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
await fenced(run.id, () =>
|
|
248
|
+
agents.messages.deleteByRunId({
|
|
249
|
+
projectId,
|
|
250
|
+
threadId,
|
|
251
|
+
runId,
|
|
252
|
+
fence: { runId: run.id, executionToken },
|
|
253
|
+
})
|
|
254
|
+
)
|
|
255
|
+
},
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function assertDelegable(
|
|
260
|
+
run: AgentRunRecord,
|
|
261
|
+
child: AgentChildDraft,
|
|
262
|
+
delegable: AgentRunDelegable
|
|
263
|
+
): void {
|
|
264
|
+
const { model, toolNames } = child.spec
|
|
265
|
+
const unknownTool = toolNames.find((name) => !delegable.tools.includes(name))
|
|
266
|
+
if (unknownTool !== undefined) {
|
|
267
|
+
throw new AgentRunRefusedError(
|
|
268
|
+
`[Sixb] Agent run '${run.id}' cannot hand a child tool '${unknownTool}'.`
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
if (
|
|
272
|
+
!delegable.models.some(
|
|
273
|
+
(each) => each.provider === model.provider && each.modelId === model.modelId
|
|
274
|
+
)
|
|
275
|
+
) {
|
|
276
|
+
throw new AgentRunRefusedError(
|
|
277
|
+
`[Sixb] Agent run '${run.id}' cannot delegate to model '${model.provider}/${model.modelId}'.`
|
|
278
|
+
)
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* A turn keeps at most the host's limit of children at work. One that resumes children paused on
|
|
284
|
+
* calls its trigger decided starts with all of them at once: each was admitted within the limit.
|
|
285
|
+
*/
|
|
286
|
+
async function childLimit(
|
|
287
|
+
host: AgentRunChildrenHost,
|
|
288
|
+
run: AgentRunRecord,
|
|
289
|
+
child: AgentChildDraft
|
|
290
|
+
): Promise<number> {
|
|
291
|
+
const limit = host.maxActiveChildren ?? DEFAULT_MAX_ACTIVE_CHILDREN
|
|
292
|
+
if (child.thread.create) return limit
|
|
293
|
+
const trigger = await host.storage.agents.messages.getById({
|
|
294
|
+
projectId: host.projectId,
|
|
295
|
+
id: run.triggerMessageId,
|
|
296
|
+
})
|
|
297
|
+
const continuing = new Set(
|
|
298
|
+
(trigger?.parts ?? []).flatMap((part) =>
|
|
299
|
+
part.type === "approval-outcome" && part.caller?.continues ? [part.caller.runId] : []
|
|
300
|
+
)
|
|
301
|
+
)
|
|
302
|
+
return Math.max(limit, continuing.size)
|
|
303
|
+
}
|
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import type { FileRef } from "../blob-storage/types"
|
|
2
|
+
import type { LanguageModel, LanguageModelStreamEvent } from "../models"
|
|
3
|
+
import type {
|
|
4
|
+
AgentRunRecord,
|
|
5
|
+
ConversationAgentRunRecord,
|
|
6
|
+
SubagentRunRecord,
|
|
7
|
+
} from "../storage/agents"
|
|
8
|
+
import type { StreamSink } from "./run-events"
|
|
9
|
+
import { AgentExecutionLostError } from "./run-fence"
|
|
10
|
+
import type { AgentRunSession } from "./run-session"
|
|
11
|
+
import {
|
|
12
|
+
AGENT_RUN_STOPPED_HEADER,
|
|
13
|
+
agentRunSessionPath,
|
|
14
|
+
decodeWireError,
|
|
15
|
+
decodeWireValue,
|
|
16
|
+
encodeWireValue,
|
|
17
|
+
type WireError,
|
|
18
|
+
} from "./run-session-wire"
|
|
19
|
+
|
|
20
|
+
// A run's session as a runner reaches it over HTTP: the same operations as the in-process session,
|
|
21
|
+
// each one request with the runner token its claim returned (see serveAgentRunSession). The runner
|
|
22
|
+
// holds no storage, broker or project: a cancel reaches it at its lease renewals, which it makes
|
|
23
|
+
// itself. Its sandbox gets the run token instead, which never reaches this session.
|
|
24
|
+
|
|
25
|
+
/** How live records go up: gathered for this long, then sent together. */
|
|
26
|
+
const EVENT_BATCH_MS = 100
|
|
27
|
+
|
|
28
|
+
export interface HttpAgentRunSessionInput<TRun extends AgentRunRecord> {
|
|
29
|
+
/** The API's origin, such as `https://api.example.com`. */
|
|
30
|
+
readonly apiUrl: string
|
|
31
|
+
/** The runner token its claim returned, which every request carries. */
|
|
32
|
+
readonly runnerToken: string
|
|
33
|
+
/** The run as its claim left it. */
|
|
34
|
+
readonly run: TRun
|
|
35
|
+
/** Sends a request; defaults to `fetch`. */
|
|
36
|
+
readonly fetch?: (request: Request) => Promise<Response>
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function createHttpAgentRunSession<TRun extends AgentRunRecord>(
|
|
40
|
+
input: HttpAgentRunSessionInput<TRun>
|
|
41
|
+
): AgentRunSession<TRun> {
|
|
42
|
+
const { run } = input
|
|
43
|
+
const executionToken = run.execution?.token
|
|
44
|
+
if (!executionToken) {
|
|
45
|
+
throw new Error(`[Sixb] Agent run '${run.id}' has no execution token, so it was never claimed.`)
|
|
46
|
+
}
|
|
47
|
+
const send = input.fetch ?? ((request: Request) => fetch(request))
|
|
48
|
+
const cancelled = new AbortController()
|
|
49
|
+
// A cancel recorded before the claim: the run stops before it starts.
|
|
50
|
+
if (run.cancelRequestedAt) cancelled.abort()
|
|
51
|
+
|
|
52
|
+
const request = async (
|
|
53
|
+
operation: string,
|
|
54
|
+
init: RequestInit & { readonly query?: string } = {}
|
|
55
|
+
) => {
|
|
56
|
+
const url = new URL(
|
|
57
|
+
`${agentRunSessionPath(run.id, operation)}${init.query ?? ""}`,
|
|
58
|
+
input.apiUrl
|
|
59
|
+
)
|
|
60
|
+
const response = await send(
|
|
61
|
+
new Request(url, {
|
|
62
|
+
...init,
|
|
63
|
+
headers: { authorization: `Bearer ${input.runnerToken}`, ...(init.headers ?? {}) },
|
|
64
|
+
})
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
// The run was stopped: this runner hears it now rather than at its next renewal.
|
|
68
|
+
if (response.headers.has(AGENT_RUN_STOPPED_HEADER)) cancelled.abort()
|
|
69
|
+
return response
|
|
70
|
+
}
|
|
71
|
+
const call = async <T>(
|
|
72
|
+
operation: string,
|
|
73
|
+
args: readonly unknown[] = [],
|
|
74
|
+
signal?: AbortSignal
|
|
75
|
+
): Promise<T> =>
|
|
76
|
+
result<T>(
|
|
77
|
+
await request(operation, {
|
|
78
|
+
method: "POST",
|
|
79
|
+
headers: { "content-type": "application/json" },
|
|
80
|
+
body: encodeWireValue({ args }),
|
|
81
|
+
...(signal === undefined ? {} : { signal }),
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
const models = new Map<string, Promise<LanguageModel>>()
|
|
86
|
+
const sink = batchedEvents(async (batch) => {
|
|
87
|
+
try {
|
|
88
|
+
await result(
|
|
89
|
+
await request("events", {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: { "content-type": "application/json" },
|
|
92
|
+
body: encodeWireValue({ events: batch }),
|
|
93
|
+
})
|
|
94
|
+
)
|
|
95
|
+
} catch (error) {
|
|
96
|
+
// A stopped run's live records are refused: its end is the record.
|
|
97
|
+
if (cancelled.signal.aborted) return
|
|
98
|
+
console.error(`[Sixb] Live records of agent run '${run.id}' could not be sent.`, error)
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
const session: AgentRunSession = {
|
|
103
|
+
run,
|
|
104
|
+
executionToken,
|
|
105
|
+
cancelled: cancelled.signal,
|
|
106
|
+
models: {
|
|
107
|
+
language(ref) {
|
|
108
|
+
const key = `${ref.provider}/${ref.modelId}`
|
|
109
|
+
let model = models.get(key)
|
|
110
|
+
if (!model) {
|
|
111
|
+
model = call<Omit<LanguageModel, "stream">>("models.describe", [ref]).then((described) =>
|
|
112
|
+
httpModel(described, ref, request)
|
|
113
|
+
)
|
|
114
|
+
model.catch(() => models.delete(key))
|
|
115
|
+
models.set(key, model)
|
|
116
|
+
}
|
|
117
|
+
return model
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
events: sink.sink,
|
|
121
|
+
heldCalls: {
|
|
122
|
+
holdsRun: () => call("heldCalls.holdsRun"),
|
|
123
|
+
pausesAfterStep: () => call("heldCalls.pausesAfterStep"),
|
|
124
|
+
},
|
|
125
|
+
children: {
|
|
126
|
+
get: (runId) => call("children.get", [runId]),
|
|
127
|
+
getMany: (runIds) => call("children.getMany", [runIds]),
|
|
128
|
+
inConversation: (filter) => call("children.inConversation", [filter]),
|
|
129
|
+
threadRuns: (threadId) => call("children.threadRuns", [threadId]),
|
|
130
|
+
approvals: (runId) => call("children.approvals", [runId]),
|
|
131
|
+
holdsRun: (runId) => call("children.holdsRun", [runId]),
|
|
132
|
+
awaitingApproval: (runIds) => call("children.awaitingApproval", [runIds]),
|
|
133
|
+
activeCount: () => call("children.activeCount"),
|
|
134
|
+
spawn: (draft) => call("children.spawn", [draft]),
|
|
135
|
+
clearAttempt: (attempt) => call("children.clearAttempt", [attempt]),
|
|
136
|
+
},
|
|
137
|
+
async renewLease(leaseExpiresAt) {
|
|
138
|
+
try {
|
|
139
|
+
const renewed = await call<{ readonly cancelled: boolean }>("renewLease", [leaseExpiresAt])
|
|
140
|
+
if (renewed.cancelled) cancelled.abort()
|
|
141
|
+
} catch (error) {
|
|
142
|
+
// Ended or taken over: this runner stops now, as an in-process one does.
|
|
143
|
+
if (error instanceof AgentExecutionLostError) cancelled.abort(error)
|
|
144
|
+
throw error
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
async finish(outcome, messages) {
|
|
148
|
+
// What it streamed goes first; the server announces the end it records.
|
|
149
|
+
await sink.flush()
|
|
150
|
+
const finished = await call<AgentRunRecord>("finish", [outcome, messages])
|
|
151
|
+
sink.end()
|
|
152
|
+
return finished
|
|
153
|
+
},
|
|
154
|
+
assertOwned: () => call("assertOwned"),
|
|
155
|
+
plan: () => call("plan"),
|
|
156
|
+
memory: (memory) => call("memory", [memory]),
|
|
157
|
+
context: () => call("context"),
|
|
158
|
+
checkpoint: (checkpoint) => call("checkpoint", [checkpoint]),
|
|
159
|
+
workspace: {
|
|
160
|
+
async transition() {
|
|
161
|
+
throw new Error(
|
|
162
|
+
`[Sixb] Agent run '${run.id}' reaches its project over HTTP: only a runner in the worker moves a persistent workspace.`
|
|
163
|
+
)
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
threads: {
|
|
167
|
+
message: (messageId) => call("threads.message", [messageId]),
|
|
168
|
+
messages: (query) => call("threads.messages", [query]),
|
|
169
|
+
},
|
|
170
|
+
callTool: (toolCall, { signal, maxFileBytes }) =>
|
|
171
|
+
call("callTool", [toolCall, maxFileBytes === undefined ? {} : { maxFileBytes }], signal),
|
|
172
|
+
artifacts: {
|
|
173
|
+
list: (query) => call("artifacts.list", [query]),
|
|
174
|
+
getVersion: (...args) => call("artifacts.getVersion", args),
|
|
175
|
+
listVersions: (...args) => call("artifacts.listVersions", args),
|
|
176
|
+
query: (...args) => call("artifacts.query", args),
|
|
177
|
+
updatable: (artifactId) => call("artifacts.updatable", [artifactId]),
|
|
178
|
+
publish: (publish) => call("artifacts.publish", [publish]),
|
|
179
|
+
},
|
|
180
|
+
files: {
|
|
181
|
+
async put(file) {
|
|
182
|
+
const body = new Uint8Array(await new Response(file.body as BodyInit).arrayBuffer())
|
|
183
|
+
const query = new URLSearchParams()
|
|
184
|
+
if (file.fileName !== undefined) query.set("fileName", file.fileName)
|
|
185
|
+
if (file.mediaType !== undefined) query.set("mediaType", file.mediaType)
|
|
186
|
+
if (file.logicalPath !== undefined) query.set("logicalPath", file.logicalPath)
|
|
187
|
+
if (file.expectedSizeBytes !== undefined) query.set("size", String(file.expectedSizeBytes))
|
|
188
|
+
return result<FileRef>(
|
|
189
|
+
await request("files.put", {
|
|
190
|
+
method: "POST",
|
|
191
|
+
body,
|
|
192
|
+
query: `?${query}`,
|
|
193
|
+
...(file.signal === undefined ? {} : { signal: file.signal }),
|
|
194
|
+
})
|
|
195
|
+
)
|
|
196
|
+
},
|
|
197
|
+
async open(blobId) {
|
|
198
|
+
const response = await request("files.open", {
|
|
199
|
+
method: "GET",
|
|
200
|
+
query: `?${new URLSearchParams({ blobId })}`,
|
|
201
|
+
})
|
|
202
|
+
if (!response.ok || !response.body) await result(response)
|
|
203
|
+
return response.body as ReadableStream<Uint8Array>
|
|
204
|
+
},
|
|
205
|
+
stat: (blobId) => call("files.stat", [blobId]),
|
|
206
|
+
},
|
|
207
|
+
authorization() {
|
|
208
|
+
throw new Error(
|
|
209
|
+
`[Sixb] Agent run '${run.id}' reaches its project over HTTP: its runner holds no authority of its own.`
|
|
210
|
+
)
|
|
211
|
+
},
|
|
212
|
+
async close() {
|
|
213
|
+
await sink.flush()
|
|
214
|
+
},
|
|
215
|
+
}
|
|
216
|
+
return session as AgentRunSession<TRun>
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** What a claim answers: the claimed run, and the runner token its session's requests carry. */
|
|
220
|
+
interface ClaimedRun<TRun extends AgentRunRecord> {
|
|
221
|
+
readonly run: TRun
|
|
222
|
+
readonly runnerToken: string
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Claim a queued conversation turn as its requester, with their signed-in session (`authorization`,
|
|
227
|
+
* such as `Bearer <session token>` from the CLI's sign-in: the route refuses access tokens), and
|
|
228
|
+
* open its session. Null when the run ended or another runner holds it; refused when its runner
|
|
229
|
+
* stopped, which ended it interrupted.
|
|
230
|
+
*/
|
|
231
|
+
export async function claimAgentRunOverHttp(input: {
|
|
232
|
+
readonly apiUrl: string
|
|
233
|
+
readonly runId: string
|
|
234
|
+
readonly authorization: string
|
|
235
|
+
readonly leaseExpiresAt: string
|
|
236
|
+
/** The computer claiming it: a computer's turn runs only on the one that runs its thread. */
|
|
237
|
+
readonly computerId?: string
|
|
238
|
+
readonly fetch?: (request: Request) => Promise<Response>
|
|
239
|
+
}): Promise<AgentRunSession<ConversationAgentRunRecord> | null> {
|
|
240
|
+
const send = input.fetch ?? ((request: Request) => fetch(request))
|
|
241
|
+
const response = await send(
|
|
242
|
+
new Request(new URL(`/api/agent-runs/${encodeURIComponent(input.runId)}/claim`, input.apiUrl), {
|
|
243
|
+
method: "POST",
|
|
244
|
+
headers: { authorization: input.authorization, "content-type": "application/json" },
|
|
245
|
+
body: encodeWireValue({
|
|
246
|
+
leaseExpiresAt: input.leaseExpiresAt,
|
|
247
|
+
...(input.computerId === undefined ? {} : { computerId: input.computerId }),
|
|
248
|
+
}),
|
|
249
|
+
})
|
|
250
|
+
)
|
|
251
|
+
const claimed = await result<ClaimedRun<ConversationAgentRunRecord> | null>(response)
|
|
252
|
+
return claimed && createHttpAgentRunSession({ ...input, ...claimed })
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Claim a child of a turn this runner runs, with the turn's runner token: the runner runs its
|
|
257
|
+
* turns' children itself. Null when the child ended or another runner holds it.
|
|
258
|
+
*/
|
|
259
|
+
export async function claimAgentRunChildOverHttp(
|
|
260
|
+
turn: HttpAgentRunSessionInput<ConversationAgentRunRecord>,
|
|
261
|
+
input: { readonly childRunId: string; readonly leaseExpiresAt: string }
|
|
262
|
+
): Promise<AgentRunSession<SubagentRunRecord> | null> {
|
|
263
|
+
const send = turn.fetch ?? ((request: Request) => fetch(request))
|
|
264
|
+
const response = await send(
|
|
265
|
+
new Request(new URL(agentRunSessionPath(turn.run.id, "children.claim"), turn.apiUrl), {
|
|
266
|
+
method: "POST",
|
|
267
|
+
headers: {
|
|
268
|
+
authorization: `Bearer ${turn.runnerToken}`,
|
|
269
|
+
"content-type": "application/json",
|
|
270
|
+
},
|
|
271
|
+
body: encodeWireValue({ args: [input.childRunId, input.leaseExpiresAt] }),
|
|
272
|
+
})
|
|
273
|
+
)
|
|
274
|
+
const claimed = await result<ClaimedRun<SubagentRunRecord> | null>(response)
|
|
275
|
+
return (
|
|
276
|
+
claimed &&
|
|
277
|
+
createHttpAgentRunSession({
|
|
278
|
+
apiUrl: turn.apiUrl,
|
|
279
|
+
...claimed,
|
|
280
|
+
...(turn.fetch === undefined ? {} : { fetch: turn.fetch }),
|
|
281
|
+
})
|
|
282
|
+
)
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
/** Read an operation's answer: its result, or the error it crossed as. */
|
|
286
|
+
async function result<T>(response: Response): Promise<T> {
|
|
287
|
+
const text = await response.text()
|
|
288
|
+
let body: { readonly result?: unknown; readonly error?: WireError }
|
|
289
|
+
try {
|
|
290
|
+
body = decodeWireValue(text) as typeof body
|
|
291
|
+
} catch {
|
|
292
|
+
throw new Error(`[Sixb] The run session answered ${response.status} without a session body.`)
|
|
293
|
+
}
|
|
294
|
+
if (body.error) throw decodeWireError(body.error)
|
|
295
|
+
return body.result as T
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/** A model the server serves: its description here, each call admitted and recorded there. */
|
|
299
|
+
function httpModel(
|
|
300
|
+
described: Omit<LanguageModel, "stream">,
|
|
301
|
+
ref: Parameters<AgentRunSession["models"]["language"]>[0],
|
|
302
|
+
request: (operation: string, init: RequestInit) => Promise<Response>
|
|
303
|
+
): LanguageModel {
|
|
304
|
+
return {
|
|
305
|
+
...described,
|
|
306
|
+
async stream({ signal, ...call }) {
|
|
307
|
+
const response = await request("models.stream", {
|
|
308
|
+
method: "POST",
|
|
309
|
+
headers: { "content-type": "application/json" },
|
|
310
|
+
body: encodeWireValue({ ref, call }),
|
|
311
|
+
signal,
|
|
312
|
+
})
|
|
313
|
+
if (!response.ok || !response.body) await result(response)
|
|
314
|
+
return { events: modelEvents(response.body as ReadableStream<Uint8Array>) }
|
|
315
|
+
},
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/** The provider's events, as the server streams them: one JSON line each. */
|
|
320
|
+
async function* modelEvents(
|
|
321
|
+
body: ReadableStream<Uint8Array>
|
|
322
|
+
): AsyncGenerator<LanguageModelStreamEvent> {
|
|
323
|
+
const reader = body.getReader()
|
|
324
|
+
const decoder = new TextDecoder()
|
|
325
|
+
let buffered = ""
|
|
326
|
+
try {
|
|
327
|
+
for (;;) {
|
|
328
|
+
const { value, done } = await reader.read()
|
|
329
|
+
if (done) break
|
|
330
|
+
buffered += decoder.decode(value, { stream: true })
|
|
331
|
+
let newline = buffered.indexOf("\n")
|
|
332
|
+
while (newline >= 0) {
|
|
333
|
+
const line = buffered.slice(0, newline)
|
|
334
|
+
buffered = buffered.slice(newline + 1)
|
|
335
|
+
if (line) {
|
|
336
|
+
const decoded = decodeWireValue(line) as {
|
|
337
|
+
readonly event?: LanguageModelStreamEvent
|
|
338
|
+
readonly error?: WireError
|
|
339
|
+
}
|
|
340
|
+
if (decoded.error) throw decodeWireError(decoded.error)
|
|
341
|
+
if (decoded.event) yield decoded.event
|
|
342
|
+
}
|
|
343
|
+
newline = buffered.indexOf("\n")
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} finally {
|
|
347
|
+
// A reader that stops early closes the request, and the server reports the call unfinished.
|
|
348
|
+
await reader.cancel().catch(() => {})
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/**
|
|
353
|
+
* A sink that sends its records in batches: each method returns once its record is queued, as
|
|
354
|
+
* live records are best effort. A run's end is sent at once, with what came before it.
|
|
355
|
+
*/
|
|
356
|
+
function batchedEvents(
|
|
357
|
+
deliver: (batch: readonly { readonly method: string; readonly input: unknown }[]) => Promise<void>
|
|
358
|
+
): { readonly sink: StreamSink; flush(): Promise<void>; end(): void } {
|
|
359
|
+
let queued: { readonly method: string; readonly input: unknown }[] = []
|
|
360
|
+
// Once the run ended, its token reaches nothing: the server announced the end.
|
|
361
|
+
let ended = false
|
|
362
|
+
let timer: ReturnType<typeof setTimeout> | undefined
|
|
363
|
+
let sending = Promise.resolve()
|
|
364
|
+
const flush = () => {
|
|
365
|
+
clearTimeout(timer)
|
|
366
|
+
timer = undefined
|
|
367
|
+
const batch = queued
|
|
368
|
+
queued = []
|
|
369
|
+
if (batch.length > 0) sending = sending.then(() => deliver(batch))
|
|
370
|
+
return sending
|
|
371
|
+
}
|
|
372
|
+
const enqueue = (method: string) => async (record: unknown) => {
|
|
373
|
+
if (ended) return
|
|
374
|
+
queued.push({ method, input: record })
|
|
375
|
+
timer ??= setTimeout(() => void flush(), EVENT_BATCH_MS)
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
sink: {
|
|
379
|
+
publishStarted: enqueue("publishStarted"),
|
|
380
|
+
publishCompactionStarted: enqueue("publishCompactionStarted"),
|
|
381
|
+
publishCompactionCompleted: enqueue("publishCompactionCompleted"),
|
|
382
|
+
publishCompactionFailed: enqueue("publishCompactionFailed"),
|
|
383
|
+
publishUiChunk: enqueue("publishUiChunk"),
|
|
384
|
+
publishMessageFinalized: enqueue("publishMessageFinalized"),
|
|
385
|
+
async publishRunFinished(record) {
|
|
386
|
+
await enqueue("publishRunFinished")(record)
|
|
387
|
+
await flush()
|
|
388
|
+
},
|
|
389
|
+
},
|
|
390
|
+
flush,
|
|
391
|
+
end() {
|
|
392
|
+
ended = true
|
|
393
|
+
clearTimeout(timer)
|
|
394
|
+
queued = []
|
|
395
|
+
},
|
|
396
|
+
}
|
|
397
|
+
}
|