@mcpjam/widget-react 0.1.1 → 0.1.3
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 +14 -1
- package/dist/index.js +55 -7
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -897,6 +897,19 @@ interface MCPAppsRendererProps {
|
|
|
897
897
|
* collapse the inline view).
|
|
898
898
|
*/
|
|
899
899
|
onRequestTeardown?: (toolCallId: string, displayWidgetId?: string) => void;
|
|
900
|
+
/**
|
|
901
|
+
* Ask the host to confirm a widget-initiated `ui/download-file` before the
|
|
902
|
+
* download runs (SEP-1865: host SHOULD confirm). Resolve `true` to proceed,
|
|
903
|
+
* `false` to deny (the widget then receives a JSON-RPC "Download denied by
|
|
904
|
+
* user" error). When omitted, downloads proceed unprompted — so embedders of
|
|
905
|
+
* the published package keep the prior behavior.
|
|
906
|
+
*/
|
|
907
|
+
onConfirmDownload?: (info: {
|
|
908
|
+
kind: "resource" | "resource_link";
|
|
909
|
+
filename?: string;
|
|
910
|
+
mimeType?: string;
|
|
911
|
+
uri?: string;
|
|
912
|
+
}) => Promise<boolean>;
|
|
900
913
|
/** Whether the server is offline (for using cached content) */
|
|
901
914
|
isOffline?: boolean;
|
|
902
915
|
/** URL to cached widget HTML for offline rendering */
|
|
@@ -960,7 +973,7 @@ interface MCPAppsRendererProps {
|
|
|
960
973
|
persistentSurfaceInitialToolCallId?: string;
|
|
961
974
|
}
|
|
962
975
|
declare function MCPAppsRenderer(props: MCPAppsRendererProps): react_jsx_runtime.JSX.Element;
|
|
963
|
-
declare function MCPAppsRendererSurface({ chatSessionId, serverId, serverName, toolCallId, toolName, toolState, toolInput, toolOutput, toolResponseMetadata, toolErrorText, resourceUri, toolMetadata, toolsMetadata, onSendFollowUp, onCallTool, onAppToolInvocationChange, onWidgetStateChange, recordMode, onRecorderStep, onRecorderReady, onReplayControllerReady, pipWidgetId, fullscreenWidgetId, onRequestPip, onExitPip, displayMode: displayModeProp, onDisplayModeChange, onRequestFullscreen, onExitFullscreen, onModelContextUpdate, onAppSupportedDisplayModesChange, onRequestTeardown, 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;
|
|
976
|
+
declare function MCPAppsRendererSurface({ chatSessionId, serverId, serverName, toolCallId, toolName, toolState, toolInput, toolOutput, toolResponseMetadata, toolErrorText, resourceUri, toolMetadata, toolsMetadata, onSendFollowUp, onCallTool, onAppToolInvocationChange, onWidgetStateChange, recordMode, onRecorderStep, onRecorderReady, onReplayControllerReady, pipWidgetId, fullscreenWidgetId, onRequestPip, onExitPip, displayMode: displayModeProp, onDisplayModeChange, onRequestFullscreen, onExitFullscreen, onModelContextUpdate, onAppSupportedDisplayModesChange, onRequestTeardown, onConfirmDownload, isOffline, cachedWidgetHtmlUrl, liveFetchPreferred, widgetCsp: initialWidgetCsp, widgetPermissions: initialWidgetPermissions, widgetPermissive: initialWidgetPermissive, prefersBorder: initialPrefersBorder, injectedOpenAiCompat: initialInjectedOpenAiCompat, injectedOpenAiCompatCapabilities: initialInjectedOpenAiCompatCapabilities, initialWidgetState, minimalMode, persistentSurfaceId, persistentSurfaceInitialToolCallId, }: MCPAppsRendererProps): react_jsx_runtime.JSX.Element | null;
|
|
964
977
|
|
|
965
978
|
declare function WidgetSurfaceHostProvider({ children, }: {
|
|
966
979
|
children: ReactNode;
|
package/dist/index.js
CHANGED
|
@@ -769,7 +769,9 @@ function useToolInputStreaming({
|
|
|
769
769
|
const outputKey = `${toolCallId}:${serialized}`;
|
|
770
770
|
if (lastToolOutputRef.current === outputKey) return;
|
|
771
771
|
lastToolOutputRef.current = outputKey;
|
|
772
|
-
bridge.sendToolResult(
|
|
772
|
+
bridge.sendToolResult(
|
|
773
|
+
toolOutput
|
|
774
|
+
);
|
|
773
775
|
}, [isReady, toolCallId, toolOutput, toolState, bridgeRef, reinitCount]);
|
|
774
776
|
useEffect(() => {
|
|
775
777
|
if (!isReady || toolState !== "output-error") return;
|
|
@@ -1158,7 +1160,9 @@ function McpAppsModal({
|
|
|
1158
1160
|
const resolvedToolInput = toolInputRef.current ?? {};
|
|
1159
1161
|
bridge.sendToolInput({ arguments: resolvedToolInput });
|
|
1160
1162
|
if (toolOutputRef.current) {
|
|
1161
|
-
bridge.sendToolResult(
|
|
1163
|
+
bridge.sendToolResult(
|
|
1164
|
+
toolOutputRef.current
|
|
1165
|
+
);
|
|
1162
1166
|
}
|
|
1163
1167
|
const appCaps = bridge.getAppCapabilities();
|
|
1164
1168
|
if (appCaps?.tools) {
|
|
@@ -1534,6 +1538,14 @@ function toSafeOpenInAppUrl(value) {
|
|
|
1534
1538
|
return null;
|
|
1535
1539
|
}
|
|
1536
1540
|
}
|
|
1541
|
+
function toSafeDownloadLinkUrl(uri) {
|
|
1542
|
+
try {
|
|
1543
|
+
const parsed = new URL(uri, window.location.href);
|
|
1544
|
+
return SAFE_OPEN_IN_APP_PROTOCOLS.has(parsed.protocol) ? parsed.href : null;
|
|
1545
|
+
} catch {
|
|
1546
|
+
return null;
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1537
1549
|
function readExplicitBaseHref(html) {
|
|
1538
1550
|
if (!html) return null;
|
|
1539
1551
|
if (typeof DOMParser !== "undefined") {
|
|
@@ -1805,6 +1817,7 @@ function MCPAppsRendererSurface({
|
|
|
1805
1817
|
onModelContextUpdate,
|
|
1806
1818
|
onAppSupportedDisplayModesChange,
|
|
1807
1819
|
onRequestTeardown,
|
|
1820
|
+
onConfirmDownload,
|
|
1808
1821
|
isOffline,
|
|
1809
1822
|
cachedWidgetHtmlUrl,
|
|
1810
1823
|
liveFetchPreferred,
|
|
@@ -2177,6 +2190,7 @@ function MCPAppsRendererSurface({
|
|
|
2177
2190
|
const onRequestPipRef = useRef(onRequestPip);
|
|
2178
2191
|
const onExitPipRef = useRef(onExitPip);
|
|
2179
2192
|
const onRequestTeardownRef = useRef(onRequestTeardown);
|
|
2193
|
+
const onConfirmDownloadRef = useRef(onConfirmDownload);
|
|
2180
2194
|
const setDisplayModeRef = useRef(setDisplayMode);
|
|
2181
2195
|
const isPlaygroundActiveRef = useRef(isPlaygroundActive);
|
|
2182
2196
|
const playgroundDeviceTypeRef = useRef(playgroundDeviceType);
|
|
@@ -3063,6 +3077,7 @@ function MCPAppsRendererSurface({
|
|
|
3063
3077
|
onModelContextUpdateRef.current = onModelContextUpdate;
|
|
3064
3078
|
onAppSupportedDisplayModesChangeRef.current = onAppSupportedDisplayModesChange;
|
|
3065
3079
|
onRequestTeardownRef.current = onRequestTeardown;
|
|
3080
|
+
onConfirmDownloadRef.current = onConfirmDownload;
|
|
3066
3081
|
}, [
|
|
3067
3082
|
onSendFollowUp,
|
|
3068
3083
|
onCallTool,
|
|
@@ -3081,7 +3096,8 @@ function MCPAppsRendererSurface({
|
|
|
3081
3096
|
toolsMetadata,
|
|
3082
3097
|
onModelContextUpdate,
|
|
3083
3098
|
onAppSupportedDisplayModesChange,
|
|
3084
|
-
onRequestTeardown
|
|
3099
|
+
onRequestTeardown,
|
|
3100
|
+
onConfirmDownload
|
|
3085
3101
|
]);
|
|
3086
3102
|
const registerBridgeHandlers = useCallback(
|
|
3087
3103
|
(bridge) => {
|
|
@@ -3253,6 +3269,38 @@ function MCPAppsRendererSurface({
|
|
|
3253
3269
|
});
|
|
3254
3270
|
},
|
|
3255
3271
|
onDownloadFile: async ({ contents }) => {
|
|
3272
|
+
const confirmDownload = onConfirmDownloadRef.current;
|
|
3273
|
+
if (confirmDownload) {
|
|
3274
|
+
for (const item of contents) {
|
|
3275
|
+
let info;
|
|
3276
|
+
if (item.type === "resource" && item.resource) {
|
|
3277
|
+
const res = item.resource;
|
|
3278
|
+
info = {
|
|
3279
|
+
kind: "resource",
|
|
3280
|
+
filename: res.uri.split("/").pop() || void 0,
|
|
3281
|
+
mimeType: res.mimeType,
|
|
3282
|
+
uri: res.uri
|
|
3283
|
+
};
|
|
3284
|
+
} else if (item.type === "resource_link") {
|
|
3285
|
+
const link = item;
|
|
3286
|
+
if (toSafeDownloadLinkUrl(link.uri) === null) {
|
|
3287
|
+
return { isError: true };
|
|
3288
|
+
}
|
|
3289
|
+
info = {
|
|
3290
|
+
kind: "resource_link",
|
|
3291
|
+
filename: link.uri.split("/").pop() || void 0,
|
|
3292
|
+
mimeType: link.mimeType,
|
|
3293
|
+
uri: link.uri
|
|
3294
|
+
};
|
|
3295
|
+
} else {
|
|
3296
|
+
continue;
|
|
3297
|
+
}
|
|
3298
|
+
const approved = await confirmDownload(info);
|
|
3299
|
+
if (!approved) {
|
|
3300
|
+
return { isError: true };
|
|
3301
|
+
}
|
|
3302
|
+
}
|
|
3303
|
+
}
|
|
3256
3304
|
try {
|
|
3257
3305
|
for (const item of contents) {
|
|
3258
3306
|
if (item.type === "resource" && item.resource) {
|
|
@@ -3283,13 +3331,13 @@ function MCPAppsRendererSurface({
|
|
|
3283
3331
|
}
|
|
3284
3332
|
} else if (item.type === "resource_link") {
|
|
3285
3333
|
const link = item;
|
|
3286
|
-
const
|
|
3287
|
-
if (
|
|
3334
|
+
const safeHref = toSafeDownloadLinkUrl(link.uri);
|
|
3335
|
+
if (safeHref === null) {
|
|
3288
3336
|
throw new Error(
|
|
3289
|
-
`Unsupported download URI
|
|
3337
|
+
`Unsupported download URI: ${link.uri}`
|
|
3290
3338
|
);
|
|
3291
3339
|
}
|
|
3292
|
-
window.open(
|
|
3340
|
+
window.open(safeHref, "_blank", "noopener,noreferrer");
|
|
3293
3341
|
}
|
|
3294
3342
|
}
|
|
3295
3343
|
return {};
|