@herbertgao/pi-extensions 2026.9.16 → 2026.9.18
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 +14 -15
- 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/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/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/extension.ts +11 -53
- 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/package.json +2 -2
- 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 +1 -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 +5 -5
- package/node_modules/pi-web-access/package.json +2 -2
- package/node_modules/remote-pi/package.json +5 -1
- package/package.json +16 -28
- 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,40 +0,0 @@
|
|
|
1
|
-
import type { UiResourcePermissions } from "./types.ts";
|
|
2
|
-
|
|
3
|
-
export const RESOURCE_MIME_TYPE = "text/html;profile=mcp-app";
|
|
4
|
-
|
|
5
|
-
const RESOURCE_URI_META_KEY = "ui/resourceUri";
|
|
6
|
-
|
|
7
|
-
export function getToolUiResourceUri(tool: { _meta?: Record<string, unknown> | undefined }): string | undefined {
|
|
8
|
-
const meta = tool._meta;
|
|
9
|
-
let resourceUri = getNestedResourceUri(meta);
|
|
10
|
-
if (resourceUri === undefined) {
|
|
11
|
-
resourceUri = meta?.[RESOURCE_URI_META_KEY];
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (typeof resourceUri === "string" && resourceUri.startsWith("ui://")) {
|
|
15
|
-
return resourceUri;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (resourceUri !== undefined) {
|
|
19
|
-
throw new Error(`Invalid UI resource URI: ${JSON.stringify(resourceUri)}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return undefined;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function buildAllowAttribute(permissions: UiResourcePermissions | undefined): string {
|
|
26
|
-
if (!permissions) return "";
|
|
27
|
-
|
|
28
|
-
const allowed: string[] = [];
|
|
29
|
-
if (permissions.camera) allowed.push("camera");
|
|
30
|
-
if (permissions.microphone) allowed.push("microphone");
|
|
31
|
-
if (permissions.geolocation) allowed.push("geolocation");
|
|
32
|
-
if (permissions.clipboardWrite) allowed.push("clipboard-write");
|
|
33
|
-
return allowed.join("; ");
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function getNestedResourceUri(meta: Record<string, unknown> | undefined): unknown {
|
|
37
|
-
const ui = meta?.ui;
|
|
38
|
-
if (!ui || typeof ui !== "object") return undefined;
|
|
39
|
-
return (ui as Record<string, unknown>).resourceUri;
|
|
40
|
-
}
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
import { RESOURCE_MIME_TYPE } from "./ui-app-bridge-helpers.ts";
|
|
2
|
-
import { UrlElicitationRequiredError, type ReadResourceResult } from "@modelcontextprotocol/client";
|
|
3
|
-
import {
|
|
4
|
-
getInputRequiredNeedsUiDetails,
|
|
5
|
-
InputRequiredNeedsUiError,
|
|
6
|
-
ResourceFetchError,
|
|
7
|
-
ResourceParseError,
|
|
8
|
-
} from "./errors.ts";
|
|
9
|
-
import { logger } from "./logger.ts";
|
|
10
|
-
import { SessionRecoveryAuthRequiredError, withSessionRecovery, type SessionRecoveryDeps } from "./session-recovery.ts";
|
|
11
|
-
import type { McpServerManager } from "./server-manager.ts";
|
|
12
|
-
import { isServerDisabled, type McpConfig, type UiResourceContent, type UiResourceCsp, type UiResourceMeta, type UiResourcePermissions } from "./types.ts";
|
|
13
|
-
|
|
14
|
-
interface ResourceContentRecord {
|
|
15
|
-
uri?: string;
|
|
16
|
-
mimeType?: string;
|
|
17
|
-
text?: string;
|
|
18
|
-
blob?: string;
|
|
19
|
-
_meta?: Record<string, unknown>;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
interface ReadUiResourceOptions {
|
|
23
|
-
config?: McpConfig;
|
|
24
|
-
signal?: AbortSignal;
|
|
25
|
-
onNeedsAuth?: SessionRecoveryDeps["onNeedsAuth"];
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export class UiResourceHandler {
|
|
29
|
-
private log = logger.child({ component: "UiResourceHandler" });
|
|
30
|
-
|
|
31
|
-
constructor(private manager: McpServerManager, private config: McpConfig | undefined = undefined) {}
|
|
32
|
-
|
|
33
|
-
async readUiResource(serverName: string, uri: string, options: ReadUiResourceOptions = {}): Promise<UiResourceContent> {
|
|
34
|
-
const log = this.log.child({ server: serverName, uri });
|
|
35
|
-
|
|
36
|
-
if (!uri.startsWith("ui://")) {
|
|
37
|
-
throw new ResourceParseError(uri, "URI must start with ui://", { server: serverName });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
log.debug("Fetching UI resource");
|
|
41
|
-
|
|
42
|
-
let result: ReadResourceResult;
|
|
43
|
-
try {
|
|
44
|
-
const config = options.config ?? this.config;
|
|
45
|
-
if (config && isServerDisabled(config.mcpServers[serverName])) {
|
|
46
|
-
throw new Error(`MCP server "${serverName}" is disabled`);
|
|
47
|
-
}
|
|
48
|
-
if (config) {
|
|
49
|
-
this.manager.touch(serverName);
|
|
50
|
-
this.manager.incrementInFlight(serverName);
|
|
51
|
-
try {
|
|
52
|
-
result = await withSessionRecovery(
|
|
53
|
-
{
|
|
54
|
-
manager: this.manager,
|
|
55
|
-
config,
|
|
56
|
-
...(options.signal ? { signal: options.signal } : {}),
|
|
57
|
-
...(options.onNeedsAuth ? { onNeedsAuth: options.onNeedsAuth } : {}),
|
|
58
|
-
},
|
|
59
|
-
serverName,
|
|
60
|
-
async (connection) => {
|
|
61
|
-
const refreshRead = await this.manager.prepareResourceUse?.(serverName, uri, connection);
|
|
62
|
-
const requestOptions = this.manager.getRequestOptions(serverName, options.signal);
|
|
63
|
-
return connection.client.readResource(
|
|
64
|
-
{ uri },
|
|
65
|
-
refreshRead ? { ...requestOptions, cacheMode: "refresh" } : requestOptions,
|
|
66
|
-
);
|
|
67
|
-
},
|
|
68
|
-
);
|
|
69
|
-
} finally {
|
|
70
|
-
this.manager.decrementInFlight(serverName);
|
|
71
|
-
this.manager.touch(serverName);
|
|
72
|
-
}
|
|
73
|
-
} else {
|
|
74
|
-
result = await this.manager.readResource(serverName, uri, options.signal);
|
|
75
|
-
}
|
|
76
|
-
} catch (error) {
|
|
77
|
-
if (error instanceof UrlElicitationRequiredError || error instanceof SessionRecoveryAuthRequiredError) throw error;
|
|
78
|
-
const inputRequired = getInputRequiredNeedsUiDetails(error, { server: serverName, resourceUri: uri });
|
|
79
|
-
if (inputRequired) {
|
|
80
|
-
throw new InputRequiredNeedsUiError(inputRequired, error instanceof Error ? error : undefined);
|
|
81
|
-
}
|
|
82
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
83
|
-
log.error("Failed to read resource", error instanceof Error ? error : undefined);
|
|
84
|
-
throw new ResourceFetchError(uri, message, {
|
|
85
|
-
server: serverName,
|
|
86
|
-
...(error instanceof Error ? { cause: error } : {}),
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const content = selectContent(result, uri);
|
|
91
|
-
const mimeType = content.mimeType;
|
|
92
|
-
|
|
93
|
-
if (mimeType && !isHtmlMimeType(mimeType)) {
|
|
94
|
-
log.warn("Unsupported MIME type", { mimeType });
|
|
95
|
-
throw new ResourceParseError(
|
|
96
|
-
uri,
|
|
97
|
-
`unsupported MIME type "${mimeType}" (expected text/html or ${RESOURCE_MIME_TYPE})`,
|
|
98
|
-
{ server: serverName, mimeType }
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const html = toHtml(content);
|
|
103
|
-
if (!html.trim()) {
|
|
104
|
-
log.warn("Resource content is empty");
|
|
105
|
-
throw new ResourceParseError(uri, "content is empty", { server: serverName });
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const contentMeta = extractUiMeta(content._meta);
|
|
109
|
-
const listMeta = extractUiMeta(this.getListResourceMeta(serverName, uri));
|
|
110
|
-
|
|
111
|
-
log.debug("Resource loaded successfully", {
|
|
112
|
-
contentLength: html.length,
|
|
113
|
-
hasCsp: !!contentMeta.csp || !!listMeta.csp,
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
return {
|
|
117
|
-
uri: content.uri ?? uri,
|
|
118
|
-
html,
|
|
119
|
-
mimeType: mimeType ?? RESOURCE_MIME_TYPE,
|
|
120
|
-
meta: {
|
|
121
|
-
...((contentMeta.csp ?? listMeta.csp) !== undefined ? { csp: contentMeta.csp ?? listMeta.csp } : {}),
|
|
122
|
-
...((contentMeta.permissions ?? listMeta.permissions) !== undefined
|
|
123
|
-
? { permissions: contentMeta.permissions ?? listMeta.permissions }
|
|
124
|
-
: {}),
|
|
125
|
-
...((contentMeta.domain ?? listMeta.domain) !== undefined ? { domain: contentMeta.domain ?? listMeta.domain } : {}),
|
|
126
|
-
...((contentMeta.prefersBorder ?? listMeta.prefersBorder) !== undefined
|
|
127
|
-
? { prefersBorder: contentMeta.prefersBorder ?? listMeta.prefersBorder }
|
|
128
|
-
: {}),
|
|
129
|
-
},
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private getListResourceMeta(serverName: string, uri: string): Record<string, unknown> | undefined {
|
|
134
|
-
const connection = this.manager.getConnection(serverName);
|
|
135
|
-
if (!connection?.resources?.length) return undefined;
|
|
136
|
-
const resource = connection.resources.find((entry) => entry.uri === uri);
|
|
137
|
-
if (!resource || !resource._meta || typeof resource._meta !== "object") return undefined;
|
|
138
|
-
return resource._meta;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
function selectContent(result: ReadResourceResult, preferredUri: string): ResourceContentRecord {
|
|
143
|
-
const contents = (result.contents ?? []) as ResourceContentRecord[];
|
|
144
|
-
if (contents.length === 0) {
|
|
145
|
-
throw new Error(`No contents returned for UI resource: ${preferredUri}`);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const byUri = contents.find((content) => content.uri === preferredUri);
|
|
149
|
-
if (byUri) return byUri;
|
|
150
|
-
|
|
151
|
-
const byHtmlMime = contents.find(
|
|
152
|
-
(content) => content.mimeType && isHtmlMimeType(content.mimeType)
|
|
153
|
-
);
|
|
154
|
-
if (byHtmlMime) return byHtmlMime;
|
|
155
|
-
|
|
156
|
-
const firstContent = contents[0];
|
|
157
|
-
if (!firstContent) {
|
|
158
|
-
throw new Error(`No contents returned for UI resource: ${preferredUri}`);
|
|
159
|
-
}
|
|
160
|
-
return firstContent;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function isHtmlMimeType(mimeType: string): boolean {
|
|
164
|
-
const normalized = mimeType.toLowerCase();
|
|
165
|
-
return normalized.startsWith("text/html") || normalized === RESOURCE_MIME_TYPE.toLowerCase();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function toHtml(content: ResourceContentRecord): string {
|
|
169
|
-
if (typeof content.text === "string") {
|
|
170
|
-
return content.text;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (typeof content.blob === "string") {
|
|
174
|
-
return Buffer.from(content.blob, "base64").toString("utf-8");
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
throw new Error(`UI resource ${content.uri ?? "(unknown)"} did not include text or blob content`);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
const OPENAI_CSP_FIELD_MAPPINGS = [
|
|
181
|
-
["resource_domains", "resourceDomains"],
|
|
182
|
-
["connect_domains", "connectDomains"],
|
|
183
|
-
["frame_domains", "frameDomains"],
|
|
184
|
-
] as const;
|
|
185
|
-
|
|
186
|
-
const UI_CSP_DOMAIN_FIELDS: readonly (keyof UiResourceCsp)[] = [
|
|
187
|
-
"resourceDomains",
|
|
188
|
-
"connectDomains",
|
|
189
|
-
"frameDomains",
|
|
190
|
-
"baseUriDomains",
|
|
191
|
-
];
|
|
192
|
-
|
|
193
|
-
function extractUiMeta(meta: Record<string, unknown> | undefined): UiResourceMeta {
|
|
194
|
-
if (!meta || typeof meta !== "object") return {};
|
|
195
|
-
|
|
196
|
-
const ui = isRecord(meta.ui) ? meta.ui : undefined;
|
|
197
|
-
const out: UiResourceMeta = {};
|
|
198
|
-
const openAiCsp = Object.hasOwn(meta, "openai/widgetCSP")
|
|
199
|
-
? normalizeOpenAiWidgetCsp(meta["openai/widgetCSP"])
|
|
200
|
-
: undefined;
|
|
201
|
-
const hasStandardCsp = !!ui && Object.hasOwn(ui, "csp");
|
|
202
|
-
const standardCspValue = hasStandardCsp ? ui.csp : undefined;
|
|
203
|
-
|
|
204
|
-
if (hasStandardCsp && !isRecord(standardCspValue)) {
|
|
205
|
-
// A declared canonical container takes precedence even when malformed.
|
|
206
|
-
out.csp = {};
|
|
207
|
-
} else {
|
|
208
|
-
const standardCsp = hasStandardCsp
|
|
209
|
-
? normalizeUiResourceCsp(standardCspValue)
|
|
210
|
-
: undefined;
|
|
211
|
-
if (openAiCsp || standardCsp) {
|
|
212
|
-
out.csp = { ...openAiCsp, ...standardCsp };
|
|
213
|
-
if (isRecord(standardCspValue)) {
|
|
214
|
-
for (const [, standardField] of OPENAI_CSP_FIELD_MAPPINGS) {
|
|
215
|
-
if (Object.hasOwn(standardCspValue, standardField) && !copyStringArray(standardCspValue[standardField])) {
|
|
216
|
-
delete out.csp[standardField];
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (ui && isRecord(ui.permissions)) {
|
|
224
|
-
out.permissions = ui.permissions as UiResourcePermissions;
|
|
225
|
-
}
|
|
226
|
-
if (ui && typeof ui.domain === "string") {
|
|
227
|
-
out.domain = ui.domain;
|
|
228
|
-
}
|
|
229
|
-
if (ui && typeof ui.prefersBorder === "boolean") {
|
|
230
|
-
out.prefersBorder = ui.prefersBorder;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return out;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function normalizeUiResourceCsp(value: unknown): UiResourceCsp {
|
|
237
|
-
if (!isRecord(value)) return {};
|
|
238
|
-
|
|
239
|
-
const csp: UiResourceCsp = {};
|
|
240
|
-
for (const field of UI_CSP_DOMAIN_FIELDS) {
|
|
241
|
-
const domains = copyStringArray(value[field]);
|
|
242
|
-
if (domains) csp[field] = domains;
|
|
243
|
-
}
|
|
244
|
-
return csp;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
function normalizeOpenAiWidgetCsp(value: unknown): UiResourceCsp {
|
|
248
|
-
if (!isRecord(value)) return {};
|
|
249
|
-
|
|
250
|
-
const csp: UiResourceCsp = {};
|
|
251
|
-
for (const [sourceField, targetField] of OPENAI_CSP_FIELD_MAPPINGS) {
|
|
252
|
-
const domains = copyStringArray(value[sourceField]);
|
|
253
|
-
if (domains) csp[targetField] = domains;
|
|
254
|
-
}
|
|
255
|
-
return csp;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function copyStringArray(value: unknown): string[] | undefined {
|
|
259
|
-
return Array.isArray(value) && value.every((entry) => typeof entry === "string")
|
|
260
|
-
? [...value]
|
|
261
|
-
: undefined;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
265
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
266
|
-
}
|