@mcp-use/client 2.2.4 → 2.2.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.tsbuildinfo +1 -0
- package/dist/auth/browser.d.ts +218 -0
- package/dist/auth/browser.d.ts.map +1 -0
- package/dist/auth/callback.d.ts +9 -0
- package/dist/auth/callback.d.ts.map +1 -0
- package/dist/auth/flow.d.ts +32 -0
- package/dist/auth/flow.d.ts.map +1 -0
- package/dist/auth/node.d.ts +212 -0
- package/dist/auth/node.d.ts.map +1 -0
- package/dist/auth/popup.d.ts +67 -0
- package/dist/auth/popup.d.ts.map +1 -0
- package/dist/auth/session-store.d.ts +125 -0
- package/dist/auth/session-store.d.ts.map +1 -0
- package/dist/auth/storage-file.d.ts +18 -0
- package/dist/auth/storage-file.d.ts.map +1 -0
- package/dist/auth/storage.d.ts +34 -0
- package/dist/auth/storage.d.ts.map +1 -0
- package/dist/auth/url.d.ts +17 -0
- package/dist/auth/url.d.ts.map +1 -0
- package/dist/code-mode/connector.d.ts +27 -0
- package/dist/code-mode/connector.d.ts.map +1 -0
- package/dist/code-mode/executor-e2b.d.ts +46 -0
- package/dist/code-mode/executor-e2b.d.ts.map +1 -0
- package/dist/code-mode/executor-vm.d.ts +39 -0
- package/dist/code-mode/executor-vm.d.ts.map +1 -0
- package/dist/code-mode/executor.d.ts +81 -0
- package/dist/code-mode/executor.d.ts.map +1 -0
- package/dist/core/base.d.ts +423 -0
- package/dist/core/base.d.ts.map +1 -0
- package/dist/core/browser.d.ts +32 -0
- package/dist/core/browser.d.ts.map +1 -0
- package/dist/core/config.d.ts +225 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/node.d.ts +437 -0
- package/dist/core/node.d.ts.map +1 -0
- package/dist/core/session.d.ts +792 -0
- package/dist/core/session.d.ts.map +1 -0
- package/dist/core/skills.d.ts +47 -0
- package/dist/core/skills.d.ts.map +1 -0
- package/dist/index-browser.d.ts +26 -0
- package/dist/index-browser.d.ts.map +1 -0
- package/dist/index-browser.js +4767 -0
- package/dist/index-browser.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6113 -0
- package/dist/index.js.map +1 -0
- package/dist/react/McpClientProvider.d.ts +254 -0
- package/dist/react/McpClientProvider.d.ts.map +1 -0
- package/dist/react/index.d.ts +39 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +9444 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/rpc-logger.d.ts +47 -0
- package/dist/react/rpc-logger.d.ts.map +1 -0
- package/dist/react/storage.d.ts +98 -0
- package/dist/react/storage.d.ts.map +1 -0
- package/dist/react/token-expiry.d.ts +9 -0
- package/dist/react/token-expiry.d.ts.map +1 -0
- package/dist/react/types.d.ts +727 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/useMcp-helpers.d.ts +99 -0
- package/dist/react/useMcp-helpers.d.ts.map +1 -0
- package/dist/react/useMcp-operations.d.ts +180 -0
- package/dist/react/useMcp-operations.d.ts.map +1 -0
- package/dist/react/useMcp.d.ts +48 -0
- package/dist/react/useMcp.d.ts.map +1 -0
- package/dist/react/useMcpServerQueues.d.ts +403 -0
- package/dist/react/useMcpServerQueues.d.ts.map +1 -0
- package/dist/react/view/ViewRenderer.d.ts +20 -0
- package/dist/react/view/ViewRenderer.d.ts.map +1 -0
- package/dist/react/view/ext-apps-bridge.d.ts +3 -0
- package/dist/react/view/ext-apps-bridge.d.ts.map +1 -0
- package/dist/react/view/initialized-sync.d.ts +13 -0
- package/dist/react/view/initialized-sync.d.ts.map +1 -0
- package/dist/react/view/inject-openai-file-apis.d.ts +9 -0
- package/dist/react/view/inject-openai-file-apis.d.ts.map +1 -0
- package/dist/react/view/parse-custom-props.d.ts +10 -0
- package/dist/react/view/parse-custom-props.d.ts.map +1 -0
- package/dist/react/view/resolve-view-resource.d.ts +22 -0
- package/dist/react/view/resolve-view-resource.d.ts.map +1 -0
- package/dist/react/view/sandbox-blob-url.d.ts +27 -0
- package/dist/react/view/sandbox-blob-url.d.ts.map +1 -0
- package/dist/react/view/types.d.ts +220 -0
- package/dist/react/view/types.d.ts.map +1 -0
- package/dist/react/view/use-display-mode.d.ts +19 -0
- package/dist/react/view/use-display-mode.d.ts.map +1 -0
- package/dist/react/view/view-detection.d.ts +22 -0
- package/dist/react/view/view-detection.d.ts.map +1 -0
- package/dist/react/view/view-host-policy.d.ts +61 -0
- package/dist/react/view/view-host-policy.d.ts.map +1 -0
- package/dist/sandbox.d.ts +2 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/sandbox.js +288 -0
- package/dist/sandbox.js.map +1 -0
- package/dist/telemetry/client-telemetry.d.ts +13 -0
- package/dist/telemetry/client-telemetry.d.ts.map +1 -0
- package/dist/telemetry/configure-browser.d.ts +2 -0
- package/dist/telemetry/configure-browser.d.ts.map +1 -0
- package/dist/telemetry/configure-node.d.ts +2 -0
- package/dist/telemetry/configure-node.d.ts.map +1 -0
- package/dist/telemetry/connector-telemetry.d.ts +8 -0
- package/dist/telemetry/connector-telemetry.d.ts.map +1 -0
- package/dist/telemetry/events.d.ts +91 -0
- package/dist/telemetry/events.d.ts.map +1 -0
- package/dist/telemetry/index.d.ts +3 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/tel-fetch.d.ts +19 -0
- package/dist/telemetry/tel-fetch.d.ts.map +1 -0
- package/dist/telemetry/telemetry-browser.d.ts +6 -0
- package/dist/telemetry/telemetry-browser.d.ts.map +1 -0
- package/dist/telemetry/telemetry-node.d.ts +8 -0
- package/dist/telemetry/telemetry-node.d.ts.map +1 -0
- package/dist/telemetry/telemetry.d.ts +75 -0
- package/dist/telemetry/telemetry.d.ts.map +1 -0
- package/dist/transport/base.d.ts +656 -0
- package/dist/transport/base.d.ts.map +1 -0
- package/dist/transport/connection-manager.d.ts +59 -0
- package/dist/transport/connection-manager.d.ts.map +1 -0
- package/dist/transport/http.d.ts +137 -0
- package/dist/transport/http.d.ts.map +1 -0
- package/dist/transport/stdio.d.ts +97 -0
- package/dist/transport/stdio.d.ts.map +1 -0
- package/dist/utils/elicitation.d.ts +54 -0
- package/dist/utils/elicitation.d.ts.map +1 -0
- package/dist/utils/favicon.d.ts +6 -0
- package/dist/utils/favicon.d.ts.map +1 -0
- package/dist/utils/json-schema-validator.d.ts +13 -0
- package/dist/utils/json-schema-validator.d.ts.map +1 -0
- package/dist/utils/logging.d.ts +33 -0
- package/dist/utils/logging.d.ts.map +1 -0
- package/dist/utils/version.d.ts +9 -0
- package/dist/utils/version.d.ts.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import type { McpUiDownloadFileRequest, McpUiDownloadFileResult, McpUiHostCapabilities, McpUiHostContext, McpUiResourceCsp, McpUiResourcePermissions, McpUiSupportedContentBlockModalities } from "./ext-apps-bridge.js";
|
|
2
|
+
import type { CreateMessageRequest, CreateMessageResult, CreateMessageResultWithTools, Tool } from "@modelcontextprotocol/client";
|
|
3
|
+
export type { McpUiDownloadFileRequest, McpUiDownloadFileResult, McpUiHostCapabilities, McpUiHostContext, McpUiResourceCsp, McpUiResourcePermissions, McpUiSupportedContentBlockModalities, };
|
|
4
|
+
import type { Transport } from "@modelcontextprotocol/client";
|
|
5
|
+
import type { ReactNode } from "react";
|
|
6
|
+
/** Display mode requested by an MCP App. */
|
|
7
|
+
export type ViewDisplayMode = "inline" | "pip" | "fullscreen";
|
|
8
|
+
/** Policy used to enforce an MCP App's declared content security policy. */
|
|
9
|
+
export type ViewCspMode = "permissive" | "widget-declared";
|
|
10
|
+
/** Host operations and server metadata available to a live MCP App. */
|
|
11
|
+
export interface ViewConnection {
|
|
12
|
+
/** Calls an MCP server tool. */
|
|
13
|
+
callTool: (name: string, args?: Record<string, unknown>, options?: {
|
|
14
|
+
timeout?: number;
|
|
15
|
+
resetTimeoutOnProgress?: boolean;
|
|
16
|
+
}) => Promise<unknown>;
|
|
17
|
+
/** Reads an MCP resource by URI. */
|
|
18
|
+
readResource: (uri: string) => Promise<unknown>;
|
|
19
|
+
/** Tools available to the host, including app visibility metadata. */
|
|
20
|
+
tools?: readonly {
|
|
21
|
+
/** Tool name. */
|
|
22
|
+
name: string;
|
|
23
|
+
/** Optional tool metadata. */
|
|
24
|
+
_meta?: {
|
|
25
|
+
/** MCP App-specific tool metadata. */
|
|
26
|
+
ui?: {
|
|
27
|
+
/** Surfaces allowed to invoke or receive the tool. */
|
|
28
|
+
visibility?: readonly ("model" | "app")[];
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}[];
|
|
32
|
+
/** Resources available to the host. */
|
|
33
|
+
resources?: readonly {
|
|
34
|
+
/** Resource URI. */
|
|
35
|
+
uri: string;
|
|
36
|
+
/** Optional resource metadata. */
|
|
37
|
+
_meta?: {
|
|
38
|
+
/** MCP App-specific resource metadata. */
|
|
39
|
+
ui?: unknown;
|
|
40
|
+
};
|
|
41
|
+
}[];
|
|
42
|
+
}
|
|
43
|
+
/** Live or preloaded content used to initialize a {@link ViewRenderer}. */
|
|
44
|
+
export type ViewRendererSource = {
|
|
45
|
+
/** Selects live resource resolution. */
|
|
46
|
+
kind: "live";
|
|
47
|
+
/** MCP connection used to read the resource and call tools. */
|
|
48
|
+
connection: ViewConnection;
|
|
49
|
+
/** URI of the MCP App resource to load. */
|
|
50
|
+
resourceUri: string;
|
|
51
|
+
} | {
|
|
52
|
+
/** Selects preloaded HTML rendering. */
|
|
53
|
+
kind: "preloaded";
|
|
54
|
+
/** Complete HTML document to render. */
|
|
55
|
+
html: string;
|
|
56
|
+
/** CSP declared for the preloaded document. */
|
|
57
|
+
csp?: McpUiResourceCsp;
|
|
58
|
+
/** Browser permissions requested by the preloaded document. */
|
|
59
|
+
permissions?: McpUiResourcePermissions;
|
|
60
|
+
/** Whether the preloaded app prefers visible host borders. */
|
|
61
|
+
prefersBorder?: boolean;
|
|
62
|
+
};
|
|
63
|
+
/** Normalized HTML, CSP, permissions, and MIME metadata for a rendered view. */
|
|
64
|
+
export type ResolvedViewResource = {
|
|
65
|
+
/** HTML document rendered in the sandbox. */
|
|
66
|
+
html: string;
|
|
67
|
+
/** CSP declared by the resource before host policy is applied. */
|
|
68
|
+
declaredCsp: McpUiResourceCsp | undefined;
|
|
69
|
+
/** CSP enforced by the host, if any. */
|
|
70
|
+
csp: McpUiResourceCsp | undefined;
|
|
71
|
+
/** Browser permissions requested by the resource. */
|
|
72
|
+
permissions: McpUiResourcePermissions | undefined;
|
|
73
|
+
/** Whether the app prefers a visible host border. */
|
|
74
|
+
prefersBorder: boolean;
|
|
75
|
+
/** MIME type reported by the resource. */
|
|
76
|
+
mimeType: string | undefined;
|
|
77
|
+
/** Whether the MIME type is the MCP App resource media type. */
|
|
78
|
+
mimeTypeValid: boolean;
|
|
79
|
+
/** MIME validation warning, or `null` for a valid resource. */
|
|
80
|
+
mimeTypeWarning: string | null;
|
|
81
|
+
};
|
|
82
|
+
/** Browser CSP violation observed while an MCP App is running. */
|
|
83
|
+
export type ViewCspViolation = {
|
|
84
|
+
/** CSP directive reported by the browser. */
|
|
85
|
+
directive: string;
|
|
86
|
+
/** Effective CSP directive reported by the browser. */
|
|
87
|
+
effectiveDirective?: string;
|
|
88
|
+
/** URI blocked by the policy. */
|
|
89
|
+
blockedUri: string;
|
|
90
|
+
/** Source file associated with the violation. */
|
|
91
|
+
sourceFile?: string | null;
|
|
92
|
+
/** Source line associated with the violation. */
|
|
93
|
+
lineNumber?: number | null;
|
|
94
|
+
/** Source column associated with the violation. */
|
|
95
|
+
columnNumber?: number | null;
|
|
96
|
+
/** Original policy text reported by the browser. */
|
|
97
|
+
originalPolicy?: string;
|
|
98
|
+
/** Unix timestamp in milliseconds when the violation occurred. */
|
|
99
|
+
timestamp: number;
|
|
100
|
+
};
|
|
101
|
+
/** App-visible tools and the function used to call them. */
|
|
102
|
+
export type ViewAppToolConnection = {
|
|
103
|
+
/** Tools available to the app. */
|
|
104
|
+
tools: Tool[];
|
|
105
|
+
/** Calls an app-visible tool. */
|
|
106
|
+
callTool: (name: string, args?: Record<string, unknown>) => Promise<unknown>;
|
|
107
|
+
};
|
|
108
|
+
/** Lifecycle stage reported by a rendered MCP App. */
|
|
109
|
+
export type ViewLifecycleStatus = "resolving" | "sandbox-loading" | "connecting" | "initialized" | "ready" | "tearing-down" | "closed" | "error";
|
|
110
|
+
/** Lifecycle update emitted by {@link ViewRenderer}. */
|
|
111
|
+
export type ViewLifecycleEvent = {
|
|
112
|
+
/** Current lifecycle stage. */
|
|
113
|
+
status: ViewLifecycleStatus;
|
|
114
|
+
/** Error message when `status` is `"error"`. */
|
|
115
|
+
error?: string;
|
|
116
|
+
};
|
|
117
|
+
/** Props accepted by {@link ViewRenderer}. */
|
|
118
|
+
export interface ViewRendererProps {
|
|
119
|
+
/** Stable identifier for the view instance. */
|
|
120
|
+
viewId: string;
|
|
121
|
+
/** Live resource or preloaded HTML to render. */
|
|
122
|
+
source: ViewRendererSource;
|
|
123
|
+
/** Sandbox page URL or function that derives one from the resolved resource. */
|
|
124
|
+
sandboxUrl?: URL | ((resolved: ResolvedViewResource) => URL);
|
|
125
|
+
/** Tool associated with the view. */
|
|
126
|
+
toolName?: string;
|
|
127
|
+
/** Complete tool input forwarded to the app. */
|
|
128
|
+
toolInput?: Record<string, unknown>;
|
|
129
|
+
/** Tool result forwarded to the app. */
|
|
130
|
+
toolOutput?: unknown;
|
|
131
|
+
/** Partial streaming tool input forwarded to the app. */
|
|
132
|
+
partialToolInput?: Record<string, unknown>;
|
|
133
|
+
/** String-valued custom properties forwarded to the app. */
|
|
134
|
+
customProps?: Record<string, string>;
|
|
135
|
+
/** Whether the associated tool call was cancelled. */
|
|
136
|
+
cancelled?: boolean;
|
|
137
|
+
/** Host identity advertised to the app. */
|
|
138
|
+
hostInfo?: {
|
|
139
|
+
/** Stable host name. */
|
|
140
|
+
name: string;
|
|
141
|
+
/** Host version. */
|
|
142
|
+
version: string;
|
|
143
|
+
};
|
|
144
|
+
/** Initial host context sent to the app. */
|
|
145
|
+
hostContext?: McpUiHostContext;
|
|
146
|
+
/** Explicit host capability overrides. */
|
|
147
|
+
hostCapabilities?: Partial<McpUiHostCapabilities>;
|
|
148
|
+
/** Content modalities accepted by the host's message handler. */
|
|
149
|
+
messageCapabilities?: McpUiSupportedContentBlockModalities;
|
|
150
|
+
/** Content modalities accepted by the model-context handler. */
|
|
151
|
+
modelContextCapabilities?: McpUiSupportedContentBlockModalities;
|
|
152
|
+
/** CSP enforcement mode. Defaults to `"permissive"`. */
|
|
153
|
+
cspMode?: ViewCspMode;
|
|
154
|
+
/** Initial display mode. Defaults to `"inline"`. */
|
|
155
|
+
displayMode?: ViewDisplayMode;
|
|
156
|
+
/** Called when the app requests a supported display mode. */
|
|
157
|
+
onDisplayModeChange?: (mode: ViewDisplayMode) => void;
|
|
158
|
+
/** Maximum inline view width in pixels. */
|
|
159
|
+
inlineMaxWidth?: number;
|
|
160
|
+
/** Whether to hide the built-in view chrome. */
|
|
161
|
+
chromeless?: boolean;
|
|
162
|
+
/** Handles content the app sends to the conversation. */
|
|
163
|
+
onMessage?: (content: unknown[]) => void | Promise<void>;
|
|
164
|
+
/** Handles sampling requests from the app. */
|
|
165
|
+
onSamplingRequest?: (params: CreateMessageRequest["params"]) => Promise<CreateMessageResult | CreateMessageResultWithTools>;
|
|
166
|
+
/** Handles file-download requests from the app. */
|
|
167
|
+
onDownloadFile?: (params: McpUiDownloadFileRequest["params"]) => Promise<McpUiDownloadFileResult>;
|
|
168
|
+
/** Receives the current app-visible tool connection. */
|
|
169
|
+
onAppToolsChanged?: (connection: ViewAppToolConnection | null) => void;
|
|
170
|
+
/** Handles model-context updates from the app. */
|
|
171
|
+
onModelContextUpdate?: (ctx: {
|
|
172
|
+
content?: unknown;
|
|
173
|
+
structuredContent?: unknown;
|
|
174
|
+
}) => void | Promise<void>;
|
|
175
|
+
/** Handles structured log entries from the app. */
|
|
176
|
+
onLog?: (entry: {
|
|
177
|
+
level: string;
|
|
178
|
+
data: unknown;
|
|
179
|
+
}) => void;
|
|
180
|
+
/** Called when the app signals that it is ready. */
|
|
181
|
+
onReady?: () => void;
|
|
182
|
+
/** Called for each view lifecycle transition. */
|
|
183
|
+
onLifecycleChange?: (event: ViewLifecycleEvent) => void;
|
|
184
|
+
/** Called when view initialization or runtime handling fails. */
|
|
185
|
+
onError?: (message: string) => void;
|
|
186
|
+
/** Called when the browser reports a CSP violation. */
|
|
187
|
+
onCspViolation?: (violation: ViewCspViolation) => void;
|
|
188
|
+
/** Called after a live or preloaded resource is normalized. */
|
|
189
|
+
onResourceResolved?: (resolved: ResolvedViewResource) => void;
|
|
190
|
+
/** Wraps the host transport before it is connected to the app bridge. */
|
|
191
|
+
wrapTransport?: (transport: Transport, viewId: string) => Transport;
|
|
192
|
+
/** Timeout in milliseconds for app-initiated tool calls. Defaults to `600000`. */
|
|
193
|
+
toolCallTimeout?: number;
|
|
194
|
+
/** Dev mock of ChatGPT file APIs for local hosts (inspector). Default false. */
|
|
195
|
+
mockOpenAiFileApis?: boolean;
|
|
196
|
+
/** Fired when the guest reports inline height via ui/notifications/size-changed. */
|
|
197
|
+
onInlineHeightChange?: (height: number) => void;
|
|
198
|
+
/** Inspector-only chrome shown above the iframe in fullscreen display mode. */
|
|
199
|
+
fullscreenHeader?: {
|
|
200
|
+
/** Header title. */
|
|
201
|
+
title: string;
|
|
202
|
+
/** Optional header icon URL. */
|
|
203
|
+
iconUrl?: string | null;
|
|
204
|
+
};
|
|
205
|
+
/** Optional host close control for fullscreen (e.g. shared Button + icon). */
|
|
206
|
+
renderFullscreenClose?: (props: {
|
|
207
|
+
onClick: () => void;
|
|
208
|
+
"data-testid": string;
|
|
209
|
+
"aria-label": string;
|
|
210
|
+
}) => ReactNode;
|
|
211
|
+
/** Additional class name applied to the view container. */
|
|
212
|
+
className?: string;
|
|
213
|
+
/** Test identifier applied to the view container. */
|
|
214
|
+
testId?: string;
|
|
215
|
+
/** Status text shown while the associated tool is running. */
|
|
216
|
+
invoking?: string;
|
|
217
|
+
/** Status text shown after the associated tool completes. */
|
|
218
|
+
invoked?: string;
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/react/view/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,oCAAoC,EACrC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,oBAAoB,EACpB,mBAAmB,EACnB,4BAA4B,EAC5B,IAAI,EACL,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EACV,wBAAwB,EACxB,uBAAuB,EACvB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,wBAAwB,EACxB,oCAAoC,GACrC,CAAC;AACF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,4CAA4C;AAC5C,MAAM,MAAM,eAAe,GAAG,QAAQ,GAAG,KAAK,GAAG,YAAY,CAAC;AAE9D,4EAA4E;AAC5E,MAAM,MAAM,WAAW,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAE3D,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC7B,gCAAgC;IAChC,QAAQ,EAAE,CACR,IAAI,EAAE,MAAM,EACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,MAAM,CAAC;QAAC,sBAAsB,CAAC,EAAE,OAAO,CAAA;KAAE,KAC7D,OAAO,CAAC,OAAO,CAAC,CAAC;IACtB,oCAAoC;IACpC,YAAY,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,OA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KAAK,IAAI,CAAC;IACvD,+DAA+D;IAC/D,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAC9D,yEAAyE;IACzE,aAAa,CAAC,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,KAAK,SAAS,CAAC;IACpE,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gFAAgF;IAChF,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,oFAAoF;IACpF,oBAAoB,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE;QACjB,oBAAoB;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,gCAAgC;QAChC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KACzB,CAAC;IACF,8EAA8E;IAC9E,qBAAqB,CAAC,EAAE,CAAC,KAAK,EAAE;QAC9B,OAAO,EAAE,MAAM,IAAI,CAAC;QACpB,aAAa,EAAE,MAAM,CAAC;QACtB,YAAY,EAAE,MAAM,CAAC;KACtB,KAAK,SAAS,CAAC;IAChB,2DAA2D;IAC3D,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6DAA6D;IAC7D,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
import type { ViewDisplayMode } from "./types.js";
|
|
3
|
+
export declare function useViewDisplayModeControls({ displayMode, setDisplayMode, }: {
|
|
4
|
+
containerRef: RefObject<HTMLElement | null>;
|
|
5
|
+
displayMode: ViewDisplayMode;
|
|
6
|
+
setDisplayMode: (mode: ViewDisplayMode) => void;
|
|
7
|
+
}): {
|
|
8
|
+
handleDisplayModeChange: (mode: ViewDisplayMode) => void;
|
|
9
|
+
fullscreenShellClassName: string | undefined;
|
|
10
|
+
pipShellClassName: string | undefined;
|
|
11
|
+
isFullscreen: boolean;
|
|
12
|
+
isPip: boolean;
|
|
13
|
+
};
|
|
14
|
+
export declare const VIEW_DIMENSIONS: {
|
|
15
|
+
readonly PIP_MAX_WIDTH: 700;
|
|
16
|
+
readonly DEFAULT_HEIGHT: 400;
|
|
17
|
+
readonly FULLSCREEN_HEADER_HEIGHT: 50;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=use-display-mode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-display-mode.d.ts","sourceRoot":"","sources":["../../../src/react/view/use-display-mode.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAC/D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmDlD,wBAAgB,0BAA0B,CAAC,EACzC,WAAW,EACX,cAAc,GACf,EAAE;IACD,YAAY,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IAC5C,WAAW,EAAE,eAAe,CAAC;IAC7B,cAAc,EAAE,CAAC,IAAI,EAAE,eAAe,KAAK,IAAI,CAAC;CACjD;oCAOU,eAAe;;;;;EAazB;AAED,eAAO,MAAM,eAAe;;;;CAIlB,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads the MCP App resource URI from tool metadata.
|
|
3
|
+
*
|
|
4
|
+
* @param toolMeta - Tool `_meta` object.
|
|
5
|
+
* @returns The declared view resource URI, or `null` when none is declared.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getViewResourceUri(toolMeta?: Record<string, unknown>): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Tests whether tool metadata declares an MCP App resource.
|
|
10
|
+
*
|
|
11
|
+
* @param toolMeta - Tool `_meta` object.
|
|
12
|
+
* @returns `true` when the tool declares a view resource URI.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isViewTool(toolMeta?: Record<string, unknown>): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Tests whether a resource uses the MCP App HTML media type.
|
|
17
|
+
*
|
|
18
|
+
* @param mimeType - Resource MIME type.
|
|
19
|
+
* @returns `true` for the MCP App resource media type.
|
|
20
|
+
*/
|
|
21
|
+
export declare function isViewResource(mimeType?: string): boolean;
|
|
22
|
+
//# sourceMappingURL=view-detection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-detection.d.ts","sourceRoot":"","sources":["../../../src/react/view/view-detection.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,MAAM,GAAG,IAAI,CAWf;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAEtE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAEzD"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { McpUiHostCapabilities, McpUiSupportedContentBlockModalities } from "./ext-apps-bridge.js";
|
|
2
|
+
import type { ViewConnection, ViewDisplayMode } from "./types.js";
|
|
3
|
+
/** Inputs used to derive the capabilities advertised by an MCP App host. */
|
|
4
|
+
type CapabilityInputs = {
|
|
5
|
+
hasConnection: boolean;
|
|
6
|
+
hasMessageHandler: boolean;
|
|
7
|
+
hasModelContextHandler: boolean;
|
|
8
|
+
hasLogHandler: boolean;
|
|
9
|
+
hasSamplingHandler?: boolean;
|
|
10
|
+
hasDownloadHandler?: boolean;
|
|
11
|
+
messageCapabilities?: McpUiSupportedContentBlockModalities;
|
|
12
|
+
modelContextCapabilities?: McpUiSupportedContentBlockModalities;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Builds host capabilities from the callbacks and connections the host exposes.
|
|
16
|
+
*
|
|
17
|
+
* @param inputs - Available host features and supported content modalities.
|
|
18
|
+
* @returns Capabilities suitable for MCP App bridge initialization.
|
|
19
|
+
*/
|
|
20
|
+
export declare function buildDefaultHostCapabilities({ hasConnection, hasMessageHandler, hasModelContextHandler, hasLogHandler, hasSamplingHandler, hasDownloadHandler, messageCapabilities, modelContextCapabilities, }: CapabilityInputs): McpUiHostCapabilities;
|
|
21
|
+
/**
|
|
22
|
+
* Tests whether a tool is visible to the model.
|
|
23
|
+
*
|
|
24
|
+
* Tools without explicit visibility metadata remain model-visible.
|
|
25
|
+
*
|
|
26
|
+
* @param tool - Tool metadata to inspect.
|
|
27
|
+
* @returns `true` when the tool may be presented to the model.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isToolVisibleToModel(tool: {
|
|
30
|
+
_meta?: unknown;
|
|
31
|
+
}): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Validates and dispatches an MCP App `ui/message` payload.
|
|
34
|
+
*
|
|
35
|
+
* @param handler - Host callback that accepts message content.
|
|
36
|
+
* @param content - Content blocks supplied by the app.
|
|
37
|
+
* @throws When the host has no message handler or `content` is empty.
|
|
38
|
+
*/
|
|
39
|
+
export declare function dispatchUiMessage(handler: ((content: unknown[]) => void | Promise<void>) | undefined, content: unknown[]): Promise<void>;
|
|
40
|
+
/**
|
|
41
|
+
* Resolves a display-mode request against host and app availability.
|
|
42
|
+
*
|
|
43
|
+
* @param options - Requested and current modes plus each side's supported modes.
|
|
44
|
+
* @returns The requested mode when both sides support it; otherwise `current`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function resolveRequestedDisplayMode({ requested, current, hostAvailable, appAvailable, }: {
|
|
47
|
+
requested: ViewDisplayMode;
|
|
48
|
+
current: ViewDisplayMode;
|
|
49
|
+
hostAvailable?: readonly ViewDisplayMode[];
|
|
50
|
+
appAvailable?: readonly ViewDisplayMode[];
|
|
51
|
+
}): ViewDisplayMode;
|
|
52
|
+
/**
|
|
53
|
+
* Asserts that an MCP App may call a named server tool.
|
|
54
|
+
*
|
|
55
|
+
* @param tools - Tools available through the live view connection.
|
|
56
|
+
* @param name - Tool name requested by the app.
|
|
57
|
+
* @throws When the tool is unavailable or not visible to apps.
|
|
58
|
+
*/
|
|
59
|
+
export declare function assertAppCanCallTool(tools: ViewConnection["tools"], name: string): void;
|
|
60
|
+
export {};
|
|
61
|
+
//# sourceMappingURL=view-host-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"view-host-policy.d.ts","sourceRoot":"","sources":["../../../src/react/view/view-host-policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,oCAAoC,EACrC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElE,4EAA4E;AAC5E,KAAK,gBAAgB,GAAG;IACtB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,sBAAsB,EAAE,OAAO,CAAC;IAChC,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,mBAAmB,CAAC,EAAE,oCAAoC,CAAC;IAC3D,wBAAwB,CAAC,EAAE,oCAAoC,CAAC;CACjE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAAC,EAC3C,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,wBAAwB,GACzB,EAAE,gBAAgB,GAAG,qBAAqB,CAmB1C;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,OAAO,CAQvE;AAED;;;;;;GAMG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,EACnE,OAAO,EAAE,OAAO,EAAE,GACjB,OAAO,CAAC,IAAI,CAAC,CAQf;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,SAAS,EACT,OAAO,EACP,aAAa,EACb,YAAY,GACb,EAAE;IACD,SAAS,EAAE,eAAe,CAAC;IAC3B,OAAO,EAAE,eAAe,CAAC;IACzB,aAAa,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;IAC3C,YAAY,CAAC,EAAE,SAAS,eAAe,EAAE,CAAC;CAC3C,GAAG,eAAe,CAMlB;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,EAC9B,IAAI,EAAE,MAAM,GACX,IAAI,CAUN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kCAAkC,CAAC"}
|
package/dist/sandbox.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
// src/react/view/sandbox-blob-url.ts
|
|
2
|
+
var SANDBOX_PROXY_HTML = `<!doctype html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta
|
|
7
|
+
http-equiv="Content-Security-Policy"
|
|
8
|
+
content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src * 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data:; style-src * blob: data: 'unsafe-inline'; connect-src * data: blob: about:; frame-src * blob: data: http://localhost:* https://localhost:* http://127.0.0.1:* https://127.0.0.1:*;"
|
|
9
|
+
/>
|
|
10
|
+
<title>MCP Apps Sandbox Proxy</title>
|
|
11
|
+
<style>
|
|
12
|
+
html, body { margin: 0; padding: 0; height: 100%; width: 100%; overflow: hidden; }
|
|
13
|
+
* { box-sizing: border-box; }
|
|
14
|
+
iframe { display: block; background-color: transparent; border: 0px none transparent; padding: 0px; width: 100%; height: 100%; }
|
|
15
|
+
</style>
|
|
16
|
+
</head>
|
|
17
|
+
<body>
|
|
18
|
+
<script>
|
|
19
|
+
function sanitizeDomain(domain) {
|
|
20
|
+
if (typeof domain !== "string") return "";
|
|
21
|
+
return domain.replace(/['"<>;]/g, "").trim();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function buildAllowAttribute(permissions) {
|
|
25
|
+
if (!permissions) return "";
|
|
26
|
+
const allowList = [];
|
|
27
|
+
if (permissions.camera) allowList.push("camera *");
|
|
28
|
+
if (permissions.microphone) allowList.push("microphone *");
|
|
29
|
+
if (permissions.geolocation) allowList.push("geolocation *");
|
|
30
|
+
if (permissions.clipboardWrite) allowList.push("clipboard-write *");
|
|
31
|
+
return allowList.join("; ");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function buildCSP(csp) {
|
|
35
|
+
if (!csp) {
|
|
36
|
+
return [
|
|
37
|
+
"default-src 'none'",
|
|
38
|
+
"script-src 'unsafe-inline'",
|
|
39
|
+
"style-src 'unsafe-inline'",
|
|
40
|
+
"img-src data:",
|
|
41
|
+
"font-src data:",
|
|
42
|
+
"media-src data:",
|
|
43
|
+
"connect-src 'none'",
|
|
44
|
+
"frame-src 'none'",
|
|
45
|
+
"object-src 'none'",
|
|
46
|
+
"base-uri 'none'",
|
|
47
|
+
].join("; ");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const connectDomains = (csp.connectDomains || []).map(sanitizeDomain).filter(Boolean);
|
|
51
|
+
const resourceDomains = (csp.resourceDomains || []).map(sanitizeDomain).filter(Boolean);
|
|
52
|
+
const frameDomains = (csp.frameDomains || []).map(sanitizeDomain).filter(Boolean);
|
|
53
|
+
const baseUriDomains = (csp.baseUriDomains || []).map(sanitizeDomain).filter(Boolean);
|
|
54
|
+
const scriptDirectives = (csp.scriptDirectives || []).filter(function(d) { return typeof d === "string" && d.length > 0; });
|
|
55
|
+
|
|
56
|
+
const connectSrc = connectDomains.length > 0 ? connectDomains.join(" ") : "'none'";
|
|
57
|
+
const resourceSrc = resourceDomains.length > 0 ? ["data:", "blob:", ...resourceDomains].join(" ") : "data: blob:";
|
|
58
|
+
const frameSrc = frameDomains.length > 0 ? frameDomains.join(" ") : "'none'";
|
|
59
|
+
const baseUri = baseUriDomains.length > 0 ? baseUriDomains.join(" ") : "'none'";
|
|
60
|
+
const scriptSrcParts = ["'unsafe-inline'", "'unsafe-eval'", resourceSrc];
|
|
61
|
+
if (scriptDirectives.length > 0) scriptSrcParts.push(scriptDirectives.join(" "));
|
|
62
|
+
|
|
63
|
+
return [
|
|
64
|
+
"default-src 'none'",
|
|
65
|
+
"script-src " + scriptSrcParts.join(" "),
|
|
66
|
+
"style-src 'unsafe-inline' " + resourceSrc,
|
|
67
|
+
"img-src " + resourceSrc,
|
|
68
|
+
"font-src " + resourceSrc,
|
|
69
|
+
"media-src " + resourceSrc,
|
|
70
|
+
"connect-src " + connectSrc,
|
|
71
|
+
"frame-src " + frameSrc,
|
|
72
|
+
"object-src 'none'",
|
|
73
|
+
"base-uri " + baseUri,
|
|
74
|
+
].join("; ");
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function buildViolationListenerScript() {
|
|
78
|
+
return \`<script>
|
|
79
|
+
document.addEventListener('securitypolicyviolation', function(e) {
|
|
80
|
+
var violation = {
|
|
81
|
+
type: 'mcp-apps:csp-violation',
|
|
82
|
+
directive: e.violatedDirective,
|
|
83
|
+
blockedUri: e.blockedURI,
|
|
84
|
+
sourceFile: e.sourceFile || null,
|
|
85
|
+
lineNumber: e.lineNumber || null,
|
|
86
|
+
columnNumber: e.columnNumber || null,
|
|
87
|
+
effectiveDirective: e.effectiveDirective,
|
|
88
|
+
originalPolicy: e.originalPolicy,
|
|
89
|
+
disposition: e.disposition,
|
|
90
|
+
timestamp: Date.now()
|
|
91
|
+
};
|
|
92
|
+
console.warn('[MCP Apps CSP Violation]', violation.directive, ':', violation.blockedUri);
|
|
93
|
+
window.parent.postMessage(violation, '*');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
function serializeConsoleArgs(args) {
|
|
97
|
+
try {
|
|
98
|
+
return Array.from(args || []).map(function(arg) {
|
|
99
|
+
if (arg instanceof Error) {
|
|
100
|
+
return {
|
|
101
|
+
type: 'Error',
|
|
102
|
+
message: arg.message,
|
|
103
|
+
stack: arg.stack,
|
|
104
|
+
name: arg.name,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if (typeof arg === 'object' && arg !== null) {
|
|
108
|
+
try {
|
|
109
|
+
return JSON.parse(JSON.stringify(arg));
|
|
110
|
+
} catch (e) {
|
|
111
|
+
return String(arg);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return arg;
|
|
115
|
+
});
|
|
116
|
+
} catch (e) {
|
|
117
|
+
return [String(args)];
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function sendConsoleToParent(level, args) {
|
|
122
|
+
try {
|
|
123
|
+
window.parent.postMessage({
|
|
124
|
+
type: 'iframe-console-log',
|
|
125
|
+
level: level,
|
|
126
|
+
args: serializeConsoleArgs(args),
|
|
127
|
+
timestamp: new Date().toISOString(),
|
|
128
|
+
url: window.location.href,
|
|
129
|
+
}, '*');
|
|
130
|
+
} catch (e) {}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
var originalConsoleError = console.error.bind(console);
|
|
134
|
+
console.error = function() {
|
|
135
|
+
var args = Array.from(arguments);
|
|
136
|
+
originalConsoleError.apply(console, args);
|
|
137
|
+
sendConsoleToParent('error', args);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
window.addEventListener('error', function(event) {
|
|
141
|
+
sendConsoleToParent('error', [{
|
|
142
|
+
message: event.message,
|
|
143
|
+
filename: event.filename,
|
|
144
|
+
lineno: event.lineno,
|
|
145
|
+
colno: event.colno,
|
|
146
|
+
error: event.error ? {
|
|
147
|
+
message: event.error.message,
|
|
148
|
+
stack: event.error.stack,
|
|
149
|
+
name: event.error.name,
|
|
150
|
+
} : null,
|
|
151
|
+
}]);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
window.addEventListener('unhandledrejection', function(event) {
|
|
155
|
+
sendConsoleToParent('error', [{
|
|
156
|
+
message: 'Unhandled Promise Rejection',
|
|
157
|
+
reason: event.reason ? String(event.reason) : 'Unknown',
|
|
158
|
+
error: event.reason instanceof Error ? {
|
|
159
|
+
message: event.reason.message,
|
|
160
|
+
stack: event.reason.stack,
|
|
161
|
+
name: event.reason.name,
|
|
162
|
+
} : null,
|
|
163
|
+
}]);
|
|
164
|
+
});
|
|
165
|
+
</\` + \`script>\`;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function injectCSP(html, cspValue) {
|
|
169
|
+
const cspMeta = '<meta http-equiv="Content-Security-Policy" content="' + cspValue + '">';
|
|
170
|
+
const violationListener = buildViolationListenerScript();
|
|
171
|
+
const injection = cspMeta + violationListener;
|
|
172
|
+
|
|
173
|
+
if (html.includes("<head>")) {
|
|
174
|
+
return html.replace("<head>", "<head>" + injection);
|
|
175
|
+
} else if (html.includes("<HEAD>")) {
|
|
176
|
+
return html.replace("<HEAD>", "<HEAD>" + injection);
|
|
177
|
+
} else if (html.includes("<html>")) {
|
|
178
|
+
return html.replace("<html>", "<html><head>" + injection + "</head>");
|
|
179
|
+
} else if (html.includes("<HTML>")) {
|
|
180
|
+
return html.replace("<HTML>", "<HTML><head>" + injection + "</head>");
|
|
181
|
+
} else if (html.includes("<!DOCTYPE") || html.includes("<!doctype")) {
|
|
182
|
+
return html.replace(/(<!DOCTYPE[^>]*>|<!doctype[^>]*>)/i, "$1<head>" + injection + "</head>");
|
|
183
|
+
} else {
|
|
184
|
+
return injection + html;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Query params from host (csp_mode, permissions, widget_csp). AppFrame only
|
|
189
|
+
// sends { html, csp } in sandbox-resource-ready; we carry the rest on the URL.
|
|
190
|
+
// Blob URLs cannot reliably carry search params, so the CDN shell injects
|
|
191
|
+
// window.__SANDBOX_SEARCH__ via buildSandboxProxyBlobHtml.
|
|
192
|
+
const query = new URLSearchParams(
|
|
193
|
+
typeof window.__SANDBOX_SEARCH__ === "string"
|
|
194
|
+
? window.__SANDBOX_SEARCH__
|
|
195
|
+
: location.search
|
|
196
|
+
);
|
|
197
|
+
const queryCspMode = query.get("csp_mode") || "permissive";
|
|
198
|
+
let queryPermissions = null;
|
|
199
|
+
let queryWidgetCsp = null;
|
|
200
|
+
try {
|
|
201
|
+
const rawPerm = query.get("permissions");
|
|
202
|
+
if (rawPerm) queryPermissions = JSON.parse(rawPerm);
|
|
203
|
+
} catch (e) {}
|
|
204
|
+
try {
|
|
205
|
+
const rawCsp = query.get("widget_csp");
|
|
206
|
+
if (rawCsp) queryWidgetCsp = JSON.parse(rawCsp);
|
|
207
|
+
} catch (e) {}
|
|
208
|
+
|
|
209
|
+
const inner = document.createElement("iframe");
|
|
210
|
+
inner.style = "width:100%; height:100%; border:none;";
|
|
211
|
+
inner.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
|
|
212
|
+
document.body.appendChild(inner);
|
|
213
|
+
|
|
214
|
+
window.addEventListener("message", async (event) => {
|
|
215
|
+
if (event.source === window.parent) {
|
|
216
|
+
if (event.data && event.data.method === "ui/notifications/sandbox-resource-ready") {
|
|
217
|
+
const params = event.data.params || {};
|
|
218
|
+
const html = params.html;
|
|
219
|
+
const sandbox = params.sandbox;
|
|
220
|
+
// Prefer message csp when present; fall back to URL widget_csp
|
|
221
|
+
const csp = params.csp != null ? params.csp : queryWidgetCsp;
|
|
222
|
+
const permissions = params.permissions != null ? params.permissions : queryPermissions;
|
|
223
|
+
const permissive =
|
|
224
|
+
typeof params.permissive === "boolean"
|
|
225
|
+
? params.permissive
|
|
226
|
+
: queryCspMode === "permissive";
|
|
227
|
+
if (typeof sandbox === "string") {
|
|
228
|
+
inner.setAttribute("sandbox", sandbox);
|
|
229
|
+
}
|
|
230
|
+
const allowAttribute = buildAllowAttribute(permissions);
|
|
231
|
+
if (allowAttribute) {
|
|
232
|
+
inner.setAttribute("allow", allowAttribute);
|
|
233
|
+
}
|
|
234
|
+
if (typeof html === "string") {
|
|
235
|
+
if (permissive) {
|
|
236
|
+
const permissiveCsp = [
|
|
237
|
+
"default-src * 'unsafe-inline' 'unsafe-eval' data: blob: filesystem: about:",
|
|
238
|
+
"script-src * 'unsafe-inline' 'unsafe-eval' data: blob:",
|
|
239
|
+
"style-src * 'unsafe-inline' data: blob:",
|
|
240
|
+
"img-src * data: blob: https: http:",
|
|
241
|
+
"media-src * data: blob: https: http:",
|
|
242
|
+
"font-src * data: blob: https: http:",
|
|
243
|
+
"connect-src * data: blob: https: http: ws: wss: about:",
|
|
244
|
+
"frame-src * data: blob: https: http: about:",
|
|
245
|
+
"object-src * data: blob:",
|
|
246
|
+
"base-uri *",
|
|
247
|
+
"form-action *",
|
|
248
|
+
].join("; ");
|
|
249
|
+
const processedHtml = injectCSP(html, permissiveCsp);
|
|
250
|
+
inner.srcdoc = processedHtml;
|
|
251
|
+
} else {
|
|
252
|
+
const cspValue = buildCSP(csp);
|
|
253
|
+
const processedHtml = injectCSP(html, cspValue);
|
|
254
|
+
inner.srcdoc = processedHtml;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
} else {
|
|
258
|
+
if (inner && inner.contentWindow) {
|
|
259
|
+
inner.contentWindow.postMessage(event.data, "*");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
} else if (event.source === inner.contentWindow) {
|
|
263
|
+
window.parent.postMessage(event.data, "*");
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
window.parent.postMessage({
|
|
268
|
+
jsonrpc: "2.0",
|
|
269
|
+
method: "ui/notifications/sandbox-proxy-ready",
|
|
270
|
+
params: {},
|
|
271
|
+
}, "*");
|
|
272
|
+
</script>
|
|
273
|
+
</body>
|
|
274
|
+
</html>`;
|
|
275
|
+
function buildSandboxProxyBlobHtml(search) {
|
|
276
|
+
const escaped = JSON.stringify(search).replace(/</g, "\\u003c");
|
|
277
|
+
const inject = "<script>window.__SANDBOX_SEARCH__ = " + escaped + ";</script>";
|
|
278
|
+
return SANDBOX_PROXY_HTML.replace(
|
|
279
|
+
` const scriptSrcParts = ["'unsafe-inline'", "'unsafe-eval'", resourceSrc];
|
|
280
|
+
`,
|
|
281
|
+
` const scriptSrcParts = ["'unsafe-inline'", resourceSrc];
|
|
282
|
+
`
|
|
283
|
+
).replace("<body>", "<body>" + inject);
|
|
284
|
+
}
|
|
285
|
+
export {
|
|
286
|
+
buildSandboxProxyBlobHtml
|
|
287
|
+
};
|
|
288
|
+
//# sourceMappingURL=sandbox.js.map
|