@makaio/framework 1.0.0-dev-1781022866275 → 1.0.0-dev-1781023871421
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 +5 -0
- package/dist/account-identity-DT5NOtFi.mjs +1 -0
- package/dist/adapter-C1eI-fGV.mjs +1 -0
- package/dist/adapters/acp-client/index.d.mts +6208 -0
- package/dist/adapters/acp-client/index.mjs +3 -0
- package/dist/adapters/config/index.d.mts +429 -0
- package/dist/adapters/config/index.mjs +1 -0
- package/dist/adapters/index.d.mts +4202 -0
- package/dist/adapters/index.mjs +18 -0
- package/dist/adapters/node.d.mts +263 -0
- package/dist/adapters/node.mjs +4 -0
- package/dist/adapters/stream-session/index.d.mts +1414 -0
- package/dist/adapters/stream-session/index.mjs +1 -0
- package/dist/adapters/stream-session/testing/index.d.mts +29 -0
- package/dist/adapters/stream-session/testing/index.mjs +1 -0
- package/dist/artifact-B3npq1cy.mjs +1 -0
- package/dist/base-orchestrator-wyumsn3b.d.mts +772 -0
- package/dist/bus/index.d.mts +3994 -0
- package/dist/bus/index.mjs +1 -0
- package/dist/bus-Caz3Jpbc.mjs +1 -0
- package/dist/bus-Hb-LGzgb.mjs +2 -0
- package/dist/capability-service-CJbmhfv9.mjs +1 -0
- package/dist/chunk-DTipWd-i.mjs +1 -0
- package/dist/chunk-cpUYaJdV.mjs +1 -0
- package/dist/cleanEnvForAdapter-KkYzQa1f.mjs +1 -0
- package/dist/client-bx74gm4R.mjs +1 -0
- package/dist/clients/index.d.mts +2639 -0
- package/dist/clients/index.mjs +2 -0
- package/dist/clients-namespace-GmSJpBUV.d.mts +332 -0
- package/dist/config-namespace-CPY9YsR8.d.mts +638 -0
- package/dist/config-namespace-ncYg2ct_.mjs +1 -0
- package/dist/contracts/adapter/index.d.mts +3 -0
- package/dist/contracts/adapter/index.mjs +1 -0
- package/dist/contracts/adapter/schemas/session-lineage.d.mts +2 -0
- package/dist/contracts/adapter/schemas/session-lineage.mjs +1 -0
- package/dist/contracts/artifact/index.d.mts +2 -0
- package/dist/contracts/artifact/index.mjs +1 -0
- package/dist/contracts/client/index.d.mts +3 -0
- package/dist/contracts/client/index.mjs +1 -0
- package/dist/contracts/common/index.d.mts +2 -0
- package/dist/contracts/common/index.mjs +1 -0
- package/dist/contracts/config/index.d.mts +455 -0
- package/dist/contracts/config/index.mjs +1 -0
- package/dist/contracts/extension/index.d.mts +4 -0
- package/dist/contracts/extension/index.mjs +1 -0
- package/dist/contracts/facet/index.d.mts +2 -0
- package/dist/contracts/facet/index.mjs +1 -0
- package/dist/contracts/harness/index.d.mts +2 -0
- package/dist/contracts/harness/index.mjs +1 -0
- package/dist/contracts/host/index.d.mts +2 -0
- package/dist/contracts/host/index.mjs +1 -0
- package/dist/contracts/index.d.mts +23046 -0
- package/dist/contracts/index.mjs +1 -0
- package/dist/contracts/materialization/index.d.mts +4 -0
- package/dist/contracts/materialization/index.mjs +1 -0
- package/dist/contracts/model-registry/index.d.mts +2 -0
- package/dist/contracts/model-registry/index.mjs +1 -0
- package/dist/contracts/native-session-supervisor/index.d.mts +2 -0
- package/dist/contracts/native-session-supervisor/index.mjs +1 -0
- package/dist/contracts/platform/index.d.mts +2 -0
- package/dist/contracts/platform/index.mjs +1 -0
- package/dist/contracts/provider/index.d.mts +3 -0
- package/dist/contracts/provider/index.mjs +1 -0
- package/dist/contracts/session/index.d.mts +3 -0
- package/dist/contracts/session/index.mjs +1 -0
- package/dist/contracts/shared/index.d.mts +2 -0
- package/dist/contracts/shared/index.mjs +1 -0
- package/dist/contracts/skill/index.d.mts +2 -0
- package/dist/contracts/skill/index.mjs +1 -0
- package/dist/contracts/telemetry/index.d.mts +2 -0
- package/dist/contracts/telemetry/index.mjs +1 -0
- package/dist/contracts/timeout/index.d.mts +2 -0
- package/dist/contracts/timeout/index.mjs +1 -0
- package/dist/contracts/toast/index.d.mts +198 -0
- package/dist/contracts/toast/index.mjs +1 -0
- package/dist/contracts/variant/index.d.mts +2 -0
- package/dist/contracts/variant/index.mjs +1 -0
- package/dist/core/index.d.mts +1263 -0
- package/dist/core/index.mjs +1 -0
- package/dist/credential-ref-YWQQENEo.mjs +1 -0
- package/dist/cursor-storage-CtVJ3JzB.mjs +1 -0
- package/dist/definition-BLCdXGzh.d.mts +383 -0
- package/dist/definition-CrgHIpTK.d.mts +60 -0
- package/dist/definition-DZMXOnjX.mjs +1 -0
- package/dist/definition-pkJ6szUl.d.mts +158 -0
- package/dist/drizzle-Eq8W1EbD.mjs +1 -0
- package/dist/event-Ca2yUf5i.mjs +1 -0
- package/dist/execution-target-CRPTfZlc.mjs +1 -0
- package/dist/extension-C-4BHMRI.mjs +1 -0
- package/dist/extension-CpIUgBKI.mjs +1 -0
- package/dist/extension-namespace-cMh_mMiL.mjs +1 -0
- package/dist/facet-BuwhrThl.mjs +1 -0
- package/dist/filesystem-service-B8rhBRgB.mjs +1 -0
- package/dist/filesystem-service-p_iJVHd4.d.mts +66 -0
- package/dist/git/index.d.mts +210 -0
- package/dist/git/index.mjs +18 -0
- package/dist/globby-rtWVaFHv.mjs +41 -0
- package/dist/handlers-CkTsQLra.mjs +41 -0
- package/dist/harness-BRCMcvQN.mjs +1 -0
- package/dist/hooks/index.d.mts +423 -0
- package/dist/hooks/index.mjs +1 -0
- package/dist/host-Br9VuOyr.mjs +1 -0
- package/dist/identity-Cz2IeEtm.mjs +1 -0
- package/dist/index-472sOmsW.d.mts +218 -0
- package/dist/index-8SZkg7s6.d.mts +353 -0
- package/dist/index-B3PK4FIn.d.mts +5116 -0
- package/dist/index-B80L4YqA.d.mts +180 -0
- package/dist/index-BFg9BUpx.d.mts +355 -0
- package/dist/index-BGfWS6GE.d.mts +483 -0
- package/dist/index-BVgfS-AJ.d.mts +109 -0
- package/dist/index-B_zQC98V.d.mts +995 -0
- package/dist/index-Bh_Ne7LF.d.mts +1008 -0
- package/dist/index-Bvb2mMH6.d.mts +1730 -0
- package/dist/index-CCGVh9BF2.d.mts +749 -0
- package/dist/index-CGmcS0Ma.d.mts +412 -0
- package/dist/index-CHQ1SqT0.d.mts +117 -0
- package/dist/index-CLpjm52M.d.mts +183 -0
- package/dist/index-Caig6TeF.d.mts +6746 -0
- package/dist/index-CelJCBjk.d.mts +2992 -0
- package/dist/index-ChunCFu4.d.mts +11 -0
- package/dist/index-Cm0dUkWL.d.mts +4651 -0
- package/dist/index-CokQYGVP.d.mts +184 -0
- package/dist/index-Cs0kZXIz2.d.mts +37 -0
- package/dist/index-D5d5HeWI2.d.mts +259 -0
- package/dist/index-D90OmGmV.d.mts +389 -0
- package/dist/index-D9MwJ2Q8.d.mts +67 -0
- package/dist/index-DANINzMu.d.mts +40 -0
- package/dist/index-DBw-89vC2.d.mts +3640 -0
- package/dist/index-DGBu6bHi2.d.mts +438 -0
- package/dist/index-DKC62dY5.d.mts +146 -0
- package/dist/index-DKia0MX1.d.mts +43 -0
- package/dist/index-DMKnON5s.d.mts +28 -0
- package/dist/index-DUaw0Dw8.d.mts +14747 -0
- package/dist/index-De3kPhlN.d.mts +72 -0
- package/dist/index-L4GjJDKb.d.mts +822 -0
- package/dist/index-U-A8eyGT.d.mts +1490 -0
- package/dist/index-eemAKwsB.d.mts +362 -0
- package/dist/index-mNec7V-9.d.mts +1075 -0
- package/dist/index-soFznFCy2.d.mts +89 -0
- package/dist/index-vtXJuwrz.d.mts +40 -0
- package/dist/index-x_lVDp_J.d.mts +134 -0
- package/dist/json-value-CmhSGMLv.mjs +1 -0
- package/dist/kernel/cli/index.d.mts +143 -0
- package/dist/kernel/cli/index.mjs +1 -0
- package/dist/kernel/cli/schemas.d.mts +64 -0
- package/dist/kernel/cli/schemas.mjs +1 -0
- package/dist/kernel/extension/index.d.mts +2 -0
- package/dist/kernel/extension/index.mjs +1 -0
- package/dist/kernel/index.d.mts +296 -0
- package/dist/kernel/index.mjs +1 -0
- package/dist/kernel/namespace/index.d.mts +2 -0
- package/dist/kernel/namespace/index.mjs +1 -0
- package/dist/kernel/observability/index.d.mts +2 -0
- package/dist/kernel/observability/index.mjs +1 -0
- package/dist/kernel/providers/index.d.mts +2 -0
- package/dist/kernel/providers/index.mjs +1 -0
- package/dist/kernel/window/index.d.mts +2 -0
- package/dist/kernel/window/index.mjs +1 -0
- package/dist/materialization-CuUBu4XI.mjs +1 -0
- package/dist/model-registry-CfXytvzx.mjs +1 -0
- package/dist/model-registry-Scn_MC2d.mjs +1 -0
- package/dist/namespace-5QQqbF-B.d.mts +3133 -0
- package/dist/namespace-BM7Djng9.d.mts +189 -0
- package/dist/namespace-BoD94mrN.mjs +1 -0
- package/dist/namespace-BwzZJqTV.mjs +1 -0
- package/dist/namespace-CFLAmQfh.mjs +1 -0
- package/dist/namespace-CTm3nEvh.d.mts +51 -0
- package/dist/namespace-CaaNnKcR.d.mts +921 -0
- package/dist/namespace-CaoZ3S78.d.mts +43 -0
- package/dist/namespace-CxhsoFUP.d.mts +607 -0
- package/dist/namespace-DD8Oiqo7.d.mts +580 -0
- package/dist/namespace-DLovh2Ws.d.mts +1313 -0
- package/dist/namespace-DgqkaOVu.d.mts +768 -0
- package/dist/namespace-DkRgbZYn.mjs +1 -0
- package/dist/namespace-Dr8K0MCp.d.mts +2047 -0
- package/dist/namespace-DuXK5AYN.mjs +1 -0
- package/dist/namespace-EQniz-Aw.d.mts +142 -0
- package/dist/namespace-IV1QK__V.d.mts +159 -0
- package/dist/namespace-LViZ-EQk.mjs +1 -0
- package/dist/namespace-TyiTsLFv.d.mts +3020 -0
- package/dist/namespace-Yna5-Pws.mjs +1 -0
- package/dist/namespace-xcmbQlxh.mjs +1 -0
- package/dist/native-session-supervisor-B1TnaPUF.mjs +1 -0
- package/dist/node/bus-server/index.d.mts +178 -0
- package/dist/node/bus-server/index.mjs +1 -0
- package/dist/node/bus-server/server-lifecycle.d.mts +2 -0
- package/dist/node/bus-server/server-lifecycle.mjs +1 -0
- package/dist/node/machine-identity/index.d.mts +85 -0
- package/dist/node/machine-identity/index.mjs +3 -0
- package/dist/node/transports/index.d.mts +1945 -0
- package/dist/node/transports/index.mjs +2 -0
- package/dist/orchestrator-shared-CIDiFJMD.mjs +1 -0
- package/dist/orchestrator-shared-Dfa7FMyw.d.mts +249 -0
- package/dist/package-DKVlsMP3.mjs +1 -0
- package/dist/platform-DZ7z-wXD.mjs +1 -0
- package/dist/profile-6ynCD5k3.mjs +1 -0
- package/dist/provider-context-CK6B4X_8.mjs +1 -0
- package/dist/providers/index.d.mts +135 -0
- package/dist/providers/index.mjs +1 -0
- package/dist/providers-namespace-DSEpli4A.d.mts +583 -0
- package/dist/providers-u8i15co9.mjs +1 -0
- package/dist/schema-CoyE6mPt.mjs +1 -0
- package/dist/schema-M5YTvSAG.d.mts +949 -0
- package/dist/schema-e0wU_lcV.mjs +1 -0
- package/dist/schema-introspection-Dn1jWQs1.mjs +1 -0
- package/dist/schemas-Bd0OjRQf.d.mts +46 -0
- package/dist/schemas-C46QfKzv.d.mts +459 -0
- package/dist/schemas-CDBSjg7o.d.mts +237 -0
- package/dist/schemas-CR1Rripy.mjs +1 -0
- package/dist/schemas-CVvwIfG4.mjs +1 -0
- package/dist/schemas-CaLhkkLn.mjs +1 -0
- package/dist/schemas-ClOOT1W6.d.mts +174 -0
- package/dist/schemas-DATniTHb.d.mts +182 -0
- package/dist/schemas-DE-GNmSD.mjs +1 -0
- package/dist/schemas-DVF1A4DF.d.mts +160 -0
- package/dist/schemas-DaRSfYLf.d.mts +73 -0
- package/dist/schemas-DiYVzG6e.d.mts +315 -0
- package/dist/schemas-hSrzflwZ.mjs +1 -0
- package/dist/schemas-j7ivZ2HI.d.mts +944 -0
- package/dist/schemas-jFe1AuI-.mjs +1 -0
- package/dist/schemas-wg_6PAdV.d.mts +153 -0
- package/dist/scoped-bus-04pwo1uM.mjs +1 -0
- package/dist/server-lifecycle-FXTPW39-.mjs +1 -0
- package/dist/server-lifecycle-YoSGFGnU.d.mts +160 -0
- package/dist/service-base/index.d.mts +98 -0
- package/dist/service-base/index.mjs +1 -0
- package/dist/services/adapter-runtime/index.d.mts +4 -0
- package/dist/services/adapter-runtime/index.mjs +1 -0
- package/dist/services/adapter-runtime/namespace.d.mts +2 -0
- package/dist/services/adapter-runtime/namespace.mjs +1 -0
- package/dist/services/adapter-runtime/schemas.d.mts +2 -0
- package/dist/services/adapter-runtime/schemas.mjs +1 -0
- package/dist/services/adapter-subsystem/index.d.mts +3 -0
- package/dist/services/adapter-subsystem/index.mjs +1 -0
- package/dist/services/adapter-subsystem/namespace.d.mts +2 -0
- package/dist/services/adapter-subsystem/namespace.mjs +1 -0
- package/dist/services/agent-runtime/index.d.mts +3 -0
- package/dist/services/agent-runtime/index.mjs +1 -0
- package/dist/services/agent-runtime/namespace.d.mts +2 -0
- package/dist/services/agent-runtime/namespace.mjs +1 -0
- package/dist/services/agent-runtime/schemas.d.mts +2 -0
- package/dist/services/agent-runtime/schemas.mjs +1 -0
- package/dist/services/capability/index.d.mts +2 -0
- package/dist/services/capability/index.mjs +1 -0
- package/dist/services/cli-detection/namespace.d.mts +56 -0
- package/dist/services/cli-detection/namespace.mjs +1 -0
- package/dist/services/codebase/index.d.mts +3 -0
- package/dist/services/codebase/index.mjs +1 -0
- package/dist/services/codebase/namespace.d.mts +2 -0
- package/dist/services/codebase/namespace.mjs +1 -0
- package/dist/services/codebase/schemas.d.mts +2 -0
- package/dist/services/codebase/schemas.mjs +1 -0
- package/dist/services/compression/index.d.mts +3 -0
- package/dist/services/compression/index.mjs +1 -0
- package/dist/services/compression/namespace.d.mts +2 -0
- package/dist/services/compression/namespace.mjs +1 -0
- package/dist/services/compression/schemas.d.mts +2 -0
- package/dist/services/compression/schemas.mjs +1 -0
- package/dist/services/context-rules/index.d.mts +412 -0
- package/dist/services/context-rules/index.mjs +1 -0
- package/dist/services/credential-change/index.d.mts +17 -0
- package/dist/services/credential-change/index.mjs +1 -0
- package/dist/services/definition/index.d.mts +2 -0
- package/dist/services/definition/index.mjs +1 -0
- package/dist/services/definition/namespace.d.mts +71 -0
- package/dist/services/definition/namespace.mjs +1 -0
- package/dist/services/definition/schemas.d.mts +38 -0
- package/dist/services/definition/schemas.mjs +1 -0
- package/dist/services/dialog/namespace.d.mts +105 -0
- package/dist/services/dialog/namespace.mjs +1 -0
- package/dist/services/dialog/schemas.d.mts +109 -0
- package/dist/services/dialog/schemas.mjs +1 -0
- package/dist/services/execution-target/index.d.mts +4 -0
- package/dist/services/execution-target/index.mjs +1 -0
- package/dist/services/execution-target/namespace.d.mts +2 -0
- package/dist/services/execution-target/namespace.mjs +1 -0
- package/dist/services/execution-target/schemas.d.mts +2 -0
- package/dist/services/execution-target/schemas.mjs +1 -0
- package/dist/services/filesystem/index.d.mts +3 -0
- package/dist/services/filesystem/index.mjs +1 -0
- package/dist/services/filesystem/namespace.d.mts +432 -0
- package/dist/services/filesystem/namespace.mjs +1 -0
- package/dist/services/filesystem/schemas.d.mts +240 -0
- package/dist/services/filesystem/schemas.mjs +1 -0
- package/dist/services/git/namespace.d.mts +1163 -0
- package/dist/services/git/namespace.mjs +1 -0
- package/dist/services/git/schemas.d.mts +932 -0
- package/dist/services/git/schemas.mjs +1 -0
- package/dist/services/harness/index.d.mts +861 -0
- package/dist/services/harness/index.mjs +1 -0
- package/dist/services/harness/storage/schema.d.mts +424 -0
- package/dist/services/harness/storage/schema.mjs +1 -0
- package/dist/services/index.d.mts +6185 -0
- package/dist/services/index.mjs +1 -0
- package/dist/services/local-notification/index.d.mts +25 -0
- package/dist/services/local-notification/index.mjs +1 -0
- package/dist/services/local-notification/namespace.d.mts +73 -0
- package/dist/services/local-notification/namespace.mjs +1 -0
- package/dist/services/local-notification/schemas.d.mts +88 -0
- package/dist/services/local-notification/schemas.mjs +1 -0
- package/dist/services/log-import/browser.d.mts +3 -0
- package/dist/services/log-import/browser.mjs +1 -0
- package/dist/services/log-import/index.d.mts +274 -0
- package/dist/services/log-import/index.mjs +2 -0
- package/dist/services/log-import/log-import.d.mts +3 -0
- package/dist/services/log-import/log-import.mjs +1 -0
- package/dist/services/log-import/namespace.d.mts +327 -0
- package/dist/services/log-import/namespace.mjs +1 -0
- package/dist/services/log-import/schemas.d.mts +217 -0
- package/dist/services/log-import/schemas.mjs +1 -0
- package/dist/services/model-registry/index.d.mts +2 -0
- package/dist/services/model-registry/index.mjs +1 -0
- package/dist/services/preferences/index.d.mts +3 -0
- package/dist/services/preferences/index.mjs +1 -0
- package/dist/services/preferences/schemas.d.mts +2 -0
- package/dist/services/preferences/schemas.mjs +1 -0
- package/dist/services/preferences/storage-namespace.d.mts +3 -0
- package/dist/services/preferences/storage-namespace.mjs +1 -0
- package/dist/services/provider-context/index.d.mts +2 -0
- package/dist/services/provider-context/index.mjs +1 -0
- package/dist/services/provider-runtime/index.d.mts +136 -0
- package/dist/services/provider-runtime/index.mjs +1 -0
- package/dist/services/session/handlers/index.d.mts +2 -0
- package/dist/services/session/handlers/index.mjs +1 -0
- package/dist/services/session/index.d.mts +10 -0
- package/dist/services/session/index.mjs +1 -0
- package/dist/services/session/messages/namespace.d.mts +2 -0
- package/dist/services/session/messages/namespace.mjs +1 -0
- package/dist/services/session/orchestrator-testing/index.d.mts +2 -0
- package/dist/services/session/orchestrator-testing/index.mjs +1 -0
- package/dist/services/session/session-events/namespace.d.mts +2 -0
- package/dist/services/session/session-events/namespace.mjs +1 -0
- package/dist/services/session/storage/namespace.d.mts +2 -0
- package/dist/services/session/storage/namespace.mjs +1 -0
- package/dist/services/session/storage/schema.d.mts +2 -0
- package/dist/services/session/storage/schema.mjs +1 -0
- package/dist/services/session/testing/index.d.mts +35 -0
- package/dist/services/session/testing/index.mjs +65 -0
- package/dist/services/session/testing/orchestrator-shared.d.mts +2 -0
- package/dist/services/session/testing/orchestrator-shared.mjs +1 -0
- package/dist/services/session/turns/namespace.d.mts +2 -0
- package/dist/services/session/turns/namespace.mjs +1 -0
- package/dist/services/session-editor/index.d.mts +119 -0
- package/dist/services/session-editor/index.mjs +1 -0
- package/dist/services/settings/index.d.mts +47 -0
- package/dist/services/settings/index.mjs +1 -0
- package/dist/services/settings/namespace.d.mts +663 -0
- package/dist/services/settings/namespace.mjs +1 -0
- package/dist/services/settings/storage/clients-namespace.d.mts +2 -0
- package/dist/services/settings/storage/clients-namespace.mjs +1 -0
- package/dist/services/settings/storage/extension-configs/namespace.d.mts +184 -0
- package/dist/services/settings/storage/extension-configs/namespace.mjs +1 -0
- package/dist/services/settings/storage/index.d.mts +4 -0
- package/dist/services/settings/storage/index.mjs +1 -0
- package/dist/services/settings/storage/providers-namespace.d.mts +2 -0
- package/dist/services/settings/storage/providers-namespace.mjs +1 -0
- package/dist/services/subagent/index.d.mts +2 -0
- package/dist/services/subagent/index.mjs +1 -0
- package/dist/services/subagent-template/index.d.mts +3 -0
- package/dist/services/subagent-template/index.mjs +1 -0
- package/dist/services/subagent-template/namespace.d.mts +2 -0
- package/dist/services/subagent-template/namespace.mjs +1 -0
- package/dist/services/subagent-template/schemas.d.mts +2 -0
- package/dist/services/subagent-template/schemas.mjs +1 -0
- package/dist/services/tool-approval/index.d.mts +2 -0
- package/dist/services/tool-approval/index.mjs +1 -0
- package/dist/services/tools/index.d.mts +2 -0
- package/dist/services/tools/index.mjs +1 -0
- package/dist/services/tray-menu/index.d.mts +4 -0
- package/dist/services/tray-menu/index.mjs +1 -0
- package/dist/services/tray-menu/namespace.d.mts +2 -0
- package/dist/services/tray-menu/namespace.mjs +1 -0
- package/dist/services/tray-menu/schemas.d.mts +2 -0
- package/dist/services/tray-menu/schemas.mjs +1 -0
- package/dist/services/turn/index.d.mts +2 -0
- package/dist/services/turn/index.mjs +1 -0
- package/dist/services/turn/namespace.d.mts +2 -0
- package/dist/services/turn/namespace.mjs +1 -0
- package/dist/services/turn/schemas.d.mts +335 -0
- package/dist/services/turn/schemas.mjs +1 -0
- package/dist/session-BoldSdNZ2.mjs +134 -0
- package/dist/session-DuVOYctZ.mjs +1 -0
- package/dist/session-lineage-CRsc9g1x.d.mts +65 -0
- package/dist/shared-DpOEfD8F.mjs +1 -0
- package/dist/shared-schemas-CPShiLNp.mjs +1 -0
- package/dist/skill-CQO4mDqK.mjs +1 -0
- package/dist/storage/drizzle/client.d.mts +78 -0
- package/dist/storage/drizzle/client.mjs +1 -0
- package/dist/storage/drizzle/index.d.mts +137 -0
- package/dist/storage/drizzle/index.mjs +1 -0
- package/dist/storage/handlers/drizzle/index.d.mts +2 -0
- package/dist/storage/handlers/drizzle/index.mjs +1 -0
- package/dist/storage/handlers/index.d.mts +33 -0
- package/dist/storage/handlers/index.mjs +1 -0
- package/dist/storage/index.d.mts +192 -0
- package/dist/storage/index.mjs +1 -0
- package/dist/storage-namespace-BXkoh5Sy.d.mts +221 -0
- package/dist/storage-namespace-DWsYLAXa.mjs +1 -0
- package/dist/storage-namespace-definition-Bkx5rSto.d.mts +17 -0
- package/dist/storage-namespace-definition-CqSdsuCC.mjs +1 -0
- package/dist/style.css +3782 -0
- package/dist/telemetry-CvdLBWuk.mjs +1 -0
- package/dist/testing/drizzle-harness.d.mts +130 -0
- package/dist/testing/drizzle-harness.mjs +1 -0
- package/dist/testing/index.d.mts +106 -0
- package/dist/testing/index.mjs +1 -0
- package/dist/timeout-XsYIOKrc.mjs +1 -0
- package/dist/tool-approval-service-BvZWhYZp.mjs +1 -0
- package/dist/tools/index.d.mts +835 -0
- package/dist/tools/index.mjs +1 -0
- package/dist/tools/testing/index.d.mts +53 -0
- package/dist/tools/testing/index.mjs +1 -0
- package/dist/tools-D-luYcDw.mjs +1431 -0
- package/dist/tray-menu-service-DuXq5k22.mjs +1 -0
- package/dist/types-BCMUtBj1.d.mts +1106 -0
- package/dist/types-C2Ob9zz_.d.mts +128 -0
- package/dist/types-CCdqjeuH.d.mts +262 -0
- package/dist/types-DZHvOc_Q.d.mts +305 -0
- package/dist/types-Dy3YTcTF.d.mts +6777 -0
- package/dist/types-MfJZ67e9.d.mts +315 -0
- package/dist/types-dyP-bXXE.d.mts +31 -0
- package/dist/ui-components/index.d.mts +2342 -0
- package/dist/ui-components/index.mjs +8 -0
- package/dist/ui-config-9bDRwFZr.mjs +1 -0
- package/dist/ui-hooks/index.d.mts +1915 -0
- package/dist/ui-hooks/index.mjs +1 -0
- package/dist/ui-kernel/index.d.mts +2793 -0
- package/dist/ui-kernel/index.mjs +1 -0
- package/dist/ui-kernel/pages/namespace.d.mts +88 -0
- package/dist/ui-kernel/pages/namespace.mjs +1 -0
- package/dist/ui-kernel/pages/schemas.d.mts +2 -0
- package/dist/ui-kernel/pages/schemas.mjs +1 -0
- package/dist/ui-views/index.d.mts +487 -0
- package/dist/ui-views/index.mjs +30 -0
- package/dist/utils/health-probe.d.mts +26 -0
- package/dist/utils/health-probe.mjs +1 -0
- package/dist/utils/index.d.mts +262 -0
- package/dist/utils/index.mjs +2 -0
- package/dist/utils/keychain.d.mts +31 -0
- package/dist/utils/keychain.mjs +1 -0
- package/dist/utils/project-manifest.d.mts +130 -0
- package/dist/utils/project-manifest.mjs +1 -0
- package/dist/utils/resolve-package-root.d.mts +12 -0
- package/dist/utils/resolve-package-root.mjs +1 -0
- package/dist/utils/scope-paths.d.mts +33 -0
- package/dist/utils/scope-paths.mjs +1 -0
- package/dist/utils/workspace-packages.d.mts +59 -0
- package/dist/utils/workspace-packages.mjs +1 -0
- package/dist/utils/workspace-root.d.mts +24 -0
- package/dist/utils/workspace-root.mjs +2 -0
- package/dist/variant-CT6XBP6T.mjs +1 -0
- package/dist/version-BeT3ASEe.mjs +1 -0
- package/dist/visibility-Cb62p9bv.mjs +1 -0
- package/dist/window-registry-CBcrGTv4.d.mts +130 -0
- package/dist/window-registry-DW-dKRjQ.mjs +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,4202 @@
|
|
|
1
|
+
import { A as MessageHandle, B as ReasoningLevelMap, C as SendMessageRequestPayload, D as IAdapterConfigFactory, E as ConfigFactoryInput, F as MessageState, H as LedgerSessionContext, I as ProcessingState, L as SendMessageOptions, M as NormalizedMessageInput, N as normalizeMessageInput, O as AIAgentConnector, P as MessageResult, R as AIModel, S as NormalizedCallUsage, T as StartAgentOptions, U as SessionToolLedger, V as ISessionToolLedger, W as ToolLedgerEntry, _ as ConnectorSendMessageOptions, a as AgentCwdChangeRequestPayload, b as ExecutionContext, c as AgentInterruptRequestPayload, d as AgentMcpServersSetResponsePayload, f as AgentModelChangeRequestPayload, g as BaseAgentConnectorConfig, h as AgentStartResult, i as AgentCredentialChangeResponsePayload, j as markCompletedWithFinalResult, k as MessageDeliveryMode, l as AgentInterruptResponsePayload, m as AgentSendMessageOptions, n as AgentContext, o as AgentCwdChangeResponsePayload, p as AgentModelChangeResponsePayload, r as AgentCredentialChangeRequestPayload, s as AgentIdentity, t as AIAgentConfig, u as AgentMcpServersSetRequestPayload, v as ConnectorStartOptions, w as SendMessageResponsePayload, x as GetCapabilitiesResponsePayload, y as ContextWindowInput, z as AIReasoningLevel } from "../types-BCMUtBj1.mjs";
|
|
2
|
+
import { _ as LogImporterConfig, a as CompactionMetadata, b as StorageMessagePayload, c as ExternalToolIdentifiers, d as ImportMetadata, f as ImportSegment, g as LogImporter, h as LogImportTestConfig, l as ExternalToolMeta, m as LogImportSessionContext, n as LogOrchestratorConfig, o as DiscoveryMetadata, p as ImportSegmentLineage, r as ParseFileResult, s as ExternalToolIdentifier, u as ImportCursorPosition, v as NormalizedEvent, x as toImportSegment, y as ProcessLogFileResult } from "../base-orchestrator-wyumsn3b.mjs";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import * as _$_makaio_core0 from "@makaio/framework/core";
|
|
5
|
+
import { CreateBusNamespaceOptions, ExtractSubjectPayload, FilterablePayloadIntersection, HandlerForSubjectDefinition, RequestContext, SchemaRecord, ScopedSubjectDefinition, SubjectDefinition, SubjectRecordFromSchemaRecord } from "@makaio/framework/core";
|
|
6
|
+
import { BusNamespace, IMakaioBus, OnOptions, ScopedBus, ScopedBusFor } from "@makaio/framework/bus";
|
|
7
|
+
import { AIReasoningLevel as AIReasoningLevel$1, AdapterClientRef, AdapterDefinitionContract, AdapterProviderDefinitionContract, AdapterSubjects, AgentSchemas, AgentStarted, AgentSubjects, AgentToolApproveRequest, AgentToolApproveResponse, BlockData, HarnessDefinition, HarnessSubjects, JsonValue, McpResolvedServer, McpRuntimeSessionContext, McpSessionContext, McpToolState, Message, MessageInput, ProviderContext, ProviderDefinitionInput, ReasoningLevelMap as ReasoningLevelMap$1, ResponseSchemaDescriptor, SendMessageRequest, SendMessageResponse, SessionContext, SessionMessageBlock, StartAgentRequest, StartAgentResponse, StepType, SystemPrompt, ToolListItem } from "@makaio/framework/contracts";
|
|
8
|
+
import * as _$_makaio_storage_core0 from "@makaio/framework/storage";
|
|
9
|
+
import * as _$type_fest0 from "type-fest";
|
|
10
|
+
import { JsonObject, SetRequired } from "type-fest";
|
|
11
|
+
import { MessageBlock as MessageBlock$1 } from "@makaio/framework/contracts/shared";
|
|
12
|
+
|
|
13
|
+
//#region adapters/core/src/log-importer/registry-types.d.ts
|
|
14
|
+
/**
|
|
15
|
+
* Configuration for log import behavior.
|
|
16
|
+
*
|
|
17
|
+
* Shared between runtime config and orchestrator setup.
|
|
18
|
+
*/
|
|
19
|
+
interface LogImportConfig {
|
|
20
|
+
/** Whether log import is enabled. */
|
|
21
|
+
enabled: boolean;
|
|
22
|
+
/** Polling interval for the file watcher in milliseconds. */
|
|
23
|
+
pollIntervalMs?: number;
|
|
24
|
+
/** Maximum events to emit per second (rate limiting). */
|
|
25
|
+
eventsPerSecond?: number;
|
|
26
|
+
/** Function to check if a session is managed by Makaio (to skip already tracked sessions). */
|
|
27
|
+
checkMakaioManaged?: (sessionId: string) => Promise<boolean>;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Minimal interface for log import orchestrators.
|
|
31
|
+
*
|
|
32
|
+
* Allows LogImportRegistry to manage lifecycle without coupling
|
|
33
|
+
* to a specific orchestrator implementation.
|
|
34
|
+
*/
|
|
35
|
+
interface LogImportOrchestrator {
|
|
36
|
+
/** Whether the orchestrator is running. */
|
|
37
|
+
isRunning(): boolean;
|
|
38
|
+
/** Start the orchestrator. */
|
|
39
|
+
start(): Promise<void>;
|
|
40
|
+
/** Stop the orchestrator. */
|
|
41
|
+
stop(): void | Promise<void>;
|
|
42
|
+
/** Dispose of any resources. */
|
|
43
|
+
dispose(): void | Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
/** Shared constructor signature for log import orchestrator classes. */
|
|
46
|
+
type LogOrchestratorConstructor = new (config: LogOrchestratorConfig) => LogImportOrchestrator;
|
|
47
|
+
/** Shared constructor signature for log importer classes. */
|
|
48
|
+
type LogImporterConstructor = new (config: LogImporterConfig) => LogImporter<unknown, unknown>;
|
|
49
|
+
/**
|
|
50
|
+
* Registration metadata for log importers.
|
|
51
|
+
*
|
|
52
|
+
* Used by runtimes to wire importers into the LogImportRegistry.
|
|
53
|
+
* The adapter name is provided by the runtime at registration time via `adapter.name`.
|
|
54
|
+
*/
|
|
55
|
+
interface LogImportRegistration {
|
|
56
|
+
/** Human-readable name. */
|
|
57
|
+
displayName: string;
|
|
58
|
+
/** Log importer class constructor. */
|
|
59
|
+
LogImporterClass: LogImporterConstructor;
|
|
60
|
+
/** Optional orchestrator class for full session import mode. */
|
|
61
|
+
LogOrchestratorClass?: LogOrchestratorConstructor;
|
|
62
|
+
/**
|
|
63
|
+
* Optional orchestrator class for shallow discovery mode.
|
|
64
|
+
*
|
|
65
|
+
* When present, the runtime uses this class instead of {@link LogOrchestratorClass}
|
|
66
|
+
* when the adapter's import mode is set to `'discover'`.
|
|
67
|
+
*/
|
|
68
|
+
LogDiscoveryOrchestratorClass?: LogOrchestratorConstructor;
|
|
69
|
+
/** Glob pattern for log files. */
|
|
70
|
+
logFilePattern: string;
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region adapters/core/src/types/provider-definition.d.ts
|
|
74
|
+
/**
|
|
75
|
+
* Runtime adapter provider definition pairing a serializable provider definition
|
|
76
|
+
* with optional runtime-only schemas.
|
|
77
|
+
*
|
|
78
|
+
* Extends {@link AdapterProviderDefinitionContract} from `@makaio/contracts` which
|
|
79
|
+
* is the single source of truth for the `definition`, `configSchema`, and
|
|
80
|
+
* `credentialSchema` fields. All fields are inherited from the contract — this
|
|
81
|
+
* type exists to give the shape a domain-specific name used throughout
|
|
82
|
+
* adapter implementation packages and to allow future additions specific to
|
|
83
|
+
* `ai-adapters-core`.
|
|
84
|
+
*
|
|
85
|
+
* Each adapter exports an array of these from its `definition.ts` (via `providers`).
|
|
86
|
+
* The `definition` field contains serializable data (models, endpoints, etc.).
|
|
87
|
+
* The schema fields are runtime-only — used for UI form generation, never serialized.
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* const anthropicProvider: AdapterProviderDefinition = {
|
|
91
|
+
* definition: {
|
|
92
|
+
* id: 'anthropic',
|
|
93
|
+
* name: 'Anthropic',
|
|
94
|
+
* endpoints: { anthropic: 'https://api.anthropic.com' },
|
|
95
|
+
* defaultModel: 'sonnet',
|
|
96
|
+
* availableModels: [...]
|
|
97
|
+
* },
|
|
98
|
+
* credentialSchema: z.object({
|
|
99
|
+
* apiKey: z.string().describe('Anthropic API Key')
|
|
100
|
+
* })
|
|
101
|
+
* };
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
interface AdapterProviderDefinition extends AdapterProviderDefinitionContract {
|
|
105
|
+
/**
|
|
106
|
+
* Provider-specific config schema for UI form generation (runtime-only).
|
|
107
|
+
*
|
|
108
|
+
* Defines provider-specific configuration fields like debugging flags,
|
|
109
|
+
* rate limiting options, or provider-specific features.
|
|
110
|
+
* Not serialized — used for dynamic form generation in the settings UI.
|
|
111
|
+
*/
|
|
112
|
+
readonly configSchema?: z.ZodObject<z.ZodRawShape>;
|
|
113
|
+
/**
|
|
114
|
+
* Provider-specific credential schema for secure credential capture (runtime-only).
|
|
115
|
+
*
|
|
116
|
+
* Defines credential fields (apiKey, apiSecret, etc.) for secure input.
|
|
117
|
+
* Credentials are stored separately via the credential service, never in plain config.
|
|
118
|
+
* Not serialized — used for dynamic form generation in the settings UI.
|
|
119
|
+
*/
|
|
120
|
+
readonly credentialSchema?: z.ZodObject<z.ZodRawShape>;
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region adapters/core/src/types/ai-adapter-init-options.d.ts
|
|
124
|
+
/**
|
|
125
|
+
* Platform-provided defaults injected by the runtime.
|
|
126
|
+
* These are the lowest priority and will be overridden by request-level values.
|
|
127
|
+
*/
|
|
128
|
+
interface PlatformDefaults {
|
|
129
|
+
/** Default working directory for agent execution (e.g., os.tmpdir() on Node.js) */
|
|
130
|
+
cwd?: string;
|
|
131
|
+
/** Default environment variables */
|
|
132
|
+
env?: Record<string, string>;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Initialization options for `AIAdapter.init()`.
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* await adapter.init({
|
|
139
|
+
* defaultModel: "claude-3.5-sonnet",
|
|
140
|
+
* providerOptions: { apiKey: process.env.API_KEY }
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
* @see {@link AIAdapterPromptOptions} for per-message config
|
|
144
|
+
* @see [Creating Adapters Guide](../../docs/creating-adapters.md)
|
|
145
|
+
*/
|
|
146
|
+
interface AIAdapterInitOptions {
|
|
147
|
+
/** Default model when not specified per-message. Provider-specific identifier. */
|
|
148
|
+
defaultModel?: string;
|
|
149
|
+
/** Provider-specific config (API keys, base URLs, defaults, etc.). Type explicitly in adapter implementations. */
|
|
150
|
+
providerOptions?: unknown;
|
|
151
|
+
adapterId?: string;
|
|
152
|
+
/**
|
|
153
|
+
* Platform-provided defaults (cwd, env, etc.).
|
|
154
|
+
* Lowest priority - overridden by request values.
|
|
155
|
+
* Injected by runtime during adapter initialization.
|
|
156
|
+
*/
|
|
157
|
+
platformDefaults?: PlatformDefaults;
|
|
158
|
+
/**
|
|
159
|
+
* Log import configuration for external session imports.
|
|
160
|
+
*/
|
|
161
|
+
logImport?: LogImportConfig;
|
|
162
|
+
/**
|
|
163
|
+
* Provider definitions from the adapter definition.
|
|
164
|
+
* Contains provider definitions with available models for context window lookup.
|
|
165
|
+
* Injected by runtime during adapter initialization.
|
|
166
|
+
*/
|
|
167
|
+
definitionProviders?: AdapterProviderDefinition[];
|
|
168
|
+
/** Client identifier for the application this adapter belongs to (e.g., 'claude-code', 'codex'). Omit for API-only adapters. */
|
|
169
|
+
clientId?: string;
|
|
170
|
+
}
|
|
171
|
+
//#endregion
|
|
172
|
+
//#region adapters/core/src/utils/safeJsonStringify.d.ts
|
|
173
|
+
/**
|
|
174
|
+
* Safely serialize a value to JSON string.
|
|
175
|
+
*
|
|
176
|
+
* Handles BigInt values, circular references, and non-serializable types
|
|
177
|
+
* without throwing. Circular nodes are replaced with `'[Circular]'` rather
|
|
178
|
+
* than aborting the entire serialization. Falls back to `String(value)` when
|
|
179
|
+
* JSON serialization is not possible at all.
|
|
180
|
+
* @param value - The value to serialize
|
|
181
|
+
* @returns JSON string representation or a fallback string on failure
|
|
182
|
+
*/
|
|
183
|
+
declare function safeJsonStringify(value: unknown): string;
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region adapters/core/src/utils/serializeTurnContext.d.ts
|
|
186
|
+
/**
|
|
187
|
+
* A single serialized context entry ready for adapter-specific formatting.
|
|
188
|
+
*/
|
|
189
|
+
interface SerializedContextBlock {
|
|
190
|
+
/** XML tag name, e.g. 'skills', 'cwdChange' */
|
|
191
|
+
readonly tag: string;
|
|
192
|
+
/** Pre-formatted content (Markdown for skills/catalog, JSON for others) */
|
|
193
|
+
readonly content: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Format one context block as an XML-tagged text block.
|
|
197
|
+
* @param tag - Block tag name (sanitized before rendering)
|
|
198
|
+
* @param content - Block content (XML-escaped before rendering)
|
|
199
|
+
* @returns XML-tagged text block safe for prompt injection
|
|
200
|
+
*/
|
|
201
|
+
declare function formatContextBlockAsText(tag: string, content: string): string;
|
|
202
|
+
/**
|
|
203
|
+
* Serialize a MessageHandle's turnContext into ordered text blocks.
|
|
204
|
+
*
|
|
205
|
+
* All non-null, non-undefined keys are serialized. The `skillCatalog`,
|
|
206
|
+
* `skills`, and `contextRules` keys get dedicated markdown formatting;
|
|
207
|
+
* all other keys are JSON-serialized.
|
|
208
|
+
*
|
|
209
|
+
* Each adapter converts these blocks to its wire format:
|
|
210
|
+
* - Claude SDK: each block → prependContextBlock(msg, tag, content)
|
|
211
|
+
* - Anthropic/OpenAI: join and prepend to user message
|
|
212
|
+
* - Gemini: push as requestPart
|
|
213
|
+
* - CLI/Copilot: prepend to prompt string
|
|
214
|
+
* - Codex: push as userInput
|
|
215
|
+
* @param turnContext - The context record from MessageHandle.turnContext
|
|
216
|
+
* @returns Ordered blocks: skillCatalog, skills, contextRules, then remaining keys alphabetical.
|
|
217
|
+
* Empty when turnContext is nullish or empty.
|
|
218
|
+
*/
|
|
219
|
+
declare function serializeTurnContext(turnContext: Record<string, JsonValue | undefined> | undefined): SerializedContextBlock[];
|
|
220
|
+
/**
|
|
221
|
+
* Format serialized context blocks as XML-tagged text.
|
|
222
|
+
* Convenience for adapters that prepend context as plain text to the user message.
|
|
223
|
+
* @param blocks - Blocks from serializeTurnContext()
|
|
224
|
+
* @returns Single string with each block wrapped in XML tags, separated by newlines.
|
|
225
|
+
* Empty string when no blocks.
|
|
226
|
+
*/
|
|
227
|
+
declare function formatContextBlocksAsText(blocks: SerializedContextBlock[]): string;
|
|
228
|
+
//#endregion
|
|
229
|
+
//#region adapters/core/src/types/capabilities.d.ts
|
|
230
|
+
/**
|
|
231
|
+
* Extensible registry of all known AI adapter capabilities.
|
|
232
|
+
*
|
|
233
|
+
* This interface can be extended by external packages (extensions) via declaration merging:
|
|
234
|
+
* @example
|
|
235
|
+
* ```typescript
|
|
236
|
+
* // In a plugin package
|
|
237
|
+
* declare module '@makaio/framework/adapters' {
|
|
238
|
+
* interface AIAdapterCapabilityRegistry {
|
|
239
|
+
* customAuth: {
|
|
240
|
+
* oauth: boolean;
|
|
241
|
+
* saml: boolean;
|
|
242
|
+
* };
|
|
243
|
+
* }
|
|
244
|
+
* }
|
|
245
|
+
*
|
|
246
|
+
* // Now these work automatically:
|
|
247
|
+
* caps.hasAll(['customAuth:oauth']) // ✅ Type-safe
|
|
248
|
+
* caps.customAuthOauth // ✅ Auto-generated property
|
|
249
|
+
* ```
|
|
250
|
+
*/
|
|
251
|
+
interface AIAdapterCapabilityRegistry {
|
|
252
|
+
systemPrompt: {
|
|
253
|
+
override: boolean;
|
|
254
|
+
append: boolean;
|
|
255
|
+
};
|
|
256
|
+
session: {
|
|
257
|
+
resume: boolean;
|
|
258
|
+
fork: boolean;
|
|
259
|
+
};
|
|
260
|
+
chat: {
|
|
261
|
+
inTurnMessages: boolean;
|
|
262
|
+
};
|
|
263
|
+
modelSwitchInSession: boolean;
|
|
264
|
+
streaming: boolean;
|
|
265
|
+
tools: boolean;
|
|
266
|
+
vision: boolean;
|
|
267
|
+
/**
|
|
268
|
+
* Adapter supports native structured output (JSON schema enforcement
|
|
269
|
+
* at the model level via response_format or equivalent).
|
|
270
|
+
*
|
|
271
|
+
* Sub-capability:
|
|
272
|
+
* - `structuredOutput:strict` — adapter enforces strict schema validation
|
|
273
|
+
* (no additional properties, all fields required). Corresponds to
|
|
274
|
+
* `response_format: { type: 'json_schema', json_schema: { strict: true } }`
|
|
275
|
+
* in the OpenAI API.
|
|
276
|
+
*/
|
|
277
|
+
structuredOutput: {
|
|
278
|
+
strict: boolean;
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Recursively builds capability path strings from registry.
|
|
283
|
+
* Example: `'systemPrompt'` | `'systemPrompt:override'` | `'systemPrompt:append'`
|
|
284
|
+
* @internal
|
|
285
|
+
*/
|
|
286
|
+
type CapabilityPath<T> = T extends object ? { [K in keyof T]: K extends string ? T[K] extends boolean ? K : T[K] extends object ? `${K}:${CapabilityPath<T[K]>}` | K : K : never }[keyof T] : never;
|
|
287
|
+
/** Union of all valid capability strings from the registry. */
|
|
288
|
+
type ValidCapability = CapabilityPath<AIAdapterCapabilityRegistry>;
|
|
289
|
+
/**
|
|
290
|
+
* Converts capability path to camelCase property name.
|
|
291
|
+
* Example: `'session:fork'` → `'sessionFork'`
|
|
292
|
+
* @internal
|
|
293
|
+
*/
|
|
294
|
+
type PathToPropertyName<S extends string> = S extends `${infer First}:${infer Rest}` ? `${First}${PathToPropertyName<Capitalize<Rest>>}` : S;
|
|
295
|
+
/** Flattens registry into camelCase boolean properties. @internal */
|
|
296
|
+
type GeneratedCapabilityProperties = { [P in ValidCapability as PathToPropertyName<P>]?: boolean };
|
|
297
|
+
/**
|
|
298
|
+
* Runtime-queryable capabilities object returned by AI adapters.
|
|
299
|
+
*
|
|
300
|
+
* Auto-generates boolean properties from {@link AIAdapterCapabilityRegistry}:
|
|
301
|
+
* - `'systemPrompt'` → `caps.systemPrompt`
|
|
302
|
+
* - `'systemPrompt:override'` → `caps.systemPromptOverride`
|
|
303
|
+
* - `'session:fork'` → `caps.sessionFork`
|
|
304
|
+
* @remarks
|
|
305
|
+
* Capabilities are **optional and declarative**:
|
|
306
|
+
* - Adapters declare only what their underlying service supports
|
|
307
|
+
* - Platform checks capabilities before using optional features
|
|
308
|
+
* - No "not implemented" exceptions
|
|
309
|
+
* - Plugin-extendable via declaration merging
|
|
310
|
+
* @example
|
|
311
|
+
* ```typescript
|
|
312
|
+
* const caps = adapter.getCapabilities();
|
|
313
|
+
*
|
|
314
|
+
* // Single checks (most common)
|
|
315
|
+
* if (caps.vision) { ... }
|
|
316
|
+
* if (caps.tools && caps.vision) { ... }
|
|
317
|
+
*
|
|
318
|
+
* // Batch checks (explicit AND/OR)
|
|
319
|
+
* if (caps.hasAll(['vision', 'tools'])) { ... }
|
|
320
|
+
* if (caps.hasAny(['session:resume', 'session:fork'])) { ... }
|
|
321
|
+
* ```
|
|
322
|
+
* @see {@link AIAdapterCapabilityRegistry} - Schema and plugin extensibility
|
|
323
|
+
* @see {@link parseAIAdapterCapabilities} - Create instances from strings
|
|
324
|
+
*/
|
|
325
|
+
type AIAdapterCapabilities = GeneratedCapabilityProperties & {
|
|
326
|
+
/** Check if ALL specified capabilities are present (AND logic) */hasAll(capabilities: ValidCapability[]): boolean; /** Check if ANY of the specified capabilities are present (OR logic) */
|
|
327
|
+
hasAny(capabilities: ValidCapability[]): boolean;
|
|
328
|
+
};
|
|
329
|
+
type AIAdapterCapability = keyof GeneratedCapabilityProperties;
|
|
330
|
+
//#endregion
|
|
331
|
+
//#region adapters/core/src/utils/capabilities.d.ts
|
|
332
|
+
/**
|
|
333
|
+
* Parses capability strings into a typed AIAdapterCapabilities object.
|
|
334
|
+
*
|
|
335
|
+
* Transforms strings (e.g., from adapter.json) into runtime-queryable object with:
|
|
336
|
+
* - Auto-generated camelCase boolean properties (`'session:fork'` → `caps.sessionFork`)
|
|
337
|
+
* - `hasAll()` and `hasAny()` methods for batch checks
|
|
338
|
+
* @example
|
|
339
|
+
* ```typescript
|
|
340
|
+
* const caps = parseAIAdapterCapabilities(['systemPrompt', 'vision', 'session:resume']);
|
|
341
|
+
*
|
|
342
|
+
* caps.systemPrompt // true
|
|
343
|
+
* caps.sessionResume // true
|
|
344
|
+
* caps.hasAll(['vision', 'systemPrompt']) // true
|
|
345
|
+
* ```
|
|
346
|
+
* @param caps - Capability strings declared by the adapter
|
|
347
|
+
* @returns Capabilities object with auto-generated properties and batch methods
|
|
348
|
+
* @see {@link AIAdapterCapabilities} - Runtime API
|
|
349
|
+
* @see {@link AIAdapterCapabilityRegistry} - Schema for custom capabilities
|
|
350
|
+
*/
|
|
351
|
+
declare function parseAIAdapterCapabilities(caps: string[]): AIAdapterCapabilities;
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region adapters/core/src/utils/cleanEnvForAdapter.d.ts
|
|
354
|
+
type AdapterEnv = Record<string, string | undefined>;
|
|
355
|
+
/**
|
|
356
|
+
* Options for adapter environment cleanup.
|
|
357
|
+
*/
|
|
358
|
+
interface CleanEnvForAdapterOptions {
|
|
359
|
+
/**
|
|
360
|
+
* Additional environment variables to remove from the inherited environment.
|
|
361
|
+
*/
|
|
362
|
+
omitEnvVars?: readonly string[];
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Clean environment variables for adapter child processes.
|
|
366
|
+
*
|
|
367
|
+
* Removes variables that should not be inherited by spawned adapter
|
|
368
|
+
* processes (for example Claude Code SDK and CLI wrappers).
|
|
369
|
+
*
|
|
370
|
+
* SEAM: Extend this list as additional problematic environment variables
|
|
371
|
+
* are discovered across adapter implementations.
|
|
372
|
+
* @param env - Optional base environment to clean (defaults to `undefined`)
|
|
373
|
+
* @param options - Additional cleanup options
|
|
374
|
+
* @returns Cleaned environment object with problematic variables removed.
|
|
375
|
+
* @example
|
|
376
|
+
* ```typescript
|
|
377
|
+
* const session = query({
|
|
378
|
+
* options: {
|
|
379
|
+
* env: cleanEnvForAdapter(customEnv),
|
|
380
|
+
* },
|
|
381
|
+
* });
|
|
382
|
+
* ```
|
|
383
|
+
*/
|
|
384
|
+
declare function cleanEnvForAdapter(env?: AdapterEnv, options?: CleanEnvForAdapterOptions): Record<string, string>;
|
|
385
|
+
//#endregion
|
|
386
|
+
//#region adapters/core/src/utils/discriminated-handlers.d.ts
|
|
387
|
+
/**
|
|
388
|
+
* Type-safe emit function for discriminated handlers.
|
|
389
|
+
* Each call is validated at compile time to ensure payload matches subject.
|
|
390
|
+
*
|
|
391
|
+
* The emit function signature matches AIAgent.emitGlobal, allowing handlers
|
|
392
|
+
* to emit events without knowing whether they're running in live agent context
|
|
393
|
+
* or log import context.
|
|
394
|
+
*/
|
|
395
|
+
type TypedEmitFn = <S extends SubjectDefinition>(subject: S, payload: Omit<ExtractSubjectPayload<S>, keyof AgentContext>) => void | Promise<void>;
|
|
396
|
+
/**
|
|
397
|
+
* Synchronous variant of TypedEmitFn.
|
|
398
|
+
* Use with processDiscriminatedItemsSync to enforce sync handlers at compile time.
|
|
399
|
+
*/
|
|
400
|
+
type SyncTypedEmitFn = <S extends SubjectDefinition>(subject: S, payload: Omit<ExtractSubjectPayload<S>, keyof AgentContext>) => void;
|
|
401
|
+
/**
|
|
402
|
+
* Handler function that receives narrowed payload and typed emit.
|
|
403
|
+
* @typeParam TPayload - The narrowed payload type (discriminated union member)
|
|
404
|
+
* @typeParam TEmit - The emit function type (defaults to TypedEmitFn)
|
|
405
|
+
*/
|
|
406
|
+
type DiscriminatedHandler<TPayload, TEmit extends TypedEmitFn = TypedEmitFn> = (payload: TPayload, emit: TEmit) => void | Promise<void>;
|
|
407
|
+
/**
|
|
408
|
+
* Synchronous handler that cannot return a Promise.
|
|
409
|
+
* Use with processDiscriminatedItemsSync to catch async handlers at compile time.
|
|
410
|
+
*/
|
|
411
|
+
type SyncDiscriminatedHandler<TPayload> = (payload: TPayload, emit: SyncTypedEmitFn) => void;
|
|
412
|
+
/**
|
|
413
|
+
* Handlers map with discriminator-narrowed payload types.
|
|
414
|
+
*
|
|
415
|
+
* Each key is a possible value of the discriminator property,
|
|
416
|
+
* and each handler receives the narrowed payload type for that discriminator value.
|
|
417
|
+
* @typeParam TPayload - The full discriminated union type
|
|
418
|
+
* @typeParam TDiscriminator - The property key used to discriminate union members
|
|
419
|
+
*/
|
|
420
|
+
type DiscriminatedHandlersMap<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string> = { [K in TPayload[TDiscriminator] & string]?: DiscriminatedHandler<Extract<TPayload, { [P in TDiscriminator]: K }>> };
|
|
421
|
+
/**
|
|
422
|
+
* Synchronous handlers map for compile-time async prevention.
|
|
423
|
+
* Use with defineDiscriminatedHandlersSync and processDiscriminatedItemsSync.
|
|
424
|
+
*/
|
|
425
|
+
type SyncDiscriminatedHandlersMap<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string> = { [K in TPayload[TDiscriminator] & string]?: SyncDiscriminatedHandler<Extract<TPayload, { [P in TDiscriminator]: K }>> };
|
|
426
|
+
/**
|
|
427
|
+
* Configuration returned by defineDiscriminatedHandlers.
|
|
428
|
+
*
|
|
429
|
+
* Encapsulates the discriminator key and handler map for use with
|
|
430
|
+
* processDiscriminatedItems.
|
|
431
|
+
* @typeParam TPayload - The full discriminated union type
|
|
432
|
+
* @typeParam TDiscriminator - The property key used to discriminate union members
|
|
433
|
+
*/
|
|
434
|
+
interface DiscriminatedHandlersConfig<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string> {
|
|
435
|
+
discriminator: TDiscriminator;
|
|
436
|
+
handlers: DiscriminatedHandlersMap<TPayload, TDiscriminator>;
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Synchronous configuration for compile-time async prevention.
|
|
440
|
+
* Use with defineDiscriminatedHandlersSync and processDiscriminatedItemsSync.
|
|
441
|
+
*/
|
|
442
|
+
interface SyncDiscriminatedHandlersConfig<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string> {
|
|
443
|
+
discriminator: TDiscriminator;
|
|
444
|
+
handlers: SyncDiscriminatedHandlersMap<TPayload, TDiscriminator>;
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* Factory to create typed discriminated handlers.
|
|
448
|
+
*
|
|
449
|
+
* This function provides compile-time validation that handlers receive
|
|
450
|
+
* correctly narrowed payload types based on the discriminator value.
|
|
451
|
+
* @param discriminator - The property key used to discriminate union members
|
|
452
|
+
* @param handlers - Map of discriminator values to handler functions
|
|
453
|
+
* @returns Configuration object for use with processDiscriminatedItems
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* // Define handlers with full type safety
|
|
457
|
+
* const handlers = defineDiscriminatedHandlers<BetaContentBlock, 'type'>('type', {
|
|
458
|
+
* text: (block, emit) => {
|
|
459
|
+
* // block is narrowed to BetaTextBlock
|
|
460
|
+
* emit(AgentSubjects.message, { content: block.text });
|
|
461
|
+
* },
|
|
462
|
+
* thinking: (block, emit) => {
|
|
463
|
+
* // block is narrowed to BetaThinkingBlock
|
|
464
|
+
* emit(AgentSubjects.reasoning, { content: block.thinking });
|
|
465
|
+
* },
|
|
466
|
+
* tool_use: (block, emit) => {
|
|
467
|
+
* // block is narrowed to BetaToolUseBlock
|
|
468
|
+
* emit(AgentSubjects.tool.use, {
|
|
469
|
+
* toolName: block.name,
|
|
470
|
+
* args: block.input,
|
|
471
|
+
* toolCallId: block.id,
|
|
472
|
+
* });
|
|
473
|
+
* },
|
|
474
|
+
* });
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
declare function defineDiscriminatedHandlers<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string = keyof TPayload & string>(discriminator: TDiscriminator, handlers: DiscriminatedHandlersMap<TPayload, TDiscriminator>): DiscriminatedHandlersConfig<TPayload, TDiscriminator>;
|
|
478
|
+
/**
|
|
479
|
+
* Factory for sync-only handlers with compile-time async prevention.
|
|
480
|
+
*
|
|
481
|
+
* Use this instead of defineDiscriminatedHandlers when handlers will be
|
|
482
|
+
* used with processDiscriminatedItemsSync. Async handlers will cause
|
|
483
|
+
* compile-time errors rather than runtime errors.
|
|
484
|
+
* @param discriminator - Property key used to discriminate payload types
|
|
485
|
+
* @param handlers - Map of discriminator values to sync handler functions
|
|
486
|
+
* @returns Config object for processDiscriminatedItemsSync
|
|
487
|
+
*/
|
|
488
|
+
declare function defineDiscriminatedHandlersSync<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string = keyof TPayload & string>(discriminator: TDiscriminator, handlers: SyncDiscriminatedHandlersMap<TPayload, TDiscriminator>): SyncDiscriminatedHandlersConfig<TPayload, TDiscriminator>;
|
|
489
|
+
/**
|
|
490
|
+
* Process items through discriminated handlers.
|
|
491
|
+
*
|
|
492
|
+
* Iterates over items (or processes single item), reads discriminator,
|
|
493
|
+
* and calls appropriate handler with typed emit. Items without a matching
|
|
494
|
+
* handler are silently skipped.
|
|
495
|
+
* @param items - Single item or array of items to process
|
|
496
|
+
* @param config - Handler configuration from defineDiscriminatedHandlers
|
|
497
|
+
* @param emit - Typed emit function (can be emitGlobal, collection push, etc.)
|
|
498
|
+
* @example
|
|
499
|
+
* ```typescript
|
|
500
|
+
* // Agent usage - emit directly
|
|
501
|
+
* await processDiscriminatedItems(
|
|
502
|
+
* content,
|
|
503
|
+
* CONTENT_BLOCK_HANDLERS,
|
|
504
|
+
* (subject, payload) => this.emitGlobal(subject, payload),
|
|
505
|
+
* );
|
|
506
|
+
*
|
|
507
|
+
* // Importer usage - collect events with enrichment
|
|
508
|
+
* const events: NormalizedEvent[] = [];
|
|
509
|
+
* await processDiscriminatedItems(
|
|
510
|
+
* content,
|
|
511
|
+
* CONTENT_BLOCK_HANDLERS,
|
|
512
|
+
* (subject, payload) => {
|
|
513
|
+
* events.push({ subject, payload: { ...basePayload, ...payload } });
|
|
514
|
+
* },
|
|
515
|
+
* );
|
|
516
|
+
* ```
|
|
517
|
+
*/
|
|
518
|
+
declare function processDiscriminatedItems<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string>(items: TPayload | TPayload[], config: DiscriminatedHandlersConfig<TPayload, TDiscriminator>, emit: TypedEmitFn): Promise<void>;
|
|
519
|
+
/**
|
|
520
|
+
* Synchronous variant of processDiscriminatedItems.
|
|
521
|
+
*
|
|
522
|
+
* Two usage modes:
|
|
523
|
+
* 1. With SyncDiscriminatedHandlersConfig: Full compile-time async prevention
|
|
524
|
+
* 2. With DiscriminatedHandlersConfig: Runtime-only async detection (for shared handlers)
|
|
525
|
+
* @param items - Single item or array of items to process
|
|
526
|
+
* @param config - Handler configuration (sync or async)
|
|
527
|
+
* @param emit - Synchronous emit function
|
|
528
|
+
* @throws Error if a handler returns a Promise
|
|
529
|
+
*/
|
|
530
|
+
declare function processDiscriminatedItemsSync<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string>(items: TPayload | TPayload[], config: SyncDiscriminatedHandlersConfig<TPayload, TDiscriminator>, emit: SyncTypedEmitFn): void;
|
|
531
|
+
/**
|
|
532
|
+
* Overload for shared handlers defined with defineDiscriminatedHandlers.
|
|
533
|
+
* Provides runtime-only async detection (no compile-time safety).
|
|
534
|
+
* @param items - Single item or array of items to process
|
|
535
|
+
* @param config - Discriminated handlers config from defineDiscriminatedHandlers
|
|
536
|
+
* @param emit - Typed emit function for publishing events
|
|
537
|
+
*/
|
|
538
|
+
declare function processDiscriminatedItemsSync<TPayload extends Record<string, unknown>, TDiscriminator extends keyof TPayload & string>(items: TPayload | TPayload[], config: DiscriminatedHandlersConfig<TPayload, TDiscriminator>, emit: SyncTypedEmitFn): void;
|
|
539
|
+
//#endregion
|
|
540
|
+
//#region adapters/core/src/utils/normalizeEnvValue.d.ts
|
|
541
|
+
/**
|
|
542
|
+
* Normalize blank environment values to `undefined`.
|
|
543
|
+
* @param value - Raw environment value
|
|
544
|
+
* @returns Trimmed value when non-empty
|
|
545
|
+
*/
|
|
546
|
+
declare function normalizeEnvValue(value: string | undefined): string | undefined;
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region adapters/core/src/utils/resolveTestConfig.d.ts
|
|
549
|
+
/** Fields injected by resolveTestConfig */
|
|
550
|
+
type InjectedTestFields<TBus extends ScopedBus<string>> = {
|
|
551
|
+
agentId: string;
|
|
552
|
+
adapterId: string;
|
|
553
|
+
adapterName: string;
|
|
554
|
+
bus: TBus;
|
|
555
|
+
/**
|
|
556
|
+
* Unresolved provider context for conformance tests.
|
|
557
|
+
*
|
|
558
|
+
* When a `testProviderDefinition` is supplied, credential refs are built
|
|
559
|
+
* from the definition's `credentialEnvVars` mapping using `env:VAR_NAME`
|
|
560
|
+
* format. Connectors resolve these refs locally via `resolveConnectorCredentials()`
|
|
561
|
+
* — which reads from `process.env` for `env:` refs — mirroring the full
|
|
562
|
+
* credential-resolution chain without requiring a database or bus handlers.
|
|
563
|
+
*
|
|
564
|
+
* Falls back to a minimal sentinel (empty `credentialRefs`) when no definition
|
|
565
|
+
* is provided.
|
|
566
|
+
*/
|
|
567
|
+
providerContext: ProviderContext;
|
|
568
|
+
};
|
|
569
|
+
/** Result type: options merged with injected fields (handles undefined options) */
|
|
570
|
+
type ResolvedTestConfig<TOptions, TBus extends ScopedBus<string>> = (TOptions extends undefined ? object : TOptions) & InjectedTestFields<TBus>;
|
|
571
|
+
/**
|
|
572
|
+
* Build an unresolved provider context for conformance tests.
|
|
573
|
+
*
|
|
574
|
+
* When a provider definition is supplied, builds credential refs in `env:VAR_NAME`
|
|
575
|
+
* format from `credentialEnvVars`. Connectors resolve these refs locally via
|
|
576
|
+
* `resolveConnectorCredentials()`. Otherwise returns a minimal sentinel.
|
|
577
|
+
* @param definition - Optional provider definition to build credential refs from
|
|
578
|
+
* @param ambientCredentialDefinitions - Provider definitions whose credential
|
|
579
|
+
* env vars should be stripped from ambient subprocess environments
|
|
580
|
+
* @returns Fresh unresolved provider context per call to prevent cross-test mutation leaks
|
|
581
|
+
*/
|
|
582
|
+
declare function createTestProviderContext(definition?: ProviderDefinitionInput, ambientCredentialDefinitions?: readonly ProviderDefinitionInput[]): ProviderContext;
|
|
583
|
+
/**
|
|
584
|
+
* Resolves test configuration by adding required fields (bus, agentId, adapterId, adapterName, providerContext).
|
|
585
|
+
*
|
|
586
|
+
* When `testProviderDefinition` is supplied, credential refs and endpoint overrides
|
|
587
|
+
* are built from the definition's `credentialEnvVars` and `endpoints` — so
|
|
588
|
+
* conformance tests can run against real providers without the full orchestrator.
|
|
589
|
+
* @param options - Partial test agent options (undefined = empty config)
|
|
590
|
+
* @param bus - Scoped bus instance for the adapter
|
|
591
|
+
* @param testProviderDefinition - Optional provider definition for credential ref building
|
|
592
|
+
* @param ambientCredentialDefinitions - Provider definitions whose credential
|
|
593
|
+
* env vars should be stripped from ambient subprocess environments
|
|
594
|
+
* @returns Complete test config with required fields injected
|
|
595
|
+
*/
|
|
596
|
+
declare function resolveTestConfig<TOptions extends CreateTestAgentOptions | undefined, TBus extends ScopedBus<string>>(options: TOptions, bus: TBus, testProviderDefinition?: ProviderDefinitionInput, ambientCredentialDefinitions?: readonly ProviderDefinitionInput[]): ResolvedTestConfig<TOptions, TBus>;
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region adapters/core/src/utils/resolveConformanceTestPreset.d.ts
|
|
599
|
+
/** Default environment variable for selecting a conformance provider preset. */
|
|
600
|
+
declare const MAKAIO_CONFORMANCE_PROVIDER_ENV = "MAKAIO_CONFORMANCE_PROVIDER";
|
|
601
|
+
/** Default environment variable for overriding the primary conformance model. */
|
|
602
|
+
declare const MAKAIO_CONFORMANCE_PRIMARY_MODEL_ENV = "MAKAIO_CONFORMANCE_PRIMARY_MODEL";
|
|
603
|
+
/** Default environment variable for overriding the secondary conformance model. */
|
|
604
|
+
declare const MAKAIO_CONFORMANCE_SECONDARY_MODEL_ENV = "MAKAIO_CONFORMANCE_SECONDARY_MODEL";
|
|
605
|
+
/** Environment variable used by the conformance runner to pass provider definitions into worker forks. */
|
|
606
|
+
declare const MAKAIO_CONFORMANCE_PROVIDER_DEFINITIONS_ENV = "MAKAIO_CONFORMANCE_PROVIDER_DEFINITIONS";
|
|
607
|
+
/** Reads an environment variable value by name. */
|
|
608
|
+
type ConformanceEnvReader = (name: string) => string | undefined;
|
|
609
|
+
/**
|
|
610
|
+
* Options for resolving the provider/model preset used by conformance tests.
|
|
611
|
+
*/
|
|
612
|
+
interface ResolveConformanceTestPresetOptions {
|
|
613
|
+
/** Adapter name used in configuration error messages. */
|
|
614
|
+
adapterName: string;
|
|
615
|
+
/** Provider ID used when no env override is supplied. */
|
|
616
|
+
defaultProviderId: string;
|
|
617
|
+
/** Provider IDs accepted by this adapter's conformance config. */
|
|
618
|
+
providerIds: readonly string[];
|
|
619
|
+
/** Full provider definitions supplied by the conformance harness. */
|
|
620
|
+
providerDefinitions?: readonly ProviderDefinitionInput[];
|
|
621
|
+
/** Default reasoning effort to attach to resolved model refs. */
|
|
622
|
+
reasoningEffort?: TestModelRef['reasoningEffort'];
|
|
623
|
+
/** Environment reader, injectable for tests. */
|
|
624
|
+
readEnv?: ConformanceEnvReader;
|
|
625
|
+
/** Provider override env var name. */
|
|
626
|
+
providerEnvVar?: string;
|
|
627
|
+
/** Primary model override env var name. */
|
|
628
|
+
primaryModelEnvVar?: string;
|
|
629
|
+
/** Secondary model override env var name. */
|
|
630
|
+
secondaryModelEnvVar?: string;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* Resolved conformance provider/model preset.
|
|
634
|
+
*/
|
|
635
|
+
interface ResolvedConformanceTestPreset {
|
|
636
|
+
/** Provider selected for this test run. */
|
|
637
|
+
provider: ProviderDefinitionInput;
|
|
638
|
+
/** All accepted provider definitions, including the selected provider. */
|
|
639
|
+
providers: readonly ProviderDefinitionInput[];
|
|
640
|
+
/** Provider context derived from the selected provider. */
|
|
641
|
+
providerContext: ProviderContext;
|
|
642
|
+
/** Fast/cheap model used by most conformance tests. */
|
|
643
|
+
primaryModel: TestModelRef;
|
|
644
|
+
/** Second model used by lifecycle mutation tests. */
|
|
645
|
+
secondaryModel: TestModelRef;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* Resolve a conformance test provider preset from defaults plus MAKAIO_CONFORMANCE_* overrides.
|
|
649
|
+
*
|
|
650
|
+
* Provider, primary model, secondary model, credentials, and endpoint overrides
|
|
651
|
+
* are resolved together so CI can swap test economics without changing local
|
|
652
|
+
* OAuth/default behavior.
|
|
653
|
+
* @param options - Resolver inputs and optional env variable names
|
|
654
|
+
* @returns Provider/model/context preset for adapter `createTestConfig()`
|
|
655
|
+
*/
|
|
656
|
+
declare function resolveConformanceTestPreset(options: ResolveConformanceTestPresetOptions): ResolvedConformanceTestPreset;
|
|
657
|
+
//#endregion
|
|
658
|
+
//#region adapters/core/src/utils/resolveDisabledNativeTools.d.ts
|
|
659
|
+
/** Result of an optional harness lookup — either unhandled or resolved. */
|
|
660
|
+
type OptionalHarnessResult = Promise<{
|
|
661
|
+
handled: false;
|
|
662
|
+
} | {
|
|
663
|
+
handled: true;
|
|
664
|
+
data: HarnessDefinition;
|
|
665
|
+
}>;
|
|
666
|
+
/**
|
|
667
|
+
* Minimal requester contract for harness lookups.
|
|
668
|
+
*
|
|
669
|
+
* Supports both ID-based lookup (`HarnessSubjects.get`) and adapter-scoped
|
|
670
|
+
* default lookup (`HarnessSubjects.getDefault`).
|
|
671
|
+
*/
|
|
672
|
+
interface HarnessRequester {
|
|
673
|
+
requestOptional(subject: typeof HarnessSubjects.get, payload: {
|
|
674
|
+
id: string;
|
|
675
|
+
}): OptionalHarnessResult;
|
|
676
|
+
requestOptional(subject: typeof HarnessSubjects.getDefault, payload: {
|
|
677
|
+
adapterName?: string;
|
|
678
|
+
clientId?: string;
|
|
679
|
+
}): OptionalHarnessResult;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Resolve SDK-native tool names disabled by the active harness for an adapter.
|
|
683
|
+
*
|
|
684
|
+
* When `harnessId` is provided, fetches that specific harness by ID.
|
|
685
|
+
* Otherwise falls back to the adapter's default harness via `adapterName` and
|
|
686
|
+
* optional `clientId` so that client-scoped harnesses are considered.
|
|
687
|
+
*
|
|
688
|
+
* Uses optional request semantics so callers can run without harness registration
|
|
689
|
+
* (for example, in lightweight test runtimes).
|
|
690
|
+
* @param requester - Bus-like requester supporting requestOptional for harness subjects
|
|
691
|
+
* @param adapterName - Adapter name used to look up the default harness (fallback path)
|
|
692
|
+
* @param harnessId - Optional explicit harness ID; takes precedence over the default lookup
|
|
693
|
+
* @param clientId - Optional client identifier for client-scoped default harness lookup
|
|
694
|
+
* @returns Disabled native tool names, or an empty array when unavailable
|
|
695
|
+
*/
|
|
696
|
+
declare function resolveDisabledNativeTools(requester: HarnessRequester, adapterName: string, harnessId?: string, clientId?: string): Promise<readonly string[]>;
|
|
697
|
+
//#endregion
|
|
698
|
+
//#region adapters/core/src/utils/formatMessageHistoryAsTranscript.d.ts
|
|
699
|
+
/**
|
|
700
|
+
* Formats message history as a human-readable conversation transcript.
|
|
701
|
+
*
|
|
702
|
+
* Converts structured Message[] into plain text format:
|
|
703
|
+
* ```
|
|
704
|
+
* User: Hello, my name is Alice
|
|
705
|
+
* Assistant: Nice to meet you, Alice!
|
|
706
|
+
* ```
|
|
707
|
+
*
|
|
708
|
+
* This avoids exposing JSON structure to the LLM, which can trigger
|
|
709
|
+
* meta-analysis of the format rather than natural conversation continuation.
|
|
710
|
+
* @param history - Array of Message objects with role and blocks
|
|
711
|
+
* @returns Human-readable transcript string
|
|
712
|
+
*/
|
|
713
|
+
declare function formatMessageHistoryAsTranscript(history: Message[]): string;
|
|
714
|
+
//#endregion
|
|
715
|
+
//#region adapters/core/src/utils/serialize-block-to-text.d.ts
|
|
716
|
+
/**
|
|
717
|
+
* Serialize a {@link MessageBlock} to plain text for contexts where native
|
|
718
|
+
* block rendering is unavailable — for example, media blocks in text positions,
|
|
719
|
+
* or history serialization for providers that only accept string content.
|
|
720
|
+
*
|
|
721
|
+
* - `text` and `reasoning` blocks return their content verbatim.
|
|
722
|
+
* - `tool_call` blocks emit a bracketed label followed by JSON-serialized args.
|
|
723
|
+
* - `tool_output` blocks emit a bracketed label with the call ID and output body.
|
|
724
|
+
* - `image` and `document` blocks emit a static placeholder.
|
|
725
|
+
* - `attachment` blocks emit the display name when present, otherwise the file name.
|
|
726
|
+
* @param block - The message block to serialize.
|
|
727
|
+
* @returns Plain-text representation of the block.
|
|
728
|
+
*/
|
|
729
|
+
declare function serializeBlockToText(block: MessageBlock$1): string;
|
|
730
|
+
//#endregion
|
|
731
|
+
//#region adapters/core/src/connector/base-connector-session.d.ts
|
|
732
|
+
/**
|
|
733
|
+
* Configuration for a connector session.
|
|
734
|
+
* @typeParam TBus - Scoped bus type for adapter namespace
|
|
735
|
+
*/
|
|
736
|
+
interface ConnectorSessionConfig<TBus extends ScopedBus<string> = ScopedBus<string>> {
|
|
737
|
+
bus: TBus;
|
|
738
|
+
adapterId: string;
|
|
739
|
+
adapterName: string;
|
|
740
|
+
cwd: string;
|
|
741
|
+
model: string;
|
|
742
|
+
env: Record<string, string>;
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Interface for turn-like objects that support pause/abort operations.
|
|
746
|
+
* Allows base session class to work with different turn implementations.
|
|
747
|
+
*/
|
|
748
|
+
interface PausableTurn {
|
|
749
|
+
pause(): Promise<unknown>;
|
|
750
|
+
}
|
|
751
|
+
/**
|
|
752
|
+
* Base abstract class for connector session implementations.
|
|
753
|
+
*
|
|
754
|
+
* Sessions manage SDK query lifecycle across multiple turns:
|
|
755
|
+
* - SDK connection management
|
|
756
|
+
* - Turn creation and coordination
|
|
757
|
+
* - Session ID management
|
|
758
|
+
*
|
|
759
|
+
* Each adapter implements its own session subclass.
|
|
760
|
+
* @typeParam TConfig - Configuration type extending ConnectorSessionConfig
|
|
761
|
+
*/
|
|
762
|
+
declare abstract class BaseConnectorSession<TConfig extends ConnectorSessionConfig = ConnectorSessionConfig> {
|
|
763
|
+
protected readonly config: TConfig;
|
|
764
|
+
protected readonly bus: TConfig['bus'];
|
|
765
|
+
protected sessionId?: string;
|
|
766
|
+
protected currentTurn?: PausableTurn;
|
|
767
|
+
constructor(config: TConfig);
|
|
768
|
+
/**
|
|
769
|
+
* Abort the session and cleanup resources.
|
|
770
|
+
* Pauses the current turn if one is active.
|
|
771
|
+
*/
|
|
772
|
+
abort(): Promise<void>;
|
|
773
|
+
/**
|
|
774
|
+
* Send a message to the provider.
|
|
775
|
+
* Not used - subclasses should implement processQueue instead.
|
|
776
|
+
* @param _message - Unused message parameter
|
|
777
|
+
* @param _options - Unused options parameter
|
|
778
|
+
*/
|
|
779
|
+
sendMessage(_message: unknown, _options?: unknown): Promise<void>;
|
|
780
|
+
/**
|
|
781
|
+
* Get the adapter session ID.
|
|
782
|
+
* @returns The session ID from the provider
|
|
783
|
+
*/
|
|
784
|
+
getAdapterSessionId(): Promise<string>;
|
|
785
|
+
}
|
|
786
|
+
//#endregion
|
|
787
|
+
//#region adapters/core/src/connector/base-connector-turn.d.ts
|
|
788
|
+
/**
|
|
789
|
+
* Result of pausing a turn.
|
|
790
|
+
* @typeParam TState - Turn state type
|
|
791
|
+
*/
|
|
792
|
+
interface PauseResult<TState = string> {
|
|
793
|
+
/** The state the turn was in before pausing */
|
|
794
|
+
stateBeforePause: TState;
|
|
795
|
+
/** Whether the turn had already ended when pause was requested */
|
|
796
|
+
turnEnded: boolean;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* Base abstract class for connector turn implementations.
|
|
800
|
+
*
|
|
801
|
+
* Turns manage the state machine for a single user message:
|
|
802
|
+
* - State transitions (idle to turn_started to step_started to ...)
|
|
803
|
+
* - Pause/resume mechanics
|
|
804
|
+
* - Safe boundary detection for immediate messages
|
|
805
|
+
* - Message handle delegation (acknowledgment, completion)
|
|
806
|
+
*
|
|
807
|
+
* Each adapter implements its own turn subclass with adapter-specific
|
|
808
|
+
* state handling and SDK integration.
|
|
809
|
+
* @typeParam TState - Turn state enum type (string union)
|
|
810
|
+
*/
|
|
811
|
+
declare abstract class BaseConnectorTurn<TState extends string = string> {
|
|
812
|
+
protected state: TState;
|
|
813
|
+
protected readonly bus: ScopedBus<string>;
|
|
814
|
+
protected readonly adapterId: string;
|
|
815
|
+
protected readonly adapterName: string;
|
|
816
|
+
protected stateChangedCallback?: (oldState: TState, newState: TState) => Promise<void> | void;
|
|
817
|
+
/**
|
|
818
|
+
* Active message handle for this turn.
|
|
819
|
+
* Subclasses must provide this handle for message lifecycle management.
|
|
820
|
+
*/
|
|
821
|
+
protected abstract activeMessageHandle: MessageHandle;
|
|
822
|
+
constructor(bus: ScopedBus<string>, adapterId: string, adapterName: string, initialState: TState);
|
|
823
|
+
/**
|
|
824
|
+
* Pause the turn at next safe boundary.
|
|
825
|
+
* @returns Pause result indicating whether turn already ended
|
|
826
|
+
*/
|
|
827
|
+
abstract pause(): Promise<PauseResult<TState>>;
|
|
828
|
+
/**
|
|
829
|
+
* Resume the paused turn with optional additional message.
|
|
830
|
+
* @param message - Optional message to inject when resuming
|
|
831
|
+
*/
|
|
832
|
+
abstract resume(message?: unknown): Promise<void>;
|
|
833
|
+
/**
|
|
834
|
+
* Check if turn is currently paused.
|
|
835
|
+
*/
|
|
836
|
+
abstract isPaused(): boolean;
|
|
837
|
+
/**
|
|
838
|
+
* Register callback for state changes.
|
|
839
|
+
* @param cb - Callback to invoke on state transitions
|
|
840
|
+
*/
|
|
841
|
+
onStateChanged(cb: (oldState: TState, newState: TState) => Promise<void> | void): void;
|
|
842
|
+
/**
|
|
843
|
+
* Transition to new state and notify listeners.
|
|
844
|
+
* Template method for shared state transition pattern.
|
|
845
|
+
*
|
|
846
|
+
* NOTE: Subclasses should use their typed namespace subjects for emission.
|
|
847
|
+
* This is a template - concrete implementation in adapter-specific Turn classes.
|
|
848
|
+
* @param newState - New state to transition to
|
|
849
|
+
*/
|
|
850
|
+
protected transitionTo(newState: TState): Promise<void>;
|
|
851
|
+
/**
|
|
852
|
+
* Emit state change event - implemented by subclass with typed subjects.
|
|
853
|
+
* @param oldState - Previous state
|
|
854
|
+
* @param newState - New state
|
|
855
|
+
*/
|
|
856
|
+
protected abstract emitStateChange(oldState: TState, newState: TState): Promise<void>;
|
|
857
|
+
/**
|
|
858
|
+
* Get current turn state.
|
|
859
|
+
* @returns Current turn state
|
|
860
|
+
*/
|
|
861
|
+
getState(): TState;
|
|
862
|
+
/**
|
|
863
|
+
* Get the message handle for this turn.
|
|
864
|
+
* @returns The message handle for this turn
|
|
865
|
+
*/
|
|
866
|
+
getMessageHandle(): MessageHandle;
|
|
867
|
+
/**
|
|
868
|
+
* Mark message handle as acknowledged.
|
|
869
|
+
*/
|
|
870
|
+
markAcknowledged(): void;
|
|
871
|
+
/**
|
|
872
|
+
* Mark message handle as completed.
|
|
873
|
+
* @param result - The completion result with outcome and optional result/error
|
|
874
|
+
*/
|
|
875
|
+
markCompleted(result: {
|
|
876
|
+
outcome: string;
|
|
877
|
+
result?: unknown;
|
|
878
|
+
error?: unknown;
|
|
879
|
+
}): void;
|
|
880
|
+
}
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region adapters/core/src/connector/procedural-connector-turn.d.ts
|
|
883
|
+
/**
|
|
884
|
+
* Typed subject references for turn lifecycle events.
|
|
885
|
+
*
|
|
886
|
+
* Each adapter provides its namespace-specific subjects when constructing
|
|
887
|
+
* a ProceduralConnectorTurn. The subjects must all accept the same
|
|
888
|
+
* TurnStateChangedPayload shape.
|
|
889
|
+
* @typeParam TSubject - The subject definition type for the adapter's bus
|
|
890
|
+
*/
|
|
891
|
+
interface TurnSubjects<TSubject = ScopedSubjectDefinition> {
|
|
892
|
+
state_changed: TSubject;
|
|
893
|
+
turn_started: TSubject;
|
|
894
|
+
step_started: TSubject;
|
|
895
|
+
step_finished: TSubject;
|
|
896
|
+
turn_finished: TSubject;
|
|
897
|
+
}
|
|
898
|
+
/**
|
|
899
|
+
* Standard turn state type for procedural adapters.
|
|
900
|
+
*
|
|
901
|
+
* Procedural adapters (Gemini, OpenAI, Copilot) use abort+restart
|
|
902
|
+
* rather than true pause/resume. Their state machine is:
|
|
903
|
+
* idle to turn_started to step_started to step_finished to turn_finished
|
|
904
|
+
*/
|
|
905
|
+
type ProceduralTurnState = 'idle' | 'turn_started' | 'step_started' | 'step_finished' | 'turn_finished';
|
|
906
|
+
/**
|
|
907
|
+
* Configuration for ProceduralConnectorTurn.
|
|
908
|
+
* @typeParam TBus - Scoped bus type for the adapter
|
|
909
|
+
* @typeParam TSubject - Subject definition type
|
|
910
|
+
*/
|
|
911
|
+
interface ProceduralTurnConfig<TBus extends ScopedBus<string>, TSubject> {
|
|
912
|
+
bus: TBus;
|
|
913
|
+
adapterId: string;
|
|
914
|
+
adapterName: string;
|
|
915
|
+
agentId: string;
|
|
916
|
+
messageHandle: MessageHandle;
|
|
917
|
+
turnSubjects: TurnSubjects<TSubject>;
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Base turn implementation for procedural adapters (Gemini, OpenAI, Copilot).
|
|
921
|
+
*
|
|
922
|
+
* These adapters share an abort+restart pattern rather than true pause/resume.
|
|
923
|
+
* This class extracts the common state machine, lifecycle methods, and
|
|
924
|
+
* message handle delegation that was duplicated across all three.
|
|
925
|
+
*
|
|
926
|
+
* Subclasses only need to add adapter-specific behavior:
|
|
927
|
+
* - Gemini: AbortController for SDK cancellation
|
|
928
|
+
* - OpenAI: AbortController for SDK cancellation
|
|
929
|
+
* - Copilot: SDK event handling (handleSdkEvent)
|
|
930
|
+
* @typeParam TState - Turn state type (defaults to ProceduralTurnState)
|
|
931
|
+
* @typeParam TBus - Scoped bus type for the adapter
|
|
932
|
+
* @typeParam TSubject - Subject definition type for emit calls
|
|
933
|
+
*/
|
|
934
|
+
declare class ProceduralConnectorTurn<TState extends string = ProceduralTurnState, TBus extends ScopedBus<string> = ScopedBus<string>, TSubject extends ScopedSubjectDefinition = ScopedSubjectDefinition> extends BaseConnectorTurn<TState> {
|
|
935
|
+
protected activeMessageHandle: MessageHandle;
|
|
936
|
+
protected readonly connectorBus: TBus;
|
|
937
|
+
protected readonly agentId: string;
|
|
938
|
+
protected readonly turnSubjects: TurnSubjects<TSubject>;
|
|
939
|
+
protected aborted: boolean;
|
|
940
|
+
constructor(config: ProceduralTurnConfig<TBus, TSubject>, initialState: TState);
|
|
941
|
+
/**
|
|
942
|
+
* Emit state change using adapter-provided turn subjects.
|
|
943
|
+
* @param oldState - Previous state before transition
|
|
944
|
+
* @param newState - New state after transition
|
|
945
|
+
*/
|
|
946
|
+
protected emitStateChange(oldState: TState, newState: TState): Promise<void>;
|
|
947
|
+
/**
|
|
948
|
+
* Start the turn.
|
|
949
|
+
*/
|
|
950
|
+
start(): Promise<void>;
|
|
951
|
+
/**
|
|
952
|
+
* Transition to step_started (called when first content arrives).
|
|
953
|
+
* Allows turn_started to step_started AND step_finished to step_started
|
|
954
|
+
* (for tool recursion).
|
|
955
|
+
*/
|
|
956
|
+
markStepStarted(): Promise<void>;
|
|
957
|
+
/**
|
|
958
|
+
* Transition to step_finished (called after content block completes).
|
|
959
|
+
*/
|
|
960
|
+
markStepFinished(): Promise<void>;
|
|
961
|
+
/**
|
|
962
|
+
* Mark turn as finished.
|
|
963
|
+
*/
|
|
964
|
+
markTurnFinished(): Promise<void>;
|
|
965
|
+
/**
|
|
966
|
+
* Pause (abort) at next opportunity.
|
|
967
|
+
* Procedural adapters don't support true pause - caller creates a new turn
|
|
968
|
+
* with merged content instead.
|
|
969
|
+
* @returns Pause result indicating turn state
|
|
970
|
+
*/
|
|
971
|
+
pause(): Promise<PauseResult<TState>>;
|
|
972
|
+
/**
|
|
973
|
+
* Resume is not supported for procedural adapters - caller creates new turn.
|
|
974
|
+
* @param _message - Unused
|
|
975
|
+
* @throws Error always
|
|
976
|
+
*/
|
|
977
|
+
resume(_message?: unknown): Promise<void>;
|
|
978
|
+
/**
|
|
979
|
+
* Check if turn was aborted.
|
|
980
|
+
* @returns True if turn was aborted
|
|
981
|
+
*/
|
|
982
|
+
isPaused(): boolean;
|
|
983
|
+
/**
|
|
984
|
+
* Check if turn is completed.
|
|
985
|
+
* @returns True if turn has finished
|
|
986
|
+
*/
|
|
987
|
+
isCompleted(): boolean;
|
|
988
|
+
/**
|
|
989
|
+
* Check if turn can accept immediate message.
|
|
990
|
+
* True if turn is active (not finished, not aborted).
|
|
991
|
+
* @returns True if turn can accept an immediate message
|
|
992
|
+
*/
|
|
993
|
+
canAcceptImmediate(): boolean;
|
|
994
|
+
}
|
|
995
|
+
//#endregion
|
|
996
|
+
//#region adapters/core/src/session/user-message-queue.d.ts
|
|
997
|
+
/**
|
|
998
|
+
* Simple FIFO queue for user messages with delivery mode support.
|
|
999
|
+
*
|
|
1000
|
+
* This queue is owned by adapter Connectors and passed to Sessions for processing.
|
|
1001
|
+
*
|
|
1002
|
+
* Delivery modes:
|
|
1003
|
+
* - 'enqueue': Add to end of queue (default); internal retries are prioritized
|
|
1004
|
+
* ahead of already queued user turns.
|
|
1005
|
+
* - 'replace': Supersede all unacknowledged messages, add to queue
|
|
1006
|
+
* - 'immediate': Handled by Session (abort/restart), not queue
|
|
1007
|
+
*
|
|
1008
|
+
* Design:
|
|
1009
|
+
* - Connector enqueues messages as they arrive
|
|
1010
|
+
* - Session dequeues messages when ready to process
|
|
1011
|
+
* - Peek allows Session to inspect next message without removing
|
|
1012
|
+
*/
|
|
1013
|
+
declare class UserMessageQueue {
|
|
1014
|
+
private readonly queue;
|
|
1015
|
+
/**
|
|
1016
|
+
* Add message to queue based on delivery mode.
|
|
1017
|
+
* @param handle - Message handle to enqueue
|
|
1018
|
+
*/
|
|
1019
|
+
enqueue(handle: MessageHandle): void;
|
|
1020
|
+
/**
|
|
1021
|
+
* Enqueue an internal retry before ordinary queued user turns while preserving
|
|
1022
|
+
* immediate-mode ordering and FIFO ordering among retries.
|
|
1023
|
+
* @param handle - Internal retry handle to enqueue
|
|
1024
|
+
*/
|
|
1025
|
+
private enqueueInternalRetry;
|
|
1026
|
+
/**
|
|
1027
|
+
* Remove all superseded messages from queue.
|
|
1028
|
+
*/
|
|
1029
|
+
private removeSuperseded;
|
|
1030
|
+
/**
|
|
1031
|
+
* Remove and return first message from queue.
|
|
1032
|
+
* @returns First message or undefined if queue empty
|
|
1033
|
+
*/
|
|
1034
|
+
dequeue(): MessageHandle | undefined;
|
|
1035
|
+
/**
|
|
1036
|
+
* Look at first message without removing.
|
|
1037
|
+
* @returns First message or undefined if queue empty
|
|
1038
|
+
*/
|
|
1039
|
+
peek(): MessageHandle | undefined;
|
|
1040
|
+
/**
|
|
1041
|
+
* Check if queue is empty.
|
|
1042
|
+
* @returns True if queue has no messages
|
|
1043
|
+
*/
|
|
1044
|
+
isEmpty(): boolean;
|
|
1045
|
+
/**
|
|
1046
|
+
* Get current queue size.
|
|
1047
|
+
* @returns Number of messages in queue
|
|
1048
|
+
*/
|
|
1049
|
+
size(): number;
|
|
1050
|
+
/**
|
|
1051
|
+
* Clear all messages from queue.
|
|
1052
|
+
*/
|
|
1053
|
+
clear(): void;
|
|
1054
|
+
/**
|
|
1055
|
+
* Find the first immediate message in the queue.
|
|
1056
|
+
* @returns First immediate message or undefined
|
|
1057
|
+
*/
|
|
1058
|
+
findImmediate(): MessageHandle | undefined;
|
|
1059
|
+
/**
|
|
1060
|
+
* Remove a specific immediate message from the queue.
|
|
1061
|
+
* @param handle - Handle to remove
|
|
1062
|
+
*/
|
|
1063
|
+
removeImmediate(handle: MessageHandle): void;
|
|
1064
|
+
/**
|
|
1065
|
+
* Remove and return all enqueued (non-immediate) messages.
|
|
1066
|
+
* Used when immediate arrives to merge their content.
|
|
1067
|
+
* @returns Array of enqueued message handles in FIFO order
|
|
1068
|
+
*/
|
|
1069
|
+
drainEnqueued(): MessageHandle[];
|
|
1070
|
+
}
|
|
1071
|
+
//#endregion
|
|
1072
|
+
//#region adapters/core/src/session/process-queue.d.ts
|
|
1073
|
+
/**
|
|
1074
|
+
* Minimal turn interface required by processQueue orchestration.
|
|
1075
|
+
*
|
|
1076
|
+
* Any turn implementation (Claude, Gemini, OpenAI, Copilot) that exposes
|
|
1077
|
+
* these methods can participate in the shared processQueue flow.
|
|
1078
|
+
*/
|
|
1079
|
+
interface QueueableTurn {
|
|
1080
|
+
canAcceptImmediate(): boolean;
|
|
1081
|
+
isCompleted(): boolean;
|
|
1082
|
+
getMessageHandle(): MessageHandle;
|
|
1083
|
+
pause(): Promise<PauseResult>;
|
|
1084
|
+
}
|
|
1085
|
+
/**
|
|
1086
|
+
* Result of processing an immediate message merge.
|
|
1087
|
+
*
|
|
1088
|
+
* Returned by the `extractMergeContent` callback so that adapters
|
|
1089
|
+
* can collect adapter-specific content (e.g., Gemini collects non-text parts).
|
|
1090
|
+
* The `mergedContent` array is always present; `extra` is an opaque bag
|
|
1091
|
+
* for adapter-specific data that flows through to `startNewTurn`.
|
|
1092
|
+
*/
|
|
1093
|
+
interface MergeResult {
|
|
1094
|
+
/** Text content collected from superseded/merged messages */
|
|
1095
|
+
mergedContent: string[];
|
|
1096
|
+
/** Adapter-specific merge data (e.g., non-text parts for Gemini) */
|
|
1097
|
+
extra?: unknown;
|
|
1098
|
+
}
|
|
1099
|
+
/**
|
|
1100
|
+
* Callbacks for adapter-specific behavior during queue processing.
|
|
1101
|
+
* @typeParam TExtra - Type of adapter-specific extra merge data
|
|
1102
|
+
*/
|
|
1103
|
+
interface ProcessQueueCallbacks<TExtra = unknown> {
|
|
1104
|
+
/**
|
|
1105
|
+
* Get the current turn, if any.
|
|
1106
|
+
* @returns The current turn or undefined
|
|
1107
|
+
*/
|
|
1108
|
+
getCurrentTurn: () => QueueableTurn | undefined;
|
|
1109
|
+
/**
|
|
1110
|
+
* Extract text content from a message handle for merge.
|
|
1111
|
+
* Default: `handle.message.message as string`
|
|
1112
|
+
* @param handle - The message handle to extract content from
|
|
1113
|
+
* @returns The text content
|
|
1114
|
+
*/
|
|
1115
|
+
extractContent?: (handle: MessageHandle) => string;
|
|
1116
|
+
/**
|
|
1117
|
+
* Called after merge content is collected from superseded/enqueued messages.
|
|
1118
|
+
* Allows adapters to collect additional content (e.g., Gemini's non-text parts).
|
|
1119
|
+
*
|
|
1120
|
+
* If not provided, only text content is collected using `extractContent`.
|
|
1121
|
+
* @param currentHandle - The in-flight message handle being superseded (or undefined)
|
|
1122
|
+
* @param enqueuedHandles - The enqueued handles being merged
|
|
1123
|
+
* @returns Extra merge data to pass through to startNewTurn
|
|
1124
|
+
*/
|
|
1125
|
+
collectMergeExtra?: (currentHandle: MessageHandle | undefined, enqueuedHandles: MessageHandle[]) => TExtra;
|
|
1126
|
+
/**
|
|
1127
|
+
* Hook called after merge is collected but before starting the new turn.
|
|
1128
|
+
* Used by Claude to create a fresh query instance.
|
|
1129
|
+
*/
|
|
1130
|
+
onBeforeImmediateTurn?: () => Promise<void>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Start a new turn with the given message and optional merge data.
|
|
1133
|
+
* @param handle - The message handle to process
|
|
1134
|
+
* @param mergedContent - Text content from superseded/merged messages
|
|
1135
|
+
* @param extra - Adapter-specific extra merge data
|
|
1136
|
+
*/
|
|
1137
|
+
startNewTurn: (handle: MessageHandle, mergedContent?: string[], extra?: TExtra) => Promise<void>;
|
|
1138
|
+
}
|
|
1139
|
+
/**
|
|
1140
|
+
* Shared processQueue orchestration for all session implementations.
|
|
1141
|
+
*
|
|
1142
|
+
* Handles the complete immediate-mode flow:
|
|
1143
|
+
* 1. Detect immediate message while a turn is active
|
|
1144
|
+
* 2. Pause the active turn
|
|
1145
|
+
* 3. Supersede the in-flight message and drain enqueued messages
|
|
1146
|
+
* 4. Collect merged content from all superseded/merged messages
|
|
1147
|
+
* 5. Start a new turn with the immediate message and merged context
|
|
1148
|
+
*
|
|
1149
|
+
* Also handles the normal queue flow:
|
|
1150
|
+
* - Late immediate rejection (immediate arrives after turn finishes)
|
|
1151
|
+
* - Normal enqueue/replace message processing
|
|
1152
|
+
*
|
|
1153
|
+
* Returns `true` when a new turn was started, `false` otherwise.
|
|
1154
|
+
* Callers can use this to decide whether to transition to idle when
|
|
1155
|
+
* the queue drains without starting a new turn (e.g., all-rejection case).
|
|
1156
|
+
* @param queue - The user message queue to process
|
|
1157
|
+
* @param callbacks - Adapter-specific callbacks
|
|
1158
|
+
* @returns True if a new turn was started, false otherwise
|
|
1159
|
+
* @typeParam TExtra - Type of adapter-specific extra merge data
|
|
1160
|
+
*/
|
|
1161
|
+
declare function processQueueMessages<TExtra = unknown>(queue: UserMessageQueue, callbacks: ProcessQueueCallbacks<TExtra>): Promise<boolean>;
|
|
1162
|
+
//#endregion
|
|
1163
|
+
//#region adapters/core/src/connector/procedural-agent-connector.d.ts
|
|
1164
|
+
/**
|
|
1165
|
+
* Minimal session interface required by ProceduralAgentConnector.
|
|
1166
|
+
*
|
|
1167
|
+
* Any session implementation (OpenAI, Copilot, Gemini) that exposes
|
|
1168
|
+
* these methods can be used with ProceduralAgentConnector's default
|
|
1169
|
+
* wireSessionEvents / processUserMessages / acceptsImmediate.
|
|
1170
|
+
*/
|
|
1171
|
+
interface ProceduralConnectorSession {
|
|
1172
|
+
/** Process messages from the queue. */
|
|
1173
|
+
processQueue(queue: UserMessageQueue): Promise<void>;
|
|
1174
|
+
/** Get the current turn for state inspection. */
|
|
1175
|
+
getCurrentTurn(): QueueableTurn | undefined;
|
|
1176
|
+
}
|
|
1177
|
+
/**
|
|
1178
|
+
* Turn subject references for wireSessionEvents.
|
|
1179
|
+
*
|
|
1180
|
+
* Each adapter provides its namespace-specific subjects. The subjects
|
|
1181
|
+
* must accept TurnStateChangedPayload (or compatible shape).
|
|
1182
|
+
* @typeParam TNamespace - The bus namespace string for subject typing
|
|
1183
|
+
*/
|
|
1184
|
+
interface WireSessionSubjects<TNamespace extends string = string> {
|
|
1185
|
+
turn_started: ScopedSubjectDefinition<TNamespace>;
|
|
1186
|
+
step_started: ScopedSubjectDefinition<TNamespace>;
|
|
1187
|
+
step_finished: ScopedSubjectDefinition<TNamespace>;
|
|
1188
|
+
turn_finished: ScopedSubjectDefinition<TNamespace>;
|
|
1189
|
+
}
|
|
1190
|
+
/**
|
|
1191
|
+
* Configuration for ProceduralAgentConnector's wireSessionEvents behavior.
|
|
1192
|
+
*
|
|
1193
|
+
* The `onTurnStarted` and `onTurnFinished` hooks allow adapters to inject
|
|
1194
|
+
* logic at turn boundaries. By default both are no-ops.
|
|
1195
|
+
*/
|
|
1196
|
+
interface WireSessionConfig {
|
|
1197
|
+
/**
|
|
1198
|
+
* Called when a new turn starts (turn_started bus event).
|
|
1199
|
+
*
|
|
1200
|
+
* Executes before the default `updateProcessingState('turn_started')` so
|
|
1201
|
+
* the connector state machine is always updated regardless of this hook.
|
|
1202
|
+
*
|
|
1203
|
+
* Supports async so that turn-start operations with I/O — such as a pending
|
|
1204
|
+
* MCP tool refresh via the bus — can complete before the API call is made.
|
|
1205
|
+
* In-memory operations (recordInjection, consumeTurnNumber) are not affected
|
|
1206
|
+
* by the async signature.
|
|
1207
|
+
*/
|
|
1208
|
+
onTurnStarted?: () => Promise<void> | void;
|
|
1209
|
+
/**
|
|
1210
|
+
* Custom handler for turn_finished events.
|
|
1211
|
+
*
|
|
1212
|
+
* When provided, replaces the default turn_finished behavior entirely.
|
|
1213
|
+
* The handler receives a callback to process the queue, which it should
|
|
1214
|
+
* call when the message is considered complete and the queue should drain.
|
|
1215
|
+
* @param drainQueue - Callback that processes the queue or goes idle
|
|
1216
|
+
*/
|
|
1217
|
+
onTurnFinished?: (drainQueue: () => Promise<void>) => Promise<void>;
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Abstract base class for procedural (non-event-driven) agent connectors.
|
|
1221
|
+
*
|
|
1222
|
+
* Procedural adapters (OpenAI, Copilot, Gemini) share common patterns:
|
|
1223
|
+
* - wireSessionEvents: subscribe to turn lifecycle events and update processing state
|
|
1224
|
+
* - processUserMessages: initialize session, enqueue, transition to active, process queue
|
|
1225
|
+
* - complete: poll processing state until idle/paused
|
|
1226
|
+
* - start: delegate to sendMessage and return AgentStartResult
|
|
1227
|
+
* - acceptsImmediate: delegate to session's current turn
|
|
1228
|
+
*
|
|
1229
|
+
* Subclasses must implement:
|
|
1230
|
+
* - `getSession()` / `ensureSession()` for session access and lazy initialization
|
|
1231
|
+
* - `getSessionQueue()` for the adapter's UserMessageQueue instance
|
|
1232
|
+
* - `getTurnSubjects()` for namespace-specific turn subjects
|
|
1233
|
+
* - `sendMessage()`, `abort()`, `close()`, `interrupt()`, `getAdapterSessionId()`
|
|
1234
|
+
*
|
|
1235
|
+
* Subclasses may override:
|
|
1236
|
+
* - `getWireSessionConfig()` for custom turn_finished behavior (e.g., Copilot multi-turn)
|
|
1237
|
+
* @typeParam TBus - Scoped bus type for adapter namespace
|
|
1238
|
+
* @typeParam TConfig - Configuration type extending BaseAgentConnectorConfig
|
|
1239
|
+
*/
|
|
1240
|
+
declare abstract class ProceduralAgentConnector<TBus extends ScopedBus<string> = ScopedBus<string>, TConfig extends BaseAgentConnectorConfig<TBus> = BaseAgentConnectorConfig<TBus>> extends AIAgentConnector<TBus, TConfig> {
|
|
1241
|
+
/** Whether turn event wiring has been setup. */
|
|
1242
|
+
private turnEventsWired;
|
|
1243
|
+
/**
|
|
1244
|
+
* Get the adapter's session instance (may be undefined if not yet initialized).
|
|
1245
|
+
* @returns The session or undefined
|
|
1246
|
+
*/
|
|
1247
|
+
protected abstract getSession(): ProceduralConnectorSession | undefined;
|
|
1248
|
+
/**
|
|
1249
|
+
* Initialize and return the adapter's session.
|
|
1250
|
+
* Must be idempotent (no-op if already initialized).
|
|
1251
|
+
* @returns The initialized session
|
|
1252
|
+
*/
|
|
1253
|
+
protected abstract ensureSession(): Promise<ProceduralConnectorSession>;
|
|
1254
|
+
/**
|
|
1255
|
+
* Get the adapter's UserMessageQueue instance.
|
|
1256
|
+
* @returns The message queue
|
|
1257
|
+
*/
|
|
1258
|
+
protected abstract getSessionQueue(): UserMessageQueue;
|
|
1259
|
+
/**
|
|
1260
|
+
* Get the adapter's namespace-specific turn subjects for wireSessionEvents.
|
|
1261
|
+
* @returns Turn subject definitions
|
|
1262
|
+
*/
|
|
1263
|
+
protected abstract getTurnSubjects(): WireSessionSubjects<TBus['namespace']>;
|
|
1264
|
+
/**
|
|
1265
|
+
* Get optional wire session configuration for custom turn_finished behavior.
|
|
1266
|
+
* Override in subclasses that need non-standard turn_finished handling
|
|
1267
|
+
* (e.g., Copilot multi-turn message completion).
|
|
1268
|
+
* @returns Wire session configuration, or undefined for default behavior
|
|
1269
|
+
*/
|
|
1270
|
+
protected getWireSessionConfig(): WireSessionConfig | undefined;
|
|
1271
|
+
/**
|
|
1272
|
+
* Wire Session turn events to Connector state updates.
|
|
1273
|
+
*
|
|
1274
|
+
* Session emits typed events, Connector subscribes and updates processing state.
|
|
1275
|
+
* This maintains separation of concerns - Session does not know about Connector state.
|
|
1276
|
+
*
|
|
1277
|
+
* Default turn_finished behavior: transition through processing_finished to idle,
|
|
1278
|
+
* or drain the queue if messages are pending. Override via `getWireSessionConfig()`.
|
|
1279
|
+
*/
|
|
1280
|
+
protected wireSessionEvents(): void;
|
|
1281
|
+
/**
|
|
1282
|
+
* Process queued user messages by delegating to Session.
|
|
1283
|
+
*
|
|
1284
|
+
* Shared flow:
|
|
1285
|
+
* 1. Initialize session if not yet created
|
|
1286
|
+
* 2. Enqueue the message
|
|
1287
|
+
* 3. Set adapterSessionId on handle
|
|
1288
|
+
* 4. Transition to active if currently idle/paused
|
|
1289
|
+
* 5. Process queue via session
|
|
1290
|
+
* @param messageHandles - Array of message handles to process
|
|
1291
|
+
* @returns Set of message handles that were processed
|
|
1292
|
+
*/
|
|
1293
|
+
protected processUserMessages(messageHandles: MessageHandle[]): Promise<Set<MessageHandle>>;
|
|
1294
|
+
/**
|
|
1295
|
+
* Initialize the connector's SDK session without sending a message.
|
|
1296
|
+
* Must set adapterSessionId before returning.
|
|
1297
|
+
* Called by createAgent for idle agent setup.
|
|
1298
|
+
* Implementations MUST be idempotent (no-op if already initialized).
|
|
1299
|
+
* @param options - Optional start options (e.g., systemPrompt)
|
|
1300
|
+
*/
|
|
1301
|
+
initialize(options?: ConnectorStartOptions): Promise<void>;
|
|
1302
|
+
/**
|
|
1303
|
+
* Start session with initial message.
|
|
1304
|
+
* @param message - The initial message to send
|
|
1305
|
+
* @param options - Optional send message options
|
|
1306
|
+
* @returns The agent start result with session ID and message handle
|
|
1307
|
+
*/
|
|
1308
|
+
start(message: NormalizedMessageInput, options?: ConnectorSendMessageOptions): Promise<AgentStartResult>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Complete the agent session by waiting for all messages to finish.
|
|
1311
|
+
* @returns Last message result or null if no messages processed
|
|
1312
|
+
*/
|
|
1313
|
+
complete(): Promise<MessageResult | null>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Returns true if current turn can accept immediate messages.
|
|
1316
|
+
* @returns True if turn can accept immediate, false otherwise
|
|
1317
|
+
*/
|
|
1318
|
+
protected acceptsImmediate(): boolean;
|
|
1319
|
+
}
|
|
1320
|
+
//#endregion
|
|
1321
|
+
//#region adapters/core/src/utils/tool-approval.d.ts
|
|
1322
|
+
/**
|
|
1323
|
+
* Context required to complete a global tool approval request.
|
|
1324
|
+
*
|
|
1325
|
+
* Provides adapter identity so the approval handler knows which
|
|
1326
|
+
* adapter/agent/session is requesting permission.
|
|
1327
|
+
*/
|
|
1328
|
+
interface ToolApprovalContext {
|
|
1329
|
+
/** Adapter instance ID */
|
|
1330
|
+
adapterId: string;
|
|
1331
|
+
/** Adapter type name (e.g., 'gemini-sdk', 'openai-node') */
|
|
1332
|
+
adapterName: string;
|
|
1333
|
+
/** Agent ID within the adapter */
|
|
1334
|
+
agentId: string;
|
|
1335
|
+
/** Adapter-side session ID */
|
|
1336
|
+
adapterSessionId: string;
|
|
1337
|
+
/** Makaio session ID — required for approval routing to the owning tab */
|
|
1338
|
+
sessionId: string;
|
|
1339
|
+
}
|
|
1340
|
+
/**
|
|
1341
|
+
* Options controlling how scoped approval payloads are promoted to the global schema.
|
|
1342
|
+
*/
|
|
1343
|
+
interface MergeScopedToolApprovalOptions {
|
|
1344
|
+
/**
|
|
1345
|
+
* Allow `payload.sessionId` to satisfy the global request when context lacks one.
|
|
1346
|
+
*
|
|
1347
|
+
* This should stay `false` for connector-scoped RPC handlers, which must rely on
|
|
1348
|
+
* agent context rather than connector-provided session identity. Enable only for
|
|
1349
|
+
* trusted call sites that already hold a canonical global approval payload.
|
|
1350
|
+
*/
|
|
1351
|
+
allowPayloadSessionFallback?: boolean;
|
|
1352
|
+
/**
|
|
1353
|
+
* Allow payload identity fields (`agentId`, `adapterId`, `adapterName`,
|
|
1354
|
+
* `adapterSessionId`) to satisfy the global request when context lacks them.
|
|
1355
|
+
*
|
|
1356
|
+
* This should stay `false` for connector-scoped RPC handlers, which must rely on
|
|
1357
|
+
* agent context rather than connector-provided identity. Enable only for trusted
|
|
1358
|
+
* call sites that already hold a canonical global approval payload (e.g., direct
|
|
1359
|
+
* bus invocations that supply the full payload without a live agent context).
|
|
1360
|
+
*/
|
|
1361
|
+
allowPayloadIdentityFallback?: boolean;
|
|
1362
|
+
}
|
|
1363
|
+
/**
|
|
1364
|
+
* Resolve the Makaio session ID required for global tool approval routing.
|
|
1365
|
+
*
|
|
1366
|
+
* Scoped connector payloads may omit `sessionId`; agent context should normally
|
|
1367
|
+
* provide it. Callers may optionally allow a payload fallback when their scoped
|
|
1368
|
+
* payload is already trusted to carry the same value.
|
|
1369
|
+
* @param contextSessionId - Session ID from agent context
|
|
1370
|
+
* @param payloadSessionId - Optional session ID from scoped payload
|
|
1371
|
+
* @param sourceLabel - Short source label used in error messages
|
|
1372
|
+
* @param allowPayloadSessionFallback - Whether trusted callers may reuse the payload session ID
|
|
1373
|
+
* @returns Resolved session ID
|
|
1374
|
+
* @throws Error if session ID is absent from all allowed sources
|
|
1375
|
+
*/
|
|
1376
|
+
declare function resolveRequiredSessionId(contextSessionId: string | undefined, payloadSessionId: string | undefined, sourceLabel: string, allowPayloadSessionFallback?: boolean): string;
|
|
1377
|
+
/**
|
|
1378
|
+
* Merge a scoped tool approval payload with agent context into the global request shape.
|
|
1379
|
+
*
|
|
1380
|
+
* All five identity fields (`sessionId`, `agentId`, `adapterId`, `adapterName`,
|
|
1381
|
+
* `adapterSessionId`) must come from trusted agent context by default. Payload
|
|
1382
|
+
* fallback for each group is enabled via the corresponding option flag.
|
|
1383
|
+
* @param payload - Scoped approval payload emitted by the connector
|
|
1384
|
+
* @param context - Agent context used to enrich the scoped payload
|
|
1385
|
+
* @param sourceLabel - Short source label used in error messages
|
|
1386
|
+
* @param options - Controls whether trusted call sites may reuse payload identity
|
|
1387
|
+
* @returns Global tool approval request with all required identity fields resolved
|
|
1388
|
+
*/
|
|
1389
|
+
declare function mergeScopedToolApproval(payload: ScopedToolApprovalRequest, context: Partial<ToolApprovalContext>, sourceLabel: string, options?: MergeScopedToolApprovalOptions): AgentToolApproveRequest;
|
|
1390
|
+
/**
|
|
1391
|
+
* Scoped tool approval schema for adapter connector buses.
|
|
1392
|
+
*
|
|
1393
|
+
* `sessionId` is optional here because the connector emits the approval request
|
|
1394
|
+
* before the agent layer has enriched it. The agent's `wireToolApprovalRpc`
|
|
1395
|
+
* (or equivalent) injects `sessionId` from its own context before forwarding
|
|
1396
|
+
* to the global `AgentSubjects.toolApprove` subject, where `sessionId` is required.
|
|
1397
|
+
*
|
|
1398
|
+
* Adapters with a genuinely different wire format (e.g., gemini-sdk's callId/name)
|
|
1399
|
+
* should define their own schema rather than extending this one.
|
|
1400
|
+
*/
|
|
1401
|
+
declare const ScopedToolApprovalSchema: {
|
|
1402
|
+
request: z.ZodObject<{
|
|
1403
|
+
agentId: z.ZodString;
|
|
1404
|
+
adapterId: z.ZodString;
|
|
1405
|
+
adapterName: z.ZodString;
|
|
1406
|
+
adapterSessionId: z.ZodString;
|
|
1407
|
+
messageId: z.ZodOptional<z.ZodString>;
|
|
1408
|
+
turnId: z.ZodOptional<z.ZodString>;
|
|
1409
|
+
clientId: z.ZodOptional<z.ZodString>;
|
|
1410
|
+
providerConfigId: z.ZodOptional<z.ZodString>;
|
|
1411
|
+
occurredAt: z.ZodOptional<z.ZodNumber>;
|
|
1412
|
+
toolName: z.ZodOptional<z.ZodString>;
|
|
1413
|
+
args: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1414
|
+
toolCallId: z.ZodString;
|
|
1415
|
+
reasoning: z.ZodOptional<z.ZodString>;
|
|
1416
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
1417
|
+
}, z.core.$strip>;
|
|
1418
|
+
response: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
1419
|
+
action: z.ZodLiteral<"allow">;
|
|
1420
|
+
updatedInput: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
1421
|
+
updatedPermissions: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
|
|
1422
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
1423
|
+
action: z.ZodLiteral<"deny">;
|
|
1424
|
+
message: z.ZodString;
|
|
1425
|
+
shouldAbort: z.ZodOptional<z.ZodBoolean>;
|
|
1426
|
+
}, z.core.$strip>], "action">;
|
|
1427
|
+
};
|
|
1428
|
+
/** Scoped tool approval request payload type — `sessionId` is optional at the connector layer. */
|
|
1429
|
+
type ScopedToolApprovalRequest = z.infer<typeof ScopedToolApprovalSchema.request>;
|
|
1430
|
+
/** Scoped tool approval response payload type — identical to the global response. */
|
|
1431
|
+
type ScopedToolApprovalResponse = z.infer<typeof ScopedToolApprovalSchema.response>;
|
|
1432
|
+
/**
|
|
1433
|
+
* Transform function signature: SDK payload → AgentToolApproveRequest.
|
|
1434
|
+
* @param payload - SDK-specific tool approval payload
|
|
1435
|
+
* @param context - Resolved tool approval context with adapter identity
|
|
1436
|
+
* @returns Global tool approval request for AgentSubjects.toolApprove
|
|
1437
|
+
*/
|
|
1438
|
+
type ToGlobalToolApprovalFn<TPayload, TContext = ToolApprovalContext> = (payload: TPayload, context: TContext) => AgentToolApproveRequest;
|
|
1439
|
+
/**
|
|
1440
|
+
* Transform function signature: AgentToolApproveResponse → SDK response format.
|
|
1441
|
+
* @param response - Global tool approval response from AgentSubjects.toolApprove
|
|
1442
|
+
* @returns SDK-compatible response format
|
|
1443
|
+
*/
|
|
1444
|
+
type FromGlobalToolApprovalFn<TResponse> = (response: AgentToolApproveResponse) => TResponse;
|
|
1445
|
+
/**
|
|
1446
|
+
* Factory: Create tool approval handler for adapter connector.
|
|
1447
|
+
*
|
|
1448
|
+
* Wires adapter-scoped tool approval subject → AgentSubjects.toolApprove.
|
|
1449
|
+
* Handles lazy context resolution to avoid race conditions with adapterSessionId.
|
|
1450
|
+
*
|
|
1451
|
+
* Used by both test harnesses (createTestConfig) and production (agent.ts).
|
|
1452
|
+
* @param subject - Adapter-scoped subject for tool approval requests
|
|
1453
|
+
* @param toGlobal - Transform SDK payload to global request
|
|
1454
|
+
* @param fromGlobal - Transform global response to SDK format
|
|
1455
|
+
* @returns Handler registration function
|
|
1456
|
+
* @example
|
|
1457
|
+
* ```typescript
|
|
1458
|
+
* // In gemini-sdk/src/tool-handling.ts
|
|
1459
|
+
* export const registerToolApprovalHandler = createToolApprovalHandler(
|
|
1460
|
+
* GeminiConnectorSubjects.acp.tool_approval,
|
|
1461
|
+
* toGlobalToolApproval,
|
|
1462
|
+
* fromGlobalToolApproval,
|
|
1463
|
+
* );
|
|
1464
|
+
* ```
|
|
1465
|
+
*/
|
|
1466
|
+
declare function createToolApprovalHandler<TPayload, TContext = ToolApprovalContext, TResponse = AgentToolApproveResponse>(subject: ScopedSubjectDefinition<string>, toGlobal: ToGlobalToolApprovalFn<TPayload, TContext>, fromGlobal: FromGlobalToolApprovalFn<TResponse>): (connector: Pick<AIAgentConnector, "on">, context: TContext | (() => Promise<TContext>)) => () => void;
|
|
1467
|
+
//#endregion
|
|
1468
|
+
//#region adapters/core/src/utils/normalizeMimeType.d.ts
|
|
1469
|
+
/**
|
|
1470
|
+
* Normalize a MIME type string for comparison.
|
|
1471
|
+
*
|
|
1472
|
+
* Strips parameters (e.g., "; charset=utf-8") and converts to lowercase.
|
|
1473
|
+
* This ensures that values like "text/plain; charset=utf-8" or
|
|
1474
|
+
* "TEXT/PLAIN" are handled correctly.
|
|
1475
|
+
* Falls back to 'application/octet-stream' if mimeType is null/undefined.
|
|
1476
|
+
* @param mimeType - MIME type string to normalize.
|
|
1477
|
+
* @returns Normalized MIME type string (lowercase, no parameters).
|
|
1478
|
+
*/
|
|
1479
|
+
declare function normalizeMimeType(mimeType: string | undefined | null): string;
|
|
1480
|
+
/**
|
|
1481
|
+
* Check if a MIME type represents text content that can be sent as a document.
|
|
1482
|
+
*
|
|
1483
|
+
* Covers `text/*` and common text-based `application/*` subtypes (JSON, XML,
|
|
1484
|
+
* SQL, GraphQL, JavaScript, TypeScript, YAML, TOML).
|
|
1485
|
+
* @param mimeType - MIME type string (parameters are allowed, e.g., "text/plain; charset=utf-8")
|
|
1486
|
+
* @returns True if the content is text-based.
|
|
1487
|
+
*/
|
|
1488
|
+
declare function isTextLikeMimeType(mimeType: string | undefined | null): boolean;
|
|
1489
|
+
//#endregion
|
|
1490
|
+
//#region adapters/core/src/utils/resolvePresetCredentials.d.ts
|
|
1491
|
+
/**
|
|
1492
|
+
* Resolve credentials from environment variables using a provider definition's credential mapping.
|
|
1493
|
+
*
|
|
1494
|
+
* Reads `definition.credentialEnvVars` and checks `process.env` for each declared variable.
|
|
1495
|
+
* Only includes fields where the env var is actually set.
|
|
1496
|
+
* @param definition - Provider definition with optional credentialEnvVars mapping
|
|
1497
|
+
* @returns Object mapping credential field names to resolved values, or undefined if none resolved
|
|
1498
|
+
*/
|
|
1499
|
+
declare function resolvePresetCredentials(definition: ProviderDefinitionInput): Record<string, string> | undefined;
|
|
1500
|
+
//#endregion
|
|
1501
|
+
//#region adapters/core/src/utils/createConnectorEventMapping.d.ts
|
|
1502
|
+
/**
|
|
1503
|
+
* Emit helper passed to handler functions for emitting to global subjects.
|
|
1504
|
+
* Automatically enriches payloads with AgentContext.
|
|
1505
|
+
*/
|
|
1506
|
+
type ConnectorEmitFn = <S extends SubjectDefinition>(subject: S, payload: Omit<ExtractSubjectPayload<S>, keyof AgentContext>) => Promise<void>;
|
|
1507
|
+
/**
|
|
1508
|
+
* Handler function signature for connector event mapping.
|
|
1509
|
+
* Receives the narrowed payload and an emit helper for further emissions.
|
|
1510
|
+
* Can be sync or async — async handlers are awaited.
|
|
1511
|
+
*/
|
|
1512
|
+
type ConnectorEventHandlerFn<TPayload> = (payload: TPayload, emit: ConnectorEmitFn) => void | Promise<void>;
|
|
1513
|
+
/**
|
|
1514
|
+
* Handler value: either a subject definition for passthrough or a handler function.
|
|
1515
|
+
*/
|
|
1516
|
+
type ConnectorEventHandlerValue<TPayload> = (SubjectDefinition & {
|
|
1517
|
+
$meta: {
|
|
1518
|
+
payload: TPayload;
|
|
1519
|
+
};
|
|
1520
|
+
}) | ConnectorEventHandlerFn<TPayload>;
|
|
1521
|
+
/**
|
|
1522
|
+
* Discriminator keys type - extracts string keys from the message type.
|
|
1523
|
+
*/
|
|
1524
|
+
type DiscriminatorKeys<TMessage> = (TMessage extends object ? keyof TMessage : never) & string;
|
|
1525
|
+
/**
|
|
1526
|
+
* Discriminator values type - extracts possible values at the discriminator key.
|
|
1527
|
+
*/
|
|
1528
|
+
type DiscriminatorValues<TMessage, TDiscriminator extends string> = (TMessage extends object ? TMessage[TDiscriminator & keyof TMessage] : never) & string;
|
|
1529
|
+
/**
|
|
1530
|
+
* Narrowed message type - extracts the union member matching a discriminator value.
|
|
1531
|
+
*/
|
|
1532
|
+
type NarrowedMessage<TMessage, TDiscriminator extends string, K extends string> = Extract<TMessage, { [P in TDiscriminator]: K }>;
|
|
1533
|
+
/**
|
|
1534
|
+
* Complete handlers record type for connector event mapping.
|
|
1535
|
+
*/
|
|
1536
|
+
type ConnectorEventHandlers<TMessage, TDiscriminator extends string> = { [K in DiscriminatorValues<TMessage, TDiscriminator>]?: ConnectorEventHandlerValue<NarrowedMessage<TMessage, TDiscriminator, K>> };
|
|
1537
|
+
//#endregion
|
|
1538
|
+
//#region adapters/core/src/agent/message-lifecycle-tracker.d.ts
|
|
1539
|
+
/**
|
|
1540
|
+
* Emit function type for global bus emissions.
|
|
1541
|
+
* Matches the signature of AIAgent.emitGlobal.
|
|
1542
|
+
*/
|
|
1543
|
+
type EmitGlobalFn = <S extends SubjectDefinition>(subject: S, payload: Omit<ExtractSubjectPayload<S>, keyof AgentContext>) => Promise<void>;
|
|
1544
|
+
/**
|
|
1545
|
+
* Configuration for MessageLifecycleTracker.
|
|
1546
|
+
*/
|
|
1547
|
+
interface MessageLifecycleTrackerConfig {
|
|
1548
|
+
/** Function to emit events to global bus with auto-enrichment */
|
|
1549
|
+
emitGlobal: EmitGlobalFn;
|
|
1550
|
+
}
|
|
1551
|
+
/**
|
|
1552
|
+
* Tracks message lifecycle and emits corresponding events.
|
|
1553
|
+
*
|
|
1554
|
+
* Responsibilities:
|
|
1555
|
+
* - Track current messageId being processed
|
|
1556
|
+
* - Emit user_message.acknowledged / user_message.completed events
|
|
1557
|
+
* - Emit agent.turn.started / agent.turn.completed events
|
|
1558
|
+
*
|
|
1559
|
+
* This provides a clean separation between message lifecycle tracking
|
|
1560
|
+
* and the core AIAgent functionality.
|
|
1561
|
+
*/
|
|
1562
|
+
declare class MessageLifecycleTracker {
|
|
1563
|
+
/** Current messageId being processed (set on acknowledgment, cleared on completion) */
|
|
1564
|
+
private currentMessageId?;
|
|
1565
|
+
/** Current turnId from the session orchestrator (set at sendMessage entry, cleared on completion) */
|
|
1566
|
+
private currentTurnId?;
|
|
1567
|
+
/** Emit function injected from AIAgent */
|
|
1568
|
+
private readonly emitGlobal;
|
|
1569
|
+
constructor(config: MessageLifecycleTrackerConfig);
|
|
1570
|
+
/**
|
|
1571
|
+
* Get the current messageId being processed.
|
|
1572
|
+
* Used by enrichPayload() to add messageId to intermediate events.
|
|
1573
|
+
* @returns The current messageId or undefined if no message is being processed
|
|
1574
|
+
*/
|
|
1575
|
+
getCurrentMessageId(): string | undefined;
|
|
1576
|
+
/**
|
|
1577
|
+
* Set the current turnId from the session orchestrator.
|
|
1578
|
+
* Called at the start of sendMessage processing.
|
|
1579
|
+
* @param turnId - Turn ID to track, or undefined to clear
|
|
1580
|
+
*/
|
|
1581
|
+
setCurrentTurnId(turnId: string | undefined): void;
|
|
1582
|
+
/**
|
|
1583
|
+
* Clear the currently tracked turn ID.
|
|
1584
|
+
*/
|
|
1585
|
+
clearCurrentTurnId(): void;
|
|
1586
|
+
/**
|
|
1587
|
+
* Get the current turnId being processed.
|
|
1588
|
+
* Used by enrichPayload() to add turnId to intermediate events.
|
|
1589
|
+
* @returns The current turnId or undefined if not set
|
|
1590
|
+
*/
|
|
1591
|
+
getCurrentTurnId(): string | undefined;
|
|
1592
|
+
/**
|
|
1593
|
+
* Acknowledge a message - marks turn start.
|
|
1594
|
+
*
|
|
1595
|
+
* Emits:
|
|
1596
|
+
* - user_message.acknowledged
|
|
1597
|
+
* - agent.turn.started
|
|
1598
|
+
* @param handle - The message handle being acknowledged
|
|
1599
|
+
*/
|
|
1600
|
+
acknowledge(handle: MessageHandle): void;
|
|
1601
|
+
/**
|
|
1602
|
+
* Complete a message - marks turn end.
|
|
1603
|
+
*
|
|
1604
|
+
* Emits:
|
|
1605
|
+
* - agent.turn.completed (always, with outcome — paired with agent.turn.started)
|
|
1606
|
+
* - user_message.completed (always, with outcome)
|
|
1607
|
+
* @param handle - The message handle being completed
|
|
1608
|
+
* @param result - The completion result with outcome
|
|
1609
|
+
*/
|
|
1610
|
+
complete(handle: MessageHandle, result: MessageResult): void;
|
|
1611
|
+
/**
|
|
1612
|
+
* Wire up a message handle for lifecycle tracking.
|
|
1613
|
+
*
|
|
1614
|
+
* Subscribes to the handle's acknowledgment and completion promises
|
|
1615
|
+
* and emits the appropriate events. When `transformTerminal` is provided,
|
|
1616
|
+
* it is registered on the handle so validation or other post-processing
|
|
1617
|
+
* amends the public completion result before lifecycle events fire.
|
|
1618
|
+
* @param handle - The message handle to track
|
|
1619
|
+
* @param onTerminal - Optional callback for any terminal outcome (emits agent.complete)
|
|
1620
|
+
* @param transformTerminal - Optional async transform applied before public completion resolves
|
|
1621
|
+
*/
|
|
1622
|
+
track(handle: MessageHandle, onTerminal?: (messageId: string, result: MessageResult) => void, transformTerminal?: (result: MessageResult) => Promise<MessageResult>): void;
|
|
1623
|
+
}
|
|
1624
|
+
//#endregion
|
|
1625
|
+
//#region adapters/core/src/agent/tool-call-tracker.d.ts
|
|
1626
|
+
/**
|
|
1627
|
+
* Hints for resolving tool output to its originating tool.use event.
|
|
1628
|
+
* Adapters provide what they can - strategies try each hint in order.
|
|
1629
|
+
*/
|
|
1630
|
+
interface ResolveHints {
|
|
1631
|
+
/** Native provider ID (e.g., toolu_* for Claude, call_* for Codex/OpenAI) */
|
|
1632
|
+
nativeId?: string;
|
|
1633
|
+
/** Tool name for FIFO matching when no native ID available */
|
|
1634
|
+
toolName?: string;
|
|
1635
|
+
}
|
|
1636
|
+
type ResolveStrategy = 'nativeId' | 'toolName' | 'oldest' | 'none';
|
|
1637
|
+
interface ResolveResult {
|
|
1638
|
+
correlationId: string | null;
|
|
1639
|
+
strategy: ResolveStrategy;
|
|
1640
|
+
/** Tool name from the matched tool.use call. Undefined when no match was found. */
|
|
1641
|
+
toolName?: string;
|
|
1642
|
+
/** Arguments from the matched tool.use call. Undefined when no match was found. */
|
|
1643
|
+
args?: Record<string, unknown>;
|
|
1644
|
+
}
|
|
1645
|
+
/**
|
|
1646
|
+
* Tracks tool.use → tool.output correlation across adapters.
|
|
1647
|
+
*
|
|
1648
|
+
* Different adapters have different correlation capabilities:
|
|
1649
|
+
* - Claude Code: toolu_* IDs
|
|
1650
|
+
* - Codex/OpenAI: call_* IDs
|
|
1651
|
+
* - Others: may have nothing
|
|
1652
|
+
*
|
|
1653
|
+
* ToolCallTracker provides a unified interface that:
|
|
1654
|
+
* 1. Uses native IDs when available
|
|
1655
|
+
* 2. Falls back to FIFO by tool name otherwise
|
|
1656
|
+
* 3. Generates UUIDs for adapters without native IDs
|
|
1657
|
+
*/
|
|
1658
|
+
declare class ToolCallTracker {
|
|
1659
|
+
private pending;
|
|
1660
|
+
/**
|
|
1661
|
+
* Register a tool.use event. Returns correlation ID to use.
|
|
1662
|
+
* If nativeId provided, uses that. Otherwise generates UUID.
|
|
1663
|
+
* @param toolName - Name of the tool being invoked
|
|
1664
|
+
* @param args - Tool arguments (optional, for future correlation strategies)
|
|
1665
|
+
* @param nativeId - Native provider ID if available
|
|
1666
|
+
* @returns Correlation ID to use for this tool call
|
|
1667
|
+
*/
|
|
1668
|
+
register(toolName: string, args?: Record<string, unknown>, nativeId?: string): string;
|
|
1669
|
+
/**
|
|
1670
|
+
* Find correlation ID for a tool output.
|
|
1671
|
+
* Tries native ID first, then falls back to FIFO by tool name,
|
|
1672
|
+
* and finally to the oldest pending tool call.
|
|
1673
|
+
* @param hints - Available hints for correlation
|
|
1674
|
+
* @returns Correlation result with strategy metadata
|
|
1675
|
+
*/
|
|
1676
|
+
resolve(hints: ResolveHints): ResolveResult;
|
|
1677
|
+
/**
|
|
1678
|
+
* Clear all pending entries.
|
|
1679
|
+
* Call on turn end to prevent stale entries from leaking across turns.
|
|
1680
|
+
*/
|
|
1681
|
+
clear(): void;
|
|
1682
|
+
}
|
|
1683
|
+
//#endregion
|
|
1684
|
+
//#region adapters/core/src/agent/ai-agent.d.ts
|
|
1685
|
+
interface ToolOutputResolution {
|
|
1686
|
+
toolCallId: string;
|
|
1687
|
+
toolName: string;
|
|
1688
|
+
args?: Record<string, unknown>;
|
|
1689
|
+
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Abstract base class for AI agents.
|
|
1692
|
+
*
|
|
1693
|
+
* Bridges adapter/agent bus subjects to connector sessions.
|
|
1694
|
+
* @typeParam TBus - The scoped bus type for this adapter
|
|
1695
|
+
* @typeParam TConnector - The connector type this agent wraps
|
|
1696
|
+
*/
|
|
1697
|
+
declare abstract class AIAgent<TBus extends ScopedBus<string> = ScopedBus<string>, TConnector extends AIAgentConnector<TBus> = AIAgentConnector<TBus>> {
|
|
1698
|
+
/** The underlying connector instance (created in init) */
|
|
1699
|
+
protected connector: TConnector;
|
|
1700
|
+
protected confirmedModel?: string;
|
|
1701
|
+
protected initialModel?: string;
|
|
1702
|
+
/** Cached adapterSessionId from the last connector that had a session — survives connector swaps. */
|
|
1703
|
+
private lastKnownAdapterSessionId?;
|
|
1704
|
+
/** Cleanup functions for bus subscriptions (stable, survive connector swap) */
|
|
1705
|
+
private busHandlerCleanups;
|
|
1706
|
+
/** Whether init() has been called */
|
|
1707
|
+
private initialized;
|
|
1708
|
+
/** Runtime system prompt captured from start/initialize, preserved across connector swaps. */
|
|
1709
|
+
private runtimeSystemPrompt?;
|
|
1710
|
+
/** Tracks message lifecycle and emits turn events. */
|
|
1711
|
+
protected readonly lifecycleTracker: MessageLifecycleTracker;
|
|
1712
|
+
/** Tracks tool.use → tool.output correlation across adapters. */
|
|
1713
|
+
protected readonly toolCallTracker: ToolCallTracker;
|
|
1714
|
+
/** Event-focused helper for usage/tool/step emissions. */
|
|
1715
|
+
private readonly eventBridge;
|
|
1716
|
+
/** Shared turn pipeline for start/sendMessage paths. */
|
|
1717
|
+
private readonly turnExecutor;
|
|
1718
|
+
/** Runtime mutation helper for cwd/model change handlers. */
|
|
1719
|
+
private readonly runtimeMutationManager;
|
|
1720
|
+
/** Connector lifecycle helper for swap/wiring ownership. */
|
|
1721
|
+
private readonly connectorLifecycleManager;
|
|
1722
|
+
/** Payload enrichment and global emission helper. */
|
|
1723
|
+
private readonly payloadEmitter;
|
|
1724
|
+
/** Stateful lifecycle emitter for start/complete/error/session.closed. */
|
|
1725
|
+
private readonly lifecycleEmitter;
|
|
1726
|
+
/** Validates structured output before public terminal results and lifecycle events resolve. */
|
|
1727
|
+
private readonly structuredOutputManager;
|
|
1728
|
+
/** Latest tracked message completion with agent-level terminal transforms applied. */
|
|
1729
|
+
private latestMessageCompletion?;
|
|
1730
|
+
/** Current content block index within the turn, reset on each turn start */
|
|
1731
|
+
private currentBlockIndex;
|
|
1732
|
+
/** Normalized config with defaults applied */
|
|
1733
|
+
protected readonly config: SetRequired<AIAgentConfig<TBus, TConnector>, 'globalBus'>;
|
|
1734
|
+
/** Available models for context window lookup */
|
|
1735
|
+
protected readonly availableModels?: AIModel[];
|
|
1736
|
+
/**
|
|
1737
|
+
* Create an AIAgent instance.
|
|
1738
|
+
*
|
|
1739
|
+
* Note: Does NOT create the connector yet - call init() after construction.
|
|
1740
|
+
* @param config - Agent configuration
|
|
1741
|
+
*/
|
|
1742
|
+
constructor(config: AIAgentConfig<TBus, TConnector>);
|
|
1743
|
+
private getEventMetadataDefaults;
|
|
1744
|
+
private createLifecycleEmitter;
|
|
1745
|
+
/**
|
|
1746
|
+
* Create the structured-output manager for this agent.
|
|
1747
|
+
* @returns Configured manager instance
|
|
1748
|
+
*/
|
|
1749
|
+
private createStructuredOutputManager;
|
|
1750
|
+
/** @returns Unique agent identifier */
|
|
1751
|
+
get agentId(): string;
|
|
1752
|
+
/** @returns Adapter instance identifier */
|
|
1753
|
+
get adapterId(): string;
|
|
1754
|
+
/** @returns Adapter type name (e.g., 'claude-code', 'gemini-sdk') */
|
|
1755
|
+
get adapterName(): string;
|
|
1756
|
+
/** @returns Adapter capabilities for runtime feature detection */
|
|
1757
|
+
get capabilities(): string[];
|
|
1758
|
+
/** @returns Native tools built into the adapter */
|
|
1759
|
+
get nativeTools(): string[];
|
|
1760
|
+
/** @returns Shared Makaio sessionId */
|
|
1761
|
+
get sessionId(): string | undefined;
|
|
1762
|
+
/** @returns Initial adapter session ID from config (may differ from connector's resolved session ID) */
|
|
1763
|
+
protected get adapterSessionId(): string | undefined;
|
|
1764
|
+
/** @returns Global bus for cross-namespace communication (defaulted in constructor) */
|
|
1765
|
+
protected get globalBus(): IMakaioBus;
|
|
1766
|
+
/**
|
|
1767
|
+
* Initialize the agent.
|
|
1768
|
+
*
|
|
1769
|
+
* Creates the connector via the abstract createConnector() method
|
|
1770
|
+
* and sets up handlers for agent.* subjects with agentId filtering.
|
|
1771
|
+
* @throws Error if already initialized
|
|
1772
|
+
*/
|
|
1773
|
+
init(): Promise<void>;
|
|
1774
|
+
protected emitStart(event?: Omit<AgentStarted, 'agentId' | 'adapterId' | 'adapterName' | 'adapterSessionId' | 'model' | 'cwd'>): Promise<void>;
|
|
1775
|
+
protected emitCompletion(result: Omit<z.infer<typeof AgentSchemas.complete>, keyof AgentContext>): Promise<void>;
|
|
1776
|
+
/**
|
|
1777
|
+
* Stash error metadata for the next emitCompletion call.
|
|
1778
|
+
*
|
|
1779
|
+
* The lifecycle tracker emits `agent.complete` with `outcome: 'error'` when the
|
|
1780
|
+
* message handle completes. This method runs first (from the connector's errorHandler)
|
|
1781
|
+
* and stashes `errorCategory` so emitCompletion can include it in the complete payload.
|
|
1782
|
+
*
|
|
1783
|
+
* No longer emits `agent.error` — all terminal events flow through `agent.complete`.
|
|
1784
|
+
* @param result - Error payload from the connector
|
|
1785
|
+
*/
|
|
1786
|
+
protected emitError(result: Pick<z.infer<typeof AgentSchemas.complete>, 'error' | 'errorCategory'>): void;
|
|
1787
|
+
/**
|
|
1788
|
+
* Emit agent session closed event. Emits only once per session.
|
|
1789
|
+
* AIAdapter listens to cleanup agent and re-emit as AdapterSubjects.session.closed.
|
|
1790
|
+
* @param reason - Reason for session closure (e.g., 'aborted', 'closed')
|
|
1791
|
+
*/
|
|
1792
|
+
protected emitSessionClosed(reason?: string): void;
|
|
1793
|
+
/**
|
|
1794
|
+
* Enrich a payload with agent context fields.
|
|
1795
|
+
* @param payload - The base payload to enrich
|
|
1796
|
+
* @returns Payload with AgentContext fields and optional messageId added
|
|
1797
|
+
*/
|
|
1798
|
+
protected enrichPayload<T extends object>(payload: T): Promise<T & AgentContext & {
|
|
1799
|
+
messageId?: string;
|
|
1800
|
+
}>;
|
|
1801
|
+
/**
|
|
1802
|
+
* Emit to a global subject with automatic payload enrichment.
|
|
1803
|
+
* @param subject - The subject to emit to
|
|
1804
|
+
* @param payload - The payload (without AgentContext fields - they're added automatically)
|
|
1805
|
+
*/
|
|
1806
|
+
protected emitGlobal<S extends SubjectDefinition>(subject: S, payload: Omit<ExtractSubjectPayload<S>, keyof AgentContext> & {
|
|
1807
|
+
messageId?: string;
|
|
1808
|
+
}): Promise<void>;
|
|
1809
|
+
/**
|
|
1810
|
+
* Track usage and emit to global bus.
|
|
1811
|
+
* AIAdapter aggregates session totals from per-call usage events.
|
|
1812
|
+
* @param normalized - Normalized usage metrics from adapter-specific normalizer
|
|
1813
|
+
*/
|
|
1814
|
+
protected trackUsage(normalized: NormalizedCallUsage): Promise<void>;
|
|
1815
|
+
/**
|
|
1816
|
+
* Get context window size for a model.
|
|
1817
|
+
*
|
|
1818
|
+
* Looks up the context window size from availableModels based on model name.
|
|
1819
|
+
* @param modelName - Model name to look up (defaults to confirmedModel or initialModel)
|
|
1820
|
+
* @returns Context window size in tokens, or undefined if not found
|
|
1821
|
+
*/
|
|
1822
|
+
protected getContextWindowSize(modelName?: string): number | undefined;
|
|
1823
|
+
/**
|
|
1824
|
+
* Emit context window status for compression trigger decisions.
|
|
1825
|
+
*
|
|
1826
|
+
* Calculates fill percentage and warning level from raw metrics.
|
|
1827
|
+
* Called by subclasses after usage tracking with provider-specific metrics.
|
|
1828
|
+
* @param input - Raw metrics: currentTokens, maxTokens, optional cachedTokens
|
|
1829
|
+
*/
|
|
1830
|
+
protected emitContextWindowUpdate(input: ContextWindowInput): Promise<void>;
|
|
1831
|
+
/**
|
|
1832
|
+
* Emit tool.use event with automatic correlation tracking.
|
|
1833
|
+
* Registers the tool call with ToolCallTracker and emits to global bus.
|
|
1834
|
+
* Use this instead of directly emitting to AgentSubjects.tool.use.
|
|
1835
|
+
* @param toolName - Name of the tool being invoked
|
|
1836
|
+
* @param args - Tool arguments
|
|
1837
|
+
* @param nativeId - Native provider ID if available (e.g., toolu_*, call_*)
|
|
1838
|
+
* @returns The correlation ID used (nativeId if provided, else generated UUID)
|
|
1839
|
+
*/
|
|
1840
|
+
protected emitToolUse(toolName: string, args?: Record<string, unknown>, nativeId?: string): Promise<string>;
|
|
1841
|
+
/**
|
|
1842
|
+
* Emit tool.output event with automatic correlation resolution.
|
|
1843
|
+
* Resolves the correlation ID from ToolCallTracker using provided hints.
|
|
1844
|
+
* Use this instead of directly emitting to AgentSubjects.tool.output.
|
|
1845
|
+
* @param output - Tool output content
|
|
1846
|
+
* @param hints - Hints for correlation (nativeId and/or toolName)
|
|
1847
|
+
* @returns Resolved toolCallId, toolName (falls back to 'unknown'), and args from the matched tool.use call
|
|
1848
|
+
*/
|
|
1849
|
+
protected emitToolOutput(output: string, hints: ResolveHints): Promise<ToolOutputResolution>;
|
|
1850
|
+
/**
|
|
1851
|
+
* Emit step.started event with automatic block index management.
|
|
1852
|
+
* Call this when a content block begins processing.
|
|
1853
|
+
* @param stepType - The type of step (text, reasoning, tool_use)
|
|
1854
|
+
* @param blockData - Optional metadata for the block (e.g., toolName for tool_use)
|
|
1855
|
+
* @param content - Optional content for the step (e.g., tool_call block for tool_use)
|
|
1856
|
+
*/
|
|
1857
|
+
protected emitStepStarted(stepType: StepType, blockData?: BlockData, content?: SessionMessageBlock): Promise<void>;
|
|
1858
|
+
/**
|
|
1859
|
+
* Emit step.finished event with content and increment block index.
|
|
1860
|
+
* Call this when a content block completes processing.
|
|
1861
|
+
* @param stepType - The type of step that finished
|
|
1862
|
+
* @param content - The complete content of the step (text, reasoning, tool_call, or tool_output)
|
|
1863
|
+
*/
|
|
1864
|
+
protected emitStepFinished(stepType: StepType, content: SessionMessageBlock): Promise<void>;
|
|
1865
|
+
/**
|
|
1866
|
+
* Get the current block index (for adapters that need to track it externally).
|
|
1867
|
+
* @returns Current block index within the turn
|
|
1868
|
+
*/
|
|
1869
|
+
protected getBlockIndex(): number;
|
|
1870
|
+
/**
|
|
1871
|
+
* Increment block index (for adapters using SDK-provided indices).
|
|
1872
|
+
* Call after emitting step.finished if managing index externally.
|
|
1873
|
+
*/
|
|
1874
|
+
protected incrementBlockIndex(): void;
|
|
1875
|
+
/**
|
|
1876
|
+
* Handle agent.sendMessage request.
|
|
1877
|
+
* The filter has already been applied at subscription time - this method
|
|
1878
|
+
* only receives messages intended for this agent.
|
|
1879
|
+
* Runs PreUserMessage hooks before delegating to the connector's sendMessage method.
|
|
1880
|
+
* Uses sessionContext signals to decide between native resume and fresh with history.
|
|
1881
|
+
* HookAbortError propagates to caller (session layer handles lifecycle).
|
|
1882
|
+
* Subclasses can override for custom handling.
|
|
1883
|
+
* @param ctx - Request context with payload and response methods
|
|
1884
|
+
*/
|
|
1885
|
+
protected sendMessage(ctx: RequestContext<SendMessageRequestPayload, SendMessageResponsePayload>): Promise<void>;
|
|
1886
|
+
/**
|
|
1887
|
+
* Handle agent.interrupt request.
|
|
1888
|
+
* Delegates to the connector's native interrupt behavior.
|
|
1889
|
+
* @param ctx - Request context with interrupt payload
|
|
1890
|
+
*/
|
|
1891
|
+
private handleInterrupt;
|
|
1892
|
+
/**
|
|
1893
|
+
* Register a cleanup function for connector wiring.
|
|
1894
|
+
* These cleanups are cleared on connector swap but preserved across bus handler changes.
|
|
1895
|
+
* @param cleanup - Cleanup function to register
|
|
1896
|
+
*/
|
|
1897
|
+
protected addConnectorWiringCleanup(cleanup: () => void): void;
|
|
1898
|
+
/**
|
|
1899
|
+
* Registers a cleanup function for a global bus subscription.
|
|
1900
|
+
* These survive connector swaps and are cleaned up in close().
|
|
1901
|
+
* @param cleanup - Function to unsubscribe from the bus
|
|
1902
|
+
*/
|
|
1903
|
+
protected addBusHandlerCleanup(cleanup: () => void): void;
|
|
1904
|
+
/**
|
|
1905
|
+
* Replace the current connector with a fresh one.
|
|
1906
|
+
*
|
|
1907
|
+
* Uses create-before-close pattern with rollback for safety:
|
|
1908
|
+
* 1. Create new connector first (old connector still alive)
|
|
1909
|
+
* 2. Wire events to new connector (accumulate cleanups separately)
|
|
1910
|
+
* 3. If successful: close old connector, assign new one
|
|
1911
|
+
* 4. If failed: close new connector, restore old wiring, throw
|
|
1912
|
+
*
|
|
1913
|
+
* This ensures the agent always has a working connector, even if factory or wiring fails.
|
|
1914
|
+
*
|
|
1915
|
+
* Preserves runtime overrides across sequential swaps by using current connector values
|
|
1916
|
+
* as baseline for non-overridden fields.
|
|
1917
|
+
* @param configOverrides - Optional config overrides (e.g., new cwd, model)
|
|
1918
|
+
* @throws Error if connector is currently processing a turn
|
|
1919
|
+
*/
|
|
1920
|
+
swapConnector(configOverrides?: Partial<{
|
|
1921
|
+
cwd: string;
|
|
1922
|
+
model: string;
|
|
1923
|
+
providerContext: ProviderContext;
|
|
1924
|
+
mcpSessionContext: McpRuntimeSessionContext | McpSessionContext | LedgerSessionContext;
|
|
1925
|
+
}>): Promise<void>;
|
|
1926
|
+
/**
|
|
1927
|
+
* Resolve the supported reasoning levels for a given model name.
|
|
1928
|
+
*
|
|
1929
|
+
* Centralised lookup into `availableModels` so callers do not repeat the
|
|
1930
|
+
* find/optional-chain pattern inline.
|
|
1931
|
+
* @param model - Model name to look up, or `undefined` to return `undefined`
|
|
1932
|
+
* @returns The `supportedReasoningLevels` map for the model, or `undefined`
|
|
1933
|
+
*/
|
|
1934
|
+
private getSupportedReasoningLevels;
|
|
1935
|
+
/**
|
|
1936
|
+
* Build config factory input from agent config with optional overrides.
|
|
1937
|
+
*
|
|
1938
|
+
* Explicitly maps AIAgentConfig fields to ConfigFactoryInput — avoids
|
|
1939
|
+
* accidentally forwarding adapter-only fields (capabilities, nativeTools, etc.)
|
|
1940
|
+
* into the factory.
|
|
1941
|
+
* @param overrides - Optional field overrides (e.g., cwd, model, adapterSessionId)
|
|
1942
|
+
* @returns ConfigFactoryInput ready for config factory
|
|
1943
|
+
*/
|
|
1944
|
+
private buildConfigInput;
|
|
1945
|
+
/**
|
|
1946
|
+
* Create the onMessageSent callback for connector factories.
|
|
1947
|
+
*
|
|
1948
|
+
* Returns a callback that emits user_message.sent events to the global bus.
|
|
1949
|
+
* @returns Callback function for connector config
|
|
1950
|
+
*/
|
|
1951
|
+
private createOnMessageSent;
|
|
1952
|
+
/**
|
|
1953
|
+
* Handle agent.cwd.change request — prefers native in-place change, falls back to connector swap.
|
|
1954
|
+
* @param ctx - Request context with newCwd payload
|
|
1955
|
+
*/
|
|
1956
|
+
private handleCwdChange;
|
|
1957
|
+
/**
|
|
1958
|
+
* Handle agent.model.change request — prefers native in-place change, falls back to connector swap.
|
|
1959
|
+
* @param ctx - Request context with newModel payload
|
|
1960
|
+
*/
|
|
1961
|
+
private handleModelChange;
|
|
1962
|
+
/**
|
|
1963
|
+
* Handle agent.mcp.servers.set request — rebuilds immediately when idle or stages for the next turn.
|
|
1964
|
+
* @param ctx - Request context with replacement MCP session context
|
|
1965
|
+
*/
|
|
1966
|
+
private handleMcpServersSet;
|
|
1967
|
+
/**
|
|
1968
|
+
* Handle agent.credential.change request — defers when a turn is active, otherwise swaps connector.
|
|
1969
|
+
* @param ctx - Request context with credential change payload
|
|
1970
|
+
*/
|
|
1971
|
+
private handleCredentialChanged;
|
|
1972
|
+
/**
|
|
1973
|
+
* Wire adapter-specific connector events.
|
|
1974
|
+
* Called automatically during init() and connector swap.
|
|
1975
|
+
* Subclasses implement this to set up their event mappings.
|
|
1976
|
+
* @param connector - Connector instance to wire
|
|
1977
|
+
*/
|
|
1978
|
+
protected abstract wireEvents(connector: TConnector): void | Promise<void>;
|
|
1979
|
+
/**
|
|
1980
|
+
* Subscribe to a connector subject and register its cleanup as connector wiring.
|
|
1981
|
+
*
|
|
1982
|
+
* Use this in adapter `wireEvents()` implementations so connector swaps can
|
|
1983
|
+
* remove old listeners before rewiring the new connector.
|
|
1984
|
+
* @param connector - Connector instance to subscribe on
|
|
1985
|
+
* @param subject - Subject definition to subscribe to
|
|
1986
|
+
* @param handler - Subject handler
|
|
1987
|
+
* @param options - Optional bus subscription options
|
|
1988
|
+
*/
|
|
1989
|
+
protected subscribeConnector<Subject extends ScopedSubjectDefinition<TConnector extends AIAgentConnector<infer TBus> ? TBus['namespace'] : never>>(connector: TConnector, subject: Subject, handler: HandlerForSubjectDefinition<Subject>, options?: OnOptions): void;
|
|
1990
|
+
/**
|
|
1991
|
+
* Clean up resources and emit session closed event.
|
|
1992
|
+
*
|
|
1993
|
+
* Emits session.closed event (once per session) unless explicitly suppressed,
|
|
1994
|
+
* then unsubscribes from all bus handlers and aborts the connector if available.
|
|
1995
|
+
* @param options - Cleanup options; ephemeral agents suppress session-close lifecycle events because they never join a session.
|
|
1996
|
+
*/
|
|
1997
|
+
close(options?: {
|
|
1998
|
+
emitSessionClosed?: boolean;
|
|
1999
|
+
}): Promise<void>;
|
|
2000
|
+
/**
|
|
2001
|
+
* Ensure the connector is initialized, throwing if not.
|
|
2002
|
+
* @returns The initialized connector instance
|
|
2003
|
+
* @throws Error if connector is not initialized
|
|
2004
|
+
*/
|
|
2005
|
+
private ensureConnector;
|
|
2006
|
+
/**
|
|
2007
|
+
* Determine whether to use native session resume or fresh with history.
|
|
2008
|
+
*
|
|
2009
|
+
* Native resume: SDK manages history, don't inject messageHistory, preserve cache.
|
|
2010
|
+
* Fresh with history: Create new session, inject messageHistory.
|
|
2011
|
+
*
|
|
2012
|
+
* Override in adapter-specific agents if needed.
|
|
2013
|
+
* @param sessionContext - Context signals from SessionOrchestrator
|
|
2014
|
+
* @returns true if native resume should be used
|
|
2015
|
+
*/
|
|
2016
|
+
protected shouldUseNativeResume(sessionContext?: SessionContext): boolean;
|
|
2017
|
+
/**
|
|
2018
|
+
* Whether this adapter supports native session resume.
|
|
2019
|
+
* Override in adapter-specific agents that can resume SDK sessions.
|
|
2020
|
+
* @returns true if native resume is supported
|
|
2021
|
+
*/
|
|
2022
|
+
protected supportsNativeResume(): boolean;
|
|
2023
|
+
/**
|
|
2024
|
+
* Start the agent with an initial message.
|
|
2025
|
+
*
|
|
2026
|
+
* Ensures the agent is initialized (idempotent) before delegating to the connector.
|
|
2027
|
+
* Runs PreUserMessage hooks before sending the message.
|
|
2028
|
+
* Uses sessionContext signals to decide between native resume and fresh with history.
|
|
2029
|
+
* HookAbortError propagates to caller.
|
|
2030
|
+
* @param message - User message (normalized or unnormalized)
|
|
2031
|
+
* @param options - Optional start options (e.g., delivery mode, sessionContext)
|
|
2032
|
+
* @returns Session ID, agent ID, and message handle for tracking
|
|
2033
|
+
*/
|
|
2034
|
+
start(message: NormalizedMessageInput | MessageInput, options?: StartAgentOptions): Promise<AgentStartResult>;
|
|
2035
|
+
/**
|
|
2036
|
+
* Initialize the agent without sending a message (idle creation).
|
|
2037
|
+
* Ensures init() is called, then delegates to connector.initialize().
|
|
2038
|
+
* @param options - Optional initialization options (system prompt, sessionContext)
|
|
2039
|
+
*/
|
|
2040
|
+
initialize(options?: StartAgentOptions): Promise<void>;
|
|
2041
|
+
protected onBeforeEmitCompletion(): Promise<void>;
|
|
2042
|
+
protected onMessageHandle(messageHandle: MessageHandle): Promise<void>;
|
|
2043
|
+
/**
|
|
2044
|
+
* Abort the agent immediately (panic mode).
|
|
2045
|
+
* Triggers AbortController which may cause provider errors.
|
|
2046
|
+
* Use close() for graceful shutdown instead.
|
|
2047
|
+
*
|
|
2048
|
+
* Emits session.closed event (once per session) then delegates
|
|
2049
|
+
* to the underlying connector's abort method.
|
|
2050
|
+
* @throws Error if connector is not initialized
|
|
2051
|
+
*/
|
|
2052
|
+
abort(): void;
|
|
2053
|
+
/**
|
|
2054
|
+
* Get session ID, waiting for provider to generate it if not yet available.
|
|
2055
|
+
*
|
|
2056
|
+
* Delegates to the underlying connector's getSessionId method.
|
|
2057
|
+
* @returns Session ID from provider
|
|
2058
|
+
* @throws Error if connector is not initialized
|
|
2059
|
+
*/
|
|
2060
|
+
getAdapterSessionId(): Promise<string>;
|
|
2061
|
+
/**
|
|
2062
|
+
* Complete the agent session by waiting for all messages to finish.
|
|
2063
|
+
*
|
|
2064
|
+
* Waits for the connector to finish, then returns the agent-level terminal
|
|
2065
|
+
* result so structured-output transforms are reflected in direct callers.
|
|
2066
|
+
* @returns Last message result or null if no messages processed
|
|
2067
|
+
* @throws Error if connector is not initialized
|
|
2068
|
+
*/
|
|
2069
|
+
complete(): Promise<MessageResult | null>;
|
|
2070
|
+
/**
|
|
2071
|
+
* Creates a type-safe event mapping from connector events to scoped subjects or handlers.
|
|
2072
|
+
* @param sourceSubject - The connector subject to subscribe to
|
|
2073
|
+
* @param discriminator - The discriminator key within the message (e.g., 'type')
|
|
2074
|
+
* @param handlers - Map of discriminator values to target subjects or handler functions
|
|
2075
|
+
* @param nestedMessageProp - Property containing the discriminated union (e.g., 'msg'), or undefined for top-level
|
|
2076
|
+
* @returns Unsubscribe function for the connector event mapping subscription
|
|
2077
|
+
*/
|
|
2078
|
+
protected createConnectorEventMapping<TSourceSubject extends ScopedSubjectDefinition<TConnector extends AIAgentConnector<infer TBus> ? TBus['namespace'] : never>, TNestedMessageProp extends keyof TSourceSubject['$meta']['payload'] | undefined = undefined, TMessage = (TNestedMessageProp extends keyof TSourceSubject['$meta']['payload'] ? TSourceSubject['$meta']['payload'][TNestedMessageProp] : TSourceSubject['$meta']['payload']), TDiscriminator extends DiscriminatorKeys<TMessage> = DiscriminatorKeys<TMessage>>(sourceSubject: TSourceSubject, discriminator: TDiscriminator, handlers: ConnectorEventHandlers<TMessage, TDiscriminator>, nestedMessageProp?: TNestedMessageProp): () => void;
|
|
2079
|
+
}
|
|
2080
|
+
//#endregion
|
|
2081
|
+
//#region adapters/core/src/factory/create-adapter-namespace.d.ts
|
|
2082
|
+
/**
|
|
2083
|
+
* Adapter namespace extends BusNamespace with additional metadata for adapters.
|
|
2084
|
+
*
|
|
2085
|
+
* Provides:
|
|
2086
|
+
* - All BusNamespace features (subjects, scoped bus factory)
|
|
2087
|
+
* - Raw schema access for adapter factory internals
|
|
2088
|
+
* - Domain name for debugging/logging
|
|
2089
|
+
* @typeParam N - Namespace domain string
|
|
2090
|
+
* @typeParam Schemas - Schema record type
|
|
2091
|
+
*/
|
|
2092
|
+
type AdapterNamespace<Domain extends string = string> = Omit<BusNamespace<Domain>, 'subjects'>;
|
|
2093
|
+
/**
|
|
2094
|
+
* Creates an adapter namespace with typed subject definitions.
|
|
2095
|
+
*
|
|
2096
|
+
* **Seam:** Thin wrapper around MakaioBus.registerNamespace that:
|
|
2097
|
+
* - Delegates to bus-core for namespace registration
|
|
2098
|
+
* - Preserves FilterPayload type for type-safe withFilter()
|
|
2099
|
+
* - Provides extension point for future adapter-specific features
|
|
2100
|
+
* @param domain - Namespace domain (e.g., 'adapter:claudeCode')
|
|
2101
|
+
* @param schemas - Record of subject schemas (events and requests)
|
|
2102
|
+
* @param options - Registration and routing options (e.g., busValidationMode for Zod version conflicts)
|
|
2103
|
+
* @returns Adapter namespace with typed subjects and pre-computed FilterPayload
|
|
2104
|
+
* @example
|
|
2105
|
+
* ```typescript
|
|
2106
|
+
* const ClaudeCodeNamespace = createAdapterNamespace('adapter:claudeCode', {
|
|
2107
|
+
* thinking: z.object({ content: z.string() }),
|
|
2108
|
+
* getContext: {
|
|
2109
|
+
* request: z.object({ path: z.string() }),
|
|
2110
|
+
* response: z.object({ content: z.string() }),
|
|
2111
|
+
* },
|
|
2112
|
+
* });
|
|
2113
|
+
*
|
|
2114
|
+
* // Access typed subjects
|
|
2115
|
+
* ClaudeCodeNamespace.subjects.thinking;
|
|
2116
|
+
*
|
|
2117
|
+
* // Get scoped bus with type-safe filtering
|
|
2118
|
+
* const bus = await ClaudeCodeNamespace.scopedBus();
|
|
2119
|
+
* bus.withFilter({ content: 'test' }); // ✅ Type-checked
|
|
2120
|
+
*
|
|
2121
|
+
* // For adapters with bundled Zod v3 (e.g., @github/copilot-sdk):
|
|
2122
|
+
* const CopilotNamespace = createAdapterNamespace('adapter:copilot', schemas, {
|
|
2123
|
+
* busValidationMode: 'skip', // Skip validation due to Zod version conflict
|
|
2124
|
+
* });
|
|
2125
|
+
*
|
|
2126
|
+
* // For adapters with lenient validation (schema drift triggers warnings, not crashes):
|
|
2127
|
+
* const ClaudeNamespace = createAdapterNamespace('adapter:claude-code', schemas, {
|
|
2128
|
+
* busValidationMode: 'lenient',
|
|
2129
|
+
* onSchemaViolation: (report) => console.warn(report),
|
|
2130
|
+
* });
|
|
2131
|
+
* ```
|
|
2132
|
+
*/
|
|
2133
|
+
declare function createAdapterNamespace<N extends string, Schemas extends SchemaRecord>(domain: N, schemas: Schemas, options?: CreateBusNamespaceOptions): BusNamespace<N, SubjectRecordFromSchemaRecord<Schemas>, FilterablePayloadIntersection<SubjectRecordFromSchemaRecord<Schemas>>, Schemas>;
|
|
2134
|
+
//#endregion
|
|
2135
|
+
//#region adapters/core/src/factory/adapter-context.d.ts
|
|
2136
|
+
/**
|
|
2137
|
+
* Context provided to adapter implementations.
|
|
2138
|
+
*
|
|
2139
|
+
* Contains shared infrastructure and configuration that all adapters need:
|
|
2140
|
+
* - Adapter name and capabilities from config
|
|
2141
|
+
* - Local event bus for emitting events
|
|
2142
|
+
*/
|
|
2143
|
+
interface AIAdapterContext<Scope extends ScopedBus<string>> {
|
|
2144
|
+
/** Unique adapter instance identifier. */
|
|
2145
|
+
adapterId: string;
|
|
2146
|
+
/** Unique adapter name (kebab-case). */
|
|
2147
|
+
name: string;
|
|
2148
|
+
/** Adapter capabilities (unparsed). Use parseAIAdapterCapabilities() to parse. */
|
|
2149
|
+
capabilities: AIAdapterCapability[];
|
|
2150
|
+
/** Scoped bus for adapter-level events. */
|
|
2151
|
+
adapterBus: Scope;
|
|
2152
|
+
/** Global event bus. */
|
|
2153
|
+
globalBus: IMakaioBus;
|
|
2154
|
+
}
|
|
2155
|
+
//#endregion
|
|
2156
|
+
//#region adapters/core/src/agent/agent-event-bridge.d.ts
|
|
2157
|
+
/**
|
|
2158
|
+
* Dependencies for AgentEventBridge.
|
|
2159
|
+
*/
|
|
2160
|
+
interface AgentEventBridgeConfig {
|
|
2161
|
+
/** Emit usage payload (agent context gets added by AIAgent). */
|
|
2162
|
+
emitUsage: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.usage>, keyof AgentContext>) => Promise<void>;
|
|
2163
|
+
/** Emit context window status payload. */
|
|
2164
|
+
emitContextWindowUpdated: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.contextWindow.updated>, keyof AgentContext>) => Promise<void>;
|
|
2165
|
+
/** Emit tool.use payload. */
|
|
2166
|
+
emitToolUse: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.tool.use>, keyof AgentContext>) => Promise<void>;
|
|
2167
|
+
/** Emit tool.output payload. */
|
|
2168
|
+
emitToolOutput: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.tool.output>, keyof AgentContext>) => Promise<void>;
|
|
2169
|
+
/** Emit adapter log payload. */
|
|
2170
|
+
emitAdapterLog: (payload: Omit<ExtractSubjectPayload<typeof AdapterSubjects.log>, 'adapterId' | 'adapterName'>) => Promise<void>;
|
|
2171
|
+
/** Emit step.started payload. */
|
|
2172
|
+
emitStepStarted: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.step.started>, keyof AgentContext>) => Promise<void>;
|
|
2173
|
+
/** Emit step.finished payload. */
|
|
2174
|
+
emitStepFinished: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.step.finished>, keyof AgentContext>) => Promise<void>;
|
|
2175
|
+
/** Correlation tracker for tool.use -\> tool.output. */
|
|
2176
|
+
toolCallTracker: ToolCallTracker;
|
|
2177
|
+
/** Current content block index getter. */
|
|
2178
|
+
getBlockIndex: () => number;
|
|
2179
|
+
/** Increment block index after step completion. */
|
|
2180
|
+
incrementBlockIndex: () => void;
|
|
2181
|
+
/** Resolve model name for usage events. */
|
|
2182
|
+
getUsageModel: () => string | undefined;
|
|
2183
|
+
}
|
|
2184
|
+
/**
|
|
2185
|
+
* Resolution metadata returned when emitting tool output.
|
|
2186
|
+
*/
|
|
2187
|
+
interface ToolOutputResult {
|
|
2188
|
+
toolCallId: string;
|
|
2189
|
+
toolName: string;
|
|
2190
|
+
args?: Record<string, unknown>;
|
|
2191
|
+
}
|
|
2192
|
+
/**
|
|
2193
|
+
* Event-focused helper for AIAgent.
|
|
2194
|
+
*
|
|
2195
|
+
* Keeps event payload formatting, correlation warnings, and block-indexed
|
|
2196
|
+
* step emissions out of the base class while preserving existing behavior.
|
|
2197
|
+
*/
|
|
2198
|
+
declare class AgentEventBridge {
|
|
2199
|
+
private readonly emitUsagePayload;
|
|
2200
|
+
private readonly emitContextWindowUpdatedPayload;
|
|
2201
|
+
private readonly emitToolUsePayload;
|
|
2202
|
+
private readonly emitToolOutputPayload;
|
|
2203
|
+
private readonly emitAdapterLogPayload;
|
|
2204
|
+
private readonly emitStepStartedPayload;
|
|
2205
|
+
private readonly emitStepFinishedPayload;
|
|
2206
|
+
private readonly toolCallTracker;
|
|
2207
|
+
private readonly getBlockIndex;
|
|
2208
|
+
private readonly incrementBlockIndex;
|
|
2209
|
+
private readonly getUsageModel;
|
|
2210
|
+
/**
|
|
2211
|
+
* Create an event bridge with emission and correlation dependencies.
|
|
2212
|
+
* @param config - Event bridge dependencies (emitters, tracker, and block-index accessors)
|
|
2213
|
+
*/
|
|
2214
|
+
constructor(config: AgentEventBridgeConfig);
|
|
2215
|
+
/**
|
|
2216
|
+
* Emit usage event to global bus.
|
|
2217
|
+
* @param normalized - Provider-normalized usage metrics
|
|
2218
|
+
*/
|
|
2219
|
+
trackUsage(normalized: NormalizedCallUsage): Promise<void>;
|
|
2220
|
+
/**
|
|
2221
|
+
* Emit context window health signal.
|
|
2222
|
+
* @param input - Raw usage and capacity metrics
|
|
2223
|
+
*/
|
|
2224
|
+
emitContextWindowUpdate(input: ContextWindowInput): Promise<void>;
|
|
2225
|
+
/**
|
|
2226
|
+
* Emit tool.use event with correlation tracking.
|
|
2227
|
+
* @param toolName - Tool identifier
|
|
2228
|
+
* @param args - Tool arguments
|
|
2229
|
+
* @param nativeId - Provider-native call ID
|
|
2230
|
+
* @returns Correlation ID for the call
|
|
2231
|
+
*/
|
|
2232
|
+
emitToolUse(toolName: string, args?: Record<string, unknown>, nativeId?: string): Promise<string>;
|
|
2233
|
+
/**
|
|
2234
|
+
* Emit tool.output event with best-effort correlation resolution.
|
|
2235
|
+
* @param output - Tool output text
|
|
2236
|
+
* @param hints - Correlation hints from adapter events
|
|
2237
|
+
* @returns Resolved toolCallId, toolName (falls back to 'unknown'), and args from the matched tool.use call
|
|
2238
|
+
*/
|
|
2239
|
+
emitToolOutput(output: string, hints: ResolveHints): Promise<ToolOutputResult>;
|
|
2240
|
+
/**
|
|
2241
|
+
* Emit step.started for the current block index.
|
|
2242
|
+
* @param stepType - Block step type
|
|
2243
|
+
* @param blockData - Optional step metadata
|
|
2244
|
+
* @param content - Optional immediate block content
|
|
2245
|
+
*/
|
|
2246
|
+
emitStepStarted(stepType: StepType, blockData?: BlockData, content?: SessionMessageBlock): Promise<void>;
|
|
2247
|
+
/**
|
|
2248
|
+
* Emit step.finished and advance block index.
|
|
2249
|
+
* @param stepType - Completed step type
|
|
2250
|
+
* @param content - Final block content
|
|
2251
|
+
*/
|
|
2252
|
+
emitStepFinished(stepType: StepType, content: SessionMessageBlock): Promise<void>;
|
|
2253
|
+
}
|
|
2254
|
+
//#endregion
|
|
2255
|
+
//#region adapters/core/src/agent/agent-turn-executor.d.ts
|
|
2256
|
+
/**
|
|
2257
|
+
* Runtime dependencies for AgentTurnExecutor.
|
|
2258
|
+
*/
|
|
2259
|
+
interface AgentTurnExecutorConfig {
|
|
2260
|
+
/** Stable agent identifier. */
|
|
2261
|
+
agentId: string;
|
|
2262
|
+
/** Stable adapter identifier. */
|
|
2263
|
+
adapterId: string;
|
|
2264
|
+
/** Optional Makaio session identifier. */
|
|
2265
|
+
sessionId?: string;
|
|
2266
|
+
/** Capability tags reported by the adapter (e.g. `'structuredOutput'`). */
|
|
2267
|
+
adapterCapabilities?: string[];
|
|
2268
|
+
/** Global bus instance for hooks. */
|
|
2269
|
+
globalBus: IMakaioBus;
|
|
2270
|
+
/** Current connector reference resolver. */
|
|
2271
|
+
getConnector: () => AIAgentConnector;
|
|
2272
|
+
/** Native resume decision function. */
|
|
2273
|
+
shouldUseNativeResume: ShouldUseNativeResumeFn;
|
|
2274
|
+
/** Completion/lifecycle tracker hook. */
|
|
2275
|
+
onMessageHandle: (messageHandle: MessageHandle) => Promise<void>;
|
|
2276
|
+
/** Side-effect callback to mark agent status active before dispatch. */
|
|
2277
|
+
onBeforeDispatch?: () => void | Promise<void>;
|
|
2278
|
+
/** When true, PreUserMessage hooks are skipped. */
|
|
2279
|
+
ephemeral?: boolean;
|
|
2280
|
+
}
|
|
2281
|
+
/**
|
|
2282
|
+
* Function type for native resume decision.
|
|
2283
|
+
*/
|
|
2284
|
+
type ShouldUseNativeResumeFn = (sessionContext?: StartAgentOptions['sessionContext']) => boolean;
|
|
2285
|
+
/**
|
|
2286
|
+
* Shared start/send-message execution pipeline for AIAgent.
|
|
2287
|
+
*/
|
|
2288
|
+
declare class AgentTurnExecutor {
|
|
2289
|
+
private readonly agentId;
|
|
2290
|
+
private readonly adapterId;
|
|
2291
|
+
private readonly sessionId?;
|
|
2292
|
+
private readonly adapterCapabilities;
|
|
2293
|
+
private readonly globalBus;
|
|
2294
|
+
private readonly getConnector;
|
|
2295
|
+
private readonly shouldUseNativeResume;
|
|
2296
|
+
private readonly onMessageHandle;
|
|
2297
|
+
private readonly onBeforeDispatch?;
|
|
2298
|
+
private readonly ephemeral;
|
|
2299
|
+
constructor(config: AgentTurnExecutorConfig);
|
|
2300
|
+
/**
|
|
2301
|
+
* Execute the turn pipeline for agent.sendMessage.
|
|
2302
|
+
* @param payload - agent.sendMessage request payload
|
|
2303
|
+
* @returns Resolved messageId from connector handle
|
|
2304
|
+
*/
|
|
2305
|
+
executeSendMessage(payload: SendMessageRequestPayload): Promise<{
|
|
2306
|
+
messageId: string;
|
|
2307
|
+
}>;
|
|
2308
|
+
/**
|
|
2309
|
+
* Execute the turn pipeline for agent.start.
|
|
2310
|
+
* @param message - Initial message payload
|
|
2311
|
+
* @param options - Start options from caller
|
|
2312
|
+
* @param systemPrompt - Runtime system prompt chosen by AIAgent
|
|
2313
|
+
* @param responseSchema - Runtime structured output descriptor chosen by AIAgent
|
|
2314
|
+
* @returns Agent start result from connector
|
|
2315
|
+
*/
|
|
2316
|
+
executeStart(message: NormalizedMessageInput | MessageInput, options: StartAgentOptions | undefined, systemPrompt: StartAgentOptions['systemPrompt'], responseSchema?: ResponseSchemaDescriptor): Promise<AgentStartResult>;
|
|
2317
|
+
/**
|
|
2318
|
+
* Resolve the pre-user hook result or preserve the caller payload for ephemeral turns.
|
|
2319
|
+
* @param input - Message and context for the outgoing user turn
|
|
2320
|
+
* @returns Message and session context to dispatch to the connector
|
|
2321
|
+
*/
|
|
2322
|
+
private resolvePreUserMessageTurn;
|
|
2323
|
+
/**
|
|
2324
|
+
* Fire PostUserMessage hooks without blocking the turn.
|
|
2325
|
+
* @param messageId - Message ID for correlation
|
|
2326
|
+
*/
|
|
2327
|
+
private firePostUserMessageHooks;
|
|
2328
|
+
}
|
|
2329
|
+
//#endregion
|
|
2330
|
+
//#region adapters/core/src/adapter/types.d.ts
|
|
2331
|
+
/** Payload type for adapter.startAgent requests. */
|
|
2332
|
+
type StartAgentRequestPayload = ExtractSubjectPayload<typeof AdapterSubjects.startAgent>;
|
|
2333
|
+
/**
|
|
2334
|
+
* Options for creating an agent, derived from a subset of `StartAgentRequestPayload`.
|
|
2335
|
+
* Used by both `handleStartAgent` and the rehydration module.
|
|
2336
|
+
*
|
|
2337
|
+
* `providerContext` is typed directly as `ProviderContext` (not via `Pick` from the
|
|
2338
|
+
* inferred payload type) because Zod loses the `CredentialRef` brand when it infers
|
|
2339
|
+
* through complex union schemas. Using the canonical TypeScript type preserves
|
|
2340
|
+
* the brand and ensures `resolveConnectorCredentials()` receives the correct type.
|
|
2341
|
+
*/
|
|
2342
|
+
type AgentCreationOptions = Omit<Partial<Pick<StartAgentRequestPayload, 'model' | 'cwd' | 'env' | 'allowedTools' | 'disallowedTools' | 'reasoningEffort' | 'mode' | 'mcpSessionContext' | 'harnessId' | 'clientId' | 'clientProfileName' | 'providerContext' | 'ephemeral'>>, 'providerContext'> & {
|
|
2343
|
+
adapterSessionId?: string; /** Unresolved provider context (credential refs, not plaintext). */
|
|
2344
|
+
providerContext?: ProviderContext;
|
|
2345
|
+
};
|
|
2346
|
+
/**
|
|
2347
|
+
* Cumulative usage totals tracked per agent.
|
|
2348
|
+
*
|
|
2349
|
+
* Token totals (`totalInputTokens`, `totalOutputTokens`) are fully restored on
|
|
2350
|
+
* rehydration by summing persisted turn history, so they reflect the lifetime
|
|
2351
|
+
* of the session across process restarts.
|
|
2352
|
+
*
|
|
2353
|
+
* `totalCalls` is intentionally **not** restored on rehydration: it is reset to
|
|
2354
|
+
* zero on each process start because the historical number of API calls is not
|
|
2355
|
+
* stored per-turn with sufficient fidelity to reconstruct accurately (one turn
|
|
2356
|
+
* may represent multiple API calls for streaming or multi-step adapters).
|
|
2357
|
+
* Treat `totalCalls` as "calls since last process start", not a lifetime count.
|
|
2358
|
+
*/
|
|
2359
|
+
interface AgentUsageTotals {
|
|
2360
|
+
totalInputTokens: number;
|
|
2361
|
+
totalOutputTokens: number;
|
|
2362
|
+
totalCalls: number;
|
|
2363
|
+
}
|
|
2364
|
+
/** Result from creating an agent runtime. */
|
|
2365
|
+
interface AgentRuntimeCreationResult {
|
|
2366
|
+
cleanup: () => void;
|
|
2367
|
+
}
|
|
2368
|
+
/**
|
|
2369
|
+
* Configuration for AIAdapter constructor.
|
|
2370
|
+
* @typeParam TBus - Scoped bus type for adapter-specific events
|
|
2371
|
+
*/
|
|
2372
|
+
interface AIAdapterConfig<TBus extends ScopedBus<string> = ScopedBus<string>> {
|
|
2373
|
+
/** Unique adapter name (e.g., 'openai-node', 'claude-code'). */
|
|
2374
|
+
name: string;
|
|
2375
|
+
/** Adapter capabilities (e.g., ['streaming', 'tools', 'vision']). */
|
|
2376
|
+
capabilities: string[];
|
|
2377
|
+
/** Native tools built into the adapter (e.g., ['shell_command', 'apply_patch']). */
|
|
2378
|
+
nativeTools?: string[];
|
|
2379
|
+
/** Adapter namespace for creating scoped bus. Bus created lazily in init(). */
|
|
2380
|
+
namespace: AdapterNamespace;
|
|
2381
|
+
/** Optional pre-generated adapter ID. Defaults to UUID. */
|
|
2382
|
+
adapterId?: string;
|
|
2383
|
+
/** Optional global bus override. Defaults to MakaioBus singleton. */
|
|
2384
|
+
globalBus?: IMakaioBus;
|
|
2385
|
+
scopedBus?: TBus;
|
|
2386
|
+
/**
|
|
2387
|
+
* Optional log import configuration.
|
|
2388
|
+
* When enabled, the adapter will watch for external session logs and import them as Makaio events.
|
|
2389
|
+
*/
|
|
2390
|
+
logImport?: LogImportConfig;
|
|
2391
|
+
/** Provider definitions for model lookup. Injected by runtime. */
|
|
2392
|
+
definitionProviders?: readonly AdapterProviderDefinition[];
|
|
2393
|
+
/** Client identifier for the application this adapter belongs to (e.g., 'claude-code', 'codex'). Omit for API-only adapters. */
|
|
2394
|
+
clientId?: string;
|
|
2395
|
+
}
|
|
2396
|
+
/**
|
|
2397
|
+
* Full constructor config including factory injections.
|
|
2398
|
+
*
|
|
2399
|
+
* Replaces the inline intersection type previously used in `AIAdapter`'s
|
|
2400
|
+
* constructor signature.
|
|
2401
|
+
* @typeParam TBus - Scoped bus type for adapter-specific events
|
|
2402
|
+
* @typeParam TConnector - Connector type bridging to the AI SDK
|
|
2403
|
+
* @typeParam TAgent - Agent implementation type (must extend AIAgent)
|
|
2404
|
+
*/
|
|
2405
|
+
interface AIAdapterConstructorConfig<TBus extends ScopedBus<string>, TConnector extends AIAgentConnector<TBus>, TAgent extends AIAgent<TBus, TConnector>> extends AIAdapterConfig {
|
|
2406
|
+
/** Factory to create agent instances from config. */
|
|
2407
|
+
agentFactory: (agentConfig: AIAgentConfig<TBus, TConnector>) => TAgent;
|
|
2408
|
+
/** Config factory — transforms partial input into full adapter-specific config (includes adapterId). */
|
|
2409
|
+
configFactory: (input: ConfigFactoryInput<TBus>) => Promise<BaseAgentConnectorConfig<TBus> & {
|
|
2410
|
+
adapterId: string;
|
|
2411
|
+
}>;
|
|
2412
|
+
/** Connector factory — creates connector from full config (includes adapterId). */
|
|
2413
|
+
connectorFactory: (config: BaseAgentConnectorConfig<TBus> & {
|
|
2414
|
+
adapterId: string;
|
|
2415
|
+
}) => TConnector | Promise<TConnector>;
|
|
2416
|
+
/** Platform-provided defaults (cwd, env). Injected by runtime. */
|
|
2417
|
+
platformDefaults?: PlatformDefaults;
|
|
2418
|
+
/** Provider definitions for model lookup. Injected by runtime. */
|
|
2419
|
+
definitionProviders?: readonly AdapterProviderDefinition[];
|
|
2420
|
+
}
|
|
2421
|
+
//#endregion
|
|
2422
|
+
//#region adapters/core/src/agent/agent-connector-lifecycle-manager.d.ts
|
|
2423
|
+
/**
|
|
2424
|
+
* Dependencies for connector lifecycle management.
|
|
2425
|
+
*/
|
|
2426
|
+
interface AgentConnectorLifecycleManagerConfig<TBus extends ScopedBus<string>, TConnector extends AIAgentConnector<TBus>> {
|
|
2427
|
+
/** Stable agent identifier (used for diagnostics). */
|
|
2428
|
+
agentId: string;
|
|
2429
|
+
/** Create config input for connector/config factories. */
|
|
2430
|
+
buildConfigInput: (overrides?: Partial<{
|
|
2431
|
+
cwd: string;
|
|
2432
|
+
model: string;
|
|
2433
|
+
providerContext: ProviderContext;
|
|
2434
|
+
adapterSessionId: string;
|
|
2435
|
+
mcpSessionContext: McpRuntimeSessionContext | McpSessionContext | LedgerSessionContext;
|
|
2436
|
+
}>) => ConfigFactoryInput<TBus>;
|
|
2437
|
+
/** Adapter config factory from AIAgent config. */
|
|
2438
|
+
configFactory: (input: ConfigFactoryInput<TBus>) => Promise<BaseAgentConnectorConfig<TBus> & {
|
|
2439
|
+
adapterId: string;
|
|
2440
|
+
}>;
|
|
2441
|
+
/** Connector factory from AIAgent config. */
|
|
2442
|
+
connectorFactory: (config: BaseAgentConnectorConfig<TBus> & {
|
|
2443
|
+
adapterId: string;
|
|
2444
|
+
}) => Promise<TConnector> | TConnector;
|
|
2445
|
+
/** Build onMessageSent callback for connector creation. */
|
|
2446
|
+
createOnMessageSent: () => (handle: MessageHandle) => void;
|
|
2447
|
+
/** Wire adapter-specific events on a connector instance. */
|
|
2448
|
+
wireEvents: (connector: TConnector) => void | Promise<void>;
|
|
2449
|
+
/** Emit idle lifecycle event on processing-state idle transitions. */
|
|
2450
|
+
emitIdle: () => Promise<void>;
|
|
2451
|
+
/** Get current connector for swap guards/baseline values. */
|
|
2452
|
+
getConnector: () => TConnector;
|
|
2453
|
+
/** Replace active connector reference on successful swap. */
|
|
2454
|
+
setConnector: (connector: TConnector) => void;
|
|
2455
|
+
/** Get runtime system prompt to preserve across swaps. */
|
|
2456
|
+
getRuntimeSystemPrompt: () => SystemPrompt | undefined;
|
|
2457
|
+
/** Store latest adapter session ID for enrichment after swaps. */
|
|
2458
|
+
setLastKnownAdapterSessionId: (adapterSessionId: string | undefined) => void;
|
|
2459
|
+
}
|
|
2460
|
+
/**
|
|
2461
|
+
* Manages connector lifecycle for AIAgent.
|
|
2462
|
+
*
|
|
2463
|
+
* Owns per-connector wiring cleanup registration and swap lifecycle choreography.
|
|
2464
|
+
*/
|
|
2465
|
+
declare class AgentConnectorLifecycleManager<TBus extends ScopedBus<string>, TConnector extends AIAgentConnector<TBus>> {
|
|
2466
|
+
/** Cleanup functions for connector event wiring (cleared on each connector swap) */
|
|
2467
|
+
private connectorWiringCleanups;
|
|
2468
|
+
private readonly config;
|
|
2469
|
+
constructor(config: AgentConnectorLifecycleManagerConfig<TBus, TConnector>);
|
|
2470
|
+
/**
|
|
2471
|
+
* Register a cleanup function for connector wiring.
|
|
2472
|
+
* @param cleanup - Cleanup function to register
|
|
2473
|
+
*/
|
|
2474
|
+
addConnectorWiringCleanup(cleanup: () => void): void;
|
|
2475
|
+
/**
|
|
2476
|
+
* Clear connector wiring cleanups.
|
|
2477
|
+
*/
|
|
2478
|
+
clearConnectorWiring(): void;
|
|
2479
|
+
/**
|
|
2480
|
+
* Wire base and adapter-specific connector events.
|
|
2481
|
+
* @param connector - Connector instance to wire
|
|
2482
|
+
*/
|
|
2483
|
+
wireAllConnectorEvents(connector: TConnector): Promise<void>;
|
|
2484
|
+
/**
|
|
2485
|
+
* Replace the active connector with a fresh instance.
|
|
2486
|
+
*
|
|
2487
|
+
* Uses create-before-close pattern with rollback to preserve availability.
|
|
2488
|
+
* @param configOverrides - Optional runtime override fields
|
|
2489
|
+
*/
|
|
2490
|
+
swapConnector(configOverrides?: Partial<{
|
|
2491
|
+
cwd: string;
|
|
2492
|
+
model: string;
|
|
2493
|
+
providerContext: ProviderContext;
|
|
2494
|
+
mcpSessionContext: McpRuntimeSessionContext | McpSessionContext | LedgerSessionContext;
|
|
2495
|
+
}>): Promise<void>;
|
|
2496
|
+
}
|
|
2497
|
+
//#endregion
|
|
2498
|
+
//#region adapters/core/src/agent/agent-lifecycle-emitter.d.ts
|
|
2499
|
+
/**
|
|
2500
|
+
* Dependencies for AgentLifecycleEmitter.
|
|
2501
|
+
*/
|
|
2502
|
+
interface AgentLifecycleEmitterConfig {
|
|
2503
|
+
/** Stable agent identifier for persistence updates. */
|
|
2504
|
+
agentId: string;
|
|
2505
|
+
/** Global bus for best-effort status updates. */
|
|
2506
|
+
globalBus: IMakaioBus;
|
|
2507
|
+
/** Emit callback for `agent.started`. */
|
|
2508
|
+
emitStarted: (payload: Omit<AgentStarted, 'agentId' | 'adapterId' | 'adapterName' | 'adapterSessionId'>) => Promise<void>;
|
|
2509
|
+
/** Emit callback for `agent.complete`. */
|
|
2510
|
+
emitComplete: (payload: Omit<z.infer<typeof AgentSchemas.complete>, keyof AgentContext>) => Promise<void>;
|
|
2511
|
+
/** Emit callback for `agent.session.closed`. */
|
|
2512
|
+
emitSessionClosed: (payload: {
|
|
2513
|
+
reason?: string;
|
|
2514
|
+
}) => Promise<void>;
|
|
2515
|
+
/** Hook executed before terminal completion emission. */
|
|
2516
|
+
onBeforeEmitCompletion: () => Promise<void>;
|
|
2517
|
+
/** Clear tool-call tracker entries on terminal outcomes. */
|
|
2518
|
+
clearToolCallTracker: () => void;
|
|
2519
|
+
}
|
|
2520
|
+
/**
|
|
2521
|
+
* Stateful lifecycle emitter for AIAgent terminal/start/session events.
|
|
2522
|
+
*/
|
|
2523
|
+
declare class AgentLifecycleEmitter {
|
|
2524
|
+
/** Tracks whether session.closed has been emitted (emit only once). */
|
|
2525
|
+
private sessionClosedEmitted;
|
|
2526
|
+
/** Tracks whether agent.started has been emitted (lifecycle invariant). */
|
|
2527
|
+
private agentStartedEmitted;
|
|
2528
|
+
/** Tracks whether agent.complete has been emitted for the current turn. */
|
|
2529
|
+
private agentCompleteEmitted;
|
|
2530
|
+
/** Stashed error category consumed by the next emitCompletion call. */
|
|
2531
|
+
private pendingErrorCategory?;
|
|
2532
|
+
private readonly config;
|
|
2533
|
+
constructor(config: AgentLifecycleEmitterConfig);
|
|
2534
|
+
/**
|
|
2535
|
+
* Emit `agent.started` and reset per-turn lifecycle state.
|
|
2536
|
+
* @param event - Start payload without auto-enriched AgentContext fields
|
|
2537
|
+
*/
|
|
2538
|
+
emitStart(event: Omit<AgentStarted, 'agentId' | 'adapterId' | 'adapterName' | 'adapterSessionId'>): Promise<void>;
|
|
2539
|
+
/**
|
|
2540
|
+
* Reset per-turn dedup state so the next completion can fire.
|
|
2541
|
+
*
|
|
2542
|
+
* Called when a new message handle is tracked — guarantees the guard
|
|
2543
|
+
* resets per-turn even for adapters that don't emit `agent.started`
|
|
2544
|
+
* on every turn (e.g., codex emits `thread_started` once per thread).
|
|
2545
|
+
*/
|
|
2546
|
+
resetTurnState(): void;
|
|
2547
|
+
/**
|
|
2548
|
+
* Emit terminal completion event with deferred error-category propagation.
|
|
2549
|
+
* @param result - Completion payload without AgentContext fields
|
|
2550
|
+
*/
|
|
2551
|
+
emitCompletion(result: Omit<z.infer<typeof AgentSchemas.complete>, keyof AgentContext>): Promise<void>;
|
|
2552
|
+
/**
|
|
2553
|
+
* Stash error metadata for the next completion emission.
|
|
2554
|
+
* @param result - Error payload from connector/runtime error handler
|
|
2555
|
+
*/
|
|
2556
|
+
emitError(result: Pick<z.infer<typeof AgentSchemas.complete>, 'error' | 'errorCategory'>): void;
|
|
2557
|
+
/**
|
|
2558
|
+
* Emit `agent.session.closed` once for this agent lifecycle.
|
|
2559
|
+
* @param reason - Optional closure reason
|
|
2560
|
+
*/
|
|
2561
|
+
emitSessionClosed(reason?: string): void;
|
|
2562
|
+
}
|
|
2563
|
+
//#endregion
|
|
2564
|
+
//#region adapters/core/src/agent/agent-payload-emitter.d.ts
|
|
2565
|
+
interface AgentPayloadEventMetadata {
|
|
2566
|
+
clientId?: string;
|
|
2567
|
+
providerConfigId?: string;
|
|
2568
|
+
occurredAt?: number;
|
|
2569
|
+
}
|
|
2570
|
+
interface AgentPayloadEventFields extends AgentPayloadEventMetadata {
|
|
2571
|
+
messageId?: string;
|
|
2572
|
+
turnId?: string;
|
|
2573
|
+
sessionId?: string;
|
|
2574
|
+
}
|
|
2575
|
+
interface EmitGlobalOptions {
|
|
2576
|
+
includeEventMetadata?: boolean;
|
|
2577
|
+
}
|
|
2578
|
+
/**
|
|
2579
|
+
* Dependencies for AgentPayloadEmitter.
|
|
2580
|
+
*/
|
|
2581
|
+
interface AgentPayloadEmitterConfig {
|
|
2582
|
+
/** Global bus for outbound emissions. */
|
|
2583
|
+
globalBus: IMakaioBus;
|
|
2584
|
+
/** Stable agent identity fields. */
|
|
2585
|
+
getAgentContextBase: () => Pick<AgentContext, 'agentId' | 'adapterId' | 'adapterName'> & {
|
|
2586
|
+
sessionId?: string;
|
|
2587
|
+
};
|
|
2588
|
+
/** Current messageId from lifecycle tracker, if any. */
|
|
2589
|
+
getCurrentMessageId: () => string | undefined;
|
|
2590
|
+
/** Current turnId from lifecycle tracker, if any. */
|
|
2591
|
+
getCurrentTurnId: () => string | undefined;
|
|
2592
|
+
/** Connector adapterSessionId, if currently available. */
|
|
2593
|
+
getConnectorAdapterSessionId: () => string | undefined;
|
|
2594
|
+
/** Last known adapterSessionId cached across connector swaps. */
|
|
2595
|
+
getLastKnownAdapterSessionId: () => string | undefined;
|
|
2596
|
+
/** Persist latest adapterSessionId after resolution. */
|
|
2597
|
+
setLastKnownAdapterSessionId: (adapterSessionId: string | undefined) => void;
|
|
2598
|
+
/** Async fallback to wait for adapter session ID. */
|
|
2599
|
+
getAdapterSessionId: () => Promise<string>;
|
|
2600
|
+
/** Live event metadata defaults resolved from current runtime state. */
|
|
2601
|
+
getEventMetadataDefaults: () => AgentPayloadEventMetadata;
|
|
2602
|
+
}
|
|
2603
|
+
/**
|
|
2604
|
+
* Handles agent context enrichment and global bus emissions.
|
|
2605
|
+
*/
|
|
2606
|
+
declare class AgentPayloadEmitter {
|
|
2607
|
+
private readonly config;
|
|
2608
|
+
/**
|
|
2609
|
+
* Create a payload emitter with context resolution dependencies.
|
|
2610
|
+
* @param config - Config controlling agent-context enrichment and global emissions
|
|
2611
|
+
*/
|
|
2612
|
+
constructor(config: AgentPayloadEmitterConfig);
|
|
2613
|
+
/**
|
|
2614
|
+
* Enrich payload with agent context fields.
|
|
2615
|
+
* @param payload - Base payload to enrich
|
|
2616
|
+
* @param overrideMessageId - Explicit messageId override from caller payload
|
|
2617
|
+
* @param options - Enrichment controls for optional analytics metadata defaults
|
|
2618
|
+
* @returns Enriched payload with agent context
|
|
2619
|
+
*/
|
|
2620
|
+
enrichPayload<T extends object>(payload: T, overrideMessageId?: string, options?: EmitGlobalOptions): Promise<T & AgentContext & AgentPayloadEventFields>;
|
|
2621
|
+
/**
|
|
2622
|
+
* Emit enriched payload to global bus.
|
|
2623
|
+
* @param subject - Subject definition to emit
|
|
2624
|
+
* @param payload - Payload without AgentContext fields
|
|
2625
|
+
* @param options - Enrichment controls for optional analytics metadata defaults
|
|
2626
|
+
*/
|
|
2627
|
+
emitGlobal<S extends SubjectDefinition>(subject: S, payload: Omit<ExtractSubjectPayload<S>, keyof AgentContext> & {
|
|
2628
|
+
messageId?: string;
|
|
2629
|
+
}, options?: EmitGlobalOptions): Promise<void>;
|
|
2630
|
+
}
|
|
2631
|
+
//#endregion
|
|
2632
|
+
//#region adapters/core/src/agent/agent-bus-handler-registrar.d.ts
|
|
2633
|
+
/**
|
|
2634
|
+
* Handler bundle required to register all `agent.*` request handlers.
|
|
2635
|
+
*/
|
|
2636
|
+
interface AgentBusHandlerRegistrarConfig {
|
|
2637
|
+
/** Global bus instance where handlers are registered. */
|
|
2638
|
+
globalBus: IMakaioBus;
|
|
2639
|
+
/** Target agent identity for filter scoping. */
|
|
2640
|
+
agentId: string;
|
|
2641
|
+
/** Handler for `agent.sendMessage`. */
|
|
2642
|
+
onSendMessage: (ctx: RequestContext<SendMessageRequestPayload, SendMessageResponsePayload>) => Promise<void>;
|
|
2643
|
+
/** Handler for `agent.interrupt`. */
|
|
2644
|
+
onInterrupt: (ctx: RequestContext<AgentInterruptRequestPayload, AgentInterruptResponsePayload>) => Promise<void>;
|
|
2645
|
+
/** Provider for `agent.getCapabilities` response payload. */
|
|
2646
|
+
getCapabilities: () => GetCapabilitiesResponsePayload;
|
|
2647
|
+
/** Handler for `agent.cwd.change`. */
|
|
2648
|
+
onCwdChange: (ctx: RequestContext<AgentCwdChangeRequestPayload, AgentCwdChangeResponsePayload>) => Promise<void>;
|
|
2649
|
+
/** Handler for `agent.model.change`. */
|
|
2650
|
+
onModelChange: (ctx: RequestContext<AgentModelChangeRequestPayload, AgentModelChangeResponsePayload>) => Promise<void>;
|
|
2651
|
+
/** Handler for `agent.mcp.servers.set`. */
|
|
2652
|
+
onMcpServersSet: (ctx: RequestContext<AgentMcpServersSetRequestPayload, AgentMcpServersSetResponsePayload>) => Promise<void>;
|
|
2653
|
+
/** Handler for `agent.credential.change`. */
|
|
2654
|
+
onCredentialChange: (ctx: RequestContext<AgentCredentialChangeRequestPayload, AgentCredentialChangeResponsePayload>) => Promise<void>;
|
|
2655
|
+
}
|
|
2656
|
+
/**
|
|
2657
|
+
* Register all stable `agent.*` bus handlers for a single agent instance.
|
|
2658
|
+
* @param config - Registration configuration with handlers
|
|
2659
|
+
* @returns Cleanup functions for all registrations
|
|
2660
|
+
*/
|
|
2661
|
+
declare function registerAgentBusHandlers(config: AgentBusHandlerRegistrarConfig): Array<() => void>;
|
|
2662
|
+
//#endregion
|
|
2663
|
+
//#region adapters/core/src/agent/agent-runtime-mutation-manager-config.d.ts
|
|
2664
|
+
/** Connector fields that can be overridden during runtime connector swaps. */
|
|
2665
|
+
interface AgentRuntimeConnectorOverrides {
|
|
2666
|
+
cwd: string;
|
|
2667
|
+
model: string;
|
|
2668
|
+
providerContext: ProviderContext;
|
|
2669
|
+
mcpSessionContext: McpRuntimeSessionContext | McpSessionContext | LedgerSessionContext;
|
|
2670
|
+
}
|
|
2671
|
+
/** Dependencies for runtime mutation handling. */
|
|
2672
|
+
interface AgentRuntimeMutationManagerConfig {
|
|
2673
|
+
/** Stable agent identifier. */
|
|
2674
|
+
agentId: string;
|
|
2675
|
+
/** Optional Makaio session identifier. */
|
|
2676
|
+
sessionId?: string;
|
|
2677
|
+
/** Global bus for persistence and events. */
|
|
2678
|
+
globalBus: IMakaioBus;
|
|
2679
|
+
/** Read current connector. */
|
|
2680
|
+
getConnector: () => AIAgentConnector;
|
|
2681
|
+
/** Swap connector with runtime overrides. */
|
|
2682
|
+
swapConnector: (configOverrides?: Partial<AgentRuntimeConnectorOverrides>) => Promise<void>;
|
|
2683
|
+
/** Emit cwd.changed payload. */
|
|
2684
|
+
emitCwdChanged: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.cwd.changed>, 'agentId' | 'adapterId' | 'adapterName' | 'adapterSessionId'>) => Promise<void>;
|
|
2685
|
+
/** Emit model.changed payload. */
|
|
2686
|
+
emitModelChanged: (payload: Omit<ExtractSubjectPayload<typeof AgentSubjects.model.changed>, 'agentId' | 'adapterId' | 'adapterName' | 'adapterSessionId'>) => Promise<void>;
|
|
2687
|
+
/** Read the agent's current provider context for no-op detection. */
|
|
2688
|
+
getProviderContext: () => ProviderContext | undefined;
|
|
2689
|
+
/** Persist provider context changes on agent config for sequential swaps. */
|
|
2690
|
+
setProviderContext: (providerContext: ProviderContext) => void;
|
|
2691
|
+
/** Persist reasoning effort changes on agent config for sequential swaps. */
|
|
2692
|
+
setReasoningEffort: (reasoningEffort: AIReasoningLevel$1 | undefined) => void;
|
|
2693
|
+
/** Persist MCP session context changes on agent config for sequential swaps. */
|
|
2694
|
+
setMcpSessionContext: (mcpSessionContext: McpRuntimeSessionContext | McpSessionContext | LedgerSessionContext | undefined) => void;
|
|
2695
|
+
/** Resolve supported reasoning levels for a model from the agent's available models. */
|
|
2696
|
+
resolveSupportedReasoningLevels: (model: string) => ReasoningLevelMap$1 | undefined;
|
|
2697
|
+
}
|
|
2698
|
+
//#endregion
|
|
2699
|
+
//#region adapters/core/src/agent/agent-runtime-mutation-manager.d.ts
|
|
2700
|
+
/**
|
|
2701
|
+
* Handles runtime mutation requests for AIAgent (cwd/model/credential changes).
|
|
2702
|
+
*/
|
|
2703
|
+
declare class AgentRuntimeMutationManager {
|
|
2704
|
+
private readonly agentId;
|
|
2705
|
+
private readonly sessionId?;
|
|
2706
|
+
private readonly globalBus;
|
|
2707
|
+
private readonly getConnector;
|
|
2708
|
+
private readonly swapConnector;
|
|
2709
|
+
private readonly emitCwdChanged;
|
|
2710
|
+
private readonly emitModelChanged;
|
|
2711
|
+
private readonly getProviderContext;
|
|
2712
|
+
private readonly setProviderContext;
|
|
2713
|
+
private readonly setReasoningEffort;
|
|
2714
|
+
private readonly setMcpSessionContext;
|
|
2715
|
+
private readonly resolveSupportedReasoningLevels;
|
|
2716
|
+
private readonly mcpServersMutationManager;
|
|
2717
|
+
private readonly credentialChangeSequencer;
|
|
2718
|
+
private stagedModelChange?;
|
|
2719
|
+
constructor(config: AgentRuntimeMutationManagerConfig);
|
|
2720
|
+
/**
|
|
2721
|
+
* Handle `agent.cwd.change` request.
|
|
2722
|
+
* @param payload - CWD change request payload
|
|
2723
|
+
* @returns CWD mutation response payload
|
|
2724
|
+
*/
|
|
2725
|
+
handleCwdChange(payload: AgentCwdChangeRequestPayload): Promise<AgentCwdChangeResponsePayload>;
|
|
2726
|
+
/**
|
|
2727
|
+
* Apply staged runtime mutations before dispatching the next user turn.
|
|
2728
|
+
*
|
|
2729
|
+
* Staged changes are accepted while a turn is active, but they must not touch
|
|
2730
|
+
* the live connector until the next turn boundary. The turn executor calls
|
|
2731
|
+
* this before handing a new message to the connector, when the connector is
|
|
2732
|
+
* expected to be idle.
|
|
2733
|
+
*/
|
|
2734
|
+
applyStagedMutations(): Promise<void>;
|
|
2735
|
+
/**
|
|
2736
|
+
* Handle `agent.mcp.servers.set` request.
|
|
2737
|
+
* @param payload - MCP server replacement request payload
|
|
2738
|
+
* @returns MCP mutation response payload
|
|
2739
|
+
*/
|
|
2740
|
+
handleMcpServersSet(payload: AgentMcpServersSetRequestPayload): Promise<AgentMcpServersSetResponsePayload>;
|
|
2741
|
+
/**
|
|
2742
|
+
* Handle `agent.model.change` request.
|
|
2743
|
+
*
|
|
2744
|
+
* Implements a four-branch decision tree based on the presence of `newModel`
|
|
2745
|
+
* and `reasoningEffort` in the request payload:
|
|
2746
|
+
*
|
|
2747
|
+
* - Both present → change model, then apply reasoningEffort (with fallback)
|
|
2748
|
+
* - Model only → change model, run fallback chain for reasoning
|
|
2749
|
+
* - Effort only → change reasoning in-place, no model swap logic
|
|
2750
|
+
* - Neither → no-op (return current state)
|
|
2751
|
+
* @param payload - Model change request payload
|
|
2752
|
+
* @returns Model mutation response payload
|
|
2753
|
+
*/
|
|
2754
|
+
handleModelChange(payload: AgentModelChangeRequestPayload): Promise<AgentModelChangeResponsePayload>;
|
|
2755
|
+
/**
|
|
2756
|
+
* Apply an in-place reasoning-effort change when no model swap is requested.
|
|
2757
|
+
* @param connector - The active connector
|
|
2758
|
+
* @param currentModel - Current model identifier
|
|
2759
|
+
* @param previousReasoningEffort - Reasoning effort before this change
|
|
2760
|
+
* @param reasoningEffort - Requested effort level
|
|
2761
|
+
* @returns Model mutation response payload
|
|
2762
|
+
*/
|
|
2763
|
+
private handleReasoningOnlyChange;
|
|
2764
|
+
/**
|
|
2765
|
+
* Execute the model-swap path, settling the connector then resolving reasoning.
|
|
2766
|
+
*
|
|
2767
|
+
* **Fallback chain** for reasoning when the request does not specify an effort level:
|
|
2768
|
+
* 1. Previous connector's `currentReasoningEffort` — if supported by the new model
|
|
2769
|
+
* 2. `'medium'` — if supported by the new model
|
|
2770
|
+
* 3. First key declared in the new model's `supportedReasoningLevels`
|
|
2771
|
+
* 4. `undefined` — model does not support reasoning
|
|
2772
|
+
* @param options - Swap options bundle
|
|
2773
|
+
* @returns Model mutation response payload
|
|
2774
|
+
*/
|
|
2775
|
+
private handleModelSwap;
|
|
2776
|
+
/**
|
|
2777
|
+
* Resolve the reasoning effort to apply after a model change.
|
|
2778
|
+
*
|
|
2779
|
+
* Fallback chain:
|
|
2780
|
+
* 1. Requested `effort` — if supported by the new model
|
|
2781
|
+
* 2. Previous connector's `currentReasoningEffort` — if supported by the new model
|
|
2782
|
+
* 3. `'medium'` — if supported by the new model
|
|
2783
|
+
* 4. First key declared in `supportedReasoningLevels`
|
|
2784
|
+
* 5. `undefined` — model does not support reasoning
|
|
2785
|
+
* @param requestedEffort - Effort level from the change request (may be absent)
|
|
2786
|
+
* @param previousEffort - Current connector's reasoning effort before the change
|
|
2787
|
+
* @param supportedLevels - Reasoning levels declared by the new model
|
|
2788
|
+
* @returns The resolved reasoning level, or `undefined` if unsupported
|
|
2789
|
+
*/
|
|
2790
|
+
private resolveReasoningEffort;
|
|
2791
|
+
/**
|
|
2792
|
+
* Confirm a connector swap when the model itself changes.
|
|
2793
|
+
*
|
|
2794
|
+
* Provider-only swaps skip the dialog because there is no model transition to
|
|
2795
|
+
* explain to the user. Model changes retain the existing warning/edit-history
|
|
2796
|
+
* workflow.
|
|
2797
|
+
* @param currentModel - Active model before the requested swap
|
|
2798
|
+
* @param newModel - Requested target model
|
|
2799
|
+
* @param skipWarning - Whether trusted callers opted out of the warning UI
|
|
2800
|
+
* @returns Proceed/result tuple for the caller
|
|
2801
|
+
*/
|
|
2802
|
+
private confirmConnectorSwap;
|
|
2803
|
+
/**
|
|
2804
|
+
* Compare provider contexts using the full public-bus shape.
|
|
2805
|
+
*
|
|
2806
|
+
* Provider switches are not limited to config identity. Endpoint overrides,
|
|
2807
|
+
* credential refs, and env-var mappings all influence connector behaviour, so
|
|
2808
|
+
* callers that mutate any of those fields must force a connector rebuild.
|
|
2809
|
+
* @param current - Persisted agent provider context
|
|
2810
|
+
* @param next - Incoming provider context from the mutation request
|
|
2811
|
+
* @returns True when the effective provider configuration changed
|
|
2812
|
+
*/
|
|
2813
|
+
private hasProviderContextChanged;
|
|
2814
|
+
/**
|
|
2815
|
+
* Compare two string-keyed records, treating absent and empty consistently.
|
|
2816
|
+
* @param left - First record
|
|
2817
|
+
* @param right - Second record
|
|
2818
|
+
* @returns True when both records contain the same keys and values
|
|
2819
|
+
*/
|
|
2820
|
+
private haveEqualStringRecords;
|
|
2821
|
+
/**
|
|
2822
|
+
* Handle a credential rotation request.
|
|
2823
|
+
*
|
|
2824
|
+
* When a turn is active, returns `{ success: false, reason: 'turn_active' }`.
|
|
2825
|
+
* Otherwise:
|
|
2826
|
+
* 1. Rebuilds provider context from storage (validates providerConfigId)
|
|
2827
|
+
* 2. Fires `credential.activate` so extensions prepare native stores
|
|
2828
|
+
* 3. Swaps the connector with updated providerContext (forces re-resolution)
|
|
2829
|
+
* @param payload - Credential change request payload
|
|
2830
|
+
* @returns Success/failure result
|
|
2831
|
+
*/
|
|
2832
|
+
handleCredentialChanged(payload: AgentCredentialChangeRequestPayload): Promise<AgentCredentialChangeResponsePayload>;
|
|
2833
|
+
/**
|
|
2834
|
+
* Persist runtime field updates to agent storage.
|
|
2835
|
+
* @param changes - CWD/model/provider mutations to persist
|
|
2836
|
+
*/
|
|
2837
|
+
private persistRuntimeMutation;
|
|
2838
|
+
}
|
|
2839
|
+
//#endregion
|
|
2840
|
+
//#region adapters/core/src/agent/mcp-call-extractor.d.ts
|
|
2841
|
+
/**
|
|
2842
|
+
* Utilities for identifying and extracting target information from `mcp_call`
|
|
2843
|
+
* tool invocations.
|
|
2844
|
+
*
|
|
2845
|
+
* The `mcp_call` meta-tool carries its real target as the `tool` field in the
|
|
2846
|
+
* parsed JSON arguments. These helpers centralise that extraction logic so
|
|
2847
|
+
* every consumer (ledger, event bridge, analytics) uses a single, tested path.
|
|
2848
|
+
* @packageDocumentation
|
|
2849
|
+
*/
|
|
2850
|
+
/**
|
|
2851
|
+
* Extract the target MCP tool name from parsed `mcp_call` arguments.
|
|
2852
|
+
*
|
|
2853
|
+
* Conforms to the `mcp_call` input schema which defines `{ tool: z.string() }`.
|
|
2854
|
+
* Returns `undefined` for any non-conformant argument shape so callers can
|
|
2855
|
+
* skip processing without throwing.
|
|
2856
|
+
* @param args - Parsed JSON arguments object from the tool call
|
|
2857
|
+
* @returns The namespaced target tool name, or `undefined` if not conformant
|
|
2858
|
+
*/
|
|
2859
|
+
declare function extractMcpCallTarget(args: Record<string, unknown>): string | undefined;
|
|
2860
|
+
/**
|
|
2861
|
+
* Check whether a tool call name refers to the `mcp_call` meta-tool.
|
|
2862
|
+
*
|
|
2863
|
+
* Uses the canonical {@link MCP_CALL_TOOL_NAME} constant so the comparison
|
|
2864
|
+
* stays in sync with the toolset definition automatically.
|
|
2865
|
+
*
|
|
2866
|
+
* Callers are responsible for stripping provider-specific prefixes before
|
|
2867
|
+
* calling this function (e.g., Gemini's `default_api.` prefix must be
|
|
2868
|
+
* removed at the call site — see `execute-tool-calls.ts` normalizedToolName).
|
|
2869
|
+
* @param toolName - Normalized tool name from the tool call
|
|
2870
|
+
* @returns `true` if this is an `mcp_call` invocation
|
|
2871
|
+
*/
|
|
2872
|
+
declare function isMcpCallTool(toolName: string): boolean;
|
|
2873
|
+
//#endregion
|
|
2874
|
+
//#region adapters/core/src/adapter/ai-adapter.d.ts
|
|
2875
|
+
/**
|
|
2876
|
+
* Base class for AI adapters.
|
|
2877
|
+
*
|
|
2878
|
+
* An adapter manages a set of agents, handles adapter.* subjects as RPC endpoints,
|
|
2879
|
+
* and provides clear file-to-subject mapping.
|
|
2880
|
+
*
|
|
2881
|
+
* Three-layer architecture:
|
|
2882
|
+
* - AIAdapter: Handles adapter.* global subjects, owns agent tracking
|
|
2883
|
+
* - AIAgent: Handles agent.* global subjects (filtered by agentId), wraps connector
|
|
2884
|
+
* - AIAgentConnector: Owns adapter-specific namespace, SDK-level bridge
|
|
2885
|
+
*
|
|
2886
|
+
* Subject Ownership:
|
|
2887
|
+
* - `adapter.startAgent` - Creates and starts new agents (owned by AIAdapter)
|
|
2888
|
+
* - `adapter.initialized` - Emitted when adapter is ready (owned by AIAdapter)
|
|
2889
|
+
* - `adapter.session.created` - Emitted after agent starts (owned by AIAdapter)
|
|
2890
|
+
* - `session.agent.added` - Emitted to notify global session service (owned by AIAdapter)
|
|
2891
|
+
* - `agent.*` subjects - Owned by agent instances (see ai-agent.ts)
|
|
2892
|
+
* @typeParam TBus - Scoped bus type for adapter-specific events
|
|
2893
|
+
* @typeParam TConnector - Connector type bridging to the AI SDK
|
|
2894
|
+
* @typeParam TAgent - Agent implementation type (must extend AIAgent)
|
|
2895
|
+
*/
|
|
2896
|
+
declare abstract class AIAdapter<TBus extends ScopedBus<string> = ScopedBus<string>, TConnector extends AIAgentConnector<TBus> = AIAgentConnector<TBus>, TAgent extends AIAgent<TBus, TConnector> = AIAgent<TBus, TConnector>> {
|
|
2897
|
+
/** Unique identifier for this adapter instance. */
|
|
2898
|
+
readonly adapterId: string;
|
|
2899
|
+
/** Adapter name (e.g., 'openai-node', 'claude-code'). */
|
|
2900
|
+
readonly name: string;
|
|
2901
|
+
/** Adapter capabilities for runtime feature detection. */
|
|
2902
|
+
readonly capabilities: string[];
|
|
2903
|
+
/** Native tools built into the adapter (e.g., ['shell_command', 'apply_patch']). */
|
|
2904
|
+
readonly nativeTools: string[];
|
|
2905
|
+
/** Adapter namespace for creating scoped bus. */
|
|
2906
|
+
protected readonly namespace: AdapterNamespace;
|
|
2907
|
+
/** Global bus for cross-adapter communication. */
|
|
2908
|
+
protected readonly globalBus: IMakaioBus;
|
|
2909
|
+
/** Scoped bus for adapter-specific communication. Created in init(). */
|
|
2910
|
+
protected adapterBus: TBus;
|
|
2911
|
+
/** Registry of active agents with session info and usage totals. */
|
|
2912
|
+
private readonly registry;
|
|
2913
|
+
/** Cleanup functions for bus subscriptions. */
|
|
2914
|
+
private cleanupFns;
|
|
2915
|
+
/** Manages agent rehydration with single-flight deduplication. */
|
|
2916
|
+
private readonly rehydrationManager;
|
|
2917
|
+
/** Tracks whether the adapter has been initialized. */
|
|
2918
|
+
private initialized;
|
|
2919
|
+
/** Client identifier for the application this adapter belongs to (e.g., 'claude-code', 'codex'). */
|
|
2920
|
+
protected readonly clientId?: string;
|
|
2921
|
+
/** Platform-provided defaults (cwd, env) injected by runtime. Lowest priority. */
|
|
2922
|
+
protected platformDefaults?: PlatformDefaults;
|
|
2923
|
+
/** Provider definitions for model lookup. Injected by runtime. */
|
|
2924
|
+
protected readonly definitionProviders: readonly AdapterProviderDefinition[];
|
|
2925
|
+
protected agentFactory: (agentConfig: AIAgentConfig<TBus, TConnector>) => TAgent;
|
|
2926
|
+
/** Config factory - transforms partial input into full adapter-specific config (includes adapterId) */
|
|
2927
|
+
protected configFactory: (input: ConfigFactoryInput<TBus>) => Promise<BaseAgentConnectorConfig<TBus> & {
|
|
2928
|
+
adapterId: string;
|
|
2929
|
+
}>;
|
|
2930
|
+
/** Connector factory - creates connector from full config (includes adapterId) */
|
|
2931
|
+
protected connectorFactory: (config: BaseAgentConnectorConfig<TBus> & {
|
|
2932
|
+
adapterId: string;
|
|
2933
|
+
}) => TConnector | Promise<TConnector>;
|
|
2934
|
+
/**
|
|
2935
|
+
* Create a new AIAdapter instance.
|
|
2936
|
+
* Constructor is synchronous - stores config only. Call init() to complete setup.
|
|
2937
|
+
* @param config - Adapter configuration
|
|
2938
|
+
*/
|
|
2939
|
+
protected constructor(config: AIAdapterConstructorConfig<TBus, TConnector, TAgent>);
|
|
2940
|
+
/** Set up RPC handlers and event listeners. */
|
|
2941
|
+
private setupHandlers;
|
|
2942
|
+
/**
|
|
2943
|
+
* Handle agent.session.closed - cleanup agent + re-emit as adapter.session.closed.
|
|
2944
|
+
* @param ctx - Event context with session closed payload
|
|
2945
|
+
*/
|
|
2946
|
+
private handleSessionClosed;
|
|
2947
|
+
/**
|
|
2948
|
+
* Handle session.closed - evict agents when their session is closed.
|
|
2949
|
+
* @param ctx - Event context with the closed session's ID
|
|
2950
|
+
*/
|
|
2951
|
+
private handleSessionClosedByService;
|
|
2952
|
+
/**
|
|
2953
|
+
* Handle agent.usage - aggregate and emit session totals.
|
|
2954
|
+
* @param ctx - Event context with usage payload
|
|
2955
|
+
*/
|
|
2956
|
+
private handleUsage;
|
|
2957
|
+
/**
|
|
2958
|
+
* Initialize adapter - call after construction.
|
|
2959
|
+
* Creates scoped bus, sets up handlers, and emits adapter.initialized event.
|
|
2960
|
+
* Safe to call multiple times - subsequent calls are no-ops.
|
|
2961
|
+
*
|
|
2962
|
+
* Note: Agents are NOT eagerly rehydrated on startup. They are rehydrated
|
|
2963
|
+
* on-demand when messages arrive (lazy rehydration via handleRehydrateAgent).
|
|
2964
|
+
*/
|
|
2965
|
+
init(): Promise<void>;
|
|
2966
|
+
/** Hook for subclass initialization. Override to perform async setup (connections, auth, etc.). */
|
|
2967
|
+
protected onInit(): Promise<void>;
|
|
2968
|
+
/**
|
|
2969
|
+
* Create an agent instance.
|
|
2970
|
+
*
|
|
2971
|
+
* Subclasses implement this to instantiate their specific AIAgent subclass.
|
|
2972
|
+
* The agent should NOT be started yet - that's handled by startAgent after creation.
|
|
2973
|
+
* @param agentId - Pre-generated agent ID (use this, don't generate your own)
|
|
2974
|
+
* @param sessionId - Makaio session ID (created or provided based on mode)
|
|
2975
|
+
* @param request - The startAgent request payload
|
|
2976
|
+
* @returns The agent instance (NOT started yet)
|
|
2977
|
+
*/
|
|
2978
|
+
protected createAgent(agentId: string, sessionId: string, request: AgentCreationOptions): Promise<TAgent>;
|
|
2979
|
+
/**
|
|
2980
|
+
* Asynchronous cleanup for awaitable shutdown.
|
|
2981
|
+
* Runs cleanup functions, aborts agents, allows subclass cleanup via onClose hook.
|
|
2982
|
+
* @returns Promise that resolves when cleanup is complete
|
|
2983
|
+
*/
|
|
2984
|
+
closeAsync(): Promise<void>;
|
|
2985
|
+
/**
|
|
2986
|
+
* Cleanup resources and unsubscribe from bus.
|
|
2987
|
+
* Runs cleanup functions, aborts agents, allows subclass cleanup via onClose hook.
|
|
2988
|
+
*/
|
|
2989
|
+
close(): void;
|
|
2990
|
+
/** Hook for subclass cleanup. Override to perform async teardown (close connections, etc.). */
|
|
2991
|
+
protected onClose(): Promise<void>;
|
|
2992
|
+
/**
|
|
2993
|
+
* Get an agent by ID with session info.
|
|
2994
|
+
* @param agentId - Agent identifier
|
|
2995
|
+
* @returns Agent with session info, or undefined if not found
|
|
2996
|
+
*/
|
|
2997
|
+
getAgent(agentId: string): (TAgent & {
|
|
2998
|
+
sessionId: string;
|
|
2999
|
+
adapterSessionId: string;
|
|
3000
|
+
}) | undefined;
|
|
3001
|
+
/**
|
|
3002
|
+
* Dispose resources for an agent.
|
|
3003
|
+
*
|
|
3004
|
+
* Aborts the agent and removes it from the tracking map.
|
|
3005
|
+
* @param agentId - Agent identifier
|
|
3006
|
+
* @returns true if agent was found and disposed, false otherwise
|
|
3007
|
+
*/
|
|
3008
|
+
disposeAgent(agentId: string): boolean;
|
|
3009
|
+
/**
|
|
3010
|
+
* Get all active agents managed by this adapter.
|
|
3011
|
+
* @returns Array of active agents with session info
|
|
3012
|
+
*/
|
|
3013
|
+
getActiveAgents(): Array<TAgent & {
|
|
3014
|
+
sessionId: string;
|
|
3015
|
+
adapterSessionId: string;
|
|
3016
|
+
}>;
|
|
3017
|
+
/**
|
|
3018
|
+
* Check if the adapter has been initialized.
|
|
3019
|
+
* @returns true if init() has been called successfully
|
|
3020
|
+
*/
|
|
3021
|
+
isInitialized(): boolean;
|
|
3022
|
+
}
|
|
3023
|
+
//#endregion
|
|
3024
|
+
//#region adapters/core/src/types/ai-adapter-definition.d.ts
|
|
3025
|
+
/**
|
|
3026
|
+
* Definition for registering adapters with the runtime.
|
|
3027
|
+
*
|
|
3028
|
+
* Extends {@link AdapterDefinitionContract} with narrowed generic type parameters
|
|
3029
|
+
* so the `providers` array and `createAdapter` factory are typed against the
|
|
3030
|
+
* concrete adapter, connector, and bus types for this implementation.
|
|
3031
|
+
*
|
|
3032
|
+
* Used for dynamic adapter loading and registry.
|
|
3033
|
+
* @typeParam TBus - The scoped bus type for this adapter
|
|
3034
|
+
* @typeParam TConnector - The connector type
|
|
3035
|
+
* @typeParam TAgent - The agent type
|
|
3036
|
+
* @example
|
|
3037
|
+
* ```typescript
|
|
3038
|
+
* export const adapterDefinition: AIAdapterDefinition<OpenAINodeBus, OpenAINodeConnector, OpenAIAgent> = {
|
|
3039
|
+
* name: 'openai-node',
|
|
3040
|
+
* displayName: 'OpenAI',
|
|
3041
|
+
* description: 'OpenAI chat completions with streaming and tool calling',
|
|
3042
|
+
* createAdapter: (options) => createOpenAINodeAdapter({ adapterId: options?.adapterId }),
|
|
3043
|
+
* };
|
|
3044
|
+
* ```
|
|
3045
|
+
*/
|
|
3046
|
+
interface AIAdapterDefinition<TBus extends ScopedBus<string> = ScopedBus<string>, TConnector extends AIAgentConnector<TBus> = AIAgentConnector<TBus>, TAgent extends AIAgent<TBus, TConnector> = AIAgent<TBus, TConnector>> extends AdapterDefinitionContract<AIAdapter<TBus, TConnector, TAgent>, AIAdapterInitOptions> {
|
|
3047
|
+
/**
|
|
3048
|
+
* Client packages this adapter can delegate to.
|
|
3049
|
+
*
|
|
3050
|
+
* Each reference names a client extension by stable ID and declares the
|
|
3051
|
+
* compatible client package version range. Runtime initialization still
|
|
3052
|
+
* receives a selected `clientId` through {@link AIAdapterInitOptions}; this
|
|
3053
|
+
* definition field is the adapter-to-client capability declaration.
|
|
3054
|
+
*/
|
|
3055
|
+
readonly clients?: readonly AdapterClientRef[];
|
|
3056
|
+
/**
|
|
3057
|
+
* Adapter definitions declare client compatibility through {@link clients}.
|
|
3058
|
+
*
|
|
3059
|
+
* `AIAdapterInitOptions.clientId` remains the runtime-selected client
|
|
3060
|
+
* override passed to adapter factories for existing client-backed adapters.
|
|
3061
|
+
*/
|
|
3062
|
+
readonly clientId?: never;
|
|
3063
|
+
/**
|
|
3064
|
+
* Factory that creates and initializes the adapter instance.
|
|
3065
|
+
*
|
|
3066
|
+
* Inherits the typed {@link AIAdapterInitOptions} parameter from the base
|
|
3067
|
+
* contract's `TOptions` generic, carrying platform defaults, log import
|
|
3068
|
+
* config, and provider definitions injected at runtime.
|
|
3069
|
+
* @param options - Optional initialization options injected by the runtime.
|
|
3070
|
+
* @returns The initialized adapter instance.
|
|
3071
|
+
*/
|
|
3072
|
+
readonly createAdapter: (options?: AIAdapterInitOptions) => Promise<AIAdapter<TBus, TConnector, TAgent>>;
|
|
3073
|
+
}
|
|
3074
|
+
//#endregion
|
|
3075
|
+
//#region adapters/core/src/types/messaging.d.ts
|
|
3076
|
+
/**
|
|
3077
|
+
* Options for `AIAdapter.promptText()`.
|
|
3078
|
+
*
|
|
3079
|
+
* Minimal universal parameters with provider-specific escape hatch.
|
|
3080
|
+
* @example
|
|
3081
|
+
* ```typescript
|
|
3082
|
+
* await adapter.promptText("Build an auth system", {
|
|
3083
|
+
* model: "gpt-4o",
|
|
3084
|
+
* sessionId: "user-123-conv-456",
|
|
3085
|
+
* providerOptions: { temperature: 0.7 }
|
|
3086
|
+
* });
|
|
3087
|
+
* ```
|
|
3088
|
+
* @see {@link AIAdapterPromptResult} for response type
|
|
3089
|
+
* @see `AIAdapter.promptText` for usage
|
|
3090
|
+
* @see [Message Handling Guide](../../docs/message-handling.md)
|
|
3091
|
+
*/
|
|
3092
|
+
interface AIAdapterPromptOptions {
|
|
3093
|
+
/** Model identifier (provider-specific). Defaults to adapter's configured model if omitted. */
|
|
3094
|
+
model?: string;
|
|
3095
|
+
/** Session ID for conversation continuity. Creates new session if omitted. Check `caps.sessionResume` for persistence support. */
|
|
3096
|
+
sessionId?: string;
|
|
3097
|
+
/** Provider-specific options (temperature, tools, system prompts, etc.). Type explicitly in adapter implementations. */
|
|
3098
|
+
providerOptions?: unknown;
|
|
3099
|
+
}
|
|
3100
|
+
/**
|
|
3101
|
+
* Successful prompt result with text response.
|
|
3102
|
+
* @see {@link AIAdapterPromptResult} for discriminated union
|
|
3103
|
+
*/
|
|
3104
|
+
interface AIAdapterPromptSuccessResult {
|
|
3105
|
+
/** Complete text response from AI model. For streaming events, contains final assembled text. */
|
|
3106
|
+
text: string;
|
|
3107
|
+
}
|
|
3108
|
+
/**
|
|
3109
|
+
* Failed prompt result. Adapters return errors as values rather than throwing.
|
|
3110
|
+
* @see {@link AIAdapterPromptResult} for discriminated union
|
|
3111
|
+
*/
|
|
3112
|
+
interface AIAdapterPromptFailureResult {
|
|
3113
|
+
/** Error message (string) or Error object describing failure. */
|
|
3114
|
+
error: string | Error;
|
|
3115
|
+
}
|
|
3116
|
+
/**
|
|
3117
|
+
* Result from `AIAdapter.promptText()`. Discriminated union of success/failure.
|
|
3118
|
+
* @example
|
|
3119
|
+
* ```typescript
|
|
3120
|
+
* const result = await adapter.promptText("Build auth");
|
|
3121
|
+
*
|
|
3122
|
+
* if ('error' in result) {
|
|
3123
|
+
* console.error('Failed:', result.error);
|
|
3124
|
+
* } else {
|
|
3125
|
+
* console.debug('Success:', result.text);
|
|
3126
|
+
* }
|
|
3127
|
+
* ```
|
|
3128
|
+
* @see {@link AIAdapterPromptSuccessResult} for success structure
|
|
3129
|
+
* @see {@link AIAdapterPromptFailureResult} for failure structure
|
|
3130
|
+
* @see `AIAdapter.promptText` for usage
|
|
3131
|
+
* @see [Message Handling Guide](../../docs/message-handling.md)
|
|
3132
|
+
*/
|
|
3133
|
+
type AIAdapterPromptResult = AIAdapterPromptFailureResult | AIAdapterPromptSuccessResult;
|
|
3134
|
+
//#endregion
|
|
3135
|
+
//#region adapters/core/src/types/mcp-integration.d.ts
|
|
3136
|
+
/**
|
|
3137
|
+
* Describes a change to the MCP tool set mid-session.
|
|
3138
|
+
* Delivered to adapters that support mid-session tool changes.
|
|
3139
|
+
*/
|
|
3140
|
+
interface McpToolChange {
|
|
3141
|
+
/** Tools newly available */
|
|
3142
|
+
readonly added: readonly McpToolState[];
|
|
3143
|
+
/** Tools no longer available */
|
|
3144
|
+
readonly removed: readonly string[];
|
|
3145
|
+
}
|
|
3146
|
+
/**
|
|
3147
|
+
* Discriminated union of resources an adapter receives from McpService.
|
|
3148
|
+
* Uses Makaio-native types, NOT SDK-specific types.
|
|
3149
|
+
* Each adapter converts to its SDK's format internally.
|
|
3150
|
+
*/
|
|
3151
|
+
type McpSessionResources = {
|
|
3152
|
+
readonly mode: 'native-passthrough';
|
|
3153
|
+
readonly servers: Record<string, McpResolvedServer>;
|
|
3154
|
+
} | {
|
|
3155
|
+
readonly mode: 'tool-injection';
|
|
3156
|
+
readonly tools: readonly ToolListItem[];
|
|
3157
|
+
} | {
|
|
3158
|
+
readonly mode: 'observe-only';
|
|
3159
|
+
};
|
|
3160
|
+
/**
|
|
3161
|
+
* Adapter-specific MCP consumption strategy.
|
|
3162
|
+
*
|
|
3163
|
+
* Each adapter that supports MCP implements this interface to declare
|
|
3164
|
+
* how it consumes MCP tools. Defined in adapter-core to avoid circular
|
|
3165
|
+
* dependencies (McpService imports this interface, adapters implement it).
|
|
3166
|
+
*/
|
|
3167
|
+
interface McpIntegrationStrategy {
|
|
3168
|
+
/** What this adapter needs from McpService */
|
|
3169
|
+
readonly mode: 'native-passthrough' | 'tool-injection' | 'observe-only';
|
|
3170
|
+
/**
|
|
3171
|
+
* Whether this adapter supports mid-session tool list changes.
|
|
3172
|
+
* If false, deferred injection is used (bridge current turn, native next turn).
|
|
3173
|
+
*/
|
|
3174
|
+
readonly supportsMidSessionToolChange: boolean;
|
|
3175
|
+
/**
|
|
3176
|
+
* Called when a session starts. Returns adapter-specific resources.
|
|
3177
|
+
* @param context - Resolved MCP config for this session (post-visibility-chain)
|
|
3178
|
+
* @returns Resources the adapter needs to consume MCP tools
|
|
3179
|
+
*/
|
|
3180
|
+
prepareMcpForSession(context: McpSessionContext): Promise<McpSessionResources>;
|
|
3181
|
+
/**
|
|
3182
|
+
* Called when MCP tools change mid-session (server reconnect, dynamic enable).
|
|
3183
|
+
* Only invoked if `supportsMidSessionToolChange` is true.
|
|
3184
|
+
* @param changes - Description of what tools changed
|
|
3185
|
+
*/
|
|
3186
|
+
onToolsChanged?(changes: McpToolChange): Promise<void>;
|
|
3187
|
+
}
|
|
3188
|
+
//#endregion
|
|
3189
|
+
//#region adapters/core/src/types/conformance-test-config.d.ts
|
|
3190
|
+
/**
|
|
3191
|
+
* Identifies a specific model offering for test execution.
|
|
3192
|
+
*
|
|
3193
|
+
* Resolves to a provider definition ID + model name, optionally with a default
|
|
3194
|
+
* reasoning effort level for tests that exercise reasoning.
|
|
3195
|
+
*/
|
|
3196
|
+
interface TestModelRef {
|
|
3197
|
+
/** Provider definition ID to test against (e.g., 'anthropic', 'nanogpt'). */
|
|
3198
|
+
definitionId: string;
|
|
3199
|
+
/** Model identifier within the provider (e.g., 'haiku', 'gpt-4o-mini'). */
|
|
3200
|
+
modelName: string;
|
|
3201
|
+
/** Default reasoning effort for tests that exercise reasoning. */
|
|
3202
|
+
reasoningEffort?: AIReasoningLevel$1;
|
|
3203
|
+
}
|
|
3204
|
+
/**
|
|
3205
|
+
* Provider definitions supplied by the conformance harness.
|
|
3206
|
+
*
|
|
3207
|
+
* Adapter packages should declare provider compatibility by stable provider ID
|
|
3208
|
+
* and let the harness supply full definitions from provider contributions.
|
|
3209
|
+
*/
|
|
3210
|
+
interface CreateConformanceTestConfigOptions {
|
|
3211
|
+
/** Full provider definitions available to conformance tests. */
|
|
3212
|
+
providerDefinitions?: readonly ProviderDefinitionInput[];
|
|
3213
|
+
}
|
|
3214
|
+
/**
|
|
3215
|
+
* Options for creating test agent instances.
|
|
3216
|
+
* Omits 'bus' (provided by test config) and makes 'adapterName'/'agentId' optional (factories provide defaults).
|
|
3217
|
+
*/
|
|
3218
|
+
type CreateTestAgentOptions = Omit<BaseAgentConnectorConfig, 'bus' | 'adapterName' | 'model'> & {
|
|
3219
|
+
adapterName?: string;
|
|
3220
|
+
model?: string; /** Override the default test provider context when testing endpoint/credential behavior. */
|
|
3221
|
+
providerContext?: ProviderContext;
|
|
3222
|
+
};
|
|
3223
|
+
interface ConformanceTestConfig<TBus extends ScopedBus<string> = ScopedBus<string>, TConnector extends AIAgentConnector<TBus> = AIAgentConnector<TBus>, TAgent extends AIAgent<TBus, TConnector> = AIAgent<TBus, TConnector>> {
|
|
3224
|
+
/**
|
|
3225
|
+
* Factory function for creating fresh agent instances.
|
|
3226
|
+
*
|
|
3227
|
+
* **Important**: Return a **new instance** on each call. The conformance
|
|
3228
|
+
* suite decides when to instantiate based on isolation requirements.
|
|
3229
|
+
*
|
|
3230
|
+
* **DO NOT** instantiate eagerly or return a singleton—tests may run
|
|
3231
|
+
* concurrently or require pristine state.
|
|
3232
|
+
* @returns Fresh connector instance configured for testing
|
|
3233
|
+
* @example
|
|
3234
|
+
* ```typescript
|
|
3235
|
+
* createConnector: () => new ClaudeCodeConnector({
|
|
3236
|
+
* bus: testBus,
|
|
3237
|
+
* agentId: `test-${Date.now()}`,
|
|
3238
|
+
* sessionId: undefined, // Let adapter generate
|
|
3239
|
+
* })
|
|
3240
|
+
* ```
|
|
3241
|
+
*/
|
|
3242
|
+
createConnector: (options?: CreateTestAgentOptions) => Promise<TConnector>;
|
|
3243
|
+
/**
|
|
3244
|
+
* Register a tool approval handler scoped to a specific connector.
|
|
3245
|
+
*
|
|
3246
|
+
* The handler will only receive approval requests from the given connector
|
|
3247
|
+
* (filtered by agentId). Returns an unsubscribe function for cleanup.
|
|
3248
|
+
* @param connector - The connector to scope approval handling to
|
|
3249
|
+
* @param context - Optional approval context (e.g., allowed tools, policies)
|
|
3250
|
+
* @returns Unsubscribe function to remove the handler
|
|
3251
|
+
*/
|
|
3252
|
+
registerToolApprovalHandler(connector: TConnector, context: ToolApprovalContext | (() => Promise<ToolApprovalContext>)): () => void;
|
|
3253
|
+
/**
|
|
3254
|
+
* Scoped bus instance for the adapter's namespace.
|
|
3255
|
+
*
|
|
3256
|
+
* This bus is used to emit events and handle requests in the adapter's
|
|
3257
|
+
* domain (e.g., 'claude-code', 'codex'). The conformance suite observes
|
|
3258
|
+
* events on this bus to verify behavior.
|
|
3259
|
+
*
|
|
3260
|
+
* **Namespace Isolation**: Each adapter should use a dedicated namespace
|
|
3261
|
+
* to prevent cross-talk between concurrent test suites.
|
|
3262
|
+
* @example
|
|
3263
|
+
* ```typescript
|
|
3264
|
+
* import { MakaioBus } from '@makaio/framework/bus';
|
|
3265
|
+
*
|
|
3266
|
+
* const scopedBus = MakaioBus.scoped('claude-code');
|
|
3267
|
+
* ```
|
|
3268
|
+
*/
|
|
3269
|
+
bus: ScopedBus<string>;
|
|
3270
|
+
/**
|
|
3271
|
+
* Optional capability flags indicating adapter-specific features.
|
|
3272
|
+
*
|
|
3273
|
+
* These flags allow conformance tests to:
|
|
3274
|
+
* - Skip tests for unsupported features (e.g., replace mode)
|
|
3275
|
+
* - Verify optional behaviors when supported
|
|
3276
|
+
* - Provide clear capability documentation
|
|
3277
|
+
*
|
|
3278
|
+
* **Default**: All capabilities are `false` (core features only)
|
|
3279
|
+
*
|
|
3280
|
+
* ## When to Enable
|
|
3281
|
+
*
|
|
3282
|
+
* - `supportsReplace`: Adapter implements 'replace' delivery mode
|
|
3283
|
+
* (clears pending queue before enqueuing message)
|
|
3284
|
+
* - `supportsInterrupt`: Adapter exposes `interrupt()` method
|
|
3285
|
+
* (cancels active turn mid-execution)
|
|
3286
|
+
* - `supportsUsageMetrics`: Adapter emits `agent.usage` events
|
|
3287
|
+
* (token counts, cost tracking)
|
|
3288
|
+
* @example Full Capabilities
|
|
3289
|
+
* ```typescript
|
|
3290
|
+
* capabilities: {
|
|
3291
|
+
* supportsReplace: true, // Claude Code's replace mode
|
|
3292
|
+
* supportsInterrupt: true, // Claude Code's interrupt()
|
|
3293
|
+
* supportsUsageMetrics: true, // Usage tracking
|
|
3294
|
+
* }
|
|
3295
|
+
* ```
|
|
3296
|
+
* @example Core Features Only
|
|
3297
|
+
* ```typescript
|
|
3298
|
+
* capabilities: undefined // or omit entirely
|
|
3299
|
+
* // Tests will skip replace, interrupt, tool approval, and usage tests
|
|
3300
|
+
* ```
|
|
3301
|
+
*/
|
|
3302
|
+
capabilities?: {
|
|
3303
|
+
/**
|
|
3304
|
+
* Supports 'replace' message delivery mode.
|
|
3305
|
+
*
|
|
3306
|
+
* When enabled, the adapter clears the pending message queue before
|
|
3307
|
+
* enqueuing a new message. This is useful for "superseding" interactions.
|
|
3308
|
+
*
|
|
3309
|
+
* **Claude Code**: `true` (implements replace via MCP SDK)
|
|
3310
|
+
* **Basic Adapters**: `false` (enqueue/immediate only)
|
|
3311
|
+
*/
|
|
3312
|
+
supportsReplace?: boolean;
|
|
3313
|
+
/**
|
|
3314
|
+
* Supports `interrupt()` method for cancelling active turns.
|
|
3315
|
+
*
|
|
3316
|
+
* When enabled, the adapter can abort mid-turn execution (e.g., during
|
|
3317
|
+
* a long-running tool call or reasoning phase).
|
|
3318
|
+
*
|
|
3319
|
+
* **Claude Code**: `true` (exposes interrupt via MCP SDK)
|
|
3320
|
+
* **Stateless Adapters**: `false` (no turn state to interrupt)
|
|
3321
|
+
*/
|
|
3322
|
+
supportsInterrupt?: boolean;
|
|
3323
|
+
/**
|
|
3324
|
+
* Supports usage metrics via `agent.usage` events.
|
|
3325
|
+
*
|
|
3326
|
+
* When enabled, the adapter emits token counts and cost data after
|
|
3327
|
+
* turns or at session completion.
|
|
3328
|
+
*
|
|
3329
|
+
* **Claude Code**: `true` (exposes MCP usage data)
|
|
3330
|
+
* **Free-Tier Adapters**: `false` (no usage tracking)
|
|
3331
|
+
*/
|
|
3332
|
+
supportsUsageMetrics?: boolean;
|
|
3333
|
+
};
|
|
3334
|
+
/**
|
|
3335
|
+
* Test configuration and environment options.
|
|
3336
|
+
*
|
|
3337
|
+
* These options tune test behavior without affecting adapter functionality.
|
|
3338
|
+
* All fields are optional with sensible defaults.
|
|
3339
|
+
* @example
|
|
3340
|
+
* ```typescript
|
|
3341
|
+
* options: {
|
|
3342
|
+
* defaultTimeout: 30000, // 30s for slow CI
|
|
3343
|
+
* fastModel: 'claude-3-haiku-20240307', // Fast model for tests
|
|
3344
|
+
* tmpDir: '/tmp/conformance-tests', // Isolated temp directory
|
|
3345
|
+
* }
|
|
3346
|
+
* ```
|
|
3347
|
+
*/
|
|
3348
|
+
options?: {
|
|
3349
|
+
/**
|
|
3350
|
+
* Default timeout for tests in milliseconds.
|
|
3351
|
+
*
|
|
3352
|
+
* Applies to async operations like agent.start() and message delivery.
|
|
3353
|
+
* Individual tests can override via Vitest's `{ timeout: ... }`.
|
|
3354
|
+
* @defaultValue 10000 (10 seconds)
|
|
3355
|
+
* @example
|
|
3356
|
+
* ```typescript
|
|
3357
|
+
* defaultTimeout: 30000 // 30s for slow CI environments
|
|
3358
|
+
* ```
|
|
3359
|
+
*/
|
|
3360
|
+
defaultTimeout?: number;
|
|
3361
|
+
/**
|
|
3362
|
+
* Maximum concurrent test FILES for this adapter.
|
|
3363
|
+
*
|
|
3364
|
+
* Controls how many conformance test files run simultaneously when using
|
|
3365
|
+
* the programmatic test runner (scripts/test-adapters.ts). Each adapter
|
|
3366
|
+
* can specify its own concurrency based on rate limits or resource constraints.
|
|
3367
|
+
*
|
|
3368
|
+
* **How it works:**
|
|
3369
|
+
* - Test runner creates a per-adapter queue with this concurrency limit
|
|
3370
|
+
* - Test files for this adapter run through the queue
|
|
3371
|
+
* - Multiple adapters can run in parallel, each with its own queue
|
|
3372
|
+
*
|
|
3373
|
+
* **vs testConcurrency:**
|
|
3374
|
+
* - `concurrency`: Limits concurrent TEST FILES
|
|
3375
|
+
* - `testConcurrency`: Limits concurrent OPERATIONS within test helpers
|
|
3376
|
+
* @defaultValue 2 (when not specified)
|
|
3377
|
+
* @example
|
|
3378
|
+
* ```typescript
|
|
3379
|
+
* // Rate-limited API (e.g., Gemini free tier)
|
|
3380
|
+
* concurrency: 1 // Run test files sequentially
|
|
3381
|
+
*
|
|
3382
|
+
* // High-throughput API
|
|
3383
|
+
* concurrency: 4 // Run 4 test files in parallel
|
|
3384
|
+
* ```
|
|
3385
|
+
*/
|
|
3386
|
+
concurrency?: number;
|
|
3387
|
+
/**
|
|
3388
|
+
* Cheap/fast model for cost-sensitive test execution.
|
|
3389
|
+
*
|
|
3390
|
+
* Used by most conformance tests that make real API calls.
|
|
3391
|
+
* Derived from the default provider preset's `fastModel` (or `defaultModel` as fallback).
|
|
3392
|
+
*
|
|
3393
|
+
* **Claude**: `{ definitionId: 'anthropic', modelName: 'haiku' }`
|
|
3394
|
+
* **Gemini**: `{ definitionId: 'gemini', modelName: 'gemini-2.5-flash' }`
|
|
3395
|
+
* @example
|
|
3396
|
+
* ```typescript
|
|
3397
|
+
* primaryModel: { definitionId: 'anthropic', modelName: 'haiku' }
|
|
3398
|
+
* ```
|
|
3399
|
+
*/
|
|
3400
|
+
primaryModel?: TestModelRef;
|
|
3401
|
+
/**
|
|
3402
|
+
* Secondary model for model-switching tests.
|
|
3403
|
+
*
|
|
3404
|
+
* Used as the target model in model-change conformance tests.
|
|
3405
|
+
* Derived from the default provider preset's `defaultModel`.
|
|
3406
|
+
*
|
|
3407
|
+
* **Claude**: `{ definitionId: 'anthropic', modelName: 'sonnet' }`
|
|
3408
|
+
* **Gemini**: `{ definitionId: 'gemini', modelName: 'gemini-2.5-pro' }`
|
|
3409
|
+
* @example
|
|
3410
|
+
* ```typescript
|
|
3411
|
+
* secondaryModel: { definitionId: 'anthropic', modelName: 'sonnet' }
|
|
3412
|
+
* ```
|
|
3413
|
+
*/
|
|
3414
|
+
secondaryModel?: TestModelRef;
|
|
3415
|
+
/**
|
|
3416
|
+
* Temporary directory for file operations during tests.
|
|
3417
|
+
*
|
|
3418
|
+
* Used for tests that create artifacts (logs, cached responses, etc.).
|
|
3419
|
+
* Should be isolated per test suite to prevent collisions.
|
|
3420
|
+
* @defaultValue OS temp dir + random suffix
|
|
3421
|
+
* @example
|
|
3422
|
+
* ```typescript
|
|
3423
|
+
* tmpDir: '/tmp/conformance-tests-claude-code'
|
|
3424
|
+
* ```
|
|
3425
|
+
*/
|
|
3426
|
+
tmpDir?: string;
|
|
3427
|
+
/**
|
|
3428
|
+
* Maximum concurrent test operations for this adapter.
|
|
3429
|
+
*
|
|
3430
|
+
* When set, test infrastructure serializes context creation and key
|
|
3431
|
+
* operations through a per-adapter queue. Useful for adapters with
|
|
3432
|
+
* aggressive rate limits (e.g., Gemini free tier).
|
|
3433
|
+
*
|
|
3434
|
+
* **Default**: undefined (no throttling - tests run fully concurrent)
|
|
3435
|
+
* @example
|
|
3436
|
+
* ```typescript
|
|
3437
|
+
* testConcurrency: 1 // Serialize all test operations
|
|
3438
|
+
* ```
|
|
3439
|
+
*/
|
|
3440
|
+
testConcurrency?: number;
|
|
3441
|
+
};
|
|
3442
|
+
/**
|
|
3443
|
+
* Factory function for creating full adapter instances (orchestration tests).
|
|
3444
|
+
*
|
|
3445
|
+
* **Orchestration vs Agent Tests:**
|
|
3446
|
+
* - Agent tests (`createAgent`): Direct agent instantiation, bypass session manager
|
|
3447
|
+
* - Orchestration tests (`createAdapter`): Full pipeline via MakaioBus.request()
|
|
3448
|
+
*
|
|
3449
|
+
* When provided, enables orchestration-level conformance tests that verify:
|
|
3450
|
+
* - Bus request/response flow (AdapterSubjects.sendMessage, etc.)
|
|
3451
|
+
* - Session manager lifecycle
|
|
3452
|
+
* - Event transformation pipeline (SDK to Adapter to Global)
|
|
3453
|
+
* - Multi-adapter coordination
|
|
3454
|
+
*
|
|
3455
|
+
* **Important**: Each call should return a fresh instance with unique adapterId
|
|
3456
|
+
* for test isolation. The factory receives optional init options to allow
|
|
3457
|
+
* passing a specific adapterId.
|
|
3458
|
+
* @returns Fresh AIAdapter instance configured for orchestration testing
|
|
3459
|
+
* @example
|
|
3460
|
+
* ```typescript
|
|
3461
|
+
* createAdapter: (options) => createClaudeAdapter({
|
|
3462
|
+
* adapterId: options?.adapterId ?? `test-${crypto.randomUUID()}`,
|
|
3463
|
+
* ...options
|
|
3464
|
+
* })
|
|
3465
|
+
* ```
|
|
3466
|
+
*/
|
|
3467
|
+
createAdapter?: (options?: AIAdapterInitOptions) => Promise<AIAdapter<TBus, TConnector, TAgent>>;
|
|
3468
|
+
/**
|
|
3469
|
+
* Adapter type name for orchestration tests (e.g., 'claude-code').
|
|
3470
|
+
* Required when createAdapter is provided.
|
|
3471
|
+
*/
|
|
3472
|
+
adapterName?: string;
|
|
3473
|
+
/**
|
|
3474
|
+
* Unresolved provider context for the test provider.
|
|
3475
|
+
*
|
|
3476
|
+
* Contains credential refs (e.g. `env:ANTHROPIC_API_KEY`) built from the test
|
|
3477
|
+
* provider definition's `credentialEnvVars`. Used by orchestration tests that
|
|
3478
|
+
* call `startAgent` directly (bypassing the conformance `createConnector` path
|
|
3479
|
+
* where `resolveTestConfig` handles credential ref building).
|
|
3480
|
+
*
|
|
3481
|
+
* The conformance test infrastructure registers a credential channel handler
|
|
3482
|
+
* that resolves `env:` refs from `process.env` so connectors can call
|
|
3483
|
+
* `resolveConnectorCredentials()` without a real credential store.
|
|
3484
|
+
*/
|
|
3485
|
+
testProviderContext?: ProviderContext;
|
|
3486
|
+
/**
|
|
3487
|
+
* Optional cleanup hook for adapter-specific test infrastructure.
|
|
3488
|
+
*
|
|
3489
|
+
* Use this for resources created by `createTestConfig()` that outlive
|
|
3490
|
+
* individual connectors/adapters (for example shared test servers).
|
|
3491
|
+
*/
|
|
3492
|
+
cleanup?: () => Promise<void> | void;
|
|
3493
|
+
}
|
|
3494
|
+
//#endregion
|
|
3495
|
+
//#region adapters/core/src/session/utilities.d.ts
|
|
3496
|
+
/**
|
|
3497
|
+
* Manages session lifecycle and abort handling.
|
|
3498
|
+
*
|
|
3499
|
+
* Provides coordinated abort signal management:
|
|
3500
|
+
* - Idempotent abort()
|
|
3501
|
+
* - Cleanup hook execution
|
|
3502
|
+
* - Termination state tracking
|
|
3503
|
+
*
|
|
3504
|
+
* ## Design Philosophy
|
|
3505
|
+
*
|
|
3506
|
+
* SessionLifecycle is a simple composition utility that encapsulates
|
|
3507
|
+
* abort signal coordination. It avoids inheritance coupling while providing
|
|
3508
|
+
* a clean API for session termination.
|
|
3509
|
+
*
|
|
3510
|
+
* ## Example Usage
|
|
3511
|
+
*
|
|
3512
|
+
* ```typescript
|
|
3513
|
+
* class MySession {
|
|
3514
|
+
* private lifecycle = new SessionLifecycle();
|
|
3515
|
+
*
|
|
3516
|
+
* abort() {
|
|
3517
|
+
* this.lifecycle.abort(() => this.transport.close());
|
|
3518
|
+
* }
|
|
3519
|
+
*
|
|
3520
|
+
* async sendMessage(msg: string) {
|
|
3521
|
+
* if (this.lifecycle.isTerminated) {
|
|
3522
|
+
* throw new Error('Session terminated');
|
|
3523
|
+
* }
|
|
3524
|
+
* // ... send logic
|
|
3525
|
+
* }
|
|
3526
|
+
*
|
|
3527
|
+
* getAbortSignal(): AbortSignal {
|
|
3528
|
+
* return this.lifecycle.signal;
|
|
3529
|
+
* }
|
|
3530
|
+
* }
|
|
3531
|
+
* ```
|
|
3532
|
+
*/
|
|
3533
|
+
declare class SessionLifecycle {
|
|
3534
|
+
private readonly abortController;
|
|
3535
|
+
private terminated;
|
|
3536
|
+
/**
|
|
3537
|
+
* Create a new SessionLifecycle
|
|
3538
|
+
* @param abortController - Optional AbortController to use (creates new if not provided)
|
|
3539
|
+
*/
|
|
3540
|
+
constructor(abortController?: AbortController);
|
|
3541
|
+
/**
|
|
3542
|
+
* Get abort signal for provider integration
|
|
3543
|
+
* @returns The abort signal
|
|
3544
|
+
*/
|
|
3545
|
+
get signal(): AbortSignal;
|
|
3546
|
+
/**
|
|
3547
|
+
* Get termination state
|
|
3548
|
+
* @returns True if session has been terminated
|
|
3549
|
+
*/
|
|
3550
|
+
get isTerminated(): boolean;
|
|
3551
|
+
/**
|
|
3552
|
+
* Abort session and run cleanup.
|
|
3553
|
+
* Idempotent - safe to call multiple times.
|
|
3554
|
+
* @param cleanup - Cleanup function (sync or async)
|
|
3555
|
+
*/
|
|
3556
|
+
abort(cleanup?: () => void | Promise<void>): void;
|
|
3557
|
+
/**
|
|
3558
|
+
* Register abort listener
|
|
3559
|
+
* @param handler - Callback to invoke when session is aborted
|
|
3560
|
+
*/
|
|
3561
|
+
onAbort(handler: () => void): void;
|
|
3562
|
+
}
|
|
3563
|
+
//#endregion
|
|
3564
|
+
//#region adapters/core/src/log-importer/base-importer.d.ts
|
|
3565
|
+
/**
|
|
3566
|
+
* Abstract base class for log importers.
|
|
3567
|
+
*
|
|
3568
|
+
* Provides default processLogFile() implementation that composes
|
|
3569
|
+
* extractSessionContext() + processRecords(). Adapters implement
|
|
3570
|
+
* the abstract methods for their specific log format.
|
|
3571
|
+
* @typeParam TRecord - The tool's native log record type
|
|
3572
|
+
* @typeParam TState - The resumable state type
|
|
3573
|
+
*/
|
|
3574
|
+
declare abstract class BaseLogImporter<TRecord, TState = unknown> implements LogImporter<TRecord, TState> {
|
|
3575
|
+
abstract canHandle(sample: string | JsonObject): boolean | {
|
|
3576
|
+
confidence: number;
|
|
3577
|
+
};
|
|
3578
|
+
abstract getLogDirectory(): string;
|
|
3579
|
+
/**
|
|
3580
|
+
* Parse a single log record from raw input.
|
|
3581
|
+
* @param line - Raw log line or parsed JSON object to parse
|
|
3582
|
+
* @param sourceFilePath - Optional source file path for format-specific context
|
|
3583
|
+
* @returns Parsed record or null when the input does not match the adapter format
|
|
3584
|
+
*/
|
|
3585
|
+
abstract parseRecord(line: string | JsonObject, sourceFilePath?: string): TRecord | null;
|
|
3586
|
+
abstract isMakaioManaged(sessionId: string): Promise<boolean>;
|
|
3587
|
+
/**
|
|
3588
|
+
* Extract discovery metadata from a log file without importing full message history.
|
|
3589
|
+
* @param filePath - Absolute path to the source log file
|
|
3590
|
+
* @returns Discovery metadata when parsing succeeds; rejects on unrecoverable read/parse errors
|
|
3591
|
+
*/
|
|
3592
|
+
abstract extractDiscoveryMetadata(filePath: string): Promise<DiscoveryMetadata>;
|
|
3593
|
+
abstract extractSessionContext(records: TRecord[]): LogImportSessionContext<TState>;
|
|
3594
|
+
abstract processRecords(records: TRecord[], context: LogImportSessionContext<TState>): NormalizedEvent[];
|
|
3595
|
+
abstract serializeState(state: TState): JsonObject;
|
|
3596
|
+
abstract deserializeState(raw: JsonObject): TState;
|
|
3597
|
+
/**
|
|
3598
|
+
* Process a complete log file in a single call.
|
|
3599
|
+
*
|
|
3600
|
+
* Composes extractSessionContext + processRecords + message extraction.
|
|
3601
|
+
* Adapters that need special handling (fork detection, field normalization)
|
|
3602
|
+
* should override this method.
|
|
3603
|
+
* @param records - All parsed records from the log file
|
|
3604
|
+
* @returns Combined session metadata, events, and message payloads
|
|
3605
|
+
*/
|
|
3606
|
+
processLogFile(records: TRecord | TRecord[]): ProcessLogFileResult;
|
|
3607
|
+
}
|
|
3608
|
+
//#endregion
|
|
3609
|
+
//#region adapters/core/src/log-importer/cursor-storage.d.ts
|
|
3610
|
+
/**
|
|
3611
|
+
* Zod schema for import cursor position.
|
|
3612
|
+
*
|
|
3613
|
+
* Mirrors the {@link ImportCursorPosition} interface for runtime validation.
|
|
3614
|
+
* Used in storage requests and responses.
|
|
3615
|
+
*/
|
|
3616
|
+
declare const ImportCursorPositionSchema: z.ZodObject<{
|
|
3617
|
+
filePath: z.ZodString;
|
|
3618
|
+
bytesRead: z.ZodNumber;
|
|
3619
|
+
lastModified: z.ZodString;
|
|
3620
|
+
sessionContext: z.ZodOptional<z.ZodCustom<{
|
|
3621
|
+
model: string | null;
|
|
3622
|
+
cwd: string | null;
|
|
3623
|
+
} & {
|
|
3624
|
+
adapterSessionId: string;
|
|
3625
|
+
sessionEvent: NormalizedEvent;
|
|
3626
|
+
startedEvent: NormalizedEvent;
|
|
3627
|
+
state: _$type_fest0.JsonObject;
|
|
3628
|
+
}, {
|
|
3629
|
+
model: string | null;
|
|
3630
|
+
cwd: string | null;
|
|
3631
|
+
} & {
|
|
3632
|
+
adapterSessionId: string;
|
|
3633
|
+
sessionEvent: NormalizedEvent;
|
|
3634
|
+
startedEvent: NormalizedEvent;
|
|
3635
|
+
state: _$type_fest0.JsonObject;
|
|
3636
|
+
}>>;
|
|
3637
|
+
}, z.core.$strip>;
|
|
3638
|
+
/**
|
|
3639
|
+
* Import cursor storage namespace.
|
|
3640
|
+
*
|
|
3641
|
+
* Provides bus subjects for tracking import progress within external log files.
|
|
3642
|
+
* Cursors enable resumption from the last successfully processed position
|
|
3643
|
+
* after restarts, preventing duplicate event emission.
|
|
3644
|
+
* @remarks
|
|
3645
|
+
* Storage domain: `storage:importCursor`
|
|
3646
|
+
*
|
|
3647
|
+
* Cursors track byte offsets rather than line numbers for efficiency.
|
|
3648
|
+
* The `lastModified` timestamp enables detection of file truncation/rotation:
|
|
3649
|
+
* if the file's mtime is older than the stored cursor, the file was likely
|
|
3650
|
+
* rotated and should be re-read from the beginning.
|
|
3651
|
+
* @example
|
|
3652
|
+
* ```typescript
|
|
3653
|
+
* import { ImportCursorStorageSubjects } from '@makaio/framework/adapters';
|
|
3654
|
+
*
|
|
3655
|
+
* // Get cursor for file (returns null if not found)
|
|
3656
|
+
* const result = await bus.request(ImportCursorStorageSubjects.get, {
|
|
3657
|
+
* filePath: '/home/user/.claude/projects/foo/session.jsonl',
|
|
3658
|
+
* });
|
|
3659
|
+
*
|
|
3660
|
+
* if (result.cursor) {
|
|
3661
|
+
* console.log(`Resuming from byte ${result.cursor.bytesRead}`);
|
|
3662
|
+
* }
|
|
3663
|
+
*
|
|
3664
|
+
* // Update cursor after processing
|
|
3665
|
+
* await bus.request(ImportCursorStorageSubjects.set, {
|
|
3666
|
+
* filePath: '/home/user/.claude/projects/foo/session.jsonl',
|
|
3667
|
+
* bytesRead: 12345,
|
|
3668
|
+
* lastModified: '2025-12-09T10:30:00Z',
|
|
3669
|
+
* });
|
|
3670
|
+
* ```
|
|
3671
|
+
* @see {@link ImportCursorPosition} - Type definition for cursor positions
|
|
3672
|
+
*/
|
|
3673
|
+
declare const ImportCursorStorageNamespace: _$_makaio_storage_core0.StorageNamespaceDefinition<"importCursor", {
|
|
3674
|
+
/**
|
|
3675
|
+
* Get the cursor position for a log file.
|
|
3676
|
+
*
|
|
3677
|
+
* Subject: `storage:importCursor.get`
|
|
3678
|
+
* Type: Request (RPC)
|
|
3679
|
+
* @returns Cursor position or null if not found
|
|
3680
|
+
*/
|
|
3681
|
+
get: {
|
|
3682
|
+
request: z.ZodObject<{
|
|
3683
|
+
filePath: z.ZodString;
|
|
3684
|
+
}, z.core.$strip>;
|
|
3685
|
+
response: z.ZodObject<{
|
|
3686
|
+
cursor: z.ZodNullable<z.ZodObject<{
|
|
3687
|
+
filePath: z.ZodString;
|
|
3688
|
+
bytesRead: z.ZodNumber;
|
|
3689
|
+
lastModified: z.ZodString;
|
|
3690
|
+
sessionContext: z.ZodOptional<z.ZodCustom<{
|
|
3691
|
+
model: string | null;
|
|
3692
|
+
cwd: string | null;
|
|
3693
|
+
} & {
|
|
3694
|
+
adapterSessionId: string;
|
|
3695
|
+
sessionEvent: NormalizedEvent;
|
|
3696
|
+
startedEvent: NormalizedEvent;
|
|
3697
|
+
state: _$type_fest0.JsonObject;
|
|
3698
|
+
}, {
|
|
3699
|
+
model: string | null;
|
|
3700
|
+
cwd: string | null;
|
|
3701
|
+
} & {
|
|
3702
|
+
adapterSessionId: string;
|
|
3703
|
+
sessionEvent: NormalizedEvent;
|
|
3704
|
+
startedEvent: NormalizedEvent;
|
|
3705
|
+
state: _$type_fest0.JsonObject;
|
|
3706
|
+
}>>;
|
|
3707
|
+
}, z.core.$strip>>;
|
|
3708
|
+
}, z.core.$strip>;
|
|
3709
|
+
};
|
|
3710
|
+
/**
|
|
3711
|
+
* Set or update the cursor position for a log file.
|
|
3712
|
+
*
|
|
3713
|
+
* Subject: `storage:importCursor.set`
|
|
3714
|
+
* Type: Request (RPC)
|
|
3715
|
+
*/
|
|
3716
|
+
set: {
|
|
3717
|
+
request: z.ZodObject<{
|
|
3718
|
+
filePath: z.ZodString;
|
|
3719
|
+
bytesRead: z.ZodNumber;
|
|
3720
|
+
lastModified: z.ZodString;
|
|
3721
|
+
sessionContext: z.ZodOptional<z.ZodCustom<{
|
|
3722
|
+
model: string | null;
|
|
3723
|
+
cwd: string | null;
|
|
3724
|
+
} & {
|
|
3725
|
+
adapterSessionId: string;
|
|
3726
|
+
sessionEvent: NormalizedEvent;
|
|
3727
|
+
startedEvent: NormalizedEvent;
|
|
3728
|
+
state: _$type_fest0.JsonObject;
|
|
3729
|
+
}, {
|
|
3730
|
+
model: string | null;
|
|
3731
|
+
cwd: string | null;
|
|
3732
|
+
} & {
|
|
3733
|
+
adapterSessionId: string;
|
|
3734
|
+
sessionEvent: NormalizedEvent;
|
|
3735
|
+
startedEvent: NormalizedEvent;
|
|
3736
|
+
state: _$type_fest0.JsonObject;
|
|
3737
|
+
}>>;
|
|
3738
|
+
}, z.core.$strip>;
|
|
3739
|
+
response: z.ZodObject<{
|
|
3740
|
+
success: z.ZodBoolean;
|
|
3741
|
+
}, z.core.$strip>;
|
|
3742
|
+
};
|
|
3743
|
+
/**
|
|
3744
|
+
* Delete the cursor for a log file.
|
|
3745
|
+
*
|
|
3746
|
+
* Subject: `storage:importCursor.delete`
|
|
3747
|
+
* Type: Request (RPC)
|
|
3748
|
+
* @remarks
|
|
3749
|
+
* Useful when a file is detected as rotated/truncated and needs
|
|
3750
|
+
* to be re-read from the beginning.
|
|
3751
|
+
*/
|
|
3752
|
+
delete: {
|
|
3753
|
+
request: z.ZodObject<{
|
|
3754
|
+
filePath: z.ZodString;
|
|
3755
|
+
}, z.core.$strip>;
|
|
3756
|
+
response: z.ZodObject<{
|
|
3757
|
+
success: z.ZodBoolean;
|
|
3758
|
+
}, z.core.$strip>;
|
|
3759
|
+
};
|
|
3760
|
+
}, _$_makaio_storage_core0.StorageNamespaceExtensions>;
|
|
3761
|
+
/**
|
|
3762
|
+
* Typed subjects for import cursor storage operations.
|
|
3763
|
+
*
|
|
3764
|
+
* Provides type-safe access to cursor storage subjects for bus requests.
|
|
3765
|
+
* @example
|
|
3766
|
+
* ```typescript
|
|
3767
|
+
* // Get cursor
|
|
3768
|
+
* const { cursor } = await bus.request(ImportCursorStorageSubjects.get, {
|
|
3769
|
+
* filePath: '/path/to/log.jsonl',
|
|
3770
|
+
* });
|
|
3771
|
+
*
|
|
3772
|
+
* // Set cursor
|
|
3773
|
+
* await bus.request(ImportCursorStorageSubjects.set, {
|
|
3774
|
+
* filePath: '/path/to/log.jsonl',
|
|
3775
|
+
* bytesRead: 1024,
|
|
3776
|
+
* lastModified: new Date().toISOString(),
|
|
3777
|
+
* });
|
|
3778
|
+
*
|
|
3779
|
+
* // Delete cursor (on file rotation)
|
|
3780
|
+
* await bus.request(ImportCursorStorageSubjects.delete, {
|
|
3781
|
+
* filePath: '/path/to/log.jsonl',
|
|
3782
|
+
* });
|
|
3783
|
+
* ```
|
|
3784
|
+
*/
|
|
3785
|
+
declare const ImportCursorStorageSubjects: _$_makaio_core0.BusSubjects<_$_makaio_core0.FlatSubjectDefinitions<"storage:importCursor", {
|
|
3786
|
+
/**
|
|
3787
|
+
* Get the cursor position for a log file.
|
|
3788
|
+
*
|
|
3789
|
+
* Subject: `storage:importCursor.get`
|
|
3790
|
+
* Type: Request (RPC)
|
|
3791
|
+
* @returns Cursor position or null if not found
|
|
3792
|
+
*/
|
|
3793
|
+
get: {
|
|
3794
|
+
request: z.ZodObject<{
|
|
3795
|
+
filePath: z.ZodString;
|
|
3796
|
+
}, z.core.$strip>;
|
|
3797
|
+
response: z.ZodObject<{
|
|
3798
|
+
cursor: z.ZodNullable<z.ZodObject<{
|
|
3799
|
+
filePath: z.ZodString;
|
|
3800
|
+
bytesRead: z.ZodNumber;
|
|
3801
|
+
lastModified: z.ZodString;
|
|
3802
|
+
sessionContext: z.ZodOptional<z.ZodCustom<{
|
|
3803
|
+
model: string | null;
|
|
3804
|
+
cwd: string | null;
|
|
3805
|
+
} & {
|
|
3806
|
+
adapterSessionId: string;
|
|
3807
|
+
sessionEvent: NormalizedEvent;
|
|
3808
|
+
startedEvent: NormalizedEvent;
|
|
3809
|
+
state: _$type_fest0.JsonObject;
|
|
3810
|
+
}, {
|
|
3811
|
+
model: string | null;
|
|
3812
|
+
cwd: string | null;
|
|
3813
|
+
} & {
|
|
3814
|
+
adapterSessionId: string;
|
|
3815
|
+
sessionEvent: NormalizedEvent;
|
|
3816
|
+
startedEvent: NormalizedEvent;
|
|
3817
|
+
state: _$type_fest0.JsonObject;
|
|
3818
|
+
}>>;
|
|
3819
|
+
}, z.core.$strip>>;
|
|
3820
|
+
}, z.core.$strip>;
|
|
3821
|
+
};
|
|
3822
|
+
/**
|
|
3823
|
+
* Set or update the cursor position for a log file.
|
|
3824
|
+
*
|
|
3825
|
+
* Subject: `storage:importCursor.set`
|
|
3826
|
+
* Type: Request (RPC)
|
|
3827
|
+
*/
|
|
3828
|
+
set: {
|
|
3829
|
+
request: z.ZodObject<{
|
|
3830
|
+
filePath: z.ZodString;
|
|
3831
|
+
bytesRead: z.ZodNumber;
|
|
3832
|
+
lastModified: z.ZodString;
|
|
3833
|
+
sessionContext: z.ZodOptional<z.ZodCustom<{
|
|
3834
|
+
model: string | null;
|
|
3835
|
+
cwd: string | null;
|
|
3836
|
+
} & {
|
|
3837
|
+
adapterSessionId: string;
|
|
3838
|
+
sessionEvent: NormalizedEvent;
|
|
3839
|
+
startedEvent: NormalizedEvent;
|
|
3840
|
+
state: _$type_fest0.JsonObject;
|
|
3841
|
+
}, {
|
|
3842
|
+
model: string | null;
|
|
3843
|
+
cwd: string | null;
|
|
3844
|
+
} & {
|
|
3845
|
+
adapterSessionId: string;
|
|
3846
|
+
sessionEvent: NormalizedEvent;
|
|
3847
|
+
startedEvent: NormalizedEvent;
|
|
3848
|
+
state: _$type_fest0.JsonObject;
|
|
3849
|
+
}>>;
|
|
3850
|
+
}, z.core.$strip>;
|
|
3851
|
+
response: z.ZodObject<{
|
|
3852
|
+
success: z.ZodBoolean;
|
|
3853
|
+
}, z.core.$strip>;
|
|
3854
|
+
};
|
|
3855
|
+
/**
|
|
3856
|
+
* Delete the cursor for a log file.
|
|
3857
|
+
*
|
|
3858
|
+
* Subject: `storage:importCursor.delete`
|
|
3859
|
+
* Type: Request (RPC)
|
|
3860
|
+
* @remarks
|
|
3861
|
+
* Useful when a file is detected as rotated/truncated and needs
|
|
3862
|
+
* to be re-read from the beginning.
|
|
3863
|
+
*/
|
|
3864
|
+
delete: {
|
|
3865
|
+
request: z.ZodObject<{
|
|
3866
|
+
filePath: z.ZodString;
|
|
3867
|
+
}, z.core.$strip>;
|
|
3868
|
+
response: z.ZodObject<{
|
|
3869
|
+
success: z.ZodBoolean;
|
|
3870
|
+
}, z.core.$strip>;
|
|
3871
|
+
};
|
|
3872
|
+
}>, "storage:importCursor">;
|
|
3873
|
+
//#endregion
|
|
3874
|
+
//#region adapters/core/src/log-importer/cursor-memory-handler.d.ts
|
|
3875
|
+
/**
|
|
3876
|
+
* Register in-memory import cursor storage handlers.
|
|
3877
|
+
*
|
|
3878
|
+
* Suitable for development, testing, and single-instance deployments.
|
|
3879
|
+
* For production with persistence, implement a file-based or database-backed handler.
|
|
3880
|
+
* @param bus - The bus instance to register handlers on
|
|
3881
|
+
* @returns Cleanup function to unsubscribe all handlers
|
|
3882
|
+
* @example
|
|
3883
|
+
* ```typescript
|
|
3884
|
+
* import { registerMemoryImportCursorStorage } from '@makaio/framework/adapters';
|
|
3885
|
+
*
|
|
3886
|
+
* const cleanup = registerMemoryImportCursorStorage(bus);
|
|
3887
|
+
*
|
|
3888
|
+
* // Later, when shutting down:
|
|
3889
|
+
* cleanup();
|
|
3890
|
+
* ```
|
|
3891
|
+
*/
|
|
3892
|
+
declare function registerMemoryImportCursorStorage(bus: IMakaioBus): () => void;
|
|
3893
|
+
//#endregion
|
|
3894
|
+
//#region adapters/core/src/log-importer/turn-tracker.d.ts
|
|
3895
|
+
/**
|
|
3896
|
+
* Turn lifecycle state.
|
|
3897
|
+
* @remarks
|
|
3898
|
+
* - `idle`: No active turn, waiting for a turn to start
|
|
3899
|
+
* - `active`: Turn in progress, waiting for completion
|
|
3900
|
+
*/
|
|
3901
|
+
type TurnState = 'idle' | 'active';
|
|
3902
|
+
/**
|
|
3903
|
+
* Synthetic turn event to be emitted during log import.
|
|
3904
|
+
* @remarks
|
|
3905
|
+
* These events are synthesized by the state machine when it detects
|
|
3906
|
+
* turn boundaries (e.g., user message starts a turn, final text completes it).
|
|
3907
|
+
* @see {@link TurnTracker} - State machine that produces these events
|
|
3908
|
+
*/
|
|
3909
|
+
interface TurnEvent {
|
|
3910
|
+
/** Type of turn event */
|
|
3911
|
+
type: 'turn.started' | 'turn.completed';
|
|
3912
|
+
/** Session ID for this turn (from the record that triggered the transition) */
|
|
3913
|
+
sessionId: string;
|
|
3914
|
+
/** Unique identifier for this turn instance */
|
|
3915
|
+
turnId: string;
|
|
3916
|
+
}
|
|
3917
|
+
/**
|
|
3918
|
+
* Configuration options for the turn tracker.
|
|
3919
|
+
* @remarks
|
|
3920
|
+
* Adapters provide detection functions specific to their log format:
|
|
3921
|
+
* - Claude Code: `detectTurnStart` triggers on user messages,
|
|
3922
|
+
* `detectTurnComplete` triggers on final text content blocks
|
|
3923
|
+
* - Copilot: Explicit `turn_start`/`turn_end` events, may bypass this tracker
|
|
3924
|
+
* @typeParam TRecord - The adapter's native log record type
|
|
3925
|
+
* @see {@link TurnTracker} - Uses these options
|
|
3926
|
+
*/
|
|
3927
|
+
interface TurnTrackerOptions<TRecord> {
|
|
3928
|
+
/**
|
|
3929
|
+
* Detect if a record indicates the start of a turn.
|
|
3930
|
+
* @param record - Log record to check
|
|
3931
|
+
* @returns True if this record starts a new turn
|
|
3932
|
+
* @example
|
|
3933
|
+
* ```typescript
|
|
3934
|
+
* // Claude Code: user message starts a turn
|
|
3935
|
+
* detectTurnStart: (record) => record.type === 'user'
|
|
3936
|
+
* ```
|
|
3937
|
+
*/
|
|
3938
|
+
detectTurnStart: (record: TRecord) => boolean;
|
|
3939
|
+
/**
|
|
3940
|
+
* Detect if a record indicates the completion of a turn.
|
|
3941
|
+
* @param record - Log record to check
|
|
3942
|
+
* @returns True if this record completes the current turn
|
|
3943
|
+
* @example
|
|
3944
|
+
* ```typescript
|
|
3945
|
+
* // Claude Code: final text block completes a turn
|
|
3946
|
+
* detectTurnComplete: (record) =>
|
|
3947
|
+
* record.type === 'assistant' &&
|
|
3948
|
+
* record.message?.content?.some((b) => b.type === 'text')
|
|
3949
|
+
* ```
|
|
3950
|
+
*/
|
|
3951
|
+
detectTurnComplete: (record: TRecord) => boolean;
|
|
3952
|
+
/**
|
|
3953
|
+
* Extract the session ID from a log record.
|
|
3954
|
+
* @param record - Log record to extract session ID from
|
|
3955
|
+
* @returns Session ID string
|
|
3956
|
+
* @example
|
|
3957
|
+
* ```typescript
|
|
3958
|
+
* getSessionId: (record) => record.sessionId
|
|
3959
|
+
* ```
|
|
3960
|
+
*/
|
|
3961
|
+
getSessionId: (record: TRecord) => string;
|
|
3962
|
+
/**
|
|
3963
|
+
* Optional custom function to generate turn IDs.
|
|
3964
|
+
* @defaultValue Uses `crypto.randomUUID()`
|
|
3965
|
+
* @remarks
|
|
3966
|
+
* Override this for deterministic testing or custom ID schemes.
|
|
3967
|
+
* @param sessionId - The session ID for context
|
|
3968
|
+
* @returns Unique turn ID string
|
|
3969
|
+
*/
|
|
3970
|
+
generateTurnId?: (sessionId: string) => string;
|
|
3971
|
+
}
|
|
3972
|
+
/**
|
|
3973
|
+
* Serialized form of TurnTracker state for persistence across chunks/restarts.
|
|
3974
|
+
* @remarks
|
|
3975
|
+
* Used by {@link TurnTracker.serialize} and {@link TurnTracker.restore} to
|
|
3976
|
+
* enable incremental log imports that can resume processing.
|
|
3977
|
+
*/
|
|
3978
|
+
interface TurnTrackerSerializedState {
|
|
3979
|
+
/** Session states keyed by session ID */
|
|
3980
|
+
sessions: Record<string, {
|
|
3981
|
+
state: TurnState;
|
|
3982
|
+
currentTurnId?: string;
|
|
3983
|
+
}>;
|
|
3984
|
+
}
|
|
3985
|
+
/**
|
|
3986
|
+
* Zod schema for validating serialized TurnTracker state.
|
|
3987
|
+
*
|
|
3988
|
+
* Used by adapter log importers to safely deserialize cursor state
|
|
3989
|
+
* without unsafe `as` casts.
|
|
3990
|
+
* @see {@link TurnTrackerSerializedState} - TypeScript interface this validates
|
|
3991
|
+
*/
|
|
3992
|
+
declare const TurnTrackerSerializedStateSchema: z.ZodDefault<z.ZodObject<{
|
|
3993
|
+
sessions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
3994
|
+
state: z.ZodEnum<{
|
|
3995
|
+
active: "active";
|
|
3996
|
+
idle: "idle";
|
|
3997
|
+
}>;
|
|
3998
|
+
currentTurnId: z.ZodOptional<z.ZodString>;
|
|
3999
|
+
}, z.core.$strip>>;
|
|
4000
|
+
}, z.core.$strip>>;
|
|
4001
|
+
/**
|
|
4002
|
+
* State machine for tracking turn boundaries during log import.
|
|
4003
|
+
*
|
|
4004
|
+
* ## Purpose
|
|
4005
|
+
*
|
|
4006
|
+
* Some external tools (like Claude Code) don't emit explicit turn start/end events.
|
|
4007
|
+
* This tracker synthesizes these events based on adapter-specific detection logic.
|
|
4008
|
+
*
|
|
4009
|
+
* ## State Transitions
|
|
4010
|
+
*
|
|
4011
|
+
* ```
|
|
4012
|
+
* idle --[turn start detected]--> active (emit turn.started)
|
|
4013
|
+
* active --[turn complete detected]--> idle (emit turn.completed)
|
|
4014
|
+
* ```
|
|
4015
|
+
*
|
|
4016
|
+
* ## Multi-Session Support
|
|
4017
|
+
*
|
|
4018
|
+
* The tracker maintains independent state per session ID, enabling
|
|
4019
|
+
* concurrent processing of multiple sessions from the same log file.
|
|
4020
|
+
* @remarks
|
|
4021
|
+
* - Thread-safe for single-threaded async processing (no mutex needed)
|
|
4022
|
+
* - Stateless between sessions (each session tracked independently)
|
|
4023
|
+
* - Idempotent: processing the same record twice produces consistent results
|
|
4024
|
+
* @typeParam TRecord - The adapter's native log record type
|
|
4025
|
+
* @example
|
|
4026
|
+
* ```typescript
|
|
4027
|
+
* // Create tracker for Claude Code logs
|
|
4028
|
+
* const tracker = new TurnTracker({
|
|
4029
|
+
* detectTurnStart: (record) => record.type === 'user',
|
|
4030
|
+
* detectTurnComplete: (record) =>
|
|
4031
|
+
* record.type === 'assistant' &&
|
|
4032
|
+
* record.message?.content?.some((b) => b.type === 'text'),
|
|
4033
|
+
* getSessionId: (record) => record.sessionId,
|
|
4034
|
+
* });
|
|
4035
|
+
*
|
|
4036
|
+
* // Process records
|
|
4037
|
+
* for (const record of records) {
|
|
4038
|
+
* const turnEvents = tracker.processRecord(record);
|
|
4039
|
+
* for (const event of turnEvents) {
|
|
4040
|
+
* // Emit turn.started or turn.completed events
|
|
4041
|
+
* console.log(event.type, event.turnId);
|
|
4042
|
+
* }
|
|
4043
|
+
* }
|
|
4044
|
+
* ```
|
|
4045
|
+
* @see {@link TurnTrackerOptions} - Configuration options
|
|
4046
|
+
* @see {@link TurnEvent} - Emitted turn events
|
|
4047
|
+
*/
|
|
4048
|
+
declare class TurnTracker<TRecord> {
|
|
4049
|
+
private readonly options;
|
|
4050
|
+
private readonly sessions;
|
|
4051
|
+
private readonly generateTurnId;
|
|
4052
|
+
/**
|
|
4053
|
+
* Create a new turn tracker.
|
|
4054
|
+
* @param options - Tracker configuration with detection functions
|
|
4055
|
+
*/
|
|
4056
|
+
constructor(options: TurnTrackerOptions<TRecord>);
|
|
4057
|
+
/**
|
|
4058
|
+
* Process a log record and return any turn events that should be emitted.
|
|
4059
|
+
* @param record - Log record to process
|
|
4060
|
+
* @returns Array of turn events (may be empty, one, or two if turn completes and new one starts)
|
|
4061
|
+
* @remarks
|
|
4062
|
+
* ## Transition Rules
|
|
4063
|
+
*
|
|
4064
|
+
* 1. **idle + turn start detected** emits `turn.started`, transitions to active
|
|
4065
|
+
* 2. **active + turn complete detected** emits `turn.completed`, transitions to idle
|
|
4066
|
+
* 3. **active + turn start detected** emits `turn.completed` for previous turn,
|
|
4067
|
+
* then emits `turn.started` for new turn (implicit completion)
|
|
4068
|
+
* 4. **idle + turn complete detected** is a no-op (no active turn to complete)
|
|
4069
|
+
*
|
|
4070
|
+
* Rule 3 handles cases where a user sends another message before the assistant
|
|
4071
|
+
* finishes responding (rare but possible in log replays).
|
|
4072
|
+
*/
|
|
4073
|
+
processRecord(record: TRecord): TurnEvent[];
|
|
4074
|
+
/**
|
|
4075
|
+
* Get the current turn state for a session.
|
|
4076
|
+
* @param sessionId - Session identifier
|
|
4077
|
+
* @returns Current turn state ('idle' if session not tracked)
|
|
4078
|
+
*/
|
|
4079
|
+
getState(sessionId: string): TurnState;
|
|
4080
|
+
/**
|
|
4081
|
+
* Get the current turn ID for a session.
|
|
4082
|
+
* @param sessionId - Session identifier
|
|
4083
|
+
* @returns Current turn ID or undefined if no active turn
|
|
4084
|
+
*/
|
|
4085
|
+
getCurrentTurnId(sessionId: string): string | undefined;
|
|
4086
|
+
/**
|
|
4087
|
+
* Check if a session has an active turn.
|
|
4088
|
+
* @param sessionId - Session identifier
|
|
4089
|
+
* @returns True if the session has an active (non-idle) turn
|
|
4090
|
+
*/
|
|
4091
|
+
hasActiveTurn(sessionId: string): boolean;
|
|
4092
|
+
/**
|
|
4093
|
+
* Reset state for a specific session.
|
|
4094
|
+
* @remarks
|
|
4095
|
+
* Use this when a session is known to be complete or when re-processing.
|
|
4096
|
+
* @param sessionId - Session identifier
|
|
4097
|
+
* @returns True if the session was tracked and removed
|
|
4098
|
+
*/
|
|
4099
|
+
resetSession(sessionId: string): boolean;
|
|
4100
|
+
/**
|
|
4101
|
+
* Reset all tracked session state.
|
|
4102
|
+
* @remarks
|
|
4103
|
+
* Use this for cleanup or when starting fresh.
|
|
4104
|
+
*/
|
|
4105
|
+
resetAll(): void;
|
|
4106
|
+
/**
|
|
4107
|
+
* Serialize the tracker state for persistence.
|
|
4108
|
+
* @remarks
|
|
4109
|
+
* Use this to save state between chunks or before process shutdown
|
|
4110
|
+
* for incremental log imports.
|
|
4111
|
+
* @returns JSON-serializable state object
|
|
4112
|
+
* @see {@link restore} - Restore state from serialized form
|
|
4113
|
+
*/
|
|
4114
|
+
serialize(): TurnTrackerSerializedState;
|
|
4115
|
+
/**
|
|
4116
|
+
* Restore tracker state from a serialized form.
|
|
4117
|
+
* @remarks
|
|
4118
|
+
* Clears all current state before restoring. Use this to resume
|
|
4119
|
+
* processing after a restart or between chunks.
|
|
4120
|
+
* @param serialized - State object from {@link serialize}
|
|
4121
|
+
* @see {@link serialize} - Create serialized state
|
|
4122
|
+
*/
|
|
4123
|
+
restore(serialized: TurnTrackerSerializedState): void;
|
|
4124
|
+
/**
|
|
4125
|
+
* Get all currently tracked session IDs.
|
|
4126
|
+
* @returns Array of session IDs being tracked
|
|
4127
|
+
*/
|
|
4128
|
+
getTrackedSessions(): string[];
|
|
4129
|
+
/**
|
|
4130
|
+
* Manually complete the current turn for a session.
|
|
4131
|
+
* @remarks
|
|
4132
|
+
* Use this for cleanup when processing ends mid-turn (e.g., end of file
|
|
4133
|
+
* with an incomplete conversation). Does nothing if no active turn.
|
|
4134
|
+
* @param sessionId - Session identifier
|
|
4135
|
+
* @returns Turn completed event or undefined if no active turn
|
|
4136
|
+
*/
|
|
4137
|
+
forceCompleteTurn(sessionId: string): TurnEvent | undefined;
|
|
4138
|
+
/**
|
|
4139
|
+
* Get or create session state for a session ID.
|
|
4140
|
+
* @param sessionId - Session identifier
|
|
4141
|
+
* @returns Session state (creates new idle state if not exists)
|
|
4142
|
+
*/
|
|
4143
|
+
private getOrCreateSessionState;
|
|
4144
|
+
}
|
|
4145
|
+
//#endregion
|
|
4146
|
+
//#region adapters/core/src/namespaces/schemas/lifecycle.d.ts
|
|
4147
|
+
/**
|
|
4148
|
+
* Schema for agent started event.
|
|
4149
|
+
* Emitted when agent begins processing a user message.
|
|
4150
|
+
*/
|
|
4151
|
+
declare const AgentStartedEventSchema: z.ZodObject<{
|
|
4152
|
+
eventType: z.ZodLiteral<"agent_started">;
|
|
4153
|
+
model: z.ZodOptional<z.ZodString>;
|
|
4154
|
+
}, z.core.$strip>;
|
|
4155
|
+
/**
|
|
4156
|
+
* Schema for agent complete event.
|
|
4157
|
+
* Emitted when agent finishes processing (success or error).
|
|
4158
|
+
*/
|
|
4159
|
+
declare const AgentCompleteEventSchema: z.ZodObject<{
|
|
4160
|
+
eventType: z.ZodLiteral<"agent_complete">;
|
|
4161
|
+
message: z.ZodOptional<z.ZodString>;
|
|
4162
|
+
error: z.ZodOptional<z.ZodString>;
|
|
4163
|
+
}, z.core.$strip>;
|
|
4164
|
+
/**
|
|
4165
|
+
* Schema for error event.
|
|
4166
|
+
* Emitted when an error occurs during processing.
|
|
4167
|
+
*/
|
|
4168
|
+
declare const ErrorEventSchema: z.ZodObject<{
|
|
4169
|
+
eventType: z.ZodLiteral<"error">;
|
|
4170
|
+
message: z.ZodString;
|
|
4171
|
+
code: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodNumber]>>;
|
|
4172
|
+
type: z.ZodOptional<z.ZodString>;
|
|
4173
|
+
}, z.core.$strip>;
|
|
4174
|
+
type AgentStartedEvent = z.infer<typeof AgentStartedEventSchema>;
|
|
4175
|
+
type AgentCompleteEvent = z.infer<typeof AgentCompleteEventSchema>;
|
|
4176
|
+
type ErrorEvent = z.infer<typeof ErrorEventSchema>;
|
|
4177
|
+
//#endregion
|
|
4178
|
+
//#region adapters/core/src/namespaces/schemas/tool-lifecycle.d.ts
|
|
4179
|
+
/**
|
|
4180
|
+
* Schema for tool started event.
|
|
4181
|
+
* Emitted when tool execution begins.
|
|
4182
|
+
*/
|
|
4183
|
+
declare const ToolStartedEventSchema: z.ZodObject<{
|
|
4184
|
+
eventType: z.ZodLiteral<"tool_started">;
|
|
4185
|
+
toolName: z.ZodString;
|
|
4186
|
+
toolCallId: z.ZodString;
|
|
4187
|
+
}, z.core.$strip>;
|
|
4188
|
+
/**
|
|
4189
|
+
* Schema for tool completed event.
|
|
4190
|
+
* Emitted when tool execution finishes (success or failure).
|
|
4191
|
+
*/
|
|
4192
|
+
declare const ToolCompletedEventSchema: z.ZodObject<{
|
|
4193
|
+
eventType: z.ZodLiteral<"tool_completed">;
|
|
4194
|
+
toolName: z.ZodString;
|
|
4195
|
+
toolCallId: z.ZodString;
|
|
4196
|
+
result: z.ZodString;
|
|
4197
|
+
success: z.ZodBoolean;
|
|
4198
|
+
}, z.core.$strip>;
|
|
4199
|
+
type ToolStartedEvent = z.infer<typeof ToolStartedEventSchema>;
|
|
4200
|
+
type ToolCompletedEvent = z.infer<typeof ToolCompletedEventSchema>;
|
|
4201
|
+
//#endregion
|
|
4202
|
+
export { AIAdapter, type AIAdapterCapabilities, type AIAdapterCapability, type AIAdapterCapabilityRegistry, type AIAdapterConfig, type AIAdapterConstructorConfig, type AIAdapterContext, type AIAdapterDefinition, type AIAdapterInitOptions, type AIAdapterPromptFailureResult, type AIAdapterPromptOptions, type AIAdapterPromptResult, type AIAdapterPromptSuccessResult, AIAgent, type AIAgentConfig, AIAgentConnector, type AIModel, type AIReasoningLevel, type AdapterNamespace, type AdapterProviderDefinition, type AgentBusHandlerRegistrarConfig, type AgentCompleteEvent, AgentCompleteEventSchema, AgentConnectorLifecycleManager, type AgentConnectorLifecycleManagerConfig, type AgentContext, AgentEventBridge, type AgentEventBridgeConfig, type AgentIdentity, AgentLifecycleEmitter, type AgentLifecycleEmitterConfig, AgentPayloadEmitter, type AgentPayloadEmitterConfig, type AgentRuntimeCreationResult, AgentRuntimeMutationManager, type AgentRuntimeMutationManagerConfig, type AgentSendMessageOptions, type AgentStartResult, type AgentStartedEvent, AgentStartedEventSchema, AgentTurnExecutor, type AgentTurnExecutorConfig, type AgentUsageTotals, type BaseAgentConnectorConfig, BaseConnectorSession, BaseConnectorTurn, BaseLogImporter, type CompactionMetadata, type ConfigFactoryInput, type ConformanceEnvReader, type ConformanceTestConfig, type ConnectorSendMessageOptions, type ConnectorSessionConfig, type ConnectorStartOptions, type CreateConformanceTestConfigOptions, type CreateTestAgentOptions, type DiscoveryMetadata, type DiscriminatedHandler, type DiscriminatedHandlersConfig, type DiscriminatedHandlersMap, type ErrorEvent, ErrorEventSchema, type ExecutionContext, type ExternalToolIdentifier, type ExternalToolIdentifiers, type ExternalToolMeta, type FromGlobalToolApprovalFn, type GeneratedCapabilityProperties, type HarnessRequester, type IAdapterConfigFactory, type ISessionToolLedger, type ImportCursorPosition, ImportCursorPositionSchema, ImportCursorStorageNamespace, ImportCursorStorageSubjects, type ImportMetadata, type ImportSegment, type ImportSegmentLineage, type LedgerSessionContext, type LogImportConfig, type LogImportOrchestrator, type LogImportRegistration, type LogImportSessionContext, type LogImportTestConfig, type LogImporter, type LogImporterConfig, type LogImporterConstructor, type LogOrchestratorConfig, type LogOrchestratorConstructor, MAKAIO_CONFORMANCE_PRIMARY_MODEL_ENV, MAKAIO_CONFORMANCE_PROVIDER_DEFINITIONS_ENV, MAKAIO_CONFORMANCE_PROVIDER_ENV, MAKAIO_CONFORMANCE_SECONDARY_MODEL_ENV, type McpIntegrationStrategy, type McpSessionResources, type McpToolChange, type MergeResult, type MergeScopedToolApprovalOptions, type MessageDeliveryMode, MessageHandle, MessageLifecycleTracker, type MessageResult, type MessageState, type NormalizedCallUsage, type NormalizedEvent, type NormalizedMessageInput, type ParseFileResult, type PauseResult, type PlatformDefaults, ProceduralAgentConnector, type ProceduralConnectorSession, ProceduralConnectorTurn, type ProceduralTurnConfig, type ProceduralTurnState, type ProcessLogFileResult, type ProcessQueueCallbacks, type ProcessingState, type QueueableTurn, type ReasoningLevelMap, type ResolveConformanceTestPresetOptions, type ResolveHints, type ResolvedConformanceTestPreset, type ScopedBusFor, type ScopedToolApprovalRequest, type ScopedToolApprovalResponse, ScopedToolApprovalSchema, type SendMessageOptions, type SendMessageRequest, type SendMessageResponse, type SerializedContextBlock, SessionLifecycle, SessionToolLedger, type ShouldUseNativeResumeFn, type StartAgentOptions, type StartAgentRequest, type StartAgentResponse, type StorageMessagePayload, type SyncDiscriminatedHandler, type SyncDiscriminatedHandlersConfig, type SyncDiscriminatedHandlersMap, type SyncTypedEmitFn, type TestModelRef, type ToGlobalToolApprovalFn, type ToolApprovalContext, ToolCallTracker, type ToolCompletedEvent, ToolCompletedEventSchema, type ToolLedgerEntry, type ToolStartedEvent, ToolStartedEventSchema, type TurnEvent, type TurnState, type TurnSubjects, TurnTracker, type TurnTrackerOptions, type TurnTrackerSerializedState, TurnTrackerSerializedStateSchema, type TypedEmitFn, UserMessageQueue, type ValidCapability, type WireSessionConfig, type WireSessionSubjects, cleanEnvForAdapter, createAdapterNamespace, createTestProviderContext, createToolApprovalHandler, defineDiscriminatedHandlers, defineDiscriminatedHandlersSync, extractMcpCallTarget, formatContextBlockAsText, formatContextBlocksAsText, formatMessageHistoryAsTranscript, isMcpCallTool, isTextLikeMimeType, markCompletedWithFinalResult, mergeScopedToolApproval, normalizeEnvValue, normalizeMessageInput, normalizeMimeType, parseAIAdapterCapabilities, processDiscriminatedItems, processDiscriminatedItemsSync, processQueueMessages, registerAgentBusHandlers, registerMemoryImportCursorStorage, resolveConformanceTestPreset, resolveDisabledNativeTools, resolvePresetCredentials, resolveRequiredSessionId, resolveTestConfig, safeJsonStringify, serializeBlockToText, serializeTurnContext, toImportSegment };
|