@blade-hq/agent-react 2612.0.1-beta.1 → 2612.0.1-beta.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/README.md +17 -1
- package/dist/McpAppCard-WFCF2MLR.js +208 -0
- package/dist/McpAppCard-WFCF2MLR.js.map +1 -0
- package/dist/{McpAppFrame-IQK5AOMD.js → McpAppFrame-MROYFPW4.js} +2 -2
- package/dist/chat/runtime/input-services.d.ts +2 -0
- package/dist/{chunk-DNND32V4.js → chunk-CSAENPN2.js} +2 -2
- package/dist/chunk-CSAENPN2.js.map +1 -0
- package/dist/{chunk-LFC3UTIJ.js → chunk-D64PHHWL.js} +77 -69
- package/dist/chunk-D64PHHWL.js.map +1 -0
- package/dist/{chunk-4WFRH7FG.js → chunk-H2RHTYTN.js} +252 -37
- package/dist/{chunk-4WFRH7FG.js.map → chunk-H2RHTYTN.js.map} +1 -1
- package/dist/{chunk-VUUX2BIU.js → chunk-ND476ANG.js} +887 -796
- package/dist/chunk-ND476ANG.js.map +1 -0
- package/dist/{chunk-7DG4JFRS.js → chunk-R3CDECVX.js} +1 -1
- package/dist/chunk-R3CDECVX.js.map +1 -0
- package/dist/{chunk-GRUDJLWG.js → chunk-USBLVHQB.js} +1 -1
- package/dist/chunk-USBLVHQB.js.map +1 -0
- package/dist/components/AgentChat.d.ts +3 -0
- package/dist/components/CaseDemoPlayer.d.ts +10 -0
- package/dist/components/ConnectorPanel.d.ts +3 -2
- package/dist/components/McpAppCard.d.ts +2 -8
- package/dist/components/McpAppFrame.d.ts +3 -0
- package/dist/components/UserMessageText.d.ts +8 -0
- package/dist/components/connector-panel-types.d.ts +1 -0
- package/dist/components/lazy-mcp-app-card.d.ts +3 -1
- package/dist/components/mcp-app-context.d.ts +2 -6
- package/dist/components/mcp-app-types.d.ts +40 -0
- package/dist/embed/entry.d.ts +3 -0
- package/dist/host.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +11 -4
- package/dist/internal.js +10 -6
- package/dist/internal.js.map +1 -1
- package/dist/rich-input/ComposerControls.d.ts +6 -1
- package/dist/rich-input.js +26 -14
- package/dist/rich-input.js.map +1 -1
- package/dist/style.full.css +1 -1
- package/dist/tool-details.js +1 -1
- package/package.json +2 -2
- package/public-api.md +71 -2
- package/dist/McpAppCard-NJEKKEEN.js +0 -171
- package/dist/McpAppCard-NJEKKEEN.js.map +0 -1
- package/dist/chunk-7DG4JFRS.js.map +0 -1
- package/dist/chunk-DNND32V4.js.map +0 -1
- package/dist/chunk-GRUDJLWG.js.map +0 -1
- package/dist/chunk-LFC3UTIJ.js.map +0 -1
- package/dist/chunk-VUUX2BIU.js.map +0 -1
- /package/dist/{McpAppFrame-IQK5AOMD.js.map → McpAppFrame-MROYFPW4.js.map} +0 -0
|
@@ -25706,33 +25706,53 @@ function SF(G, Q) {
|
|
|
25706
25706
|
// src/components/McpAppFrame.tsx
|
|
25707
25707
|
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
25708
25708
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
25709
|
-
|
|
25710
|
-
|
|
25709
|
+
var CSP_WILDCARD_ORIGIN = /^(https?):\/\/\*\.([a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+)(?::([0-9]{1,5}))?$/i;
|
|
25710
|
+
var CSP_FORBIDDEN_CHARS = /[\s;,'"`\\]/;
|
|
25711
|
+
function validateCspSource(value) {
|
|
25712
|
+
if (!value || CSP_FORBIDDEN_CHARS.test(value)) {
|
|
25713
|
+
throw new Error("\u5E94\u7528\u8D44\u6E90\u6765\u6E90\u65E0\u6548");
|
|
25714
|
+
}
|
|
25715
|
+
const wildcard = CSP_WILDCARD_ORIGIN.exec(value);
|
|
25716
|
+
if (wildcard) {
|
|
25717
|
+
const [, scheme, domain2, port] = wildcard;
|
|
25718
|
+
if (port) {
|
|
25719
|
+
const parsedPort = Number(port);
|
|
25720
|
+
if (!Number.isInteger(parsedPort) || parsedPort < 1 || parsedPort > 65535) {
|
|
25721
|
+
throw new Error("\u5E94\u7528\u8D44\u6E90\u6765\u6E90\u65E0\u6548");
|
|
25722
|
+
}
|
|
25723
|
+
return `${scheme.toLowerCase()}://*.${domain2.toLowerCase()}:${parsedPort}`;
|
|
25724
|
+
}
|
|
25725
|
+
return `${scheme.toLowerCase()}://*.${domain2.toLowerCase()}`;
|
|
25726
|
+
}
|
|
25727
|
+
const url2 = new URL(value);
|
|
25728
|
+
if (!["https:", "http:"].includes(url2.protocol) || url2.username || url2.password || url2.origin !== value || url2.hostname.includes("*")) {
|
|
25729
|
+
throw new Error("\u5E94\u7528\u8D44\u6E90\u6765\u6E90\u65E0\u6548");
|
|
25730
|
+
}
|
|
25731
|
+
return url2.origin;
|
|
25732
|
+
}
|
|
25733
|
+
function buildCspPolicy(resourceMeta) {
|
|
25734
|
+
const ui = resourceMeta.ui;
|
|
25711
25735
|
const csp = ui?.csp ?? {};
|
|
25712
25736
|
if (typeof csp !== "object" || Array.isArray(csp)) throw new Error("\u5E94\u7528\u5B89\u5168\u7B56\u7565\u65E0\u6548");
|
|
25713
25737
|
const permissions = ui?.permissions;
|
|
25714
25738
|
if (permissions != null && (typeof permissions !== "object" || Array.isArray(permissions))) {
|
|
25715
25739
|
throw new Error("\u5E94\u7528\u6743\u9650\u58F0\u660E\u65E0\u6548");
|
|
25716
25740
|
}
|
|
25717
|
-
if (permissions && Object.keys(permissions).length) {
|
|
25718
|
-
throw new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u6388\u4E88\u6B64\u5E94\u7528\u8BF7\u6C42\u7684\u8BBE\u5907\u6743\u9650");
|
|
25719
|
-
}
|
|
25720
25741
|
const domains = (key) => {
|
|
25721
25742
|
const values = csp[key] ?? [];
|
|
25722
25743
|
if (!Array.isArray(values)) throw new Error("\u5E94\u7528\u5B89\u5168\u7B56\u7565\u65E0\u6548");
|
|
25723
25744
|
return values.map((value) => {
|
|
25724
25745
|
if (typeof value !== "string") throw new Error("\u5E94\u7528\u5B89\u5168\u7B56\u7565\u65E0\u6548");
|
|
25725
|
-
|
|
25726
|
-
if (!["https:", "http:"].includes(url2.protocol) || url2.username || url2.password || url2.origin !== value) {
|
|
25727
|
-
throw new Error("\u5E94\u7528\u8D44\u6E90\u6765\u6E90\u65E0\u6548");
|
|
25728
|
-
}
|
|
25729
|
-
return url2.origin;
|
|
25746
|
+
return validateCspSource(value);
|
|
25730
25747
|
}).join(" ");
|
|
25731
25748
|
};
|
|
25732
25749
|
const resource = domains("resourceDomains");
|
|
25733
25750
|
const connect = domains("connectDomains");
|
|
25734
25751
|
const frame = domains("frameDomains");
|
|
25735
|
-
|
|
25752
|
+
return `default-src 'none'; script-src 'unsafe-inline' ${resource}; style-src 'unsafe-inline' ${resource}; img-src data: ${resource}; font-src ${resource || "'none'"}; connect-src ${connect || "'none'"}; frame-src ${frame || "'none'"}; base-uri 'none'; form-action 'none'; object-src 'none'`;
|
|
25753
|
+
}
|
|
25754
|
+
function securedHtml(archive) {
|
|
25755
|
+
const policy = buildCspPolicy(archive.resourceMeta);
|
|
25736
25756
|
const doc = new DOMParser().parseFromString(archive.html, "text/html");
|
|
25737
25757
|
const meta3 = doc.createElement("meta");
|
|
25738
25758
|
meta3.httpEquiv = "Content-Security-Policy";
|
|
@@ -25740,19 +25760,113 @@ function securedHtml(archive) {
|
|
|
25740
25760
|
doc.head.prepend(meta3);
|
|
25741
25761
|
return `<!doctype html>${doc.documentElement.outerHTML}`;
|
|
25742
25762
|
}
|
|
25763
|
+
function detectHostTheme(element) {
|
|
25764
|
+
const root = element?.getRootNode();
|
|
25765
|
+
const hostEl = root instanceof ShadowRoot ? root.host : document.documentElement;
|
|
25766
|
+
const candidates = [element, hostEl, document.documentElement, document.body].filter(Boolean);
|
|
25767
|
+
for (const node2 of candidates) {
|
|
25768
|
+
const attr = node2.getAttribute("data-theme")?.toLowerCase();
|
|
25769
|
+
if (attr === "dark" || attr === "light") return attr;
|
|
25770
|
+
if (node2.classList.contains("dark")) return "dark";
|
|
25771
|
+
}
|
|
25772
|
+
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
25773
|
+
try {
|
|
25774
|
+
if (window.matchMedia("(prefers-color-scheme: dark)").matches) return "dark";
|
|
25775
|
+
} catch {
|
|
25776
|
+
}
|
|
25777
|
+
}
|
|
25778
|
+
return "light";
|
|
25779
|
+
}
|
|
25780
|
+
function readHostStyleVariables(element, theme) {
|
|
25781
|
+
const dark = theme === "dark";
|
|
25782
|
+
const defaults = {
|
|
25783
|
+
"--color-background-primary": dark ? "#18181b" : "#ffffff",
|
|
25784
|
+
"--color-background-secondary": dark ? "#27272a" : "#f4f4f5",
|
|
25785
|
+
"--color-text-primary": dark ? "#f4f4f5" : "#18181b",
|
|
25786
|
+
"--color-text-secondary": dark ? "#a1a1aa" : "#52525b",
|
|
25787
|
+
"--color-border-primary": dark ? "#3f3f46" : "#d4d4d8",
|
|
25788
|
+
"--color-accent-primary": dark ? "#60a5fa" : "#2563eb",
|
|
25789
|
+
"--border-radius-md": "6px"
|
|
25790
|
+
};
|
|
25791
|
+
if (typeof window === "undefined" || typeof window.getComputedStyle !== "function") return defaults;
|
|
25792
|
+
try {
|
|
25793
|
+
const computed = window.getComputedStyle(element ?? document.documentElement);
|
|
25794
|
+
const fontSans = computed.fontFamily?.trim();
|
|
25795
|
+
if (fontSans) defaults["--font-sans"] = fontSans;
|
|
25796
|
+
} catch {
|
|
25797
|
+
}
|
|
25798
|
+
return defaults;
|
|
25799
|
+
}
|
|
25800
|
+
function sanitizeToolInfo(toolInfo) {
|
|
25801
|
+
if (!toolInfo?.tool?.name || typeof toolInfo.tool.inputSchema !== "object" || toolInfo.tool.inputSchema === null) {
|
|
25802
|
+
return void 0;
|
|
25803
|
+
}
|
|
25804
|
+
return {
|
|
25805
|
+
...toolInfo.id ? { id: toolInfo.id } : {},
|
|
25806
|
+
tool: {
|
|
25807
|
+
name: toolInfo.tool.name,
|
|
25808
|
+
...toolInfo.tool.title ? { title: toolInfo.tool.title } : {},
|
|
25809
|
+
...toolInfo.tool.description ? { description: toolInfo.tool.description } : {},
|
|
25810
|
+
inputSchema: toolInfo.tool.inputSchema
|
|
25811
|
+
}
|
|
25812
|
+
};
|
|
25813
|
+
}
|
|
25814
|
+
function buildHostContext(element, displayMode, width, toolInfo) {
|
|
25815
|
+
const theme = detectHostTheme(element);
|
|
25816
|
+
const locale = typeof navigator !== "undefined" && navigator.language ? navigator.language : "zh-CN";
|
|
25817
|
+
let timeZone = "UTC";
|
|
25818
|
+
try {
|
|
25819
|
+
timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
|
25820
|
+
} catch {
|
|
25821
|
+
}
|
|
25822
|
+
const safeToolInfo = sanitizeToolInfo(toolInfo);
|
|
25823
|
+
return {
|
|
25824
|
+
theme,
|
|
25825
|
+
styles: { variables: readHostStyleVariables(element, theme) },
|
|
25826
|
+
locale,
|
|
25827
|
+
timeZone,
|
|
25828
|
+
platform: "web",
|
|
25829
|
+
displayMode,
|
|
25830
|
+
availableDisplayModes: ["inline", "fullscreen"],
|
|
25831
|
+
...width && width > 0 ? {
|
|
25832
|
+
containerDimensions: {
|
|
25833
|
+
width: Math.round(width),
|
|
25834
|
+
maxHeight: displayMode === "fullscreen" && typeof window !== "undefined" ? window.innerHeight : 1200
|
|
25835
|
+
}
|
|
25836
|
+
} : {},
|
|
25837
|
+
...safeToolInfo ? { toolInfo: safeToolInfo } : {}
|
|
25838
|
+
};
|
|
25839
|
+
}
|
|
25840
|
+
function buildHostCapabilities(props) {
|
|
25841
|
+
return {
|
|
25842
|
+
openLinks: {},
|
|
25843
|
+
sandbox: { permissions: {} },
|
|
25844
|
+
...props.callTool ? { serverTools: {} } : {},
|
|
25845
|
+
...props.sendMessage ? { message: { text: {} } } : {},
|
|
25846
|
+
...props.updateModelContext ? { updateModelContext: { text: {}, structuredContent: {} } } : {}
|
|
25847
|
+
};
|
|
25848
|
+
}
|
|
25849
|
+
function prefersBorder(resourceMeta) {
|
|
25850
|
+
const ui = resourceMeta.ui;
|
|
25851
|
+
return ui?.prefersBorder !== false;
|
|
25852
|
+
}
|
|
25743
25853
|
function McpAppFrame(props) {
|
|
25744
|
-
const { html: sourceHtml, resourceMeta, title = "\u5DE5\u5177\u754C\u9762" } = props;
|
|
25854
|
+
const { html: sourceHtml, resourceMeta, title = "\u5DE5\u5177\u754C\u9762", toolInfo } = props;
|
|
25745
25855
|
const callbacks = useRef(props);
|
|
25746
25856
|
callbacks.current = props;
|
|
25747
25857
|
const frame = useRef(null);
|
|
25748
25858
|
const panel = useRef(null);
|
|
25749
25859
|
const bridgeRef = useRef(null);
|
|
25860
|
+
const closingRef = useRef(Promise.resolve());
|
|
25750
25861
|
const [html, setHtml] = useState();
|
|
25751
25862
|
const [failure2, setError] = useState(null);
|
|
25752
25863
|
const error62 = props.error ?? failure2;
|
|
25753
25864
|
const [ready, setReady] = useState(false);
|
|
25754
25865
|
const [expanded, setExpanded] = useState(false);
|
|
25755
25866
|
const [height, setHeight] = useState(360);
|
|
25867
|
+
const expandedRef = useRef(expanded);
|
|
25868
|
+
expandedRef.current = expanded;
|
|
25869
|
+
const showBorder = prefersBorder(resourceMeta);
|
|
25756
25870
|
useLayoutEffect(() => {
|
|
25757
25871
|
const dialog = panel.current;
|
|
25758
25872
|
if (!dialog) return;
|
|
@@ -25771,19 +25885,38 @@ function McpAppFrame(props) {
|
|
|
25771
25885
|
if (sourceHtml === void 0) return;
|
|
25772
25886
|
let disposed = false;
|
|
25773
25887
|
let bridge;
|
|
25888
|
+
let lastContextJson = "";
|
|
25889
|
+
let lastWidth = 0;
|
|
25774
25890
|
const timer = window.setTimeout(() => {
|
|
25775
25891
|
if (!disposed && !bridge?.getAppCapabilities()) {
|
|
25776
25892
|
setError("\u5E94\u7528\u8FDE\u63A5\u8D85\u65F6");
|
|
25777
25893
|
callbacks.current.onLoadError?.();
|
|
25778
25894
|
}
|
|
25779
25895
|
}, 2e4);
|
|
25896
|
+
const pushHostContext = (mode, width) => {
|
|
25897
|
+
if (disposed || !bridge) return;
|
|
25898
|
+
const next = buildHostContext(panel.current, mode, width ?? lastWidth, callbacks.current.toolInfo);
|
|
25899
|
+
const serialized = JSON.stringify(next);
|
|
25900
|
+
if (serialized === lastContextJson) return;
|
|
25901
|
+
lastContextJson = serialized;
|
|
25902
|
+
bridge.setHostContext(next);
|
|
25903
|
+
};
|
|
25780
25904
|
const start = async () => {
|
|
25905
|
+
await closingRef.current;
|
|
25906
|
+
if (disposed) return;
|
|
25781
25907
|
if (!frame.current?.contentWindow) throw new Error("\u5E94\u7528\u4F1A\u8BDD\u4E0D\u53EF\u7528");
|
|
25782
25908
|
const secured = securedHtml({ html: sourceHtml, resourceMeta });
|
|
25783
|
-
|
|
25784
|
-
|
|
25785
|
-
|
|
25786
|
-
|
|
25909
|
+
const measuredWidth = panel.current?.getBoundingClientRect?.().width ?? 0;
|
|
25910
|
+
lastWidth = measuredWidth > 0 ? Math.round(measuredWidth) : 0;
|
|
25911
|
+
const initialContext = buildHostContext(panel.current, "inline", lastWidth || void 0, toolInfo);
|
|
25912
|
+
lastContextJson = JSON.stringify(initialContext);
|
|
25913
|
+
const capabilities = buildHostCapabilities(callbacks.current);
|
|
25914
|
+
bridge = new MF(
|
|
25915
|
+
null,
|
|
25916
|
+
{ name: "Blade Agent", version: "1.0.0" },
|
|
25917
|
+
capabilities,
|
|
25918
|
+
{ hostContext: initialContext }
|
|
25919
|
+
);
|
|
25787
25920
|
bridgeRef.current = bridge;
|
|
25788
25921
|
bridge.oninitialized = () => {
|
|
25789
25922
|
if (disposed || !bridge) return;
|
|
@@ -25808,10 +25941,11 @@ function McpAppFrame(props) {
|
|
|
25808
25941
|
return callbacks.current.updateModelContext(params, extra);
|
|
25809
25942
|
};
|
|
25810
25943
|
bridge.onrequestdisplaymode = async (params, extra) => {
|
|
25944
|
+
if (disposed) throw new Error("\u5E94\u7528\u5DF2\u5173\u95ED");
|
|
25811
25945
|
if (callbacks.current.requestDisplayMode) return callbacks.current.requestDisplayMode(params, extra);
|
|
25812
25946
|
const next = params.mode === "fullscreen" ? "fullscreen" : "inline";
|
|
25813
25947
|
setExpanded(next === "fullscreen");
|
|
25814
|
-
|
|
25948
|
+
pushHostContext(next);
|
|
25815
25949
|
return { mode: next };
|
|
25816
25950
|
};
|
|
25817
25951
|
bridge.onsizechange = (params) => {
|
|
@@ -25821,6 +25955,7 @@ function McpAppFrame(props) {
|
|
|
25821
25955
|
if (params.height && Number.isFinite(params.height)) setHeight(Math.max(120, Math.min(1200, params.height)));
|
|
25822
25956
|
};
|
|
25823
25957
|
bridge.onopenlink = async (params, extra) => {
|
|
25958
|
+
if (disposed) throw new Error("\u5E94\u7528\u5DF2\u5173\u95ED");
|
|
25824
25959
|
if (callbacks.current.openLink) return callbacks.current.openLink(params, extra);
|
|
25825
25960
|
const target = new URL(params.url);
|
|
25826
25961
|
if (!["https:", "http:"].includes(target.protocol) || target.username || target.password) throw new Error("\u94FE\u63A5\u65E0\u6548");
|
|
@@ -25828,36 +25963,89 @@ function McpAppFrame(props) {
|
|
|
25828
25963
|
return {};
|
|
25829
25964
|
};
|
|
25830
25965
|
await bridge.connect(new c(frame.current.contentWindow, frame.current.contentWindow));
|
|
25831
|
-
if (
|
|
25966
|
+
if (disposed) {
|
|
25967
|
+
void bridge.close().catch(() => void 0);
|
|
25968
|
+
return;
|
|
25969
|
+
}
|
|
25970
|
+
setHtml(secured);
|
|
25832
25971
|
};
|
|
25833
|
-
|
|
25972
|
+
let mutationObserver;
|
|
25973
|
+
if (typeof MutationObserver !== "undefined" && typeof document !== "undefined") {
|
|
25974
|
+
mutationObserver = new MutationObserver(() => {
|
|
25975
|
+
pushHostContext(expandedRef.current ? "fullscreen" : "inline");
|
|
25976
|
+
});
|
|
25977
|
+
mutationObserver.observe(document.documentElement, { attributes: true, attributeFilter: ["class", "data-theme"] });
|
|
25978
|
+
}
|
|
25979
|
+
let resizeObserver;
|
|
25980
|
+
let resizeFrame;
|
|
25981
|
+
if (typeof ResizeObserver !== "undefined" && panel.current) {
|
|
25982
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
25983
|
+
const nextWidth = Math.round(entries[0]?.contentRect?.width ?? 0);
|
|
25984
|
+
if (nextWidth > 0 && nextWidth !== lastWidth) {
|
|
25985
|
+
lastWidth = nextWidth;
|
|
25986
|
+
if (resizeFrame !== void 0) cancelAnimationFrame(resizeFrame);
|
|
25987
|
+
resizeFrame = requestAnimationFrame(() => {
|
|
25988
|
+
resizeFrame = void 0;
|
|
25989
|
+
pushHostContext(expandedRef.current ? "fullscreen" : "inline", nextWidth);
|
|
25990
|
+
});
|
|
25991
|
+
}
|
|
25992
|
+
});
|
|
25993
|
+
resizeObserver.observe(panel.current);
|
|
25994
|
+
}
|
|
25995
|
+
let mediaQuery;
|
|
25996
|
+
const onColorSchemeChange = () => pushHostContext(expandedRef.current ? "fullscreen" : "inline");
|
|
25997
|
+
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
25998
|
+
try {
|
|
25999
|
+
mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
|
|
26000
|
+
mediaQuery.addEventListener?.("change", onColorSchemeChange);
|
|
26001
|
+
} catch {
|
|
26002
|
+
}
|
|
26003
|
+
}
|
|
26004
|
+
void start().catch((err) => {
|
|
25834
26005
|
window.clearTimeout(timer);
|
|
25835
26006
|
if (!disposed) {
|
|
25836
|
-
setError(
|
|
26007
|
+
setError(err instanceof Error ? err.message : "\u5E94\u7528\u52A0\u8F7D\u5931\u8D25");
|
|
25837
26008
|
callbacks.current.onLoadError?.();
|
|
25838
26009
|
}
|
|
25839
26010
|
});
|
|
25840
26011
|
return () => {
|
|
25841
26012
|
disposed = true;
|
|
25842
26013
|
window.clearTimeout(timer);
|
|
26014
|
+
mutationObserver?.disconnect();
|
|
26015
|
+
resizeObserver?.disconnect();
|
|
26016
|
+
if (resizeFrame !== void 0) cancelAnimationFrame(resizeFrame);
|
|
26017
|
+
mediaQuery?.removeEventListener?.("change", onColorSchemeChange);
|
|
25843
26018
|
bridgeRef.current = null;
|
|
25844
|
-
|
|
26019
|
+
const closing = bridge;
|
|
26020
|
+
if (closing) {
|
|
26021
|
+
const previous = closingRef.current;
|
|
26022
|
+
const done = previous.catch(() => void 0).then(() => typeof closing.teardownResource === "function" ? Promise.race([
|
|
26023
|
+
closing.teardownResource({}).catch(() => void 0),
|
|
26024
|
+
new Promise((resolve) => window.setTimeout(resolve, 300))
|
|
26025
|
+
]) : Promise.resolve()).finally(() => closing.close().catch(() => void 0));
|
|
26026
|
+
closingRef.current = done;
|
|
26027
|
+
}
|
|
25845
26028
|
};
|
|
25846
|
-
}, [sourceHtml, resourceMeta]);
|
|
26029
|
+
}, [sourceHtml, resourceMeta, toolInfo]);
|
|
25847
26030
|
useEffect(() => {
|
|
25848
26031
|
let disposed = false;
|
|
25849
|
-
if (ready && props.toolInput) void bridgeRef.current?.sendToolInput(props.toolInput).catch((
|
|
25850
|
-
if (!disposed) setError(
|
|
26032
|
+
if (ready && props.toolInput) void bridgeRef.current?.sendToolInput(props.toolInput).catch((err) => {
|
|
26033
|
+
if (!disposed) setError(err instanceof Error ? err.message : "\u5E94\u7528\u7ED3\u679C\u5237\u65B0\u5931\u8D25");
|
|
25851
26034
|
});
|
|
25852
26035
|
return () => {
|
|
25853
26036
|
disposed = true;
|
|
25854
26037
|
};
|
|
25855
26038
|
}, [props.toolInput, ready]);
|
|
25856
26039
|
const nativeDialog = typeof HTMLDialogElement !== "undefined" && typeof HTMLDialogElement.prototype.showModal === "function";
|
|
25857
|
-
const
|
|
25858
|
-
setExpanded(
|
|
25859
|
-
|
|
25860
|
-
|
|
26040
|
+
const updateDisplayMode = (nextExpanded) => {
|
|
26041
|
+
setExpanded(nextExpanded);
|
|
26042
|
+
const mode = nextExpanded ? "fullscreen" : "inline";
|
|
26043
|
+
bridgeRef.current?.setHostContext(
|
|
26044
|
+
buildHostContext(panel.current, mode, void 0, toolInfo)
|
|
26045
|
+
);
|
|
26046
|
+
};
|
|
26047
|
+
const toggle = () => updateDisplayMode(!expanded);
|
|
26048
|
+
const borderlessInline = !expanded && !showBorder;
|
|
25861
26049
|
return /* @__PURE__ */ jsxs(
|
|
25862
26050
|
"dialog",
|
|
25863
26051
|
{
|
|
@@ -25867,13 +26055,11 @@ function McpAppFrame(props) {
|
|
|
25867
26055
|
onKeyDown: (event) => {
|
|
25868
26056
|
if (!nativeDialog && expanded && event.key === "Escape") {
|
|
25869
26057
|
event.preventDefault();
|
|
25870
|
-
|
|
25871
|
-
bridgeRef.current?.setHostContext({ displayMode: "inline" });
|
|
26058
|
+
updateDisplayMode(false);
|
|
25872
26059
|
}
|
|
25873
26060
|
},
|
|
25874
26061
|
onCancel: () => {
|
|
25875
|
-
|
|
25876
|
-
bridgeRef.current?.setHostContext({ displayMode: "inline" });
|
|
26062
|
+
updateDisplayMode(false);
|
|
25877
26063
|
},
|
|
25878
26064
|
className: "blade-chat-mcp-app blade-mcp-app",
|
|
25879
26065
|
part: "mcp-app",
|
|
@@ -25891,15 +26077,44 @@ function McpAppFrame(props) {
|
|
|
25891
26077
|
maxWidth: "none",
|
|
25892
26078
|
maxHeight: "none",
|
|
25893
26079
|
zIndex: 80,
|
|
25894
|
-
background: "
|
|
26080
|
+
background: "var(--blade-surface, var(--background, #ffffff))",
|
|
26081
|
+
color: "var(--blade-text, var(--foreground, #27272a))",
|
|
25895
26082
|
boxShadow: "-4px 0 20px #0002",
|
|
25896
26083
|
display: "flex",
|
|
25897
26084
|
flexDirection: "column"
|
|
25898
|
-
} : {
|
|
26085
|
+
} : {
|
|
26086
|
+
position: "relative",
|
|
26087
|
+
margin: 0,
|
|
26088
|
+
padding: 0,
|
|
26089
|
+
width: "100%",
|
|
26090
|
+
maxWidth: "none",
|
|
26091
|
+
maxHeight: "none",
|
|
26092
|
+
border: borderlessInline ? 0 : "1px solid var(--blade-border, var(--border, #d4d4d8))",
|
|
26093
|
+
borderRadius: borderlessInline ? 0 : 6,
|
|
26094
|
+
overflow: "hidden",
|
|
26095
|
+
background: borderlessInline ? "transparent" : "var(--blade-surface, var(--background, #ffffff))",
|
|
26096
|
+
color: "var(--blade-text, var(--foreground, #27272a))",
|
|
26097
|
+
display: nativeDialog ? void 0 : "block"
|
|
26098
|
+
},
|
|
25899
26099
|
children: [
|
|
25900
|
-
/* @__PURE__ */
|
|
26100
|
+
borderlessInline ? /* @__PURE__ */ jsx("button", { type: "button", onClick: toggle, title: "\u5C55\u5F00", "aria-label": "\u5C55\u5F00", style: {
|
|
26101
|
+
position: "absolute",
|
|
26102
|
+
top: 6,
|
|
26103
|
+
right: 6,
|
|
26104
|
+
zIndex: 2,
|
|
26105
|
+
width: 28,
|
|
26106
|
+
height: 28,
|
|
26107
|
+
display: "grid",
|
|
26108
|
+
placeItems: "center",
|
|
26109
|
+
borderRadius: 6,
|
|
26110
|
+
border: "1px solid var(--blade-border, #d4d4d8)",
|
|
26111
|
+
background: "var(--blade-surface, #ffffff)",
|
|
26112
|
+
color: "inherit",
|
|
26113
|
+
opacity: 0.85,
|
|
26114
|
+
padding: 0
|
|
26115
|
+
}, children: /* @__PURE__ */ jsx(Maximize2, { size: 14 }) }) : /* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between", padding: "8px 12px", color: "inherit" }, children: [
|
|
25901
26116
|
/* @__PURE__ */ jsx("span", { children: title }),
|
|
25902
|
-
/* @__PURE__ */ jsx("button", { type: "button", onClick: toggle, title: expanded ? "\u6536\u8D77" : "\u5C55\u5F00", "aria-label": expanded ? "\u6536\u8D77" : "\u5C55\u5F00", style: { width: 32, height: 32, display: "grid", placeItems: "center", background: "transparent", border: 0, padding: 0 }, children: expanded ? /* @__PURE__ */ jsx(Minimize2, { size: 16 }) : /* @__PURE__ */ jsx(Maximize2, { size: 16 }) })
|
|
26117
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: toggle, title: expanded ? "\u6536\u8D77" : "\u5C55\u5F00", "aria-label": expanded ? "\u6536\u8D77" : "\u5C55\u5F00", style: { width: 32, height: 32, display: "grid", placeItems: "center", background: "transparent", border: 0, padding: 0, color: "inherit" }, children: expanded ? /* @__PURE__ */ jsx(Minimize2, { size: 16 }) : /* @__PURE__ */ jsx(Maximize2, { size: 16 }) })
|
|
25903
26118
|
] }),
|
|
25904
26119
|
error62 ? /* @__PURE__ */ jsx("p", { role: "alert", style: { padding: 12, color: "#b91c1c" }, children: error62 }) : !ready ? /* @__PURE__ */ jsx("output", { style: { padding: 12 }, children: "\u6B63\u5728\u52A0\u8F7D" }) : null,
|
|
25905
26120
|
/* @__PURE__ */ jsx(
|
|
@@ -25930,4 +26145,4 @@ export {
|
|
|
25930
26145
|
* MIT Licensed
|
|
25931
26146
|
*)
|
|
25932
26147
|
*/
|
|
25933
|
-
//# sourceMappingURL=chunk-
|
|
26148
|
+
//# sourceMappingURL=chunk-H2RHTYTN.js.map
|