@mcpjam/widget-react 0.1.12 → 0.1.13
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 +16 -2
- package/dist/index.js +62 -18
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -111,7 +111,7 @@ type ResolvedMcpAppsCapabilities = {
|
|
|
111
111
|
/**
|
|
112
112
|
* getHostStyleOrDefault / DEFAULT_HOST_STYLE result — typed to the renderer's
|
|
113
113
|
* AUDITED reads only: `.mcp.{resolveStyleVariables,fontCss,platform}` and
|
|
114
|
-
* `.chatUi.resolveChatBackground` (+ `.id`). The real `HostStyleDefinition` has
|
|
114
|
+
* `.chatUi.{label,resolveChatBackground}` (+ `.id`). The real `HostStyleDefinition` has
|
|
115
115
|
* more (the full profile/chat-ui graph); the adapter assigns it (assignable to
|
|
116
116
|
* this minimal surface), so the package never replicates that graph.
|
|
117
117
|
*/
|
|
@@ -123,6 +123,7 @@ interface ResolvedHostStyle {
|
|
|
123
123
|
platform: "web" | "desktop" | "mobile";
|
|
124
124
|
};
|
|
125
125
|
chatUi: {
|
|
126
|
+
label?: string;
|
|
126
127
|
resolveChatBackground: (theme: "light" | "dark") => string;
|
|
127
128
|
};
|
|
128
129
|
}
|
|
@@ -173,8 +174,18 @@ interface WidgetMount {
|
|
|
173
174
|
}
|
|
174
175
|
/** New mounts use an opaque string; numbers remain valid for saved data. */
|
|
175
176
|
type CspMountId = string | number;
|
|
177
|
+
/** Selected client and declared domains captured with the mount recipe. */
|
|
178
|
+
interface CspClientContext {
|
|
179
|
+
surface?: "inline" | "modal";
|
|
180
|
+
clientName: string;
|
|
181
|
+
declaredCsp?: McpUiResourceCsp;
|
|
182
|
+
capabilities: Pick<ResolvedMcpAppsCapabilities, "cspConnectDomains" | "cspResourceDomains" | "cspFrameDomains" | "cspBaseUriDomains">;
|
|
183
|
+
}
|
|
176
184
|
/** What MCPJam meant to install before the sandbox proxy serialized it. */
|
|
177
185
|
interface CspApplicationIntent {
|
|
186
|
+
/** Actual restrictions used to serialize this mount, not the live profile. */
|
|
187
|
+
cspSubtypePolicy?: CspSubtypePolicy;
|
|
188
|
+
clientContext?: CspClientContext;
|
|
178
189
|
csp?: McpUiResourceCsp;
|
|
179
190
|
cspDirectives?: Record<string, string[]>;
|
|
180
191
|
permissive: boolean;
|
|
@@ -350,6 +361,8 @@ interface UiLogEvent {
|
|
|
350
361
|
}
|
|
351
362
|
/** Diagnostics sink — 1:1 with widget-debug-store + traffic-log addLog. */
|
|
352
363
|
interface WidgetDebugSink {
|
|
364
|
+
/** Release notifications for one surface without clearing other live views. */
|
|
365
|
+
clearCspMount?: (toolCallId: string, mountId: CspMountId) => void;
|
|
353
366
|
recordMount: (toolCallId: string, reason: string) => void;
|
|
354
367
|
setWidgetDebugInfo: (toolCallId: string, info: Partial<Omit<WidgetDebugInfo, "toolCallId" | "updatedAt">>) => void;
|
|
355
368
|
setWidgetState: (toolCallId: string, state: unknown) => void;
|
|
@@ -913,6 +926,7 @@ interface SandboxedIframeProps {
|
|
|
913
926
|
cspDirectives?: Record<string, string[]>;
|
|
914
927
|
/** Probe-derived host policy for individual CSP-backed browser APIs. */
|
|
915
928
|
cspSubtypePolicy?: CspSubtypePolicy;
|
|
929
|
+
clientContext?: CspClientContext;
|
|
916
930
|
/**
|
|
917
931
|
* Probe-derived host policy for browser storage inside the widget.
|
|
918
932
|
* Absent or `true` means available; `false` makes the proxy install a guard
|
|
@@ -1175,4 +1189,4 @@ declare function getRenderableSurfaceEntries(surfaces: Map<WidgetSurfaceId, Widg
|
|
|
1175
1189
|
props: MCPAppsRendererProps;
|
|
1176
1190
|
}[];
|
|
1177
1191
|
|
|
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 };
|
|
1192
|
+
export { type AddTrafficLog, type AppInstance, type AppToolAlias, type AppToolAttribution, type AppToolDescriptor, type AppToolInvocationRecord, type AppToolSnapshotEntry, 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, 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 };
|
package/dist/index.js
CHANGED
|
@@ -916,6 +916,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
916
916
|
allowFeatures,
|
|
917
917
|
cspDirectives,
|
|
918
918
|
cspSubtypePolicy,
|
|
919
|
+
clientContext,
|
|
919
920
|
browserStorage,
|
|
920
921
|
permissive,
|
|
921
922
|
recordMode,
|
|
@@ -1025,6 +1026,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1025
1026
|
csp: csp ?? null,
|
|
1026
1027
|
cspDirectives: cspDirectives ?? null,
|
|
1027
1028
|
cspSubtypePolicy: cspSubtypePolicy ?? null,
|
|
1029
|
+
clientContext: clientContext ?? null,
|
|
1028
1030
|
browserStorage: browserStorage ?? null,
|
|
1029
1031
|
html: html ?? null,
|
|
1030
1032
|
permissive: permissive ?? null,
|
|
@@ -1042,6 +1044,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1042
1044
|
csp,
|
|
1043
1045
|
cspDirectives,
|
|
1044
1046
|
cspSubtypePolicy,
|
|
1047
|
+
clientContext,
|
|
1045
1048
|
browserStorage,
|
|
1046
1049
|
html,
|
|
1047
1050
|
permissive,
|
|
@@ -1079,6 +1082,7 @@ var SandboxedIframe = forwardRef(function SandboxedIframe2({
|
|
|
1079
1082
|
// field.
|
|
1080
1083
|
cspDirectives,
|
|
1081
1084
|
cspSubtypePolicy,
|
|
1085
|
+
clientContext,
|
|
1082
1086
|
browserStorage,
|
|
1083
1087
|
permissive,
|
|
1084
1088
|
colorScheme,
|
|
@@ -1141,6 +1145,7 @@ function McpAppsModal({
|
|
|
1141
1145
|
widgetAllowFeatures,
|
|
1142
1146
|
widgetCspDirectives,
|
|
1143
1147
|
widgetCspSubtypePolicy,
|
|
1148
|
+
widgetClientContext,
|
|
1144
1149
|
widgetToolResult,
|
|
1145
1150
|
widgetBrowserStorage,
|
|
1146
1151
|
hostContextRef,
|
|
@@ -1157,7 +1162,8 @@ function McpAppsModal({
|
|
|
1157
1162
|
toolOutputRef,
|
|
1158
1163
|
themeModeRef,
|
|
1159
1164
|
addUiLog,
|
|
1160
|
-
onCspViolation
|
|
1165
|
+
onCspViolation,
|
|
1166
|
+
onCspApplied
|
|
1161
1167
|
}) {
|
|
1162
1168
|
const host = useWidgetHost();
|
|
1163
1169
|
const Modal = host.components?.Modal;
|
|
@@ -1352,10 +1358,26 @@ function McpAppsModal({
|
|
|
1352
1358
|
hostInfo,
|
|
1353
1359
|
effectiveHostCapabilities
|
|
1354
1360
|
]);
|
|
1361
|
+
const modalCspMountRef = useRef(void 0);
|
|
1362
|
+
const clearCspMount = host.debug?.clearCspMount;
|
|
1363
|
+
useEffect(
|
|
1364
|
+
() => () => {
|
|
1365
|
+
if (modalCspMountRef.current !== void 0) {
|
|
1366
|
+
clearCspMount?.(toolCallId, modalCspMountRef.current);
|
|
1367
|
+
modalCspMountRef.current = void 0;
|
|
1368
|
+
}
|
|
1369
|
+
},
|
|
1370
|
+
[open, modalHtml, toolCallId, clearCspMount]
|
|
1371
|
+
);
|
|
1355
1372
|
const handleModalMessage = (event) => {
|
|
1356
1373
|
const data = event.data;
|
|
1357
1374
|
if (!data) return;
|
|
1358
|
-
if (data.type === "
|
|
1375
|
+
if (data.type === "mcpjam:csp-applied" && (typeof data.mountId === "string" || typeof data.mountId === "number")) {
|
|
1376
|
+
modalCspMountRef.current = data.mountId;
|
|
1377
|
+
}
|
|
1378
|
+
if (data.type === "mcpjam:csp-applied") {
|
|
1379
|
+
onCspApplied(event);
|
|
1380
|
+
} else if (data.type === "mcp-apps:csp-violation") {
|
|
1359
1381
|
onCspViolation(event);
|
|
1360
1382
|
}
|
|
1361
1383
|
};
|
|
@@ -1373,6 +1395,7 @@ function McpAppsModal({
|
|
|
1373
1395
|
allowFeatures: widgetAllowFeatures,
|
|
1374
1396
|
cspDirectives: widgetCspDirectives,
|
|
1375
1397
|
cspSubtypePolicy: widgetCspSubtypePolicy,
|
|
1398
|
+
clientContext: widgetClientContext ? { ...widgetClientContext, surface: "modal" } : void 0,
|
|
1376
1399
|
browserStorage: widgetBrowserStorage,
|
|
1377
1400
|
colorScheme: modalColorScheme,
|
|
1378
1401
|
onMessage: handleModalMessage,
|
|
@@ -1650,6 +1673,8 @@ function normalizeCspApplicationIntent(value) {
|
|
|
1650
1673
|
return {
|
|
1651
1674
|
csp: candidate.csp && typeof candidate.csp === "object" ? candidate.csp : void 0,
|
|
1652
1675
|
cspDirectives: candidate.cspDirectives && typeof candidate.cspDirectives === "object" ? candidate.cspDirectives : void 0,
|
|
1676
|
+
cspSubtypePolicy: candidate.cspSubtypePolicy && typeof candidate.cspSubtypePolicy === "object" ? candidate.cspSubtypePolicy : void 0,
|
|
1677
|
+
clientContext: candidate.clientContext && typeof candidate.clientContext === "object" && typeof candidate.clientContext.clientName === "string" && candidate.clientContext.capabilities && typeof candidate.clientContext.capabilities === "object" ? candidate.clientContext : void 0,
|
|
1653
1678
|
permissive: candidate.permissive
|
|
1654
1679
|
};
|
|
1655
1680
|
}
|
|
@@ -3734,7 +3759,7 @@ function MCPAppsRendererSurface({
|
|
|
3734
3759
|
const handleCspViolation = useCallback(
|
|
3735
3760
|
(event) => {
|
|
3736
3761
|
const data = event.data;
|
|
3737
|
-
if (
|
|
3762
|
+
if (data?.type !== "mcp-apps:csp-violation") return;
|
|
3738
3763
|
const {
|
|
3739
3764
|
directive,
|
|
3740
3765
|
blockedUri,
|
|
@@ -3793,6 +3818,24 @@ function MCPAppsRendererSurface({
|
|
|
3793
3818
|
toolCallId
|
|
3794
3819
|
]
|
|
3795
3820
|
);
|
|
3821
|
+
const handleCspApplied = (event) => {
|
|
3822
|
+
const data = event.data;
|
|
3823
|
+
if (data?.type !== "mcpjam:csp-applied") return;
|
|
3824
|
+
const mountId = normalizeCspMountId(data.mountId);
|
|
3825
|
+
if (mountId !== void 0 && typeof data.csp === "string" && data.csp.length > 0) {
|
|
3826
|
+
setWidgetAppliedCspStore(toolCallIdRef.current, {
|
|
3827
|
+
mountId,
|
|
3828
|
+
headerString: data.csp,
|
|
3829
|
+
mode: data.mode === "permissive" ? "permissive" : "widget-declared",
|
|
3830
|
+
intent: normalizeCspApplicationIntent(data.intent)
|
|
3831
|
+
});
|
|
3832
|
+
logWidgetDebug("ui-to-host", "debug/csp-applied", {
|
|
3833
|
+
mountId,
|
|
3834
|
+
mode: data.mode,
|
|
3835
|
+
headerLength: data.csp.length
|
|
3836
|
+
});
|
|
3837
|
+
}
|
|
3838
|
+
};
|
|
3796
3839
|
const handleSandboxMessage = (event) => {
|
|
3797
3840
|
const data = event.data;
|
|
3798
3841
|
if (!data) return;
|
|
@@ -3801,20 +3844,7 @@ function MCPAppsRendererSurface({
|
|
|
3801
3844
|
return;
|
|
3802
3845
|
}
|
|
3803
3846
|
if (data.type === "mcpjam:csp-applied") {
|
|
3804
|
-
|
|
3805
|
-
if (mountId !== void 0 && typeof data.csp === "string" && data.csp.length > 0) {
|
|
3806
|
-
setWidgetAppliedCspStore(toolCallIdRef.current, {
|
|
3807
|
-
mountId,
|
|
3808
|
-
headerString: data.csp,
|
|
3809
|
-
mode: data.mode === "permissive" ? "permissive" : "widget-declared",
|
|
3810
|
-
intent: normalizeCspApplicationIntent(data.intent)
|
|
3811
|
-
});
|
|
3812
|
-
logWidgetDebug("ui-to-host", "debug/csp-applied", {
|
|
3813
|
-
mountId,
|
|
3814
|
-
mode: data.mode,
|
|
3815
|
-
headerLength: data.csp.length
|
|
3816
|
-
});
|
|
3817
|
-
}
|
|
3847
|
+
handleCspApplied(event);
|
|
3818
3848
|
return;
|
|
3819
3849
|
}
|
|
3820
3850
|
if (data.type === "mcpjam:view-mode") {
|
|
@@ -4083,6 +4113,17 @@ function MCPAppsRendererSurface({
|
|
|
4083
4113
|
const hostChromeStyle = showHostChrome ? {
|
|
4084
4114
|
backgroundColor: mergedStyleVariables["--color-background-primary"]
|
|
4085
4115
|
} : void 0;
|
|
4116
|
+
const cspClientContext = {
|
|
4117
|
+
surface: "inline",
|
|
4118
|
+
clientName: hostStyleDefinition.chatUi.label ?? "Selected client",
|
|
4119
|
+
declaredCsp: widgetCsp,
|
|
4120
|
+
capabilities: {
|
|
4121
|
+
cspConnectDomains: earlyEffectiveMcpAppsCapabilities.cspConnectDomains,
|
|
4122
|
+
cspResourceDomains: earlyEffectiveMcpAppsCapabilities.cspResourceDomains,
|
|
4123
|
+
cspFrameDomains: earlyEffectiveMcpAppsCapabilities.cspFrameDomains,
|
|
4124
|
+
cspBaseUriDomains: earlyEffectiveMcpAppsCapabilities.cspBaseUriDomains
|
|
4125
|
+
}
|
|
4126
|
+
};
|
|
4086
4127
|
const iframe = /* @__PURE__ */ jsx(
|
|
4087
4128
|
SandboxedIframe,
|
|
4088
4129
|
{
|
|
@@ -4096,6 +4137,7 @@ function MCPAppsRendererSurface({
|
|
|
4096
4137
|
allowFeatures: effectiveSandbox.allowFeatures,
|
|
4097
4138
|
cspDirectives: effectiveSandbox.cspDirectives,
|
|
4098
4139
|
cspSubtypePolicy: effectiveSandbox.cspSubtypePolicy,
|
|
4140
|
+
clientContext: cspClientContext,
|
|
4099
4141
|
browserStorage: effectiveSandbox.browserStorage,
|
|
4100
4142
|
colorScheme: resolvedTheme,
|
|
4101
4143
|
recordMode,
|
|
@@ -4250,6 +4292,7 @@ function MCPAppsRendererSurface({
|
|
|
4250
4292
|
widgetAllowFeatures: effectiveSandbox.allowFeatures,
|
|
4251
4293
|
widgetCspDirectives: effectiveSandbox.cspDirectives,
|
|
4252
4294
|
widgetCspSubtypePolicy: effectiveSandbox.cspSubtypePolicy,
|
|
4295
|
+
widgetClientContext: cspClientContext,
|
|
4253
4296
|
widgetBrowserStorage: effectiveSandbox.browserStorage,
|
|
4254
4297
|
widgetToolResult: earlyEffectiveMcpAppsCapabilities.toolResult,
|
|
4255
4298
|
hostContextRef,
|
|
@@ -4269,7 +4312,8 @@ function MCPAppsRendererSurface({
|
|
|
4269
4312
|
...log,
|
|
4270
4313
|
protocol: "mcp-apps"
|
|
4271
4314
|
}),
|
|
4272
|
-
onCspViolation: handleCspViolation
|
|
4315
|
+
onCspViolation: handleCspViolation,
|
|
4316
|
+
onCspApplied: handleCspApplied
|
|
4273
4317
|
}
|
|
4274
4318
|
),
|
|
4275
4319
|
checkoutSession != null && Checkout && /* @__PURE__ */ jsx(
|