@herbertgao/pi-extensions 2026.9.17 → 2026.9.19
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 +31 -33
- package/THIRD_PARTY_NOTICES.md +1 -1
- package/node_modules/@herbertgao/pi-bark/package.json +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +4 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/working-message.ts +21 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +15 -4
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/diff/index.ts +43 -7
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +7 -2
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/result.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +75 -75
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +6 -0
- package/node_modules/@herbertgao/pi-subagents/package.json +7 -7
- package/node_modules/@herbertgao/resume-from/package.json +4 -2
- package/node_modules/@herbertgao/sol-pi/package.json +6 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +99 -99
- package/node_modules/@pi-plugins/fast-mode/package.json +1 -1
- package/node_modules/@tifan/pi-handoff/package.json +1 -1
- package/node_modules/@tifan/pi-handoff/src/index.ts +56 -26
- package/node_modules/@tifan/pi-mermaid-open/package.json +1 -1
- package/node_modules/@tifan/pi-preferred-thinking/package.json +1 -1
- package/node_modules/@tifan/pi-recap/package.json +1 -1
- package/node_modules/@tifan/pi-rename/package.json +1 -1
- package/node_modules/pi-antigravity/README.md +29 -6
- package/node_modules/pi-antigravity/package.json +14 -9
- package/node_modules/pi-antigravity/src/auth/accounts.ts +327 -0
- package/node_modules/pi-antigravity/src/auth/index.ts +9 -0
- package/node_modules/pi-antigravity/src/client/client.ts +1 -1
- package/node_modules/pi-antigravity/src/image/image.ts +4 -4
- package/node_modules/pi-antigravity/src/index.ts +203 -13
- package/node_modules/pi-antigravity/src/search/index.ts +1 -0
- package/node_modules/pi-antigravity/src/search/search.ts +325 -0
- package/node_modules/pi-antigravity/src/stream/stream.ts +191 -14
- package/node_modules/pi-antigravity/src/types/enums.ts +45 -36
- package/node_modules/pi-antigravity/src/types/types.ts +5 -12
- package/node_modules/pi-antigravity/src/utils/http.ts +7 -2
- package/node_modules/pi-antigravity/src/utils/util.ts +31 -3
- package/node_modules/pi-lens/package.json +158 -158
- package/node_modules/pi-multi-account/package.json +2 -2
- package/node_modules/pi-typesafe/README.md +3 -1
- package/node_modules/pi-typesafe/dist/auth.d.ts +9 -5
- package/node_modules/pi-typesafe/dist/auth.js +7 -3
- package/node_modules/pi-typesafe/dist/backends.d.ts +33 -3
- package/node_modules/pi-typesafe/dist/backends.js +95 -1
- package/node_modules/pi-typesafe/dist/client.d.ts +5 -5
- package/node_modules/pi-typesafe/dist/client.js +12 -9
- package/node_modules/pi-typesafe/dist/credentials.d.ts +14 -8
- package/node_modules/pi-typesafe/dist/credentials.js +10 -7
- package/node_modules/pi-typesafe/dist/errors.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/index.js +1 -1
- package/node_modules/pi-typesafe/dist/login.d.ts +2 -2
- package/node_modules/pi-typesafe/dist/login.js +2 -2
- package/node_modules/pi-typesafe/package.json +6 -5
- package/node_modules/pi-web-access/CHANGELOG.md +72 -0
- package/node_modules/pi-web-access/README.md +34 -13
- package/node_modules/pi-web-access/chrome-cookies.ts +79 -25
- package/node_modules/pi-web-access/curator-page.ts +5 -1
- package/node_modules/pi-web-access/curator-server.ts +2 -0
- package/node_modules/pi-web-access/dist/index.js +1337 -1009
- package/node_modules/pi-web-access/exa.ts +20 -52
- package/node_modules/pi-web-access/extract.ts +41 -4
- package/node_modules/pi-web-access/gemini-search.ts +12 -4
- package/node_modules/pi-web-access/index.ts +29 -37
- package/node_modules/pi-web-access/openai-search.ts +35 -7
- package/node_modules/pi-web-access/package.json +8 -7
- package/node_modules/pi-web-access/page-query.ts +2 -2
- package/node_modules/pi-web-access/query-rewrite.ts +2 -3
- package/node_modules/pi-web-access/ssrf-protection.ts +27 -10
- package/node_modules/pi-web-access/storage.ts +48 -77
- package/node_modules/pi-web-access/summary-model-scope.ts +6 -77
- package/node_modules/pi-web-access/summary-review.ts +3 -4
- package/node_modules/pi-web-access/tavily.ts +67 -20
- package/node_modules/pi-web-access/tool-activation.ts +53 -33
- package/node_modules/pi-web-access/utils.ts +1 -1
- package/node_modules/pi-web-access/you.ts +164 -0
- package/node_modules/pi-web-access/zai.ts +161 -0
- package/node_modules/remote-pi/package.json +5 -1
- package/package.json +19 -31
- package/node_modules/pi-mcp-adapter/CHANGELOG.md +0 -1013
- package/node_modules/pi-mcp-adapter/LICENSE +0 -21
- package/node_modules/pi-mcp-adapter/OAUTH.md +0 -369
- package/node_modules/pi-mcp-adapter/README.md +0 -1021
- package/node_modules/pi-mcp-adapter/abort.ts +0 -34
- package/node_modules/pi-mcp-adapter/agent-dir.ts +0 -68
- package/node_modules/pi-mcp-adapter/agent-plugin-loader.ts +0 -416
- package/node_modules/pi-mcp-adapter/agent-plugin-provenance.ts +0 -36
- package/node_modules/pi-mcp-adapter/app-bridge.bundle.js +0 -67
- package/node_modules/pi-mcp-adapter/banner.png +0 -0
- package/node_modules/pi-mcp-adapter/bearer-command-resolver.ts +0 -193
- package/node_modules/pi-mcp-adapter/claude-plugin-loader.ts +0 -365
- package/node_modules/pi-mcp-adapter/cli.js +0 -454
- package/node_modules/pi-mcp-adapter/commands.ts +0 -861
- package/node_modules/pi-mcp-adapter/config.ts +0 -1565
- package/node_modules/pi-mcp-adapter/consent-manager.ts +0 -95
- package/node_modules/pi-mcp-adapter/direct-tool-surface.ts +0 -244
- package/node_modules/pi-mcp-adapter/direct-tools.ts +0 -428
- package/node_modules/pi-mcp-adapter/dist/abort.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/abort.js +0 -36
- package/node_modules/pi-mcp-adapter/dist/abort.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-dir.d.ts +0 -10
- package/node_modules/pi-mcp-adapter/dist/agent-dir.js +0 -63
- package/node_modules/pi-mcp-adapter/dist/agent-dir.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.d.ts +0 -8
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js +0 -398
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.d.ts +0 -1
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js +0 -31
- package/node_modules/pi-mcp-adapter/dist/agent-plugin-provenance.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js +0 -194
- package/node_modules/pi-mcp-adapter/dist/bearer-command-resolver.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.d.ts +0 -9
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js +0 -362
- package/node_modules/pi-mcp-adapter/dist/claude-plugin-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/config.d.ts +0 -134
- package/node_modules/pi-mcp-adapter/dist/config.js +0 -1361
- package/node_modules/pi-mcp-adapter/dist/config.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/consent-manager.d.ts +0 -18
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js +0 -88
- package/node_modules/pi-mcp-adapter/dist/consent-manager.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js +0 -316
- package/node_modules/pi-mcp-adapter/dist/elicitation-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/errors.d.ts +0 -131
- package/node_modules/pi-mcp-adapter/dist/errors.js +0 -278
- package/node_modules/pi-mcp-adapter/dist/errors.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/http-ca.d.ts +0 -8
- package/node_modules/pi-mcp-adapter/dist/http-ca.js +0 -88
- package/node_modules/pi-mcp-adapter/dist/http-ca.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-client.d.ts +0 -14
- package/node_modules/pi-mcp-adapter/dist/jev-client.js +0 -367
- package/node_modules/pi-mcp-adapter/dist/jev-client.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.d.ts +0 -77
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js +0 -2
- package/node_modules/pi-mcp-adapter/dist/jev-contracts.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.d.ts +0 -51
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js +0 -205
- package/node_modules/pi-mcp-adapter/dist/jev-key-store.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js +0 -68
- package/node_modules/pi-mcp-adapter/dist/json-schema-validator.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/lifecycle.d.ts +0 -56
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js +0 -410
- package/node_modules/pi-mcp-adapter/dist/lifecycle.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/logger.d.ts +0 -51
- package/node_modules/pi-mcp-adapter/dist/logger.js +0 -131
- package/node_modules/pi-mcp-adapter/dist/logger.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.d.ts +0 -26
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js +0 -103
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-fetch.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.d.ts +0 -118
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js +0 -1097
- package/node_modules/pi-mcp-adapter/dist/mcp-auth-flow.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.d.ts +0 -170
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js +0 -1142
- package/node_modules/pi-mcp-adapter/dist/mcp-auth.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.d.ts +0 -24
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js +0 -203
- package/node_modules/pi-mcp-adapter/dist/mcp-bearer-store.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.d.ts +0 -53
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js +0 -441
- package/node_modules/pi-mcp-adapter/dist/mcp-callback-server.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.d.ts +0 -148
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js +0 -689
- package/node_modules/pi-mcp-adapter/dist/mcp-oauth-provider.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js +0 -166
- package/node_modules/pi-mcp-adapter/dist/mcp-probe.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.d.ts +0 -102
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js +0 -369
- package/node_modules/pi-mcp-adapter/dist/mcp-tasks.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.d.ts +0 -95
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js +0 -242
- package/node_modules/pi-mcp-adapter/dist/mcp-trace.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.d.ts +0 -19
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js +0 -301
- package/node_modules/pi-mcp-adapter/dist/metadata-cache.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js +0 -505
- package/node_modules/pi-mcp-adapter/dist/npx-resolver.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.d.ts +0 -2
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js +0 -144
- package/node_modules/pi-mcp-adapter/dist/package-mcp-loader.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.d.ts +0 -10
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js +0 -312
- package/node_modules/pi-mcp-adapter/dist/request-headers-command.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/resource-tools.d.ts +0 -1
- package/node_modules/pi-mcp-adapter/dist/resource-tools.js +0 -15
- package/node_modules/pi-mcp-adapter/dist/resource-tools.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.d.ts +0 -13
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js +0 -97
- package/node_modules/pi-mcp-adapter/dist/runtime-owner.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js +0 -203
- package/node_modules/pi-mcp-adapter/dist/sampling-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.d.ts +0 -11
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js +0 -172
- package/node_modules/pi-mcp-adapter/dist/secure-keyring.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/server-manager.d.ts +0 -157
- package/node_modules/pi-mcp-adapter/dist/server-manager.js +0 -1745
- package/node_modules/pi-mcp-adapter/dist/server-manager.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/session-approvals.d.ts +0 -34
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js +0 -140
- package/node_modules/pi-mcp-adapter/dist/session-approvals.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/session-recovery.d.ts +0 -26
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js +0 -142
- package/node_modules/pi-mcp-adapter/dist/session-recovery.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/state.d.ts +0 -73
- package/node_modules/pi-mcp-adapter/dist/state.js +0 -2
- package/node_modules/pi-mcp-adapter/dist/state.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/types.d.ts +0 -642
- package/node_modules/pi-mcp-adapter/dist/types.js +0 -331
- package/node_modules/pi-mcp-adapter/dist/types.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.d.ts +0 -6
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js +0 -37
- package/node_modules/pi-mcp-adapter/dist/ui-app-bridge-helpers.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.d.ts +0 -17
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js +0 -219
- package/node_modules/pi-mcp-adapter/dist/ui-resource-handler.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.d.ts +0 -104
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js +0 -59
- package/node_modules/pi-mcp-adapter/dist/ui-stream-types.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.d.ts +0 -4
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js +0 -27
- package/node_modules/pi-mcp-adapter/dist/ui-tool-visibility.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.d.ts +0 -15
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js +0 -85
- package/node_modules/pi-mcp-adapter/dist/unix-socket-transport.js.map +0 -1
- package/node_modules/pi-mcp-adapter/dist/utils.d.ts +0 -41
- package/node_modules/pi-mcp-adapter/dist/utils.js +0 -417
- package/node_modules/pi-mcp-adapter/dist/utils.js.map +0 -1
- package/node_modules/pi-mcp-adapter/elicitation-handler.ts +0 -358
- package/node_modules/pi-mcp-adapter/error-signal.ts +0 -32
- package/node_modules/pi-mcp-adapter/errors.ts +0 -364
- package/node_modules/pi-mcp-adapter/examples/jev-accessibility-loop.mjs +0 -85
- package/node_modules/pi-mcp-adapter/examples/jev-semantic-filter.mjs +0 -34
- package/node_modules/pi-mcp-adapter/failure-backoff.ts +0 -23
- package/node_modules/pi-mcp-adapter/glimpse-ui.ts +0 -80
- package/node_modules/pi-mcp-adapter/host-html-template.ts +0 -515
- package/node_modules/pi-mcp-adapter/http-ca.ts +0 -84
- package/node_modules/pi-mcp-adapter/index.ts +0 -2106
- package/node_modules/pi-mcp-adapter/init.ts +0 -721
- package/node_modules/pi-mcp-adapter/jev-client.ts +0 -300
- package/node_modules/pi-mcp-adapter/jev-contracts.ts +0 -53
- package/node_modules/pi-mcp-adapter/jev-key-store.ts +0 -192
- package/node_modules/pi-mcp-adapter/json-schema-validator.ts +0 -83
- package/node_modules/pi-mcp-adapter/lazy-loader.ts +0 -7
- package/node_modules/pi-mcp-adapter/lifecycle.ts +0 -457
- package/node_modules/pi-mcp-adapter/logger.ts +0 -169
- package/node_modules/pi-mcp-adapter/mcp-auth-fetch.ts +0 -113
- package/node_modules/pi-mcp-adapter/mcp-auth-flow.ts +0 -1296
- package/node_modules/pi-mcp-adapter/mcp-auth.ts +0 -1287
- package/node_modules/pi-mcp-adapter/mcp-bearer-store.ts +0 -250
- package/node_modules/pi-mcp-adapter/mcp-callback-server.ts +0 -534
- package/node_modules/pi-mcp-adapter/mcp-code.ts +0 -495
- package/node_modules/pi-mcp-adapter/mcp-install.ts +0 -60
- package/node_modules/pi-mcp-adapter/mcp-keyring-helper.cjs +0 -89
- package/node_modules/pi-mcp-adapter/mcp-oauth-provider.ts +0 -819
- package/node_modules/pi-mcp-adapter/mcp-output-guard.ts +0 -511
- package/node_modules/pi-mcp-adapter/mcp-panel-theme.ts +0 -104
- package/node_modules/pi-mcp-adapter/mcp-panel.ts +0 -1099
- package/node_modules/pi-mcp-adapter/mcp-probe.ts +0 -201
- package/node_modules/pi-mcp-adapter/mcp-references.ts +0 -373
- package/node_modules/pi-mcp-adapter/mcp-script-worker.mjs +0 -137
- package/node_modules/pi-mcp-adapter/mcp-setup-panel.ts +0 -747
- package/node_modules/pi-mcp-adapter/mcp-status.ts +0 -105
- package/node_modules/pi-mcp-adapter/mcp-tasks.ts +0 -467
- package/node_modules/pi-mcp-adapter/mcp-trace.ts +0 -306
- package/node_modules/pi-mcp-adapter/metadata-cache.ts +0 -362
- package/node_modules/pi-mcp-adapter/namespace-tools.ts +0 -334
- package/node_modules/pi-mcp-adapter/npx-resolver.ts +0 -543
- package/node_modules/pi-mcp-adapter/oauth-handler.ts +0 -30
- package/node_modules/pi-mcp-adapter/oauth.ts +0 -52
- package/node_modules/pi-mcp-adapter/onboarding-state.ts +0 -76
- package/node_modules/pi-mcp-adapter/package-mcp-loader.ts +0 -156
- package/node_modules/pi-mcp-adapter/package.json +0 -219
- package/node_modules/pi-mcp-adapter/panel-keys.ts +0 -53
- package/node_modules/pi-mcp-adapter/prompts.ts +0 -385
- package/node_modules/pi-mcp-adapter/proxy-modes.ts +0 -1735
- package/node_modules/pi-mcp-adapter/request-headers-command.ts +0 -333
- package/node_modules/pi-mcp-adapter/resource-tools.ts +0 -17
- package/node_modules/pi-mcp-adapter/runtime-owner.ts +0 -106
- package/node_modules/pi-mcp-adapter/sampling-handler.ts +0 -261
- package/node_modules/pi-mcp-adapter/sandbox-proxy-template.ts +0 -144
- package/node_modules/pi-mcp-adapter/search-ranking.ts +0 -309
- package/node_modules/pi-mcp-adapter/secure-keyring.ts +0 -170
- package/node_modules/pi-mcp-adapter/semantic-search.ts +0 -186
- package/node_modules/pi-mcp-adapter/server-manager.ts +0 -2088
- package/node_modules/pi-mcp-adapter/session-approvals.ts +0 -201
- package/node_modules/pi-mcp-adapter/session-recovery.ts +0 -158
- package/node_modules/pi-mcp-adapter/skills/mcp-scripting/SKILL.md +0 -49
- package/node_modules/pi-mcp-adapter/state.ts +0 -71
- package/node_modules/pi-mcp-adapter/tool-approval.ts +0 -205
- package/node_modules/pi-mcp-adapter/tool-metadata.ts +0 -302
- package/node_modules/pi-mcp-adapter/tool-registrar.ts +0 -255
- package/node_modules/pi-mcp-adapter/tool-result-renderer.ts +0 -573
- package/node_modules/pi-mcp-adapter/ts-shape.ts +0 -149
- package/node_modules/pi-mcp-adapter/types.ts +0 -1120
- package/node_modules/pi-mcp-adapter/ui-app-bridge-helpers.ts +0 -40
- package/node_modules/pi-mcp-adapter/ui-resource-handler.ts +0 -266
- package/node_modules/pi-mcp-adapter/ui-server.ts +0 -993
- package/node_modules/pi-mcp-adapter/ui-session.ts +0 -624
- package/node_modules/pi-mcp-adapter/ui-stream-types.ts +0 -89
- package/node_modules/pi-mcp-adapter/ui-tool-visibility.ts +0 -25
- package/node_modules/pi-mcp-adapter/unix-socket-transport.ts +0 -85
- package/node_modules/pi-mcp-adapter/utils.ts +0 -464
|
@@ -1,534 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP OAuth Callback Server
|
|
3
|
-
*
|
|
4
|
-
* HTTP server that handles OAuth callbacks from the authorization server.
|
|
5
|
-
* Uses Node.js http module for compatibility.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createServer, type Server, type IncomingMessage, type ServerResponse } from "http"
|
|
9
|
-
import { getAppName } from "./agent-dir.ts"
|
|
10
|
-
import {
|
|
11
|
-
DEFAULT_OAUTH_CALLBACK_PATH,
|
|
12
|
-
getConfiguredOAuthCallbackPort,
|
|
13
|
-
getOAuthCallbackPath,
|
|
14
|
-
getOAuthCallbackPort,
|
|
15
|
-
setOAuthCallbackPath,
|
|
16
|
-
setOAuthCallbackPort,
|
|
17
|
-
} from "./mcp-oauth-provider.ts"
|
|
18
|
-
|
|
19
|
-
// HTML templates for callback responses.
|
|
20
|
-
//
|
|
21
|
-
// These pages are served from localhost during OAuth and are the last thing a
|
|
22
|
-
// user sees before returning to their terminal, so they are self-contained: no
|
|
23
|
-
// webfonts, no external assets, nothing that needs the network. They also name
|
|
24
|
-
// the host rather than hardcoding "Pi", so a distribution that rebrands pi
|
|
25
|
-
// (arc, tau, …) does not send its users back to an app they are not running.
|
|
26
|
-
|
|
27
|
-
/** Shared chrome: system fonts, a centred card, and light/dark support. */
|
|
28
|
-
const PAGE_STYLE = `
|
|
29
|
-
:root { color-scheme: light dark; }
|
|
30
|
-
* { box-sizing: border-box; }
|
|
31
|
-
body {
|
|
32
|
-
margin: 0;
|
|
33
|
-
min-height: 100vh;
|
|
34
|
-
display: flex;
|
|
35
|
-
align-items: center;
|
|
36
|
-
justify-content: center;
|
|
37
|
-
padding: 24px;
|
|
38
|
-
font: 15px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
39
|
-
background: #0f1117;
|
|
40
|
-
color: #e6e8ee;
|
|
41
|
-
}
|
|
42
|
-
.card {
|
|
43
|
-
width: 100%;
|
|
44
|
-
max-width: 26rem;
|
|
45
|
-
padding: 2.5rem 2rem;
|
|
46
|
-
text-align: center;
|
|
47
|
-
background: #161922;
|
|
48
|
-
border: 1px solid #242938;
|
|
49
|
-
border-radius: 14px;
|
|
50
|
-
box-shadow: 0 1px 2px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.25);
|
|
51
|
-
}
|
|
52
|
-
.badge {
|
|
53
|
-
width: 3rem; height: 3rem;
|
|
54
|
-
margin: 0 auto 1.25rem;
|
|
55
|
-
display: grid; place-items: center;
|
|
56
|
-
border-radius: 50%;
|
|
57
|
-
}
|
|
58
|
-
.badge svg { width: 1.5rem; height: 1.5rem; display: block; }
|
|
59
|
-
.ok { background: rgba(74,222,128,.12); color: #4ade80; }
|
|
60
|
-
.bad { background: rgba(248,113,113,.12); color: #f87171; }
|
|
61
|
-
h1 { margin: 0 0 .5rem; font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; }
|
|
62
|
-
p { margin: 0; color: #9aa1b1; }
|
|
63
|
-
.app { color: #e6e8ee; font-weight: 500; }
|
|
64
|
-
.hint { margin-top: 1.25rem; font-size: .8125rem; color: #6b7280; }
|
|
65
|
-
code {
|
|
66
|
-
display: block;
|
|
67
|
-
margin-top: 1.25rem;
|
|
68
|
-
padding: .75rem .875rem;
|
|
69
|
-
text-align: left;
|
|
70
|
-
font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
|
|
71
|
-
color: #fca5a5;
|
|
72
|
-
background: rgba(248,113,113,.08);
|
|
73
|
-
border: 1px solid rgba(248,113,113,.2);
|
|
74
|
-
border-radius: 8px;
|
|
75
|
-
overflow-wrap: anywhere;
|
|
76
|
-
}
|
|
77
|
-
@media (prefers-color-scheme: light) {
|
|
78
|
-
body { background: #f6f7f9; color: #121620; }
|
|
79
|
-
.card { background: #fff; border-color: #e4e7ee; }
|
|
80
|
-
p { color: #5b6474; }
|
|
81
|
-
.app { color: #121620; }
|
|
82
|
-
.hint { color: #8b93a3; }
|
|
83
|
-
}`
|
|
84
|
-
|
|
85
|
-
const CHECK_ICON =
|
|
86
|
-
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>'
|
|
87
|
-
|
|
88
|
-
const CROSS_ICON =
|
|
89
|
-
'<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18M6 6l12 12"/></svg>'
|
|
90
|
-
|
|
91
|
-
function page(options: {
|
|
92
|
-
title: string
|
|
93
|
-
heading: string
|
|
94
|
-
body: string
|
|
95
|
-
icon: string
|
|
96
|
-
tone: "ok" | "bad"
|
|
97
|
-
extra?: string
|
|
98
|
-
autoClose?: boolean
|
|
99
|
-
}): string {
|
|
100
|
-
return `<!DOCTYPE html>
|
|
101
|
-
<html lang="en">
|
|
102
|
-
<head>
|
|
103
|
-
<meta charset="utf-8">
|
|
104
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
105
|
-
<title>${options.title}</title>
|
|
106
|
-
<style>${PAGE_STYLE}
|
|
107
|
-
</style>
|
|
108
|
-
</head>
|
|
109
|
-
<body>
|
|
110
|
-
<main class="card">
|
|
111
|
-
<div class="badge ${options.tone}">${options.icon}</div>
|
|
112
|
-
<h1>${options.heading}</h1>
|
|
113
|
-
<p>${options.body}</p>
|
|
114
|
-
${options.extra ?? ""}
|
|
115
|
-
</main>
|
|
116
|
-
${options.autoClose ? " <script>setTimeout(() => window.close(), 2000);</script>\n" : ""}</body>
|
|
117
|
-
</html>`
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
function escapeHtml(value: string): string {
|
|
121
|
-
return value
|
|
122
|
-
.replace(/&/g, "&")
|
|
123
|
-
.replace(/</g, "<")
|
|
124
|
-
.replace(/>/g, ">")
|
|
125
|
-
.replace(/"/g, """)
|
|
126
|
-
.replace(/'/g, "'")
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/** Built per request so a host that sets PI_PACKAGE_DIR late is still named right. */
|
|
130
|
-
function htmlSuccess(): string {
|
|
131
|
-
const app = escapeHtml(getAppName())
|
|
132
|
-
return page({
|
|
133
|
-
title: `${app} — Authorization Successful`,
|
|
134
|
-
heading: "Authorization Successful",
|
|
135
|
-
body: `You can close this window and return to <span class="app">${app}</span>.`,
|
|
136
|
-
icon: CHECK_ICON,
|
|
137
|
-
tone: "ok",
|
|
138
|
-
autoClose: true,
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function htmlManualSuccess(): string {
|
|
143
|
-
const app = escapeHtml(getAppName())
|
|
144
|
-
return page({
|
|
145
|
-
title: `${app} — Authorization Received`,
|
|
146
|
-
heading: "Authorization Received",
|
|
147
|
-
body: `Copy the full callback URL from your browser address bar and paste it back into <span class="app">${app}</span> with auth-complete.`,
|
|
148
|
-
icon: CHECK_ICON,
|
|
149
|
-
tone: "ok",
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function htmlError(error: string): string {
|
|
154
|
-
const app = escapeHtml(getAppName())
|
|
155
|
-
return page({
|
|
156
|
-
title: `${app} — Authorization Failed`,
|
|
157
|
-
heading: "Authorization Failed",
|
|
158
|
-
body: `Something went wrong during authorization. You can close this window and try again from <span class="app">${app}</span>.`,
|
|
159
|
-
icon: CROSS_ICON,
|
|
160
|
-
tone: "bad",
|
|
161
|
-
extra: `<code>${escapeHtml(error)}</code>`,
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/** Result of a successful OAuth callback */
|
|
166
|
-
export interface OAuthCallbackResult {
|
|
167
|
-
code: string
|
|
168
|
-
/** RFC 9207 `iss` authorization response parameter, when provided */
|
|
169
|
-
iss?: string
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/** Pending authorization request */
|
|
173
|
-
interface PendingAuth {
|
|
174
|
-
resolve: (result: OAuthCallbackResult) => void
|
|
175
|
-
reject: (error: Error) => void
|
|
176
|
-
timeout: ReturnType<typeof setTimeout>
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/** Server singleton state */
|
|
180
|
-
let server: Server | undefined
|
|
181
|
-
let bindingPromise: Promise<void> | undefined
|
|
182
|
-
let stoppingPromise: Promise<void> | undefined
|
|
183
|
-
let restartableStoppingPromise: Promise<void> | undefined
|
|
184
|
-
let callbackGeneration = 0
|
|
185
|
-
const pendingAuths = new Map<string, PendingAuth>()
|
|
186
|
-
const reservedAuthStates = new Set<string>()
|
|
187
|
-
|
|
188
|
-
/** Timeout for callback completion (5 minutes) */
|
|
189
|
-
const CALLBACK_TIMEOUT_MS = 5 * 60 * 1000
|
|
190
|
-
|
|
191
|
-
interface EnsureCallbackServerOptions {
|
|
192
|
-
strictPort?: boolean
|
|
193
|
-
port?: number
|
|
194
|
-
callbackHost?: string
|
|
195
|
-
callbackPath?: string
|
|
196
|
-
oauthState?: string
|
|
197
|
-
reserveState?: boolean
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const DEFAULT_OAUTH_CALLBACK_HOST = "localhost"
|
|
201
|
-
let callbackServerHost = DEFAULT_OAUTH_CALLBACK_HOST
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Handle incoming HTTP requests to the callback server.
|
|
205
|
-
*/
|
|
206
|
-
function handleRequest(req: IncomingMessage, res: ServerResponse): void {
|
|
207
|
-
const url = new URL(req.url || "/", `http://${req.headers.host}`)
|
|
208
|
-
|
|
209
|
-
// Only handle the callback path
|
|
210
|
-
if (url.pathname !== getOAuthCallbackPath()) {
|
|
211
|
-
res.writeHead(404, { "Content-Type": "text/plain" })
|
|
212
|
-
res.end("Not found")
|
|
213
|
-
return
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
const code = url.searchParams.get("code")
|
|
217
|
-
const iss = url.searchParams.get("iss")
|
|
218
|
-
const state = url.searchParams.get("state")
|
|
219
|
-
const error = url.searchParams.get("error")
|
|
220
|
-
const errorDescription = url.searchParams.get("error_description")
|
|
221
|
-
|
|
222
|
-
// Enforce state parameter presence for CSRF protection
|
|
223
|
-
if (!state) {
|
|
224
|
-
const errorMsg = "Missing required state parameter - potential CSRF attack"
|
|
225
|
-
res.writeHead(400, { "Content-Type": "text/html" })
|
|
226
|
-
res.end(htmlError(errorMsg))
|
|
227
|
-
return
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const pending = pendingAuths.get(state)
|
|
231
|
-
const isReserved = reservedAuthStates.has(state)
|
|
232
|
-
|
|
233
|
-
// Handle OAuth errors only for a state that belongs to an active flow.
|
|
234
|
-
if (error) {
|
|
235
|
-
if (!pending && !isReserved) {
|
|
236
|
-
const errorMsg = "Invalid or expired state parameter - potential CSRF attack"
|
|
237
|
-
res.writeHead(400, { "Content-Type": "text/html" })
|
|
238
|
-
res.end(htmlError(errorMsg))
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
const errorMsg = errorDescription || error
|
|
243
|
-
// Send HTTP response first before rejecting promise
|
|
244
|
-
res.writeHead(200, { "Content-Type": "text/html" })
|
|
245
|
-
res.end(htmlError(errorMsg))
|
|
246
|
-
// Reject promise after response is sent (defer to allow test to attach handler)
|
|
247
|
-
if (pending) {
|
|
248
|
-
reservedAuthStates.delete(state)
|
|
249
|
-
clearTimeout(pending.timeout)
|
|
250
|
-
pendingAuths.delete(state)
|
|
251
|
-
setTimeout(() => pending.reject(new Error(errorMsg)), 0)
|
|
252
|
-
}
|
|
253
|
-
return
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
// Validate state parameter
|
|
257
|
-
if (!pending && !isReserved) {
|
|
258
|
-
const errorMsg = "Invalid or expired state parameter - potential CSRF attack"
|
|
259
|
-
res.writeHead(400, { "Content-Type": "text/html" })
|
|
260
|
-
res.end(htmlError(errorMsg))
|
|
261
|
-
return
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// Require authorization code
|
|
265
|
-
if (!code) {
|
|
266
|
-
res.writeHead(400, { "Content-Type": "text/html" })
|
|
267
|
-
res.end(htmlError("No authorization code provided"))
|
|
268
|
-
return
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
if (!pending) {
|
|
272
|
-
res.writeHead(200, { "Content-Type": "text/html" })
|
|
273
|
-
res.end(htmlManualSuccess())
|
|
274
|
-
return
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
// Clear timeout and resolve the pending promise
|
|
278
|
-
clearTimeout(pending.timeout)
|
|
279
|
-
pendingAuths.delete(state)
|
|
280
|
-
pending.resolve({ code, ...(iss !== null ? { iss } : {}) })
|
|
281
|
-
|
|
282
|
-
res.writeHead(200, { "Content-Type": "text/html" })
|
|
283
|
-
res.end(htmlSuccess())
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Ensure the callback server is running.
|
|
288
|
-
* If strictPort is true, requires binding on the configured callback port.
|
|
289
|
-
* If strictPort is false, asks the OS for an available local port.
|
|
290
|
-
*/
|
|
291
|
-
export async function ensureCallbackServer(options: EnsureCallbackServerOptions = {}): Promise<void> {
|
|
292
|
-
const generation = callbackGeneration
|
|
293
|
-
if (stoppingPromise) {
|
|
294
|
-
if (!restartableStoppingPromise) {
|
|
295
|
-
throw new Error("OAuth callback server stopped")
|
|
296
|
-
}
|
|
297
|
-
await restartableStoppingPromise
|
|
298
|
-
if (generation !== callbackGeneration) {
|
|
299
|
-
throw new Error("OAuth callback server stopped")
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
while (bindingPromise) {
|
|
303
|
-
await bindingPromise
|
|
304
|
-
if (generation !== callbackGeneration) {
|
|
305
|
-
throw new Error("OAuth callback server stopped")
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
if (generation !== callbackGeneration) {
|
|
309
|
-
throw new Error("OAuth callback server stopped")
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
const operation = ensureCallbackServerLocked(options)
|
|
313
|
-
bindingPromise = operation
|
|
314
|
-
try {
|
|
315
|
-
await operation
|
|
316
|
-
} finally {
|
|
317
|
-
if (bindingPromise === operation) {
|
|
318
|
-
bindingPromise = undefined
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
async function ensureCallbackServerLocked(options: EnsureCallbackServerOptions = {}): Promise<void> {
|
|
324
|
-
const requiredPort = options.port ?? getConfiguredOAuthCallbackPort()
|
|
325
|
-
const strictPort = options.strictPort === true
|
|
326
|
-
const requestedHost = options.callbackHost ?? DEFAULT_OAUTH_CALLBACK_HOST
|
|
327
|
-
const rawRequestedPath = options.callbackPath ?? DEFAULT_OAUTH_CALLBACK_PATH
|
|
328
|
-
const requestedPath = rawRequestedPath.startsWith("/") ? rawRequestedPath : `/${rawRequestedPath}`
|
|
329
|
-
if (options.reserveState && !options.oauthState) {
|
|
330
|
-
throw new Error("OAuth callback reservation requires an oauthState")
|
|
331
|
-
}
|
|
332
|
-
let reservedState: string | undefined
|
|
333
|
-
|
|
334
|
-
const previousServer = server
|
|
335
|
-
const needsStrictRebind = Boolean(previousServer && strictPort && getOAuthCallbackPort() !== requiredPort)
|
|
336
|
-
const needsHostSwitch = Boolean(previousServer && callbackServerHost !== requestedHost)
|
|
337
|
-
const needsPathSwitch = Boolean(previousServer && getOAuthCallbackPath() !== requestedPath)
|
|
338
|
-
|
|
339
|
-
if (previousServer) {
|
|
340
|
-
if (!needsStrictRebind && !needsHostSwitch) {
|
|
341
|
-
if (needsPathSwitch) {
|
|
342
|
-
if (pendingAuths.size > 0 || reservedAuthStates.size > 0) {
|
|
343
|
-
throw new Error(
|
|
344
|
-
`OAuth callback server is using path ${getOAuthCallbackPath()}, but callback path ${requestedPath} is required and cannot be switched while authorizations are pending`
|
|
345
|
-
)
|
|
346
|
-
}
|
|
347
|
-
setOAuthCallbackPath(requestedPath)
|
|
348
|
-
}
|
|
349
|
-
if (options.reserveState && options.oauthState) {
|
|
350
|
-
reservedAuthStates.add(options.oauthState)
|
|
351
|
-
reservedState = options.oauthState
|
|
352
|
-
}
|
|
353
|
-
return
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (pendingAuths.size > 0 || reservedAuthStates.size > 0) {
|
|
357
|
-
throw new Error(
|
|
358
|
-
`OAuth callback server is running on ${callbackServerHost}:${getOAuthCallbackPort()}, but strict callback endpoint ${requestedHost}:${requiredPort} is required and cannot be switched while authorizations are pending`
|
|
359
|
-
)
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
const candidateServer = createServer(handleRequest)
|
|
364
|
-
const listenPort = strictPort ? requiredPort : 0
|
|
365
|
-
|
|
366
|
-
try {
|
|
367
|
-
await new Promise<void>((resolve, reject) => {
|
|
368
|
-
candidateServer.once("error", (err) => {
|
|
369
|
-
reject(err)
|
|
370
|
-
})
|
|
371
|
-
|
|
372
|
-
candidateServer.listen(listenPort, requestedHost, () => {
|
|
373
|
-
resolve()
|
|
374
|
-
})
|
|
375
|
-
})
|
|
376
|
-
|
|
377
|
-
if (strictPort) {
|
|
378
|
-
setOAuthCallbackPort(requiredPort)
|
|
379
|
-
} else {
|
|
380
|
-
const address = candidateServer.address()
|
|
381
|
-
if (!address || typeof address === "string" || typeof address.port !== "number") {
|
|
382
|
-
throw new Error("OAuth callback server did not report an assigned port")
|
|
383
|
-
}
|
|
384
|
-
setOAuthCallbackPort(address.port)
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
if (previousServer && (needsStrictRebind || needsHostSwitch)) {
|
|
388
|
-
await new Promise<void>((resolve) => {
|
|
389
|
-
previousServer.close(() => resolve())
|
|
390
|
-
})
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
callbackServerHost = requestedHost
|
|
394
|
-
setOAuthCallbackPath(requestedPath)
|
|
395
|
-
server = candidateServer
|
|
396
|
-
if (options.reserveState && options.oauthState) {
|
|
397
|
-
reservedAuthStates.add(options.oauthState)
|
|
398
|
-
reservedState = options.oauthState
|
|
399
|
-
}
|
|
400
|
-
server.unref()
|
|
401
|
-
} catch (error) {
|
|
402
|
-
if (reservedState) {
|
|
403
|
-
reservedAuthStates.delete(reservedState)
|
|
404
|
-
}
|
|
405
|
-
const nodeError = error as NodeJS.ErrnoException
|
|
406
|
-
await new Promise<void>((resolve) => {
|
|
407
|
-
candidateServer.close(() => resolve())
|
|
408
|
-
})
|
|
409
|
-
|
|
410
|
-
if (strictPort && nodeError.code === "EADDRINUSE") {
|
|
411
|
-
throw new Error(
|
|
412
|
-
`OAuth callback port ${requiredPort} is already in use. Pre-registered OAuth clients require an exact redirect URI; set MCP_OAUTH_CALLBACK_PORT to your registered port or free port ${requiredPort}`,
|
|
413
|
-
{ cause: error }
|
|
414
|
-
)
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
throw error
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
export function reserveCallbackServer(oauthState: string): void {
|
|
422
|
-
reservedAuthStates.add(oauthState)
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
export function releaseCallbackServer(oauthState: string): void {
|
|
426
|
-
reservedAuthStates.delete(oauthState)
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
/**
|
|
430
|
-
* Wait for a callback with the given OAuth state.
|
|
431
|
-
* Returns a promise that resolves with the authorization code and, when the
|
|
432
|
-
* authorization server sends one, the RFC 9207 `iss` parameter.
|
|
433
|
-
*/
|
|
434
|
-
export function waitForCallback(oauthState: string): Promise<OAuthCallbackResult> {
|
|
435
|
-
reservedAuthStates.delete(oauthState)
|
|
436
|
-
return new Promise((resolve, reject) => {
|
|
437
|
-
const timeout = setTimeout(() => {
|
|
438
|
-
if (pendingAuths.has(oauthState)) {
|
|
439
|
-
pendingAuths.delete(oauthState)
|
|
440
|
-
reject(new Error("OAuth callback timeout - authorization took too long"))
|
|
441
|
-
}
|
|
442
|
-
}, CALLBACK_TIMEOUT_MS)
|
|
443
|
-
|
|
444
|
-
pendingAuths.set(oauthState, { resolve, reject, timeout })
|
|
445
|
-
})
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Cancel a pending authorization by state.
|
|
450
|
-
*/
|
|
451
|
-
export function cancelPendingCallback(oauthState: string): void {
|
|
452
|
-
reservedAuthStates.delete(oauthState)
|
|
453
|
-
const pending = pendingAuths.get(oauthState)
|
|
454
|
-
if (pending) {
|
|
455
|
-
clearTimeout(pending.timeout)
|
|
456
|
-
pendingAuths.delete(oauthState)
|
|
457
|
-
pending.reject(new Error("Authorization cancelled"))
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Stop the callback server and reject all pending authorizations.
|
|
463
|
-
*/
|
|
464
|
-
export function stopCallbackServer(): Promise<void> {
|
|
465
|
-
if (stoppingPromise) {
|
|
466
|
-
restartableStoppingPromise = undefined
|
|
467
|
-
callbackGeneration += 1
|
|
468
|
-
return stoppingPromise
|
|
469
|
-
}
|
|
470
|
-
|
|
471
|
-
callbackGeneration += 1
|
|
472
|
-
const cleanup = (async () => {
|
|
473
|
-
while (bindingPromise) {
|
|
474
|
-
await bindingPromise.catch(() => {})
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
if (server) {
|
|
478
|
-
await new Promise<void>((resolve) => {
|
|
479
|
-
server!.close(() => {
|
|
480
|
-
resolve()
|
|
481
|
-
})
|
|
482
|
-
})
|
|
483
|
-
server = undefined
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
setOAuthCallbackPort(getConfiguredOAuthCallbackPort())
|
|
487
|
-
callbackServerHost = DEFAULT_OAUTH_CALLBACK_HOST
|
|
488
|
-
setOAuthCallbackPath(DEFAULT_OAUTH_CALLBACK_PATH)
|
|
489
|
-
|
|
490
|
-
// Reject all pending auths (defer to allow any pending operations to complete)
|
|
491
|
-
const pendingList = Array.from(pendingAuths.entries())
|
|
492
|
-
pendingAuths.clear()
|
|
493
|
-
reservedAuthStates.clear()
|
|
494
|
-
setTimeout(() => {
|
|
495
|
-
for (const [, pending] of pendingList) {
|
|
496
|
-
clearTimeout(pending.timeout)
|
|
497
|
-
pending.reject(new Error("OAuth callback server stopped"))
|
|
498
|
-
}
|
|
499
|
-
}, 0)
|
|
500
|
-
})()
|
|
501
|
-
|
|
502
|
-
const operation = cleanup.finally(() => {
|
|
503
|
-
if (stoppingPromise === operation) stoppingPromise = undefined
|
|
504
|
-
})
|
|
505
|
-
stoppingPromise = operation
|
|
506
|
-
return operation
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
/** Stop the callback server only when no bind or authorization owns it. */
|
|
510
|
-
export function stopCallbackServerIfIdle(): Promise<void> {
|
|
511
|
-
if (stoppingPromise) return stoppingPromise
|
|
512
|
-
if (bindingPromise || !server || pendingAuths.size > 0 || reservedAuthStates.size > 0) {
|
|
513
|
-
return Promise.resolve()
|
|
514
|
-
}
|
|
515
|
-
const operation = stopCallbackServer().finally(() => {
|
|
516
|
-
if (restartableStoppingPromise === operation) restartableStoppingPromise = undefined
|
|
517
|
-
})
|
|
518
|
-
restartableStoppingPromise = operation
|
|
519
|
-
return operation
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
/**
|
|
523
|
-
* Check if the callback server is running.
|
|
524
|
-
*/
|
|
525
|
-
export function isCallbackServerRunning(): boolean {
|
|
526
|
-
return server !== undefined
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
/**
|
|
530
|
-
* Get the number of pending authorizations.
|
|
531
|
-
*/
|
|
532
|
-
export function getPendingAuthCount(): number {
|
|
533
|
-
return pendingAuths.size
|
|
534
|
-
}
|