@xopcai/xopc 0.0.368 → 0.0.370
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/README.md +59 -174
- package/README.zh-CN.md +59 -174
- package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/_md.js +131 -0
- package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/_u64.js +30 -0
- package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/sha2.js +252 -0
- package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/sha256.js +16 -0
- package/dist/.pnpm/@noble_hashes@1.8.0/node_modules/@noble/hashes/esm/utils.js +66 -0
- package/dist/browser-ext/_locales/en/messages.json +30 -1
- package/dist/browser-ext/_locales/zh_CN/messages.json +30 -1
- package/dist/browser-ext/dist/assets/{auth-beGtbLPS.js → page-context-BeworyNB.js} +1331 -1355
- package/dist/browser-ext/dist/assets/{sidepanel-BT0ojEzG.css → sidepanel-Ccl0eSa1.css} +43 -0
- package/dist/browser-ext/dist/background.js +680 -182
- package/dist/browser-ext/dist/sidepanel.html +2 -2
- package/dist/browser-ext/dist/sidepanel.js +393 -194
- package/dist/browser-ext/manifest.json +2 -8
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{activity-store-D9ZMh5ZR.js → activity-store-BQ3PMp2q.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-Bj3rvcTm.js → agent-avatar-dicebear-C61i1QbX.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-0fCR1DHx.js +1 -0
- package/dist/gateway/static/root/assets/agent-plugin-dialog-Di99mUTT.js +1 -0
- package/dist/gateway/static/root/assets/agents-BRZZmYH_.js +66 -0
- package/dist/gateway/static/root/assets/{agents-admin-api-B5QDepbW.js → agents-admin-api-HBZvVyzF.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-2rTEtB_X.js → app-management-settings-panel-noqqxkds.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-BPVBS80k.js → appearance-settings-DG8QN0gR.js} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-1FuKlZYP.js → apps-page-CgiyzFYo.js} +1 -1
- package/dist/gateway/static/root/assets/{archive-plugin-BbT1O7oK.js → archive-plugin-BO3I9zRP.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-DjwP_h8h.js → automations-page-CgAcRFDS.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-BIkxIpab.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-gS7Wg68v.js → binary-plugins-gFD7vH9R.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-DbwMaivP.js → block-editor-B1VE-jAe.js} +2 -2
- package/dist/gateway/static/root/assets/browser-automation-inputs-DxRoKFun.js +1 -0
- package/dist/gateway/static/root/assets/browser-automations-page-CIjyMS6f.js +3 -0
- package/dist/gateway/static/root/assets/browser-settings-page-BMAivBfp.js +3 -0
- package/dist/gateway/static/root/assets/{capabilities-Lswa0hv8.js → capabilities-CY4SiHcP.js} +1 -1
- package/dist/gateway/static/root/assets/{capabilities-Dd1PZRQw.js → capabilities-gjQtMhKu.js} +1 -1
- package/dist/gateway/static/root/assets/capabilities-page-DRdcfo68.js +2 -0
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-DTHR1DrJ.js → capabilities-settings-panel-ZuL6pWjM.js} +4 -4
- package/dist/gateway/static/root/assets/{capability-header-actions-494dnJsj.js → capability-header-actions-D0GC1FEv.js} +1 -1
- package/dist/gateway/static/root/assets/channels-CgE22Pzd.js +1 -0
- package/dist/gateway/static/root/assets/{chat-terminal-dock-Bl7-Zk-x.js → chat-terminal-dock-CEjh1utz.js} +2 -2
- package/dist/gateway/static/root/assets/{computer-settings-page-ByExKr_6.js → computer-settings-page-vFHJAmQr.js} +1 -1
- package/dist/gateway/static/root/assets/{connector-service-page-BK_5aFxO.js → connector-service-page-DTrwZ4kV.js} +1 -1
- package/dist/gateway/static/root/assets/connectors-page-DRcMiTWu.js +1 -0
- package/dist/gateway/static/root/assets/copy-text-row-C1gaJwlZ.js +1 -0
- package/dist/gateway/static/root/assets/{date-picker-BXJv6472.js → date-picker-NfGIPSYY.js} +1 -1
- package/dist/gateway/static/root/assets/dependency-picker-CqguveUi.js +1 -0
- package/dist/gateway/static/root/assets/{desktop-pet-DWNEC3mk.js → desktop-pet-CTx1zkJm.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-BYwlxGiN.js → desktop-pet-settings-BRDS3EGc.js} +1 -1
- package/dist/gateway/static/root/assets/{device-pairing-wizard-BAc4F35b.js → device-pairing-wizard-Du4Ciuyw.js} +1 -1
- package/dist/gateway/static/root/assets/{directory-picker-path-field-D26tSY8Z.js → directory-picker-path-field-CjstlxFl.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-xYIGNegB.js → extension-debug-page-BfAtjhoK.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-BoQ1-3AW.js → extension-page-BJmudejr.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-provider-Cw_JU6RR.js → extension-provider-Br6LXyIj.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BH5TFGPe.js → extension-settings-page-UvmHniyz.js} +1 -1
- package/dist/gateway/static/root/assets/{fallback-models-04Wqmw14.js → fallback-models-euw9MGdt.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-CNf0ZeRw.js → gateway-config-swr-7RKqgU_U.js} +1 -1
- package/dist/gateway/static/root/assets/gateway-realtime-F6D4A7N5.js +1 -0
- package/dist/gateway/static/root/assets/gateway-realtime-store-BheKaO6d.js +1 -0
- package/dist/gateway/static/root/assets/{gateway-settings-BqvCJVUC.js → gateway-settings-C7roPHh1.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DIxHacUw.js → gateway-startup-retry-jiV5sbEX.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-BGNCTtM3.js +2 -0
- package/dist/gateway/static/root/assets/{image-generation-api-CS0q0Kto.js → image-generation-api-DO4mXb6I.js} +1 -1
- package/dist/gateway/static/root/assets/{imports-page-n_rSLo6b.js → imports-page-DxCoT0VV.js} +1 -1
- package/dist/gateway/static/root/assets/index-BGBkIIzM.css +1 -0
- package/dist/gateway/static/root/assets/index-FCEE325-.js +106 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-tVkrHbYF.js → keyboard-shortcuts-settings-CnLln9Ds.js} +1 -1
- package/dist/gateway/static/root/assets/{local-app-workbench-page-L8tYuas0.js → local-app-workbench-page-yXRkSrEj.js} +1 -1
- package/dist/gateway/static/root/assets/{local-apps-page-SSJ9B1bH.js → local-apps-page-D46buzTk.js} +1 -1
- package/dist/gateway/static/root/assets/local-session-drafts-pox8evDV.js +1 -0
- package/dist/gateway/static/root/assets/{locale-store-D6_rF-qT.js → locale-store-COVscAqC.js} +1 -1
- package/dist/gateway/static/root/assets/logs-page-DmcCHnH0.js +2 -0
- package/dist/gateway/static/root/assets/management-settings-khN1ThNL.js +1 -0
- package/dist/gateway/static/root/assets/{markdown-view-_xwUuKce.js → markdown-view-B_qnAcW2.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-C631CDu4.js → media-plugins-C0Pc-wSY.js} +1 -1
- package/dist/gateway/static/root/assets/messages-Bb2GK-Nj.js +3 -0
- package/dist/gateway/static/root/assets/models-hub-cache-DyPPksMP.js +1 -0
- package/dist/gateway/static/root/assets/note-detail-panel-C_t58yha.js +5 -0
- package/dist/gateway/static/root/assets/{notes-api-vIZWQ9Yt.js → notes-api-sBgBcyLW.js} +1 -1
- package/dist/gateway/static/root/assets/notes-page-BJ0QS6xx.js +8 -0
- package/dist/gateway/static/root/assets/{page-context-capture-button-BlPDM7GM.js → page-context-capture-button-DfRODHv1.js} +1 -1
- package/dist/gateway/static/root/assets/personal-page-CiiXwwQE.js +1 -0
- package/dist/gateway/static/root/assets/{product-open-page-BJjWvoER.js → product-open-page-_Bp6HRmm.js} +1 -1
- package/dist/gateway/static/root/assets/{product-preview-content-CEd4E7Gf.js → product-preview-content-BUdiO0Ct.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-Clb-fXYk.js +1 -0
- package/dist/gateway/static/root/assets/{projects-page-lszV8HuS.js → projects-page-D9JEEqhh.js} +1 -1
- package/dist/gateway/static/root/assets/{registry-api-uJnjqTcn.js → registry-api-Bh9UBb-f.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-CmyTq3_l.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-CjnNQYW8.js → runtime-tools-settings-panel-B1_inj8L.js} +1 -1
- package/dist/gateway/static/root/assets/{scenes-page-B3T3dDOR.js → scenes-page-CUNAZN2_.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-DT3c4Vd_.js → schema-form-CfT-9UVw.js} +1 -1
- package/dist/gateway/static/root/assets/{send-session-input-CICkGwn-.js → send-session-input-BW40VHiL.js} +1 -1
- package/dist/gateway/static/root/assets/{session-api-BcQodoAu.js → session-api-yjpEz4pP.js} +1 -1
- package/dist/gateway/static/root/assets/session-manager-BqlvrjPE.js +16 -0
- package/dist/gateway/static/root/assets/sessions-page-CXZKScvu.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-B2vKXmzg.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-D-PZjcss.js → settings-page-1h3vyueg.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-Cqc7UlZy.js +1 -0
- package/dist/gateway/static/root/assets/{share-link-dialog-CWS8EkJS.js → share-link-dialog-HCHM8qnf.js} +1 -1
- package/dist/gateway/static/root/assets/{share-preview-page-23NJAKiq.js → share-preview-page-Ce6FNWt1.js} +1 -1
- package/dist/gateway/static/root/assets/{shares-api-iKhHbvBD.js → shares-api-c0dfWz6h.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-Dh5jisCK.js +1 -0
- package/dist/gateway/static/root/assets/{skill-api-C-MWdQwl.js → skill-api-deDZeQS8.js} +1 -1
- package/dist/gateway/static/root/assets/{skill-reload-api-iy02aB13.js → skill-reload-api-Ge5XymHa.js} +1 -1
- package/dist/gateway/static/root/assets/skills-page-DZozl9U_.js +2 -0
- package/dist/gateway/static/root/assets/system-settings-panel-CtzyMxqq.js +1 -0
- package/dist/gateway/static/root/assets/{task-detail-page-B2SIEyhZ.js → task-detail-page-5f_V0h-p.js} +2 -2
- package/dist/gateway/static/root/assets/{task-expandable-content-D2LRR4BC.js → task-expandable-content-hYcgCEE3.js} +1 -1
- package/dist/gateway/static/root/assets/{theme-store-BJfhz-Zq.js → theme-store-BOfCKgl6.js} +1 -1
- package/dist/gateway/static/root/assets/{tracing-settings-page-aHD56iaS.js → tracing-settings-page-DDWFXcST.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-BCf8CfTC.js → tunnel-api-vMtlbJ-m.js} +1 -1
- package/dist/gateway/static/root/assets/{usage-page-B4XUkuJd.js → usage-page-B1-BCW8U.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-BnnTw9RE.js → use-autosave-CSckcjFx.js} +1 -1
- package/dist/gateway/static/root/assets/{use-composer-attachments-Itczg0y1.js → use-composer-attachments-DJya1hIL.js} +1 -1
- package/dist/gateway/static/root/assets/use-file-preview-expanded-C5ONO7sF.js +2 -0
- package/dist/gateway/static/root/assets/user-model-page-D4BSq9HJ.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-BphJku8x.js → voice-api-key-field-GEw5x2fU.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-B4u4coFj.js → voice-config-api-3yyVwXln.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-jgOEP1xw.js → work-discovery-overlay-CjiNYJV5.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-N69crzRu.js → workflow-run-setup-panel-DJOetXvm.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-CcAPFh2R.js +6 -0
- package/dist/gateway/static/root/assets/{workspace-api-Lzv6GDO8.js → workspace-api-WhbMvdBE.js} +2 -2
- package/dist/gateway/static/root/index.html +32 -34
- package/dist/package.js +1 -1
- package/dist/packages/browser-control-contract/src/automation.js +213 -0
- package/dist/packages/browser-control-contract/src/index.js +43 -12
- package/dist/packages/endpoint-tools-client/src/index.js +189 -0
- package/dist/packages/endpoint-tools-protocol/src/bridge.js +105 -0
- package/dist/packages/endpoint-tools-protocol/src/index.js +93 -2
- package/dist/packages/endpoint-tools-protocol/src/location.js +109 -0
- package/dist/packages/gateway-contract/src/gateway-scopes.js +3 -1
- package/dist/packages/gateway-contract/src/notifications.js +1 -0
- package/dist/packages/gateway-contract/src/session-input-command.js +30 -5
- package/dist/packages/realtime-protocol/src/voice.js +9 -3
- package/dist/src/agent/agent-manager.js +22 -26
- package/dist/src/agent/coding/repository-instructions.js +8 -1
- package/dist/src/agent/embedded/codemode-extension.d.ts +7 -0
- package/dist/src/agent/embedded/codemode-extension.js +232 -0
- package/dist/src/agent/embedded/codemode-output.d.ts +2 -0
- package/dist/src/agent/embedded/codemode-output.js +34 -0
- package/dist/src/agent/embedded/external-tool-discovery.d.ts +6 -0
- package/dist/src/agent/embedded/external-tool-discovery.js +60 -0
- package/dist/src/agent/embedded/model-runtime.js +5 -2
- package/dist/src/agent/embedded/run-for-session.js +10 -1
- package/dist/src/agent/embedded/run-turn.js +10 -3
- package/dist/src/agent/embedded/session-runner.d.ts +9 -1
- package/dist/src/agent/embedded/session-runner.js +111 -23
- package/dist/src/agent/embedded/session-tool-result-guard.d.ts +2 -0
- package/dist/src/agent/embedded/session-tool-result-guard.js +17 -0
- package/dist/src/agent/embedded/subscribe-session.js +14 -4
- package/dist/src/agent/embedded/tool-metadata.d.ts +15 -0
- package/dist/src/agent/embedded/tool-metadata.js +38 -0
- package/dist/src/agent/embedded/tool-search-extension.d.ts +5 -0
- package/dist/src/agent/embedded/tool-search-extension.js +31 -0
- package/dist/src/agent/embedded/types.d.ts +7 -0
- package/dist/src/agent/embedded/xopc-tools-bridge.js +6 -0
- package/dist/src/agent/external-tools/endpoint-provider.d.ts +1 -1
- package/dist/src/agent/external-tools/endpoint-provider.js +148 -56
- package/dist/src/agent/external-tools/extension-provider.js +8 -1
- package/dist/src/agent/external-tools/gateway-tools.d.ts +1 -1
- package/dist/src/agent/external-tools/gateway-tools.js +45 -22
- package/dist/src/agent/external-tools/index.js +46 -14
- package/dist/src/agent/external-tools/memory-provider.js +8 -1
- package/dist/src/agent/external-tools/read-policy.js +2 -1
- package/dist/src/agent/external-tools/service.d.ts +2 -0
- package/dist/src/agent/external-tools/service.js +25 -3
- package/dist/src/agent/external-tools/tool-registry.d.ts +14 -0
- package/dist/src/agent/external-tools/tool-registry.js +14 -0
- package/dist/src/agent/external-tools/types.d.ts +8 -1
- package/dist/src/agent/external-tools/types.js +0 -1
- package/dist/src/agent/mcp/config.d.ts +18 -0
- package/dist/src/agent/mcp/{bundle-mcp-config.js → config.js} +8 -25
- package/dist/src/agent/mcp/native-mcp.d.ts +6 -0
- package/dist/src/agent/mcp/native-mcp.js +73 -0
- package/dist/src/agent/service.js +2 -5
- package/dist/src/agent/skills/installer.js +1 -1
- package/dist/src/agent/skills/skill-manager.js +1 -1
- package/dist/src/agent/skills/skill-sources.js +1 -1
- package/dist/src/agent/source-context/index.d.ts +0 -1
- package/dist/src/agent/source-context/index.js +1 -2
- package/dist/src/agent/source-context/injector.js +1 -0
- package/dist/src/agent/source-context/types.d.ts +2 -2
- package/dist/src/agent/source-context/types.js +1 -1
- package/dist/src/agent/tool-manuals/browser.d.ts +1 -1
- package/dist/src/agent/tool-manuals/browser.js +3 -3
- package/dist/src/agent/tools/browser/tool/browser-use-tool.js +1 -1
- package/dist/src/agent/tools/browser/tool/schemas.d.ts +0 -13
- package/dist/src/agent/tools/browser/tool/schemas.js +0 -4
- package/dist/src/agent/tools/browser-automation-tool.d.ts +74 -1
- package/dist/src/agent/tools/browser-automation-tool.js +52 -6
- package/dist/src/agent/tools/cli-clarify.js +1 -1
- package/dist/src/agent/tools/codemode-permissions.d.ts +4 -0
- package/dist/src/agent/tools/codemode-permissions.js +23 -0
- package/dist/src/agent/tools/dataBatch.js +3 -1
- package/dist/src/agent/tools/delegation-parent-policy.js +1 -4
- package/dist/src/agent/tools/factory.js +4 -3
- package/dist/src/agent/transcript/provider-capabilities.js +0 -1
- package/dist/src/agent/transcript/transcript-policy.js +1 -2
- package/dist/src/agent-config/schema.d.ts +28 -0
- package/dist/src/agent-config/schema.js +7 -0
- package/dist/src/auth/credentials.js +7 -20
- package/dist/src/auth/model-credential-store.js +11 -4
- package/dist/src/auth/oauth/index.d.ts +1 -1
- package/dist/src/auth/oauth/index.js +3 -3
- package/dist/src/auth/oauth/openai.d.ts +2 -0
- package/dist/src/auth/oauth/openai.js +90 -0
- package/dist/src/auth/oauth/registry.js +3 -3
- package/dist/src/auth/oauth/types.d.ts +1 -0
- package/dist/src/auth/oauth/xopc-cloud.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +5 -0
- package/dist/src/automations/capabilities/write.d.ts +2 -0
- package/dist/src/automations/domain/types.d.ts +11 -0
- package/dist/src/automations/domain/validation.d.ts +4 -0
- package/dist/src/automations/domain/validation.js +1 -0
- package/dist/src/automations/draft/automation-draft-validator.d.ts +1 -0
- package/dist/src/automations/service/action-executor.js +11 -3
- package/dist/src/automations/service/automation-service.d.ts +1 -0
- package/dist/src/automations/service/automation-service.js +13 -1
- package/dist/src/bootstrap/application-state.js +1 -1
- package/dist/src/browser/automations/repository.d.ts +4 -0
- package/dist/src/browser/automations/repository.js +27 -6
- package/dist/src/browser/automations/runner.js +101 -9
- package/dist/src/browser/automations/runtime-service.js +4 -3
- package/dist/src/browser/automations/schema.d.ts +84 -1
- package/dist/src/browser/automations/schema.js +68 -2
- package/dist/src/browser/automations/service.d.ts +78 -1
- package/dist/src/browser/automations/service.js +36 -4
- package/dist/src/browser/automations/types.d.ts +19 -4
- package/dist/src/browser/drivers/extension-driver.d.ts +5 -5
- package/dist/src/browser/drivers/extension-driver.js +10 -10
- package/dist/src/browser/drivers/playwright-driver.js +46 -0
- package/dist/src/browser/index.d.ts +1 -2
- package/dist/src/browser/index.js +2 -3
- package/dist/src/browser/policy/browser-policy.d.ts +0 -1
- package/dist/src/browser/policy/browser-policy.js +1 -4
- package/dist/src/browser/providers/index.d.ts +1 -1
- package/dist/src/browser/providers/index.js +2 -2
- package/dist/src/browser/providers/realtime-extension.d.ts +1 -1
- package/dist/src/browser/providers/realtime-extension.js +5 -1
- package/dist/src/browser/recordings/service.d.ts +22 -0
- package/dist/src/browser/recordings/service.js +160 -0
- package/dist/src/browser/runtime/browser-runtime.d.ts +1 -1
- package/dist/src/browser/runtime/browser-runtime.js +19 -56
- package/dist/src/chat-commands/builtins/model.js +2 -2
- package/dist/src/cli/command-manifest.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/cli/commands/extension-agent-plugin.js +0 -19
- package/dist/src/cli/commands/mcp.js +36 -2
- package/dist/src/cli/commands/models.js +1 -1
- package/dist/src/cli/utils/oauth-login.js +2 -2
- package/dist/src/computer/runtime.js +2 -2
- package/dist/src/config/index.js +3 -3
- package/dist/src/config/mcp-config-normalize.d.ts +0 -3
- package/dist/src/config/mcp-config-normalize.js +2 -22
- package/dist/src/config/models-json.d.ts +0 -5
- package/dist/src/config/models-json.js +13 -4
- package/dist/src/config/paths.d.ts +0 -1
- package/dist/src/config/paths.js +1 -4
- package/dist/src/config/schema.d.ts +142 -48
- package/dist/src/config/schema.js +64 -47
- package/dist/src/connectors/auth-provider-registry.d.ts +1 -1
- package/dist/src/connectors/auth-provider-registry.js +1 -21
- package/dist/src/connectors/china-catalog.js +5 -5
- package/dist/src/connectors/connection-recovery-service.d.ts +1 -6
- package/dist/src/connectors/connection-recovery-service.js +3 -105
- package/dist/src/connectors/health.d.ts +1 -2
- package/dist/src/connectors/health.js +2 -101
- package/dist/src/connectors/types.d.ts +1 -1
- package/dist/src/endpoint-tools/binding-service.d.ts +2 -0
- package/dist/src/endpoint-tools/binding-service.js +14 -2
- package/dist/src/endpoint-tools/bridge-host.d.ts +15 -0
- package/dist/src/endpoint-tools/bridge-host.js +166 -0
- package/dist/src/endpoint-tools/bridge.d.ts +27 -0
- package/dist/src/endpoint-tools/bridge.js +88 -0
- package/dist/src/endpoint-tools/capability-catalog.d.ts +2 -0
- package/dist/src/endpoint-tools/capability-catalog.js +8 -0
- package/dist/src/endpoint-tools/grant-service.d.ts +69 -0
- package/dist/src/endpoint-tools/grant-service.js +113 -0
- package/dist/src/endpoint-tools/index.js +1 -1
- package/dist/src/endpoint-tools/invocation-service.js +6 -2
- package/dist/src/endpoint-tools/location-task.d.ts +22 -0
- package/dist/src/endpoint-tools/location-task.js +114 -0
- package/dist/src/endpoint-tools/policy.js +20 -4
- package/dist/src/endpoint-tools/registry.d.ts +2 -0
- package/dist/src/endpoint-tools/registry.js +9 -0
- package/dist/src/endpoint-tools/result-projector.d.ts +15 -0
- package/dist/src/endpoint-tools/result-projector.js +31 -0
- package/dist/src/endpoint-tools/runtime.d.ts +2 -0
- package/dist/src/endpoint-tools/runtime.js +15 -2
- package/dist/src/endpoint-tools/target-resolver.d.ts +12 -0
- package/dist/src/endpoint-tools/target-resolver.js +27 -0
- package/dist/src/endpoint-tools/turn-context.d.ts +6 -0
- package/dist/src/endpoint-tools/turn-context.js +29 -0
- package/dist/src/extensions/agent-plugins/auth.d.ts +0 -2
- package/dist/src/extensions/agent-plugins/auth.js +2 -19
- package/dist/src/extensions/agent-plugins/credentials.js +3 -19
- package/dist/src/extensions/agent-plugins/inventory.d.ts +2 -2
- package/dist/src/extensions/agent-plugins/mcp-adapter.js +1 -5
- package/dist/src/extensions/agent-plugins/source-http-fetch.d.ts +2 -0
- package/dist/src/{agent/mcp/plugin-http-fetch.js → extensions/agent-plugins/source-http-fetch.js} +7 -7
- package/dist/src/extensions/agent-plugins/sources.js +2 -2
- package/dist/src/extensions/agent-plugins/store.js +1 -3
- package/dist/src/extensions/agent-plugins/validation.d.ts +0 -4
- package/dist/src/extensions/agent-plugins/validation.js +13 -20
- package/dist/src/gateway/agents-admin.d.ts +5 -0
- package/dist/src/gateway/agents-admin.js +56 -1
- package/dist/src/gateway/chat-stream/mapper.js +9 -0
- package/dist/src/gateway/chat-stream/protocol.d.ts +4 -4
- package/dist/src/gateway/hono/lib/config-payload.d.ts +9 -4
- package/dist/src/gateway/hono/lib/config-payload.js +2 -5
- package/dist/src/gateway/hono/oauth-async.js +9 -2
- package/dist/src/gateway/hono/routes/agent-plugins.js +4 -9
- package/dist/src/gateway/hono/routes/agents.js +4 -3
- package/dist/src/gateway/hono/routes/browser-automations.js +23 -7
- package/dist/src/gateway/hono/routes/browser-recordings.d.ts +3 -0
- package/dist/src/gateway/hono/routes/browser-recordings.js +78 -0
- package/dist/src/gateway/hono/routes/browser.js +1 -34
- package/dist/src/gateway/hono/routes/connection-waits.js +2 -5
- package/dist/src/gateway/hono/routes/connectors.js +5 -60
- package/dist/src/gateway/hono/routes/device-authorizations.d.ts +3 -0
- package/dist/src/gateway/hono/routes/device-authorizations.js +74 -0
- package/dist/src/gateway/hono/routes/device-push.js +1 -0
- package/dist/src/gateway/hono/routes/endpoint-compatibility.js +7 -0
- package/dist/src/gateway/hono/routes/endpoint-tools.d.ts +1 -0
- package/dist/src/gateway/hono/routes/endpoint-tools.js +53 -3
- package/dist/src/gateway/hono/routes/home.js +1 -1
- package/dist/src/gateway/hono/routes/lazy-bundles.js +25 -1
- package/dist/src/gateway/hono/routes/mcp.d.ts +1 -1
- package/dist/src/gateway/hono/routes/mcp.js +11 -237
- package/dist/src/gateway/hono/routes/personal-agent.js +35 -0
- package/dist/src/gateway/hono/routes/session-command-handler.js +11 -1
- package/dist/src/gateway/hono/routes/session-input-handler.d.ts +8 -2
- package/dist/src/gateway/hono/routes/session-input-handler.js +25 -1
- package/dist/src/gateway/hono/routes/voice.js +5 -2
- package/dist/src/gateway/security/gateway-scopes.js +3 -1
- package/dist/src/gateway/service/agent-runner.js +1 -0
- package/dist/src/gateway/service/config-coordinator.js +2 -5
- package/dist/src/gateway/service/marketplace-service.js +2 -2
- package/dist/src/gateway/service/run-gateway-agent.js +13 -5
- package/dist/src/gateway/service/session-input-coordinator.d.ts +1 -1
- package/dist/src/gateway/service/session-input-coordinator.js +29 -9
- package/dist/src/gateway/service/sessions-api.js +0 -6
- package/dist/src/gateway/service.js +3 -12
- package/dist/src/gateway/session-reset-service.js +0 -6
- package/dist/src/home-intelligence/generator.d.ts +2 -0
- package/dist/src/home-intelligence/generator.js +53 -4
- package/dist/src/home-intelligence/host.d.ts +2 -1
- package/dist/src/home-intelligence/host.js +23 -3
- package/dist/src/imports/compatibility.js +12 -10
- package/dist/src/mcp/channel-bridge.js +1 -1
- package/dist/src/migrations/cloud-public-models.js +1 -0
- package/dist/src/notifications/clarification.d.ts +5 -0
- package/dist/src/notifications/clarification.js +66 -0
- package/dist/src/notifications/device-store.js +1 -0
- package/dist/src/notifications/harmony-push.d.ts +1 -0
- package/dist/src/notifications/harmony-push.js +3 -1
- package/dist/src/notifications/planner.d.ts +1 -0
- package/dist/src/notifications/service.d.ts +2 -2
- package/dist/src/notifications/service.js +20 -4
- package/dist/src/notifications/store.d.ts +2 -0
- package/dist/src/notifications/store.js +7 -1
- package/dist/src/notifications/types.d.ts +1 -0
- package/dist/src/notifications/types.js +1 -0
- package/dist/src/providers/env-keys.js +1 -1
- package/dist/src/providers/index.js +26 -24
- package/dist/src/providers/model-call.d.ts +0 -2
- package/dist/src/providers/model-call.js +2 -6
- package/dist/src/providers/model-registry.js +4 -2
- package/dist/src/providers/model-supplements.d.ts +3 -3
- package/dist/src/providers/model-supplements.js +6 -27
- package/dist/src/providers/presentation.js +3 -8
- package/dist/src/providers/prompt-cache-plan.js +1 -1
- package/dist/src/providers/provider-auth-service.d.ts +1 -1
- package/dist/src/providers/provider-auth-service.js +7 -2
- package/dist/src/providers/provider-policy.d.ts +3 -0
- package/dist/src/providers/provider-policy.js +14 -0
- package/dist/src/providers/register-runtime-providers.js +6 -1
- package/dist/src/realtime/runtime.js +1 -1
- package/dist/src/session/store.js +7 -1
- package/dist/src/session/transcript-events.d.ts +5 -0
- package/dist/src/session/transcript-events.js +1 -0
- package/dist/src/session/types.d.ts +2 -0
- package/dist/src/storage/sqlite/clarification-wait-repository.js +1 -0
- package/dist/src/storage/sqlite/device-grant-audit-repository.d.ts +11 -0
- package/dist/src/storage/sqlite/device-grant-audit-repository.js +10 -0
- package/dist/src/storage/sqlite/endpoint-device-settings-repository.d.ts +7 -0
- package/dist/src/storage/sqlite/endpoint-device-settings-repository.js +17 -0
- package/dist/src/storage/sqlite/migrations/238_browser_record_replay.sql +45 -0
- package/dist/src/storage/sqlite/migrations/239_clarification_notifications.sql +26 -0
- package/dist/src/storage/sqlite/migrations/240_device_settings.sql +5 -0
- package/dist/src/storage/sqlite/migrations/241_device_grant_audit.sql +13 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/session-input-repository.d.ts +1 -0
- package/dist/src/storage/sqlite/session-input-repository.js +5 -1
- package/dist/src/tasks/home-query-service.d.ts +1 -1
- package/dist/src/tasks/home-query-service.js +6 -2
- package/dist/src/tui/backends/gateway-realtime-backend.js +1 -1
- package/dist/src/tui/xopc-tui-keybindings.d.ts +4 -4
- package/dist/src/voice/dashscope/streaming-tts-stream.d.ts +2 -1
- package/dist/src/voice/dashscope/streaming-tts-stream.js +135 -79
- package/dist/src/voice/realtime/agentEngine.js +78 -1
- package/dist/src/voice/realtime/speakable-segmenter.d.ts +2 -0
- package/dist/src/voice/realtime/speakable-segmenter.js +30 -0
- package/dist/src/voice/tts/providers/alibaba-speech.js +17 -1
- package/dist/src/voice/tts/speak-core.d.ts +3 -0
- package/dist/src/voice/tts/speak-core.js +21 -1
- package/dist/src/voice/tts/speech-provider-types.d.ts +8 -0
- package/package.json +18 -7
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-D0tD3kCe.js +0 -1
- package/dist/gateway/static/root/assets/agent-plugin-dialog-BjdgKCnk.js +0 -1
- package/dist/gateway/static/root/assets/agents-CWXKzX5L.js +0 -66
- package/dist/gateway/static/root/assets/automations-workspace-C9ZT6TAU.js +0 -6
- package/dist/gateway/static/root/assets/browser-automation-inputs-CXG_JveC.js +0 -1
- package/dist/gateway/static/root/assets/browser-automations-page-CJc7OKR3.js +0 -3
- package/dist/gateway/static/root/assets/browser-settings-page-BjaTEUR8.js +0 -3
- package/dist/gateway/static/root/assets/capabilities-page-djBsC_tG.js +0 -2
- package/dist/gateway/static/root/assets/channels-BaYRJtz3.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-DyqRwSH2.js +0 -2
- package/dist/gateway/static/root/assets/copy-text-row-BHDs3cBa.js +0 -1
- package/dist/gateway/static/root/assets/dependency-picker-CWbbhKZa.js +0 -1
- package/dist/gateway/static/root/assets/dist-Che_jiQF.js +0 -1
- package/dist/gateway/static/root/assets/gateway-realtime-C4KtwMY3.js +0 -1
- package/dist/gateway/static/root/assets/gateway-realtime-store-ChZUzVbe.js +0 -1
- package/dist/gateway/static/root/assets/home-page-DhPPLbdD.js +0 -2
- package/dist/gateway/static/root/assets/index-CK4O2xMa.css +0 -1
- package/dist/gateway/static/root/assets/index-DpLD-7Hc.js +0 -106
- package/dist/gateway/static/root/assets/link-2-D_ZKYUW7.js +0 -1
- package/dist/gateway/static/root/assets/local-session-drafts-B_McurIj.js +0 -1
- package/dist/gateway/static/root/assets/logs-page-BWD63eg1.js +0 -2
- package/dist/gateway/static/root/assets/management-settings-aKSibklM.js +0 -1
- package/dist/gateway/static/root/assets/messages-Bnx3GMDB.js +0 -3
- package/dist/gateway/static/root/assets/models-hub-cache-Di83uIPw.js +0 -1
- package/dist/gateway/static/root/assets/note-detail-panel-B_fve3_2.js +0 -5
- package/dist/gateway/static/root/assets/notes-page-DnChyp8S.js +0 -8
- package/dist/gateway/static/root/assets/personal-page-BM2qAgg_.js +0 -1
- package/dist/gateway/static/root/assets/project-detail-page-DM4_VLNX.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-O6j9CWX0.js +0 -1
- package/dist/gateway/static/root/assets/session-manager-B0tOE4qz.js +0 -16
- package/dist/gateway/static/root/assets/sessions-page-BIixHXlQ.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-49SUEWPh.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-Ce3gTbT3.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-CNEZjF66.js +0 -1
- package/dist/gateway/static/root/assets/skills-page-BndNdYsJ.js +0 -2
- package/dist/gateway/static/root/assets/system-settings-panel-EpZeMlvp.js +0 -1
- package/dist/gateway/static/root/assets/use-file-preview-expanded-DJ5vyrvM.js +0 -2
- package/dist/gateway/static/root/assets/user-model-page-Bz5lkFG9.js +0 -2
- package/dist/gateway/static/root/assets/workflows-page-CPCgOfHh.js +0 -6
- package/dist/src/agent/embedded/system-prompt-override.d.ts +0 -2
- package/dist/src/agent/embedded/system-prompt-override.js +0 -21
- package/dist/src/agent/external-tools/mcp-provider.d.ts +0 -32
- package/dist/src/agent/external-tools/mcp-provider.js +0 -208
- package/dist/src/agent/mcp/bundle-mcp-config.d.ts +0 -20
- package/dist/src/agent/mcp/bundle-mcp-gateway.d.ts +0 -79
- package/dist/src/agent/mcp/bundle-mcp-gateway.js +0 -93
- package/dist/src/agent/mcp/bundle-mcp-names.d.ts +0 -1
- package/dist/src/agent/mcp/bundle-mcp-names.js +0 -25
- package/dist/src/agent/mcp/bundle-mcp-policy.d.ts +0 -1
- package/dist/src/agent/mcp/bundle-mcp-policy.js +0 -6
- package/dist/src/agent/mcp/bundle-mcp-runtime.d.ts +0 -46
- package/dist/src/agent/mcp/bundle-mcp-runtime.js +0 -571
- package/dist/src/agent/mcp/bundle-mcp-tools.d.ts +0 -2
- package/dist/src/agent/mcp/bundle-mcp-tools.js +0 -2
- package/dist/src/agent/mcp/bundle-mcp-types.d.ts +0 -76
- package/dist/src/agent/mcp/bundle-mcp-types.js +0 -1
- package/dist/src/agent/mcp/embedded-mcp.d.ts +0 -10
- package/dist/src/agent/mcp/embedded-mcp.js +0 -14
- package/dist/src/agent/mcp/index.d.ts +0 -5
- package/dist/src/agent/mcp/index.js +0 -12
- package/dist/src/agent/mcp/mcp-config-shared.d.ts +0 -8
- package/dist/src/agent/mcp/mcp-config-shared.js +0 -39
- package/dist/src/agent/mcp/mcp-http.d.ts +0 -23
- package/dist/src/agent/mcp/mcp-http.js +0 -67
- package/dist/src/agent/mcp/mcp-resource-id.d.ts +0 -6
- package/dist/src/agent/mcp/mcp-resource-id.js +0 -19
- package/dist/src/agent/mcp/mcp-stdio-transport.d.ts +0 -26
- package/dist/src/agent/mcp/mcp-stdio-transport.js +0 -120
- package/dist/src/agent/mcp/mcp-stdio.d.ts +0 -18
- package/dist/src/agent/mcp/mcp-stdio.js +0 -35
- package/dist/src/agent/mcp/mcp-transport-config.d.ts +0 -28
- package/dist/src/agent/mcp/mcp-transport-config.js +0 -91
- package/dist/src/agent/mcp/mcp-transport.d.ts +0 -17
- package/dist/src/agent/mcp/mcp-transport.js +0 -141
- package/dist/src/agent/mcp/oauth/index.d.ts +0 -6
- package/dist/src/agent/mcp/oauth/index.js +0 -6
- package/dist/src/agent/mcp/oauth/mcp-oauth-errors.d.ts +0 -5
- package/dist/src/agent/mcp/oauth/mcp-oauth-errors.js +0 -14
- package/dist/src/agent/mcp/oauth/mcp-oauth-manager.d.ts +0 -30
- package/dist/src/agent/mcp/oauth/mcp-oauth-manager.js +0 -276
- package/dist/src/agent/mcp/oauth/mcp-oauth-provider.d.ts +0 -33
- package/dist/src/agent/mcp/oauth/mcp-oauth-provider.js +0 -103
- package/dist/src/agent/mcp/oauth/mcp-oauth-session.d.ts +0 -31
- package/dist/src/agent/mcp/oauth/mcp-oauth-session.js +0 -181
- package/dist/src/agent/mcp/oauth/mcp-oauth-store.d.ts +0 -12
- package/dist/src/agent/mcp/oauth/mcp-oauth-store.js +0 -91
- package/dist/src/agent/mcp/oauth/mcp-oauth-types.d.ts +0 -22
- package/dist/src/agent/mcp/oauth/mcp-oauth-types.js +0 -1
- package/dist/src/agent/mcp/plugin-http-fetch.d.ts +0 -2
- package/dist/src/agent/source-context/mcp-resource-context.d.ts +0 -8
- package/dist/src/agent/source-context/mcp-resource-context.js +0 -30
- package/dist/src/auth/oauth/openai-codex.d.ts +0 -9
- package/dist/src/auth/oauth/openai-codex.js +0 -414
- package/dist/src/browser/policy/approval-store.d.ts +0 -17
- package/dist/src/browser/policy/approval-store.js +0 -62
- package/dist/src/browser/providers/extension-ws-acquire.d.ts +0 -19
- package/dist/src/browser/providers/extension-ws-acquire.js +0 -78
- package/dist/src/browser/providers/extension.d.ts +0 -61
- package/dist/src/browser/providers/extension.js +0 -378
- package/dist/src/connectors/plugin-mcp-recovery.d.ts +0 -28
- package/dist/src/connectors/plugin-mcp-recovery.js +0 -90
- package/dist/src/extensions/agent-plugins/connection.d.ts +0 -8
- package/dist/src/extensions/agent-plugins/connection.js +0 -41
- package/dist/src/extensions/agent-plugins/health.d.ts +0 -4
- package/dist/src/extensions/agent-plugins/health.js +0 -48
- package/dist/src/extensions/agent-plugins/plugin-oauth-scope.d.ts +0 -1
- package/dist/src/extensions/agent-plugins/plugin-oauth-scope.js +0 -8
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { McpAuthorizationRequiredError, isMcpAuthorizationError } from "./mcp-oauth-errors.js";
|
|
2
|
-
import { McpOAuthStore, canonicalMcpServerUrl, mcpOAuthServerKey } from "./mcp-oauth-store.js";
|
|
3
|
-
import { XopcMcpOAuthClientProvider } from "./mcp-oauth-provider.js";
|
|
4
|
-
import { McpOAuthSession } from "./mcp-oauth-session.js";
|
|
5
|
-
import { McpOAuthManager, getMcpOAuthManager } from "./mcp-oauth-manager.js";
|
|
6
|
-
export { McpAuthorizationRequiredError, McpOAuthManager, McpOAuthSession, McpOAuthStore, XopcMcpOAuthClientProvider, canonicalMcpServerUrl, getMcpOAuthManager, isMcpAuthorizationError, mcpOAuthServerKey };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
2
|
-
//#region src/agent/mcp/oauth/mcp-oauth-errors.ts
|
|
3
|
-
var McpAuthorizationRequiredError = class extends Error {
|
|
4
|
-
code = "MCP_AUTHORIZATION_REQUIRED";
|
|
5
|
-
constructor(message = "MCP server authorization is required") {
|
|
6
|
-
super(message);
|
|
7
|
-
this.name = "McpAuthorizationRequiredError";
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
function isMcpAuthorizationError(error) {
|
|
11
|
-
return error instanceof UnauthorizedError || error instanceof McpAuthorizationRequiredError;
|
|
12
|
-
}
|
|
13
|
-
//#endregion
|
|
14
|
-
export { McpAuthorizationRequiredError, isMcpAuthorizationError };
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Config } from '../../../config/schema.js';
|
|
2
|
-
import { McpOAuthStore } from './mcp-oauth-store.js';
|
|
3
|
-
import type { McpOAuthSessionSnapshot } from './mcp-oauth-types.js';
|
|
4
|
-
export type McpOAuthConnectionStatus = 'not_configured' | 'disconnected' | 'authorizing' | 'connected' | 'error';
|
|
5
|
-
export type McpOAuthStatus = {
|
|
6
|
-
configured: boolean;
|
|
7
|
-
status: McpOAuthConnectionStatus;
|
|
8
|
-
session?: McpOAuthSessionSnapshot;
|
|
9
|
-
};
|
|
10
|
-
type StartMcpOAuthParams = {
|
|
11
|
-
serverId: string;
|
|
12
|
-
rawServer: unknown;
|
|
13
|
-
cfg?: Config;
|
|
14
|
-
};
|
|
15
|
-
export declare class McpOAuthManager {
|
|
16
|
-
private readonly store;
|
|
17
|
-
private readonly sessionsByServerUrl;
|
|
18
|
-
private readonly pending;
|
|
19
|
-
private cancelling;
|
|
20
|
-
constructor(store?: McpOAuthStore);
|
|
21
|
-
status(serverId: string, rawServer: unknown): Promise<McpOAuthStatus>;
|
|
22
|
-
start(params: StartMcpOAuthParams): Promise<McpOAuthStatus>;
|
|
23
|
-
cancelPending(): Promise<void>;
|
|
24
|
-
private startSession;
|
|
25
|
-
disconnect(serverId: string, rawServer: unknown): Promise<McpOAuthStatus>;
|
|
26
|
-
submitCallback(serverId: string, rawServer: unknown, callbackUrl: string): Promise<McpOAuthStatus>;
|
|
27
|
-
private finishAuthorization;
|
|
28
|
-
}
|
|
29
|
-
export declare function getMcpOAuthManager(rawServer?: unknown): McpOAuthManager;
|
|
30
|
-
export {};
|
|
@@ -1,276 +0,0 @@
|
|
|
1
|
-
import { createLogger } from "../../../utils/logger/index.js";
|
|
2
|
-
import { init_logger } from "../../../utils/logger.js";
|
|
3
|
-
import { init_global_singleton, resolveGlobalSingleton } from "../../../utils/global-singleton.js";
|
|
4
|
-
import { resolveConnectorSecretReferences } from "../../../connectors/secret-store.js";
|
|
5
|
-
import { recordPluginMcpHealth } from "../../../extensions/agent-plugins/health.js";
|
|
6
|
-
import { redactSensitiveUrlLikeString } from "../../../utils/redact-sensitive-url.js";
|
|
7
|
-
import { resolveMcpTransportConfig } from "../mcp-transport-config.js";
|
|
8
|
-
import { isMcpAuthorizationError } from "./mcp-oauth-errors.js";
|
|
9
|
-
import { McpOAuthStore, canonicalMcpServerUrl } from "./mcp-oauth-store.js";
|
|
10
|
-
import { XopcMcpOAuthClientProvider } from "./mcp-oauth-provider.js";
|
|
11
|
-
import { pluginOAuthScope } from "../../../extensions/agent-plugins/plugin-oauth-scope.js";
|
|
12
|
-
import { resolveMcpTransport } from "../mcp-transport.js";
|
|
13
|
-
import { disposeAllSessionMcpRuntimes } from "../bundle-mcp-runtime.js";
|
|
14
|
-
import { McpOAuthSession } from "./mcp-oauth-session.js";
|
|
15
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
16
|
-
//#region src/agent/mcp/oauth/mcp-oauth-manager.ts
|
|
17
|
-
init_logger();
|
|
18
|
-
init_global_singleton();
|
|
19
|
-
const log = createLogger("Mcp:OAuth");
|
|
20
|
-
const MCP_OAUTH_MANAGER_KEY = Symbol.for("xopc.mcpOAuthManager");
|
|
21
|
-
function createClient() {
|
|
22
|
-
return new Client({
|
|
23
|
-
name: "xopc-mcp-oauth",
|
|
24
|
-
version: "0.0.0"
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
async function connectClient(client, resolved) {
|
|
28
|
-
await new Promise((resolve, reject) => {
|
|
29
|
-
const timer = setTimeout(() => reject(/* @__PURE__ */ new Error(`MCP server connection timed out after ${resolved.connectionTimeoutMs}ms`)), resolved.connectionTimeoutMs);
|
|
30
|
-
client.connect(resolved.transport).then(() => {
|
|
31
|
-
clearTimeout(timer);
|
|
32
|
-
resolve();
|
|
33
|
-
}, (error) => {
|
|
34
|
-
clearTimeout(timer);
|
|
35
|
-
reject(error);
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
async function closeConnection(client, resolved) {
|
|
40
|
-
await client.close().catch(() => {});
|
|
41
|
-
await resolved.transport.close().catch(() => {});
|
|
42
|
-
resolved.detachStderr?.();
|
|
43
|
-
}
|
|
44
|
-
function isAuthorizing(snapshot) {
|
|
45
|
-
return [
|
|
46
|
-
"starting",
|
|
47
|
-
"waiting_browser",
|
|
48
|
-
"exchanging_code"
|
|
49
|
-
].includes(snapshot.status);
|
|
50
|
-
}
|
|
51
|
-
var McpOAuthManager = class {
|
|
52
|
-
store;
|
|
53
|
-
sessionsByServerUrl = /* @__PURE__ */ new Map();
|
|
54
|
-
pending = /* @__PURE__ */ new Set();
|
|
55
|
-
cancelling = false;
|
|
56
|
-
constructor(store = new McpOAuthStore()) {
|
|
57
|
-
this.store = store;
|
|
58
|
-
}
|
|
59
|
-
async status(serverId, rawServer) {
|
|
60
|
-
const resolved = resolveMcpTransportConfig(serverId, rawServer);
|
|
61
|
-
if (!resolved || resolved.kind !== "http" || !resolved.auth) return {
|
|
62
|
-
configured: false,
|
|
63
|
-
status: "not_configured"
|
|
64
|
-
};
|
|
65
|
-
const session = this.sessionsByServerUrl.get(canonicalMcpServerUrl(resolved.url))?.snapshot();
|
|
66
|
-
if (session) {
|
|
67
|
-
if (isAuthorizing(session)) return {
|
|
68
|
-
configured: true,
|
|
69
|
-
status: "authorizing",
|
|
70
|
-
session
|
|
71
|
-
};
|
|
72
|
-
if (session.status === "failed" || session.status === "expired") return {
|
|
73
|
-
configured: true,
|
|
74
|
-
status: "error",
|
|
75
|
-
session
|
|
76
|
-
};
|
|
77
|
-
if (session.status === "connected") return {
|
|
78
|
-
configured: true,
|
|
79
|
-
status: "connected",
|
|
80
|
-
session
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
configured: true,
|
|
85
|
-
status: (await this.store.load(resolved.url))?.tokens ? "connected" : "disconnected",
|
|
86
|
-
session
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
async start(params) {
|
|
90
|
-
if (this.cancelling) throw new Error("OAuth connections are being cleared");
|
|
91
|
-
const task = this.startSession(params);
|
|
92
|
-
this.pending.add(task);
|
|
93
|
-
try {
|
|
94
|
-
return await task;
|
|
95
|
-
} finally {
|
|
96
|
-
this.pending.delete(task);
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
async cancelPending() {
|
|
100
|
-
this.cancelling = true;
|
|
101
|
-
try {
|
|
102
|
-
await Promise.all([...this.sessionsByServerUrl.values()].map((session) => session.close()));
|
|
103
|
-
await Promise.allSettled([...this.pending]);
|
|
104
|
-
this.sessionsByServerUrl.clear();
|
|
105
|
-
} finally {
|
|
106
|
-
this.cancelling = false;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
async startSession(params) {
|
|
110
|
-
const rawServer = await resolveConnectorSecretReferences(params.rawServer);
|
|
111
|
-
if (this.cancelling) throw new Error("OAuth connections are being cleared");
|
|
112
|
-
const resolvedConfig = resolveMcpTransportConfig(params.serverId, rawServer);
|
|
113
|
-
if (!resolvedConfig || resolvedConfig.kind !== "http" || !resolvedConfig.auth) throw new Error(`MCP server "${params.serverId}" is not configured for OAuth`);
|
|
114
|
-
const serverUrl = new URL(resolvedConfig.url);
|
|
115
|
-
const conversationId = canonicalMcpServerUrl(serverUrl);
|
|
116
|
-
const previous = this.sessionsByServerUrl.get(conversationId);
|
|
117
|
-
if (previous && isAuthorizing(previous.snapshot())) return this.status(params.serverId, params.rawServer);
|
|
118
|
-
if (previous) await previous.close();
|
|
119
|
-
const session = new McpOAuthSession(params.serverId, serverUrl);
|
|
120
|
-
this.sessionsByServerUrl.set(conversationId, session);
|
|
121
|
-
try {
|
|
122
|
-
await session.start();
|
|
123
|
-
} catch (error) {
|
|
124
|
-
this.sessionsByServerUrl.delete(conversationId);
|
|
125
|
-
throw error;
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
await this.store.update(serverUrl, (current) => current ? {
|
|
129
|
-
...current,
|
|
130
|
-
clientInformation: void 0,
|
|
131
|
-
tokens: void 0,
|
|
132
|
-
tokensSavedAt: void 0
|
|
133
|
-
} : void 0);
|
|
134
|
-
} catch (error) {
|
|
135
|
-
session.fail(error);
|
|
136
|
-
throw error;
|
|
137
|
-
}
|
|
138
|
-
let provider;
|
|
139
|
-
let resolved;
|
|
140
|
-
try {
|
|
141
|
-
provider = new XopcMcpOAuthClientProvider({
|
|
142
|
-
serverUrl,
|
|
143
|
-
clientId: resolvedConfig.auth.clientId,
|
|
144
|
-
store: this.store,
|
|
145
|
-
interaction: {
|
|
146
|
-
redirectUrl: session.redirectUrl,
|
|
147
|
-
state: session.state,
|
|
148
|
-
onRedirect: (authorizationUrl) => session.setAuthorizationUrl(authorizationUrl)
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
resolved = await resolveMcpTransport(params.serverId, rawServer, params.cfg, {
|
|
152
|
-
oauthProvider: provider,
|
|
153
|
-
oauthStore: this.store
|
|
154
|
-
});
|
|
155
|
-
} catch (error) {
|
|
156
|
-
session.fail(error);
|
|
157
|
-
return this.status(params.serverId, params.rawServer);
|
|
158
|
-
}
|
|
159
|
-
if (!resolved || resolved.transportType !== "streamable-http") {
|
|
160
|
-
session.fail(/* @__PURE__ */ new Error("MCP OAuth requires a streamable HTTP transport"));
|
|
161
|
-
await resolved?.transport.close().catch(() => {});
|
|
162
|
-
return this.status(params.serverId, params.rawServer);
|
|
163
|
-
}
|
|
164
|
-
const client = createClient();
|
|
165
|
-
try {
|
|
166
|
-
await connectClient(client, resolved);
|
|
167
|
-
if (session.snapshot().status === "cancelled") {
|
|
168
|
-
await this.store.delete(serverUrl);
|
|
169
|
-
await closeConnection(client, resolved);
|
|
170
|
-
return {
|
|
171
|
-
configured: true,
|
|
172
|
-
status: "disconnected"
|
|
173
|
-
};
|
|
174
|
-
}
|
|
175
|
-
session.complete();
|
|
176
|
-
recordPluginMcpHealth(rawServer, "ready");
|
|
177
|
-
await closeConnection(client, resolved);
|
|
178
|
-
await disposeAllSessionMcpRuntimes();
|
|
179
|
-
} catch (error) {
|
|
180
|
-
if (session.snapshot().status === "cancelled") {
|
|
181
|
-
await this.store.delete(serverUrl);
|
|
182
|
-
await closeConnection(client, resolved);
|
|
183
|
-
} else if (!isMcpAuthorizationError(error) || !session.snapshot().authorizationUrl) {
|
|
184
|
-
session.fail(error);
|
|
185
|
-
await closeConnection(client, resolved);
|
|
186
|
-
} else {
|
|
187
|
-
const task = this.finishAuthorization({
|
|
188
|
-
session,
|
|
189
|
-
provider,
|
|
190
|
-
client,
|
|
191
|
-
resolved,
|
|
192
|
-
params: {
|
|
193
|
-
...params,
|
|
194
|
-
rawServer
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
this.pending.add(task);
|
|
198
|
-
task.finally(() => this.pending.delete(task));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
return this.status(params.serverId, params.rawServer);
|
|
202
|
-
}
|
|
203
|
-
async disconnect(serverId, rawServer) {
|
|
204
|
-
const resolved = resolveMcpTransportConfig(serverId, rawServer);
|
|
205
|
-
if (!resolved || resolved.kind !== "http" || !resolved.auth) throw new Error(`MCP server "${serverId}" is not configured for OAuth`);
|
|
206
|
-
const conversationId = canonicalMcpServerUrl(resolved.url);
|
|
207
|
-
const session = this.sessionsByServerUrl.get(conversationId);
|
|
208
|
-
this.sessionsByServerUrl.delete(conversationId);
|
|
209
|
-
if (session) await session.close();
|
|
210
|
-
await this.store.delete(resolved.url);
|
|
211
|
-
recordPluginMcpHealth(rawServer, "authorization_required");
|
|
212
|
-
await disposeAllSessionMcpRuntimes();
|
|
213
|
-
return {
|
|
214
|
-
configured: true,
|
|
215
|
-
status: "disconnected"
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
async submitCallback(serverId, rawServer, callbackUrl) {
|
|
219
|
-
const resolved = resolveMcpTransportConfig(serverId, rawServer);
|
|
220
|
-
if (!resolved || resolved.kind !== "http") throw new Error("Unknown OAuth server");
|
|
221
|
-
const session = this.sessionsByServerUrl.get(canonicalMcpServerUrl(resolved.url));
|
|
222
|
-
if (!session) throw new Error("OAuth session not found");
|
|
223
|
-
session.submitCallback(callbackUrl);
|
|
224
|
-
return this.status(serverId, rawServer);
|
|
225
|
-
}
|
|
226
|
-
async finishAuthorization(context) {
|
|
227
|
-
const { session, provider, client, resolved, params } = context;
|
|
228
|
-
try {
|
|
229
|
-
const code = await session.waitForCode();
|
|
230
|
-
await resolved.transport.finishAuth(code);
|
|
231
|
-
if (session.snapshot().status === "cancelled") {
|
|
232
|
-
await this.store.delete(session.serverUrl);
|
|
233
|
-
await closeConnection(client, resolved);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
await closeConnection(client, resolved);
|
|
237
|
-
const authenticated = await resolveMcpTransport(params.serverId, params.rawServer, params.cfg, {
|
|
238
|
-
oauthProvider: provider,
|
|
239
|
-
oauthStore: this.store
|
|
240
|
-
});
|
|
241
|
-
if (!authenticated) throw new Error("MCP transport could not be created after authorization");
|
|
242
|
-
const authenticatedClient = createClient();
|
|
243
|
-
try {
|
|
244
|
-
await connectClient(authenticatedClient, authenticated);
|
|
245
|
-
} finally {
|
|
246
|
-
await closeConnection(authenticatedClient, authenticated);
|
|
247
|
-
}
|
|
248
|
-
if (session.snapshot().status === "cancelled") {
|
|
249
|
-
await this.store.delete(session.serverUrl);
|
|
250
|
-
return;
|
|
251
|
-
}
|
|
252
|
-
session.complete();
|
|
253
|
-
recordPluginMcpHealth(params.rawServer, "ready");
|
|
254
|
-
await disposeAllSessionMcpRuntimes();
|
|
255
|
-
} catch (error) {
|
|
256
|
-
if (session.snapshot().status === "cancelled") {
|
|
257
|
-
await this.store.delete(session.serverUrl);
|
|
258
|
-
await closeConnection(client, resolved);
|
|
259
|
-
return;
|
|
260
|
-
}
|
|
261
|
-
session.fail(error);
|
|
262
|
-
await closeConnection(client, resolved);
|
|
263
|
-
log.warn({
|
|
264
|
-
err: error,
|
|
265
|
-
phase: "mcp.oauth_finish",
|
|
266
|
-
serverId: params.serverId
|
|
267
|
-
}, `MCP OAuth failed for server "${params.serverId}": ${redactSensitiveUrlLikeString(error instanceof Error ? error.message : String(error))}`);
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
};
|
|
271
|
-
function getMcpOAuthManager(rawServer) {
|
|
272
|
-
const scope = pluginOAuthScope(rawServer);
|
|
273
|
-
return resolveGlobalSingleton(scope ? Symbol.for(`xopc.mcpOAuthManager:${scope}`) : MCP_OAUTH_MANAGER_KEY, () => new McpOAuthManager(new McpOAuthStore(scope)));
|
|
274
|
-
}
|
|
275
|
-
//#endregion
|
|
276
|
-
export { McpOAuthManager, getMcpOAuthManager };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import type { OAuthClientProvider, OAuthDiscoveryState } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
|
-
import type { OAuthClientInformationMixed, OAuthClientMetadata, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
3
|
-
import { McpOAuthStore } from './mcp-oauth-store.js';
|
|
4
|
-
export type McpOAuthInteraction = {
|
|
5
|
-
redirectUrl: URL;
|
|
6
|
-
state: string;
|
|
7
|
-
onRedirect: (authorizationUrl: URL) => void | Promise<void>;
|
|
8
|
-
};
|
|
9
|
-
export type McpOAuthClientProviderOptions = {
|
|
10
|
-
serverUrl: URL;
|
|
11
|
-
clientId?: string;
|
|
12
|
-
interaction?: McpOAuthInteraction;
|
|
13
|
-
store?: McpOAuthStore;
|
|
14
|
-
};
|
|
15
|
-
export declare class XopcMcpOAuthClientProvider implements OAuthClientProvider {
|
|
16
|
-
private readonly options;
|
|
17
|
-
private readonly store;
|
|
18
|
-
private codeVerifierValue?;
|
|
19
|
-
constructor(options: McpOAuthClientProviderOptions);
|
|
20
|
-
get redirectUrl(): URL;
|
|
21
|
-
get clientMetadata(): OAuthClientMetadata;
|
|
22
|
-
state(): string | undefined;
|
|
23
|
-
clientInformation(): Promise<OAuthClientInformationMixed | undefined>;
|
|
24
|
-
saveClientInformation(clientInformation: OAuthClientInformationMixed): Promise<void>;
|
|
25
|
-
tokens(): Promise<OAuthTokens | undefined>;
|
|
26
|
-
saveTokens(tokens: OAuthTokens): Promise<void>;
|
|
27
|
-
redirectToAuthorization(authorizationUrl: URL): Promise<void>;
|
|
28
|
-
saveCodeVerifier(codeVerifier: string): void;
|
|
29
|
-
codeVerifier(): string;
|
|
30
|
-
saveDiscoveryState(discoveryState: OAuthDiscoveryState): Promise<void>;
|
|
31
|
-
discoveryState(): Promise<OAuthDiscoveryState | undefined>;
|
|
32
|
-
invalidateCredentials(scope: 'all' | 'client' | 'tokens' | 'verifier' | 'discovery'): Promise<void>;
|
|
33
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { McpAuthorizationRequiredError } from "./mcp-oauth-errors.js";
|
|
2
|
-
import { McpOAuthStore } from "./mcp-oauth-store.js";
|
|
3
|
-
//#region src/agent/mcp/oauth/mcp-oauth-provider.ts
|
|
4
|
-
var XopcMcpOAuthClientProvider = class {
|
|
5
|
-
store;
|
|
6
|
-
codeVerifierValue;
|
|
7
|
-
constructor(options) {
|
|
8
|
-
this.options = options;
|
|
9
|
-
this.store = options.store ?? new McpOAuthStore();
|
|
10
|
-
}
|
|
11
|
-
get redirectUrl() {
|
|
12
|
-
return this.options.interaction?.redirectUrl ?? new URL("http://127.0.0.1/oauth/callback");
|
|
13
|
-
}
|
|
14
|
-
get clientMetadata() {
|
|
15
|
-
return {
|
|
16
|
-
client_name: "XOPC",
|
|
17
|
-
client_uri: "https://xopc.ai",
|
|
18
|
-
redirect_uris: [this.redirectUrl.toString()],
|
|
19
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
20
|
-
response_types: ["code"],
|
|
21
|
-
token_endpoint_auth_method: "none"
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
state() {
|
|
25
|
-
return this.options.interaction?.state;
|
|
26
|
-
}
|
|
27
|
-
async clientInformation() {
|
|
28
|
-
if (this.options.clientId) return { client_id: this.options.clientId };
|
|
29
|
-
return (await this.store.load(this.options.serverUrl))?.clientInformation;
|
|
30
|
-
}
|
|
31
|
-
async saveClientInformation(clientInformation) {
|
|
32
|
-
await this.store.update(this.options.serverUrl, (current) => ({
|
|
33
|
-
...current,
|
|
34
|
-
version: 1,
|
|
35
|
-
serverUrl: this.options.serverUrl.toString(),
|
|
36
|
-
clientInformation,
|
|
37
|
-
updatedAt: current?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
38
|
-
}));
|
|
39
|
-
}
|
|
40
|
-
async tokens() {
|
|
41
|
-
return (await this.store.load(this.options.serverUrl))?.tokens;
|
|
42
|
-
}
|
|
43
|
-
async saveTokens(tokens) {
|
|
44
|
-
await this.store.update(this.options.serverUrl, (current) => ({
|
|
45
|
-
...current,
|
|
46
|
-
version: 1,
|
|
47
|
-
serverUrl: this.options.serverUrl.toString(),
|
|
48
|
-
tokens,
|
|
49
|
-
tokensSavedAt: Date.now(),
|
|
50
|
-
updatedAt: current?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
51
|
-
}));
|
|
52
|
-
}
|
|
53
|
-
async redirectToAuthorization(authorizationUrl) {
|
|
54
|
-
if (!this.options.interaction) throw new McpAuthorizationRequiredError();
|
|
55
|
-
await this.options.interaction.onRedirect(authorizationUrl);
|
|
56
|
-
}
|
|
57
|
-
saveCodeVerifier(codeVerifier) {
|
|
58
|
-
this.codeVerifierValue = codeVerifier;
|
|
59
|
-
}
|
|
60
|
-
codeVerifier() {
|
|
61
|
-
if (!this.codeVerifierValue) throw new Error("MCP OAuth code verifier is unavailable");
|
|
62
|
-
return this.codeVerifierValue;
|
|
63
|
-
}
|
|
64
|
-
async saveDiscoveryState(discoveryState) {
|
|
65
|
-
await this.store.update(this.options.serverUrl, (current) => {
|
|
66
|
-
const authorizationServerChanged = Boolean(current?.discoveryState?.authorizationServerUrl && current.discoveryState.authorizationServerUrl !== discoveryState.authorizationServerUrl);
|
|
67
|
-
return {
|
|
68
|
-
...current,
|
|
69
|
-
version: 1,
|
|
70
|
-
serverUrl: this.options.serverUrl.toString(),
|
|
71
|
-
discoveryState,
|
|
72
|
-
clientInformation: authorizationServerChanged ? void 0 : current?.clientInformation,
|
|
73
|
-
tokens: authorizationServerChanged ? void 0 : current?.tokens,
|
|
74
|
-
tokensSavedAt: authorizationServerChanged ? void 0 : current?.tokensSavedAt,
|
|
75
|
-
updatedAt: current?.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
76
|
-
};
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async discoveryState() {
|
|
80
|
-
return (await this.store.load(this.options.serverUrl))?.discoveryState;
|
|
81
|
-
}
|
|
82
|
-
async invalidateCredentials(scope) {
|
|
83
|
-
if (scope === "verifier") {
|
|
84
|
-
this.codeVerifierValue = void 0;
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
await this.store.update(this.options.serverUrl, (current) => {
|
|
88
|
-
if (!current) return void 0;
|
|
89
|
-
if (scope === "all") return void 0;
|
|
90
|
-
return {
|
|
91
|
-
...current,
|
|
92
|
-
...scope === "client" ? { clientInformation: void 0 } : {},
|
|
93
|
-
...scope === "tokens" ? {
|
|
94
|
-
tokens: void 0,
|
|
95
|
-
tokensSavedAt: void 0
|
|
96
|
-
} : {},
|
|
97
|
-
...scope === "discovery" ? { discoveryState: void 0 } : {}
|
|
98
|
-
};
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
//#endregion
|
|
103
|
-
export { XopcMcpOAuthClientProvider };
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { McpOAuthSessionSnapshot } from './mcp-oauth-types.js';
|
|
2
|
-
export declare class McpOAuthSession {
|
|
3
|
-
readonly serverId: string;
|
|
4
|
-
readonly serverUrl: URL;
|
|
5
|
-
readonly id: string;
|
|
6
|
-
readonly state: string;
|
|
7
|
-
readonly createdAt: number;
|
|
8
|
-
readonly expiresAt: number;
|
|
9
|
-
private statusValue;
|
|
10
|
-
private authorizationUrlValue?;
|
|
11
|
-
private errorValue?;
|
|
12
|
-
private callbackServer?;
|
|
13
|
-
private redirectUrlValue?;
|
|
14
|
-
private settleCode?;
|
|
15
|
-
private callbackConsumed;
|
|
16
|
-
private readonly codePromise;
|
|
17
|
-
private timeout?;
|
|
18
|
-
constructor(serverId: string, serverUrl: URL, ttlMs?: number);
|
|
19
|
-
get redirectUrl(): URL;
|
|
20
|
-
start(): Promise<void>;
|
|
21
|
-
setAuthorizationUrl(url: URL): void;
|
|
22
|
-
/** Remote Gateway users can submit the browser's loopback callback URL over the authenticated API. */
|
|
23
|
-
submitCallback(url: string): void;
|
|
24
|
-
waitForCode(): Promise<string>;
|
|
25
|
-
complete(): void;
|
|
26
|
-
fail(error: unknown): void;
|
|
27
|
-
cancel(): void;
|
|
28
|
-
snapshot(): McpOAuthSessionSnapshot;
|
|
29
|
-
close(): Promise<void>;
|
|
30
|
-
private closeServer;
|
|
31
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { randomBytes, randomUUID } from "node:crypto";
|
|
2
|
-
import { createServer } from "node:http";
|
|
3
|
-
//#region src/agent/mcp/oauth/mcp-oauth-session.ts
|
|
4
|
-
const CALLBACK_PATH = "/oauth/callback";
|
|
5
|
-
const DEFAULT_SESSION_TTL_MS = 600 * 1e3;
|
|
6
|
-
function callbackPage(title, message) {
|
|
7
|
-
return `<!doctype html><html><head><meta charset="utf-8"><title>${title}</title></head><body><h1>${title}</h1><p>${message}</p></body></html>`;
|
|
8
|
-
}
|
|
9
|
-
var McpOAuthSession = class {
|
|
10
|
-
id = `mcp_oauth_${randomUUID()}`;
|
|
11
|
-
state = randomBytes(24).toString("base64url");
|
|
12
|
-
createdAt = Date.now();
|
|
13
|
-
expiresAt;
|
|
14
|
-
statusValue = "starting";
|
|
15
|
-
authorizationUrlValue;
|
|
16
|
-
errorValue;
|
|
17
|
-
callbackServer;
|
|
18
|
-
redirectUrlValue;
|
|
19
|
-
settleCode;
|
|
20
|
-
callbackConsumed = false;
|
|
21
|
-
codePromise;
|
|
22
|
-
timeout;
|
|
23
|
-
constructor(serverId, serverUrl, ttlMs = DEFAULT_SESSION_TTL_MS) {
|
|
24
|
-
this.serverId = serverId;
|
|
25
|
-
this.serverUrl = serverUrl;
|
|
26
|
-
this.expiresAt = this.createdAt + ttlMs;
|
|
27
|
-
this.codePromise = new Promise((resolve) => {
|
|
28
|
-
this.settleCode = resolve;
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
get redirectUrl() {
|
|
32
|
-
if (!this.redirectUrlValue) throw new Error("MCP OAuth callback server has not started");
|
|
33
|
-
return this.redirectUrlValue;
|
|
34
|
-
}
|
|
35
|
-
async start() {
|
|
36
|
-
if (this.callbackServer) return;
|
|
37
|
-
const server = createServer((request, response) => {
|
|
38
|
-
response.setHeader("content-type", "text/html; charset=utf-8");
|
|
39
|
-
response.setHeader("cache-control", "no-store");
|
|
40
|
-
response.setHeader("referrer-policy", "no-referrer");
|
|
41
|
-
response.setHeader("x-content-type-options", "nosniff");
|
|
42
|
-
try {
|
|
43
|
-
const callback = new URL(request.url ?? "", "http://127.0.0.1");
|
|
44
|
-
if (callback.pathname !== CALLBACK_PATH) {
|
|
45
|
-
response.statusCode = 404;
|
|
46
|
-
response.end(callbackPage("Not found", "This is not an XOPC OAuth callback."));
|
|
47
|
-
return;
|
|
48
|
-
}
|
|
49
|
-
if (callback.searchParams.get("state") !== this.state) {
|
|
50
|
-
response.statusCode = 400;
|
|
51
|
-
response.end(callbackPage("Authorization failed", "MCP OAuth state mismatch"));
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
if (this.callbackConsumed) {
|
|
55
|
-
response.statusCode = 409;
|
|
56
|
-
response.end(callbackPage("Authorization already handled", "Return to XOPC to continue."));
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const oauthError = callback.searchParams.get("error");
|
|
60
|
-
const code = callback.searchParams.get("code");
|
|
61
|
-
if (oauthError || !code) {
|
|
62
|
-
const error = /* @__PURE__ */ new Error(oauthError === "access_denied" ? "Authorization was denied" : "Authorization code is missing");
|
|
63
|
-
response.statusCode = 400;
|
|
64
|
-
response.end(callbackPage("Authorization failed", error.message));
|
|
65
|
-
this.fail(error);
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
this.callbackConsumed = true;
|
|
69
|
-
this.statusValue = "exchanging_code";
|
|
70
|
-
response.statusCode = 200;
|
|
71
|
-
response.end(callbackPage("Authorization complete", "Return to XOPC to finish connecting the MCP server."));
|
|
72
|
-
this.settleCode?.({ code });
|
|
73
|
-
this.settleCode = void 0;
|
|
74
|
-
} catch {
|
|
75
|
-
const error = /* @__PURE__ */ new Error("MCP OAuth callback could not be processed");
|
|
76
|
-
response.statusCode = 500;
|
|
77
|
-
response.end(callbackPage("Authorization failed", error.message));
|
|
78
|
-
this.fail(error);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
this.callbackServer = server;
|
|
82
|
-
try {
|
|
83
|
-
this.redirectUrlValue = await new Promise((resolve, reject) => {
|
|
84
|
-
server.once("error", reject);
|
|
85
|
-
server.listen(0, "127.0.0.1", () => {
|
|
86
|
-
server.removeListener("error", reject);
|
|
87
|
-
const address = server.address();
|
|
88
|
-
if (!address || typeof address === "string") {
|
|
89
|
-
reject(/* @__PURE__ */ new Error("MCP OAuth callback server did not expose a TCP port"));
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
resolve(new URL(`http://127.0.0.1:${address.port}${CALLBACK_PATH}`));
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
} catch (error) {
|
|
96
|
-
this.callbackServer = void 0;
|
|
97
|
-
server.close();
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
this.timeout = setTimeout(() => {
|
|
101
|
-
this.statusValue = "expired";
|
|
102
|
-
this.errorValue = "MCP OAuth session expired";
|
|
103
|
-
this.settleCode?.({ error: new Error(this.errorValue) });
|
|
104
|
-
this.settleCode = void 0;
|
|
105
|
-
this.closeServer();
|
|
106
|
-
}, Math.max(1, this.expiresAt - Date.now()));
|
|
107
|
-
this.timeout.unref?.();
|
|
108
|
-
}
|
|
109
|
-
setAuthorizationUrl(url) {
|
|
110
|
-
this.authorizationUrlValue = url.toString();
|
|
111
|
-
this.statusValue = "waiting_browser";
|
|
112
|
-
}
|
|
113
|
-
/** Remote Gateway users can submit the browser's loopback callback URL over the authenticated API. */
|
|
114
|
-
submitCallback(url) {
|
|
115
|
-
const callback = new URL(url);
|
|
116
|
-
if (callback.origin !== this.redirectUrl.origin || callback.pathname !== CALLBACK_PATH || callback.searchParams.get("state") !== this.state) throw new Error("MCP OAuth callback mismatch");
|
|
117
|
-
if (this.statusValue !== "waiting_browser" || this.callbackConsumed || Date.now() >= this.expiresAt) throw new Error("MCP OAuth session is not waiting for a callback");
|
|
118
|
-
const code = callback.searchParams.get("code");
|
|
119
|
-
if (!code || callback.searchParams.has("error")) throw new Error("MCP OAuth authorization code is missing or denied");
|
|
120
|
-
this.callbackConsumed = true;
|
|
121
|
-
this.statusValue = "exchanging_code";
|
|
122
|
-
this.settleCode?.({ code });
|
|
123
|
-
this.settleCode = void 0;
|
|
124
|
-
}
|
|
125
|
-
async waitForCode() {
|
|
126
|
-
const result = await this.codePromise;
|
|
127
|
-
if (result.error) throw result.error;
|
|
128
|
-
if (!result.code) throw new Error("MCP OAuth authorization code is unavailable");
|
|
129
|
-
return result.code;
|
|
130
|
-
}
|
|
131
|
-
complete() {
|
|
132
|
-
this.statusValue = "connected";
|
|
133
|
-
this.errorValue = void 0;
|
|
134
|
-
this.closeServer();
|
|
135
|
-
}
|
|
136
|
-
fail(error) {
|
|
137
|
-
this.statusValue = "failed";
|
|
138
|
-
this.errorValue = error instanceof Error ? error.message : String(error);
|
|
139
|
-
this.settleCode?.({ error: error instanceof Error ? error : new Error(String(error)) });
|
|
140
|
-
this.settleCode = void 0;
|
|
141
|
-
this.closeServer();
|
|
142
|
-
}
|
|
143
|
-
cancel() {
|
|
144
|
-
if ([
|
|
145
|
-
"connected",
|
|
146
|
-
"failed",
|
|
147
|
-
"expired",
|
|
148
|
-
"cancelled"
|
|
149
|
-
].includes(this.statusValue)) return;
|
|
150
|
-
this.statusValue = "cancelled";
|
|
151
|
-
this.settleCode?.({ error: /* @__PURE__ */ new Error("MCP OAuth session cancelled") });
|
|
152
|
-
this.settleCode = void 0;
|
|
153
|
-
this.closeServer();
|
|
154
|
-
}
|
|
155
|
-
snapshot() {
|
|
156
|
-
return {
|
|
157
|
-
id: this.id,
|
|
158
|
-
serverId: this.serverId,
|
|
159
|
-
serverUrl: this.serverUrl.toString(),
|
|
160
|
-
status: this.statusValue,
|
|
161
|
-
authorizationUrl: this.authorizationUrlValue,
|
|
162
|
-
error: this.errorValue,
|
|
163
|
-
createdAt: this.createdAt,
|
|
164
|
-
expiresAt: this.expiresAt
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
async close() {
|
|
168
|
-
this.cancel();
|
|
169
|
-
await this.closeServer();
|
|
170
|
-
}
|
|
171
|
-
async closeServer() {
|
|
172
|
-
if (this.timeout) clearTimeout(this.timeout);
|
|
173
|
-
this.timeout = void 0;
|
|
174
|
-
const server = this.callbackServer;
|
|
175
|
-
this.callbackServer = void 0;
|
|
176
|
-
if (!server) return;
|
|
177
|
-
await new Promise((resolve) => server.close(() => resolve()));
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
//#endregion
|
|
181
|
-
export { McpOAuthSession };
|