@sixb/core 0.2.5 → 0.2.7
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 +36 -35
- package/dist/actions/index.js.map +1 -1
- package/dist/actions/validation.d.ts.map +1 -1
- package/dist/agents/errors.d.ts +1 -1
- package/dist/agents/errors.d.ts.map +1 -1
- package/dist/agents/execution.d.ts +17 -2
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/index.d.ts +3 -3
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +53 -45
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-routing.d.ts +16 -2
- package/dist/agents/model-routing.d.ts.map +1 -1
- package/dist/agents/request.d.ts +45 -4
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-events.d.ts +4 -0
- package/dist/agents/run-events.d.ts.map +1 -1
- package/dist/agents/run-session-children.d.ts.map +1 -1
- package/dist/agents/run-token.d.ts +6 -0
- package/dist/agents/run-token.d.ts.map +1 -1
- package/dist/agents/run-turn.d.ts +9 -1
- package/dist/agents/run-turn.d.ts.map +1 -1
- package/dist/agents/streams/index.d.ts +1 -1
- package/dist/agents/streams/index.d.ts.map +1 -1
- package/dist/agents/streams/index.js +1 -1
- package/dist/agents/streams/internal.d.ts +2 -1
- package/dist/agents/streams/internal.d.ts.map +1 -1
- package/dist/agents/streams/internal.js +22 -2
- package/dist/agents/streams/internal.js.map +1 -1
- package/dist/agents/streams/protocol.d.ts +37 -0
- package/dist/agents/streams/protocol.d.ts.map +1 -1
- package/dist/agents/streams/steps.d.ts +24 -0
- package/dist/agents/streams/steps.d.ts.map +1 -0
- package/dist/agents/thread-access.d.ts +44 -2
- package/dist/agents/thread-access.d.ts.map +1 -1
- package/dist/artifacts/live/server.js +19 -18
- package/dist/artifacts/live/server.js.map +1 -1
- package/dist/artifacts/publish/index.js +18 -17
- package/dist/artifacts/publish/index.js.map +1 -1
- package/dist/artifacts/publish/merge.d.ts +2 -1
- package/dist/artifacts/publish/merge.d.ts.map +1 -1
- package/dist/artifacts/run-query.d.ts.map +1 -1
- package/dist/auth/index.js +6 -6
- package/dist/authorization/index.js +2 -2
- package/dist/bootstrap/discovery.d.ts +6 -0
- package/dist/bootstrap/discovery.d.ts.map +1 -1
- package/dist/bootstrap/index.js +40 -38
- package/dist/bootstrap/index.js.map +2 -2
- package/dist/calendar.d.ts +55 -0
- package/dist/calendar.d.ts.map +1 -0
- package/dist/calendar.js +19 -0
- package/dist/calendar.js.map +9 -0
- package/dist/chunk-04r2fdsd.js +386 -0
- package/dist/chunk-04r2fdsd.js.map +14 -0
- package/dist/{chunk-gjhrz66x.js → chunk-06kpaqg4.js} +248 -21
- package/dist/{chunk-gjhrz66x.js.map → chunk-06kpaqg4.js.map} +6 -6
- package/dist/{chunk-5a4a52tq.js → chunk-0pmpwn3g.js} +18 -2
- package/dist/chunk-0pmpwn3g.js.map +10 -0
- package/dist/{chunk-nxysqbt0.js → chunk-389ybvw9.js} +6 -2
- package/dist/chunk-389ybvw9.js.map +10 -0
- package/dist/{chunk-xcrnrpfh.js → chunk-394zjzjs.js} +20 -10
- package/dist/{chunk-xcrnrpfh.js.map → chunk-394zjzjs.js.map} +5 -5
- package/dist/{chunk-stmxh0hv.js → chunk-3neam1y5.js} +2 -2
- package/dist/{chunk-zeykm8my.js → chunk-3qtk0070.js} +16 -42
- package/dist/chunk-3qtk0070.js.map +14 -0
- package/dist/{chunk-0hkdtwqk.js → chunk-44hrfmbk.js} +5 -5
- package/dist/{chunk-ey1p8w68.js → chunk-5pz3htbe.js} +86 -5
- package/dist/chunk-5pz3htbe.js.map +13 -0
- package/dist/{chunk-s5pj68fa.js → chunk-5sswe5ej.js} +2 -2
- package/dist/{chunk-k3jh8gsg.js → chunk-5xkqasvn.js} +21 -4
- package/dist/chunk-5xkqasvn.js.map +10 -0
- package/dist/{chunk-5t9gm5tt.js → chunk-6md802cc.js} +38 -14
- package/dist/chunk-6md802cc.js.map +22 -0
- package/dist/{chunk-3zagkr6w.js → chunk-7mhbs9yy.js} +4 -4
- package/dist/{chunk-3zagkr6w.js.map → chunk-7mhbs9yy.js.map} +1 -1
- package/dist/{chunk-ewqn51gr.js → chunk-88xeh6zx.js} +6 -4
- package/dist/{chunk-ewqn51gr.js.map → chunk-88xeh6zx.js.map} +4 -4
- package/dist/{chunk-z1njfqqs.js → chunk-8qmp9fpa.js} +783 -171
- package/dist/{chunk-z1njfqqs.js.map → chunk-8qmp9fpa.js.map} +13 -13
- package/dist/{chunk-r2psmn42.js → chunk-95ps0k5q.js} +3 -3
- package/dist/{chunk-r2psmn42.js.map → chunk-95ps0k5q.js.map} +3 -3
- package/dist/{chunk-fpf57gca.js → chunk-9cyq87qa.js} +276 -68
- package/dist/{chunk-fpf57gca.js.map → chunk-9cyq87qa.js.map} +6 -6
- package/dist/{chunk-q9nkpr8k.js → chunk-9tpmfh3n.js} +1 -1
- package/dist/chunk-9wr3yajk.js.map +2 -2
- package/dist/{chunk-naxjka9v.js → chunk-brhp9d97.js} +2 -2
- package/dist/{chunk-8a8k38tz.js → chunk-brybqw5k.js} +1 -1
- package/dist/{chunk-vehcr9eb.js → chunk-cg7cygfj.js} +1 -1
- package/dist/{chunk-b4escq4c.js → chunk-cpy282b8.js} +6 -6
- package/dist/chunk-dq3t5sr3.js +114 -0
- package/dist/chunk-dq3t5sr3.js.map +11 -0
- package/dist/{chunk-68hm50qh.js → chunk-fdk0ks9p.js} +16 -46
- package/dist/chunk-fdk0ks9p.js.map +12 -0
- package/dist/{chunk-fzae1jpq.js → chunk-fycac8e9.js} +50 -16
- package/dist/{chunk-fzae1jpq.js.map → chunk-fycac8e9.js.map} +3 -3
- package/dist/{chunk-zft9bzbc.js → chunk-hkbks1xm.js} +2 -1
- package/dist/{chunk-zft9bzbc.js.map → chunk-hkbks1xm.js.map} +3 -3
- package/dist/{chunk-m3qx2pns.js → chunk-hvq8xs66.js} +28 -12
- package/dist/{chunk-m3qx2pns.js.map → chunk-hvq8xs66.js.map} +5 -5
- package/dist/{chunk-bc3y6gff.js → chunk-jka26v8c.js} +1 -1
- package/dist/{chunk-s1mqyqmm.js → chunk-js9e6487.js} +12 -8
- package/dist/chunk-js9e6487.js.map +18 -0
- package/dist/{chunk-zxhym8tr.js → chunk-k29rdc3h.js} +1 -1
- package/dist/{chunk-rg725hry.js → chunk-m1cwncee.js} +86 -34
- package/dist/{chunk-rg725hry.js.map → chunk-m1cwncee.js.map} +8 -8
- package/dist/{chunk-1yh6jgtz.js → chunk-mrs7jy17.js} +2 -2
- package/dist/{chunk-qavwr628.js → chunk-n1hbwc6y.js} +5 -6
- package/dist/chunk-n1hbwc6y.js.map +12 -0
- package/dist/{chunk-pqvvqc65.js → chunk-pfdq1ga6.js} +3 -3
- package/dist/{chunk-k29n4176.js → chunk-phs5fbff.js} +6 -6
- package/dist/{chunk-wqe9shx2.js → chunk-qbd282aa.js} +2 -2
- package/dist/{chunk-e91fmg6t.js → chunk-qsa7nw6f.js} +2 -1
- package/dist/{chunk-e91fmg6t.js.map → chunk-qsa7nw6f.js.map} +3 -3
- package/dist/chunk-r588h4ev.js +98 -0
- package/dist/chunk-r588h4ev.js.map +10 -0
- package/dist/{chunk-rtdrm592.js → chunk-t58sktr5.js} +12 -4
- package/dist/{chunk-rtdrm592.js.map → chunk-t58sktr5.js.map} +3 -3
- package/dist/{chunk-paxabbqd.js → chunk-tapdssb5.js} +1 -1
- package/dist/{chunk-dhkc9b23.js → chunk-v8a1qjzp.js} +1 -1
- package/dist/{chunk-q8d9p0tb.js → chunk-wzcjhv54.js} +8 -1
- package/dist/{chunk-q8d9p0tb.js.map → chunk-wzcjhv54.js.map} +3 -3
- package/dist/{chunk-pc7kra3k.js → chunk-xavet0qs.js} +1 -1
- package/dist/{chunk-m9ketb51.js → chunk-ygvay56w.js} +1 -1
- package/dist/{chunk-0mvjpgvm.js → chunk-yyj009tv.js} +4 -4
- package/dist/connectors/connections/capability.d.ts +11 -0
- package/dist/connectors/connections/capability.d.ts.map +1 -1
- package/dist/connectors/connections/internal.d.ts +2 -1
- package/dist/connectors/connections/internal.d.ts.map +1 -1
- package/dist/connectors/connections/internal.js +8 -4
- package/dist/connectors/connections/internal.js.map +1 -1
- package/dist/connectors/connections/service.d.ts +9 -1
- package/dist/connectors/connections/service.d.ts.map +1 -1
- package/dist/connectors/execution.d.ts +7 -1
- package/dist/connectors/execution.d.ts.map +1 -1
- package/dist/connectors/service.d.ts +5 -1
- package/dist/connectors/service.d.ts.map +1 -1
- package/dist/deploy/index.d.ts +1 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/internal.js +2 -2
- package/dist/deploy/internal.js.map +2 -2
- package/dist/deploy/types.d.ts +12 -59
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/env/index.d.ts +10 -3
- package/dist/env/index.d.ts.map +1 -1
- package/dist/env/index.js.map +2 -2
- package/dist/events/execution.d.ts +8 -1
- package/dist/events/execution.d.ts.map +1 -1
- package/dist/events/types/syncs.d.ts +4 -0
- package/dist/events/types/syncs.d.ts.map +1 -1
- package/dist/execution/agent.js +37 -36
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorized-object-reader.d.ts +4 -0
- package/dist/execution/authorized-object-reader.d.ts.map +1 -1
- package/dist/execution/object-reader-ontology.d.ts +3 -0
- package/dist/execution/object-reader-ontology.d.ts.map +1 -1
- package/dist/execution/primitive.js +36 -35
- package/dist/execution/primitive.js.map +1 -1
- package/dist/execution/request.d.ts +1 -1
- package/dist/execution/request.d.ts.map +1 -1
- package/dist/execution/request.js +33 -32
- package/dist/execution/request.js.map +3 -3
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +63 -59
- package/dist/index.js.map +1 -1
- package/dist/maintenance/index.js +1 -1
- package/dist/materializer/index.js +22 -21
- package/dist/materializer/index.js.map +1 -1
- package/dist/models/audio/runtime.d.ts.map +1 -1
- package/dist/models/audio/types.d.ts +19 -0
- package/dist/models/audio/types.d.ts.map +1 -1
- package/dist/models/execution/index.js +20 -19
- package/dist/models/execution/index.js.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/objects/index.js +36 -35
- package/dist/objects/index.js.map +1 -1
- package/dist/objects/query/executor.d.ts +3 -1
- package/dist/objects/query/executor.d.ts.map +1 -1
- package/dist/objects/query/explain.d.ts +3 -1
- package/dist/objects/query/explain.d.ts.map +1 -1
- package/dist/objects/query/index.d.ts +1 -1
- package/dist/objects/query/index.d.ts.map +1 -1
- package/dist/objects/query/index.js +19 -18
- package/dist/objects/query/index.js.map +1 -1
- package/dist/objects/query/link-query-clearance.d.ts +3 -0
- package/dist/objects/query/link-query-clearance.d.ts.map +1 -1
- package/dist/objects/query/links.d.ts +1 -1
- package/dist/objects/query/links.d.ts.map +1 -1
- package/dist/objects/query/validate.d.ts +17 -0
- package/dist/objects/query/validate.d.ts.map +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts +1 -1
- package/dist/objects/sdk/runtime-query-executor.d.ts.map +1 -1
- package/dist/ontology/index.js +3 -3
- package/dist/ontology/internal.js +3 -3
- package/dist/pipelines/index.js +21 -20
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/internal.js +20 -19
- package/dist/projections/internal.js.map +1 -1
- package/dist/queues/in-memory.d.ts +1 -1
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/runtime/create.d.ts.map +1 -1
- package/dist/runtime/definitions.d.ts +14 -0
- package/dist/runtime/definitions.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +3 -1
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/internal.js +24 -23
- package/dist/runtime/internal.js.map +2 -2
- package/dist/runtime/locale.d.ts +0 -2
- package/dist/runtime/locale.d.ts.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +2 -1
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/sixb.d.ts.map +1 -1
- package/dist/sandboxes/auth.d.ts +26 -4
- package/dist/sandboxes/auth.d.ts.map +1 -1
- package/dist/sandboxes/errors.d.ts +19 -0
- package/dist/sandboxes/errors.d.ts.map +1 -1
- package/dist/sandboxes/exec.d.ts +2 -0
- package/dist/sandboxes/exec.d.ts.map +1 -1
- package/dist/sandboxes/index.d.ts +4 -2
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +13 -7
- package/dist/sandboxes/index.js.map +1 -1
- package/dist/sandboxes/sandbox.d.ts +15 -1
- package/dist/sandboxes/sandbox.d.ts.map +1 -1
- package/dist/security/view-conditions.d.ts.map +1 -1
- package/dist/shares/internal.js +16 -15
- package/dist/shares/internal.js.map +2 -2
- package/dist/storage/agents/in-memory.d.ts +18 -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 +43 -9
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +19 -3
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +150 -4
- package/dist/storage/agents/types.d.ts.map +1 -1
- package/dist/storage/ai-cost/analytics.d.ts +3 -2
- package/dist/storage/ai-cost/analytics.d.ts.map +1 -1
- package/dist/storage/ai-cost/provider.js +4 -3
- package/dist/storage/ai-cost/provider.js.map +1 -1
- package/dist/storage/ai-cost/types.d.ts +5 -1
- package/dist/storage/ai-cost/types.d.ts.map +1 -1
- package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
- package/dist/storage/artifacts/record.d.ts +3 -1
- package/dist/storage/artifacts/record.d.ts.map +1 -1
- package/dist/storage/artifacts/types.d.ts +7 -0
- package/dist/storage/artifacts/types.d.ts.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +7 -7
- package/dist/storage/index.d.ts +2 -2
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +23 -22
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.js +8 -8
- package/dist/storage/operation-scope.d.ts.map +1 -1
- package/dist/storage/operation-scope.js +1 -1
- package/dist/storage/sync-runs/idempotency.d.ts.map +1 -1
- package/dist/storage/sync-runs/in-memory.d.ts +2 -1
- package/dist/storage/sync-runs/in-memory.d.ts.map +1 -1
- package/dist/storage/sync-runs/index.d.ts +1 -1
- package/dist/storage/sync-runs/index.d.ts.map +1 -1
- package/dist/storage/sync-runs/types.d.ts +27 -2
- package/dist/storage/sync-runs/types.d.ts.map +1 -1
- package/dist/storage/workflow-runs/provider.js +7 -7
- package/dist/syncs/accounts.d.ts +36 -0
- package/dist/syncs/accounts.d.ts.map +1 -0
- package/dist/syncs/builders.d.ts.map +1 -1
- package/dist/syncs/connections.d.ts +36 -0
- package/dist/syncs/connections.d.ts.map +1 -0
- package/dist/syncs/execution.d.ts +14 -4
- package/dist/syncs/execution.d.ts.map +1 -1
- package/dist/syncs/index.d.ts +2 -1
- package/dist/syncs/index.d.ts.map +1 -1
- package/dist/syncs/index.js +22 -21
- package/dist/syncs/index.js.map +1 -1
- package/dist/syncs/request.d.ts +16 -2
- package/dist/syncs/request.d.ts.map +1 -1
- package/dist/syncs/run-dispatch.d.ts +14 -2
- package/dist/syncs/run-dispatch.d.ts.map +1 -1
- package/dist/testing/agent-approval-storage-contract.d.ts.map +1 -1
- package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -1
- package/dist/testing/agent-storage-contract.d.ts.map +1 -1
- package/dist/testing/ai-cost-storage-contract.d.ts.map +1 -1
- package/dist/testing/artifact-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.js +1157 -100
- package/dist/testing/index.js.map +9 -9
- package/dist/testing/run-claim-storage-contract.d.ts.map +1 -1
- package/dist/testing/sandboxes-contract.d.ts.map +1 -1
- package/dist/webhooks/internal.js +17 -16
- package/dist/webhooks/internal.js.map +2 -2
- package/dist/workers/index.js +66 -13
- package/dist/workers/index.js.map +4 -4
- package/dist/workers/queue-worker.d.ts +5 -0
- package/dist/workers/queue-worker.d.ts.map +1 -1
- package/dist/workers/worker.d.ts +8 -0
- package/dist/workers/worker.d.ts.map +1 -1
- package/dist/workflows/index.js +42 -40
- package/dist/workflows/index.js.map +1 -1
- package/package.json +7 -1
- package/src/actions/validation.ts +3 -1
- package/src/agents/children.ts +6 -0
- package/src/agents/errors.ts +3 -0
- package/src/agents/execution.ts +170 -20
- package/src/agents/index.ts +5 -0
- package/src/agents/model-routing.ts +116 -34
- package/src/agents/request.ts +783 -38
- package/src/agents/run-events.ts +235 -38
- package/src/agents/run-session-children.ts +13 -2
- package/src/agents/run-token.ts +7 -0
- package/src/agents/run-turn.ts +140 -23
- package/src/agents/streams/index.ts +2 -0
- package/src/agents/streams/internal.ts +12 -0
- package/src/agents/streams/protocol.ts +69 -1
- package/src/agents/streams/steps.ts +131 -0
- package/src/agents/thread-access.ts +57 -2
- package/src/artifacts/publish/merge.ts +14 -3
- package/src/artifacts/run-query.ts +5 -2
- package/src/bootstrap/discovery.ts +61 -11
- package/src/calendar.ts +195 -0
- package/src/connectors/connections/capability.ts +40 -0
- package/src/connectors/connections/internal.ts +3 -0
- package/src/connectors/connections/service.ts +74 -5
- package/src/connectors/execution.ts +5 -6
- package/src/connectors/service.ts +23 -0
- package/src/deploy/index.ts +0 -5
- package/src/deploy/types.ts +12 -64
- package/src/deploy/validation.ts +1 -1
- package/src/env/index.ts +10 -4
- package/src/events/execution.ts +42 -2
- package/src/events/types/syncs.ts +4 -0
- package/src/execution/authorized-object-reader.ts +33 -5
- package/src/execution/object-reader-ontology.ts +6 -0
- package/src/execution/request.ts +1 -0
- package/src/http/api-routes.ts +8 -0
- package/src/index.ts +21 -2
- package/src/models/audio/runtime.ts +57 -14
- package/src/models/audio/types.ts +20 -0
- package/src/models/index.ts +1 -0
- package/src/objects/query/executor.ts +4 -0
- package/src/objects/query/explain.ts +5 -0
- package/src/objects/query/index.ts +1 -0
- package/src/objects/query/link-query-clearance.ts +4 -1
- package/src/objects/query/links.ts +5 -1
- package/src/objects/query/validate.ts +33 -1
- package/src/objects/sdk/runtime-query-executor.ts +7 -3
- package/src/runtime/create.ts +1 -0
- package/src/runtime/definitions.ts +25 -0
- package/src/runtime/host.ts +16 -8
- package/src/runtime/index.ts +6 -1
- package/src/runtime/locale.ts +0 -10
- package/src/runtime/resolve-definitions.ts +7 -1
- package/src/runtime/sixb.ts +12 -2
- package/src/sandboxes/README.md +12 -1
- package/src/sandboxes/auth.ts +32 -4
- package/src/sandboxes/errors.ts +27 -0
- package/src/sandboxes/exec.ts +3 -1
- package/src/sandboxes/index.ts +18 -1
- package/src/sandboxes/sandbox.ts +15 -1
- package/src/security/view-conditions.ts +2 -1
- package/src/storage/agents/in-memory.ts +271 -6
- package/src/storage/agents/index.ts +10 -0
- package/src/storage/agents/provider.ts +178 -13
- package/src/storage/agents/types.ts +166 -4
- package/src/storage/ai-cost/analytics.ts +22 -43
- package/src/storage/ai-cost/types.ts +5 -1
- package/src/storage/artifacts/in-memory.ts +20 -5
- package/src/storage/artifacts/record.ts +8 -2
- package/src/storage/artifacts/types.ts +7 -0
- package/src/storage/index.ts +11 -0
- package/src/storage/operation-scope.ts +1 -0
- package/src/storage/sync-runs/idempotency.ts +1 -0
- package/src/storage/sync-runs/in-memory.ts +43 -1
- package/src/storage/sync-runs/index.ts +1 -0
- package/src/storage/sync-runs/types.ts +30 -1
- package/src/syncs/accounts.ts +85 -0
- package/src/syncs/builders.ts +18 -1
- package/src/syncs/connections.ts +123 -0
- package/src/syncs/execution.ts +64 -22
- package/src/syncs/index.ts +3 -0
- package/src/syncs/request.ts +81 -23
- package/src/syncs/run-dispatch.ts +69 -7
- package/src/testing/agent-approval-storage-contract.ts +123 -0
- package/src/testing/agent-inbox-storage-contract.ts +59 -0
- package/src/testing/agent-storage-contract.ts +794 -8
- package/src/testing/ai-cost-storage-contract.ts +80 -0
- package/src/testing/artifact-storage-contract.ts +139 -0
- package/src/testing/run-claim-storage-contract.ts +116 -0
- package/src/testing/sandboxes-contract.ts +50 -0
- package/src/workers/README.md +4 -1
- package/src/workers/lost-runs.ts +1 -0
- package/src/workers/queue-worker.ts +16 -5
- package/src/workers/worker.ts +67 -7
- package/dist/chunk-5a4a52tq.js.map +0 -10
- package/dist/chunk-5t9gm5tt.js.map +0 -22
- package/dist/chunk-68hm50qh.js.map +0 -13
- package/dist/chunk-aw1z0gre.js +0 -234
- package/dist/chunk-aw1z0gre.js.map +0 -12
- package/dist/chunk-ey1p8w68.js.map +0 -13
- package/dist/chunk-k3jh8gsg.js.map +0 -10
- package/dist/chunk-nxysqbt0.js.map +0 -10
- package/dist/chunk-qavwr628.js.map +0 -12
- package/dist/chunk-s1mqyqmm.js.map +0 -18
- package/dist/chunk-zeykm8my.js.map +0 -14
- /package/dist/{chunk-stmxh0hv.js.map → chunk-3neam1y5.js.map} +0 -0
- /package/dist/{chunk-0hkdtwqk.js.map → chunk-44hrfmbk.js.map} +0 -0
- /package/dist/{chunk-s5pj68fa.js.map → chunk-5sswe5ej.js.map} +0 -0
- /package/dist/{chunk-q9nkpr8k.js.map → chunk-9tpmfh3n.js.map} +0 -0
- /package/dist/{chunk-naxjka9v.js.map → chunk-brhp9d97.js.map} +0 -0
- /package/dist/{chunk-8a8k38tz.js.map → chunk-brybqw5k.js.map} +0 -0
- /package/dist/{chunk-vehcr9eb.js.map → chunk-cg7cygfj.js.map} +0 -0
- /package/dist/{chunk-b4escq4c.js.map → chunk-cpy282b8.js.map} +0 -0
- /package/dist/{chunk-bc3y6gff.js.map → chunk-jka26v8c.js.map} +0 -0
- /package/dist/{chunk-zxhym8tr.js.map → chunk-k29rdc3h.js.map} +0 -0
- /package/dist/{chunk-1yh6jgtz.js.map → chunk-mrs7jy17.js.map} +0 -0
- /package/dist/{chunk-pqvvqc65.js.map → chunk-pfdq1ga6.js.map} +0 -0
- /package/dist/{chunk-k29n4176.js.map → chunk-phs5fbff.js.map} +0 -0
- /package/dist/{chunk-wqe9shx2.js.map → chunk-qbd282aa.js.map} +0 -0
- /package/dist/{chunk-paxabbqd.js.map → chunk-tapdssb5.js.map} +0 -0
- /package/dist/{chunk-dhkc9b23.js.map → chunk-v8a1qjzp.js.map} +0 -0
- /package/dist/{chunk-pc7kra3k.js.map → chunk-xavet0qs.js.map} +0 -0
- /package/dist/{chunk-m9ketb51.js.map → chunk-ygvay56w.js.map} +0 -0
- /package/dist/{chunk-0mvjpgvm.js.map → chunk-yyj009tv.js.map} +0 -0
package/src/agents/run-events.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Broker } from "../broker"
|
|
1
|
+
import type { Broker, BrokerStreamDefinition } from "../broker"
|
|
2
2
|
import { createSixbError } from "../errors/internal"
|
|
3
3
|
import type { JsonValue } from "../json"
|
|
4
4
|
import type {
|
|
@@ -9,17 +9,27 @@ import type {
|
|
|
9
9
|
import type {
|
|
10
10
|
AgentCompactionFailureCode,
|
|
11
11
|
AgentInboxReadMessage,
|
|
12
|
+
AgentRunStepsRead,
|
|
12
13
|
AgentRunStreamEvent,
|
|
13
14
|
ModelUiChunk,
|
|
14
15
|
} from "./streams"
|
|
15
16
|
import {
|
|
16
17
|
agentRunFinishedEvent,
|
|
18
|
+
agentRunStepsStreamDefinition,
|
|
19
|
+
agentRunStepsStreamId,
|
|
17
20
|
agentRunStreamDefinition,
|
|
18
21
|
agentRunStreamEventBase,
|
|
19
22
|
agentRunStreamId,
|
|
20
23
|
agentRunStreamIdempotencyKey,
|
|
21
24
|
publishAgentRunActivity,
|
|
22
25
|
} from "./streams/protocol"
|
|
26
|
+
import {
|
|
27
|
+
appendCompacted,
|
|
28
|
+
continuesDelta,
|
|
29
|
+
type DeltaChunk,
|
|
30
|
+
isDeltaChunk,
|
|
31
|
+
mergeDeltas,
|
|
32
|
+
} from "./streams/steps"
|
|
23
33
|
|
|
24
34
|
export interface CompactionStartedInput {
|
|
25
35
|
/** A conversation's turn, or a child compacting its own thread. */
|
|
@@ -78,8 +88,14 @@ export const NOOP_STREAM_SINK: StreamSink = {
|
|
|
78
88
|
export function createBrokerStreamSink(input: {
|
|
79
89
|
readonly broker: Broker
|
|
80
90
|
readonly projectId: string
|
|
91
|
+
/** How long deltas of one span wait to go out as one record; 0 publishes each as it comes. */
|
|
92
|
+
readonly deltaWindowMs?: number
|
|
81
93
|
}): StreamSink {
|
|
82
|
-
return new BrokerStreamSink(
|
|
94
|
+
return new BrokerStreamSink(
|
|
95
|
+
input.broker,
|
|
96
|
+
input.projectId,
|
|
97
|
+
input.deltaWindowMs ?? AGENT_RUN_STREAM_DELTA_WINDOW_MS
|
|
98
|
+
)
|
|
83
99
|
}
|
|
84
100
|
|
|
85
101
|
/** Keeps stream delivery observational so sink failures never fail a turn. */
|
|
@@ -143,16 +159,44 @@ async function publishLifecycle(deliveries: readonly Promise<void>[]): Promise<v
|
|
|
143
159
|
if (failure?.status === "rejected") throw failure.reason
|
|
144
160
|
}
|
|
145
161
|
|
|
162
|
+
/** How long the deltas of one span wait to go out as one record. */
|
|
163
|
+
export const AGENT_RUN_STREAM_DELTA_WINDOW_MS = 50
|
|
164
|
+
|
|
165
|
+
/** Runs one sink keeps stream state for at once: one that never finished here is dropped first. */
|
|
166
|
+
const MAX_TRACKED_RUNS = 256
|
|
167
|
+
|
|
168
|
+
/** What a sink keeps about one run while it streams. */
|
|
169
|
+
interface RunStream {
|
|
170
|
+
readonly attempt: number
|
|
171
|
+
/** Every record of the run goes out through this chain, so they keep their order. */
|
|
172
|
+
tail: Promise<void>
|
|
173
|
+
/** Deltas of one span not published yet, under the index of the first. */
|
|
174
|
+
pending: {
|
|
175
|
+
run: AgentRunRecord
|
|
176
|
+
readonly chunkIndex: number
|
|
177
|
+
chunk: DeltaChunk
|
|
178
|
+
} | null
|
|
179
|
+
timer: ReturnType<typeof setTimeout> | undefined
|
|
180
|
+
/** The chunks published since the last step was logged, compacted. */
|
|
181
|
+
step: ModelUiChunk[]
|
|
182
|
+
/** What the turn read from its inbox since then, each after the first `at` chunks of `step`. */
|
|
183
|
+
reads: AgentRunStepsRead[]
|
|
184
|
+
/** The index of the last chunk published. */
|
|
185
|
+
lastChunkIndex: number | undefined
|
|
186
|
+
}
|
|
187
|
+
|
|
146
188
|
class BrokerStreamSink implements StreamSink {
|
|
147
189
|
private readonly ensured = new Set<string>()
|
|
190
|
+
private readonly runs = new Map<string, RunStream>()
|
|
148
191
|
|
|
149
192
|
constructor(
|
|
150
193
|
private readonly broker: Broker,
|
|
151
|
-
private readonly projectId: string
|
|
194
|
+
private readonly projectId: string,
|
|
195
|
+
private readonly deltaWindowMs: number
|
|
152
196
|
) {}
|
|
153
197
|
|
|
154
198
|
async publishStarted(run: AgentRunRecord): Promise<void> {
|
|
155
|
-
await this.
|
|
199
|
+
await this.publishInOrder(run, {
|
|
156
200
|
...agentRunStreamEventBase(run),
|
|
157
201
|
type: "agent.run.started",
|
|
158
202
|
...(run.modelId === undefined ? {} : { modelId: run.modelId }),
|
|
@@ -160,7 +204,7 @@ class BrokerStreamSink implements StreamSink {
|
|
|
160
204
|
}
|
|
161
205
|
|
|
162
206
|
async publishCompactionStarted(input: CompactionStartedInput): Promise<void> {
|
|
163
|
-
await this.
|
|
207
|
+
await this.publishInOrder(input.run, {
|
|
164
208
|
...agentRunStreamEventBase(input.run),
|
|
165
209
|
type: "agent.compaction.started",
|
|
166
210
|
reason: input.reason,
|
|
@@ -169,7 +213,7 @@ class BrokerStreamSink implements StreamSink {
|
|
|
169
213
|
}
|
|
170
214
|
|
|
171
215
|
async publishCompactionCompleted(input: CompactionCompletedInput): Promise<void> {
|
|
172
|
-
await this.
|
|
216
|
+
await this.publishInOrder(input.run, {
|
|
173
217
|
...agentRunStreamEventBase(input.run),
|
|
174
218
|
type: "agent.compaction.completed",
|
|
175
219
|
reason: input.reason,
|
|
@@ -180,7 +224,7 @@ class BrokerStreamSink implements StreamSink {
|
|
|
180
224
|
}
|
|
181
225
|
|
|
182
226
|
async publishCompactionFailed(input: CompactionFailedInput): Promise<void> {
|
|
183
|
-
await this.
|
|
227
|
+
await this.publishInOrder(input.run, {
|
|
184
228
|
...agentRunStreamEventBase(input.run),
|
|
185
229
|
type: "agent.compaction.failed",
|
|
186
230
|
reason: input.reason,
|
|
@@ -188,7 +232,11 @@ class BrokerStreamSink implements StreamSink {
|
|
|
188
232
|
})
|
|
189
233
|
}
|
|
190
234
|
|
|
191
|
-
/**
|
|
235
|
+
/**
|
|
236
|
+
* Publishes one live UI chunk. Deltas of one span arriving within the window go out as one record:
|
|
237
|
+
* a model streams a few characters per delta, far more often than anyone reads. Anything else
|
|
238
|
+
* first sends the deltas held, and is awaited, so broker backpressure throttles the token stream.
|
|
239
|
+
*/
|
|
192
240
|
async publishUiChunk(input: {
|
|
193
241
|
readonly run: AgentRunRecord
|
|
194
242
|
readonly chunkIndex: number
|
|
@@ -205,28 +253,45 @@ class BrokerStreamSink implements StreamSink {
|
|
|
205
253
|
return
|
|
206
254
|
}
|
|
207
255
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
{
|
|
219
|
-
|
|
256
|
+
const stream = this.stream(input.run)
|
|
257
|
+
const pending = stream.pending
|
|
258
|
+
if (pending && continuesDelta(pending.chunk, chunk)) {
|
|
259
|
+
pending.chunk = mergeDeltas(pending.chunk, chunk)
|
|
260
|
+
pending.run = input.run
|
|
261
|
+
return
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
const flushed = this.flush(stream)
|
|
265
|
+
if (isDeltaChunk(chunk) && this.deltaWindowMs > 0) {
|
|
266
|
+
stream.pending = { run: input.run, chunkIndex: input.chunkIndex, chunk }
|
|
267
|
+
stream.timer = setTimeout(() => void this.flush(stream), this.deltaWindowMs)
|
|
268
|
+
await flushed
|
|
269
|
+
return
|
|
270
|
+
}
|
|
271
|
+
await this.enqueue(stream, () => this.appendChunk(input.run, stream, input.chunkIndex, chunk))
|
|
220
272
|
}
|
|
221
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Publishes what the turn read, after every chunk it streamed before. Its step keeps it too, so
|
|
276
|
+
* whoever opens the turn later reads it where the turn did.
|
|
277
|
+
*/
|
|
222
278
|
async publishInboxRead(input: {
|
|
223
279
|
readonly run: ConversationAgentRunRecord
|
|
224
280
|
readonly messages: readonly AgentInboxReadMessage[]
|
|
225
281
|
}): Promise<void> {
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
282
|
+
const stream = this.stream(input.run)
|
|
283
|
+
void this.flush(stream)
|
|
284
|
+
|
|
285
|
+
await this.enqueue(stream, async () => {
|
|
286
|
+
const afterChunkIndex = stream.lastChunkIndex
|
|
287
|
+
await this.publish({
|
|
288
|
+
...agentRunStreamEventBase(input.run),
|
|
289
|
+
type: "agent.inbox.read",
|
|
290
|
+
messages: input.messages,
|
|
291
|
+
...(afterChunkIndex === undefined ? {} : { afterChunkIndex }),
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
stream.reads.push({ at: stream.step.length, messages: input.messages })
|
|
230
295
|
})
|
|
231
296
|
}
|
|
232
297
|
|
|
@@ -234,7 +299,7 @@ class BrokerStreamSink implements StreamSink {
|
|
|
234
299
|
readonly run: ConversationAgentRunRecord
|
|
235
300
|
readonly messageId: string
|
|
236
301
|
}): Promise<void> {
|
|
237
|
-
await this.
|
|
302
|
+
await this.publishInOrder(input.run, {
|
|
238
303
|
...agentRunStreamEventBase(input.run),
|
|
239
304
|
type: "agent.message.finalized",
|
|
240
305
|
messageId: input.messageId,
|
|
@@ -245,17 +310,153 @@ class BrokerStreamSink implements StreamSink {
|
|
|
245
310
|
if (run.status === "queued" || run.status === "running") {
|
|
246
311
|
return
|
|
247
312
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
313
|
+
try {
|
|
314
|
+
await this.publishInOrder(run, agentRunFinishedEvent(run))
|
|
315
|
+
} finally {
|
|
316
|
+
// This is the last event for the run: drop what the sink kept for it, to bound a long-lived
|
|
317
|
+
// worker's memory.
|
|
318
|
+
this.forget(run.id)
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** The run's stream state, started over for a new attempt. */
|
|
323
|
+
private stream(run: AgentRunRecord): RunStream {
|
|
324
|
+
const known = this.runs.get(run.id)
|
|
325
|
+
if (known && known.attempt === run.attempt) return known
|
|
326
|
+
if (known) clearTimeout(known.timer)
|
|
327
|
+
else if (this.runs.size >= MAX_TRACKED_RUNS) {
|
|
328
|
+
const [oldest] = this.runs.keys()
|
|
329
|
+
if (oldest !== undefined) this.forget(oldest)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
const stream: RunStream = {
|
|
333
|
+
attempt: run.attempt,
|
|
334
|
+
tail: Promise.resolve(),
|
|
335
|
+
pending: null,
|
|
336
|
+
timer: undefined,
|
|
337
|
+
step: [],
|
|
338
|
+
reads: [],
|
|
339
|
+
lastChunkIndex: undefined,
|
|
340
|
+
}
|
|
341
|
+
this.runs.set(run.id, stream)
|
|
342
|
+
return stream
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
private forget(runId: string): void {
|
|
346
|
+
clearTimeout(this.runs.get(runId)?.timer)
|
|
347
|
+
this.runs.delete(runId)
|
|
348
|
+
this.ensured.delete(agentRunStreamId(runId))
|
|
349
|
+
this.ensured.delete(agentRunStepsStreamId(runId))
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
/** Runs `task` after every record the run sent before it. */
|
|
353
|
+
private enqueue(stream: RunStream, task: () => Promise<void>): Promise<void> {
|
|
354
|
+
const next = stream.tail.then(task)
|
|
355
|
+
stream.tail = next.catch(() => {})
|
|
356
|
+
return next
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
/** Sends the deltas held, if any. Never rejects: a failed send is logged, as for any chunk. */
|
|
360
|
+
private flush(stream: RunStream): Promise<void> {
|
|
361
|
+
clearTimeout(stream.timer)
|
|
362
|
+
stream.timer = undefined
|
|
363
|
+
const pending = stream.pending
|
|
364
|
+
if (!pending) return stream.tail
|
|
365
|
+
stream.pending = null
|
|
366
|
+
return this.enqueue(stream, () =>
|
|
367
|
+
this.appendChunk(pending.run, stream, pending.chunkIndex, pending.chunk)
|
|
368
|
+
).catch((error: unknown) => {
|
|
369
|
+
console.error(`[Sixb] Agent run '${pending.run.id}' ui chunk stream publish failed:`, error)
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private async publishInOrder(run: AgentRunRecord, event: AgentRunStreamEvent): Promise<void> {
|
|
374
|
+
const stream = this.stream(run)
|
|
375
|
+
void this.flush(stream)
|
|
376
|
+
await this.enqueue(stream, () => this.publish(event))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private async appendChunk(
|
|
380
|
+
run: AgentRunRecord,
|
|
381
|
+
stream: RunStream,
|
|
382
|
+
chunkIndex: number,
|
|
383
|
+
chunk: ModelUiChunk
|
|
384
|
+
): Promise<void> {
|
|
385
|
+
const startsStep = chunk.type === "start-step" && !chunk.retry
|
|
386
|
+
// A new step: the one before is finished, and logged for whoever opens the turn later.
|
|
387
|
+
if (startsStep && (stream.step.length > 0 || stream.reads.length > 0)) {
|
|
388
|
+
await this.logStep(run, stream)
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
// `chunk` is already validated JSON and every other field is a JSON primitive, so the event is
|
|
392
|
+
// JSON as-built. Publish it pre-validated so the chunk — the highest-frequency agent event — is
|
|
393
|
+
// not serialized a second time inside `publish`.
|
|
394
|
+
await this.publish(
|
|
395
|
+
{
|
|
396
|
+
...agentRunStreamEventBase(run),
|
|
397
|
+
type: "agent.ui.chunk",
|
|
398
|
+
chunkIndex,
|
|
399
|
+
chunk,
|
|
400
|
+
},
|
|
401
|
+
{ prevalidated: true }
|
|
402
|
+
)
|
|
403
|
+
|
|
404
|
+
stream.lastChunkIndex = chunkIndex
|
|
405
|
+
if (chunk.type === "start-step" && chunk.retry) {
|
|
406
|
+
// A step asked again drops what its first call streamed, as a reader does. What the turn read
|
|
407
|
+
// as the step started stays: the step reads it again.
|
|
408
|
+
const [head] = stream.step
|
|
409
|
+
stream.step = head?.type === "start-step" ? [head] : []
|
|
410
|
+
stream.reads = stream.reads.filter((read) => read.at <= stream.step.length)
|
|
411
|
+
return
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// A chunk after a read starts a span of its own: the read sits between the two.
|
|
415
|
+
if (stream.reads.at(-1)?.at === stream.step.length) stream.step.push(chunk)
|
|
416
|
+
else appendCompacted(stream.step, chunk)
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* Appends the chunks since the last step logged to the run's steps stream. A failed append keeps
|
|
421
|
+
* them, so they go out with the next step: the live record is published either way.
|
|
422
|
+
*/
|
|
423
|
+
private async logStep(run: AgentRunRecord, stream: RunStream): Promise<void> {
|
|
424
|
+
if (stream.lastChunkIndex === undefined) return
|
|
425
|
+
const event: AgentRunStreamEvent = {
|
|
426
|
+
...agentRunStreamEventBase(run),
|
|
427
|
+
type: "agent.ui.steps",
|
|
428
|
+
throughChunkIndex: stream.lastChunkIndex,
|
|
429
|
+
chunks: stream.step,
|
|
430
|
+
...(stream.reads.length === 0 ? {} : { reads: stream.reads }),
|
|
431
|
+
}
|
|
432
|
+
try {
|
|
433
|
+
const definition = agentRunStepsStreamDefinition(run.id)
|
|
434
|
+
await this.ensure(definition)
|
|
435
|
+
await this.broker.append({
|
|
436
|
+
projectId: this.projectId,
|
|
437
|
+
streamId: definition.id,
|
|
438
|
+
records: [
|
|
439
|
+
{
|
|
440
|
+
name: event.type,
|
|
441
|
+
key: run.id,
|
|
442
|
+
// Its chunks were validated as they were published.
|
|
443
|
+
payload: event as unknown as JsonValue,
|
|
444
|
+
idempotencyKey: agentRunStreamIdempotencyKey(event),
|
|
445
|
+
},
|
|
446
|
+
],
|
|
447
|
+
})
|
|
448
|
+
stream.step = []
|
|
449
|
+
stream.reads = []
|
|
450
|
+
} catch (error) {
|
|
451
|
+
console.error(`[Sixb] Agent run '${run.id}' step log publish failed:`, error)
|
|
452
|
+
}
|
|
252
453
|
}
|
|
253
454
|
|
|
254
455
|
private async publish(
|
|
255
456
|
event: AgentRunStreamEvent,
|
|
256
457
|
options: { readonly prevalidated?: boolean } = {}
|
|
257
458
|
): Promise<void> {
|
|
258
|
-
await this.ensure(event.runId)
|
|
459
|
+
await this.ensure(agentRunStreamDefinition(event.runId))
|
|
259
460
|
// Broker payloads are plain JSON; keep SDK-specific chunk shapes opaque at this boundary. A
|
|
260
461
|
// pre-validated event (its only opaque field, the chunk, was already encoded by the caller) is
|
|
261
462
|
// already JSON, so it is forwarded as-is instead of being serialized a second time.
|
|
@@ -278,16 +479,12 @@ class BrokerStreamSink implements StreamSink {
|
|
|
278
479
|
})
|
|
279
480
|
}
|
|
280
481
|
|
|
281
|
-
private async ensure(
|
|
282
|
-
|
|
283
|
-
if (this.ensured.has(streamId)) {
|
|
482
|
+
private async ensure(stream: BrokerStreamDefinition): Promise<void> {
|
|
483
|
+
if (this.ensured.has(stream.id)) {
|
|
284
484
|
return
|
|
285
485
|
}
|
|
286
|
-
await this.broker.ensureStream({
|
|
287
|
-
|
|
288
|
-
stream: agentRunStreamDefinition(runId),
|
|
289
|
-
})
|
|
290
|
-
this.ensured.add(streamId)
|
|
486
|
+
await this.broker.ensureStream({ projectId: this.projectId, stream })
|
|
487
|
+
this.ensured.add(stream.id)
|
|
291
488
|
}
|
|
292
489
|
}
|
|
293
490
|
|
|
@@ -177,8 +177,19 @@ export function agentRunChildren(
|
|
|
177
177
|
const included = await Promise.all(found.map((each) => scope.includes(each.threadId)))
|
|
178
178
|
return found.filter((_, index) => included[index])
|
|
179
179
|
},
|
|
180
|
-
inConversation: (input) =>
|
|
181
|
-
|
|
180
|
+
inConversation: async (input) => {
|
|
181
|
+
const { total } = await agents.messages.list({
|
|
182
|
+
projectId,
|
|
183
|
+
threadId: run.threadId,
|
|
184
|
+
limit: 1,
|
|
185
|
+
})
|
|
186
|
+
return agents.runs.listThreadSubagents({
|
|
187
|
+
...input,
|
|
188
|
+
projectId,
|
|
189
|
+
threadId: run.threadId,
|
|
190
|
+
...(total > 0 ? { retainedTurnsOnly: true } : {}),
|
|
191
|
+
})
|
|
192
|
+
},
|
|
182
193
|
async threadRuns(threadId) {
|
|
183
194
|
if (!(await scope.includes(threadId))) return []
|
|
184
195
|
return listSubagentThreadRuns(agents, { projectId, threadId })
|
package/src/agents/run-token.ts
CHANGED
|
@@ -40,6 +40,13 @@ export const AGENT_API_ROUTES: readonly AgentApiRoute[] = SIXB_API_ROUTES.filter
|
|
|
40
40
|
effect: route.agentEffect ?? "read",
|
|
41
41
|
}))
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* The run a run-token request is from, which the sandbox CLI sends from `SIXB_RUN_ID`: one of the
|
|
45
|
+
* token's run's own children when the child works in its parent's workspace, under its parent's
|
|
46
|
+
* token. The server narrows the token's authority to that child; it never widens it.
|
|
47
|
+
*/
|
|
48
|
+
export const AGENT_RUN_HEADER = "x-sixb-run"
|
|
49
|
+
|
|
43
50
|
export function createAgentRunToken(input: AgentRunTokenInput): string {
|
|
44
51
|
return signToken(RUN_TOKEN, input)
|
|
45
52
|
}
|
package/src/agents/run-turn.ts
CHANGED
|
@@ -6,8 +6,10 @@ import type {
|
|
|
6
6
|
AgentRunRecord,
|
|
7
7
|
AgentThreadParticipantRecord,
|
|
8
8
|
AgentThreadRecord,
|
|
9
|
+
ConversationAgentRunRecord,
|
|
9
10
|
SubagentRunRecord,
|
|
10
11
|
} from "../storage/agents"
|
|
12
|
+
import { runPlaceKey } from "../storage/agents/provider"
|
|
11
13
|
import type { AiModelCallUsageRecord } from "../storage/ai-usage"
|
|
12
14
|
import type { ExecutionRecord } from "../storage/executions/types"
|
|
13
15
|
import { isPausedSubagentRun } from "./approvals"
|
|
@@ -50,6 +52,12 @@ export interface AgentTurnHistory {
|
|
|
50
52
|
* project that predates it.
|
|
51
53
|
*/
|
|
52
54
|
readonly sentLocales?: Readonly<Record<string, string>>
|
|
55
|
+
/**
|
|
56
|
+
* Retained user messages where the conversation changed workspace (between the cloud, computers
|
|
57
|
+
* or folders) since the message before. Stored run history decides it, so the system prompt
|
|
58
|
+
* carries no move timestamp and cached prefixes hold across round-trip moves.
|
|
59
|
+
*/
|
|
60
|
+
readonly movedMessageIds?: readonly string[]
|
|
53
61
|
/**
|
|
54
62
|
* The model call that ended the latest assistant message after the checkpoint: what a token
|
|
55
63
|
* estimate anchors on, as the provider counted it. None when that message's run compacted the
|
|
@@ -106,11 +114,17 @@ export interface AgentTurnHistoryHost {
|
|
|
106
114
|
/** A conversation's history: its latest checkpoint and the messages after it. */
|
|
107
115
|
export async function readAgentTurnHistory(
|
|
108
116
|
host: AgentTurnHistoryHost,
|
|
109
|
-
threadId: string
|
|
117
|
+
threadId: string,
|
|
118
|
+
options?: { readonly thread?: AgentThreadRecord | null }
|
|
110
119
|
): Promise<AgentTurnHistory> {
|
|
111
|
-
const { checkpoint, messages } = await
|
|
120
|
+
const [{ checkpoint, messages }, thread] = await Promise.all([
|
|
121
|
+
readRetainedHistory(host, threadId),
|
|
122
|
+
options && "thread" in options
|
|
123
|
+
? Promise.resolve(options.thread ?? null)
|
|
124
|
+
: host.storage.agents.threads.getById({ projectId: host.projectId, id: threadId }),
|
|
125
|
+
])
|
|
112
126
|
const [sent, usageAnchor] = await Promise.all([
|
|
113
|
-
readSentSettings(host, threadId, messages),
|
|
127
|
+
readSentSettings(host, threadId, messages, checkpoint, thread),
|
|
114
128
|
readUsageAnchor(host, messages, checkpoint),
|
|
115
129
|
])
|
|
116
130
|
return { checkpoint, messages, ...sent, ...(usageAnchor ? { usageAnchor } : {}) }
|
|
@@ -148,10 +162,10 @@ async function readTurnContext(
|
|
|
148
162
|
execution: ExecutionRecord | null
|
|
149
163
|
): Promise<AgentTurnContext> {
|
|
150
164
|
const { projectId } = host
|
|
151
|
-
const
|
|
152
|
-
|
|
165
|
+
const thread = await host.storage.agents.threads.getById({ projectId, id: run.threadId })
|
|
166
|
+
const [participants, history] = await Promise.all([
|
|
153
167
|
host.storage.agents.threads.listParticipants({ projectId, threadIds: [run.threadId] }),
|
|
154
|
-
readAgentTurnHistory(host, run.threadId),
|
|
168
|
+
readAgentTurnHistory(host, run.threadId, { thread }),
|
|
155
169
|
])
|
|
156
170
|
const readers = await readReaders(host, participants)
|
|
157
171
|
const named: Principal[] = [
|
|
@@ -180,10 +194,10 @@ async function readChildContext(
|
|
|
180
194
|
): Promise<AgentChildContext> {
|
|
181
195
|
const { projectId } = host
|
|
182
196
|
const agents = host.storage.agents
|
|
183
|
-
const
|
|
197
|
+
const thread = await agents.threads.getById({ projectId, id: run.threadId })
|
|
198
|
+
const [parent, history, runs] = await Promise.all([
|
|
184
199
|
agents.runs.getById({ projectId, id: run.parentRunId }),
|
|
185
|
-
|
|
186
|
-
readAgentTurnHistory(host, run.threadId),
|
|
200
|
+
readAgentTurnHistory(host, run.threadId, { thread }),
|
|
187
201
|
listSubagentThreadRuns(agents, { projectId, threadId: run.threadId }),
|
|
188
202
|
])
|
|
189
203
|
const [conversation, task] = await Promise.all([
|
|
@@ -259,28 +273,44 @@ function readUser(host: AgentRunSessionHost, id: string) {
|
|
|
259
273
|
}
|
|
260
274
|
|
|
261
275
|
/**
|
|
262
|
-
* The time zone and
|
|
263
|
-
*
|
|
276
|
+
* The time zone, locale and workspace transitions of each retained user message: read from the
|
|
277
|
+
* runs that answered them, so every later turn replays the exact same bytes.
|
|
264
278
|
*/
|
|
265
279
|
async function readSentSettings(
|
|
266
280
|
host: AgentTurnHistoryHost,
|
|
267
281
|
threadId: string,
|
|
268
|
-
messages: readonly AgentMessageRecord[]
|
|
269
|
-
|
|
282
|
+
messages: readonly AgentMessageRecord[],
|
|
283
|
+
checkpoint: AgentContextCheckpointRecord | null,
|
|
284
|
+
thread: AgentThreadRecord | null
|
|
285
|
+
): Promise<Pick<AgentTurnHistory, "sentTimeZones" | "sentLocales" | "movedMessageIds">> {
|
|
270
286
|
const userMessages = messages.filter((message) => message.role === "user")
|
|
271
287
|
const oldest = userMessages[0]
|
|
272
|
-
if (!oldest) return { sentTimeZones: {}, sentLocales: {} }
|
|
288
|
+
if (!oldest || thread?.kind === "subagent") return { sentTimeZones: {}, sentLocales: {} }
|
|
273
289
|
|
|
274
|
-
// A run starts after its trigger message, so this window holds every run that answered one
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
290
|
+
// A run starts after its trigger message, so this window holds every run that answered one;
|
|
291
|
+
// after a compaction, also check the latest summarized turn to catch a move right across it.
|
|
292
|
+
const [{ runs }, earlier] = await Promise.all([
|
|
293
|
+
host.storage.agents.runs.list({
|
|
294
|
+
projectId: host.projectId,
|
|
295
|
+
threadId,
|
|
296
|
+
kinds: ["conversation"],
|
|
297
|
+
startedAfter: new Date(oldest.createdAt.getTime() - 1),
|
|
298
|
+
}),
|
|
299
|
+
checkpoint
|
|
300
|
+
? host.storage.agents.runs.list({
|
|
301
|
+
projectId: host.projectId,
|
|
302
|
+
threadId,
|
|
303
|
+
kinds: ["conversation"],
|
|
304
|
+
startedBefore: new Date(oldest.createdAt.getTime()),
|
|
305
|
+
order: "desc",
|
|
306
|
+
limit: 5,
|
|
307
|
+
})
|
|
308
|
+
: Promise.resolve({ runs: [] }),
|
|
309
|
+
])
|
|
281
310
|
const retained = new Set(userMessages.map((message) => message.id))
|
|
282
311
|
const zones: Record<string, string> = {}
|
|
283
312
|
const locales: Record<string, string> = {}
|
|
313
|
+
const places: Record<string, string> = {}
|
|
284
314
|
for (const message of userMessages) {
|
|
285
315
|
// A message a turn read mid-run keeps the settings it was rendered with, so a later turn closes
|
|
286
316
|
// it with the same `<sixb_current_time>`.
|
|
@@ -288,13 +318,100 @@ async function readSentSettings(
|
|
|
288
318
|
if (typeof metadata?.timeZone === "string") zones[message.id] = metadata.timeZone
|
|
289
319
|
if (typeof metadata?.locale === "string") locales[message.id] = metadata.locale
|
|
290
320
|
}
|
|
291
|
-
|
|
321
|
+
// Oldest first so a retried turn's latest run records where the message ultimately ran.
|
|
322
|
+
for (const run of [...runs].reverse()) {
|
|
292
323
|
if (run.kind !== "conversation" || !retained.has(run.triggerMessageId)) continue
|
|
293
324
|
|
|
294
325
|
if (run.spec?.timeZone) zones[run.triggerMessageId] = run.spec.timeZone
|
|
295
326
|
if (run.spec?.locale) locales[run.triggerMessageId] = run.spec.locale
|
|
327
|
+
places[run.triggerMessageId] = runPlaceKey(run.spec)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// The latest turn the summary holds. It may have started after the oldest message kept, one sent
|
|
331
|
+
// while it waited: look for it in both lists.
|
|
332
|
+
const priorRun = await latestSummarizedRun(host, [...runs, ...earlier.runs], retained)
|
|
333
|
+
const movedMessageIds = detectMovedMessages({
|
|
334
|
+
userMessages,
|
|
335
|
+
checkpoint,
|
|
336
|
+
places,
|
|
337
|
+
priorPlace: priorRun ? runPlaceKey(priorRun.spec) : undefined,
|
|
338
|
+
})
|
|
339
|
+
return {
|
|
340
|
+
sentTimeZones: zones,
|
|
341
|
+
sentLocales: locales,
|
|
342
|
+
...(movedMessageIds.length > 0 ? { movedMessageIds } : {}),
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* The newest turn whose trigger message the summary holds. A turn whose message isn't kept is
|
|
348
|
+
* either summarized, its message still stored, or rewound by an edit, its message deleted: only the
|
|
349
|
+
* first tells where the conversation ran before its oldest kept message.
|
|
350
|
+
*/
|
|
351
|
+
async function latestSummarizedRun(
|
|
352
|
+
host: AgentTurnHistoryHost,
|
|
353
|
+
runs: readonly AgentRunRecord[],
|
|
354
|
+
retained: ReadonlySet<string>
|
|
355
|
+
): Promise<ConversationAgentRunRecord | undefined> {
|
|
356
|
+
const candidates = runs
|
|
357
|
+
.filter(
|
|
358
|
+
(run): run is ConversationAgentRunRecord =>
|
|
359
|
+
run.kind === "conversation" && !retained.has(run.triggerMessageId)
|
|
360
|
+
)
|
|
361
|
+
.sort((left, right) => startOf(right) - startOf(left))
|
|
362
|
+
|
|
363
|
+
const rewound = new Set<string>()
|
|
364
|
+
for (const run of candidates) {
|
|
365
|
+
if (rewound.has(run.triggerMessageId)) continue
|
|
366
|
+
|
|
367
|
+
const trigger = await host.storage.agents.messages.getById({
|
|
368
|
+
projectId: host.projectId,
|
|
369
|
+
id: run.triggerMessageId,
|
|
370
|
+
})
|
|
371
|
+
if (trigger) return run
|
|
372
|
+
rewound.add(run.triggerMessageId)
|
|
373
|
+
}
|
|
374
|
+
return undefined
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** When a run started, or was admitted when it never did: the order the run lists sort by. */
|
|
378
|
+
function startOf(run: AgentRunRecord): number {
|
|
379
|
+
return (run.startedAt ?? run.createdAt).getTime()
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The user messages that ran in another workspace than the one before them. Only runs decide it,
|
|
384
|
+
* never the thread's latest move, so a message keeps its note, or its lack of one, at every later
|
|
385
|
+
* turn: a round trip with no turn in between changes nothing, and the workspace it comes back to
|
|
386
|
+
* reads its cached prefix again.
|
|
387
|
+
*/
|
|
388
|
+
function detectMovedMessages(input: {
|
|
389
|
+
readonly userMessages: readonly AgentMessageRecord[]
|
|
390
|
+
readonly checkpoint: AgentContextCheckpointRecord | null
|
|
391
|
+
readonly places: Readonly<Record<string, string>>
|
|
392
|
+
readonly priorPlace: string | undefined
|
|
393
|
+
}): readonly string[] {
|
|
394
|
+
const moved: string[] = []
|
|
395
|
+
let previous = input.priorPlace
|
|
396
|
+
|
|
397
|
+
// A message with no run of its own, such as one sent into a turn that runs, decides nothing.
|
|
398
|
+
// Before any run of the thread, though, such messages are a fork's copies, answered in its
|
|
399
|
+
// source's workspace, as is a summary with no run before it: the fork's first turn starts
|
|
400
|
+
// elsewhere.
|
|
401
|
+
let inherited = previous === undefined && input.checkpoint !== null
|
|
402
|
+
|
|
403
|
+
for (const message of input.userMessages) {
|
|
404
|
+
const place = input.places[message.id]
|
|
405
|
+
if (place === undefined) {
|
|
406
|
+
inherited = true
|
|
407
|
+
continue
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
const crossed = previous === undefined ? inherited : previous !== place
|
|
411
|
+
if (crossed) moved.push(message.id)
|
|
412
|
+
previous = place
|
|
296
413
|
}
|
|
297
|
-
return
|
|
414
|
+
return moved
|
|
298
415
|
}
|
|
299
416
|
|
|
300
417
|
/**
|