@mcpjam/widget-react 0.1.5 → 0.1.6
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 +10 -10
- package/dist/index.js +57 -13
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -35,8 +35,8 @@ interface OpenAiAppsCapabilities {
|
|
|
35
35
|
}
|
|
36
36
|
/** usePreferencesStore theme mode. */
|
|
37
37
|
type ThemeMode = "light" | "dark";
|
|
38
|
-
/** Host-style id (the inspector's `
|
|
39
|
-
type
|
|
38
|
+
/** Host-style id (the inspector's `ScenarioHostStyle`). */
|
|
39
|
+
type ScenarioHostStyle = string;
|
|
40
40
|
interface DeviceCapabilities {
|
|
41
41
|
hover: boolean;
|
|
42
42
|
touch: boolean;
|
|
@@ -105,9 +105,9 @@ interface ResolvedHostStyle {
|
|
|
105
105
|
}
|
|
106
106
|
/**
|
|
107
107
|
* Which surface the widget is mounted on. Collapses the inspector's
|
|
108
|
-
* `
|
|
108
|
+
* `useIsScenarioSurface` / `useWidgetSurface` signals into one descriptor.
|
|
109
109
|
*/
|
|
110
|
-
type WidgetSurfaceKind = "chat" | "playground" | "
|
|
110
|
+
type WidgetSurfaceKind = "chat" | "playground" | "scenario" | "standalone";
|
|
111
111
|
/** Per-surface identity + routing the renderer reads ambiently. */
|
|
112
112
|
interface WidgetSurfaceInfo {
|
|
113
113
|
kind: WidgetSurfaceKind;
|
|
@@ -362,9 +362,9 @@ interface WidgetHostProfileSandbox {
|
|
|
362
362
|
*/
|
|
363
363
|
interface WidgetHostEnvironmentInputs {
|
|
364
364
|
themeMode: ThemeMode;
|
|
365
|
-
sharedHostStyle:
|
|
366
|
-
|
|
367
|
-
|
|
365
|
+
sharedHostStyle: ScenarioHostStyle;
|
|
366
|
+
scenarioHostStyle: ScenarioHostStyle | null;
|
|
367
|
+
scenarioHostTheme: "light" | "dark" | null;
|
|
368
368
|
hostCapabilitiesOverride: Record<string, unknown> | undefined;
|
|
369
369
|
/**
|
|
370
370
|
* Stable hash of the active MCP profile. The profile object is bound in the
|
|
@@ -396,10 +396,10 @@ interface WidgetHostEnvironmentInputs {
|
|
|
396
396
|
*/
|
|
397
397
|
interface WidgetHostResolvers {
|
|
398
398
|
resolveEffectiveCompatRuntime: (args: {
|
|
399
|
-
hostStyle:
|
|
399
|
+
hostStyle: ScenarioHostStyle | string | null | undefined;
|
|
400
400
|
}) => EffectiveCompatRuntime;
|
|
401
401
|
resolveEffectiveMcpAppsCapabilities: (args: {
|
|
402
|
-
hostStyle:
|
|
402
|
+
hostStyle: ScenarioHostStyle | string | null | undefined;
|
|
403
403
|
}) => ResolvedMcpAppsCapabilities;
|
|
404
404
|
resolveEffectiveHostCapabilities: (args: {
|
|
405
405
|
hostStyle: string | null | undefined;
|
|
@@ -1014,4 +1014,4 @@ declare function getRenderableSurfaceEntries(surfaces: Map<WidgetSurfaceId, Widg
|
|
|
1014
1014
|
props: MCPAppsRendererProps;
|
|
1015
1015
|
}[];
|
|
1016
1016
|
|
|
1017
|
-
export { type AddTrafficLog, type AppInstance, type AppToolAlias, type AppToolAttribution, type AppToolDescriptor, type AppToolInvocationRecord, type AppToolSnapshotEntry, type BridgeId, type
|
|
1017
|
+
export { type AddTrafficLog, type AppInstance, type AppToolAlias, type AppToolAttribution, type AppToolDescriptor, type AppToolInvocationRecord, type AppToolSnapshotEntry, type BridgeId, type CspMode, type CspViolation, type DeviceCapabilities, type DeviceType, type DisplayMode, type EffectiveCompatRuntime, type FetchWidgetContentRequest, type FetchWidgetContentResponse, type ListResourcesResult, MCPAppsRenderer, type MCPAppsRendererProps, MCPAppsRendererSurface, type OpenAiAppsCapabilities, PARTIAL_INPUT_THROTTLE_MS, type ProjectHostContextDraft, type ResolvedHostCapabilities, type ResolvedHostInfo, type ResolvedHostStyle, type ResolvedMcpAppsCapabilities, type ResolvedOpenAiAppsCapabilities, SIGNATURE_MAX_ARRAY_ITEMS, SIGNATURE_MAX_DEPTH, SIGNATURE_MAX_OBJECT_KEYS, SIGNATURE_STRING_EDGE_LENGTH, STREAMING_REVEAL_FALLBACK_MS, type SafeAreaInsets, SandboxedIframe, type SandboxedIframeHandle, type ScenarioHostStyle, type ThemeMode, type ToolLike, type ToolState, UIType, type UiLogEvent, type UiProtocol, type UseToolInputStreamingParams, type UseToolInputStreamingReturn, type WidgetCheckoutProps, type WidgetDebugInfo, type WidgetDebugSink, type WidgetGlobals, type WidgetHost, type WidgetHostComponents, type WidgetHostEnvironment, type WidgetHostEnvironmentInputs, WidgetHostProvider, type WidgetHostProviderProps, type WidgetHostResolvers, type WidgetHostServices, type WidgetLifecycleEvent, type WidgetModalProps, type WidgetMount, type WidgetSandboxApplied, type WidgetSandboxInfo, WidgetSurfaceHost, WidgetSurfaceHostProvider, type WidgetSurfaceId, type WidgetSurfaceInfo, type WidgetSurfaceKind, type WidgetSurfaceRecord, __internal, detectUIType, detectUiTypeFromTool, getRenderableSurfaceEntries, getToolInputSignature, getUIResourceUri, readToolResultMeta, readToolResultObject, readToolResultServerId, recordAppToolInvocation, useAppToolAttribution, useAppToolAttributionResolver, useAppToolInvocationLog, useAppToolsRegistry, usePersistentWidgetSurfaceHost, useToolInputStreaming, useWidgetHost, useWidgetSurfaceStore };
|
package/dist/index.js
CHANGED
|
@@ -1529,6 +1529,7 @@ var NOOP_WIDGET_DEBUG_SINK = {
|
|
|
1529
1529
|
var DEFAULT_INPUT_SCHEMA = { type: "object" };
|
|
1530
1530
|
var SUPPRESSED_UI_LOG_METHODS = /* @__PURE__ */ new Set(["ui/notifications/size-changed"]);
|
|
1531
1531
|
var PIP_MAX_HEIGHT = "min(40vh, 600px)";
|
|
1532
|
+
var CSP_BLOCKED_NOTICE_DELAY_MS = 1500;
|
|
1532
1533
|
var SAFE_OPEN_IN_APP_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
1533
1534
|
function toSafeOpenInAppUrl(value) {
|
|
1534
1535
|
try {
|
|
@@ -1877,8 +1878,8 @@ function MCPAppsRendererSurface({
|
|
|
1877
1878
|
const { environment, resolvers } = host;
|
|
1878
1879
|
const themeMode = environment.themeMode;
|
|
1879
1880
|
const sharedHostStyle = environment.sharedHostStyle;
|
|
1880
|
-
const
|
|
1881
|
-
const
|
|
1881
|
+
const scenarioHostStyle = environment.scenarioHostStyle;
|
|
1882
|
+
const scenarioHostTheme = environment.scenarioHostTheme;
|
|
1882
1883
|
const hostCapabilitiesOverride = environment.hostCapabilitiesOverride;
|
|
1883
1884
|
const activeMcpProfileKey = environment.profileKey;
|
|
1884
1885
|
const profileSandbox = environment.profileSandbox;
|
|
@@ -1889,9 +1890,9 @@ function MCPAppsRendererSurface({
|
|
|
1889
1890
|
);
|
|
1890
1891
|
const liveEffectiveCompatRuntime = useMemo(
|
|
1891
1892
|
() => resolvers.resolveEffectiveCompatRuntime({
|
|
1892
|
-
hostStyle:
|
|
1893
|
+
hostStyle: scenarioHostStyle ?? sharedHostStyle
|
|
1893
1894
|
}),
|
|
1894
|
-
[activeMcpProfileKey,
|
|
1895
|
+
[activeMcpProfileKey, scenarioHostStyle, sharedHostStyle]
|
|
1895
1896
|
);
|
|
1896
1897
|
const liveInjectOpenAiCompat = liveEffectiveCompatRuntime.injected;
|
|
1897
1898
|
const liveOpenAiCompatCapabilities = liveEffectiveCompatRuntime.injected ? liveEffectiveCompatRuntime.capabilities : null;
|
|
@@ -1907,11 +1908,11 @@ function MCPAppsRendererSurface({
|
|
|
1907
1908
|
);
|
|
1908
1909
|
const isPlaygroundActive = environment.isPlaygroundActive;
|
|
1909
1910
|
const configuredHostTheme = resolvers.extractHostTheme(baseHostContext);
|
|
1910
|
-
const resolvedTheme = isPlaygroundActive ? configuredHostTheme ??
|
|
1911
|
+
const resolvedTheme = isPlaygroundActive ? configuredHostTheme ?? scenarioHostTheme ?? themeMode : scenarioHostTheme ?? themeMode;
|
|
1911
1912
|
const webManagedServers = host.surface.webManagedServers;
|
|
1912
1913
|
const webManagedServersRef = useRef(webManagedServers);
|
|
1913
1914
|
webManagedServersRef.current = webManagedServers;
|
|
1914
|
-
const cspMode = host.surface.kind === "
|
|
1915
|
+
const cspMode = host.surface.kind === "scenario" || minimalMode ? "permissive" : host.surface.kind === "playground" ? host.surface.playgroundCspMode : "widget-declared";
|
|
1915
1916
|
const playgroundLocale = environment.playgroundLocale;
|
|
1916
1917
|
const playgroundTimeZone = environment.playgroundTimeZone;
|
|
1917
1918
|
const fallbackLocale = isPlaygroundActive ? playgroundLocale : navigator.language || "en-US";
|
|
@@ -1927,7 +1928,7 @@ function MCPAppsRendererSurface({
|
|
|
1927
1928
|
() => resolvers.extractHostDisplayModes(draftHostContext),
|
|
1928
1929
|
[draftHostContext]
|
|
1929
1930
|
);
|
|
1930
|
-
const earlyEffectiveHostStyle = isPlaygroundActive ? sharedHostStyle :
|
|
1931
|
+
const earlyEffectiveHostStyle = isPlaygroundActive ? sharedHostStyle : scenarioHostStyle;
|
|
1931
1932
|
const earlyEffectiveMcpAppsCapabilities = useMemo(
|
|
1932
1933
|
() => resolvers.resolveEffectiveMcpAppsCapabilities({
|
|
1933
1934
|
hostStyle: earlyEffectiveHostStyle
|
|
@@ -2060,6 +2061,7 @@ function MCPAppsRendererSurface({
|
|
|
2060
2061
|
const [isReady, setIsReady] = useState(false);
|
|
2061
2062
|
const [reinitCount, setReinitCount] = useState(0);
|
|
2062
2063
|
const [loadError, setLoadError] = useState(null);
|
|
2064
|
+
const [firstCspBlock, setFirstCspBlock] = useState(null);
|
|
2063
2065
|
const [widgetHtml, setWidgetHtml] = useState(null);
|
|
2064
2066
|
const [openInAppUrlOverride, setOpenInAppUrlOverride] = useState(null);
|
|
2065
2067
|
const [sandboxProxyReady, setSandboxProxyReady] = useState(false);
|
|
@@ -2153,6 +2155,7 @@ function MCPAppsRendererSurface({
|
|
|
2153
2155
|
setWidgetPermissions(void 0);
|
|
2154
2156
|
setWidgetPermissive(isCachedReplay ? true : false);
|
|
2155
2157
|
setPrefersBorder(cachedReplayPrefersBorder ?? true);
|
|
2158
|
+
setFirstCspBlock(null);
|
|
2156
2159
|
}, [
|
|
2157
2160
|
cachedReplayWidgetHtmlUrl,
|
|
2158
2161
|
cachedReplayPrefersBorder,
|
|
@@ -2277,6 +2280,7 @@ function MCPAppsRendererSurface({
|
|
|
2277
2280
|
liveRenderIdentityRef.current = null;
|
|
2278
2281
|
setWidgetHtml(html);
|
|
2279
2282
|
setWidgetCsp(void 0);
|
|
2283
|
+
setFirstCspBlock(null);
|
|
2280
2284
|
setWidgetPermissions(void 0);
|
|
2281
2285
|
setWidgetPermissive(true);
|
|
2282
2286
|
setPrefersBorder(initialPrefersBorder ?? true);
|
|
@@ -2359,6 +2363,7 @@ function MCPAppsRendererSurface({
|
|
|
2359
2363
|
liveRenderIdentityRef.current = liveRenderIdentityKey;
|
|
2360
2364
|
setWidgetHtml(html);
|
|
2361
2365
|
setWidgetCsp(csp);
|
|
2366
|
+
setFirstCspBlock(null);
|
|
2362
2367
|
setWidgetPermissions(permissions);
|
|
2363
2368
|
setWidgetPermissive(permissive ?? false);
|
|
2364
2369
|
setPrefersBorder(prefersBorder2 ?? true);
|
|
@@ -2589,6 +2594,7 @@ function MCPAppsRendererSurface({
|
|
|
2589
2594
|
useEffect(() => {
|
|
2590
2595
|
if (loadedCspMode !== null && loadedCspMode !== cspMode) {
|
|
2591
2596
|
clearCspViolations(toolCallId);
|
|
2597
|
+
setFirstCspBlock(null);
|
|
2592
2598
|
}
|
|
2593
2599
|
}, [cspMode, loadedCspMode, toolCallId, clearCspViolations]);
|
|
2594
2600
|
useEffect(() => {
|
|
@@ -2596,6 +2602,7 @@ function MCPAppsRendererSurface({
|
|
|
2596
2602
|
const capabilitiesChanged = loadedCompatCapabilitiesHash !== null && loadedCompatCapabilitiesHash !== widgetCompatCapabilitiesReloadKey || loadedMcpAppsCapabilitiesHash !== null && loadedMcpAppsCapabilitiesHash !== widgetMcpAppsCapabilitiesReloadKey;
|
|
2597
2603
|
if (injectionChanged || capabilitiesChanged) {
|
|
2598
2604
|
clearCspViolations(toolCallId);
|
|
2605
|
+
setFirstCspBlock(null);
|
|
2599
2606
|
}
|
|
2600
2607
|
}, [
|
|
2601
2608
|
widgetInjectOpenAiCompatReloadKey,
|
|
@@ -2699,7 +2706,7 @@ function MCPAppsRendererSurface({
|
|
|
2699
2706
|
safeAreaInsets,
|
|
2700
2707
|
setWidgetGlobals
|
|
2701
2708
|
]);
|
|
2702
|
-
const effectiveHostStyle = isPlaygroundActive ? sharedHostStyle :
|
|
2709
|
+
const effectiveHostStyle = isPlaygroundActive ? sharedHostStyle : scenarioHostStyle;
|
|
2703
2710
|
const hostStyleDefinition = resolvers.getHostStyleOrDefault(effectiveHostStyle);
|
|
2704
2711
|
const activeShimCapabilities = isCachedReplay ? initialInjectedOpenAiCompatCapabilities ?? null : liveOpenAiCompatCapabilities;
|
|
2705
2712
|
const liveOpenAiCompatCapabilitiesRef = useRef(
|
|
@@ -2856,7 +2863,7 @@ function MCPAppsRendererSurface({
|
|
|
2856
2863
|
return true;
|
|
2857
2864
|
})
|
|
2858
2865
|
);
|
|
2859
|
-
const userTogglePermissive = cspMode === "permissive" && isPlaygroundActive && host.surface.kind !== "
|
|
2866
|
+
const userTogglePermissive = cspMode === "permissive" && isPlaygroundActive && host.surface.kind !== "scenario" && !minimalMode;
|
|
2860
2867
|
if (userTogglePermissive) {
|
|
2861
2868
|
let resolvedPermissions2;
|
|
2862
2869
|
if (sandboxPermissionsPolicy) {
|
|
@@ -3014,6 +3021,14 @@ function MCPAppsRendererSurface({
|
|
|
3014
3021
|
() => stableStringifyJson(effectiveSandbox),
|
|
3015
3022
|
[effectiveSandbox]
|
|
3016
3023
|
);
|
|
3024
|
+
const lastEffectiveSandboxKeyRef = useRef(null);
|
|
3025
|
+
useEffect(() => {
|
|
3026
|
+
const previous = lastEffectiveSandboxKeyRef.current;
|
|
3027
|
+
lastEffectiveSandboxKeyRef.current = effectiveSandboxKey;
|
|
3028
|
+
if (previous === null || previous === effectiveSandboxKey) return;
|
|
3029
|
+
clearCspViolations(toolCallId);
|
|
3030
|
+
setFirstCspBlock(null);
|
|
3031
|
+
}, [effectiveSandboxKey, toolCallId, clearCspViolations]);
|
|
3017
3032
|
const sandboxHostInfo = useMemo(() => {
|
|
3018
3033
|
const raw = profileHostInfo;
|
|
3019
3034
|
if (!raw || typeof raw !== "object") return null;
|
|
@@ -3339,9 +3354,7 @@ function MCPAppsRendererSurface({
|
|
|
3339
3354
|
const link = item;
|
|
3340
3355
|
const safeHref = toSafeDownloadLinkUrl(link.uri);
|
|
3341
3356
|
if (safeHref === null) {
|
|
3342
|
-
throw new Error(
|
|
3343
|
-
`Unsupported download URI: ${link.uri}`
|
|
3344
|
-
);
|
|
3357
|
+
throw new Error(`Unsupported download URI: ${link.uri}`);
|
|
3345
3358
|
}
|
|
3346
3359
|
window.open(safeHref, "_blank", "noopener,noreferrer");
|
|
3347
3360
|
}
|
|
@@ -3560,6 +3573,12 @@ function MCPAppsRendererSurface({
|
|
|
3560
3573
|
columnNumber,
|
|
3561
3574
|
timestamp: timestamp || Date.now()
|
|
3562
3575
|
});
|
|
3576
|
+
setFirstCspBlock(
|
|
3577
|
+
(prev) => prev ?? {
|
|
3578
|
+
directive: typeof effectiveDirective === "string" && effectiveDirective ? effectiveDirective : typeof directive === "string" ? directive : void 0,
|
|
3579
|
+
blockedUri: typeof blockedUri === "string" ? blockedUri : void 0
|
|
3580
|
+
}
|
|
3581
|
+
);
|
|
3563
3582
|
if (!minimalMode) {
|
|
3564
3583
|
console.warn(
|
|
3565
3584
|
`[MCP Apps CSP Violation] ${directive}: Blocked ${blockedUri}`,
|
|
@@ -3702,6 +3721,19 @@ function MCPAppsRendererSurface({
|
|
|
3702
3721
|
}
|
|
3703
3722
|
};
|
|
3704
3723
|
const showWidget = isReady && canRenderStreamingInput;
|
|
3724
|
+
const [cspBlockedNoticeVisible, setCspBlockedNoticeVisible] = useState(false);
|
|
3725
|
+
useEffect(() => {
|
|
3726
|
+
if (!firstCspBlock || isReady) {
|
|
3727
|
+
setCspBlockedNoticeVisible(false);
|
|
3728
|
+
return;
|
|
3729
|
+
}
|
|
3730
|
+
const timer = window.setTimeout(
|
|
3731
|
+
() => setCspBlockedNoticeVisible(true),
|
|
3732
|
+
CSP_BLOCKED_NOTICE_DELAY_MS
|
|
3733
|
+
);
|
|
3734
|
+
return () => window.clearTimeout(timer);
|
|
3735
|
+
}, [firstCspBlock, isReady]);
|
|
3736
|
+
const showCspBlockedNotice = cspBlockedNoticeVisible && !showWidget;
|
|
3705
3737
|
useEffect(() => {
|
|
3706
3738
|
logWidgetDebug("host-to-ui", "debug/widget-visibility", {
|
|
3707
3739
|
bridgeTransportReady,
|
|
@@ -3811,7 +3843,7 @@ function MCPAppsRendererSurface({
|
|
|
3811
3843
|
// Keep iframe in the layout but invisible while not ready
|
|
3812
3844
|
...!showWidget ? { position: "absolute", pointerEvents: "none" } : {}
|
|
3813
3845
|
};
|
|
3814
|
-
const showHostChrome = !isFullscreen && matrixGatedPrefersBorder;
|
|
3846
|
+
const showHostChrome = !isFullscreen && matrixGatedPrefersBorder && !showCspBlockedNotice;
|
|
3815
3847
|
const hostChromeStyle = showHostChrome ? {
|
|
3816
3848
|
backgroundColor: mergedStyleVariables["--color-background-primary"]
|
|
3817
3849
|
} : void 0;
|
|
@@ -3938,6 +3970,18 @@ function MCPAppsRendererSurface({
|
|
|
3938
3970
|
children: iframe
|
|
3939
3971
|
}
|
|
3940
3972
|
),
|
|
3973
|
+
showCspBlockedNotice && /* @__PURE__ */ jsxs(
|
|
3974
|
+
"div",
|
|
3975
|
+
{
|
|
3976
|
+
"data-testid": "mcp-app-csp-blocked-notice",
|
|
3977
|
+
role: "status",
|
|
3978
|
+
className: "border border-destructive/40 bg-destructive/10 text-destructive text-xs rounded-md px-3 py-2",
|
|
3979
|
+
children: [
|
|
3980
|
+
/* @__PURE__ */ jsx("span", { children: minimalMode ? "This app couldn't load its resources." : `MCP App blocked by Content Security Policy${firstCspBlock?.directive ? ` (${firstCspBlock.directive})` : ""}.` }),
|
|
3981
|
+
firstCspBlock?.blockedUri ? /* @__PURE__ */ jsx("span", { className: "mt-0.5 block font-mono break-all opacity-80", children: firstCspBlock.blockedUri }) : null
|
|
3982
|
+
]
|
|
3983
|
+
}
|
|
3984
|
+
),
|
|
3941
3985
|
pendingAppToolCalls > 0 && !isFullscreen && /* @__PURE__ */ jsx(
|
|
3942
3986
|
"div",
|
|
3943
3987
|
{
|