@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,257 @@
|
|
|
1
|
+
import { ArtifactRequestError } from "../artifacts/errors"
|
|
2
|
+
import {
|
|
3
|
+
type ArtifactsRuntime,
|
|
4
|
+
artifactAccessRule,
|
|
5
|
+
artifactQueryChecker,
|
|
6
|
+
} from "../artifacts/execution"
|
|
7
|
+
import type { ArtifactKind } from "../artifacts/kinds"
|
|
8
|
+
import {
|
|
9
|
+
artifactVersionWarnings,
|
|
10
|
+
type PublishedArtifact,
|
|
11
|
+
prepareArtifactVersion,
|
|
12
|
+
storeArtifactVersion,
|
|
13
|
+
} from "../artifacts/publish/publish"
|
|
14
|
+
import { type Principal, principalsEqual } from "../auth/types"
|
|
15
|
+
import type { Sixb } from "../runtime/sixb"
|
|
16
|
+
import type { Storage } from "../storage"
|
|
17
|
+
import type { AgentStorage, ConversationAgentRunRecord, SubagentRunRecord } from "../storage/agents"
|
|
18
|
+
import type { ArtifactFile, ArtifactRecord } from "../storage/artifacts/types"
|
|
19
|
+
import { assertAgentRunOwned } from "./run-fence"
|
|
20
|
+
import { conversationThreadId } from "./thread-access"
|
|
21
|
+
|
|
22
|
+
// A run's artifacts are its conversation's. It reads them as its requester, and what it publishes
|
|
23
|
+
// lands in the conversation, owned by the conversation's owner. The worker reaches this through the
|
|
24
|
+
// run's session; the API, for a request with the run's token. Both apply the same rules here.
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* What a run reads and publishes of artifacts, as its requester: it lists its conversation's, reads
|
|
28
|
+
* any its requester reads, and publishes into its conversation.
|
|
29
|
+
*/
|
|
30
|
+
export interface AgentRunArtifacts {
|
|
31
|
+
/** The artifacts the conversation shares, most recently updated first. */
|
|
32
|
+
list(input: { readonly limit: number }): Promise<readonly ArtifactRecord[]>
|
|
33
|
+
getVersion: ArtifactsRuntime["getVersion"]
|
|
34
|
+
listVersions: ArtifactsRuntime["listVersions"]
|
|
35
|
+
query: ArtifactsRuntime["query"]
|
|
36
|
+
/**
|
|
37
|
+
* The artifact, when the run may publish its next version: its requester owns it, or the
|
|
38
|
+
* conversation shares it and they take part. Another is `null`, even one they could update from
|
|
39
|
+
* another conversation: publishing here would share it in this one.
|
|
40
|
+
*/
|
|
41
|
+
updatable(artifactId: string): Promise<ArtifactRecord | null>
|
|
42
|
+
/**
|
|
43
|
+
* Publish as the run: a new artifact owned by the conversation's owner, or the next version of an
|
|
44
|
+
* updatable one, authored by the requester, with the run and its conversation as origin. Nothing
|
|
45
|
+
* is stored once the run lost its execution ({@link AgentExecutionLostError}), or a child's
|
|
46
|
+
* parent ended. Refusals are {@link ArtifactRequestError}s.
|
|
47
|
+
*/
|
|
48
|
+
publish(input: AgentRunArtifactPublish): Promise<PublishedArtifact>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A version a run publishes: of a new artifact of `kind`, or of the artifact `artifactId`. */
|
|
52
|
+
export type AgentRunArtifactPublish = {
|
|
53
|
+
readonly title: string
|
|
54
|
+
readonly files: readonly ArtifactFile[]
|
|
55
|
+
} & (
|
|
56
|
+
| { readonly kind: ArtifactKind }
|
|
57
|
+
| {
|
|
58
|
+
readonly artifactId: string
|
|
59
|
+
/** The artifact's kind, when the caller names one: another is refused. */
|
|
60
|
+
readonly kind?: ArtifactKind
|
|
61
|
+
/** The version this one was made from: publishing fails with `artifact_moved` past it. */
|
|
62
|
+
readonly baseVersion?: number
|
|
63
|
+
}
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
export interface AgentRunArtifactsHost {
|
|
67
|
+
readonly projectId: string
|
|
68
|
+
readonly storage: Storage
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** The SDK a run acts through, bound to its execution: as its requester. */
|
|
72
|
+
export type AgentRunSdk = Pick<Sixb, "artifacts" | "blobs" | "execution">
|
|
73
|
+
|
|
74
|
+
/** The run that publishes: a conversation's turn, or a child of one. */
|
|
75
|
+
export type AgentRunArtifactsRun =
|
|
76
|
+
| Pick<ConversationAgentRunRecord, "id" | "projectId" | "kind" | "threadId">
|
|
77
|
+
| Pick<SubagentRunRecord, "id" | "projectId" | "kind" | "threadId" | "parentRunId">
|
|
78
|
+
|
|
79
|
+
export function agentRunArtifacts(
|
|
80
|
+
host: AgentRunArtifactsHost,
|
|
81
|
+
run: AgentRunArtifactsRun,
|
|
82
|
+
executionToken: string,
|
|
83
|
+
sdk: () => Promise<AgentRunSdk>
|
|
84
|
+
): AgentRunArtifacts {
|
|
85
|
+
const { projectId, storage } = host
|
|
86
|
+
let publisher: Promise<Publisher> | undefined
|
|
87
|
+
const publisherOf = () => {
|
|
88
|
+
publisher ??= readPublisher(host, run).catch((error: unknown) => {
|
|
89
|
+
publisher = undefined
|
|
90
|
+
throw error
|
|
91
|
+
})
|
|
92
|
+
return publisher
|
|
93
|
+
}
|
|
94
|
+
const fence = { projectId, id: run.id, executionToken }
|
|
95
|
+
|
|
96
|
+
const updatable = async (artifactId: string): Promise<ArtifactRecord | null> => {
|
|
97
|
+
const [{ threadId }, { artifacts: reader }] = await Promise.all([publisherOf(), sdk()])
|
|
98
|
+
const artifact = await requireArtifacts(storage).get({ projectId, id: artifactId })
|
|
99
|
+
if (!artifact) return null
|
|
100
|
+
const access = await artifactAccessRule(reader, storage).publishAccess(artifact, threadId)
|
|
101
|
+
return access === "owner" || access === "update" ? artifact : null
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
async list({ limit }) {
|
|
106
|
+
const [{ threadId }, { artifacts }] = await Promise.all([publisherOf(), sdk()])
|
|
107
|
+
return (await artifacts.list({ threadId, limit })).artifacts
|
|
108
|
+
},
|
|
109
|
+
getVersion: async (...args) => (await sdk()).artifacts.getVersion(...args),
|
|
110
|
+
listVersions: async (...args) => (await sdk()).artifacts.listVersions(...args),
|
|
111
|
+
query: async (...args) => (await sdk()).artifacts.query(...args),
|
|
112
|
+
updatable,
|
|
113
|
+
|
|
114
|
+
async publish(input) {
|
|
115
|
+
const [{ threadId, owner }, { artifacts: reader, blobs, execution }] = await Promise.all([
|
|
116
|
+
publisherOf(),
|
|
117
|
+
sdk(),
|
|
118
|
+
])
|
|
119
|
+
// Whoever asked for the turn is each version's author.
|
|
120
|
+
const author = execution.requestedBy ?? owner
|
|
121
|
+
await assertAgentRunOwned(requireAgents(storage), fence)
|
|
122
|
+
|
|
123
|
+
let kind = input.kind
|
|
124
|
+
if ("artifactId" in input) {
|
|
125
|
+
const artifact = await updatable(input.artifactId)
|
|
126
|
+
if (!artifact) {
|
|
127
|
+
throw new ArtifactRequestError(
|
|
128
|
+
"artifact_not_found",
|
|
129
|
+
`[Sixb] There is no artifact '${input.artifactId}' in this conversation.`
|
|
130
|
+
)
|
|
131
|
+
}
|
|
132
|
+
kind ??= artifact.kind
|
|
133
|
+
}
|
|
134
|
+
if (!kind) throw new Error("[Sixb] A new artifact needs a kind.")
|
|
135
|
+
|
|
136
|
+
// Validation reads the files back and parses them, so it runs before the transaction, which
|
|
137
|
+
// checks again that the run holds its conversation and the requester may still publish.
|
|
138
|
+
const context = { projectId, storage: requireArtifacts(storage), blobStorage: blobs }
|
|
139
|
+
const reading = artifactAccessRule(reader, storage)
|
|
140
|
+
const prepared = await prepareArtifactVersion(context, {
|
|
141
|
+
...("artifactId" in input
|
|
142
|
+
? {
|
|
143
|
+
artifactId: input.artifactId,
|
|
144
|
+
...(input.baseVersion === undefined ? {} : { baseVersion: input.baseVersion }),
|
|
145
|
+
}
|
|
146
|
+
: {}),
|
|
147
|
+
kind,
|
|
148
|
+
title: input.title,
|
|
149
|
+
files: input.files,
|
|
150
|
+
author,
|
|
151
|
+
owner,
|
|
152
|
+
readable: async (artifact) => (await reading.accessTo(artifact)) !== "none",
|
|
153
|
+
// As the requester, so a query never reads what they cannot.
|
|
154
|
+
checkQuery: artifactQueryChecker(reader),
|
|
155
|
+
origin: { threadId, runId: run.id },
|
|
156
|
+
})
|
|
157
|
+
const stored = await storage.transaction(async (tx) => {
|
|
158
|
+
await assertAgentRunOwned(requireAgents(tx), fence)
|
|
159
|
+
if (run.kind === "subagent") await assertParentActive(requireAgents(tx), run)
|
|
160
|
+
if (execution.requestedBy) {
|
|
161
|
+
await assertTakesPart(
|
|
162
|
+
requireAgents(tx),
|
|
163
|
+
{ projectId, threadId, owner },
|
|
164
|
+
execution.requestedBy
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
// The owner may have deleted it since, or removed the requester from the conversation.
|
|
168
|
+
return storeArtifactVersion(
|
|
169
|
+
{ ...context, storage: requireArtifacts(tx) },
|
|
170
|
+
prepared,
|
|
171
|
+
(each) => artifactAccessRule(reader, tx).publishAccess(each, threadId)
|
|
172
|
+
)
|
|
173
|
+
})
|
|
174
|
+
return { ...stored, warnings: await artifactVersionWarnings(context, prepared, stored) }
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface Publisher {
|
|
180
|
+
/** The conversation's thread: a child publishes into its parent's. */
|
|
181
|
+
readonly threadId: string
|
|
182
|
+
/** The conversation's owner, who owns what the run creates. */
|
|
183
|
+
readonly owner: Principal
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
async function readPublisher(
|
|
187
|
+
host: AgentRunArtifactsHost,
|
|
188
|
+
run: AgentRunArtifactsRun
|
|
189
|
+
): Promise<Publisher> {
|
|
190
|
+
const { projectId } = host
|
|
191
|
+
const agents = requireAgents(host.storage)
|
|
192
|
+
const thread = await agents.threads.getById({ projectId, id: run.threadId })
|
|
193
|
+
const conversation =
|
|
194
|
+
thread && run.kind === "subagent"
|
|
195
|
+
? await agents.threads.getById({ projectId, id: conversationThreadId(thread) })
|
|
196
|
+
: thread
|
|
197
|
+
if (!conversation) {
|
|
198
|
+
throw new ArtifactRequestError(
|
|
199
|
+
"not_allowed",
|
|
200
|
+
`[Sixb] Agent run '${run.id}' has no conversation to publish artifacts in.`
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
return { threadId: conversation.id, owner: conversation.ownerPrincipal }
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** The requester may have been removed from the conversation while the run went on. */
|
|
207
|
+
async function assertTakesPart(
|
|
208
|
+
agents: AgentStorage,
|
|
209
|
+
conversation: {
|
|
210
|
+
readonly projectId: string
|
|
211
|
+
readonly threadId: string
|
|
212
|
+
readonly owner: Principal
|
|
213
|
+
},
|
|
214
|
+
requester: Principal
|
|
215
|
+
): Promise<void> {
|
|
216
|
+
if (principalsEqual(requester, conversation.owner)) return
|
|
217
|
+
const participants = await agents.threads.listParticipants({
|
|
218
|
+
projectId: conversation.projectId,
|
|
219
|
+
threadIds: [conversation.threadId],
|
|
220
|
+
})
|
|
221
|
+
if (participants.some((participant) => principalsEqual(participant.principal, requester))) return
|
|
222
|
+
throw new ArtifactRequestError(
|
|
223
|
+
"not_allowed",
|
|
224
|
+
"[Sixb] The requester no longer takes part in this conversation, so nothing was published."
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
async function assertParentActive(
|
|
229
|
+
agents: AgentStorage,
|
|
230
|
+
run: Extract<AgentRunArtifactsRun, { readonly kind: "subagent" }>
|
|
231
|
+
): Promise<void> {
|
|
232
|
+
const parent = await agents.runs.getById({ projectId: run.projectId, id: run.parentRunId })
|
|
233
|
+
// A cancel recorded on the parent ends it, as the run token already reads it.
|
|
234
|
+
if ((parent?.status === "queued" || parent?.status === "running") && !parent.cancelRequestedAt) {
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
throw new ArtifactRequestError(
|
|
239
|
+
"not_allowed",
|
|
240
|
+
"[Sixb] The parent Agent run has ended, so nothing was published."
|
|
241
|
+
)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function requireArtifacts(storage: Storage) {
|
|
245
|
+
if (!storage.artifacts) {
|
|
246
|
+
throw new ArtifactRequestError(
|
|
247
|
+
"storage_unavailable",
|
|
248
|
+
"[Sixb] Artifacts need storage that supports them."
|
|
249
|
+
)
|
|
250
|
+
}
|
|
251
|
+
return storage.artifacts
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function requireAgents(storage: Storage): AgentStorage {
|
|
255
|
+
if (!storage.agents) throw new Error("[Sixb] Agent runs need storage that holds them.")
|
|
256
|
+
return storage.agents
|
|
257
|
+
}
|
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import type { Broker } from "../broker"
|
|
2
|
+
import { createSixbError } from "../errors/internal"
|
|
3
|
+
import type { JsonValue } from "../json"
|
|
4
|
+
import type {
|
|
5
|
+
AgentContextCheckpointReason,
|
|
6
|
+
AgentRunRecord,
|
|
7
|
+
ConversationAgentRunRecord,
|
|
8
|
+
} from "../storage/agents"
|
|
9
|
+
import type { AgentCompactionFailureCode, AgentRunStreamEvent, ModelUiChunk } from "./streams"
|
|
10
|
+
import {
|
|
11
|
+
agentRunFinishedEvent,
|
|
12
|
+
agentRunStreamDefinition,
|
|
13
|
+
agentRunStreamEventBase,
|
|
14
|
+
agentRunStreamId,
|
|
15
|
+
agentRunStreamIdempotencyKey,
|
|
16
|
+
publishAgentRunActivity,
|
|
17
|
+
} from "./streams/protocol"
|
|
18
|
+
|
|
19
|
+
export interface CompactionStartedInput {
|
|
20
|
+
readonly run: ConversationAgentRunRecord
|
|
21
|
+
readonly reason: AgentContextCheckpointReason
|
|
22
|
+
readonly estimatedInputTokensBefore: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface CompactionCompletedInput extends CompactionStartedInput {
|
|
26
|
+
readonly checkpointId: string
|
|
27
|
+
readonly estimatedInputTokensAfter: number
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface CompactionFailedInput {
|
|
31
|
+
readonly run: ConversationAgentRunRecord
|
|
32
|
+
readonly reason: AgentContextCheckpointReason
|
|
33
|
+
readonly errorCode: AgentCompactionFailureCode
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Receives live and lifecycle records for one agent run stream. */
|
|
37
|
+
export interface StreamSink {
|
|
38
|
+
publishStarted(run: AgentRunRecord): Promise<void>
|
|
39
|
+
publishCompactionStarted(input: CompactionStartedInput): Promise<void>
|
|
40
|
+
publishCompactionCompleted(input: CompactionCompletedInput): Promise<void>
|
|
41
|
+
publishCompactionFailed(input: CompactionFailedInput): Promise<void>
|
|
42
|
+
publishUiChunk(input: {
|
|
43
|
+
readonly run: AgentRunRecord
|
|
44
|
+
readonly chunkIndex: number
|
|
45
|
+
readonly chunk: ModelUiChunk
|
|
46
|
+
}): Promise<void>
|
|
47
|
+
publishMessageFinalized(input: {
|
|
48
|
+
readonly run: ConversationAgentRunRecord
|
|
49
|
+
readonly messageId: string
|
|
50
|
+
}): Promise<void>
|
|
51
|
+
publishRunFinished(run: AgentRunRecord): Promise<void>
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Test sink that keeps the worker running without publishing live stream records. */
|
|
55
|
+
export const NOOP_STREAM_SINK: StreamSink = {
|
|
56
|
+
async publishStarted() {},
|
|
57
|
+
async publishCompactionStarted() {},
|
|
58
|
+
async publishCompactionCompleted() {},
|
|
59
|
+
async publishCompactionFailed() {},
|
|
60
|
+
async publishUiChunk() {},
|
|
61
|
+
async publishMessageFinalized() {},
|
|
62
|
+
async publishRunFinished() {},
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Creates the default sink backed by Sixb's broker stream contract. */
|
|
66
|
+
export function createBrokerStreamSink(input: {
|
|
67
|
+
readonly broker: Broker
|
|
68
|
+
readonly projectId: string
|
|
69
|
+
}): StreamSink {
|
|
70
|
+
return new BrokerStreamSink(input.broker, input.projectId)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** Keeps stream delivery observational so sink failures never fail a turn. */
|
|
74
|
+
export function isolateStreamSink(sink: StreamSink): StreamSink {
|
|
75
|
+
return {
|
|
76
|
+
publishStarted: (run) =>
|
|
77
|
+
isolateStreamSinkCall(run.id, "started", () => sink.publishStarted(run)),
|
|
78
|
+
publishCompactionStarted: (input) =>
|
|
79
|
+
isolateStreamSinkCall(input.run.id, "compaction started", () =>
|
|
80
|
+
sink.publishCompactionStarted(input)
|
|
81
|
+
),
|
|
82
|
+
publishCompactionCompleted: (input) =>
|
|
83
|
+
isolateStreamSinkCall(input.run.id, "compaction completed", () =>
|
|
84
|
+
sink.publishCompactionCompleted(input)
|
|
85
|
+
),
|
|
86
|
+
publishCompactionFailed: (input) =>
|
|
87
|
+
isolateStreamSinkCall(input.run.id, "compaction failed", () =>
|
|
88
|
+
sink.publishCompactionFailed(input)
|
|
89
|
+
),
|
|
90
|
+
publishUiChunk: (input) =>
|
|
91
|
+
isolateStreamSinkCall(input.run.id, "ui chunk", () => sink.publishUiChunk(input)),
|
|
92
|
+
publishMessageFinalized: (input) =>
|
|
93
|
+
isolateStreamSinkCall(input.run.id, "message finalized", () =>
|
|
94
|
+
sink.publishMessageFinalized(input)
|
|
95
|
+
),
|
|
96
|
+
publishRunFinished: (run) =>
|
|
97
|
+
isolateStreamSinkCall(run.id, "run finished", () => sink.publishRunFinished(run)),
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Keep the lifecycle feed platform-owned even when callers replace transcript streaming: a
|
|
103
|
+
* conversation's on the project's activity feed.
|
|
104
|
+
*/
|
|
105
|
+
export function withAgentActivityStream(sink: StreamSink, broker: Broker): StreamSink {
|
|
106
|
+
return {
|
|
107
|
+
publishStarted: (run) =>
|
|
108
|
+
publishLifecycle([
|
|
109
|
+
sink.publishStarted(run),
|
|
110
|
+
...(run.kind === "conversation" ? [publishAgentRunActivity(broker, run)] : []),
|
|
111
|
+
]),
|
|
112
|
+
publishCompactionStarted: (input) => sink.publishCompactionStarted(input),
|
|
113
|
+
publishCompactionCompleted: (input) => sink.publishCompactionCompleted(input),
|
|
114
|
+
publishCompactionFailed: (input) => sink.publishCompactionFailed(input),
|
|
115
|
+
publishUiChunk: (input) => sink.publishUiChunk(input),
|
|
116
|
+
publishMessageFinalized: (input) => sink.publishMessageFinalized(input),
|
|
117
|
+
publishRunFinished: (run) =>
|
|
118
|
+
publishLifecycle([
|
|
119
|
+
sink.publishRunFinished(run),
|
|
120
|
+
...(run.kind === "conversation" ? [publishAgentRunActivity(broker, run)] : []),
|
|
121
|
+
]),
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function publishLifecycle(deliveries: readonly Promise<void>[]): Promise<void> {
|
|
126
|
+
const results = await Promise.allSettled(deliveries)
|
|
127
|
+
const failure = results.find((result) => result.status === "rejected")
|
|
128
|
+
if (failure?.status === "rejected") throw failure.reason
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class BrokerStreamSink implements StreamSink {
|
|
132
|
+
private readonly ensured = new Set<string>()
|
|
133
|
+
|
|
134
|
+
constructor(
|
|
135
|
+
private readonly broker: Broker,
|
|
136
|
+
private readonly projectId: string
|
|
137
|
+
) {}
|
|
138
|
+
|
|
139
|
+
async publishStarted(run: AgentRunRecord): Promise<void> {
|
|
140
|
+
await this.publish({
|
|
141
|
+
...agentRunStreamEventBase(run),
|
|
142
|
+
type: "agent.run.started",
|
|
143
|
+
...(run.modelId === undefined ? {} : { modelId: run.modelId }),
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
async publishCompactionStarted(input: CompactionStartedInput): Promise<void> {
|
|
148
|
+
await this.publish({
|
|
149
|
+
...agentRunStreamEventBase(input.run),
|
|
150
|
+
type: "agent.compaction.started",
|
|
151
|
+
reason: input.reason,
|
|
152
|
+
estimatedInputTokensBefore: input.estimatedInputTokensBefore,
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async publishCompactionCompleted(input: CompactionCompletedInput): Promise<void> {
|
|
157
|
+
await this.publish({
|
|
158
|
+
...agentRunStreamEventBase(input.run),
|
|
159
|
+
type: "agent.compaction.completed",
|
|
160
|
+
reason: input.reason,
|
|
161
|
+
checkpointId: input.checkpointId,
|
|
162
|
+
estimatedInputTokensBefore: input.estimatedInputTokensBefore,
|
|
163
|
+
estimatedInputTokensAfter: input.estimatedInputTokensAfter,
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
async publishCompactionFailed(input: CompactionFailedInput): Promise<void> {
|
|
168
|
+
await this.publish({
|
|
169
|
+
...agentRunStreamEventBase(input.run),
|
|
170
|
+
type: "agent.compaction.failed",
|
|
171
|
+
reason: input.reason,
|
|
172
|
+
errorCode: input.errorCode,
|
|
173
|
+
})
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Publishes one live UI chunk; awaited per chunk so broker backpressure throttles the token stream. */
|
|
177
|
+
async publishUiChunk(input: {
|
|
178
|
+
readonly run: AgentRunRecord
|
|
179
|
+
readonly chunkIndex: number
|
|
180
|
+
readonly chunk: ModelUiChunk
|
|
181
|
+
}): Promise<void> {
|
|
182
|
+
let chunk: ModelUiChunk
|
|
183
|
+
try {
|
|
184
|
+
// The round-trip keeps the chunk's shape: every field of a chunk is JSON by type.
|
|
185
|
+
chunk = toBrokerJson(input.chunk, "Agent stream chunk", {
|
|
186
|
+
runId: input.run.id,
|
|
187
|
+
}) as ModelUiChunk
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.error("[Sixb] Agent run stream chunk encoding failed:", error)
|
|
190
|
+
return
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// `chunk` is already validated JSON and every other field is a JSON primitive, so the event is
|
|
194
|
+
// JSON as-built. Publish it pre-validated so the chunk — the highest-frequency agent event, one
|
|
195
|
+
// per streamed token batch — is not serialized a second time inside `publish`.
|
|
196
|
+
await this.publish(
|
|
197
|
+
{
|
|
198
|
+
...agentRunStreamEventBase(input.run),
|
|
199
|
+
type: "agent.ui.chunk",
|
|
200
|
+
chunkIndex: input.chunkIndex,
|
|
201
|
+
chunk,
|
|
202
|
+
},
|
|
203
|
+
{ prevalidated: true }
|
|
204
|
+
)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
async publishMessageFinalized(input: {
|
|
208
|
+
readonly run: ConversationAgentRunRecord
|
|
209
|
+
readonly messageId: string
|
|
210
|
+
}): Promise<void> {
|
|
211
|
+
await this.publish({
|
|
212
|
+
...agentRunStreamEventBase(input.run),
|
|
213
|
+
type: "agent.message.finalized",
|
|
214
|
+
messageId: input.messageId,
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
async publishRunFinished(run: AgentRunRecord): Promise<void> {
|
|
219
|
+
if (run.status === "queued" || run.status === "running") {
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
await this.publish(agentRunFinishedEvent(run))
|
|
223
|
+
// This is the last event for the run, so drop its ensured-stream marker to bound the Set over a
|
|
224
|
+
// long-lived worker. Evict only after a successful append, and only on the terminal path.
|
|
225
|
+
this.ensured.delete(agentRunStreamId(run.id))
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
private async publish(
|
|
229
|
+
event: AgentRunStreamEvent,
|
|
230
|
+
options: { readonly prevalidated?: boolean } = {}
|
|
231
|
+
): Promise<void> {
|
|
232
|
+
await this.ensure(event.runId)
|
|
233
|
+
// Broker payloads are plain JSON; keep SDK-specific chunk shapes opaque at this boundary. A
|
|
234
|
+
// pre-validated event (its only opaque field, the chunk, was already encoded by the caller) is
|
|
235
|
+
// already JSON, so it is forwarded as-is instead of being serialized a second time.
|
|
236
|
+
const payload = options.prevalidated
|
|
237
|
+
? (event as unknown as JsonValue)
|
|
238
|
+
: toBrokerJson(event, "Agent stream event", {
|
|
239
|
+
runId: event.runId,
|
|
240
|
+
})
|
|
241
|
+
await this.broker.append({
|
|
242
|
+
projectId: this.projectId,
|
|
243
|
+
streamId: agentRunStreamId(event.runId),
|
|
244
|
+
records: [
|
|
245
|
+
{
|
|
246
|
+
name: event.type,
|
|
247
|
+
key: event.runId,
|
|
248
|
+
payload,
|
|
249
|
+
idempotencyKey: agentRunStreamIdempotencyKey(event),
|
|
250
|
+
},
|
|
251
|
+
],
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
private async ensure(runId: string): Promise<void> {
|
|
256
|
+
const streamId = agentRunStreamId(runId)
|
|
257
|
+
if (this.ensured.has(streamId)) {
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
await this.broker.ensureStream({
|
|
261
|
+
projectId: this.projectId,
|
|
262
|
+
stream: agentRunStreamDefinition(runId),
|
|
263
|
+
})
|
|
264
|
+
this.ensured.add(streamId)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
async function isolateStreamSinkCall(
|
|
269
|
+
runId: string,
|
|
270
|
+
label: string,
|
|
271
|
+
publish: () => Promise<void>
|
|
272
|
+
): Promise<void> {
|
|
273
|
+
try {
|
|
274
|
+
await publish()
|
|
275
|
+
} catch (error) {
|
|
276
|
+
console.error(`[Sixb] Agent run '${runId}' ${label} stream publish failed:`, error)
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function toBrokerJson(
|
|
281
|
+
value: unknown,
|
|
282
|
+
label: string,
|
|
283
|
+
details: { readonly runId: string }
|
|
284
|
+
): JsonValue {
|
|
285
|
+
try {
|
|
286
|
+
const serialized = JSON.stringify(value)
|
|
287
|
+
if (serialized === undefined) {
|
|
288
|
+
throw createSixbError("internal.unexpected", `[Sixb] ${label} serialized to undefined.`, {
|
|
289
|
+
details,
|
|
290
|
+
})
|
|
291
|
+
}
|
|
292
|
+
// The stringify/parse round-trip already yields a pure JSON value (functions/symbols/undefined
|
|
293
|
+
// are dropped or throw above, NaN/Infinity become null), so no further validation is needed —
|
|
294
|
+
// the broker append boundary re-checks the payload anyway.
|
|
295
|
+
return JSON.parse(serialized) as JsonValue
|
|
296
|
+
} catch (error) {
|
|
297
|
+
throw createSixbError("internal.unexpected", `[Sixb] ${label} could not be JSON encoded.`, {
|
|
298
|
+
cause: error,
|
|
299
|
+
details,
|
|
300
|
+
})
|
|
301
|
+
}
|
|
302
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type AgentStorage, AgentStorageError } from "../storage/agents"
|
|
2
|
+
|
|
3
|
+
/** This session's execution token is stale, so it must make no further durable writes. */
|
|
4
|
+
export class AgentExecutionLostError extends Error {
|
|
5
|
+
readonly name = "AgentExecutionLostError"
|
|
6
|
+
constructor(readonly runId: string) {
|
|
7
|
+
super(`[Sixb] Lost execution ownership of agent run '${runId}'.`)
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* The session refuses what its run may not do: read beyond its conversation, hand a child what the
|
|
13
|
+
* project does not offer. Its message is the runner's to read, wherever the runner is.
|
|
14
|
+
*/
|
|
15
|
+
export class AgentRunRefusedError extends Error {
|
|
16
|
+
readonly name = "AgentRunRefusedError"
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Storage outcomes that mean the run is no longer this session's: another delivery owns it, or it
|
|
21
|
+
* already ended. There is nothing more to record either way.
|
|
22
|
+
*/
|
|
23
|
+
export function isTerminalOrExecutionGone(error: unknown): boolean {
|
|
24
|
+
return (
|
|
25
|
+
error instanceof AgentStorageError &&
|
|
26
|
+
(error.code === "execution_lost" ||
|
|
27
|
+
error.code === "invalid_state" ||
|
|
28
|
+
error.code === "run_not_found")
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Make a write the run's token fences, and report the fence as {@link AgentExecutionLostError}: a
|
|
34
|
+
* runner checks for that one error, whichever write found the run gone. `ended` also counts a run
|
|
35
|
+
* that ended as gone, for a write whose storage says so with `invalid_state`.
|
|
36
|
+
*/
|
|
37
|
+
export async function fenced<T>(
|
|
38
|
+
runId: string,
|
|
39
|
+
write: () => Promise<T>,
|
|
40
|
+
options: { readonly ended?: boolean } = {}
|
|
41
|
+
): Promise<T> {
|
|
42
|
+
try {
|
|
43
|
+
return await write()
|
|
44
|
+
} catch (error) {
|
|
45
|
+
const gone = options.ended
|
|
46
|
+
? isTerminalOrExecutionGone(error)
|
|
47
|
+
: error instanceof AgentStorageError &&
|
|
48
|
+
(error.code === "execution_lost" || error.code === "run_not_found")
|
|
49
|
+
if (gone) throw new AgentExecutionLostError(runId)
|
|
50
|
+
throw error
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Throws {@link AgentExecutionLostError} unless the run still runs under this execution token,
|
|
56
|
+
* within its lease. `agents` may be a transaction's, so the check and the write it guards commit
|
|
57
|
+
* together.
|
|
58
|
+
*/
|
|
59
|
+
export async function assertAgentRunOwned(
|
|
60
|
+
agents: AgentStorage,
|
|
61
|
+
fence: { readonly projectId: string; readonly id: string; readonly executionToken: string }
|
|
62
|
+
): Promise<void> {
|
|
63
|
+
const current = await agents.runs.getById({ projectId: fence.projectId, id: fence.id })
|
|
64
|
+
if (
|
|
65
|
+
current?.status !== "running" ||
|
|
66
|
+
current.execution?.token !== fence.executionToken ||
|
|
67
|
+
current.execution.queueLeaseExpiresAt.getTime() <= Date.now()
|
|
68
|
+
) {
|
|
69
|
+
throw new AgentExecutionLostError(fence.id)
|
|
70
|
+
}
|
|
71
|
+
}
|