@mcpjam/widget-react 0.2.1 → 0.3.0

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,10 +1,10 @@
1
1
  import * as react from 'react';
2
2
  import { ComponentType, ReactNode, ContextType } from 'react';
3
3
  import * as _mcpjam_sdk_widget_runtime from '@mcpjam/sdk/widget-runtime';
4
- import { ToolResultPolicy, BrowserStoragePolicy, AppToolInvocationUpdate } from '@mcpjam/sdk/widget-runtime';
4
+ import { ToolResultPolicy, PrepareSandboxViewRequest, PreparedSandboxView, ReleaseSandboxViewRequest, BrowserStoragePolicy, DisplayBehavior, AppToolRequestContext, AppToolInvocationUpdate } from '@mcpjam/sdk/widget-runtime';
5
5
  export { getToolVisibility, isVisibleToAppOnly, isVisibleToModelOnly } from '@mcpjam/sdk/widget-runtime';
6
- import { McpUiResourceCsp, McpUiResourcePermissions, McpUiHostCapabilities, McpUiStyles, McpUiHostContext, AppBridge } from '@modelcontextprotocol/ext-apps/app-bridge';
7
- import { SandboxCspPolicy, SandboxPermissionsPolicy, MCPPrompt, MCPResourceTemplate } from '@mcpjam/sdk/browser';
6
+ import { McpUiResourceCsp, McpUiResourcePermissions, McpUiHostCapabilities, McpUiStyles, AppBridge, McpUiHostContext } from '@modelcontextprotocol/ext-apps/app-bridge';
7
+ import { MCPPrompt, MCPResourceTemplate, SandboxCspPolicy, SandboxPermissionsPolicy } from '@mcpjam/sdk/browser';
8
8
  import * as zustand from 'zustand';
9
9
  import { StoreApi } from 'zustand';
10
10
  import { CallToolResult, ContentBlock } from '@modelcontextprotocol/client';
@@ -177,14 +177,16 @@ interface WidgetSurfaceInfo {
177
177
  */
178
178
  fixedDisplayMode?: DisplayMode;
179
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.
180
+ * How the client picks display modes while its Display modes extension is
181
+ * on. `hints` names the resource metadata the hints come from. `start:
182
+ * "hint-first"` is OpenAI's rules: omitted resource modes mean every host
183
+ * mode, a preference picks the starting mode without narrowing, a resource
184
+ * that declares both inline and fullscreen starts fullscreen, and a fixed
185
+ * mode the initialized App says it cannot show refuses the App.
186
+ * `"inline-then-move"` is Claude's: the App starts inline and moves once to
187
+ * the side panel. Absent: modes are negotiated as before.
186
188
  */
187
- openAIDisplayModes?: boolean;
189
+ displayBehavior?: DisplayBehavior;
188
190
  }
