@makaio/framework 1.0.0-dev-1785407933303 → 1.0.0-dev-1786014320559
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/.makaio-build.json +4 -3
- package/dist/{account-identity-DFx8pwKL.mjs → account-identity-DGpXd8h_.mjs} +1 -1
- package/dist/adapter-BkdJaOOG.mjs +1 -0
- package/dist/adapter-subsystem/index.d.mts +138 -6
- package/dist/adapter-subsystem/index.mjs +1 -1
- package/dist/adapters/acp-client/index.d.mts +105 -7
- package/dist/adapters/acp-client/index.mjs +2 -2
- package/dist/adapters/claude/index.d.mts +24 -24
- package/dist/adapters/config/index.d.mts +1 -1
- package/dist/adapters/config/index.mjs +1 -1
- package/dist/adapters/index.d.mts +379 -812
- package/dist/adapters/index.mjs +6 -6
- package/dist/adapters/node.d.mts +1 -1
- package/dist/adapters/node.mjs +1 -1
- package/dist/adapters/stream-session/index.d.mts +28 -7
- package/dist/adapters/stream-session/index.mjs +1 -1
- package/dist/agent-namespace-D51PODFf.mjs +1 -0
- package/dist/{ajv-DD3SIL2i.mjs → ajv-L5fKxaia.mjs} +2 -2
- package/dist/artifact-k3veR4Yx.mjs +1 -0
- package/dist/attach-error-BSlc7JfL.mjs +1 -0
- package/dist/{auth-DGEdiHF6.mjs → auth-A1K_7q-8.mjs} +1 -1
- package/dist/authority-state-bootstrap-YwtEImIB.mjs +1 -0
- package/dist/automation-trigger-CuSdQwir.mjs +1 -0
- package/dist/await-trigger-ph1S0zVI.mjs +1 -0
- package/dist/bus/index.d.mts +17 -3
- package/dist/bus/index.mjs +1 -1
- package/dist/bus-BIj0_aG6.mjs +1 -0
- package/dist/bus-CqgrphNE.mjs +2 -0
- package/dist/{canonical-model-BAytQ4NV.mjs → canonical-model-DJASlL4m.mjs} +1 -1
- package/dist/{capabilities-BQEp34ir.mjs → capabilities-Bqckjh7G.mjs} +1 -1
- package/dist/{client-DbS847wW.mjs → client-BL5__WT0.mjs} +1 -1
- package/dist/clients/index.d.mts +7 -7
- package/dist/clients/index.mjs +1 -1
- package/dist/clients/managed-install.d.mts +1 -1
- package/dist/clients/managed-install.mjs +1 -1
- package/dist/{compression-74fFeBha.mjs → compression-BbttSqm8.mjs} +1 -1
- package/dist/{config-namespace-TVX-hG4I.mjs → config-namespace-CyzeLWSg.mjs} +1 -1
- package/dist/{context-resolution-DNRkyQto.d.mts → context-resolution-CW0ya4QO.d.mts} +14 -14
- package/dist/contracts/adapter/index.d.mts +3 -3
- package/dist/contracts/adapter/index.mjs +1 -1
- package/dist/contracts/adapter/schemas/session-lineage.d.mts +1 -1
- package/dist/contracts/artifact/index.d.mts +3 -3
- package/dist/contracts/artifact/index.mjs +1 -1
- package/dist/contracts/auth/index.d.mts +2 -2
- package/dist/contracts/auth/index.mjs +1 -1
- package/dist/contracts/automation-trigger/index.d.mts +4 -0
- package/dist/contracts/automation-trigger/index.mjs +1 -0
- package/dist/contracts/canonical-model/index.d.mts +1 -1
- package/dist/contracts/canonical-model/index.mjs +1 -1
- package/dist/contracts/capabilities/index.d.mts +1 -1
- package/dist/contracts/capabilities/index.mjs +1 -1
- package/dist/contracts/client/index.d.mts +2 -2
- package/dist/contracts/client/index.mjs +1 -1
- package/dist/contracts/common/index.d.mts +1 -1
- package/dist/contracts/config/index.d.mts +1 -1
- package/dist/contracts/config/index.mjs +1 -1
- package/dist/contracts/extension/index.d.mts +6 -5
- package/dist/contracts/extension/index.mjs +1 -1
- package/dist/contracts/facet/index.d.mts +1 -1
- package/dist/contracts/facet/index.mjs +1 -1
- package/dist/contracts/harness/index.d.mts +1 -1
- package/dist/contracts/harness/index.mjs +1 -1
- package/dist/contracts/host/index.d.mts +1 -1
- package/dist/contracts/host/index.mjs +1 -1
- package/dist/contracts/index.d.mts +161 -100
- package/dist/contracts/index.mjs +1 -1
- package/dist/contracts/materialization/index.d.mts +3 -3
- package/dist/contracts/materialization/index.mjs +1 -1
- package/dist/contracts/model-registry/index.d.mts +1 -1
- package/dist/contracts/model-registry/index.mjs +1 -1
- package/dist/contracts/native-session-supervisor/index.d.mts +1 -1
- package/dist/contracts/native-session-supervisor/index.mjs +1 -1
- package/dist/contracts/platform/index.d.mts +1 -1
- package/dist/contracts/platform/index.mjs +1 -1
- package/dist/contracts/provider/index.d.mts +2 -2
- package/dist/contracts/provider/index.mjs +1 -1
- package/dist/contracts/reaction/index.d.mts +2 -0
- package/dist/contracts/reaction/index.mjs +1 -0
- package/dist/contracts/session/index.d.mts +3 -3
- package/dist/contracts/session/index.mjs +1 -1
- package/dist/contracts/shared/index.d.mts +3 -3
- package/dist/contracts/shared/index.mjs +1 -1
- package/dist/contracts/skill/index.d.mts +1 -1
- package/dist/contracts/skill/index.mjs +1 -1
- package/dist/contracts/telemetry/index.d.mts +1 -1
- package/dist/contracts/telemetry/index.mjs +1 -1
- package/dist/contracts/timeout/index.d.mts +1 -1
- package/dist/contracts/timeout/index.mjs +1 -1
- package/dist/contracts/toast/index.mjs +1 -1
- package/dist/contracts/variant/index.d.mts +1 -1
- package/dist/contracts/variant/index.mjs +1 -1
- package/dist/contracts/worker-node/index.d.mts +1 -1
- package/dist/contracts/worker-node/index.mjs +1 -1
- package/dist/contracts/workflow/index.d.mts +3 -3
- package/dist/contracts/workflow/index.mjs +1 -1
- package/dist/contribution-BH-wKsWI.d.mts +35 -0
- package/dist/core/index.d.mts +60 -1
- package/dist/core/index.mjs +1 -1
- package/dist/definition-BYgHlmMw.d.mts +375 -0
- package/dist/{definition-CJfiv8xm.mjs → definition-CDg-Jq1T.mjs} +1 -1
- package/dist/{detached-extension-handle-Ddfquy5_.mjs → detached-extension-handle-DKd17UB6.mjs} +1 -1
- package/dist/drizzle/0031_adapter_session_currency.sql +66 -0
- package/dist/drizzle/0032_native_session_ownership.sql +77 -0
- package/dist/drizzle/0033_m_msf3hu2s.sql +1 -0
- package/dist/drizzle/meta/_journal.json +21 -0
- package/dist/{execution-attempt-repository-DWXKY41_.d.mts → execution-attempt-repository-DFyAnchJ.d.mts} +1 -1
- package/dist/{execution-target-Cf645pDj.mjs → execution-target-ByNwZh5-.mjs} +1 -1
- package/dist/extension-DMdmj9gi.mjs +1 -0
- package/dist/extension-DUmibvMk.mjs +1 -0
- package/dist/extension-context-CqfddWXs.d.mts +295 -0
- package/dist/{extension-discovery-CQRdbVQ6.d.mts → extension-discovery-Fhps4icD.d.mts} +2 -0
- package/dist/{extension-namespace-Yu41YepM.mjs → extension-namespace-B554RmCp.mjs} +1 -1
- package/dist/extension-package-provenance-Dh_-Z-tE.mjs +1 -0
- package/dist/{filesystem-service-DlP2HfDg.mjs → filesystem-service-FAtd9gWH.mjs} +1 -1
- package/dist/framework-packages-D_2hBZ-p.mjs +1 -0
- package/dist/git/index.mjs +1 -1
- package/dist/{globby-1yCVCk8s.mjs → globby-BBLuT_vy.mjs} +1 -1
- package/dist/handlers-2yd00VEq.mjs +57 -0
- package/dist/{harness-DpwsFsE7.mjs → harness-KxbWGL4I.mjs} +1 -1
- package/dist/{hook-responses-Dh1PWXqJ.d.mts → hook-responses-CQZIv3L3.d.mts} +2 -293
- package/dist/{index-HsTxm-R3.d.mts → index-3eUIRy7T.d.mts} +250 -20
- package/dist/{index-brqfk9JQ.d.mts → index-B4xdTT3c.d.mts} +6 -6
- package/dist/{index-CmFbzuiW.d.mts → index-B5op6AsV.d.mts} +72 -62
- package/dist/{index-CMgLxw14.d.mts → index-B6GOuxVy2.d.mts} +18 -18
- package/dist/index-BFhJe-Sb.d.mts +302 -0
- package/dist/{index-fmR2JNgJ.d.mts → index-BQprJNA_.d.mts} +4 -4
- package/dist/{index-EjsSBQXy2.d.mts → index-BSQ30wYP.d.mts} +1 -1
- package/dist/{index-Hk9mpC3o.d.mts → index-BSbGB23v.d.mts} +8 -8
- package/dist/{index-BbF2gRwd.d.mts → index-BiAYXjgM.d.mts} +41 -41
- package/dist/{index-sFsAqeK1.d.mts → index-ByZi9bml.d.mts} +7616 -4158
- package/dist/{index-CMJZ2Z8m.d.mts → index-C7HcDpHE.d.mts} +4 -0
- package/dist/{index-BskPjMet.d.mts → index-CB4aIUoF.d.mts} +16 -16
- package/dist/{index-B-xrJCwa.d.mts → index-CDusRXio.d.mts} +136 -137
- package/dist/{index-CUvNKYkV.d.mts → index-CSN_0sCo.d.mts} +19 -2
- package/dist/{index-BAXkicoQ.d.mts → index-C__EQfKa.d.mts} +1 -1
- package/dist/{index-BfLulUMy2.d.mts → index-CqQYgsbB.d.mts} +1659 -217
- package/dist/{index-DF9ffhVe.d.mts → index-CwDiyJkJ.d.mts} +327 -756
- package/dist/{index-GHASUiem.d.mts → index-DBadVauL.d.mts} +1 -1
- package/dist/{index-gUhidukN.d.mts → index-DI7-tIL3.d.mts} +299 -2
- package/dist/index-DP3o_13U.d.mts +165 -0
- package/dist/{index-DSBT83c0.d.mts → index-DcYAAJ0V.d.mts} +24 -3
- package/dist/{index-DqkjRTr7.d.mts → index-Dch_AxUg.d.mts} +77 -39
- package/dist/{index-XZyMxxnU.d.mts → index-DcqSUsX6.d.mts} +39 -83
- package/dist/{index-B0Kf_OWi.d.mts → index-DgOfgjx3.d.mts} +1 -1
- package/dist/{index-Ds5_rDEJ.d.mts → index-DwLRZscE.d.mts} +1 -12
- package/dist/{index-DkiTJM5p.d.mts → index-DxYDRoDE2.d.mts} +17 -3
- package/dist/{index-CRvpVIqA.d.mts → index-OsbtyMgx2.d.mts} +10 -1
- package/dist/{index-BaZeoZoS.d.mts → index-bIe_57cL.d.mts} +1 -1
- package/dist/{json-value-Brslhqbm.d.mts → json-value-C1RGgS0a.d.mts} +16 -1
- package/dist/{json-value-DmU8ibo_.mjs → json-value-D57aJhVn.mjs} +1 -1
- package/dist/kernel/cli/index.d.mts +2 -2
- package/dist/kernel/cli/index.mjs +1 -1
- package/dist/kernel/cli/register.d.mts +1 -1
- package/dist/kernel/cli/register.mjs +1 -1
- package/dist/kernel/cli/schemas.mjs +1 -1
- package/dist/kernel/extension/index.d.mts +1 -1
- package/dist/kernel/extension/index.mjs +1 -1
- package/dist/kernel/index.d.mts +9 -9
- package/dist/kernel/index.mjs +1 -1
- package/dist/kernel/namespace/index.d.mts +2 -2
- package/dist/kernel/namespace/index.mjs +1 -1
- package/dist/kernel/observability/index.d.mts +1 -1
- package/dist/kernel/observability/index.mjs +1 -1
- package/dist/kernel/providers/index.d.mts +1 -1
- package/dist/kernel/providers/index.mjs +1 -1
- package/dist/kernel/window/index.d.mts +1 -1
- package/dist/kernel/window/index.mjs +1 -1
- package/dist/{lib-C7-s68uf.mjs → lib-B_rJ6r0T.mjs} +1 -1
- package/dist/{lib-DErgth_E.mjs → lib-CnOAtohU.mjs} +1 -1
- package/dist/load-extensions-CW9uzNR5.mjs +1 -0
- package/dist/{load-extensions-BxsDB87B.d.mts → load-extensions-DUpaMQ7G.d.mts} +17 -13
- package/dist/{materialization-Jd198K3y.mjs → materialization-CcpCDhXh.mjs} +1 -1
- package/dist/mcp-http-server/index.mjs +1 -1
- package/dist/model-ZH3L1dPW.mjs +1 -0
- package/dist/{namespace-BqxtpNAn.mjs → namespace-B7bntOB8.mjs} +1 -1
- package/dist/{namespace-CWUDFGOy.mjs → namespace-BFqkUTJp.mjs} +1 -1
- package/dist/{namespace-D-WH2uYV2.d.mts → namespace-CAy4P5mW.d.mts} +8 -8
- package/dist/{namespace-B8uKAzWJ.mjs → namespace-CFjdyNXG.mjs} +1 -1
- package/dist/{namespace-DV-Hr9sZ.d.mts → namespace-ChnRTUG4.d.mts} +11 -1
- package/dist/namespace-CxrOLeeP.mjs +1 -0
- package/dist/{namespace-g_mbIZq_.d.mts → namespace-DSlfFhB1.d.mts} +410 -26
- package/dist/{namespace-Dkod-w11.d.mts → namespace-DwZwGXgF.d.mts} +4 -0
- package/dist/{namespace-BXvD9t0I.d.mts → namespace-Rge9mMI-.d.mts} +27 -19
- package/dist/{native-session-supervisor-DRx0MX-d.mjs → native-session-supervisor-fZYPUk0-.mjs} +1 -1
- package/dist/node/bus-server/index.d.mts +1 -1
- package/dist/node/bus-server/index.mjs +1 -1
- package/dist/node/bus-server/server-lifecycle.d.mts +1 -1
- package/dist/node/bus-server/server-lifecycle.mjs +1 -1
- package/dist/{orchestrator-shared-BHCv-l2O.d.mts → orchestrator-shared-B-KRW1Z0.d.mts} +1 -0
- package/dist/orchestrator-shared-CTCZc6Vl.mjs +1 -0
- package/dist/ownership-memory-handler-Bblp93YC.mjs +1 -0
- package/dist/{package-DWMxGfzK.d.mts → package-Bf3hyuzs.d.mts} +234 -84
- package/dist/package-CBdvjyyZ.mjs +1 -0
- package/dist/package-CddkNbZI.mjs +1 -0
- package/dist/package-ypz4rKvn.mjs +7 -0
- package/dist/package.json +1 -1
- package/dist/{profile-BTAI31Nt.mjs → profile-BtznZlq3.mjs} +1 -1
- package/dist/{provider-context-Dq53Cgzz.mjs → provider-context-BrLZYnDW.mjs} +1 -1
- package/dist/{provider-context-PZIQWcqQ.mjs → provider-context-Dh-VOOYF.mjs} +1 -1
- package/dist/reaction-BS0k4eNN.mjs +1 -0
- package/dist/{registry-wfF2uTty.mjs → registry-BO_bOoky.mjs} +2 -2
- package/dist/{resolved-DZgqql2Z.mjs → resolved-DMByz1_2.mjs} +1 -1
- package/dist/rules/index.d.mts +1 -1
- package/dist/rules/index.mjs +1 -1
- package/dist/rules/schemas.d.mts +1 -1
- package/dist/runtime-bun/index.mjs +1 -1
- package/dist/runtime-node/extension-discovery.d.mts +1 -1
- package/dist/runtime-node/extension-validation.d.mts +1 -1
- package/dist/runtime-node/extension-validation.mjs +1 -1
- package/dist/runtime-node/index.d.mts +4 -4
- package/dist/runtime-node/index.mjs +24 -24
- package/dist/runtime-node/makaio-config.d.mts +1 -1
- package/dist/runtime-node/makaio-config.mjs +1 -1
- package/dist/runtime-node/workflow-worker/index.d.mts +1 -1
- package/dist/runtime-node/workflow-worker/index.mjs +1 -1
- package/dist/runtime-node/workflow-worker/worker-entry.mjs +1 -1
- package/dist/{schema-Dd-e89MO.mjs → schema-DBG7Jq5_.mjs} +1 -1
- package/dist/{schema-DKUb4rkr.d.mts → schema-DKTzriEY.d.mts} +519 -9
- package/dist/{schemas-B5eUUi6u.d.mts → schemas-9qeeHGBf.d.mts} +8 -8
- package/dist/{schemas-CRB2O5zo.mjs → schemas-BqD8LlQw.mjs} +1 -1
- package/dist/{schemas-DaHQzpgm.mjs → schemas-CsjN7cmM.mjs} +1 -1
- package/dist/schemas-DSkBOdx_.mjs +1 -0
- package/dist/schemas-DplrlAyR.mjs +1 -0
- package/dist/{schemas-DuIlOWR3.d.mts → schemas-VbB1FTxx.d.mts} +4 -0
- package/dist/scoped-bus-ClwTWqX8.mjs +1 -0
- package/dist/{selection-BNwTKEVT.mjs → selection-7Ku8DBnh.mjs} +1 -1
- package/dist/services/adapter-runtime/index.d.mts +3 -3
- package/dist/services/adapter-runtime/index.mjs +1 -1
- package/dist/services/adapter-runtime/namespace.d.mts +1 -1
- package/dist/services/adapter-runtime/schemas.d.mts +1 -1
- package/dist/services/adapter-subsystem/index.d.mts +4 -4
- package/dist/services/adapter-subsystem/index.mjs +1 -1
- package/dist/services/adapter-subsystem/namespace.d.mts +2 -2
- package/dist/services/adapter-subsystem/namespace.mjs +1 -1
- package/dist/services/agent-runtime/index.d.mts +2 -2
- package/dist/services/agent-runtime/namespace.d.mts +1 -1
- package/dist/services/agent-runtime/schemas.d.mts +1 -1
- package/dist/services/automation-trigger/index.d.mts +943 -0
- package/dist/services/automation-trigger/index.mjs +1 -0
- package/dist/services/capability/index.d.mts +1 -1
- package/dist/services/capability/index.mjs +1 -1
- package/dist/services/codebase/index.d.mts +2 -2
- package/dist/services/codebase/namespace.d.mts +1 -1
- package/dist/services/codebase/schemas.d.mts +1 -1
- package/dist/services/compression/index.d.mts +2 -2
- package/dist/services/compression/namespace.d.mts +1 -1
- package/dist/services/compression/schemas.d.mts +1 -1
- package/dist/services/context-rules/index.d.mts +4 -4
- package/dist/services/context-rules/index.mjs +1 -1
- package/dist/services/execution-target/index.d.mts +3 -3
- package/dist/services/execution-target/index.mjs +1 -1
- package/dist/services/execution-target/namespace.d.mts +1 -1
- package/dist/services/execution-target/namespace.mjs +1 -1
- package/dist/services/execution-target/schemas.d.mts +1 -1
- package/dist/services/execution-target/schemas.mjs +1 -1
- package/dist/services/filesystem/index.d.mts +1 -1
- package/dist/services/filesystem/index.mjs +1 -1
- package/dist/services/filesystem/namespace.d.mts +6 -6
- package/dist/services/filesystem/schemas.d.mts +3 -3
- package/dist/services/git/namespace.d.mts +2 -2
- package/dist/services/git/namespace.mjs +1 -1
- package/dist/services/git/schemas.d.mts +1 -1
- package/dist/services/git/schemas.mjs +1 -1
- package/dist/services/harness/index.d.mts +3 -3
- package/dist/services/harness/index.mjs +1 -1
- package/dist/services/index.d.mts +449 -83
- package/dist/services/index.mjs +1 -1
- package/dist/services/log-import/browser.d.mts +2 -2
- package/dist/services/log-import/index.d.mts +3 -3
- package/dist/services/log-import/log-import.d.mts +1 -1
- package/dist/services/log-import/log-import.mjs +1 -1
- package/dist/services/log-import/namespace.mjs +1 -1
- package/dist/services/log-import/schemas.mjs +1 -1
- package/dist/services/materialization/index.d.mts +1 -1
- package/dist/services/materialization/index.mjs +1 -1
- package/dist/services/model-registry/index.d.mts +1 -1
- package/dist/services/model-registry/index.mjs +1 -1
- package/dist/services/preferences/index.d.mts +2 -2
- package/dist/services/preferences/schemas.d.mts +1 -1
- package/dist/services/preferences/storage-namespace.d.mts +2 -2
- package/dist/services/provider-context/index.d.mts +1 -1
- package/dist/services/provider-context/index.mjs +1 -1
- package/dist/services/provider-runtime/index.mjs +1 -1
- package/dist/services/session/handlers/index.d.mts +2 -2
- package/dist/services/session/handlers/index.mjs +1 -1
- package/dist/services/session/index.d.mts +10 -10
- package/dist/services/session/index.mjs +1 -1
- package/dist/services/session/messages/namespace.d.mts +1 -1
- package/dist/services/session/messages/namespace.mjs +1 -1
- package/dist/services/session/orchestrator-testing/index.d.mts +1 -1
- package/dist/services/session/orchestrator-testing/index.mjs +1 -1
- package/dist/services/session/session-events/namespace.d.mts +1 -1
- package/dist/services/session/session-events/namespace.mjs +1 -1
- package/dist/services/session/storage/namespace.d.mts +1 -1
- package/dist/services/session/storage/schema.d.mts +2 -2
- package/dist/services/session/storage/schema.mjs +1 -1
- package/dist/services/session/testing/index.d.mts +12 -4
- package/dist/services/session/testing/index.mjs +36 -4
- package/dist/services/session/testing/orchestrator-shared.d.mts +1 -1
- package/dist/services/session/testing/orchestrator-shared.mjs +1 -1
- package/dist/services/session/turns/namespace.d.mts +1 -1
- package/dist/services/session/turns/namespace.mjs +1 -1
- package/dist/services/session-editor/index.d.mts +1 -1
- package/dist/services/session-editor/index.mjs +1 -1
- package/dist/services/settings/index.d.mts +3 -3
- package/dist/services/settings/index.mjs +1 -1
- package/dist/services/settings/namespace.d.mts +8 -8
- package/dist/services/settings/namespace.mjs +1 -1
- package/dist/services/settings/storage/clients-namespace.d.mts +1 -1
- package/dist/services/settings/storage/clients-namespace.mjs +1 -1
- package/dist/services/settings/storage/index.d.mts +3 -3
- package/dist/services/settings/storage/index.mjs +1 -1
- package/dist/services/settings/storage/providers-namespace.d.mts +1 -1
- package/dist/services/settings/storage/providers-namespace.mjs +1 -1
- package/dist/services/subagent/index.d.mts +1 -1
- package/dist/services/subagent/index.mjs +1 -1
- package/dist/services/subagent-template/index.d.mts +2 -2
- package/dist/services/subagent-template/namespace.d.mts +1 -1
- package/dist/services/subagent-template/schemas.d.mts +1 -1
- package/dist/services/tool-approval/index.d.mts +1 -1
- package/dist/services/tool-approval/index.mjs +1 -1
- package/dist/services/tools/index.d.mts +1 -1
- package/dist/services/tools/index.mjs +1 -1
- package/dist/services/tray-menu/index.d.mts +3 -3
- package/dist/services/tray-menu/index.mjs +1 -1
- package/dist/services/tray-menu/namespace.d.mts +1 -1
- package/dist/services/tray-menu/schemas.d.mts +1 -1
- package/dist/services/turn/index.d.mts +1 -1
- package/dist/services/turn/namespace.d.mts +1 -1
- package/dist/services/workflow-transitions/index.d.mts +1 -1
- package/dist/services/workflow-transitions/index.mjs +1 -1
- package/dist/session-BMy2kRpX.mjs +90 -0
- package/dist/session-Cipx34j6.mjs +1 -0
- package/dist/{session-lineage-B_JW5LpF.d.mts → session-lineage-B_PVa1XN.d.mts} +1 -1
- package/dist/shared-BFVuCDPx.mjs +1 -0
- package/dist/{skill-BR6rkfLe.mjs → skill-C1D51nhh.mjs} +1 -1
- package/dist/{src-DD0v-nIj.mjs → src-xbmzokNe.mjs} +1 -1
- package/dist/storage/drizzle/client.d.mts +1 -1
- package/dist/storage/drizzle/client.mjs +1 -1
- package/dist/storage/drizzle/index.d.mts +42 -2
- package/dist/storage/drizzle/index.mjs +1 -1
- package/dist/storage/handlers/drizzle/index.d.mts +1 -1
- package/dist/storage/handlers/drizzle/index.mjs +1 -1
- package/dist/storage/handlers/index.d.mts +1 -1
- package/dist/storage/handlers/index.mjs +1 -1
- package/dist/tool-approval-service-BVgN9Q1r.mjs +1 -0
- package/dist/{tools-PdG9fO1M.mjs → tools-DxwHox1a.mjs} +1 -1
- package/dist/{transition-DwqL8W9V.d.mts → transition-BF1nevaC.d.mts} +7 -34
- package/dist/{types-DMLDHFR9.d.mts → types-BNjPhj_a.d.mts} +1 -1
- package/dist/{types-DR60yv6W.d.mts → types-CijlWGwb.d.mts} +1575 -157
- package/dist/types-ClpEaoAm.d.mts +2917 -0
- package/dist/ui-hooks/index.d.mts +29 -2
- package/dist/ui-hooks/index.mjs +1 -1
- package/dist/ui-kernel/index.d.mts +2 -2
- package/dist/ui-kernel/pages/schemas.d.mts +1 -1
- package/dist/ui-views/index.d.mts +1 -1
- package/dist/utils/index.d.mts +77 -1
- package/dist/utils/index.mjs +2 -2
- package/dist/{version-CoCeMxDT.mjs → version-BfNnVAGr.mjs} +1 -1
- package/dist/{view-builder-qp51cMWh.d.mts → view-builder-Bc9dx6jF.d.mts} +1 -1
- package/dist/{visibility-qhGWmpSJ.mjs → visibility-Dl1o2I01.mjs} +1 -1
- package/dist/{worker-node-Bl9_vqYi.mjs → worker-node-BDOYPEpi.mjs} +1 -1
- package/dist/{worker-node-DZTuT1DS.mjs → worker-node-DJ41Tr-F.mjs} +1 -1
- package/dist/workflow-Hzc5jlnV.mjs +1 -0
- package/dist/workflow-engine/execution-attempt-repository.d.mts +1 -1
- package/dist/workflow-engine/index.d.mts +161 -442
- package/dist/workflow-engine/index.mjs +1 -1
- package/dist/workflow-engine/package.d.mts +1 -1
- package/dist/workflow-engine/package.mjs +1 -1
- package/dist/workflow-engine/provider-operation.d.mts +1 -1
- package/dist/workflow-engine/testing/index.d.mts +2 -2
- package/dist/workflow-engine/testing/index.mjs +1 -1
- package/dist/workflow-engine/testing/sqlite.d.mts +1 -1
- package/dist/workflow-engine/testing/sqlite.mjs +27 -27
- package/dist/workflow-engine/workflow-orchestrator.mjs +1 -1
- package/dist/workflow-engine/workflow-trigger-binding-consumer.d.mts +46 -0
- package/dist/workflow-engine/workflow-trigger-binding-consumer.mjs +1 -0
- package/dist/{workflow-transitions-DSc45ixc.mjs → workflow-transitions-DM0fN_eP.mjs} +1 -1
- package/dist/workflow-worker-DARC7UZl.mjs +1 -0
- package/dist/zod-json-schema-BAGAFfCN.mjs +1 -0
- package/package.json +29 -1
- package/dist/adapter-D5c5LrPN.mjs +0 -1
- package/dist/artifact-DGiXqb11.mjs +0 -1
- package/dist/attach-error-C3tngg6J.mjs +0 -1
- package/dist/authority-state-bootstrap-GPL_tqaT.mjs +0 -1
- package/dist/await-trigger-I3lrepb8.mjs +0 -1
- package/dist/bus-B6SAjgOC.mjs +0 -2
- package/dist/bus-C2l3K74u.mjs +0 -1
- package/dist/extension-DCA4pYrY.mjs +0 -1
- package/dist/extension-hjOPs10e.mjs +0 -1
- package/dist/framework-packages-C3RWfJDk.mjs +0 -1
- package/dist/handlers-CfnLyLfE.mjs +0 -57
- package/dist/load-extensions-D0DfjYLC.mjs +0 -1
- package/dist/model-BGgVmRnN.mjs +0 -1
- package/dist/namespace-DJfUADSV.mjs +0 -1
- package/dist/orchestrator-shared-BxmHCPvx.mjs +0 -1
- package/dist/package-CNUPPcU1.mjs +0 -7
- package/dist/package-Dft_RItb.mjs +0 -1
- package/dist/schemas-Cm09dXL4.mjs +0 -1
- package/dist/scoped-bus-C9BdNwfM.mjs +0 -1
- package/dist/session-BOGCd18q.mjs +0 -1
- package/dist/session-BTFiDoGz.mjs +0 -76
- package/dist/shared-BQ0CHIVy.mjs +0 -1
- package/dist/tool-approval-service-kBA0fRzm.mjs +0 -1
- package/dist/types-CJ_QZ1yW.d.mts +0 -1487
- package/dist/workflow-BfDbgtIQ.mjs +0 -1
- package/dist/workflow-worker-BN9XPxQO.mjs +0 -1
- package/dist/{adapter-auth-runtime-DO-FVTXg.mjs → adapter-auth-runtime-D9Lnl7cc.mjs} +0 -0
- package/dist/{adapter-binding-DQchUtrK.d.mts → adapter-binding-B-FBoCys.d.mts} +0 -0
- package/dist/{attempt-record-codec-CqO1_XnE.mjs → attempt-record-codec-DaFLKR5C.mjs} +0 -0
- package/dist/{base-orchestrator-BilsQNW1.d.mts → base-orchestrator-D9u4NyiM.d.mts} +0 -0
- package/dist/{capability-service-BqiLlRGA.mjs → capability-service-CJHNkjvm.mjs} +0 -0
- package/dist/{client-B--e2qcU.d.mts → client-4ihewPUm.d.mts} +0 -0
- package/dist/{client-binary-version-verifier-taewmKTY.mjs → client-binary-version-verifier-DJajc_Ff.mjs} +0 -0
- package/dist/{client-binary-version-verifier-CgjM_vGF.d.mts → client-binary-version-verifier-jDDZ64Ah.d.mts} +0 -0
- package/dist/{clients-namespace-DfxjG2ZP.d.mts → clients-namespace-DFWuUawf.d.mts} +0 -0
- package/dist/{config-namespace-BCqvufbD.d.mts → config-namespace-D1kyZj0B.d.mts} +0 -0
- package/dist/{create-static-mount-bbQhTt6W.mjs → create-static-mount-9tnGpIeK.mjs} +0 -0
- package/dist/{cross-spawn-B57KZuns.mjs → cross-spawn-BIgueAqr.mjs} +0 -0
- package/dist/{cursor-storage-DIFK_9hg.mjs → cursor-storage-ROWfiTh1.mjs} +0 -0
- package/dist/{definition-gnKgXU91.d.mts → definition-DB-kKc0d.d.mts} +0 -0
- package/dist/{definitions-xrrY0wgz.mjs → definitions-CF6YmEhL.mjs} +0 -0
- package/dist/{descriptor-to-package-DvF08krT.mjs → descriptor-to-package-BecVCopf.mjs} +0 -0
- package/dist/{drizzle-z_0SiGY8.mjs → drizzle-CPv3vdTE.mjs} +0 -0
- package/dist/{esm-CltRnX8_.mjs → esm-CBFWM8u_.mjs} +0 -0
- package/dist/{event-CmVjR6Ib.mjs → event-DR8U9Efx.mjs} +0 -0
- package/dist/{facet-BCI00njh.mjs → facet-DVsW12iF.mjs} +0 -0
- package/dist/{filesystem-service-CQ9yVkSz.d.mts → filesystem-service-Cm2RHKBa.d.mts} +0 -0
- package/dist/{handler-Cbv9FqDO.mjs → handler-Bqlk-6BY.mjs} +0 -0
- package/dist/{host-Caq6ZfSJ.mjs → host-k5yoyKHg.mjs} +0 -0
- package/dist/{identity-D6guMtmi.mjs → identity-DC3Pk0ps.mjs} +0 -0
- package/dist/{index-dtsLKOID.d.mts → index-42UdYStR.d.mts} +0 -0
- package/dist/{index-DR40QWlw.d.mts → index-BJAB-BW_.d.mts} +0 -0
- package/dist/{index-Dm1nUxCF.d.mts → index-BJMezANn.d.mts} +0 -0
- package/dist/{index-Cv-o5Krs.d.mts → index-BRCrFirq.d.mts} +0 -0
- package/dist/{index-BVRQEpAg.d.mts → index-BRzHs7Bx.d.mts} +6 -6
- /package/dist/{index-vA--0lOM.d.mts → index-BVcQcphK.d.mts} +0 -0
- /package/dist/{index-ye0oklfU.d.mts → index-BcvqDfcN.d.mts} +0 -0
- /package/dist/{index-CGZQVTid.d.mts → index-BeENojSx2.d.mts} +0 -0
- /package/dist/{index-DjgLchuQ.d.mts → index-Beo_Ik8-.d.mts} +0 -0
- /package/dist/{index-sS6KUlrx.d.mts → index-BgGe9WZz.d.mts} +0 -0
- /package/dist/{index-CWHfOz6d.d.mts → index-CK3f0bAL.d.mts} +0 -0
- /package/dist/{index-DZunhZec.d.mts → index-CQuRTeRa.d.mts} +0 -0
- /package/dist/{index-jTaAHsul.d.mts → index-CRmE88hi.d.mts} +0 -0
- /package/dist/{index-CjdRdsd0.d.mts → index-CvW9_SzR.d.mts} +0 -0
- /package/dist/{index-ByKi34v5.d.mts → index-CxSSdIZz.d.mts} +0 -0
- /package/dist/{index-vcSj12YQ.d.mts → index-E4SET1AA.d.mts} +0 -0
- /package/dist/{index-DN4NOCqN2.d.mts → index-Ol9RBB0W2.d.mts} +0 -0
- /package/dist/{index-BIdsFcQs2.d.mts → index-aoxdnhJ42.d.mts} +0 -0
- /package/dist/{index-SsBHjUqA.d.mts → index-nydhGvXa.d.mts} +0 -0
- /package/dist/{jsonl-transport-bQl3JwIu.mjs → jsonl-transport-Bp_6pB2a.mjs} +0 -0
- /package/dist/{lib-DOBXZmYX.mjs → lib-Bwdd2m81.mjs} +0 -0
- /package/dist/{model-registry-CmgcPDH3.mjs → model-registry-Y854mUml.mjs} +0 -0
- /package/dist/{model-registry-xyBKSye-.mjs → model-registry-yURX738J.mjs} +0 -0
- /package/dist/{modes-BheyN7SS.mjs → modes-DmUsjHdV.mjs} +0 -0
- /package/dist/{namespace-HO2J9sO8.mjs → namespace-B9FEGuEu.mjs} +0 -0
- /package/dist/{namespace-jDhZjw-i.d.mts → namespace-Bi3CmYQy.d.mts} +0 -0
- /package/dist/{namespace-GPA7zots.d.mts → namespace-BusZERU8.d.mts} +0 -0
- /package/dist/{namespace-BOkKoq34.d.mts → namespace-ByP1Iipi.d.mts} +0 -0
- /package/dist/{namespace-YytVKIgI.d.mts → namespace-C1D77w7U.d.mts} +0 -0
- /package/dist/{namespace-CErHuXtb.d.mts → namespace-C6CVEGH8.d.mts} +0 -0
- /package/dist/{namespace-C-9si-fV.mjs → namespace-CfIW0hpQ.mjs} +0 -0
- /package/dist/{namespace-YxU1xf-K.mjs → namespace-CkBbNFSU.mjs} +0 -0
- /package/dist/{namespace-DWCEo-9M.d.mts → namespace-DX1Ec15L.d.mts} +0 -0
- /package/dist/{namespace-CWGKCNZm.mjs → namespace-DbNWsPFY.mjs} +0 -0
- /package/dist/{namespace-Cv1RFP7n.d.mts → namespace-Dgg0uoe6.d.mts} +0 -0
- /package/dist/{namespace-tGRAod3o.d.mts → namespace-s2y_NFKf.d.mts} +0 -0
- /package/dist/{namespace-Blp4c8GK.d.mts → namespace-yREpGJgG.d.mts} +0 -0
- /package/dist/{out-CvjtANXN.mjs → out-DrhwCgqM.mjs} +0 -0
- /package/dist/{packages-DtEEP0Vt.mjs → packages-FBv3fAOR.mjs} +0 -0
- /package/dist/{packages-BZ6pzFIq.d.mts → packages-N3-2Kl-Y.d.mts} +0 -0
- /package/dist/{platform-Bv8llU9c.mjs → platform-BrsMv_S3.mjs} +0 -0
- /package/dist/{provider-operation-Cxoe2SUr.d.mts → provider-operation-DJ_TLZFf.d.mts} +0 -0
- /package/dist/{providers-Co5UszRH.mjs → providers-CCcn4Ndp.mjs} +0 -0
- /package/dist/{providers-namespace-DjFkmvBR.d.mts → providers-namespace-DeJBh6MP.d.mts} +0 -0
- /package/dist/{quick-lru-CrOpWwrf.mjs → quick-lru-uwB0hP-y.mjs} +0 -0
- /package/dist/{schema-introspection-DgWQCpwx.mjs → schema-introspection-C1wvklj9.mjs} +0 -0
- /package/dist/{schema-Db-y-09L.mjs → schema-jIapW8Kb.mjs} +0 -0
- /package/dist/{schemas-CR8hSqTy.d.mts → schemas-B7zo7Zcx.d.mts} +0 -0
- /package/dist/{schemas-CqRm0i9a.mjs → schemas-BNdiVBWh.mjs} +0 -0
- /package/dist/{schemas-B1NWNASS.d.mts → schemas-C-Bm6Oac.d.mts} +0 -0
- /package/dist/{schemas-BO7uOum6.d.mts → schemas-CD0wOQxx.d.mts} +0 -0
- /package/dist/{schemas-N6x2z7Lf.d.mts → schemas-CeUI2i5j.d.mts} +0 -0
- /package/dist/{schemas-CwbYk_kZ.d.mts → schemas-Cg-Kwp8c.d.mts} +0 -0
- /package/dist/{schemas-BtZqovRH.d.mts → schemas-Cv3rR9Sz.d.mts} +0 -0
- /package/dist/{schemas-tDf_WiC8.mjs → schemas-CvHFbzdy.mjs} +0 -0
- /package/dist/{schemas-BsVYZviy.d.mts → schemas-DZH9lpxs.d.mts} +0 -0
- /package/dist/{schemas-BGExwp3j.mjs → schemas-DgwEVUt-.mjs} +0 -0
- /package/dist/{schemas-Bfxskx_2.mjs → schemas-mLpOfMoN.mjs} +0 -0
- /package/dist/{schemas-CQyRBqD6.d.mts → schemas-qA279_j_.d.mts} +0 -0
- /package/dist/{schemas-miYxK_Z1.d.mts → schemas-sMoRnBdZ.d.mts} +0 -0
- /package/dist/{semver-DlM8znk4.mjs → semver-DTXuyLcK.mjs} +0 -0
- /package/dist/{server-lifecycle-Dsq56aqC.d.mts → server-lifecycle-C_8iKgat.d.mts} +0 -0
- /package/dist/{server-lifecycle-kmQ5PUDv.mjs → server-lifecycle-DKx_fWlq.mjs} +0 -0
- /package/dist/{shared-schemas-DXwyMCwZ.mjs → shared-schemas-aahW97QW.mjs} +0 -0
- /package/dist/{src-CCu8TwL6.mjs → src-DHqsl5Pg.mjs} +0 -0
- /package/dist/{storage-namespace-BSrv0vXR.mjs → storage-namespace-Dz2jsssp.mjs} +0 -0
- /package/dist/{storage-namespace-dfywhXR3.d.mts → storage-namespace-Tf3P5yJ5.d.mts} +0 -0
- /package/dist/{storage-namespace-definition-BvlX0QV_.d.mts → storage-namespace-definition-BsnYAPot.d.mts} +0 -0
- /package/dist/{storage-namespace-definition-CkMKt7-I.mjs → storage-namespace-definition-CDef0E20.mjs} +0 -0
- /package/dist/{supports-color-DUugCQsK.mjs → supports-color-i7OTnKcZ.mjs} +0 -0
- /package/dist/{telemetry-Pr3oP2rk.mjs → telemetry-BvCBUjFg.mjs} +0 -0
- /package/dist/{timeout-DWDhddRJ.mjs → timeout-B0nYjLc8.mjs} +0 -0
- /package/dist/{tray-menu-service-BBLa-Rcv.mjs → tray-menu-service-Deo6yyP8.mjs} +0 -0
- /package/dist/{types-BrcjaNPZ.d.mts → types-CNS55jvt.d.mts} +0 -0
- /package/dist/{types-b54n1o57.d.mts → types-Ce6LL25v.d.mts} +0 -0
- /package/dist/{types-DHmPneIO.d.mts → types-xCdGghb2.d.mts} +0 -0
- /package/dist/{ui-config-CyCdlns_.mjs → ui-config-BIyGzMNL.mjs} +0 -0
- /package/dist/{variant-krjlTdJt.mjs → variant-B4uWdxW7.mjs} +0 -0
- /package/dist/{window-registry-BDnZLPVx.d.mts → window-registry-BLtVx3Iw.d.mts} +0 -0
- /package/dist/{window-registry-I-imZHV_.mjs → window-registry-CoBJq3u4.mjs} +0 -0
|
@@ -0,0 +1,2917 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DeferredPromise, TimeoutConfig, TrackedTimeoutConfig } from "@makaio/framework/utils";
|
|
3
|
+
import { AuthenticationError, ExtractSubjectPayload, ExtractSubjectResponse, HandlerForSubjectDefinition, ScopedSubjectDefinition, SubjectRecord } from "@makaio/framework/core";
|
|
4
|
+
import { IFilteredBus, IMakaioBus, OnOptions, ScopedBus } from "@makaio/framework/bus";
|
|
5
|
+
import { AIModel, AIReasoningLevel, AIReasoningLevel as AIReasoningLevel$1, AdapterAuthBinding, AdapterAuthConstant, AdapterProviderAuth, AdapterProviderDefinitionContract, AgentSchemas, AgentSubjects, AuthCredentialRef, CacheStrategy, ConnectorTeardownResult, JsonValue, McpRuntimeSessionContext, McpSessionContext, McpToolState, Message, MessageBlock, MessageDeliveryMode, MessageDeliveryMode as MessageDeliveryMode$1, MessageInput, MessageOutcome, NativeForkDirective, ProtocolId, ProviderContext, ReasoningLevelMap as ReasoningLevelMap$1, RequestCorrelationContext, ResolvedProviderAuth, ResponseSchemaDescriptor, SendMessageResultInnerResult, SessionContext, StructuredOutputValidation, SystemPrompt, TeardownEvidence, ToolListItem } from "@makaio/framework/contracts";
|
|
6
|
+
import { ClientExecutionContext } from "@makaio/framework/contracts/client";
|
|
7
|
+
import { SetRequired } from "type-fest";
|
|
8
|
+
|
|
9
|
+
//#region adapters/core/src/agent/session-tool-ledger.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Single tool tracked in the session ledger.
|
|
12
|
+
* Accumulates injection, discovery, and call history across the session lifetime.
|
|
13
|
+
*/
|
|
14
|
+
interface ToolLedgerEntry {
|
|
15
|
+
/** Namespaced tool name, e.g. "github__create_issue" */
|
|
16
|
+
readonly fullName: string;
|
|
17
|
+
/** Original tool name without server prefix, e.g. "create_issue" */
|
|
18
|
+
readonly originalName: string;
|
|
19
|
+
/** MCP server that provides the tool, e.g. "github" */
|
|
20
|
+
readonly serverName: string;
|
|
21
|
+
/** Whether the tool is currently in the direct-injection set */
|
|
22
|
+
injected: boolean;
|
|
23
|
+
/** Turn number when this tool was last included in the injection set */
|
|
24
|
+
lastInjectedAtTurn: number | undefined;
|
|
25
|
+
/** Whether the model has seen this tool via mcp_discover or mcp_call */
|
|
26
|
+
discovered: boolean;
|
|
27
|
+
/** Turn number when this tool was first discovered (set once, never overwritten) */
|
|
28
|
+
firstDiscoveredAtTurn: number | undefined;
|
|
29
|
+
/** Total number of mcp_call invocations across the session */
|
|
30
|
+
callCount: number;
|
|
31
|
+
/** Turn number of the most recent mcp_call invocation */
|
|
32
|
+
lastCalledAtTurn: number | undefined;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Narrowed view of McpSessionContext that the ledger needs.
|
|
36
|
+
* Decouples the ledger from the full session context shape.
|
|
37
|
+
*/
|
|
38
|
+
interface LedgerSessionContext {
|
|
39
|
+
/** Tools resolved for direct injection in this session */
|
|
40
|
+
readonly directTools: readonly McpToolState[];
|
|
41
|
+
/** Tools available for discovery (not direct-injected) */
|
|
42
|
+
readonly discoverableTools: readonly McpToolState[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Public contract for the session-scoped tool ledger.
|
|
46
|
+
* Tracks injection, discovery, and call state for all MCP tools during a session.
|
|
47
|
+
*/
|
|
48
|
+
interface ISessionToolLedger {
|
|
49
|
+
/**
|
|
50
|
+
* Replace the current injection set with the provided list.
|
|
51
|
+
* Tools not in the new list have their `injected` flag cleared (eviction sweep).
|
|
52
|
+
* @param tools - The new set of directly-injected tools
|
|
53
|
+
* @param turnNumber - The current turn number
|
|
54
|
+
*/
|
|
55
|
+
recordInjection(tools: readonly ToolListItem[], turnNumber: number): void;
|
|
56
|
+
/**
|
|
57
|
+
* Record that the model discovered a tool.
|
|
58
|
+
* Applies first-discovery semantics: `firstDiscoveredAtTurn` is set only once.
|
|
59
|
+
* @param toolFullName - The namespaced tool name, e.g. "github__create_issue"
|
|
60
|
+
* @param turnNumber - The current turn number
|
|
61
|
+
*/
|
|
62
|
+
recordDiscovery(toolFullName: string, turnNumber: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Record one mcp_call invocation for a tool.
|
|
65
|
+
* Implies discovery: also sets `discovered` and `firstDiscoveredAtTurn` if unset.
|
|
66
|
+
* @param toolFullName - The namespaced tool name, e.g. "github__create_issue"
|
|
67
|
+
* @param turnNumber - The current turn number
|
|
68
|
+
*/
|
|
69
|
+
recordCall(toolFullName: string, turnNumber: number): void;
|
|
70
|
+
/**
|
|
71
|
+
* Return all entries where `injected === true`.
|
|
72
|
+
* @returns Snapshot of currently-injected tool entries
|
|
73
|
+
*/
|
|
74
|
+
getInjectedTools(): readonly ToolLedgerEntry[];
|
|
75
|
+
/**
|
|
76
|
+
* Return the total call count for a tool, or 0 if not tracked.
|
|
77
|
+
* @param toolFullName - The namespaced tool name
|
|
78
|
+
* @returns Call count (0 for unknown tools)
|
|
79
|
+
*/
|
|
80
|
+
getCallCount(toolFullName: string): number;
|
|
81
|
+
/**
|
|
82
|
+
* Return a single ledger entry by full name, or undefined if not tracked.
|
|
83
|
+
* @param toolFullName - The namespaced tool name
|
|
84
|
+
* @returns The entry, or undefined
|
|
85
|
+
*/
|
|
86
|
+
getEntry(toolFullName: string): ToolLedgerEntry | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Return all tracked entries regardless of state.
|
|
89
|
+
* @returns Snapshot of all ledger entries
|
|
90
|
+
*/
|
|
91
|
+
getAllEntries(): readonly ToolLedgerEntry[];
|
|
92
|
+
/**
|
|
93
|
+
* Phase 2 seam: suggest the optimal injection set for the next turn.
|
|
94
|
+
* Phase 1 pass-through: returns `context.directTools` mapped to ToolListItem format.
|
|
95
|
+
* @param context - Current session context providing direct and discoverable tools
|
|
96
|
+
* @param currentTurnNumber - The current turn number (for future scoring heuristics)
|
|
97
|
+
* @returns Suggested list of tools to inject for the next turn
|
|
98
|
+
*/
|
|
99
|
+
suggestInjectionSet(context: LedgerSessionContext, currentTurnNumber: number): Promise<readonly ToolListItem[]>;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Agent-scoped ledger that tracks every MCP tool's injection, discovery, and
|
|
103
|
+
* call history within a single agent lifecycle.
|
|
104
|
+
*
|
|
105
|
+
* One instance is created per agent factory call and discarded when
|
|
106
|
+
* the agent is torn down. If the adapter switches connectors mid-session
|
|
107
|
+
* (e.g. model swap), the same ledger is passed to the new connector so
|
|
108
|
+
* history is preserved across the connector boundary.
|
|
109
|
+
*
|
|
110
|
+
* Follows the same plain-class, no-bus pattern as {@link ToolCallTracker}.
|
|
111
|
+
*/
|
|
112
|
+
declare class SessionToolLedger implements ISessionToolLedger {
|
|
113
|
+
private readonly entries;
|
|
114
|
+
/**
|
|
115
|
+
* Upsert an entry for the given full name, creating it if absent.
|
|
116
|
+
* @param fullName - Namespaced tool name
|
|
117
|
+
* @returns The existing or newly-created entry (mutable reference)
|
|
118
|
+
*/
|
|
119
|
+
private upsert;
|
|
120
|
+
/**
|
|
121
|
+
* Replace the current injection set with the provided list.
|
|
122
|
+
* Tools absent from the new list have their `injected` flag cleared (eviction sweep).
|
|
123
|
+
* @param tools - The new set of directly-injected tools
|
|
124
|
+
* @param turnNumber - The current turn number
|
|
125
|
+
*/
|
|
126
|
+
recordInjection(tools: readonly ToolListItem[], turnNumber: number): void;
|
|
127
|
+
/**
|
|
128
|
+
* Record that the model discovered a tool.
|
|
129
|
+
* Applies first-discovery semantics: `firstDiscoveredAtTurn` is only set once.
|
|
130
|
+
* @param toolFullName - The namespaced tool name, e.g. "github__create_issue"
|
|
131
|
+
* @param turnNumber - The current turn number
|
|
132
|
+
*/
|
|
133
|
+
recordDiscovery(toolFullName: string, turnNumber: number): void;
|
|
134
|
+
/**
|
|
135
|
+
* Record one mcp_call invocation for a tool.
|
|
136
|
+
* Implies discovery: also sets `discovered` and `firstDiscoveredAtTurn` if unset.
|
|
137
|
+
* @param toolFullName - The namespaced tool name, e.g. "github__create_issue"
|
|
138
|
+
* @param turnNumber - The current turn number
|
|
139
|
+
*/
|
|
140
|
+
recordCall(toolFullName: string, turnNumber: number): void;
|
|
141
|
+
/**
|
|
142
|
+
* Return all entries where `injected === true`.
|
|
143
|
+
* @returns Snapshot of currently-injected tool entries
|
|
144
|
+
*/
|
|
145
|
+
getInjectedTools(): readonly ToolLedgerEntry[];
|
|
146
|
+
/**
|
|
147
|
+
* Return the total call count for a tool, or 0 if not tracked.
|
|
148
|
+
* @param toolFullName - The namespaced tool name
|
|
149
|
+
* @returns Call count (0 for unknown tools)
|
|
150
|
+
*/
|
|
151
|
+
getCallCount(toolFullName: string): number;
|
|
152
|
+
/**
|
|
153
|
+
* Return a single ledger entry by full name, or undefined if not tracked.
|
|
154
|
+
* @param toolFullName - The namespaced tool name
|
|
155
|
+
* @returns The entry, or undefined
|
|
156
|
+
*/
|
|
157
|
+
getEntry(toolFullName: string): ToolLedgerEntry | undefined;
|
|
158
|
+
/**
|
|
159
|
+
* Return all tracked entries regardless of state.
|
|
160
|
+
* @returns Snapshot of all ledger entries
|
|
161
|
+
*/
|
|
162
|
+
getAllEntries(): readonly ToolLedgerEntry[];
|
|
163
|
+
/**
|
|
164
|
+
* Phase 1 pass-through: return `context.directTools` mapped to ToolListItem format.
|
|
165
|
+
* Phase 2 will replace this with a scoring heuristic that factors in call history
|
|
166
|
+
* and discovery patterns.
|
|
167
|
+
* @param context - Current session context providing direct and discoverable tools
|
|
168
|
+
* @param _currentTurnNumber - The current turn number (reserved for Phase 2 scoring heuristics)
|
|
169
|
+
* @returns Suggested list of tools to inject for the next turn
|
|
170
|
+
*/
|
|
171
|
+
suggestInjectionSet(context: LedgerSessionContext, _currentTurnNumber: number): Promise<readonly ToolListItem[]>;
|
|
172
|
+
}
|
|
173
|
+
//#endregion
|
|
174
|
+
//#region node_modules/emittery/index.d.ts
|
|
175
|
+
/**
|
|
176
|
+
Removes an event subscription.
|
|
177
|
+
*/
|
|
178
|
+
type UnsubscribeFunction = () => void;
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region adapters/core/src/message-handle/types.d.ts
|
|
181
|
+
/**
|
|
182
|
+
* Result of a message operation.
|
|
183
|
+
*/
|
|
184
|
+
type MessageResult = {
|
|
185
|
+
result?: SendMessageResultInnerResult | null;
|
|
186
|
+
error?: Error | string;
|
|
187
|
+
outcome: MessageOutcome; /** Present when outcome='superseded': the messageId that replaced this one */
|
|
188
|
+
supersededBy?: string; /** Present when outcome='merged': the messageId this was folded into */
|
|
189
|
+
mergedInto?: string;
|
|
190
|
+
/**
|
|
191
|
+
* Structured-output validation result for this turn.
|
|
192
|
+
* Present only when a {@link ResponseSchemaDescriptor} was active and validation ran.
|
|
193
|
+
*/
|
|
194
|
+
structuredOutputValidation?: StructuredOutputValidation;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Lifecycle states for a queued message.
|
|
198
|
+
*/
|
|
199
|
+
type MessageState = 'queued' | 'acknowledged' | 'completed' | 'cancelled';
|
|
200
|
+
/**
|
|
201
|
+
* Options for sending a message.
|
|
202
|
+
*/
|
|
203
|
+
interface SendMessageOptions {
|
|
204
|
+
/**
|
|
205
|
+
* Custom identifier for message tracking (generated if not provided).
|
|
206
|
+
*/
|
|
207
|
+
messageId?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Controls delivery behavior.
|
|
210
|
+
* @defaultValue 'enqueue'
|
|
211
|
+
*/
|
|
212
|
+
deliveryMode?: MessageDeliveryMode;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Options bag used when creating a message handle.
|
|
216
|
+
*
|
|
217
|
+
* Passed to {@link MessageHandle} via `AIAgentConnector.createMessageHandle`.
|
|
218
|
+
*/
|
|
219
|
+
interface MessageHandleOptions {
|
|
220
|
+
/** Optional stable message identifier; autogenerated when omitted. */
|
|
221
|
+
messageId?: string;
|
|
222
|
+
/** Optional delivery semantics for queue processing. */
|
|
223
|
+
deliveryMode?: MessageDeliveryMode;
|
|
224
|
+
/** Optional prior conversation messages to materialize for the turn. */
|
|
225
|
+
messageHistory?: Message[];
|
|
226
|
+
/** Optional per-turn metadata/context payload for prompt materialization. */
|
|
227
|
+
turnContext?: Record<string, JsonValue>;
|
|
228
|
+
/** Content-free transport context that must never be added to model input. */
|
|
229
|
+
requestCorrelation?: RequestCorrelationContext;
|
|
230
|
+
/** Caller-expressed caching intent for the injected history prefix. */
|
|
231
|
+
cacheStrategy?: CacheStrategy;
|
|
232
|
+
/**
|
|
233
|
+
* Per-turn structured-output schema descriptor.
|
|
234
|
+
* When set, the agent's structured-output manager validates the terminal
|
|
235
|
+
* message against this schema before emitting completion events.
|
|
236
|
+
*/
|
|
237
|
+
responseSchema?: ResponseSchemaDescriptor;
|
|
238
|
+
/**
|
|
239
|
+
* Whether this message handle was created for an internal retry turn.
|
|
240
|
+
* When `true`, the `onMessageSent` callback is suppressed so no
|
|
241
|
+
* `user_message.sent` event is emitted for the synthetic retry message.
|
|
242
|
+
*/
|
|
243
|
+
internalRetry?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Lifecycle turnId from the session orchestrator. Distinct from
|
|
246
|
+
* `requestCorrelation.turnId` (transport correlation, which may be present
|
|
247
|
+
* when no lifecycle turn exists): all user_message lifecycle events for the
|
|
248
|
+
* handle pair by this value.
|
|
249
|
+
*/
|
|
250
|
+
turnId?: string;
|
|
251
|
+
/**
|
|
252
|
+
* Caller decision on provider-native session resume for this dispatch.
|
|
253
|
+
* When `false`, the session layer must not arm its pending start-time
|
|
254
|
+
* resume target for the turn this handle drives (see
|
|
255
|
+
* `ConnectorSendMessageOptions.useNativeResume` for the full contract).
|
|
256
|
+
*/
|
|
257
|
+
useNativeResume?: boolean;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Processing state for agent orchestration.
|
|
261
|
+
*/
|
|
262
|
+
type ProcessingState = 'idle' | 'processing_started' | 'turn_started' | 'step_started' | 'step_finished' | 'turn_finished' | 'processing_finished' | 'active' | 'paused';
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region adapters/core/src/utils/normalizeMessageInput.d.ts
|
|
265
|
+
type NormalizedMessageInput = Required<Message> & {
|
|
266
|
+
blocks: MessageBlock[];
|
|
267
|
+
message?: string;
|
|
268
|
+
};
|
|
269
|
+
/**
|
|
270
|
+
* Normalizes various MessageInput formats into a consistent structure with blocks and optional message text.
|
|
271
|
+
* @param input - The message input to normalize (string or Message object)
|
|
272
|
+
* @returns Normalized message with role, blocks array, and optional message text
|
|
273
|
+
*/
|
|
274
|
+
declare function normalizeMessageInput(input: MessageInput): NormalizedMessageInput;
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region adapters/core/src/message-handle/message-handle.d.ts
|
|
277
|
+
type CompletionTransform = (result: MessageResult) => MessageResult | Promise<MessageResult>;
|
|
278
|
+
type CompletionObserver = (result: MessageResult) => void;
|
|
279
|
+
type CompletionNotification = (handle: MessageHandle, result: MessageResult) => void | Promise<void>;
|
|
280
|
+
declare class MessageHandle {
|
|
281
|
+
readonly messageId: string;
|
|
282
|
+
readonly message: NormalizedMessageInput;
|
|
283
|
+
readonly deliveryMode: MessageDeliveryMode;
|
|
284
|
+
/**
|
|
285
|
+
* Per-turn structured-output schema descriptor.
|
|
286
|
+
* When present, the agent validates the terminal message against this
|
|
287
|
+
* schema before resolving completion and emitting terminal events.
|
|
288
|
+
*/
|
|
289
|
+
readonly responseSchema?: ResponseSchemaDescriptor | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* Internal structured-output retry turns must stay hidden from user-message
|
|
292
|
+
* lifecycle events while still taking precedence over queued user turns.
|
|
293
|
+
*/
|
|
294
|
+
readonly internalRetry: boolean;
|
|
295
|
+
/** Content-free transport correlation for provider requests. */
|
|
296
|
+
readonly requestCorrelation?: RequestCorrelationContext | undefined;
|
|
297
|
+
/**
|
|
298
|
+
* Lifecycle turnId from the session orchestrator (`agent.sendMessage.turnId`).
|
|
299
|
+
* Distinct from `requestCorrelation.turnId`, which is transport correlation
|
|
300
|
+
* and may be present when no lifecycle turn exists. All user_message
|
|
301
|
+
* lifecycle events for this handle (sent/acknowledged/completed) pair by
|
|
302
|
+
* this value.
|
|
303
|
+
*/
|
|
304
|
+
readonly turnId?: string | undefined;
|
|
305
|
+
/**
|
|
306
|
+
* Caller decision on provider-native session resume for this dispatch.
|
|
307
|
+
* When `false`, the session layer must not arm its pending start-time
|
|
308
|
+
* resume target for the turn this handle drives (see
|
|
309
|
+
* `ConnectorSendMessageOptions.useNativeResume` for the full contract).
|
|
310
|
+
*/
|
|
311
|
+
readonly useNativeResume?: boolean | undefined;
|
|
312
|
+
protected readonly deferredCompletion: DeferredPromise<MessageResult>;
|
|
313
|
+
protected readonly deferredAcknowledgement: DeferredPromise<boolean>;
|
|
314
|
+
state: MessageState;
|
|
315
|
+
private isAcknowledged;
|
|
316
|
+
private completionResult;
|
|
317
|
+
private completionStarted;
|
|
318
|
+
private readonly completionTransforms;
|
|
319
|
+
private readonly completionObservers;
|
|
320
|
+
/** If this message was merged into another, the winner's messageId */
|
|
321
|
+
mergedInto?: string;
|
|
322
|
+
/** If this is the merge winner, messageIds that were folded in */
|
|
323
|
+
mergedFrom?: string[];
|
|
324
|
+
/** If this message was superseded by replace/immediate, the replacer's messageId */
|
|
325
|
+
supersededBy?: string;
|
|
326
|
+
/** Adapter session ID - resolved when processing starts */
|
|
327
|
+
private readonly deferredAdapterSessionId;
|
|
328
|
+
private _adapterSessionId?;
|
|
329
|
+
/** Curated message history from sessionContext (mutable for merge propagation) */
|
|
330
|
+
private _messageHistory?;
|
|
331
|
+
/** Shared cache strategy type from contracts keeps handle options and session context aligned. */
|
|
332
|
+
private _cacheStrategy?;
|
|
333
|
+
/** Turn-scoped context from PreUserMessage hooks (mutable for merge propagation) */
|
|
334
|
+
private _turnContext?;
|
|
335
|
+
constructor(messageId: string, message: NormalizedMessageInput, deliveryMode: MessageDeliveryMode, /** Curated message history from sessionContext */
|
|
336
|
+
|
|
337
|
+
messageHistory?: Message[], /** Turn-scoped context from PreUserMessage hooks */
|
|
338
|
+
|
|
339
|
+
turnContext?: Record<string, JsonValue>,
|
|
340
|
+
/**
|
|
341
|
+
* Per-turn structured-output schema descriptor.
|
|
342
|
+
* When present, the agent validates the terminal message against this
|
|
343
|
+
* schema before resolving completion and emitting terminal events.
|
|
344
|
+
*/
|
|
345
|
+
|
|
346
|
+
responseSchema?: ResponseSchemaDescriptor | undefined,
|
|
347
|
+
/**
|
|
348
|
+
* Internal structured-output retry turns must stay hidden from user-message
|
|
349
|
+
* lifecycle events while still taking precedence over queued user turns.
|
|
350
|
+
*/
|
|
351
|
+
|
|
352
|
+
internalRetry?: boolean, /** Caller-expressed caching intent for the injected history prefix */
|
|
353
|
+
|
|
354
|
+
cacheStrategy?: CacheStrategy, /** Content-free transport correlation for provider requests. */
|
|
355
|
+
|
|
356
|
+
requestCorrelation?: RequestCorrelationContext | undefined,
|
|
357
|
+
/**
|
|
358
|
+
* Lifecycle turnId from the session orchestrator (`agent.sendMessage.turnId`).
|
|
359
|
+
* Distinct from `requestCorrelation.turnId`, which is transport correlation
|
|
360
|
+
* and may be present when no lifecycle turn exists. All user_message
|
|
361
|
+
* lifecycle events for this handle (sent/acknowledged/completed) pair by
|
|
362
|
+
* this value.
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
turnId?: string | undefined,
|
|
366
|
+
/**
|
|
367
|
+
* Caller decision on provider-native session resume for this dispatch.
|
|
368
|
+
* When `false`, the session layer must not arm its pending start-time
|
|
369
|
+
* resume target for the turn this handle drives (see
|
|
370
|
+
* `ConnectorSendMessageOptions.useNativeResume` for the full contract).
|
|
371
|
+
*/
|
|
372
|
+
|
|
373
|
+
useNativeResume?: boolean | undefined);
|
|
374
|
+
/**
|
|
375
|
+
* Curated message history from sessionContext
|
|
376
|
+
* @returns The message history array or undefined if not set
|
|
377
|
+
*/
|
|
378
|
+
get messageHistory(): Message[] | undefined;
|
|
379
|
+
/** Set messageHistory (used by merge strategies to propagate history) */
|
|
380
|
+
set messageHistory(value: Message[] | undefined);
|
|
381
|
+
/**
|
|
382
|
+
* Caller-expressed caching intent for the injected history prefix
|
|
383
|
+
* @returns The cache strategy or undefined if not set
|
|
384
|
+
*/
|
|
385
|
+
get cacheStrategy(): CacheStrategy | undefined;
|
|
386
|
+
/** Set cacheStrategy (used by merge strategies to propagate) */
|
|
387
|
+
set cacheStrategy(value: CacheStrategy | undefined);
|
|
388
|
+
/**
|
|
389
|
+
* Turn-scoped context from PreUserMessage hooks
|
|
390
|
+
* @returns The turn context record or undefined if not set
|
|
391
|
+
*/
|
|
392
|
+
get turnContext(): Record<string, JsonValue> | undefined;
|
|
393
|
+
/** Set turnContext (used by merge strategies to propagate context) */
|
|
394
|
+
set turnContext(value: Record<string, JsonValue> | undefined);
|
|
395
|
+
/**
|
|
396
|
+
* Get adapter session ID synchronously (undefined if not yet set)
|
|
397
|
+
* @returns The adapter session ID or undefined if not yet set
|
|
398
|
+
*/
|
|
399
|
+
get adapterSessionId(): string | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Set adapter session ID (called by connector when processing starts)
|
|
402
|
+
*/
|
|
403
|
+
set adapterSessionId(value: string | undefined);
|
|
404
|
+
/**
|
|
405
|
+
* Wait for adapter session ID to be set
|
|
406
|
+
* @returns Promise resolving to session ID when processing starts
|
|
407
|
+
*/
|
|
408
|
+
waitForAdapterSessionId(): Promise<string>;
|
|
409
|
+
/**
|
|
410
|
+
* Whether the message was successfully delivered to the provider.
|
|
411
|
+
*
|
|
412
|
+
* Returns `true` only when {@link markAcknowledged} was called with
|
|
413
|
+
* `delivered = true` (the default). Handles that were completed before
|
|
414
|
+
* dispatch (merged, superseded, rejected) auto-resolve acknowledgment
|
|
415
|
+
* with `false`, so this getter returns `false` for them.
|
|
416
|
+
*
|
|
417
|
+
* Used by {@link MessageLifecycleTracker} to decide whether
|
|
418
|
+
* `agent.turn.completed` should pair with an earlier `agent.turn.started`.
|
|
419
|
+
* @returns `true` when the handle was acknowledged as delivered
|
|
420
|
+
*/
|
|
421
|
+
get wasDelivered(): boolean;
|
|
422
|
+
get isProcessed(): boolean;
|
|
423
|
+
getState(): MessageState;
|
|
424
|
+
/**
|
|
425
|
+
* Update message state
|
|
426
|
+
* @param state - New message state
|
|
427
|
+
*/
|
|
428
|
+
updateState(state: MessageState): void;
|
|
429
|
+
/**
|
|
430
|
+
* Cancel a pending message
|
|
431
|
+
* @returns True if cancelled, false if already submitted/completed
|
|
432
|
+
*/
|
|
433
|
+
cancel(): Promise<boolean>;
|
|
434
|
+
/**
|
|
435
|
+
* Mark message as acknowledged
|
|
436
|
+
* @param delivered - Whether message was successfully delivered to provider
|
|
437
|
+
* (e.g. false if immediate message arrived too late)
|
|
438
|
+
*/
|
|
439
|
+
markAcknowledged(delivered?: boolean): void;
|
|
440
|
+
/**
|
|
441
|
+
* Register a transform that canonicalizes the terminal result before
|
|
442
|
+
* {@link waitForCompletion} resolves.
|
|
443
|
+
* @param transform - Transform applied to the raw provider completion result
|
|
444
|
+
*/
|
|
445
|
+
addCompletionTransform(transform: CompletionTransform): void;
|
|
446
|
+
/**
|
|
447
|
+
* Register an observer that runs after all completion transforms have
|
|
448
|
+
* produced the canonical terminal result, but before completion resolves.
|
|
449
|
+
* @param observer - Observer called with the final completion result
|
|
450
|
+
*/
|
|
451
|
+
addCompletionObserver(observer: CompletionObserver): void;
|
|
452
|
+
/**
|
|
453
|
+
* Mark message turn as completed
|
|
454
|
+
* @param result - The result message or null if no result available
|
|
455
|
+
*/
|
|
456
|
+
markCompleted(result: MessageResult): void;
|
|
457
|
+
/**
|
|
458
|
+
* Apply registered completion transforms and publish the canonical result.
|
|
459
|
+
* @param result - Raw provider completion result
|
|
460
|
+
*/
|
|
461
|
+
private resolveCompletion;
|
|
462
|
+
/**
|
|
463
|
+
* Notify registered completion observers without changing terminal outcome.
|
|
464
|
+
* @param result - Canonical completion result
|
|
465
|
+
*/
|
|
466
|
+
private notifyCompletionObservers;
|
|
467
|
+
waitForAcknowledgment(timeoutMs?: number): Promise<boolean>;
|
|
468
|
+
waitForCompletion(timeoutMs?: number): Promise<MessageResult>;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Complete a handle while notifying a callback with the transformed final result.
|
|
472
|
+
*
|
|
473
|
+
* `markCompleted()` starts async completion transforms before resolving
|
|
474
|
+
* waiters. Connector/session layers that cache `lastResult` must observe the
|
|
475
|
+
* final transformed value, not the raw provider result they pass into
|
|
476
|
+
* `markCompleted()`.
|
|
477
|
+
* @param handle - Message handle being completed
|
|
478
|
+
* @param result - Raw provider completion result
|
|
479
|
+
* @param onComplete - Optional notification callback receiving the final result
|
|
480
|
+
* @returns Promise that settles after the final-result callback completes
|
|
481
|
+
*/
|
|
482
|
+
declare function markCompletedWithFinalResult(handle: MessageHandle, result: MessageResult, onComplete?: CompletionNotification): Promise<void>;
|
|
483
|
+
//#endregion
|
|
484
|
+
//#region adapters/core/src/connector/agent-connector.d.ts
|
|
485
|
+
type Forbid<T, K extends PropertyKey> = Omit<T, K> & { [P in K]?: never };
|
|
486
|
+
type ForbiddenKeys = 'agentId' | 'adapterId' | 'adapterSessionId' | 'adapterName' | 'sessionId';
|
|
487
|
+
/** Extract Subjects type parameter from a ScopedBus */
|
|
488
|
+
type ExtractScopedBusSubjects<T> = T extends {
|
|
489
|
+
withFilter: (...args: unknown[]) => IFilteredBus<string, infer S>;
|
|
490
|
+
} ? S : T extends ScopedBus<string, infer S> ? S : SubjectRecord;
|
|
491
|
+
/**
|
|
492
|
+
* Abstract base class for AI agent implementations.
|
|
493
|
+
*
|
|
494
|
+
* Each adapter provides its own message queue implementation (UserMessageQueue).
|
|
495
|
+
* This base class provides common infrastructure for state management, bus operations,
|
|
496
|
+
* and error handling.
|
|
497
|
+
* @typeParam TBus - Scoped bus type for adapter namespace
|
|
498
|
+
*/
|
|
499
|
+
declare abstract class AIAgentConnector<TBus extends ScopedBus<string> = ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> {
|
|
500
|
+
/** Unique identifier for this agent instance. */
|
|
501
|
+
protected readonly agentId: string;
|
|
502
|
+
/** Session ID from the provider (set after connection/start). */
|
|
503
|
+
adapterSessionId?: string;
|
|
504
|
+
/** Makaio session ID for cross-session correlation and approval routing. */
|
|
505
|
+
protected readonly sessionId?: string;
|
|
506
|
+
/** Currently active message handle waiting for completion. */
|
|
507
|
+
protected pendingMessageHandle?: MessageHandle;
|
|
508
|
+
/** Scoped event bus for adapter-specific emission; global bus owns cross-namespace runtime requests. */
|
|
509
|
+
private readonly scopedBus;
|
|
510
|
+
protected readonly globalBus: IMakaioBus;
|
|
511
|
+
/** Filtered event bus for agent-specific (filtered by agentId) message handling. */
|
|
512
|
+
private readonly filteredBus;
|
|
513
|
+
/** Optional error handler callback. */
|
|
514
|
+
protected readonly errorHandler?: (error: Error, terminate: boolean) => void;
|
|
515
|
+
/** Deferred promise for interrupt coordination. */
|
|
516
|
+
protected deferredInterrupt: DeferredPromise<void> | undefined;
|
|
517
|
+
/**
|
|
518
|
+
* Raw state emitter stays private so subclasses use updateProcessingState()
|
|
519
|
+
* and the public subscription methods instead of coupling to Emittery internals.
|
|
520
|
+
*/
|
|
521
|
+
private readonly emittery;
|
|
522
|
+
/** Current processing state of the agent. */
|
|
523
|
+
private processingState;
|
|
524
|
+
/** Adapter identifier shared across instances of the same adapter type. */
|
|
525
|
+
readonly adapterId: string;
|
|
526
|
+
/** Resolved timeout configuration with provenance tracking. */
|
|
527
|
+
protected readonly timeouts: TrackedTimeoutConfig;
|
|
528
|
+
protected lastResult: MessageResult | null;
|
|
529
|
+
protected readonly config: TConfig & {
|
|
530
|
+
adapterId: string;
|
|
531
|
+
};
|
|
532
|
+
/** Model used for this agent (subclasses may update when SDK confirms actual model) */
|
|
533
|
+
model: string;
|
|
534
|
+
/** ProviderConfig UUID used during agent creation, carried for runtime introspection */
|
|
535
|
+
providerConfigId?: string;
|
|
536
|
+
/** Working directory for agent execution */
|
|
537
|
+
cwd: string;
|
|
538
|
+
/** Current reasoning effort level, updated by changeReasoningInPlace. */
|
|
539
|
+
currentReasoningEffort: AIReasoningLevel | undefined;
|
|
540
|
+
/**
|
|
541
|
+
* Reasoning levels supported by the current model, forwarded from the config factory.
|
|
542
|
+
* `undefined` when the model does not declare reasoning support.
|
|
543
|
+
*/
|
|
544
|
+
supportedReasoningLevels: BaseAgentConnectorConfig['supportedReasoningLevels'];
|
|
545
|
+
protected readonly env: Record<string, string>;
|
|
546
|
+
/** Monotonic turn-number bookkeeping for the MCP tool ledger. */
|
|
547
|
+
private readonly turnNumbers;
|
|
548
|
+
/** Adapter type name for event identification. */
|
|
549
|
+
protected readonly adapterName: string;
|
|
550
|
+
/** Runtime system prompt from start/initialize options. */
|
|
551
|
+
protected systemPrompt?: SystemPrompt;
|
|
552
|
+
protected constructor(config: BaseAgentConnectorConfig<TBus> & {
|
|
553
|
+
adapterId: string;
|
|
554
|
+
});
|
|
555
|
+
/**
|
|
556
|
+
* Get the current processing state of the agent.
|
|
557
|
+
* @returns The current processing state
|
|
558
|
+
*/
|
|
559
|
+
getProcessingState(): ProcessingState;
|
|
560
|
+
/**
|
|
561
|
+
* Handle pause after rejection or error.
|
|
562
|
+
* Subclasses should clear pending messages as appropriate.
|
|
563
|
+
* @param _reason - Reason for pause ('rejection' | 'error'); available for subclass overrides
|
|
564
|
+
*/
|
|
565
|
+
protected handlePause(_reason: 'rejection' | 'error'): void;
|
|
566
|
+
/**
|
|
567
|
+
* Store runtime system prompt for session creation.
|
|
568
|
+
* Subclasses may override to apply SDK-specific side effects (e.g., Gemini's setSystemInstruction).
|
|
569
|
+
* @param prompt - System prompt from start/initialize options
|
|
570
|
+
*/
|
|
571
|
+
protected captureSystemPrompt(prompt: SystemPrompt | undefined): void;
|
|
572
|
+
/**
|
|
573
|
+
* Update the agent's processing state.
|
|
574
|
+
* State transitions trigger events via emittery.
|
|
575
|
+
* @param state - New processing state
|
|
576
|
+
*/
|
|
577
|
+
protected updateProcessingState(state: ProcessingState): Promise<void>;
|
|
578
|
+
/**
|
|
579
|
+
* Subscribe to processing state changes (idle ↔ processing transitions).
|
|
580
|
+
* @param handler - Called with `{ isProcessing: boolean }` on each state change
|
|
581
|
+
* @returns Unsubscribe function
|
|
582
|
+
*/
|
|
583
|
+
onProcessingStateChanged(handler: (payload: EmitteryEvents['processingStateChanged']) => Promise<void> | void): UnsubscribeFunction;
|
|
584
|
+
/**
|
|
585
|
+
* Wait for a single processing state change matching an optional predicate.
|
|
586
|
+
* @param predicate - Optional filter, e.g., `(e) => !e.isProcessing` for idle
|
|
587
|
+
* @returns Promise resolving to `{ isProcessing: boolean }`
|
|
588
|
+
*/
|
|
589
|
+
onceProcessingStateChanged(predicate?: (eventData: EmitteryEvents['processingStateChanged']) => boolean): Promise<ProcessingState>;
|
|
590
|
+
/**
|
|
591
|
+
* Initialize the connector's SDK session without sending a message.
|
|
592
|
+
* Must set adapterSessionId before returning.
|
|
593
|
+
* Called by createAgent for idle agent setup.
|
|
594
|
+
* Implementations MUST be idempotent (no-op if already initialized).
|
|
595
|
+
* @param options - Optional start options (e.g., systemPrompt for Claude)
|
|
596
|
+
*/
|
|
597
|
+
abstract initialize(options?: ConnectorStartOptions): Promise<void>;
|
|
598
|
+
/**
|
|
599
|
+
* Start agent with initial message.
|
|
600
|
+
* @param message - Normalized user message (role and content)
|
|
601
|
+
* @param options - Optional start options (e.g., delivery mode)
|
|
602
|
+
* @returns Session ID, agent ID, and message handle for tracking
|
|
603
|
+
*/
|
|
604
|
+
abstract start(message: NormalizedMessageInput, options?: ConnectorStartOptions): Promise<AgentStartResult>;
|
|
605
|
+
/**
|
|
606
|
+
* Send a message to the agent.
|
|
607
|
+
* For initial message, use start() instead.
|
|
608
|
+
* @param message - Normalized message content
|
|
609
|
+
* @param options - Send options (e.g., delivery mode, message ID)
|
|
610
|
+
* @returns Message handle for tracking
|
|
611
|
+
*/
|
|
612
|
+
abstract sendMessage(message: NormalizedMessageInput, options?: ConnectorSendMessageOptions): Promise<MessageHandle>;
|
|
613
|
+
/**
|
|
614
|
+
* Abort the agent and cleanup resources (panic mode).
|
|
615
|
+
* Triggers AbortController which may cause provider errors.
|
|
616
|
+
* Use close() for graceful shutdown instead.
|
|
617
|
+
*/
|
|
618
|
+
abstract abort(): void;
|
|
619
|
+
/**
|
|
620
|
+
* Tear this connector down and report what was observed; unlike `abort()` this
|
|
621
|
+
* triggers no AbortController errors. **Return the class you can prove** — `TeardownEvidenceSchema` says what each
|
|
622
|
+
* asserts, and only *local* evidence counts: a third-party `dispose`, a wrapper type or the absence of a thrown
|
|
623
|
+
* error prove no provider-side end. Unobservable ⇒ `detached` with a `detail`;
|
|
624
|
+
* an unaccounted failed stage ⇒ `unknown`, named. Throwing also means `unknown`.
|
|
625
|
+
* @returns What this runtime observed about the end of its resources
|
|
626
|
+
*/
|
|
627
|
+
abstract close(): Promise<ConnectorTeardownResult>;
|
|
628
|
+
/**
|
|
629
|
+
* Get session ID, waiting for provider to generate it if not yet available.
|
|
630
|
+
* @returns Session ID from provider
|
|
631
|
+
*/
|
|
632
|
+
abstract getAdapterSessionId(): Promise<string>;
|
|
633
|
+
/**
|
|
634
|
+
* The provider session ID this connector is currently authoritative on, or
|
|
635
|
+
* `undefined` when it has none. "Confirmed" means safe to report, not echoed
|
|
636
|
+
* back by the provider: a seeded ID qualifies when the provider adopts it, and
|
|
637
|
+
* Claude connectors withhold it only while a fork awaits `system.init`. For
|
|
638
|
+
* "did the provider commit to it" see {@link movesProviderSessionOnSuppressedResume}.
|
|
639
|
+
* Samplers (payload enrichment, rotation guards) must not read this accessor
|
|
640
|
+
* directly — resolve through `providerCommittedAdapterSessionId` in
|
|
641
|
+
* `agent/agent-adapter-session-movement.ts`, which withholds an armed resume
|
|
642
|
+
* target that an in-flight dispatch may still abandon.
|
|
643
|
+
* @returns Currently authoritative provider session ID, or `undefined`
|
|
644
|
+
*/
|
|
645
|
+
getConfirmedAdapterSessionId(): string | undefined;
|
|
646
|
+
/**
|
|
647
|
+
* Whether a dispatch that declines native resume would make this connector
|
|
648
|
+
* abandon its armed resume target for a fresh provider session.
|
|
649
|
+
* Narrow honesty query for the movement seam (contract in
|
|
650
|
+
* `agent/agent-adapter-session-movement.ts`): the executor must know before
|
|
651
|
+
* dispatching so the session row stops advertising the abandoned target.
|
|
652
|
+
* Default `false`; connectors that rotate must override.
|
|
653
|
+
* @returns `true` when declining native resume rotates the provider session
|
|
654
|
+
*/
|
|
655
|
+
movesProviderSessionOnSuppressedResume(): boolean;
|
|
656
|
+
/**
|
|
657
|
+
* Complete the agent session by waiting for all messages to finish.
|
|
658
|
+
* @returns Last message result or null if no messages processed
|
|
659
|
+
*/
|
|
660
|
+
abstract complete(): Promise<MessageResult | null>;
|
|
661
|
+
/**
|
|
662
|
+
* Create a MessageHandle with standard initialization (messageId, adapterSessionId, onMessageSent).
|
|
663
|
+
* @param message - Normalized user message
|
|
664
|
+
* @param options - Optional message options (id, delivery mode, history, and turn context)
|
|
665
|
+
* @returns Initialized MessageHandle instance
|
|
666
|
+
*/
|
|
667
|
+
protected createMessageHandle(message: NormalizedMessageInput, options?: MessageHandleOptions): MessageHandle;
|
|
668
|
+
/** Signal MCP tools changed; connectors with direct-inject refresh override this. */
|
|
669
|
+
markToolRefreshPending(): void;
|
|
670
|
+
/**
|
|
671
|
+
* Stage the canonical orchestrator-assigned turn number for consumption by the next
|
|
672
|
+
* {@link consumeTurnNumber} call. The counter is monotonically increasing.
|
|
673
|
+
* @param turnNumber - Canonical 1-based turn number from SessionOrchestrator
|
|
674
|
+
* @throws RangeError when the value is invalid, regresses, or downgrades a staged value
|
|
675
|
+
*/
|
|
676
|
+
setCanonicalTurnNumber(turnNumber: number): void;
|
|
677
|
+
/**
|
|
678
|
+
* Advance to the next turn number, consuming any pending canonical value.
|
|
679
|
+
* Orchestrator-staged values win; otherwise the local counter increments by one.
|
|
680
|
+
* @returns The current turn number after advancement
|
|
681
|
+
*/
|
|
682
|
+
protected consumeTurnNumber(): number;
|
|
683
|
+
/**
|
|
684
|
+
* Current turn number (read-only). Use {@link consumeTurnNumber} to advance.
|
|
685
|
+
* @returns The current turn number
|
|
686
|
+
*/
|
|
687
|
+
protected get currentTurnNumber(): number;
|
|
688
|
+
/**
|
|
689
|
+
* Staged canonical turn number, or `undefined` if none was staged.
|
|
690
|
+
* @returns The pending canonical turn number
|
|
691
|
+
*/
|
|
692
|
+
protected get pendingTurnNumber(): number | undefined;
|
|
693
|
+
/**
|
|
694
|
+
* Attempt to change the model without a connector swap.
|
|
695
|
+
* Subclasses override when the SDK supports in-place model changes.
|
|
696
|
+
* Base implementation returns false (swap required).
|
|
697
|
+
*
|
|
698
|
+
* **Mutation contract:** Implementations MUST NOT mutate `this.model` directly.
|
|
699
|
+
* The caller (AIAgent.handleModelChange) owns the `this.model` field update after
|
|
700
|
+
* a successful in-place change. Implementations only configure the SDK-internal model
|
|
701
|
+
* (e.g., `query.setModel()`, `geminiConfig.setModel()`).
|
|
702
|
+
* @param _newModel - The model identifier to switch to
|
|
703
|
+
* @returns true if changed in-place, false if swap needed. Exceptions are caught by the
|
|
704
|
+
* caller and treated as false (automatic swap fallback), so implementations need not guard.
|
|
705
|
+
*/
|
|
706
|
+
changeModelInPlace(_newModel: string): Promise<boolean>;
|
|
707
|
+
/**
|
|
708
|
+
* Attempt to change the working directory without a connector swap.
|
|
709
|
+
* Subclasses override when the adapter supports in-place cwd changes (e.g., stateless APIs).
|
|
710
|
+
* Base implementation returns false (swap required).
|
|
711
|
+
*
|
|
712
|
+
* **Mutation contract:** Implementations MUST NOT mutate `this.cwd` directly.
|
|
713
|
+
* The caller (AIAgent.handleCwdChange) owns the `this.cwd` field update after
|
|
714
|
+
* a successful in-place change. Implementations only update SDK-internal state.
|
|
715
|
+
* @param _newCwd - The working directory path to switch to
|
|
716
|
+
* @returns true if changed in-place, false if swap needed. Exceptions are caught by the
|
|
717
|
+
* caller and treated as false (automatic swap fallback), so implementations need not guard.
|
|
718
|
+
*/
|
|
719
|
+
changeCwdInPlace(_newCwd: string): Promise<boolean>;
|
|
720
|
+
/**
|
|
721
|
+
* Attempt to change reasoning effort without swapping the connector.
|
|
722
|
+
*
|
|
723
|
+
* Override in subclasses that support in-place reasoning changes (e.g., adapters
|
|
724
|
+
* that pass reasoning parameters per-request rather than at session-creation time).
|
|
725
|
+
* The base implementation returns `false` so callers fall back to a connector swap.
|
|
726
|
+
*
|
|
727
|
+
* **Mutation contract:** Implementations MUST NOT mutate `this.currentReasoningEffort`
|
|
728
|
+
* directly. The caller owns the `currentReasoningEffort` field update after a successful
|
|
729
|
+
* in-place change. Implementations only configure the SDK-internal reasoning parameter.
|
|
730
|
+
* @param _newLevel - The new reasoning effort level to apply
|
|
731
|
+
* @returns `true` if the change was applied in-place, `false` if a connector swap is needed
|
|
732
|
+
*/
|
|
733
|
+
changeReasoningInPlace(_newLevel: AIReasoningLevel): Promise<boolean>;
|
|
734
|
+
/**
|
|
735
|
+
* Interrupt the current message processing.
|
|
736
|
+
* @returns Promise that resolves when interrupt is handled
|
|
737
|
+
*/
|
|
738
|
+
abstract interrupt(): Promise<void>;
|
|
739
|
+
/**
|
|
740
|
+
* Marks pending message as failed, calls error handler, resolves completion promise.
|
|
741
|
+
* @param error - Error that occurred
|
|
742
|
+
* @param terminate - Whether to abort the agent after handling error
|
|
743
|
+
* @internal
|
|
744
|
+
*/
|
|
745
|
+
handleError(error: unknown, terminate?: boolean): void;
|
|
746
|
+
protected handleToolApprovalDenied(abort: 'not_requested' | 'not_supported' | 'handled', details?: string): void;
|
|
747
|
+
getAgentId(): string;
|
|
748
|
+
getAdapterName(): string;
|
|
749
|
+
/**
|
|
750
|
+
* Get timeout value for a specific category.
|
|
751
|
+
* @param category - Timeout category (initialization, acknowledgement, completion, toolApproval, eventWait)
|
|
752
|
+
* @returns Timeout value in milliseconds
|
|
753
|
+
*/
|
|
754
|
+
getTimeoutMs(category: keyof typeof this.timeouts.values): number;
|
|
755
|
+
/**
|
|
756
|
+
* Request tool approval via the scoped bus with auto-injected metadata.
|
|
757
|
+
*
|
|
758
|
+
* Wraps `scopedBus.request()` to automatically include connector identity
|
|
759
|
+
* (adapterName, agentId, adapterId, adapterSessionId) in the payload.
|
|
760
|
+
* @param subject - Subject definition for the tool approval request
|
|
761
|
+
* @param payload - Request payload (metadata fields are forbidden and auto-injected)
|
|
762
|
+
* @returns Promise resolving to the approval response
|
|
763
|
+
*/
|
|
764
|
+
protected requestToolApproval<TSubject extends ScopedSubjectDefinition<TBus['namespace']>>(subject: TSubject, payload: Forbid<TSubject['$meta']['payload']['request'], ForbiddenKeys>): Promise<TSubject['$meta']['payload']['response']>;
|
|
765
|
+
/**
|
|
766
|
+
* Execute a tool approval request with the shared diagnostics wrapper.
|
|
767
|
+
*
|
|
768
|
+
* Handles the common `RequestError`/`NoHandlerError` path by logging a helpful
|
|
769
|
+
* message via `handleError` and re-throwing so callers can decide whether to
|
|
770
|
+
* surface the failure or fall back to a denial.
|
|
771
|
+
* @param subject - Scoped subject definition for the tool approval request
|
|
772
|
+
* @param payload - Payload that must not include adapter metadata
|
|
773
|
+
* @returns Tool approval response payload
|
|
774
|
+
*/
|
|
775
|
+
protected requestToolApprovalWithHandling<TSubject extends ScopedSubjectDefinition<TBus['namespace']>>(subject: TSubject, payload: Forbid<TSubject['$meta']['payload']['request'], ForbiddenKeys>): Promise<TSubject['$meta']['payload']['response']>;
|
|
776
|
+
/**
|
|
777
|
+
* Emit an event via the scoped bus with auto-injected metadata.
|
|
778
|
+
*
|
|
779
|
+
* Wraps `scopedBus.emit()` to automatically include connector identity
|
|
780
|
+
* (adapterName, agentId, adapterId, adapterSessionId) in the payload.
|
|
781
|
+
* @param subject - Subject definition for the event
|
|
782
|
+
* @param payload - Event payload (metadata fields are forbidden and auto-injected)
|
|
783
|
+
* @returns Promise that resolves when the event is emitted
|
|
784
|
+
*/
|
|
785
|
+
protected emit<TSubject extends ScopedSubjectDefinition<TBus['namespace']>>(subject: TSubject, payload: Forbid<TSubject['$meta']['payload'], ForbiddenKeys>): Promise<void>;
|
|
786
|
+
/**
|
|
787
|
+
* Subscribe to events on the filtered bus (pre-filtered by agentId).
|
|
788
|
+
*
|
|
789
|
+
* Uses `filteredBus` which only delivers events matching this connector's agentId.
|
|
790
|
+
* @param subject - Subject definition to subscribe to
|
|
791
|
+
* @param handler - Event handler receiving the event context
|
|
792
|
+
* @param options - Optional subscription options (e.g., priority)
|
|
793
|
+
* @returns Unsubscribe function
|
|
794
|
+
*/
|
|
795
|
+
on<Subject extends ScopedSubjectDefinition<TBus['namespace']>>(subject: Subject, handler: HandlerForSubjectDefinition<Subject>, options?: OnOptions): () => void;
|
|
796
|
+
/**
|
|
797
|
+
* Wait for a single event on the filtered bus (pre-filtered by agentId).
|
|
798
|
+
*
|
|
799
|
+
* Uses `filteredBus` which only delivers events matching this connector's agentId.
|
|
800
|
+
* @param subject - Subject definition to wait for
|
|
801
|
+
* @param options - Optional options (e.g., predicate filter, timeout)
|
|
802
|
+
* @returns Promise resolving to the event context
|
|
803
|
+
*/
|
|
804
|
+
once<Subject extends ScopedSubjectDefinition<TBus['namespace']>>(subject: Subject, options?: Parameters<IFilteredBus<TBus['namespace'], ExtractScopedBusSubjects<TBus>>['once']>[1]): Promise<never>;
|
|
805
|
+
protected logLowLevelEvent(_event: unknown): void;
|
|
806
|
+
}
|
|
807
|
+
//#endregion
|
|
808
|
+
//#region adapters/core/src/connector/teardown-timing.d.ts
|
|
809
|
+
/**
|
|
810
|
+
* Timing budgets a connector may spend *observing* the end of a resource it is
|
|
811
|
+
* tearing down.
|
|
812
|
+
*
|
|
813
|
+
* These are deliberately not general-purpose timeouts. A teardown reports what
|
|
814
|
+
* it observed, and observing an end takes a bounded amount of wall-clock time;
|
|
815
|
+
* the budget below is the boundary between "we watched it end" and "we stopped
|
|
816
|
+
* watching and can no longer claim it ended".
|
|
817
|
+
* @packageDocumentation
|
|
818
|
+
*/
|
|
819
|
+
/**
|
|
820
|
+
* Milliseconds a connector may wait for a resource it just terminated to be
|
|
821
|
+
* observed as terminated.
|
|
822
|
+
*
|
|
823
|
+
* Chosen to match the archive and cancel budgets connectors already apply to
|
|
824
|
+
* provider round-trips, and deliberately far below the adapter-instance close
|
|
825
|
+
* budget so a single instance close can still contain several agent teardowns.
|
|
826
|
+
*
|
|
827
|
+
* The same budget bounds the confirmation a backend has to acquire for itself
|
|
828
|
+
* when its termination call reports success but publishes no end event: "did
|
|
829
|
+
* the resource end" is one question whether it is asked of a process, a
|
|
830
|
+
* connection, or a superseded generation of either.
|
|
831
|
+
*/
|
|
832
|
+
declare const CONNECTOR_EXIT_OBSERVATION_MS = 2000;
|
|
833
|
+
/**
|
|
834
|
+
* Milliseconds a teardown may wait for a connector replacement it found in
|
|
835
|
+
* flight to settle.
|
|
836
|
+
*
|
|
837
|
+
* **A liveness ceiling, not a correctness boundary.** It exists so a stop is
|
|
838
|
+
* never *unbounded*, not so it can only fire on a broken replacement: the waited
|
|
839
|
+
* region contains awaits no adapter budget covers — config resolution, auth
|
|
840
|
+
* preparation, connector construction, event wiring, account prepare and commit,
|
|
841
|
+
* the awaited movement announcement, the previous runtime's lease release — so a
|
|
842
|
+
* replacement that respects every budget it declares can still lose this race.
|
|
843
|
+
* **Its expiry may hit a perfectly legal replacement, and that is a specified
|
|
844
|
+
* normal path rather than an anomaly**, which is safe only because expiry hands
|
|
845
|
+
* both runtimes back to the replacement instead of closing anything.
|
|
846
|
+
*
|
|
847
|
+
* The value is therefore a user-visible-latency decision: every consumer of a
|
|
848
|
+
* teardown waits for it synchronously, including a session close that holds
|
|
849
|
+
* until its slowest agent teardown finishes and has no request deadline of its
|
|
850
|
+
* own to clamp against. Ten seconds is the order at which an interface must show
|
|
851
|
+
* progress rather than appear hung, and it is deliberately **shorter** than a
|
|
852
|
+
* legal slow replacement's worst case.
|
|
853
|
+
*
|
|
854
|
+
* It is **not** ordered against the deadline of whoever is waiting on the
|
|
855
|
+
* teardown. The two are related per request by a clamp — the effective wait is
|
|
856
|
+
* the smaller of this ceiling and what remains of that deadline less one
|
|
857
|
+
* {@link CONNECTOR_EXIT_OBSERVATION_MS} of margin — and the margin is that
|
|
858
|
+
* constant rather than a new one because the expiry arm closes nothing: all that
|
|
859
|
+
* remains after it is a status write and the reply.
|
|
860
|
+
*
|
|
861
|
+
* Against the other two budgets the ordering runs from smallest to largest:
|
|
862
|
+
* {@link CONNECTOR_EXIT_OBSERVATION_MS} (one observation), then
|
|
863
|
+
* `ADAPTER_INSTANCE_CLOSE_TIMEOUT_MS` (an instance close containing several
|
|
864
|
+
* observations), then this (one user-visible stop). That last step is an
|
|
865
|
+
* intentional inversion: an instance shutdown overlapping a replacement times out
|
|
866
|
+
* and reports `unknown`, and inside that window the replacement owns both
|
|
867
|
+
* runtimes.
|
|
868
|
+
*/
|
|
869
|
+
declare const SWAP_SETTLEMENT_WAIT_MS = 10000;
|
|
870
|
+
//#endregion
|
|
871
|
+
//#region adapters/core/src/connector/teardown-report.d.ts
|
|
872
|
+
/**
|
|
873
|
+
* A teardown class plus the failure that capped it.
|
|
874
|
+
*
|
|
875
|
+
* The wire-facing {@link ConnectorTeardownResult} carries only the class and a
|
|
876
|
+
* `detail`, because that is all a consumer needs to decide anything. This shape
|
|
877
|
+
* adds the original failure for the one caller that must **rethrow** it rather
|
|
878
|
+
* than report it: eviction's rollback consumer builds an aggregate from the
|
|
879
|
+
* throw, and returning instead of throwing would delete that signal silently.
|
|
880
|
+
*
|
|
881
|
+
* Kept as one type across the runtime, agent and registry layers on purpose. The
|
|
882
|
+
* contract names the registry's copy an *agent* teardown report, but the fields
|
|
883
|
+
* are identical at all three, and two names for one shape is how the layers
|
|
884
|
+
* drift apart.
|
|
885
|
+
*/
|
|
886
|
+
interface TeardownReport extends ConnectorTeardownResult {
|
|
887
|
+
/**
|
|
888
|
+
* Failure that made this class `unknown`, when there was one.
|
|
889
|
+
*
|
|
890
|
+
* Present only alongside `evidence: 'unknown'`. Never inspected to *derive* a
|
|
891
|
+
* class — the class is derived where the failure happened, and this field only
|
|
892
|
+
* carries it to a caller whose contract is to rethrow.
|
|
893
|
+
*/
|
|
894
|
+
readonly closeError?: unknown;
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Report a teardown that could not be attempted or observed at all.
|
|
898
|
+
* @param detail - Why nothing is known, for diagnostics.
|
|
899
|
+
* @param closeError - Failure that produced this class, when one exists.
|
|
900
|
+
* @returns The `unknown` report.
|
|
901
|
+
*/
|
|
902
|
+
declare function unknownTeardown(detail: string, closeError?: unknown): TeardownReport;
|
|
903
|
+
/**
|
|
904
|
+
* Combine several teardowns of one logical resource set into one report.
|
|
905
|
+
*
|
|
906
|
+
* Class and joined `detail` are the contract's {@link aggregateTeardownResults},
|
|
907
|
+
* not a restatement of it. What this layer adds is the one field the wire shape
|
|
908
|
+
* does not carry: the first `closeError`, so a rethrowing caller still has a
|
|
909
|
+
* failure to throw.
|
|
910
|
+
* @param reports - Reports from the individual teardowns.
|
|
911
|
+
* @returns One report standing for all of them.
|
|
912
|
+
*/
|
|
913
|
+
declare function aggregateTeardownReports(reports: readonly TeardownReport[]): TeardownReport;
|
|
914
|
+
/**
|
|
915
|
+
* Await a teardown and rethrow the failure that capped it, if there was one.
|
|
916
|
+
*
|
|
917
|
+
* The bridge for the callers whose contract is still a **throw**: a rollback that
|
|
918
|
+
* aggregates "the operation failed *and* its cleanup failed" learns the second
|
|
919
|
+
* half from an exception, and the reporting teardowns below it stopped raising
|
|
920
|
+
* one. Without this the aggregate would silently lose its cleanup arm — a
|
|
921
|
+
* connector and its lease left behind with nobody told.
|
|
922
|
+
*
|
|
923
|
+
* One helper rather than four call-site copies, because the conversion is the same
|
|
924
|
+
* everywhere and a missing copy is invisible until something leaks.
|
|
925
|
+
* @param teardown - Teardown whose report carries the failure, if any
|
|
926
|
+
* @throws The failure that capped the reported class
|
|
927
|
+
*/
|
|
928
|
+
declare function rethrowTeardownFailure(teardown: Promise<TeardownReport>): Promise<void>;
|
|
929
|
+
//#endregion
|
|
930
|
+
//#region adapters/core/src/connector/teardown-observation.d.ts
|
|
931
|
+
/** Inputs for {@link reportObservedExit}. */
|
|
932
|
+
interface ObservedExitOptions {
|
|
933
|
+
/**
|
|
934
|
+
* Promise settled by the runtime's own observation of the end.
|
|
935
|
+
*
|
|
936
|
+
* Must be the promise the *existing* listener settles, never a second
|
|
937
|
+
* subscription: two observations of one event are two things to keep in step,
|
|
938
|
+
* and the second one is always the one that goes stale.
|
|
939
|
+
*/
|
|
940
|
+
readonly exited: Promise<unknown>;
|
|
941
|
+
/**
|
|
942
|
+
* What was signalled, named for the `detail` a non-observation carries.
|
|
943
|
+
*
|
|
944
|
+
* Read by a human triaging a `detached` teardown, so it should name the
|
|
945
|
+
* resource ("the qwen ACP process", "the tmux pane process") rather than
|
|
946
|
+
* restating the class.
|
|
947
|
+
*/
|
|
948
|
+
readonly resource: string;
|
|
949
|
+
}
|
|
950
|
+
/**
|
|
951
|
+
* Wait for an end to be observed, bounded by the observation budget.
|
|
952
|
+
*
|
|
953
|
+
* The bound is what makes the wait admissible at all: a teardown that waited
|
|
954
|
+
* for an exit that never comes would hang every consumer behind it, and a
|
|
955
|
+
* consumer that hangs is strictly worse off than one told the end was not
|
|
956
|
+
* observed. So expiry is a normal answer here, not a failure.
|
|
957
|
+
*
|
|
958
|
+
* A **rejected** observation counts as no observation. These promises are built
|
|
959
|
+
* not to reject, but if one does then what failed is the watching, and a failed
|
|
960
|
+
* watch has seen nothing.
|
|
961
|
+
* @param exited - Promise settled by the runtime's own end observation.
|
|
962
|
+
* @param budgetMs - Milliseconds to watch for; defaults to the wave's budget.
|
|
963
|
+
* @returns Whether the end was observed inside the budget.
|
|
964
|
+
*/
|
|
965
|
+
declare function exitWasObserved(exited: Promise<unknown>, budgetMs?: number): Promise<boolean>;
|
|
966
|
+
/**
|
|
967
|
+
* Report the class a signalled resource's own end evidence supports.
|
|
968
|
+
*
|
|
969
|
+
* `exited` when the end was watched, `detached` when it was not — never
|
|
970
|
+
* `unknown`, because nothing failed: the signal was sent and the handle is
|
|
971
|
+
* gone, and the only missing fact is whether the peer finished before the
|
|
972
|
+
* budget ran out. A `detail` names the resource so the weaker class is
|
|
973
|
+
* actionable rather than merely honest.
|
|
974
|
+
*
|
|
975
|
+
* The budget is {@link CONNECTOR_EXIT_OBSERVATION_MS} and is not an option: "did
|
|
976
|
+
* the resource end" is one question with one answer time across the wave, and a
|
|
977
|
+
* per-call override nobody passed would only be a second place for it to differ.
|
|
978
|
+
* @param options - Observation promise and resource name.
|
|
979
|
+
* @returns `exited` on an observed end, `detached` with a `detail` otherwise.
|
|
980
|
+
*/
|
|
981
|
+
declare function reportObservedExit(options: ObservedExitOptions): Promise<ConnectorTeardownResult>;
|
|
982
|
+
/**
|
|
983
|
+
* Report the class available to a teardown that finds one already finished.
|
|
984
|
+
*
|
|
985
|
+
* Every connector with a termination guard reaches this: a panic `abort()` ran,
|
|
986
|
+
* or a first `close()` already reported, and a second caller arrives with no
|
|
987
|
+
* observation of its own. It may not borrow the first one's — the class a
|
|
988
|
+
* teardown reports is a statement about what *it* watched — and it may not claim
|
|
989
|
+
* `released` either, because the handle being gone says nothing about the peer.
|
|
990
|
+
* `detached` is what is left, and it is the truth: we stopped holding it and
|
|
991
|
+
* cannot say more.
|
|
992
|
+
* @returns `detached`, naming the missing observation.
|
|
993
|
+
*/
|
|
994
|
+
declare function reportRepeatTeardown(): ConnectorTeardownResult;
|
|
995
|
+
/**
|
|
996
|
+
* Render a failure for a diagnostic `detail` without leaking a stack.
|
|
997
|
+
*
|
|
998
|
+
* Kept to the message because these `detail`s travel over the bus and end up in
|
|
999
|
+
* logs a human reads; a stack there buries the one line that identifies the
|
|
1000
|
+
* stage.
|
|
1001
|
+
* @param error - Failure caught by a best-effort teardown stage.
|
|
1002
|
+
* @returns One-line description.
|
|
1003
|
+
*/
|
|
1004
|
+
declare function describeTeardownFailure(error: unknown): string;
|
|
1005
|
+
/**
|
|
1006
|
+
* Name a best-effort stage that failed, for {@link reportBestEffortStages}.
|
|
1007
|
+
*
|
|
1008
|
+
* For the connectors whose guarded region is interleaved with work that must run
|
|
1009
|
+
* regardless — a `finally` that closes a transport, an MCP unregistration behind a
|
|
1010
|
+
* disposal — and which therefore keep their own `try`/`catch` (and its log line)
|
|
1011
|
+
* and only borrow the naming.
|
|
1012
|
+
* @param stage - What was being released.
|
|
1013
|
+
* @param error - Failure the stage produced.
|
|
1014
|
+
* @returns The stage, named for a report.
|
|
1015
|
+
*/
|
|
1016
|
+
declare function stageFailure(stage: string, error: unknown): string;
|
|
1017
|
+
/**
|
|
1018
|
+
* Run one best-effort teardown stage and name it when it fails.
|
|
1019
|
+
*
|
|
1020
|
+
* Several stages release several different things, so the first failure must not
|
|
1021
|
+
* skip the rest — and yet a stage nobody accounted for must not be reported as one
|
|
1022
|
+
* that succeeded. Returning the stage name instead of throwing is what lets a
|
|
1023
|
+
* caller do both: run everything, then decide the class from what went
|
|
1024
|
+
* unaccounted for.
|
|
1025
|
+
* @param stage - What is being released, for the reported `detail`.
|
|
1026
|
+
* @param run - The release call, which may be a no-op when the resource is absent.
|
|
1027
|
+
* @returns The named failure when the stage failed, `undefined` when it did not.
|
|
1028
|
+
*/
|
|
1029
|
+
declare function runBestEffortStage(stage: string, run: () => Promise<unknown> | undefined): Promise<string | undefined>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Report the class a best-effort teardown with unaccounted stages may claim.
|
|
1032
|
+
*
|
|
1033
|
+
* The taxonomy's rule applied to the one case every such teardown shares: a
|
|
1034
|
+
* connector that could not tell whether its own release landed has no business
|
|
1035
|
+
* claiming it watched anything, so the class is `unknown` and *names* the stage —
|
|
1036
|
+
* a bare `unknown` leaves a human unable to tell which of several handles it was.
|
|
1037
|
+
*
|
|
1038
|
+
* `undefined` means every stage was accounted for, which is deliberately **not** a
|
|
1039
|
+
* class: what a fully accounted teardown may claim differs per connector (an
|
|
1040
|
+
* observed process exit, a `released` in-process object, a `detached` SDK handle)
|
|
1041
|
+
* and only the connector knows which. So the caller keeps that decision and this
|
|
1042
|
+
* only takes the branch the four of them shared.
|
|
1043
|
+
* @param subject - The teardown, named for the report ("Copilot close").
|
|
1044
|
+
* @param failures - Stages named by {@link runBestEffortStage} or {@link stageFailure}.
|
|
1045
|
+
* @returns The `unknown` report, or `undefined` when nothing went unaccounted for.
|
|
1046
|
+
*/
|
|
1047
|
+
declare function reportBestEffortStages(subject: string, failures: readonly string[]): TeardownReport | undefined;
|
|
1048
|
+
/**
|
|
1049
|
+
* Weaken a reported class to the weakest of itself and a ceiling.
|
|
1050
|
+
*
|
|
1051
|
+
* A connector sometimes learns *after* computing its class that something it
|
|
1052
|
+
* held was never proven finished — the canonical case being a superseded
|
|
1053
|
+
* resource generation nobody watched end. The class it may claim is then the
|
|
1054
|
+
* weakest of the two facts, which is the wave's single aggregation rule applied
|
|
1055
|
+
* to a set of two rather than a second rule.
|
|
1056
|
+
*
|
|
1057
|
+
* The reason travels with it: a capped class whose `detail` does not say what
|
|
1058
|
+
* capped it is indistinguishable from a resource that was simply slow.
|
|
1059
|
+
* @param result - Class the teardown computed for what it did observe.
|
|
1060
|
+
* @param ceiling - Strongest class the additional fact permits.
|
|
1061
|
+
* @param detail - Why the ceiling applies, appended to any existing `detail`.
|
|
1062
|
+
* @returns The capped class carrying both reasons.
|
|
1063
|
+
*/
|
|
1064
|
+
declare function capTeardownEvidence(result: ConnectorTeardownResult, ceiling: TeardownEvidence, detail: string): ConnectorTeardownResult;
|
|
1065
|
+
//#endregion
|
|
1066
|
+
//#region adapters/core/src/connector/generation-retirement.d.ts
|
|
1067
|
+
/** One resource generation taken out of service, with the end still to consume. */
|
|
1068
|
+
interface SupersededGeneration {
|
|
1069
|
+
/** Monotonic number of this generation within its connector, for diagnostics. */
|
|
1070
|
+
readonly generation: number;
|
|
1071
|
+
/**
|
|
1072
|
+
* The superseded generation's own end observation.
|
|
1073
|
+
*
|
|
1074
|
+
* `undefined` when the generation exposed none — which is itself a
|
|
1075
|
+
* non-observation and is recorded as one, because "we never had a way to look"
|
|
1076
|
+
* and "we looked and saw nothing" put a consumer in the same position.
|
|
1077
|
+
*/
|
|
1078
|
+
readonly exited: Promise<unknown> | undefined;
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Records which of a connector's superseded resource generations were never
|
|
1082
|
+
* observed to end.
|
|
1083
|
+
*
|
|
1084
|
+
* One per connector instance. Deliberately generic: I33 binds every connector
|
|
1085
|
+
* that replaces a resource inside itself, including ones that do not exist yet,
|
|
1086
|
+
* and a rule implemented twice is a rule that will hold in one place.
|
|
1087
|
+
*/
|
|
1088
|
+
declare class GenerationRetirementLedger {
|
|
1089
|
+
private readonly resource;
|
|
1090
|
+
/** Count of generations taken out of service, used to number them. */
|
|
1091
|
+
private supersededCount;
|
|
1092
|
+
/**
|
|
1093
|
+
* Generations whose end is not (yet) proven — retirement pending or given up on.
|
|
1094
|
+
*
|
|
1095
|
+
* A generation enters the moment it is superseded and leaves only when its end
|
|
1096
|
+
* has actually been observed. That is deliberate: a retirement still in flight
|
|
1097
|
+
* is a resource whose end nobody has proven, and a teardown arriving during one
|
|
1098
|
+
* must not be able to claim an observed class in the window before the wait
|
|
1099
|
+
* expires. Pending and abandoned are the same fact to every consumer — "no
|
|
1100
|
+
* proof" — so they are one set rather than two that could disagree.
|
|
1101
|
+
*/
|
|
1102
|
+
private readonly unproven;
|
|
1103
|
+
/**
|
|
1104
|
+
* @param resource - What a generation of this resource is, for the `detail`
|
|
1105
|
+
* an unretired generation puts on every later teardown. Names the thing
|
|
1106
|
+
* that may still be running ("qwen ACP process"), because that is what a
|
|
1107
|
+
* human triaging the capped class needs to go looking for.
|
|
1108
|
+
*/
|
|
1109
|
+
constructor(resource: string);
|
|
1110
|
+
/**
|
|
1111
|
+
* Take the live generation out of service and hand back what must be consumed.
|
|
1112
|
+
*
|
|
1113
|
+
* Called at the single choke point through which a connector retires a
|
|
1114
|
+
* generation, so the count cannot drift from the replacements that actually
|
|
1115
|
+
* happened. The caller has already signalled the end; this only opens the
|
|
1116
|
+
* bookkeeping for it.
|
|
1117
|
+
*
|
|
1118
|
+
* The generation counts as **unproven from this moment**, not from the moment a
|
|
1119
|
+
* wait for it expires. Between the two a teardown could otherwise arrive and
|
|
1120
|
+
* claim an observed class for a resource nobody had watched end yet.
|
|
1121
|
+
* @param exited - The superseded generation's own end observation, if it has one.
|
|
1122
|
+
* @returns The generation to retire, to pass to {@link retire} or {@link abandon}.
|
|
1123
|
+
*/
|
|
1124
|
+
supersede(exited: Promise<unknown> | undefined): SupersededGeneration;
|
|
1125
|
+
/**
|
|
1126
|
+
* Consume a superseded generation's end inside the observation budget.
|
|
1127
|
+
*
|
|
1128
|
+
* The budget is the same constant a connector spends observing its own
|
|
1129
|
+
* termination, because "did the resource end" is one question whether it is
|
|
1130
|
+
* asked of a connector or of a superseded generation of one.
|
|
1131
|
+
*
|
|
1132
|
+
* Expiry does **not** fail the replacement: a stuck predecessor must not block
|
|
1133
|
+
* a live agent, so the rebuild completes and the non-observation is carried in
|
|
1134
|
+
* the class instead.
|
|
1135
|
+
* @param generation - Generation returned by {@link supersede}.
|
|
1136
|
+
* @returns Whether the generation's end was observed and the generation retired.
|
|
1137
|
+
*/
|
|
1138
|
+
retire(generation: SupersededGeneration): Promise<boolean>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Record a generation as unretired without waiting for its end.
|
|
1141
|
+
*
|
|
1142
|
+
* The synchronous half of the split: a connector's `abort()` is synchronous by
|
|
1143
|
+
* contract and cannot await anything, so it signals the end and gives up on
|
|
1144
|
+
* observing it. Capping the class is what keeps that from being a hole —
|
|
1145
|
+
* without it, a synchronous retirement would silently claim what an asynchronous
|
|
1146
|
+
* one has to prove.
|
|
1147
|
+
*
|
|
1148
|
+
* A no-op in effect, because {@link supersede} already booked the generation as
|
|
1149
|
+
* unproven. It is kept as an explicit statement of intent: a caller that never
|
|
1150
|
+
* intends to wait says so, rather than leaving the reader to infer it from the
|
|
1151
|
+
* absence of a `retire`.
|
|
1152
|
+
* @param generation - Generation returned by {@link supersede}.
|
|
1153
|
+
*/
|
|
1154
|
+
abandon(generation: SupersededGeneration): void;
|
|
1155
|
+
/**
|
|
1156
|
+
* Apply the ceiling every unproven generation puts on a reported class.
|
|
1157
|
+
*
|
|
1158
|
+
* A no-op while every generation's end was observed, so a connector may call it
|
|
1159
|
+
* unconditionally on its way out and no caller has to remember the rule.
|
|
1160
|
+
* @param result - Class the teardown computed for what it did observe.
|
|
1161
|
+
* @returns The class capped at `detached` while a generation's end is unproven.
|
|
1162
|
+
*/
|
|
1163
|
+
capReport(result: ConnectorTeardownResult): ConnectorTeardownResult;
|
|
1164
|
+
/**
|
|
1165
|
+
* Name the generations whose end this connector has not observed.
|
|
1166
|
+
* @returns The diagnostic, or `undefined` when every end was observed.
|
|
1167
|
+
*/
|
|
1168
|
+
unretiredDetail(): string | undefined;
|
|
1169
|
+
}
|
|
1170
|
+
//#endregion
|
|
1171
|
+
//#region adapters/core/src/connector/base-connector-session.d.ts
|
|
1172
|
+
/**
|
|
1173
|
+
* Configuration for a connector session.
|
|
1174
|
+
* @typeParam TBus - Scoped bus type for adapter namespace
|
|
1175
|
+
*/
|
|
1176
|
+
interface ConnectorSessionConfig<TBus extends ScopedBus<string> = ScopedBus<string>> {
|
|
1177
|
+
bus: TBus;
|
|
1178
|
+
adapterId: string;
|
|
1179
|
+
adapterName: string;
|
|
1180
|
+
cwd: string;
|
|
1181
|
+
model: string;
|
|
1182
|
+
env: Record<string, string>;
|
|
1183
|
+
/** Auth-free environment safe for bus-routable tool and MCP contexts. */
|
|
1184
|
+
contextEnv?: Readonly<Record<string, string>>;
|
|
1185
|
+
}
|
|
1186
|
+
/**
|
|
1187
|
+
* Interface for turn-like objects that support pause/abort operations.
|
|
1188
|
+
* Allows base session class to work with different turn implementations.
|
|
1189
|
+
*/
|
|
1190
|
+
interface PausableTurn {
|
|
1191
|
+
pause(): Promise<unknown>;
|
|
1192
|
+
}
|
|
1193
|
+
/**
|
|
1194
|
+
* Base abstract class for connector session implementations.
|
|
1195
|
+
*
|
|
1196
|
+
* Sessions manage SDK query lifecycle across multiple turns:
|
|
1197
|
+
* - SDK connection management
|
|
1198
|
+
* - Turn creation and coordination
|
|
1199
|
+
* - Session ID management
|
|
1200
|
+
*
|
|
1201
|
+
* Each adapter implements its own session subclass.
|
|
1202
|
+
* @typeParam TConfig - Configuration type extending ConnectorSessionConfig
|
|
1203
|
+
*/
|
|
1204
|
+
declare abstract class BaseConnectorSession<TConfig extends ConnectorSessionConfig = ConnectorSessionConfig> {
|
|
1205
|
+
protected readonly config: TConfig;
|
|
1206
|
+
protected readonly bus: TConfig['bus'];
|
|
1207
|
+
protected sessionId?: string;
|
|
1208
|
+
protected currentTurn?: PausableTurn;
|
|
1209
|
+
/**
|
|
1210
|
+
* True once `close()` or `abort()` has begun; gates queue processing.
|
|
1211
|
+
*
|
|
1212
|
+
* ## Shutdown vs queue processing invariant
|
|
1213
|
+
*
|
|
1214
|
+
* Once `close()` or `abort()` begins, no new turn may start.
|
|
1215
|
+
* `processQueue` implementations must refuse to dequeue or start turns
|
|
1216
|
+
* when `this.closing` is `true`, and drain all remaining queued handles
|
|
1217
|
+
* with an error outcome so that callers awaiting `waitForCompletion()`
|
|
1218
|
+
* resolve deterministically instead of hanging.
|
|
1219
|
+
*
|
|
1220
|
+
* A dequeued handle that has entered the start-turn path either starts
|
|
1221
|
+
* its turn before `close()` begins, or is completed with the closing
|
|
1222
|
+
* error at every await point where `close()` can interleave. This is
|
|
1223
|
+
* enforced by {@link completeHandleIfClosing}, which rechecks the flag
|
|
1224
|
+
* after each awaited setup step and completes the handle with the same
|
|
1225
|
+
* error contract used by {@link rejectQueuedHandles}.
|
|
1226
|
+
*/
|
|
1227
|
+
protected closing: boolean;
|
|
1228
|
+
constructor(config: TConfig);
|
|
1229
|
+
/**
|
|
1230
|
+
* Recheck the shutdown flag after an awaited setup step in the start path.
|
|
1231
|
+
*
|
|
1232
|
+
* When `close()` sets `this.closing` while the subclass start-turn method
|
|
1233
|
+
* is awaiting an async setup step (schema rotation, query creation, MCP
|
|
1234
|
+
* registration, env resolution), the dequeued handle is no longer in the
|
|
1235
|
+
* queue and {@link rejectQueuedHandles} cannot reach it. This helper
|
|
1236
|
+
* completes the handle with the same error contract so callers see a
|
|
1237
|
+
* consistent shutdown outcome.
|
|
1238
|
+
* @param handle - Dequeued message handle currently being set up
|
|
1239
|
+
* @returns `true` when the session is closing and the handle was completed
|
|
1240
|
+
*/
|
|
1241
|
+
protected completeHandleIfClosing(handle: MessageHandle): boolean;
|
|
1242
|
+
/**
|
|
1243
|
+
* Abort the session and cleanup resources.
|
|
1244
|
+
* Pauses the current turn if one is active.
|
|
1245
|
+
*/
|
|
1246
|
+
abort(): Promise<void>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Send a message to the provider.
|
|
1249
|
+
* Not used - subclasses should implement processQueue instead.
|
|
1250
|
+
* @param _message - Unused message parameter
|
|
1251
|
+
* @param _options - Unused options parameter
|
|
1252
|
+
*/
|
|
1253
|
+
sendMessage(_message: unknown, _options?: unknown): Promise<void>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Get the adapter session ID.
|
|
1256
|
+
* @returns The session ID from the provider
|
|
1257
|
+
*/
|
|
1258
|
+
getAdapterSessionId(): Promise<string>;
|
|
1259
|
+
}
|
|
1260
|
+
//#endregion
|
|
1261
|
+
//#region adapters/core/src/connector/base-connector-turn.d.ts
|
|
1262
|
+
/**
|
|
1263
|
+
* Result of pausing a turn.
|
|
1264
|
+
* @typeParam TState - Turn state type
|
|
1265
|
+
*/
|
|
1266
|
+
interface PauseResult<TState = string> {
|
|
1267
|
+
/** The state the turn was in before pausing */
|
|
1268
|
+
stateBeforePause: TState;
|
|
1269
|
+
/** Whether the turn had already ended when pause was requested */
|
|
1270
|
+
turnEnded: boolean;
|
|
1271
|
+
}
|
|
1272
|
+
/**
|
|
1273
|
+
* Base abstract class for connector turn implementations.
|
|
1274
|
+
*
|
|
1275
|
+
* Turns manage the state machine for a single user message:
|
|
1276
|
+
* - State transitions (idle to turn_started to step_started to ...)
|
|
1277
|
+
* - Pause/resume mechanics
|
|
1278
|
+
* - Safe boundary detection for immediate messages
|
|
1279
|
+
* - Message handle delegation (acknowledgment, completion)
|
|
1280
|
+
*
|
|
1281
|
+
* Each adapter implements its own turn subclass with adapter-specific
|
|
1282
|
+
* state handling and SDK integration.
|
|
1283
|
+
* @typeParam TState - Turn state enum type (string union)
|
|
1284
|
+
*/
|
|
1285
|
+
declare abstract class BaseConnectorTurn<TState extends string = string> {
|
|
1286
|
+
protected state: TState;
|
|
1287
|
+
protected readonly bus: ScopedBus<string>;
|
|
1288
|
+
protected readonly adapterId: string;
|
|
1289
|
+
protected readonly adapterName: string;
|
|
1290
|
+
protected stateChangedCallback?: (oldState: TState, newState: TState) => Promise<void> | void;
|
|
1291
|
+
/**
|
|
1292
|
+
* Active message handle for this turn.
|
|
1293
|
+
* Subclasses must provide this handle for message lifecycle management.
|
|
1294
|
+
*/
|
|
1295
|
+
protected abstract activeMessageHandle: MessageHandle;
|
|
1296
|
+
constructor(bus: ScopedBus<string>, adapterId: string, adapterName: string, initialState: TState);
|
|
1297
|
+
/**
|
|
1298
|
+
* Pause the turn at next safe boundary.
|
|
1299
|
+
* @returns Pause result indicating whether turn already ended
|
|
1300
|
+
*/
|
|
1301
|
+
abstract pause(): Promise<PauseResult<TState>>;
|
|
1302
|
+
/**
|
|
1303
|
+
* Resume the paused turn with optional additional message.
|
|
1304
|
+
* @param message - Optional message to inject when resuming
|
|
1305
|
+
*/
|
|
1306
|
+
abstract resume(message?: unknown): Promise<void>;
|
|
1307
|
+
/**
|
|
1308
|
+
* Check if turn is currently paused.
|
|
1309
|
+
*/
|
|
1310
|
+
abstract isPaused(): boolean;
|
|
1311
|
+
/**
|
|
1312
|
+
* Register callback for state changes.
|
|
1313
|
+
* @param cb - Callback to invoke on state transitions
|
|
1314
|
+
*/
|
|
1315
|
+
onStateChanged(cb: (oldState: TState, newState: TState) => Promise<void> | void): void;
|
|
1316
|
+
/**
|
|
1317
|
+
* Transition to new state and notify listeners.
|
|
1318
|
+
* Template method for shared state transition pattern.
|
|
1319
|
+
*
|
|
1320
|
+
* NOTE: Subclasses should use their typed namespace subjects for emission.
|
|
1321
|
+
* This is a template - concrete implementation in adapter-specific Turn classes.
|
|
1322
|
+
* @param newState - New state to transition to
|
|
1323
|
+
*/
|
|
1324
|
+
protected transitionTo(newState: TState): Promise<void>;
|
|
1325
|
+
/**
|
|
1326
|
+
* Emit state change event - implemented by subclass with typed subjects.
|
|
1327
|
+
* @param oldState - Previous state
|
|
1328
|
+
* @param newState - New state
|
|
1329
|
+
*/
|
|
1330
|
+
protected abstract emitStateChange(oldState: TState, newState: TState): Promise<void>;
|
|
1331
|
+
/**
|
|
1332
|
+
* Get current turn state.
|
|
1333
|
+
* @returns Current turn state
|
|
1334
|
+
*/
|
|
1335
|
+
getState(): TState;
|
|
1336
|
+
/**
|
|
1337
|
+
* Get the message handle for this turn.
|
|
1338
|
+
* @returns The message handle for this turn
|
|
1339
|
+
*/
|
|
1340
|
+
getMessageHandle(): MessageHandle;
|
|
1341
|
+
/**
|
|
1342
|
+
* Mark message handle as acknowledged.
|
|
1343
|
+
*/
|
|
1344
|
+
markAcknowledged(): void;
|
|
1345
|
+
/**
|
|
1346
|
+
* Mark message handle as completed.
|
|
1347
|
+
* @param result - The completion result with outcome and optional result/error
|
|
1348
|
+
*/
|
|
1349
|
+
markCompleted(result: {
|
|
1350
|
+
outcome: string;
|
|
1351
|
+
result?: unknown;
|
|
1352
|
+
error?: unknown;
|
|
1353
|
+
}): void;
|
|
1354
|
+
}
|
|
1355
|
+
//#endregion
|
|
1356
|
+
//#region adapters/core/src/connector/procedural-connector-turn.d.ts
|
|
1357
|
+
/**
|
|
1358
|
+
* Typed subject references for turn lifecycle events.
|
|
1359
|
+
*
|
|
1360
|
+
* Each adapter provides its namespace-specific subjects when constructing
|
|
1361
|
+
* a ProceduralConnectorTurn. The subjects must all accept the same
|
|
1362
|
+
* TurnStateChangedPayload shape.
|
|
1363
|
+
* @typeParam TSubject - The subject definition type for the adapter's bus
|
|
1364
|
+
*/
|
|
1365
|
+
interface TurnSubjects<TSubject = ScopedSubjectDefinition> {
|
|
1366
|
+
state_changed: TSubject;
|
|
1367
|
+
turn_started: TSubject;
|
|
1368
|
+
step_started: TSubject;
|
|
1369
|
+
step_finished: TSubject;
|
|
1370
|
+
turn_finished: TSubject;
|
|
1371
|
+
}
|
|
1372
|
+
/**
|
|
1373
|
+
* Standard turn state type for procedural adapters.
|
|
1374
|
+
*
|
|
1375
|
+
* Procedural adapters (Gemini, OpenAI, Copilot) use abort+restart
|
|
1376
|
+
* rather than true pause/resume. Their state machine is:
|
|
1377
|
+
* idle to turn_started to step_started to step_finished to turn_finished
|
|
1378
|
+
*/
|
|
1379
|
+
type ProceduralTurnState = 'idle' | 'turn_started' | 'step_started' | 'step_finished' | 'turn_finished';
|
|
1380
|
+
/**
|
|
1381
|
+
* Configuration for ProceduralConnectorTurn.
|
|
1382
|
+
* @typeParam TBus - Scoped bus type for the adapter
|
|
1383
|
+
* @typeParam TSubject - Subject definition type
|
|
1384
|
+
*/
|
|
1385
|
+
interface ProceduralTurnConfig<TBus extends ScopedBus<string>, TSubject> {
|
|
1386
|
+
bus: TBus;
|
|
1387
|
+
adapterId: string;
|
|
1388
|
+
adapterName: string;
|
|
1389
|
+
agentId: string;
|
|
1390
|
+
messageHandle: MessageHandle;
|
|
1391
|
+
turnSubjects: TurnSubjects<TSubject>;
|
|
1392
|
+
}
|
|
1393
|
+
/**
|
|
1394
|
+
* Base turn implementation for procedural adapters (Gemini, OpenAI, Copilot).
|
|
1395
|
+
*
|
|
1396
|
+
* These adapters share an abort+restart pattern rather than true pause/resume.
|
|
1397
|
+
* This class extracts the common state machine, lifecycle methods, and
|
|
1398
|
+
* message handle delegation that was duplicated across all three.
|
|
1399
|
+
*
|
|
1400
|
+
* Subclasses only need to add adapter-specific behavior:
|
|
1401
|
+
* - Gemini: AbortController for SDK cancellation
|
|
1402
|
+
* - OpenAI: AbortController for SDK cancellation
|
|
1403
|
+
* - Copilot: SDK event handling (handleSdkEvent)
|
|
1404
|
+
* @typeParam TState - Turn state type (defaults to ProceduralTurnState)
|
|
1405
|
+
* @typeParam TBus - Scoped bus type for the adapter
|
|
1406
|
+
* @typeParam TSubject - Subject definition type for emit calls
|
|
1407
|
+
*/
|
|
1408
|
+
declare class ProceduralConnectorTurn<TState extends string = ProceduralTurnState, TBus extends ScopedBus<string> = ScopedBus<string>, TSubject extends ScopedSubjectDefinition = ScopedSubjectDefinition> extends BaseConnectorTurn<TState> {
|
|
1409
|
+
protected activeMessageHandle: MessageHandle;
|
|
1410
|
+
protected readonly connectorBus: TBus;
|
|
1411
|
+
protected readonly agentId: string;
|
|
1412
|
+
protected readonly turnSubjects: TurnSubjects<TSubject>;
|
|
1413
|
+
protected aborted: boolean;
|
|
1414
|
+
constructor(config: ProceduralTurnConfig<TBus, TSubject>, initialState: TState);
|
|
1415
|
+
/**
|
|
1416
|
+
* Emit state change using adapter-provided turn subjects.
|
|
1417
|
+
* @param oldState - Previous state before transition
|
|
1418
|
+
* @param newState - New state after transition
|
|
1419
|
+
*/
|
|
1420
|
+
protected emitStateChange(oldState: TState, newState: TState): Promise<void>;
|
|
1421
|
+
/**
|
|
1422
|
+
* Start the turn.
|
|
1423
|
+
*/
|
|
1424
|
+
start(): Promise<void>;
|
|
1425
|
+
/**
|
|
1426
|
+
* Transition to step_started (called when first content arrives).
|
|
1427
|
+
* Allows turn_started to step_started AND step_finished to step_started
|
|
1428
|
+
* (for tool recursion).
|
|
1429
|
+
*/
|
|
1430
|
+
markStepStarted(): Promise<void>;
|
|
1431
|
+
/**
|
|
1432
|
+
* Transition to step_finished (called after content block completes).
|
|
1433
|
+
*/
|
|
1434
|
+
markStepFinished(): Promise<void>;
|
|
1435
|
+
/**
|
|
1436
|
+
* Mark turn as finished.
|
|
1437
|
+
*/
|
|
1438
|
+
markTurnFinished(): Promise<void>;
|
|
1439
|
+
/**
|
|
1440
|
+
* Pause (abort) at next opportunity.
|
|
1441
|
+
* Procedural adapters don't support true pause - caller creates a new turn
|
|
1442
|
+
* with merged content instead.
|
|
1443
|
+
* @returns Pause result indicating turn state
|
|
1444
|
+
*/
|
|
1445
|
+
pause(): Promise<PauseResult<TState>>;
|
|
1446
|
+
/**
|
|
1447
|
+
* Resume is not supported for procedural adapters - caller creates new turn.
|
|
1448
|
+
* @param _message - Unused
|
|
1449
|
+
* @throws Error always
|
|
1450
|
+
*/
|
|
1451
|
+
resume(_message?: unknown): Promise<void>;
|
|
1452
|
+
/**
|
|
1453
|
+
* Check if turn was aborted.
|
|
1454
|
+
* @returns True if turn was aborted
|
|
1455
|
+
*/
|
|
1456
|
+
isPaused(): boolean;
|
|
1457
|
+
/**
|
|
1458
|
+
* Check if turn is completed.
|
|
1459
|
+
* @returns True if turn has finished
|
|
1460
|
+
*/
|
|
1461
|
+
isCompleted(): boolean;
|
|
1462
|
+
/**
|
|
1463
|
+
* Check if turn can accept immediate message.
|
|
1464
|
+
* True if turn is active (not finished, not aborted).
|
|
1465
|
+
* @returns True if turn can accept an immediate message
|
|
1466
|
+
*/
|
|
1467
|
+
canAcceptImmediate(): boolean;
|
|
1468
|
+
}
|
|
1469
|
+
//#endregion
|
|
1470
|
+
//#region adapters/core/src/session/user-message-queue.d.ts
|
|
1471
|
+
/**
|
|
1472
|
+
* Simple FIFO queue for user messages with delivery mode support.
|
|
1473
|
+
*
|
|
1474
|
+
* This queue is owned by adapter Connectors and passed to Sessions for processing.
|
|
1475
|
+
*
|
|
1476
|
+
* Delivery modes:
|
|
1477
|
+
* - 'enqueue': Add to end of queue (default); internal retries are prioritized
|
|
1478
|
+
* ahead of already queued user turns.
|
|
1479
|
+
* - 'replace': Supersede all unacknowledged messages, add to queue
|
|
1480
|
+
* - 'immediate': Handled by Session (abort/restart), not queue
|
|
1481
|
+
*
|
|
1482
|
+
* Design:
|
|
1483
|
+
* - Connector enqueues messages as they arrive
|
|
1484
|
+
* - Session dequeues messages when ready to process
|
|
1485
|
+
* - Peek allows Session to inspect next message without removing
|
|
1486
|
+
*/
|
|
1487
|
+
declare class UserMessageQueue {
|
|
1488
|
+
private readonly queue;
|
|
1489
|
+
/**
|
|
1490
|
+
* Add message to queue based on delivery mode.
|
|
1491
|
+
* @param handle - Message handle to enqueue
|
|
1492
|
+
*/
|
|
1493
|
+
enqueue(handle: MessageHandle): void;
|
|
1494
|
+
/**
|
|
1495
|
+
* Enqueue an internal retry before ordinary queued user turns while preserving
|
|
1496
|
+
* immediate-mode ordering and FIFO ordering among retries.
|
|
1497
|
+
* @param handle - Internal retry handle to enqueue
|
|
1498
|
+
*/
|
|
1499
|
+
private enqueueInternalRetry;
|
|
1500
|
+
/**
|
|
1501
|
+
* Remove all superseded messages from queue.
|
|
1502
|
+
*/
|
|
1503
|
+
private removeSuperseded;
|
|
1504
|
+
/**
|
|
1505
|
+
* Remove and return first message from queue.
|
|
1506
|
+
* @returns First message or undefined if queue empty
|
|
1507
|
+
*/
|
|
1508
|
+
dequeue(): MessageHandle | undefined;
|
|
1509
|
+
/**
|
|
1510
|
+
* Look at first message without removing.
|
|
1511
|
+
* @returns First message or undefined if queue empty
|
|
1512
|
+
*/
|
|
1513
|
+
peek(): MessageHandle | undefined;
|
|
1514
|
+
/**
|
|
1515
|
+
* Check if queue is empty.
|
|
1516
|
+
* @returns True if queue has no messages
|
|
1517
|
+
*/
|
|
1518
|
+
isEmpty(): boolean;
|
|
1519
|
+
/**
|
|
1520
|
+
* Get current queue size.
|
|
1521
|
+
* @returns Number of messages in queue
|
|
1522
|
+
*/
|
|
1523
|
+
size(): number;
|
|
1524
|
+
/**
|
|
1525
|
+
* Clear all messages from queue.
|
|
1526
|
+
*/
|
|
1527
|
+
clear(): void;
|
|
1528
|
+
/**
|
|
1529
|
+
* Find the first immediate message in the queue.
|
|
1530
|
+
* @returns First immediate message or undefined
|
|
1531
|
+
*/
|
|
1532
|
+
findImmediate(): MessageHandle | undefined;
|
|
1533
|
+
/**
|
|
1534
|
+
* Remove a specific immediate message from the queue.
|
|
1535
|
+
* @param handle - Handle to remove
|
|
1536
|
+
*/
|
|
1537
|
+
removeImmediate(handle: MessageHandle): void;
|
|
1538
|
+
/**
|
|
1539
|
+
* Remove and return all enqueued (non-immediate) messages.
|
|
1540
|
+
* Used when immediate arrives to merge their content.
|
|
1541
|
+
* @returns Array of enqueued message handles in FIFO order
|
|
1542
|
+
*/
|
|
1543
|
+
drainEnqueued(): MessageHandle[];
|
|
1544
|
+
}
|
|
1545
|
+
//#endregion
|
|
1546
|
+
//#region adapters/core/src/session/process-queue.d.ts
|
|
1547
|
+
/**
|
|
1548
|
+
* Canonical error message used when a queued message cannot be processed
|
|
1549
|
+
* because the session has entered the shutdown path.
|
|
1550
|
+
*
|
|
1551
|
+
* Shared between {@link rejectQueuedHandles} (queue drain) and the per-handle
|
|
1552
|
+
* shutdown gate ({@link BaseConnectorSession.completeHandleIfClosing}) so that
|
|
1553
|
+
* callers see a consistent error contract regardless of whether the handle was
|
|
1554
|
+
* still in the queue or had already been dequeued when `close()` interleaved.
|
|
1555
|
+
*/
|
|
1556
|
+
declare const SESSION_CLOSED_QUEUE_ERROR = "Session closed before queued message could be processed";
|
|
1557
|
+
/**
|
|
1558
|
+
* Minimal turn interface required by processQueue orchestration.
|
|
1559
|
+
*
|
|
1560
|
+
* Any turn implementation (Claude, Gemini, OpenAI, Copilot) that exposes
|
|
1561
|
+
* these methods can participate in the shared processQueue flow.
|
|
1562
|
+
*/
|
|
1563
|
+
interface QueueableTurn {
|
|
1564
|
+
canAcceptImmediate(): boolean;
|
|
1565
|
+
isCompleted(): boolean;
|
|
1566
|
+
getMessageHandle(): MessageHandle;
|
|
1567
|
+
pause(): Promise<PauseResult>;
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1570
|
+
* Result of processing an immediate message merge.
|
|
1571
|
+
*
|
|
1572
|
+
* Returned by the `extractMergeContent` callback so that adapters
|
|
1573
|
+
* can collect adapter-specific content (e.g., Gemini collects non-text parts).
|
|
1574
|
+
* The `mergedContent` array is always present; `extra` is an opaque bag
|
|
1575
|
+
* for adapter-specific data that flows through to `startNewTurn`.
|
|
1576
|
+
*/
|
|
1577
|
+
interface MergeResult {
|
|
1578
|
+
/** Text content collected from superseded/merged messages */
|
|
1579
|
+
mergedContent: string[];
|
|
1580
|
+
/** Adapter-specific merge data (e.g., non-text parts for Gemini) */
|
|
1581
|
+
extra?: unknown;
|
|
1582
|
+
}
|
|
1583
|
+
/**
|
|
1584
|
+
* Callbacks for adapter-specific behavior during queue processing.
|
|
1585
|
+
* @typeParam TExtra - Type of adapter-specific extra merge data
|
|
1586
|
+
*/
|
|
1587
|
+
interface ProcessQueueCallbacks<TExtra = unknown> {
|
|
1588
|
+
/**
|
|
1589
|
+
* Get the current turn, if any.
|
|
1590
|
+
* @returns The current turn or undefined
|
|
1591
|
+
*/
|
|
1592
|
+
getCurrentTurn: () => QueueableTurn | undefined;
|
|
1593
|
+
/**
|
|
1594
|
+
* Extract text content from a message handle for merge.
|
|
1595
|
+
* Default: `handle.message.message as string`
|
|
1596
|
+
* @param handle - The message handle to extract content from
|
|
1597
|
+
* @returns The text content
|
|
1598
|
+
*/
|
|
1599
|
+
extractContent?: (handle: MessageHandle) => string;
|
|
1600
|
+
/**
|
|
1601
|
+
* Called after merge content is collected from superseded/enqueued messages.
|
|
1602
|
+
* Allows adapters to collect additional content (e.g., Gemini's non-text parts).
|
|
1603
|
+
*
|
|
1604
|
+
* If not provided, only text content is collected using `extractContent`.
|
|
1605
|
+
* @param currentHandle - The in-flight message handle being superseded (or undefined)
|
|
1606
|
+
* @param enqueuedHandles - The enqueued handles being merged
|
|
1607
|
+
* @returns Extra merge data to pass through to startNewTurn
|
|
1608
|
+
*/
|
|
1609
|
+
collectMergeExtra?: (currentHandle: MessageHandle | undefined, enqueuedHandles: MessageHandle[]) => TExtra;
|
|
1610
|
+
/**
|
|
1611
|
+
* Hook called after merge is collected but before starting the new turn.
|
|
1612
|
+
* Used by Claude to create a fresh query instance.
|
|
1613
|
+
*/
|
|
1614
|
+
onBeforeImmediateTurn?: () => Promise<void>;
|
|
1615
|
+
/**
|
|
1616
|
+
* Start a new turn with the given message and optional merge data.
|
|
1617
|
+
*
|
|
1618
|
+
* Returns `void` (or `undefined`) when the turn was started normally.
|
|
1619
|
+
* Returns `false` explicitly when the turn was **not** started (e.g.,
|
|
1620
|
+
* shutdown interleaved during setup and the handle was completed with
|
|
1621
|
+
* an error). `processQueueMessages` propagates this so callers see an
|
|
1622
|
+
* accurate "no turn started" result and can transition to idle.
|
|
1623
|
+
* @param handle - The message handle to process
|
|
1624
|
+
* @param mergedContent - Text content from superseded/merged messages
|
|
1625
|
+
* @param extra - Adapter-specific extra merge data
|
|
1626
|
+
* @returns `false` when the turn was skipped; `void` otherwise
|
|
1627
|
+
*/
|
|
1628
|
+
startNewTurn: (handle: MessageHandle, mergedContent?: string[], extra?: TExtra) => Promise<void | false>;
|
|
1629
|
+
}
|
|
1630
|
+
/**
|
|
1631
|
+
* Shared processQueue orchestration for all session implementations.
|
|
1632
|
+
*
|
|
1633
|
+
* Handles the complete immediate-mode flow:
|
|
1634
|
+
* 1. Detect immediate message while a turn is active
|
|
1635
|
+
* 2. Pause the active turn
|
|
1636
|
+
* 3. Supersede the in-flight message and drain enqueued messages
|
|
1637
|
+
* 4. Collect merged content from all superseded/merged messages
|
|
1638
|
+
* 5. Start a new turn with the immediate message and merged context
|
|
1639
|
+
*
|
|
1640
|
+
* Also handles the normal queue flow:
|
|
1641
|
+
* - Late immediate rejection (immediate arrives after turn finishes)
|
|
1642
|
+
* - Normal enqueue/replace message processing
|
|
1643
|
+
*
|
|
1644
|
+
* Returns `true` when a new turn was started, `false` otherwise.
|
|
1645
|
+
* Callers can use this to decide whether to transition to idle when
|
|
1646
|
+
* the queue drains without starting a new turn (e.g., all-rejection case).
|
|
1647
|
+
* @param queue - The user message queue to process
|
|
1648
|
+
* @param callbacks - Adapter-specific callbacks
|
|
1649
|
+
* @returns True if a new turn was started, false otherwise
|
|
1650
|
+
* @typeParam TExtra - Type of adapter-specific extra merge data
|
|
1651
|
+
*/
|
|
1652
|
+
declare function processQueueMessages<TExtra = unknown>(queue: UserMessageQueue, callbacks: ProcessQueueCallbacks<TExtra>): Promise<boolean>;
|
|
1653
|
+
/**
|
|
1654
|
+
* Drain all remaining handles from the queue and complete each with an error
|
|
1655
|
+
* outcome so callers awaiting `waitForCompletion()` resolve deterministically.
|
|
1656
|
+
*
|
|
1657
|
+
* Used by session implementations during shutdown to prevent queued messages
|
|
1658
|
+
* from hanging indefinitely when the session refuses to start new turns.
|
|
1659
|
+
* @param queue - User message queue to drain
|
|
1660
|
+
* @param message - Error message to attach to each rejected handle
|
|
1661
|
+
*/
|
|
1662
|
+
declare function rejectQueuedHandles(queue: UserMessageQueue, message?: string): void;
|
|
1663
|
+
//#endregion
|
|
1664
|
+
//#region adapters/core/src/connector/procedural-agent-connector.d.ts
|
|
1665
|
+
/**
|
|
1666
|
+
* Minimal session interface required by ProceduralAgentConnector.
|
|
1667
|
+
*
|
|
1668
|
+
* Any session implementation (OpenAI, Copilot, Gemini) that exposes
|
|
1669
|
+
* these methods can be used with ProceduralAgentConnector's default
|
|
1670
|
+
* wireSessionEvents / processUserMessages / acceptsImmediate.
|
|
1671
|
+
*/
|
|
1672
|
+
interface ProceduralConnectorSession {
|
|
1673
|
+
/** Process messages from the queue. */
|
|
1674
|
+
processQueue(queue: UserMessageQueue): Promise<void>;
|
|
1675
|
+
/** Get the current turn for state inspection. */
|
|
1676
|
+
getCurrentTurn(): QueueableTurn | undefined;
|
|
1677
|
+
}
|
|
1678
|
+
/**
|
|
1679
|
+
* Turn subject references for wireSessionEvents.
|
|
1680
|
+
*
|
|
1681
|
+
* Each adapter provides its namespace-specific subjects. The subjects
|
|
1682
|
+
* must accept TurnStateChangedPayload (or compatible shape).
|
|
1683
|
+
* @typeParam TNamespace - The bus namespace string for subject typing
|
|
1684
|
+
*/
|
|
1685
|
+
interface WireSessionSubjects<TNamespace extends string = string> {
|
|
1686
|
+
turn_started: ScopedSubjectDefinition<TNamespace>;
|
|
1687
|
+
step_started: ScopedSubjectDefinition<TNamespace>;
|
|
1688
|
+
step_finished: ScopedSubjectDefinition<TNamespace>;
|
|
1689
|
+
turn_finished: ScopedSubjectDefinition<TNamespace>;
|
|
1690
|
+
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Configuration for ProceduralAgentConnector's wireSessionEvents behavior.
|
|
1693
|
+
*
|
|
1694
|
+
* The `onTurnStarted` and `onTurnFinished` hooks allow adapters to inject
|
|
1695
|
+
* logic at turn boundaries. By default both are no-ops.
|
|
1696
|
+
*/
|
|
1697
|
+
interface WireSessionConfig {
|
|
1698
|
+
/**
|
|
1699
|
+
* Called when a new turn starts (turn_started bus event).
|
|
1700
|
+
*
|
|
1701
|
+
* Executes before the default `updateProcessingState('turn_started')` so
|
|
1702
|
+
* the connector state machine is always updated regardless of this hook.
|
|
1703
|
+
*
|
|
1704
|
+
* Supports async so that turn-start operations with I/O — such as a pending
|
|
1705
|
+
* MCP tool refresh via the bus — can complete before the API call is made.
|
|
1706
|
+
* In-memory operations (recordInjection, consumeTurnNumber) are not affected
|
|
1707
|
+
* by the async signature.
|
|
1708
|
+
*/
|
|
1709
|
+
onTurnStarted?: () => Promise<void> | void;
|
|
1710
|
+
/**
|
|
1711
|
+
* Custom handler for turn_finished events.
|
|
1712
|
+
*
|
|
1713
|
+
* When provided, replaces the default turn_finished behavior entirely.
|
|
1714
|
+
* The handler receives a callback to process the queue, which it should
|
|
1715
|
+
* call when the message is considered complete and the queue should drain.
|
|
1716
|
+
* @param drainQueue - Callback that processes the queue or goes idle
|
|
1717
|
+
*/
|
|
1718
|
+
onTurnFinished?: (drainQueue: () => Promise<void>) => Promise<void>;
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Abstract base class for procedural (non-event-driven) agent connectors.
|
|
1722
|
+
*
|
|
1723
|
+
* Procedural adapters (OpenAI, Copilot, Gemini) share common patterns:
|
|
1724
|
+
* - wireSessionEvents: subscribe to turn lifecycle events and update processing state
|
|
1725
|
+
* - processUserMessages: initialize session, enqueue, transition to active, process queue
|
|
1726
|
+
* - complete: poll processing state until idle/paused
|
|
1727
|
+
* - start: delegate to sendMessage and return AgentStartResult
|
|
1728
|
+
* - acceptsImmediate: delegate to session's current turn
|
|
1729
|
+
*
|
|
1730
|
+
* Subclasses must implement:
|
|
1731
|
+
* - `getSession()` / `ensureSession()` for session access and lazy initialization
|
|
1732
|
+
* - `getSessionQueue()` for the adapter's UserMessageQueue instance
|
|
1733
|
+
* - `getTurnSubjects()` for namespace-specific turn subjects
|
|
1734
|
+
* - `sendMessage()`, `abort()`, `close()`, `interrupt()`, `getAdapterSessionId()`
|
|
1735
|
+
*
|
|
1736
|
+
* Subclasses may override:
|
|
1737
|
+
* - `getWireSessionConfig()` for custom turn_finished behavior (e.g., Copilot multi-turn)
|
|
1738
|
+
* @typeParam TBus - Scoped bus type for adapter namespace
|
|
1739
|
+
* @typeParam TConfig - Configuration type extending BaseAgentConnectorConfig
|
|
1740
|
+
*/
|
|
1741
|
+
declare abstract class ProceduralAgentConnector<TBus extends ScopedBus<string> = ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> extends AIAgentConnector<TBus, TConfig> {
|
|
1742
|
+
/** Whether turn event wiring has been setup. */
|
|
1743
|
+
private turnEventsWired;
|
|
1744
|
+
/**
|
|
1745
|
+
* Terminal lifecycle latch. Once a connector starts closing, initialization
|
|
1746
|
+
* that resumes later must not install fresh turn handlers.
|
|
1747
|
+
*/
|
|
1748
|
+
private turnEventLifecycleClosed;
|
|
1749
|
+
/**
|
|
1750
|
+
* Unsubscribe functions for the turn subscriptions {@link wireSessionEvents}
|
|
1751
|
+
* installed.
|
|
1752
|
+
*
|
|
1753
|
+
* Held here, at the wiring, because that is the only place that knows what was
|
|
1754
|
+
* subscribed. A subclass owns *when* its connector ends; it cannot own the
|
|
1755
|
+
* undoing of subscriptions it never registered — and every connector on this base
|
|
1756
|
+
* needs them undone, whatever class its teardown reports: a subscription outliving
|
|
1757
|
+
* its connector keeps that connector reachable from the bus, so a later generation
|
|
1758
|
+
* on the same agent id delivers turn events into an object that already closed.
|
|
1759
|
+
*/
|
|
1760
|
+
private turnEventCleanups;
|
|
1761
|
+
/** Turn handlers that already started and must settle before provider teardown. */
|
|
1762
|
+
private activeTurnEventHandlers;
|
|
1763
|
+
/**
|
|
1764
|
+
* Get the adapter's session instance (may be undefined if not yet initialized).
|
|
1765
|
+
* @returns The session or undefined
|
|
1766
|
+
*/
|
|
1767
|
+
protected abstract getSession(): ProceduralConnectorSession | undefined;
|
|
1768
|
+
/**
|
|
1769
|
+
* Initialize and return the adapter's session.
|
|
1770
|
+
* Must be idempotent (no-op if already initialized).
|
|
1771
|
+
* @returns The initialized session
|
|
1772
|
+
*/
|
|
1773
|
+
protected abstract ensureSession(): Promise<ProceduralConnectorSession>;
|
|
1774
|
+
/**
|
|
1775
|
+
* Get the adapter's UserMessageQueue instance.
|
|
1776
|
+
* @returns The message queue
|
|
1777
|
+
*/
|
|
1778
|
+
protected abstract getSessionQueue(): UserMessageQueue;
|
|
1779
|
+
/**
|
|
1780
|
+
* Get the adapter's namespace-specific turn subjects for wireSessionEvents.
|
|
1781
|
+
* @returns Turn subject definitions
|
|
1782
|
+
*/
|
|
1783
|
+
protected abstract getTurnSubjects(): WireSessionSubjects<TBus['namespace']>;
|
|
1784
|
+
/**
|
|
1785
|
+
* Get optional wire session configuration for custom turn_finished behavior.
|
|
1786
|
+
* Override in subclasses that need non-standard turn_finished handling
|
|
1787
|
+
* (e.g., Copilot multi-turn message completion).
|
|
1788
|
+
* @returns Wire session configuration, or undefined for default behavior
|
|
1789
|
+
*/
|
|
1790
|
+
protected getWireSessionConfig(): WireSessionConfig | undefined;
|
|
1791
|
+
/**
|
|
1792
|
+
* Wire Session turn events to Connector state updates.
|
|
1793
|
+
*
|
|
1794
|
+
* Session emits typed events, Connector subscribes and updates processing state.
|
|
1795
|
+
* This maintains separation of concerns - Session does not know about Connector state.
|
|
1796
|
+
*
|
|
1797
|
+
* Default turn_finished behavior: transition through processing_finished to idle,
|
|
1798
|
+
* or drain the queue if messages are pending. Override via `getWireSessionConfig()`.
|
|
1799
|
+
*
|
|
1800
|
+
* Every subscription's unsubscribe function is retained so
|
|
1801
|
+
* {@link unwireSessionEvents} can undo the whole set; a connector that closes
|
|
1802
|
+
* without undoing them stays reachable from the bus for the rest of the process.
|
|
1803
|
+
*/
|
|
1804
|
+
protected wireSessionEvents(): void;
|
|
1805
|
+
/**
|
|
1806
|
+
* Run a turn handler only while this connector owns its lifecycle.
|
|
1807
|
+
*
|
|
1808
|
+
* The bus snapshots handlers before it begins invoking them, so unsubscribe
|
|
1809
|
+
* alone cannot stop a snapshotted callback. This second terminal check rejects
|
|
1810
|
+
* that callback when it eventually starts, while the active set lets close
|
|
1811
|
+
* wait for callbacks that started before the terminal latch.
|
|
1812
|
+
* @param handler - Turn callback registered with the scoped bus
|
|
1813
|
+
*/
|
|
1814
|
+
private dispatchTurnEvent;
|
|
1815
|
+
/**
|
|
1816
|
+
* Cancel every turn subscription {@link wireSessionEvents} installed.
|
|
1817
|
+
*
|
|
1818
|
+
* **What makes a connector's end total.** §2.2's `released` is the claim that no
|
|
1819
|
+
* callback can arrive afterwards, and a turn subscription is precisely a way for
|
|
1820
|
+
* one to: the bus keeps the closed connector alive, and a later connector
|
|
1821
|
+
* generation on the same agent id emits into the filtered bus both of them are
|
|
1822
|
+
* subscribed to, so the dead one advances its own state machine and touches a
|
|
1823
|
+
* session it already dropped. That is the same defect for a connector reporting
|
|
1824
|
+
* `detached` — it merely has a weaker claim to overstate.
|
|
1825
|
+
*
|
|
1826
|
+
* Idempotent. The separate terminal lifecycle latch decides whether wiring may
|
|
1827
|
+
* be installed again; close paths set that latch before calling this cleanup.
|
|
1828
|
+
*/
|
|
1829
|
+
protected unwireSessionEvents(): void;
|
|
1830
|
+
/**
|
|
1831
|
+
* Permanently prevent turn wiring and remove any handlers already installed.
|
|
1832
|
+
*
|
|
1833
|
+
* Close implementations call this before awaiting provider teardown so an
|
|
1834
|
+
* initialization that was already in flight cannot re-wire afterwards.
|
|
1835
|
+
*/
|
|
1836
|
+
protected closeTurnEventLifecycle(): Promise<void>;
|
|
1837
|
+
/**
|
|
1838
|
+
* Whether connector initialization lost the terminal close race.
|
|
1839
|
+
* @returns `true` once close permanently claimed the wiring lifecycle
|
|
1840
|
+
*/
|
|
1841
|
+
protected get isTurnEventLifecycleClosed(): boolean;
|
|
1842
|
+
/**
|
|
1843
|
+
* Process queued user messages by delegating to Session.
|
|
1844
|
+
*
|
|
1845
|
+
* Shared flow:
|
|
1846
|
+
* 1. Initialize session if not yet created
|
|
1847
|
+
* 2. Enqueue the message
|
|
1848
|
+
* 3. Set adapterSessionId on handle
|
|
1849
|
+
* 4. Transition to active if currently idle/paused
|
|
1850
|
+
* 5. Process queue via session
|
|
1851
|
+
* @param messageHandles - Array of message handles to process
|
|
1852
|
+
* @returns Set of message handles that were processed
|
|
1853
|
+
*/
|
|
1854
|
+
protected processUserMessages(messageHandles: MessageHandle[]): Promise<Set<MessageHandle>>;
|
|
1855
|
+
/**
|
|
1856
|
+
* Initialize the connector's SDK session without sending a message.
|
|
1857
|
+
* Must set adapterSessionId before returning.
|
|
1858
|
+
* Called by createAgent for idle agent setup.
|
|
1859
|
+
* Implementations MUST be idempotent (no-op if already initialized).
|
|
1860
|
+
* @param options - Optional start options (e.g., systemPrompt)
|
|
1861
|
+
*/
|
|
1862
|
+
initialize(options?: ConnectorStartOptions): Promise<void>;
|
|
1863
|
+
/**
|
|
1864
|
+
* Start session with initial message.
|
|
1865
|
+
* @param message - The initial message to send
|
|
1866
|
+
* @param options - Optional send message options
|
|
1867
|
+
* @returns The agent start result with session ID and message handle
|
|
1868
|
+
*/
|
|
1869
|
+
start(message: NormalizedMessageInput, options?: ConnectorSendMessageOptions): Promise<AgentStartResult>;
|
|
1870
|
+
/**
|
|
1871
|
+
* Complete the agent session by waiting for all messages to finish.
|
|
1872
|
+
* @returns Last message result or null if no messages processed
|
|
1873
|
+
*/
|
|
1874
|
+
complete(): Promise<MessageResult | null>;
|
|
1875
|
+
/**
|
|
1876
|
+
* Returns true if current turn can accept immediate messages.
|
|
1877
|
+
* @returns True if turn can accept immediate, false otherwise
|
|
1878
|
+
*/
|
|
1879
|
+
protected acceptsImmediate(): boolean;
|
|
1880
|
+
}
|
|
1881
|
+
//#endregion
|
|
1882
|
+
//#region adapters/core/src/config/resolve-adapter-auth.d.ts
|
|
1883
|
+
/** Stable normalized adapter-auth failure categories. */
|
|
1884
|
+
type AdapterAuthErrorReason = 'provider-context-unresolved' | 'binding-missing' | 'binding-ambiguous' | 'client-mismatch' | 'credential-resolution-failed' | 'credential-missing' | 'runtime-bus-missing' | 'native-auth-unavailable';
|
|
1885
|
+
/** Typed, credential-free failure at the normalized adapter-auth boundary. */
|
|
1886
|
+
declare class AdapterAuthError extends AuthenticationError {
|
|
1887
|
+
readonly reason: AdapterAuthErrorReason;
|
|
1888
|
+
/**
|
|
1889
|
+
* Create a normalized adapter-auth failure.
|
|
1890
|
+
* @param reason - Stable failure category
|
|
1891
|
+
* @param message - Credential-free diagnostic
|
|
1892
|
+
*/
|
|
1893
|
+
constructor(reason: AdapterAuthErrorReason, message: string);
|
|
1894
|
+
}
|
|
1895
|
+
/** Plaintext values produced by the trusted credential resolver. */
|
|
1896
|
+
type ResolvedAuthCredentialValues = Readonly<Record<string, string>>;
|
|
1897
|
+
/** Resolve normalized credential refs without exposing them outside the trusted consumer. */
|
|
1898
|
+
type ResolveAuthCredentialRefs = (credentialRefs: Readonly<Record<string, AuthCredentialRef>>) => Promise<ResolvedAuthCredentialValues>;
|
|
1899
|
+
/** Input for binding one normalized provider selection to an adapter declaration. */
|
|
1900
|
+
interface BindProviderAuthOptions {
|
|
1901
|
+
/** Resolved provider authentication selection containing refs but no plaintext. */
|
|
1902
|
+
readonly auth: ResolvedProviderAuth;
|
|
1903
|
+
/** Authentication declaration for the selected adapter/provider junction. */
|
|
1904
|
+
readonly adapterProviderAuth: AdapterProviderAuth;
|
|
1905
|
+
/** Other compatible declarations whose environment sinks must also be scrubbed. */
|
|
1906
|
+
readonly compatibleProviderAuths?: readonly AdapterProviderAuth[];
|
|
1907
|
+
}
|
|
1908
|
+
/** Immutable refs-only adapter binding emitted before connector-local resolution. */
|
|
1909
|
+
interface BoundProviderAuthContext {
|
|
1910
|
+
/** Selected normalized provider authentication. */
|
|
1911
|
+
readonly auth: ResolvedProviderAuth;
|
|
1912
|
+
/** The single adapter delivery binding matching the selected method exactly. */
|
|
1913
|
+
readonly binding: AdapterAuthBinding;
|
|
1914
|
+
/** Complete adapter-wide environment variables removed before selected delivery. */
|
|
1915
|
+
readonly scrubEnvVars: readonly string[];
|
|
1916
|
+
}
|
|
1917
|
+
/**
|
|
1918
|
+
* Select optional field IDs from an explicit normalized auth selection.
|
|
1919
|
+
*
|
|
1920
|
+
* Trusted credential resolvers use this policy to omit only selected optional
|
|
1921
|
+
* refs whose backing secret is unavailable. Keeping it next to the binding
|
|
1922
|
+
* contract guarantees host and container materialization share one rule.
|
|
1923
|
+
* @param bound - Exact provider/auth binding selected for one adapter runtime.
|
|
1924
|
+
* @returns Field IDs whose unavailable refs may be omitted during resolution.
|
|
1925
|
+
*/
|
|
1926
|
+
declare function getOptionalAuthCredentialFields(bound: BoundProviderAuthContext): readonly string[];
|
|
1927
|
+
/** One immutable connector-owned authentication operation. */
|
|
1928
|
+
interface ResolvedConnectorAuthDelivery {
|
|
1929
|
+
/** Adapter-specific operation identifier. */
|
|
1930
|
+
readonly target: string;
|
|
1931
|
+
/** Plaintext fields and constant/null suppressions consumed by the operation. */
|
|
1932
|
+
readonly values: Readonly<Record<string, AdapterAuthConstant>>;
|
|
1933
|
+
}
|
|
1934
|
+
/** Immutable connector-local authentication snapshot. */
|
|
1935
|
+
interface ResolvedAdapterAuth {
|
|
1936
|
+
/** Selected plaintext values delivered to a spawned process. */
|
|
1937
|
+
readonly processEnv: Readonly<Record<string, string>>;
|
|
1938
|
+
/** Selected adapter-specific connector operations. */
|
|
1939
|
+
readonly connectorDeliveries: readonly ResolvedConnectorAuthDelivery[];
|
|
1940
|
+
/** Native auth is inherited only for inferred methods. */
|
|
1941
|
+
readonly configInheritance: 'auth-only' | 'empty';
|
|
1942
|
+
}
|
|
1943
|
+
/**
|
|
1944
|
+
* Bind normalized provider authentication to one exact adapter delivery declaration.
|
|
1945
|
+
*
|
|
1946
|
+
* The result remains refs-only and can therefore travel through adapter configuration
|
|
1947
|
+
* plumbing without exposing plaintext. Every object is cloned by schema parsing and
|
|
1948
|
+
* deeply frozen so connector startup observes one stable selection.
|
|
1949
|
+
* @param options - Selected auth plus selected and compatible adapter declarations.
|
|
1950
|
+
* @returns Immutable refs-only provider auth binding.
|
|
1951
|
+
*/
|
|
1952
|
+
declare function bindProviderAuth(options: BindProviderAuthOptions): BoundProviderAuthContext;
|
|
1953
|
+
/**
|
|
1954
|
+
* Resolve a bound provider auth context into one immutable connector-local snapshot.
|
|
1955
|
+
*
|
|
1956
|
+
* Explicit refs are resolved exactly once. Only required fields must materialize;
|
|
1957
|
+
* unavailable optional fields are omitted from every delivery. Inferred and no-auth
|
|
1958
|
+
* methods never invoke the credential resolver.
|
|
1959
|
+
* @param bound - Immutable refs-only adapter binding.
|
|
1960
|
+
* @param resolveCredentialRefs - Trusted local credential resolver.
|
|
1961
|
+
* @returns Immutable plaintext delivery snapshot.
|
|
1962
|
+
*/
|
|
1963
|
+
declare function resolveBoundProviderAuth(bound: BoundProviderAuthContext, resolveCredentialRefs: ResolveAuthCredentialRefs): Promise<ResolvedAdapterAuth>;
|
|
1964
|
+
//#endregion
|
|
1965
|
+
//#region adapters/core/src/config/adapter-auth-runtime.d.ts
|
|
1966
|
+
/** Refs-only config emitted by the common adapter factory. */
|
|
1967
|
+
type BoundAdapterRuntimeConfig<TBus extends ScopedBus<string> = ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> = TConfig & {
|
|
1968
|
+
/** Adapter instance identifier required by connector factories. */adapterId: string; /** Exact normalized auth selection and adapter delivery binding. */
|
|
1969
|
+
boundProviderAuth?: BoundProviderAuthContext;
|
|
1970
|
+
};
|
|
1971
|
+
/** Connector-facing config after auth refs and client state have been materialized. */
|
|
1972
|
+
type ResolvedAdapterRuntimeConfig<TBus extends ScopedBus<string> = ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> = Omit<TConfig, 'boundProviderAuth'> & {
|
|
1973
|
+
/** Adapter instance identifier required by connector factories. */adapterId: string; /** Selected connector-local auth delivery, including plaintext. */
|
|
1974
|
+
adapterAuth?: ResolvedAdapterAuth; /** Selected managed client binary, when this adapter has a client. */
|
|
1975
|
+
clientExecution?: ClientExecutionContext; /** Auth-free environment safe for routable/shared execution contexts. */
|
|
1976
|
+
contextEnv: Readonly<Record<string, string>>;
|
|
1977
|
+
};
|
|
1978
|
+
/** Explicit connector-owned client config lease. */
|
|
1979
|
+
interface AdapterAuthLeaseHandle {
|
|
1980
|
+
/** Client whose isolated config directory is leased. */
|
|
1981
|
+
readonly clientId: string;
|
|
1982
|
+
/** Connector-unique lease identifier. */
|
|
1983
|
+
readonly leaseId: string;
|
|
1984
|
+
/** Release the lease exactly once. Repeated calls share the same result. */
|
|
1985
|
+
release(): Promise<void>;
|
|
1986
|
+
}
|
|
1987
|
+
/** Runtime config plus the lease whose lifetime must match its connector. */
|
|
1988
|
+
interface PreparedAdapterAuthRuntime<TBus extends ScopedBus<string> = ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> {
|
|
1989
|
+
/** Connector-facing config with one immutable auth snapshot. */
|
|
1990
|
+
readonly config: ResolvedAdapterRuntimeConfig<TBus, TConfig>;
|
|
1991
|
+
/** Explicit lease handle, present only for client-backed adapters. */
|
|
1992
|
+
readonly lease?: AdapterAuthLeaseHandle;
|
|
1993
|
+
}
|
|
1994
|
+
/** Trusted non-serializable strategy for preparing auth in the current host. */
|
|
1995
|
+
type AdapterAuthRuntimePreparer<TBus extends ScopedBus<string> = ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> = (config: BoundAdapterRuntimeConfig<TBus, TConfig>) => Promise<PreparedAdapterAuthRuntime<TBus, TConfig>>;
|
|
1996
|
+
/** Host-resolved auth material supplied to a runtime without local secret services. */
|
|
1997
|
+
interface SuppliedAdapterAuthRuntime {
|
|
1998
|
+
/** Auth snapshot already compiled against the selected adapter binding by the host. */
|
|
1999
|
+
readonly selectorValidatedAuth: ResolvedAdapterAuth;
|
|
2000
|
+
/** Complete host-compiled adapter auth source/sink scrub union. */
|
|
2001
|
+
readonly scrubEnvVars: readonly string[];
|
|
2002
|
+
/** Non-auth session environment supplied by the host. */
|
|
2003
|
+
readonly sessionEnv?: Readonly<Record<string, string>>;
|
|
2004
|
+
/** Pre-resolved non-auth binary environment supplied by the host. */
|
|
2005
|
+
readonly binaryEnv?: Readonly<Record<string, string>>;
|
|
2006
|
+
/** Environment for an externally-owned config lease or mounted native state. */
|
|
2007
|
+
readonly leaseEnv?: Readonly<Record<string, string>>;
|
|
2008
|
+
}
|
|
2009
|
+
/**
|
|
2010
|
+
* Prepare the single connector-local auth snapshot and client config lease.
|
|
2011
|
+
*
|
|
2012
|
+
* Explicit credential refs are resolved exactly once through the encrypted
|
|
2013
|
+
* credential channel. The existing session-environment helper remains the
|
|
2014
|
+
* sole merge authority: it scrubs the full adapter set before selected auth
|
|
2015
|
+
* values are applied last. The caller owns the returned lease and must release
|
|
2016
|
+
* it in every connector close or rollback path.
|
|
2017
|
+
* @param config - Refs-only config emitted by the adapter config factory
|
|
2018
|
+
* @returns Connector-facing config and its explicit lease handle
|
|
2019
|
+
*/
|
|
2020
|
+
declare function prepareAdapterAuthRuntime<TBus extends ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus>>(config: BoundAdapterRuntimeConfig<TBus, TConfig>): Promise<PreparedAdapterAuthRuntime<TBus, TConfig>>;
|
|
2021
|
+
/**
|
|
2022
|
+
* Apply host-resolved auth without opening credential channels or owning leases.
|
|
2023
|
+
*
|
|
2024
|
+
* This is the container/bootstrap seam. Its input must already have been
|
|
2025
|
+
* selector-validated with {@link resolveBoundProviderAuth} by the trusted host.
|
|
2026
|
+
* Every supplied non-auth source is merged before the full scrub union, then
|
|
2027
|
+
* only the selected process delivery is injected. Connector deliveries remain
|
|
2028
|
+
* structured values and are never serialized or logged here.
|
|
2029
|
+
* @param config - Connector config containing only non-auth runtime inputs
|
|
2030
|
+
* @param supplied - Host-compiled auth and non-auth environment sources
|
|
2031
|
+
* @returns Connector-facing config with one immutable auth snapshot
|
|
2032
|
+
*/
|
|
2033
|
+
declare function applySuppliedAdapterAuthRuntime<TBus extends ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus>>(config: BoundAdapterRuntimeConfig<TBus, TConfig>, supplied: SuppliedAdapterAuthRuntime): Promise<ResolvedAdapterRuntimeConfig<TBus, TConfig>>;
|
|
2034
|
+
//#endregion
|
|
2035
|
+
//#region adapters/core/src/agent/connector-runtime.d.ts
|
|
2036
|
+
/** Connector instance paired with its explicit client config lease. */
|
|
2037
|
+
interface ConnectorRuntimeHandle<TConnector extends Pick<AIAgentConnector, 'close'>> {
|
|
2038
|
+
/** Live connector instance. */
|
|
2039
|
+
readonly connector: TConnector;
|
|
2040
|
+
/** Lease whose lifetime exactly matches this connector. */
|
|
2041
|
+
readonly lease?: AdapterAuthLeaseHandle;
|
|
2042
|
+
}
|
|
2043
|
+
/** Dependencies for creating one managed connector runtime. */
|
|
2044
|
+
interface CreateConnectorRuntimeOptions<TBus extends ScopedBus<string>, TConnector extends AIAgentConnector<TBus>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> {
|
|
2045
|
+
/** Refs-only config emitted by the common adapter factory. */
|
|
2046
|
+
readonly config: BoundAdapterRuntimeConfig<TBus, TConfig>;
|
|
2047
|
+
/** Adapter connector constructor. */
|
|
2048
|
+
readonly connectorFactory: (config: ResolvedAdapterRuntimeConfig<TBus, TConfig>) => TConnector | Promise<TConnector>;
|
|
2049
|
+
/** Optional user-message callback attached only after auth preparation. */
|
|
2050
|
+
readonly onMessageSent?: (handle: MessageHandle) => void;
|
|
2051
|
+
/** Sink for connector-owned provider-session rotations; see `BaseAgentConnectorConfig`. */
|
|
2052
|
+
readonly onAdapterSessionMoved?: () => Promise<void>;
|
|
2053
|
+
/** Trusted host-local auth preparer; defaults to DirectChannel + client lease. */
|
|
2054
|
+
readonly prepareAuthRuntime?: AdapterAuthRuntimePreparer<TBus, TConfig>;
|
|
2055
|
+
}
|
|
2056
|
+
//#endregion
|
|
2057
|
+
//#region adapters/core/src/agent/agent-teardown-arbiter.d.ts
|
|
2058
|
+
/**
|
|
2059
|
+
* A connector runtime seen only as something that can be closed.
|
|
2060
|
+
*
|
|
2061
|
+
* The arbiter holds handles produced by every agent on one adapter instance, so
|
|
2062
|
+
* it cannot carry their connector types; closing is the whole of what it does
|
|
2063
|
+
* with them.
|
|
2064
|
+
*/
|
|
2065
|
+
type ClosableConnectorRuntime = ConnectorRuntimeHandle<Pick<AIAgentConnector, 'close'>>;
|
|
2066
|
+
/**
|
|
2067
|
+
* How one connector replacement ended, for the teardown waiting on it.
|
|
2068
|
+
*
|
|
2069
|
+
* **In-process only, and deliberately not a wire type.** It carries live runtime
|
|
2070
|
+
* handles, so it cannot cross a transport and no subject may take it as a
|
|
2071
|
+
* payload. Both parties are inside one adapter instance by construction — the map
|
|
2072
|
+
* it travels through is this object's own memory — so this is a boundary being
|
|
2073
|
+
* written down rather than a limitation being accepted. A future cross-process
|
|
2074
|
+
* consumer needs a *reported* form (a class plus a detail), not this one.
|
|
2075
|
+
*/
|
|
2076
|
+
interface ConnectorReplacementSettlement {
|
|
2077
|
+
/** Which runtime is current once the replacement is over. */
|
|
2078
|
+
readonly outcome: 'committed' | 'rolled-back';
|
|
2079
|
+
/**
|
|
2080
|
+
* Runtimes this replacement started or superseded and could **not** prove
|
|
2081
|
+
* closed.
|
|
2082
|
+
*
|
|
2083
|
+
* The outcome names which runtime is *current*, which is not the same question
|
|
2084
|
+
* as which started resources are still *live*: a committed replacement whose
|
|
2085
|
+
* close of the superseded runtime failed leaves that runtime holding its
|
|
2086
|
+
* connector and its lease, and a rolled-back one whose close of the replacement
|
|
2087
|
+
* failed leaves that one. A waiting teardown closes these too, best-effort, and
|
|
2088
|
+
* aggregates — so the outcome stays two-valued and every consumer keeps one
|
|
2089
|
+
* branch instead of gaining an "unsafe" third arm.
|
|
2090
|
+
*/
|
|
2091
|
+
readonly unclosed: readonly ClosableConnectorRuntime[];
|
|
2092
|
+
/**
|
|
2093
|
+
* What the closes this replacement performed **itself** observed.
|
|
2094
|
+
*
|
|
2095
|
+
* The outcome and `unclosed` together say which runtimes still need closing;
|
|
2096
|
+
* neither says how strong the replacement's own closes were. A superseded close
|
|
2097
|
+
* that reports `detached` — the ordinary answer of a process connector that
|
|
2098
|
+
* signalled a kill it did not see land — fails nothing, so it appears in neither
|
|
2099
|
+
* field, and a teardown aggregating only its own closes would then answer for the
|
|
2100
|
+
* agent more strongly than the runtime it inherited the end of ever allowed.
|
|
2101
|
+
*
|
|
2102
|
+
* So the reports travel and the waiting teardown aggregates them with its own.
|
|
2103
|
+
* This is the same rule as everywhere else in this seam: whoever is last
|
|
2104
|
+
* answerable reports, and the weakest class in the set is the answer.
|
|
2105
|
+
*/
|
|
2106
|
+
readonly closeReports: readonly TeardownReport[];
|
|
2107
|
+
}
|
|
2108
|
+
/**
|
|
2109
|
+
* What a replacement learns about its waiter at the instant it settles.
|
|
2110
|
+
*
|
|
2111
|
+
* Two different questions, and a replacement acts on both: *who closes the
|
|
2112
|
+
* runtimes* and *who reports the closes already performed*. They are not the same
|
|
2113
|
+
* question, because a settlement can have no waiter at all — the ordinary case,
|
|
2114
|
+
* with no teardown anywhere — and then nobody abandoned anything and nobody took
|
|
2115
|
+
* the reports either.
|
|
2116
|
+
*/
|
|
2117
|
+
interface ConnectorSwapHandover {
|
|
2118
|
+
/**
|
|
2119
|
+
* A teardown gave up waiting, making both runtimes this replacement's to close.
|
|
2120
|
+
*
|
|
2121
|
+
* Distinct from the case below: an expired waiter inherits *obligations*, an
|
|
2122
|
+
* absent one never had any.
|
|
2123
|
+
*/
|
|
2124
|
+
readonly abandonedByWaiter: boolean;
|
|
2125
|
+
/**
|
|
2126
|
+
* A teardown received this settlement, so its {@link
|
|
2127
|
+
* ConnectorReplacementSettlement.closeReports} are already answered for.
|
|
2128
|
+
*
|
|
2129
|
+
* `false` covers both an absent waiter and an expired one, and the replacement
|
|
2130
|
+
* treats them alike: the reports have no consumer, so they travel to the party
|
|
2131
|
+
* that is still answerable for the agent instead of being discarded.
|
|
2132
|
+
*/
|
|
2133
|
+
readonly reportsConsumedByWaiter: boolean;
|
|
2134
|
+
}
|
|
2135
|
+
/** The admission a replacement holds between the door and its own `finally`. */
|
|
2136
|
+
interface ConnectorSwapAdmission {
|
|
2137
|
+
/**
|
|
2138
|
+
* Settle this replacement and learn what became of its waiter.
|
|
2139
|
+
*
|
|
2140
|
+
* Called before the post-settlement work in the `finally` of the very function
|
|
2141
|
+
* that took the admission, so a teardown already waiting can proceed. That
|
|
2142
|
+
* function retires the admission after its post-settlement work finishes.
|
|
2143
|
+
* @param settlement - Which runtime is current, and what could not be proven closed
|
|
2144
|
+
* @returns Who closes what is left, and whether anybody took the reports
|
|
2145
|
+
*/
|
|
2146
|
+
settle: (settlement: ConnectorReplacementSettlement) => ConnectorSwapHandover;
|
|
2147
|
+
/**
|
|
2148
|
+
* Retire this replacement from identity-wide visibility after its own
|
|
2149
|
+
* post-settlement obligations finish.
|
|
2150
|
+
*
|
|
2151
|
+
* Settlement removes only current-runtime handover eligibility so a teardown
|
|
2152
|
+
* can proceed. Retirement is deliberately separate: an abandoned waiter makes
|
|
2153
|
+
* the coordinator close inherited runtimes after settlement, and no-entry
|
|
2154
|
+
* disposal must remain `unknown` until those closes finish. Repeated calls are
|
|
2155
|
+
* harmless.
|
|
2156
|
+
*/
|
|
2157
|
+
retire: () => void;
|
|
2158
|
+
}
|
|
2159
|
+
/** What a teardown flight needs from the registry that owns the agent. */
|
|
2160
|
+
interface TeardownSubject {
|
|
2161
|
+
/**
|
|
2162
|
+
* Close whichever runtime the agent holds now, and report.
|
|
2163
|
+
*
|
|
2164
|
+
* Called after any replacement has settled, which is what makes "the runtime
|
|
2165
|
+
* current for that outcome" automatic: a committed replacement published its
|
|
2166
|
+
* own, a rolled-back one restored the previous.
|
|
2167
|
+
*/
|
|
2168
|
+
readonly closeCurrent: () => Promise<TeardownReport>;
|
|
2169
|
+
/**
|
|
2170
|
+
* Close one runtime a settlement could not prove closed.
|
|
2171
|
+
* @param runtime - Handle reported as unclosed
|
|
2172
|
+
*/
|
|
2173
|
+
readonly closeUnclosed: (runtime: ClosableConnectorRuntime) => Promise<TeardownReport>;
|
|
2174
|
+
/**
|
|
2175
|
+
* Give the agent's identity up without closing anything.
|
|
2176
|
+
*
|
|
2177
|
+
* Separate from the closes because the two are separable: an agent stops being
|
|
2178
|
+
* the instance that answers for its ID at the instant this teardown gives up on
|
|
2179
|
+
* it, whatever the connector replacement it abandoned later does with the
|
|
2180
|
+
* runtimes. Only the expiry arm calls it — every other arm reaches
|
|
2181
|
+
* `AIAgent.close()`, which takes the wiring down itself.
|
|
2182
|
+
*/
|
|
2183
|
+
readonly releaseIdentity: () => void;
|
|
2184
|
+
/**
|
|
2185
|
+
* Absolute deadline of the request driving this teardown, when it has one.
|
|
2186
|
+
*
|
|
2187
|
+
* Present for an RPC-driven stop, absent for a session close that fans out
|
|
2188
|
+
* over every agent it owns — which is exactly the path where the policy
|
|
2189
|
+
* ceiling stands alone.
|
|
2190
|
+
*/
|
|
2191
|
+
readonly deadline?: number | undefined;
|
|
2192
|
+
}
|
|
2193
|
+
/** Arbitrate teardowns and connector replacements for one adapter instance. */
|
|
2194
|
+
declare class AgentTeardownArbiter {
|
|
2195
|
+
/**
|
|
2196
|
+
* Teardowns in flight, keyed by agent.
|
|
2197
|
+
*
|
|
2198
|
+
* Installed **before** any close starts and removed in a `finally`, which is
|
|
2199
|
+
* what makes joining total: a second caller reads the answer the first is
|
|
2200
|
+
* already producing, and a reentrant close triggered by the first one's own
|
|
2201
|
+
* lifecycle event joins the flight that emitted it.
|
|
2202
|
+
*/
|
|
2203
|
+
private readonly teardowns;
|
|
2204
|
+
/** The newest replacement eligible to hand a teardown its current runtime. */
|
|
2205
|
+
private readonly swaps;
|
|
2206
|
+
/** Replacements with post-settlement obligations, keyed by agent. */
|
|
2207
|
+
private readonly swapRetirementCounts;
|
|
2208
|
+
/**
|
|
2209
|
+
* Whether a teardown of this agent is in flight.
|
|
2210
|
+
*
|
|
2211
|
+
* "Nothing here" is only true when nothing is in flight, so a caller answering
|
|
2212
|
+
* that question asks this one too rather than reading the registry alone.
|
|
2213
|
+
* @param agentId - Agent to probe
|
|
2214
|
+
* @returns Whether a flight is installed for it
|
|
2215
|
+
*/
|
|
2216
|
+
hasTeardownInFlight(agentId: string): boolean;
|
|
2217
|
+
/**
|
|
2218
|
+
* Whether a connector replacement of this agent is in flight.
|
|
2219
|
+
*
|
|
2220
|
+
* **The state an expiry leaves behind.** A teardown that gave up waiting removes
|
|
2221
|
+
* its own flight and its registry entry, while the replacement it abandoned still
|
|
2222
|
+
* holds *both* runtimes and closes neither until it settles. So a caller
|
|
2223
|
+
* answering "nothing on this instance can still be speaking for that identity"
|
|
2224
|
+
* asks this question too: without it, the one answer that frees an identity is
|
|
2225
|
+
* given while two live connectors answer for it.
|
|
2226
|
+
*
|
|
2227
|
+
* **Any** admitted replacement counts until its retirement, not only the newest:
|
|
2228
|
+
* a superseded predecessor holds runtimes and closes them on its own schedule,
|
|
2229
|
+
* so an identity is free only once every replacement admitted on it has finished
|
|
2230
|
+
* its post-settlement obligations.
|
|
2231
|
+
* @param agentId - Agent to probe
|
|
2232
|
+
* @returns Whether a replacement is installed for it
|
|
2233
|
+
*/
|
|
2234
|
+
hasReplacementInFlight(agentId: string): boolean;
|
|
2235
|
+
/**
|
|
2236
|
+
* Admit a connector replacement, or refuse it.
|
|
2237
|
+
*
|
|
2238
|
+
* **The door, and the entire boundary between the two acts.** It is a
|
|
2239
|
+
* synchronous prologue with no await between its steps, which is what makes the
|
|
2240
|
+
* two arbitration regions exhaustive: a teardown is either installed before this
|
|
2241
|
+
* instant or it is not, and there is no interval in between for one to arrive
|
|
2242
|
+
* in.
|
|
2243
|
+
*
|
|
2244
|
+
* Refusing costs nothing here — no replacement runtime exists yet, no provider
|
|
2245
|
+
* thread has been started, no lifecycle event has been delivered and no account
|
|
2246
|
+
* transition has been committed. Whatever a producer did *before* reaching the
|
|
2247
|
+
* door is the producer's own to compensate, which every producer already does.
|
|
2248
|
+
* @param agentId - Agent whose connector would be replaced
|
|
2249
|
+
* @param hasConnectorRuntime - Read of the agent's runtime presence, evaluated
|
|
2250
|
+
* inside the prologue so its refusal is ordered after the teardown read
|
|
2251
|
+
* @returns The admission whose settlement the door must resolve
|
|
2252
|
+
* @throws ConnectorSwapVetoedError When a teardown is in flight, or the agent
|
|
2253
|
+
* holds no runtime to replace
|
|
2254
|
+
*/
|
|
2255
|
+
admitSwap(agentId: string, hasConnectorRuntime: () => boolean): ConnectorSwapAdmission;
|
|
2256
|
+
/**
|
|
2257
|
+
* Run — or join — the single teardown flight for one agent.
|
|
2258
|
+
*
|
|
2259
|
+
* The flight **writes no status**: the four entry points want different
|
|
2260
|
+
* terminal effects, so a plan carried into the flight would make the terminal
|
|
2261
|
+
* status depend on which caller won the race, and applying the effects after a
|
|
2262
|
+
* join would write it twice. Removing status from the flight dissolves both, and
|
|
2263
|
+
* costs nothing because the statuses are already idempotent — `disposed` is
|
|
2264
|
+
* terminal in storage, so the *effective* terminal status is `disposed` whenever
|
|
2265
|
+
* a disposal participated, in either order.
|
|
2266
|
+
*
|
|
2267
|
+
* Reading the replacement map is the flight's **first act after installing its
|
|
2268
|
+
* own entry**, and that order is what makes the arbitration total: a replacement
|
|
2269
|
+
* beginning after the install finds this flight and refuses, one that began
|
|
2270
|
+
* before it is awaited rather than raced.
|
|
2271
|
+
*
|
|
2272
|
+
* **The install happens before the body runs, not after it returns.** An async
|
|
2273
|
+
* function runs synchronously up to its first await, and the body reaches
|
|
2274
|
+
* `closeCurrent()` — and through it `agent.session.closed` — inside that window.
|
|
2275
|
+
* Writing the map with the promise the body returned would leave a synchronously
|
|
2276
|
+
* reentrant teardown unable to see the flight that provoked it, making
|
|
2277
|
+
* reentrancy safe only by the emitter's scheduling rather than by construction.
|
|
2278
|
+
* A deferred promise is what makes the installation first.
|
|
2279
|
+
* @param agentId - Agent being torn down
|
|
2280
|
+
* @param subject - How to close this agent's runtimes, and the caller's deadline
|
|
2281
|
+
* @returns What the teardown observed — the joined answer for a second caller
|
|
2282
|
+
*/
|
|
2283
|
+
runTeardown(agentId: string, subject: TeardownSubject): Promise<TeardownReport>;
|
|
2284
|
+
/**
|
|
2285
|
+
* Run the flight body and hand its answer to the installed promise.
|
|
2286
|
+
*
|
|
2287
|
+
* Separated from {@link runTeardown} so the installation stays synchronous: this
|
|
2288
|
+
* is the first thing that may await, and by the time it does the map already
|
|
2289
|
+
* carries the flight. The removal is in a `finally` and therefore runs in the same
|
|
2290
|
+
* synchronous continuation as the settlement, so no joiner can resume and find
|
|
2291
|
+
* the entry still there.
|
|
2292
|
+
* @param agentId - Agent being torn down
|
|
2293
|
+
* @param subject - How to close this agent's runtimes, and the caller's deadline
|
|
2294
|
+
* @param deferred - The promise already installed for this flight
|
|
2295
|
+
*/
|
|
2296
|
+
private settleFlight;
|
|
2297
|
+
/**
|
|
2298
|
+
* The flight body: arbitrate against any replacement, then close.
|
|
2299
|
+
* @param agentId - Agent being torn down
|
|
2300
|
+
* @param subject - How to close this agent's runtimes, and the caller's deadline
|
|
2301
|
+
* @returns What the teardown observed
|
|
2302
|
+
*/
|
|
2303
|
+
private flyTeardown;
|
|
2304
|
+
/**
|
|
2305
|
+
* Wait for a replacement to settle, bounded by the caller's own budget.
|
|
2306
|
+
*
|
|
2307
|
+
* **The waiter takes its own bound**, because a contract may not claim
|
|
2308
|
+
* boundedness while making a teardown wait on somebody else's discipline. The
|
|
2309
|
+
* effective wait is the smaller of the policy ceiling and what remains of the
|
|
2310
|
+
* caller's deadline less one observation margin; the margin is that constant
|
|
2311
|
+
* because the expiry arm closes nothing, so all that remains after it is a
|
|
2312
|
+
* status write and the reply.
|
|
2313
|
+
*
|
|
2314
|
+
* **What this bound proves, and nothing beyond it:** the wait itself always
|
|
2315
|
+
* expires with at least one observation margin of the caller's budget
|
|
2316
|
+
* unconsumed, so it can never consume the whole outer budget on its own.
|
|
2317
|
+
* Response *reachability* stays best-effort while the post-wait tail is
|
|
2318
|
+
* unbounded — a caller whose deadline expires receives its timeout by bus law,
|
|
2319
|
+
* and from inside here that is indistinguishable from the tail being slow.
|
|
2320
|
+
*
|
|
2321
|
+
* Below the margin the clamp yields a **zero wait**: the teardown does not wait
|
|
2322
|
+
* at all and answers as fast as it can. Marking the abandonment synchronously in
|
|
2323
|
+
* that arm is load-bearing — it must be visible to a door whose own settlement
|
|
2324
|
+
* has already resolved.
|
|
2325
|
+
* @param swap - Replacement entry found in flight
|
|
2326
|
+
* @param deadline - Absolute deadline of the request driving this teardown
|
|
2327
|
+
* @returns The settlement, or `undefined` when the bound expired first
|
|
2328
|
+
*/
|
|
2329
|
+
private awaitSettlement;
|
|
2330
|
+
}
|
|
2331
|
+
//#endregion
|
|
2332
|
+
//#region adapters/core/src/adapter/ai-adapter-config.d.ts
|
|
2333
|
+
/**
|
|
2334
|
+
* Input provided by agent to the config factory.
|
|
2335
|
+
* Contains partial configuration - adapters provide defaults for missing required fields.
|
|
2336
|
+
*
|
|
2337
|
+
* Includes all runtime options from StartAgentRequest (allowedTools, disallowedTools, etc.)
|
|
2338
|
+
* to ensure they flow through to the connector.
|
|
2339
|
+
*/
|
|
2340
|
+
interface ConfigFactoryInput<TBus extends ScopedBus<string> = ScopedBus<string>> {
|
|
2341
|
+
/** Scoped bus for adapter-specific events */
|
|
2342
|
+
bus: TBus;
|
|
2343
|
+
/** Global bus for cross-namespace runtime requests */
|
|
2344
|
+
globalBus?: IMakaioBus;
|
|
2345
|
+
/** Unique agent identifier (required - generated by AIAgent) */
|
|
2346
|
+
agentId: string;
|
|
2347
|
+
/** Adapter instance identifier (required - provided by AIAgent from adapter) */
|
|
2348
|
+
adapterId: string;
|
|
2349
|
+
/** Adapter type name (required - provided by AIAgent from adapter) */
|
|
2350
|
+
adapterName: string;
|
|
2351
|
+
/** Refs-only normalized provider selection consumed by the common auth runtime. */
|
|
2352
|
+
providerContext: ProviderContext;
|
|
2353
|
+
/** Exact HTTP protocol declared by the selected adapter/provider reference. */
|
|
2354
|
+
providerProtocol?: ProtocolId;
|
|
2355
|
+
/** Adapter/provider auth metadata selected by `providerContext.definitionId`. */
|
|
2356
|
+
adapterProviderAuth?: AdapterProviderAuth;
|
|
2357
|
+
/** Other adapter/provider auth declarations contributing to the scrub union. */
|
|
2358
|
+
compatibleProviderAuths?: readonly AdapterProviderAuth[];
|
|
2359
|
+
/** Whether this adapter rejects the unresolved provider state. */
|
|
2360
|
+
providerContextRequired?: boolean;
|
|
2361
|
+
/** Provider's session ID for resuming existing conversations */
|
|
2362
|
+
adapterSessionId?: string;
|
|
2363
|
+
/** Makaio session ID for tool execution context and multi-session correlation */
|
|
2364
|
+
sessionId?: string;
|
|
2365
|
+
/** Previous adapter session ID for resume attempts (from recovery). */
|
|
2366
|
+
resumeAdapterSessionId?: string;
|
|
2367
|
+
/** Model to use - optional, adapters provide defaults */
|
|
2368
|
+
model?: string;
|
|
2369
|
+
/** Working directory for agent execution */
|
|
2370
|
+
cwd?: string;
|
|
2371
|
+
/** Environment variables to pass to agent execution */
|
|
2372
|
+
env?: Record<string, string>;
|
|
2373
|
+
/** Reasoning effort for supporting adapters */
|
|
2374
|
+
reasoningEffort?: AIReasoningLevel$1;
|
|
2375
|
+
/** Reasoning levels supported by the resolved model, forwarded to the connector. */
|
|
2376
|
+
supportedReasoningLevels?: ReasoningLevelMap$1;
|
|
2377
|
+
/** Error handler for connector errors */
|
|
2378
|
+
errorHandler?: (error: Error, terminate: boolean) => void;
|
|
2379
|
+
/** Allowed tool names (adapter-specific). Empty array = disable all tools. */
|
|
2380
|
+
allowedTools?: string[];
|
|
2381
|
+
/** Disallowed tool names (adapter-specific). Takes precedence over allowedTools. */
|
|
2382
|
+
disallowedTools?: string[];
|
|
2383
|
+
/** Directory restrictions for file-system tool execution. */
|
|
2384
|
+
allowedDirectories?: string[];
|
|
2385
|
+
/**
|
|
2386
|
+
* Adapter-specific per-call configuration (non-credential settings).
|
|
2387
|
+
*
|
|
2388
|
+
* This receives `startAgent.adapterConfig` at runtime and feeds the existing
|
|
2389
|
+
* `createAdapterConfigFactory` providerConfig merge slot. It is unrelated to
|
|
2390
|
+
* ProviderConfig credential entities, which flow through `providerContext`.
|
|
2391
|
+
*/
|
|
2392
|
+
providerConfig?: Record<string, unknown>;
|
|
2393
|
+
runtimeTimeouts?: TimeoutConfig;
|
|
2394
|
+
/** Client identifier for the application this adapter belongs to (e.g., 'claude-code', 'gemini'). */
|
|
2395
|
+
clientId?: string;
|
|
2396
|
+
/** Client profile name for session-scoped config isolation. */
|
|
2397
|
+
clientProfileName?: string;
|
|
2398
|
+
/** Harness identifier used to resolve per-agent tool governance. */
|
|
2399
|
+
harnessId?: string;
|
|
2400
|
+
/**
|
|
2401
|
+
* Resolved MCP session context including upstream server configs.
|
|
2402
|
+
* When present, native-passthrough adapters use `servers` to configure SDK MCP connections.
|
|
2403
|
+
*/
|
|
2404
|
+
mcpSessionContext?: LedgerSessionContext | McpRuntimeSessionContext | McpSessionContext;
|
|
2405
|
+
/**
|
|
2406
|
+
* Session-scoped MCP tool ledger.
|
|
2407
|
+
* Passed through unchanged so connectors can track injection and mcp_call usage.
|
|
2408
|
+
*/
|
|
2409
|
+
toolLedger?: ISessionToolLedger;
|
|
2410
|
+
/**
|
|
2411
|
+
* When true, the agent is ephemeral (one-shot, not a resume/fork target).
|
|
2412
|
+
*
|
|
2413
|
+
* Ephemeral agents skip PreUserMessage hooks and are never resumed or forked
|
|
2414
|
+
* natively. Connectors should disable session persistence for ephemeral agents
|
|
2415
|
+
* so no transcript is written to the provider's session store.
|
|
2416
|
+
*/
|
|
2417
|
+
ephemeral?: boolean;
|
|
2418
|
+
/**
|
|
2419
|
+
* Whether this agent's provider session is this adapter's to publish yet.
|
|
2420
|
+
*
|
|
2421
|
+
* Absent means yes, which is every adapter-owned agent: the adapter is the
|
|
2422
|
+
* only publisher such an agent has. It answers `false` for the window in which
|
|
2423
|
+
* a **caller-owned** start has not handed its key over — the caller reserved
|
|
2424
|
+
* the provider session and settles the key its connector confirms, so an
|
|
2425
|
+
* announcement or an event field from here would publish a key no generation
|
|
2426
|
+
* holds yet, and the observer would settle it under a token that caller's
|
|
2427
|
+
* failure paths cannot name.
|
|
2428
|
+
*
|
|
2429
|
+
* A predicate rather than a flag because the window has an end the adapter can
|
|
2430
|
+
* observe — its own registration — and no new state to keep in step with it.
|
|
2431
|
+
*/
|
|
2432
|
+
isProviderKeyPublishable?: () => boolean;
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
2435
|
+
* Interface for adapter-specific configuration factories.
|
|
2436
|
+
*
|
|
2437
|
+
* Transforms partial ConfigFactoryInput into full adapter-specific config.
|
|
2438
|
+
* The key responsibility is applying adapter defaults (especially model).
|
|
2439
|
+
* @example
|
|
2440
|
+
* ```typescript
|
|
2441
|
+
* const OpenAIConfigFactory: IAdapterConfigFactory<OpenAINodeAgentConfig> = {
|
|
2442
|
+
* getConfig: async (input) => ({
|
|
2443
|
+
* ...input,
|
|
2444
|
+
* model: input.model ?? 'gpt-4o',
|
|
2445
|
+
* providerConfig: { debugMode: true },
|
|
2446
|
+
* }),
|
|
2447
|
+
* };
|
|
2448
|
+
* ```
|
|
2449
|
+
*/
|
|
2450
|
+
interface IAdapterConfigFactory<TConfig extends BaseAgentConnectorConfig, TBus extends ScopedBus<string> = ScopedBus<string>> {
|
|
2451
|
+
getConfig(input: ConfigFactoryInput<TBus>): Promise<TConfig>;
|
|
2452
|
+
}
|
|
2453
|
+
//#endregion
|
|
2454
|
+
//#region adapters/core/src/types/provider-definition.d.ts
|
|
2455
|
+
/**
|
|
2456
|
+
* Runtime adapter provider definition pairing a serializable provider definition
|
|
2457
|
+
* with optional runtime-only provider configuration metadata.
|
|
2458
|
+
*
|
|
2459
|
+
* Aliases {@link AdapterProviderDefinitionContract} from `@makaio/contracts`,
|
|
2460
|
+
* the single source of truth for the `definition` and `configSchema` fields.
|
|
2461
|
+
* The domain-specific name keeps adapter implementation signatures readable
|
|
2462
|
+
* without creating a second provider-definition contract.
|
|
2463
|
+
*
|
|
2464
|
+
* Each adapter exports an array of these from its `definition.ts` (via `providers`).
|
|
2465
|
+
* The `definition` field contains serializable data (models, endpoints, etc.).
|
|
2466
|
+
* Config schemas are runtime-only — used for UI form generation, never serialized.
|
|
2467
|
+
*/
|
|
2468
|
+
type AdapterProviderDefinition = AdapterProviderDefinitionContract;
|
|
2469
|
+
//#endregion
|
|
2470
|
+
//#region adapters/core/src/agent/types.d.ts
|
|
2471
|
+
/**
|
|
2472
|
+
* Core agent identity fields.
|
|
2473
|
+
* Used as base for contexts, configs, and request payloads.
|
|
2474
|
+
*/
|
|
2475
|
+
interface AgentIdentity {
|
|
2476
|
+
/** Unique agent identifier */
|
|
2477
|
+
agentId: string;
|
|
2478
|
+
/** Adapter instance identifier */
|
|
2479
|
+
adapterId: string;
|
|
2480
|
+
/** Adapter type name (e.g., 'claude-code', 'gemini-sdk') */
|
|
2481
|
+
adapterName: string;
|
|
2482
|
+
/** Session identifier for multi-turn conversations */
|
|
2483
|
+
adapterSessionId?: string;
|
|
2484
|
+
}
|
|
2485
|
+
/**
|
|
2486
|
+
* Runtime options as INPUT - model/cwd optional (adapters provide defaults via configFactory).
|
|
2487
|
+
*/
|
|
2488
|
+
interface AgentRuntimeInput {
|
|
2489
|
+
/** Model to use (optional - adapter provides default) */
|
|
2490
|
+
model?: string;
|
|
2491
|
+
/** Working directory for agent execution (optional - platform provides default) */
|
|
2492
|
+
cwd?: string;
|
|
2493
|
+
/** Environment variables to pass to agent execution */
|
|
2494
|
+
env?: Record<string, string>;
|
|
2495
|
+
/** Reasoning effort for supporting adapters */
|
|
2496
|
+
reasoningEffort?: AIReasoningLevel$1;
|
|
2497
|
+
/** Allowed tool names. Empty array disables all adapter-visible tools. */
|
|
2498
|
+
allowedTools?: string[];
|
|
2499
|
+
/** Disallowed tool names. Takes precedence over allowedTools. */
|
|
2500
|
+
disallowedTools?: string[];
|
|
2501
|
+
}
|
|
2502
|
+
/**
|
|
2503
|
+
* Runtime options as RESOLVED config - model/cwd required (after configFactory applies defaults).
|
|
2504
|
+
*/
|
|
2505
|
+
type AgentRuntimeOptions = SetRequired<AgentRuntimeInput, 'model' | 'cwd'>;
|
|
2506
|
+
/**
|
|
2507
|
+
* Common context fields for all agent.* subject emissions.
|
|
2508
|
+
* AIAgent automatically enriches payloads with these fields.
|
|
2509
|
+
*/
|
|
2510
|
+
type AgentContext = Required<AgentIdentity>;
|
|
2511
|
+
/**
|
|
2512
|
+
* Execution context for per-agent processors.
|
|
2513
|
+
* Baked in at processor creation time, eliminating runtime registry lookups.
|
|
2514
|
+
*/
|
|
2515
|
+
type ExecutionContext = AgentContext;
|
|
2516
|
+
interface MinimalAgentConnectorConfig<TBus extends ScopedBus<string> = ScopedBus<string>> {
|
|
2517
|
+
bus: TBus;
|
|
2518
|
+
globalBus?: IMakaioBus;
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* Base configuration for AI agent connector instances.
|
|
2522
|
+
*/
|
|
2523
|
+
interface BaseAgentConnectorConfig<TBus extends ScopedBus<string> = ScopedBus<string>, TProviderConfig extends object = object> extends MinimalAgentConnectorConfig<TBus>, Omit<AgentIdentity, 'adapterId'>, AgentRuntimeOptions {
|
|
2524
|
+
/** Makaio session ID for tool execution context and multi-session correlation */
|
|
2525
|
+
sessionId?: string;
|
|
2526
|
+
errorHandler?: (error: Error, terminate: boolean) => void;
|
|
2527
|
+
/**
|
|
2528
|
+
* Resolved timeout configuration with provenance tracking.
|
|
2529
|
+
* Set by configFactory after merging all timeout layers.
|
|
2530
|
+
*/
|
|
2531
|
+
timeouts?: TrackedTimeoutConfig;
|
|
2532
|
+
/**
|
|
2533
|
+
* UUID of the ProviderConfig entity used during agent creation.
|
|
2534
|
+
* Carried on the connector config for runtime introspection and dynamic provider switching.
|
|
2535
|
+
*/
|
|
2536
|
+
providerConfigId?: string;
|
|
2537
|
+
/**
|
|
2538
|
+
* Refs-only normalized provider selection retained for runtime introspection.
|
|
2539
|
+
* Plaintext authentication is available only through {@link adapterAuth}.
|
|
2540
|
+
*/
|
|
2541
|
+
providerContext?: ProviderContext;
|
|
2542
|
+
/** Exact HTTP protocol selected by the active adapter/provider reference. */
|
|
2543
|
+
providerProtocol?: ProtocolId;
|
|
2544
|
+
providerConfig?: TProviderConfig;
|
|
2545
|
+
/**
|
|
2546
|
+
* Maps supported reasoning levels to provider-native values for the active model.
|
|
2547
|
+
*
|
|
2548
|
+
* Populated by the config factory when the resolved model declares reasoning support.
|
|
2549
|
+
* Absent when the model does not support extended thinking.
|
|
2550
|
+
*/
|
|
2551
|
+
supportedReasoningLevels?: ReasoningLevelMap$1;
|
|
2552
|
+
/** Previous adapter session ID for resume attempts. */
|
|
2553
|
+
resumeAdapterSessionId?: string;
|
|
2554
|
+
/**
|
|
2555
|
+
* Provider-native fork directive approved by session orchestration.
|
|
2556
|
+
* When present, native-fork capable connectors should branch from the source
|
|
2557
|
+
* provider session instead of starting fresh with replayed history.
|
|
2558
|
+
*/
|
|
2559
|
+
nativeFork?: NativeForkDirective;
|
|
2560
|
+
/** Resolved harness ID for tool policy lookup. */
|
|
2561
|
+
harnessId?: string;
|
|
2562
|
+
/** Client identifier for the application this adapter belongs to (e.g., 'claude-code', 'gemini'). */
|
|
2563
|
+
clientId?: string;
|
|
2564
|
+
/** Client profile name for session-scoped config isolation. */
|
|
2565
|
+
clientProfileName?: string;
|
|
2566
|
+
/**
|
|
2567
|
+
* Auth-free environment safe for bus-routable tool and MCP contexts.
|
|
2568
|
+
*
|
|
2569
|
+
* The central adapter runtime derives this from the same merged inputs as
|
|
2570
|
+
* `env`, but omits the selected process authentication delivery.
|
|
2571
|
+
*/
|
|
2572
|
+
contextEnv?: Readonly<Record<string, string>>;
|
|
2573
|
+
/**
|
|
2574
|
+
* Single connector-local normalized auth snapshot.
|
|
2575
|
+
*
|
|
2576
|
+
* Plaintext exists only on this trusted connector config and must never be
|
|
2577
|
+
* emitted, persisted, stringified, or copied back into provider context.
|
|
2578
|
+
*/
|
|
2579
|
+
adapterAuth?: ResolvedAdapterAuth;
|
|
2580
|
+
/** Managed client binary selected by the central runtime, when applicable. */
|
|
2581
|
+
clientExecution?: ClientExecutionContext;
|
|
2582
|
+
/** Callback when a user message is enqueued */
|
|
2583
|
+
onMessageSent?: (messageHandle: MessageHandle) => void;
|
|
2584
|
+
/**
|
|
2585
|
+
* Announce that the connector rotated its provider session with no confirmed
|
|
2586
|
+
* successor yet.
|
|
2587
|
+
*
|
|
2588
|
+
* For rotations the executor can predict, the movement seam is driven from the
|
|
2589
|
+
* pre-dispatch check in `AgentTurnExecutor` (see
|
|
2590
|
+
* `agent/agent-adapter-session-movement.ts`). A connector that rotates on a
|
|
2591
|
+
* decision only it can observe — the CLI's immediate-mode restart, which kills
|
|
2592
|
+
* the in-flight subprocess and mints a fresh identity — must announce that
|
|
2593
|
+
* movement itself, and `await` it before the dispatch that abandons the old
|
|
2594
|
+
* provider session (duty 2).
|
|
2595
|
+
*
|
|
2596
|
+
* Injected by the owning agent, so the announcement routes through its
|
|
2597
|
+
* `ConfirmedAdapterSessionTracker` and inherits the seam's retry anchor
|
|
2598
|
+
* (duties 3 and 4) instead of emitting one unrecoverable event.
|
|
2599
|
+
*/
|
|
2600
|
+
onAdapterSessionMoved?: () => Promise<void>;
|
|
2601
|
+
/**
|
|
2602
|
+
* Directory restrictions for file-system tool execution.
|
|
2603
|
+
* When set, forwarded as `constraints.allowedDirectories` in every tool call.
|
|
2604
|
+
* Empty array means no restriction; undefined means no restriction.
|
|
2605
|
+
*/
|
|
2606
|
+
allowedDirectories?: string[];
|
|
2607
|
+
/**
|
|
2608
|
+
* MCP session context resolved by the orchestrator.
|
|
2609
|
+
* Provides the direct and discoverable tool sets for the current session.
|
|
2610
|
+
* When present, enables MCP tool injection and ledger tracking.
|
|
2611
|
+
*
|
|
2612
|
+
* Intentionally narrowed to LedgerSessionContext — the minimal shape the
|
|
2613
|
+
* ledger needs. Adapters requiring the full McpSessionContext (with
|
|
2614
|
+
* resolution keys / servers) re-declare this field via Omit + intersection
|
|
2615
|
+
* in their own config types (e.g. BaseStreamConnectorConfig, ClaudeAgentConfig).
|
|
2616
|
+
*/
|
|
2617
|
+
mcpSessionContext?: LedgerSessionContext | McpRuntimeSessionContext | McpSessionContext;
|
|
2618
|
+
/**
|
|
2619
|
+
* Session-scoped tool ledger for tracking injection, discovery, and call history.
|
|
2620
|
+
* When present, the connector records tool events into this ledger.
|
|
2621
|
+
*/
|
|
2622
|
+
toolLedger?: ISessionToolLedger;
|
|
2623
|
+
/**
|
|
2624
|
+
* When true, the connector is handling an ephemeral one-shot agent.
|
|
2625
|
+
*
|
|
2626
|
+
* Ephemeral agents are by contract never resume or fork targets. Connectors
|
|
2627
|
+
* that support session persistence should disable it for ephemeral agents so
|
|
2628
|
+
* no transcript is written to the provider's session store.
|
|
2629
|
+
*/
|
|
2630
|
+
ephemeral?: boolean;
|
|
2631
|
+
}
|
|
2632
|
+
/**
|
|
2633
|
+
* Configuration for creating an AIAgent instance.
|
|
2634
|
+
*
|
|
2635
|
+
* Combines agent identity, runtime input, and factory functions.
|
|
2636
|
+
* model/cwd are optional here - configFactory provides adapter defaults.
|
|
2637
|
+
* @typeParam TBus - The scoped bus type for this adapter
|
|
2638
|
+
* @typeParam TConnector - The connector type (for proper factory return typing)
|
|
2639
|
+
*/
|
|
2640
|
+
interface AIAgentConfig<TBus extends ScopedBus<string> = ScopedBus<string>, TConnector extends AIAgentConnector<TBus> = AIAgentConnector<TBus>> extends Omit<AgentIdentity, 'adapterSessionId'>, AgentRuntimeInput {
|
|
2641
|
+
/** Adapter-specific session identifier for multi-turn conversations */
|
|
2642
|
+
adapterSessionId?: string;
|
|
2643
|
+
/** Makaio session identifier */
|
|
2644
|
+
sessionId?: string;
|
|
2645
|
+
/** Refs-only normalized provider selection set by session orchestration. */
|
|
2646
|
+
providerContext?: ProviderContext;
|
|
2647
|
+
/** Previous adapter session ID for resume attempts (from recovery). */
|
|
2648
|
+
resumeAdapterSessionId?: string;
|
|
2649
|
+
/** Resolved harness ID for tool policy lookup. */
|
|
2650
|
+
harnessId?: string;
|
|
2651
|
+
/** Client identifier for the application this adapter belongs to (e.g., 'claude-code', 'gemini'). */
|
|
2652
|
+
clientId?: string;
|
|
2653
|
+
/** Client profile name for session-scoped config isolation. */
|
|
2654
|
+
clientProfileName?: string;
|
|
2655
|
+
/** Trusted non-serializable auth preparation strategy injected by the host. */
|
|
2656
|
+
prepareAuthRuntime?: AdapterAuthRuntimePreparer<TBus>;
|
|
2657
|
+
/** Global bus instance (defaults to MakaioBus singleton) */
|
|
2658
|
+
globalBus?: IMakaioBus;
|
|
2659
|
+
/** Scoped bus for adapter-specific events */
|
|
2660
|
+
adapterBus: TBus;
|
|
2661
|
+
/**
|
|
2662
|
+
* Adapter-instance arbiter between teardowns and connector replacements.
|
|
2663
|
+
*
|
|
2664
|
+
* **Required**, and that is the point: the arbiter is what makes "replacements
|
|
2665
|
+
* refuse when they find a teardown, teardowns wait when they find a
|
|
2666
|
+
* replacement" a property of the module rather than a convention. An agent
|
|
2667
|
+
* constructed without one would replace connectors with no arbitration at all,
|
|
2668
|
+
* so it does not compile.
|
|
2669
|
+
*/
|
|
2670
|
+
teardownArbiter: AgentTeardownArbiter;
|
|
2671
|
+
/** Adapter capabilities (e.g., ['streaming', 'tools', 'vision']) */
|
|
2672
|
+
capabilities: string[];
|
|
2673
|
+
/** Native tools built into the adapter (e.g., ['shell_command', 'apply_patch']) */
|
|
2674
|
+
nativeTools: string[];
|
|
2675
|
+
/** Available models for this adapter (used for context window lookup) */
|
|
2676
|
+
availableModels?: AIModel[];
|
|
2677
|
+
/** Resolved provider definitions, including adapter-provider auth metadata. */
|
|
2678
|
+
definitionProviders?: readonly AdapterProviderDefinition[];
|
|
2679
|
+
/** Allowed tool names (adapter-specific). Empty array = disable all tools. */
|
|
2680
|
+
allowedTools?: string[];
|
|
2681
|
+
/** Disallowed tool names (adapter-specific). Takes precedence over allowedTools. */
|
|
2682
|
+
disallowedTools?: string[];
|
|
2683
|
+
/** Directory restrictions for file-system tool execution. */
|
|
2684
|
+
allowedDirectories?: string[];
|
|
2685
|
+
/** Per-call adapter-specific JSON config forwarded to the adapter config factory. */
|
|
2686
|
+
adapterConfig?: Record<string, unknown>;
|
|
2687
|
+
/**
|
|
2688
|
+
* MCP session context resolved by the orchestrator.
|
|
2689
|
+
* Passed through to the connector config so adapters can inject direct tools.
|
|
2690
|
+
*/
|
|
2691
|
+
mcpSessionContext?: LedgerSessionContext | McpRuntimeSessionContext;
|
|
2692
|
+
/**
|
|
2693
|
+
* Session-scoped ledger tracking MCP injection/discovery/call history.
|
|
2694
|
+
* Created once per agent session and passed through unchanged on connector swaps.
|
|
2695
|
+
*/
|
|
2696
|
+
toolLedger?: ISessionToolLedger;
|
|
2697
|
+
/**
|
|
2698
|
+
* When true, PreUserMessage hooks are skipped for this agent.
|
|
2699
|
+
* Use for ephemeral ping agents where session enrichment and context injection
|
|
2700
|
+
* are not needed and would be actively harmful.
|
|
2701
|
+
*/
|
|
2702
|
+
ephemeral?: boolean;
|
|
2703
|
+
/**
|
|
2704
|
+
* Native fork directive from the orchestrator.
|
|
2705
|
+
*
|
|
2706
|
+
* When present, the adapter should use the provider's branching API
|
|
2707
|
+
* rather than replaying history into a fresh session.
|
|
2708
|
+
* Populated by AIAdapter.createAgent when the startAgent mode is 'fork'.
|
|
2709
|
+
*
|
|
2710
|
+
* AIAgent forwards this through config-factory input so standardized adapter
|
|
2711
|
+
* config factories can carry it into connector config. Adapter code must not
|
|
2712
|
+
* derive this from raw fork-mode request fields.
|
|
2713
|
+
*/
|
|
2714
|
+
nativeFork?: NativeForkDirective;
|
|
2715
|
+
/**
|
|
2716
|
+
* Config factory - transforms partial input into full adapter-specific config.
|
|
2717
|
+
* This is the seam where adapters inject their defaults (especially model).
|
|
2718
|
+
*/
|
|
2719
|
+
configFactory: (input: ConfigFactoryInput<TBus>) => Promise<BaseAgentConnectorConfig<TBus> & {
|
|
2720
|
+
adapterId: string;
|
|
2721
|
+
}>;
|
|
2722
|
+
/**
|
|
2723
|
+
* Connector factory - creates connector from full config.
|
|
2724
|
+
* Called AFTER configFactory returns the complete configuration.
|
|
2725
|
+
* Config includes adapterId (passed through from input by config factory).
|
|
2726
|
+
*/
|
|
2727
|
+
connectorFactory: (config: BaseAgentConnectorConfig<TBus> & {
|
|
2728
|
+
adapterId: string;
|
|
2729
|
+
}) => TConnector | Promise<TConnector>;
|
|
2730
|
+
}
|
|
2731
|
+
/**
|
|
2732
|
+
* Result returned from agent.start()
|
|
2733
|
+
*/
|
|
2734
|
+
interface AgentStartResult {
|
|
2735
|
+
adapterSessionId: string;
|
|
2736
|
+
agentId: string;
|
|
2737
|
+
messageHandle: MessageHandle;
|
|
2738
|
+
}
|
|
2739
|
+
/**
|
|
2740
|
+
* Options for sending a message to an agent.
|
|
2741
|
+
* Extends SendMessageOptions with curated message history and system prompt configuration.
|
|
2742
|
+
*/
|
|
2743
|
+
interface AgentSendMessageOptions extends SendMessageOptions {
|
|
2744
|
+
/** Curated message history from orchestration layer */
|
|
2745
|
+
messageHistory?: Message[];
|
|
2746
|
+
/**
|
|
2747
|
+
* System prompt configuration.
|
|
2748
|
+
* - `string`: Replace/set the entire system prompt
|
|
2749
|
+
* - `{ mode: 'append', content: string }`: Append to adapter's default system prompt
|
|
2750
|
+
*/
|
|
2751
|
+
systemPrompt?: SystemPrompt;
|
|
2752
|
+
/**
|
|
2753
|
+
* Context signals assembled by SessionOrchestrator.
|
|
2754
|
+
* Used by AIAgent to decide: native resume vs fresh with history.
|
|
2755
|
+
* Hooks inject context via sessionContext.turnContext (set by replacePayload).
|
|
2756
|
+
*/
|
|
2757
|
+
sessionContext?: SessionContext;
|
|
2758
|
+
/**
|
|
2759
|
+
* Structured output descriptor for the turn.
|
|
2760
|
+
*
|
|
2761
|
+
* Adapters that declare `structuredOutput` pass this schema to their native
|
|
2762
|
+
* model-level output controls. Other adapters receive an instruction block
|
|
2763
|
+
* and the agent validates the terminal output after completion.
|
|
2764
|
+
*
|
|
2765
|
+
* Validation retries are default-off (`maxRetries: 0`) and fallback
|
|
2766
|
+
* enforcement is a no-op unless the host registers structured-output override
|
|
2767
|
+
* handlers.
|
|
2768
|
+
*/
|
|
2769
|
+
responseSchema?: ResponseSchemaDescriptor;
|
|
2770
|
+
}
|
|
2771
|
+
/**
|
|
2772
|
+
* Options for starting an agent session.
|
|
2773
|
+
* Same as AgentSendMessageOptions - both start() and sendMessage() accept the same options.
|
|
2774
|
+
*/
|
|
2775
|
+
type StartAgentOptions = AgentSendMessageOptions;
|
|
2776
|
+
/**
|
|
2777
|
+
* Options for connector-level message operations.
|
|
2778
|
+
* Extends AgentSendMessageOptions with turnContext for internal AIAgent to Connector communication.
|
|
2779
|
+
* AIAgent extracts sessionContext.turnContext and passes it here.
|
|
2780
|
+
* Inherits responseSchema from AgentSendMessageOptions.
|
|
2781
|
+
*/
|
|
2782
|
+
interface ConnectorSendMessageOptions extends AgentSendMessageOptions {
|
|
2783
|
+
/**
|
|
2784
|
+
* Content-free provider transport correlation. This is carried on the
|
|
2785
|
+
* message handle and never materialized into the LLM-facing message.
|
|
2786
|
+
*/
|
|
2787
|
+
requestCorrelation?: RequestCorrelationContext;
|
|
2788
|
+
/**
|
|
2789
|
+
* Lifecycle turnId from the session orchestrator (`agent.sendMessage.turnId`).
|
|
2790
|
+
* Carried on the message handle so user_message lifecycle events pair by it.
|
|
2791
|
+
* Distinct from `requestCorrelation.turnId`, which is transport correlation
|
|
2792
|
+
* and may be present when no lifecycle turn exists.
|
|
2793
|
+
*/
|
|
2794
|
+
turnId?: string;
|
|
2795
|
+
/**
|
|
2796
|
+
* Turn-scoped context assembled by PreUserMessage hooks and the orchestrator.
|
|
2797
|
+
* Extracted from sessionContext.turnContext by AIAgent.
|
|
2798
|
+
* Adapters use this to prepend context blocks to the SDK message.
|
|
2799
|
+
*
|
|
2800
|
+
* ADAPTER CONTRACT: Every adapter MUST materialize turnContext into the
|
|
2801
|
+
* LLM-facing message using serializeTurnContext().
|
|
2802
|
+
*/
|
|
2803
|
+
turnContext?: Record<string, JsonValue>;
|
|
2804
|
+
/**
|
|
2805
|
+
* Caller-expressed caching intent for the injected message history.
|
|
2806
|
+
* Adapters map this to provider-specific cache mechanisms.
|
|
2807
|
+
*/
|
|
2808
|
+
cacheStrategy?: CacheStrategy;
|
|
2809
|
+
/**
|
|
2810
|
+
* Whether this message is an internal retry turn synthesized by the structured-output
|
|
2811
|
+
* manager. When `true`, the connector suppresses `user_message.sent` so the retry
|
|
2812
|
+
* is not surfaced as a new user message.
|
|
2813
|
+
*/
|
|
2814
|
+
internalRetry?: boolean;
|
|
2815
|
+
/**
|
|
2816
|
+
* Caller decision on provider-native session resume for this dispatch.
|
|
2817
|
+
*
|
|
2818
|
+
* The turn pipeline sets this from the agent's native-resume decision. When
|
|
2819
|
+
* `false`, the connector MUST NOT arm its pending start-time resume target
|
|
2820
|
+
* (`resumeAdapterSessionId`) for this dispatch: the caller has replaced the
|
|
2821
|
+
* provider thread with injected `messageHistory`, so natively resuming would
|
|
2822
|
+
* double the conversation context. Honoring connectors discard the
|
|
2823
|
+
* unconsumed resume target and mint a fresh provider session instead.
|
|
2824
|
+
*
|
|
2825
|
+
* When `true` or absent, the connector applies its default resume behavior.
|
|
2826
|
+
* The flag never affects a connector's continuity of its own
|
|
2827
|
+
* provider-confirmed session (intra-generation multi-turn), and it does not
|
|
2828
|
+
* cancel an approved `nativeFork` directive — fork is a separate contract.
|
|
2829
|
+
*/
|
|
2830
|
+
useNativeResume?: boolean;
|
|
2831
|
+
}
|
|
2832
|
+
/**
|
|
2833
|
+
* Options for connector-level start operations.
|
|
2834
|
+
* Same as ConnectorSendMessageOptions.
|
|
2835
|
+
*/
|
|
2836
|
+
type ConnectorStartOptions = ConnectorSendMessageOptions;
|
|
2837
|
+
/** Payload type for `agent.sendMessage` requests. */
|
|
2838
|
+
type SendMessageRequestPayload = ExtractSubjectPayload<typeof AgentSubjects.sendMessage>;
|
|
2839
|
+
/** Response type for `agent.sendMessage` requests. */
|
|
2840
|
+
type SendMessageResponsePayload = ExtractSubjectResponse<typeof AgentSubjects.sendMessage>;
|
|
2841
|
+
/** Payload type for `agent.interrupt` requests. */
|
|
2842
|
+
type AgentInterruptRequestPayload = ExtractSubjectPayload<typeof AgentSubjects.interrupt>;
|
|
2843
|
+
/** Response type for `agent.interrupt` requests. */
|
|
2844
|
+
type AgentInterruptResponsePayload = ExtractSubjectResponse<typeof AgentSubjects.interrupt>;
|
|
2845
|
+
/** Response type for `agent.getCapabilities` requests. */
|
|
2846
|
+
type GetCapabilitiesResponsePayload = ExtractSubjectResponse<typeof AgentSubjects.getCapabilities>;
|
|
2847
|
+
/** Payload type for `agent.cwd.change` requests. */
|
|
2848
|
+
type AgentCwdChangeRequestPayload = ExtractSubjectPayload<typeof AgentSubjects.cwd.change>;
|
|
2849
|
+
/** Response type for `agent.cwd.change` requests. */
|
|
2850
|
+
type AgentCwdChangeResponsePayload = ExtractSubjectResponse<typeof AgentSubjects.cwd.change>;
|
|
2851
|
+
/** Payload type for `agent.model.change` requests. */
|
|
2852
|
+
type AgentModelChangeRequestPayload = ExtractSubjectPayload<typeof AgentSubjects.model.change>;
|
|
2853
|
+
/** Response type for `agent.model.change` requests. */
|
|
2854
|
+
type AgentModelChangeResponsePayload = ExtractSubjectResponse<typeof AgentSubjects.model.change>;
|
|
2855
|
+
/** Payload type for `agent.mcp.servers.set` requests. */
|
|
2856
|
+
type AgentMcpServersSetRequestPayload = ExtractSubjectPayload<typeof AgentSubjects.mcp.servers.set>;
|
|
2857
|
+
/** Response type for `agent.mcp.servers.set` requests. */
|
|
2858
|
+
type AgentMcpServersSetResponsePayload = ExtractSubjectResponse<typeof AgentSubjects.mcp.servers.set>;
|
|
2859
|
+
/** Payload type for `agent.credential.change` requests. */
|
|
2860
|
+
type AgentCredentialChangeRequestPayload = ExtractSubjectPayload<typeof AgentSubjects.credential.change>;
|
|
2861
|
+
/** Response type for `agent.credential.change` requests. */
|
|
2862
|
+
type AgentCredentialChangeResponsePayload = ExtractSubjectResponse<typeof AgentSubjects.credential.change>;
|
|
2863
|
+
type EmitteryEvents = {
|
|
2864
|
+
processingStateChanged: ProcessingState;
|
|
2865
|
+
};
|
|
2866
|
+
/**
|
|
2867
|
+
* Normalized usage metrics for a single agent call.
|
|
2868
|
+
* Adapter implementations normalize provider-specific usage data to this format.
|
|
2869
|
+
*
|
|
2870
|
+
* Derived from the `agent.usage` schema, so the mandatory `granularity` field
|
|
2871
|
+
* is part of this type: adapters MUST declare the truthful measurement
|
|
2872
|
+
* granularity of every usage signal they normalize (see
|
|
2873
|
+
* `docs/architecture/adapters/usage-and-provenance.md`).
|
|
2874
|
+
*/
|
|
2875
|
+
type NormalizedCallUsage = Omit<z.infer<typeof AgentSchemas.usage>, keyof AgentContext | 'model'>;
|
|
2876
|
+
/**
|
|
2877
|
+
* Input for context window update emission.
|
|
2878
|
+
* Adapters provide raw metrics, helper calculates percentage and level.
|
|
2879
|
+
*/
|
|
2880
|
+
interface ContextWindowInput {
|
|
2881
|
+
/** Total tokens in context (input + output for next turn prediction) */
|
|
2882
|
+
currentTokens: number;
|
|
2883
|
+
/** Model's context window limit */
|
|
2884
|
+
maxTokens: number;
|
|
2885
|
+
/** Cached tokens (optional, reduces cost but still in context) */
|
|
2886
|
+
cachedTokens?: number;
|
|
2887
|
+
}
|
|
2888
|
+
/**
|
|
2889
|
+
* Per-call overrides for connector (re)creation paths.
|
|
2890
|
+
*
|
|
2891
|
+
* Shared by `AIAgent.swapConnector`, config-input assembly, and the connector
|
|
2892
|
+
* lifecycle factory so the override surface cannot drift between them.
|
|
2893
|
+
*/
|
|
2894
|
+
type AgentConnectorConfigOverrides = Partial<{
|
|
2895
|
+
cwd: string;
|
|
2896
|
+
model: string;
|
|
2897
|
+
providerContext: ProviderContext;
|
|
2898
|
+
adapterSessionId: string;
|
|
2899
|
+
/**
|
|
2900
|
+
* Provider session the replacement generation should native-resume. Key
|
|
2901
|
+
* presence (not value) selects this over the agent config's start-time
|
|
2902
|
+
* resume target, so an explicit `undefined` builds a fresh connector
|
|
2903
|
+
* instead of silently re-resuming a stale start directive.
|
|
2904
|
+
*/
|
|
2905
|
+
resumeAdapterSessionId: string | undefined;
|
|
2906
|
+
mcpSessionContext: McpRuntimeSessionContext | McpSessionContext | LedgerSessionContext;
|
|
2907
|
+
/**
|
|
2908
|
+
* Target reasoning effort for the replacement generation. Key presence (not
|
|
2909
|
+
* value) selects this over the live connector's current effort, so an
|
|
2910
|
+
* explicit `undefined` builds a reasoning-less connector. Adapters may
|
|
2911
|
+
* consume reasoning only at construction/start, so the replacement must be
|
|
2912
|
+
* built with its target effort rather than mutated afterwards.
|
|
2913
|
+
*/
|
|
2914
|
+
reasoningEffort: AIReasoningLevel$1 | undefined;
|
|
2915
|
+
}>;
|
|
2916
|
+
//#endregion
|
|
2917
|
+
export { bindProviderAuth as $, SessionToolLedger as $t, AgentTeardownArbiter as A, runBestEffortStage as At, PreparedAdapterAuthRuntime as B, MessageHandle as Bt, NormalizedCallUsage as C, ObservedExitOptions as Ct, AdapterProviderDefinition as D, reportBestEffortStages as Dt, StartAgentOptions as E, exitWasObserved as Et, TeardownSubject as F, unknownTeardown as Ft, AdapterAuthError as G, MessageState as Gt, SuppliedAdapterAuthRuntime as H, NormalizedMessageInput as Ht, CreateConnectorRuntimeOptions as I, CONNECTOR_EXIT_OBSERVATION_MS as It, BoundProviderAuthContext as J, AIModel as Jt, AdapterAuthErrorReason as K, ProcessingState as Kt, AdapterAuthLeaseHandle as L, SWAP_SETTLEMENT_WAIT_MS as Lt, ConnectorReplacementSettlement as M, TeardownReport as Mt, ConnectorSwapAdmission as N, aggregateTeardownReports as Nt, ConfigFactoryInput as O, reportObservedExit as Ot, ConnectorSwapHandover as P, rethrowTeardownFailure as Pt, ResolvedConnectorAuthDelivery as Q, LedgerSessionContext as Qt, AdapterAuthRuntimePreparer as R, AIAgentConnector as Rt, GetCapabilitiesResponsePayload as S, SupersededGeneration as St, SendMessageResponsePayload as T, describeTeardownFailure as Tt, applySuppliedAdapterAuthRuntime as U, normalizeMessageInput as Ut, ResolvedAdapterRuntimeConfig as V, markCompletedWithFinalResult as Vt, prepareAdapterAuthRuntime as W, MessageResult as Wt, ResolvedAdapterAuth as X, ReasoningLevelMap$1 as Xt, ResolveAuthCredentialRefs as Y, AIReasoningLevel$1 as Yt, ResolvedAuthCredentialValues as Z, ISessionToolLedger as Zt, BaseAgentConnectorConfig as _, BaseConnectorTurn as _t, AgentCredentialChangeResponsePayload as a, WireSessionSubjects as at, ContextWindowInput as b, ConnectorSessionConfig as bt, AgentIdentity as c, QueueableTurn as ct, AgentMcpServersSetRequestPayload as d, rejectQueuedHandles as dt, ToolLedgerEntry as en, getOptionalAuthCredentialFields as et, AgentMcpServersSetResponsePayload as f, UserMessageQueue as ft, AgentStartResult as g, TurnSubjects as gt, AgentSendMessageOptions as h, ProceduralTurnState as ht, AgentCredentialChangeRequestPayload as i, WireSessionConfig as it, ClosableConnectorRuntime as j, stageFailure as jt, IAdapterConfigFactory as k, reportRepeatTeardown as kt, AgentInterruptRequestPayload as l, SESSION_CLOSED_QUEUE_ERROR as lt, AgentModelChangeResponsePayload as m, ProceduralTurnConfig as mt, AgentConnectorConfigOverrides as n, ProceduralAgentConnector as nt, AgentCwdChangeRequestPayload as o, MergeResult as ot, AgentModelChangeRequestPayload as p, ProceduralConnectorTurn as pt, BindProviderAuthOptions as q, SendMessageOptions as qt, AgentContext as r, ProceduralConnectorSession as rt, AgentCwdChangeResponsePayload as s, ProcessQueueCallbacks as st, AIAgentConfig as t, resolveBoundProviderAuth as tt, AgentInterruptResponsePayload as u, processQueueMessages as ut, ConnectorSendMessageOptions as v, PauseResult as vt, SendMessageRequestPayload as w, capTeardownEvidence as wt, ExecutionContext as x, GenerationRetirementLedger as xt, ConnectorStartOptions as y, BaseConnectorSession as yt, BoundAdapterRuntimeConfig as z, MessageDeliveryMode$1 as zt };
|