@sixb/core 0.1.24 → 0.1.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions/index.js +35 -35
- package/dist/agents/attachment-keys.d.ts +25 -0
- package/dist/agents/attachment-keys.d.ts.map +1 -0
- package/dist/agents/cancel.d.ts +12 -0
- package/dist/agents/cancel.d.ts.map +1 -1
- package/dist/agents/children.d.ts.map +1 -1
- package/dist/agents/dispatch.d.ts +1 -9
- package/dist/agents/dispatch.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +5 -0
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/index.d.ts +31 -6
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +154 -66
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-loop.d.ts +3 -5
- package/dist/agents/model-loop.d.ts.map +1 -1
- package/dist/agents/model-routing.d.ts +4 -1
- package/dist/agents/model-routing.d.ts.map +1 -1
- package/dist/agents/request.d.ts +9 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-after-finish.d.ts +11 -0
- package/dist/agents/run-after-finish.d.ts.map +1 -0
- package/dist/agents/run-artifacts.d.ts +56 -0
- package/dist/agents/run-artifacts.d.ts.map +1 -0
- package/dist/agents/run-events.d.ts +49 -0
- package/dist/agents/run-events.d.ts.map +1 -0
- package/dist/agents/run-fence.d.ts +38 -0
- package/dist/agents/run-fence.d.ts.map +1 -0
- package/dist/agents/run-liveness.d.ts +36 -0
- package/dist/agents/run-liveness.d.ts.map +1 -0
- package/dist/agents/run-plan.d.ts +110 -0
- package/dist/agents/run-plan.d.ts.map +1 -0
- package/dist/agents/run-session-children.d.ts +89 -0
- package/dist/agents/run-session-children.d.ts.map +1 -0
- package/dist/agents/run-session-http.d.ts +37 -0
- package/dist/agents/run-session-http.d.ts.map +1 -0
- package/dist/agents/run-session-serve.d.ts +24 -0
- package/dist/agents/run-session-serve.d.ts.map +1 -0
- package/dist/agents/run-session-wire.d.ts +31 -0
- package/dist/agents/run-session-wire.d.ts.map +1 -0
- package/dist/agents/run-session.d.ts +239 -0
- package/dist/agents/run-session.d.ts.map +1 -0
- package/dist/agents/run-token.d.ts +40 -0
- package/dist/agents/run-token.d.ts.map +1 -0
- package/dist/agents/run-tools.d.ts +68 -0
- package/dist/agents/run-tools.d.ts.map +1 -0
- package/dist/agents/run-turn.d.ts +59 -0
- package/dist/agents/run-turn.d.ts.map +1 -0
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.d.ts +1 -1
- package/dist/agents/streams/internal.d.ts.map +1 -1
- package/dist/agents/streams/internal.js +2 -4
- package/dist/agents/streams/internal.js.map +1 -1
- package/dist/agents/streams/protocol.d.ts +1 -96
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/subagent-runs.d.ts +7 -1
- package/dist/agents/subagent-runs.d.ts.map +1 -1
- package/dist/agents/tool-files.d.ts +34 -0
- package/dist/agents/tool-files.d.ts.map +1 -0
- package/dist/agents/workflow-node-session.d.ts +99 -0
- package/dist/agents/workflow-node-session.d.ts.map +1 -0
- package/dist/artifacts/frames/index.js +6 -3
- package/dist/artifacts/frames/index.js.map +3 -3
- package/dist/artifacts/frames/probe.d.ts.map +1 -1
- package/dist/artifacts/index.js.map +1 -1
- package/dist/artifacts/publish/index.d.ts +1 -1
- package/dist/artifacts/publish/index.d.ts.map +1 -1
- package/dist/artifacts/publish/index.js +19 -19
- package/dist/auth/index.js +8 -8
- package/dist/authorization/index.js +4 -4
- package/dist/bootstrap/index.js +45 -43
- package/dist/bootstrap/index.js.map +2 -2
- package/dist/{chunk-2fn60nvs.js → chunk-06sg8s4z.js} +2 -2
- package/dist/{chunk-2fn60nvs.js.map → chunk-06sg8s4z.js.map} +1 -1
- package/dist/chunk-07kkp2e1.js.map +1 -1
- package/dist/{chunk-9ntbsnke.js → chunk-0bc3w0zq.js} +7 -7
- package/dist/{chunk-9ntbsnke.js.map → chunk-0bc3w0zq.js.map} +2 -2
- package/dist/{chunk-d2m879s4.js → chunk-0kk2wt0h.js} +27 -27
- package/dist/chunk-0kk2wt0h.js.map +12 -0
- package/dist/chunk-16a9dmfy.js.map +1 -1
- package/dist/chunk-18sk89cg.js.map +2 -2
- package/dist/{chunk-3qms4nax.js → chunk-1vg43g9q.js} +20 -20
- package/dist/{chunk-3qms4nax.js.map → chunk-1vg43g9q.js.map} +4 -4
- package/dist/{chunk-hqsp2sx4.js → chunk-1xvqgg88.js} +31 -33
- package/dist/{chunk-hqsp2sx4.js.map → chunk-1xvqgg88.js.map} +6 -6
- package/dist/chunk-2adz0h75.js.map +1 -1
- package/dist/{chunk-fm62y49k.js → chunk-2pk5hjj9.js} +5 -3
- package/dist/{chunk-fm62y49k.js.map → chunk-2pk5hjj9.js.map} +5 -5
- package/dist/{chunk-vrf90dkv.js → chunk-2vjnyz1s.js} +1 -1
- package/dist/{chunk-vrf90dkv.js.map → chunk-2vjnyz1s.js.map} +1 -1
- package/dist/{chunk-4f3ydv7t.js → chunk-315qye3g.js} +1 -1
- package/dist/{chunk-4f3ydv7t.js.map → chunk-315qye3g.js.map} +1 -1
- package/dist/{chunk-rap5w0x0.js → chunk-31khg3g0.js} +1 -1
- package/dist/{chunk-rap5w0x0.js.map → chunk-31khg3g0.js.map} +1 -1
- package/dist/chunk-45ngkxkp.js.map +1 -1
- package/dist/chunk-48jezz3j.js.map +1 -1
- package/dist/{chunk-vr3j63jq.js → chunk-4jq2bg8t.js} +78 -78
- package/dist/{chunk-vr3j63jq.js.map → chunk-4jq2bg8t.js.map} +4 -4
- package/dist/chunk-4ymrcdbm.js.map +1 -1
- package/dist/chunk-58geavnf.js.map +1 -1
- package/dist/{chunk-6y0mkhex.js → chunk-59kf345w.js} +2 -2
- package/dist/{chunk-6y0mkhex.js.map → chunk-59kf345w.js.map} +1 -1
- package/dist/{chunk-3p93tb91.js → chunk-6qn7nmd3.js} +102 -102
- package/dist/{chunk-3p93tb91.js.map → chunk-6qn7nmd3.js.map} +4 -4
- package/dist/chunk-73j0v4qv.js +355 -0
- package/dist/chunk-73j0v4qv.js.map +13 -0
- package/dist/{chunk-2gjj5dx3.js → chunk-78ymxrn0.js} +1 -1
- package/dist/{chunk-6bkbyer5.js → chunk-7ex2p3zp.js} +3 -3
- package/dist/{chunk-6bkbyer5.js.map → chunk-7ex2p3zp.js.map} +1 -1
- package/dist/{chunk-5tfev0fv.js → chunk-7hf6tkgs.js} +167 -167
- package/dist/{chunk-5tfev0fv.js.map → chunk-7hf6tkgs.js.map} +4 -4
- package/dist/{chunk-8z4726jz.js → chunk-7wn5z7mq.js} +10 -10
- package/dist/{chunk-8z4726jz.js.map → chunk-7wn5z7mq.js.map} +2 -2
- package/dist/{chunk-6n69k945.js → chunk-8mb7mt8n.js} +2 -2
- package/dist/chunk-8ncg20rd.js.map +1 -1
- package/dist/{chunk-68wghpdf.js → chunk-8v5a54qz.js} +50 -11
- package/dist/{chunk-68wghpdf.js.map → chunk-8v5a54qz.js.map} +3 -3
- package/dist/{chunk-gqm0b7vd.js → chunk-8v6xzwgr.js} +92 -76
- package/dist/{chunk-gqm0b7vd.js.map → chunk-8v6xzwgr.js.map} +6 -6
- package/dist/{chunk-m36fw8ft.js → chunk-8wsjr52f.js} +1 -1
- package/dist/{chunk-vd1rk42q.js → chunk-8xnz9vvp.js} +4 -4
- package/dist/{chunk-vd1rk42q.js.map → chunk-8xnz9vvp.js.map} +1 -1
- package/dist/chunk-9mab3dvg.js.map +1 -1
- package/dist/chunk-9tc8dxmn.js.map +1 -1
- package/dist/chunk-9x8dybsb.js.map +2 -2
- package/dist/chunk-a3faa34j.js.map +1 -1
- package/dist/{chunk-62a63pr6.js → chunk-axb4ss9a.js} +7 -7
- package/dist/{chunk-62a63pr6.js.map → chunk-axb4ss9a.js.map} +2 -2
- package/dist/{chunk-z3ryd53f.js → chunk-b6ghvap7.js} +35 -11
- package/dist/{chunk-z3ryd53f.js.map → chunk-b6ghvap7.js.map} +3 -3
- package/dist/{chunk-sqfvnvqj.js → chunk-c14ap3s9.js} +2 -2
- package/dist/{chunk-sqfvnvqj.js.map → chunk-c14ap3s9.js.map} +1 -1
- package/dist/{chunk-661ezhks.js → chunk-cbcgs9f7.js} +87 -8
- package/dist/chunk-cbcgs9f7.js.map +11 -0
- package/dist/chunk-cwdzcv37.js.map +1 -1
- package/dist/{chunk-bab05bhg.js → chunk-dgtd0836.js} +1 -1
- package/dist/{chunk-1j6j0rht.js → chunk-e24fvw8g.js} +1 -1
- package/dist/{chunk-1j6j0rht.js.map → chunk-e24fvw8g.js.map} +1 -1
- package/dist/chunk-e5wf5vz0.js.map +1 -1
- package/dist/chunk-eptrvnby.js.map +1 -1
- package/dist/chunk-ey1nk510.js.map +1 -1
- package/dist/{chunk-j936th07.js → chunk-fakrpfy3.js} +58 -58
- package/dist/{chunk-j936th07.js.map → chunk-fakrpfy3.js.map} +5 -5
- package/dist/chunk-fb3feg1e.js.map +1 -1
- package/dist/chunk-ff5xkv0p.js.map +1 -1
- package/dist/chunk-fntqb7qy.js.map +1 -1
- package/dist/{chunk-7ny9mjgm.js → chunk-ft3w5ahs.js} +1 -1
- package/dist/chunk-g663fahq.js.map +1 -1
- package/dist/{chunk-cdk3egjj.js → chunk-h1na2cxc.js} +1 -1
- package/dist/{chunk-cdk3egjj.js.map → chunk-h1na2cxc.js.map} +1 -1
- package/dist/chunk-hn2r7z41.js.map +1 -1
- package/dist/{chunk-24bqx0dx.js → chunk-hn76sanm.js} +1 -1
- package/dist/{chunk-24bqx0dx.js.map → chunk-hn76sanm.js.map} +1 -1
- package/dist/chunk-jmfet9r4.js.map +1 -1
- package/dist/{chunk-bnr4a734.js → chunk-jn3ysaf2.js} +24 -22
- package/dist/{chunk-bnr4a734.js.map → chunk-jn3ysaf2.js.map} +5 -5
- package/dist/{chunk-4y26vs3v.js → chunk-jspskey0.js} +16 -3
- package/dist/chunk-jspskey0.js.map +10 -0
- package/dist/{chunk-r6szek0x.js → chunk-jt3r6thp.js} +2 -135
- package/dist/chunk-jt3r6thp.js.map +10 -0
- package/dist/chunk-kfee1h52.js.map +1 -1
- package/dist/{chunk-qx00vjrj.js → chunk-kwfhd1g0.js} +23 -23
- package/dist/{chunk-qx00vjrj.js.map → chunk-kwfhd1g0.js.map} +4 -4
- package/dist/chunk-m427qgq0.js.map +1 -1
- package/dist/chunk-mbsbxarb.js.map +1 -1
- package/dist/{chunk-et017krg.js → chunk-mdxmt0n3.js} +8657 -8704
- package/dist/{chunk-et017krg.js.map → chunk-mdxmt0n3.js.map} +37 -37
- package/dist/chunk-mmagke4x.js.map +1 -1
- package/dist/{chunk-2x19q6k6.js → chunk-mqx25wwh.js} +319 -154
- package/dist/chunk-mqx25wwh.js.map +18 -0
- package/dist/chunk-mzx71snp.js.map +1 -1
- package/dist/chunk-n8q5j6y5.js.map +1 -1
- package/dist/chunk-npcr0228.js.map +1 -1
- package/dist/{chunk-m2nevja0.js → chunk-phm3c7b9.js} +1 -1
- package/dist/{chunk-m2nevja0.js.map → chunk-phm3c7b9.js.map} +1 -1
- package/dist/chunk-qf954wje.js.map +1 -1
- package/dist/{chunk-65pyhyas.js → chunk-qgvbxfqv.js} +6 -8
- package/dist/{chunk-65pyhyas.js.map → chunk-qgvbxfqv.js.map} +2 -2
- package/dist/{chunk-hk38wahh.js → chunk-qst145py.js} +4 -4
- package/dist/{chunk-hk38wahh.js.map → chunk-qst145py.js.map} +1 -1
- package/dist/{chunk-c844dkwd.js → chunk-qtzftvxa.js} +4 -5
- package/dist/{chunk-c844dkwd.js.map → chunk-qtzftvxa.js.map} +2 -2
- package/dist/chunk-ratkv4zc.js +3 -0
- package/dist/chunk-ratkv4zc.js.map +9 -0
- package/dist/{chunk-nzapm6p0.js → chunk-s3we74h8.js} +1 -2
- package/dist/chunk-s3we74h8.js.map +12 -0
- package/dist/{chunk-0xmt5p5y.js → chunk-t3brw0wd.js} +1 -2
- package/dist/{chunk-0xmt5p5y.js.map → chunk-t3brw0wd.js.map} +2 -2
- package/dist/chunk-t5608tkq.js.map +1 -1
- package/dist/chunk-tdxfsg1c.js.map +1 -1
- package/dist/{chunk-1t6k1avb.js → chunk-tnhqtfea.js} +1 -1
- package/dist/chunk-vhbw5sqm.js.map +1 -1
- package/dist/{chunk-rp9wwk7b.js → chunk-vx4e4zv4.js} +30 -30
- package/dist/{chunk-rp9wwk7b.js.map → chunk-vx4e4zv4.js.map} +4 -4
- package/dist/chunk-waqk73p1.js.map +1 -1
- package/dist/chunk-x0v3jd47.js.map +1 -1
- package/dist/{chunk-yecwnwpq.js → chunk-xm8qgbqm.js} +58 -29
- package/dist/{chunk-yecwnwpq.js.map → chunk-xm8qgbqm.js.map} +7 -7
- package/dist/{chunk-97wr6p2g.js → chunk-y7j6x4h0.js} +8 -8
- package/dist/{chunk-97wr6p2g.js.map → chunk-y7j6x4h0.js.map} +4 -4
- package/dist/{chunk-xe0732g0.js → chunk-yavhtnac.js} +12 -8
- package/dist/{chunk-xe0732g0.js.map → chunk-yavhtnac.js.map} +4 -4
- package/dist/chunk-yd00vzqr.js +3394 -0
- package/dist/chunk-yd00vzqr.js.map +37 -0
- package/dist/{chunk-n9w3n38q.js → chunk-ye5c8016.js} +54 -8
- package/dist/chunk-ye5c8016.js.map +23 -0
- package/dist/chunk-yw9pyg66.js.map +1 -1
- package/dist/{chunk-nydf3dbe.js → chunk-z9mg7wya.js} +37 -20
- package/dist/chunk-z9mg7wya.js.map +13 -0
- package/dist/chunk-zbc929zg.js.map +1 -1
- package/dist/chunk-zhh1jd89.js +290 -0
- package/dist/chunk-zhh1jd89.js.map +10 -0
- package/dist/connectors/connections/authorizations.d.ts +2 -2
- package/dist/connectors/connections/authorizations.d.ts.map +1 -1
- package/dist/connectors/connections/service.d.ts.map +1 -1
- package/dist/connectors/connections/tokens.d.ts +2 -2
- package/dist/connectors/connections/tokens.d.ts.map +1 -1
- package/dist/connectors/connections/validation.d.ts +5 -0
- package/dist/connectors/connections/validation.d.ts.map +1 -1
- package/dist/connectors/types.d.ts +9 -2
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/datasets/write.js +3 -3
- package/dist/deploy/internal.js +2 -5
- package/dist/deploy/internal.js.map +3 -3
- package/dist/deploy/types.d.ts +0 -2
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/execution/agent.d.ts +2 -2
- package/dist/execution/agent.d.ts.map +1 -1
- package/dist/execution/agent.js +38 -38
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/primitive.js +35 -35
- package/dist/execution/request.js +37 -37
- package/dist/execution/request.js.map +2 -2
- package/dist/http/api-routes.d.ts +12 -11
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +53 -51
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/index.js +3 -3
- package/dist/logging/internal.js +1 -1
- package/dist/materializer/index.js +17 -17
- package/dist/models/execution/errors.d.ts +5 -0
- package/dist/models/execution/errors.d.ts.map +1 -1
- package/dist/models/execution/index.d.ts +2 -1
- package/dist/models/execution/index.d.ts.map +1 -1
- package/dist/models/execution/index.js +55 -50
- package/dist/models/execution/index.js.map +1 -1
- package/dist/models/execution/model-call-recorder.d.ts +7 -2
- package/dist/models/execution/model-call-recorder.d.ts.map +1 -1
- package/dist/models/execution.d.ts.map +1 -1
- package/dist/models/language-call.d.ts +51 -0
- package/dist/models/language-call.d.ts.map +1 -0
- package/dist/objects/index.js +35 -35
- package/dist/objects/query/index.js +17 -17
- package/dist/ontology/docs-markdown.d.ts.map +1 -1
- package/dist/ontology/index.d.ts +1 -1
- package/dist/ontology/index.d.ts.map +1 -1
- package/dist/ontology/index.js +4 -4
- package/dist/ontology/internal.js +8 -275
- package/dist/ontology/internal.js.map +3 -4
- package/dist/ontology/user-ref.d.ts +21 -3
- package/dist/ontology/user-ref.d.ts.map +1 -1
- package/dist/pipelines/index.js +19 -19
- package/dist/projections/builders.d.ts +13 -2
- package/dist/projections/builders.d.ts.map +1 -1
- package/dist/projections/index.d.ts +1 -1
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/internal.js +17 -17
- package/dist/projections/types.d.ts +7 -0
- package/dist/projections/types.d.ts.map +1 -1
- package/dist/projections/validation.d.ts +2 -0
- package/dist/projections/validation.d.ts.map +1 -1
- package/dist/query.js +2 -2
- package/dist/queues/in-memory.d.ts +0 -1
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/types.d.ts +0 -8
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/internal.js +23 -23
- package/dist/runtime/internal.js.map +1 -1
- package/dist/sandboxes/configuration.d.ts +4 -6
- package/dist/sandboxes/configuration.d.ts.map +1 -1
- package/dist/sandboxes/environment.d.ts.map +1 -1
- package/dist/sandboxes/exec.d.ts +5 -3
- package/dist/sandboxes/exec.d.ts.map +1 -1
- package/dist/sandboxes/guest-credentials.d.ts +61 -0
- package/dist/sandboxes/guest-credentials.d.ts.map +1 -0
- package/dist/sandboxes/index.d.ts +2 -0
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +23 -9
- package/dist/sandboxes/index.js.map +1 -1
- package/dist/sandboxes/sandbox.d.ts +18 -4
- package/dist/sandboxes/sandbox.d.ts.map +1 -1
- package/dist/security/internal.js +1 -1
- package/dist/security/internal.js.map +1 -1
- package/dist/shares/internal.js +17 -17
- package/dist/shares/internal.js.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +3 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +1 -1
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +6 -0
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +8 -2
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +63 -7
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +2 -2
- package/dist/storage/connector-connections/provider.js.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +9 -9
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +15 -15
- package/dist/storage/ontology/provider.js +1 -1
- package/dist/storage/share-grants/provider.js +3 -3
- package/dist/storage/types.d.ts +1 -1
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +9 -9
- package/dist/syncs/index.js +20 -20
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +677 -352
- package/dist/testing/index.js.map +9 -7
- package/dist/testing/queues-contract.d.ts.map +1 -1
- package/dist/testing/sandbox-credentials-contract.d.ts +27 -0
- package/dist/testing/sandbox-credentials-contract.d.ts.map +1 -0
- package/dist/testing/sandboxes-contract.d.ts.map +1 -1
- package/dist/testing/users.d.ts +20 -0
- package/dist/testing/users.d.ts.map +1 -0
- package/dist/users/execution.d.ts +6 -2
- package/dist/users/execution.d.ts.map +1 -1
- package/dist/users/index.d.ts +1 -1
- package/dist/users/index.d.ts.map +1 -1
- package/dist/webhooks/internal.js +17 -17
- package/dist/webhooks/internal.js.map +1 -1
- package/dist/workers/index.js.map +1 -1
- package/dist/workflows/index.js +41 -39
- package/dist/workflows/index.js.map +1 -1
- package/package.json +1 -1
- package/src/agents/README.md +136 -0
- package/src/agents/attachment-keys.ts +83 -0
- package/src/agents/cancel.ts +16 -1
- package/src/agents/children.ts +5 -3
- package/src/agents/dispatch.ts +6 -58
- package/src/agents/execution.ts +18 -0
- package/src/agents/index.ts +127 -21
- package/src/agents/model-loop.ts +23 -73
- package/src/agents/model-routing.ts +7 -2
- package/src/agents/request.ts +69 -20
- package/src/agents/run-after-finish.ts +133 -0
- package/src/agents/run-artifacts.ts +257 -0
- package/src/agents/run-events.ts +302 -0
- package/src/agents/run-fence.ts +71 -0
- package/src/agents/run-liveness.ts +122 -0
- package/src/agents/run-plan.ts +316 -0
- package/src/agents/run-session-children.ts +303 -0
- package/src/agents/run-session-http.ts +397 -0
- package/src/agents/run-session-serve.ts +479 -0
- package/src/agents/run-session-wire.ts +189 -0
- package/src/agents/run-session.ts +802 -0
- package/src/agents/run-token.ts +124 -0
- package/src/agents/run-tools.ts +180 -0
- package/src/agents/run-turn.ts +265 -0
- package/src/agents/streams/internal.ts +0 -1
- package/src/agents/streams/protocol.ts +0 -292
- package/src/agents/subagent-runs.ts +19 -1
- package/src/agents/tool-files.ts +225 -0
- package/src/agents/workflow-node-session.ts +387 -0
- package/src/artifacts/frames/probe.ts +14 -1
- package/src/artifacts/publish/index.ts +1 -0
- package/src/connectors/connections/authorizations.ts +3 -2
- package/src/connectors/connections/service.ts +5 -1
- package/src/connectors/connections/tokens.ts +41 -5
- package/src/connectors/connections/validation.ts +21 -0
- package/src/connectors/types.ts +12 -2
- package/src/deploy/types.ts +0 -2
- package/src/deploy/validation.ts +1 -4
- package/src/execution/agent.ts +2 -2
- package/src/execution/authorized-object-reader.ts +28 -1
- package/src/http/api-routes.ts +114 -27
- package/src/index.ts +3 -1
- package/src/models/execution/README.md +15 -1
- package/src/models/execution/errors.ts +14 -0
- package/src/models/execution/index.ts +2 -1
- package/src/models/execution/model-call-recorder.ts +12 -10
- package/src/models/execution.ts +9 -11
- package/src/models/language-call.ts +247 -0
- package/src/ontology/docs-markdown.ts +14 -0
- package/src/ontology/index.ts +1 -1
- package/src/ontology/user-ref.ts +40 -6
- package/src/projections/builders.ts +48 -4
- package/src/projections/index.ts +1 -0
- package/src/projections/registry.ts +1 -0
- package/src/projections/revision.ts +10 -0
- package/src/projections/types.ts +8 -0
- package/src/projections/validation.ts +52 -6
- package/src/queues/in-memory.ts +0 -5
- package/src/queues/index.ts +0 -2
- package/src/queues/types.ts +0 -13
- package/src/runtime/host.ts +1 -1
- package/src/sandboxes/README.md +17 -6
- package/src/sandboxes/configuration.ts +7 -9
- package/src/sandboxes/environment.ts +1 -0
- package/src/sandboxes/exec.ts +17 -9
- package/src/sandboxes/guest-credentials.ts +262 -0
- package/src/sandboxes/index.ts +14 -0
- package/src/sandboxes/sandbox.ts +19 -4
- package/src/storage/agents/in-memory.ts +53 -0
- package/src/storage/agents/index.ts +2 -0
- package/src/storage/agents/provider.ts +56 -11
- package/src/storage/agents/types.ts +59 -7
- package/src/storage/index.ts +2 -0
- package/src/storage/types.ts +1 -0
- package/src/testing/agent-storage-contract.ts +175 -2
- package/src/testing/ai-model-call-groups-contract.ts +0 -1
- package/src/testing/index.ts +5 -0
- package/src/testing/queues-contract.ts +0 -16
- package/src/testing/sandbox-credentials-contract.ts +284 -0
- package/src/testing/sandboxes-contract.ts +21 -0
- package/src/testing/users.ts +39 -0
- package/src/users/execution.ts +33 -7
- package/src/users/index.ts +7 -1
- package/dist/agents/api-gateway.d.ts +0 -26
- package/dist/agents/api-gateway.d.ts.map +0 -1
- package/dist/chunk-2x19q6k6.js.map +0 -17
- package/dist/chunk-4y26vs3v.js.map +0 -10
- package/dist/chunk-661ezhks.js.map +0 -11
- package/dist/chunk-d2m879s4.js.map +0 -12
- package/dist/chunk-n9w3n38q.js.map +0 -23
- package/dist/chunk-nydf3dbe.js.map +0 -13
- package/dist/chunk-nzapm6p0.js.map +0 -12
- package/dist/chunk-r6szek0x.js.map +0 -10
- package/dist/chunk-vabga7fk.js +0 -176
- package/dist/chunk-vabga7fk.js.map +0 -12
- package/dist/chunk-vpgwq5nf.js +0 -810
- package/dist/chunk-vpgwq5nf.js.map +0 -21
- package/src/agents/api-gateway.ts +0 -68
- /package/dist/{chunk-2gjj5dx3.js.map → chunk-78ymxrn0.js.map} +0 -0
- /package/dist/{chunk-6n69k945.js.map → chunk-8mb7mt8n.js.map} +0 -0
- /package/dist/{chunk-m36fw8ft.js.map → chunk-8wsjr52f.js.map} +0 -0
- /package/dist/{chunk-bab05bhg.js.map → chunk-dgtd0836.js.map} +0 -0
- /package/dist/{chunk-7ny9mjgm.js.map → chunk-ft3w5ahs.js.map} +0 -0
- /package/dist/{chunk-1t6k1avb.js.map → chunk-tnhqtfea.js.map} +0 -0
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from "node:crypto"
|
|
2
|
+
import { type AgentApiEffect, SIXB_API_ROUTES } from "../http/api-routes"
|
|
3
|
+
import { matchesPathPattern, normalizeRoutePath } from "../http/route-pattern"
|
|
4
|
+
|
|
5
|
+
// A run token lets an Agent's commands call the API as their run: a bearer token that names the
|
|
6
|
+
// run and proves it was issued under the run's current execution token. It needs no storage of
|
|
7
|
+
// its own and stops working when the run's execution ends or moves to another worker.
|
|
8
|
+
//
|
|
9
|
+
// A runner token is the runner's own: it reaches the run's session (run-session-serve.ts), which
|
|
10
|
+
// finishes the run, writes its messages and calls its models. It is issued under the same
|
|
11
|
+
// execution but signed for another purpose, so neither is ever accepted as the other: the run's
|
|
12
|
+
// commands hold only the run token, and never reach the session that runs them.
|
|
13
|
+
const RUN_TOKEN = { prefix: "sixb_run_v1_", purpose: "agent-run-token" } as const
|
|
14
|
+
const RUNNER_TOKEN = { prefix: "sixb_runner_v1_", purpose: "agent-runner-token" } as const
|
|
15
|
+
|
|
16
|
+
type TokenKind = typeof RUN_TOKEN | typeof RUNNER_TOKEN
|
|
17
|
+
|
|
18
|
+
export interface AgentRunTokenInput {
|
|
19
|
+
readonly projectId: string
|
|
20
|
+
readonly runId: string
|
|
21
|
+
readonly executionToken: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface AgentApiRoute {
|
|
25
|
+
readonly method: string
|
|
26
|
+
readonly path: string
|
|
27
|
+
/** What a call changes; a GET reads. */
|
|
28
|
+
readonly effect: AgentApiEffect
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The routes a run token may call — the `agentApi` projection of the canonical
|
|
33
|
+
* {@link SIXB_API_ROUTES} table, so this list can never drift from (nor exceed) the bearer boundary.
|
|
34
|
+
*/
|
|
35
|
+
export const AGENT_API_ROUTES: readonly AgentApiRoute[] = SIXB_API_ROUTES.filter(
|
|
36
|
+
(route) => route.agentApi
|
|
37
|
+
).map((route) => ({
|
|
38
|
+
method: route.method,
|
|
39
|
+
path: route.path,
|
|
40
|
+
effect: route.agentEffect ?? "read",
|
|
41
|
+
}))
|
|
42
|
+
|
|
43
|
+
export function createAgentRunToken(input: AgentRunTokenInput): string {
|
|
44
|
+
return signToken(RUN_TOKEN, input)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Whether a bearer token is a run token, whatever run it names or whether it is still valid. */
|
|
48
|
+
export function isAgentRunToken(token: string): boolean {
|
|
49
|
+
return token.startsWith(RUN_TOKEN.prefix)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** The run a run token names, unverified; undefined when the token is malformed. */
|
|
53
|
+
export function agentRunTokenRunId(token: string): string | undefined {
|
|
54
|
+
return tokenRunId(RUN_TOKEN, token)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Whether the token was issued for this run under this execution token. */
|
|
58
|
+
export function isValidAgentRunToken(
|
|
59
|
+
input: AgentRunTokenInput & { readonly token: string }
|
|
60
|
+
): boolean {
|
|
61
|
+
return isValidToken(RUN_TOKEN, input)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** The token a run's runner reaches its session with, never handed to the run's commands. */
|
|
65
|
+
export function createAgentRunnerToken(input: AgentRunTokenInput): string {
|
|
66
|
+
return signToken(RUNNER_TOKEN, input)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Whether a bearer token is a runner token, whatever run it names or whether it is still valid. */
|
|
70
|
+
export function isAgentRunnerToken(token: string): boolean {
|
|
71
|
+
return token.startsWith(RUNNER_TOKEN.prefix)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** The run a runner token names, unverified; undefined when the token is malformed. */
|
|
75
|
+
export function agentRunnerTokenRunId(token: string): string | undefined {
|
|
76
|
+
return tokenRunId(RUNNER_TOKEN, token)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Whether the runner token was issued for this run under this execution token. */
|
|
80
|
+
export function isValidAgentRunnerToken(
|
|
81
|
+
input: AgentRunTokenInput & { readonly token: string }
|
|
82
|
+
): boolean {
|
|
83
|
+
return isValidToken(RUNNER_TOKEN, input)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function isAllowedAgentApiRequest(method: string, pathname: string): boolean {
|
|
87
|
+
return findAgentApiRoute(method, pathname) !== undefined
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The gateway route a request matches, with what it changes. */
|
|
91
|
+
export function findAgentApiRoute(method: string, pathname: string): AgentApiRoute | undefined {
|
|
92
|
+
const normalizedMethod = method.toUpperCase()
|
|
93
|
+
const normalizedPath = normalizeRoutePath(pathname)
|
|
94
|
+
return AGENT_API_ROUTES.find(
|
|
95
|
+
(route) => route.method === normalizedMethod && matchesPathPattern(normalizedPath, route.path)
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function signToken(kind: TokenKind, input: AgentRunTokenInput): string {
|
|
100
|
+
const runId = Buffer.from(input.runId, "utf8").toString("base64url")
|
|
101
|
+
const digest = createHmac("sha256", input.executionToken)
|
|
102
|
+
.update(`${kind.purpose}:${input.projectId}:${input.runId}`)
|
|
103
|
+
.digest("base64url")
|
|
104
|
+
return `${kind.prefix}${runId}.${digest}`
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function tokenRunId(kind: TokenKind, token: string): string | undefined {
|
|
108
|
+
if (!token.startsWith(kind.prefix)) return undefined
|
|
109
|
+
const [runId, digest, ...rest] = token.slice(kind.prefix.length).split(".")
|
|
110
|
+
if (!runId || !digest || rest.length > 0) return undefined
|
|
111
|
+
return Buffer.from(runId, "base64url").toString("utf8") || undefined
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function isValidToken(
|
|
115
|
+
kind: TokenKind,
|
|
116
|
+
input: AgentRunTokenInput & { readonly token: string }
|
|
117
|
+
): boolean {
|
|
118
|
+
const expectedBuffer = Buffer.from(signToken(kind, input))
|
|
119
|
+
const actualBuffer = Buffer.from(input.token)
|
|
120
|
+
return (
|
|
121
|
+
expectedBuffer.byteLength === actualBuffer.byteLength &&
|
|
122
|
+
timingSafeEqual(expectedBuffer, actualBuffer)
|
|
123
|
+
)
|
|
124
|
+
}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { posix } from "node:path"
|
|
2
|
+
import { openFileRef } from "../blob-storage/file-content"
|
|
3
|
+
import type { JsonObject, JsonValue } from "../json"
|
|
4
|
+
import type { Logger } from "../logging/types"
|
|
5
|
+
import { schemaRecordToJsonSchema } from "../ontology/json-schema"
|
|
6
|
+
import type { ValueType } from "../ontology/types"
|
|
7
|
+
import type { AgentMessageRecord, SubagentRunFile } from "../storage/agents"
|
|
8
|
+
import { attachmentKeyMessageId, findMessageAttachment } from "./attachment-keys"
|
|
9
|
+
import { AgentToolPublicError } from "./errors"
|
|
10
|
+
import type { AgentRunFileStore } from "./run-session"
|
|
11
|
+
import { type AgentToolCallFile, SANDBOX_CONTEXT_DIRECTORY, storeAgentToolFile } from "./tool-files"
|
|
12
|
+
import type {
|
|
13
|
+
AgentToolAttachments,
|
|
14
|
+
AgentToolDefinition,
|
|
15
|
+
AgentToolRunInfo,
|
|
16
|
+
AgentToolRuntimeFacade,
|
|
17
|
+
} from "./types"
|
|
18
|
+
import { validateAndNormalizeAgentToolInput } from "./validation"
|
|
19
|
+
|
|
20
|
+
// A project tool is the project's code, so it runs where the project is: in the worker for a run
|
|
21
|
+
// it holds, on the server for a run on a computer. Either way it runs here, as the run: its input
|
|
22
|
+
// checked against the tool's schema, its handler given the run's SDK and attachments, and the
|
|
23
|
+
// files it puts stored for its runner to copy into the sandbox.
|
|
24
|
+
|
|
25
|
+
/** A project tool as the model is offered it. */
|
|
26
|
+
export interface AgentToolSpec {
|
|
27
|
+
readonly name: string
|
|
28
|
+
readonly description: string
|
|
29
|
+
readonly inputSchema: JsonObject
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A call the model made to a project tool. */
|
|
33
|
+
export interface AgentToolCall {
|
|
34
|
+
readonly toolName: string
|
|
35
|
+
readonly toolCallId: string
|
|
36
|
+
readonly input: unknown
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** How a call runs: until `signal` aborts, its files within what the run's file budget has left. */
|
|
40
|
+
export interface AgentToolCallOptions {
|
|
41
|
+
readonly signal: AbortSignal
|
|
42
|
+
/** The bytes the run may still store; the put that would pass it is refused. */
|
|
43
|
+
readonly maxFileBytes?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** What a project tool returned, and the files it stored for the run's sandbox. */
|
|
47
|
+
export interface AgentToolCallResult {
|
|
48
|
+
readonly output: JsonValue
|
|
49
|
+
/** Each at its path in the sandbox's context directory. */
|
|
50
|
+
readonly files: readonly AgentToolCallFile[]
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** The spec the model gets for a project tool: its input as JSON Schema. */
|
|
54
|
+
export function agentToolSpec(
|
|
55
|
+
definition: AgentToolDefinition,
|
|
56
|
+
valueTypesById: ReadonlyMap<string, ValueType>
|
|
57
|
+
): AgentToolSpec {
|
|
58
|
+
return {
|
|
59
|
+
name: definition.name,
|
|
60
|
+
description: definition.description,
|
|
61
|
+
inputSchema: schemaRecordToJsonSchema({ shape: definition.input, valueTypesById }),
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Run one call of a project tool as the run. Input the tool's schema refuses is an
|
|
67
|
+
* {@link AgentToolPublicError}, which the model reads. Whatever the handler throws is thrown as it
|
|
68
|
+
* is: its runner decides what the model may read of it.
|
|
69
|
+
*/
|
|
70
|
+
export async function runAgentTool(input: {
|
|
71
|
+
readonly definition: AgentToolDefinition
|
|
72
|
+
readonly valueTypesById: ReadonlyMap<string, ValueType>
|
|
73
|
+
readonly call: AgentToolCall
|
|
74
|
+
readonly signal: AbortSignal
|
|
75
|
+
readonly run: AgentToolRunInfo
|
|
76
|
+
/** The run's SDK, bound as its requester. */
|
|
77
|
+
readonly sixb: AgentToolRuntimeFacade
|
|
78
|
+
readonly logger: Logger
|
|
79
|
+
readonly attachments: AgentToolAttachments
|
|
80
|
+
/** Where the files it puts are stored. */
|
|
81
|
+
readonly files: Pick<AgentRunFileStore, "put">
|
|
82
|
+
/** The bytes its files may take in all: the run's budget left. */
|
|
83
|
+
readonly maxFileBytes?: number
|
|
84
|
+
}): Promise<AgentToolCallResult> {
|
|
85
|
+
const { definition, call, signal } = input
|
|
86
|
+
let toolInput: Readonly<Record<string, JsonValue>>
|
|
87
|
+
try {
|
|
88
|
+
toolInput = validateAndNormalizeAgentToolInput(
|
|
89
|
+
definition.name,
|
|
90
|
+
definition.input,
|
|
91
|
+
call.input,
|
|
92
|
+
input.valueTypesById
|
|
93
|
+
)
|
|
94
|
+
} catch (error) {
|
|
95
|
+
throw new AgentToolPublicError(
|
|
96
|
+
error instanceof Error
|
|
97
|
+
? error.message
|
|
98
|
+
: `[Sixb] Agent tool '${definition.name}' input is invalid.`
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const stored: AgentToolCallFile[] = []
|
|
103
|
+
let storedBytes = 0
|
|
104
|
+
const output = await definition.handler({
|
|
105
|
+
input: toolInput,
|
|
106
|
+
toolCallId: call.toolCallId,
|
|
107
|
+
signal,
|
|
108
|
+
run: input.run,
|
|
109
|
+
sixb: input.sixb,
|
|
110
|
+
logger: input.logger,
|
|
111
|
+
files: {
|
|
112
|
+
async put(file) {
|
|
113
|
+
const { fileRef, path } = await storeAgentToolFile({
|
|
114
|
+
toolName: definition.name,
|
|
115
|
+
toolCallId: call.toolCallId,
|
|
116
|
+
file,
|
|
117
|
+
store: input.files,
|
|
118
|
+
signal,
|
|
119
|
+
// Counted as it is read: the put that would pass the run's budget stores nothing.
|
|
120
|
+
onBytes: (sizeBytes) => {
|
|
121
|
+
storedBytes += sizeBytes
|
|
122
|
+
if (input.maxFileBytes !== undefined && storedBytes > input.maxFileBytes) {
|
|
123
|
+
throw new AgentToolPublicError(
|
|
124
|
+
`[SixbAgent] Agent tool '${definition.name}' files exceed the run's file limit, ${input.maxFileBytes} bytes left.`
|
|
125
|
+
)
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
})
|
|
129
|
+
stored.push({ fileRef, path })
|
|
130
|
+
// Where the runner copies it, in a sandbox that keeps its run files in the usual place.
|
|
131
|
+
return { fileRef, sandboxPath: posix.join(SANDBOX_CONTEXT_DIRECTORY, path) }
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
attachments: input.attachments,
|
|
135
|
+
})
|
|
136
|
+
// The tool's definition checked it is JSON.
|
|
137
|
+
return { output: output as JsonValue, files: stored }
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* A chat's attachments: files of its thread's messages, by the key `$SIXB_ATTACHMENTS` lists. A key
|
|
142
|
+
* resolves only in a message of the run's own thread.
|
|
143
|
+
*/
|
|
144
|
+
export function threadToolAttachments(input: {
|
|
145
|
+
readonly threadId: string
|
|
146
|
+
readonly message: (messageId: string) => Promise<AgentMessageRecord | null>
|
|
147
|
+
readonly files: Pick<AgentRunFileStore, "stat" | "open">
|
|
148
|
+
}): AgentToolAttachments {
|
|
149
|
+
return {
|
|
150
|
+
async open(key) {
|
|
151
|
+
const messageId = attachmentKeyMessageId(key)
|
|
152
|
+
const message = messageId && (await input.message(messageId))
|
|
153
|
+
const fileRef =
|
|
154
|
+
message && message.threadId === input.threadId ? findMessageAttachment(message, key) : null
|
|
155
|
+
if (!fileRef) throw unknownAttachment(key)
|
|
156
|
+
return openFileRef(input.files, fileRef)
|
|
157
|
+
},
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** A child Agent's attachments: the files its parent handed over, by their path such as `q3.pdf`. */
|
|
162
|
+
export function handedToolAttachments(input: {
|
|
163
|
+
readonly files: readonly SubagentRunFile[]
|
|
164
|
+
readonly store: Pick<AgentRunFileStore, "stat" | "open">
|
|
165
|
+
}): AgentToolAttachments {
|
|
166
|
+
const fileRefs = new Map(input.files.map((file) => [file.path, file.fileRef]))
|
|
167
|
+
return {
|
|
168
|
+
async open(key) {
|
|
169
|
+
const fileRef = fileRefs.get(key)
|
|
170
|
+
if (!fileRef) throw unknownAttachment(key)
|
|
171
|
+
return openFileRef(input.store, fileRef)
|
|
172
|
+
},
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function unknownAttachment(key: string): AgentToolPublicError {
|
|
177
|
+
return new AgentToolPublicError(
|
|
178
|
+
`[SixbAgent] '${key}' is not an attachment of this run. Pass a key listed in $SIXB_ATTACHMENTS.`
|
|
179
|
+
)
|
|
180
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import type { Principal, UserPrincipal } from "../auth/types"
|
|
2
|
+
import type {
|
|
3
|
+
AgentContextCheckpointRecord,
|
|
4
|
+
AgentMessageRecord,
|
|
5
|
+
AgentRunRecord,
|
|
6
|
+
AgentThreadParticipantRecord,
|
|
7
|
+
AgentThreadRecord,
|
|
8
|
+
SubagentRunRecord,
|
|
9
|
+
} from "../storage/agents"
|
|
10
|
+
import type { AiModelCallUsageRecord } from "../storage/ai-usage"
|
|
11
|
+
import type { ExecutionRecord } from "../storage/executions/types"
|
|
12
|
+
import { isPausedSubagentRun } from "./approvals"
|
|
13
|
+
import { userCanRunAgent } from "./authority"
|
|
14
|
+
import type { AgentRunSessionHost } from "./run-session"
|
|
15
|
+
import { listSubagentThreadRuns } from "./subagent-runs"
|
|
16
|
+
import { conversationThreadId } from "./thread-access"
|
|
17
|
+
|
|
18
|
+
// What a run reads to prepare, read in one go when it starts. Plain data: a runner in the worker
|
|
19
|
+
// gets it in process, and a runner over HTTP gets the same thing as one answer.
|
|
20
|
+
|
|
21
|
+
/** What a run starts from: a conversation turn's, or a child's. */
|
|
22
|
+
export type AgentRunContext = AgentTurnContext | AgentChildContext
|
|
23
|
+
|
|
24
|
+
export interface AgentTurnContext {
|
|
25
|
+
readonly kind: "conversation"
|
|
26
|
+
readonly thread: AgentThreadRecord | null
|
|
27
|
+
readonly execution: ExecutionRecord | null
|
|
28
|
+
/** Everyone added to the thread, even someone who cannot read it now. */
|
|
29
|
+
readonly participants: readonly AgentThreadParticipantRecord[]
|
|
30
|
+
/** The participants who can read the thread now: active users the project lets use the Agent. */
|
|
31
|
+
readonly readers: readonly UserPrincipal[]
|
|
32
|
+
/**
|
|
33
|
+
* Display names of the people the turn names, by `type:id`: its requester, the thread's owner,
|
|
34
|
+
* its readers and who wrote its retained messages. Someone without one is absent.
|
|
35
|
+
*/
|
|
36
|
+
readonly names: Readonly<Record<string, string>>
|
|
37
|
+
readonly history: AgentTurnHistory
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A conversation's history as a turn reads it: the latest checkpoint and what follows it. */
|
|
41
|
+
export interface AgentTurnHistory {
|
|
42
|
+
readonly checkpoint: AgentContextCheckpointRecord | null
|
|
43
|
+
/** The messages after the checkpoint, oldest first. */
|
|
44
|
+
readonly messages: readonly AgentMessageRecord[]
|
|
45
|
+
/** The time zone of the run that answered each retained user message, by message id. */
|
|
46
|
+
readonly sentTimeZones: Readonly<Record<string, string>>
|
|
47
|
+
/**
|
|
48
|
+
* The model call that ended the latest assistant message after the checkpoint: what a token
|
|
49
|
+
* estimate anchors on, as the provider counted it.
|
|
50
|
+
*/
|
|
51
|
+
readonly usageAnchor?: {
|
|
52
|
+
readonly messageId: string
|
|
53
|
+
readonly modelCall: AiModelCallUsageRecord
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface AgentChildContext {
|
|
58
|
+
readonly kind: "subagent"
|
|
59
|
+
/** The turn that spawned the child, as it is now. */
|
|
60
|
+
readonly parent: AgentRunRecord | null
|
|
61
|
+
readonly execution: ExecutionRecord | null
|
|
62
|
+
/** The child's own thread. */
|
|
63
|
+
readonly thread: AgentThreadRecord | null
|
|
64
|
+
/** The thread of the conversation the child works for. */
|
|
65
|
+
readonly conversation: AgentThreadRecord | null
|
|
66
|
+
/** The child's thread, oldest first. */
|
|
67
|
+
readonly messages: readonly AgentMessageRecord[]
|
|
68
|
+
/** The run of the thread that paused on its held calls, when this run continues it. */
|
|
69
|
+
readonly paused?: SubagentRunRecord
|
|
70
|
+
/** The display name of whoever asked for the parent turn, by `type:id`, when they have one. */
|
|
71
|
+
readonly names: Readonly<Record<string, string>>
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Read what a run starts from. */
|
|
75
|
+
export async function readAgentRunContext(
|
|
76
|
+
host: AgentRunSessionHost,
|
|
77
|
+
run: AgentRunRecord
|
|
78
|
+
): Promise<AgentRunContext> {
|
|
79
|
+
const execution = await host.storage.executions.getById({
|
|
80
|
+
projectId: host.projectId,
|
|
81
|
+
id: run.executionId,
|
|
82
|
+
})
|
|
83
|
+
return run.kind === "conversation"
|
|
84
|
+
? readTurnContext(host, run, execution)
|
|
85
|
+
: readChildContext(host, run, execution)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A conversation's history: its latest checkpoint and the messages after it. */
|
|
89
|
+
export async function readAgentTurnHistory(
|
|
90
|
+
host: AgentRunSessionHost,
|
|
91
|
+
threadId: string
|
|
92
|
+
): Promise<AgentTurnHistory> {
|
|
93
|
+
const { projectId } = host
|
|
94
|
+
const agents = host.storage.agents
|
|
95
|
+
const checkpoint = await agents.checkpoints.getLatest({ projectId, threadId })
|
|
96
|
+
const { messages } = await agents.messages.list({
|
|
97
|
+
projectId,
|
|
98
|
+
threadId,
|
|
99
|
+
...(checkpoint ? { afterSeq: checkpoint.summarizedThroughSeq } : {}),
|
|
100
|
+
order: "asc",
|
|
101
|
+
})
|
|
102
|
+
const [sentTimeZones, usageAnchor] = await Promise.all([
|
|
103
|
+
readSentTimeZones(host, threadId, messages),
|
|
104
|
+
readUsageAnchor(host, messages, checkpoint?.observedHeadSeq ?? 0),
|
|
105
|
+
])
|
|
106
|
+
return { checkpoint, messages, sentTimeZones, ...(usageAnchor ? { usageAnchor } : {}) }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
async function readTurnContext(
|
|
110
|
+
host: AgentRunSessionHost,
|
|
111
|
+
run: AgentRunRecord & { readonly kind: "conversation" },
|
|
112
|
+
execution: ExecutionRecord | null
|
|
113
|
+
): Promise<AgentTurnContext> {
|
|
114
|
+
const { projectId } = host
|
|
115
|
+
const [thread, participants, history] = await Promise.all([
|
|
116
|
+
host.storage.agents.threads.getById({ projectId, id: run.threadId }),
|
|
117
|
+
host.storage.agents.threads.listParticipants({ projectId, threadIds: [run.threadId] }),
|
|
118
|
+
readAgentTurnHistory(host, run.threadId),
|
|
119
|
+
])
|
|
120
|
+
const readers = await readReaders(host, participants)
|
|
121
|
+
const named: Principal[] = [
|
|
122
|
+
...(execution?.requestedBy?.type === "user" ? [execution.requestedBy] : []),
|
|
123
|
+
...(thread ? [thread.ownerPrincipal] : []),
|
|
124
|
+
...readers,
|
|
125
|
+
...history.messages.flatMap((message) =>
|
|
126
|
+
message.role === "user" && message.authorPrincipal ? [message.authorPrincipal] : []
|
|
127
|
+
),
|
|
128
|
+
]
|
|
129
|
+
return {
|
|
130
|
+
kind: "conversation",
|
|
131
|
+
thread,
|
|
132
|
+
execution,
|
|
133
|
+
participants,
|
|
134
|
+
readers,
|
|
135
|
+
names: await readNames(host, named),
|
|
136
|
+
history,
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async function readChildContext(
|
|
141
|
+
host: AgentRunSessionHost,
|
|
142
|
+
run: SubagentRunRecord,
|
|
143
|
+
execution: ExecutionRecord | null
|
|
144
|
+
): Promise<AgentChildContext> {
|
|
145
|
+
const { projectId } = host
|
|
146
|
+
const agents = host.storage.agents
|
|
147
|
+
const [parent, thread, { messages }, runs] = await Promise.all([
|
|
148
|
+
agents.runs.getById({ projectId, id: run.parentRunId }),
|
|
149
|
+
agents.threads.getById({ projectId, id: run.threadId }),
|
|
150
|
+
agents.messages.list({ projectId, threadId: run.threadId, order: "asc" }),
|
|
151
|
+
listSubagentThreadRuns(agents, { projectId, threadId: run.threadId }),
|
|
152
|
+
])
|
|
153
|
+
const conversation = thread
|
|
154
|
+
? await agents.threads.getById({ projectId, id: conversationThreadId(thread) })
|
|
155
|
+
: null
|
|
156
|
+
// A continuation goes on from the latest run that succeeded: only a child paused on its calls
|
|
157
|
+
// succeeds without ending its thread.
|
|
158
|
+
const previous = runs.filter((each) => each.status === "succeeded").at(-1)
|
|
159
|
+
const paused = previous && isPausedSubagentRun(previous) ? previous : undefined
|
|
160
|
+
return {
|
|
161
|
+
kind: "subagent",
|
|
162
|
+
parent,
|
|
163
|
+
execution,
|
|
164
|
+
thread,
|
|
165
|
+
conversation,
|
|
166
|
+
messages,
|
|
167
|
+
...(paused ? { paused } : {}),
|
|
168
|
+
names: await readNames(host, execution?.requestedBy ? [execution.requestedBy] : []),
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* The participants who can read the thread now: active users the project's roles let use the
|
|
174
|
+
* Agent. Someone added before losing access is not named to the model as taking part.
|
|
175
|
+
*/
|
|
176
|
+
async function readReaders(
|
|
177
|
+
host: AgentRunSessionHost,
|
|
178
|
+
participants: readonly AgentThreadParticipantRecord[]
|
|
179
|
+
): Promise<readonly UserPrincipal[]> {
|
|
180
|
+
const readers = await Promise.all(
|
|
181
|
+
participants.map(async ({ principal }) => {
|
|
182
|
+
const user = await readUser(host, principal.id)
|
|
183
|
+
if (user?.status !== "active") return null
|
|
184
|
+
const allowed = await userCanRunAgent({
|
|
185
|
+
auth: host.storage.auth,
|
|
186
|
+
projectId: host.projectId,
|
|
187
|
+
userId: principal.id,
|
|
188
|
+
security: host.security,
|
|
189
|
+
})
|
|
190
|
+
return allowed ? principal : null
|
|
191
|
+
})
|
|
192
|
+
)
|
|
193
|
+
return readers.filter((reader) => reader !== null)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
async function readNames(
|
|
197
|
+
host: AgentRunSessionHost,
|
|
198
|
+
principals: readonly Principal[]
|
|
199
|
+
): Promise<Readonly<Record<string, string>>> {
|
|
200
|
+
const users = [
|
|
201
|
+
...new Set(
|
|
202
|
+
principals.flatMap((principal) => (principal.type === "user" ? [principal.id] : []))
|
|
203
|
+
),
|
|
204
|
+
]
|
|
205
|
+
const names: Record<string, string> = {}
|
|
206
|
+
await Promise.all(
|
|
207
|
+
users.map(async (id) => {
|
|
208
|
+
const name = (await readUser(host, id))?.displayName
|
|
209
|
+
if (name) names[`user:${id}`] = name
|
|
210
|
+
})
|
|
211
|
+
)
|
|
212
|
+
return names
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function readUser(host: AgentRunSessionHost, id: string) {
|
|
216
|
+
return host.storage.auth.users.getById({ projectId: host.projectId, id })
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** The time zone each retained user message was sent in: the zone of the run that answered it. */
|
|
220
|
+
async function readSentTimeZones(
|
|
221
|
+
host: AgentRunSessionHost,
|
|
222
|
+
threadId: string,
|
|
223
|
+
messages: readonly AgentMessageRecord[]
|
|
224
|
+
): Promise<Readonly<Record<string, string>>> {
|
|
225
|
+
const userMessages = messages.filter((message) => message.role === "user")
|
|
226
|
+
const oldest = userMessages[0]
|
|
227
|
+
if (!oldest) return {}
|
|
228
|
+
|
|
229
|
+
// A run starts after its trigger message, so this window holds every run that answered one.
|
|
230
|
+
const { runs } = await host.storage.agents.runs.list({
|
|
231
|
+
projectId: host.projectId,
|
|
232
|
+
threadId,
|
|
233
|
+
kinds: ["conversation"],
|
|
234
|
+
startedAfter: new Date(oldest.createdAt.getTime() - 1),
|
|
235
|
+
})
|
|
236
|
+
const retained = new Set(userMessages.map((message) => message.id))
|
|
237
|
+
const zones: Record<string, string> = {}
|
|
238
|
+
for (const run of runs) {
|
|
239
|
+
if (run.kind === "conversation" && run.spec?.timeZone && retained.has(run.triggerMessageId)) {
|
|
240
|
+
zones[run.triggerMessageId] = run.spec.timeZone
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return zones
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
async function readUsageAnchor(
|
|
247
|
+
host: AgentRunSessionHost,
|
|
248
|
+
messages: readonly AgentMessageRecord[],
|
|
249
|
+
afterSeq: number
|
|
250
|
+
): Promise<AgentTurnHistory["usageAnchor"]> {
|
|
251
|
+
const anchor = [...messages]
|
|
252
|
+
.reverse()
|
|
253
|
+
.find((message) => message.role === "assistant" && message.seq > afterSeq && message.runId)
|
|
254
|
+
if (!anchor?.runId) return undefined
|
|
255
|
+
const run = await host.storage.agents.runs.getById({
|
|
256
|
+
projectId: host.projectId,
|
|
257
|
+
id: anchor.runId,
|
|
258
|
+
})
|
|
259
|
+
if (!run) return undefined
|
|
260
|
+
const modelCall = await host.storage.aiUsage.getLatestForExecution({
|
|
261
|
+
projectId: host.projectId,
|
|
262
|
+
executionId: run.executionId,
|
|
263
|
+
})
|
|
264
|
+
return modelCall ? { messageId: anchor.id, modelCall } : undefined
|
|
265
|
+
}
|