@mcpjam/widget-react 0.1.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 +976 -0
- package/dist/index.js +3883 -0
- package/dist/index.js.map +1 -0
- package/dist/styles.css +11 -0
- package/package.json +54 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,976 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import * as react from 'react';
|
|
3
|
+
import { ComponentType, ReactNode } from 'react';
|
|
4
|
+
import { McpUiResourceCsp, McpUiResourcePermissions, McpUiHostCapabilities, McpUiStyles, McpUiHostContext, AppBridge } from '@modelcontextprotocol/ext-apps/app-bridge';
|
|
5
|
+
import { SandboxCspPolicy, SandboxPermissionsPolicy, MCPPrompt, MCPResourceTemplate } from '@mcpjam/sdk/browser';
|
|
6
|
+
import * as zustand from 'zustand';
|
|
7
|
+
import { CallToolResult, ContentBlock } from '@modelcontextprotocol/client';
|
|
8
|
+
import { AppToolInvocationUpdate } from '@mcpjam/sdk/widget-runtime';
|
|
9
|
+
export { getToolVisibility, isVisibleToAppOnly, isVisibleToModelOnly } from '@mcpjam/sdk/widget-runtime';
|
|
10
|
+
|
|
11
|
+
/** Sandbox CSP-mode selection. Mirrors the inspector ui-playground-store. */
|
|
12
|
+
type CspMode = "permissive" | "widget-declared";
|
|
13
|
+
/** Widget display-mode union (SEP HostDisplayMode). */
|
|
14
|
+
type DisplayMode = "inline" | "pip" | "fullscreen";
|
|
15
|
+
/** JSON-RPC protocol tag for traffic logging. */
|
|
16
|
+
type UiProtocol = "mcp-apps" | "openai-apps";
|
|
17
|
+
/**
|
|
18
|
+
* OpenAI Apps compat capability flags (the `window.openai.*` surface to inject).
|
|
19
|
+
* Structural mirror of the inspector's `InjectedOpenAiCompatCapabilities`.
|
|
20
|
+
*/
|
|
21
|
+
interface OpenAiAppsCapabilities {
|
|
22
|
+
callTool?: boolean;
|
|
23
|
+
sendFollowUpMessage?: boolean;
|
|
24
|
+
setWidgetState?: boolean;
|
|
25
|
+
requestDisplayMode?: "all" | "fullscreen-only" | "none";
|
|
26
|
+
notifyIntrinsicHeight?: boolean;
|
|
27
|
+
openExternal?: boolean;
|
|
28
|
+
setOpenInAppUrl?: boolean;
|
|
29
|
+
requestModal?: boolean;
|
|
30
|
+
uploadFile?: boolean;
|
|
31
|
+
selectFiles?: boolean;
|
|
32
|
+
getFileDownloadUrl?: boolean;
|
|
33
|
+
requestCheckout?: boolean;
|
|
34
|
+
requestClose?: boolean;
|
|
35
|
+
}
|
|
36
|
+
/** usePreferencesStore theme mode. */
|
|
37
|
+
type ThemeMode = "light" | "dark";
|
|
38
|
+
/** Host-style id (the inspector's `ChatboxHostStyle`). */
|
|
39
|
+
type ChatboxHostStyle = string;
|
|
40
|
+
interface DeviceCapabilities {
|
|
41
|
+
hover: boolean;
|
|
42
|
+
touch: boolean;
|
|
43
|
+
}
|
|
44
|
+
type DeviceType = "fill" | "mobile" | "tablet" | "desktop" | "custom";
|
|
45
|
+
interface SafeAreaInsets {
|
|
46
|
+
top: number;
|
|
47
|
+
bottom: number;
|
|
48
|
+
left: number;
|
|
49
|
+
right: number;
|
|
50
|
+
}
|
|
51
|
+
/** useHostContextStore draftHostContext. */
|
|
52
|
+
type ProjectHostContextDraft = Record<string, unknown>;
|
|
53
|
+
/** resolveEffectiveHostCapabilities — vendor-trait host caps (sandbox composed separately). */
|
|
54
|
+
type ResolvedHostCapabilities = Omit<McpUiHostCapabilities, "sandbox">;
|
|
55
|
+
/** resolveHostInfo. */
|
|
56
|
+
type ResolvedHostInfo = Record<string, unknown> | undefined;
|
|
57
|
+
/** Required form of the OpenAI Apps compat surface. */
|
|
58
|
+
type ResolvedOpenAiAppsCapabilities = Required<OpenAiAppsCapabilities>;
|
|
59
|
+
/** resolveEffectiveCompatRuntime result. */
|
|
60
|
+
type EffectiveCompatRuntime = {
|
|
61
|
+
injected: false;
|
|
62
|
+
} | {
|
|
63
|
+
injected: true;
|
|
64
|
+
capabilities: ResolvedOpenAiAppsCapabilities;
|
|
65
|
+
};
|
|
66
|
+
/** resolveEffectiveMcpAppsCapabilities — the resolved MCP-Apps capability matrix. */
|
|
67
|
+
type ResolvedMcpAppsCapabilities = {
|
|
68
|
+
availableDisplayModes: ("inline" | "fullscreen" | "pip")[];
|
|
69
|
+
toolInputPartial: boolean;
|
|
70
|
+
toolCancelled: boolean;
|
|
71
|
+
hostContextChanged: boolean;
|
|
72
|
+
resourceTeardown: boolean;
|
|
73
|
+
toolInfo: boolean;
|
|
74
|
+
openLinks: boolean;
|
|
75
|
+
serverTools: boolean;
|
|
76
|
+
serverResources: boolean;
|
|
77
|
+
logging: boolean;
|
|
78
|
+
updateModelContext: boolean;
|
|
79
|
+
message: boolean;
|
|
80
|
+
sandboxPermissions: boolean;
|
|
81
|
+
cspFrameDomains: boolean;
|
|
82
|
+
cspBaseUriDomains: boolean;
|
|
83
|
+
resourcePrefersBorder: boolean;
|
|
84
|
+
downloadFile: boolean;
|
|
85
|
+
requestTeardown: boolean;
|
|
86
|
+
widgetDisplayModeRequests: "accept" | "user-initiated-only" | "decline";
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* getHostStyleOrDefault / DEFAULT_HOST_STYLE result — typed to the renderer's
|
|
90
|
+
* AUDITED reads only: `.mcp.{resolveStyleVariables,fontCss,platform}` and
|
|
91
|
+
* `.chatUi.resolveChatBackground` (+ `.id`). The real `HostStyleDefinition` has
|
|
92
|
+
* more (the full profile/chat-ui graph); the adapter assigns it (assignable to
|
|
93
|
+
* this minimal surface), so the package never replicates that graph.
|
|
94
|
+
*/
|
|
95
|
+
interface ResolvedHostStyle {
|
|
96
|
+
id: string;
|
|
97
|
+
mcp: {
|
|
98
|
+
resolveStyleVariables: (theme: "light" | "dark") => McpUiStyles;
|
|
99
|
+
fontCss: string;
|
|
100
|
+
platform: "web" | "desktop" | "mobile";
|
|
101
|
+
};
|
|
102
|
+
chatUi: {
|
|
103
|
+
resolveChatBackground: (theme: "light" | "dark") => string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Which surface the widget is mounted on. Collapses the inspector's
|
|
108
|
+
* `useIsChatboxSurface` / `useWidgetSurface` signals into one descriptor.
|
|
109
|
+
*/
|
|
110
|
+
type WidgetSurfaceKind = "chat" | "playground" | "chatbox" | "standalone";
|
|
111
|
+
/** Per-surface identity + routing the renderer reads ambiently. */
|
|
112
|
+
interface WidgetSurfaceInfo {
|
|
113
|
+
kind: WidgetSurfaceKind;
|
|
114
|
+
/** usePersistentWidgetSurfaceHost — persistent resource-scoped surfaces. */
|
|
115
|
+
persistentSurfaceHost: boolean;
|
|
116
|
+
/** useWebManagedServers — route widget-content through /api/web. */
|
|
117
|
+
webManagedServers: boolean;
|
|
118
|
+
/**
|
|
119
|
+
* HOSTED_MODE (the inspector's `@/lib/config` flag): the app runs against
|
|
120
|
+
* the hosted backend (web-managed servers, no local file APIs). The renderer
|
|
121
|
+
* + sandboxed iframe read this to pick hosted vs. local proxy/file paths and
|
|
122
|
+
* to gate upload/download/resource-template features.
|
|
123
|
+
*/
|
|
124
|
+
hostedMode: boolean;
|
|
125
|
+
/** SANDBOX_ORIGIN (VITE_MCPJAM_SANDBOX_ORIGIN); "" when unset. */
|
|
126
|
+
sandboxOrigin: string;
|
|
127
|
+
/**
|
|
128
|
+
* Playground CSP-mode selection (useUIPlaygroundStore.mcpAppsCspMode) — an
|
|
129
|
+
* INPUT, not the effective mode. The renderer derives the effective sandbox
|
|
130
|
+
* CSP mode from `kind` + this + the per-widget `minimalMode` prop (kept as an
|
|
131
|
+
* input because `minimalMode` is per-instance).
|
|
132
|
+
*/
|
|
133
|
+
playgroundCspMode: CspMode;
|
|
134
|
+
}
|
|
135
|
+
interface WidgetMount {
|
|
136
|
+
index: number;
|
|
137
|
+
reason: string;
|
|
138
|
+
at: number;
|
|
139
|
+
}
|
|
140
|
+
interface CspViolation {
|
|
141
|
+
directive: string;
|
|
142
|
+
effectiveDirective?: string;
|
|
143
|
+
blockedUri: string;
|
|
144
|
+
sourceFile?: string | null;
|
|
145
|
+
lineNumber?: number | null;
|
|
146
|
+
columnNumber?: number | null;
|
|
147
|
+
timestamp: number;
|
|
148
|
+
}
|
|
149
|
+
interface WidgetLifecycleEvent {
|
|
150
|
+
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";
|
|
151
|
+
status: "ok" | "error" | "pending";
|
|
152
|
+
message?: string;
|
|
153
|
+
timestamp: number;
|
|
154
|
+
}
|
|
155
|
+
interface WidgetSandboxApplied {
|
|
156
|
+
sandboxAttrs?: string[];
|
|
157
|
+
allowFeatures?: Record<string, string>;
|
|
158
|
+
cspDirectives?: Record<string, string[]>;
|
|
159
|
+
permissive: boolean;
|
|
160
|
+
hostPolicyApplied: boolean;
|
|
161
|
+
restrictTo?: {
|
|
162
|
+
connectDomains?: string[];
|
|
163
|
+
resourceDomains?: string[];
|
|
164
|
+
frameDomains?: string[];
|
|
165
|
+
baseUriDomains?: string[];
|
|
166
|
+
};
|
|
167
|
+
cspMode?: "host-default" | "declared" | "relaxed";
|
|
168
|
+
permissions?: {
|
|
169
|
+
camera?: {};
|
|
170
|
+
microphone?: {};
|
|
171
|
+
geolocation?: {};
|
|
172
|
+
clipboardWrite?: {};
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
interface WidgetSandboxInfo {
|
|
176
|
+
mode: CspMode;
|
|
177
|
+
connectDomains: string[];
|
|
178
|
+
resourceDomains: string[];
|
|
179
|
+
frameDomains?: string[];
|
|
180
|
+
baseUriDomains?: string[];
|
|
181
|
+
permissions?: {
|
|
182
|
+
camera?: {};
|
|
183
|
+
microphone?: {};
|
|
184
|
+
geolocation?: {};
|
|
185
|
+
clipboardWrite?: {};
|
|
186
|
+
};
|
|
187
|
+
headerString?: string;
|
|
188
|
+
violations: CspViolation[];
|
|
189
|
+
widgetDeclared?: {
|
|
190
|
+
connect_domains?: string[];
|
|
191
|
+
resource_domains?: string[];
|
|
192
|
+
connectDomains?: string[];
|
|
193
|
+
resourceDomains?: string[];
|
|
194
|
+
frameDomains?: string[];
|
|
195
|
+
baseUriDomains?: string[];
|
|
196
|
+
} | null;
|
|
197
|
+
}
|
|
198
|
+
interface WidgetGlobals {
|
|
199
|
+
theme: "light" | "dark";
|
|
200
|
+
displayMode: "inline" | "pip" | "fullscreen";
|
|
201
|
+
maxHeight?: number;
|
|
202
|
+
maxWidth?: number;
|
|
203
|
+
locale?: string;
|
|
204
|
+
safeArea?: {
|
|
205
|
+
insets: {
|
|
206
|
+
top: number;
|
|
207
|
+
bottom: number;
|
|
208
|
+
left: number;
|
|
209
|
+
right: number;
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
timeZone?: string;
|
|
213
|
+
deviceCapabilities?: {
|
|
214
|
+
hover: boolean;
|
|
215
|
+
touch: boolean;
|
|
216
|
+
};
|
|
217
|
+
safeAreaInsets?: {
|
|
218
|
+
top: number;
|
|
219
|
+
bottom: number;
|
|
220
|
+
left: number;
|
|
221
|
+
right: number;
|
|
222
|
+
};
|
|
223
|
+
userAgent?: {
|
|
224
|
+
device: {
|
|
225
|
+
type: string;
|
|
226
|
+
};
|
|
227
|
+
capabilities: {
|
|
228
|
+
hover: boolean;
|
|
229
|
+
touch: boolean;
|
|
230
|
+
};
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
interface WidgetDebugInfo {
|
|
234
|
+
toolCallId: string;
|
|
235
|
+
toolName: string;
|
|
236
|
+
protocol: "openai-apps" | "mcp-apps";
|
|
237
|
+
widgetState: unknown;
|
|
238
|
+
globals: WidgetGlobals;
|
|
239
|
+
prefersBorder?: boolean;
|
|
240
|
+
updatedAt: number;
|
|
241
|
+
csp?: WidgetSandboxInfo;
|
|
242
|
+
applied?: WidgetSandboxApplied;
|
|
243
|
+
hostProfileId?: string;
|
|
244
|
+
hostInfo?: {
|
|
245
|
+
name: string;
|
|
246
|
+
version: string;
|
|
247
|
+
} | null;
|
|
248
|
+
lifecycle: WidgetLifecycleEvent[];
|
|
249
|
+
mounts: WidgetMount[];
|
|
250
|
+
modelContext?: {
|
|
251
|
+
content?: unknown[];
|
|
252
|
+
structuredContent?: Record<string, unknown>;
|
|
253
|
+
updatedAt: number;
|
|
254
|
+
} | null;
|
|
255
|
+
widgetHtml?: string;
|
|
256
|
+
injectedOpenAiCompat?: boolean;
|
|
257
|
+
injectedOpenAiCompatCapabilities?: OpenAiAppsCapabilities;
|
|
258
|
+
}
|
|
259
|
+
interface UiLogEvent {
|
|
260
|
+
id: string;
|
|
261
|
+
/** toolCallId */
|
|
262
|
+
widgetId: string;
|
|
263
|
+
serverId: string;
|
|
264
|
+
serverName?: string;
|
|
265
|
+
direction: "host-to-ui" | "ui-to-host";
|
|
266
|
+
protocol: UiProtocol;
|
|
267
|
+
method: string;
|
|
268
|
+
timestamp: string;
|
|
269
|
+
message: unknown;
|
|
270
|
+
}
|
|
271
|
+
/** Diagnostics sink — 1:1 with widget-debug-store + traffic-log addLog. */
|
|
272
|
+
interface WidgetDebugSink {
|
|
273
|
+
recordMount: (toolCallId: string, reason: string) => void;
|
|
274
|
+
setWidgetDebugInfo: (toolCallId: string, info: Partial<Omit<WidgetDebugInfo, "toolCallId" | "updatedAt">>) => void;
|
|
275
|
+
setWidgetState: (toolCallId: string, state: unknown) => void;
|
|
276
|
+
setWidgetGlobals: (toolCallId: string, globals: Partial<WidgetGlobals>) => void;
|
|
277
|
+
setWidgetCsp: (toolCallId: string, csp: Omit<WidgetSandboxInfo, "violations">) => void;
|
|
278
|
+
addCspViolation: (toolCallId: string, violation: CspViolation) => void;
|
|
279
|
+
clearCspViolations: (toolCallId: string) => void;
|
|
280
|
+
setWidgetModelContext: (toolCallId: string, context: {
|
|
281
|
+
content?: unknown[];
|
|
282
|
+
structuredContent?: Record<string, unknown>;
|
|
283
|
+
} | null) => void;
|
|
284
|
+
setWidgetHtml: (toolCallId: string, html: string, injectedOpenAiCompat?: boolean, injectedOpenAiCompatCapabilities?: OpenAiAppsCapabilities) => void;
|
|
285
|
+
setSandboxApplied: (toolCallId: string, applied: WidgetSandboxApplied, hostProfileId?: string, hostInfo?: {
|
|
286
|
+
name: string;
|
|
287
|
+
version: string;
|
|
288
|
+
} | null) => void;
|
|
289
|
+
appendLifecycle: (toolCallId: string, event: WidgetLifecycleEvent) => void;
|
|
290
|
+
/** useTrafficLogStore.addLog */
|
|
291
|
+
addTrafficLog: (event: Omit<UiLogEvent, "id" | "timestamp">) => void;
|
|
292
|
+
}
|
|
293
|
+
interface WidgetModalProps {
|
|
294
|
+
open: boolean;
|
|
295
|
+
onClose: () => void;
|
|
296
|
+
title?: string;
|
|
297
|
+
children: ReactNode;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Checkout chrome injection (Agentic Commerce / ACP). The package owns the
|
|
301
|
+
* `requestCheckout` lifecycle but not the inspector's checkout UI; the inspector
|
|
302
|
+
* injects its `CheckoutDialogV2` via `components.Checkout`. `session` is the raw
|
|
303
|
+
* ACP checkout-session payload the widget supplied — opaque to the package, so
|
|
304
|
+
* it is typed `unknown` and the inspector adapter narrows it to its own
|
|
305
|
+
* `CheckoutSession` shape.
|
|
306
|
+
*/
|
|
307
|
+
interface WidgetCheckoutProps {
|
|
308
|
+
session: unknown;
|
|
309
|
+
open: boolean;
|
|
310
|
+
onOpenChange: (open: boolean) => void;
|
|
311
|
+
/** Resolve the widget's checkout promise with the successful result. */
|
|
312
|
+
onComplete: (result: unknown) => void;
|
|
313
|
+
/** Reject the widget's checkout promise with a non-UI error. */
|
|
314
|
+
onError: (error: string) => void;
|
|
315
|
+
onCancel: () => void;
|
|
316
|
+
onCallTool: (toolName: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
317
|
+
}
|
|
318
|
+
interface WidgetHostComponents {
|
|
319
|
+
Modal?: ComponentType<WidgetModalProps>;
|
|
320
|
+
Checkout?: ComponentType<WidgetCheckoutProps>;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Per-`serverId` resolved host environment — the deferred `resolveEnvironment`
|
|
324
|
+
* target. Currently unused by the renderer (Phase 1b reads the raw `environment`
|
|
325
|
+
* inputs + `resolvers` instead); kept on the contract for the eventual fold-in.
|
|
326
|
+
*/
|
|
327
|
+
interface WidgetHostEnvironment {
|
|
328
|
+
hostInfo: ResolvedHostInfo;
|
|
329
|
+
hostCapabilities: ResolvedHostCapabilities;
|
|
330
|
+
mcpAppsCapabilities: ResolvedMcpAppsCapabilities;
|
|
331
|
+
injectOpenAiCompat: boolean;
|
|
332
|
+
openAiCompatCapabilities?: ResolvedOpenAiAppsCapabilities;
|
|
333
|
+
supportsWidgetRendering: boolean;
|
|
334
|
+
theme: string;
|
|
335
|
+
hostStyle: ResolvedHostStyle;
|
|
336
|
+
baseHostContext: McpUiHostContext;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Minimal structural projection of `mcpProfile.apps.sandbox` (the host-policy
|
|
340
|
+
* sandbox overrides the renderer reads directly). The full `HostConfigMcpProfileV1`
|
|
341
|
+
* is bound inside the inspector adapter's resolvers and never enters the public
|
|
342
|
+
* surface; only these read-by-the-renderer fields are projected here. `csp` is
|
|
343
|
+
* the SDK `SandboxCspPolicy` plus the inspector-only `cspDirectives` escape hatch.
|
|
344
|
+
*/
|
|
345
|
+
interface WidgetHostProfileSandbox {
|
|
346
|
+
csp?: SandboxCspPolicy & {
|
|
347
|
+
cspDirectives?: Record<string, string[]>;
|
|
348
|
+
};
|
|
349
|
+
permissions?: SandboxPermissionsPolicy;
|
|
350
|
+
sandboxAttrs?: string[];
|
|
351
|
+
allowFeatures?: Record<string, string>;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Raw ambient ENV inputs the renderer reads (Phase 1b). The inspector's
|
|
355
|
+
* use-widget-host adapter supplies these from its stores/contexts; these are
|
|
356
|
+
* structural mirrors of the inspector store/context shapes.
|
|
357
|
+
*
|
|
358
|
+
* The active MCP profile (`HostConfigMcpProfileV1`) is NOT exposed as a typed
|
|
359
|
+
* object — it is bound inside the adapter's resolvers (3d-iii). The renderer
|
|
360
|
+
* instead reads `profileKey` (a reactivity hash) plus the minimal structural
|
|
361
|
+
* projections it actually inspects (`profileSandbox`, `profileHostInfo`).
|
|
362
|
+
*/
|
|
363
|
+
interface WidgetHostEnvironmentInputs {
|
|
364
|
+
themeMode: ThemeMode;
|
|
365
|
+
sharedHostStyle: ChatboxHostStyle;
|
|
366
|
+
chatboxHostStyle: ChatboxHostStyle | null;
|
|
367
|
+
chatboxHostTheme: "light" | "dark" | null;
|
|
368
|
+
hostCapabilitiesOverride: Record<string, unknown> | undefined;
|
|
369
|
+
/**
|
|
370
|
+
* Stable hash of the active MCP profile. The profile object is bound in the
|
|
371
|
+
* adapter's resolvers; the renderer keys its capability memos on this so they
|
|
372
|
+
* recompute when the profile changes without the profile type leaking here.
|
|
373
|
+
*/
|
|
374
|
+
profileKey: string;
|
|
375
|
+
/** `mcpProfile.apps.sandbox` projection (host-policy sandbox overrides). */
|
|
376
|
+
profileSandbox: WidgetHostProfileSandbox | undefined;
|
|
377
|
+
/** `mcpProfile.apps.uiInitialize.hostInfo` projection (AppBridge identity override). */
|
|
378
|
+
profileHostInfo: {
|
|
379
|
+
name?: unknown;
|
|
380
|
+
version?: unknown;
|
|
381
|
+
} | undefined;
|
|
382
|
+
draftHostContext: ProjectHostContextDraft;
|
|
383
|
+
isPlaygroundActive: boolean;
|
|
384
|
+
playgroundLocale: string;
|
|
385
|
+
playgroundTimeZone: string;
|
|
386
|
+
playgroundDisplayMode: DisplayMode;
|
|
387
|
+
playgroundCapabilities: DeviceCapabilities;
|
|
388
|
+
playgroundSafeAreaInsets: SafeAreaInsets;
|
|
389
|
+
playgroundDeviceType: DeviceType;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Resolver / projection fns the renderer calls. The inspector's use-widget-host
|
|
393
|
+
* adapter binds them to the real client-config-v2 / client-styles /
|
|
394
|
+
* client-config implementations; typed structurally so the package owns no
|
|
395
|
+
* inspector code. Drift is caught where the adapter assigns the real fns.
|
|
396
|
+
*/
|
|
397
|
+
interface WidgetHostResolvers {
|
|
398
|
+
resolveEffectiveCompatRuntime: (args: {
|
|
399
|
+
hostStyle: ChatboxHostStyle | string | null | undefined;
|
|
400
|
+
}) => EffectiveCompatRuntime;
|
|
401
|
+
resolveEffectiveMcpAppsCapabilities: (args: {
|
|
402
|
+
hostStyle: ChatboxHostStyle | string | null | undefined;
|
|
403
|
+
}) => ResolvedMcpAppsCapabilities;
|
|
404
|
+
resolveEffectiveHostCapabilities: (args: {
|
|
405
|
+
hostStyle: string | null | undefined;
|
|
406
|
+
hostCapabilitiesOverride?: Record<string, unknown>;
|
|
407
|
+
}) => ResolvedHostCapabilities;
|
|
408
|
+
resolveHostInfo: () => ResolvedHostInfo;
|
|
409
|
+
getHostStyleOrDefault: (id: string | null | undefined) => ResolvedHostStyle;
|
|
410
|
+
DEFAULT_HOST_STYLE: ResolvedHostStyle;
|
|
411
|
+
extractHostTheme: (hostContext?: Record<string, unknown>) => "light" | "dark" | undefined;
|
|
412
|
+
extractHostDisplayMode: (hostContext?: Record<string, unknown>) => DisplayMode | undefined;
|
|
413
|
+
extractHostDisplayModes: (hostContext?: Record<string, unknown>) => DisplayMode[];
|
|
414
|
+
clampDisplayModeToAvailableModes: (displayMode: DisplayMode | undefined, availableDisplayModes: DisplayMode[]) => DisplayMode;
|
|
415
|
+
stableStringifyJson: (value: unknown) => string;
|
|
416
|
+
}
|
|
417
|
+
interface FetchWidgetContentRequest {
|
|
418
|
+
serverId: string;
|
|
419
|
+
resourceUri: string;
|
|
420
|
+
toolInput: Record<string, unknown> | undefined;
|
|
421
|
+
toolOutput: unknown;
|
|
422
|
+
toolResponseMetadata?: Record<string, unknown> | null;
|
|
423
|
+
initialWidgetState?: unknown;
|
|
424
|
+
toolId: string;
|
|
425
|
+
toolName: string;
|
|
426
|
+
theme: string;
|
|
427
|
+
cspMode: CspMode;
|
|
428
|
+
injectOpenAiCompat: boolean;
|
|
429
|
+
openAiCompatCapabilities?: ResolvedOpenAiAppsCapabilities;
|
|
430
|
+
template?: string;
|
|
431
|
+
viewMode?: string;
|
|
432
|
+
viewParams?: Record<string, unknown>;
|
|
433
|
+
forceWebEndpoint?: boolean;
|
|
434
|
+
}
|
|
435
|
+
interface FetchWidgetContentResponse {
|
|
436
|
+
html: string;
|
|
437
|
+
csp?: McpUiResourceCsp;
|
|
438
|
+
permissions?: McpUiResourcePermissions;
|
|
439
|
+
permissive?: boolean;
|
|
440
|
+
mimeTypeWarning?: string;
|
|
441
|
+
mimeTypeValid?: boolean;
|
|
442
|
+
prefersBorder?: boolean;
|
|
443
|
+
injectedOpenAiCompat?: boolean;
|
|
444
|
+
injectedOpenAiCompatCapabilities?: ResolvedOpenAiAppsCapabilities;
|
|
445
|
+
}
|
|
446
|
+
type ListResourcesResult = {
|
|
447
|
+
resources: Array<{
|
|
448
|
+
uri: string;
|
|
449
|
+
name: string;
|
|
450
|
+
description?: string;
|
|
451
|
+
mimeType?: string;
|
|
452
|
+
}>;
|
|
453
|
+
nextCursor?: string;
|
|
454
|
+
};
|
|
455
|
+
/**
|
|
456
|
+
* Widget content fetch + MCP transport. The inspector binds these to
|
|
457
|
+
* `fetchMcpAppsWidgetContent` + the MCP resource/prompt apis.
|
|
458
|
+
* `listResourceTemplates` is HOST-OWNED — the inspector applies the
|
|
459
|
+
* HOSTED_MODE / web-managed guard before calling the raw api.
|
|
460
|
+
*/
|
|
461
|
+
interface WidgetHostServices {
|
|
462
|
+
fetchWidgetContent: (req: FetchWidgetContentRequest) => Promise<FetchWidgetContentResponse>;
|
|
463
|
+
readResource: (serverId: string, uri: string, opts?: {
|
|
464
|
+
forceHosted?: boolean;
|
|
465
|
+
}) => Promise<any>;
|
|
466
|
+
listResources: (serverId: string, cursor?: string, opts?: {
|
|
467
|
+
forceHosted?: boolean;
|
|
468
|
+
}) => Promise<ListResourcesResult>;
|
|
469
|
+
listPrompts: (serverId: string, opts?: {
|
|
470
|
+
forceHosted?: boolean;
|
|
471
|
+
}) => Promise<MCPPrompt[]>;
|
|
472
|
+
listResourceTemplates: (serverId: string) => Promise<MCPResourceTemplate[]>;
|
|
473
|
+
/**
|
|
474
|
+
* Session-authenticated `fetch` (the inspector's `authFetch`): attaches the
|
|
475
|
+
* hosted bearer/session token for inspector API paths. Used by the widget
|
|
476
|
+
* file-upload bridge (`openai:uploadFile`); plain static/cached fetches use
|
|
477
|
+
* the global `fetch` directly.
|
|
478
|
+
*/
|
|
479
|
+
authFetch: (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
480
|
+
}
|
|
481
|
+
interface WidgetHost {
|
|
482
|
+
/**
|
|
483
|
+
* Resolved per-server environment — the deferred fully-pre-resolved target.
|
|
484
|
+
* OPTIONAL: the renderer reads the raw `environment` inputs + `resolvers`
|
|
485
|
+
* instead. 3d-iii already removed the `HostConfigMcpProfileV1` type from the
|
|
486
|
+
* public surface (the profile is bound inside the adapter's resolvers);
|
|
487
|
+
* collapsing `environment` + `resolvers` entirely into this is a later step.
|
|
488
|
+
*/
|
|
489
|
+
resolveEnvironment?: (serverId: string | undefined) => WidgetHostEnvironment;
|
|
490
|
+
/** Raw ambient ENV inputs (Phase 1b); supplied by the inspector adapter. */
|
|
491
|
+
environment: WidgetHostEnvironmentInputs;
|
|
492
|
+
/** Bound resolver/projection fns (Phase 1b); bound by the inspector adapter. */
|
|
493
|
+
resolvers: WidgetHostResolvers;
|
|
494
|
+
services: WidgetHostServices;
|
|
495
|
+
surface: WidgetSurfaceInfo;
|
|
496
|
+
debug?: WidgetDebugSink;
|
|
497
|
+
components?: WidgetHostComponents;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
interface WidgetHostProviderProps {
|
|
501
|
+
/** The concrete host the inspector builds from its stores/contexts. */
|
|
502
|
+
value: WidgetHost;
|
|
503
|
+
children: ReactNode;
|
|
504
|
+
}
|
|
505
|
+
declare function WidgetHostProvider({ value, children, }: WidgetHostProviderProps): react_jsx_runtime.JSX.Element;
|
|
506
|
+
/**
|
|
507
|
+
* Read the injected {@link WidgetHost}. Throws if no `<WidgetHostProvider>` is
|
|
508
|
+
* mounted above — the package never reaches into inspector state itself, so a
|
|
509
|
+
* missing provider is a wiring bug, not a fallback.
|
|
510
|
+
*/
|
|
511
|
+
declare function useWidgetHost(): WidgetHost;
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Minimal structural shape `detectUiTypeFromTool` needs — just the `_meta` bag.
|
|
515
|
+
* Kept structural (rather than importing `Tool` from
|
|
516
|
+
* `@modelcontextprotocol/client`) so the package's public detection surface
|
|
517
|
+
* doesn't pin a specific MCP SDK Tool type; any `{ _meta }`-bearing tool works.
|
|
518
|
+
*/
|
|
519
|
+
interface ToolLike {
|
|
520
|
+
_meta?: Record<string, unknown>;
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
declare enum UIType {
|
|
524
|
+
MCP_APPS = "mcp-apps",
|
|
525
|
+
OPENAI_SDK = "openai-sdk",
|
|
526
|
+
OPENAI_SDK_AND_MCP_APPS = "openai-sdk-and-mcp-apps",
|
|
527
|
+
MCP_UI = "mcp-ui"
|
|
528
|
+
}
|
|
529
|
+
declare function detectUiTypeFromTool(tool: ToolLike): UIType | null;
|
|
530
|
+
declare function detectUIType(toolMeta: Record<string, unknown> | undefined, toolResult: unknown): UIType | null;
|
|
531
|
+
declare function getUIResourceUri(uiType: UIType | null, toolMeta: Record<string, unknown> | undefined): string | null;
|
|
532
|
+
|
|
533
|
+
/**
|
|
534
|
+
* Shared helpers for reading metadata and server IDs from tool results.
|
|
535
|
+
*
|
|
536
|
+
* Tool results may carry `_meta` and `_serverId` either at the top level or
|
|
537
|
+
* nested under a `.value` wrapper. These utilities normalise access across both
|
|
538
|
+
* shapes. Pure (no deps) — relocated from the inspector in Phase 3d-ii.
|
|
539
|
+
*/
|
|
540
|
+
declare function readToolResultObject(result: unknown): Record<string, unknown> | undefined;
|
|
541
|
+
declare function readToolResultMeta(result: unknown): Record<string, unknown> | undefined;
|
|
542
|
+
declare function readToolResultServerId(result: unknown): string | undefined;
|
|
543
|
+
|
|
544
|
+
/** Injected traffic-log sink — `WidgetDebugSink["addTrafficLog"]`. */
|
|
545
|
+
type AddTrafficLog = WidgetDebugSink["addTrafficLog"];
|
|
546
|
+
/** Per-AppBridge instance identifier (independent of parentToolCallId). */
|
|
547
|
+
type BridgeId = string;
|
|
548
|
+
type AppToolDescriptor = NonNullable<Awaited<ReturnType<AppBridge["listTools"]>>["tools"]>[number];
|
|
549
|
+
interface AppInstance {
|
|
550
|
+
bridgeId: BridgeId;
|
|
551
|
+
/** Chat session/lane that owns this rendered iframe. */
|
|
552
|
+
chatSessionId?: string;
|
|
553
|
+
/** The host tool call whose render mounted this iframe. */
|
|
554
|
+
parentToolCallId: string;
|
|
555
|
+
serverId: string;
|
|
556
|
+
appName: string;
|
|
557
|
+
appVersion?: string;
|
|
558
|
+
surface: "inline" | "modal";
|
|
559
|
+
bridge: AppBridge;
|
|
560
|
+
tools: AppToolDescriptor[];
|
|
561
|
+
registeredAtMs: number;
|
|
562
|
+
/**
|
|
563
|
+
* Accessor for the iframe DOM node that hosts this app instance. Lets
|
|
564
|
+
* callers (e.g. `onToolCall`) scroll the iframe into view before
|
|
565
|
+
* dispatching `tools/call`. Optional because legacy callers and tests
|
|
566
|
+
* may not set it.
|
|
567
|
+
*/
|
|
568
|
+
getIframeElement?: () => HTMLIFrameElement | null;
|
|
569
|
+
}
|
|
570
|
+
interface AppToolAlias {
|
|
571
|
+
alias: string;
|
|
572
|
+
bridgeId: BridgeId;
|
|
573
|
+
rawName: string;
|
|
574
|
+
/** Cached from `annotations.readOnlyHint === true`. */
|
|
575
|
+
readOnly: boolean;
|
|
576
|
+
}
|
|
577
|
+
/** What the snapshot ships to the server in the chat POST body. */
|
|
578
|
+
interface AppToolSnapshotEntry {
|
|
579
|
+
alias: string;
|
|
580
|
+
appName: string;
|
|
581
|
+
appVersion?: string;
|
|
582
|
+
serverId: string;
|
|
583
|
+
parentToolCallId: string;
|
|
584
|
+
rawName: string;
|
|
585
|
+
description?: string;
|
|
586
|
+
inputSchema?: Record<string, unknown>;
|
|
587
|
+
readOnly: boolean;
|
|
588
|
+
}
|
|
589
|
+
interface AppToolAttribution {
|
|
590
|
+
rawName: string;
|
|
591
|
+
appName: string;
|
|
592
|
+
}
|
|
593
|
+
interface AppToolsRegistryState {
|
|
594
|
+
instancesByBridgeId: Map<BridgeId, AppInstance>;
|
|
595
|
+
aliases: Map<string, AppToolAlias>;
|
|
596
|
+
/** Active app-tool provider per chat-scoped host tool call. */
|
|
597
|
+
activeBridgeByParent: Map<string, BridgeId>;
|
|
598
|
+
/**
|
|
599
|
+
* AbortControllers for in-flight `bridge.callTool(...)` dispatches, keyed
|
|
600
|
+
* by the dispatching bridge's id. `unregisterInstance` aborts every
|
|
601
|
+
* controller in the matching set so a torn-down iframe never leaves a
|
|
602
|
+
* paused server stream waiting forever. Each set is also the source of
|
|
603
|
+
* truth for the per-iframe busy indicator.
|
|
604
|
+
*/
|
|
605
|
+
pendingControllers: Map<BridgeId, Set<AbortController>>;
|
|
606
|
+
registerInstance: (inst: AppInstance) => Promise<void>;
|
|
607
|
+
unregisterInstance: (bridgeId: BridgeId) => void;
|
|
608
|
+
pushActive: (parentToolCallId: string, bridgeId: BridgeId, chatSessionId?: string) => void;
|
|
609
|
+
popActive: (parentToolCallId: string, bridgeId: BridgeId, chatSessionId?: string) => void;
|
|
610
|
+
/** Adds `controller` to the bridge's pending set and bumps the busy count. */
|
|
611
|
+
registerPendingCall: (bridgeId: BridgeId, controller: AbortController) => void;
|
|
612
|
+
/** Removes `controller` from the bridge's pending set (no-op if absent). */
|
|
613
|
+
unregisterPendingCall: (bridgeId: BridgeId, controller: AbortController) => void;
|
|
614
|
+
snapshotForChatBody: (chatSessionId?: string) => AppToolSnapshotEntry[];
|
|
615
|
+
resolve: (alias: string, chatSessionId?: string) => {
|
|
616
|
+
bridge: AppBridge;
|
|
617
|
+
rawName: string;
|
|
618
|
+
readOnly: boolean;
|
|
619
|
+
instance: AppInstance;
|
|
620
|
+
} | null;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Produce an opaque alias for a rendered app tool. SHA-256 hashed over stable
|
|
624
|
+
* identity-bearing inputs and truncated to 8 hex chars so the wire
|
|
625
|
+
* name is always 12 chars: well under Anthropic's 64-char tool-name limit
|
|
626
|
+
* and never collides with the `getInvalidAnthropicToolNames` charset.
|
|
627
|
+
*
|
|
628
|
+
* Deliberately exclude `bridgeId`: a live app can reconnect/re-register its
|
|
629
|
+
* bridge without changing the rendered host tool call or raw app-tool name.
|
|
630
|
+
* The alias must stay stable across that churn so the model does not see the
|
|
631
|
+
* same app tool under a fresh name.
|
|
632
|
+
*
|
|
633
|
+
* Collision retry: if a generated alias is already in use, the caller
|
|
634
|
+
* (`registerInstance`) re-rolls with a numeric salt appended to the
|
|
635
|
+
* preimage. In practice 8 hex chars over the joined inputs has negligible
|
|
636
|
+
* collision risk; the retry is a belt-and-suspenders guard.
|
|
637
|
+
*/
|
|
638
|
+
declare function generateAlias(chatSessionId: string | undefined, serverId: string, parentToolCallId: string, surface: AppInstance["surface"], rawName: string, salt?: number): Promise<string>;
|
|
639
|
+
declare function isReadOnly(tool: AppToolDescriptor): boolean;
|
|
640
|
+
declare const useAppToolsRegistry: zustand.UseBoundStore<zustand.StoreApi<AppToolsRegistryState>>;
|
|
641
|
+
/**
|
|
642
|
+
* Side-channel log of every app-tool invocation for debugging and future UI.
|
|
643
|
+
* Mirrors the widget-html debug store pattern. The full untouched
|
|
644
|
+
* `CallToolResult` is stored here so the UI can later display
|
|
645
|
+
* `structuredContent` / `_meta` that were intentionally stripped from model
|
|
646
|
+
* context.
|
|
647
|
+
*/
|
|
648
|
+
interface AppToolInvocationRecord {
|
|
649
|
+
alias: string;
|
|
650
|
+
rawName: string;
|
|
651
|
+
appName: string;
|
|
652
|
+
serverId: string;
|
|
653
|
+
parentToolCallId: string;
|
|
654
|
+
bridgeId: BridgeId;
|
|
655
|
+
input: unknown;
|
|
656
|
+
raw: CallToolResult;
|
|
657
|
+
invokedAtMs: number;
|
|
658
|
+
}
|
|
659
|
+
interface AppToolInvocationLogState {
|
|
660
|
+
records: AppToolInvocationRecord[];
|
|
661
|
+
append: (r: AppToolInvocationRecord) => void;
|
|
662
|
+
clear: () => void;
|
|
663
|
+
}
|
|
664
|
+
declare const useAppToolInvocationLog: zustand.UseBoundStore<zustand.StoreApi<AppToolInvocationLogState>>;
|
|
665
|
+
declare function recordAppToolInvocation(args: Omit<AppToolInvocationRecord, "invokedAtMs">, addTrafficLog?: AddTrafficLog): void;
|
|
666
|
+
declare function useAppToolAttributionResolver(chatSessionId?: string): (label: string) => AppToolAttribution | null;
|
|
667
|
+
declare function useAppToolAttribution(label: string, chatSessionId?: string): AppToolAttribution | null;
|
|
668
|
+
declare const __internal: {
|
|
669
|
+
generateAlias: typeof generateAlias;
|
|
670
|
+
isReadOnly: typeof isReadOnly;
|
|
671
|
+
ALIAS_REGEX: RegExp;
|
|
672
|
+
};
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* useToolInputStreaming – manages the streaming delivery of tool input to
|
|
676
|
+
* an MCP App bridge.
|
|
677
|
+
*
|
|
678
|
+
* Extracted from mcp-apps-renderer.tsx so the streaming logic can be tested
|
|
679
|
+
* in isolation and extended with debug tooling (e.g. a streaming slider)
|
|
680
|
+
* without touching the renderer component.
|
|
681
|
+
*/
|
|
682
|
+
|
|
683
|
+
declare const PARTIAL_INPUT_THROTTLE_MS = 120;
|
|
684
|
+
declare const STREAMING_REVEAL_FALLBACK_MS = 700;
|
|
685
|
+
declare const SIGNATURE_MAX_DEPTH = 4;
|
|
686
|
+
declare const SIGNATURE_MAX_ARRAY_ITEMS = 24;
|
|
687
|
+
declare const SIGNATURE_MAX_OBJECT_KEYS = 32;
|
|
688
|
+
declare const SIGNATURE_STRING_EDGE_LENGTH = 24;
|
|
689
|
+
type ToolState = "input-streaming" | "input-available" | "approval-requested" | "output-available" | "output-denied" | "output-error";
|
|
690
|
+
/**
|
|
691
|
+
* Produce a compact structural fingerprint of `input` so we can cheaply
|
|
692
|
+
* detect whether a new streaming partial is meaningfully different from the
|
|
693
|
+
* last one we sent to the bridge.
|
|
694
|
+
*/
|
|
695
|
+
declare function getToolInputSignature(input: Record<string, unknown> | undefined): string;
|
|
696
|
+
interface UseToolInputStreamingParams {
|
|
697
|
+
bridgeRef: React.RefObject<AppBridge | null>;
|
|
698
|
+
isReady: boolean;
|
|
699
|
+
isReadyRef: React.RefObject<boolean>;
|
|
700
|
+
toolState: ToolState | undefined;
|
|
701
|
+
toolInput: Record<string, unknown> | undefined;
|
|
702
|
+
toolOutput: unknown;
|
|
703
|
+
toolErrorText: string | undefined;
|
|
704
|
+
toolCallId: string;
|
|
705
|
+
/**
|
|
706
|
+
* Whether this View should receive the one-shot complete tool-input
|
|
707
|
+
* notification for the current render. Resource-scoped persistent Views
|
|
708
|
+
* keep the iframe alive across tool calls, but each new tool call still
|
|
709
|
+
* gets a complete input notification before its result.
|
|
710
|
+
*/
|
|
711
|
+
sendToolInput: boolean;
|
|
712
|
+
onToolInputSent?: () => void;
|
|
713
|
+
/** Incremented when the guest re-initializes (e.g. SDK app after openai-compat shim) */
|
|
714
|
+
reinitCount: number;
|
|
715
|
+
/**
|
|
716
|
+
* Resolved SEP-1865 MCP Apps spec-bridge matrix. Gates the
|
|
717
|
+
* notifications this hook emits to the View:
|
|
718
|
+
* - `toolInputPartial: false` → suppress
|
|
719
|
+
* `bridge.sendToolInputPartial` (Microsoft 365 Copilot does
|
|
720
|
+
* not deliver this notification — widgets running under that
|
|
721
|
+
* simulated surface must not see partials).
|
|
722
|
+
* - `toolCancelled: false` → suppress `bridge.sendToolCancelled`
|
|
723
|
+
* (Copilot does not deliver this either).
|
|
724
|
+
*
|
|
725
|
+
* Passed as a ref so the hook reads the latest resolved value
|
|
726
|
+
* without rebuilding the effect closures on every host-style /
|
|
727
|
+
* profile change. Null while the renderer is still resolving the
|
|
728
|
+
* matrix (e.g. before host context is wired) — null reads as
|
|
729
|
+
* "default on" so the inspector keeps emitting notifications by
|
|
730
|
+
* default, matching the pre-matrix behavior for any host the
|
|
731
|
+
* renderer hasn't classified yet.
|
|
732
|
+
*/
|
|
733
|
+
mcpAppsCapabilitiesRef: React.RefObject<ResolvedMcpAppsCapabilities | null>;
|
|
734
|
+
}
|
|
735
|
+
interface UseToolInputStreamingReturn {
|
|
736
|
+
canRenderStreamingInput: boolean;
|
|
737
|
+
/** Called by LoggingTransport onReceive when a size-changed notification arrives. */
|
|
738
|
+
signalStreamingRender: () => void;
|
|
739
|
+
/** Called on CSP mode change (or externally) to clear all streaming state. */
|
|
740
|
+
resetStreamingState: () => void;
|
|
741
|
+
}
|
|
742
|
+
declare function useToolInputStreaming({ bridgeRef, isReady, isReadyRef, toolState, toolInput, toolOutput, toolErrorText, toolCallId, sendToolInput, onToolInputSent, reinitCount, mcpAppsCapabilitiesRef, }: UseToolInputStreamingParams): UseToolInputStreamingReturn;
|
|
743
|
+
|
|
744
|
+
interface SandboxedIframeHandle {
|
|
745
|
+
postMessage: (data: unknown) => void;
|
|
746
|
+
getIframeElement: () => HTMLIFrameElement | null;
|
|
747
|
+
}
|
|
748
|
+
interface SandboxedIframeProps {
|
|
749
|
+
/** HTML content to render in the sandbox */
|
|
750
|
+
html: string | null;
|
|
751
|
+
/** Sandbox attribute for the inner iframe */
|
|
752
|
+
sandbox?: string;
|
|
753
|
+
/** CSP metadata from resource _meta.ui.csp (SEP-1865) */
|
|
754
|
+
csp?: McpUiResourceCsp;
|
|
755
|
+
/** Permissions metadata from resource _meta.ui.permissions (SEP-1865) */
|
|
756
|
+
permissions?: McpUiResourcePermissions;
|
|
757
|
+
/**
|
|
758
|
+
* Inspector-only: extra `sandbox=` tokens unioned with the spec-mandated
|
|
759
|
+
* `allow-scripts allow-same-origin` on both outer and inner iframes.
|
|
760
|
+
* Models tokens real hosts emit (e.g. `allow-forms`) that aren't part of
|
|
761
|
+
* SEP-1865 metadata.
|
|
762
|
+
*/
|
|
763
|
+
sandboxAttrs?: string[];
|
|
764
|
+
/**
|
|
765
|
+
* Inspector-only: extra Permissions Policy entries appended to outer/inner
|
|
766
|
+
* iframe `allow=`. Keys are kebab Permissions Policy tokens
|
|
767
|
+
* (`fullscreen`, `web-share`); the 4 spec features
|
|
768
|
+
* (camera/microphone/geolocation/clipboard-write) live in `permissions`
|
|
769
|
+
* and are NOT permitted here.
|
|
770
|
+
*/
|
|
771
|
+
allowFeatures?: Record<string, string>;
|
|
772
|
+
/**
|
|
773
|
+
* Inspector-only: per-directive CSP source-expression overrides merged
|
|
774
|
+
* into the inner doc's `<meta http-equiv="Content-Security-Policy">`.
|
|
775
|
+
* Keys are CSP directive names (`script-src`, …); values are token arrays
|
|
776
|
+
* (`["'unsafe-eval'", "'wasm-unsafe-eval'"]`).
|
|
777
|
+
*/
|
|
778
|
+
cspDirectives?: Record<string, string[]>;
|
|
779
|
+
/** Skip CSP injection entirely (for permissive/testing mode) */
|
|
780
|
+
permissive?: boolean;
|
|
781
|
+
/** Callback when sandbox proxy is ready */
|
|
782
|
+
onProxyReady?: () => void;
|
|
783
|
+
/** Callback for messages from guest UI (excluding sandbox-internal messages) */
|
|
784
|
+
onMessage: (event: MessageEvent) => void;
|
|
785
|
+
/** CSS class for the outer iframe */
|
|
786
|
+
className?: string;
|
|
787
|
+
/** Inline styles for the outer iframe */
|
|
788
|
+
style?: React.CSSProperties;
|
|
789
|
+
/** Host color scheme used to keep transparent iframe canvas rendering aligned */
|
|
790
|
+
colorScheme?: "light" | "dark";
|
|
791
|
+
/** Title for accessibility */
|
|
792
|
+
title?: string;
|
|
793
|
+
/**
|
|
794
|
+
* Whether the app runs against the hosted backend (the inspector's
|
|
795
|
+
* `HOSTED_MODE`). Selects the hosted vs. local sandbox-proxy path and the
|
|
796
|
+
* same-origin security warning. Supplied by the host (`host.surface.hostedMode`)
|
|
797
|
+
* so this component carries no inspector config import.
|
|
798
|
+
*/
|
|
799
|
+
hostedMode?: boolean;
|
|
800
|
+
/**
|
|
801
|
+
* Operator-configured sandbox origin (the inspector's `SANDBOX_ORIGIN` /
|
|
802
|
+
* `VITE_MCPJAM_SANDBOX_ORIGIN`); "" when unset. Used in hosted mode to load
|
|
803
|
+
* the sandbox proxy from a distinct origin. Supplied by the host
|
|
804
|
+
* (`host.surface.sandboxOrigin`).
|
|
805
|
+
*/
|
|
806
|
+
sandboxOrigin?: string;
|
|
807
|
+
}
|
|
808
|
+
/**
|
|
809
|
+
* SandboxedIframe provides a secure double-iframe architecture per SEP-1865.
|
|
810
|
+
*
|
|
811
|
+
* Message flow:
|
|
812
|
+
* 1. Proxy sends ui/notifications/sandbox-proxy-ready when loaded
|
|
813
|
+
* 2. Host sends ui/notifications/sandbox-resource-ready with HTML
|
|
814
|
+
* 3. Guest UI initializes and communicates via JSON-RPC 2.0
|
|
815
|
+
*/
|
|
816
|
+
declare const SandboxedIframe: react.ForwardRefExoticComponent<SandboxedIframeProps & react.RefAttributes<SandboxedIframeHandle>>;
|
|
817
|
+
|
|
818
|
+
interface MCPAppsRendererProps {
|
|
819
|
+
chatSessionId?: string;
|
|
820
|
+
serverId: string;
|
|
821
|
+
serverName?: string;
|
|
822
|
+
toolCallId: string;
|
|
823
|
+
toolName: string;
|
|
824
|
+
toolState?: ToolState;
|
|
825
|
+
toolInput?: Record<string, unknown>;
|
|
826
|
+
toolOutput?: unknown;
|
|
827
|
+
/**
|
|
828
|
+
* Tool response `_meta`, pre-extracted by the caller from the raw
|
|
829
|
+
* (still-wrapped) tool result. Required because `toolOutput` is
|
|
830
|
+
* typically the *unwrapped* value (e.g. `result.value`), at which
|
|
831
|
+
* point `_meta` from the wrapper is no longer reachable from the
|
|
832
|
+
* value alone. Passing this explicitly preserves Apps SDK's
|
|
833
|
+
* `window.openai.toolResponseMetadata` surface for widgets relying
|
|
834
|
+
* on it (timestamps, source IDs, etc.).
|
|
835
|
+
*/
|
|
836
|
+
toolResponseMetadata?: Record<string, unknown> | null;
|
|
837
|
+
toolErrorText?: string;
|
|
838
|
+
resourceUri: string;
|
|
839
|
+
toolMetadata?: Record<string, unknown>;
|
|
840
|
+
/** All tools metadata for visibility checking when widget calls tools */
|
|
841
|
+
toolsMetadata?: Record<string, Record<string, unknown>>;
|
|
842
|
+
onSendFollowUp?: (text: string) => void;
|
|
843
|
+
onCallTool?: (toolName: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
844
|
+
onAppToolInvocationChange?: (invocation: AppToolInvocationUpdate) => void;
|
|
845
|
+
onWidgetStateChange?: (toolCallId: string, state: unknown) => void;
|
|
846
|
+
pipWidgetId?: string | null;
|
|
847
|
+
fullscreenWidgetId?: string | null;
|
|
848
|
+
onRequestPip?: (toolCallId: string) => void;
|
|
849
|
+
onExitPip?: (toolCallId: string) => void;
|
|
850
|
+
/** Controlled display mode - when provided, component uses this instead of internal state */
|
|
851
|
+
displayMode?: DisplayMode;
|
|
852
|
+
/** Callback when display mode changes - required when displayMode is controlled */
|
|
853
|
+
onDisplayModeChange?: (mode: DisplayMode) => void;
|
|
854
|
+
onRequestFullscreen?: (toolCallId: string) => void;
|
|
855
|
+
onExitFullscreen?: (toolCallId: string) => void;
|
|
856
|
+
/** Callback when widget updates model context (SEP-1865 ui/update-model-context) */
|
|
857
|
+
onModelContextUpdate?: (toolCallId: string, context: {
|
|
858
|
+
content?: ContentBlock[];
|
|
859
|
+
structuredContent?: Record<string, unknown>;
|
|
860
|
+
}) => void;
|
|
861
|
+
/** Callback when app declares its supported display modes during ui/initialize */
|
|
862
|
+
onAppSupportedDisplayModesChange?: (modes: DisplayMode[] | undefined) => void;
|
|
863
|
+
/**
|
|
864
|
+
* Called when the widget sends `ui/notifications/request-teardown`
|
|
865
|
+
* and the host has agreed to honor it (matrix `requestTeardown !==
|
|
866
|
+
* false`). The renderer has already attempted a graceful
|
|
867
|
+
* `ui/resource-teardown` round-trip; the parent is now expected to
|
|
868
|
+
* unmount this tool call's MCP app surface (e.g. dismiss the modal,
|
|
869
|
+
* collapse the inline view).
|
|
870
|
+
*/
|
|
871
|
+
onRequestTeardown?: (toolCallId: string, displayWidgetId?: string) => void;
|
|
872
|
+
/** Whether the server is offline (for using cached content) */
|
|
873
|
+
isOffline?: boolean;
|
|
874
|
+
/** URL to cached widget HTML for offline rendering */
|
|
875
|
+
cachedWidgetHtmlUrl?: string;
|
|
876
|
+
/**
|
|
877
|
+
* If true, attempt the live MCP Apps fetch first and only fall back to
|
|
878
|
+
* `cachedWidgetHtmlUrl` if the live fetch fails (e.g. the server is no
|
|
879
|
+
* longer connected). Used by in-flow session revisit; persisted offline
|
|
880
|
+
* replay (Views tab, eval traces) leaves this unset so the cached path
|
|
881
|
+
* stays primary.
|
|
882
|
+
*/
|
|
883
|
+
liveFetchPreferred?: boolean;
|
|
884
|
+
/** Persisted CSP metadata for cached/offline replay */
|
|
885
|
+
widgetCsp?: McpUiResourceCsp | null;
|
|
886
|
+
/** Persisted permissions metadata for cached/offline replay */
|
|
887
|
+
widgetPermissions?: McpUiResourcePermissions | null;
|
|
888
|
+
/** Persisted permissive flag for cached/offline replay */
|
|
889
|
+
widgetPermissive?: boolean;
|
|
890
|
+
/** Persisted prefersBorder value for cached/offline replay */
|
|
891
|
+
prefersBorder?: boolean;
|
|
892
|
+
/**
|
|
893
|
+
* Persisted compat-runtime flag from a saved view or eval snapshot.
|
|
894
|
+
* When set, the renderer trusts the cached blob as the source of
|
|
895
|
+
* truth for whether `window.openai` was injected at capture time —
|
|
896
|
+
* the live profile's flag is ignored for cached replay because the
|
|
897
|
+
* HTML is byte-frozen. When undefined (no snapshot metadata), the
|
|
898
|
+
* renderer falls back to the resolved live flag for fresh fetches.
|
|
899
|
+
*/
|
|
900
|
+
injectedOpenAiCompat?: boolean;
|
|
901
|
+
/**
|
|
902
|
+
* Persisted per-method `window.openai.*` surface that was injected
|
|
903
|
+
* into the cached HTML blob. Threads through the saved-view replay
|
|
904
|
+
* path so the SDK runtime reproduces the same set of methods on
|
|
905
|
+
* `window.openai` that the original capture had, even after the
|
|
906
|
+
* active host config has flipped. Absent for pre-feature snapshots
|
|
907
|
+
* — those replay against the runtime's full ChatGPT surface
|
|
908
|
+
* default (matches behavior at capture time).
|
|
909
|
+
*/
|
|
910
|
+
injectedOpenAiCompatCapabilities?: OpenAiAppsCapabilities;
|
|
911
|
+
/**
|
|
912
|
+
* Persisted widget state from a saved view or fork. When set, the
|
|
913
|
+
* compat runtime seeds `window.openai.widgetState` with this value so
|
|
914
|
+
* the widget boots in the same state it was when the view was saved
|
|
915
|
+
* (Apps SDK parity — the legacy ChatGPTAppRenderer wired this the same
|
|
916
|
+
* way).
|
|
917
|
+
*/
|
|
918
|
+
initialWidgetState?: unknown;
|
|
919
|
+
/** Minimal mode hides diagnostics and metadata surfaces */
|
|
920
|
+
minimalMode?: boolean;
|
|
921
|
+
/**
|
|
922
|
+
* Stable identity assigned by WidgetSurfaceHost. Present only when the
|
|
923
|
+
* renderer is mounted as a persistent, resource-scoped surface.
|
|
924
|
+
*/
|
|
925
|
+
persistentSurfaceId?: string;
|
|
926
|
+
/**
|
|
927
|
+
* The first tool call registered for a resource-scoped persistent surface.
|
|
928
|
+
* Kept for host/debug attribution; complete tool-input is still gated by
|
|
929
|
+
* the surface's one-shot delivery latch so restored transcripts cannot skip
|
|
930
|
+
* input when multiple rows register before the host mounts.
|
|
931
|
+
*/
|
|
932
|
+
persistentSurfaceInitialToolCallId?: string;
|
|
933
|
+
}
|
|
934
|
+
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;
|
|
936
|
+
|
|
937
|
+
declare function WidgetSurfaceHostProvider({ children, }: {
|
|
938
|
+
children: ReactNode;
|
|
939
|
+
}): react_jsx_runtime.JSX.Element;
|
|
940
|
+
declare function usePersistentWidgetSurfaceHost(): boolean;
|
|
941
|
+
|
|
942
|
+
declare function WidgetSurfaceHost({ chatSessionId, }: {
|
|
943
|
+
chatSessionId?: string;
|
|
944
|
+
}): react_jsx_runtime.JSX.Element;
|
|
945
|
+
|
|
946
|
+
type WidgetSurfaceId = string;
|
|
947
|
+
interface WidgetSurfaceRegistration {
|
|
948
|
+
toolCallId: string;
|
|
949
|
+
order: number;
|
|
950
|
+
props: MCPAppsRendererProps;
|
|
951
|
+
anchorElement: HTMLDivElement | null;
|
|
952
|
+
}
|
|
953
|
+
interface WidgetSurfaceRecord {
|
|
954
|
+
surfaceId: WidgetSurfaceId;
|
|
955
|
+
chatSessionId?: string;
|
|
956
|
+
initialToolCallId: string;
|
|
957
|
+
latestToolCallId: string;
|
|
958
|
+
registrations: Map<string, WidgetSurfaceRegistration>;
|
|
959
|
+
}
|
|
960
|
+
interface WidgetSurfaceStoreState {
|
|
961
|
+
surfaces: Map<WidgetSurfaceId, WidgetSurfaceRecord>;
|
|
962
|
+
nextOrder: number;
|
|
963
|
+
upsertRegistration: (surfaceId: WidgetSurfaceId, toolCallId: string, props: MCPAppsRendererProps) => void;
|
|
964
|
+
setAnchor: (surfaceId: WidgetSurfaceId, toolCallId: string, anchorElement: HTMLDivElement | null) => void;
|
|
965
|
+
releaseRegistration: (surfaceId: WidgetSurfaceId, toolCallId: string) => void;
|
|
966
|
+
clearChatSession: (chatSessionId?: string) => void;
|
|
967
|
+
}
|
|
968
|
+
declare const useWidgetSurfaceStore: zustand.UseBoundStore<zustand.StoreApi<WidgetSurfaceStoreState>>;
|
|
969
|
+
declare function getRenderableSurfaceEntries(surfaces: Map<WidgetSurfaceId, WidgetSurfaceRecord>, chatSessionId?: string): {
|
|
970
|
+
surfaceId: WidgetSurfaceId;
|
|
971
|
+
anchorElement: HTMLDivElement | null;
|
|
972
|
+
initialToolCallId: string;
|
|
973
|
+
props: MCPAppsRendererProps;
|
|
974
|
+
}[];
|
|
975
|
+
|
|
976
|
+
export { type AddTrafficLog, type AppInstance, type AppToolAlias, type AppToolAttribution, type AppToolDescriptor, type AppToolInvocationRecord, type AppToolSnapshotEntry, type BridgeId, type ChatboxHostStyle, 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, SandboxedIframe, type SandboxedIframeHandle, 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, useAppToolAttribution, useAppToolAttributionResolver, useAppToolInvocationLog, useAppToolsRegistry, usePersistentWidgetSurfaceHost, useToolInputStreaming, useWidgetHost, useWidgetSurfaceStore };
|