@sixb/core 0.2.4 → 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 +41 -40
- 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 +50 -3
- package/dist/agents/execution.d.ts.map +1 -1
- package/dist/agents/ids.d.ts +2 -0
- package/dist/agents/ids.d.ts.map +1 -1
- package/dist/agents/index.d.ts +7 -5
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +74 -50
- 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/queued-turn.d.ts +16 -0
- package/dist/agents/queued-turn.d.ts.map +1 -0
- package/dist/agents/request.d.ts +120 -1
- package/dist/agents/request.d.ts.map +1 -1
- package/dist/agents/run-after-finish.d.ts +10 -0
- package/dist/agents/run-after-finish.d.ts.map +1 -1
- package/dist/agents/run-artifacts.d.ts +0 -38
- package/dist/agents/run-artifacts.d.ts.map +1 -1
- package/dist/agents/run-events.d.ts +10 -1
- 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-session-http.d.ts.map +1 -1
- package/dist/agents/run-session-serve.d.ts.map +1 -1
- package/dist/agents/run-session.d.ts +14 -1
- package/dist/agents/run-session.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 +53 -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/agents/turn-answered.d.ts +7 -0
- package/dist/agents/turn-answered.d.ts.map +1 -0
- package/dist/agents/validation.d.ts +1 -1
- package/dist/agents/validation.d.ts.map +1 -1
- package/dist/artifacts/canvas-display.d.ts +3 -5
- package/dist/artifacts/canvas-display.d.ts.map +1 -1
- package/dist/artifacts/comments.d.ts +14 -3
- package/dist/artifacts/comments.d.ts.map +1 -1
- package/dist/artifacts/document-fill.d.ts +18 -0
- package/dist/artifacts/document-fill.d.ts.map +1 -0
- package/dist/artifacts/errors.d.ts +1 -1
- package/dist/artifacts/errors.d.ts.map +1 -1
- package/dist/artifacts/events.d.ts +3 -2
- package/dist/artifacts/events.d.ts.map +1 -1
- package/dist/artifacts/execution.d.ts +40 -4
- package/dist/artifacts/execution.d.ts.map +1 -1
- package/dist/artifacts/frames/assets.d.ts +8 -1
- package/dist/artifacts/frames/assets.d.ts.map +1 -1
- package/dist/artifacts/frames/document-data.d.ts +98 -0
- package/dist/artifacts/frames/document-data.d.ts.map +1 -0
- package/dist/artifacts/frames/entries.d.ts +12 -7
- package/dist/artifacts/frames/entries.d.ts.map +1 -1
- package/dist/artifacts/frames/index.d.ts +2 -1
- package/dist/artifacts/frames/index.d.ts.map +1 -1
- package/dist/artifacts/frames/index.js +22 -13
- package/dist/artifacts/frames/index.js.map +4 -4
- package/dist/artifacts/frames/kit.d.ts +15 -0
- package/dist/artifacts/frames/kit.d.ts.map +1 -1
- package/dist/artifacts/frames/protocol.d.ts +12 -1
- package/dist/artifacts/frames/protocol.d.ts.map +1 -1
- package/dist/artifacts/frames/runtime.d.ts +24 -4
- package/dist/artifacts/frames/runtime.d.ts.map +1 -1
- package/dist/artifacts/index.d.ts +3 -1
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +9 -3
- package/dist/artifacts/index.js.map +3 -3
- package/dist/artifacts/live/blocks.d.ts +62 -0
- package/dist/artifacts/live/blocks.d.ts.map +1 -0
- package/dist/artifacts/live/board.d.ts +6 -0
- package/dist/artifacts/live/board.d.ts.map +1 -1
- package/dist/artifacts/live/document.d.ts +12 -0
- package/dist/artifacts/live/document.d.ts.map +1 -1
- package/dist/artifacts/live/index.d.ts +2 -0
- package/dist/artifacts/live/index.d.ts.map +1 -1
- package/dist/artifacts/live/index.js +148 -44
- package/dist/artifacts/live/index.js.map +3 -3
- package/dist/artifacts/live/page.d.ts +49 -0
- package/dist/artifacts/live/page.d.ts.map +1 -0
- package/dist/artifacts/live/protocol.d.ts +5 -0
- package/dist/artifacts/live/protocol.d.ts.map +1 -1
- package/dist/artifacts/live/server.d.ts +2 -2
- package/dist/artifacts/live/server.d.ts.map +1 -1
- package/dist/artifacts/live/server.js +29 -24
- package/dist/artifacts/live/server.js.map +1 -1
- package/dist/artifacts/live/state.d.ts +4 -1
- package/dist/artifacts/live/state.d.ts.map +1 -1
- package/dist/artifacts/outline.d.ts +16 -0
- package/dist/artifacts/outline.d.ts.map +1 -1
- package/dist/artifacts/paper.d.ts +22 -0
- package/dist/artifacts/paper.d.ts.map +1 -0
- package/dist/artifacts/pdf-job.d.ts +9 -0
- package/dist/artifacts/pdf-job.d.ts.map +1 -0
- package/dist/artifacts/publish/fields.d.ts +25 -0
- package/dist/artifacts/publish/fields.d.ts.map +1 -0
- package/dist/artifacts/publish/index.d.ts +2 -1
- package/dist/artifacts/publish/index.d.ts.map +1 -1
- package/dist/artifacts/publish/index.js +32 -23
- package/dist/artifacts/publish/index.js.map +1 -1
- package/dist/artifacts/publish/merge.d.ts +7 -6
- package/dist/artifacts/publish/merge.d.ts.map +1 -1
- package/dist/artifacts/publish/pdf.d.ts +28 -0
- package/dist/artifacts/publish/pdf.d.ts.map +1 -0
- package/dist/artifacts/publish/previews.d.ts +12 -20
- package/dist/artifacts/publish/previews.d.ts.map +1 -1
- package/dist/artifacts/publish/publish.d.ts.map +1 -1
- package/dist/artifacts/publish/queries.d.ts +6 -1
- package/dist/artifacts/publish/queries.d.ts.map +1 -1
- package/dist/artifacts/publish/query-answers.d.ts +5 -2
- package/dist/artifacts/publish/query-answers.d.ts.map +1 -1
- package/dist/artifacts/publish/validate/document-html.d.ts +24 -0
- package/dist/artifacts/publish/validate/document-html.d.ts.map +1 -0
- package/dist/artifacts/publish/validate/document.d.ts +5 -3
- package/dist/artifacts/publish/validate/document.d.ts.map +1 -1
- package/dist/artifacts/queries.d.ts +16 -2
- package/dist/artifacts/queries.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/event-visibility.d.ts.map +1 -1
- package/dist/authorization/index.js +2 -2
- package/dist/blob-storage/index.js +1 -1
- package/dist/bootstrap/index.js +50 -48
- 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-0k3r5kb3.js → chunk-394zjzjs.js} +20 -10
- package/dist/{chunk-0k3r5kb3.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-p8pgnq8d.js → chunk-425ydk65.js} +5 -5
- package/dist/{chunk-p351afzm.js → chunk-5sswe5ej.js} +2 -2
- package/dist/{chunk-a6fjkcne.js → chunk-60662fyv.js} +54 -28
- package/dist/{chunk-a6fjkcne.js.map → chunk-60662fyv.js.map} +7 -6
- package/dist/{chunk-e0hnbb1m.js → chunk-61zptves.js} +1 -1
- 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-gxwy4c3s.js → chunk-7r9mqpva.js} +570 -104
- package/dist/chunk-7r9mqpva.js.map +47 -0
- package/dist/{chunk-3014rfjz.js → chunk-88xeh6zx.js} +28 -8
- package/dist/{chunk-3014rfjz.js.map → chunk-88xeh6zx.js.map} +4 -4
- package/dist/{chunk-9nsjjd44.js → chunk-8tv3qd65.js} +2 -1
- package/dist/chunk-8tv3qd65.js.map +12 -0
- package/dist/chunk-90nqenq8.js +386 -0
- package/dist/chunk-90nqenq8.js.map +14 -0
- package/dist/{chunk-fe6r7yhg.js → chunk-92wrka15.js} +1 -1
- package/dist/{chunk-w1wq7gfr.js → chunk-9c9yknwt.js} +464 -29
- package/dist/{chunk-w1wq7gfr.js.map → chunk-9c9yknwt.js.map} +7 -7
- package/dist/{chunk-q9nkpr8k.js → chunk-9tpmfh3n.js} +1 -1
- package/dist/chunk-9wr3yajk.js.map +2 -2
- package/dist/{chunk-rtm1jq00.js → chunk-ats8y3d9.js} +1202 -246
- package/dist/{chunk-rtm1jq00.js.map → chunk-ats8y3d9.js.map} +16 -14
- package/dist/{chunk-td26wjr5.js → chunk-bcz9dxtf.js} +17 -47
- package/dist/chunk-bcz9dxtf.js.map +12 -0
- package/dist/chunk-bqr703h4.js +1799 -0
- package/dist/chunk-bqr703h4.js.map +13 -0
- package/dist/{chunk-sysnvjce.js → chunk-brhp9d97.js} +2 -2
- package/dist/{chunk-8a8k38tz.js → chunk-brybqw5k.js} +1 -1
- package/dist/{chunk-rsxb14an.js → chunk-bs1sd0e0.js} +12 -8
- package/dist/chunk-bs1sd0e0.js.map +18 -0
- package/dist/{chunk-eptrvnby.js → chunk-c29729me.js} +42 -3
- package/dist/chunk-c29729me.js.map +12 -0
- package/dist/{chunk-855w9nvw.js → chunk-cg7cygfj.js} +1 -1
- package/dist/chunk-dq3t5sr3.js +114 -0
- package/dist/chunk-dq3t5sr3.js.map +11 -0
- package/dist/{chunk-t24yktqr.js → chunk-dvgc56n2.js} +20 -4
- package/dist/{chunk-t24yktqr.js.map → chunk-dvgc56n2.js.map} +5 -5
- package/dist/{chunk-r2psmn42.js → chunk-eg6xqef7.js} +1 -1
- package/dist/{chunk-7kpqntgw.js → chunk-f05994as.js} +1 -1
- package/dist/{chunk-msyevpp3.js → chunk-fmgf9h5e.js} +38 -14
- package/dist/chunk-fmgf9h5e.js.map +22 -0
- package/dist/{chunk-b9qfh2ya.js → chunk-fzbhybya.js} +29 -2
- package/dist/chunk-fzbhybya.js.map +11 -0
- package/dist/{chunk-t0s7b3d1.js → chunk-gaj8djsw.js} +251 -6
- package/dist/chunk-gaj8djsw.js.map +13 -0
- package/dist/{chunk-2bn6813a.js → chunk-grt2j5vp.js} +2 -2
- package/dist/{chunk-s7xqfxs9.js → chunk-hkbks1xm.js} +3 -1
- package/dist/{chunk-s7xqfxs9.js.map → chunk-hkbks1xm.js.map} +3 -3
- package/dist/chunk-hn2r7z41.js.map +1 -1
- package/dist/{chunk-rtdrm592.js → chunk-htdzx40w.js} +2 -2
- package/dist/{chunk-bc3y6gff.js → chunk-jka26v8c.js} +1 -1
- package/dist/{chunk-yy914zfr.js → chunk-jt012fxq.js} +772 -98
- package/dist/chunk-jt012fxq.js.map +34 -0
- package/dist/{chunk-48c1z8nj.js → chunk-kft7mp7z.js} +28 -3
- package/dist/chunk-kft7mp7z.js.map +10 -0
- package/dist/chunk-mbwsgjn7.js +40 -0
- package/dist/chunk-mbwsgjn7.js.map +11 -0
- package/dist/{chunk-wa05txmk.js → chunk-n1hbwc6y.js} +51 -8
- package/dist/chunk-n1hbwc6y.js.map +12 -0
- package/dist/{chunk-n4zzaf6q.js → chunk-nxysqbt0.js} +4 -2
- package/dist/chunk-nxysqbt0.js.map +10 -0
- package/dist/{chunk-6ef4esq4.js → chunk-pqj8vff9.js} +4 -4
- package/dist/chunk-pvpq483h.js.map +2 -2
- package/dist/{chunk-mzx71snp.js → chunk-q7g9cqwt.js} +7 -2
- package/dist/{chunk-mzx71snp.js.map → chunk-q7g9cqwt.js.map} +3 -3
- package/dist/{chunk-n68vz95m.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-rsrc7vtw.js → chunk-s8xxef60.js} +240 -46
- package/dist/chunk-s8xxef60.js.map +50 -0
- package/dist/{chunk-r9rtavg9.js → chunk-t19wjmnc.js} +7 -7
- package/dist/{chunk-vzkxqf8h.js → chunk-tapdssb5.js} +50 -6
- package/dist/chunk-tapdssb5.js.map +23 -0
- package/dist/{chunk-dhkc9b23.js → chunk-v8a1qjzp.js} +1 -1
- package/dist/{chunk-hvbvq7p4.js → chunk-vs2s3p8n.js} +731 -10
- package/dist/chunk-vs2s3p8n.js.map +20 -0
- package/dist/chunk-vtjzwymr.js.map +2 -2
- package/dist/{chunk-8t2ynwg0.js → chunk-wzcjhv54.js} +31 -1
- package/dist/{chunk-8t2ynwg0.js.map → chunk-wzcjhv54.js.map} +3 -3
- package/dist/{chunk-8tqnsx3q.js → chunk-xavet0qs.js} +5 -3
- package/dist/{chunk-8tqnsx3q.js.map → chunk-xavet0qs.js.map} +3 -3
- package/dist/{chunk-8bns0y68.js → chunk-xf76csps.js} +5 -5
- package/dist/{chunk-cwdzcv37.js → chunk-xrmbhap8.js} +2 -2
- package/dist/{chunk-cwdzcv37.js.map → chunk-xrmbhap8.js.map} +2 -2
- package/dist/{chunk-f6ahf5gf.js → chunk-xxfj0rr2.js} +20 -5
- package/dist/chunk-xxfj0rr2.js.map +13 -0
- package/dist/{chunk-3hzhcfsv.js → chunk-y8fwm3z2.js} +2 -2
- package/dist/{chunk-3hzhcfsv.js.map → chunk-y8fwm3z2.js.map} +3 -3
- package/dist/{chunk-smnt672s.js → chunk-ygvay56w.js} +20 -4
- package/dist/chunk-ygvay56w.js.map +10 -0
- package/dist/{chunk-evj5jxz3.js → chunk-ykchk644.js} +63 -15
- package/dist/{chunk-evj5jxz3.js.map → chunk-ykchk644.js.map} +7 -7
- package/dist/{chunk-vepea5c3.js → chunk-ym1bqd98.js} +6 -6
- package/dist/{chunk-yv8hv4wq.js → chunk-z4jqb44a.js} +3 -1
- package/dist/chunk-z4jqb44a.js.map +10 -0
- package/dist/connectors/connection-handles.d.ts +9 -0
- package/dist/connectors/connection-handles.d.ts.map +1 -0
- package/dist/connectors/connections/authorizations.d.ts +9 -0
- package/dist/connectors/connections/authorizations.d.ts.map +1 -1
- package/dist/connectors/connections/capability.d.ts +11 -0
- package/dist/connectors/connections/capability.d.ts.map +1 -1
- package/dist/connectors/connections/events.d.ts +17 -0
- package/dist/connectors/connections/events.d.ts.map +1 -0
- 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/runs.d.ts +3 -0
- package/dist/connectors/connections/runs.d.ts.map +1 -1
- package/dist/connectors/connections/service.d.ts +13 -1
- package/dist/connectors/connections/service.d.ts.map +1 -1
- package/dist/connectors/execution.d.ts +14 -2
- package/dist/connectors/execution.d.ts.map +1 -1
- package/dist/connectors/index.d.ts +1 -1
- package/dist/connectors/index.d.ts.map +1 -1
- package/dist/connectors/service.d.ts +5 -1
- package/dist/connectors/service.d.ts.map +1 -1
- package/dist/connectors/types.d.ts +22 -1
- package/dist/connectors/types.d.ts.map +1 -1
- package/dist/datasets/write.js +1 -1
- package/dist/deploy/index.d.ts +1 -1
- package/dist/deploy/index.d.ts.map +1 -1
- package/dist/deploy/internal.js +3 -2
- package/dist/deploy/internal.js.map +3 -3
- package/dist/deploy/services.d.ts.map +1 -1
- package/dist/deploy/types.d.ts +22 -2
- package/dist/deploy/types.d.ts.map +1 -1
- package/dist/events/definitions.d.ts +4 -0
- package/dist/events/definitions.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/index.d.ts +2 -2
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +3 -3
- package/dist/events/outbox-dispatcher.d.ts +7 -0
- package/dist/events/outbox-dispatcher.d.ts.map +1 -1
- package/dist/events/scope.d.ts +1 -0
- package/dist/events/scope.d.ts.map +1 -1
- package/dist/events/scope.js +1 -1
- package/dist/events/selectors/builder.d.ts +9 -1
- package/dist/events/selectors/builder.d.ts.map +1 -1
- package/dist/events/selectors/index.d.ts +2 -2
- package/dist/events/selectors/index.d.ts.map +1 -1
- package/dist/events/selectors/index.js +2 -2
- package/dist/events/selectors/predicate.d.ts.map +1 -1
- package/dist/events/selectors/types.d.ts +18 -3
- package/dist/events/selectors/types.d.ts.map +1 -1
- package/dist/events/types/artifacts.d.ts +7 -1
- package/dist/events/types/artifacts.d.ts.map +1 -1
- package/dist/events/types/connectors.d.ts +32 -0
- package/dist/events/types/connectors.d.ts.map +1 -0
- package/dist/events/types/index.d.ts +3 -1
- package/dist/events/types/index.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 +43 -42
- package/dist/execution/agent.js.map +1 -1
- package/dist/execution/authorization.d.ts +5 -0
- package/dist/execution/authorization.d.ts.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 +41 -40
- 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 +39 -38
- package/dist/execution/request.js.map +3 -3
- package/dist/execution/scopes.d.ts +8 -0
- package/dist/execution/scopes.d.ts.map +1 -1
- package/dist/execution/script.d.ts +7 -0
- package/dist/execution/script.d.ts.map +1 -0
- package/dist/execution/types.d.ts +16 -1
- package/dist/execution/types.d.ts.map +1 -1
- package/dist/http/api-routes.d.ts.map +1 -1
- package/dist/http/index.js +1 -1
- package/dist/index.d.ts +13 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +74 -70
- package/dist/index.js.map +1 -1
- package/dist/lake-storage/index.js +1 -1
- package/dist/lineage/executors.d.ts +1 -1
- package/dist/lineage/executors.d.ts.map +1 -1
- package/dist/maintenance/index.js +2 -2
- package/dist/materialization/event-envelopes.d.ts +3 -3
- package/dist/materialization/event-envelopes.d.ts.map +1 -1
- package/dist/materialization/events.d.ts +6 -0
- package/dist/materialization/events.d.ts.map +1 -1
- package/dist/materialization/index.js +1 -1
- package/dist/materialization/model.d.ts +6 -0
- package/dist/materialization/model.d.ts.map +1 -1
- package/dist/materializer/index.js +24 -23
- package/dist/materializer/index.js.map +1 -1
- package/dist/materializer/projections/replace.d.ts.map +1 -1
- package/dist/materializer/projections/replacement-plan.d.ts +2 -0
- package/dist/materializer/projections/replacement-plan.d.ts.map +1 -1
- package/dist/materializer/shared/normalize.d.ts +1 -0
- package/dist/materializer/shared/normalize.d.ts.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 +22 -21
- 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 +41 -40
- 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 +21 -20
- 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 +27 -26
- package/dist/pipelines/index.js.map +1 -1
- package/dist/projections/builders.d.ts +7 -1
- package/dist/projections/builders.d.ts.map +1 -1
- package/dist/projections/index.d.ts +1 -1
- package/dist/projections/index.d.ts.map +1 -1
- package/dist/projections/internal.js +22 -21
- package/dist/projections/internal.js.map +1 -1
- package/dist/projections/types.d.ts +10 -0
- package/dist/projections/types.d.ts.map +1 -1
- package/dist/projections/validation.d.ts.map +1 -1
- package/dist/queues/in-memory.d.ts +3 -2
- package/dist/queues/in-memory.d.ts.map +1 -1
- package/dist/queues/index.d.ts +1 -1
- package/dist/queues/index.d.ts.map +1 -1
- package/dist/queues/index.js +1 -1
- package/dist/queues/types.d.ts +40 -13
- package/dist/queues/types.d.ts.map +1 -1
- package/dist/runtime/host.d.ts +13 -0
- package/dist/runtime/host.d.ts.map +1 -1
- package/dist/runtime/internal.d.ts +1 -0
- package/dist/runtime/internal.d.ts.map +1 -1
- package/dist/runtime/internal.js +47 -25
- package/dist/runtime/internal.js.map +4 -3
- package/dist/runtime/locale.d.ts +0 -2
- package/dist/runtime/locale.d.ts.map +1 -1
- package/dist/runtime/resolve-definitions.d.ts +1 -1
- package/dist/runtime/resolve-definitions.d.ts.map +1 -1
- package/dist/runtime/script.d.ts +39 -0
- package/dist/runtime/script.d.ts.map +1 -0
- package/dist/runtime/sixb.d.ts +2 -2
- 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/schedules/builders.d.ts.map +1 -1
- package/dist/schedules/index.js +3 -3
- package/dist/schedules/runtime.d.ts.map +1 -1
- package/dist/schedules/validation.d.ts +2 -0
- package/dist/schedules/validation.d.ts.map +1 -1
- package/dist/security/view-conditions.d.ts.map +1 -1
- package/dist/shares/internal.js +19 -18
- package/dist/shares/internal.js.map +2 -2
- package/dist/storage/agents/errors.d.ts +1 -1
- package/dist/storage/agents/errors.d.ts.map +1 -1
- package/dist/storage/agents/in-memory.d.ts +43 -1
- package/dist/storage/agents/in-memory.d.ts.map +1 -1
- package/dist/storage/agents/index.d.ts +2 -2
- package/dist/storage/agents/index.d.ts.map +1 -1
- package/dist/storage/agents/provider.d.ts +54 -11
- package/dist/storage/agents/provider.d.ts.map +1 -1
- package/dist/storage/agents/provider.js +41 -5
- package/dist/storage/agents/provider.js.map +1 -1
- package/dist/storage/agents/types.d.ts +291 -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 +7 -1
- package/dist/storage/artifacts/in-memory.d.ts.map +1 -1
- package/dist/storage/artifacts/index.d.ts +1 -1
- package/dist/storage/artifacts/index.d.ts.map +1 -1
- package/dist/storage/artifacts/record.d.ts +5 -2
- package/dist/storage/artifacts/record.d.ts.map +1 -1
- package/dist/storage/artifacts/types.d.ts +41 -0
- package/dist/storage/artifacts/types.d.ts.map +1 -1
- package/dist/storage/executions/provider.d.ts +3 -3
- package/dist/storage/executions/provider.d.ts.map +1 -1
- package/dist/storage/executions/provider.js +1 -1
- package/dist/storage/executions/types.d.ts +6 -0
- package/dist/storage/executions/types.d.ts.map +1 -1
- package/dist/storage/executions/validation.d.ts.map +1 -1
- package/dist/storage/file-upload-sessions/provider.js +7 -7
- package/dist/storage/index.d.ts +4 -4
- package/dist/storage/index.d.ts.map +1 -1
- package/dist/storage/index.js +30 -25
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/internal.d.ts +1 -1
- package/dist/storage/internal.d.ts.map +1 -1
- package/dist/storage/internal.js +12 -10
- package/dist/storage/internal.js.map +2 -2
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts +2 -0
- package/dist/storage/ontology/in-memory/replacement-plans.d.ts.map +1 -1
- package/dist/storage/ontology/provider.js +1 -1
- package/dist/storage/ontology/replacement-plans.d.ts +8 -0
- package/dist/storage/ontology/replacement-plans.d.ts.map +1 -1
- 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 +28 -27
- 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-execution.d.ts +3 -0
- package/dist/testing/agent-execution.d.ts.map +1 -1
- package/dist/testing/agent-inbox-storage-contract.d.ts +15 -0
- package/dist/testing/agent-inbox-storage-contract.d.ts.map +1 -0
- 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/execution-storage-contract.d.ts.map +1 -1
- package/dist/testing/index.d.ts +1 -0
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js +6589 -4627
- package/dist/testing/index.js.map +13 -12
- package/dist/testing/materializer-storage-contract.d.ts.map +1 -1
- package/dist/testing/queues-contract.d.ts.map +1 -1
- package/dist/testing/run-claim-storage-contract.d.ts.map +1 -1
- package/dist/webhooks/connections.d.ts +3 -4
- package/dist/webhooks/connections.d.ts.map +1 -1
- package/dist/webhooks/index.d.ts +1 -1
- package/dist/webhooks/index.d.ts.map +1 -1
- package/dist/webhooks/internal.js +22 -54
- package/dist/webhooks/internal.js.map +3 -3
- package/dist/webhooks/types.d.ts +2 -11
- package/dist/webhooks/types.d.ts.map +1 -1
- 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/queued-run-dispatch.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 +50 -48
- package/dist/workflows/index.js.map +1 -1
- package/package.json +12 -1
- package/src/actions/validation.ts +3 -1
- package/src/agents/README.md +6 -2
- package/src/agents/children.ts +6 -0
- package/src/agents/errors.ts +3 -0
- package/src/agents/execution.ts +331 -43
- package/src/agents/ids.ts +5 -0
- package/src/agents/index.ts +22 -4
- package/src/agents/model-routing.ts +25 -9
- package/src/agents/queued-turn.ts +46 -0
- package/src/agents/request.ts +1444 -210
- package/src/agents/run-after-finish.ts +259 -2
- package/src/agents/run-artifacts.ts +3 -93
- package/src/agents/run-events.ts +256 -34
- package/src/agents/run-session-children.ts +13 -2
- package/src/agents/run-session-http.ts +9 -2
- package/src/agents/run-session-serve.ts +2 -8
- package/src/agents/run-session.ts +142 -3
- package/src/agents/run-turn.ts +148 -23
- package/src/agents/streams/index.ts +3 -0
- package/src/agents/streams/internal.ts +12 -0
- package/src/agents/streams/protocol.ts +109 -1
- package/src/agents/streams/steps.ts +131 -0
- package/src/agents/thread-access.ts +57 -2
- package/src/agents/turn-answered.ts +31 -0
- package/src/agents/validation.ts +2 -0
- package/src/artifacts/canvas-display.ts +4 -6
- package/src/artifacts/comments.ts +70 -17
- package/src/artifacts/document-fill.ts +103 -0
- package/src/artifacts/errors.ts +2 -0
- package/src/artifacts/events.ts +4 -1
- package/src/artifacts/execution.ts +265 -31
- package/src/artifacts/frames/assets.ts +42 -7
- package/src/artifacts/frames/document-data.ts +353 -0
- package/src/artifacts/frames/entries.ts +22 -16
- package/src/artifacts/frames/grants.ts +2 -2
- package/src/artifacts/frames/index.ts +3 -0
- package/src/artifacts/frames/kit.ts +102 -0
- package/src/artifacts/frames/protocol.ts +12 -1
- package/src/artifacts/frames/runtime.ts +413 -6
- package/src/artifacts/index.ts +3 -0
- package/src/artifacts/live/blocks.ts +889 -0
- package/src/artifacts/live/board.ts +195 -42
- package/src/artifacts/live/document.ts +170 -5
- package/src/artifacts/live/index.ts +7 -0
- package/src/artifacts/live/page.ts +807 -0
- package/src/artifacts/live/protocol.ts +5 -0
- package/src/artifacts/live/server.ts +2 -2
- package/src/artifacts/live/state.ts +9 -4
- package/src/artifacts/outline.ts +17 -0
- package/src/artifacts/paper.ts +173 -0
- package/src/artifacts/pdf-job.ts +11 -0
- package/src/artifacts/publish/fields.ts +177 -0
- package/src/artifacts/publish/index.ts +6 -1
- package/src/artifacts/publish/merge.ts +28 -15
- package/src/artifacts/publish/pdf.ts +82 -0
- package/src/artifacts/publish/previews.ts +24 -34
- package/src/artifacts/publish/publish.ts +26 -3
- package/src/artifacts/publish/queries.ts +20 -4
- package/src/artifacts/publish/query-answers.ts +14 -3
- package/src/artifacts/publish/validate/document-html.ts +245 -0
- package/src/artifacts/publish/validate/document.ts +34 -3
- package/src/artifacts/queries.ts +59 -13
- package/src/artifacts/run-query.ts +5 -2
- package/src/authorization/event-visibility.ts +13 -0
- package/src/calendar.ts +195 -0
- package/src/connectors/connection-handles.ts +71 -0
- package/src/connectors/connections/authorizations.ts +50 -2
- package/src/connectors/connections/capability.ts +40 -0
- package/src/connectors/connections/events.ts +57 -0
- package/src/connectors/connections/internal.ts +3 -0
- package/src/connectors/connections/runs.ts +5 -0
- package/src/connectors/connections/service.ts +93 -6
- package/src/connectors/execution.ts +35 -8
- package/src/connectors/index.ts +3 -0
- package/src/connectors/service.ts +23 -0
- package/src/connectors/types.ts +29 -1
- package/src/deploy/index.ts +1 -0
- package/src/deploy/services.ts +1 -0
- package/src/deploy/types.ts +30 -2
- package/src/events/definitions.ts +14 -0
- package/src/events/execution.ts +51 -4
- package/src/events/index.ts +8 -0
- package/src/events/outbox-dispatcher.ts +12 -2
- package/src/events/scope.ts +3 -0
- package/src/events/selectors/builder.ts +49 -0
- package/src/events/selectors/index.ts +5 -0
- package/src/events/selectors/predicate.ts +2 -0
- package/src/events/selectors/types.ts +30 -1
- package/src/events/types/artifacts.ts +7 -1
- package/src/events/types/connectors.ts +36 -0
- package/src/events/types/index.ts +7 -0
- package/src/events/types/syncs.ts +4 -0
- package/src/execution/authorization.ts +45 -0
- package/src/execution/authorized-object-reader.ts +33 -5
- package/src/execution/durable.ts +2 -0
- package/src/execution/object-reader-ontology.ts +6 -0
- package/src/execution/request.ts +1 -0
- package/src/execution/scopes.ts +24 -0
- package/src/execution/script.ts +27 -0
- package/src/execution/types.ts +7 -1
- package/src/http/api-routes.ts +33 -0
- package/src/index.ts +39 -4
- package/src/lineage/executors.ts +3 -1
- package/src/materialization/event-envelopes.ts +10 -5
- package/src/materialization/events.ts +2 -0
- package/src/materialization/model.ts +6 -0
- package/src/materializer/README.md +10 -0
- package/src/materializer/projections/replace.ts +42 -1
- package/src/materializer/projections/replacement-plan.ts +44 -4
- package/src/materializer/shared/normalize.ts +4 -0
- 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/projections/builders.ts +20 -0
- package/src/projections/index.ts +1 -0
- package/src/projections/registry.ts +1 -0
- package/src/projections/revision.ts +2 -0
- package/src/projections/types.ts +11 -0
- package/src/projections/validation.ts +6 -0
- package/src/queues/in-memory.ts +5 -0
- package/src/queues/index.ts +3 -1
- package/src/queues/types.ts +45 -14
- package/src/runtime/host.ts +125 -11
- package/src/runtime/internal.ts +1 -0
- package/src/runtime/locale.ts +0 -10
- package/src/runtime/resolve-definitions.ts +4 -1
- package/src/runtime/script.ts +62 -0
- package/src/runtime/sixb.ts +15 -5
- package/src/sandboxes/README.md +3 -1
- package/src/sandboxes/auth.ts +32 -4
- package/src/sandboxes/index.ts +15 -1
- package/src/schedules/builders.ts +4 -1
- package/src/schedules/runtime.ts +3 -0
- package/src/schedules/validation.ts +20 -2
- package/src/security/view-conditions.ts +2 -1
- package/src/storage/agents/errors.ts +1 -0
- package/src/storage/agents/in-memory.ts +500 -7
- package/src/storage/agents/index.ts +26 -0
- package/src/storage/agents/provider.ts +454 -15
- package/src/storage/agents/types.ts +315 -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 +52 -6
- package/src/storage/artifacts/index.ts +2 -0
- package/src/storage/artifacts/record.ts +33 -4
- package/src/storage/artifacts/types.ts +44 -0
- package/src/storage/executions/provider.ts +22 -2
- package/src/storage/executions/types.ts +2 -0
- package/src/storage/executions/validation.ts +27 -0
- package/src/storage/index.ts +29 -0
- package/src/storage/internal.ts +1 -0
- package/src/storage/ontology/in-memory/replacement-plans.ts +22 -0
- package/src/storage/ontology/replacement-plans.ts +6 -0
- package/src/storage/operation-scope.ts +2 -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-execution.ts +45 -2
- package/src/testing/agent-inbox-storage-contract.ts +874 -0
- package/src/testing/agent-storage-contract.ts +965 -103
- package/src/testing/ai-cost-storage-contract.ts +80 -0
- package/src/testing/artifact-storage-contract.ts +201 -4
- package/src/testing/execution-storage-contract.ts +31 -0
- package/src/testing/index.ts +5 -0
- package/src/testing/materializer-storage-contract.ts +139 -1
- package/src/testing/queues-contract.ts +22 -0
- package/src/testing/run-claim-storage-contract.ts +116 -0
- package/src/webhooks/connections.ts +9 -50
- package/src/webhooks/index.ts +0 -2
- package/src/webhooks/types.ts +2 -13
- 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/queued-run-dispatch.ts +8 -1
- package/src/workers/worker.ts +67 -7
- package/dist/chunk-3z1vxzcm.js +0 -234
- package/dist/chunk-3z1vxzcm.js.map +0 -12
- package/dist/chunk-48c1z8nj.js.map +0 -10
- package/dist/chunk-58geavnf.js +0 -29
- package/dist/chunk-58geavnf.js.map +0 -10
- package/dist/chunk-5a4a52tq.js.map +0 -10
- package/dist/chunk-9nsjjd44.js.map +0 -12
- package/dist/chunk-b9qfh2ya.js.map +0 -11
- package/dist/chunk-eptrvnby.js.map +0 -12
- package/dist/chunk-f6ahf5gf.js.map +0 -13
- package/dist/chunk-gxwy4c3s.js.map +0 -47
- package/dist/chunk-hvbvq7p4.js.map +0 -18
- package/dist/chunk-m2jerfef.js +0 -474
- package/dist/chunk-m2jerfef.js.map +0 -11
- package/dist/chunk-msyevpp3.js.map +0 -22
- package/dist/chunk-n4zzaf6q.js.map +0 -10
- package/dist/chunk-rsrc7vtw.js.map +0 -49
- package/dist/chunk-rsxb14an.js.map +0 -18
- package/dist/chunk-smnt672s.js.map +0 -10
- package/dist/chunk-t0s7b3d1.js.map +0 -13
- package/dist/chunk-td26wjr5.js.map +0 -13
- package/dist/chunk-vzkxqf8h.js.map +0 -23
- package/dist/chunk-wa05txmk.js.map +0 -11
- package/dist/chunk-yv8hv4wq.js.map +0 -10
- package/dist/chunk-yy914zfr.js.map +0 -30
- package/dist/chunk-zeykm8my.js.map +0 -14
- /package/dist/{chunk-stmxh0hv.js.map → chunk-3neam1y5.js.map} +0 -0
- /package/dist/{chunk-p8pgnq8d.js.map → chunk-425ydk65.js.map} +0 -0
- /package/dist/{chunk-p351afzm.js.map → chunk-5sswe5ej.js.map} +0 -0
- /package/dist/{chunk-e0hnbb1m.js.map → chunk-61zptves.js.map} +0 -0
- /package/dist/{chunk-fe6r7yhg.js.map → chunk-92wrka15.js.map} +0 -0
- /package/dist/{chunk-q9nkpr8k.js.map → chunk-9tpmfh3n.js.map} +0 -0
- /package/dist/{chunk-sysnvjce.js.map → chunk-brhp9d97.js.map} +0 -0
- /package/dist/{chunk-8a8k38tz.js.map → chunk-brybqw5k.js.map} +0 -0
- /package/dist/{chunk-855w9nvw.js.map → chunk-cg7cygfj.js.map} +0 -0
- /package/dist/{chunk-r2psmn42.js.map → chunk-eg6xqef7.js.map} +0 -0
- /package/dist/{chunk-7kpqntgw.js.map → chunk-f05994as.js.map} +0 -0
- /package/dist/{chunk-2bn6813a.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-6ef4esq4.js.map → chunk-pqj8vff9.js.map} +0 -0
- /package/dist/{chunk-n68vz95m.js.map → chunk-qbd282aa.js.map} +0 -0
- /package/dist/{chunk-r9rtavg9.js.map → chunk-t19wjmnc.js.map} +0 -0
- /package/dist/{chunk-dhkc9b23.js.map → chunk-v8a1qjzp.js.map} +0 -0
- /package/dist/{chunk-8bns0y68.js.map → chunk-xf76csps.js.map} +0 -0
- /package/dist/{chunk-vepea5c3.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,11 +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,
|
|
31
|
+
type AgentInboxItemRecord,
|
|
32
|
+
type AgentMessageRecord,
|
|
30
33
|
type AgentStorage,
|
|
31
34
|
AgentStorageError,
|
|
32
35
|
type AgentThreadComputer,
|
|
@@ -34,6 +37,7 @@ import {
|
|
|
34
37
|
type ConversationAgentRunRecord,
|
|
35
38
|
type ConversationAgentRunSpec,
|
|
36
39
|
} from "../storage/agents"
|
|
40
|
+
import { type AgentTurnPlace, countsAsThreadMessage, turnPlace } from "../storage/agents/provider"
|
|
37
41
|
import {
|
|
38
42
|
aiLimitSubjectsFromAttribution,
|
|
39
43
|
aiUsageLimitExceededError,
|
|
@@ -41,7 +45,9 @@ import {
|
|
|
41
45
|
applicableAiLimitPolicyStatuses,
|
|
42
46
|
} from "../storage/ai-limits/enforcement"
|
|
43
47
|
import type { AiLimitPolicyStatus } from "../storage/ai-limits/types"
|
|
48
|
+
import type { PublishedArtifactVersion } from "../storage/artifacts/types"
|
|
44
49
|
import type { ExecutionRecord } from "../storage/executions"
|
|
50
|
+
import type { Storage } from "../storage/types"
|
|
45
51
|
import {
|
|
46
52
|
type AgentTurnReadiness,
|
|
47
53
|
announceAgentApprovals,
|
|
@@ -53,16 +59,23 @@ import {
|
|
|
53
59
|
resolveAgentApprovalMode,
|
|
54
60
|
turnResumeReadiness,
|
|
55
61
|
} from "./approvals"
|
|
62
|
+
import { cancelAgentRun } from "./cancel"
|
|
56
63
|
import type { AgentContextEntryInput } from "./context/entries"
|
|
57
64
|
import { resolveAgentContextParts } from "./context-resolution"
|
|
58
65
|
import { dispatchQueuedAgentRuns } from "./dispatch"
|
|
59
66
|
import { AgentRequestError } from "./errors"
|
|
60
|
-
import {
|
|
67
|
+
import {
|
|
68
|
+
createAgentInboxItemId,
|
|
69
|
+
createAgentMessageId,
|
|
70
|
+
createAgentRunId,
|
|
71
|
+
createAgentThreadId,
|
|
72
|
+
} from "./ids"
|
|
61
73
|
import type { AgentMessagePart } from "./message"
|
|
62
74
|
import type { TurnModelRouter } from "./model-routing"
|
|
63
75
|
import { assertNoAgentSelector } from "./retired-config"
|
|
64
76
|
import { publishAgentRunActivity } from "./streams/protocol"
|
|
65
77
|
import { assertConversationThread } from "./thread-access"
|
|
78
|
+
import { turnAnsweredEveryMessage } from "./turn-answered"
|
|
66
79
|
import { AGENT_REASONING_LEVELS, type AgentReasoning } from "./types"
|
|
67
80
|
|
|
68
81
|
export interface RequestAgentRunInput {
|
|
@@ -113,6 +126,31 @@ export interface RequestAgentRunInput {
|
|
|
113
126
|
readonly principal?: Principal
|
|
114
127
|
}
|
|
115
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
|
+
|
|
116
154
|
/** What a turn's model is chosen from. */
|
|
117
155
|
export interface AgentRequestModels {
|
|
118
156
|
readonly language?: LanguageModelCatalog
|
|
@@ -166,74 +204,1286 @@ export async function requestAgentRun(
|
|
|
166
204
|
routed ?? (await resolveConversationRunSpec({ models: models.language, selection, settings }))
|
|
167
205
|
assertAttachments(input.attachments)
|
|
168
206
|
|
|
169
|
-
// Resolve context before creating a thread: invalid or inaccessible references must not leave an
|
|
170
|
-
// empty conversation behind. The resulting parts are the exact snapshot persisted below.
|
|
171
|
-
const contextParts = await resolveAgentContextParts(runtime, input.context)
|
|
207
|
+
// Resolve context before creating a thread: invalid or inaccessible references must not leave an
|
|
208
|
+
// empty conversation behind. The resulting parts are the exact snapshot persisted below.
|
|
209
|
+
const contextParts = await resolveAgentContextParts(runtime, input.context)
|
|
210
|
+
|
|
211
|
+
const agents = requireAgentStorage(runtime)
|
|
212
|
+
const projectId = runtime.projectId
|
|
213
|
+
// Attribution comes from the exact capability/execution pair, never the optional context cache
|
|
214
|
+
// on the runtime. `input.principal` remains available to unrestricted server integrations that
|
|
215
|
+
// have already authenticated their request.
|
|
216
|
+
const principal =
|
|
217
|
+
authority.type === "principal"
|
|
218
|
+
? authority.context.principal
|
|
219
|
+
: (input.principal ?? SYSTEM_PRINCIPAL)
|
|
220
|
+
const runId = createAgentRunId()
|
|
221
|
+
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId)
|
|
222
|
+
await assertAiLimitPreflight(runtime, durableExecution)
|
|
223
|
+
|
|
224
|
+
const existingThread = input.threadId
|
|
225
|
+
? await agents.threads.getById({ projectId, id: input.threadId })
|
|
226
|
+
: null
|
|
227
|
+
if (existingThread) assertThreadAcceptsRun(existingThread, principal)
|
|
228
|
+
if (input.runsOn !== undefined && input.runsOn !== "computer") {
|
|
229
|
+
throw new AgentRequestError("invalid_message", `[Sixb] 'runsOn' must be "computer" or omitted.`)
|
|
230
|
+
}
|
|
231
|
+
if (!existingThread) assertComputerPlaceRequest(input.runsOn, input.computer)
|
|
232
|
+
const runsOn = existingThread ? existingThread.runsOn : input.runsOn
|
|
233
|
+
// The message's mode, else the sender's in the thread.
|
|
234
|
+
const approvalMode =
|
|
235
|
+
input.approvalMode ??
|
|
236
|
+
(await resolveAgentApprovalMode(agents, { projectId, principal, threadId: existingThread?.id }))
|
|
237
|
+
.approvalMode
|
|
238
|
+
|
|
239
|
+
const place = turnPlace(runsOn, existingThread ? existingThread.computer : input.computer)
|
|
240
|
+
|
|
241
|
+
// Last before anything is written, so a message the checks above refuse never reaches the
|
|
242
|
+
// decision model. Concurrent messages to an idle thread can still each ask before one of them is
|
|
243
|
+
// refused with `active_run_exists` below.
|
|
244
|
+
const selected =
|
|
245
|
+
"router" in requested
|
|
246
|
+
? await routedConversationRunSpec({
|
|
247
|
+
...requested,
|
|
248
|
+
previous: existingThread
|
|
249
|
+
? await latestConversationRun(agents, projectId, existingThread.id)
|
|
250
|
+
: undefined,
|
|
251
|
+
place,
|
|
252
|
+
settings,
|
|
253
|
+
language: models.language,
|
|
254
|
+
})
|
|
255
|
+
: requested
|
|
256
|
+
const spec: ConversationAgentRunSpec = Object.freeze({ ...selected, approvalMode, ...place })
|
|
257
|
+
|
|
258
|
+
const createdThread = existingThread === null
|
|
259
|
+
const thread =
|
|
260
|
+
existingThread ??
|
|
261
|
+
(await createThread(agents, {
|
|
262
|
+
projectId,
|
|
263
|
+
threadId: input.threadId,
|
|
264
|
+
title: input.title,
|
|
265
|
+
principal,
|
|
266
|
+
runsOn,
|
|
267
|
+
...(input.computer === undefined ? {} : { computer: input.computer }),
|
|
268
|
+
}))
|
|
269
|
+
|
|
270
|
+
const triggerMessageId = input.messageId ?? createAgentMessageId()
|
|
271
|
+
let run: ConversationAgentRunRecord
|
|
272
|
+
let superseded: readonly AgentApprovalRecord[] = []
|
|
273
|
+
try {
|
|
274
|
+
run = await runtime.storage.transaction(async (tx) => {
|
|
275
|
+
const agents = tx.agents
|
|
276
|
+
if (!agents) {
|
|
277
|
+
throw new AgentRequestError(
|
|
278
|
+
"storage_unavailable",
|
|
279
|
+
"[Sixb] Agent storage is not configured."
|
|
280
|
+
)
|
|
281
|
+
}
|
|
282
|
+
await tx.executions.create(durableExecution)
|
|
283
|
+
// The model learns, once, how the calls it made earlier ended: the ones still waiting are
|
|
284
|
+
// set aside by this message.
|
|
285
|
+
const reported = createdThread
|
|
286
|
+
? { parts: [], superseded: [] }
|
|
287
|
+
: await reportAgentApprovals(agents, {
|
|
288
|
+
projectId,
|
|
289
|
+
threadId: thread.id,
|
|
290
|
+
messageId: triggerMessageId,
|
|
291
|
+
})
|
|
292
|
+
superseded = reported.superseded
|
|
293
|
+
await agents.messages.append({
|
|
294
|
+
id: triggerMessageId,
|
|
295
|
+
projectId,
|
|
296
|
+
threadId: thread.id,
|
|
297
|
+
runId: null,
|
|
298
|
+
role: "user",
|
|
299
|
+
parts: [
|
|
300
|
+
...reported.parts,
|
|
301
|
+
...contextParts,
|
|
302
|
+
...trigger,
|
|
303
|
+
...(input.attachments ?? []).map((fileRef) => ({ type: "file" as const, fileRef })),
|
|
304
|
+
],
|
|
305
|
+
authorPrincipal: principal,
|
|
306
|
+
})
|
|
307
|
+
return agents.runs.create({
|
|
308
|
+
id: runId,
|
|
309
|
+
projectId,
|
|
310
|
+
executionId: durableExecution.id,
|
|
311
|
+
threadId: thread.id,
|
|
312
|
+
triggerMessageId,
|
|
313
|
+
spec,
|
|
314
|
+
})
|
|
315
|
+
})
|
|
316
|
+
} catch (error) {
|
|
317
|
+
if (error instanceof AgentStorageError && error.code === "active_run_exists") {
|
|
318
|
+
throw new AgentRequestError("active_run_exists", error.message)
|
|
319
|
+
}
|
|
320
|
+
throw error
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
await announceAgentApprovals(runtime.broker, superseded)
|
|
324
|
+
await publishRunActivity(runtime, run)
|
|
325
|
+
const jobId = await dispatchAgentRun(runtime, agents, runId)
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
run,
|
|
329
|
+
...(jobId ? { jobId } : {}),
|
|
330
|
+
createdThread,
|
|
331
|
+
}
|
|
332
|
+
}
|
|
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
|
+
|
|
936
|
+
/** A failed turn, or one its worker died during, can run again from the same trigger message. */
|
|
937
|
+
export function isRetryableAgentRun(
|
|
938
|
+
run: Pick<ConversationAgentRunRecord, "status" | "finishReason">
|
|
939
|
+
): boolean {
|
|
940
|
+
return (
|
|
941
|
+
run.status === "failed" || (run.status === "cancelled" && run.finishReason === "interrupted")
|
|
942
|
+
)
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/** Retry a failed turn as a new child execution while reusing its immutable trigger message. */
|
|
946
|
+
export async function retryAgentRun(
|
|
947
|
+
runtime: SixbRuntimeContext,
|
|
948
|
+
execution: ExecutionContext,
|
|
949
|
+
models: LanguageModelCatalog | undefined,
|
|
950
|
+
failedRun: ConversationAgentRunRecord,
|
|
951
|
+
/**
|
|
952
|
+
* Where a canvas the retry puts back stores its document; without it, the document is left
|
|
953
|
+
* behind, and brought up to the content by whoever loads it next.
|
|
954
|
+
*/
|
|
955
|
+
blobStorage?: Pick<BlobStorage, "open" | "put">
|
|
956
|
+
): Promise<RequestAgentRunResult> {
|
|
957
|
+
const authority = resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
958
|
+
execution,
|
|
959
|
+
authorization: runtime.runtimeAuthorization,
|
|
960
|
+
})
|
|
961
|
+
assertAuthorized(runtime, { kind: "agent.run" })
|
|
962
|
+
assertRequestAuthorityCanRunAgent(runtime)
|
|
963
|
+
if (!isRetryableAgentRun(failedRun)) {
|
|
964
|
+
throw new AgentRequestError(
|
|
965
|
+
"run_not_retryable",
|
|
966
|
+
`[Sixb] Only failed or interrupted Agent runs can be retried.`
|
|
967
|
+
)
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
const agents = requireAgentStorage(runtime)
|
|
971
|
+
const thread = await agents.threads.getById({
|
|
972
|
+
projectId: runtime.projectId,
|
|
973
|
+
id: failedRun.threadId,
|
|
974
|
+
})
|
|
975
|
+
if (!thread) {
|
|
976
|
+
throw new AgentRequestError(
|
|
977
|
+
"thread_not_found",
|
|
978
|
+
`[Sixb] Agent thread '${failedRun.threadId}' was not found.`
|
|
979
|
+
)
|
|
980
|
+
}
|
|
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
|
+
}
|
|
992
|
+
const runId = createAgentRunId()
|
|
993
|
+
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId)
|
|
994
|
+
await assertAiLimitPreflight(runtime, durableExecution)
|
|
995
|
+
|
|
996
|
+
// A canvas put back takes its restore point as a change to its document, made before the undo.
|
|
997
|
+
const artifacts = runtime.storage.artifacts
|
|
998
|
+
const documents =
|
|
999
|
+
artifacts && blobStorage
|
|
1000
|
+
? await undoneTurnDocuments(
|
|
1001
|
+
{ projectId: runtime.projectId, storage: artifacts, blobStorage },
|
|
1002
|
+
failedRun.id
|
|
1003
|
+
)
|
|
1004
|
+
: {}
|
|
1005
|
+
|
|
1006
|
+
const { run, undone } = await runtime.storage.transaction(async (tx) => {
|
|
1007
|
+
const agents = tx.agents
|
|
1008
|
+
if (!agents) {
|
|
1009
|
+
throw new AgentRequestError("storage_unavailable", "[Sixb] Agent storage is not configured.")
|
|
1010
|
+
}
|
|
1011
|
+
await agents.messages.deleteByRunId({
|
|
1012
|
+
projectId: runtime.projectId,
|
|
1013
|
+
threadId: failedRun.threadId,
|
|
1014
|
+
runId: failedRun.id,
|
|
1015
|
+
})
|
|
1016
|
+
// What the failed turn wrote goes with what it said, so the retry starts clean: each artifact
|
|
1017
|
+
// nobody changed since is put back as it was, or deleted when the turn created it and nobody
|
|
1018
|
+
// but its requester commented on it. Its children wrote as the turn.
|
|
1019
|
+
const trigger = await agents.messages.getById({
|
|
1020
|
+
projectId: runtime.projectId,
|
|
1021
|
+
id: failedRun.triggerMessageId,
|
|
1022
|
+
})
|
|
1023
|
+
const requester = trigger?.authorPrincipal
|
|
1024
|
+
|
|
1025
|
+
const undone = await tx.artifacts?.undoTurnWrites({
|
|
1026
|
+
projectId: runtime.projectId,
|
|
1027
|
+
turnRunId: failedRun.id,
|
|
1028
|
+
documents,
|
|
1029
|
+
...(requester ? { requester } : {}),
|
|
1030
|
+
})
|
|
1031
|
+
await tx.executions.create(durableExecution)
|
|
1032
|
+
const run = await agents.runs.create({
|
|
1033
|
+
id: runId,
|
|
1034
|
+
projectId: runtime.projectId,
|
|
1035
|
+
executionId: durableExecution.id,
|
|
1036
|
+
threadId: failedRun.threadId,
|
|
1037
|
+
triggerMessageId: failedRun.triggerMessageId,
|
|
1038
|
+
spec: inPlace(
|
|
1039
|
+
thread,
|
|
1040
|
+
failedRun.spec ??
|
|
1041
|
+
(await resolveConversationRunSpec({ models, selection: {}, settings: {} }))
|
|
1042
|
+
),
|
|
1043
|
+
})
|
|
1044
|
+
return { run, undone }
|
|
1045
|
+
})
|
|
1046
|
+
await announceArtifactUpdates(
|
|
1047
|
+
runtime.events,
|
|
1048
|
+
(undone?.restored ?? []).map(({ version }) => version)
|
|
1049
|
+
)
|
|
1050
|
+
await publishRunActivity(runtime, run)
|
|
1051
|
+
const jobId = await dispatchAgentRun(runtime, agents, runId)
|
|
1052
|
+
return { run, ...(jobId ? { jobId } : {}), createdThread: false }
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/** Where a resume left a paused turn. */
|
|
1056
|
+
export type AgentTurnResume =
|
|
1057
|
+
| { readonly status: "resumed"; readonly run: ConversationAgentRunRecord }
|
|
1058
|
+
| { readonly status: Exclude<AgentTurnReadiness, "ready"> }
|
|
1059
|
+
|
|
1060
|
+
/** How a message sent to a thread is delivered while a turn runs. */
|
|
1061
|
+
export const AGENT_MESSAGE_DELIVERIES = ["auto", "steer", "queue", "send_now"] as const
|
|
1062
|
+
export type AgentMessageDelivery = (typeof AGENT_MESSAGE_DELIVERIES)[number]
|
|
1063
|
+
|
|
1064
|
+
export interface SendAgentMessageInput
|
|
1065
|
+
extends Omit<RequestAgentRunInput, "principal" | "continue"> {
|
|
1066
|
+
readonly threadId: string
|
|
1067
|
+
/**
|
|
1068
|
+
* `auto` (the default) starts a turn, and refuses while another one runs. `steer` reaches the
|
|
1069
|
+
* running turn at its next step. `queue` starts a turn once the running one ends. `send_now` stops
|
|
1070
|
+
* the running turn and starts this message after it.
|
|
1071
|
+
*/
|
|
1072
|
+
readonly delivery?: AgentMessageDelivery
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/** What a message became: the turn it started, or the inbox item that waits for one. */
|
|
1076
|
+
export type SendAgentMessageResult =
|
|
1077
|
+
| {
|
|
1078
|
+
readonly kind: "turn"
|
|
1079
|
+
readonly run: ConversationAgentRunRecord
|
|
1080
|
+
readonly createdThread: boolean
|
|
1081
|
+
}
|
|
1082
|
+
| { readonly kind: "inbox"; readonly item: AgentInboxItemRecord }
|
|
1083
|
+
|
|
1084
|
+
/**
|
|
1085
|
+
* Send a message to a conversation, delivered as asked.
|
|
1086
|
+
*
|
|
1087
|
+
* A steer or a send-now reaches only the turn its requester asked for: it runs as them. Any reader
|
|
1088
|
+
* may queue a message, which starts as a turn of their own.
|
|
1089
|
+
*/
|
|
1090
|
+
export async function sendAgentMessage(
|
|
1091
|
+
runtime: SixbRuntimeContext,
|
|
1092
|
+
execution: ExecutionContext,
|
|
1093
|
+
models: AgentRequestModels,
|
|
1094
|
+
input: SendAgentMessageInput,
|
|
1095
|
+
blobStorage?: RewindBlobStorage
|
|
1096
|
+
): Promise<SendAgentMessageResult> {
|
|
1097
|
+
const delivery = input.delivery ?? "auto"
|
|
1098
|
+
const agents = requireAgentStorage(runtime)
|
|
1099
|
+
const projectId = runtime.projectId
|
|
1100
|
+
const thread = await agents.threads.getById({ projectId, id: input.threadId })
|
|
1101
|
+
if (!thread) {
|
|
1102
|
+
throw new AgentRequestError(
|
|
1103
|
+
"thread_not_found",
|
|
1104
|
+
`[Sixb] Agent thread '${input.threadId}' was not found.`
|
|
1105
|
+
)
|
|
1106
|
+
}
|
|
1107
|
+
assertConversationThread(thread)
|
|
1108
|
+
|
|
1109
|
+
const startTurn = async (): Promise<SendAgentMessageResult> => {
|
|
1110
|
+
const { delivery: _delivery, ...request } = input
|
|
1111
|
+
const result = await requestAgentRun(runtime, execution, models, request)
|
|
1112
|
+
return { kind: "turn", run: result.run, createdThread: result.createdThread }
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
// Nothing runs, so there is nothing to steer or wait behind.
|
|
1116
|
+
const activeId = thread.activeRunId
|
|
1117
|
+
if (delivery === "auto" || activeId === null) return startTurn()
|
|
1118
|
+
|
|
1119
|
+
const active = await agents.runs.getById({ projectId, id: activeId })
|
|
1120
|
+
const requester = active
|
|
1121
|
+
? (await runtime.storage.executions.getById({ projectId, id: active.executionId }))?.requestedBy
|
|
1122
|
+
: undefined
|
|
1123
|
+
const principal = messageAuthor(runtime, execution)
|
|
1124
|
+
const requesterOfTurn = requester !== undefined && principalsEqual(requester, principal)
|
|
1125
|
+
|
|
1126
|
+
if (!requesterOfTurn && delivery !== "queue") {
|
|
1127
|
+
throw new AgentRequestError(
|
|
1128
|
+
"not_run_requester",
|
|
1129
|
+
`[Sixb] Agent thread '${thread.id}' runs a turn someone else asked for: only they can steer it or send now. Queue the message for your own turn.`
|
|
1130
|
+
)
|
|
1131
|
+
}
|
|
1132
|
+
|
|
1133
|
+
const settings = requesterSettings(input)
|
|
1134
|
+
const contextParts = await resolveAgentContextParts(runtime, input.context)
|
|
1135
|
+
const trigger = deliveredParts(input, delivery)
|
|
1136
|
+
const spec = {
|
|
1137
|
+
...(input.model === undefined ? {} : { model: input.model }),
|
|
1138
|
+
...(input.reasoning === undefined ? {} : { reasoning: input.reasoning }),
|
|
1139
|
+
...(input.approvalMode === undefined ? {} : { approvalMode: input.approvalMode }),
|
|
1140
|
+
}
|
|
1141
|
+
// The request that sends it is recorded with it: a turn that starts it once this request is gone
|
|
1142
|
+
// runs as that request's child, as a turn this request started would have.
|
|
1143
|
+
assertRequestAuthorityCanRunAgent(runtime)
|
|
1144
|
+
const request = await ensureExecutionRecord(
|
|
1145
|
+
runtime.storage.executions,
|
|
1146
|
+
executionRecordInputFromRuntime({
|
|
1147
|
+
execution,
|
|
1148
|
+
runtimeAuthorization: runtime.runtimeAuthorization,
|
|
1149
|
+
})
|
|
1150
|
+
)
|
|
1151
|
+
const { item } = await agents.inbox.enqueue({
|
|
1152
|
+
id: createAgentInboxItemId(),
|
|
1153
|
+
projectId,
|
|
1154
|
+
threadId: thread.id,
|
|
1155
|
+
messageId: input.messageId ?? createAgentMessageId(),
|
|
1156
|
+
authorPrincipal: principal,
|
|
1157
|
+
mode: delivery === "steer" ? "steer" : "queue",
|
|
1158
|
+
parts: [...contextParts, ...trigger],
|
|
1159
|
+
...(Object.keys(spec).length === 0 ? {} : { spec }),
|
|
1160
|
+
...settings,
|
|
1161
|
+
...(delivery === "send_now" ? { immediate: true } : {}),
|
|
1162
|
+
executionId: request.id,
|
|
1163
|
+
})
|
|
1164
|
+
|
|
1165
|
+
if (delivery === "send_now") {
|
|
1166
|
+
await stopTurnBefore(runtime, execution, active as ConversationAgentRunRecord, blobStorage)
|
|
1167
|
+
}
|
|
1168
|
+
await startIfThreadIdle(runtime, execution, thread.id, blobStorage)
|
|
1169
|
+
return { kind: "inbox", item }
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
/** What a message the caller sent may become once it waits in a thread's inbox. */
|
|
1173
|
+
export interface PromoteAgentInboxItemInput {
|
|
1174
|
+
readonly threadId: string
|
|
1175
|
+
readonly itemId: string
|
|
1176
|
+
/** Edit what it says; its context and files stay as they are. */
|
|
1177
|
+
readonly text?: string
|
|
1178
|
+
readonly model?: LanguageModelRef
|
|
1179
|
+
readonly reasoning?: AgentReasoning
|
|
1180
|
+
readonly approvalMode?: AgentApprovalMode
|
|
1181
|
+
/** Steer the running turn with it, or keep it for the next turn. */
|
|
1182
|
+
readonly delivery?: "steer" | "queue"
|
|
1183
|
+
/** Stop the turn it waits behind, and start it now. */
|
|
1184
|
+
readonly immediate?: boolean
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
/**
|
|
1188
|
+
* Change a message waiting in a thread's inbox, before a turn reads it: what it says, the model it
|
|
1189
|
+
* asks for, where it goes, or that it goes now.
|
|
1190
|
+
*
|
|
1191
|
+
* Only the person who sent it may change it, and a message that steers or goes now reaches only the
|
|
1192
|
+
* turn its own requester asked for.
|
|
1193
|
+
*/
|
|
1194
|
+
export async function promoteAgentInboxItem(
|
|
1195
|
+
runtime: SixbRuntimeContext,
|
|
1196
|
+
execution: ExecutionContext,
|
|
1197
|
+
input: PromoteAgentInboxItemInput,
|
|
1198
|
+
blobStorage?: RewindBlobStorage
|
|
1199
|
+
): Promise<AgentInboxItemRecord> {
|
|
1200
|
+
const agents = requireAgentStorage(runtime)
|
|
1201
|
+
const projectId = runtime.projectId
|
|
1202
|
+
const thread = await agents.threads.getById({ projectId, id: input.threadId })
|
|
1203
|
+
if (!thread) {
|
|
1204
|
+
throw new AgentRequestError(
|
|
1205
|
+
"thread_not_found",
|
|
1206
|
+
`[Sixb] Agent thread '${input.threadId}' was not found.`
|
|
1207
|
+
)
|
|
1208
|
+
}
|
|
1209
|
+
assertConversationThread(thread)
|
|
1210
|
+
|
|
1211
|
+
const item = await agents.inbox.getById({ projectId, id: input.itemId })
|
|
1212
|
+
if (!item || item.threadId !== thread.id) {
|
|
1213
|
+
throw new AgentRequestError(
|
|
1214
|
+
"invalid_message",
|
|
1215
|
+
`[Sixb] Agent inbox item '${input.itemId}' is not waiting in thread '${thread.id}'.`
|
|
1216
|
+
)
|
|
1217
|
+
}
|
|
1218
|
+
const principal = messageAuthor(runtime, execution)
|
|
1219
|
+
if (!principalsEqual(item.authorPrincipal, principal)) {
|
|
1220
|
+
throw new AgentRequestError(
|
|
1221
|
+
"not_run_requester",
|
|
1222
|
+
`[Sixb] Agent inbox item '${item.id}' was sent by someone else: only they can change it.`
|
|
1223
|
+
)
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
const active = thread.activeRunId
|
|
1227
|
+
? await agents.runs.getById({ projectId, id: thread.activeRunId })
|
|
1228
|
+
: null
|
|
1229
|
+
const delivery = input.delivery ?? item.mode
|
|
1230
|
+
const turn = active?.kind === "conversation" ? active : null
|
|
1231
|
+
if ((delivery === "steer" || input.immediate === true) && turn) {
|
|
1232
|
+
if (!(await askedForTurn(runtime, turn, principal))) {
|
|
1233
|
+
throw new AgentRequestError(
|
|
1234
|
+
"not_run_requester",
|
|
1235
|
+
`[Sixb] Agent thread '${thread.id}' runs a turn someone else asked for: only they can steer it or send now. Keep the message queued for your own turn.`
|
|
1236
|
+
)
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
const spec = {
|
|
1241
|
+
...(input.model === undefined ? {} : { model: input.model }),
|
|
1242
|
+
...(input.reasoning === undefined ? {} : { reasoning: input.reasoning }),
|
|
1243
|
+
...(input.approvalMode === undefined ? {} : { approvalMode: input.approvalMode }),
|
|
1244
|
+
}
|
|
1245
|
+
const updated = await agents.inbox.update({
|
|
1246
|
+
projectId,
|
|
1247
|
+
threadId: thread.id,
|
|
1248
|
+
id: item.id,
|
|
1249
|
+
...(input.delivery === undefined ? {} : { mode: input.delivery }),
|
|
1250
|
+
...(input.text === undefined
|
|
1251
|
+
? {}
|
|
1252
|
+
: {
|
|
1253
|
+
parts: [
|
|
1254
|
+
{ type: "text" as const, text: input.text },
|
|
1255
|
+
...item.parts.filter((part) => part.type !== "text"),
|
|
1256
|
+
],
|
|
1257
|
+
}),
|
|
1258
|
+
// What it does not name stays as it asked: a new reasoning keeps its model.
|
|
1259
|
+
...(Object.keys(spec).length === 0 ? {} : { spec: { ...item.spec, ...spec } }),
|
|
1260
|
+
...(input.immediate === true ? { immediate: true } : {}),
|
|
1261
|
+
})
|
|
1262
|
+
if (!updated) {
|
|
1263
|
+
throw new AgentRequestError(
|
|
1264
|
+
"invalid_message",
|
|
1265
|
+
`[Sixb] Agent inbox item '${item.id}' is no longer waiting in thread '${thread.id}'.`
|
|
1266
|
+
)
|
|
1267
|
+
}
|
|
1268
|
+
if (input.immediate === true && turn) {
|
|
1269
|
+
await stopTurnBefore(runtime, execution, turn, blobStorage)
|
|
1270
|
+
}
|
|
1271
|
+
await startIfThreadIdle(runtime, execution, thread.id, blobStorage)
|
|
1272
|
+
return updated
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
/**
|
|
1276
|
+
* Take back a message waiting in a thread's inbox, before a turn reads it. Only the person who sent
|
|
1277
|
+
* it may withdraw it.
|
|
1278
|
+
*/
|
|
1279
|
+
export async function withdrawAgentInboxItem(
|
|
1280
|
+
runtime: SixbRuntimeContext,
|
|
1281
|
+
execution: ExecutionContext,
|
|
1282
|
+
input: { readonly threadId: string; readonly itemId: string }
|
|
1283
|
+
): Promise<void> {
|
|
1284
|
+
const agents = requireAgentStorage(runtime)
|
|
1285
|
+
const projectId = runtime.projectId
|
|
1286
|
+
const thread = await agents.threads.getById({ projectId, id: input.threadId })
|
|
1287
|
+
if (!thread) {
|
|
1288
|
+
throw new AgentRequestError(
|
|
1289
|
+
"thread_not_found",
|
|
1290
|
+
`[Sixb] Agent thread '${input.threadId}' was not found.`
|
|
1291
|
+
)
|
|
1292
|
+
}
|
|
1293
|
+
assertConversationThread(thread)
|
|
1294
|
+
const item = await agents.inbox.getById({ projectId, id: input.itemId })
|
|
1295
|
+
if (!item || item.threadId !== thread.id) {
|
|
1296
|
+
throw new AgentRequestError(
|
|
1297
|
+
"invalid_message",
|
|
1298
|
+
`[Sixb] Agent inbox item '${input.itemId}' is not waiting in thread '${thread.id}'.`
|
|
1299
|
+
)
|
|
1300
|
+
}
|
|
1301
|
+
if (!principalsEqual(item.authorPrincipal, messageAuthor(runtime, execution))) {
|
|
1302
|
+
throw new AgentRequestError(
|
|
1303
|
+
"not_run_requester",
|
|
1304
|
+
`[Sixb] Agent inbox item '${item.id}' was sent by someone else: only they can withdraw it.`
|
|
1305
|
+
)
|
|
1306
|
+
}
|
|
1307
|
+
const removed = await agents.inbox.remove({ projectId, threadId: thread.id, id: item.id })
|
|
1308
|
+
if (!removed) {
|
|
1309
|
+
throw new AgentRequestError(
|
|
1310
|
+
"invalid_message",
|
|
1311
|
+
`[Sixb] Agent inbox item '${item.id}' is no longer waiting in thread '${thread.id}': a turn read it.`
|
|
1312
|
+
)
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
|
|
1316
|
+
/** The person a message this request sends is from. */
|
|
1317
|
+
function messageAuthor(runtime: SixbRuntimeContext, execution: ExecutionContext): Principal {
|
|
1318
|
+
const authority = resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
1319
|
+
execution,
|
|
1320
|
+
authorization: runtime.runtimeAuthorization,
|
|
1321
|
+
})
|
|
1322
|
+
return authority.type === "principal" ? authority.context.principal : SYSTEM_PRINCIPAL
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
/** Whether the person asked for this turn, which alone may steer it or send now. */
|
|
1326
|
+
async function askedForTurn(
|
|
1327
|
+
runtime: SixbRuntimeContext,
|
|
1328
|
+
run: ConversationAgentRunRecord,
|
|
1329
|
+
principal: Principal
|
|
1330
|
+
): Promise<boolean> {
|
|
1331
|
+
const requester = (
|
|
1332
|
+
await runtime.storage.executions.getById({ projectId: runtime.projectId, id: run.executionId })
|
|
1333
|
+
)?.requestedBy
|
|
1334
|
+
return requester !== undefined && principalsEqual(requester, principal)
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
/**
|
|
1338
|
+
* Stop the turn a message waits behind, so the message starts now. A turn still running ends first,
|
|
1339
|
+
* and its end starts the message (see afterAgentRunFinished); one that never started has no end to
|
|
1340
|
+
* wait for, so it starts here.
|
|
1341
|
+
*/
|
|
1342
|
+
async function stopTurnBefore(
|
|
1343
|
+
runtime: SixbRuntimeContext,
|
|
1344
|
+
execution: ExecutionContext,
|
|
1345
|
+
active: ConversationAgentRunRecord,
|
|
1346
|
+
blobStorage: RewindBlobStorage | undefined
|
|
1347
|
+
): Promise<void> {
|
|
1348
|
+
if (active.status === "running") {
|
|
1349
|
+
await cancelAgentRun(runtime, active)
|
|
1350
|
+
return
|
|
1351
|
+
}
|
|
1352
|
+
await cancelAgentRun(runtime, active).catch(() => undefined)
|
|
1353
|
+
await startQueuedAgentTurnFromInbox(
|
|
1354
|
+
runtime,
|
|
1355
|
+
execution,
|
|
1356
|
+
active,
|
|
1357
|
+
{ onlyImmediate: true },
|
|
1358
|
+
blobStorage
|
|
1359
|
+
)
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
/**
|
|
1363
|
+
* Start what the caller left waiting once no turn holds the thread: the turn it waited behind ended
|
|
1364
|
+
* before the message reached the inbox, or before a stop reached it, so that end read none of it,
|
|
1365
|
+
* or it was someone else's, whose end starts their own messages first. It starts the caller's own
|
|
1366
|
+
* turn, as them, by the rules a turn's end applies. A failure leaves the message waiting for the
|
|
1367
|
+
* repair pass.
|
|
1368
|
+
*/
|
|
1369
|
+
async function startIfThreadIdle(
|
|
1370
|
+
runtime: SixbRuntimeContext,
|
|
1371
|
+
execution: ExecutionContext,
|
|
1372
|
+
threadId: string,
|
|
1373
|
+
blobStorage: RewindBlobStorage | undefined
|
|
1374
|
+
): Promise<void> {
|
|
1375
|
+
const agents = requireAgentStorage(runtime)
|
|
1376
|
+
const projectId = runtime.projectId
|
|
1377
|
+
try {
|
|
1378
|
+
const thread = await agents.threads.getById({ projectId, id: threadId })
|
|
1379
|
+
// A turn holds it: that turn's end starts the message.
|
|
1380
|
+
if (!thread || thread.activeRunId !== null) return
|
|
1381
|
+
const {
|
|
1382
|
+
runs: [last],
|
|
1383
|
+
} = await agents.runs.list({
|
|
1384
|
+
projectId,
|
|
1385
|
+
threadId,
|
|
1386
|
+
kinds: ["conversation"],
|
|
1387
|
+
order: "desc",
|
|
1388
|
+
limit: 1,
|
|
1389
|
+
})
|
|
1390
|
+
if (last?.kind !== "conversation") return
|
|
1391
|
+
// A paused turn resumes first, and its end starts what waits: only a message sent now passes
|
|
1392
|
+
// it, setting its held calls aside as a message typed in the chat would.
|
|
1393
|
+
const onlyImmediate =
|
|
1394
|
+
isAwaitingApprovalRun(last) || !(await turnAnsweredEveryMessage(agents, last))
|
|
1395
|
+
await startQueuedAgentTurnFromInbox(runtime, execution, last, { onlyImmediate }, blobStorage)
|
|
1396
|
+
} catch (error) {
|
|
1397
|
+
console.error(
|
|
1398
|
+
`[Sixb] Could not start what waits in Agent thread '${threadId}'; the repair pass retries.`,
|
|
1399
|
+
error
|
|
1400
|
+
)
|
|
1401
|
+
}
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
/** The parts a message of its own carries: what it says, then the files it brings. */
|
|
1405
|
+
function deliveredParts(
|
|
1406
|
+
input: Pick<SendAgentMessageInput, "text" | "attachments">,
|
|
1407
|
+
delivery: AgentMessageDelivery
|
|
1408
|
+
): readonly AgentMessagePart[] {
|
|
1409
|
+
if (delivery === "steer" && (input.attachments?.length ?? 0) > 0) {
|
|
1410
|
+
throw new AgentRequestError(
|
|
1411
|
+
"invalid_attachment",
|
|
1412
|
+
"[Sixb] A message that steers a running turn carries no file: queue it for the next turn instead."
|
|
1413
|
+
)
|
|
1414
|
+
}
|
|
1415
|
+
assertAttachments(input.attachments)
|
|
1416
|
+
const text =
|
|
1417
|
+
typeof input.text === "string" && input.text.trim().length > 0
|
|
1418
|
+
? [{ type: "text" as const, text: input.text }]
|
|
1419
|
+
: []
|
|
1420
|
+
const files = (input.attachments ?? []).map((fileRef) => ({ type: "file" as const, fileRef }))
|
|
1421
|
+
if (text.length === 0 && files.length === 0) {
|
|
1422
|
+
throw new AgentRequestError(
|
|
1423
|
+
"invalid_message",
|
|
1424
|
+
"[Sixb] An Agent message needs text or attachments."
|
|
1425
|
+
)
|
|
1426
|
+
}
|
|
1427
|
+
return [...text, ...files]
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
/** Where a queued turn started from: the thread moved on, nothing waited, or it started. */
|
|
1431
|
+
export type AgentQueuedTurnStart =
|
|
1432
|
+
| { readonly status: "started"; readonly run: ConversationAgentRunRecord }
|
|
1433
|
+
| { readonly status: "nothing" }
|
|
1434
|
+
| { readonly status: "closed" }
|
|
172
1435
|
|
|
1436
|
+
/**
|
|
1437
|
+
* Start the next message the execution's requester queued for this thread, as them, from
|
|
1438
|
+
* `finishedRun`: a turn of the thread, whose model and reasoning carry over.
|
|
1439
|
+
*
|
|
1440
|
+
* It pops the item in the same transaction that writes its message and its run, so two turns
|
|
1441
|
+
* ending at once start one between them. `onlyImmediate` starts only a message someone sent now,
|
|
1442
|
+
* which is what a turn that did not answer (a stop, a failure) may follow.
|
|
1443
|
+
*/
|
|
1444
|
+
export async function startQueuedAgentTurnFromInbox(
|
|
1445
|
+
runtime: SixbRuntimeContext,
|
|
1446
|
+
execution: ExecutionContext,
|
|
1447
|
+
finishedRun: ConversationAgentRunRecord,
|
|
1448
|
+
input: { readonly onlyImmediate: boolean },
|
|
1449
|
+
blobStorage?: RewindBlobStorage
|
|
1450
|
+
): Promise<AgentQueuedTurnStart> {
|
|
1451
|
+
resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
1452
|
+
execution,
|
|
1453
|
+
authorization: runtime.runtimeAuthorization,
|
|
1454
|
+
})
|
|
1455
|
+
assertAuthorized(runtime, { kind: "agent.run" })
|
|
1456
|
+
assertRequestAuthorityCanRunAgent(runtime)
|
|
173
1457
|
const agents = requireAgentStorage(runtime)
|
|
174
1458
|
const projectId = runtime.projectId
|
|
175
|
-
// Attribution comes from the exact capability/execution pair, never the optional context cache
|
|
176
|
-
// on the runtime. `input.principal` remains available to unrestricted server integrations that
|
|
177
|
-
// have already authenticated their request.
|
|
178
|
-
const principal =
|
|
179
|
-
authority.type === "principal"
|
|
180
|
-
? authority.context.principal
|
|
181
|
-
: (input.principal ?? SYSTEM_PRINCIPAL)
|
|
182
|
-
const runId = createAgentRunId()
|
|
183
|
-
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId)
|
|
184
|
-
await assertAiLimitPreflight(runtime, durableExecution)
|
|
185
1459
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (
|
|
190
|
-
if (input.runsOn !== undefined && input.runsOn !== "computer") {
|
|
191
|
-
throw new AgentRequestError("invalid_message", `[Sixb] 'runsOn' must be "computer" or omitted.`)
|
|
192
|
-
}
|
|
193
|
-
if (!existingThread) assertComputerPlaceRequest(input.runsOn, input.computer)
|
|
194
|
-
const runsOn = existingThread ? existingThread.runsOn : input.runsOn
|
|
195
|
-
// The message's mode, else the sender's in the thread.
|
|
196
|
-
const approvalMode =
|
|
197
|
-
input.approvalMode ??
|
|
198
|
-
(await resolveAgentApprovalMode(agents, { projectId, principal, threadId: existingThread?.id }))
|
|
199
|
-
.approvalMode
|
|
1460
|
+
// The finished turn's spec is where a queued message starts: its model and reasoning, unless the
|
|
1461
|
+
// message names others. A turn too old to carry one has nothing to start from.
|
|
1462
|
+
const kept = finishedRun.spec
|
|
1463
|
+
if (!kept) return { status: "closed" }
|
|
200
1464
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
language: models.language,
|
|
212
|
-
})
|
|
213
|
-
: requested
|
|
214
|
-
const spec: ConversationAgentRunSpec = Object.freeze({
|
|
215
|
-
...selected,
|
|
216
|
-
approvalMode,
|
|
217
|
-
...(runsOn === undefined ? {} : { runsOn }),
|
|
218
|
-
})
|
|
1465
|
+
const thread = await agents.threads.getById({ projectId, id: finishedRun.threadId })
|
|
1466
|
+
if (!thread) return { status: "closed" }
|
|
1467
|
+
assertSandboxExecutionAvailable(thread)
|
|
1468
|
+
// Whom the turn runs as, and whose messages it starts: a turn starts only its requester's.
|
|
1469
|
+
const principal = execution.requestedBy
|
|
1470
|
+
if (!principal) return { status: "closed" }
|
|
1471
|
+
// Its owner's computer runs its turns as its owner: another's message waits for one of theirs.
|
|
1472
|
+
if (thread.runsOn === "computer" && !principalsEqual(principal, thread.ownerPrincipal)) {
|
|
1473
|
+
return { status: "closed" }
|
|
1474
|
+
}
|
|
219
1475
|
|
|
220
|
-
const
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
projectId,
|
|
225
|
-
threadId: input.threadId,
|
|
226
|
-
title: input.title,
|
|
227
|
-
principal,
|
|
228
|
-
runsOn,
|
|
229
|
-
...(input.computer === undefined ? {} : { computer: input.computer }),
|
|
230
|
-
}))
|
|
1476
|
+
const runId = createAgentRunId()
|
|
1477
|
+
const durableExecution = await prepareResumedExecution(runtime, execution, runId)
|
|
1478
|
+
await assertAiLimitPreflight(runtime, durableExecution)
|
|
1479
|
+
const documents = await waitingEditDocuments(runtime, blobStorage, thread, principal)
|
|
231
1480
|
|
|
232
|
-
|
|
233
|
-
let
|
|
1481
|
+
let started: ConversationAgentRunRecord | null
|
|
1482
|
+
let rewind: AgentThreadRewind | undefined
|
|
1483
|
+
let dropped: { readonly item: AgentInboxItemRecord; readonly reason: unknown } | undefined
|
|
234
1484
|
let superseded: readonly AgentApprovalRecord[] = []
|
|
235
1485
|
try {
|
|
236
|
-
|
|
1486
|
+
started = await runtime.storage.transaction(async (tx) => {
|
|
237
1487
|
const agents = tx.agents
|
|
238
1488
|
if (!agents) {
|
|
239
1489
|
throw new AgentRequestError(
|
|
@@ -241,172 +1491,149 @@ export async function requestAgentRun(
|
|
|
241
1491
|
"[Sixb] Agent storage is not configured."
|
|
242
1492
|
)
|
|
243
1493
|
}
|
|
244
|
-
await
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
1494
|
+
const item = await agents.inbox.takeNextQueued({
|
|
1495
|
+
projectId,
|
|
1496
|
+
threadId: thread.id,
|
|
1497
|
+
onlyImmediate: input.onlyImmediate,
|
|
1498
|
+
authorPrincipal: principal,
|
|
1499
|
+
})
|
|
1500
|
+
if (!item) return null
|
|
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, {
|
|
250
1507
|
projectId,
|
|
251
|
-
|
|
252
|
-
messageId:
|
|
1508
|
+
thread,
|
|
1509
|
+
messageId: item.replacesMessageId,
|
|
1510
|
+
editor: item.authorPrincipal,
|
|
1511
|
+
documents,
|
|
253
1512
|
})
|
|
1513
|
+
} catch (error) {
|
|
1514
|
+
if (!(error instanceof AgentRequestError)) throw error
|
|
1515
|
+
dropped = { item, reason: error }
|
|
1516
|
+
return null
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
const inherited = await resolveAgentApprovalMode(agents, {
|
|
1521
|
+
projectId,
|
|
1522
|
+
principal,
|
|
1523
|
+
threadId: thread.id,
|
|
1524
|
+
})
|
|
1525
|
+
const approvalMode = item.spec?.approvalMode ?? inherited.approvalMode
|
|
1526
|
+
const spec = queuedConversationRunSpec(thread, kept, item, approvalMode)
|
|
1527
|
+
|
|
1528
|
+
await tx.executions.create(durableExecution)
|
|
1529
|
+
// Like any message that starts a turn, it tells the model how its earlier calls ended, and
|
|
1530
|
+
// sets aside the ones still waiting.
|
|
1531
|
+
const reported = await reportAgentApprovals(agents, {
|
|
1532
|
+
projectId,
|
|
1533
|
+
threadId: thread.id,
|
|
1534
|
+
messageId: item.messageId,
|
|
1535
|
+
})
|
|
254
1536
|
superseded = reported.superseded
|
|
255
1537
|
await agents.messages.append({
|
|
256
|
-
id:
|
|
1538
|
+
id: item.messageId,
|
|
257
1539
|
projectId,
|
|
258
1540
|
threadId: thread.id,
|
|
259
1541
|
runId: null,
|
|
260
1542
|
role: "user",
|
|
261
|
-
parts: [
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
1543
|
+
parts: [...reported.parts, ...item.parts],
|
|
1544
|
+
authorPrincipal: item.authorPrincipal,
|
|
1545
|
+
createdAt: item.createdAt,
|
|
1546
|
+
...(item.timeZone === undefined && item.locale === undefined
|
|
1547
|
+
? {}
|
|
1548
|
+
: {
|
|
1549
|
+
metadata: {
|
|
1550
|
+
...(item.timeZone === undefined ? {} : { timeZone: item.timeZone }),
|
|
1551
|
+
...(item.locale === undefined ? {} : { locale: item.locale }),
|
|
1552
|
+
},
|
|
1553
|
+
}),
|
|
268
1554
|
})
|
|
269
1555
|
return agents.runs.create({
|
|
270
1556
|
id: runId,
|
|
271
1557
|
projectId,
|
|
272
1558
|
executionId: durableExecution.id,
|
|
273
1559
|
threadId: thread.id,
|
|
274
|
-
triggerMessageId,
|
|
1560
|
+
triggerMessageId: item.messageId,
|
|
275
1561
|
spec,
|
|
276
1562
|
})
|
|
277
1563
|
})
|
|
278
1564
|
} catch (error) {
|
|
1565
|
+
// A turn took the thread meanwhile: its end starts this message, or its requester does.
|
|
279
1566
|
if (error instanceof AgentStorageError && error.code === "active_run_exists") {
|
|
280
|
-
|
|
1567
|
+
return { status: "closed" }
|
|
281
1568
|
}
|
|
282
1569
|
throw error
|
|
283
1570
|
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
return {
|
|
290
|
-
run,
|
|
291
|
-
...(jobId ? { jobId } : {}),
|
|
292
|
-
createdThread,
|
|
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
|
+
)
|
|
293
1576
|
}
|
|
294
|
-
}
|
|
1577
|
+
if (!started) return { status: "nothing" }
|
|
295
1578
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
return (
|
|
301
|
-
run.status === "failed" || (run.status === "cancelled" && run.finishReason === "interrupted")
|
|
302
|
-
)
|
|
1579
|
+
await announceAgentThreadRewind(runtime, rewind, superseded)
|
|
1580
|
+
await publishRunActivity(runtime, started)
|
|
1581
|
+
await dispatchAgentRun(runtime, agents, runId)
|
|
1582
|
+
return { status: "started", run: started }
|
|
303
1583
|
}
|
|
304
1584
|
|
|
305
|
-
/**
|
|
306
|
-
|
|
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(
|
|
307
1591
|
runtime: SixbRuntimeContext,
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
* behind, and brought up to the content by whoever loads it next.
|
|
314
|
-
*/
|
|
315
|
-
blobStorage?: Pick<BlobStorage, "open" | "put">
|
|
316
|
-
): Promise<RequestAgentRunResult> {
|
|
317
|
-
resolveExecutionScopeAuthorization(runtime.projectId, {
|
|
318
|
-
execution,
|
|
319
|
-
authorization: runtime.runtimeAuthorization,
|
|
320
|
-
})
|
|
321
|
-
assertAuthorized(runtime, { kind: "agent.run" })
|
|
322
|
-
assertRequestAuthorityCanRunAgent(runtime)
|
|
323
|
-
if (!isRetryableAgentRun(failedRun)) {
|
|
324
|
-
throw new AgentRequestError(
|
|
325
|
-
"run_not_retryable",
|
|
326
|
-
`[Sixb] Only failed or interrupted Agent runs can be retried.`
|
|
327
|
-
)
|
|
328
|
-
}
|
|
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()
|
|
329
1597
|
|
|
330
1598
|
const agents = requireAgentStorage(runtime)
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
"thread_not_found",
|
|
338
|
-
`[Sixb] Agent thread '${failedRun.threadId}' was not found.`
|
|
339
|
-
)
|
|
340
|
-
}
|
|
341
|
-
assertSandboxExecutionAvailable(thread)
|
|
342
|
-
const runId = createAgentRunId()
|
|
343
|
-
const durableExecution = await prepareDurableAgentExecution(runtime, execution, runId)
|
|
344
|
-
await assertAiLimitPreflight(runtime, durableExecution)
|
|
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()
|
|
345
1605
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const documents =
|
|
349
|
-
artifacts && blobStorage
|
|
350
|
-
? await undoneTurnDocuments(
|
|
351
|
-
{ projectId: runtime.projectId, storage: artifacts, blobStorage },
|
|
352
|
-
failedRun.id
|
|
353
|
-
)
|
|
354
|
-
: {}
|
|
1606
|
+
const target = await agents.messages.getById({ projectId, id: next.replacesMessageId })
|
|
1607
|
+
if (!target || target.threadId !== thread.id) return new Map()
|
|
355
1608
|
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
}
|
|
361
|
-
await agents.messages.deleteByRunId({
|
|
362
|
-
projectId: runtime.projectId,
|
|
363
|
-
threadId: failedRun.threadId,
|
|
364
|
-
runId: failedRun.id,
|
|
365
|
-
})
|
|
366
|
-
// What the failed turn wrote goes with what it said, so the retry starts clean: each artifact
|
|
367
|
-
// nobody changed since is put back as it was, or deleted when the turn created it and nobody
|
|
368
|
-
// but its requester commented on it. Its children wrote as the turn.
|
|
369
|
-
const trigger = await agents.messages.getById({
|
|
370
|
-
projectId: runtime.projectId,
|
|
371
|
-
id: failedRun.triggerMessageId,
|
|
372
|
-
})
|
|
373
|
-
const requester = trigger?.authorPrincipal
|
|
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
|
+
}
|
|
374
1613
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
})
|
|
394
|
-
|
|
1614
|
+
/** A queued message's turn: the finished turn's spec, with the message's own choices over it. */
|
|
1615
|
+
function queuedConversationRunSpec(
|
|
1616
|
+
thread: AgentThreadRecord,
|
|
1617
|
+
kept: ConversationAgentRunSpec,
|
|
1618
|
+
item: AgentInboxItemRecord,
|
|
1619
|
+
approvalMode: AgentApprovalMode
|
|
1620
|
+
): ConversationAgentRunSpec {
|
|
1621
|
+
const model = item.spec?.model ?? kept.model
|
|
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)
|
|
1626
|
+
const timeZone = item.timeZone ?? kept.timeZone
|
|
1627
|
+
const locale = item.locale ?? kept.locale
|
|
1628
|
+
return inPlace(thread, {
|
|
1629
|
+
model,
|
|
1630
|
+
...(reasoning === undefined ? {} : { reasoning }),
|
|
1631
|
+
...(timeZone === undefined ? {} : { timeZone }),
|
|
1632
|
+
...(locale === undefined ? {} : { locale }),
|
|
1633
|
+
approvalMode,
|
|
395
1634
|
})
|
|
396
|
-
await announceArtifactUpdates(
|
|
397
|
-
runtime.events,
|
|
398
|
-
(undone?.restored ?? []).map(({ version }) => version)
|
|
399
|
-
)
|
|
400
|
-
await publishRunActivity(runtime, run)
|
|
401
|
-
const jobId = await dispatchAgentRun(runtime, agents, runId)
|
|
402
|
-
return { run, ...(jobId ? { jobId } : {}), createdThread: false }
|
|
403
1635
|
}
|
|
404
1636
|
|
|
405
|
-
/** Where a resume left a paused turn. */
|
|
406
|
-
export type AgentTurnResume =
|
|
407
|
-
| { readonly status: "resumed"; readonly run: ConversationAgentRunRecord }
|
|
408
|
-
| { readonly status: Exclude<AgentTurnReadiness, "ready"> }
|
|
409
|
-
|
|
410
1637
|
/**
|
|
411
1638
|
* Resume a turn that paused on held calls, once its requester decided on all of them: a new turn
|
|
412
1639
|
* with the paused one's spec and the given mode, whose trigger message carries how each call ended,
|
|
@@ -564,8 +1791,8 @@ function inPlace(
|
|
|
564
1791
|
thread: AgentThreadRecord,
|
|
565
1792
|
spec: ConversationAgentRunSpec
|
|
566
1793
|
): ConversationAgentRunSpec {
|
|
567
|
-
const { runsOn: _runsOn, ...rest } = spec
|
|
568
|
-
return Object.freeze(
|
|
1794
|
+
const { runsOn: _runsOn, computer: _computer, ...rest } = spec
|
|
1795
|
+
return Object.freeze({ ...rest, ...turnPlace(thread.runsOn, thread.computer) })
|
|
569
1796
|
}
|
|
570
1797
|
|
|
571
1798
|
/** The paused turn's spec, with defaults for a model that has since left the catalog. */
|
|
@@ -638,18 +1865,16 @@ function routedTurn(
|
|
|
638
1865
|
|
|
639
1866
|
/** The spec of a turn Sixb picks the model for, compared to the thread's previous turn. */
|
|
640
1867
|
async function routedConversationRunSpec(
|
|
641
|
-
agents: AgentStorage,
|
|
642
1868
|
input: RoutedTurn & {
|
|
643
|
-
|
|
644
|
-
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
|
|
645
1873
|
readonly settings: RequesterSettings
|
|
646
1874
|
readonly language: LanguageModelCatalog | undefined
|
|
647
1875
|
}
|
|
648
1876
|
): Promise<ConversationAgentRunSpec> {
|
|
649
|
-
const
|
|
650
|
-
? await latestConversationRun(agents, input.projectId, input.threadId)
|
|
651
|
-
: undefined
|
|
652
|
-
const choice = await input.router.choose(input.text, previous)
|
|
1877
|
+
const choice = await input.router.choose(input.text, input.previous, input.place)
|
|
653
1878
|
|
|
654
1879
|
return resolveConversationRunSpec({
|
|
655
1880
|
models: input.language,
|
|
@@ -711,6 +1936,18 @@ function assertAttachments(attachments: readonly FileRef[] | undefined): void {
|
|
|
711
1936
|
}
|
|
712
1937
|
|
|
713
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 {
|
|
714
1951
|
assertConversationThread(thread)
|
|
715
1952
|
assertSandboxExecutionAvailable(thread)
|
|
716
1953
|
// Its owner's computer runs its turns as its owner: nobody else may send it one.
|
|
@@ -720,20 +1957,17 @@ function assertThreadAcceptsRun(thread: AgentThreadRecord, principal: Principal)
|
|
|
720
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.`
|
|
721
1958
|
)
|
|
722
1959
|
}
|
|
723
|
-
// Fast single-flight check for a clear error. `runs.create` is the atomic authority.
|
|
724
|
-
if (thread.activeRunId !== null) {
|
|
725
|
-
throw new AgentRequestError(
|
|
726
|
-
"active_run_exists",
|
|
727
|
-
`[Sixb] Agent thread '${thread.id}' already has an active run '${thread.activeRunId}'.`
|
|
728
|
-
)
|
|
729
|
-
}
|
|
730
1960
|
}
|
|
731
1961
|
|
|
732
1962
|
function assertSandboxExecutionAvailable(thread: AgentThreadRecord): void {
|
|
733
|
-
if (
|
|
1963
|
+
if (
|
|
1964
|
+
thread.runsOn !== "computer" &&
|
|
1965
|
+
thread.sandboxState &&
|
|
1966
|
+
!["new", "ready"].includes(thread.sandboxState.status)
|
|
1967
|
+
) {
|
|
734
1968
|
throw new AgentRequestError(
|
|
735
1969
|
"sandbox_execution_unavailable",
|
|
736
|
-
"[Sixb] Sandbox recovery is required before another run. Reload the thread
|
|
1970
|
+
"[Sixb] Sandbox recovery is required before another run. Reload the thread, then resume its previous sandbox or recreate it to start fresh."
|
|
737
1971
|
)
|
|
738
1972
|
}
|
|
739
1973
|
}
|