@mcpjam/widget-react 0.1.11 → 0.1.13
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 +135 -34
- package/dist/index.js +229 -31
- 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,
|
|
@@ -891,6 +916,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
891
916
|
allowFeatures,
|
|
892
917
|
cspDirectives,
|
|
893
918
|
cspSubtypePolicy,
|
|
919
|
+
clientContext,
|
|
894
920
|
browserStorage,
|
|
895
921
|
permissive,
|
|
896
922
|
recordMode,
|
|
@@ -901,7 +927,10 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
901
927
|
colorScheme,
|
|
902
928
|
title = "Sandboxed Content",
|
|
903
929
|
hostedMode = false,
|
|
904
|
-
sandboxOrigin = ""
|
|
930
|
+
sandboxOrigin = "",
|
|
931
|
+
mountMode,
|
|
932
|
+
viewOriginLabel,
|
|
933
|
+
viewSubdomainsEnabled
|
|
905
934
|
}, ref) {
|
|
906
935
|
const outerRef = useRef(null);
|
|
907
936
|
const [proxyReady, setProxyReady] = useState(false);
|
|
@@ -910,12 +939,17 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
910
939
|
const onProxyReadyRef = useRef(onProxyReady);
|
|
911
940
|
onMessageRef.current = onMessage;
|
|
912
941
|
onProxyReadyRef.current = onProxyReady;
|
|
913
|
-
const
|
|
942
|
+
const sandboxProxyUrl = useMemo(
|
|
914
943
|
() => resolveSandboxProxyUrl({
|
|
915
944
|
hostedMode,
|
|
916
945
|
sandboxOrigin,
|
|
917
|
-
location: window.location
|
|
918
|
-
|
|
946
|
+
location: window.location,
|
|
947
|
+
viewOriginLabel,
|
|
948
|
+
viewSubdomainsEnabled,
|
|
949
|
+
userAgent: typeof navigator === "undefined" ? "" : navigator.userAgent
|
|
950
|
+
}),
|
|
951
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
952
|
+
[hostedMode, sandboxOrigin, viewOriginLabel, viewSubdomainsEnabled]
|
|
919
953
|
);
|
|
920
954
|
const sandboxProxyOrigin = useMemo(() => {
|
|
921
955
|
try {
|
|
@@ -948,6 +982,14 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
948
982
|
onMessageRef.current(event);
|
|
949
983
|
return;
|
|
950
984
|
}
|
|
985
|
+
if (event.data?.type === "mcpjam:view-mode") {
|
|
986
|
+
onMessageRef.current(event);
|
|
987
|
+
return;
|
|
988
|
+
}
|
|
989
|
+
if (event.data?.type === "mcpjam:csp-applied") {
|
|
990
|
+
onMessageRef.current(event);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
951
993
|
if (event.data?.type === "recorder:step" || event.data?.type === "recorder:ready" || event.data?.type === "recorder:replay-result") {
|
|
952
994
|
recorderDebug(`forward ${event.data.type}`);
|
|
953
995
|
onMessageRef.current(event);
|
|
@@ -984,6 +1026,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
984
1026
|
csp: csp ?? null,
|
|
985
1027
|
cspDirectives: cspDirectives ?? null,
|
|
986
1028
|
cspSubtypePolicy: cspSubtypePolicy ?? null,
|
|
1029
|
+
clientContext: clientContext ?? null,
|
|
987
1030
|
browserStorage: browserStorage ?? null,
|
|
988
1031
|
html: html ?? null,
|
|
989
1032
|
permissive: permissive ?? null,
|
|
@@ -992,19 +1035,24 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
992
1035
|
sandboxAttrs: sandboxAttrs ?? null,
|
|
993
1036
|
// Include recordMode so record-capable surfaces receive the recorder
|
|
994
1037
|
// shim, and stale/non-recordable surfaces reload without it.
|
|
995
|
-
recordMode: recordMode ?? null
|
|
1038
|
+
recordMode: recordMode ?? null,
|
|
1039
|
+
// Part of the render recipe: it decides how the proxy mounts the HTML,
|
|
1040
|
+
// so a change must re-send rather than leave the previous mount up.
|
|
1041
|
+
mountMode: mountMode ?? null
|
|
996
1042
|
}),
|
|
997
1043
|
[
|
|
998
1044
|
csp,
|
|
999
1045
|
cspDirectives,
|
|
1000
1046
|
cspSubtypePolicy,
|
|
1047
|
+
clientContext,
|
|
1001
1048
|
browserStorage,
|
|
1002
1049
|
html,
|
|
1003
1050
|
permissive,
|
|
1004
1051
|
permissions,
|
|
1005
1052
|
sandbox,
|
|
1006
1053
|
sandboxAttrs,
|
|
1007
|
-
recordMode
|
|
1054
|
+
recordMode,
|
|
1055
|
+
mountMode
|
|
1008
1056
|
]
|
|
1009
1057
|
);
|
|
1010
1058
|
useEffect(() => {
|
|
@@ -1034,11 +1082,13 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1034
1082
|
// field.
|
|
1035
1083
|
cspDirectives,
|
|
1036
1084
|
cspSubtypePolicy,
|
|
1085
|
+
clientContext,
|
|
1037
1086
|
browserStorage,
|
|
1038
1087
|
permissive,
|
|
1039
1088
|
colorScheme,
|
|
1040
1089
|
recordMode,
|
|
1041
|
-
recorderDebug: isRecorderDebugEnabled()
|
|
1090
|
+
recorderDebug: isRecorderDebugEnabled(),
|
|
1091
|
+
mountMode
|
|
1042
1092
|
}
|
|
1043
1093
|
},
|
|
1044
1094
|
sandboxProxyOrigin
|
|
@@ -1065,7 +1115,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1065
1115
|
const iframeStyle = colorScheme ? { ...style, colorScheme } : style;
|
|
1066
1116
|
useEffect(() => {
|
|
1067
1117
|
setProxyReady(false);
|
|
1068
|
-
}, [outerSandboxAttribute]);
|
|
1118
|
+
}, [outerSandboxAttribute, sandboxProxyOrigin]);
|
|
1069
1119
|
return /* @__PURE__ */ jsx(
|
|
1070
1120
|
"iframe",
|
|
1071
1121
|
{
|
|
@@ -1077,7 +1127,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1077
1127
|
className,
|
|
1078
1128
|
style: iframeStyle
|
|
1079
1129
|
},
|
|
1080
|
-
outerSandboxAttribute
|
|
1130
|
+
`${sandboxProxyOrigin}\0${outerSandboxAttribute}`
|
|
1081
1131
|
);
|
|
1082
1132
|
});
|
|
1083
1133
|
function McpAppsModal({
|
|
@@ -1095,6 +1145,7 @@ function McpAppsModal({
|
|
|
1095
1145
|
widgetAllowFeatures,
|
|
1096
1146
|
widgetCspDirectives,
|
|
1097
1147
|
widgetCspSubtypePolicy,
|
|
1148
|
+
widgetClientContext,
|
|
1098
1149
|
widgetToolResult,
|
|
1099
1150
|
widgetBrowserStorage,
|
|
1100
1151
|
hostContextRef,
|
|
@@ -1111,7 +1162,8 @@ function McpAppsModal({
|
|
|
1111
1162
|
toolOutputRef,
|
|
1112
1163
|
themeModeRef,
|
|
1113
1164
|
addUiLog,
|
|
1114
|
-
onCspViolation
|
|
1165
|
+
onCspViolation,
|
|
1166
|
+
onCspApplied
|
|
1115
1167
|
}) {
|
|
1116
1168
|
const host = useWidgetHost();
|
|
1117
1169
|
const Modal = host.components?.Modal;
|
|
@@ -1306,10 +1358,26 @@ function McpAppsModal({
|
|
|
1306
1358
|
hostInfo,
|
|
1307
1359
|
effectiveHostCapabilities
|
|
1308
1360
|
]);
|
|
1361
|
+
const modalCspMountRef = useRef(void 0);
|
|
1362
|
+
const clearCspMount = host.debug?.clearCspMount;
|
|
1363
|
+
useEffect(
|
|
1364
|
+
() => () => {
|
|
1365
|
+
if (modalCspMountRef.current !== void 0) {
|
|
1366
|
+
clearCspMount?.(toolCallId, modalCspMountRef.current);
|
|
1367
|
+
modalCspMountRef.current = void 0;
|
|
1368
|
+
}
|
|
1369
|
+
},
|
|
1370
|
+
[open, modalHtml, toolCallId, clearCspMount]
|
|
1371
|
+
);
|
|
1309
1372
|
const handleModalMessage = (event) => {
|
|
1310
1373
|
const data = event.data;
|
|
1311
1374
|
if (!data) return;
|
|
1312
|
-
if (data.type === "
|
|
1375
|
+
if (data.type === "mcpjam:csp-applied" && (typeof data.mountId === "string" || typeof data.mountId === "number")) {
|
|
1376
|
+
modalCspMountRef.current = data.mountId;
|
|
1377
|
+
}
|
|
1378
|
+
if (data.type === "mcpjam:csp-applied") {
|
|
1379
|
+
onCspApplied(event);
|
|
1380
|
+
} else if (data.type === "mcp-apps:csp-violation") {
|
|
1313
1381
|
onCspViolation(event);
|
|
1314
1382
|
}
|
|
1315
1383
|
};
|
|
@@ -1327,12 +1395,15 @@ function McpAppsModal({
|
|
|
1327
1395
|
allowFeatures: widgetAllowFeatures,
|
|
1328
1396
|
cspDirectives: widgetCspDirectives,
|
|
1329
1397
|
cspSubtypePolicy: widgetCspSubtypePolicy,
|
|
1398
|
+
clientContext: widgetClientContext ? { ...widgetClientContext, surface: "modal" } : void 0,
|
|
1330
1399
|
browserStorage: widgetBrowserStorage,
|
|
1331
1400
|
colorScheme: modalColorScheme,
|
|
1332
1401
|
onMessage: handleModalMessage,
|
|
1333
1402
|
title: `MCP App Modal: ${title}`,
|
|
1334
1403
|
hostedMode: host.surface.hostedMode,
|
|
1335
1404
|
sandboxOrigin: host.surface.sandboxOrigin,
|
|
1405
|
+
mountMode: host.surface.viewMountMode,
|
|
1406
|
+
viewSubdomainsEnabled: host.surface.viewSubdomainsEnabled,
|
|
1336
1407
|
className: "min-w-full border-0 rounded-md bg-transparent overflow-hidden",
|
|
1337
1408
|
style: {
|
|
1338
1409
|
height: "100%",
|
|
@@ -1360,7 +1431,7 @@ async function handleUploadFileMessage(data, sendResponse, { authFetch, hostedMo
|
|
|
1360
1431
|
sendResponse({
|
|
1361
1432
|
type: "openai:uploadFile:response",
|
|
1362
1433
|
callId: uploadCallId,
|
|
1363
|
-
error: "File upload
|
|
1434
|
+
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
1435
|
});
|
|
1365
1436
|
return;
|
|
1366
1437
|
}
|
|
@@ -1403,7 +1474,7 @@ function handleGetFileDownloadUrlMessage(data, sendResponse, { hostedMode }) {
|
|
|
1403
1474
|
sendResponse({
|
|
1404
1475
|
type: "openai:getFileDownloadUrl:response",
|
|
1405
1476
|
callId: dlCallId,
|
|
1406
|
-
error: "File download
|
|
1477
|
+
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
1478
|
});
|
|
1408
1479
|
return;
|
|
1409
1480
|
}
|
|
@@ -1563,8 +1634,12 @@ var NOOP_WIDGET_DEBUG_SINK = {
|
|
|
1563
1634
|
},
|
|
1564
1635
|
setWidgetCsp: () => {
|
|
1565
1636
|
},
|
|
1637
|
+
setWidgetAppliedCsp: () => {
|
|
1638
|
+
},
|
|
1566
1639
|
addCspViolation: () => {
|
|
1567
1640
|
},
|
|
1641
|
+
reportCspViolation: () => {
|
|
1642
|
+
},
|
|
1568
1643
|
clearCspViolations: () => {
|
|
1569
1644
|
},
|
|
1570
1645
|
setWidgetModelContext: () => {
|
|
@@ -1583,6 +1658,26 @@ var SUPPRESSED_UI_LOG_METHODS = /* @__PURE__ */ new Set(["ui/notifications/size-
|
|
|
1583
1658
|
var PIP_MAX_HEIGHT = "min(40vh, 600px)";
|
|
1584
1659
|
var CSP_BLOCKED_NOTICE_DELAY_MS = 1500;
|
|
1585
1660
|
var SAFE_OPEN_IN_APP_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
1661
|
+
function normalizeCspMountId(value) {
|
|
1662
|
+
if (typeof value === "number") {
|
|
1663
|
+
return Number.isInteger(value) && value > 0 ? value : void 0;
|
|
1664
|
+
}
|
|
1665
|
+
if (typeof value !== "string") return void 0;
|
|
1666
|
+
const trimmed = value.trim();
|
|
1667
|
+
return trimmed.length > 0 && trimmed.length <= 128 ? trimmed : void 0;
|
|
1668
|
+
}
|
|
1669
|
+
function normalizeCspApplicationIntent(value) {
|
|
1670
|
+
if (!value || typeof value !== "object") return void 0;
|
|
1671
|
+
const candidate = value;
|
|
1672
|
+
if (typeof candidate.permissive !== "boolean") return void 0;
|
|
1673
|
+
return {
|
|
1674
|
+
csp: candidate.csp && typeof candidate.csp === "object" ? candidate.csp : void 0,
|
|
1675
|
+
cspDirectives: candidate.cspDirectives && typeof candidate.cspDirectives === "object" ? candidate.cspDirectives : void 0,
|
|
1676
|
+
cspSubtypePolicy: candidate.cspSubtypePolicy && typeof candidate.cspSubtypePolicy === "object" ? candidate.cspSubtypePolicy : void 0,
|
|
1677
|
+
clientContext: candidate.clientContext && typeof candidate.clientContext === "object" && typeof candidate.clientContext.clientName === "string" && candidate.clientContext.capabilities && typeof candidate.clientContext.capabilities === "object" ? candidate.clientContext : void 0,
|
|
1678
|
+
permissive: candidate.permissive
|
|
1679
|
+
};
|
|
1680
|
+
}
|
|
1586
1681
|
function toSafeOpenInAppUrl(value) {
|
|
1587
1682
|
try {
|
|
1588
1683
|
const parsed = new URL(value);
|
|
@@ -1679,19 +1774,22 @@ function mapLogToLifecycle(method, details) {
|
|
|
1679
1774
|
"debug/bridge-connect-ready": "bridge-connect-ready",
|
|
1680
1775
|
"debug/bridge-connect-error": "bridge-connect-error",
|
|
1681
1776
|
"debug/bridge-connect-skipped": "bridge-connect-skipped",
|
|
1682
|
-
"debug/app-initialized": "app-initialized"
|
|
1777
|
+
"debug/app-initialized": "app-initialized",
|
|
1778
|
+
"debug/view-mounted": "view-mounted"
|
|
1683
1779
|
};
|
|
1684
1780
|
const kind = kindByMethod[method];
|
|
1685
1781
|
if (!kind) return null;
|
|
1686
1782
|
let status;
|
|
1687
|
-
if (method
|
|
1783
|
+
if (method === "debug/view-mounted") {
|
|
1784
|
+
status = details.mode === "url" ? "ok" : "error";
|
|
1785
|
+
} else if (method.endsWith("-error") || method === "debug/widget-content-invalid-mimetype") {
|
|
1688
1786
|
status = "error";
|
|
1689
1787
|
} else if (method.endsWith("-ready") || method === "debug/app-initialized" || method === "debug/bridge-connect-skipped") {
|
|
1690
1788
|
status = "ok";
|
|
1691
1789
|
} else {
|
|
1692
1790
|
status = "pending";
|
|
1693
1791
|
}
|
|
1694
|
-
const message = typeof details.error === "string" ? details.error : typeof details.reason === "string" ? details.reason : void 0;
|
|
1792
|
+
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
1793
|
return { kind, status, message, timestamp: Date.now() };
|
|
1696
1794
|
}
|
|
1697
1795
|
function recorderDebug2(message, details) {
|
|
@@ -1950,6 +2048,11 @@ function MCPAppsRendererSurface({
|
|
|
1950
2048
|
const liveOpenAiCompatCapabilities = liveEffectiveCompatRuntime.injected ? liveEffectiveCompatRuntime.capabilities : null;
|
|
1951
2049
|
const isCachedReplay = !!cachedWidgetHtmlUrl && !liveFetchPreferred;
|
|
1952
2050
|
const cachedReplayWidgetHtmlUrl = isCachedReplay ? cachedWidgetHtmlUrl : void 0;
|
|
2051
|
+
const artifactCacheKey = host.services.artifactCacheKey;
|
|
2052
|
+
const cachedWidgetHtmlKey = cachedWidgetHtmlUrl ? artifactCacheKey?.(cachedWidgetHtmlUrl) ?? cachedWidgetHtmlUrl : void 0;
|
|
2053
|
+
const cachedReplayWidgetHtmlKey = isCachedReplay ? cachedWidgetHtmlKey : void 0;
|
|
2054
|
+
const fetchArtifactRef = useRef(host.services.fetchArtifact);
|
|
2055
|
+
fetchArtifactRef.current = host.services.fetchArtifact;
|
|
1953
2056
|
const widgetFetchModeKey = isCachedReplay ? "cached" : "live";
|
|
1954
2057
|
const cachedReplayPrefersBorder = isCachedReplay ? initialPrefersBorder : void 0;
|
|
1955
2058
|
const effectiveInjectOpenAiCompat = isCachedReplay && typeof initialInjectedOpenAiCompat === "boolean" ? initialInjectedOpenAiCompat : liveInjectOpenAiCompat;
|
|
@@ -2117,6 +2220,7 @@ function MCPAppsRendererSurface({
|
|
|
2117
2220
|
const [widgetHtml, setWidgetHtml] = useState(null);
|
|
2118
2221
|
const [openInAppUrlOverride, setOpenInAppUrlOverride] = useState(null);
|
|
2119
2222
|
const [sandboxProxyReady, setSandboxProxyReady] = useState(false);
|
|
2223
|
+
const [viewMount, setViewMount] = useState(null);
|
|
2120
2224
|
const [bridgeTransportReady, setBridgeTransportReady] = useState(false);
|
|
2121
2225
|
const explicitOpenInAppBaseUrl = useMemo(
|
|
2122
2226
|
() => resolveExplicitBaseUrl(widgetHtml, resourceUri),
|
|
@@ -2148,6 +2252,9 @@ function MCPAppsRendererSurface({
|
|
|
2148
2252
|
const [widgetPermissive, setWidgetPermissive] = useState(
|
|
2149
2253
|
isCachedReplay ? true : initialWidgetPermissive ?? false
|
|
2150
2254
|
);
|
|
2255
|
+
const [viewOriginLabel, setViewOriginLabel] = useState(
|
|
2256
|
+
void 0
|
|
2257
|
+
);
|
|
2151
2258
|
const [prefersBorder, setPrefersBorder] = useState(
|
|
2152
2259
|
initialPrefersBorder ?? true
|
|
2153
2260
|
);
|
|
@@ -2209,7 +2316,7 @@ function MCPAppsRendererSurface({
|
|
|
2209
2316
|
setPrefersBorder(cachedReplayPrefersBorder ?? true);
|
|
2210
2317
|
setFirstCspBlock(null);
|
|
2211
2318
|
}, [
|
|
2212
|
-
|
|
2319
|
+
cachedReplayWidgetHtmlKey,
|
|
2213
2320
|
cachedReplayPrefersBorder,
|
|
2214
2321
|
hasRenderedLiveForCurrentIdentity,
|
|
2215
2322
|
isCachedReplay
|
|
@@ -2235,7 +2342,7 @@ function MCPAppsRendererSurface({
|
|
|
2235
2342
|
userPreferInlineRef.current = earlyEffectiveMcpAppsCapabilities.widgetDisplayModeRequests === "user-initiated-only";
|
|
2236
2343
|
}, [
|
|
2237
2344
|
resourceUri,
|
|
2238
|
-
|
|
2345
|
+
cachedWidgetHtmlKey,
|
|
2239
2346
|
earlyEffectiveMcpAppsCapabilities.widgetDisplayModeRequests
|
|
2240
2347
|
]);
|
|
2241
2348
|
const onSendFollowUpRef = useRef(onSendFollowUp);
|
|
@@ -2301,7 +2408,7 @@ function MCPAppsRendererSurface({
|
|
|
2301
2408
|
return;
|
|
2302
2409
|
const fetchSourceKey = [
|
|
2303
2410
|
resourceUri ?? "",
|
|
2304
|
-
|
|
2411
|
+
cachedReplayWidgetHtmlKey ?? "",
|
|
2305
2412
|
cspMode,
|
|
2306
2413
|
widgetFetchModeKey,
|
|
2307
2414
|
// String() so `null` (cached-replay sentinel), `true`, and
|
|
@@ -2319,7 +2426,8 @@ function MCPAppsRendererSurface({
|
|
|
2319
2426
|
}
|
|
2320
2427
|
const isStillCurrent = () => latestFetchSourceKeyRef.current === fetchSourceKey;
|
|
2321
2428
|
const loadFromCachedUrl = async (cachedUrl) => {
|
|
2322
|
-
const
|
|
2429
|
+
const fetchArtifact = fetchArtifactRef.current;
|
|
2430
|
+
const cachedResponse = fetchArtifact ? await fetchArtifact(cachedUrl) : await fetch(cachedUrl);
|
|
2323
2431
|
if (!cachedResponse.ok) {
|
|
2324
2432
|
throw new Error(
|
|
2325
2433
|
`Failed to fetch cached widget HTML: ${cachedResponse.statusText}`
|
|
@@ -2327,6 +2435,7 @@ function MCPAppsRendererSurface({
|
|
|
2327
2435
|
}
|
|
2328
2436
|
const html = await cachedResponse.text();
|
|
2329
2437
|
if (!isStillCurrent()) return;
|
|
2438
|
+
setLoadError(null);
|
|
2330
2439
|
setBridgeTransportReady(false);
|
|
2331
2440
|
hasRenderedLiveRef.current = false;
|
|
2332
2441
|
liveRenderIdentityRef.current = null;
|
|
@@ -2368,6 +2477,8 @@ function MCPAppsRendererSurface({
|
|
|
2368
2477
|
mimeTypeWarning: warning,
|
|
2369
2478
|
mimeTypeValid: valid,
|
|
2370
2479
|
prefersBorder: prefersBorder2,
|
|
2480
|
+
declaredDomain: serverDeclaredDomain,
|
|
2481
|
+
viewOriginLabel: serverViewOriginLabel,
|
|
2371
2482
|
injectedOpenAiCompat: serverInjectedOpenAiCompat,
|
|
2372
2483
|
injectedOpenAiCompatCapabilities: serverInjectedOpenAiCompatCapabilities
|
|
2373
2484
|
} = await host.services.fetchWidgetContent({
|
|
@@ -2429,8 +2540,10 @@ function MCPAppsRendererSurface({
|
|
|
2429
2540
|
resolvedInjectedOpenAiCompat,
|
|
2430
2541
|
resolvedInjectedOpenAiCompatCapabilities
|
|
2431
2542
|
);
|
|
2432
|
-
|
|
2543
|
+
setViewOriginLabel(serverViewOriginLabel);
|
|
2544
|
+
if (csp || permissions || !permissive || serverDeclaredDomain) {
|
|
2433
2545
|
setWidgetCspStore(toolCallIdRef.current, {
|
|
2546
|
+
declaredDomain: serverDeclaredDomain ?? null,
|
|
2434
2547
|
mode: permissive ? "permissive" : "widget-declared",
|
|
2435
2548
|
connectDomains: csp?.connectDomains || [],
|
|
2436
2549
|
resourceDomains: csp?.resourceDomains || [],
|
|
@@ -2521,6 +2634,7 @@ function MCPAppsRendererSurface({
|
|
|
2521
2634
|
isOffline,
|
|
2522
2635
|
cachedWidgetHtmlUrl,
|
|
2523
2636
|
cachedReplayWidgetHtmlUrl,
|
|
2637
|
+
cachedReplayWidgetHtmlKey,
|
|
2524
2638
|
liveFetchPreferred,
|
|
2525
2639
|
widgetFetchModeKey,
|
|
2526
2640
|
initialPrefersBorder,
|
|
@@ -2639,7 +2753,9 @@ function MCPAppsRendererSurface({
|
|
|
2639
2753
|
const setWidgetGlobals = debug.setWidgetGlobals;
|
|
2640
2754
|
const setWidgetStateStore = debug.setWidgetState;
|
|
2641
2755
|
const setWidgetCspStore = debug.setWidgetCsp;
|
|
2756
|
+
const setWidgetAppliedCspStore = debug.setWidgetAppliedCsp;
|
|
2642
2757
|
const addCspViolation = debug.addCspViolation;
|
|
2758
|
+
const reportCspViolation = debug.reportCspViolation;
|
|
2643
2759
|
const clearCspViolations = debug.clearCspViolations;
|
|
2644
2760
|
const setWidgetModelContext = debug.setWidgetModelContext;
|
|
2645
2761
|
const setWidgetHtmlStore = debug.setWidgetHtml;
|
|
@@ -3131,6 +3247,14 @@ function MCPAppsRendererSurface({
|
|
|
3131
3247
|
() => stableStringifyJson(resolvedBridgeHostInfo),
|
|
3132
3248
|
[resolvedBridgeHostInfo]
|
|
3133
3249
|
);
|
|
3250
|
+
const viewAssignedOrigin = useMemo(() => {
|
|
3251
|
+
if (!viewMount || viewMount.mode !== "url") return void 0;
|
|
3252
|
+
try {
|
|
3253
|
+
return new URL(viewMount.url).origin;
|
|
3254
|
+
} catch {
|
|
3255
|
+
return void 0;
|
|
3256
|
+
}
|
|
3257
|
+
}, [viewMount]);
|
|
3134
3258
|
useEffect(() => {
|
|
3135
3259
|
if (!toolCallId) return;
|
|
3136
3260
|
setSandboxAppliedStore(
|
|
@@ -3144,7 +3268,11 @@ function MCPAppsRendererSurface({
|
|
|
3144
3268
|
hostPolicyApplied: effectiveSandbox.hostPolicyApplied,
|
|
3145
3269
|
restrictTo: sandboxCspPolicy?.restrictTo,
|
|
3146
3270
|
cspMode: sandboxCspPolicy?.mode,
|
|
3147
|
-
permissions: effectiveSandbox.permissions
|
|
3271
|
+
permissions: effectiveSandbox.permissions,
|
|
3272
|
+
mountId: viewMount?.mountId,
|
|
3273
|
+
viewMode: viewMount?.mode,
|
|
3274
|
+
viewUrl: viewMount?.url,
|
|
3275
|
+
assignedOrigin: viewAssignedOrigin
|
|
3148
3276
|
},
|
|
3149
3277
|
void 0,
|
|
3150
3278
|
sandboxHostInfo
|
|
@@ -3154,7 +3282,9 @@ function MCPAppsRendererSurface({
|
|
|
3154
3282
|
effectiveSandbox,
|
|
3155
3283
|
sandboxCspPolicy,
|
|
3156
3284
|
sandboxHostInfo,
|
|
3157
|
-
setSandboxAppliedStore
|
|
3285
|
+
setSandboxAppliedStore,
|
|
3286
|
+
viewMount,
|
|
3287
|
+
viewAssignedOrigin
|
|
3158
3288
|
]);
|
|
3159
3289
|
useLayoutEffect(() => {
|
|
3160
3290
|
onSendFollowUpRef.current = onSendFollowUp;
|
|
@@ -3629,7 +3759,7 @@ function MCPAppsRendererSurface({
|
|
|
3629
3759
|
const handleCspViolation = useCallback(
|
|
3630
3760
|
(event) => {
|
|
3631
3761
|
const data = event.data;
|
|
3632
|
-
if (
|
|
3762
|
+
if (data?.type !== "mcp-apps:csp-violation") return;
|
|
3633
3763
|
const {
|
|
3634
3764
|
directive,
|
|
3635
3765
|
blockedUri,
|
|
@@ -3637,6 +3767,9 @@ function MCPAppsRendererSurface({
|
|
|
3637
3767
|
lineNumber,
|
|
3638
3768
|
columnNumber,
|
|
3639
3769
|
effectiveDirective,
|
|
3770
|
+
mountId,
|
|
3771
|
+
originalPolicy,
|
|
3772
|
+
disposition,
|
|
3640
3773
|
timestamp,
|
|
3641
3774
|
subtype
|
|
3642
3775
|
} = data;
|
|
@@ -3648,16 +3781,21 @@ function MCPAppsRendererSurface({
|
|
|
3648
3781
|
method: "csp-violation",
|
|
3649
3782
|
message: data
|
|
3650
3783
|
});
|
|
3651
|
-
|
|
3784
|
+
const violation = {
|
|
3652
3785
|
directive,
|
|
3653
3786
|
effectiveDirective,
|
|
3654
3787
|
blockedUri,
|
|
3788
|
+
mountId: normalizeCspMountId(mountId),
|
|
3789
|
+
originalPolicy: typeof originalPolicy === "string" ? originalPolicy : void 0,
|
|
3790
|
+
disposition: disposition === "enforce" || disposition === "report" ? disposition : void 0,
|
|
3655
3791
|
sourceFile,
|
|
3656
3792
|
lineNumber,
|
|
3657
3793
|
columnNumber,
|
|
3658
3794
|
timestamp: timestamp || Date.now(),
|
|
3659
3795
|
subtype
|
|
3660
|
-
}
|
|
3796
|
+
};
|
|
3797
|
+
addCspViolation(toolCallId, violation);
|
|
3798
|
+
reportCspViolation(toolCallId, serverId, violation);
|
|
3661
3799
|
setFirstCspBlock(
|
|
3662
3800
|
(prev) => prev ?? {
|
|
3663
3801
|
directive: typeof effectiveDirective === "string" && effectiveDirective ? effectiveDirective : typeof directive === "string" ? directive : void 0,
|
|
@@ -3671,8 +3809,33 @@ function MCPAppsRendererSurface({
|
|
|
3671
3809
|
);
|
|
3672
3810
|
}
|
|
3673
3811
|
},
|
|
3674
|
-
[
|
|
3812
|
+
[
|
|
3813
|
+
addCspViolation,
|
|
3814
|
+
logUiEvent,
|
|
3815
|
+
minimalMode,
|
|
3816
|
+
reportCspViolation,
|
|
3817
|
+
serverId,
|
|
3818
|
+
toolCallId
|
|
3819
|
+
]
|
|
3675
3820
|
);
|
|
3821
|
+
const handleCspApplied = (event) => {
|
|
3822
|
+
const data = event.data;
|
|
3823
|
+
if (data?.type !== "mcpjam:csp-applied") return;
|
|
3824
|
+
const mountId = normalizeCspMountId(data.mountId);
|
|
3825
|
+
if (mountId !== void 0 && typeof data.csp === "string" && data.csp.length > 0) {
|
|
3826
|
+
setWidgetAppliedCspStore(toolCallIdRef.current, {
|
|
3827
|
+
mountId,
|
|
3828
|
+
headerString: data.csp,
|
|
3829
|
+
mode: data.mode === "permissive" ? "permissive" : "widget-declared",
|
|
3830
|
+
intent: normalizeCspApplicationIntent(data.intent)
|
|
3831
|
+
});
|
|
3832
|
+
logWidgetDebug("ui-to-host", "debug/csp-applied", {
|
|
3833
|
+
mountId,
|
|
3834
|
+
mode: data.mode,
|
|
3835
|
+
headerLength: data.csp.length
|
|
3836
|
+
});
|
|
3837
|
+
}
|
|
3838
|
+
};
|
|
3676
3839
|
const handleSandboxMessage = (event) => {
|
|
3677
3840
|
const data = event.data;
|
|
3678
3841
|
if (!data) return;
|
|
@@ -3680,6 +3843,24 @@ function MCPAppsRendererSurface({
|
|
|
3680
3843
|
handleCspViolation(event);
|
|
3681
3844
|
return;
|
|
3682
3845
|
}
|
|
3846
|
+
if (data.type === "mcpjam:csp-applied") {
|
|
3847
|
+
handleCspApplied(event);
|
|
3848
|
+
return;
|
|
3849
|
+
}
|
|
3850
|
+
if (data.type === "mcpjam:view-mode") {
|
|
3851
|
+
const mode = data.mode;
|
|
3852
|
+
if (mode === "url" || mode === "srcdoc" || mode === "srcdoc-fallback") {
|
|
3853
|
+
const url = typeof data.url === "string" ? data.url : "";
|
|
3854
|
+
const mountId = normalizeCspMountId(data.mountId);
|
|
3855
|
+
setViewMount({ mountId, mode, url });
|
|
3856
|
+
logWidgetDebug("ui-to-host", "debug/view-mounted", {
|
|
3857
|
+
mountId,
|
|
3858
|
+
mode,
|
|
3859
|
+
url
|
|
3860
|
+
});
|
|
3861
|
+
}
|
|
3862
|
+
return;
|
|
3863
|
+
}
|
|
3683
3864
|
if (data.type === "recorder:step") {
|
|
3684
3865
|
recorderDebug2("step from sandbox", {
|
|
3685
3866
|
toolName,
|
|
@@ -3932,6 +4113,17 @@ function MCPAppsRendererSurface({
|
|
|
3932
4113
|
const hostChromeStyle = showHostChrome ? {
|
|
3933
4114
|
backgroundColor: mergedStyleVariables["--color-background-primary"]
|
|
3934
4115
|
} : void 0;
|
|
4116
|
+
const cspClientContext = {
|
|
4117
|
+
surface: "inline",
|
|
4118
|
+
clientName: hostStyleDefinition.chatUi.label ?? "Selected client",
|
|
4119
|
+
declaredCsp: widgetCsp,
|
|
4120
|
+
capabilities: {
|
|
4121
|
+
cspConnectDomains: earlyEffectiveMcpAppsCapabilities.cspConnectDomains,
|
|
4122
|
+
cspResourceDomains: earlyEffectiveMcpAppsCapabilities.cspResourceDomains,
|
|
4123
|
+
cspFrameDomains: earlyEffectiveMcpAppsCapabilities.cspFrameDomains,
|
|
4124
|
+
cspBaseUriDomains: earlyEffectiveMcpAppsCapabilities.cspBaseUriDomains
|
|
4125
|
+
}
|
|
4126
|
+
};
|
|
3935
4127
|
const iframe = /* @__PURE__ */ jsx(
|
|
3936
4128
|
SandboxedIframe,
|
|
3937
4129
|
{
|
|
@@ -3945,6 +4137,7 @@ function MCPAppsRendererSurface({
|
|
|
3945
4137
|
allowFeatures: effectiveSandbox.allowFeatures,
|
|
3946
4138
|
cspDirectives: effectiveSandbox.cspDirectives,
|
|
3947
4139
|
cspSubtypePolicy: effectiveSandbox.cspSubtypePolicy,
|
|
4140
|
+
clientContext: cspClientContext,
|
|
3948
4141
|
browserStorage: effectiveSandbox.browserStorage,
|
|
3949
4142
|
colorScheme: resolvedTheme,
|
|
3950
4143
|
recordMode,
|
|
@@ -3959,6 +4152,9 @@ function MCPAppsRendererSurface({
|
|
|
3959
4152
|
title: `MCP App: ${toolName}`,
|
|
3960
4153
|
hostedMode: host.surface.hostedMode,
|
|
3961
4154
|
sandboxOrigin: host.surface.sandboxOrigin,
|
|
4155
|
+
mountMode: host.surface.viewMountMode,
|
|
4156
|
+
viewOriginLabel,
|
|
4157
|
+
viewSubdomainsEnabled: host.surface.viewSubdomainsEnabled,
|
|
3962
4158
|
className: `bg-transparent overflow-hidden ${isFullscreen ? "flex-1 border-0 rounded-none" : `rounded-md ${matrixGatedPrefersBorder ? "border border-border/40" : ""}`}`,
|
|
3963
4159
|
style: iframeStyle
|
|
3964
4160
|
}
|
|
@@ -4096,6 +4292,7 @@ function MCPAppsRendererSurface({
|
|
|
4096
4292
|
widgetAllowFeatures: effectiveSandbox.allowFeatures,
|
|
4097
4293
|
widgetCspDirectives: effectiveSandbox.cspDirectives,
|
|
4098
4294
|
widgetCspSubtypePolicy: effectiveSandbox.cspSubtypePolicy,
|
|
4295
|
+
widgetClientContext: cspClientContext,
|
|
4099
4296
|
widgetBrowserStorage: effectiveSandbox.browserStorage,
|
|
4100
4297
|
widgetToolResult: earlyEffectiveMcpAppsCapabilities.toolResult,
|
|
4101
4298
|
hostContextRef,
|
|
@@ -4115,7 +4312,8 @@ function MCPAppsRendererSurface({
|
|
|
4115
4312
|
...log,
|
|
4116
4313
|
protocol: "mcp-apps"
|
|
4117
4314
|
}),
|
|
4118
|
-
onCspViolation: handleCspViolation
|
|
4315
|
+
onCspViolation: handleCspViolation,
|
|
4316
|
+
onCspApplied: handleCspApplied
|
|
4119
4317
|
}
|
|
4120
4318
|
),
|
|
4121
4319
|
checkoutSession != null && Checkout && /* @__PURE__ */ jsx(
|