@mcpjam/widget-react 0.2.0 → 0.2.2

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, 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';
@@ -571,6 +571,7 @@ interface FetchWidgetContentRequest {
571
571
  forceWebEndpoint?: boolean;
572
572
  }
573
573
  interface FetchWidgetContentResponse {
574
+ sourceReceipt?: string;
574
575
  resourceDisplayHints?: _mcpjam_sdk_widget_runtime.ResourceDisplayHints;
575
576
  html: string;
576
577
  csp?: McpUiResourceCsp;
@@ -611,6 +612,8 @@ type ListResourcesResult = {
611
612
  * HOSTED_MODE / web-managed guard before calling the raw api.
612
613
  */
613
614
  interface WidgetHostServices {
615
+ prepareSandboxView?: (request: PrepareSandboxViewRequest, signal?: AbortSignal) => Promise<PreparedSandboxView>;
616
+ releaseSandboxView?: (request: ReleaseSandboxViewRequest) => Promise<void>;
614
617
  /** Host-admitted plugin navigation, never arbitrary external navigation. */
615
618
  openAppLink?: (url: string) => Promise<void>;
616
619
  sendMessage?: (params: unknown) => Promise<Record<string, unknown>>;
@@ -716,15 +719,24 @@ declare function readToolResultObject(result: unknown): Record<string, unknown>
716
719
  declare function readToolResultMeta(result: unknown): Record<string, unknown> | undefined;
717
720
  declare function readToolResultServerId(result: unknown): string | undefined;
718
721
 
722
+ /** Host presentation only; never changes tool routing or grants authority. */
723
+ interface AppToolPresentation {
724
+ label?: string;
725
+ visibility?: "visible" | "hidden";
726
+ }
727
+
719
728
  /** Injected traffic-log sink — `WidgetDebugSink["addTrafficLog"]`. */
720
729
  type AddTrafficLog = WidgetDebugSink["addTrafficLog"];
721
730
  /** Per-AppBridge instance identifier (independent of parentToolCallId). */
722
731
  type BridgeId = string;
723
732
  type AppToolDescriptor = NonNullable<Awaited<ReturnType<AppBridge["listTools"]>>["tools"]>[number];
724
733
  interface AppInstance {
734
+ presentation?: AppToolPresentation;
725
735
  bridgeId: BridgeId;
726
736
  /** Chat session/lane that owns this rendered iframe. */
727
737
  chatSessionId?: string;
738
+ /** Retained workspace Apps target this conversation without changing ownership. */
739
+ getModelChatSessionId?: () => string | undefined;
728
740
  /** The host tool call whose render mounted this iframe. */
729
741
  parentToolCallId: string;
730
742
  serverId: string;
@@ -752,6 +764,8 @@ interface AppToolAlias {
752
764
  }
753
765
  /** What the snapshot ships to the server in the chat POST body. */
754
766
  interface AppToolSnapshotEntry {
767
+ /** Exact bridge generation; older clients omit it and cannot use native app tools. */
768
+ bridgeId?: string;
755
769
  alias: string;
756
770
  appName: string;
757
771
  appVersion?: string;
@@ -767,6 +781,7 @@ interface AppToolAttribution {
767
781
  appName: string;
768
782
  }
769
783
  interface AppToolsRegistryState {
784
+ updatePresentation: (bridgeId: string, presentation: AppToolPresentation) => void;
770
785
  enabled: boolean;
771
786
  instancesByBridgeId: Map<BridgeId, AppInstance>;
772
787
  aliases: Map<string, AppToolAlias>;
@@ -1042,6 +1057,11 @@ interface UseToolInputStreamingReturn {
1042
1057
  }
1043
1058
  declare function useToolInputStreaming({ bridgeRef, isReady, isReadyRef, toolState, toolInput, toolOutput, toolErrorText, toolCallId, sendToolInput, onToolInputSent, reinitCount, mcpAppsCapabilitiesRef, }: UseToolInputStreamingParams): UseToolInputStreamingReturn;
1044
1059
 
1060
+ interface SandboxViewAdmission {
1061
+ services: Pick<WidgetHostServices, "prepareSandboxView" | "releaseSandboxView">;
1062
+ request: Omit<PrepareSandboxViewRequest, "viewInstanceId" | "admissionId" | "hostOrigin">;
1063
+ }
1064
+
1045
1065
  /** The parts of `window.location` the sandbox origin is derived from. */
1046
1066
  type SandboxProxyLocation = Pick<Location, "hostname" | "port" | "protocol" | "origin">;
1047
1067
  declare function resolveSandboxProxyUrl({ hostedMode, sandboxOrigin, location, viewOriginLabel, viewSubdomainsEnabled, userAgent, }: {
@@ -1058,6 +1078,8 @@ interface SandboxedIframeHandle {
1058
1078
  getIframeElement: () => HTMLIFrameElement | null;
1059
1079
  }
1060
1080
  interface SandboxedIframeProps {
1081
+ /** An authorized host supplies this before loading any proxy document. */
1082
+ viewAdmission?: SandboxViewAdmission;
1061
1083
  /** HTML content to render in the sandbox */
1062
1084
  html: string | null;
1063
1085
  /** Sandbox attribute for the inner iframe */
@@ -1170,7 +1192,13 @@ interface SandboxedIframeProps {
1170
1192
  declare const SandboxedIframe: react.ForwardRefExoticComponent<SandboxedIframeProps & react.RefAttributes<SandboxedIframeHandle>>;
1171
1193
 
1172
1194
  interface MCPAppsRendererProps {
1195
+ /** Host-owned instance label, never a filesystem path or guest claim. */
1196
+ appToolSourceLabel?: string;
1197
+ /** A form owned by this exact chat must stay above its App presentation. */
1198
+ hostInputPending?: boolean;
1173
1199
  chatSessionId?: string;
1200
+ /** Conversation eligible to call a retained workspace App; ownership stays fixed. */
1201
+ getModelChatSessionId?: () => string | undefined;
1174
1202
  serverId: string;
1175
1203
  serverName?: string;
1176
1204
  toolCallId: string;
@@ -1194,7 +1222,7 @@ interface MCPAppsRendererProps {
1194
1222
  /** All tools metadata for visibility checking when widget calls tools */
1195
1223
  toolsMetadata?: Record<string, Record<string, unknown>>;
1196
1224
  onSendFollowUp?: (text: string) => void;
1197
- onCallTool?: (toolName: string, params: Record<string, unknown>) => Promise<unknown>;
1225
+ onCallTool?: (toolName: string, params: Record<string, unknown>, context?: AppToolRequestContext) => Promise<unknown>;
1198
1226
  onAppToolInvocationChange?: (invocation: AppToolInvocationUpdate) => void;
1199
1227
  onWidgetStateChange?: (toolCallId: string, state: unknown) => void;
1200
1228
  /** Fixed initial-render outcome, without guest content or error text. */
@@ -1236,7 +1264,7 @@ interface MCPAppsRendererProps {
1236
1264
  content?: ContentBlock[];
1237
1265
  structuredContent?: Record<string, unknown>;
1238
1266
  }) => void;
1239
- /** Callback when app declares its supported display modes during ui/initialize */
1267
+ /** Modes allowed by the host, resource and initialized App for presentation controls. */
1240
1268
  onAppSupportedDisplayModesChange?: (modes: DisplayMode[] | undefined) => void;
1241
1269
  /**
1242
1270
  * Called when the widget sends `ui/notifications/request-teardown`
@@ -1325,7 +1353,7 @@ interface MCPAppsRendererProps {
1325
1353
  persistentSurfaceInitialToolCallId?: string;
1326
1354
  }
1327
1355
  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;
1356
+ 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
1357
 
1330
1358
  declare function WidgetSurfaceHostProvider({ children, }: {
1331
1359
  children: ReactNode;
@@ -1411,9 +1439,11 @@ declare const WidgetWorkspaceContext: react.Context<{
1411
1439
  } | null>;
1412
1440
 
1413
1441
  /** One owner per workspace/lane. Key this provider when its binding changes. */
1414
- declare function WidgetWorkspaceProvider({ workspaceId, children, }: {
1442
+ declare function WidgetWorkspaceProvider({ workspaceId, children, inheritAppTools, }: {
1415
1443
  workspaceId: string;
1416
1444
  children: ReactNode;
1445
+ /** Share model tools with the surrounding chat, while retaining owned surfaces. */
1446
+ inheritAppTools?: boolean;
1417
1447
  }): react.JSX.Element;
1418
1448
  declare function useOptionalWidgetWorkspace(): {
1419
1449
  workspaceId: string;
@@ -1490,7 +1520,13 @@ interface AppToolCatalog {
1490
1520
  })[];
1491
1521
  }
1492
1522
  type AppToolCatalogState = Pick<AppToolsRegistryState, "aliases" | "instancesByBridgeId" | "activeBridgeByParent" | "enabled">;
1523
+ declare function modelChatSessionId(instance: AppInstance): string | undefined;
1493
1524
  /** Alias order is the wire order, including when an app re-registers. */
1494
1525
  declare function listAppToolCatalog(state: AppToolCatalogState, chatSessionId?: string | null): AppToolCatalog;
1495
1526
 
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 };
1527
+ declare class SandboxViewAdmissionError extends Error {
1528
+ readonly retryable: boolean;
1529
+ constructor(retryable?: boolean);
1530
+ }
1531
+
1532
+ 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 };