@mcpjam/widget-react 0.1.11 → 0.1.12
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/index.d.ts +120 -33
- package/dist/index.js +181 -27
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -847,15 +847,38 @@ function parseSandboxOrigin(value) {
|
|
|
847
847
|
}
|
|
848
848
|
return parsed.origin;
|
|
849
849
|
}
|
|
850
|
+
var VIEW_ORIGIN_LABEL = /^[a-f0-9]{16}$/;
|
|
851
|
+
function labelledOrigin(origin, label, userAgent) {
|
|
852
|
+
let url;
|
|
853
|
+
try {
|
|
854
|
+
url = new URL(origin);
|
|
855
|
+
} catch {
|
|
856
|
+
return null;
|
|
857
|
+
}
|
|
858
|
+
const isLoopback = url.hostname === "localhost" || url.hostname === "127.0.0.1";
|
|
859
|
+
if (isLoopback) {
|
|
860
|
+
const chromiumOrFirefox = /Chrome\/|Chromium\/|Firefox\//.test(userAgent) && !/^((?!Chrome|Chromium).)*Safari/.test(userAgent);
|
|
861
|
+
if (!chromiumOrFirefox) return null;
|
|
862
|
+
url.hostname = `${label}.localhost`;
|
|
863
|
+
} else {
|
|
864
|
+
url.hostname = `${label}.${url.hostname}`;
|
|
865
|
+
}
|
|
866
|
+
return url.origin;
|
|
867
|
+
}
|
|
850
868
|
function resolveSandboxProxyUrl({
|
|
851
869
|
hostedMode,
|
|
852
870
|
sandboxOrigin,
|
|
853
|
-
location
|
|
871
|
+
location,
|
|
872
|
+
viewOriginLabel,
|
|
873
|
+
viewSubdomainsEnabled,
|
|
874
|
+
userAgent
|
|
854
875
|
}) {
|
|
855
876
|
const proxyPath = hostedMode ? "/api/web/apps/mcp-apps/sandbox-proxy" : "/api/apps/mcp-apps/sandbox-proxy";
|
|
877
|
+
const label = viewSubdomainsEnabled && typeof viewOriginLabel === "string" && VIEW_ORIGIN_LABEL.test(viewOriginLabel) ? viewOriginLabel : null;
|
|
856
878
|
const configuredOrigin = hostedMode ? parseSandboxOrigin(sandboxOrigin) : null;
|
|
857
879
|
if (configuredOrigin && configuredOrigin !== location.origin) {
|
|
858
|
-
|
|
880
|
+
const perApp2 = label ? labelledOrigin(configuredOrigin, label, userAgent ?? "") : null;
|
|
881
|
+
return `${perApp2 ?? configuredOrigin}${proxyPath}?v=${Date.now()}`;
|
|
859
882
|
}
|
|
860
883
|
const currentHost = location.hostname;
|
|
861
884
|
const currentPort = location.port;
|
|
@@ -880,7 +903,9 @@ function resolveSandboxProxyUrl({
|
|
|
880
903
|
sandboxHost = currentHost;
|
|
881
904
|
}
|
|
882
905
|
const portSuffix = currentPort ? `:${currentPort}` : "";
|
|
883
|
-
|
|
906
|
+
const baseOrigin = `${protocol}//${sandboxHost}${portSuffix}`;
|
|
907
|
+
const perApp = label ? labelledOrigin(baseOrigin, label, userAgent ?? "") : null;
|
|
908
|
+
return `${perApp ?? baseOrigin}${proxyPath}?v=${Date.now()}`;
|
|
884
909
|
}
|
|
885
910
|
var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
886
911
|
html,
|
|
@@ -901,7 +926,10 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
901
926
|
colorScheme,
|
|
902
927
|
title = "Sandboxed Content",
|
|
903
928
|
hostedMode = false,
|
|
904
|
-
sandboxOrigin = ""
|
|
929
|
+
sandboxOrigin = "",
|
|
930
|
+
mountMode,
|
|
931
|
+
viewOriginLabel,
|
|
932
|
+
viewSubdomainsEnabled
|
|
905
933
|
}, ref) {
|
|
906
934
|
const outerRef = useRef(null);
|
|
907
935
|
const [proxyReady, setProxyReady] = useState(false);
|
|
@@ -910,12 +938,17 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
910
938
|
const onProxyReadyRef = useRef(onProxyReady);
|
|
911
939
|
onMessageRef.current = onMessage;
|
|
912
940
|
onProxyReadyRef.current = onProxyReady;
|
|
913
|
-
const
|
|
941
|
+
const sandboxProxyUrl = useMemo(
|
|
914
942
|
() => resolveSandboxProxyUrl({
|
|
915
943
|
hostedMode,
|
|
916
944
|
sandboxOrigin,
|
|
917
|
-
location: window.location
|
|
918
|
-
|
|
945
|
+
location: window.location,
|
|
946
|
+
viewOriginLabel,
|
|
947
|
+
viewSubdomainsEnabled,
|
|
948
|
+
userAgent: typeof navigator === "undefined" ? "" : navigator.userAgent
|
|
949
|
+
}),
|
|
950
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
951
|
+
[hostedMode, sandboxOrigin, viewOriginLabel, viewSubdomainsEnabled]
|
|
919
952
|
);
|
|
920
953
|
const sandboxProxyOrigin = useMemo(() => {
|
|
921
954
|
try {
|
|
@@ -948,6 +981,14 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
948
981
|
onMessageRef.current(event);
|
|
949
982
|
return;
|
|
950
983
|
}
|
|
984
|
+
if (event.data?.type === "mcpjam:view-mode") {
|
|
985
|
+
onMessageRef.current(event);
|
|
986
|
+
return;
|
|
987
|
+
}
|
|
988
|
+
if (event.data?.type === "mcpjam:csp-applied") {
|
|
989
|
+
onMessageRef.current(event);
|
|
990
|
+
return;
|
|
991
|
+
}
|
|
951
992
|
if (event.data?.type === "recorder:step" || event.data?.type === "recorder:ready" || event.data?.type === "recorder:replay-result") {
|
|
952
993
|
recorderDebug(`forward ${event.data.type}`);
|
|
953
994
|
onMessageRef.current(event);
|
|
@@ -992,7 +1033,10 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
992
1033
|
sandboxAttrs: sandboxAttrs ?? null,
|
|
993
1034
|
// Include recordMode so record-capable surfaces receive the recorder
|
|
994
1035
|
// shim, and stale/non-recordable surfaces reload without it.
|
|
995
|
-
recordMode: recordMode ?? null
|
|
1036
|
+
recordMode: recordMode ?? null,
|
|
1037
|
+
// Part of the render recipe: it decides how the proxy mounts the HTML,
|
|
1038
|
+
// so a change must re-send rather than leave the previous mount up.
|
|
1039
|
+
mountMode: mountMode ?? null
|
|
996
1040
|
}),
|
|
997
1041
|
[
|
|
998
1042
|
csp,
|
|
@@ -1004,7 +1048,8 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1004
1048
|
permissions,
|
|
1005
1049
|
sandbox,
|
|
1006
1050
|
sandboxAttrs,
|
|
1007
|
-
recordMode
|
|
1051
|
+
recordMode,
|
|
1052
|
+
mountMode
|
|
1008
1053
|
]
|
|
1009
1054
|
);
|
|
1010
1055
|
useEffect(() => {
|
|
@@ -1038,7 +1083,8 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1038
1083
|
permissive,
|
|
1039
1084
|
colorScheme,
|
|
1040
1085
|
recordMode,
|
|
1041
|
-
recorderDebug: isRecorderDebugEnabled()
|
|
1086
|
+
recorderDebug: isRecorderDebugEnabled(),
|
|
1087
|
+
mountMode
|
|
1042
1088
|
}
|
|
1043
1089
|
},
|
|
1044
1090
|
sandboxProxyOrigin
|
|
@@ -1065,7 +1111,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1065
1111
|
const iframeStyle = colorScheme ? { ...style, colorScheme } : style;
|
|
1066
1112
|
useEffect(() => {
|
|
1067
1113
|
setProxyReady(false);
|
|
1068
|
-
}, [outerSandboxAttribute]);
|
|
1114
|
+
}, [outerSandboxAttribute, sandboxProxyOrigin]);
|
|
1069
1115
|
return /* @__PURE__ */ jsx(
|
|
1070
1116
|
"iframe",
|
|
1071
1117
|
{
|
|
@@ -1077,7 +1123,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1077
1123
|
className,
|
|
1078
1124
|
style: iframeStyle
|
|
1079
1125
|
},
|
|
1080
|
-
outerSandboxAttribute
|
|
1126
|
+
`${sandboxProxyOrigin}\0${outerSandboxAttribute}`
|
|
1081
1127
|
);
|
|
1082
1128
|
});
|
|
1083
1129
|
function McpAppsModal({
|
|
@@ -1333,6 +1379,8 @@ function McpAppsModal({
|
|
|
1333
1379
|
title: `MCP App Modal: ${title}`,
|
|
1334
1380
|
hostedMode: host.surface.hostedMode,
|
|
1335
1381
|
sandboxOrigin: host.surface.sandboxOrigin,
|
|
1382
|
+
mountMode: host.surface.viewMountMode,
|
|
1383
|
+
viewSubdomainsEnabled: host.surface.viewSubdomainsEnabled,
|
|
1336
1384
|
className: "min-w-full border-0 rounded-md bg-transparent overflow-hidden",
|
|
1337
1385
|
style: {
|
|
1338
1386
|
height: "100%",
|
|
@@ -1360,7 +1408,7 @@ async function handleUploadFileMessage(data, sendResponse, { authFetch, hostedMo
|
|
|
1360
1408
|
sendResponse({
|
|
1361
1409
|
type: "openai:uploadFile:response",
|
|
1362
1410
|
callId: uploadCallId,
|
|
1363
|
-
error: "File upload
|
|
1411
|
+
error: "File upload isn\u2019t available in MCPJam\u2019s hosted web app. To use it, run npx @mcpjam/inspector@latest on your computer or use the MCPJam desktop app."
|
|
1364
1412
|
});
|
|
1365
1413
|
return;
|
|
1366
1414
|
}
|
|
@@ -1403,7 +1451,7 @@ function handleGetFileDownloadUrlMessage(data, sendResponse, { hostedMode }) {
|
|
|
1403
1451
|
sendResponse({
|
|
1404
1452
|
type: "openai:getFileDownloadUrl:response",
|
|
1405
1453
|
callId: dlCallId,
|
|
1406
|
-
error: "File download
|
|
1454
|
+
error: "File download isn\u2019t available in MCPJam\u2019s hosted web app. To use it, run npx @mcpjam/inspector@latest on your computer or use the MCPJam desktop app."
|
|
1407
1455
|
});
|
|
1408
1456
|
return;
|
|
1409
1457
|
}
|
|
@@ -1563,8 +1611,12 @@ var NOOP_WIDGET_DEBUG_SINK = {
|
|
|
1563
1611
|
},
|
|
1564
1612
|
setWidgetCsp: () => {
|
|
1565
1613
|
},
|
|
1614
|
+
setWidgetAppliedCsp: () => {
|
|
1615
|
+
},
|
|
1566
1616
|
addCspViolation: () => {
|
|
1567
1617
|
},
|
|
1618
|
+
reportCspViolation: () => {
|
|
1619
|
+
},
|
|
1568
1620
|
clearCspViolations: () => {
|
|
1569
1621
|
},
|
|
1570
1622
|
setWidgetModelContext: () => {
|
|
@@ -1583,6 +1635,24 @@ var SUPPRESSED_UI_LOG_METHODS = /* @__PURE__ */ new Set(["ui/notifications/size-
|
|
|
1583
1635
|
var PIP_MAX_HEIGHT = "min(40vh, 600px)";
|
|
1584
1636
|
var CSP_BLOCKED_NOTICE_DELAY_MS = 1500;
|
|
1585
1637
|
var SAFE_OPEN_IN_APP_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
1638
|
+
function normalizeCspMountId(value) {
|
|
1639
|
+
if (typeof value === "number") {
|
|
1640
|
+
return Number.isInteger(value) && value > 0 ? value : void 0;
|
|
1641
|
+
}
|
|
1642
|
+
if (typeof value !== "string") return void 0;
|
|
1643
|
+
const trimmed = value.trim();
|
|
1644
|
+
return trimmed.length > 0 && trimmed.length <= 128 ? trimmed : void 0;
|
|
1645
|
+
}
|
|
1646
|
+
function normalizeCspApplicationIntent(value) {
|
|
1647
|
+
if (!value || typeof value !== "object") return void 0;
|
|
1648
|
+
const candidate = value;
|
|
1649
|
+
if (typeof candidate.permissive !== "boolean") return void 0;
|
|
1650
|
+
return {
|
|
1651
|
+
csp: candidate.csp && typeof candidate.csp === "object" ? candidate.csp : void 0,
|
|
1652
|
+
cspDirectives: candidate.cspDirectives && typeof candidate.cspDirectives === "object" ? candidate.cspDirectives : void 0,
|
|
1653
|
+
permissive: candidate.permissive
|
|
1654
|
+
};
|
|
1655
|
+
}
|
|
1586
1656
|
function toSafeOpenInAppUrl(value) {
|
|
1587
1657
|
try {
|
|
1588
1658
|
const parsed = new URL(value);
|
|
@@ -1679,19 +1749,22 @@ function mapLogToLifecycle(method, details) {
|
|
|
1679
1749
|
"debug/bridge-connect-ready": "bridge-connect-ready",
|
|
1680
1750
|
"debug/bridge-connect-error": "bridge-connect-error",
|
|
1681
1751
|
"debug/bridge-connect-skipped": "bridge-connect-skipped",
|
|
1682
|
-
"debug/app-initialized": "app-initialized"
|
|
1752
|
+
"debug/app-initialized": "app-initialized",
|
|
1753
|
+
"debug/view-mounted": "view-mounted"
|
|
1683
1754
|
};
|
|
1684
1755
|
const kind = kindByMethod[method];
|
|
1685
1756
|
if (!kind) return null;
|
|
1686
1757
|
let status;
|
|
1687
|
-
if (method
|
|
1758
|
+
if (method === "debug/view-mounted") {
|
|
1759
|
+
status = details.mode === "url" ? "ok" : "error";
|
|
1760
|
+
} else if (method.endsWith("-error") || method === "debug/widget-content-invalid-mimetype") {
|
|
1688
1761
|
status = "error";
|
|
1689
1762
|
} else if (method.endsWith("-ready") || method === "debug/app-initialized" || method === "debug/bridge-connect-skipped") {
|
|
1690
1763
|
status = "ok";
|
|
1691
1764
|
} else {
|
|
1692
1765
|
status = "pending";
|
|
1693
1766
|
}
|
|
1694
|
-
const message = typeof details.error === "string" ? details.error : typeof details.reason === "string" ? details.reason : void 0;
|
|
1767
|
+
const message = typeof details.error === "string" ? details.error : typeof details.reason === "string" ? details.reason : method === "debug/view-mounted" && typeof details.url === "string" ? details.url : void 0;
|
|
1695
1768
|
return { kind, status, message, timestamp: Date.now() };
|
|
1696
1769
|
}
|
|
1697
1770
|
function recorderDebug2(message, details) {
|
|
@@ -1950,6 +2023,11 @@ function MCPAppsRendererSurface({
|
|
|
1950
2023
|
const liveOpenAiCompatCapabilities = liveEffectiveCompatRuntime.injected ? liveEffectiveCompatRuntime.capabilities : null;
|
|
1951
2024
|
const isCachedReplay = !!cachedWidgetHtmlUrl && !liveFetchPreferred;
|
|
1952
2025
|
const cachedReplayWidgetHtmlUrl = isCachedReplay ? cachedWidgetHtmlUrl : void 0;
|
|
2026
|
+
const artifactCacheKey = host.services.artifactCacheKey;
|
|
2027
|
+
const cachedWidgetHtmlKey = cachedWidgetHtmlUrl ? artifactCacheKey?.(cachedWidgetHtmlUrl) ?? cachedWidgetHtmlUrl : void 0;
|
|
2028
|
+
const cachedReplayWidgetHtmlKey = isCachedReplay ? cachedWidgetHtmlKey : void 0;
|
|
2029
|
+
const fetchArtifactRef = useRef(host.services.fetchArtifact);
|
|
2030
|
+
fetchArtifactRef.current = host.services.fetchArtifact;
|
|
1953
2031
|
const widgetFetchModeKey = isCachedReplay ? "cached" : "live";
|
|
1954
2032
|
const cachedReplayPrefersBorder = isCachedReplay ? initialPrefersBorder : void 0;
|
|
1955
2033
|
const effectiveInjectOpenAiCompat = isCachedReplay && typeof initialInjectedOpenAiCompat === "boolean" ? initialInjectedOpenAiCompat : liveInjectOpenAiCompat;
|
|
@@ -2117,6 +2195,7 @@ function MCPAppsRendererSurface({
|
|
|
2117
2195
|
const [widgetHtml, setWidgetHtml] = useState(null);
|
|
2118
2196
|
const [openInAppUrlOverride, setOpenInAppUrlOverride] = useState(null);
|
|
2119
2197
|
const [sandboxProxyReady, setSandboxProxyReady] = useState(false);
|
|
2198
|
+
const [viewMount, setViewMount] = useState(null);
|
|
2120
2199
|
const [bridgeTransportReady, setBridgeTransportReady] = useState(false);
|
|
2121
2200
|
const explicitOpenInAppBaseUrl = useMemo(
|
|
2122
2201
|
() => resolveExplicitBaseUrl(widgetHtml, resourceUri),
|
|
@@ -2148,6 +2227,9 @@ function MCPAppsRendererSurface({
|
|
|
2148
2227
|
const [widgetPermissive, setWidgetPermissive] = useState(
|
|
2149
2228
|
isCachedReplay ? true : initialWidgetPermissive ?? false
|
|
2150
2229
|
);
|
|
2230
|
+
const [viewOriginLabel, setViewOriginLabel] = useState(
|
|
2231
|
+
void 0
|
|
2232
|
+
);
|
|
2151
2233
|
const [prefersBorder, setPrefersBorder] = useState(
|
|
2152
2234
|
initialPrefersBorder ?? true
|
|
2153
2235
|
);
|
|
@@ -2209,7 +2291,7 @@ function MCPAppsRendererSurface({
|
|
|
2209
2291
|
setPrefersBorder(cachedReplayPrefersBorder ?? true);
|
|
2210
2292
|
setFirstCspBlock(null);
|
|
2211
2293
|
}, [
|
|
2212
|
-
|
|
2294
|
+
cachedReplayWidgetHtmlKey,
|
|
2213
2295
|
cachedReplayPrefersBorder,
|
|
2214
2296
|
hasRenderedLiveForCurrentIdentity,
|
|
2215
2297
|
isCachedReplay
|
|
@@ -2235,7 +2317,7 @@ function MCPAppsRendererSurface({
|
|
|
2235
2317
|
userPreferInlineRef.current = earlyEffectiveMcpAppsCapabilities.widgetDisplayModeRequests === "user-initiated-only";
|
|
2236
2318
|
}, [
|
|
2237
2319
|
resourceUri,
|
|
2238
|
-
|
|
2320
|
+
cachedWidgetHtmlKey,
|
|
2239
2321
|
earlyEffectiveMcpAppsCapabilities.widgetDisplayModeRequests
|
|
2240
2322
|
]);
|
|
2241
2323
|
const onSendFollowUpRef = useRef(onSendFollowUp);
|
|
@@ -2301,7 +2383,7 @@ function MCPAppsRendererSurface({
|
|
|
2301
2383
|
return;
|
|
2302
2384
|
const fetchSourceKey = [
|
|
2303
2385
|
resourceUri ?? "",
|
|
2304
|
-
|
|
2386
|
+
cachedReplayWidgetHtmlKey ?? "",
|
|
2305
2387
|
cspMode,
|
|
2306
2388
|
widgetFetchModeKey,
|
|
2307
2389
|
// String() so `null` (cached-replay sentinel), `true`, and
|
|
@@ -2319,7 +2401,8 @@ function MCPAppsRendererSurface({
|
|
|
2319
2401
|
}
|
|
2320
2402
|
const isStillCurrent = () => latestFetchSourceKeyRef.current === fetchSourceKey;
|
|
2321
2403
|
const loadFromCachedUrl = async (cachedUrl) => {
|
|
2322
|
-
const
|
|
2404
|
+
const fetchArtifact = fetchArtifactRef.current;
|
|
2405
|
+
const cachedResponse = fetchArtifact ? await fetchArtifact(cachedUrl) : await fetch(cachedUrl);
|
|
2323
2406
|
if (!cachedResponse.ok) {
|
|
2324
2407
|
throw new Error(
|
|
2325
2408
|
`Failed to fetch cached widget HTML: ${cachedResponse.statusText}`
|
|
@@ -2327,6 +2410,7 @@ function MCPAppsRendererSurface({
|
|
|
2327
2410
|
}
|
|
2328
2411
|
const html = await cachedResponse.text();
|
|
2329
2412
|
if (!isStillCurrent()) return;
|
|
2413
|
+
setLoadError(null);
|
|
2330
2414
|
setBridgeTransportReady(false);
|
|
2331
2415
|
hasRenderedLiveRef.current = false;
|
|
2332
2416
|
liveRenderIdentityRef.current = null;
|
|
@@ -2368,6 +2452,8 @@ function MCPAppsRendererSurface({
|
|
|
2368
2452
|
mimeTypeWarning: warning,
|
|
2369
2453
|
mimeTypeValid: valid,
|
|
2370
2454
|
prefersBorder: prefersBorder2,
|
|
2455
|
+
declaredDomain: serverDeclaredDomain,
|
|
2456
|
+
viewOriginLabel: serverViewOriginLabel,
|
|
2371
2457
|
injectedOpenAiCompat: serverInjectedOpenAiCompat,
|
|
2372
2458
|
injectedOpenAiCompatCapabilities: serverInjectedOpenAiCompatCapabilities
|
|
2373
2459
|
} = await host.services.fetchWidgetContent({
|
|
@@ -2429,8 +2515,10 @@ function MCPAppsRendererSurface({
|
|
|
2429
2515
|
resolvedInjectedOpenAiCompat,
|
|
2430
2516
|
resolvedInjectedOpenAiCompatCapabilities
|
|
2431
2517
|
);
|
|
2432
|
-
|
|
2518
|
+
setViewOriginLabel(serverViewOriginLabel);
|
|
2519
|
+
if (csp || permissions || !permissive || serverDeclaredDomain) {
|
|
2433
2520
|
setWidgetCspStore(toolCallIdRef.current, {
|
|
2521
|
+
declaredDomain: serverDeclaredDomain ?? null,
|
|
2434
2522
|
mode: permissive ? "permissive" : "widget-declared",
|
|
2435
2523
|
connectDomains: csp?.connectDomains || [],
|
|
2436
2524
|
resourceDomains: csp?.resourceDomains || [],
|
|
@@ -2521,6 +2609,7 @@ function MCPAppsRendererSurface({
|
|
|
2521
2609
|
isOffline,
|
|
2522
2610
|
cachedWidgetHtmlUrl,
|
|
2523
2611
|
cachedReplayWidgetHtmlUrl,
|
|
2612
|
+
cachedReplayWidgetHtmlKey,
|
|
2524
2613
|
liveFetchPreferred,
|
|
2525
2614
|
widgetFetchModeKey,
|
|
2526
2615
|
initialPrefersBorder,
|
|
@@ -2639,7 +2728,9 @@ function MCPAppsRendererSurface({
|
|
|
2639
2728
|
const setWidgetGlobals = debug.setWidgetGlobals;
|
|
2640
2729
|
const setWidgetStateStore = debug.setWidgetState;
|
|
2641
2730
|
const setWidgetCspStore = debug.setWidgetCsp;
|
|
2731
|
+
const setWidgetAppliedCspStore = debug.setWidgetAppliedCsp;
|
|
2642
2732
|
const addCspViolation = debug.addCspViolation;
|
|
2733
|
+
const reportCspViolation = debug.reportCspViolation;
|
|
2643
2734
|
const clearCspViolations = debug.clearCspViolations;
|
|
2644
2735
|
const setWidgetModelContext = debug.setWidgetModelContext;
|
|
2645
2736
|
const setWidgetHtmlStore = debug.setWidgetHtml;
|
|
@@ -3131,6 +3222,14 @@ function MCPAppsRendererSurface({
|
|
|
3131
3222
|
() => stableStringifyJson(resolvedBridgeHostInfo),
|
|
3132
3223
|
[resolvedBridgeHostInfo]
|
|
3133
3224
|
);
|
|
3225
|
+
const viewAssignedOrigin = useMemo(() => {
|
|
3226
|
+
if (!viewMount || viewMount.mode !== "url") return void 0;
|
|
3227
|
+
try {
|
|
3228
|
+
return new URL(viewMount.url).origin;
|
|
3229
|
+
} catch {
|
|
3230
|
+
return void 0;
|
|
3231
|
+
}
|
|
3232
|
+
}, [viewMount]);
|
|
3134
3233
|
useEffect(() => {
|
|
3135
3234
|
if (!toolCallId) return;
|
|
3136
3235
|
setSandboxAppliedStore(
|
|
@@ -3144,7 +3243,11 @@ function MCPAppsRendererSurface({
|
|
|
3144
3243
|
hostPolicyApplied: effectiveSandbox.hostPolicyApplied,
|
|
3145
3244
|
restrictTo: sandboxCspPolicy?.restrictTo,
|
|
3146
3245
|
cspMode: sandboxCspPolicy?.mode,
|
|
3147
|
-
permissions: effectiveSandbox.permissions
|
|
3246
|
+
permissions: effectiveSandbox.permissions,
|
|
3247
|
+
mountId: viewMount?.mountId,
|
|
3248
|
+
viewMode: viewMount?.mode,
|
|
3249
|
+
viewUrl: viewMount?.url,
|
|
3250
|
+
assignedOrigin: viewAssignedOrigin
|
|
3148
3251
|
},
|
|
3149
3252
|
void 0,
|
|
3150
3253
|
sandboxHostInfo
|
|
@@ -3154,7 +3257,9 @@ function MCPAppsRendererSurface({
|
|
|
3154
3257
|
effectiveSandbox,
|
|
3155
3258
|
sandboxCspPolicy,
|
|
3156
3259
|
sandboxHostInfo,
|
|
3157
|
-
setSandboxAppliedStore
|
|
3260
|
+
setSandboxAppliedStore,
|
|
3261
|
+
viewMount,
|
|
3262
|
+
viewAssignedOrigin
|
|
3158
3263
|
]);
|
|
3159
3264
|
useLayoutEffect(() => {
|
|
3160
3265
|
onSendFollowUpRef.current = onSendFollowUp;
|
|
@@ -3637,6 +3742,9 @@ function MCPAppsRendererSurface({
|
|
|
3637
3742
|
lineNumber,
|
|
3638
3743
|
columnNumber,
|
|
3639
3744
|
effectiveDirective,
|
|
3745
|
+
mountId,
|
|
3746
|
+
originalPolicy,
|
|
3747
|
+
disposition,
|
|
3640
3748
|
timestamp,
|
|
3641
3749
|
subtype
|
|
3642
3750
|
} = data;
|
|
@@ -3648,16 +3756,21 @@ function MCPAppsRendererSurface({
|
|
|
3648
3756
|
method: "csp-violation",
|
|
3649
3757
|
message: data
|
|
3650
3758
|
});
|
|
3651
|
-
|
|
3759
|
+
const violation = {
|
|
3652
3760
|
directive,
|
|
3653
3761
|
effectiveDirective,
|
|
3654
3762
|
blockedUri,
|
|
3763
|
+
mountId: normalizeCspMountId(mountId),
|
|
3764
|
+
originalPolicy: typeof originalPolicy === "string" ? originalPolicy : void 0,
|
|
3765
|
+
disposition: disposition === "enforce" || disposition === "report" ? disposition : void 0,
|
|
3655
3766
|
sourceFile,
|
|
3656
3767
|
lineNumber,
|
|
3657
3768
|
columnNumber,
|
|
3658
3769
|
timestamp: timestamp || Date.now(),
|
|
3659
3770
|
subtype
|
|
3660
|
-
}
|
|
3771
|
+
};
|
|
3772
|
+
addCspViolation(toolCallId, violation);
|
|
3773
|
+
reportCspViolation(toolCallId, serverId, violation);
|
|
3661
3774
|
setFirstCspBlock(
|
|
3662
3775
|
(prev) => prev ?? {
|
|
3663
3776
|
directive: typeof effectiveDirective === "string" && effectiveDirective ? effectiveDirective : typeof directive === "string" ? directive : void 0,
|
|
@@ -3671,7 +3784,14 @@ function MCPAppsRendererSurface({
|
|
|
3671
3784
|
);
|
|
3672
3785
|
}
|
|
3673
3786
|
},
|
|
3674
|
-
[
|
|
3787
|
+
[
|
|
3788
|
+
addCspViolation,
|
|
3789
|
+
logUiEvent,
|
|
3790
|
+
minimalMode,
|
|
3791
|
+
reportCspViolation,
|
|
3792
|
+
serverId,
|
|
3793
|
+
toolCallId
|
|
3794
|
+
]
|
|
3675
3795
|
);
|
|
3676
3796
|
const handleSandboxMessage = (event) => {
|
|
3677
3797
|
const data = event.data;
|
|
@@ -3680,6 +3800,37 @@ function MCPAppsRendererSurface({
|
|
|
3680
3800
|
handleCspViolation(event);
|
|
3681
3801
|
return;
|
|
3682
3802
|
}
|
|
3803
|
+
if (data.type === "mcpjam:csp-applied") {
|
|
3804
|
+
const mountId = normalizeCspMountId(data.mountId);
|
|
3805
|
+
if (mountId !== void 0 && typeof data.csp === "string" && data.csp.length > 0) {
|
|
3806
|
+
setWidgetAppliedCspStore(toolCallIdRef.current, {
|
|
3807
|
+
mountId,
|
|
3808
|
+
headerString: data.csp,
|
|
3809
|
+
mode: data.mode === "permissive" ? "permissive" : "widget-declared",
|
|
3810
|
+
intent: normalizeCspApplicationIntent(data.intent)
|
|
3811
|
+
});
|
|
3812
|
+
logWidgetDebug("ui-to-host", "debug/csp-applied", {
|
|
3813
|
+
mountId,
|
|
3814
|
+
mode: data.mode,
|
|
3815
|
+
headerLength: data.csp.length
|
|
3816
|
+
});
|
|
3817
|
+
}
|
|
3818
|
+
return;
|
|
3819
|
+
}
|
|
3820
|
+
if (data.type === "mcpjam:view-mode") {
|
|
3821
|
+
const mode = data.mode;
|
|
3822
|
+
if (mode === "url" || mode === "srcdoc" || mode === "srcdoc-fallback") {
|
|
3823
|
+
const url = typeof data.url === "string" ? data.url : "";
|
|
3824
|
+
const mountId = normalizeCspMountId(data.mountId);
|
|
3825
|
+
setViewMount({ mountId, mode, url });
|
|
3826
|
+
logWidgetDebug("ui-to-host", "debug/view-mounted", {
|
|
3827
|
+
mountId,
|
|
3828
|
+
mode,
|
|
3829
|
+
url
|
|
3830
|
+
});
|
|
3831
|
+
}
|
|
3832
|
+
return;
|
|
3833
|
+
}
|
|
3683
3834
|
if (data.type === "recorder:step") {
|
|
3684
3835
|
recorderDebug2("step from sandbox", {
|
|
3685
3836
|
toolName,
|
|
@@ -3959,6 +4110,9 @@ function MCPAppsRendererSurface({
|
|
|
3959
4110
|
title: `MCP App: ${toolName}`,
|
|
3960
4111
|
hostedMode: host.surface.hostedMode,
|
|
3961
4112
|
sandboxOrigin: host.surface.sandboxOrigin,
|
|
4113
|
+
mountMode: host.surface.viewMountMode,
|
|
4114
|
+
viewOriginLabel,
|
|
4115
|
+
viewSubdomainsEnabled: host.surface.viewSubdomainsEnabled,
|
|
3962
4116
|
className: `bg-transparent overflow-hidden ${isFullscreen ? "flex-1 border-0 rounded-none" : `rounded-md ${matrixGatedPrefersBorder ? "border border-border/40" : ""}`}`,
|
|
3963
4117
|
style: iframeStyle
|
|
3964
4118
|
}
|