@mcpjam/widget-react 0.1.10 → 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 CHANGED
@@ -1,4 +1,3 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
1
  import * as react from 'react';
3
2
  import { ComponentType, ReactNode } from 'react';
4
3
  import { ToolResultPolicy, BrowserStoragePolicy, AppToolInvocationUpdate } from '@mcpjam/sdk/widget-runtime';
@@ -148,6 +147,17 @@ interface WidgetSurfaceInfo {
148
147
  hostedMode: boolean;
149
148
  /** SANDBOX_ORIGIN (VITE_MCPJAM_SANDBOX_ORIGIN); "" when unset. */
150
149
  sandboxOrigin: string;
150
+ /**
151
+ * VIEW_MOUNT_MODE (VITE_MCPJAM_VIEW_MOUNT) — how the sandbox proxy mounts
152
+ * the view. Absent means `"write"`, which is what gives the view a real URL.
153
+ */
154
+ viewMountMode?: "write" | "srcdoc";
155
+ /**
156
+ * VIEW_SUBDOMAINS_ENABLED (VITE_MCPJAM_VIEW_SUBDOMAINS) — serve each
157
+ * server's views from their own origin. Requires wildcard DNS and a
158
+ * certificate for the sandbox apex, so it is off unless a deploy has them.
159
+ */
160
+ viewSubdomainsEnabled?: boolean;
151
161
  /**
152
162
  * Playground CSP-mode selection (useUIPlaygroundStore.mcpAppsCspMode) — an
153
163
  * INPUT, not the effective mode. The renderer derives the effective sandbox
@@ -161,10 +171,23 @@ interface WidgetMount {
161
171
  reason: string;
162
172
  at: number;
163
173
  }
174
+ /** New mounts use an opaque string; numbers remain valid for saved data. */
175
+ type CspMountId = string | number;
176
+ /** What MCPJam meant to install before the sandbox proxy serialized it. */
177
+ interface CspApplicationIntent {
178
+ csp?: McpUiResourceCsp;
179
+ cspDirectives?: Record<string, string[]>;
180
+ permissive: boolean;
181
+ }
164
182
  interface CspViolation {
165
183
  directive: string;
166
184
  effectiveDirective?: string;
167
185
  blockedUri: string;
186
+ /** Id of the exact inner iframe mount that emitted this event. */
187
+ mountId?: CspMountId;
188
+ /** The policy that caused this specific violation. */
189
+ originalPolicy?: string;
190
+ disposition?: "enforce" | "report";
168
191
  sourceFile?: string | null;
169
192
  lineNumber?: number | null;
170
193
  columnNumber?: number | null;
@@ -172,7 +195,7 @@ interface CspViolation {
172
195
  subtype?: CspSubtype;
173
196
  }
174
197
  interface WidgetLifecycleEvent {
175
- kind: "sandbox-proxy-ready" | "widget-content-requested" | "widget-content-ready" | "widget-content-error" | "widget-content-invalid-mimetype" | "bridge-connect-start" | "bridge-connect-ready" | "bridge-connect-error" | "bridge-connect-skipped" | "app-initialized";
198
+ kind: "sandbox-proxy-ready" | "widget-content-requested" | "widget-content-ready" | "widget-content-error" | "widget-content-invalid-mimetype" | "bridge-connect-start" | "bridge-connect-ready" | "bridge-connect-error" | "bridge-connect-skipped" | "app-initialized" | "view-mounted";
176
199
  status: "ok" | "error" | "pending";
177
200
  message?: string;
178
201
  timestamp: number;
@@ -197,6 +220,22 @@ interface WidgetSandboxApplied {
197
220
  geolocation?: {};
198
221
  clipboardWrite?: {};
199
222
  };
223
+ /**
224
+ * How the proxy mounted the view. `"url"` means it was written into a blank
225
+ * same-origin frame and runs at the proxy's URL; the srcdoc values mean it
226
+ * has no URL of its own (`"srcdoc"` was asked for, `"srcdoc-fallback"` was
227
+ * forced because the frame's document was unreachable).
228
+ */
229
+ viewMode?: "url" | "srcdoc" | "srcdoc-fallback";
230
+ /** Id of the currently displayed inner iframe mount. */
231
+ mountId?: CspMountId;
232
+ /** The view's document URL as reported by the proxy. */
233
+ viewUrl?: string;
234
+ /**
235
+ * Origin of `viewUrl` — what a developer allowlists with a third party that
236
+ * keys on the page URL. Absent on the srcdoc paths, which have no origin.
237
+ */
238
+ assignedOrigin?: string;
200
239
  }
201
240
  interface WidgetSandboxInfo {
202
241
  mode: CspMode;
@@ -211,6 +250,14 @@ interface WidgetSandboxInfo {
211
250
  clipboardWrite?: {};
212
251
  };
213
252
  headerString?: string;
253
+ /** Latest proxy mount, retained for consumers that show current state. */
254
+ activeMountId?: CspMountId;
255
+ /** Applied policies keyed by proxy mount id so remounts cannot mix data. */
256
+ appliedPoliciesByMount?: Record<string, {
257
+ headerString: string;
258
+ mode: "permissive" | "widget-declared";
259
+ intent?: CspApplicationIntent;
260
+ }>;
214
261
  violations: CspViolation[];
215
262
  widgetDeclared?: {
216
263
  connect_domains?: string[];
@@ -220,6 +267,13 @@ interface WidgetSandboxInfo {
220
267
  frameDomains?: string[];
221
268
  baseUriDomains?: string[];
222
269
  } | null;
270
+ /**
271
+ * `_meta.ui.domain` as declared by the server, or null when it declared
272
+ * none. Compared against the origin MCPJam actually serves the view from;
273
+ * a mismatch is informational, since each host's domain format differs and
274
+ * a server can only declare one string.
275
+ */
276
+ declaredDomain?: string | null;
223
277
  }
224
278
  interface WidgetGlobals {
225
279
  theme: "light" | "dark";
@@ -301,7 +355,18 @@ interface WidgetDebugSink {
301
355
  setWidgetState: (toolCallId: string, state: unknown) => void;
302
356
  setWidgetGlobals: (toolCallId: string, globals: Partial<WidgetGlobals>) => void;
303
357
  setWidgetCsp: (toolCallId: string, csp: Omit<WidgetSandboxInfo, "violations">) => void;
358
+ /**
359
+ * The CSP string the proxy actually injected for the current mount. Merges
360
+ * into the stored `csp` object; see the store's `setWidgetAppliedCsp`.
361
+ */
362
+ setWidgetAppliedCsp: (toolCallId: string, applied: {
363
+ mountId: CspMountId;
364
+ headerString: string;
365
+ mode: "permissive" | "widget-declared";
366
+ intent?: CspApplicationIntent;
367
+ }) => void;
304
368
  addCspViolation: (toolCallId: string, violation: CspViolation) => void;
369
+ reportCspViolation: (toolCallId: string, serverId: string, violation: CspViolation) => void;
305
370
  clearCspViolations: (toolCallId: string) => void;
306
371
  setWidgetModelContext: (toolCallId: string, context: {
307
372
  content?: unknown[];
@@ -473,6 +538,19 @@ interface FetchWidgetContentResponse {
473
538
  mimeTypeWarning?: string;
474
539
  mimeTypeValid?: boolean;
475
540
  prefersBorder?: boolean;
541
+ /**
542
+ * `_meta.ui.domain` — the dedicated origin the server ASKED for. Advisory:
543
+ * MCPJam derives the origin it serves the view from, and reports this only
544
+ * so the Workbench can say whether the declaration matches.
545
+ */
546
+ declaredDomain?: string;
547
+ /**
548
+ * Subdomain label for this server's dedicated view origin
549
+ * (`<label>.sandbox.mcpjam.com`), derived from the server's identity. Absent
550
+ * when the server identifies nothing to derive from; the view then renders
551
+ * on the default sandbox origin.
552
+ */
553
+ viewOriginLabel?: string;
476
554
  injectedOpenAiCompat?: boolean;
477
555
  injectedOpenAiCompatCapabilities?: ResolvedOpenAiAppsCapabilities;
478
556
  }
@@ -510,6 +588,19 @@ interface WidgetHostServices {
510
588
  * the global `fetch` directly.
511
589
  */
512
590
  authFetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
591
+ /**
592
+ * Fetch a persisted artifact (cached widget HTML) by URL. Hosts that serve
593
+ * artifacts through short-lived links bind this to a fetch that renews an
594
+ * expired link. Optional: the renderer falls back to the global `fetch`.
595
+ */
596
+ fetchArtifact?: (url: string) => Promise<Response>;
597
+ /**
598
+ * What a cached artifact URL points at. A host whose artifact links are
599
+ * re-minted over time (a new expiry, the same object) returns a key that
600
+ * ignores the expiry, so a re-minted link does not reload a widget whose
601
+ * bytes did not change. Optional: the URL itself is the key.
602
+ */
603
+ artifactCacheKey?: (url: string) => string;
513
604
  }
514
605
  interface WidgetHost {
515
606
  /**
@@ -535,7 +626,7 @@ interface WidgetHostProviderProps {
535
626
  value: WidgetHost;
536
627
  children: ReactNode;
537
628
  }
538
- declare function WidgetHostProvider({ value, children, }: WidgetHostProviderProps): react_jsx_runtime.JSX.Element;
629
+ declare function WidgetHostProvider({ value, children, }: WidgetHostProviderProps): react.JSX.Element;
539
630
  /**
540
631
  * Read the injected {@link WidgetHost}. Throws if no `<WidgetHostProvider>` is
541
632
  * mounted above — the package never reaches into inspector state itself, so a
@@ -776,34 +867,14 @@ declare function useToolInputStreaming({ bridgeRef, isReady, isReadyRef, toolSta
776
867
 
777
868
  /** The parts of `window.location` the sandbox origin is derived from. */
778
869
  type SandboxProxyLocation = Pick<Location, "hostname" | "port" | "protocol" | "origin">;
779
- /**
780
- * Where the outer sandbox iframe loads from.
781
- *
782
- * SEP-1865: host and sandbox MUST have different origins.
783
- *
784
- * Hosted: prefer the operator-configured SANDBOX_ORIGIN
785
- * (`VITE_MCPJAM_SANDBOX_ORIGIN`). It MUST be a distinct origin from the host
786
- * app so the sandboxed iframe cannot reach host cookies or storage even when
787
- * its sandbox carries `allow-same-origin`.
788
- *
789
- * A configured origin EQUAL to the app's own counts as unset. It produces
790
- * exactly the same same-origin iframe as no value at all, and it is the more
791
- * likely of the two mistakes because it looks configured. The client boot
792
- * guard used to be the only thing that said so, and it could not tell that
793
- * case apart from the app legitimately being loaded on the sandbox hostname
794
- * (INSPECTOR-CLIENT-247) — so the deploy-level check moved to the server and
795
- * this renderer stopped walking straight through the condition.
796
- *
797
- * Local: keep the localhost ↔ 127.0.0.1 swap so dev gets the same
798
- * origin-separation property without operator config.
799
- *
800
- * Same-origin fallback exists only as a soft-fail for misconfigured hosted
801
- * deploys; it emits a loud security warning.
802
- */
803
- declare function resolveSandboxProxyUrl({ hostedMode, sandboxOrigin, location, }: {
870
+ declare function resolveSandboxProxyUrl({ hostedMode, sandboxOrigin, location, viewOriginLabel, viewSubdomainsEnabled, userAgent, }: {
804
871
  hostedMode: boolean;
805
872
  sandboxOrigin: string;
806
873
  location: SandboxProxyLocation;
874
+ /** Per-server label; views share the sandbox origin without one. */
875
+ viewOriginLabel?: string;
876
+ viewSubdomainsEnabled?: boolean;
877
+ userAgent?: string;
807
878
  }): string;
808
879
  interface SandboxedIframeHandle {
809
880
  postMessage: (data: unknown) => void;
@@ -884,6 +955,22 @@ interface SandboxedIframeProps {
884
955
  * (`host.surface.sandboxOrigin`).
885
956
  */
886
957
  sandboxOrigin?: string;
958
+ /**
959
+ * How the proxy mounts the view: `"write"` (default) writes the HTML into a
960
+ * blank same-origin iframe so the view runs at the proxy's URL; `"srcdoc"`
961
+ * restores the legacy `iframe.srcdoc` mount, where the view has no URL of
962
+ * its own. Supplied by the host (`host.surface.viewMountMode`); build-time
963
+ * only, so it exists to exercise the srcdoc branch rather than to switch
964
+ * behaviour at runtime.
965
+ */
966
+ mountMode?: "write" | "srcdoc";
967
+ /**
968
+ * Per-server label for a dedicated view origin, and whether this deploy
969
+ * serves one. Supplied by the host; without both the view renders on the
970
+ * shared sandbox origin.
971
+ */
972
+ viewOriginLabel?: string;
973
+ viewSubdomainsEnabled?: boolean;
887
974
  }
888
975
  /**
889
976
  * SandboxedIframe provides a secure double-iframe architecture per SEP-1865.
@@ -1046,17 +1133,17 @@ interface MCPAppsRendererProps {
1046
1133
  */
1047
1134
  persistentSurfaceInitialToolCallId?: string;
1048
1135
  }
1049
- declare function MCPAppsRenderer(props: MCPAppsRendererProps): react_jsx_runtime.JSX.Element;
1050
- 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, onConfirmDownload, 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;
1136
+ declare function MCPAppsRenderer(props: MCPAppsRendererProps): react.JSX.Element;
1137
+ 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, onConfirmDownload, isOffline, cachedWidgetHtmlUrl, liveFetchPreferred, widgetCsp: initialWidgetCsp, widgetPermissions: initialWidgetPermissions, widgetPermissive: initialWidgetPermissive, prefersBorder: initialPrefersBorder, injectedOpenAiCompat: initialInjectedOpenAiCompat, injectedOpenAiCompatCapabilities: initialInjectedOpenAiCompatCapabilities, initialWidgetState, minimalMode, persistentSurfaceId, persistentSurfaceInitialToolCallId, }: MCPAppsRendererProps): react.JSX.Element | null;
1051
1138
 
1052
1139
  declare function WidgetSurfaceHostProvider({ children, }: {
1053
1140
  children: ReactNode;
1054
- }): react_jsx_runtime.JSX.Element;
1141
+ }): react.JSX.Element;
1055
1142
  declare function usePersistentWidgetSurfaceHost(): boolean;
1056
1143
 
1057
1144
  declare function WidgetSurfaceHost({ chatSessionId, }: {
1058
1145
  chatSessionId?: string;
1059
- }): react_jsx_runtime.JSX.Element;
1146
+ }): react.JSX.Element;
1060
1147
 
1061
1148
  type WidgetSurfaceId = string;
1062
1149
  interface WidgetSurfaceRegistration {
@@ -1088,4 +1175,4 @@ declare function getRenderableSurfaceEntries(surfaces: Map<WidgetSurfaceId, Widg
1088
1175
  props: MCPAppsRendererProps;
1089
1176
  }[];
1090
1177
 
1091
- 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, type SandboxProxyLocation, 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, resolveSandboxProxyUrl, useAppToolAttribution, useAppToolAttributionResolver, useAppToolInvocationLog, useAppToolsRegistry, usePersistentWidgetSurfaceHost, useToolInputStreaming, useWidgetHost, useWidgetSurfaceStore };
1178
+ export { type AddTrafficLog, type AppInstance, type AppToolAlias, type AppToolAttribution, type AppToolDescriptor, type AppToolInvocationRecord, type AppToolSnapshotEntry, type BridgeId, type CspApplicationIntent, type CspMode, type CspMountId, 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, type SandboxProxyLocation, 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, resolveSandboxProxyUrl, useAppToolAttribution, useAppToolAttributionResolver, useAppToolInvocationLog, useAppToolsRegistry, usePersistentWidgetSurfaceHost, useToolInputStreaming, useWidgetHost, useWidgetSurfaceStore };