@mcpjam/widget-react 0.1.15 → 0.1.17
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 +9 -0
- package/dist/index.js +54 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -176,6 +176,15 @@ interface WidgetSurfaceInfo {
|
|
|
176
176
|
* refuses the App either. Absent: modes are negotiated as usual.
|
|
177
177
|
*/
|
|
178
178
|
fixedDisplayMode?: DisplayMode;
|
|
179
|
+
/**
|
|
180
|
+
* Apply OpenAI's display-mode rules (ChatGPT and Codex with the Display
|
|
181
|
+
* modes extension on): omitted resource modes mean every host mode, a
|
|
182
|
+
* preference picks the starting mode without narrowing, a resource that
|
|
183
|
+
* declares both inline and fullscreen starts fullscreen, and a fixed mode
|
|
184
|
+
* the initialized App says it cannot show refuses the App. Absent: modes are
|
|
185
|
+
* negotiated as before.
|
|
186
|
+
*/
|
|
187
|
+
openAIDisplayModes?: boolean;
|
|
179
188
|
}
|
|
180
189
|
interface WidgetMount {
|
|
181
190
|
index: number;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createContext, forwardRef, useRef, useState, useMemo, useImperativeHandle, useCallback, useEffect, useContext, useLayoutEffect, Fragment as Fragment$1 } from 'react';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
import { isUIResource } from '@mcp-ui/client';
|
|
4
|
-
import { buildOuterAllowAttribute, buildOuterSandboxAttribute, stableStringifyJson, resolveToolUiResourceUri, applyToolResultPolicy, negotiateResourceDisplayModes, registerHostBridgeHandlers, createHostAppBridge, LoggingTransport, extractMethod } from '@mcpjam/sdk/widget-runtime';
|
|
4
|
+
import { buildOuterAllowAttribute, buildOuterSandboxAttribute, stableStringifyJson, resolveToolUiResourceUri, applyToolResultPolicy, openAIDisplayModes, negotiateResourceDisplayModes, registerHostBridgeHandlers, pickOpenAIDisplayMode, createHostAppBridge, LoggingTransport, extractMethod } from '@mcpjam/sdk/widget-runtime';
|
|
5
5
|
export { getToolVisibility, isVisibleToAppOnly, isVisibleToModelOnly } from '@mcpjam/sdk/widget-runtime';
|
|
6
6
|
import { useStore, create } from 'zustand';
|
|
7
7
|
import { useShallow } from 'zustand/react/shallow';
|
|
@@ -1245,6 +1245,27 @@ function useInitialRenderOutcome(ready, failed, notify) {
|
|
|
1245
1245
|
}
|
|
1246
1246
|
}, [ready, failed, notify]);
|
|
1247
1247
|
}
|
|
1248
|
+
function useSandboxProxyGeneration({
|
|
1249
|
+
bridgeTransportReady,
|
|
1250
|
+
hasWidgetHtml,
|
|
1251
|
+
logReady
|
|
1252
|
+
}) {
|
|
1253
|
+
const [generation, setGeneration] = useState(0);
|
|
1254
|
+
const bridgeTransportReadyRef = useRef(bridgeTransportReady);
|
|
1255
|
+
bridgeTransportReadyRef.current = bridgeTransportReady;
|
|
1256
|
+
const hasWidgetHtmlRef = useRef(hasWidgetHtml);
|
|
1257
|
+
hasWidgetHtmlRef.current = hasWidgetHtml;
|
|
1258
|
+
const logReadyRef = useRef(logReady);
|
|
1259
|
+
logReadyRef.current = logReady;
|
|
1260
|
+
const onReady = useCallback(() => {
|
|
1261
|
+
setGeneration((current) => current + 1);
|
|
1262
|
+
logReadyRef.current({
|
|
1263
|
+
bridgeTransportReady: bridgeTransportReadyRef.current,
|
|
1264
|
+
hasWidgetHtml: hasWidgetHtmlRef.current
|
|
1265
|
+
});
|
|
1266
|
+
}, []);
|
|
1267
|
+
return { generation, onReady };
|
|
1268
|
+
}
|
|
1248
1269
|
var WidgetFullscreenPlacementContext = createContext(null);
|
|
1249
1270
|
function McpAppsModal({
|
|
1250
1271
|
open,
|
|
@@ -2344,9 +2365,14 @@ function MCPAppsRendererSurface({
|
|
|
2344
2365
|
const fixedDisplayMode = host.surface.fixedDisplayMode;
|
|
2345
2366
|
const fixedDisplayModeRef = useRef(fixedDisplayMode);
|
|
2346
2367
|
fixedDisplayModeRef.current = fixedDisplayMode;
|
|
2368
|
+
const openAIRules = host.surface.openAIDisplayModes === true;
|
|
2369
|
+
const openAIRulesRef = useRef(openAIRules);
|
|
2370
|
+
openAIRulesRef.current = openAIRules;
|
|
2347
2371
|
const displayModesFor = useCallback(
|
|
2348
2372
|
(hostModes, hints, appModes) => {
|
|
2349
2373
|
const fixed = fixedDisplayModeRef.current;
|
|
2374
|
+
if (openAIRulesRef.current)
|
|
2375
|
+
return openAIDisplayModes(hostModes, hints, appModes, fixed);
|
|
2350
2376
|
return fixed && hostModes.includes(fixed) ? [fixed] : negotiateResourceDisplayModes([...hostModes], hints, appModes);
|
|
2351
2377
|
},
|
|
2352
2378
|
[]
|
|
@@ -2360,6 +2386,7 @@ function MCPAppsRendererSurface({
|
|
|
2360
2386
|
[
|
|
2361
2387
|
displayModesFor,
|
|
2362
2388
|
fixedDisplayMode,
|
|
2389
|
+
openAIRules,
|
|
2363
2390
|
hostAvailableDisplayModes,
|
|
2364
2391
|
resourceDisplayHints,
|
|
2365
2392
|
appSupportedDisplayModes
|
|
@@ -2503,7 +2530,6 @@ function MCPAppsRendererSurface({
|
|
|
2503
2530
|
const [firstCspBlock, setFirstCspBlock] = useState(null);
|
|
2504
2531
|
const [widgetHtml, setWidgetHtml] = useState(null);
|
|
2505
2532
|
const [openInAppUrlOverride, setOpenInAppUrlOverride] = useState(null);
|
|
2506
|
-
const [sandboxProxyReady, setSandboxProxyReady] = useState(false);
|
|
2507
2533
|
const [viewMount, setViewMount] = useState(null);
|
|
2508
2534
|
const [bridgeTransportReady, setBridgeTransportReady] = useState(false);
|
|
2509
2535
|
const [bridgeGeneration, setBridgeGeneration] = useState(0);
|
|
@@ -2823,8 +2849,9 @@ function MCPAppsRendererSurface({
|
|
|
2823
2849
|
return false;
|
|
2824
2850
|
}
|
|
2825
2851
|
setResourceDisplayHints(resourceHints);
|
|
2826
|
-
|
|
2827
|
-
|
|
2852
|
+
const initialMode = openAIRulesRef.current ? pickOpenAIDisplayMode(allowed, resourceHints) : resourceHints?.preferredDisplayMode;
|
|
2853
|
+
if (initialMode && allowed.includes(initialMode) && !(openAIRulesRef.current && initialMode === effectiveDisplayModeRef.current)) {
|
|
2854
|
+
setDisplayMode(initialMode);
|
|
2828
2855
|
}
|
|
2829
2856
|
setWidgetHtml(html);
|
|
2830
2857
|
setWidgetCsp(csp);
|
|
@@ -3663,11 +3690,21 @@ function MCPAppsRendererSurface({
|
|
|
3663
3690
|
declaredAppModes
|
|
3664
3691
|
);
|
|
3665
3692
|
if (negotiated.length === 0) {
|
|
3666
|
-
|
|
3693
|
+
const fixed = fixedDisplayModeRef.current;
|
|
3694
|
+
setLoadError(
|
|
3695
|
+
openAIRulesRef.current && fixed === "fullscreen" ? "This App can't open here because it doesn't support full screen. Add full screen support to the App, then open it again." : "This App has no supported display mode"
|
|
3696
|
+
);
|
|
3667
3697
|
void b.close();
|
|
3668
3698
|
return;
|
|
3669
3699
|
}
|
|
3670
3700
|
setAppSupportedDisplayModes(declaredAppModes);
|
|
3701
|
+
if (openAIRulesRef.current && !negotiated.includes(effectiveDisplayModeRef.current)) {
|
|
3702
|
+
const next = pickOpenAIDisplayMode(
|
|
3703
|
+
negotiated,
|
|
3704
|
+
resourceDisplayHintsRef.current
|
|
3705
|
+
);
|
|
3706
|
+
if (next) setDisplayModeRef.current(next);
|
|
3707
|
+
}
|
|
3671
3708
|
if (wasReady) {
|
|
3672
3709
|
setReinitCount((c) => c + 1);
|
|
3673
3710
|
}
|
|
@@ -3938,9 +3975,17 @@ function MCPAppsRendererSurface({
|
|
|
3938
3975
|
hasOwnedMessage
|
|
3939
3976
|
]
|
|
3940
3977
|
);
|
|
3978
|
+
const {
|
|
3979
|
+
generation: sandboxProxyGeneration,
|
|
3980
|
+
onReady: handleSandboxProxyReady
|
|
3981
|
+
} = useSandboxProxyGeneration({
|
|
3982
|
+
bridgeTransportReady,
|
|
3983
|
+
hasWidgetHtml,
|
|
3984
|
+
logReady: (details) => logWidgetDebug("ui-to-host", "debug/sandbox-proxy-ready", details)
|
|
3985
|
+
});
|
|
3941
3986
|
useEffect(() => {
|
|
3942
3987
|
if (!widgetHtml) return;
|
|
3943
|
-
if (
|
|
3988
|
+
if (sandboxProxyGeneration === 0) {
|
|
3944
3989
|
logWidgetDebug("host-to-ui", "debug/bridge-connect-skipped", {
|
|
3945
3990
|
reason: "sandbox-proxy-not-ready"
|
|
3946
3991
|
});
|
|
@@ -4079,7 +4124,8 @@ function MCPAppsRendererSurface({
|
|
|
4079
4124
|
};
|
|
4080
4125
|
}, [
|
|
4081
4126
|
widgetHtml,
|
|
4082
|
-
|
|
4127
|
+
// A reloaded proxy is a new window with no view: reconnect to it.
|
|
4128
|
+
sandboxProxyGeneration,
|
|
4083
4129
|
registerBridgeHandlers,
|
|
4084
4130
|
refreshAppProvidedTools,
|
|
4085
4131
|
// Bridge must rebuild when the resolved sandbox policy changes — a host
|
|
@@ -4504,13 +4550,7 @@ function MCPAppsRendererSurface({
|
|
|
4504
4550
|
browserStorage: effectiveSandbox.browserStorage,
|
|
4505
4551
|
colorScheme: resolvedTheme,
|
|
4506
4552
|
recordMode,
|
|
4507
|
-
onProxyReady:
|
|
4508
|
-
setSandboxProxyReady(true);
|
|
4509
|
-
logWidgetDebug("ui-to-host", "debug/sandbox-proxy-ready", {
|
|
4510
|
-
bridgeTransportReady,
|
|
4511
|
-
hasWidgetHtml
|
|
4512
|
-
});
|
|
4513
|
-
},
|
|
4553
|
+
onProxyReady: handleSandboxProxyReady,
|
|
4514
4554
|
onMessage: handleSandboxMessage,
|
|
4515
4555
|
title: `MCP App: ${toolName}`,
|
|
4516
4556
|
hostedMode: host.surface.hostedMode,
|