@mcpjam/widget-react 0.1.0 → 0.1.1

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 CHANGED
@@ -778,6 +778,12 @@ interface SandboxedIframeProps {
778
778
  cspDirectives?: Record<string, string[]>;
779
779
  /** Skip CSP injection entirely (for permissive/testing mode) */
780
780
  permissive?: boolean;
781
+ /**
782
+ * Tier 2 recorder: when true, the proxy injects a recorder shim into the
783
+ * guest that posts `recorder:step` / `recorder:ready` messages (forwarded via
784
+ * `onMessage`). Default off — only the eval authoring preview sets it.
785
+ */
786
+ recordMode?: boolean;
781
787
  /** Callback when sandbox proxy is ready */
782
788
  onProxyReady?: () => void;
783
789
  /** Callback for messages from guest UI (excluding sandbox-internal messages) */
@@ -843,6 +849,28 @@ interface MCPAppsRendererProps {
843
849
  onCallTool?: (toolName: string, params: Record<string, unknown>) => Promise<unknown>;
844
850
  onAppToolInvocationChange?: (invocation: AppToolInvocationUpdate) => void;
845
851
  onWidgetStateChange?: (toolCallId: string, state: unknown) => void;
852
+ /**
853
+ * Tier 2 recorder. When `recordMode` is on, the sandbox proxy injects a
854
+ * recorder shim into the guest; `onRecorderStep` fires for each captured
855
+ * click/type (the raw `{ kind, target, ... }` step), and `onRecorderReady`
856
+ * fires once when the shim installs (so the host can detect a strict-CSP
857
+ * guest that silently blocked it). Default off — only the eval authoring
858
+ * preview sets these.
859
+ */
860
+ recordMode?: boolean;
861
+ onRecorderStep?: (step: unknown) => void;
862
+ onRecorderReady?: () => void;
863
+ /**
864
+ * Replay (inverse of recording): published when the guest shim is record-capable
865
+ * so the host can drive the live widget. The host calls `replay(step)` with one
866
+ * scripted step; the renderer relays it to the guest and resolves with the
867
+ * step's result. Published as `null` on unmount so the host drops the handle.
868
+ */
869
+ onReplayControllerReady?: (replay: ((step: unknown) => Promise<{
870
+ ok: boolean;
871
+ reason?: string;
872
+ deferred?: string;
873
+ }>) | null) => void;
846
874
  pipWidgetId?: string | null;
847
875
  fullscreenWidgetId?: string | null;
848
876
  onRequestPip?: (toolCallId: string) => void;
@@ -932,7 +960,7 @@ interface MCPAppsRendererProps {
932
960
  persistentSurfaceInitialToolCallId?: string;
933
961
  }
934
962
  declare function MCPAppsRenderer(props: MCPAppsRendererProps): react_jsx_runtime.JSX.Element;
935
- declare function MCPAppsRendererSurface({ chatSessionId, serverId, serverName, toolCallId, toolName, toolState, toolInput, toolOutput, toolResponseMetadata, toolErrorText, resourceUri, toolMetadata, toolsMetadata, onSendFollowUp, onCallTool, onAppToolInvocationChange, onWidgetStateChange, pipWidgetId, fullscreenWidgetId, onRequestPip, onExitPip, displayMode: displayModeProp, onDisplayModeChange, onRequestFullscreen, onExitFullscreen, onModelContextUpdate, onAppSupportedDisplayModesChange, onRequestTeardown, isOffline, cachedWidgetHtmlUrl, liveFetchPreferred, widgetCsp: initialWidgetCsp, widgetPermissions: initialWidgetPermissions, widgetPermissive: initialWidgetPermissive, prefersBorder: initialPrefersBorder, injectedOpenAiCompat: initialInjectedOpenAiCompat, injectedOpenAiCompatCapabilities: initialInjectedOpenAiCompatCapabilities, initialWidgetState, minimalMode, persistentSurfaceId, persistentSurfaceInitialToolCallId, }: MCPAppsRendererProps): react_jsx_runtime.JSX.Element | null;
963
+ declare function MCPAppsRendererSurface({ chatSessionId, serverId, serverName, toolCallId, toolName, toolState, toolInput, toolOutput, toolResponseMetadata, toolErrorText, resourceUri, toolMetadata, toolsMetadata, onSendFollowUp, onCallTool, onAppToolInvocationChange, onWidgetStateChange, recordMode, onRecorderStep, onRecorderReady, onReplayControllerReady, pipWidgetId, fullscreenWidgetId, onRequestPip, onExitPip, displayMode: displayModeProp, onDisplayModeChange, onRequestFullscreen, onExitFullscreen, onModelContextUpdate, onAppSupportedDisplayModesChange, onRequestTeardown, isOffline, cachedWidgetHtmlUrl, liveFetchPreferred, widgetCsp: initialWidgetCsp, widgetPermissions: initialWidgetPermissions, widgetPermissive: initialWidgetPermissive, prefersBorder: initialPrefersBorder, injectedOpenAiCompat: initialInjectedOpenAiCompat, injectedOpenAiCompatCapabilities: initialInjectedOpenAiCompatCapabilities, initialWidgetState, minimalMode, persistentSurfaceId, persistentSurfaceInitialToolCallId, }: MCPAppsRendererProps): react_jsx_runtime.JSX.Element | null;
936
964
 
937
965
  declare function WidgetSurfaceHostProvider({ children, }: {
938
966
  children: ReactNode;
package/dist/index.js CHANGED
@@ -806,6 +806,21 @@ function useToolInputStreaming({
806
806
  resetStreamingState
807
807
  };
808
808
  }
809
+ function isRecorderDebugEnabled() {
810
+ try {
811
+ return typeof window !== "undefined" && window.localStorage?.getItem("mcpjam:recorder-debug") === "1";
812
+ } catch {
813
+ return false;
814
+ }
815
+ }
816
+ function recorderDebug(message, details) {
817
+ try {
818
+ if (isRecorderDebugEnabled()) {
819
+ console.info(`[recorder:sandboxed-iframe] ${message}`, details ?? {});
820
+ }
821
+ } catch {
822
+ }
823
+ }
809
824
  var SandboxedIframe = forwardRef(function SandboxedIframe2({
810
825
  html,
811
826
  sandbox = "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox",
@@ -815,6 +830,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
815
830
  allowFeatures,
816
831
  cspDirectives,
817
832
  permissive,
833
+ recordMode,
818
834
  onProxyReady,
819
835
  onMessage,
820
836
  className,
@@ -827,6 +843,10 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
827
843
  const outerRef = useRef(null);
828
844
  const [proxyReady, setProxyReady] = useState(false);
829
845
  const lastResourceReadyKeyRef = useRef(null);
846
+ const onMessageRef = useRef(onMessage);
847
+ const onProxyReadyRef = useRef(onProxyReady);
848
+ onMessageRef.current = onMessage;
849
+ onProxyReadyRef.current = onProxyReady;
830
850
  const [sandboxProxyUrl] = useState(() => {
831
851
  const proxyPath = hostedMode ? "/api/web/apps/mcp-apps/sandbox-proxy" : "/api/apps/mcp-apps/sandbox-proxy";
832
852
  if (hostedMode && sandboxOrigin) {
@@ -881,26 +901,31 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
881
901
  }
882
902
  if (event.source !== outerRef.current?.contentWindow) return;
883
903
  if (event.data?.type === "mcp-apps:csp-violation") {
884
- onMessage(event);
904
+ onMessageRef.current(event);
885
905
  return;
886
906
  }
887
907
  if (event.data?.type === "openai:uploadFile" || event.data?.type === "openai:getFileDownloadUrl" || event.data?.type === "openai:setWidgetState" || event.data?.type === "openai:setOpenInAppUrl") {
888
- onMessage(event);
908
+ onMessageRef.current(event);
909
+ return;
910
+ }
911
+ if (event.data?.type === "recorder:step" || event.data?.type === "recorder:ready" || event.data?.type === "recorder:replay-result") {
912
+ recorderDebug(`forward ${event.data.type}`);
913
+ onMessageRef.current(event);
889
914
  return;
890
915
  }
891
916
  const { jsonrpc, method } = event.data || {};
892
917
  if (jsonrpc !== "2.0") return;
893
918
  if (method === "ui/notifications/sandbox-proxy-ready") {
894
919
  setProxyReady(true);
895
- onProxyReady?.();
920
+ onProxyReadyRef.current?.();
896
921
  return;
897
922
  }
898
923
  if (method?.startsWith("ui/notifications/sandbox-")) {
899
924
  return;
900
925
  }
901
- onMessage(event);
926
+ onMessageRef.current(event);
902
927
  },
903
- [onMessage, onProxyReady, sandboxProxyOrigin]
928
+ [sandboxProxyOrigin]
904
929
  );
905
930
  useEffect(() => {
906
931
  window.addEventListener("message", handleMessage);
@@ -922,7 +947,10 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
922
947
  permissive: permissive ?? null,
923
948
  permissions: permissions ?? null,
924
949
  sandbox,
925
- sandboxAttrs: sandboxAttrs ?? null
950
+ sandboxAttrs: sandboxAttrs ?? null,
951
+ // Include recordMode so record-capable surfaces receive the recorder
952
+ // shim, and stale/non-recordable surfaces reload without it.
953
+ recordMode: recordMode ?? null
926
954
  }),
927
955
  [
928
956
  csp,
@@ -931,7 +959,8 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
931
959
  permissive,
932
960
  permissions,
933
961
  sandbox,
934
- sandboxAttrs
962
+ sandboxAttrs,
963
+ recordMode
935
964
  ]
936
965
  );
937
966
  useEffect(() => {
@@ -961,17 +990,21 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
961
990
  // field.
962
991
  cspDirectives,
963
992
  permissive,
964
- colorScheme
993
+ colorScheme,
994
+ recordMode,
995
+ recorderDebug: isRecorderDebugEnabled()
965
996
  }
966
997
  },
967
998
  sandboxProxyOrigin
968
999
  );
969
- }, [
970
- proxyReady,
971
- html,
972
- resourceReadyKey,
973
- sandboxProxyOrigin
974
- ]);
1000
+ recorderDebug("sent resource ready", {
1001
+ recordMode: !!recordMode,
1002
+ recorderDebug: isRecorderDebugEnabled(),
1003
+ proxyReady,
1004
+ hasHtml: !!html,
1005
+ sandboxProxyOrigin
1006
+ });
1007
+ }, [proxyReady, html, resourceReadyKey, sandboxProxyOrigin]);
975
1008
  useEffect(() => {
976
1009
  if (!proxyReady || !colorScheme) return;
977
1010
  outerRef.current?.contentWindow?.postMessage(
@@ -1596,6 +1629,14 @@ function mapLogToLifecycle(method, details) {
1596
1629
  const message = typeof details.error === "string" ? details.error : typeof details.reason === "string" ? details.reason : void 0;
1597
1630
  return { kind, status, message, timestamp: Date.now() };
1598
1631
  }
1632
+ function recorderDebug2(message, details) {
1633
+ try {
1634
+ if (typeof window !== "undefined" && window.localStorage?.getItem("mcpjam:recorder-debug") === "1") {
1635
+ console.info(`[recorder:renderer] ${message}`, details ?? {});
1636
+ }
1637
+ } catch {
1638
+ }
1639
+ }
1599
1640
  var FETCH_SOURCE_KEY_SEGMENTS = [
1600
1641
  "resourceUri",
1601
1642
  "cachedReplayWidgetHtmlUrl",
@@ -1722,7 +1763,10 @@ function PersistentMCPAppsRendererRegistration(props) {
1722
1763
  function MCPAppsRenderer(props) {
1723
1764
  const persistentHostEnabled = usePersistentWidgetSurfaceHost();
1724
1765
  const isCachedReplay = !!props.cachedWidgetHtmlUrl && !props.liveFetchPreferred;
1725
- const shouldUsePersistentSurface = persistentHostEnabled && !props.isOffline && !isCachedReplay;
1766
+ const wantPersistentSurface = persistentHostEnabled && !props.isOffline && !isCachedReplay;
1767
+ const everPersistentRef = useRef(false);
1768
+ if (wantPersistentSurface) everPersistentRef.current = true;
1769
+ const shouldUsePersistentSurface = everPersistentRef.current && !props.isOffline ? true : wantPersistentSurface;
1726
1770
  if (!shouldUsePersistentSurface) {
1727
1771
  return /* @__PURE__ */ jsx(MCPAppsRendererSurface, { ...props });
1728
1772
  }
@@ -1746,6 +1790,10 @@ function MCPAppsRendererSurface({
1746
1790
  onCallTool,
1747
1791
  onAppToolInvocationChange,
1748
1792
  onWidgetStateChange,
1793
+ recordMode,
1794
+ onRecorderStep,
1795
+ onRecorderReady,
1796
+ onReplayControllerReady,
1749
1797
  pipWidgetId,
1750
1798
  fullscreenWidgetId,
1751
1799
  onRequestPip,
@@ -1772,6 +1820,44 @@ function MCPAppsRendererSurface({
1772
1820
  persistentSurfaceInitialToolCallId
1773
1821
  }) {
1774
1822
  const sandboxRef = useRef(null);
1823
+ const replayIdRef = useRef(0);
1824
+ const pendingReplaysRef = useRef(/* @__PURE__ */ new Map());
1825
+ const REPLAY_STEP_TIMEOUT_MS = 8e3;
1826
+ const replayStep = useCallback(
1827
+ (step) => new Promise((resolve) => {
1828
+ const id = replayIdRef.current += 1;
1829
+ const timer = setTimeout(() => {
1830
+ pendingReplaysRef.current.delete(id);
1831
+ resolve({ ok: false, reason: "replay step timed out" });
1832
+ }, REPLAY_STEP_TIMEOUT_MS);
1833
+ pendingReplaysRef.current.set(id, { resolve, timer });
1834
+ sandboxRef.current?.postMessage({
1835
+ type: "recorder:replay-step",
1836
+ id,
1837
+ step
1838
+ });
1839
+ }),
1840
+ []
1841
+ );
1842
+ const onReplayControllerReadyRef = useRef(onReplayControllerReady);
1843
+ onReplayControllerReadyRef.current = onReplayControllerReady;
1844
+ useEffect(() => {
1845
+ const publish = onReplayControllerReadyRef.current;
1846
+ if (!recordMode) {
1847
+ publish?.(null);
1848
+ return;
1849
+ }
1850
+ publish?.(replayStep);
1851
+ return () => {
1852
+ onReplayControllerReadyRef.current?.(null);
1853
+ const pending = pendingReplaysRef.current;
1854
+ for (const { resolve, timer } of pending.values()) {
1855
+ clearTimeout(timer);
1856
+ resolve({ ok: false, reason: "widget unmounted" });
1857
+ }
1858
+ pending.clear();
1859
+ };
1860
+ }, [recordMode, replayStep]);
1775
1861
  const host = useWidgetHost();
1776
1862
  const Checkout = host.components?.Checkout;
1777
1863
  const debug = host.debug ?? NOOP_WIDGET_DEBUG_SINK;
@@ -2026,7 +2112,24 @@ function MCPAppsRendererSurface({
2026
2112
  const [checkoutOpen, setCheckoutOpen] = useState(false);
2027
2113
  const [checkoutSession, setCheckoutSession] = useState(null);
2028
2114
  const [checkoutCallId, setCheckoutCallId] = useState(null);
2115
+ const hasRenderedLiveRef = useRef(false);
2116
+ const liveRenderIdentityKey = useMemo(
2117
+ () => stableStringifyJson({
2118
+ chatSessionId: chatSessionId ?? null,
2119
+ serverId,
2120
+ resourceUri
2121
+ }),
2122
+ [chatSessionId, serverId, resourceUri]
2123
+ );
2124
+ const liveRenderIdentityRef = useRef(null);
2125
+ const hasRenderedLiveForCurrentIdentity = useCallback(
2126
+ () => hasRenderedLiveRef.current && liveRenderIdentityRef.current === liveRenderIdentityKey,
2127
+ [liveRenderIdentityKey]
2128
+ );
2029
2129
  useEffect(() => {
2130
+ if (isCachedReplay && hasRenderedLiveForCurrentIdentity()) return;
2131
+ hasRenderedLiveRef.current = false;
2132
+ liveRenderIdentityRef.current = null;
2030
2133
  setWidgetHtml(null);
2031
2134
  setBridgeTransportReady(false);
2032
2135
  setLoadedCspMode(null);
@@ -2037,7 +2140,12 @@ function MCPAppsRendererSurface({
2037
2140
  setWidgetPermissions(void 0);
2038
2141
  setWidgetPermissive(isCachedReplay ? true : false);
2039
2142
  setPrefersBorder(cachedReplayPrefersBorder ?? true);
2040
- }, [cachedReplayWidgetHtmlUrl, cachedReplayPrefersBorder, isCachedReplay]);
2143
+ }, [
2144
+ cachedReplayWidgetHtmlUrl,
2145
+ cachedReplayPrefersBorder,
2146
+ hasRenderedLiveForCurrentIdentity,
2147
+ isCachedReplay
2148
+ ]);
2041
2149
  const bridgeRef = useRef(null);
2042
2150
  const hostContextRef = useRef(null);
2043
2151
  const isReadyRef = useRef(false);
@@ -2117,6 +2225,9 @@ function MCPAppsRendererSurface({
2117
2225
  const isActiveToolState = toolState === "input-streaming" || toolState === "input-available" || toolState === "output-available";
2118
2226
  if (!isActiveToolState) return;
2119
2227
  if (shouldWaitForCompatToolOutput) return;
2228
+ if (widgetHtml && isCachedReplay && hasRenderedLiveForCurrentIdentity()) {
2229
+ return;
2230
+ }
2120
2231
  if (widgetHtml && loadedCspMode === cspMode && loadedInjectOpenAiCompat === widgetInjectOpenAiCompatReloadKey && loadedCompatCapabilitiesHash === widgetCompatCapabilitiesReloadKey && loadedMcpAppsCapabilitiesHash === widgetMcpAppsCapabilitiesReloadKey)
2121
2232
  return;
2122
2233
  const fetchSourceKey = [
@@ -2148,6 +2259,8 @@ function MCPAppsRendererSurface({
2148
2259
  const html = await cachedResponse.text();
2149
2260
  if (!isStillCurrent()) return;
2150
2261
  setBridgeTransportReady(false);
2262
+ hasRenderedLiveRef.current = false;
2263
+ liveRenderIdentityRef.current = null;
2151
2264
  setWidgetHtml(html);
2152
2265
  setWidgetCsp(void 0);
2153
2266
  setWidgetPermissions(void 0);
@@ -2228,6 +2341,8 @@ function MCPAppsRendererSurface({
2228
2341
  return false;
2229
2342
  }
2230
2343
  setBridgeTransportReady(false);
2344
+ hasRenderedLiveRef.current = true;
2345
+ liveRenderIdentityRef.current = liveRenderIdentityKey;
2231
2346
  setWidgetHtml(html);
2232
2347
  setWidgetCsp(csp);
2233
2348
  setWidgetPermissions(permissions);
@@ -2340,6 +2455,8 @@ function MCPAppsRendererSurface({
2340
2455
  initialPrefersBorder,
2341
2456
  cachedReplayInjectOpenAiCompat,
2342
2457
  initialInjectedOpenAiCompatCapabilities,
2458
+ hasRenderedLiveForCurrentIdentity,
2459
+ liveRenderIdentityKey,
2343
2460
  shouldWaitForCompatToolOutput,
2344
2461
  recordMountStore
2345
2462
  ]);
@@ -2453,6 +2570,8 @@ function MCPAppsRendererSurface({
2453
2570
  const appendLifecycleStore = debug.appendLifecycle;
2454
2571
  const appendLifecycleRef = useRef(appendLifecycleStore);
2455
2572
  appendLifecycleRef.current = appendLifecycleStore;
2573
+ const setWidgetModelContextRef = useRef(setWidgetModelContext);
2574
+ setWidgetModelContextRef.current = setWidgetModelContext;
2456
2575
  useEffect(() => {
2457
2576
  if (loadedCspMode !== null && loadedCspMode !== cspMode) {
2458
2577
  clearCspViolations(toolCallId);
@@ -2580,6 +2699,10 @@ function MCPAppsRendererSurface({
2580
2699
  }),
2581
2700
  [effectiveHostStyle, activeMcpProfileKey, hostCapabilitiesOverrideKey]
2582
2701
  );
2702
+ const effectiveHostCapabilitiesKey = useMemo(
2703
+ () => stableStringifyJson(effectiveHostCapabilities),
2704
+ [effectiveHostCapabilities]
2705
+ );
2583
2706
  const effectiveMcpAppsCapabilities = earlyEffectiveMcpAppsCapabilities;
2584
2707
  mcpAppsCapabilitiesRef.current = effectiveMcpAppsCapabilities;
2585
2708
  themeModeRef.current = resolvedTheme;
@@ -2873,6 +2996,10 @@ function MCPAppsRendererSurface({
2873
2996
  allowFeaturesPolicy,
2874
2997
  cspDirectivesEffective
2875
2998
  ]);
2999
+ const effectiveSandboxKey = useMemo(
3000
+ () => stableStringifyJson(effectiveSandbox),
3001
+ [effectiveSandbox]
3002
+ );
2876
3003
  const sandboxHostInfo = useMemo(() => {
2877
3004
  const raw = profileHostInfo;
2878
3005
  if (!raw || typeof raw !== "object") return null;
@@ -2889,6 +3016,10 @@ function MCPAppsRendererSurface({
2889
3016
  },
2890
3017
  [activeMcpProfileKey]
2891
3018
  );
3019
+ const resolvedBridgeHostInfoKey = useMemo(
3020
+ () => stableStringifyJson(resolvedBridgeHostInfo),
3021
+ [resolvedBridgeHostInfo]
3022
+ );
2892
3023
  useEffect(() => {
2893
3024
  if (!toolCallId) return;
2894
3025
  setSandboxAppliedStore(
@@ -3024,7 +3155,9 @@ function MCPAppsRendererSurface({
3024
3155
  );
3025
3156
  },
3026
3157
  onListResourceTemplates: async () => {
3027
- const resourceTemplates = await host.services.listResourceTemplates(serverIdRef.current);
3158
+ const resourceTemplates = await host.services.listResourceTemplates(
3159
+ serverIdRef.current
3160
+ );
3028
3161
  return { resourceTemplates };
3029
3162
  },
3030
3163
  onListPrompts: async () => {
@@ -3110,7 +3243,7 @@ function MCPAppsRendererSurface({
3110
3243
  return { mode: actualMode };
3111
3244
  },
3112
3245
  onUpdateModelContext: (ctxToolCallId, { content, structuredContent }) => {
3113
- setWidgetModelContext(ctxToolCallId, {
3246
+ setWidgetModelContextRef.current(ctxToolCallId, {
3114
3247
  content,
3115
3248
  structuredContent
3116
3249
  });
@@ -3178,10 +3311,9 @@ function MCPAppsRendererSurface({
3178
3311
  },
3179
3312
  [
3180
3313
  setIsReady,
3181
- setWidgetModelContext,
3182
3314
  logWidgetDebug,
3183
3315
  refreshAppProvidedTools,
3184
- effectiveHostCapabilities
3316
+ effectiveHostCapabilitiesKey
3185
3317
  ]
3186
3318
  );
3187
3319
  useEffect(() => {
@@ -3238,7 +3370,7 @@ function MCPAppsRendererSurface({
3238
3370
  pendingRpcMethods.set(request.id, request.method);
3239
3371
  }
3240
3372
  if (SUPPRESSED_UI_LOG_METHODS.has(method)) return;
3241
- logUiEvent({
3373
+ logUiEventRef.current({
3242
3374
  widgetId: toolCallIdRef.current,
3243
3375
  serverId: serverIdRef.current,
3244
3376
  direction: "host-to-ui",
@@ -3264,7 +3396,7 @@ function MCPAppsRendererSurface({
3264
3396
  }
3265
3397
  }
3266
3398
  if (SUPPRESSED_UI_LOG_METHODS.has(method)) return;
3267
- logUiEvent({
3399
+ logUiEventRef.current({
3268
3400
  widgetId: toolCallIdRef.current,
3269
3401
  serverId: serverIdRef.current,
3270
3402
  direction: "ui-to-host",
@@ -3314,32 +3446,28 @@ function MCPAppsRendererSurface({
3314
3446
  }
3315
3447
  bridge.close().catch(() => {
3316
3448
  });
3317
- setWidgetModelContext(toolCallIdRef.current, null);
3449
+ setWidgetModelContextRef.current(toolCallIdRef.current, null);
3318
3450
  };
3319
3451
  }, [
3320
- logUiEvent,
3321
- minimalMode,
3322
- serverId,
3323
3452
  widgetHtml,
3324
3453
  sandboxProxyReady,
3325
3454
  registerBridgeHandlers,
3326
3455
  refreshAppProvidedTools,
3327
- setWidgetModelContext,
3328
- cspMode,
3329
3456
  // Bridge must rebuild when the resolved sandbox policy changes — a host
3330
3457
  // toggling sandbox policy at runtime needs the new handshake. The memo
3331
- // identity captures `widgetCsp`/`widgetPermissions`/`widgetPermissive`
3332
- // and the sandbox slice of mcpProfile transitively.
3333
- effectiveSandbox,
3458
+ // identity key captures `widgetCsp`/`widgetPermissions`/`widgetPermissive`
3459
+ // and the sandbox slice of mcpProfile transitively without treating
3460
+ // reference-only object churn as a reload signal.
3461
+ effectiveSandboxKey,
3334
3462
  logWidgetDebug,
3335
3463
  // Bridge must rebuild when the advertised host capabilities change
3336
3464
  // (host style switch or override edit) so the new handshake reflects
3337
3465
  // the new contract.
3338
- effectiveHostCapabilities,
3466
+ effectiveHostCapabilitiesKey,
3339
3467
  // Bridge must rebuild when the host identity advertised in
3340
3468
  // ui/initialize changes — switching to a template that overrides
3341
3469
  // hostInfo (e.g. ChatGPT) is observable to the View.
3342
- resolvedBridgeHostInfo
3470
+ resolvedBridgeHostInfoKey
3343
3471
  ]);
3344
3472
  useEffect(() => {
3345
3473
  const bridge = bridgeRef.current;
@@ -3394,6 +3522,37 @@ function MCPAppsRendererSurface({
3394
3522
  handleCspViolation(event);
3395
3523
  return;
3396
3524
  }
3525
+ if (data.type === "recorder:step") {
3526
+ recorderDebug2("step from sandbox", {
3527
+ toolName,
3528
+ toolCallId,
3529
+ recordMode: !!recordMode
3530
+ });
3531
+ onRecorderStep?.(data.step);
3532
+ return;
3533
+ }
3534
+ if (data.type === "recorder:ready") {
3535
+ recorderDebug2("ready from sandbox", {
3536
+ toolName,
3537
+ toolCallId,
3538
+ recordMode: !!recordMode
3539
+ });
3540
+ onRecorderReady?.();
3541
+ return;
3542
+ }
3543
+ if (data.type === "recorder:replay-result") {
3544
+ const pending = typeof data.id === "number" ? pendingReplaysRef.current.get(data.id) : void 0;
3545
+ if (pending) {
3546
+ clearTimeout(pending.timer);
3547
+ pendingReplaysRef.current.delete(data.id);
3548
+ pending.resolve({
3549
+ ok: !!data.ok,
3550
+ reason: data.reason,
3551
+ deferred: data.deferred
3552
+ });
3553
+ }
3554
+ return;
3555
+ }
3397
3556
  const liveCaps = liveOpenAiCompatCapabilitiesRef.current;
3398
3557
  const policyError = (callId, method) => {
3399
3558
  sandboxRef.current?.postMessage({
@@ -3443,10 +3602,7 @@ function MCPAppsRendererSurface({
3443
3602
  }
3444
3603
  if (data.type === "openai:setOpenInAppUrl") {
3445
3604
  if (liveCaps !== null && liveCaps.setOpenInAppUrl === false) return;
3446
- const nextUrl = resolveOpenInAppHref(
3447
- data.href,
3448
- explicitOpenInAppBaseUrl
3449
- );
3605
+ const nextUrl = resolveOpenInAppHref(data.href, explicitOpenInAppBaseUrl);
3450
3606
  if (nextUrl) {
3451
3607
  setOpenInAppUrlOverride(nextUrl);
3452
3608
  }
@@ -3618,6 +3774,7 @@ function MCPAppsRendererSurface({
3618
3774
  allowFeatures: effectiveSandbox.allowFeatures,
3619
3775
  cspDirectives: effectiveSandbox.cspDirectives,
3620
3776
  colorScheme: resolvedTheme,
3777
+ recordMode,
3621
3778
  onProxyReady: () => {
3622
3779
  setSandboxProxyReady(true);
3623
3780
  logWidgetDebug("ui-to-host", "debug/sandbox-proxy-ready", {