@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,284 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test"
|
|
2
|
+
import { randomUUID } from "node:crypto"
|
|
3
|
+
import type { CommandResult, Sandbox, SandboxFactory, SandboxRequestCredential } from "../sandboxes"
|
|
4
|
+
|
|
5
|
+
export interface SandboxCredentialsContractSuiteOptions {
|
|
6
|
+
/** A factory that advertises `supportsRequestCredentials`. */
|
|
7
|
+
readonly createFactory: () => SandboxFactory | Promise<SandboxFactory>
|
|
8
|
+
/**
|
|
9
|
+
* The origin guest commands reach the suite's server at, given the port it listens on. Defaults
|
|
10
|
+
* to its loopback address, which only a provider running commands on this host can reach.
|
|
11
|
+
*/
|
|
12
|
+
readonly originFor?: (port: number) => string
|
|
13
|
+
/**
|
|
14
|
+
* Whether one sandbox's commands are kept from another's credentials. Defaults to true; false
|
|
15
|
+
* only for a provider that runs commands without isolation.
|
|
16
|
+
*/
|
|
17
|
+
readonly separatesSandboxes?: boolean
|
|
18
|
+
/**
|
|
19
|
+
* Where the provider keeps credentials on the commands' side of the boundary, such as a guest
|
|
20
|
+
* forwarder's state: the suite tries to read everything under them.
|
|
21
|
+
*/
|
|
22
|
+
readonly privatePaths?: readonly string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Provider-independent contract for request credentials: a command reaches the credential's
|
|
27
|
+
* origin with the credential added outside the guest, and nothing the command can read holds it.
|
|
28
|
+
* The suite listens on this host, so the provider's commands must be able to reach it.
|
|
29
|
+
*/
|
|
30
|
+
export function runSandboxCredentialsContractSuite(
|
|
31
|
+
label: string,
|
|
32
|
+
options: SandboxCredentialsContractSuiteOptions
|
|
33
|
+
): void {
|
|
34
|
+
describe(label, () => {
|
|
35
|
+
let server: ReturnType<typeof Bun.serve>
|
|
36
|
+
let origin: string
|
|
37
|
+
/** A second origin, so a test can tell a credential stays on its own. */
|
|
38
|
+
let otherServer: ReturnType<typeof Bun.serve>
|
|
39
|
+
let otherOrigin: string
|
|
40
|
+
let factory: SandboxFactory
|
|
41
|
+
const received: (string | null)[] = []
|
|
42
|
+
|
|
43
|
+
// Echoes what reached it, so a test can tell the credential was added on the way.
|
|
44
|
+
const listen = () =>
|
|
45
|
+
Bun.serve({
|
|
46
|
+
hostname: "0.0.0.0",
|
|
47
|
+
port: 0,
|
|
48
|
+
fetch: (request) => {
|
|
49
|
+
received.push(request.headers.get("authorization"))
|
|
50
|
+
return Response.json({
|
|
51
|
+
method: request.method,
|
|
52
|
+
path: new URL(request.url).pathname,
|
|
53
|
+
authorization: request.headers.get("authorization"),
|
|
54
|
+
})
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
const originOf = ({ port }: ReturnType<typeof Bun.serve>) =>
|
|
58
|
+
options.originFor?.(port ?? 0) ?? `http://127.0.0.1:${port}`
|
|
59
|
+
|
|
60
|
+
beforeAll(async () => {
|
|
61
|
+
server = listen()
|
|
62
|
+
otherServer = listen()
|
|
63
|
+
origin = originOf(server)
|
|
64
|
+
otherOrigin = originOf(otherServer)
|
|
65
|
+
factory = await options.createFactory()
|
|
66
|
+
expect(factory.supportsRequestCredentials).toBe(true)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
afterAll(() => {
|
|
70
|
+
server.stop(true)
|
|
71
|
+
otherServer.stop(true)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const credential = (
|
|
75
|
+
secret: string,
|
|
76
|
+
overrides: Partial<SandboxRequestCredential> = {}
|
|
77
|
+
): SandboxRequestCredential => ({
|
|
78
|
+
origin,
|
|
79
|
+
path: { prefix: "/api/" },
|
|
80
|
+
method: ["GET", "POST"],
|
|
81
|
+
headers: { Authorization: `Bearer ${secret}` },
|
|
82
|
+
...overrides,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
async function withSandbox(
|
|
86
|
+
credentials: readonly SandboxRequestCredential[],
|
|
87
|
+
use: (sandbox: Sandbox) => Promise<void>
|
|
88
|
+
): Promise<void> {
|
|
89
|
+
const sandbox = await factory.create({
|
|
90
|
+
network: {
|
|
91
|
+
mode: "restricted",
|
|
92
|
+
allow: [
|
|
93
|
+
{ name: "credentials-suite", origin },
|
|
94
|
+
{ name: "credentials-suite-other", origin: otherOrigin },
|
|
95
|
+
],
|
|
96
|
+
},
|
|
97
|
+
requestCredentials: credentials,
|
|
98
|
+
})
|
|
99
|
+
try {
|
|
100
|
+
await use(sandbox)
|
|
101
|
+
} finally {
|
|
102
|
+
await sandbox.destroy()
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
test("a command reaches the origin with the credential added", async () => {
|
|
107
|
+
const secret = `suite-${randomUUID()}`
|
|
108
|
+
await withSandbox([credential(secret)], async (sandbox) => {
|
|
109
|
+
const seen = await request(sandbox, origin, "/api/whoami")
|
|
110
|
+
expect(seen).toEqual({
|
|
111
|
+
method: "GET",
|
|
112
|
+
path: "/api/whoami",
|
|
113
|
+
authorization: `Bearer ${secret}`,
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
test("only a request the credential matches gets it, replacing the command's own", async () => {
|
|
119
|
+
const secret = `suite-${randomUUID()}`
|
|
120
|
+
await withSandbox([credential(secret)], async (sandbox) => {
|
|
121
|
+
expect((await request(sandbox, origin, "/health")).authorization).toBeNull()
|
|
122
|
+
expect(
|
|
123
|
+
(await request(sandbox, origin, "/api/x", { method: "DELETE" })).authorization
|
|
124
|
+
).toBeNull()
|
|
125
|
+
const forged = await request(sandbox, origin, "/api/x", { authorization: "Bearer guest" })
|
|
126
|
+
expect(forged.authorization).toBe(`Bearer ${secret}`)
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// Guard proof: drop the origin check from `matches` in @sixb/sandboxes-local's
|
|
131
|
+
// credential-forwarder.ts; the other origin gets this origin's credential.
|
|
132
|
+
test("a credential reaches its own origin alone, whatever the paths it shares", async () => {
|
|
133
|
+
const secret = `suite-${randomUUID()}`
|
|
134
|
+
const otherSecret = `suite-${randomUUID()}`
|
|
135
|
+
const credentials = [
|
|
136
|
+
credential(secret),
|
|
137
|
+
credential(otherSecret, { origin: otherOrigin, path: { prefix: "/api/v2/" } }),
|
|
138
|
+
]
|
|
139
|
+
await withSandbox(credentials, async (sandbox) => {
|
|
140
|
+
const authorization = async (on: string, path: string) =>
|
|
141
|
+
(await request(sandbox, on, path)).authorization
|
|
142
|
+
|
|
143
|
+
expect(await authorization(origin, "/api/v2/x")).toBe(`Bearer ${secret}`)
|
|
144
|
+
expect(await authorization(otherOrigin, "/api/v2/x")).toBe(`Bearer ${otherSecret}`)
|
|
145
|
+
expect(await authorization(otherOrigin, "/api/x")).toBeNull()
|
|
146
|
+
})
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
test("setRequestCredentials replaces the credentials, and an empty list removes them", async () => {
|
|
150
|
+
const first = `suite-${randomUUID()}`
|
|
151
|
+
const second = `suite-${randomUUID()}`
|
|
152
|
+
await withSandbox([credential(first)], async (sandbox) => {
|
|
153
|
+
if (!sandbox.setRequestCredentials) throw new Error("setRequestCredentials is missing")
|
|
154
|
+
await sandbox.setRequestCredentials([credential(second)])
|
|
155
|
+
expect((await request(sandbox, origin, "/api/x")).authorization).toBe(`Bearer ${second}`)
|
|
156
|
+
await sandbox.setRequestCredentials([])
|
|
157
|
+
expect((await request(sandbox, origin, "/api/x")).authorization).toBeNull()
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
// Guard proof: drop the forwarder's rules from buildSeatbeltProfile (macOS) or buildBwrapArgv
|
|
162
|
+
// (Linux) in @sixb/sandboxes-local; B's command gets A's credential.
|
|
163
|
+
test.skipIf(options.separatesSandboxes === false)(
|
|
164
|
+
"a sandbox's commands can't use another sandbox's credentials",
|
|
165
|
+
async () => {
|
|
166
|
+
const secretA = `suite-${randomUUID()}`
|
|
167
|
+
const secretB = `suite-${randomUUID()}`
|
|
168
|
+
await withSandbox([credential(secretA)], async (a) => {
|
|
169
|
+
if (!a.credentialedUrl) throw new Error("credentialedUrl is missing")
|
|
170
|
+
const address = a.credentialedUrl(origin)
|
|
171
|
+
|
|
172
|
+
await withSandbox([credential(secretB)], async (b) => {
|
|
173
|
+
// The request may fail; whatever it reaches, A's credential must not come with it.
|
|
174
|
+
const result = await send(b, address, "/api/whoami")
|
|
175
|
+
expect(result.stdout).not.toContain(secretA)
|
|
176
|
+
expect(result.stderr).not.toContain(secretA)
|
|
177
|
+
})
|
|
178
|
+
})
|
|
179
|
+
expect(received).not.toContain(`Bearer ${secretA}`)
|
|
180
|
+
}
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
test("nothing a command can read holds the credential", async () => {
|
|
184
|
+
const secret = `suite-${randomUUID()}`
|
|
185
|
+
await withSandbox([credential(secret)], async (sandbox) => {
|
|
186
|
+
// The command's env, every process's command line and env it may read, and its files.
|
|
187
|
+
const looked = await sandbox.runCommand("bash", [
|
|
188
|
+
"-c",
|
|
189
|
+
[
|
|
190
|
+
"env",
|
|
191
|
+
"ps -eo args 2>/dev/null",
|
|
192
|
+
"cat /proc/*/environ /proc/*/cmdline 2>/dev/null | tr '\\0' '\\n'",
|
|
193
|
+
"find . -type f -exec cat {} + 2>/dev/null",
|
|
194
|
+
...(options.privatePaths ?? []).map(
|
|
195
|
+
(path) => `find '${path}' -type f -exec cat {} + 2>/dev/null`
|
|
196
|
+
),
|
|
197
|
+
].join("; "),
|
|
198
|
+
])
|
|
199
|
+
expect(looked.stdout.length).toBeGreaterThan(0)
|
|
200
|
+
expect(looked.stdout).not.toContain(secret)
|
|
201
|
+
expect(looked.stderr).not.toContain(secret)
|
|
202
|
+
})
|
|
203
|
+
})
|
|
204
|
+
})
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** One request from a command, through the sandbox's credentialed address for `origin`. */
|
|
208
|
+
async function request(
|
|
209
|
+
sandbox: Sandbox,
|
|
210
|
+
origin: string,
|
|
211
|
+
path: string,
|
|
212
|
+
options: RequestOptions = {}
|
|
213
|
+
): Promise<{
|
|
214
|
+
readonly method: string
|
|
215
|
+
readonly path: string
|
|
216
|
+
readonly authorization: string | null
|
|
217
|
+
}> {
|
|
218
|
+
if (!sandbox.credentialedUrl) throw new Error("credentialedUrl is missing")
|
|
219
|
+
const address = sandbox.credentialedUrl(origin)
|
|
220
|
+
const result = await send(sandbox, address, path, options)
|
|
221
|
+
if (result.exitCode !== 0) {
|
|
222
|
+
throw new Error(
|
|
223
|
+
`a request through ${address} failed: ${result.stderr.trim() || result.exitCode}`
|
|
224
|
+
)
|
|
225
|
+
}
|
|
226
|
+
return JSON.parse(result.stdout)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
interface RequestOptions {
|
|
230
|
+
readonly method?: string
|
|
231
|
+
readonly authorization?: string
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** One request from a command, through `address`, whatever comes of it. */
|
|
235
|
+
function send(
|
|
236
|
+
sandbox: Sandbox,
|
|
237
|
+
address: string,
|
|
238
|
+
path: string,
|
|
239
|
+
options: RequestOptions = {}
|
|
240
|
+
): Promise<CommandResult> {
|
|
241
|
+
return sandbox.runCommand("sh", ["-c", REQUEST_SCRIPT], {
|
|
242
|
+
env: {
|
|
243
|
+
SUITE_ADDRESS: address,
|
|
244
|
+
SUITE_PATH: path,
|
|
245
|
+
SUITE_METHOD: options.method ?? "GET",
|
|
246
|
+
SUITE_AUTHORIZATION: options.authorization ?? "",
|
|
247
|
+
SUITE_FETCH: FETCH_PROGRAM,
|
|
248
|
+
},
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// curl where the guest has it, else Bun or Node: a guest that runs `sixb` has one.
|
|
253
|
+
const REQUEST_SCRIPT = `set -eu
|
|
254
|
+
if command -v curl >/dev/null 2>&1; then
|
|
255
|
+
set -- -sS -m 10 -X "$SUITE_METHOD"
|
|
256
|
+
[ -z "$SUITE_AUTHORIZATION" ] || set -- "$@" -H "Authorization: $SUITE_AUTHORIZATION"
|
|
257
|
+
case "$SUITE_ADDRESS" in
|
|
258
|
+
unix:*) exec curl "$@" --unix-socket "\${SUITE_ADDRESS#unix:}" "http://localhost$SUITE_PATH" ;;
|
|
259
|
+
*) exec curl "$@" "\${SUITE_ADDRESS%/}$SUITE_PATH" ;;
|
|
260
|
+
esac
|
|
261
|
+
elif command -v bun >/dev/null 2>&1; then
|
|
262
|
+
exec bun -e "$SUITE_FETCH"
|
|
263
|
+
else
|
|
264
|
+
exec node --input-type=module -e "$SUITE_FETCH"
|
|
265
|
+
fi`
|
|
266
|
+
|
|
267
|
+
const FETCH_PROGRAM = `const { SUITE_ADDRESS: address, SUITE_PATH: path, SUITE_METHOD: method } = process.env
|
|
268
|
+
const headers = process.env.SUITE_AUTHORIZATION ? { authorization: process.env.SUITE_AUTHORIZATION } : {}
|
|
269
|
+
if (!address.startsWith("unix:")) {
|
|
270
|
+
console.log(await (await fetch(address.replace(/\\/+$/, "") + path, { method, headers })).text())
|
|
271
|
+
} else if (typeof Bun !== "undefined") {
|
|
272
|
+
console.log(await (await fetch("http://localhost" + path, { method, headers, unix: address.slice(5) })).text())
|
|
273
|
+
} else {
|
|
274
|
+
const http = await import("node:http")
|
|
275
|
+
console.log(await new Promise((resolve, reject) => {
|
|
276
|
+
const sent = http.request({ socketPath: address.slice(5), path, method, headers: { ...headers, host: "localhost" } }, (response) => {
|
|
277
|
+
let body = ""
|
|
278
|
+
response.on("data", (chunk) => { body += chunk })
|
|
279
|
+
response.on("end", () => resolve(body))
|
|
280
|
+
})
|
|
281
|
+
sent.on("error", reject)
|
|
282
|
+
sent.end()
|
|
283
|
+
}))
|
|
284
|
+
}`
|
|
@@ -272,6 +272,27 @@ export function runSandboxesContractSuite(
|
|
|
272
272
|
await sandbox.destroy()
|
|
273
273
|
}
|
|
274
274
|
})
|
|
275
|
+
|
|
276
|
+
// An agent's commands are shell lines: the shell waits on `sleep`, which holds its output.
|
|
277
|
+
test("abort stops a shell and the commands it started", async () => {
|
|
278
|
+
const sandbox = await factory.create()
|
|
279
|
+
try {
|
|
280
|
+
const ac = new AbortController()
|
|
281
|
+
setTimeout(() => ac.abort(), shortTimeoutMs)
|
|
282
|
+
const start = Date.now()
|
|
283
|
+
const result = await sandbox.runCommand(
|
|
284
|
+
"sh",
|
|
285
|
+
["-c", `sleep ${SLEEP_BUDGET_SECONDS} && echo finished`],
|
|
286
|
+
{ signal: ac.signal }
|
|
287
|
+
)
|
|
288
|
+
const elapsed = Date.now() - start
|
|
289
|
+
expect(result.exitCode).not.toBe(0)
|
|
290
|
+
expect(result.stdout).not.toContain("finished")
|
|
291
|
+
expect(elapsed).toBeLessThan(SLEEP_BUDGET_SECONDS * 1000)
|
|
292
|
+
} finally {
|
|
293
|
+
await sandbox.destroy()
|
|
294
|
+
}
|
|
295
|
+
})
|
|
275
296
|
})
|
|
276
297
|
|
|
277
298
|
describe("file materialization", () => {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Storage, UserStatus } from "../storage"
|
|
2
|
+
import { toUserProfile, type UserProfile } from "../users/execution"
|
|
3
|
+
|
|
4
|
+
/** A member to seed, with the fields the member directory shows. */
|
|
5
|
+
export interface TestUser {
|
|
6
|
+
readonly id: string
|
|
7
|
+
readonly email: string
|
|
8
|
+
readonly displayName?: string
|
|
9
|
+
readonly avatarUrl?: string
|
|
10
|
+
/** Defaults to `"active"`. */
|
|
11
|
+
readonly status?: UserStatus
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Add members to a test host, so objects, actions and workflows can reference them with
|
|
16
|
+
* `userRef(id)`. Ids and emails must be unique in the project. Returns their profiles, in order.
|
|
17
|
+
*/
|
|
18
|
+
export async function seedTestUsers(
|
|
19
|
+
host: { readonly id: string; readonly storage: Pick<Storage, "auth"> },
|
|
20
|
+
users: readonly TestUser[]
|
|
21
|
+
): Promise<UserProfile[]> {
|
|
22
|
+
const store = host.storage.auth?.users
|
|
23
|
+
if (!store) {
|
|
24
|
+
throw new Error("[Sixb] seedTestUsers needs storage with auth, such as InMemoryStorage.")
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// A millisecond apart: the directory lists members oldest first, so it keeps the order given.
|
|
28
|
+
const seededAt = Date.now()
|
|
29
|
+
const profiles: UserProfile[] = []
|
|
30
|
+
for (const [index, user] of users.entries()) {
|
|
31
|
+
const record = await store.create({
|
|
32
|
+
...user,
|
|
33
|
+
projectId: host.id,
|
|
34
|
+
createdAt: new Date(seededAt + index),
|
|
35
|
+
})
|
|
36
|
+
profiles.push(toUserProfile(record))
|
|
37
|
+
}
|
|
38
|
+
return profiles
|
|
39
|
+
}
|
package/src/users/execution.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type { UserRecord, UserStatus } from "../storage"
|
|
|
6
6
|
const DEFAULT_LIMIT = 50
|
|
7
7
|
const MAX_LIMIT = 200
|
|
8
8
|
const MAX_SEARCH_LENGTH = 200
|
|
9
|
+
const MAX_EMAIL_LENGTH = 320
|
|
9
10
|
|
|
10
11
|
/** A member as the directory shows them. Read from auth storage, never from what a writer stored. */
|
|
11
12
|
export interface UserProfile {
|
|
@@ -29,6 +30,9 @@ export interface ListUsersInput {
|
|
|
29
30
|
readonly offset?: number
|
|
30
31
|
}
|
|
31
32
|
|
|
33
|
+
/** The member `users.get` reads: by user reference, or by email, matched exactly but ignoring case. */
|
|
34
|
+
export type UserLookup = UserRef | { readonly email: string }
|
|
35
|
+
|
|
32
36
|
/** One page of members, oldest first. */
|
|
33
37
|
export interface UsersPage {
|
|
34
38
|
readonly users: readonly UserProfile[]
|
|
@@ -39,8 +43,8 @@ export interface UsersPage {
|
|
|
39
43
|
|
|
40
44
|
/** The project's member directory. Reading it requires `can.view(project.users)`. */
|
|
41
45
|
export interface UsersRuntime {
|
|
42
|
-
/** The member's profile, suspended or not, or `null` when no member has this id. */
|
|
43
|
-
get(user:
|
|
46
|
+
/** The member's profile, suspended or not, or `null` when no member has this id or email. */
|
|
47
|
+
get(user: UserLookup): Promise<UserProfile | null>
|
|
44
48
|
list(input?: ListUsersInput): Promise<UsersPage>
|
|
45
49
|
}
|
|
46
50
|
|
|
@@ -50,15 +54,15 @@ export function createUsersRuntime(runtime: SixbRuntimeContext): UsersRuntime {
|
|
|
50
54
|
return {
|
|
51
55
|
get: async (user) => {
|
|
52
56
|
assertReadable()
|
|
53
|
-
|
|
54
|
-
if (!isUserRef(user)) {
|
|
55
|
-
throw new Error("[Sixb] users.get expects a user reference, such as userRef(id).")
|
|
56
|
-
}
|
|
57
|
+
const lookup = userLookup(user)
|
|
57
58
|
|
|
58
59
|
const users = runtime.storage.auth?.users
|
|
59
60
|
if (!users) return null
|
|
60
61
|
|
|
61
|
-
const record =
|
|
62
|
+
const record =
|
|
63
|
+
"email" in lookup
|
|
64
|
+
? await users.getByEmail({ projectId: runtime.projectId, email: lookup.email })
|
|
65
|
+
: await users.getById({ projectId: runtime.projectId, id: lookup.id })
|
|
62
66
|
return record ? toUserProfile(record) : null
|
|
63
67
|
},
|
|
64
68
|
|
|
@@ -101,6 +105,28 @@ export function toUserProfile(record: UserRecord): UserProfile {
|
|
|
101
105
|
}
|
|
102
106
|
}
|
|
103
107
|
|
|
108
|
+
function userLookup(user: UserLookup): UserLookup {
|
|
109
|
+
if (isUserRef(user)) return user
|
|
110
|
+
if (isEmailLookup(user)) {
|
|
111
|
+
const email = user.email.trim()
|
|
112
|
+
if (email && email.length <= MAX_EMAIL_LENGTH) return { email }
|
|
113
|
+
|
|
114
|
+
throw new Error(
|
|
115
|
+
`[Sixb] users.get email must be nonblank and at most ${MAX_EMAIL_LENGTH} characters.`
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
throw new Error(
|
|
120
|
+
'[Sixb] users.get expects a user reference, such as userRef(id), or { email: "ava@acme.com" }.'
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function isEmailLookup(value: unknown): value is { readonly email: string } {
|
|
125
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return false
|
|
126
|
+
const keys = Object.keys(value)
|
|
127
|
+
return keys.length === 1 && keys[0] === "email" && typeof Reflect.get(value, "email") === "string"
|
|
128
|
+
}
|
|
129
|
+
|
|
104
130
|
function statusFilter(status: ListUsersInput["status"] = "active") {
|
|
105
131
|
if (status === "all") return {}
|
|
106
132
|
if (status === "active" || status === "suspended") return { statuses: [status] }
|
package/src/users/index.ts
CHANGED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { type AgentApiEffect } from "../http/api-routes";
|
|
2
|
-
export declare const AGENT_API_GATEWAY_PREFIX = "/__sixb/agent-api";
|
|
3
|
-
export interface AgentApiGatewayCapabilityInput {
|
|
4
|
-
readonly projectId: string;
|
|
5
|
-
readonly runId: string;
|
|
6
|
-
readonly executionToken: string;
|
|
7
|
-
}
|
|
8
|
-
export interface AgentApiRoute {
|
|
9
|
-
readonly method: string;
|
|
10
|
-
readonly path: string;
|
|
11
|
-
/** What a call changes; a GET reads. */
|
|
12
|
-
readonly effect: AgentApiEffect;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* The routes the agent API gateway may proxy — the `agentApi` projection of the canonical
|
|
16
|
-
* {@link SIXB_API_ROUTES} table, so this list can never drift from (nor exceed) the bearer boundary.
|
|
17
|
-
*/
|
|
18
|
-
export declare const AGENT_API_ROUTES: readonly AgentApiRoute[];
|
|
19
|
-
export declare function createAgentApiGatewayCapability(input: AgentApiGatewayCapabilityInput): string;
|
|
20
|
-
export declare function isValidAgentApiGatewayCapability(input: AgentApiGatewayCapabilityInput & {
|
|
21
|
-
readonly capability: string;
|
|
22
|
-
}): boolean;
|
|
23
|
-
export declare function isAllowedAgentApiRequest(method: string, pathname: string): boolean;
|
|
24
|
-
/** The gateway route a request matches, with what it changes. */
|
|
25
|
-
export declare function findAgentApiRoute(method: string, pathname: string): AgentApiRoute | undefined;
|
|
26
|
-
//# sourceMappingURL=api-gateway.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"api-gateway.d.ts","sourceRoot":"","sources":["../../src/agents/api-gateway.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAmB,MAAM,oBAAoB,CAAA;AAGzE,eAAO,MAAM,wBAAwB,sBAAsB,CAAA;AAI3D,MAAM,WAAW,8BAA8B;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;CAChC;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,wCAAwC;IACxC,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAA;CAChC;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,SAAS,aAAa,EAMlD,CAAA;AAEH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,8BAA8B,GAAG,MAAM,CAE7F;AAED,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,8BAA8B,GAAG;IAAE,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GACtE,OAAO,CAST;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAElF;AAED,iEAAiE;AACjE,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAM7F"}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/models/execution/model-call-limits.ts", "../src/models/execution/errors.ts", "../src/models/execution/model-call-accounting.ts", "../src/models/execution/usage.ts", "../src/models/execution/model-call-recovery.ts", "../src/models/execution/model-call-recorder.ts", "../src/models/execution/model-call-admission.ts", "../src/models/execution/recovery-queue.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import { isSixbError } from \"../../errors/internal\"\nimport type { AuthorizablePrincipal } from \"../../execution\"\nimport type {\n AiLimitPolicy,\n AiLimitQuantity,\n AiModelCallReservationIdentity,\n ReserveAiModelCallResult,\n} from \"../../storage\"\nimport {\n aiLimitSubjectsFromAttribution,\n aiUsageLimitExceededError,\n aiUsageLimitUnavailableError,\n applicableAiLimitPolicies,\n} from \"../../storage/ai-limits/enforcement\"\nimport { aiLimitMeterApplies } from \"../../storage/ai-limits/provider\"\nimport type {\n AiModelCallAdmissionDecision,\n AiModelCallAdmissionInput,\n BeforeAiModelCall,\n MarkAiModelCallUnknown,\n} from \"./model-call-admission\"\nimport type { ModelCallAccountingStorage } from \"./types\"\n\nexport interface AiModelCallLimitController {\n readonly beforeModelCall: BeforeAiModelCall\n readonly markModelCallUnknown: MarkAiModelCallUnknown\n}\n\n/** Build the reservation lifecycle for model calls from any execution. */\nexport function createAiModelCallLimitController(input: {\n readonly storage: Pick<ModelCallAccountingStorage, \"aiLimits\">\n readonly projectId: string\n readonly requestedBy?: AuthorizablePrincipal\n readonly requesterGroupIds: readonly string[]\n}): AiModelCallLimitController {\n const subjects = aiLimitSubjectsFromAttribution(input.requestedBy, input.requesterGroupIds)\n\n return {\n beforeModelCall: async (admission) => {\n let applicable: readonly AiLimitPolicy[]\n try {\n const policies = await input.storage.aiLimits.listPolicies({\n projectId: input.projectId,\n })\n applicable = applicableAiLimitPolicies(policies, subjects).filter((policy) =>\n aiLimitMeterApplies(policy.limit.meter, admission.modelKind)\n )\n } catch (error) {\n throw limitStorageUnavailable(error)\n }\n // This read is the fast no-policy path. A concurrently created policy linearizes after it;\n // every later call will see it, while existing policies always continue to atomic reserve.\n if (applicable.length === 0) return { reservation: \"none\" }\n\n const estimates = reservationEstimates(\n admission,\n applicable.some((policy) => policy.limit.meter === \"cost.catalogEstimated\")\n )\n if (estimates.length === 0) {\n throw aiUsageLimitUnavailableError([\"missingEstimate\"])\n }\n\n let result: ReserveAiModelCallResult\n try {\n result = await input.storage.aiLimits.reserveModelCall({\n ...reservationIdentity(admission),\n subjects,\n estimates,\n ...(admission.modelKind === undefined ? {} : { modelKind: admission.modelKind }),\n })\n } catch (error) {\n throw limitStorageUnavailable(error)\n }\n switch (result.status) {\n case \"reserved\":\n return { reservation: \"active\" } satisfies AiModelCallAdmissionDecision\n case \"notRequired\":\n return { reservation: \"none\" } satisfies AiModelCallAdmissionDecision\n case \"denied\":\n throw aiUsageLimitExceededError(result.resetAt)\n case \"unavailable\":\n throw aiUsageLimitUnavailableError(result.reasons)\n case \"terminal\":\n throw aiUsageLimitUnavailableError([\"terminalReservationReplay\"])\n }\n },\n markModelCallUnknown: async (identity) => {\n try {\n await input.storage.aiLimits.markReservationUnknown(identity)\n } catch (error) {\n throw limitStorageUnavailable(error)\n }\n },\n }\n}\n\nfunction reservationEstimates(\n input: AiModelCallAdmissionInput,\n needsCost: boolean\n): readonly AiLimitQuantity[] {\n const estimates: AiLimitQuantity[] = []\n if (input.inputTokens.status === \"estimated\" && input.estimatedTotalTokens !== undefined) {\n estimates.push({ meter: \"tokens.total\", amount: input.estimatedTotalTokens })\n }\n\n if (needsCost) {\n try {\n let money = input.reservationCost\n if (money == null && input.inputTokens.status === \"estimated\") {\n money = input.costEstimator?.estimateReservation?.({\n inputTokens: input.inputTokens.tokens,\n outputTokens: input.outputTokenAllowance,\n })\n }\n\n if (money) {\n estimates.push({ meter: \"cost.catalogEstimated\", amount: money })\n }\n } catch {\n // An unavailable price must not prevent a token-only policy from being evaluated.\n return estimates\n }\n }\n\n return estimates\n}\n\nfunction reservationIdentity(input: AiModelCallAdmissionInput): AiModelCallReservationIdentity {\n return {\n projectId: input.projectId,\n executionId: input.executionId,\n attempt: input.attempt,\n callId: input.callId,\n }\n}\n\nfunction limitStorageUnavailable(error: unknown): unknown {\n if (\n isSixbError(error) &&\n (error.code === \"ai.usage_limit_exceeded\" || error.code === \"ai.usage_limit_unavailable\")\n ) {\n return error\n }\n return aiUsageLimitUnavailableError([\"limitStorageUnavailable\"])\n}\n",
|
|
6
|
-
"/** A provider call was not recorded synchronously, so its execution must stop. */\nexport class ModelUsageRecordingError extends Error {\n readonly name = \"ModelUsageRecordingError\"\n\n constructor(\n readonly executionId: string,\n readonly callId: string,\n readonly recoveryScheduled: boolean,\n options?: ErrorOptions\n ) {\n super(\n recoveryScheduled\n ? `[SixbModels] AI usage for call '${callId}' in execution '${executionId}' was deferred to durable recovery.`\n : `[SixbModels] Could not preserve AI usage for call '${callId}' in execution '${executionId}'.`,\n options\n )\n }\n}\n",
|
|
7
|
-
"import { createHash } from \"node:crypto\"\nimport { assertJsonObject } from \"../../json\"\nimport type {\n AiBillableMeter,\n AiCostStorage,\n AiLimitStorage,\n AiModelCallCostRecord,\n AiModelCallUsageRecord,\n AiPricingContext,\n AiUsageStorage,\n RecordAiModelCallResult,\n Storage,\n} from \"../../storage\"\nimport {\n aiModelCallCostMatchesUsage,\n normalizeAiModelCallCostRecord,\n} from \"../../storage/ai-cost/provider\"\nimport { normalizeAiModelCallRecord } from \"../../storage/ai-usage/record\"\nimport type { ModelCostEstimate } from \"../pricing\"\nimport type { ModelCallAccountingStorage, RecoverAiModelCallInput } from \"./types\"\n\ninterface RecordAiModelCallAccountingInput extends RecoverAiModelCallInput {\n readonly storage: Pick<ModelCallAccountingStorage, \"transaction\">\n}\n\ninterface AiAccountingCapabilities {\n readonly aiUsage: AiUsageStorage\n readonly aiCosts: AiCostStorage\n readonly aiLimits: AiLimitStorage\n}\n\n/** Atomically append one provider call's usage and the valuation captured by the model runtime. */\nexport async function recordAiModelCallAccounting(\n input: RecordAiModelCallAccountingInput\n): Promise<RecordAiModelCallResult> {\n return input.storage.transaction(async (tx) => {\n const { aiUsage, aiCosts, aiLimits } = requireAccountingCapabilities(tx)\n const usage = await aiUsage.recordModelCall(input.usage)\n // Usage deduplicates provider lifecycle replays by execution/call identity. Always attach the\n // valuation to the canonical row it returns, not the fresh candidate ID from a replay.\n const canonical = normalizeModelCallAccounting({\n ...input,\n usage: usage.record,\n ratedAt: usage.record.recordedAt,\n })\n const record = modelCostRecord(canonical, usage.record.id)\n const estimate =\n canonical.cost.status !== \"reported\" || canonical.estimate === undefined\n ? undefined\n : modelCostRecord({ ...canonical, cost: canonical.estimate }, usage.record.id)\n await aiCosts.recordModelCallCost({\n ...record,\n ...(estimate === undefined\n ? {}\n : {\n estimate:\n estimate.status === \"rated\"\n ? { status: \"rated\", money: estimate.money, components: estimate.components }\n : {\n status: \"unpriceable\",\n reason: estimate.reason,\n ...(estimate.missingMeters === undefined\n ? {}\n : { missingMeters: estimate.missingMeters }),\n },\n }),\n })\n if (usage.created) {\n await aiLimits.recordModelCallActuals({\n projectId: usage.record.projectId,\n usageRecordId: usage.record.id,\n recordedAt: input.ratedAt,\n })\n }\n if (input.reconcileLimitReservation) {\n await aiLimits.reconcileModelCall({\n projectId: usage.record.projectId,\n executionId: usage.record.executionId,\n attempt: usage.record.attempt,\n callId: usage.record.callId,\n usageRecordId: usage.record.id,\n reconciledAt: input.ratedAt,\n })\n }\n return usage\n })\n}\n\n/** Sanitize optional enrichment before either persistence or a JSON-safe recovery handoff. */\nexport function normalizeModelCallAccounting(\n input: RecoverAiModelCallInput\n): RecoverAiModelCallInput {\n const usage = normalizeAiModelCallRecord(input.usage)\n return {\n ...input,\n cost:\n input.cost.status === \"reported\" ? input.cost : validatedEstimate(input.cost, input, usage),\n ...(input.estimate === undefined\n ? {}\n : { estimate: validatedEstimate(input.estimate, input, usage) }),\n }\n}\n\nfunction validatedEstimate(\n cost: ModelCostEstimate,\n input: RecoverAiModelCallInput,\n usage: AiModelCallUsageRecord\n): ModelCostEstimate {\n try {\n assertJsonObject(cost, \"model cost estimate\")\n const record = normalizeAiModelCallCostRecord(modelCostRecord({ ...input, cost }, usage.id))\n if (!aiModelCallCostMatchesUsage(record, usage)) {\n throw new TypeError(\"Estimate quantities do not match recorded usage.\")\n }\n return structuredClone(cost)\n } catch {\n console.warn(\n \"[SixbModels] Invalid model cost estimate; preserving call usage and provider cost.\"\n )\n return { status: \"unpriceable\", reason: \"inconsistent-usage\" }\n }\n}\n\nfunction modelCostRecord(\n input: RecoverAiModelCallInput,\n usageRecordId: string\n): AiModelCallCostRecord {\n const billingIdentity = {\n providerId: input.usage.providerId,\n modelId: input.usage.requestedModelId,\n }\n const pricingContext: AiPricingContext = {\n ...(input.route?.providerId === undefined ? {} : { routedProviderId: input.route.providerId }),\n ...(input.route?.modelId === undefined ? {} : { routedModelId: input.route.modelId }),\n }\n if (input.cost.status === \"reported\" || input.cost.status === \"rated\") {\n return {\n projectId: input.usage.projectId,\n usageRecordId,\n status: \"rated\",\n billingIdentity,\n pricingContext,\n priceSource: costPriceSource(input.usage, input.cost),\n money: input.cost.money,\n components: input.cost.status === \"rated\" ? input.cost.components : [],\n ratedAt: new Date(input.ratedAt),\n }\n }\n\n const reason =\n input.cost.reason === \"missing-rate-card\"\n ? \"missingRateCard\"\n : input.cost.reason === \"missing-usage\"\n ? \"missingUsageMeter\"\n : input.cost.reason === \"unsupported-pricing-dimension\"\n ? \"unsupportedPricingDimension\"\n : \"invalidUsageForFormula\"\n const missingMeters =\n reason === \"missingUsageMeter\" ? normalizeMissingMeters(input.cost.missingMeters) : undefined\n return {\n projectId: input.usage.projectId,\n usageRecordId,\n status: \"unpriceable\",\n billingIdentity,\n pricingContext,\n reason,\n ...(missingMeters === undefined ? {} : { missingMeters }),\n ratedAt: new Date(input.ratedAt),\n }\n}\n\nfunction costPriceSource(\n usage: RecoverAiModelCallInput[\"usage\"],\n cost: Extract<RecoverAiModelCallInput[\"cost\"], { status: \"reported\" | \"rated\" }>\n) {\n if (cost.status === \"reported\") {\n return {\n sourceId: \"provider-reported\",\n sourceEntryId: `${usage.providerId}/${usage.responseId}`,\n sourceVersion: \"response-v1\",\n observedAt: new Date(usage.occurredAt),\n }\n }\n const rates = cost.components.map(({ meter, rateAmountNanosPerMillion }) => ({\n meter,\n rateAmountNanosPerMillion,\n }))\n const version = createHash(\"sha256\").update(JSON.stringify(rates)).digest(\"hex\")\n return {\n sourceId: \"model-rate-card\",\n sourceEntryId: `${usage.providerId}/${usage.requestedModelId}`,\n sourceVersion: `sha256:${version}`,\n observedAt: new Date(usage.occurredAt),\n }\n}\n\nfunction normalizeMissingMeters(\n meters: Extract<RecoverAiModelCallInput[\"cost\"], { status: \"unpriceable\" }>[\"missingMeters\"]\n): readonly AiBillableMeter[] {\n const fallback: readonly AiBillableMeter[] = [\"tokens.input.total\", \"tokens.output.total\"]\n return [...new Set<AiBillableMeter>(meters ?? fallback)]\n}\n\nexport function requireAccountingCapabilities(\n storage: Pick<Storage, \"aiUsage\" | \"aiCosts\" | \"aiLimits\">\n): AiAccountingCapabilities {\n if (!storage.aiUsage || !storage.aiCosts || !storage.aiLimits) {\n throw new Error(\n \"[SixbModels] AI model-call accounting requires storage.aiUsage, storage.aiCosts, and storage.aiLimits.\"\n )\n }\n return { aiUsage: storage.aiUsage, aiCosts: storage.aiCosts, aiLimits: storage.aiLimits }\n}\n",
|
|
8
|
-
"import type { AiModelCallUsageInput } from \"../../storage\"\nimport type { ModelUsage } from \"../events\"\n\n/** Map one provider-neutral model call into Sixb's durable accounting vocabulary. */\nexport function aiModelCallUsageFromModel(usage: ModelUsage): AiModelCallUsageInput {\n return {\n ...(usage.audioDurationMs === undefined ? {} : { audioDurationMs: usage.audioDurationMs }),\n ...(usage.inputTokens === undefined ? {} : { inputTokens: usage.inputTokens }),\n ...(usage.outputTokens === undefined ? {} : { outputTokens: usage.outputTokens }),\n ...(usage.uncachedInputTokens === undefined\n ? {}\n : { uncachedInputTokens: usage.uncachedInputTokens }),\n ...(usage.cacheReadInputTokens === undefined\n ? {}\n : { cacheReadInputTokens: usage.cacheReadInputTokens }),\n ...(usage.cacheWriteInputTokens === undefined\n ? {}\n : { cacheWriteInputTokens: usage.cacheWriteInputTokens }),\n ...(usage.textOutputTokens === undefined ? {} : { textOutputTokens: usage.textOutputTokens }),\n ...(usage.reasoningOutputTokens === undefined\n ? {}\n : { reasoningOutputTokens: usage.reasoningOutputTokens }),\n ...(usage.imageOutputTokens === undefined\n ? {}\n : { imageOutputTokens: usage.imageOutputTokens }),\n ...(usage.audioOutputTokens === undefined\n ? {}\n : { audioOutputTokens: usage.audioOutputTokens }),\n ...(usage.outputImages === undefined ? {} : { outputImages: usage.outputImages }),\n ...(usage.inputCharacters === undefined ? {} : { inputCharacters: usage.inputCharacters }),\n }\n}\n",
|
|
9
|
-
"import type { RecordAiModelCallInput, RecordAiModelCallResult } from \"../../storage\"\nimport { AiCostStorageError, AiLimitStorageError, AiUsageStorageError } from \"../../storage\"\nimport { normalizeAiModelCallRecord } from \"../../storage/ai-usage/record\"\nimport { recordAiModelCallAccounting } from \"./model-call-accounting\"\nimport type {\n AiModelCallAccountingPayload,\n AiModelCallRecordPayload,\n AiModelCallRecoveryRecord,\n ModelCallAccountingStorage,\n RecoverAiModelCallInput,\n} from \"./types\"\nimport { aiModelCallUsageFromModel } from \"./usage\"\n\nclass InvalidAiUsageRecoveryJobError extends Error {\n readonly name = \"InvalidAiUsageRecoveryJobError\"\n\n constructor(message: string, options?: ErrorOptions) {\n super(`[SixbModels] ${message}`, options)\n }\n}\n\n/** Encode one failed accounting transaction for a durable, JSON-safe handoff. */\nexport function modelCallRecoveryPayload(input: RecoverAiModelCallInput): {\n readonly record: AiModelCallRecordPayload\n readonly accounting: AiModelCallAccountingPayload\n} {\n normalizeAiModelCallRecord(input.usage)\n return {\n record: toQueuePayload(input.usage),\n accounting: toAccountingPayload(input),\n }\n}\n\n/** Replay one durable handoff through the idempotent atomic accounting boundary. */\nexport async function recordRecoveredAiModelCall(\n storage: Pick<ModelCallAccountingStorage, \"transaction\">,\n job: AiModelCallRecoveryRecord\n): Promise<RecordAiModelCallResult> {\n const usage = fromQueuePayload(job)\n const accounting = accountingFromQueuePayload(job)\n return recordAiModelCallAccounting({ storage, usage, ...accounting })\n}\n\n/** Validation and referential-integrity failures cannot become valid through queue redelivery. */\nexport function isPermanentAiUsageRecoveryError(error: unknown): boolean {\n return (\n error instanceof InvalidAiUsageRecoveryJobError ||\n error instanceof TypeError ||\n (error instanceof AiUsageStorageError &&\n (error.code === \"duplicate_id\" || error.code === \"missing_execution\")) ||\n (error instanceof AiCostStorageError &&\n (error.code === \"missing_usage\" || error.code === \"cost_mismatch\")) ||\n (error instanceof AiLimitStorageError &&\n (error.code === \"missing_execution\" ||\n error.code === \"missing_reservation\" ||\n error.code === \"missing_usage_record\" ||\n error.code === \"usage_mismatch\" ||\n error.code === \"reservation_conflict\" ||\n error.code === \"reconciliation_conflict\" ||\n error.code === \"invalid_reservation_state\"))\n )\n}\n\nfunction toQueuePayload(record: RecordAiModelCallInput): AiModelCallRecordPayload {\n return {\n id: record.id,\n executionId: record.executionId,\n attempt: record.attempt,\n callId: record.callId,\n requesterGroupIds: [...record.requesterGroupIds],\n providerId: record.providerId,\n ...(record.providerIds === undefined\n ? {}\n : { providerIds: structuredClone(record.providerIds) }),\n requestedModelId: record.requestedModelId,\n ...(record.modelKind === undefined ? {} : { modelKind: record.modelKind }),\n ...(record.requestedReasoning === undefined\n ? {}\n : { requestedReasoning: structuredClone(record.requestedReasoning) }),\n ...(record.responseModelId === undefined ? {} : { responseModelId: record.responseModelId }),\n responseId: record.responseId,\n usage: aiModelCallUsageFromModel(record.usage),\n ...(record.rawUsage === undefined ? {} : { rawUsage: structuredClone(record.rawUsage) }),\n occurredAt: record.occurredAt.toISOString(),\n }\n}\n\nfunction toAccountingPayload(input: RecoverAiModelCallInput): AiModelCallAccountingPayload {\n return {\n cost: structuredClone(input.cost),\n ...(input.estimate === undefined ? {} : { estimate: structuredClone(input.estimate) }),\n ...(input.route === undefined ? {} : { route: structuredClone(input.route) }),\n ratedAt: input.ratedAt.toISOString(),\n ...(input.reconcileLimitReservation ? { reconcileLimitReservation: true } : {}),\n }\n}\n\nfunction fromQueuePayload(job: AiModelCallRecoveryRecord): RecordAiModelCallInput {\n const occurredAt = parseDate(job.payload.record.occurredAt, job.id, \"occurredAt\")\n return { ...job.payload.record, projectId: job.projectId, occurredAt }\n}\n\nfunction accountingFromQueuePayload(\n job: AiModelCallRecoveryRecord\n): Omit<RecoverAiModelCallInput, \"usage\"> {\n const accounting = job.payload.accounting\n return {\n cost: structuredClone(accounting.cost),\n ...(accounting.estimate === undefined\n ? {}\n : { estimate: structuredClone(accounting.estimate) }),\n ...(accounting.route === undefined ? {} : { route: structuredClone(accounting.route) }),\n ratedAt: parseDate(accounting.ratedAt, job.id, \"ratedAt\"),\n reconcileLimitReservation: accounting.reconcileLimitReservation === true,\n }\n}\n\nfunction parseDate(value: string, jobId: string, field: string): Date {\n const date = new Date(value)\n if (!Number.isFinite(date.getTime())) {\n throw new InvalidAiUsageRecoveryJobError(\n `AI usage recovery job '${jobId}' has an invalid ${field} timestamp.`\n )\n }\n return date\n}\n",
|
|
10
|
-
"import { randomUUID } from \"node:crypto\"\nimport type { FileRef } from \"../../blob-storage/types\"\nimport {\n AiUsageStorageError,\n type ReadonlyJsonObject,\n type RecordAiModelCallInput,\n} from \"../../storage\"\nimport type { ModelCallEndEvent, ModelUsage } from \"../events\"\nimport type { LanguageModel } from \"../language-model\"\nimport { ModelUsageRecordingError } from \"./errors\"\nimport {\n normalizeModelCallAccounting,\n recordAiModelCallAccounting,\n requireAccountingCapabilities,\n} from \"./model-call-accounting\"\nimport {\n type AiModelCallAdmissionInput,\n aiModelCallOutputTokenAllowance,\n estimateAiModelCallInputTokens,\n estimatedAiModelCallTotalTokens,\n} from \"./model-call-admission\"\nimport type { AiModelCallLimitController } from \"./model-call-limits\"\nimport { isPermanentAiUsageRecoveryError } from \"./model-call-recovery\"\nimport type {\n ModelCallAccountingStorage,\n RecoverAiModelCall,\n RecoverAiModelCallInput,\n} from \"./types\"\nimport { aiModelCallUsageFromModel } from \"./usage\"\n\nconst STORAGE_RETRY_DELAYS_MS = [50, 200, 600] as const\n\nexport interface AiModelCallRecorderInput {\n readonly storage: ModelCallAccountingStorage\n readonly projectId: string\n readonly executionId: string\n readonly attempt: number\n readonly requesterGroupIds: readonly string[]\n readonly limits: AiModelCallLimitController\n readonly recoverAiModelCall: RecoverAiModelCall\n}\n\ninterface AiModelCallRecorderInternals {\n readonly generateId?: () => string\n readonly now?: () => Date\n readonly retryDelaysMs?: readonly number[]\n readonly sleep?: (ms: number) => Promise<void>\n readonly recordAccounting?: (input: RecoverAiModelCallInput) => Promise<void>\n}\n\n/** Persist every completed provider call before another billable loop step can start. */\nexport class AiModelCallRecorder {\n private readonly generateId: () => string\n private readonly now: () => Date\n private readonly retryDelaysMs: readonly number[]\n private readonly sleep: (ms: number) => Promise<void>\n private readonly recordAccounting: (input: RecoverAiModelCallInput) => Promise<void>\n private readonly reservations = new Set<string>()\n private admissionError: unknown\n private recordingError: ModelUsageRecordingError | undefined\n\n constructor(\n private readonly input: AiModelCallRecorderInput,\n internals: AiModelCallRecorderInternals = {}\n ) {\n requireAccountingCapabilities(input.storage)\n this.generateId = internals.generateId ?? (() => `ai_usage_${randomUUID()}`)\n this.now = internals.now ?? (() => new Date())\n this.retryDelaysMs = internals.retryDelaysMs ?? STORAGE_RETRY_DELAYS_MS\n this.sleep = internals.sleep ?? sleep\n this.recordAccounting =\n internals.recordAccounting ??\n (async (recovery) => {\n await recordAiModelCallAccounting({ storage: this.input.storage, ...recovery })\n })\n }\n\n /** The execution every call this recorder admits is attributed to. */\n get executionId(): string {\n return this.input.executionId\n }\n\n /** The execution attempt every call this recorder admits is attributed to. */\n get attempt(): number {\n return this.input.attempt\n }\n\n /** Wrap the resolved model so all calls in an execution share admission. */\n wrapModel(model: LanguageModel): LanguageModel {\n return {\n providerId: model.providerId,\n modelId: model.modelId,\n definition: model.definition,\n costEstimator: model.costEstimator,\n ...(model.validateResponseFormat === undefined\n ? {}\n : { validateResponseFormat: model.validateResponseFormat.bind(model) }),\n stream: async (request) => {\n this.assertHealthy()\n const inputTokens = estimateAiModelCallInputTokens({\n prompt: request.messages,\n tools: request.tools,\n responseFormat: request.responseFormat,\n })\n const outputTokenAllowance = aiModelCallOutputTokenAllowance(request.maxOutputTokens)\n await this.admitCall({\n callId: request.callId,\n providerId: model.providerId,\n modelId: model.modelId,\n costEstimator: model.costEstimator,\n inputTokens,\n outputTokenAllowance,\n estimatedTotalTokens: estimatedAiModelCallTotalTokens(inputTokens, outputTokenAllowance),\n })\n try {\n return await model.stream(request)\n } catch (error) {\n await this.markCallUnknown(request.callId)\n throw error\n }\n },\n }\n }\n\n /** Admit one provider attempt, independently of its language or embedding protocol. */\n async admitCall(\n call: Omit<\n AiModelCallAdmissionInput,\n \"projectId\" | \"executionId\" | \"attempt\" | \"requesterGroupIds\"\n >\n ): Promise<void> {\n this.assertHealthy()\n try {\n const decision = await this.input.limits.beforeModelCall({\n ...call,\n projectId: this.input.projectId,\n executionId: this.input.executionId,\n attempt: this.input.attempt,\n requesterGroupIds: this.input.requesterGroupIds,\n })\n if (decision.reservation === \"active\") this.reservations.add(call.callId)\n } catch (error) {\n // Execution boundaries must retain the original coded admission failure.\n this.admissionError = error\n throw error\n }\n }\n\n /** Keep an unresolved reservation when an attempted call's billable outcome is unknown. */\n private async markCallUnknown(callId: string): Promise<void> {\n if (!this.reservations.has(callId)) return\n await this.input.limits.markModelCallUnknown({\n projectId: this.input.projectId,\n executionId: this.input.executionId,\n attempt: this.input.attempt,\n callId,\n })\n }\n\n readonly onModelCallEnd = async (event: ModelCallEndEvent): Promise<void> => {\n // Calls already in flight still need their own accounting after another call fails.\n // Only admission is gated by the execution's sticky failure.\n try {\n const occurredAt = this.now()\n const record: RecordAiModelCallInput = {\n id: this.generateId(),\n projectId: this.input.projectId,\n executionId: this.input.executionId,\n attempt: this.input.attempt,\n callId: event.callId,\n requesterGroupIds: this.input.requesterGroupIds,\n providerId: event.providerId,\n ...(event.providerIds === undefined ? {} : { providerIds: event.providerIds }),\n requestedModelId: event.modelId,\n ...(event.modelKind === undefined ? {} : { modelKind: event.modelKind }),\n ...(event.requestedReasoning === undefined\n ? {}\n : { requestedReasoning: event.requestedReasoning }),\n ...(event.responseModelId === undefined ? {} : { responseModelId: event.responseModelId }),\n responseId: event.responseId,\n usage: aiModelCallUsageFromModel(event.usage),\n ...(event.usage.raw === undefined ? {} : { rawUsage: rawUsage(event.usage) }),\n occurredAt,\n }\n const recoveryInput = normalizeModelCallAccounting({\n usage: record,\n cost: event.cost,\n ...(event.estimate === undefined ? {} : { estimate: event.estimate }),\n ...(event.route === undefined ? {} : { route: event.route }),\n ratedAt: new Date(occurredAt),\n ...(this.reservations.has(event.callId) ? { reconcileLimitReservation: true } : {}),\n })\n\n try {\n await retryOperation(\n () => this.recordAccounting(recoveryInput),\n this.retryDelaysMs,\n this.sleep,\n (error) => !isPermanentAiUsageRecoveryError(error)\n )\n } catch (storageError) {\n if (isPermanentAiUsageRecoveryError(storageError)) throw storageError\n\n try {\n await retryOperation(\n () => this.input.recoverAiModelCall(recoveryInput),\n this.retryDelaysMs,\n this.sleep,\n (error) => !isPermanentAiUsageRecoveryError(error)\n )\n } catch (recoveryError) {\n throw new AggregateError(\n [storageError, recoveryError],\n \"Direct AI accounting and durable recovery both failed.\"\n )\n }\n throw new ModelUsageRecordingError(this.input.executionId, event.callId, true, {\n cause: storageError,\n })\n }\n } catch (error) {\n const recordingError =\n error instanceof ModelUsageRecordingError\n ? error\n : new ModelUsageRecordingError(this.input.executionId, event.callId, false, {\n cause: error,\n })\n this.recordingError ??= recordingError\n throw recordingError\n }\n }\n\n /** Record the files a completed call produced; the call's readers download them through it. */\n async recordFiles(callId: string, files: readonly FileRef[]): Promise<void> {\n try {\n await retryOperation(\n () =>\n this.input.storage.aiUsage.recordModelCallFiles({\n projectId: this.input.projectId,\n executionId: this.input.executionId,\n callId,\n files,\n }),\n this.retryDelaysMs,\n this.sleep,\n (error) => !(error instanceof TypeError || error instanceof AiUsageStorageError)\n )\n } catch (error) {\n throw new Error(\n `[SixbModels] Model call '${callId}' completed, but its files could not be recorded.`,\n { cause: error }\n )\n }\n }\n\n assertHealthy(): void {\n if (this.admissionError !== undefined) throw this.admissionError\n if (this.recordingError) throw this.recordingError\n }\n}\n\nfunction rawUsage(usage: ModelUsage): ReadonlyJsonObject {\n return structuredClone(usage.raw ?? {})\n}\n\nasync function retryOperation<TResult>(\n operation: () => Promise<TResult>,\n retryDelaysMs: readonly number[],\n wait: (ms: number) => Promise<void>,\n shouldRetry: (error: unknown) => boolean\n): Promise<TResult> {\n for (let attempt = 0; ; attempt += 1) {\n try {\n return await operation()\n } catch (error) {\n if (!shouldRetry(error)) throw error\n const delay = retryDelaysMs[attempt]\n if (delay === undefined) throw error\n await wait(delay)\n }\n }\n}\n\nfunction sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms))\n}\n",
|
|
11
|
-
"import type { AiModelCallReservationIdentity } from \"../../storage\"\nimport type { ModelKind } from \"../definitions\"\nimport type { ModelCostEstimator, ModelMoney } from \"../pricing\"\n\n/** Default output ceiling when a call and its resolved model supply no limit. */\nexport const AI_MODEL_CALL_OUTPUT_TOKEN_ALLOWANCE = 4_096\n\nexport type AiModelCallInputTokenEstimate =\n | {\n readonly status: \"estimated\"\n readonly tokens: number\n readonly method: \"utf8BytesDividedByFour\"\n }\n | {\n readonly status: \"unavailable\"\n readonly reason: \"nonTextInput\" | \"unserializableInput\"\n }\n\n/** Provider-neutral snapshot passed to aggregate-budget admission before a provider request. */\nexport interface AiModelCallAdmissionInput {\n readonly projectId: string\n readonly executionId: string\n readonly attempt: number\n readonly requesterGroupIds: readonly string[]\n readonly callId: string\n readonly providerId: string\n readonly modelId: string\n /** Selects the applicable limit meters; transcription and reranking skip token limits. */\n readonly modelKind?: ModelKind\n readonly costEstimator?: ModelCostEstimator\n /** A non-token estimate, computed by the resolved binding before inference. */\n readonly reservationCost?: ModelMoney\n readonly inputTokens: AiModelCallInputTokenEstimate\n readonly outputTokenAllowance: number\n readonly estimatedTotalTokens?: number\n}\n\nexport interface AiModelCallAdmissionDecision {\n /** Active means accounting must reconcile the reservation for this provider attempt. */\n readonly reservation: \"active\" | \"none\"\n}\n\nexport type BeforeAiModelCall = (\n input: AiModelCallAdmissionInput\n) => AiModelCallAdmissionDecision | Promise<AiModelCallAdmissionDecision>\n\nexport type MarkAiModelCallUnknown = (input: AiModelCallReservationIdentity) => void | Promise<void>\n\n/**\n * Estimate the exact, prepared provider request without requiring a provider-specific tokenizer.\n *\n * The heuristic is intentionally explicit so reservations are reproducible. Non-text inputs are\n * reported as unavailable; an enforced token or cost policy can then fail closed instead of\n * pretending that an image, file, or provider-defined payload has no token cost.\n */\nexport function estimateAiModelCallInputTokens(input: {\n readonly prompt: unknown\n readonly tools: unknown\n readonly responseFormat: unknown\n}): AiModelCallInputTokenEstimate {\n if (containsNonTextInput(input.prompt)) {\n return { status: \"unavailable\", reason: \"nonTextInput\" }\n }\n\n let serialized: string | undefined\n try {\n serialized = JSON.stringify(input)\n } catch {\n return { status: \"unavailable\", reason: \"unserializableInput\" }\n }\n if (serialized === undefined) {\n return { status: \"unavailable\", reason: \"unserializableInput\" }\n }\n\n const bytes = new TextEncoder().encode(serialized).byteLength\n return {\n status: \"estimated\",\n tokens: Math.ceil(bytes / 4),\n method: \"utf8BytesDividedByFour\",\n }\n}\n\nexport function aiModelCallOutputTokenAllowance(maxOutputTokens: number | undefined): number {\n if (maxOutputTokens === undefined) return AI_MODEL_CALL_OUTPUT_TOKEN_ALLOWANCE\n if (!Number.isSafeInteger(maxOutputTokens) || maxOutputTokens <= 0) {\n throw new TypeError(\n \"[SixbModels] AI model-call maxOutputTokens must be a positive safe integer.\"\n )\n }\n return maxOutputTokens\n}\n\nexport function estimatedAiModelCallTotalTokens(\n inputTokens: AiModelCallInputTokenEstimate,\n outputTokenAllowance: number\n): number | undefined {\n if (inputTokens.status !== \"estimated\") return undefined\n const total = inputTokens.tokens + outputTokenAllowance\n if (!Number.isSafeInteger(total)) {\n throw new TypeError(\"[SixbModels] AI model-call token estimate exceeds the safe range.\")\n }\n return total\n}\n\nfunction containsNonTextInput(value: unknown, seen = new WeakSet<object>()): boolean {\n if (value === null || typeof value !== \"object\") return false\n if (\n value instanceof URL ||\n value instanceof ArrayBuffer ||\n ArrayBuffer.isView(value) ||\n (typeof Blob !== \"undefined\" && value instanceof Blob)\n ) {\n return true\n }\n if (seen.has(value)) return false\n seen.add(value)\n\n if (!Array.isArray(value)) {\n const type = Reflect.get(value, \"type\")\n if (\n type === \"image\" ||\n type === \"file\" ||\n type === \"reasoning-file\" ||\n type === \"custom\" ||\n type === \"provider-state\"\n ) {\n return true\n }\n }\n\n return Object.values(value).some((entry) => containsNonTextInput(entry, seen))\n}\n",
|
|
12
|
-
"import { createSixbError } from \"../../errors/internal\"\nimport type { AgentQueueJob, Queue } from \"../../queues\"\nimport { modelCallRecoveryPayload } from \"./model-call-recovery\"\nimport type { RecoverAiModelCallInput } from \"./types\"\n\n/** Stable queue identity: a lost enqueue response can safely retry the same accounting handoff. */\nfunction agentAiUsageRecoveryJobId(recordId: string): string {\n return `agt_usage_job_${recordId}`\n}\n\n/** Transport adapter for the agent worker's existing durable recovery lane. */\nexport async function enqueueAiModelCallRecovery(\n queue: Pick<Queue<AgentQueueJob>, \"enqueue\">,\n input: RecoverAiModelCallInput\n): Promise<void> {\n const payload = modelCallRecoveryPayload(input)\n const record = input.usage\n const jobId = agentAiUsageRecoveryJobId(record.id)\n const [job] = await queue.enqueue({\n projectId: record.projectId,\n jobs: [{ id: jobId, type: \"agent.ai-usage.record.requested\", payload }],\n })\n\n if (job?.id !== jobId || job.type !== \"agent.ai-usage.record.requested\") {\n throw createSixbError(\n \"internal.unexpected\",\n `[SixbModels] Agent queue did not confirm AI usage recovery job '${jobId}'.`,\n { details: { jobId } }\n )\n }\n}\n"
|
|
13
|
-
],
|
|
14
|
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OAAO;AAAA,MACd,IAAI,CAAC,YAAY,KAAK;AAAA,QAAG,MAAM;AAAA,MAC/B,MAAM,QAAQ,cAAc;AAAA,MAC5B,IAAI,UAAU;AAAA,QAAW,MAAM;AAAA,MAC/B,MAAM,KAAK,KAAK;AAAA;AAAA,EAEpB;AAAA;AAGF,SAAS,KAAK,CAAC,IAA2B;AAAA,EACxC,OAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,EAAE,CAAC;AAAA;;;AEtRzD,SAAS,yBAAyB,CAAC,UAA0B;AAAA,EAC3D,OAAO,iBAAiB;AAAA;AAI1B,eAAsB,2BAA0B,CAC9C,OACA,OACe;AAAA,EACf,MAAM,UAAU,yBAAyB,KAAK;AAAA,EAC9C,MAAM,SAAS,MAAM;AAAA,EACrB,MAAM,QAAQ,0BAA0B,OAAO,EAAE;AAAA,EACjD,OAAO,OAAO,MAAM,MAAM,QAAQ;AAAA,IAChC,WAAW,OAAO;AAAA,IAClB,MAAM,CAAC,EAAE,IAAI,OAAO,MAAM,mCAAmC,QAAQ,CAAC;AAAA,EACxE,CAAC;AAAA,EAED,IAAI,KAAK,OAAO,SAAS,IAAI,SAAS,mCAAmC;AAAA,IACvE,MAAM,iBACJ,uBACA,mEAAmE,WACnE,EAAE,SAAS,EAAE,MAAM,EAAE,CACvB;AAAA,EACF;AAAA;",
|
|
15
|
-
"debugId": "8311E82DEB61C61564756E2164756E21",
|
|
16
|
-
"names": []
|
|
17
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../src/ontology/user-ref.ts"],
|
|
4
|
-
"sourcesContent": [
|
|
5
|
-
"import type { Principal } from \"../auth/types\"\nimport type { UserStatus } from \"../storage/auth/types\"\nimport { OntologyValidationError } from \"./errors\"\nimport type { Schema, ValueType } from \"./types\"\n\n/**\n * Value of a `ref.user()` (`\"userRef\"`) schema: the principal shape, narrowed to users.\n *\n * It carries no display data on purpose: a name or avatar supplied by the writer would be\n * spoofable. It grants or restricts nothing by itself either; only an explicit policy gives it a\n * security meaning.\n */\nexport type UserRef = Extract<Principal, { readonly type: \"user\" }>\n\n/**\n * Build a reference to one user, for writes and query predicates:\n * `where(({ p }) => p.assignee.eq(userRef(userId)))`.\n */\nexport function userRef(id: string): UserRef {\n if (typeof id !== \"string\" || !id.trim()) {\n throw new OntologyValidationError(\"[Sixb] User reference id must not be empty.\")\n }\n return Object.freeze({ type: \"user\" as const, id })\n}\n\n/** Exactly `{ type: \"user\", id }` with a nonblank id and no other field. */\nexport function isUserRef(value: unknown): value is UserRef {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return false\n const record = value as Record<string, unknown>\n return (\n Object.keys(record).every((key) => key === \"type\" || key === \"id\") &&\n record.type === \"user\" &&\n typeof record.id === \"string\" &&\n record.id.trim().length > 0\n )\n}\n\n/**\n * A `ref.user()` schema, or an array of them: the property schemas whose members a query can\n * expand into profiles.\n */\nexport function isUserRefPropertySchema(schema: Schema): boolean {\n if (schema === \"userRef\") return true\n return typeof schema === \"object\" && schema.type === \"array\" && schema.items === \"userRef\"\n}\n\n/**\n * The user reading, in a query predicate. The server binds it to the requester when the query runs:\n * a query never stores or returns it.\n */\nexport type CurrentUserRef = { readonly type: \"currentUser\" }\n\nconst CURRENT_USER: CurrentUserRef = Object.freeze({ type: \"currentUser\" })\n\n/**\n * Match the user reading: `where(({ p }) => p.assignee.eq(currentUser()))`.\n *\n * Only query predicates on a `ref.user()` property accept it: `eq`, `neq`, `in`, and `contains`\n * on a list of user references. It cannot be stored.\n */\nexport function currentUser(): CurrentUserRef {\n return CURRENT_USER\n}\n\n/** Exactly `{ type: \"currentUser\" }`, the form `currentUser()` takes on the wire too. */\nexport function isCurrentUser(value: unknown): value is CurrentUserRef {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) return false\n const record = value as Record<string, unknown>\n return Object.keys(record).length === 1 && record.type === \"currentUser\"\n}\n\n/** Why `subject` refuses `currentUser()`: it stands for the reader of a query, never for a value. */\nexport function currentUserNotStorableMessage(subject: string): string {\n return `${subject} cannot store currentUser(): it only stands for the user reading, in a query predicate. Store a user reference { type: \"user\", id } instead.`\n}\n\n/**\n * Collect the user ids a value holds at `userRef` positions of its schema, however deeply nested.\n *\n * Positions whose value does not match the schema are skipped: shape validation reports them.\n */\nexport function collectUserRefIds(\n schema: Schema,\n value: unknown,\n valueTypesById: ReadonlyMap<string, ValueType>,\n into: Set<string>,\n seenValueTypeIds: ReadonlySet<string> = new Set()\n): Set<string> {\n if (value === null || value === undefined) return into\n if (typeof schema === \"string\") {\n if (schema === \"userRef\" && isUserRef(value)) into.add(value.id)\n return into\n }\n switch (schema.type) {\n case \"array\":\n if (Array.isArray(value)) {\n for (const item of value) {\n collectUserRefIds(schema.items, item, valueTypesById, into, seenValueTypeIds)\n }\n }\n return into\n case \"map\":\n if (isRecord(value)) {\n for (const item of Object.values(value)) {\n collectUserRefIds(schema.valueSchema, item, valueTypesById, into, seenValueTypeIds)\n }\n }\n return into\n case \"object\":\n if (isRecord(value)) {\n for (const [fieldId, field] of Object.entries(schema.properties)) {\n collectUserRefIds(field.schema, value[fieldId], valueTypesById, into, seenValueTypeIds)\n }\n }\n return into\n case \"valueTypeRef\": {\n if (seenValueTypeIds.has(schema.valueTypeId)) return into\n const resolved = schema._resolved ?? valueTypesById.get(schema.valueTypeId)?.schema\n if (!resolved) return into\n return collectUserRefIds(\n resolved,\n value,\n valueTypesById,\n into,\n new Set([...seenValueTypeIds, schema.valueTypeId])\n )\n }\n case \"enum\":\n return into\n }\n}\n\n/**\n * Why `path` cannot newly reference user `id`, or `undefined` when it can.\n *\n * `status` is the user's status, `null` for an unknown id, or `\"unverifiable\"` without auth\n * storage. Unknown and suspended users get distinct messages: the writer already holds the id, and\n * telling \"wrong id\" from \"suspended member\" is what makes the error actionable.\n */\nexport function userReferenceProblem(\n path: string,\n id: string,\n status: UserStatus | null | \"unverifiable\"\n): string | undefined {\n switch (status) {\n case \"active\":\n return undefined\n case null:\n return `[Sixb] ${path} references user '${id}', which does not exist.`\n case \"unverifiable\":\n return `[Sixb] ${path} references user '${id}', but this runtime has no auth storage to verify users. Configure storage with auth to write user references.`\n default:\n return `[Sixb] ${path} references user '${id}', who is ${status}. Only active users can be newly referenced; existing references are kept.`\n }\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null && !Array.isArray(value)\n}\n"
|
|
6
|
-
],
|
|
7
|
-
"mappings": ";;;;;;AAkBO,SAAS,QAAO,CAAC,IAAqB;AAAA,EAC3C,IAAI,OAAO,OAAO,YAAY,CAAC,GAAG,KAAK,GAAG;AAAA,IACxC,MAAM,IAAI,yBAAwB,6CAA6C;AAAA,EACjF;AAAA,EACA,OAAO,OAAO,OAAO,EAAE,MAAM,QAAiB,GAAG,CAAC;AAAA;AAI7C,SAAS,SAAS,CAAC,OAAkC;AAAA,EAC1D,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK;AAAA,IAAG,OAAO;AAAA,EAChF,MAAM,SAAS;AAAA,EACf,OACE,OAAO,KAAK,MAAM,EAAE,MAAM,CAAC,QAAQ,QAAQ,UAAU,QAAQ,IAAI,KACjE,OAAO,SAAS,UAChB,OAAO,OAAO,OAAO,YACrB,OAAO,GAAG,KAAK,EAAE,SAAS;AAAA;AAQvB,SAAS,uBAAuB,CAAC,QAAyB;AAAA,EAC/D,IAAI,WAAW;AAAA,IAAW,OAAO;AAAA,EACjC,OAAO,OAAO,WAAW,YAAY,OAAO,SAAS,WAAW,OAAO,UAAU;AAAA;AASnF,IAAM,eAA+B,OAAO,OAAO,EAAE,MAAM,cAAc,CAAC;AAQnE,SAAS,YAAW,GAAmB;AAAA,EAC5C,OAAO;AAAA;AAIF,SAAS,aAAa,CAAC,OAAyC;AAAA,EACrE,IAAI,OAAO,UAAU,YAAY,UAAU,QAAQ,MAAM,QAAQ,KAAK;AAAA,IAAG,OAAO;AAAA,EAChF,MAAM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