@copilotkit/react-core 1.71.1 → 1.72.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/{copilotkit-DCIXZawe.d.cts → copilotkit-DoHSqB_u.d.cts} +10 -82
- package/dist/copilotkit-DoHSqB_u.d.cts.map +1 -0
- package/dist/{copilotkit-ChjzWqn6.d.mts → copilotkit-DsMFLrpY.d.mts} +10 -82
- package/dist/copilotkit-DsMFLrpY.d.mts.map +1 -0
- package/dist/{copilotkit-BkVEkUS0.cjs → copilotkit-gopQXrTQ.cjs} +74 -390
- package/dist/copilotkit-gopQXrTQ.cjs.map +1 -0
- package/dist/{copilotkit-D5BTo0YG.mjs → copilotkit-qK-Q3rmE.mjs} +72 -370
- package/dist/copilotkit-qK-Q3rmE.mjs.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.umd.js +65 -371
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +20 -4
- package/dist/v2/index.d.cts +1 -1
- package/dist/v2/index.d.mts +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +94 -378
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +8 -10
- package/dist/copilotkit-BkVEkUS0.cjs.map +0 -1
- package/dist/copilotkit-ChjzWqn6.d.mts.map +0 -1
- package/dist/copilotkit-D5BTo0YG.mjs.map +0 -1
- package/dist/copilotkit-DCIXZawe.d.cts.map +0 -1
|
@@ -14,6 +14,7 @@ import * as TooltipPrimitive from "@radix-ui/react-tooltip";
|
|
|
14
14
|
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
|
|
15
15
|
import { Streamdown } from "streamdown";
|
|
16
16
|
import { z } from "zod";
|
|
17
|
+
import { MCPAppsActivityContentSchema, MCPAppsActivityType, ɵrunMcpFollowUp } from "@copilotkit/mcp-apps-renderer/activity";
|
|
17
18
|
import { A2UIProvider, A2UIRenderer, A2UI_SCHEMA_CONTEXT_DESCRIPTION, Catalog, DEFAULT_SURFACE_ID, ROOT_COMPONENT_ID, buildCatalogContextValue, extractCatalogComponentSchemas, filterCatalog, initializeDefaultCatalog, injectStyles, useA2UIActions, useA2UIError, viewerTheme } from "@copilotkit/a2ui-renderer";
|
|
18
19
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
19
20
|
import { createPortal, flushSync } from "react-dom";
|
|
@@ -1826,197 +1827,17 @@ function InlineFeatureWarning({ featureName }) {
|
|
|
1826
1827
|
//#endregion
|
|
1827
1828
|
//#region src/v2/components/MCPAppsActivityRenderer.tsx
|
|
1828
1829
|
/**
|
|
1829
|
-
* Run an MCP app `ui/message` follow-up, scoped to the thread it was enqueued
|
|
1830
|
-
* for (issue #5819).
|
|
1831
|
-
*
|
|
1832
|
-
* The MCP request queue delays follow-up work until the agent is idle. There is
|
|
1833
|
-
* a single shared registry agent per id, and switching threads overwrites its
|
|
1834
|
-
* `threadId`/`messages` in place. So if the host switches threads while a
|
|
1835
|
-
* follow-up is queued, running it now would execute against — and stream into —
|
|
1836
|
-
* the now-foreground thread.
|
|
1837
|
-
*
|
|
1838
|
-
* - **Same thread** (the common case): run on the shared agent, unchanged.
|
|
1839
|
-
* - **Thread changed**: the shared agent has moved on, so the follow-up can no
|
|
1840
|
-
* longer run in its originating thread's context. Drop it rather than leak it
|
|
1841
|
-
* into the current thread. (The MCP app already received its `ui/message` ack
|
|
1842
|
-
* at enqueue time; only the optional agent turn is skipped.)
|
|
1843
|
-
*
|
|
1844
|
-
* @internal exported for testing.
|
|
1845
|
-
*/
|
|
1846
|
-
async function ɵrunMcpFollowUp({ host, agent, capturedThreadId }) {
|
|
1847
|
-
const currentThreadId = agent.threadId || "default";
|
|
1848
|
-
const originThreadId = capturedThreadId || "default";
|
|
1849
|
-
if (currentThreadId === originThreadId) return host.runAgent({ agent });
|
|
1850
|
-
console.warn(`[MCPAppsRenderer] ui/message follow-up dropped: the thread changed (${originThreadId} → ${currentThreadId}) between enqueue and execution, so running it would leak into the now-foreground thread.`);
|
|
1851
|
-
return {
|
|
1852
|
-
result: void 0,
|
|
1853
|
-
newMessages: []
|
|
1854
|
-
};
|
|
1855
|
-
}
|
|
1856
|
-
function buildSandboxHTML(extraCspDomains) {
|
|
1857
|
-
const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
|
|
1858
|
-
const baseFrameSrc = "* blob: data: http://localhost:* https://localhost:*";
|
|
1859
|
-
const extra = extraCspDomains?.length ? " " + extraCspDomains.join(" ") : "";
|
|
1860
|
-
return `<!doctype html>
|
|
1861
|
-
<html>
|
|
1862
|
-
<head>
|
|
1863
|
-
<meta charset="utf-8" />
|
|
1864
|
-
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src * data: blob: 'unsafe-inline'; media-src * blob: data:; font-src * blob: data:; script-src ${baseScriptSrc + extra}; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src ${baseFrameSrc + extra}; base-uri 'self';" />
|
|
1865
|
-
<style>html,body{margin:0;padding:0;height:100%;width:100%;overflow:hidden}*{box-sizing:border-box}iframe{background-color:transparent;border:none;padding:0;overflow:hidden;width:100%;height:100%}</style>
|
|
1866
|
-
</head>
|
|
1867
|
-
<body>
|
|
1868
|
-
<script>
|
|
1869
|
-
if(window.self===window.top){throw new Error("This file must be used in an iframe.")}
|
|
1870
|
-
const inner=document.createElement("iframe");
|
|
1871
|
-
inner.style="width:100%;height:100%;border:none;";
|
|
1872
|
-
inner.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms");
|
|
1873
|
-
document.body.appendChild(inner);
|
|
1874
|
-
window.addEventListener("message",async(event)=>{
|
|
1875
|
-
if(event.source===window.parent){
|
|
1876
|
-
if(event.data&&event.data.method==="ui/notifications/sandbox-resource-ready"){
|
|
1877
|
-
const{html,sandbox}=event.data.params;
|
|
1878
|
-
if(typeof sandbox==="string")inner.setAttribute("sandbox",sandbox);
|
|
1879
|
-
if(typeof html==="string")inner.srcdoc=html;
|
|
1880
|
-
}else if(inner&&inner.contentWindow){
|
|
1881
|
-
inner.contentWindow.postMessage(event.data,"*");
|
|
1882
|
-
}
|
|
1883
|
-
}else if(event.source===inner.contentWindow){
|
|
1884
|
-
window.parent.postMessage(event.data,"*");
|
|
1885
|
-
}
|
|
1886
|
-
});
|
|
1887
|
-
window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-ready",params:{}},"*");
|
|
1888
|
-
<\/script>
|
|
1889
|
-
</body>
|
|
1890
|
-
</html>`;
|
|
1891
|
-
}
|
|
1892
|
-
/**
|
|
1893
|
-
* Queue for serializing MCP app requests to an agent.
|
|
1894
|
-
* Ensures requests wait for the agent to stop running and are processed one at a time.
|
|
1895
|
-
*/
|
|
1896
|
-
var MCPAppsRequestQueue = class {
|
|
1897
|
-
constructor() {
|
|
1898
|
-
this.queues = /* @__PURE__ */ new Map();
|
|
1899
|
-
this.processing = /* @__PURE__ */ new Map();
|
|
1900
|
-
}
|
|
1901
|
-
/**
|
|
1902
|
-
* Add a request to the queue for a specific agent thread.
|
|
1903
|
-
* Returns a promise that resolves when the request completes.
|
|
1904
|
-
*/
|
|
1905
|
-
async enqueue(agent, request) {
|
|
1906
|
-
const threadId = agent.threadId || "default";
|
|
1907
|
-
return new Promise((resolve, reject) => {
|
|
1908
|
-
let queue = this.queues.get(threadId);
|
|
1909
|
-
if (!queue) {
|
|
1910
|
-
queue = [];
|
|
1911
|
-
this.queues.set(threadId, queue);
|
|
1912
|
-
}
|
|
1913
|
-
queue.push({
|
|
1914
|
-
execute: request,
|
|
1915
|
-
resolve,
|
|
1916
|
-
reject
|
|
1917
|
-
});
|
|
1918
|
-
this.processQueue(threadId, agent);
|
|
1919
|
-
});
|
|
1920
|
-
}
|
|
1921
|
-
async processQueue(threadId, agent) {
|
|
1922
|
-
if (this.processing.get(threadId)) return;
|
|
1923
|
-
this.processing.set(threadId, true);
|
|
1924
|
-
try {
|
|
1925
|
-
const queue = this.queues.get(threadId);
|
|
1926
|
-
if (!queue) return;
|
|
1927
|
-
while (queue.length > 0) {
|
|
1928
|
-
const item = queue[0];
|
|
1929
|
-
try {
|
|
1930
|
-
await this.waitForAgentIdle(agent);
|
|
1931
|
-
const result = await item.execute();
|
|
1932
|
-
item.resolve(result);
|
|
1933
|
-
} catch (error) {
|
|
1934
|
-
item.reject(error instanceof Error ? error : new Error(String(error)));
|
|
1935
|
-
}
|
|
1936
|
-
queue.shift();
|
|
1937
|
-
}
|
|
1938
|
-
} finally {
|
|
1939
|
-
this.processing.set(threadId, false);
|
|
1940
|
-
}
|
|
1941
|
-
}
|
|
1942
|
-
waitForAgentIdle(agent) {
|
|
1943
|
-
return new Promise((resolve) => {
|
|
1944
|
-
if (!agent.isRunning) {
|
|
1945
|
-
resolve();
|
|
1946
|
-
return;
|
|
1947
|
-
}
|
|
1948
|
-
let done = false;
|
|
1949
|
-
const finish = () => {
|
|
1950
|
-
if (done) return;
|
|
1951
|
-
done = true;
|
|
1952
|
-
clearInterval(checkInterval);
|
|
1953
|
-
sub.unsubscribe();
|
|
1954
|
-
resolve();
|
|
1955
|
-
};
|
|
1956
|
-
const sub = agent.subscribe({
|
|
1957
|
-
onRunFinalized: finish,
|
|
1958
|
-
onRunFailed: finish
|
|
1959
|
-
});
|
|
1960
|
-
const checkInterval = setInterval(() => {
|
|
1961
|
-
if (!agent.isRunning) finish();
|
|
1962
|
-
}, 500);
|
|
1963
|
-
});
|
|
1964
|
-
}
|
|
1965
|
-
};
|
|
1966
|
-
const mcpAppsRequestQueue = new MCPAppsRequestQueue();
|
|
1967
|
-
const MCP_OPEN_LINK_BLOCKED_SCHEMES = new Set([
|
|
1968
|
-
"javascript:",
|
|
1969
|
-
"data:",
|
|
1970
|
-
"vbscript:",
|
|
1971
|
-
"blob:",
|
|
1972
|
-
"file:"
|
|
1973
|
-
]);
|
|
1974
|
-
/**
|
|
1975
|
-
* Activity type for MCP Apps events - must match the middleware's MCPAppsActivityType
|
|
1976
|
-
*/
|
|
1977
|
-
const MCPAppsActivityType = "mcp-apps";
|
|
1978
|
-
const MCPAppsActivityContentSchema = z.object({
|
|
1979
|
-
result: z.object({
|
|
1980
|
-
content: z.array(z.any()).optional(),
|
|
1981
|
-
structuredContent: z.any().optional(),
|
|
1982
|
-
isError: z.boolean().optional()
|
|
1983
|
-
}),
|
|
1984
|
-
resourceUri: z.string(),
|
|
1985
|
-
serverHash: z.string(),
|
|
1986
|
-
serverId: z.string().optional(),
|
|
1987
|
-
toolInput: z.record(z.string(), z.unknown()).optional()
|
|
1988
|
-
});
|
|
1989
|
-
/**
|
|
1990
1830
|
* MCP Apps Extension Activity Renderer
|
|
1991
1831
|
*
|
|
1992
1832
|
* Renders MCP Apps UI in a sandboxed iframe with full protocol support.
|
|
1993
|
-
* Fetches resource content on-demand via proxied MCP requests.
|
|
1994
|
-
|
|
1995
|
-
/**
|
|
1996
|
-
* Permissive `ui/message` schema. ext-apps restricts the request to
|
|
1997
|
-
* `role: "user"` with no `followUp`, but CopilotKit intentionally extends
|
|
1998
|
-
* `ui/message` with `role` ("user" | "assistant") and `followUp` (documented
|
|
1999
|
-
* behavior with dedicated tests). We register our own handler (instead of the
|
|
2000
|
-
* bridge's strict `onmessage`) so those extensions survive the migration.
|
|
2001
|
-
*
|
|
2002
|
-
* Going forward, widgets SHOULD pass the extensions under
|
|
2003
|
-
* `params._meta.copilotkit`; the top-level `role`/`followUp` fields are the
|
|
2004
|
-
* legacy channel, kept for backward compatibility and slated for deprecation.
|
|
1833
|
+
* Fetches resource content on-demand via proxied MCP requests. The React shell
|
|
1834
|
+
* owns the iframe; `bindMcpApp` owns the protocol.
|
|
2005
1835
|
*/
|
|
2006
|
-
const CopilotKitUiMessageSchema = z.object({
|
|
2007
|
-
method: z.literal("ui/message"),
|
|
2008
|
-
params: z.object({
|
|
2009
|
-
role: z.string().optional(),
|
|
2010
|
-
content: z.array(z.any()).optional(),
|
|
2011
|
-
followUp: z.boolean().optional(),
|
|
2012
|
-
_meta: z.record(z.string(), z.any()).optional()
|
|
2013
|
-
}).passthrough()
|
|
2014
|
-
});
|
|
2015
1836
|
const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
|
|
2016
1837
|
const { copilotkit } = useCopilotKit$1();
|
|
2017
1838
|
const containerRef = useRef(null);
|
|
2018
1839
|
const iframeRef = useRef(null);
|
|
2019
|
-
const
|
|
1840
|
+
const sessionRef = useRef(null);
|
|
2020
1841
|
const [error, setError] = useState(null);
|
|
2021
1842
|
const [isLoading, setIsLoading] = useState(true);
|
|
2022
1843
|
const [iframeSize, setIframeSize] = useState({});
|
|
@@ -2025,207 +1846,81 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
|
|
|
2025
1846
|
contentRef.current = content;
|
|
2026
1847
|
const agentRef = useRef(agent);
|
|
2027
1848
|
agentRef.current = agent;
|
|
2028
|
-
const bridgeRef = useRef(null);
|
|
2029
|
-
const fetchStateRef = useRef({
|
|
2030
|
-
inProgress: false,
|
|
2031
|
-
promise: null,
|
|
2032
|
-
resourceUri: null
|
|
2033
|
-
});
|
|
2034
1849
|
useEffect(() => {
|
|
2035
|
-
const
|
|
2036
|
-
if (
|
|
2037
|
-
fetchStateRef.current.promise?.then((resource) => {
|
|
2038
|
-
if (resource) {
|
|
2039
|
-
setFetchedResource(resource);
|
|
2040
|
-
setIsLoading(false);
|
|
2041
|
-
}
|
|
2042
|
-
}).catch((err) => {
|
|
2043
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
2044
|
-
setIsLoading(false);
|
|
2045
|
-
});
|
|
2046
|
-
return;
|
|
2047
|
-
}
|
|
1850
|
+
const container = containerRef.current;
|
|
1851
|
+
if (!container) return;
|
|
2048
1852
|
if (!agent) {
|
|
2049
1853
|
setError(/* @__PURE__ */ new Error("No agent available to fetch resource"));
|
|
2050
1854
|
setIsLoading(false);
|
|
2051
1855
|
return;
|
|
2052
1856
|
}
|
|
2053
|
-
fetchStateRef.current.inProgress = true;
|
|
2054
|
-
fetchStateRef.current.resourceUri = resourceUri;
|
|
2055
|
-
const fetchPromise = (async () => {
|
|
2056
|
-
try {
|
|
2057
|
-
const resource = (await mcpAppsRequestQueue.enqueue(agent, () => agent.runAgent({ forwardedProps: { __proxiedMCPRequest: {
|
|
2058
|
-
serverHash,
|
|
2059
|
-
serverId,
|
|
2060
|
-
method: "resources/read",
|
|
2061
|
-
params: { uri: resourceUri }
|
|
2062
|
-
} } }))).result?.contents?.[0];
|
|
2063
|
-
if (!resource) throw new Error("No resource content in response");
|
|
2064
|
-
return resource;
|
|
2065
|
-
} catch (err) {
|
|
2066
|
-
console.error("[MCPAppsRenderer] Failed to fetch resource:", err);
|
|
2067
|
-
throw err;
|
|
2068
|
-
} finally {
|
|
2069
|
-
fetchStateRef.current.inProgress = false;
|
|
2070
|
-
}
|
|
2071
|
-
})();
|
|
2072
|
-
fetchStateRef.current.promise = fetchPromise;
|
|
2073
|
-
fetchPromise.then((resource) => {
|
|
2074
|
-
if (resource) {
|
|
2075
|
-
setFetchedResource(resource);
|
|
2076
|
-
setIsLoading(false);
|
|
2077
|
-
}
|
|
2078
|
-
}).catch((err) => {
|
|
2079
|
-
setError(err instanceof Error ? err : new Error(String(err)));
|
|
2080
|
-
setIsLoading(false);
|
|
2081
|
-
});
|
|
2082
|
-
}, [agent, content]);
|
|
2083
|
-
useEffect(() => {
|
|
2084
|
-
if (isLoading || !fetchedResource) return;
|
|
2085
|
-
const container = containerRef.current;
|
|
2086
|
-
if (!container) return;
|
|
2087
1857
|
let mounted = true;
|
|
2088
|
-
|
|
2089
|
-
|
|
1858
|
+
setIsLoading(true);
|
|
1859
|
+
setError(null);
|
|
1860
|
+
const iframe = document.createElement("iframe");
|
|
1861
|
+
iframe.style.width = "100%";
|
|
1862
|
+
iframe.style.height = "100px";
|
|
1863
|
+
iframe.style.border = "none";
|
|
1864
|
+
iframe.style.backgroundColor = "transparent";
|
|
1865
|
+
iframe.style.display = "block";
|
|
1866
|
+
container.appendChild(iframe);
|
|
1867
|
+
iframeRef.current = iframe;
|
|
2090
1868
|
const setup = async () => {
|
|
2091
1869
|
try {
|
|
2092
|
-
const
|
|
2093
|
-
throw new Error("MCP Apps require '@
|
|
2094
|
-
});
|
|
2095
|
-
if (!mounted) return;
|
|
2096
|
-
const { AppBridge, PostMessageTransport } = bridgeModule;
|
|
2097
|
-
const iframe = document.createElement("iframe");
|
|
2098
|
-
createdIframe = iframe;
|
|
2099
|
-
iframe.style.width = "100%";
|
|
2100
|
-
iframe.style.height = "100px";
|
|
2101
|
-
iframe.style.border = "none";
|
|
2102
|
-
iframe.style.backgroundColor = "transparent";
|
|
2103
|
-
iframe.style.display = "block";
|
|
2104
|
-
iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
|
|
2105
|
-
iframe.setAttribute("data-testid", "mcp-app-iframe");
|
|
2106
|
-
iframe.setAttribute("title", "Interactive MCP application");
|
|
2107
|
-
const cspDomains = fetchedResource._meta?.ui?.csp?.resourceDomains;
|
|
2108
|
-
iframe.srcdoc = buildSandboxHTML(cspDomains);
|
|
2109
|
-
iframeRef.current = iframe;
|
|
2110
|
-
container.appendChild(iframe);
|
|
2111
|
-
const win = iframe.contentWindow;
|
|
2112
|
-
if (!win) throw new Error("Sandbox iframe has no contentWindow");
|
|
2113
|
-
let html;
|
|
2114
|
-
if (fetchedResource.text) html = fetchedResource.text;
|
|
2115
|
-
else if (fetchedResource.blob) html = atob(fetchedResource.blob);
|
|
2116
|
-
else throw new Error("Resource has no text or blob content");
|
|
2117
|
-
bridge = new AppBridge(null, {
|
|
2118
|
-
name: "CopilotKit MCP Apps Host",
|
|
2119
|
-
version: "1.0.0"
|
|
2120
|
-
}, {
|
|
2121
|
-
openLinks: {},
|
|
2122
|
-
logging: {},
|
|
2123
|
-
message: { text: {} }
|
|
2124
|
-
}, { hostContext: {
|
|
2125
|
-
theme: "light",
|
|
2126
|
-
platform: "web"
|
|
2127
|
-
} });
|
|
2128
|
-
bridge.onsandboxready = () => {
|
|
2129
|
-
bridge?.sendSandboxResourceReady({ html });
|
|
2130
|
-
};
|
|
2131
|
-
bridge.setRequestHandler(CopilotKitUiMessageSchema, async (req) => {
|
|
2132
|
-
const currentAgent = agentRef.current;
|
|
2133
|
-
if (!currentAgent) {
|
|
2134
|
-
console.warn("[MCPAppsRenderer] ui/message: No agent available");
|
|
2135
|
-
return { isError: false };
|
|
2136
|
-
}
|
|
2137
|
-
try {
|
|
2138
|
-
const params = req.params;
|
|
2139
|
-
const ck = params._meta?.copilotkit ?? {};
|
|
2140
|
-
const role = ck.role || params.role || "user";
|
|
2141
|
-
const textContent = params.content?.filter((c) => c.type === "text" && c.text).map((c) => c.text).join("\n") || "";
|
|
2142
|
-
if (textContent) currentAgent.addMessage({
|
|
2143
|
-
id: crypto.randomUUID(),
|
|
2144
|
-
role,
|
|
2145
|
-
content: textContent
|
|
2146
|
-
});
|
|
2147
|
-
if ((ck.followUp ?? params.followUp ?? role === "user") && textContent) {
|
|
2148
|
-
const capturedThreadId = currentAgent.threadId || "default";
|
|
2149
|
-
mcpAppsRequestQueue.enqueue(currentAgent, () => ɵrunMcpFollowUp({
|
|
2150
|
-
host: copilotkit,
|
|
2151
|
-
agent: currentAgent,
|
|
2152
|
-
capturedThreadId
|
|
2153
|
-
})).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
|
|
2154
|
-
}
|
|
2155
|
-
return { isError: false };
|
|
2156
|
-
} catch (err) {
|
|
2157
|
-
console.error("[MCPAppsRenderer] ui/message error:", err);
|
|
2158
|
-
return { isError: true };
|
|
2159
|
-
}
|
|
1870
|
+
const mod = await import("@copilotkit/mcp-apps-renderer").catch((importErr) => {
|
|
1871
|
+
throw new Error("MCP Apps require '@copilotkit/mcp-apps-renderer' and its '@modelcontextprotocol/ext-apps' dependency. Reinstall your dependencies if this package is missing.", { cause: importErr });
|
|
2160
1872
|
});
|
|
2161
|
-
bridge.onopenlink = async ({ url }) => {
|
|
2162
|
-
let parsed;
|
|
2163
|
-
try {
|
|
2164
|
-
parsed = new URL(url);
|
|
2165
|
-
} catch {
|
|
2166
|
-
console.warn("[MCPAppsRenderer] ui/open-link rejected: unparseable url");
|
|
2167
|
-
return { isError: true };
|
|
2168
|
-
}
|
|
2169
|
-
if (MCP_OPEN_LINK_BLOCKED_SCHEMES.has(parsed.protocol)) {
|
|
2170
|
-
console.warn("[MCPAppsRenderer] ui/open-link rejected: blocked scheme", parsed.protocol);
|
|
2171
|
-
return { isError: true };
|
|
2172
|
-
}
|
|
2173
|
-
window.open(url, "_blank", "noopener,noreferrer");
|
|
2174
|
-
return { isError: false };
|
|
2175
|
-
};
|
|
2176
|
-
bridge.oncalltool = async (params) => {
|
|
2177
|
-
const { serverHash, serverId } = contentRef.current;
|
|
2178
|
-
const currentAgent = agentRef.current;
|
|
2179
|
-
if (!serverHash) throw new Error("No server hash available for proxying");
|
|
2180
|
-
if (!currentAgent) throw new Error("No agent available for proxying");
|
|
2181
|
-
return (await mcpAppsRequestQueue.enqueue(currentAgent, () => currentAgent.runAgent({ forwardedProps: { __proxiedMCPRequest: {
|
|
2182
|
-
serverHash,
|
|
2183
|
-
serverId,
|
|
2184
|
-
method: "tools/call",
|
|
2185
|
-
params
|
|
2186
|
-
} } }))).result || { content: [] };
|
|
2187
|
-
};
|
|
2188
|
-
bridge.onsizechange = (p) => {
|
|
2189
|
-
if (!mounted) return;
|
|
2190
|
-
const { width, height } = p || {};
|
|
2191
|
-
setIframeSize({
|
|
2192
|
-
width: typeof width === "number" ? width : void 0,
|
|
2193
|
-
height: typeof height === "number" ? height : void 0
|
|
2194
|
-
});
|
|
2195
|
-
};
|
|
2196
|
-
bridge.oninitialized = () => {
|
|
2197
|
-
if (mounted) setIframeReady(true);
|
|
2198
|
-
};
|
|
2199
|
-
bridge.onloggingmessage = (p) => {
|
|
2200
|
-
console.log("[MCPAppsRenderer] App log:", p);
|
|
2201
|
-
};
|
|
2202
|
-
const transport = new PostMessageTransport(win, win);
|
|
2203
|
-
await bridge.connect(transport);
|
|
2204
1873
|
if (!mounted) {
|
|
2205
|
-
|
|
1874
|
+
iframe.remove();
|
|
2206
1875
|
return;
|
|
2207
1876
|
}
|
|
2208
|
-
|
|
1877
|
+
const session = mod.bindMcpApp({
|
|
1878
|
+
iframe,
|
|
1879
|
+
getContent: () => contentRef.current,
|
|
1880
|
+
getAgent: () => agentRef.current,
|
|
1881
|
+
host: copilotkit,
|
|
1882
|
+
hooks: {
|
|
1883
|
+
onResource: (resource) => {
|
|
1884
|
+
if (!mounted) return;
|
|
1885
|
+
setFetchedResource(resource);
|
|
1886
|
+
setIsLoading(false);
|
|
1887
|
+
},
|
|
1888
|
+
onSizeChanged: (size) => {
|
|
1889
|
+
if (mounted) setIframeSize(size);
|
|
1890
|
+
},
|
|
1891
|
+
onError: (err) => {
|
|
1892
|
+
if (!mounted) return;
|
|
1893
|
+
setError(err);
|
|
1894
|
+
setIsLoading(false);
|
|
1895
|
+
}
|
|
1896
|
+
}
|
|
1897
|
+
});
|
|
1898
|
+
sessionRef.current = session;
|
|
1899
|
+
const current = contentRef.current;
|
|
1900
|
+
if (current.toolInput) session.sendToolInput(current.toolInput);
|
|
1901
|
+
if (current.result) session.sendToolResult(current.result);
|
|
2209
1902
|
} catch (err) {
|
|
2210
1903
|
console.error("[MCPAppsRenderer] Setup error:", err);
|
|
2211
|
-
if (mounted)
|
|
1904
|
+
if (mounted) {
|
|
1905
|
+
setError(err instanceof Error ? err : new Error(String(err)));
|
|
1906
|
+
setIsLoading(false);
|
|
1907
|
+
}
|
|
2212
1908
|
}
|
|
2213
1909
|
};
|
|
2214
1910
|
setup();
|
|
2215
1911
|
return () => {
|
|
2216
1912
|
mounted = false;
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
createdIframe.remove();
|
|
2221
|
-
createdIframe = null;
|
|
2222
|
-
}
|
|
1913
|
+
sessionRef.current?.teardown();
|
|
1914
|
+
sessionRef.current = null;
|
|
1915
|
+
iframe.remove();
|
|
2223
1916
|
iframeRef.current = null;
|
|
2224
1917
|
};
|
|
2225
1918
|
}, [
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
1919
|
+
agent,
|
|
1920
|
+
copilotkit,
|
|
1921
|
+
content.resourceUri,
|
|
1922
|
+
content.serverHash,
|
|
1923
|
+
content.serverId
|
|
2229
1924
|
]);
|
|
2230
1925
|
useEffect(() => {
|
|
2231
1926
|
if (iframeRef.current) {
|
|
@@ -2237,11 +1932,11 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
|
|
|
2237
1932
|
}
|
|
2238
1933
|
}, [iframeSize]);
|
|
2239
1934
|
useEffect(() => {
|
|
2240
|
-
if (
|
|
2241
|
-
}, [
|
|
1935
|
+
if (content.toolInput) sessionRef.current?.sendToolInput(content.toolInput);
|
|
1936
|
+
}, [content.toolInput]);
|
|
2242
1937
|
useEffect(() => {
|
|
2243
|
-
if (
|
|
2244
|
-
}, [
|
|
1938
|
+
if (content.result) sessionRef.current?.sendToolResult(content.result);
|
|
1939
|
+
}, [content.result]);
|
|
2245
1940
|
const borderStyle = fetchedResource?._meta?.ui?.prefersBorder === true ? {
|
|
2246
1941
|
borderRadius: "8px",
|
|
2247
1942
|
backgroundColor: "#f9f9f9",
|
|
@@ -6829,9 +6524,15 @@ const VideoAttachment = memo(function VideoAttachment({ src, className }) {
|
|
|
6829
6524
|
className: cn("cpk:max-w-[400px] cpk:w-full cpk:rounded-lg", className)
|
|
6830
6525
|
});
|
|
6831
6526
|
});
|
|
6832
|
-
const DocumentAttachment = memo(function DocumentAttachment({ source, filename, className }) {
|
|
6833
|
-
|
|
6834
|
-
|
|
6527
|
+
const DocumentAttachment = memo(function DocumentAttachment({ src, source, filename, className }) {
|
|
6528
|
+
const label = filename || source.mimeType || "Document attachment";
|
|
6529
|
+
return /* @__PURE__ */ jsxs("a", {
|
|
6530
|
+
href: src,
|
|
6531
|
+
download: filename ?? "",
|
|
6532
|
+
target: "_blank",
|
|
6533
|
+
rel: "noopener noreferrer",
|
|
6534
|
+
"aria-label": label,
|
|
6535
|
+
className: cn("cpk:inline-flex cpk:max-w-full cpk:items-center cpk:gap-2 cpk:px-3 cpk:py-2 cpk:border cpk:border-border cpk:rounded-lg cpk:bg-muted", className),
|
|
6835
6536
|
children: [/* @__PURE__ */ jsx("span", {
|
|
6836
6537
|
className: "cpk:text-xs cpk:font-bold cpk:uppercase",
|
|
6837
6538
|
children: getDocumentIcon(source.mimeType ?? "")
|
|
@@ -6858,6 +6559,7 @@ const CopilotChatAttachmentRenderer = ({ type, source, filename, className }) =>
|
|
|
6858
6559
|
className
|
|
6859
6560
|
});
|
|
6860
6561
|
case "document": return /* @__PURE__ */ jsx(DocumentAttachment, {
|
|
6562
|
+
src,
|
|
6861
6563
|
source,
|
|
6862
6564
|
filename,
|
|
6863
6565
|
className
|
|
@@ -6931,7 +6633,7 @@ function CopilotChatUserMessage({ message, onEditMessage, branchIndex, numberOfB
|
|
|
6931
6633
|
...props,
|
|
6932
6634
|
children: [
|
|
6933
6635
|
mediaParts.length > 0 && /* @__PURE__ */ jsx("div", {
|
|
6934
|
-
className: "cpk:flex cpk:flex-row cpk:flex-wrap cpk:justify-end cpk:gap-2 cpk:mb-2",
|
|
6636
|
+
className: "cpk:flex cpk:flex-row cpk:flex-wrap cpk:max-w-full cpk:justify-end cpk:gap-2 cpk:mb-2",
|
|
6935
6637
|
children: mediaParts.map((part, index) => /* @__PURE__ */ jsx(CopilotChatAttachmentRenderer, {
|
|
6936
6638
|
type: part.type,
|
|
6937
6639
|
source: part.source,
|
|
@@ -12665,4 +12367,4 @@ function validateProps(props) {
|
|
|
12665
12367
|
|
|
12666
12368
|
//#endregion
|
|
12667
12369
|
export { useAgentContext as $, CopilotChatMessageView as A, AudioRecorderError as At, CopilotChatAssistantMessage_default as B, CopilotModalHeader as C, MCPAppsActivityContentSchema as Ct, CopilotChat as D, CopilotKitInspector as Dt, DefaultOpenIcon as E, ɵrunMcpFollowUp as Et, CopilotChatSuggestionView as F, useLearnFromUserActionInCurrentThread as G, useLearningContainersInCurrentThread as H, CopilotChatSuggestionPill as I, useThreads$1 as J, useLearnFromUserAction as K, CopilotChatReasoningMessage_default as L, IntelligenceIndicator as M, CopilotChatConfigurationProvider as Mt, getIntelligenceTurnAnchors as N, useCopilotChatConfiguration as Nt, CopilotChatView_default as O, useRenderToolCall as Ot, IntelligenceIndicatorView as P, useSuggestions as Q, CopilotChatUserMessage_default as R, CopilotSidebarView as S, useSandboxFunctions as St, DefaultCloseIcon as T, MCPAppsActivityType as Tt, useLearningContainers as U, CopilotChatToolCallsView as V, useAttachments as W, INTERRUPT_EVENT_NAME as X, useInterrupt as Y, useConfigureSuggestions as Z, WildcardToolCallRender as _, OpenGenerativeUIActivityRenderer as _t, ThreadsProvider as a, useRenderTool as at, CopilotSidebar as b, OpenGenerativeUIToolRenderer as bt, CoAgentStateRendersProvider as c, useRenderActivityMessage as ct, shouldShowDevConsole as d, useCopilotKit$1 as dt, useCapabilities as et, useToast as f, useLicenseContext$1 as ft, useCopilotContext as g, GenerateSandboxedUiArgsSchema as gt, CopilotContext as h, createA2UIMessageRenderer as ht, ThreadsContext as i, useDefaultRenderTool as it, INTELLIGENCE_TURN_HEAD as j, CopilotChatAudioRecorder as jt, CopilotChatAttachmentQueue as k, CopilotChatInput_default as kt, useCoAgentStateRenders as l, useRenderCustomMessages as lt, useCopilotMessagesContext as m, defineToolCallRenderer as mt, defaultCopilotContextCategories as n, useAgent as nt, useThreads as o, useComponent as ot, CopilotMessagesContext as p, CopilotKitCoreReact as pt, useMemories as q, CoAgentStateRenderBridge as r, useHumanInTheLoop as rt, CoAgentStateRendersContext as s, useFrontendTool as st, CopilotKit as t, UseAgentUpdate as tt, useAsyncCallback as u, CopilotKitProvider as ut, CopilotThreadsDrawer as v, OpenGenerativeUIActivityType as vt, CopilotChatToggleButton as w, MCPAppsActivityRenderer as wt, CopilotPopupView as x, SandboxFunctionsContext as xt, CopilotPopup as y, OpenGenerativeUIContentSchema as yt, CopilotChatAttachmentRenderer as z };
|
|
12668
|
-
//# sourceMappingURL=copilotkit-
|
|
12370
|
+
//# sourceMappingURL=copilotkit-qK-Q3rmE.mjs.map
|