vite-hub 0.5.0 → 0.6.0
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 +9 -8
- package/dist/_internal/runtime/browser-errors.d.ts +0 -2
- package/dist/_internal/runtime/browser-errors.js +3 -4
- package/dist/_internal/runtime/redirects.d.ts +1 -2
- package/dist/_internal/runtime/redirects.js +2 -3
- package/dist/_internal/runtime/request-policy.d.ts +1 -2
- package/dist/_internal/runtime/request-policy.js +2 -3
- package/dist/_internal/runtime/security.d.ts +1 -2
- package/dist/_internal/runtime/security.js +1 -2
- package/dist/{access-BC9HtX_M.js → access-CUFHPi8T.js} +13 -140
- package/dist/{access-policy-DhsEACna.d.ts → access-DkBck8Vu.d.ts} +17 -21
- package/dist/{access-policy-CVZg9LPR.js → access-policy-BM48XstY.js} +5 -6
- package/dist/{account-Cjj-tYzo.d.ts → account-DNr8fHcQ.d.ts} +5 -7
- package/dist/{console/runtime/server → agent/console}/agents.get.d.ts +2 -3
- package/dist/{console/runtime/server → agent/console}/agents.get.js +3 -4
- package/dist/{console/runtime/server → agent/console}/channel-replay.d.ts +3 -5
- package/dist/{console/runtime/server → agent/console}/channel-replay.js +6 -7
- package/dist/{console/runtime/server → agent/console}/invocation-capabilities.get.d.ts +1 -3
- package/dist/{console/runtime/server → agent/console}/invocation-capabilities.get.js +4 -5
- package/dist/agent/console/invocation-workspace.get.d.ts +6 -0
- package/dist/{console/runtime/server → agent/console}/invocation-workspace.get.js +6 -7
- package/dist/{console/runtime/server → agent/console}/invocation.get.d.ts +4 -6
- package/dist/{console/runtime/server → agent/console}/invocation.get.js +8 -9
- package/dist/{console/runtime/server → agent/console}/invocations.get.d.ts +1 -2
- package/dist/{console/runtime/server → agent/console}/invocations.get.js +5 -6
- package/dist/agent/console/invocations.usage.d.ts +6 -0
- package/dist/agent/console/invocations.usage.js +51 -0
- package/dist/agent/console/operations.d.ts +6 -0
- package/dist/agent/console/operations.js +247 -0
- package/dist/{console/runtime/server → agent/console}/status.get.d.ts +2 -4
- package/dist/{console/runtime/server → agent/console}/status.get.js +6 -7
- package/dist/{server-W0c79AYZ.js → agent-console-CHsLxKk_.js} +4 -4
- package/dist/agent-console-FmaYpVv-.d.ts +14 -0
- package/dist/{agent-invocations.post-C3Onl2yH.js → agent-invocations.post-CF5anHY6.js} +14 -17
- package/dist/agents-DBm_PJie.js +1 -0
- package/dist/{agents-B76RICcy.js → agents-DXLHsE7x.js} +5 -6
- package/dist/{agents-C94A4N9u.d.ts → agents-Gyw4VKPt.d.ts} +0 -2
- package/dist/auth/console/auth.d.ts +25 -0
- package/dist/{console/runtime/server → auth/console}/auth.js +11 -13
- package/dist/auth/console/operations.d.ts +3 -0
- package/dist/auth/console/operations.js +135 -0
- package/dist/auth/server.js +1 -2
- package/dist/{auth-operations-GcQk0O0X.js → auth-operations-BKqoX8Ua.js} +4 -5
- package/dist/{auth-types-D3ugQ8xM.d.ts → auth-types-Cotn7406.d.ts} +4 -21
- package/dist/bin.js +8 -11
- package/dist/blob/console/operations.d.ts +3 -0
- package/dist/blob/console/operations.js +44 -0
- package/dist/blob/nuxt-image.js +1 -2
- package/dist/{blob-BcgsZtqM.js → blob-iw8pWQ6o.js} +5 -6
- package/dist/{blob-iVewd7KQ.d.ts → blob-uNin0_TV.d.ts} +1 -3
- package/dist/{browser-error-limits-CToqAD-O.js → browser-error-limits-B0yS95zt.js} +2 -4
- package/dist/cache/operations.d.ts +2 -4
- package/dist/cache/operations.js +3 -4
- package/dist/cache.d.ts +1 -3
- package/dist/cache.js +2 -3
- package/dist/{cli-config-FPHk1nbC.js → cli-config-BX8H4ZCo.js} +2 -3
- package/dist/cli-config-DgpmE_7z.js +1 -0
- package/dist/cms.js +1 -2
- package/dist/console/auth-types.d.ts +2 -2
- package/dist/console/auth.d.ts +2 -4
- package/dist/console/auth.js +2 -3
- package/dist/console/runtime/auth-operations.d.ts +4 -6
- package/dist/console/runtime/auth-operations.js +1 -2
- package/dist/console/runtime/client/account-views.d.ts +1 -3
- package/dist/console/runtime/client/account-views.js +1 -2
- package/dist/console/runtime/client/account.d.ts +1 -1
- package/dist/console/runtime/client/account.js +29 -45
- package/dist/console/runtime/client/appearance.d.ts +1 -2
- package/dist/console/runtime/client/appearance.js +1 -2
- package/dist/console/runtime/client/auth-management.ts +6 -6
- package/dist/console/runtime/client/blob-media.d.ts +2 -4
- package/dist/console/runtime/client/blob-media.js +5 -6
- package/dist/console/runtime/client/comment-thread.d.ts +1 -3
- package/dist/console/runtime/client/comment-thread.js +3 -4
- package/dist/console/runtime/client/content-heads.d.ts +1 -2
- package/dist/console/runtime/client/content-heads.js +2 -3
- package/dist/console/runtime/client/documents.d.ts +2 -2
- package/dist/console/runtime/client/documents.js +1 -2
- package/dist/console/runtime/client/editor.d.ts +3 -5
- package/dist/console/runtime/client/editor.js +1 -2
- package/dist/console/runtime/client/env-groups.d.ts +1 -3
- package/dist/console/runtime/client/env-groups.js +1 -2
- package/dist/console/runtime/client/env-status.d.ts +1 -3
- package/dist/console/runtime/client/env-status.js +1 -2
- package/dist/console/runtime/client/format.d.ts +1 -3
- package/dist/console/runtime/client/format.js +1 -2
- package/dist/console/runtime/client/invocation-deletion.d.ts +1 -2
- package/dist/console/runtime/client/invocation-deletion.js +1 -2
- package/dist/console/runtime/client/invocation.d.ts +1 -2
- package/dist/console/runtime/client/invocation.js +4 -5
- package/dist/console/runtime/client/live.d.ts +2 -4
- package/dist/console/runtime/client/live.js +1 -2
- package/dist/console/runtime/client/mcp-client.d.ts +7 -5
- package/dist/console/runtime/client/mcp-client.js +10 -5
- package/dist/console/runtime/client/media-library.d.ts +1 -1
- package/dist/console/runtime/client/media-library.js +1 -2
- package/dist/console/runtime/client/media-uploads.d.ts +2 -4
- package/dist/console/runtime/client/media-uploads.js +2 -3
- package/dist/console/runtime/client/media.d.ts +1 -1
- package/dist/console/runtime/client/media.js +1 -2
- package/dist/console/runtime/client/operation-view.d.ts +2 -4
- package/dist/console/runtime/client/operation-view.js +4 -5
- package/dist/console/runtime/client/presence.d.ts +2 -4
- package/dist/console/runtime/client/presence.js +1 -2
- package/dist/console/runtime/client/preview.d.ts +1 -3
- package/dist/console/runtime/client/preview.js +1 -2
- package/dist/console/runtime/client/problem.d.ts +2 -4
- package/dist/console/runtime/client/problem.js +3 -4
- package/dist/console/runtime/client/project-link.d.ts +1 -1
- package/dist/console/runtime/client/project-link.js +1 -2
- package/dist/console/runtime/client/project-session.d.ts +19 -10
- package/dist/console/runtime/client/project-session.js +1 -723
- package/dist/console/runtime/client/project.d.ts +1 -3
- package/dist/console/runtime/client/project.js +1 -2
- package/dist/console/runtime/client/projects.d.ts +1 -1
- package/dist/console/runtime/client/projects.js +1 -2
- package/dist/console/runtime/client/publish.d.ts +2 -4
- package/dist/console/runtime/client/publish.js +1 -2
- package/dist/console/runtime/client/rate-limit.d.ts +1 -3
- package/dist/console/runtime/client/rate-limit.js +3 -4
- package/dist/console/runtime/client/read-only.d.ts +2 -4
- package/dist/console/runtime/client/read-only.js +2 -3
- package/dist/console/runtime/client/request.d.ts +2 -2
- package/dist/console/runtime/client/request.js +1 -2
- package/dist/console/runtime/client/route-query.d.ts +4 -5
- package/dist/console/runtime/client/route-query.js +1 -2
- package/dist/console/runtime/client/schedule-run.d.ts +1 -3
- package/dist/console/runtime/client/schedule-run.js +3 -4
- package/dist/console/runtime/client/schema-form.d.ts +1 -1
- package/dist/console/runtime/client/schema-form.js +1 -2
- package/dist/console/runtime/client/sections.d.ts +1 -1
- package/dist/console/runtime/client/sections.js +1 -2
- package/dist/console/runtime/client/site-access.d.ts +83 -16
- package/dist/console/runtime/client/site-access.js +159 -32
- package/dist/console/runtime/client/site-link.d.ts +2 -0
- package/dist/console/runtime/client/site-link.js +1 -0
- package/dist/console/runtime/client/stored.d.ts +1 -3
- package/dist/console/runtime/client/stored.js +1 -2
- package/dist/console/runtime/client/toast.d.ts +1 -3
- package/dist/console/runtime/client/toast.js +1 -2
- package/dist/console/runtime/client/workflow.d.ts +1 -3
- package/dist/console/runtime/client/workflow.js +3 -4
- package/dist/console/runtime/components/console-account-home.vue +9 -7
- package/dist/console/runtime/components/console-account-link.vue +8 -5
- package/dist/console/runtime/components/console-account-setup.vue +10 -7
- package/dist/console/runtime/components/console-account-shell.vue +7 -2
- package/dist/console/runtime/components/console-account-unlink.vue +2 -3
- package/dist/console/runtime/components/console-app-settings.vue +8 -2
- package/dist/console/runtime/components/console-auth-detail.vue +1 -1
- package/dist/console/runtime/components/console-auth-event-list.vue +1 -0
- package/dist/console/runtime/components/console-document-editor.vue +3 -4
- package/dist/console/runtime/components/console-hosted-comments-embed.vue +106 -0
- package/dist/console/runtime/components/console-mcp-callback.vue +6 -1
- package/dist/console/runtime/components/console-mcp-items.vue +3 -16
- package/dist/console/runtime/components/console-site.vue +10 -8
- package/dist/console/runtime/components/console-usage.vue +2 -2
- package/dist/console/runtime/console-route.d.ts +1 -3
- package/dist/console/runtime/console-route.js +1 -2
- package/dist/console/runtime/definitions.d.ts +1 -1
- package/dist/console/runtime/definitions.js +1 -2
- package/dist/console/runtime/diagnostics.ts +14 -49
- package/dist/console/runtime/mcp-client.d.ts +2 -2
- package/dist/console/runtime/mcp-client.js +1 -2
- package/dist/console/runtime/operation-loader.d.ts +1 -0
- package/dist/console/runtime/operation-loader.js +10 -0
- package/dist/console/runtime/page-tool/account.js +26 -0
- package/dist/console/runtime/page-tool/page-tool.js +2 -2
- package/dist/console/runtime/rpc.d.ts +1 -1
- package/dist/console/runtime/rpc.js +1 -2
- package/dist/console/runtime/sections.d.ts +2 -2
- package/dist/console/runtime/sections.js +1 -2
- package/dist/console/runtime/server/access-policy.d.ts +1 -1
- package/dist/console/runtime/server/access-policy.js +1 -2
- package/dist/console/runtime/server/agent-console.d.ts +2 -0
- package/dist/console/runtime/server/agent-console.js +1 -0
- package/dist/console/runtime/server/blob.d.ts +1 -1
- package/dist/console/runtime/server/blob.js +1 -2
- package/dist/console/runtime/server/database.d.ts +1 -1
- package/dist/console/runtime/server/database.js +1 -2
- package/dist/console/runtime/server/definitions.d.ts +1 -1
- package/dist/console/runtime/server/definitions.get.d.ts +4 -6
- package/dist/console/runtime/server/definitions.get.js +5 -6
- package/dist/console/runtime/server/definitions.js +1 -2
- package/dist/console/runtime/server/development.d.ts +1 -1
- package/dist/console/runtime/server/development.js +1 -2
- package/dist/console/runtime/server/documents.d.ts +2 -2
- package/dist/console/runtime/server/documents.js +3 -3
- package/dist/console/runtime/server/entry-site-access.d.ts +3 -0
- package/dist/console/runtime/server/entry-site-access.js +4 -0
- package/dist/console/runtime/server/entry.d.ts +3 -0
- package/dist/console/runtime/server/entry.js +4 -0
- package/dist/console/runtime/server/env.d.ts +1 -3
- package/dist/console/runtime/server/env.js +1 -2
- package/dist/console/runtime/server/operation-contributions.d.ts +1 -1
- package/dist/console/runtime/server/operation-contributions.js +1 -2
- package/dist/console/runtime/server/pill.d.ts +45 -0
- package/dist/console/runtime/server/pill.js +62 -0
- package/dist/console/runtime/server/rpc.d.ts +5 -10
- package/dist/console/runtime/server/rpc.js +19 -27
- package/dist/console/runtime/server/runtime.d.ts +1 -1
- package/dist/console/runtime/server/runtime.js +1 -2
- package/dist/console/runtime/server/sections.d.ts +5 -5
- package/dist/console/runtime/server/sections.get.d.ts +1 -1
- package/dist/console/runtime/server/sections.get.js +8 -9
- package/dist/console/runtime/server/sections.js +6 -6
- package/dist/console/runtime/server/setup.d.ts +5 -5
- package/dist/console/runtime/server/setup.js +5 -5
- package/dist/console/runtime/server/site-access-operation.d.ts +7 -0
- package/dist/console/runtime/server/site-access-operation.js +36 -0
- package/dist/console/runtime/server/site-actions.d.ts +73 -0
- package/dist/console/runtime/server/site-actions.js +105 -0
- package/dist/console/runtime/server/site-entry.d.ts +16 -9
- package/dist/console/runtime/server/site-entry.js +62 -46
- package/dist/console/runtime/server/site-visitor.d.ts +17 -0
- package/dist/console/runtime/server/site-visitor.js +1 -0
- package/dist/console/runtime/server/site.d.ts +27 -0
- package/dist/console/runtime/server/site.js +1 -0
- package/dist/console/runtime/skills.d.ts +1 -3
- package/dist/console/runtime/skills.js +1 -2
- package/dist/console/server.d.ts +9 -25
- package/dist/console/server.js +8 -8
- package/dist/console/ui.d.ts +0 -10
- package/dist/console/ui.js +14 -27
- package/dist/console-lazy-views-VEjcbL4Q.js +1 -0
- package/dist/{console-route-CM2G5hiC.js → console-route-DbdnLkkF.js} +2 -3
- package/dist/console-signature--55DIKf2.js +237 -0
- package/dist/console.d.ts +1 -3
- package/dist/console.js +1 -2
- package/dist/content/console/operations.d.ts +3 -0
- package/dist/content/console/operations.js +62 -0
- package/dist/{console/runtime/server → database/console}/database.get.d.ts +2 -3
- package/dist/{console/runtime/server → database/console}/database.get.js +4 -5
- package/dist/database/console/operations.d.ts +3 -0
- package/dist/database/console/operations.js +49 -0
- package/dist/{database-UMJgnU2z.js → database-CrgBUdIx.js} +3 -4
- package/dist/{database-DC67Ipm-.d.ts → database-yFezh5U1.d.ts} +1 -3
- package/dist/{definition-catalog-BUcclwSH.js → definition-catalog-1xPPtzOx.js} +3 -4
- package/dist/definition-catalog-M5ua7JRS.js +1 -0
- package/dist/{definitions-BW6SvmMM.js → definitions-BFYqXchw.js} +1 -2
- package/dist/{definitions-DB4LbZ7T.d.ts → definitions-ChvMnA1L.d.ts} +0 -2
- package/dist/{definitions-DTytrw42.js → definitions-DGo2rNQ9.js} +5 -6
- package/dist/{definitions-Dbgxfz3I.d.ts → definitions-DRkgHKmk.d.ts} +1 -3
- package/dist/{deployment-BUshgN5Q.js → deployment-CURATxjG.js} +2 -3
- package/dist/deployment-l7RuKdEp.js +1 -0
- package/dist/{dev-peer-CHjyHYG6.js → dev-peer-CRYp01PE.js} +2 -222
- package/dist/dev-peer-CX5C9243.js +1 -0
- package/dist/{development-zLxOp-AO.js → development-DD567hhJ.js} +2 -3
- package/dist/{development-RnopiRwK.d.ts → development-I40mfD7B.d.ts} +1 -3
- package/dist/{diagnostics-DtR0TAmq.js → diagnostics-DLHqjKGe.js} +3 -9
- package/dist/diagnostics-DgGKvWzF.d.ts +7 -0
- package/dist/docs/nuxt.js +1 -2
- package/dist/doctor.d.ts +0 -6
- package/dist/doctor.js +11492 -12152
- package/dist/{documents-BDR0AkYR.d.ts → documents-A-7Ho0g0.d.ts} +12 -16
- package/dist/{documents-B4R4JSfH.js → documents-BduuZjm3.js} +6 -6
- package/dist/{documents-BASIRZ91.d.ts → documents-CApMRd4o.d.ts} +4 -7
- package/dist/{documents-BewAPY61.js → documents-D6ueeoUR.js} +17 -21
- package/dist/durability/operations.d.ts +2 -4
- package/dist/durability/operations.js +3 -4
- package/dist/{entries-DbyNPLC9.js → entries-UFs9n1MB.js} +2 -3
- package/dist/{console/runtime/server → env/console}/env.get.d.ts +2 -4
- package/dist/env/console/env.get.js +15 -0
- package/dist/env/console/operations.d.ts +3 -0
- package/dist/env/console/operations.js +12 -0
- package/dist/env/vite.d.ts +1 -0
- package/dist/env/vite.js +2 -0
- package/dist/{env-Dg1I_DWr.js → env-D-wtSupz.js} +2 -3
- package/dist/{error-diagnostics-B1yAIaSn.js → error-diagnostics-CBtvqI30.js} +2 -7
- package/dist/{error-diagnostics-C0KyI408.js → error-diagnostics-kKXseq8d.js} +5 -2
- package/dist/error-diagnostics.ts +1 -7
- package/dist/{features-CC5OcZqJ.js → features-BXRKlmtN.js} +5 -6
- package/dist/features-CD5i5I8V.js +1 -0
- package/dist/{format-BOYlanIZ.js → format-Df-bS4Ly.js} +1 -2
- package/dist/{github-login-Bi3bfjRX.js → github-login-W-vaahWP.js} +1 -2
- package/dist/{host-CkL0jjBq.js → host-DeNPYIeV.js} +1 -2
- package/dist/{http-error-Bs6e8_-8.js → http-error-BorAxJYM.js} +1 -2
- package/dist/index.d.ts +1 -7
- package/dist/index.js +5 -7
- package/dist/{inspect-DbZuP_7b.js → inspect-CWwAuL-B.js} +2 -3
- package/dist/internal/agent-invocations-libsql.js +1 -2
- package/dist/internal/disabled-redis-driver.d.ts +1 -3
- package/dist/internal/disabled-redis-driver.js +2 -3
- package/dist/internal/disabled-upstash-driver.d.ts +1 -3
- package/dist/internal/disabled-upstash-driver.js +2 -3
- package/dist/internal/test-loader.d.ts +1 -3
- package/dist/internal/test-loader.js +2 -3
- package/dist/internal/test-server.js +2 -3
- package/dist/{internal-BreyUsQ6.js → internal-0C_CC601.js} +1 -2
- package/dist/{internal-Cc9N0shU.d.ts → internal-BRNf11h3.d.ts} +14 -8
- package/dist/{invariant-DolT9EEx.js → invariant-Dj2R1eMr.js} +1 -2
- package/dist/{invocation-page-undo-DqYcPlkQ.js → invocation-page-undo-DHbXczWY.js} +8 -7
- package/dist/invocations-B60XWNES.js +45 -0
- package/dist/{limits-BUlwWYQE.js → limits-BLo31qDR.js} +1 -2
- package/dist/logs/client.d.ts +1 -3
- package/dist/logs/client.js +1 -2
- package/dist/{console/runtime/server → logs/console}/logs.get.d.ts +3 -5
- package/dist/{console/runtime/server → logs/console}/logs.get.js +7 -8
- package/dist/logs/console/operations.d.ts +3 -0
- package/dist/logs/console/operations.js +23 -0
- package/dist/logs/host.d.ts +2 -4
- package/dist/logs/host.js +1 -2
- package/dist/logs/memory.d.ts +1 -1
- package/dist/logs/memory.js +1 -2
- package/dist/logs/source.d.ts +1 -1
- package/dist/logs/source.js +1 -2
- package/dist/logs.d.ts +2 -2
- package/dist/logs.js +2 -2
- package/dist/loopback-Bl9Cvj1k.js +139 -0
- package/dist/mcp/eval.d.ts +1 -0
- package/dist/mcp/eval.js +2 -0
- package/dist/{mcp-client-C_sEmyQw.d.ts → mcp-client-uXVvS7RL.d.ts} +5 -10
- package/dist/{media-uKX4Wy-c.d.ts → media-C79RB1oH.d.ts} +0 -2
- package/dist/{media-D3OfyKni.js → media-CNwnh6CG.js} +8 -9
- package/dist/{media-library-o8RRsnn_.js → media-library-DTC8TLsZ.js} +5 -6
- package/dist/{media-library-D9ThbXqs.d.ts → media-library-DxGu6w9z.d.ts} +0 -2
- package/dist/{memory-C54SDH_l.js → memory-D3EJS_Bp.js} +3 -4
- package/dist/{memory-2bbl4hcV.d.ts → memory-GK5ZGWrp.d.ts} +1 -3
- package/dist/{nuxt-server-auto-imports-cfTZYvgy.js → nuxt-server-auto-imports-4aT5BD4u.js} +1 -2
- package/dist/{nuxt-server-imports-75bWMeXc.js → nuxt-server-imports-BdJqiVhT.js} +1 -2
- package/dist/nuxt.d.ts +1 -3
- package/dist/nuxt.js +276 -182
- package/dist/{object-D8pRdprI.js → object-DRSmpe04.js} +1 -2
- package/dist/{operation-contributions-C3lwePQu.js → operation-contributions-BU10k2QS.js} +9 -9
- package/dist/{operation-contributions-CrdmqtJW.d.ts → operation-contributions-xwjDzj28.d.ts} +6 -7
- package/dist/{operation-definition-DxjKcCGm.js → operation-definition-D04Rdjbe.js} +7 -9
- package/dist/operation-modules-BUXlwjvd.js +1 -0
- package/dist/operation-modules-DHWkPcfS.js +139 -0
- package/dist/{operation-registry-BogGwk_I.js → operation-registry-DfQbL7vE.js} +1 -2
- package/dist/{operation-rpc-DI9txNxK.js → operation-rpc-BMdfapja.js} +3 -4
- package/dist/operations-D-7ljPqw.js +1 -0
- package/dist/{operations-TTjL_7Zc.d.ts → operations-DgFhA1WE.d.ts} +0 -4
- package/dist/{operations-CFYGXqLm.js → operations-DksTrRMb.js} +4 -5
- package/dist/operations-byxiZ2R2.js +113 -0
- package/dist/{optional-owners-O6sj4uoj.js → optional-owners-Cypch7V3.js} +4 -6
- package/dist/{out-fRNaVslw.js → out-Cw5Tvr92.js} +2933 -2301
- package/dist/{owned-paths-BnjT0FhU.js → owned-paths-MjjDftBn.js} +1 -2
- package/dist/page/pill.iife.js +2 -2
- package/dist/page-tools-BeZrtn4S.js +46 -0
- package/dist/page-tools-Chk8Gm9x.d.ts +23 -0
- package/dist/page-tools-shared-BLPidmCi.js +39 -0
- package/dist/{pathe.M-eThtNZ-J4gfe1m9.js → pathe.M-eThtNZ-D4EC7Wue.js} +1 -2
- package/dist/{plugins-DoXnU6-s.d.ts → plugins-BmkOoyIh.d.ts} +25 -110
- package/dist/{plugins-BTZQaFtZ.js → plugins-DfXcUnzN.js} +1779 -1384
- package/dist/presets/workspace.js +1 -2
- package/dist/{project-Dgyq1F1V.d.ts → project-B2qWt8on.d.ts} +3 -12
- package/dist/{project-DlWTGB7h.js → project-DRC67Uiu.js} +1 -2
- package/dist/{project-DXZRZEPX.js → project-_juMSuAS.js} +8 -11
- package/dist/{project-link-DT99MoyU.js → project-link-CJbCkOlC.js} +7 -8
- package/dist/{project-link-bNS-KROO.d.ts → project-link-Ck3vuq9w.d.ts} +2 -4
- package/dist/{project-root-v6ba4tn7.js → project-root-mAVQGZTX.js} +1 -2
- package/dist/project-session-8pN7pRo8.js +764 -0
- package/dist/{projects-CAcXztf4.js → projects-BRp0iseV.js} +1 -2
- package/dist/{projects-Ddvl9EJp.d.ts → projects-mgPxrKZr.d.ts} +0 -2
- package/dist/{registry-zw6aE2N9.js → registry-B8JE5NY-.js} +1 -2
- package/dist/{registry-CDKLACCZ.js → registry-CnPC-gNu.js} +1 -2
- package/dist/{request-CMA2UKKq.js → request-D769eiBL.js} +5 -6
- package/dist/{request-D7h3SQ92.d.ts → request-DYmjLTqP.d.ts} +2 -4
- package/dist/{request-SBLxvpyr.d.ts → request-DkoE0b2h.d.ts} +11 -4
- package/dist/{request-Cs0FqxEL.js → request-XFVx7CGC.js} +30 -9
- package/dist/{request-origin-COUkgHd6.js → request-origin-pzWr9UUu.js} +1 -2
- package/dist/{rolldown-runtime-CMFfr-1z.js → rolldown-runtime-DegdyBIC.js} +2 -3
- package/dist/{route-query-CRVWXIrc.js → route-query-BWVl6ZO6.js} +4 -5
- package/dist/routes-D02vxUSg.js +26 -0
- package/dist/{rpc-DIUA61pv.js → rpc-D3tsx5lZ.js} +1 -2
- package/dist/{rpc-7nlHSv3y.d.ts → rpc-oijgKQtD.d.ts} +0 -2
- package/dist/{runtime-YLWfdrtO.js → runtime-CAbuQGMP.js} +3 -4
- package/dist/{runtime-B-46Bawt.js → runtime-CRJsqVTa.js} +2 -3
- package/dist/{runtime-DxfJOfCd.js → runtime-DA7HJe10.js} +3 -4
- package/dist/runtime-DGvimtvc.d.ts +5 -0
- package/dist/{runtime-CX_l_78I.js → runtime-F0CTqBFx.js} +5 -6
- package/dist/{runtime-feature-guard-CuyPVGj9.js → runtime-feature-guard-BKAMRZzM.js} +6 -7
- package/dist/scan-module-B1A24jqP.js +1 -0
- package/dist/{scan-module-Df58L_6T.js → scan-module-BfZvDBxb.js} +2 -4
- package/dist/{schema-form-C-fy3xaU.d.ts → schema-form-Bl79Bdm-.d.ts} +0 -2
- package/dist/search-jgMrZJXR.js +84 -0
- package/dist/{sections-DumoLKQN.js → sections-AUGy9EkY.js} +2 -8
- package/dist/{sections-BogiCmtz.d.ts → sections-BMkFB3S-.d.ts} +4 -6
- package/dist/{sections-C83x0slv.js → sections-BNTdIEJw.js} +2 -3
- package/dist/{sections-Do7X4Nwt.d.ts → sections-DCoCa4nF.d.ts} +1 -8
- package/dist/sections-DjeAUX7o.d.ts +8 -0
- package/dist/{sections-BKUReack.js → sections-ZFAlI4JW.js} +14 -7
- package/dist/{sections.get-H46e2urg.d.ts → sections.get-BY5dClJY.d.ts} +2 -4
- package/dist/seo/runtime.d.ts +2 -5
- package/dist/seo/runtime.js +3 -5
- package/dist/{seo-CtLywyRx.d.ts → seo-CgW5uI9L.d.ts} +0 -2
- package/dist/seo.d.ts +1 -1
- package/dist/seo.js +1 -2
- package/dist/{setup-BC0P3eZy.d.ts → setup-BBnZPziq.d.ts} +5 -10
- package/dist/{setup-DNGzawFn.js → setup-yc3_WKNG.js} +4 -17
- package/dist/site-CZCIWsUQ.js +169 -0
- package/dist/site-link-Bvo2SxPo.js +58 -0
- package/dist/site-link-Dtw8MNVB.d.ts +18 -0
- package/dist/site-pages-B6J8U2Nq.js +66 -0
- package/dist/site-token-Wa7fhjwg.js +215 -0
- package/dist/site-visitor-BkhE2TA0.js +89 -0
- package/dist/skills/operations.d.ts +1 -5
- package/dist/skills/operations.js +4 -5
- package/dist/{skills-DdpSMiCI.js → skills-C1MaGEbO.js} +1 -2
- package/dist/skills.d.ts +1 -2
- package/dist/{skills.get-CRd06TTb.js → skills.get-CW8vc_Hf.js} +3 -4
- package/dist/skills.js +1 -2
- package/dist/{source-Cw3iYvJF.js → source-DYFndd0W.js} +2 -3
- package/dist/{source-S-LChQvw.d.ts → source-DemBtwla.d.ts} +0 -2
- package/dist/{stored-Dhv2qsQv.js → stored-J3TetMKf.js} +1 -2
- package/dist/task/operations.d.ts +1 -5
- package/dist/task/operations.js +3 -4
- package/dist/test/register.js +2 -3
- package/dist/test.d.ts +0 -4
- package/dist/test.js +1 -2
- package/dist/ui/vite.js +1 -2
- package/dist/usage-DBi7aOhx.js +33 -0
- package/dist/{version-dkga9imp.js → version-DUCd7Orc.js} +24 -21
- package/dist/{vite-stage-D7fe614I.js → vite-stage-Dmo4RgnK.js} +3 -5
- package/dist/{vue-router-C68IU1jM.d.ts → vue-router-plZJLlpm.d.ts} +120 -182
- package/dist/workspace/console/operations.d.ts +3 -0
- package/dist/workspace/console/operations.js +22 -0
- package/dist/{console/runtime/server → workspace/console}/workspace-files.get.d.ts +3 -5
- package/dist/{console/runtime/server → workspace/console}/workspace-files.get.js +4 -5
- package/dist/{workspace-history-B95Q-kGI.js → workspace-history-B52xib2J.js} +3 -4
- package/dist/{workspace-history-CeVwBB6Q.d.ts → workspace-history-WuxgLsi4.d.ts} +0 -2
- package/package.json +158 -149
- package/dist/agents-BhFggA26.js +0 -2
- package/dist/auth-GFIN6xSJ.d.ts +0 -120
- package/dist/cli-config-g_mbWdjT.js +0 -2
- package/dist/cloudflare-env-lookup-DKXdr4P_.js +0 -16
- package/dist/console/runtime/client/ticket.d.ts +0 -2
- package/dist/console/runtime/client/ticket.js +0 -2
- package/dist/console/runtime/page/loader.js +0 -134
- package/dist/console/runtime/server/auth.d.ts +0 -2
- package/dist/console/runtime/server/env.get.js +0 -16
- package/dist/console/runtime/server/invocation-workspace.get.d.ts +0 -8
- package/dist/console/runtime/server/mcp-client-operations.d.ts +0 -5
- package/dist/console/runtime/server/mcp-client-operations.js +0 -139
- package/dist/console/runtime/server/page-auth.d.ts +0 -18
- package/dist/console/runtime/server/page-auth.js +0 -44
- package/dist/console/runtime/server/page-tool.d.ts +0 -2
- package/dist/console/runtime/server/page-tool.js +0 -110
- package/dist/console/runtime/server/page-tools-route.d.ts +0 -2
- package/dist/console/runtime/server/page-tools-route.js +0 -5
- package/dist/console/runtime/server/search.get.d.ts +0 -4
- package/dist/console/runtime/server/search.get.js +0 -97
- package/dist/console/runtime/server/site-session.d.ts +0 -80
- package/dist/console/runtime/server/site-session.js +0 -2
- package/dist/console/runtime/server/tickets.d.ts +0 -2
- package/dist/console/runtime/server/tickets.js +0 -2
- package/dist/console/runtime/server/usage.get.d.ts +0 -10
- package/dist/console/runtime/server/usage.get.js +0 -92
- package/dist/console/runtime/site-access.d.ts +0 -2
- package/dist/console/runtime/site-access.js +0 -2
- package/dist/console-lazy-views-DXnIkdyd.js +0 -2
- package/dist/definition-catalog-og_1razf.js +0 -2
- package/dist/deployment-C2B0hBBj.js +0 -2
- package/dist/diagnostics-CjGiniKb.d.ts +0 -11
- package/dist/features-ujWsvlEH.js +0 -2
- package/dist/invocations-6jxqLkGY.js +0 -86
- package/dist/mcp-client-C91h8Taa.js +0 -1024
- package/dist/mcp-client-CTbTbn7d.js +0 -10
- package/dist/operations-5Lwd1xEI.js +0 -2
- package/dist/operations-ChEXk2ij.js +0 -853
- package/dist/page-tool-PmxH65gt.d.ts +0 -69
- package/dist/page-tools-ClgqElu-.js +0 -462
- package/dist/page-tools-DcCCtDKi.d.ts +0 -23
- package/dist/page-tools-shared-aNC9YtoI.js +0 -125
- package/dist/runtime-B_btezs1.d.ts +0 -7
- package/dist/scan-module-D_3X08mj.js +0 -2
- package/dist/secret-DELGKpCJ.js +0 -44
- package/dist/sections-CFiMNsqu.d.ts +0 -10
- package/dist/site-access-BycrwM2v.js +0 -18
- package/dist/site-access-CAiWyKOD.js +0 -2
- package/dist/site-access-DxfdOel1.d.ts +0 -55
- package/dist/site-access-L1qbvKt6.js +0 -293
- package/dist/site-session-CRwgKtTF.js +0 -300
- package/dist/skills/vitehub/SKILL.md +0 -142
- package/dist/skills/vitehub/agents/openai.yaml +0 -4
- package/dist/skills/vitehub/references/agent-definitions.md +0 -36
- package/dist/skills/vitehub/references/bundle.md +0 -57
- package/dist/skills/vitehub/references/capabilities-authority.md +0 -30
- package/dist/skills/vitehub/references/channels-triggers.md +0 -27
- package/dist/skills/vitehub/references/framework-composition.md +0 -29
- package/dist/skills/vitehub/references/preview-contract.md +0 -44
- package/dist/skills/vitehub/references/primitives/auth.md +0 -14
- package/dist/skills/vitehub/references/primitives/blob.md +0 -13
- package/dist/skills/vitehub/references/primitives/browser.md +0 -17
- package/dist/skills/vitehub/references/primitives/cache.md +0 -13
- package/dist/skills/vitehub/references/primitives/channels.md +0 -11
- package/dist/skills/vitehub/references/primitives/connections.md +0 -14
- package/dist/skills/vitehub/references/primitives/content.md +0 -13
- package/dist/skills/vitehub/references/primitives/database.md +0 -15
- package/dist/skills/vitehub/references/primitives/email.md +0 -11
- package/dist/skills/vitehub/references/primitives/env.md +0 -13
- package/dist/skills/vitehub/references/primitives/kv.md +0 -13
- package/dist/skills/vitehub/references/primitives/markdown-template.md +0 -13
- package/dist/skills/vitehub/references/primitives/queue.md +0 -14
- package/dist/skills/vitehub/references/primitives/rate-limit.md +0 -11
- package/dist/skills/vitehub/references/primitives/realtime.md +0 -19
- package/dist/skills/vitehub/references/primitives/sandbox-task.md +0 -11
- package/dist/skills/vitehub/references/primitives/sandbox.md +0 -13
- package/dist/skills/vitehub/references/primitives/schedule.md +0 -11
- package/dist/skills/vitehub/references/primitives/shell.md +0 -11
- package/dist/skills/vitehub/references/primitives/source.md +0 -11
- package/dist/skills/vitehub/references/primitives/workflow.md +0 -11
- package/dist/skills/vitehub/references/primitives/workspace.md +0 -11
- package/dist/skills/vitehub/references/project-patterns.md +0 -19
- package/dist/skills/vitehub/references/project-shapes.md +0 -81
- package/dist/skills/vitehub/references/proof-recovery.md +0 -31
- package/dist/skills/vitehub/references/sandboxes-hosts.md +0 -26
- package/dist/skills/vitehub/references/schedules-workflows-invocations.md +0 -28
- package/dist/skills/vitehub/references/server-primitives.md +0 -39
- package/dist/skills/vitehub/references/workspaces-sources-access.md +0 -26
- package/dist/ticket-DtBAstEU.js +0 -31
- package/dist/ticket-Pr_8ZtXW.d.ts +0 -14
- package/dist/tickets-DahBmKDT.js +0 -357
- package/dist/usage-CoQXs5nW.d.ts +0 -22
- package/dist/usage-index-VJAZ7a0p.js +0 -335
- package/dist/usage-jKtAgJZ0.js +0 -571
- /package/dist/{console/runtime/public/skills → console-skills}/index.json +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/SKILL.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/agents/openai.yaml +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/agent-definitions.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/bundle.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/capabilities-authority.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/channels-triggers.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/framework-composition.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/preview-contract.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/auth.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/blob.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/browser.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/cache.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/channels.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/connections.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/content.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/database.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/email.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/env.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/kv.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/markdown-template.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/queue.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/rate-limit.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/realtime.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/sandbox-task.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/sandbox.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/schedule.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/shell.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/source.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/workflow.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/primitives/workspace.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/project-patterns.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/project-shapes.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/proof-recovery.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/sandboxes-hosts.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/schedules-workflows-invocations.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/server-primitives.md +0 -0
- /package/dist/{console/runtime/public/skills → console-skills}/vitehub/references/workspaces-sources-access.md +0 -0
|
@@ -1,1024 +0,0 @@
|
|
|
1
|
-
import { n as isRecord } from "./object-D8pRdprI.js";
|
|
2
|
-
import { t as consoleDiagnostic } from "./diagnostics-DtR0TAmq.js";
|
|
3
|
-
import { m as readConsoleOperationUser } from "./access-BC9HtX_M.js";
|
|
4
|
-
import { i as consoleRequestError, r as consolePublicURL } from "./request-CMA2UKKq.js";
|
|
5
|
-
import { r as consoleMountBase } from "./console-route-CM2G5hiC.js";
|
|
6
|
-
import { r as getConsoleSections } from "./sections-C83x0slv.js";
|
|
7
|
-
import { t as consoleMcpCallbackPath } from "./mcp-client-CTbTbn7d.js";
|
|
8
|
-
import { n as getActiveCloudflareEnv } from "./cloudflare-env-lookup-DKXdr4P_.js";
|
|
9
|
-
import * as v from "valibot";
|
|
10
|
-
import { importSealKey, sealWithKey, unsealWithKey } from "@vite-hub/env/seal";
|
|
11
|
-
import { UnauthorizedError, auth, discoverOAuthServerInfo, extractWWWAuthenticateParams } from "@modelcontextprotocol/sdk/client/auth.js";
|
|
12
|
-
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
13
|
-
import { StreamableHTTPClientTransport, StreamableHTTPError } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
14
|
-
import { McpError, ResultSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
15
|
-
import { OAuthClientInformationSchema, OAuthTokensSchema } from "@modelcontextprotocol/sdk/shared/auth.js";
|
|
16
|
-
//#region src/console/runtime/server/mcp-client-store.ts
|
|
17
|
-
const stateKey = Symbol.for("vitehub.console.mcp-client");
|
|
18
|
-
const scope = globalThis;
|
|
19
|
-
function memoryRecords() {
|
|
20
|
-
const state = scope[stateKey] ??= {
|
|
21
|
-
clients: /* @__PURE__ */ new Map(),
|
|
22
|
-
connections: /* @__PURE__ */ new Map()
|
|
23
|
-
};
|
|
24
|
-
return {
|
|
25
|
-
durable: false,
|
|
26
|
-
client: async (key) => state.clients.get(key),
|
|
27
|
-
connection: async (owner, id) => {
|
|
28
|
-
const connection = state.connections.get(id);
|
|
29
|
-
return connection?.owner === owner ? connection : void 0;
|
|
30
|
-
},
|
|
31
|
-
connections: async (owner) => [...state.connections.values()].filter((connection) => connection.owner === owner),
|
|
32
|
-
remove: async (connection) => {
|
|
33
|
-
state.connections.delete(connection.id);
|
|
34
|
-
},
|
|
35
|
-
removeClient: async (key) => {
|
|
36
|
-
state.clients.delete(key);
|
|
37
|
-
},
|
|
38
|
-
save: async (connection) => {
|
|
39
|
-
state.connections.set(connection.id, connection);
|
|
40
|
-
},
|
|
41
|
-
saveClient: async (key, client) => {
|
|
42
|
-
state.clients.set(key, client);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
const optionalText = v.optional(v.string());
|
|
47
|
-
const clientSchema = v.custom((value) => OAuthClientInformationSchema.safeParse(value).success);
|
|
48
|
-
const connectionSchema = v.object({
|
|
49
|
-
auth: v.picklist([
|
|
50
|
-
"bearer",
|
|
51
|
-
"console",
|
|
52
|
-
"none",
|
|
53
|
-
"oauth"
|
|
54
|
-
]),
|
|
55
|
-
bearer: optionalText,
|
|
56
|
-
consoleOrigin: v.string(),
|
|
57
|
-
createdAt: v.number(),
|
|
58
|
-
error: optionalText,
|
|
59
|
-
id: v.string(),
|
|
60
|
-
identity: v.optional(v.object({
|
|
61
|
-
email: optionalText,
|
|
62
|
-
name: optionalText,
|
|
63
|
-
picture: optionalText,
|
|
64
|
-
subject: optionalText
|
|
65
|
-
})),
|
|
66
|
-
label: v.string(),
|
|
67
|
-
labelled: v.boolean(),
|
|
68
|
-
oauth: v.optional(v.object({
|
|
69
|
-
client: v.optional(clientSchema),
|
|
70
|
-
discovery: v.optional(v.custom((value) => isRecord(value) && typeof value.authorizationServerUrl === "string")),
|
|
71
|
-
pending: v.optional(v.object({
|
|
72
|
-
expiresAt: v.number(),
|
|
73
|
-
prompt: v.optional(v.literal("login")),
|
|
74
|
-
state: v.string(),
|
|
75
|
-
url: optionalText,
|
|
76
|
-
verifier: optionalText
|
|
77
|
-
})),
|
|
78
|
-
receivedAt: v.optional(v.number()),
|
|
79
|
-
redirectUrl: v.string(),
|
|
80
|
-
tokens: v.optional(v.custom((value) => OAuthTokensSchema.safeParse(value).success))
|
|
81
|
-
})),
|
|
82
|
-
owner: v.string(),
|
|
83
|
-
protocolVersion: optionalText,
|
|
84
|
-
sameOrigin: v.boolean(),
|
|
85
|
-
server: v.optional(v.custom((value) => isRecord(value) && typeof value.name === "string" && isRecord(value.capabilities))),
|
|
86
|
-
sessionId: optionalText,
|
|
87
|
-
status: v.picklist([
|
|
88
|
-
"authorizing",
|
|
89
|
-
"connected",
|
|
90
|
-
"failed",
|
|
91
|
-
"signed-out"
|
|
92
|
-
]),
|
|
93
|
-
url: v.string(),
|
|
94
|
-
usedAt: v.optional(v.number())
|
|
95
|
-
});
|
|
96
|
-
const keyVariable = "VITEHUB_CONSOLE_MCP_KEY";
|
|
97
|
-
const prefix = "vitehub:console:mcp-client";
|
|
98
|
-
function decodeKey(value) {
|
|
99
|
-
if (/^[a-f0-9]{64}$/i.test(value)) return Uint8Array.from(value.match(/../g), (byte) => Number.parseInt(byte, 16));
|
|
100
|
-
if (!/^[\w+/-]+={0,2}$/.test(value)) return void 0;
|
|
101
|
-
try {
|
|
102
|
-
return Uint8Array.from(atob(value.replace(/=+$/, "").replaceAll("-", "+").replaceAll("_", "/")), (character) => character.charCodeAt(0));
|
|
103
|
-
} catch {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
function configuredKey() {
|
|
108
|
-
const value = globalThis.process?.env?.[keyVariable] ?? getActiveCloudflareEnv()?.[keyVariable];
|
|
109
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
110
|
-
}
|
|
111
|
-
/** A short hash, so KV key names do not show who owns a connection, such as a Cloudflare Access email. */
|
|
112
|
-
async function hashed(value) {
|
|
113
|
-
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)));
|
|
114
|
-
return Array.from(digest.slice(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
115
|
-
}
|
|
116
|
-
function unwrap([error, value]) {
|
|
117
|
-
if (error) throw error;
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Records in KV, one sealed value per connection and per client registration. Each value is bound to its key, so a
|
|
122
|
-
* record copied under another owner does not open. Two requests that change the same connection at once keep the
|
|
123
|
-
* last write.
|
|
124
|
-
*/
|
|
125
|
-
function kvConsoleMcpRecords(kv, key) {
|
|
126
|
-
const encoder = new TextEncoder();
|
|
127
|
-
async function read(name, schema) {
|
|
128
|
-
const stored = unwrap(await kv.get(name));
|
|
129
|
-
const sealed = isRecord(stored) && typeof stored.sealed === "string" ? stored.sealed : void 0;
|
|
130
|
-
if (!sealed) return void 0;
|
|
131
|
-
let value;
|
|
132
|
-
try {
|
|
133
|
-
value = JSON.parse(await unsealWithKey(key, encoder.encode(name), sealed));
|
|
134
|
-
} catch {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
const parsed = v.safeParse(schema, value);
|
|
138
|
-
return parsed.success ? parsed.output : void 0;
|
|
139
|
-
}
|
|
140
|
-
async function write(name, value) {
|
|
141
|
-
unwrap(await kv.set(name, { sealed: await sealWithKey(key, encoder.encode(name), JSON.stringify(value)) }));
|
|
142
|
-
}
|
|
143
|
-
const connectionKey = async (owner, id) => `${prefix}:connections:${await hashed(owner)}:${id}`;
|
|
144
|
-
const clientKey = async (name) => `${prefix}:clients:${await hashed(name)}`;
|
|
145
|
-
return {
|
|
146
|
-
durable: true,
|
|
147
|
-
client: async (name) => read(await clientKey(name), clientSchema),
|
|
148
|
-
connection: async (owner, id) => {
|
|
149
|
-
const connection = await read(await connectionKey(owner, id), connectionSchema);
|
|
150
|
-
return connection?.owner === owner ? connection : void 0;
|
|
151
|
-
},
|
|
152
|
-
connections: async (owner) => {
|
|
153
|
-
const base = `${prefix}:connections:${await hashed(owner)}`;
|
|
154
|
-
const names = (unwrap(await kv.list({ prefix: `${base}:` }))?.keys ?? []).map((name) => name.replaceAll("/", ":")).filter((name) => name.startsWith(`${base}:`));
|
|
155
|
-
return (await Promise.all(names.map((name) => read(name, connectionSchema)))).filter((connection) => connection?.owner === owner);
|
|
156
|
-
},
|
|
157
|
-
remove: async (connection) => {
|
|
158
|
-
unwrap(await kv.delete(await connectionKey(connection.owner, connection.id)));
|
|
159
|
-
},
|
|
160
|
-
removeClient: async (name) => {
|
|
161
|
-
unwrap(await kv.delete(await clientKey(name)));
|
|
162
|
-
},
|
|
163
|
-
save: async (connection) => write(await connectionKey(connection.owner, connection.id), connection),
|
|
164
|
-
saveClient: async (name, client) => write(await clientKey(name), client)
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
let durable;
|
|
168
|
-
/** The records of this process: in KV with `VITEHUB_CONSOLE_MCP_KEY`, else in memory. */
|
|
169
|
-
async function consoleMcpRecords() {
|
|
170
|
-
const value = configuredKey();
|
|
171
|
-
if (!value) return memoryRecords();
|
|
172
|
-
const bytes = decodeKey(value);
|
|
173
|
-
if (bytes?.byteLength !== 32) throw consoleRequestError(500, `${keyVariable} must be 32 random bytes as base64 or hex. Create one with \`openssl rand -base64 32\`.`, "CONSOLE_MCP_KEY_INVALID");
|
|
174
|
-
if (!getConsoleSections().includes("kv")) throw consoleRequestError(500, `${keyVariable} requires the app's default KV store. Set kv: true in vitehub(), or configure a default KV store.`, "CONSOLE_MCP_KV_REQUIRED");
|
|
175
|
-
if (durable?.value !== value) durable = {
|
|
176
|
-
records: Promise.all([import("@vite-hub/kv"), importSealKey(bytes)]).then(([{ kv }, sealKey]) => kvConsoleMcpRecords(kv, sealKey)),
|
|
177
|
-
value
|
|
178
|
-
};
|
|
179
|
-
return durable.records;
|
|
180
|
-
}
|
|
181
|
-
/** Forget every connection kept in memory. Tests use it. */
|
|
182
|
-
function resetConsoleMcpRecords() {
|
|
183
|
-
delete scope[stateKey];
|
|
184
|
-
durable = void 0;
|
|
185
|
-
}
|
|
186
|
-
//#endregion
|
|
187
|
-
//#region src/console/runtime/server/mcp-client.ts
|
|
188
|
-
/** The MCP servers that each origin announced, for a minute. */
|
|
189
|
-
const discovered = /* @__PURE__ */ new Map();
|
|
190
|
-
const connectionRuntimes = /* @__PURE__ */ new Map();
|
|
191
|
-
const completingAuthorizations = /* @__PURE__ */ new Set();
|
|
192
|
-
const pendingLifetimeMs = 6e5;
|
|
193
|
-
const discoveryLifetimeMs = 6e4;
|
|
194
|
-
const requestTimeoutMs = 3e4;
|
|
195
|
-
const callTimeoutMs = 12e4;
|
|
196
|
-
const maximumConnections = 20;
|
|
197
|
-
const clientInfo = {
|
|
198
|
-
name: "vitehub-console",
|
|
199
|
-
title: "ViteHub Console",
|
|
200
|
-
version: "1.0.0"
|
|
201
|
-
};
|
|
202
|
-
/** Every person keeps their own connections. A Console without accounts shares one owner per access mode. */
|
|
203
|
-
async function ownerOf(caller) {
|
|
204
|
-
const user = await readConsoleOperationUser(caller.access);
|
|
205
|
-
return user?.id ? `user:${user.id}` : caller.access.mode;
|
|
206
|
-
}
|
|
207
|
-
/** The origin and Console mount that the browser sees, from the RPC request. */
|
|
208
|
-
function consolePage(caller) {
|
|
209
|
-
if (!caller.request) throw consoleRequestError(400, "MCP connections need the Console page that calls them.");
|
|
210
|
-
const url = consolePublicURL(caller.request);
|
|
211
|
-
return {
|
|
212
|
-
mount: consoleMountBase(url.pathname),
|
|
213
|
-
origin: url.origin
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
const loopbackHosts = /* @__PURE__ */ new Set([
|
|
217
|
-
"localhost",
|
|
218
|
-
"127.0.0.1",
|
|
219
|
-
"[::1]"
|
|
220
|
-
]);
|
|
221
|
-
/** Resolve a URL or a path such as `/mcp` against the Console origin. Plain HTTP works only on this origin and on loopback hosts. */
|
|
222
|
-
function serverUrl(value, origin) {
|
|
223
|
-
let url;
|
|
224
|
-
try {
|
|
225
|
-
url = new URL(value.trim(), origin);
|
|
226
|
-
} catch {
|
|
227
|
-
throw consoleRequestError(400, "Enter the URL of an MCP endpoint, such as https://example.com/mcp, or a path on this app, such as /mcp.");
|
|
228
|
-
}
|
|
229
|
-
const loopback = loopbackHosts.has(url.hostname) || url.hostname.endsWith(".localhost");
|
|
230
|
-
if (url.protocol !== "https:" && !(url.protocol === "http:" && (url.origin === origin || loopback))) throw consoleRequestError(400, "Use an HTTPS URL. Plain HTTP works only for this app and for localhost.");
|
|
231
|
-
if (url.username || url.password || url.hash) throw consoleRequestError(400, "The MCP URL cannot contain credentials or a fragment.");
|
|
232
|
-
return url;
|
|
233
|
-
}
|
|
234
|
-
const redirectStatuses = /* @__PURE__ */ new Set([
|
|
235
|
-
301,
|
|
236
|
-
302,
|
|
237
|
-
303,
|
|
238
|
-
307,
|
|
239
|
-
308
|
|
240
|
-
]);
|
|
241
|
-
function withTimeout(timeoutMs, origin) {
|
|
242
|
-
return async (input, init) => {
|
|
243
|
-
let request = new Request(input, init);
|
|
244
|
-
const signal = AbortSignal.any([request.signal, AbortSignal.timeout(timeoutMs)]);
|
|
245
|
-
for (let redirects = 0;; redirects++) {
|
|
246
|
-
signal.throwIfAborted();
|
|
247
|
-
serverUrl(request.url, origin);
|
|
248
|
-
const response = await fetch(request.clone(), {
|
|
249
|
-
redirect: "manual",
|
|
250
|
-
signal
|
|
251
|
-
});
|
|
252
|
-
const location = response.headers.get("location");
|
|
253
|
-
if (!redirectStatuses.has(response.status) || location === null || request.redirect === "manual") return response;
|
|
254
|
-
await response.body?.cancel();
|
|
255
|
-
if (request.redirect === "error") throw consoleRequestError(502, "The server returned a redirect.");
|
|
256
|
-
if (redirects >= 20) throw consoleRequestError(502, "Too many redirects from the MCP or OAuth server.");
|
|
257
|
-
const target = serverUrl(new URL(location, request.url).href, origin);
|
|
258
|
-
const headers = new Headers(request.headers);
|
|
259
|
-
if (target.origin !== new URL(request.url).origin) for (const name of [
|
|
260
|
-
"authorization",
|
|
261
|
-
"proxy-authorization",
|
|
262
|
-
"cookie"
|
|
263
|
-
]) headers.delete(name);
|
|
264
|
-
if ((response.status === 301 || response.status === 302) && request.method === "POST" || response.status === 303 && request.method !== "GET" && request.method !== "HEAD") {
|
|
265
|
-
for (const name of [
|
|
266
|
-
"content-encoding",
|
|
267
|
-
"content-language",
|
|
268
|
-
"content-location",
|
|
269
|
-
"content-type"
|
|
270
|
-
]) headers.delete(name);
|
|
271
|
-
request = new Request(target, {
|
|
272
|
-
headers,
|
|
273
|
-
method: "GET",
|
|
274
|
-
redirect: request.redirect,
|
|
275
|
-
signal
|
|
276
|
-
});
|
|
277
|
-
} else request = new Request(new Request(target, request), { headers });
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
function randomId(bytes = 16) {
|
|
282
|
-
const values = crypto.getRandomValues(new Uint8Array(bytes));
|
|
283
|
-
return btoa(String.fromCharCode(...values)).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
|
|
284
|
-
}
|
|
285
|
-
function text(value) {
|
|
286
|
-
return typeof value === "string" && value.trim() ? value.trim() : void 0;
|
|
287
|
-
}
|
|
288
|
-
/** The claims of a JWT, without checking its signature. The token came straight from the token endpoint. */
|
|
289
|
-
function jwtClaims(token) {
|
|
290
|
-
const payload = token?.split(".")[1];
|
|
291
|
-
if (!payload) return void 0;
|
|
292
|
-
try {
|
|
293
|
-
const binary = atob(payload.replaceAll("-", "+").replaceAll("_", "/"));
|
|
294
|
-
const claims = JSON.parse(new TextDecoder().decode(Uint8Array.from(binary, (character) => character.charCodeAt(0))));
|
|
295
|
-
return isRecord(claims) ? claims : void 0;
|
|
296
|
-
} catch {
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
function identityFrom(claims) {
|
|
301
|
-
if (!claims) return void 0;
|
|
302
|
-
const identity = {};
|
|
303
|
-
const subject = text(claims.sub);
|
|
304
|
-
const name = text(claims.name) ?? text(claims.preferred_username);
|
|
305
|
-
const email = text(claims.email);
|
|
306
|
-
const picture = text(claims.picture);
|
|
307
|
-
if (subject) identity.subject = subject;
|
|
308
|
-
if (name) identity.name = name;
|
|
309
|
-
if (email) identity.email = email;
|
|
310
|
-
if (picture?.startsWith("https://")) identity.picture = picture;
|
|
311
|
-
return Object.keys(identity).length ? identity : void 0;
|
|
312
|
-
}
|
|
313
|
-
/** Who the grant belongs to: the ID token, then the userinfo endpoint, then the access token. */
|
|
314
|
-
async function readIdentity(connection) {
|
|
315
|
-
const tokens = connection.oauth?.tokens;
|
|
316
|
-
if (!tokens) return void 0;
|
|
317
|
-
const fromIdToken = identityFrom(jwtClaims(tokens.id_token));
|
|
318
|
-
if (fromIdToken?.name || fromIdToken?.email) return fromIdToken;
|
|
319
|
-
const userinfo = text(connection.oauth?.discovery?.authorizationServerMetadata?.userinfo_endpoint);
|
|
320
|
-
if (userinfo) try {
|
|
321
|
-
const response = await withTimeout(requestTimeoutMs, connection.consoleOrigin)(userinfo, { headers: {
|
|
322
|
-
accept: "application/json",
|
|
323
|
-
authorization: `Bearer ${tokens.access_token}`
|
|
324
|
-
} });
|
|
325
|
-
const claims = response.ok ? await response.json() : void 0;
|
|
326
|
-
const identity = identityFrom(isRecord(claims) ? claims : void 0);
|
|
327
|
-
if (identity) return {
|
|
328
|
-
...fromIdToken,
|
|
329
|
-
...identity
|
|
330
|
-
};
|
|
331
|
-
} catch {}
|
|
332
|
-
return fromIdToken ?? identityFrom(jwtClaims(tokens.access_token));
|
|
333
|
-
}
|
|
334
|
-
function clientKey(connection) {
|
|
335
|
-
const oauth = connection.oauth;
|
|
336
|
-
return `${oauth.discovery?.authorizationServerUrl ?? new URL(connection.url).origin}\n${oauth.redirectUrl}\n${connection.url}`;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* The OAuth client of one connection for the MCP SDK. Everything it saves stays on the server: the registration, the
|
|
340
|
-
* PKCE verifier, the discovery result, and the tokens. The operation saves the connection when it ends.
|
|
341
|
-
* `redirectToAuthorization()` only records the URL; the Console page opens it.
|
|
342
|
-
*/
|
|
343
|
-
function oauthProvider(connection, onAuthorize) {
|
|
344
|
-
const oauth = connection.oauth;
|
|
345
|
-
const pending = () => oauth.pending ??= {
|
|
346
|
-
expiresAt: Date.now() + pendingLifetimeMs,
|
|
347
|
-
state: randomId()
|
|
348
|
-
};
|
|
349
|
-
const metadata = {
|
|
350
|
-
client_name: "ViteHub Console",
|
|
351
|
-
client_uri: "https://vitehub.dev/docs/console/mcp-client",
|
|
352
|
-
grant_types: ["authorization_code", "refresh_token"],
|
|
353
|
-
redirect_uris: [oauth.redirectUrl],
|
|
354
|
-
response_types: ["code"],
|
|
355
|
-
token_endpoint_auth_method: "none"
|
|
356
|
-
};
|
|
357
|
-
return {
|
|
358
|
-
get clientMetadata() {
|
|
359
|
-
return metadata;
|
|
360
|
-
},
|
|
361
|
-
get redirectUrl() {
|
|
362
|
-
return oauth.redirectUrl;
|
|
363
|
-
},
|
|
364
|
-
clientInformation: async () => oauth.client ??= await (await consoleMcpRecords()).client(clientKey(connection)),
|
|
365
|
-
codeVerifier: () => {
|
|
366
|
-
const verifier = oauth.pending?.verifier;
|
|
367
|
-
if (!verifier) throw consoleRequestError(409, "This sign-in has no PKCE verifier. Start it again.", "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
368
|
-
return verifier;
|
|
369
|
-
},
|
|
370
|
-
discoveryState: () => {
|
|
371
|
-
onAuthorize?.();
|
|
372
|
-
return oauth.discovery;
|
|
373
|
-
},
|
|
374
|
-
invalidateCredentials: async (credentials) => {
|
|
375
|
-
if (credentials === "all" || credentials === "client") {
|
|
376
|
-
const records = await consoleMcpRecords();
|
|
377
|
-
const registered = await records.client(clientKey(connection));
|
|
378
|
-
if (registered?.client_id === oauth.client?.client_id && registered?.client_secret === oauth.client?.client_secret) await records.removeClient(clientKey(connection));
|
|
379
|
-
delete oauth.client;
|
|
380
|
-
}
|
|
381
|
-
if (credentials === "all" || credentials === "tokens") oauth.tokens = void 0;
|
|
382
|
-
if (credentials === "all" || credentials === "verifier") delete pending().verifier;
|
|
383
|
-
if (credentials === "all" || credentials === "discovery") oauth.discovery = void 0;
|
|
384
|
-
},
|
|
385
|
-
redirectToAuthorization: (url) => {
|
|
386
|
-
const validated = serverUrl(url.href, connection.consoleOrigin);
|
|
387
|
-
const current = pending();
|
|
388
|
-
if (current.prompt) validated.searchParams.set("prompt", [current.prompt, ...validated.searchParams.get("prompt")?.split(" ") ?? []].filter((value, index, all) => all.indexOf(value) === index).join(" "));
|
|
389
|
-
current.url = validated.href;
|
|
390
|
-
},
|
|
391
|
-
saveClientInformation: async (information) => {
|
|
392
|
-
oauth.client = information;
|
|
393
|
-
await (await consoleMcpRecords()).saveClient(clientKey(connection), information);
|
|
394
|
-
},
|
|
395
|
-
saveCodeVerifier: (verifier) => {
|
|
396
|
-
pending().verifier = verifier;
|
|
397
|
-
},
|
|
398
|
-
saveDiscoveryState: (state) => {
|
|
399
|
-
oauth.discovery = state;
|
|
400
|
-
},
|
|
401
|
-
saveTokens: (tokens) => {
|
|
402
|
-
oauth.tokens = tokens;
|
|
403
|
-
oauth.receivedAt = Date.now();
|
|
404
|
-
},
|
|
405
|
-
state: () => pending().state,
|
|
406
|
-
tokens: () => oauth.tokens
|
|
407
|
-
};
|
|
408
|
-
}
|
|
409
|
-
function serverInfo(client, protocolVersion) {
|
|
410
|
-
const version = client.getServerVersion();
|
|
411
|
-
if (!version) return void 0;
|
|
412
|
-
const capabilities = client.getServerCapabilities() ?? {};
|
|
413
|
-
const details = version;
|
|
414
|
-
const icon = (Array.isArray(details.icons) ? details.icons : []).map((entry) => isRecord(entry) ? text(entry.src) : void 0).find((source) => source?.startsWith("https://") || source?.startsWith("http://") || source?.startsWith("data:image/"));
|
|
415
|
-
const info = {
|
|
416
|
-
capabilities: {
|
|
417
|
-
completions: Boolean(capabilities.completions),
|
|
418
|
-
logging: Boolean(capabilities.logging),
|
|
419
|
-
prompts: Boolean(capabilities.prompts),
|
|
420
|
-
resources: Boolean(capabilities.resources),
|
|
421
|
-
tools: Boolean(capabilities.tools)
|
|
422
|
-
},
|
|
423
|
-
name: version.name
|
|
424
|
-
};
|
|
425
|
-
const optional = {
|
|
426
|
-
description: text(details.description),
|
|
427
|
-
icon,
|
|
428
|
-
instructions: text(client.getInstructions()),
|
|
429
|
-
protocolVersion,
|
|
430
|
-
title: text(version.title),
|
|
431
|
-
version: text(version.version),
|
|
432
|
-
websiteUrl: text(details.websiteUrl)
|
|
433
|
-
};
|
|
434
|
-
for (const [key, value] of Object.entries(optional)) if (value) Object.assign(info, { [key]: value });
|
|
435
|
-
return info;
|
|
436
|
-
}
|
|
437
|
-
/** `CONSOLE_MCP_SIGNED_OUT`, with the `401` challenge that a new sign-in starts from. */
|
|
438
|
-
function signedOutError(message, challenge) {
|
|
439
|
-
return Object.assign(consoleRequestError(409, message, "CONSOLE_MCP_SIGNED_OUT"), { challenge });
|
|
440
|
-
}
|
|
441
|
-
function isSignedOut(error) {
|
|
442
|
-
return error instanceof Error && Reflect.get(error, "code") === "CONSOLE_MCP_SIGNED_OUT";
|
|
443
|
-
}
|
|
444
|
-
function connectionKey(owner, id) {
|
|
445
|
-
return JSON.stringify([owner, id]);
|
|
446
|
-
}
|
|
447
|
-
function runtimeOf(key) {
|
|
448
|
-
let runtime = connectionRuntimes.get(key);
|
|
449
|
-
if (!runtime) connectionRuntimes.set(key, runtime = {});
|
|
450
|
-
return runtime;
|
|
451
|
-
}
|
|
452
|
-
function releaseRuntime(key, runtime) {
|
|
453
|
-
if (!runtime.closing && !runtime.operation && !runtime.clientOperation && connectionRuntimes.get(key) === runtime) connectionRuntimes.delete(key);
|
|
454
|
-
}
|
|
455
|
-
function assertOpen(runtime) {
|
|
456
|
-
if (runtime?.closing) throw consoleRequestError(404, "This MCP connection was disconnected.");
|
|
457
|
-
}
|
|
458
|
-
/** Serialize grant and session work, including callbacks and work left running after a browser abort. */
|
|
459
|
-
function withClientOperation(connection, run) {
|
|
460
|
-
const key = connectionKey(connection.owner, connection.id);
|
|
461
|
-
const runtime = runtimeOf(key);
|
|
462
|
-
const operation = (runtime.clientOperation ?? Promise.resolve()).then(async () => {
|
|
463
|
-
assertOpen(runtime);
|
|
464
|
-
runtime.connection = connection;
|
|
465
|
-
const value = await run();
|
|
466
|
-
assertOpen(runtime);
|
|
467
|
-
return value;
|
|
468
|
-
});
|
|
469
|
-
const settled = operation.then(() => {}, () => {});
|
|
470
|
-
runtime.clientOperation = settled;
|
|
471
|
-
settled.then(() => {
|
|
472
|
-
if (runtime.clientOperation === settled) delete runtime.clientOperation;
|
|
473
|
-
releaseRuntime(key, runtime);
|
|
474
|
-
});
|
|
475
|
-
return operation;
|
|
476
|
-
}
|
|
477
|
-
function withClient(caller, connection, run, options = {}) {
|
|
478
|
-
return withClientOperation(connection, () => runClient(caller, connection, run, options));
|
|
479
|
-
}
|
|
480
|
-
/**
|
|
481
|
-
* Run `run` with an MCP client of the connection. The client reuses the MCP session of the connection when the server
|
|
482
|
-
* gave one, and starts a new session when the server forgot it. A grant that the server rejects marks the connection
|
|
483
|
-
* signed out.
|
|
484
|
-
*/
|
|
485
|
-
async function runClient(caller, connection, run, options) {
|
|
486
|
-
let authorizing = false;
|
|
487
|
-
let challenge;
|
|
488
|
-
const fetchWithTimeout = withTimeout(options.timeoutMs ?? requestTimeoutMs, connection.consoleOrigin);
|
|
489
|
-
const headers = connection.bearer ? { authorization: `Bearer ${connection.bearer}` } : {};
|
|
490
|
-
const attempt = async (sessionId) => {
|
|
491
|
-
const transport = new StreamableHTTPClientTransport(new URL(connection.url), {
|
|
492
|
-
...connection.auth === "oauth" ? { authProvider: oauthProvider(connection, () => {
|
|
493
|
-
authorizing = true;
|
|
494
|
-
}) } : {},
|
|
495
|
-
...Object.keys(headers).length ? { requestInit: { headers } } : {},
|
|
496
|
-
fetch: async (input, init) => {
|
|
497
|
-
const response = await fetchWithTimeout(input, connection.auth === "console" ? {
|
|
498
|
-
...init,
|
|
499
|
-
redirect: "error"
|
|
500
|
-
} : init);
|
|
501
|
-
if (response.status === 401) challenge = extractWWWAuthenticateParams(response);
|
|
502
|
-
return response;
|
|
503
|
-
},
|
|
504
|
-
...sessionId ? { sessionId } : {}
|
|
505
|
-
});
|
|
506
|
-
if (sessionId && connection.protocolVersion) transport.setProtocolVersion(connection.protocolVersion);
|
|
507
|
-
const client = new Client(clientInfo, {
|
|
508
|
-
capabilities: {},
|
|
509
|
-
jsonSchemaValidator: { getValidator: () => (input) => ({
|
|
510
|
-
data: input,
|
|
511
|
-
errorMessage: void 0,
|
|
512
|
-
valid: true
|
|
513
|
-
}) }
|
|
514
|
-
});
|
|
515
|
-
try {
|
|
516
|
-
await client.connect(transport, { timeout: requestTimeoutMs });
|
|
517
|
-
if (!sessionId) {
|
|
518
|
-
connection.protocolVersion = transport.protocolVersion;
|
|
519
|
-
connection.server = serverInfo(client, transport.protocolVersion) ?? connection.server;
|
|
520
|
-
}
|
|
521
|
-
connection.sessionId = transport.sessionId;
|
|
522
|
-
const value = await run(client);
|
|
523
|
-
connection.status = "connected";
|
|
524
|
-
delete connection.error;
|
|
525
|
-
connection.usedAt = Date.now();
|
|
526
|
-
return value;
|
|
527
|
-
} finally {
|
|
528
|
-
await transport.close().catch(() => {});
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
try {
|
|
532
|
-
const sessionId = options.fresh ? void 0 : connection.sessionId;
|
|
533
|
-
try {
|
|
534
|
-
return await attempt(sessionId);
|
|
535
|
-
} catch (error) {
|
|
536
|
-
if (!sessionId || !(error instanceof StreamableHTTPError) || error.code !== 404) throw error;
|
|
537
|
-
delete connection.sessionId;
|
|
538
|
-
return await attempt(void 0);
|
|
539
|
-
}
|
|
540
|
-
} catch (error) {
|
|
541
|
-
if (error instanceof UnauthorizedError || error instanceof StreamableHTTPError && error.code === 401) {
|
|
542
|
-
if (connection.oauth?.pending) delete connection.oauth.pending;
|
|
543
|
-
connection.status = "signed-out";
|
|
544
|
-
connection.error = {
|
|
545
|
-
bearer: "The server rejected this token.",
|
|
546
|
-
console: "ViteHub MCP did not accept your Console session.",
|
|
547
|
-
none: "The server asks for credentials.",
|
|
548
|
-
oauth: "The server rejected the grant. Sign in again."
|
|
549
|
-
}[connection.auth];
|
|
550
|
-
delete connection.sessionId;
|
|
551
|
-
throw signedOutError(connection.error, challenge);
|
|
552
|
-
}
|
|
553
|
-
if (error instanceof McpError) throw error;
|
|
554
|
-
connection.status = "failed";
|
|
555
|
-
if (authorizing) {
|
|
556
|
-
if (connection.oauth?.pending && !connection.oauth.pending.url) delete connection.oauth.pending;
|
|
557
|
-
connection.error = `OAuth sign-in could not start: ${failureMessage(error)}`;
|
|
558
|
-
throw consoleRequestError(502, connection.error, "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
559
|
-
}
|
|
560
|
-
connection.error = failureMessage(error);
|
|
561
|
-
throw consoleRequestError(502, connection.error, "CONSOLE_MCP_UNREACHABLE");
|
|
562
|
-
}
|
|
563
|
-
}
|
|
564
|
-
function failureMessage(error) {
|
|
565
|
-
if (error instanceof StreamableHTTPError) return error.code === 404 ? "The URL does not serve MCP. Check the endpoint path, such as /mcp." : `The server answered HTTP ${error.code ?? "error"}.`;
|
|
566
|
-
if (error instanceof Error && (error.name === "TimeoutError" || error.name === "AbortError")) return "The server did not answer in time.";
|
|
567
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
568
|
-
if (/fetch failed|ECONNREFUSED|ENOTFOUND|EAI_AGAIN/i.test(message)) return "The server cannot be reached.";
|
|
569
|
-
return message.slice(0, 300) || "The MCP handshake failed.";
|
|
570
|
-
}
|
|
571
|
-
function describe(connection) {
|
|
572
|
-
const tokens = connection.oauth?.tokens;
|
|
573
|
-
const described = {
|
|
574
|
-
auth: connection.auth,
|
|
575
|
-
createdAt: new Date(connection.createdAt).toISOString(),
|
|
576
|
-
id: connection.id,
|
|
577
|
-
label: connection.label,
|
|
578
|
-
sameOrigin: connection.sameOrigin,
|
|
579
|
-
status: connection.status,
|
|
580
|
-
url: connection.url
|
|
581
|
-
};
|
|
582
|
-
if (connection.error) described.error = connection.error;
|
|
583
|
-
if (connection.identity) described.identity = connection.identity;
|
|
584
|
-
if (connection.server) described.server = connection.server;
|
|
585
|
-
if (connection.sessionId) described.session = connection.sessionId.slice(-8);
|
|
586
|
-
if (connection.usedAt) described.usedAt = new Date(connection.usedAt).toISOString();
|
|
587
|
-
if (connection.bearer) described.grant = {
|
|
588
|
-
hint: connection.bearer.slice(-4),
|
|
589
|
-
refreshable: false,
|
|
590
|
-
scopes: []
|
|
591
|
-
};
|
|
592
|
-
if (tokens) {
|
|
593
|
-
const issuer = text(connection.oauth?.discovery?.authorizationServerMetadata?.issuer) ?? text(connection.oauth?.discovery?.authorizationServerUrl);
|
|
594
|
-
described.grant = {
|
|
595
|
-
...tokens.expires_in && connection.oauth?.receivedAt ? { expiresAt: new Date(connection.oauth.receivedAt + tokens.expires_in * 1e3).toISOString() } : {},
|
|
596
|
-
...issuer ? { issuer } : {},
|
|
597
|
-
refreshable: Boolean(tokens.refresh_token),
|
|
598
|
-
scopes: tokens.scope?.split(" ").filter(Boolean) ?? []
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
return described;
|
|
602
|
-
}
|
|
603
|
-
/** End a sign-in that did not finish in time. Returns whether the connection changed. */
|
|
604
|
-
function prune(connection, now = Date.now()) {
|
|
605
|
-
const pending = connection.oauth?.pending;
|
|
606
|
-
if (!pending || pending.expiresAt > now) return false;
|
|
607
|
-
delete connection.oauth.pending;
|
|
608
|
-
if (connection.status === "authorizing") {
|
|
609
|
-
connection.status = connection.oauth?.tokens ? "signed-out" : "failed";
|
|
610
|
-
connection.error = "The sign-in did not finish in time. Start it again.";
|
|
611
|
-
}
|
|
612
|
-
return true;
|
|
613
|
-
}
|
|
614
|
-
async function save(connection) {
|
|
615
|
-
const records = await consoleMcpRecords();
|
|
616
|
-
if (!connectionRuntimes.get(connectionKey(connection.owner, connection.id))?.closing) await records.save(connection);
|
|
617
|
-
}
|
|
618
|
-
/** The connections of one person, oldest first. */
|
|
619
|
-
async function owned(owner) {
|
|
620
|
-
const connections = await (await consoleMcpRecords()).connections(owner);
|
|
621
|
-
await Promise.all(connections.filter((connection) => prune(connection)).map(save));
|
|
622
|
-
return connections.sort((left, right) => left.createdAt - right.createdAt);
|
|
623
|
-
}
|
|
624
|
-
async function connectionOf(caller, id) {
|
|
625
|
-
const records = await consoleMcpRecords();
|
|
626
|
-
const connection = await records.connection(await ownerOf(caller), id);
|
|
627
|
-
if (!connection) throw consoleRequestError(404, records.durable ? "This MCP connection does not exist. It was disconnected." : "This MCP connection does not exist. It ends when the server restarts.");
|
|
628
|
-
assertOpen(connectionRuntimes.get(connectionKey(connection.owner, connection.id)));
|
|
629
|
-
if (prune(connection)) await save(connection);
|
|
630
|
-
return connection;
|
|
631
|
-
}
|
|
632
|
-
/** Serialize this process's load/change/save operations so a waiting request reads any rotated tokens. */
|
|
633
|
-
async function withConnection(caller, id, change) {
|
|
634
|
-
const key = connectionKey(await ownerOf(caller), id);
|
|
635
|
-
const runtime = runtimeOf(key);
|
|
636
|
-
const operation = (runtime.operation ?? Promise.resolve()).then(async () => {
|
|
637
|
-
assertOpen(runtime);
|
|
638
|
-
const connection = await connectionOf(caller, id);
|
|
639
|
-
runtime.connection = connection;
|
|
640
|
-
try {
|
|
641
|
-
const value = await change(connection);
|
|
642
|
-
assertOpen(runtime);
|
|
643
|
-
return value;
|
|
644
|
-
} finally {
|
|
645
|
-
await save(connection);
|
|
646
|
-
}
|
|
647
|
-
});
|
|
648
|
-
const settled = operation.then(() => {}, () => {});
|
|
649
|
-
runtime.operation = settled;
|
|
650
|
-
settled.then(() => {
|
|
651
|
-
if (runtime.operation === settled) delete runtime.operation;
|
|
652
|
-
releaseRuntime(key, runtime);
|
|
653
|
-
});
|
|
654
|
-
return operation;
|
|
655
|
-
}
|
|
656
|
-
/** MCP servers that the app announces on its own origin, from RFC 9728 protected resource metadata. */
|
|
657
|
-
async function discoverAppServers(origin) {
|
|
658
|
-
const cached = discovered.get(origin);
|
|
659
|
-
if (cached && Date.now() - cached.at < discoveryLifetimeMs) return cached.servers;
|
|
660
|
-
const servers = [];
|
|
661
|
-
try {
|
|
662
|
-
const response = await withTimeout(5e3, origin)(`${origin}/.well-known/oauth-protected-resource`, { headers: { accept: "application/json" } });
|
|
663
|
-
const metadata = response.ok ? await response.json() : void 0;
|
|
664
|
-
if (isRecord(metadata)) {
|
|
665
|
-
const resource = text(metadata.resource);
|
|
666
|
-
const url = resource && URL.canParse(resource) ? new URL(resource) : void 0;
|
|
667
|
-
if (url && url.origin === origin) {
|
|
668
|
-
const authorizationServer = text((Array.isArray(metadata.authorization_servers) ? metadata.authorization_servers : [])[0]);
|
|
669
|
-
servers.push({
|
|
670
|
-
label: text(metadata.resource_name) ?? "This app",
|
|
671
|
-
url: url.href,
|
|
672
|
-
...authorizationServer ? { authorizationServer } : {}
|
|
673
|
-
});
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
} catch {}
|
|
677
|
-
discovered.set(origin, {
|
|
678
|
-
at: Date.now(),
|
|
679
|
-
servers
|
|
680
|
-
});
|
|
681
|
-
return servers;
|
|
682
|
-
}
|
|
683
|
-
async function listConsoleMcp(caller, options) {
|
|
684
|
-
const owner = await ownerOf(caller);
|
|
685
|
-
const { origin } = consolePage(caller);
|
|
686
|
-
return {
|
|
687
|
-
connections: (await owned(owner)).map(describe),
|
|
688
|
-
servers: await discoverAppServers(origin),
|
|
689
|
-
sharedSession: options.sharedSession
|
|
690
|
-
};
|
|
691
|
-
}
|
|
692
|
-
/**
|
|
693
|
-
* The scope of a sign-in: the one that the server asked for, else the one in its resource metadata, as the MCP SDK
|
|
694
|
-
* picks it. When the authorization server offers `offline_access`, the Console adds it (SEP-2207), so the server can
|
|
695
|
-
* issue a refresh token.
|
|
696
|
-
*/
|
|
697
|
-
function signInScope(discovery, requested) {
|
|
698
|
-
const scope = requested || discovery.resourceMetadata?.scopes_supported?.join(" ");
|
|
699
|
-
if (scope?.split(" ").includes("offline_access") || !discovery.authorizationServerMetadata?.scopes_supported?.includes("offline_access")) return scope;
|
|
700
|
-
return scope ? `${scope} offline_access` : "offline_access";
|
|
701
|
-
}
|
|
702
|
-
/**
|
|
703
|
-
* Start the authorization code flow of an OAuth connection. Returns the URL that the browser opens. `challenge` is the
|
|
704
|
-
* `WWW-Authenticate` of the `401` that asked for the sign-in.
|
|
705
|
-
*/
|
|
706
|
-
async function startAuthorization(connection, prompt, challenge) {
|
|
707
|
-
return withClientOperation(connection, () => authorize(connection, prompt, challenge));
|
|
708
|
-
}
|
|
709
|
-
async function authorize(connection, prompt, challenge) {
|
|
710
|
-
const oauth = connection.oauth;
|
|
711
|
-
oauth.pending = {
|
|
712
|
-
expiresAt: Date.now() + pendingLifetimeMs,
|
|
713
|
-
state: randomId(),
|
|
714
|
-
...prompt ? { prompt } : {}
|
|
715
|
-
};
|
|
716
|
-
oauth.tokens = void 0;
|
|
717
|
-
delete connection.sessionId;
|
|
718
|
-
const fetchFn = withTimeout(requestTimeoutMs, connection.consoleOrigin);
|
|
719
|
-
try {
|
|
720
|
-
const known = oauth.discovery?.resourceMetadataUrl;
|
|
721
|
-
const resourceMetadataUrl = challenge?.resourceMetadataUrl ?? (known ? new URL(known) : void 0);
|
|
722
|
-
oauth.discovery = {
|
|
723
|
-
...await discoverOAuthServerInfo(connection.url, {
|
|
724
|
-
fetchFn,
|
|
725
|
-
...resourceMetadataUrl ? { resourceMetadataUrl } : {}
|
|
726
|
-
}),
|
|
727
|
-
...resourceMetadataUrl ? { resourceMetadataUrl: resourceMetadataUrl.href } : {}
|
|
728
|
-
};
|
|
729
|
-
const scope = signInScope(oauth.discovery, challenge?.scope);
|
|
730
|
-
if (await auth(oauthProvider(connection), {
|
|
731
|
-
fetchFn,
|
|
732
|
-
serverUrl: connection.url,
|
|
733
|
-
...resourceMetadataUrl ? { resourceMetadataUrl } : {},
|
|
734
|
-
...scope ? { scope } : {}
|
|
735
|
-
}) === "REDIRECT" && oauth.pending.url) {
|
|
736
|
-
connection.status = "authorizing";
|
|
737
|
-
delete connection.error;
|
|
738
|
-
return oauth.pending.url;
|
|
739
|
-
}
|
|
740
|
-
throw consoleDiagnostic("CONSOLE_MCP_AUTHORIZATION_FAILED", "The authorization server did not start a sign-in.");
|
|
741
|
-
} catch (error) {
|
|
742
|
-
delete oauth.pending;
|
|
743
|
-
connection.status = "failed";
|
|
744
|
-
connection.error = `OAuth sign-in could not start: ${failureMessage(error)}`;
|
|
745
|
-
throw consoleRequestError(502, connection.error, "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* Connect to an MCP server. A pasted `token` is sent as a bearer token. Without one, the Console first connects
|
|
750
|
-
* without credentials; a server that answers `401` starts the MCP authorization flow, and the result names the URL
|
|
751
|
-
* to open. `prompt: "login"` asks the authorization server to show its sign-in even when someone is signed in.
|
|
752
|
-
*/
|
|
753
|
-
async function connectConsoleMcp(caller, input) {
|
|
754
|
-
const owner = await ownerOf(caller);
|
|
755
|
-
const { mount, origin } = consolePage(caller);
|
|
756
|
-
const url = serverUrl(input.server, origin);
|
|
757
|
-
const token = text(input.token);
|
|
758
|
-
if ((await owned(owner)).length >= maximumConnections) throw consoleRequestError(409, `The Console keeps ${maximumConnections} MCP connections per person. Disconnect one first.`);
|
|
759
|
-
const connection = {
|
|
760
|
-
auth: token ? "bearer" : "none",
|
|
761
|
-
...token ? { bearer: token } : {},
|
|
762
|
-
consoleOrigin: origin,
|
|
763
|
-
createdAt: Date.now(),
|
|
764
|
-
id: `mcp_${randomId(12)}`,
|
|
765
|
-
label: text(input.label)?.slice(0, 80) ?? url.host + (url.pathname === "/" ? "" : url.pathname),
|
|
766
|
-
labelled: Boolean(text(input.label)),
|
|
767
|
-
owner,
|
|
768
|
-
sameOrigin: url.origin === origin,
|
|
769
|
-
status: "failed",
|
|
770
|
-
url: url.href
|
|
771
|
-
};
|
|
772
|
-
try {
|
|
773
|
-
await withClient(caller, connection, async () => {}, { fresh: true });
|
|
774
|
-
await save(connection);
|
|
775
|
-
return { connection: describe(connection) };
|
|
776
|
-
} catch (error) {
|
|
777
|
-
if (!isSignedOut(error) || connection.auth !== "none") throw error;
|
|
778
|
-
connection.auth = "oauth";
|
|
779
|
-
connection.oauth = { redirectUrl: `${origin}${mount}${consoleMcpCallbackPath}` };
|
|
780
|
-
try {
|
|
781
|
-
return {
|
|
782
|
-
authorizationUrl: await startAuthorization(connection, input.prompt, error.challenge),
|
|
783
|
-
connection: describe(connection)
|
|
784
|
-
};
|
|
785
|
-
} finally {
|
|
786
|
-
await save(connection);
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
/** Finish the sign-in that the authorization server redirected back from. */
|
|
791
|
-
async function completeConsoleMcp(caller, input) {
|
|
792
|
-
const connection = (await owned(await ownerOf(caller))).find((candidate) => candidate.oauth?.pending?.state === input.state);
|
|
793
|
-
if (!connection?.oauth?.pending || completingAuthorizations.has(input.state)) throw consoleRequestError(404, "This sign-in is not known. It expired, finished already, or was started by someone else. Start it again.", "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
794
|
-
completingAuthorizations.add(input.state);
|
|
795
|
-
try {
|
|
796
|
-
return await withConnection(caller, connection.id, async (current) => {
|
|
797
|
-
if (current.oauth?.pending?.state !== input.state) throw consoleRequestError(404, "This sign-in is not known. Start it again.", "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
798
|
-
return finishSignIn(caller, current, input);
|
|
799
|
-
});
|
|
800
|
-
} finally {
|
|
801
|
-
completingAuthorizations.delete(input.state);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
async function finishSignIn(caller, connection, input) {
|
|
805
|
-
const oauth = connection.oauth;
|
|
806
|
-
const pending = oauth.pending;
|
|
807
|
-
if (input.error || !input.code) {
|
|
808
|
-
delete oauth.pending;
|
|
809
|
-
connection.status = oauth.tokens ? "signed-out" : "failed";
|
|
810
|
-
connection.error = input.error === "access_denied" ? "The sign-in was denied." : `The authorization server returned ${text(input.error) ?? "no code"}${input.errorDescription ? `: ${input.errorDescription.slice(0, 200)}` : "."}`;
|
|
811
|
-
throw consoleRequestError(400, connection.error, "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
812
|
-
}
|
|
813
|
-
const metadata = { ...oauth.discovery?.authorizationServerMetadata };
|
|
814
|
-
const missingIssuer = metadata?.authorization_response_iss_parameter_supported === true && !input.iss;
|
|
815
|
-
if (missingIssuer || input.iss !== void 0 && input.iss !== metadata?.issuer) {
|
|
816
|
-
delete oauth.pending;
|
|
817
|
-
connection.status = "failed";
|
|
818
|
-
connection.error = missingIssuer ? "The authorization server did not return its issuer." : "The sign-in came back from another authorization server.";
|
|
819
|
-
throw consoleRequestError(400, connection.error, "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
820
|
-
}
|
|
821
|
-
return withClientOperation(connection, async () => {
|
|
822
|
-
try {
|
|
823
|
-
if (await auth(oauthProvider(connection), {
|
|
824
|
-
authorizationCode: input.code,
|
|
825
|
-
fetchFn: withTimeout(requestTimeoutMs, connection.consoleOrigin),
|
|
826
|
-
serverUrl: connection.url
|
|
827
|
-
}) !== "AUTHORIZED") throw consoleDiagnostic("CONSOLE_MCP_AUTHORIZATION_FAILED", "The authorization server did not issue a token.");
|
|
828
|
-
} catch (error) {
|
|
829
|
-
delete oauth.pending;
|
|
830
|
-
connection.status = "failed";
|
|
831
|
-
connection.error = `The token exchange failed: ${failureMessage(error)}`;
|
|
832
|
-
throw consoleRequestError(502, connection.error, "CONSOLE_MCP_AUTHORIZATION_FAILED");
|
|
833
|
-
}
|
|
834
|
-
if (pending === oauth.pending) delete oauth.pending;
|
|
835
|
-
connection.identity = await readIdentity(connection);
|
|
836
|
-
if (!connection.labelled) connection.label = connection.identity?.name ?? connection.identity?.email ?? connection.label;
|
|
837
|
-
await runClient(caller, connection, async () => {}, { fresh: true });
|
|
838
|
-
return describe(connection);
|
|
839
|
-
});
|
|
840
|
-
}
|
|
841
|
-
/** Sign in again, or open a new MCP session. OAuth connections return the URL to open. */
|
|
842
|
-
async function reconnectConsoleMcp(caller, input) {
|
|
843
|
-
return withConnection(caller, input.id, async (connection) => {
|
|
844
|
-
if (connection.auth === "oauth" && (input.prompt || connection.status === "signed-out" || connection.status === "authorizing" || !connection.oauth?.tokens)) return {
|
|
845
|
-
authorizationUrl: await startAuthorization(connection, input.prompt),
|
|
846
|
-
connection: describe(connection)
|
|
847
|
-
};
|
|
848
|
-
try {
|
|
849
|
-
await withClient(caller, connection, async () => {}, { fresh: true });
|
|
850
|
-
} catch (error) {
|
|
851
|
-
if (!isSignedOut(error) || connection.auth !== "oauth") throw error;
|
|
852
|
-
return {
|
|
853
|
-
authorizationUrl: await startAuthorization(connection, input.prompt, error.challenge),
|
|
854
|
-
connection: describe(connection)
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
return { connection: describe(connection) };
|
|
858
|
-
});
|
|
859
|
-
}
|
|
860
|
-
/** RFC 7009: ask the authorization server to forget a token. Returns whether it confirmed. */
|
|
861
|
-
async function revoke(connection) {
|
|
862
|
-
const oauth = connection.oauth;
|
|
863
|
-
const endpoint = text({ ...oauth?.discovery?.authorizationServerMetadata }.revocation_endpoint);
|
|
864
|
-
const client = oauth?.client ?? (oauth ? await (await consoleMcpRecords()).client(clientKey(connection)) : void 0);
|
|
865
|
-
if (!oauth?.tokens || !endpoint || !client) return false;
|
|
866
|
-
const tokens = [[oauth.tokens.refresh_token, "refresh_token"], [oauth.tokens.access_token, "access_token"]];
|
|
867
|
-
let revoked = false;
|
|
868
|
-
for (const [token, hint] of tokens) {
|
|
869
|
-
if (!token) continue;
|
|
870
|
-
const body = new URLSearchParams({
|
|
871
|
-
client_id: client.client_id,
|
|
872
|
-
token,
|
|
873
|
-
token_type_hint: hint
|
|
874
|
-
});
|
|
875
|
-
if (client.client_secret) body.set("client_secret", client.client_secret);
|
|
876
|
-
try {
|
|
877
|
-
const response = await withTimeout(requestTimeoutMs, connection.consoleOrigin)(endpoint, {
|
|
878
|
-
body,
|
|
879
|
-
headers: { "content-type": "application/x-www-form-urlencoded" },
|
|
880
|
-
method: "POST"
|
|
881
|
-
});
|
|
882
|
-
revoked ||= response.ok;
|
|
883
|
-
} catch {}
|
|
884
|
-
}
|
|
885
|
-
return revoked;
|
|
886
|
-
}
|
|
887
|
-
/** End the MCP session, revoke the OAuth tokens, and forget the connection. */
|
|
888
|
-
async function disconnectConsoleMcp(caller, input) {
|
|
889
|
-
let connection = await connectionOf(caller, input.id);
|
|
890
|
-
const key = connectionKey(connection.owner, connection.id);
|
|
891
|
-
const runtime = runtimeOf(key);
|
|
892
|
-
runtime.closing = true;
|
|
893
|
-
const records = await consoleMcpRecords();
|
|
894
|
-
try {
|
|
895
|
-
await records.remove(connection);
|
|
896
|
-
await runtime.operation;
|
|
897
|
-
await runtime.clientOperation;
|
|
898
|
-
connection = runtime.connection ?? connection;
|
|
899
|
-
await records.remove(connection);
|
|
900
|
-
let sessionEnded = false;
|
|
901
|
-
if (connection.sessionId) try {
|
|
902
|
-
const headers = { "mcp-session-id": connection.sessionId };
|
|
903
|
-
const bearer = connection.bearer ?? connection.oauth?.tokens?.access_token;
|
|
904
|
-
if (bearer) headers.authorization = `Bearer ${bearer}`;
|
|
905
|
-
if (connection.protocolVersion) headers["mcp-protocol-version"] = connection.protocolVersion;
|
|
906
|
-
sessionEnded = (await withTimeout(requestTimeoutMs, connection.consoleOrigin)(connection.url, {
|
|
907
|
-
headers,
|
|
908
|
-
method: "DELETE"
|
|
909
|
-
})).ok;
|
|
910
|
-
} catch {}
|
|
911
|
-
return {
|
|
912
|
-
revoked: await revoke(connection),
|
|
913
|
-
sessionEnded
|
|
914
|
-
};
|
|
915
|
-
} finally {
|
|
916
|
-
connectionRuntimes.delete(key);
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
const listMethods = {
|
|
920
|
-
"prompts": {
|
|
921
|
-
field: "prompts",
|
|
922
|
-
method: "prompts/list"
|
|
923
|
-
},
|
|
924
|
-
"resource-templates": {
|
|
925
|
-
field: "resourceTemplates",
|
|
926
|
-
method: "resources/templates/list"
|
|
927
|
-
},
|
|
928
|
-
"resources": {
|
|
929
|
-
field: "resources",
|
|
930
|
-
method: "resources/list"
|
|
931
|
-
},
|
|
932
|
-
"tools": {
|
|
933
|
-
field: "tools",
|
|
934
|
-
method: "tools/list"
|
|
935
|
-
}
|
|
936
|
-
};
|
|
937
|
-
/** One page of tools, resources, resource templates, or prompts. */
|
|
938
|
-
async function listConsoleMcpItems(caller, input) {
|
|
939
|
-
return withConnection(caller, input.id, async (connection) => {
|
|
940
|
-
const { field, method } = listMethods[input.kind];
|
|
941
|
-
try {
|
|
942
|
-
const result = await withClient(caller, connection, (client) => client.request({
|
|
943
|
-
method,
|
|
944
|
-
params: input.cursor ? { cursor: input.cursor } : {}
|
|
945
|
-
}, ResultSchema, { timeout: requestTimeoutMs }));
|
|
946
|
-
const values = Reflect.get(result, field);
|
|
947
|
-
const items = Array.isArray(values) ? values.filter(isRecord) : [];
|
|
948
|
-
const nextCursor = text(Reflect.get(result, "nextCursor"));
|
|
949
|
-
return {
|
|
950
|
-
connection: describe(connection),
|
|
951
|
-
items,
|
|
952
|
-
...nextCursor ? { nextCursor } : {}
|
|
953
|
-
};
|
|
954
|
-
} catch (error) {
|
|
955
|
-
if (error instanceof McpError && error.code === -32601) return {
|
|
956
|
-
connection: describe(connection),
|
|
957
|
-
items: []
|
|
958
|
-
};
|
|
959
|
-
throw error;
|
|
960
|
-
}
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
|
-
/** Send one request and return the result or the JSON-RPC error of the server, with the time it took. */
|
|
964
|
-
async function outcome(caller, id, request, timeoutMs) {
|
|
965
|
-
return withConnection(caller, id, async (connection) => {
|
|
966
|
-
const startedAt = performance.now();
|
|
967
|
-
try {
|
|
968
|
-
const result = await withClient(caller, connection, (client) => client.request(request, ResultSchema, {
|
|
969
|
-
maxTotalTimeout: timeoutMs,
|
|
970
|
-
timeout: timeoutMs
|
|
971
|
-
}), { timeoutMs });
|
|
972
|
-
return {
|
|
973
|
-
connection: describe(connection),
|
|
974
|
-
durationMs: Math.round(performance.now() - startedAt),
|
|
975
|
-
result
|
|
976
|
-
};
|
|
977
|
-
} catch (error) {
|
|
978
|
-
if (!(error instanceof McpError)) throw error;
|
|
979
|
-
connection.status = "connected";
|
|
980
|
-
return {
|
|
981
|
-
connection: describe(connection),
|
|
982
|
-
durationMs: Math.round(performance.now() - startedAt),
|
|
983
|
-
error: {
|
|
984
|
-
code: error.code,
|
|
985
|
-
message: error.message.replace(/^(?:MCP error -?\d+: )+/, ""),
|
|
986
|
-
...error.data === void 0 ? {} : { data: error.data }
|
|
987
|
-
}
|
|
988
|
-
};
|
|
989
|
-
}
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
function callConsoleMcpTool(caller, input) {
|
|
993
|
-
return outcome(caller, input.id, {
|
|
994
|
-
method: "tools/call",
|
|
995
|
-
params: {
|
|
996
|
-
arguments: input.arguments ?? {},
|
|
997
|
-
name: input.tool
|
|
998
|
-
}
|
|
999
|
-
}, callTimeoutMs);
|
|
1000
|
-
}
|
|
1001
|
-
function readConsoleMcpResource(caller, input) {
|
|
1002
|
-
return outcome(caller, input.id, {
|
|
1003
|
-
method: "resources/read",
|
|
1004
|
-
params: { uri: input.uri }
|
|
1005
|
-
}, requestTimeoutMs);
|
|
1006
|
-
}
|
|
1007
|
-
function getConsoleMcpPrompt(caller, input) {
|
|
1008
|
-
return outcome(caller, input.id, {
|
|
1009
|
-
method: "prompts/get",
|
|
1010
|
-
params: {
|
|
1011
|
-
arguments: input.arguments ?? {},
|
|
1012
|
-
name: input.name
|
|
1013
|
-
}
|
|
1014
|
-
}, requestTimeoutMs);
|
|
1015
|
-
}
|
|
1016
|
-
/** Forget every connection of this process. Tests use it. */
|
|
1017
|
-
function resetConsoleMcp() {
|
|
1018
|
-
connectionRuntimes.clear();
|
|
1019
|
-
completingAuthorizations.clear();
|
|
1020
|
-
resetConsoleMcpRecords();
|
|
1021
|
-
discovered.clear();
|
|
1022
|
-
}
|
|
1023
|
-
//#endregion
|
|
1024
|
-
export { callConsoleMcpTool, completeConsoleMcp, connectConsoleMcp, disconnectConsoleMcp, getConsoleMcpPrompt, listConsoleMcp, listConsoleMcpItems, readConsoleMcpResource, reconnectConsoleMcp, resetConsoleMcp };
|