189
191
  interface WidgetMount {
190
192
  index: number;
@@ -571,7 +573,12 @@ interface FetchWidgetContentRequest {
571
573
  forceWebEndpoint?: boolean;
572
574
  }
573
575
  interface FetchWidgetContentResponse {
576
+ sourceReceipt?: string;
574
577
  resourceDisplayHints?: _mcpjam_sdk_widget_runtime.ResourceDisplayHints;
578
+ /** `_meta.ui` display hints, read under `displayBehavior.hints: "ui"`. */
579
+ uiDisplayHints?: _mcpjam_sdk_widget_runtime.ResourceDisplayHints;
580
+ /** A `_meta.ui.preferredDisplayMode` that isn't a mode, as JSON; ignored. */
581
+ ignoredPreferredDisplayMode?: string;
575
582
  html: string;
576
583
  csp?: McpUiResourceCsp;
577
584
  permissions?: McpUiResourcePermissions;
@@ -611,6 +618,8 @@ type ListResourcesResult = {
611
618
  * HOSTED_MODE / web-managed guard before calling the raw api.
612
619
  */
613
620
  interface WidgetHostServices {
621
+ prepareSandboxView?: (request: PrepareSandboxViewRequest, signal?: AbortSignal) => Promise<PreparedSandboxView>;
622
+ releaseSandboxView?: (request: ReleaseSandboxViewRequest) => Promise<void>;
614
623
  /** Host-admitted plugin navigation, never arbitrary external navigation. */
615
624
  openAppLink?: (url: string) => Promise<void>;
616
625
  sendMessage?: (params: unknown) => Promise<Record<string, unknown>>;
@@ -716,15 +725,24 @@ declare function readToolResultObject(result: unknown): Record<string, unknown>
716
725
  declare function readToolResultMeta(result: unknown): Record<string, unknown> | undefined;
717
726
  declare function readToolResultServerId(result: unknown): string | undefined;
718
727
 
728
+ /** Host presentation only; never changes tool routing or grants authority. */
729
+ interface AppToolPresentation {
730
+ label?: string;
731
+ visibility?: "visible" | "hidden";
732
+ }
733
+
719
734
  /** Injected traffic-log sink — `WidgetDebugSink["addTrafficLog"]`. */
720
735
  type AddTrafficLog = WidgetDebugSink["addTrafficLog"];
721
736
  /** Per-AppBridge instance identifier (independent of parentToolCallId). */
722
737
  type BridgeId = string;
723
738
  type AppToolDescriptor = NonNullable<Awaited<ReturnType<AppBridge["listTools"]>>["tools"]>[number];
724
739
  interface AppInstance {
740
+ presentation?: AppToolPresentation;
725
741
  bridgeId: BridgeId;
726
742
  /** Chat session/lane that owns this rendered iframe. */
727
743
  chatSessionId?: string;
744
+ /** Retained workspace Apps target this conversation without changing ownership. */
745
+ getModelChatSessionId?: () => string | undefined;
728
746
  /** The host tool call whose render mounted this iframe. */
729
747
  parentToolCallId: string;
730
748
  serverId: string;
@@ -752,6 +770,8 @@ interface AppToolAlias {
752
770
  }
753
771
  /** What the snapshot ships to the server in the chat POST body. */
754
772
  interface AppToolSnapshotEntry {
773
+ /** Exact bridge generation; older clients omit it and cannot use native app tools. */
774
+ bridgeId?: string;
755
775
  alias: string;
756
776
  appName: string;
757
777
  appVersion?: string;
@@ -767,6 +787,7 @@ interface AppToolAttribution {
767
787
  appName: string;
768
788
  }
769
789
  interface AppToolsRegistryState {
790
+ updatePresentation: (bridgeId: string, presentation: AppToolPresentation) => void;
770
791
  enabled: boolean;
771
792
  instancesByBridgeId: Map<BridgeId, AppInstance>;
772
793
  aliases: Map<string, AppToolAlias>;
@@ -1042,6 +1063,11 @@ interface UseToolInputStreamingReturn {
1042
1063
  }
1043
1064
  declare function useToolInputStreaming({ bridgeRef, isReady, isReadyRef, toolState, toolInput, toolOutput, toolErrorText, toolCallId, sendToolInput, onToolInputSent, reinitCount, mcpAppsCapabilitiesRef, }: UseToolInputStreamingParams): UseToolInputStreamingReturn;
1044
1065
 
1066
+ interface SandboxViewAdmission {
1067
+ services: Pick<WidgetHostServices, "prepareSandboxView" | "releaseSandboxView">;
1068
+ request: Omit<PrepareSandboxViewRequest, "viewInstanceId" | "admissionId" | "hostOrigin">;
1069
+ }
1070
+
1045
1071
  /** The parts of `window.location` the sandbox origin is derived from. */
1046
1072
  type SandboxProxyLocation = Pick<Location, "hostname" | "port" | "protocol" | "origin">;
1047
1073
  declare function resolveSandboxProxyUrl({ hostedMode, sandboxOrigin, location, viewOriginLabel, viewSubdomainsEnabled, userAgent, }: {
@@ -1058,6 +1084,8 @@ interface SandboxedIframeHandle {
1058
1084
  getIframeElement: () => HTMLIFrameElement | null;
1059
1085
  }
1060
1086
  interface SandboxedIframeProps {
1087
+ /** An authorized host supplies this before loading any proxy document. */
1088
+ viewAdmission?: SandboxViewAdmission;
1061
1089
  /** HTML content to render in the sandbox */
1062
1090
  html: string | null;
1063
1091
  /** Sandbox attribute for the inner iframe */
@@ -1170,7 +1198,13 @@ interface SandboxedIframeProps {
1170
1198
  declare const SandboxedIframe: react.ForwardRefExoticComponent<SandboxedIframeProps & react.RefAttributes<SandboxedIframeHandle>>;
1171
1199
 
1172
1200
  interface MCPAppsRendererProps {
1201
+ /** Host-owned instance label, never a filesystem path or guest claim. */
1202
+ appToolSourceLabel?: string;
1203
+ /** A form owned by this exact chat must stay above its App presentation. */
1204
+ hostInputPending?: boolean;
1173
1205
  chatSessionId?: string;
1206
+ /** Conversation eligible to call a retained workspace App; ownership stays fixed. */
1207
+ getModelChatSessionId?: () => string | undefined;
1174
1208
  serverId: string;
1175
1209
  serverName?: string;
1176
1210
  toolCallId: string;
@@ -1194,7 +1228,7 @@ interface MCPAppsRendererProps {
1194
1228
  /** All tools metadata for visibility checking when widget calls tools */
1195
1229
  toolsMetadata?: Record<string, Record<string, unknown>>;
1196
1230
  onSendFollowUp?: (text: string) => void;
1197
- onCallTool?: (toolName: string, params: Record<string, unknown>) => Promise<unknown>;
1231
+ onCallTool?: (toolName: string, params: Record<string, unknown>, context?: AppToolRequestContext) => Promise<unknown>;
1198
1232
  onAppToolInvocationChange?: (invocation: AppToolInvocationUpdate) => void;
1199
1233
  onWidgetStateChange?: (toolCallId: string, state: unknown) => void;
1200
1234
  /** Fixed initial-render outcome, without guest content or error text. */
@@ -1236,7 +1270,7 @@ interface MCPAppsRendererProps {
1236
1270
  content?: ContentBlock[];
1237
1271
  structuredContent?: Record<string, unknown>;
1238
1272
  }) => void;
1239
- /** Callback when app declares its supported display modes during ui/initialize */
1273
+ /** Modes allowed by the host, resource and initialized App for presentation controls. */
1240
1274
  onAppSupportedDisplayModesChange?: (modes: DisplayMode[] | undefined) => void;
1241
1275
  /**
1242
1276
  * Called when the widget sends `ui/notifications/request-teardown`
@@ -1325,7 +1359,7 @@ interface MCPAppsRendererProps {
1325
1359
  persistentSurfaceInitialToolCallId?: string;
1326
1360
  }
1327
1361
  declare function MCPAppsRenderer(props: MCPAppsRendererProps): react.JSX.Element;
1328
- declare function MCPAppsRendererSurface({ chatSessionId, serverId, serverName, toolCallId, toolName, toolState, toolInput, toolOutput, toolResponseMetadata, toolErrorText, resourceUri, toolMetadata, toolsMetadata, onSendFollowUp, onCallTool, onAppToolInvocationChange, onWidgetStateChange, onInitialRenderOutcome, 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, hostManagedPresentation, persistentSurfaceId, persistentSurfaceInitialToolCallId, }: MCPAppsRendererProps): react.JSX.Element | null;
1362
+ declare function MCPAppsRendererSurface({ appToolSourceLabel, hostInputPending, chatSessionId, getModelChatSessionId, serverId, serverName, toolCallId, toolName, toolState, toolInput, toolOutput, toolResponseMetadata, toolErrorText, resourceUri, toolMetadata, toolsMetadata, onSendFollowUp, onCallTool, onAppToolInvocationChange, onWidgetStateChange, onInitialRenderOutcome, 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, hostManagedPresentation, persistentSurfaceId, persistentSurfaceInitialToolCallId, }: MCPAppsRendererProps): react.JSX.Element | null;
1329
1363
 
1330
1364
  declare function WidgetSurfaceHostProvider({ children, }: {
1331
1365
  children: ReactNode;
@@ -1411,9 +1445,11 @@ declare const WidgetWorkspaceContext: react.Context<{
1411
1445
  } | null>;
1412
1446
 
1413
1447
  /** One owner per workspace/lane. Key this provider when its binding changes. */
1414
- declare function WidgetWorkspaceProvider({ workspaceId, children, }: {
1448
+ declare function WidgetWorkspaceProvider({ workspaceId, children, inheritAppTools, }: {
1415
1449
  workspaceId: string;
1416
1450
  children: ReactNode;
1451
+ /** Share model tools with the surrounding chat, while retaining owned surfaces. */
1452
+ inheritAppTools?: boolean;
1417
1453
  }): react.JSX.Element;
1418
1454
  declare function useOptionalWidgetWorkspace(): {
1419
1455
  workspaceId: string;
@@ -1473,6 +1509,12 @@ interface WidgetFullscreenPlacement {
1473
1509
  * opposed to the host ending it (another tab chosen, the panel hidden).
1474
1510
  */
1475
1511
  onExit?: () => void;
1512
+ /**
1513
+ * Bring the panel holding the placed App back into view (open it, or widen
1514
+ * it from a sliver): the conversation's card for an App that is only full
1515
+ * screen calls it.
1516
+ */
1517
+ reveal?: () => void;
1476
1518
  }
1477
1519
  declare const WidgetFullscreenPlacementContext: react.Context<WidgetFullscreenPlacement | null>;
1478
1520
 
@@ -1490,7 +1532,13 @@ interface AppToolCatalog {
1490
1532
  })[];
1491
1533
  }
1492
1534
  type AppToolCatalogState = Pick<AppToolsRegistryState, "aliases" | "instancesByBridgeId" | "activeBridgeByParent" | "enabled">;
1535
+ declare function modelChatSessionId(instance: AppInstance): string | undefined;
1493
1536
  /** Alias order is the wire order, including when an app re-registers. */
1494
1537
  declare function listAppToolCatalog(state: AppToolCatalogState, chatSessionId?: string | null): AppToolCatalog;
1495
1538
 
1496
- export { type AddTrafficLog, type AppInstance, type AppToolAlias, type AppToolAttribution, type AppToolCatalog, type AppToolCatalogEntry, type AppToolCatalogState, type AppToolDescriptor, type AppToolDropReason, type AppToolInvocationLog, type AppToolInvocationLogState, type AppToolInvocationRecord, type AppToolSnapshotEntry, type AppToolsRegistry, type AppToolsRegistryState, type BridgeId, type CspApplicationIntent, type CspClientContext, type CspMode, type CspMountId, type CspSubtypePolicy, type CspViolation, type DeviceCapabilities, type DeviceType, type DisplayMode, type EffectiveCompatRuntime, type FetchWidgetContentRequest, type FetchWidgetContentResponse, type ListResourcesResult, MAX_SNAPSHOT_ENTRIES, 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 WidgetFullscreenPlacement, WidgetFullscreenPlacementContext, 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, type WidgetSurfaceAdmissionError, WidgetSurfaceHost, WidgetSurfaceHostProvider, type WidgetSurfaceId, type WidgetSurfaceInfo, type WidgetSurfaceKind, type WidgetSurfaceRecord, type WidgetSurfaceStore, WidgetWorkspaceProvider, WidgetWorkspaceSurfaceHost, __internal, closeWorkspaceSurface, createAppToolInvocationLog, createAppToolsRegistry, createWidgetSurfaceStore, detectUIType, detectUiTypeFromTool, dispatchAppToolCall, getRenderableSurfaceEntries, getToolInputSignature, getUIResourceUri, listAppToolCatalog, readToolResultMeta, readToolResultObject, readToolResultServerId, recordAppToolInvocation, resolveSandboxProxyUrl, useAppToolAttribution, useAppToolAttributionResolver, useAppToolInvocationLog, useAppToolInvocationLogApi, useAppToolsRegistry, useAppToolsRegistryApi, useOptionalWidgetWorkspace, usePersistentWidgetSurfaceHost, useToolInputStreaming, useWidgetHost, useWidgetSurfaceAdmissionError, useWidgetSurfaceStore, useWidgetSurfaceStoreApi, useWidgetWorkspace };
1539
+ declare class SandboxViewAdmissionError extends Error {
1540
+ readonly retryable: boolean;
1541
+ constructor(retryable?: boolean);
1542
+ }
1543
+
1544
+ export { type AddTrafficLog, type AppInstance, type AppToolAlias, type AppToolAttribution, type AppToolCatalog, type AppToolCatalogEntry, type AppToolCatalogState, type AppToolDescriptor, type AppToolDropReason, type AppToolInvocationLog, type AppToolInvocationLogState, type AppToolInvocationRecord, type AppToolSnapshotEntry, type AppToolsRegistry, type AppToolsRegistryState, type BridgeId, type CspApplicationIntent, type CspClientContext, type CspMode, type CspMountId, type CspSubtypePolicy, type CspViolation, type DeviceCapabilities, type DeviceType, type DisplayMode, type EffectiveCompatRuntime, type FetchWidgetContentRequest, type FetchWidgetContentResponse, type ListResourcesResult, MAX_SNAPSHOT_ENTRIES, 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, SandboxViewAdmissionError, 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 WidgetFullscreenPlacement, WidgetFullscreenPlacementContext, 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, type WidgetSurfaceAdmissionError, WidgetSurfaceHost, WidgetSurfaceHostProvider, type WidgetSurfaceId, type WidgetSurfaceInfo, type WidgetSurfaceKind, type WidgetSurfaceRecord, type WidgetSurfaceStore, WidgetWorkspaceProvider, WidgetWorkspaceSurfaceHost, __internal, closeWorkspaceSurface, createAppToolInvocationLog, createAppToolsRegistry, createWidgetSurfaceStore, detectUIType, detectUiTypeFromTool, dispatchAppToolCall, getRenderableSurfaceEntries, getToolInputSignature, getUIResourceUri, listAppToolCatalog, modelChatSessionId, readToolResultMeta, readToolResultObject, readToolResultServerId, recordAppToolInvocation, resolveSandboxProxyUrl, useAppToolAttribution, useAppToolAttributionResolver, useAppToolInvocationLog, useAppToolInvocationLogApi, useAppToolsRegistry, useAppToolsRegistryApi, useOptionalWidgetWorkspace, usePersistentWidgetSurfaceHost, useToolInputStreaming, useWidgetHost, useWidgetSurfaceAdmissionError, useWidgetSurfaceStore, useWidgetSurfaceStoreApi, useWidgetWorkspace };