@sixb/core 0.2.5 → 0.2.6
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 +2 -2
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +50 -44
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/model-routing.d.ts +5 -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-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/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-5a4a52tq.js → chunk-0pmpwn3g.js} +18 -2
- package/dist/chunk-0pmpwn3g.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-0mvjpgvm.js → chunk-425ydk65.js} +4 -4
- package/dist/{chunk-s5pj68fa.js → chunk-5sswe5ej.js} +2 -2
- package/dist/chunk-6hfbz4d0.js +98 -0
- package/dist/chunk-6hfbz4d0.js.map +10 -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-fpf57gca.js → chunk-7r9mqpva.js} +273 -66
- package/dist/{chunk-fpf57gca.js.map → chunk-7r9mqpva.js.map} +5 -5
- 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-90nqenq8.js +386 -0
- package/dist/chunk-90nqenq8.js.map +14 -0
- package/dist/{chunk-gjhrz66x.js → chunk-9c9yknwt.js} +247 -20
- package/dist/{chunk-gjhrz66x.js.map → chunk-9c9yknwt.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-z1njfqqs.js → chunk-ats8y3d9.js} +721 -156
- package/dist/{chunk-z1njfqqs.js.map → chunk-ats8y3d9.js.map} +13 -13
- package/dist/{chunk-68hm50qh.js → chunk-bcz9dxtf.js} +16 -46
- package/dist/chunk-bcz9dxtf.js.map +12 -0
- package/dist/{chunk-naxjka9v.js → chunk-brhp9d97.js} +2 -2
- package/dist/{chunk-8a8k38tz.js → chunk-brybqw5k.js} +1 -1
- package/dist/{chunk-s1mqyqmm.js → chunk-bs1sd0e0.js} +12 -8
- package/dist/chunk-bs1sd0e0.js.map +18 -0
- package/dist/{chunk-vehcr9eb.js → chunk-cg7cygfj.js} +1 -1
- package/dist/chunk-dq3t5sr3.js +114 -0
- package/dist/chunk-dq3t5sr3.js.map +11 -0
- package/dist/{chunk-r2psmn42.js → chunk-eg6xqef7.js} +1 -1
- package/dist/{chunk-zxhym8tr.js → chunk-f05994as.js} +1 -1
- package/dist/{chunk-5t9gm5tt.js → chunk-fmgf9h5e.js} +38 -14
- package/dist/chunk-fmgf9h5e.js.map +22 -0
- package/dist/{chunk-ey1p8w68.js → chunk-gaj8djsw.js} +80 -4
- package/dist/chunk-gaj8djsw.js.map +13 -0
- package/dist/{chunk-1yh6jgtz.js → chunk-grt2j5vp.js} +2 -2
- 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-rtdrm592.js → chunk-htdzx40w.js} +2 -2
- package/dist/{chunk-bc3y6gff.js → chunk-jka26v8c.js} +1 -1
- package/dist/{chunk-m3qx2pns.js → chunk-jt012fxq.js} +28 -12
- package/dist/{chunk-m3qx2pns.js.map → chunk-jt012fxq.js.map} +5 -5
- package/dist/{chunk-k3jh8gsg.js → chunk-kft7mp7z.js} +20 -3
- package/dist/chunk-kft7mp7z.js.map +10 -0
- package/dist/{chunk-qavwr628.js → chunk-n1hbwc6y.js} +5 -6
- package/dist/chunk-n1hbwc6y.js.map +12 -0
- package/dist/chunk-nxysqbt0.js.map +2 -2
- package/dist/{chunk-pqvvqc65.js → chunk-pqj8vff9.js} +3 -3
- 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-rg725hry.js → chunk-s8xxef60.js} +83 -33
- package/dist/{chunk-rg725hry.js.map → chunk-s8xxef60.js.map} +5 -5
- package/dist/{chunk-fzae1jpq.js → chunk-t19wjmnc.js} +5 -5
- 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-0hkdtwqk.js → chunk-xf76csps.js} +5 -5
- package/dist/{chunk-m9ketb51.js → chunk-ygvay56w.js} +1 -1
- package/dist/{chunk-b4escq4c.js → chunk-ykchk644.js} +6 -6
- package/dist/{chunk-k29n4176.js → chunk-ym1bqd98.js} +6 -6
- 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/types.d.ts +4 -1
- package/dist/deploy/types.d.ts.map +1 -1
- 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 +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -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/host.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/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/index.d.ts +3 -1
- package/dist/sandboxes/index.d.ts.map +1 -1
- package/dist/sandboxes/index.js +5 -5
- 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 +18 -2
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +136 -3
- 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 +22 -21
- 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 +1051 -58
- package/dist/testing/index.js.map +8 -8
- package/dist/testing/run-claim-storage-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 +4 -0
- package/src/agents/model-routing.ts +25 -9
- package/src/agents/request.ts +759 -40
- package/src/agents/run-events.ts +235 -38
- package/src/agents/run-session-children.ts +13 -2
- 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/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/types.ts +4 -1
- 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 +18 -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/host.ts +13 -7
- package/src/runtime/locale.ts +0 -10
- package/src/runtime/sixb.ts +12 -2
- package/src/sandboxes/README.md +3 -1
- package/src/sandboxes/auth.ts +32 -4
- package/src/sandboxes/index.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 +170 -13
- package/src/storage/agents/types.ts +148 -3
- 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 +767 -8
- package/src/testing/ai-cost-storage-contract.ts +80 -0
- package/src/testing/artifact-storage-contract.ts +129 -0
- package/src/testing/run-claim-storage-contract.ts +116 -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-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-0mvjpgvm.js.map → chunk-425ydk65.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-r2psmn42.js.map → chunk-eg6xqef7.js.map} +0 -0
- /package/dist/{chunk-zxhym8tr.js.map → chunk-f05994as.js.map} +0 -0
- /package/dist/{chunk-1yh6jgtz.js.map → chunk-grt2j5vp.js.map} +0 -0
- /package/dist/{chunk-rtdrm592.js.map → chunk-htdzx40w.js.map} +0 -0
- /package/dist/{chunk-bc3y6gff.js.map → chunk-jka26v8c.js.map} +0 -0
- /package/dist/{chunk-pqvvqc65.js.map → chunk-pqj8vff9.js.map} +0 -0
- /package/dist/{chunk-wqe9shx2.js.map → chunk-qbd282aa.js.map} +0 -0
- /package/dist/{chunk-fzae1jpq.js.map → chunk-t19wjmnc.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-0hkdtwqk.js.map → chunk-xf76csps.js.map} +0 -0
- /package/dist/{chunk-m9ketb51.js.map → chunk-ygvay56w.js.map} +0 -0
- /package/dist/{chunk-b4escq4c.js.map → chunk-ykchk644.js.map} +0 -0
- /package/dist/{chunk-k29n4176.js.map → chunk-ym1bqd98.js.map} +0 -0
package/src/agents/request.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { assertAuthorized } from "../authorization"
|
|
|
7
7
|
import type { FileRef } from "../blob-storage"
|
|
8
8
|
import type { BlobStorage } from "../blob-storage/types"
|
|
9
9
|
import { isValidFileRef } from "../blob-storage/validation"
|
|
10
|
+
import { canonicalTimeZone } from "../calendar"
|
|
10
11
|
import {
|
|
11
12
|
canInheritAgentRequestAuthorization,
|
|
12
13
|
createInheritedAgentExecutionRecord,
|
|
@@ -22,12 +23,13 @@ import type {
|
|
|
22
23
|
} from "../models"
|
|
23
24
|
import { isModelReasoning, modelReasoningSupportIssue } from "../models/language-model"
|
|
24
25
|
import { resolveLanguageModel } from "../models/resolve"
|
|
25
|
-
import { canonicalLocale
|
|
26
|
+
import { canonicalLocale } from "../runtime/locale"
|
|
26
27
|
import type { SixbRuntimeContext } from "../runtime/types"
|
|
27
28
|
import {
|
|
28
29
|
type AgentApprovalMode,
|
|
29
30
|
type AgentApprovalRecord,
|
|
30
31
|
type AgentInboxItemRecord,
|
|
32
|
+
type AgentMessageRecord,
|
|
31
33
|
type AgentStorage,
|
|
32
34
|
AgentStorageError,
|
|
33
35
|
type AgentThreadComputer,
|
|
@@ -35,6 +37,7 @@ import {
|
|
|
35
37
|
type ConversationAgentRunRecord,
|
|
36
38
|
type ConversationAgentRunSpec,
|
|
37
39
|
} from "../storage/agents"
|
|
40
|
+
import { type AgentTurnPlace, countsAsThreadMessage, turnPlace } from "../storage/agents/provider"
|
|
38
41
|
import {
|
|
39
42
|
aiLimitSubjectsFromAttribution,
|
|
40
43
|
aiUsageLimitExceededError,
|
|
@@ -42,7 +45,9 @@ import {
|
|
|
42
45
|
applicableAiLimitPolicyStatuses,
|
|
43
46
|
} from "../storage/ai-limits/enforcement"
|
|
44
47
|
import type { AiLimitPolicyStatus } from "../storage/ai-limits/types"
|
|
48
|
+
import type { PublishedArtifactVersion } from "../storage/artifacts/types"
|
|
45
49
|
import type { ExecutionRecord } from "../storage/executions"
|
|
50
|
+
import type { Storage } from "../storage/types"
|
|
46
51
|
import {
|
|
47
52
|
type AgentTurnReadiness,
|
|
48
53
|
announceAgentApprovals,
|
|
@@ -121,6 +126,31 @@ export interface RequestAgentRunInput {
|
|
|
121
126
|
readonly principal?: Principal
|
|
122
127
|
}
|
|
123
128
|
|
|
129
|
+
/** An earlier message to replace, and the turn its new text starts. */
|
|
130
|
+
export interface EditAgentMessageInput {
|
|
131
|
+
/** The conversation thread containing the message to edit. */
|
|
132
|
+
readonly threadId: string
|
|
133
|
+
/** The existing user message to replace and rewind from. */
|
|
134
|
+
readonly messageId: string
|
|
135
|
+
/** Updated user text. Omitted when attachments are the whole message. */
|
|
136
|
+
readonly text?: string
|
|
137
|
+
/** Blob-backed files attached to the edited message. */
|
|
138
|
+
readonly attachments?: readonly FileRef[]
|
|
139
|
+
/** Structured page/object context snapshotted onto the edited user message. */
|
|
140
|
+
readonly context?: readonly AgentContextEntryInput[]
|
|
141
|
+
/** Configured language model selected for the re-run. Omitted uses routing or the agent default. */
|
|
142
|
+
readonly model?: LanguageModelRef
|
|
143
|
+
/** Reasoning effort or token budget for the re-run. Omitted uses the model's default. */
|
|
144
|
+
readonly reasoning?: AgentReasoning
|
|
145
|
+
readonly timeZone?: string
|
|
146
|
+
readonly locale?: string
|
|
147
|
+
readonly approvalMode?: AgentApprovalMode
|
|
148
|
+
/** Explicit id for the replacement user message. Defaults to a generated id. */
|
|
149
|
+
readonly nextMessageId?: string
|
|
150
|
+
/** Caller principal for privileged integrations; scoped runtimes use their authorization principal. */
|
|
151
|
+
readonly principal?: Principal
|
|
152
|
+
}
|
|
153
|
+
|
|
124
154
|
/** What a turn's model is chosen from. */
|
|
125
155
|
export interface AgentRequestModels {
|
|
126
156
|
readonly language?: LanguageModelCatalog
|
|
@@ -206,24 +236,24 @@ export async function requestAgentRun(
|
|
|
206
236
|
(await resolveAgentApprovalMode(agents, { projectId, principal, threadId: existingThread?.id }))
|
|
207
237
|
.approvalMode
|
|
208
238
|
|
|
239
|
+
const place = turnPlace(runsOn, existingThread ? existingThread.computer : input.computer)
|
|
240
|
+
|
|
209
241
|
// Last before anything is written, so a message the checks above refuse never reaches the
|
|
210
242
|
// decision model. Concurrent messages to an idle thread can still each ask before one of them is
|
|
211
243
|
// refused with `active_run_exists` below.
|
|
212
244
|
const selected =
|
|
213
245
|
"router" in requested
|
|
214
|
-
? await routedConversationRunSpec(
|
|
246
|
+
? await routedConversationRunSpec({
|
|
215
247
|
...requested,
|
|
216
|
-
|
|
217
|
-
|
|
248
|
+
previous: existingThread
|
|
249
|
+
? await latestConversationRun(agents, projectId, existingThread.id)
|
|
250
|
+
: undefined,
|
|
251
|
+
place,
|
|
218
252
|
settings,
|
|
219
253
|
language: models.language,
|
|
220
254
|
})
|
|
221
255
|
: requested
|
|
222
|
-
const spec: ConversationAgentRunSpec = Object.freeze({
|
|
223
|
-
...selected,
|
|
224
|
-
approvalMode,
|
|
225
|
-
...(runsOn === undefined ? {} : { runsOn }),
|
|
226
|
-
})
|
|
256
|
+
const spec: ConversationAgentRunSpec = Object.freeze({ ...selected, approvalMode, ...place })
|
|
227
257
|
|
|
228
258
|
const createdThread = existingThread === null
|
|
229
259
|
const thread =
|
|
@@ -301,6 +331,608 @@ export async function requestAgentRun(
|
|
|
301
331
|
}
|
|
302
332
|
}
|
|
303
333
|
|
|
334
|
+
/** Whether a stored message is a user-authored prompt that can be edited in place. */
|
|
335
|
+
export function isEditableAgentMessage(
|
|
336
|
+
message: Pick<AgentMessageRecord, "role" | "parts">
|
|
337
|
+
): boolean {
|
|
338
|
+
if (message.role !== "user") return false
|
|
339
|
+
if (message.parts.some((part) => part.type === "continuation")) return false
|
|
340
|
+
return countsAsThreadMessage(message)
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Edit an earlier user message in place: the thread loses that message and everything after it,
|
|
345
|
+
* and the edited message starts a new turn.
|
|
346
|
+
*
|
|
347
|
+
* On an idle thread the rewind and the new turn are one transaction. While a turn runs, the edit
|
|
348
|
+
* waits in the thread's inbox, sent now: the turn stops, and its end rewinds the thread and starts
|
|
349
|
+
* the edited message (see `startQueuedAgentTurnFromInbox`), so nothing the stopped turn still
|
|
350
|
+
* writes lands after the edit.
|
|
351
|
+
*
|
|
352
|
+
* Historical `agent_runs` and `executions` remain intact for AI usage and cost accounting.
|
|
353
|
+
*/
|
|
354
|
+
export async function editAgentMessage(
|
|
355
|
+
runtime: SixbRuntimeContext,
|
|
356
|
+
execution: ExecutionContext,
|
|
357
|
+
models: AgentRequestModels,
|
|
358
|
+
input: EditAgentMessageInput,
|
|
359
|
+
blobStorage?: RewindBlobStorage
|
|
360
|
+
): Promise<SendAgentMessageResult> {
|
|
361
|
+
const authority = resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
362
|
+
execution,
|
|
363
|
+
authorization: runtime.runtimeAuthorization,
|
|
364
|
+
})
|
|
365
|
+
assertNoAgentSelector(input)
|
|
366
|
+
assertAuthorized(runtime, { kind: "agent.run" })
|
|
367
|
+
assertRequestAuthorityCanRunAgent(runtime)
|
|
368
|
+
|
|
369
|
+
const trigger = triggerParts(input)
|
|
370
|
+
const selection = { model: input.model, reasoning: input.reasoning }
|
|
371
|
+
const settings = requesterSettings(input)
|
|
372
|
+
if (input.approvalMode !== undefined) assertAgentApprovalMode(input.approvalMode)
|
|
373
|
+
|
|
374
|
+
const routed = routedTurn(models.router, selection, input)
|
|
375
|
+
const requested =
|
|
376
|
+
routed ?? (await resolveConversationRunSpec({ models: models.language, selection, settings }))
|
|
377
|
+
assertAttachments(input.attachments)
|
|
378
|
+
|
|
379
|
+
const contextParts = await resolveAgentContextParts(runtime, input.context)
|
|
380
|
+
const agents = requireAgentStorage(runtime)
|
|
381
|
+
const projectId = runtime.projectId
|
|
382
|
+
const principal =
|
|
383
|
+
authority.type === "principal"
|
|
384
|
+
? authority.context.principal
|
|
385
|
+
: (input.principal ?? SYSTEM_PRINCIPAL)
|
|
386
|
+
|
|
387
|
+
const thread = await agents.threads.getById({ projectId, id: input.threadId })
|
|
388
|
+
if (!thread) {
|
|
389
|
+
throw new AgentRequestError(
|
|
390
|
+
"thread_not_found",
|
|
391
|
+
`[Sixb] Agent thread '${input.threadId}' not found.`
|
|
392
|
+
)
|
|
393
|
+
}
|
|
394
|
+
assertThreadAcceptsMessages(thread, principal)
|
|
395
|
+
|
|
396
|
+
const target = await agents.messages.getById({ projectId, id: input.messageId })
|
|
397
|
+
if (!target || target.threadId !== thread.id) {
|
|
398
|
+
throw new AgentRequestError(
|
|
399
|
+
"message_not_found",
|
|
400
|
+
`[Sixb] Agent message '${input.messageId}' not found in thread '${thread.id}'.`
|
|
401
|
+
)
|
|
402
|
+
}
|
|
403
|
+
assertEditableMessageAuthority(thread, target, principal)
|
|
404
|
+
|
|
405
|
+
const tail = await listAllThreadMessagesFromSeq(agents, projectId, thread.id, target.seq)
|
|
406
|
+
assertParticipantCanRewindTail(thread, tail, principal)
|
|
407
|
+
const rewoundRuns = await listRewoundConversationRuns(agents, projectId, thread.id, tail)
|
|
408
|
+
assertRewindsWholeTurns(target, tail, rewoundRuns)
|
|
409
|
+
|
|
410
|
+
const approvalMode =
|
|
411
|
+
input.approvalMode ??
|
|
412
|
+
(await resolveAgentApprovalMode(agents, { projectId, principal, threadId: thread.id }))
|
|
413
|
+
.approvalMode
|
|
414
|
+
|
|
415
|
+
// The edited turn runs where the thread runs now, like any message sent to it, and is routed
|
|
416
|
+
// against the turn it continues: the newest one the rewind keeps.
|
|
417
|
+
const place = turnPlace(thread.runsOn, thread.computer)
|
|
418
|
+
const selected =
|
|
419
|
+
"router" in requested
|
|
420
|
+
? await routedConversationRunSpec({
|
|
421
|
+
...requested,
|
|
422
|
+
previous: await latestRetainedConversationRun(agents, projectId, thread.id, tail),
|
|
423
|
+
place,
|
|
424
|
+
settings,
|
|
425
|
+
language: models.language,
|
|
426
|
+
})
|
|
427
|
+
: requested
|
|
428
|
+
const spec: ConversationAgentRunSpec = Object.freeze({ ...selected, approvalMode, ...place })
|
|
429
|
+
|
|
430
|
+
const edit: AgentMessageEdit = {
|
|
431
|
+
target,
|
|
432
|
+
messageId: input.nextMessageId ?? createAgentMessageId(),
|
|
433
|
+
authorPrincipal: principal,
|
|
434
|
+
parts: [
|
|
435
|
+
...contextParts,
|
|
436
|
+
...trigger,
|
|
437
|
+
...(input.attachments ?? []).map((fileRef) => ({ type: "file" as const, fileRef })),
|
|
438
|
+
],
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// Checked before anything stops: an edit the budget refuses must not end the turn it replaces.
|
|
442
|
+
const runId = createAgentRunId()
|
|
443
|
+
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId)
|
|
444
|
+
await assertAiLimitPreflight(runtime, durableExecution)
|
|
445
|
+
|
|
446
|
+
if (thread.activeRunId !== null) {
|
|
447
|
+
const item = await deferAgentMessageEdit(runtime, execution, thread, edit, {
|
|
448
|
+
spec,
|
|
449
|
+
settings,
|
|
450
|
+
blobStorage,
|
|
451
|
+
})
|
|
452
|
+
return { kind: "inbox", item }
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
const documents = await rewoundTurnDocuments(runtime, blobStorage, rewoundRuns, tail)
|
|
456
|
+
|
|
457
|
+
let run: ConversationAgentRunRecord
|
|
458
|
+
let rewind: AgentThreadRewind | undefined
|
|
459
|
+
let superseded: readonly AgentApprovalRecord[] = []
|
|
460
|
+
try {
|
|
461
|
+
run = await runtime.storage.transaction(async (tx) => {
|
|
462
|
+
const txAgents = tx.agents
|
|
463
|
+
if (!txAgents) {
|
|
464
|
+
throw new AgentRequestError(
|
|
465
|
+
"storage_unavailable",
|
|
466
|
+
"[Sixb] Agent storage is not configured."
|
|
467
|
+
)
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
rewind = await rewindAgentThread(tx, txAgents, {
|
|
471
|
+
projectId,
|
|
472
|
+
thread,
|
|
473
|
+
messageId: edit.target.id,
|
|
474
|
+
editor: principal,
|
|
475
|
+
documents,
|
|
476
|
+
})
|
|
477
|
+
|
|
478
|
+
await tx.executions.create(durableExecution)
|
|
479
|
+
const reported = await reportAgentApprovals(txAgents, {
|
|
480
|
+
projectId,
|
|
481
|
+
threadId: thread.id,
|
|
482
|
+
messageId: edit.messageId,
|
|
483
|
+
})
|
|
484
|
+
superseded = reported.superseded
|
|
485
|
+
|
|
486
|
+
await txAgents.messages.append({
|
|
487
|
+
id: edit.messageId,
|
|
488
|
+
projectId,
|
|
489
|
+
threadId: thread.id,
|
|
490
|
+
runId: null,
|
|
491
|
+
role: "user",
|
|
492
|
+
parts: [...reported.parts, ...edit.parts],
|
|
493
|
+
authorPrincipal: principal,
|
|
494
|
+
})
|
|
495
|
+
|
|
496
|
+
return txAgents.runs.create({
|
|
497
|
+
id: runId,
|
|
498
|
+
projectId,
|
|
499
|
+
executionId: durableExecution.id,
|
|
500
|
+
threadId: thread.id,
|
|
501
|
+
triggerMessageId: edit.messageId,
|
|
502
|
+
spec,
|
|
503
|
+
})
|
|
504
|
+
})
|
|
505
|
+
} catch (error) {
|
|
506
|
+
if (error instanceof AgentStorageError && error.code === "active_run_exists") {
|
|
507
|
+
throw new AgentRequestError("active_run_exists", error.message)
|
|
508
|
+
}
|
|
509
|
+
throw error
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
await announceAgentThreadRewind(runtime, rewind, superseded)
|
|
513
|
+
await publishRunActivity(runtime, run)
|
|
514
|
+
await dispatchAgentRun(runtime, agents, runId)
|
|
515
|
+
return { kind: "turn", run, createdThread: false }
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** Where a rewind reads the documents that restore the canvases a rewound turn wrote. */
|
|
519
|
+
type RewindBlobStorage = Pick<BlobStorage, "open" | "put">
|
|
520
|
+
|
|
521
|
+
/** An edit of an earlier message: the message it replaces, and the one that replaces it. */
|
|
522
|
+
interface AgentMessageEdit {
|
|
523
|
+
readonly target: AgentMessageRecord
|
|
524
|
+
readonly messageId: string
|
|
525
|
+
readonly authorPrincipal: Principal
|
|
526
|
+
readonly parts: readonly AgentMessagePart[]
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* Stop the running turn so the edit starts after it: the edit waits in the thread's inbox, sent
|
|
531
|
+
* now, and the turn's end rewinds the thread and starts it. Stopping a turn is for whoever may: the
|
|
532
|
+
* person who asked for it, or the thread's owner. A newer edit replaces one still waiting.
|
|
533
|
+
*/
|
|
534
|
+
async function deferAgentMessageEdit(
|
|
535
|
+
runtime: SixbRuntimeContext,
|
|
536
|
+
execution: ExecutionContext,
|
|
537
|
+
thread: AgentThreadRecord,
|
|
538
|
+
edit: AgentMessageEdit,
|
|
539
|
+
options: {
|
|
540
|
+
readonly spec: ConversationAgentRunSpec
|
|
541
|
+
readonly settings: RequesterSettings
|
|
542
|
+
readonly blobStorage: RewindBlobStorage | undefined
|
|
543
|
+
}
|
|
544
|
+
): Promise<AgentInboxItemRecord> {
|
|
545
|
+
const { spec, settings } = options
|
|
546
|
+
const agents = requireAgentStorage(runtime)
|
|
547
|
+
const projectId = runtime.projectId
|
|
548
|
+
const active = thread.activeRunId
|
|
549
|
+
? await agents.runs.getById({ projectId, id: thread.activeRunId })
|
|
550
|
+
: null
|
|
551
|
+
if (active?.kind !== "conversation") {
|
|
552
|
+
throw new AgentRequestError(
|
|
553
|
+
"active_run_exists",
|
|
554
|
+
`[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`
|
|
555
|
+
)
|
|
556
|
+
}
|
|
557
|
+
// The turn's end starts the edit as the person who sent it: a request no person sent, with sign-in
|
|
558
|
+
// off, leaves no one to start it as.
|
|
559
|
+
if (!execution.requestedBy) {
|
|
560
|
+
throw new AgentRequestError(
|
|
561
|
+
"active_run_exists",
|
|
562
|
+
`[Sixb] Agent thread '${thread.id}' is answering, and an edit without a signed-in sender cannot wait for it: stop the answer, then edit.`
|
|
563
|
+
)
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
const mayStop =
|
|
567
|
+
principalsEqual(edit.authorPrincipal, thread.ownerPrincipal) ||
|
|
568
|
+
(await askedForTurn(runtime, active, edit.authorPrincipal))
|
|
569
|
+
if (!mayStop) {
|
|
570
|
+
throw new AgentRequestError(
|
|
571
|
+
"not_run_requester",
|
|
572
|
+
`[Sixb] Agent thread '${thread.id}' runs a turn someone else asked for: only they or the thread's owner can stop it. Edit the message once it ends.`
|
|
573
|
+
)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// The request that sends it is recorded with it: the turn that starts it once this request is
|
|
577
|
+
// gone runs as that request's child.
|
|
578
|
+
const request = await ensureExecutionRecord(
|
|
579
|
+
runtime.storage.executions,
|
|
580
|
+
executionRecordInputFromRuntime({
|
|
581
|
+
execution,
|
|
582
|
+
runtimeAuthorization: runtime.runtimeAuthorization,
|
|
583
|
+
})
|
|
584
|
+
)
|
|
585
|
+
|
|
586
|
+
for (const waiting of await agents.inbox.list({ projectId, threadId: thread.id })) {
|
|
587
|
+
if (
|
|
588
|
+
waiting.replacesMessageId !== undefined &&
|
|
589
|
+
principalsEqual(waiting.authorPrincipal, edit.authorPrincipal)
|
|
590
|
+
) {
|
|
591
|
+
await agents.inbox.remove({ projectId, threadId: thread.id, id: waiting.id })
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
const { item } = await agents.inbox.enqueue({
|
|
596
|
+
id: createAgentInboxItemId(),
|
|
597
|
+
projectId,
|
|
598
|
+
threadId: thread.id,
|
|
599
|
+
messageId: edit.messageId,
|
|
600
|
+
authorPrincipal: edit.authorPrincipal,
|
|
601
|
+
mode: "queue",
|
|
602
|
+
immediate: true,
|
|
603
|
+
replacesMessageId: edit.target.id,
|
|
604
|
+
parts: edit.parts,
|
|
605
|
+
// Routed now, against the turn the edit continues: the stopped turn is not one of those.
|
|
606
|
+
spec: {
|
|
607
|
+
model: spec.model,
|
|
608
|
+
...(spec.reasoning === undefined ? {} : { reasoning: spec.reasoning }),
|
|
609
|
+
approvalMode: spec.approvalMode,
|
|
610
|
+
},
|
|
611
|
+
...settings,
|
|
612
|
+
executionId: request.id,
|
|
613
|
+
})
|
|
614
|
+
|
|
615
|
+
// Taken from the turn before it stops: it would read them at its next step.
|
|
616
|
+
await queueWaitingSteers(agents, projectId, thread.id, edit.authorPrincipal)
|
|
617
|
+
await stopTurnBefore(runtime, execution, active, options.blobStorage)
|
|
618
|
+
// The turn may have ended before the edit reached the inbox, its end reading none of it.
|
|
619
|
+
await startIfThreadIdle(runtime, execution, thread.id, options.blobStorage)
|
|
620
|
+
return item
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** What a rewind took back, for the events that tell watchers. */
|
|
624
|
+
interface AgentThreadRewind {
|
|
625
|
+
readonly restoredVersions: readonly PublishedArtifactVersion["version"][]
|
|
626
|
+
readonly cancelledApprovals: readonly AgentApprovalRecord[]
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
/**
|
|
630
|
+
* Take the thread back to just before the edited message, in the caller's transaction: undo the
|
|
631
|
+
* artifact writes of the turns it removes, newest first, drop their approvals and the summaries
|
|
632
|
+
* that saw them, then delete the message and everything after it. It checks again what the edit
|
|
633
|
+
* checked, as the thread may have moved on since, and writes nothing when a check fails.
|
|
634
|
+
*/
|
|
635
|
+
async function rewindAgentThread(
|
|
636
|
+
tx: Storage,
|
|
637
|
+
agents: AgentStorage,
|
|
638
|
+
input: {
|
|
639
|
+
readonly projectId: string
|
|
640
|
+
readonly thread: AgentThreadRecord
|
|
641
|
+
/** The edited message: the thread keeps what came before it. */
|
|
642
|
+
readonly messageId: string
|
|
643
|
+
readonly editor: Principal
|
|
644
|
+
/** Restore documents of the rewound turns' canvases, read before the transaction. */
|
|
645
|
+
readonly documents: ReadonlyMap<string, Record<string, FileRef>>
|
|
646
|
+
}
|
|
647
|
+
): Promise<AgentThreadRewind> {
|
|
648
|
+
const { projectId, thread, editor } = input
|
|
649
|
+
|
|
650
|
+
const target = await agents.messages.getById({ projectId, id: input.messageId })
|
|
651
|
+
if (!target || target.threadId !== thread.id) {
|
|
652
|
+
throw new AgentRequestError(
|
|
653
|
+
"message_not_found",
|
|
654
|
+
`[Sixb] Agent message '${input.messageId}' not found in thread '${thread.id}'.`
|
|
655
|
+
)
|
|
656
|
+
}
|
|
657
|
+
assertEditableMessageAuthority(thread, target, editor)
|
|
658
|
+
|
|
659
|
+
const tail = await listAllThreadMessagesFromSeq(agents, projectId, thread.id, target.seq)
|
|
660
|
+
assertParticipantCanRewindTail(thread, tail, editor)
|
|
661
|
+
const rewoundRuns = await listRewoundConversationRuns(agents, projectId, thread.id, tail)
|
|
662
|
+
assertRewindsWholeTurns(target, tail, rewoundRuns)
|
|
663
|
+
|
|
664
|
+
const restored = new Map<string, PublishedArtifactVersion["version"]>()
|
|
665
|
+
if (tx.artifacts) {
|
|
666
|
+
for (const { run, later } of oldestFirst(rewoundRuns, tail)) {
|
|
667
|
+
const trigger = tail.find((message) => message.id === run.triggerMessageId)
|
|
668
|
+
const undone = await tx.artifacts.undoTurnWrites({
|
|
669
|
+
projectId,
|
|
670
|
+
turnRunId: run.id,
|
|
671
|
+
laterTurnRunIds: later,
|
|
672
|
+
documents: input.documents.get(run.id) ?? {},
|
|
673
|
+
...(trigger?.authorPrincipal ? { requester: trigger.authorPrincipal } : {}),
|
|
674
|
+
})
|
|
675
|
+
for (const entry of undone.restored) restored.set(entry.artifact.id, entry.version)
|
|
676
|
+
for (const deletedId of undone.deleted) restored.delete(deletedId)
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
const approvals = await agents.approvals.rewind({
|
|
681
|
+
projectId,
|
|
682
|
+
threadId: thread.id,
|
|
683
|
+
runIds: rewoundRuns.map((run) => run.id),
|
|
684
|
+
clearedMessageIds: tail.map((message) => message.id),
|
|
685
|
+
})
|
|
686
|
+
await agents.checkpoints.deleteAfterSeq({
|
|
687
|
+
projectId,
|
|
688
|
+
threadId: thread.id,
|
|
689
|
+
afterSeq: target.seq - 1,
|
|
690
|
+
})
|
|
691
|
+
await agents.messages.deleteFromSeq({ projectId, threadId: thread.id, fromSeq: target.seq })
|
|
692
|
+
await queueWaitingSteers(agents, projectId, thread.id, editor)
|
|
693
|
+
|
|
694
|
+
return { restoredVersions: [...restored.values()], cancelledApprovals: approvals.cancelled }
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* The editor's steers still waiting were written for a turn the edit takes back: they wait for the
|
|
699
|
+
* next turn instead, where the tray shows them to keep or withdraw. Someone else's stay as they are.
|
|
700
|
+
*/
|
|
701
|
+
async function queueWaitingSteers(
|
|
702
|
+
agents: AgentStorage,
|
|
703
|
+
projectId: string,
|
|
704
|
+
threadId: string,
|
|
705
|
+
editor: Principal
|
|
706
|
+
): Promise<void> {
|
|
707
|
+
const waiting = await agents.inbox.list({ projectId, threadId, includeClaimed: false })
|
|
708
|
+
for (const item of waiting) {
|
|
709
|
+
if (item.mode !== "steer" || item.immediate) continue
|
|
710
|
+
if (!principalsEqual(item.authorPrincipal, editor)) continue
|
|
711
|
+
|
|
712
|
+
try {
|
|
713
|
+
await agents.inbox.update({ projectId, threadId, id: item.id, mode: "queue" })
|
|
714
|
+
} catch (error) {
|
|
715
|
+
// The stopping turn took it meanwhile: its end lets it go, and the rewind queues it then.
|
|
716
|
+
if (error instanceof AgentStorageError && error.code === "invalid_state") continue
|
|
717
|
+
throw error
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
/** The documents that restore the canvases the rewound turns wrote, read before the rewind. */
|
|
723
|
+
async function rewoundTurnDocuments(
|
|
724
|
+
runtime: SixbRuntimeContext,
|
|
725
|
+
blobStorage: RewindBlobStorage | undefined,
|
|
726
|
+
rewoundRuns: readonly ConversationAgentRunRecord[],
|
|
727
|
+
tail: readonly AgentMessageRecord[]
|
|
728
|
+
): Promise<ReadonlyMap<string, Record<string, FileRef>>> {
|
|
729
|
+
const documents = new Map<string, Record<string, FileRef>>()
|
|
730
|
+
const artifacts = runtime.storage.artifacts
|
|
731
|
+
if (!artifacts || !blobStorage) return documents
|
|
732
|
+
|
|
733
|
+
for (const { run, later } of oldestFirst(rewoundRuns, tail)) {
|
|
734
|
+
documents.set(
|
|
735
|
+
run.id,
|
|
736
|
+
await undoneTurnDocuments(
|
|
737
|
+
{ projectId: runtime.projectId, storage: artifacts, blobStorage },
|
|
738
|
+
run.id,
|
|
739
|
+
later
|
|
740
|
+
)
|
|
741
|
+
)
|
|
742
|
+
}
|
|
743
|
+
return documents
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* The rewound turns oldest first, each with the turns after it: undone together, an artifact
|
|
748
|
+
* several of them wrote goes back to before the first, as no one else wrote it in between. Turns
|
|
749
|
+
* follow their trigger messages through the thread, and a retry follows the attempt it replaced.
|
|
750
|
+
*/
|
|
751
|
+
function oldestFirst(
|
|
752
|
+
rewoundRuns: readonly ConversationAgentRunRecord[],
|
|
753
|
+
tail: readonly AgentMessageRecord[]
|
|
754
|
+
): readonly { readonly run: ConversationAgentRunRecord; readonly later: readonly string[] }[] {
|
|
755
|
+
const seqOf = new Map(tail.map((message) => [message.id, message.seq]))
|
|
756
|
+
const started = (run: ConversationAgentRunRecord) => (run.startedAt ?? run.createdAt).getTime()
|
|
757
|
+
const ordered = [...rewoundRuns].sort(
|
|
758
|
+
(left, right) =>
|
|
759
|
+
(seqOf.get(left.triggerMessageId) ?? 0) - (seqOf.get(right.triggerMessageId) ?? 0) ||
|
|
760
|
+
started(left) - started(right) ||
|
|
761
|
+
left.attempt - right.attempt
|
|
762
|
+
)
|
|
763
|
+
|
|
764
|
+
return ordered.map((run, index) => ({
|
|
765
|
+
run,
|
|
766
|
+
later: ordered.slice(index + 1).map((each) => each.id),
|
|
767
|
+
}))
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
async function announceAgentThreadRewind(
|
|
771
|
+
runtime: SixbRuntimeContext,
|
|
772
|
+
rewind: AgentThreadRewind | undefined,
|
|
773
|
+
superseded: readonly AgentApprovalRecord[]
|
|
774
|
+
): Promise<void> {
|
|
775
|
+
await announceArtifactUpdates(runtime.events, rewind?.restoredVersions ?? [])
|
|
776
|
+
await announceAgentApprovals(runtime.broker, [
|
|
777
|
+
...(rewind?.cancelledApprovals ?? []),
|
|
778
|
+
...superseded,
|
|
779
|
+
])
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
function assertEditableMessageAuthority(
|
|
783
|
+
_thread: AgentThreadRecord,
|
|
784
|
+
target: AgentMessageRecord,
|
|
785
|
+
principal: Principal
|
|
786
|
+
): void {
|
|
787
|
+
if (!isEditableAgentMessage(target)) {
|
|
788
|
+
throw new AgentRequestError(
|
|
789
|
+
"message_not_editable",
|
|
790
|
+
`[Sixb] Only user-authored messages can be edited.`
|
|
791
|
+
)
|
|
792
|
+
}
|
|
793
|
+
if (
|
|
794
|
+
principal.type === "user" &&
|
|
795
|
+
(!target.authorPrincipal || !principalsEqual(target.authorPrincipal, principal))
|
|
796
|
+
) {
|
|
797
|
+
throw new AgentRequestError(
|
|
798
|
+
"not_message_author",
|
|
799
|
+
`[Sixb] Only the author of message '${target.id}' can edit it.`
|
|
800
|
+
)
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
|
|
804
|
+
function assertParticipantCanRewindTail(
|
|
805
|
+
thread: AgentThreadRecord,
|
|
806
|
+
tail: readonly AgentMessageRecord[],
|
|
807
|
+
principal: Principal
|
|
808
|
+
): void {
|
|
809
|
+
if (principal.type !== "user" || principalsEqual(principal, thread.ownerPrincipal)) return
|
|
810
|
+
|
|
811
|
+
const erasesOthers = tail.some(
|
|
812
|
+
(message) =>
|
|
813
|
+
message.role === "user" &&
|
|
814
|
+
countsAsThreadMessage(message) &&
|
|
815
|
+
message.authorPrincipal !== undefined &&
|
|
816
|
+
!principalsEqual(message.authorPrincipal, principal)
|
|
817
|
+
)
|
|
818
|
+
if (erasesOthers) {
|
|
819
|
+
throw new AgentRequestError(
|
|
820
|
+
"not_thread_owner",
|
|
821
|
+
"[Sixb] Only the thread's owner can rewind past another person's messages."
|
|
822
|
+
)
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* An edit takes back whole turns: each turn it rewinds answered a message it removes. A message a
|
|
828
|
+
* turn read while it was answering, as a steer, sits inside that turn: rewinding from it would
|
|
829
|
+
* keep the turn's first part in the chat and undo everything the turn did.
|
|
830
|
+
*/
|
|
831
|
+
function assertRewindsWholeTurns(
|
|
832
|
+
target: AgentMessageRecord,
|
|
833
|
+
tail: readonly AgentMessageRecord[],
|
|
834
|
+
rewoundRuns: readonly ConversationAgentRunRecord[]
|
|
835
|
+
): void {
|
|
836
|
+
const removed = new Set(tail.map((message) => message.id))
|
|
837
|
+
const cut = rewoundRuns.find((run) => !removed.has(run.triggerMessageId))
|
|
838
|
+
if (!cut) return
|
|
839
|
+
|
|
840
|
+
throw new AgentRequestError(
|
|
841
|
+
"message_not_editable",
|
|
842
|
+
`[Sixb] Agent message '${target.id}' came in while the Agent was answering message '${cut.triggerMessageId}': edit that message instead.`
|
|
843
|
+
)
|
|
844
|
+
}
|
|
845
|
+
|
|
846
|
+
async function listAllThreadMessagesFromSeq(
|
|
847
|
+
agents: AgentStorage,
|
|
848
|
+
projectId: string,
|
|
849
|
+
threadId: string,
|
|
850
|
+
fromSeq: number
|
|
851
|
+
): Promise<readonly AgentMessageRecord[]> {
|
|
852
|
+
const messages: AgentMessageRecord[] = []
|
|
853
|
+
const afterSeq = fromSeq - 1
|
|
854
|
+
for (;;) {
|
|
855
|
+
const page = await agents.messages.list({
|
|
856
|
+
projectId,
|
|
857
|
+
threadId,
|
|
858
|
+
afterSeq,
|
|
859
|
+
order: "asc",
|
|
860
|
+
limit: 200,
|
|
861
|
+
offset: messages.length,
|
|
862
|
+
})
|
|
863
|
+
messages.push(...page.messages)
|
|
864
|
+
if (!page.hasMore || page.messages.length === 0) return messages
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
/** Conversation runs triggered at or after the rewound message, newest first. */
|
|
869
|
+
async function listRewoundConversationRuns(
|
|
870
|
+
agents: AgentStorage,
|
|
871
|
+
projectId: string,
|
|
872
|
+
threadId: string,
|
|
873
|
+
tail: readonly AgentMessageRecord[]
|
|
874
|
+
): Promise<readonly ConversationAgentRunRecord[]> {
|
|
875
|
+
const removedMessageIds = new Set(tail.map((message) => message.id))
|
|
876
|
+
const removedRunIds = new Set(
|
|
877
|
+
tail.flatMap((message) => (message.runId === null ? [] : [message.runId]))
|
|
878
|
+
)
|
|
879
|
+
const found: ConversationAgentRunRecord[] = []
|
|
880
|
+
for (let offset = 0; ; ) {
|
|
881
|
+
const page = await agents.runs.list({
|
|
882
|
+
projectId,
|
|
883
|
+
threadId,
|
|
884
|
+
kinds: ["conversation"],
|
|
885
|
+
order: "desc",
|
|
886
|
+
limit: 100,
|
|
887
|
+
offset,
|
|
888
|
+
})
|
|
889
|
+
for (const run of page.runs) {
|
|
890
|
+
if (
|
|
891
|
+
run.kind === "conversation" &&
|
|
892
|
+
(removedMessageIds.has(run.triggerMessageId) || removedRunIds.has(run.id))
|
|
893
|
+
) {
|
|
894
|
+
found.push(run)
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
offset += page.runs.length
|
|
898
|
+
if (!page.hasMore || page.runs.length === 0) return found
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
/**
|
|
903
|
+
* The newest turn an edit keeps: its trigger message is still in the thread, before the edited one.
|
|
904
|
+
* Turns the edit rewinds answered a message of `tail`; turns an earlier edit rewound answered a
|
|
905
|
+
* message that is gone.
|
|
906
|
+
*/
|
|
907
|
+
async function latestRetainedConversationRun(
|
|
908
|
+
agents: AgentStorage,
|
|
909
|
+
projectId: string,
|
|
910
|
+
threadId: string,
|
|
911
|
+
tail: readonly AgentMessageRecord[]
|
|
912
|
+
): Promise<ConversationAgentRunRecord | undefined> {
|
|
913
|
+
const notRetained = new Set(tail.map((message) => message.id))
|
|
914
|
+
|
|
915
|
+
for (let offset = 0; ; ) {
|
|
916
|
+
const page = await agents.runs.list({
|
|
917
|
+
projectId,
|
|
918
|
+
threadId,
|
|
919
|
+
kinds: ["conversation"],
|
|
920
|
+
order: "desc",
|
|
921
|
+
limit: 50,
|
|
922
|
+
offset,
|
|
923
|
+
})
|
|
924
|
+
|
|
925
|
+
for (const run of page.runs) {
|
|
926
|
+
if (run.kind !== "conversation" || notRetained.has(run.triggerMessageId)) continue
|
|
927
|
+
if (await agents.messages.getById({ projectId, id: run.triggerMessageId })) return run
|
|
928
|
+
notRetained.add(run.triggerMessageId)
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
offset += page.runs.length
|
|
932
|
+
if (!page.hasMore || page.runs.length === 0) return undefined
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
304
936
|
/** A failed turn, or one its worker died during, can run again from the same trigger message. */
|
|
305
937
|
export function isRetryableAgentRun(
|
|
306
938
|
run: Pick<ConversationAgentRunRecord, "status" | "finishReason">
|
|
@@ -322,7 +954,7 @@ export async function retryAgentRun(
|
|
|
322
954
|
*/
|
|
323
955
|
blobStorage?: Pick<BlobStorage, "open" | "put">
|
|
324
956
|
): Promise<RequestAgentRunResult> {
|
|
325
|
-
resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
957
|
+
const authority = resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
326
958
|
execution,
|
|
327
959
|
authorization: runtime.runtimeAuthorization,
|
|
328
960
|
})
|
|
@@ -347,6 +979,16 @@ export async function retryAgentRun(
|
|
|
347
979
|
)
|
|
348
980
|
}
|
|
349
981
|
assertSandboxExecutionAvailable(thread)
|
|
982
|
+
if (
|
|
983
|
+
authority.type === "principal" &&
|
|
984
|
+
thread.runsOn === "computer" &&
|
|
985
|
+
!principalsEqual(authority.context.principal, thread.ownerPrincipal)
|
|
986
|
+
) {
|
|
987
|
+
throw new AgentRequestError(
|
|
988
|
+
"not_thread_owner",
|
|
989
|
+
`[Sixb] Agent thread '${thread.id}' runs on its owner's computer, as them: only its owner can retry a turn in it.`
|
|
990
|
+
)
|
|
991
|
+
}
|
|
350
992
|
const runId = createAgentRunId()
|
|
351
993
|
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId)
|
|
352
994
|
await assertAiLimitPreflight(runtime, durableExecution)
|
|
@@ -449,7 +1091,8 @@ export async function sendAgentMessage(
|
|
|
449
1091
|
runtime: SixbRuntimeContext,
|
|
450
1092
|
execution: ExecutionContext,
|
|
451
1093
|
models: AgentRequestModels,
|
|
452
|
-
input: SendAgentMessageInput
|
|
1094
|
+
input: SendAgentMessageInput,
|
|
1095
|
+
blobStorage?: RewindBlobStorage
|
|
453
1096
|
): Promise<SendAgentMessageResult> {
|
|
454
1097
|
const delivery = input.delivery ?? "auto"
|
|
455
1098
|
const agents = requireAgentStorage(runtime)
|
|
@@ -520,9 +1163,9 @@ export async function sendAgentMessage(
|
|
|
520
1163
|
})
|
|
521
1164
|
|
|
522
1165
|
if (delivery === "send_now") {
|
|
523
|
-
await stopTurnBefore(runtime, execution, active as ConversationAgentRunRecord)
|
|
1166
|
+
await stopTurnBefore(runtime, execution, active as ConversationAgentRunRecord, blobStorage)
|
|
524
1167
|
}
|
|
525
|
-
await startIfThreadIdle(runtime, execution, thread.id)
|
|
1168
|
+
await startIfThreadIdle(runtime, execution, thread.id, blobStorage)
|
|
526
1169
|
return { kind: "inbox", item }
|
|
527
1170
|
}
|
|
528
1171
|
|
|
@@ -551,7 +1194,8 @@ export interface PromoteAgentInboxItemInput {
|
|
|
551
1194
|
export async function promoteAgentInboxItem(
|
|
552
1195
|
runtime: SixbRuntimeContext,
|
|
553
1196
|
execution: ExecutionContext,
|
|
554
|
-
input: PromoteAgentInboxItemInput
|
|
1197
|
+
input: PromoteAgentInboxItemInput,
|
|
1198
|
+
blobStorage?: RewindBlobStorage
|
|
555
1199
|
): Promise<AgentInboxItemRecord> {
|
|
556
1200
|
const agents = requireAgentStorage(runtime)
|
|
557
1201
|
const projectId = runtime.projectId
|
|
@@ -622,9 +1266,9 @@ export async function promoteAgentInboxItem(
|
|
|
622
1266
|
)
|
|
623
1267
|
}
|
|
624
1268
|
if (input.immediate === true && turn) {
|
|
625
|
-
await stopTurnBefore(runtime, execution, turn)
|
|
1269
|
+
await stopTurnBefore(runtime, execution, turn, blobStorage)
|
|
626
1270
|
}
|
|
627
|
-
await startIfThreadIdle(runtime, execution, thread.id)
|
|
1271
|
+
await startIfThreadIdle(runtime, execution, thread.id, blobStorage)
|
|
628
1272
|
return updated
|
|
629
1273
|
}
|
|
630
1274
|
|
|
@@ -698,14 +1342,21 @@ async function askedForTurn(
|
|
|
698
1342
|
async function stopTurnBefore(
|
|
699
1343
|
runtime: SixbRuntimeContext,
|
|
700
1344
|
execution: ExecutionContext,
|
|
701
|
-
active: ConversationAgentRunRecord
|
|
1345
|
+
active: ConversationAgentRunRecord,
|
|
1346
|
+
blobStorage: RewindBlobStorage | undefined
|
|
702
1347
|
): Promise<void> {
|
|
703
1348
|
if (active.status === "running") {
|
|
704
1349
|
await cancelAgentRun(runtime, active)
|
|
705
1350
|
return
|
|
706
1351
|
}
|
|
707
1352
|
await cancelAgentRun(runtime, active).catch(() => undefined)
|
|
708
|
-
await startQueuedAgentTurnFromInbox(
|
|
1353
|
+
await startQueuedAgentTurnFromInbox(
|
|
1354
|
+
runtime,
|
|
1355
|
+
execution,
|
|
1356
|
+
active,
|
|
1357
|
+
{ onlyImmediate: true },
|
|
1358
|
+
blobStorage
|
|
1359
|
+
)
|
|
709
1360
|
}
|
|
710
1361
|
|
|
711
1362
|
/**
|
|
@@ -718,7 +1369,8 @@ async function stopTurnBefore(
|
|
|
718
1369
|
async function startIfThreadIdle(
|
|
719
1370
|
runtime: SixbRuntimeContext,
|
|
720
1371
|
execution: ExecutionContext,
|
|
721
|
-
threadId: string
|
|
1372
|
+
threadId: string,
|
|
1373
|
+
blobStorage: RewindBlobStorage | undefined
|
|
722
1374
|
): Promise<void> {
|
|
723
1375
|
const agents = requireAgentStorage(runtime)
|
|
724
1376
|
const projectId = runtime.projectId
|
|
@@ -740,7 +1392,7 @@ async function startIfThreadIdle(
|
|
|
740
1392
|
// it, setting its held calls aside as a message typed in the chat would.
|
|
741
1393
|
const onlyImmediate =
|
|
742
1394
|
isAwaitingApprovalRun(last) || !(await turnAnsweredEveryMessage(agents, last))
|
|
743
|
-
await startQueuedAgentTurnFromInbox(runtime, execution, last, { onlyImmediate })
|
|
1395
|
+
await startQueuedAgentTurnFromInbox(runtime, execution, last, { onlyImmediate }, blobStorage)
|
|
744
1396
|
} catch (error) {
|
|
745
1397
|
console.error(
|
|
746
1398
|
`[Sixb] Could not start what waits in Agent thread '${threadId}'; the repair pass retries.`,
|
|
@@ -793,7 +1445,8 @@ export async function startQueuedAgentTurnFromInbox(
|
|
|
793
1445
|
runtime: SixbRuntimeContext,
|
|
794
1446
|
execution: ExecutionContext,
|
|
795
1447
|
finishedRun: ConversationAgentRunRecord,
|
|
796
|
-
input: { readonly onlyImmediate: boolean }
|
|
1448
|
+
input: { readonly onlyImmediate: boolean },
|
|
1449
|
+
blobStorage?: RewindBlobStorage
|
|
797
1450
|
): Promise<AgentQueuedTurnStart> {
|
|
798
1451
|
resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
799
1452
|
execution,
|
|
@@ -823,8 +1476,11 @@ export async function startQueuedAgentTurnFromInbox(
|
|
|
823
1476
|
const runId = createAgentRunId()
|
|
824
1477
|
const durableExecution = await prepareResumedExecution(runtime, execution, runId)
|
|
825
1478
|
await assertAiLimitPreflight(runtime, durableExecution)
|
|
1479
|
+
const documents = await waitingEditDocuments(runtime, blobStorage, thread, principal)
|
|
826
1480
|
|
|
827
1481
|
let started: ConversationAgentRunRecord | null
|
|
1482
|
+
let rewind: AgentThreadRewind | undefined
|
|
1483
|
+
let dropped: { readonly item: AgentInboxItemRecord; readonly reason: unknown } | undefined
|
|
828
1484
|
let superseded: readonly AgentApprovalRecord[] = []
|
|
829
1485
|
try {
|
|
830
1486
|
started = await runtime.storage.transaction(async (tx) => {
|
|
@@ -843,6 +1499,24 @@ export async function startQueuedAgentTurnFromInbox(
|
|
|
843
1499
|
})
|
|
844
1500
|
if (!item) return null
|
|
845
1501
|
|
|
1502
|
+
// An edit takes the thread back to the message it replaces first. One the thread moved past
|
|
1503
|
+
// since it was sent (that message is gone) is dropped: the checks write nothing.
|
|
1504
|
+
if (item.replacesMessageId !== undefined) {
|
|
1505
|
+
try {
|
|
1506
|
+
rewind = await rewindAgentThread(tx, agents, {
|
|
1507
|
+
projectId,
|
|
1508
|
+
thread,
|
|
1509
|
+
messageId: item.replacesMessageId,
|
|
1510
|
+
editor: item.authorPrincipal,
|
|
1511
|
+
documents,
|
|
1512
|
+
})
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
if (!(error instanceof AgentRequestError)) throw error
|
|
1515
|
+
dropped = { item, reason: error }
|
|
1516
|
+
return null
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
|
|
846
1520
|
const inherited = await resolveAgentApprovalMode(agents, {
|
|
847
1521
|
projectId,
|
|
848
1522
|
principal,
|
|
@@ -894,14 +1568,49 @@ export async function startQueuedAgentTurnFromInbox(
|
|
|
894
1568
|
}
|
|
895
1569
|
throw error
|
|
896
1570
|
}
|
|
1571
|
+
if (dropped) {
|
|
1572
|
+
console.warn(
|
|
1573
|
+
`[Sixb] Dropped the edit of Agent message '${dropped.item.replacesMessageId}' waiting in thread '${thread.id}': it no longer applies.`,
|
|
1574
|
+
dropped.reason
|
|
1575
|
+
)
|
|
1576
|
+
}
|
|
897
1577
|
if (!started) return { status: "nothing" }
|
|
898
1578
|
|
|
899
|
-
await
|
|
1579
|
+
await announceAgentThreadRewind(runtime, rewind, superseded)
|
|
900
1580
|
await publishRunActivity(runtime, started)
|
|
901
1581
|
await dispatchAgentRun(runtime, agents, runId)
|
|
902
1582
|
return { status: "started", run: started }
|
|
903
1583
|
}
|
|
904
1584
|
|
|
1585
|
+
/**
|
|
1586
|
+
* The restore documents for the edit the caller's next queued message would make, read before
|
|
1587
|
+
* the transaction that starts it, as an edit on an idle thread reads them. Edits are always sent
|
|
1588
|
+
* now, so the caller's oldest message sent now is the one their turn takes first.
|
|
1589
|
+
*/
|
|
1590
|
+
async function waitingEditDocuments(
|
|
1591
|
+
runtime: SixbRuntimeContext,
|
|
1592
|
+
blobStorage: RewindBlobStorage | undefined,
|
|
1593
|
+
thread: AgentThreadRecord,
|
|
1594
|
+
principal: Principal
|
|
1595
|
+
): Promise<ReadonlyMap<string, Record<string, FileRef>>> {
|
|
1596
|
+
if (!runtime.storage.artifacts || !blobStorage) return new Map()
|
|
1597
|
+
|
|
1598
|
+
const agents = requireAgentStorage(runtime)
|
|
1599
|
+
const projectId = runtime.projectId
|
|
1600
|
+
const waiting = await agents.inbox.list({ projectId, threadId: thread.id, includeClaimed: false })
|
|
1601
|
+
const next = waiting
|
|
1602
|
+
.filter((item) => item.immediate && principalsEqual(item.authorPrincipal, principal))
|
|
1603
|
+
.sort((left, right) => left.seq - right.seq)[0]
|
|
1604
|
+
if (next?.replacesMessageId === undefined) return new Map()
|
|
1605
|
+
|
|
1606
|
+
const target = await agents.messages.getById({ projectId, id: next.replacesMessageId })
|
|
1607
|
+
if (!target || target.threadId !== thread.id) return new Map()
|
|
1608
|
+
|
|
1609
|
+
const tail = await listAllThreadMessagesFromSeq(agents, projectId, thread.id, target.seq)
|
|
1610
|
+
const rewoundRuns = await listRewoundConversationRuns(agents, projectId, thread.id, tail)
|
|
1611
|
+
return rewoundTurnDocuments(runtime, blobStorage, rewoundRuns, tail)
|
|
1612
|
+
}
|
|
1613
|
+
|
|
905
1614
|
/** A queued message's turn: the finished turn's spec, with the message's own choices over it. */
|
|
906
1615
|
function queuedConversationRunSpec(
|
|
907
1616
|
thread: AgentThreadRecord,
|
|
@@ -910,7 +1619,10 @@ function queuedConversationRunSpec(
|
|
|
910
1619
|
approvalMode: AgentApprovalMode
|
|
911
1620
|
): ConversationAgentRunSpec {
|
|
912
1621
|
const model = item.spec?.model ?? kept.model
|
|
913
|
-
|
|
1622
|
+
// An edit's choices were made against the turn it continues: the stopped turn it rewinds passes
|
|
1623
|
+
// nothing on.
|
|
1624
|
+
const reasoning =
|
|
1625
|
+
item.spec?.reasoning ?? (item.replacesMessageId === undefined ? kept.reasoning : undefined)
|
|
914
1626
|
const timeZone = item.timeZone ?? kept.timeZone
|
|
915
1627
|
const locale = item.locale ?? kept.locale
|
|
916
1628
|
return inPlace(thread, {
|
|
@@ -1079,8 +1791,8 @@ function inPlace(
|
|
|
1079
1791
|
thread: AgentThreadRecord,
|
|
1080
1792
|
spec: ConversationAgentRunSpec
|
|
1081
1793
|
): ConversationAgentRunSpec {
|
|
1082
|
-
const { runsOn: _runsOn, ...rest } = spec
|
|
1083
|
-
return Object.freeze(
|
|
1794
|
+
const { runsOn: _runsOn, computer: _computer, ...rest } = spec
|
|
1795
|
+
return Object.freeze({ ...rest, ...turnPlace(thread.runsOn, thread.computer) })
|
|
1084
1796
|
}
|
|
1085
1797
|
|
|
1086
1798
|
/** The paused turn's spec, with defaults for a model that has since left the catalog. */
|
|
@@ -1153,18 +1865,16 @@ function routedTurn(
|
|
|
1153
1865
|
|
|
1154
1866
|
/** The spec of a turn Sixb picks the model for, compared to the thread's previous turn. */
|
|
1155
1867
|
async function routedConversationRunSpec(
|
|
1156
|
-
agents: AgentStorage,
|
|
1157
1868
|
input: RoutedTurn & {
|
|
1158
|
-
|
|
1159
|
-
readonly
|
|
1869
|
+
/** The turn this one continues, absent for a thread's first. */
|
|
1870
|
+
readonly previous: ConversationAgentRunRecord | undefined
|
|
1871
|
+
/** Where the turn runs: the previous turn's cache holds its prompt only if it ran there. */
|
|
1872
|
+
readonly place: AgentTurnPlace
|
|
1160
1873
|
readonly settings: RequesterSettings
|
|
1161
1874
|
readonly language: LanguageModelCatalog | undefined
|
|
1162
1875
|
}
|
|
1163
1876
|
): Promise<ConversationAgentRunSpec> {
|
|
1164
|
-
const
|
|
1165
|
-
? await latestConversationRun(agents, input.projectId, input.threadId)
|
|
1166
|
-
: undefined
|
|
1167
|
-
const choice = await input.router.choose(input.text, previous)
|
|
1877
|
+
const choice = await input.router.choose(input.text, input.previous, input.place)
|
|
1168
1878
|
|
|
1169
1879
|
return resolveConversationRunSpec({
|
|
1170
1880
|
models: input.language,
|
|
@@ -1226,6 +1936,18 @@ function assertAttachments(attachments: readonly FileRef[] | undefined): void {
|
|
|
1226
1936
|
}
|
|
1227
1937
|
|
|
1228
1938
|
function assertThreadAcceptsRun(thread: AgentThreadRecord, principal: Principal): void {
|
|
1939
|
+
assertThreadAcceptsMessages(thread, principal)
|
|
1940
|
+
// Fast single-flight check for a clear error. `runs.create` is the atomic authority.
|
|
1941
|
+
if (thread.activeRunId !== null) {
|
|
1942
|
+
throw new AgentRequestError(
|
|
1943
|
+
"active_run_exists",
|
|
1944
|
+
`[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`
|
|
1945
|
+
)
|
|
1946
|
+
}
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
/** Whether `principal` may send the thread a message: a turn may still be running. */
|
|
1950
|
+
function assertThreadAcceptsMessages(thread: AgentThreadRecord, principal: Principal): void {
|
|
1229
1951
|
assertConversationThread(thread)
|
|
1230
1952
|
assertSandboxExecutionAvailable(thread)
|
|
1231
1953
|
// Its owner's computer runs its turns as its owner: nobody else may send it one.
|
|
@@ -1235,17 +1957,14 @@ function assertThreadAcceptsRun(thread: AgentThreadRecord, principal: Principal)
|
|
|
1235
1957
|
`[Sixb] Agent thread '${thread.id}' runs on its owner's computer, as them: only its owner can message it. Shared with you, it is yours to read and follow.`
|
|
1236
1958
|
)
|
|
1237
1959
|
}
|
|
1238
|
-
// Fast single-flight check for a clear error. `runs.create` is the atomic authority.
|
|
1239
|
-
if (thread.activeRunId !== null) {
|
|
1240
|
-
throw new AgentRequestError(
|
|
1241
|
-
"active_run_exists",
|
|
1242
|
-
`[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`
|
|
1243
|
-
)
|
|
1244
|
-
}
|
|
1245
1960
|
}
|
|
1246
1961
|
|
|
1247
1962
|
function assertSandboxExecutionAvailable(thread: AgentThreadRecord): void {
|
|
1248
|
-
if (
|
|
1963
|
+
if (
|
|
1964
|
+
thread.runsOn !== "computer" &&
|
|
1965
|
+
thread.sandboxState &&
|
|
1966
|
+
!["new", "ready"].includes(thread.sandboxState.status)
|
|
1967
|
+
) {
|
|
1249
1968
|
throw new AgentRequestError(
|
|
1250
1969
|
"sandbox_execution_unavailable",
|
|
1251
1970
|
"[Sixb] Sandbox recovery is required before another run. Reload the thread, then resume its previous sandbox or recreate it to start fresh."
|