@copilotkitnext/react 0.0.0-0.0.0-max-changeset-10101010101010-20260109194224 → 0.0.0-fix-runtime-openai-api-key-passthrough-20260115015318

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.js CHANGED
@@ -74,7 +74,6 @@ __export(index_exports, {
74
74
  useSuggestions: () => useSuggestions
75
75
  });
76
76
  module.exports = __toCommonJS(index_exports);
77
- __reExport(index_exports, require("@ag-ui/core"), module.exports);
78
77
  __reExport(index_exports, require("@ag-ui/client"), module.exports);
79
78
 
80
79
  // src/components/chat/CopilotChatInput.tsx
@@ -1517,6 +1516,104 @@ var import_react6 = require("react");
1517
1516
  var import_zod = require("zod");
1518
1517
  var import_jsx_runtime8 = require("react/jsx-runtime");
1519
1518
  var PROTOCOL_VERSION = "2025-06-18";
1519
+ var SANDBOX_HTML = `<!doctype html>
1520
+ <html>
1521
+ <head>
1522
+ <meta charset="utf-8" />
1523
+ <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 'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*; style-src * blob: data: 'unsafe-inline'; connect-src *; frame-src * blob: data: http://localhost:* https://localhost:*; base-uri 'self';" />
1524
+ <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>
1525
+ </head>
1526
+ <body>
1527
+ <script>
1528
+ if(window.self===window.top){throw new Error("This file must be used in an iframe.")}
1529
+ const inner=document.createElement("iframe");
1530
+ inner.style="width:100%;height:100%;border:none;";
1531
+ inner.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms");
1532
+ document.body.appendChild(inner);
1533
+ window.addEventListener("message",async(event)=>{
1534
+ if(event.source===window.parent){
1535
+ if(event.data&&event.data.method==="ui/notifications/sandbox-resource-ready"){
1536
+ const{html,sandbox}=event.data.params;
1537
+ if(typeof sandbox==="string")inner.setAttribute("sandbox",sandbox);
1538
+ if(typeof html==="string")inner.srcdoc=html;
1539
+ }else if(inner&&inner.contentWindow){
1540
+ inner.contentWindow.postMessage(event.data,"*");
1541
+ }
1542
+ }else if(event.source===inner.contentWindow){
1543
+ window.parent.postMessage(event.data,"*");
1544
+ }
1545
+ });
1546
+ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-ready",params:{}},"*");
1547
+ </script>
1548
+ </body>
1549
+ </html>`;
1550
+ var MCPAppsRequestQueue = class {
1551
+ queues = /* @__PURE__ */ new Map();
1552
+ processing = /* @__PURE__ */ new Map();
1553
+ /**
1554
+ * Add a request to the queue for a specific agent thread.
1555
+ * Returns a promise that resolves when the request completes.
1556
+ */
1557
+ async enqueue(agent, request) {
1558
+ const threadId = agent.threadId || "default";
1559
+ return new Promise((resolve, reject) => {
1560
+ let queue = this.queues.get(threadId);
1561
+ if (!queue) {
1562
+ queue = [];
1563
+ this.queues.set(threadId, queue);
1564
+ }
1565
+ queue.push({ execute: request, resolve, reject });
1566
+ this.processQueue(threadId, agent);
1567
+ });
1568
+ }
1569
+ async processQueue(threadId, agent) {
1570
+ if (this.processing.get(threadId)) {
1571
+ return;
1572
+ }
1573
+ this.processing.set(threadId, true);
1574
+ try {
1575
+ const queue = this.queues.get(threadId);
1576
+ if (!queue) return;
1577
+ while (queue.length > 0) {
1578
+ const item = queue[0];
1579
+ try {
1580
+ await this.waitForAgentIdle(agent);
1581
+ const result = await item.execute();
1582
+ item.resolve(result);
1583
+ } catch (error) {
1584
+ item.reject(error instanceof Error ? error : new Error(String(error)));
1585
+ }
1586
+ queue.shift();
1587
+ }
1588
+ } finally {
1589
+ this.processing.set(threadId, false);
1590
+ }
1591
+ }
1592
+ waitForAgentIdle(agent) {
1593
+ return new Promise((resolve) => {
1594
+ if (!agent.isRunning) {
1595
+ resolve();
1596
+ return;
1597
+ }
1598
+ let done = false;
1599
+ const finish = () => {
1600
+ if (done) return;
1601
+ done = true;
1602
+ clearInterval(checkInterval);
1603
+ sub.unsubscribe();
1604
+ resolve();
1605
+ };
1606
+ const sub = agent.subscribe({
1607
+ onRunFinalized: finish,
1608
+ onRunFailed: finish
1609
+ });
1610
+ const checkInterval = setInterval(() => {
1611
+ if (!agent.isRunning) finish();
1612
+ }, 500);
1613
+ });
1614
+ }
1615
+ };
1616
+ var mcpAppsRequestQueue = new MCPAppsRequestQueue();
1520
1617
  var MCPAppsActivityType = "mcp-apps";
1521
1618
  var MCPAppsActivityContentSchema = import_zod.z.object({
1522
1619
  result: import_zod.z.object({
@@ -1524,13 +1621,11 @@ var MCPAppsActivityContentSchema = import_zod.z.object({
1524
1621
  structuredContent: import_zod.z.any().optional(),
1525
1622
  isError: import_zod.z.boolean().optional()
1526
1623
  }),
1527
- resource: import_zod.z.object({
1528
- uri: import_zod.z.string(),
1529
- mimeType: import_zod.z.string().optional(),
1530
- text: import_zod.z.string().optional(),
1531
- blob: import_zod.z.string().optional()
1532
- }),
1533
- // Server ID for proxying requests (MD5 hash of server config)
1624
+ // Resource URI to fetch (e.g., "ui://server/dashboard")
1625
+ resourceUri: import_zod.z.string(),
1626
+ // MD5 hash of server config (renamed from serverId in 0.0.1)
1627
+ serverHash: import_zod.z.string(),
1628
+ // Optional stable server ID from config (takes precedence over serverHash)
1534
1629
  serverId: import_zod.z.string().optional(),
1535
1630
  // Original tool input arguments
1536
1631
  toolInput: import_zod.z.record(import_zod.z.unknown()).optional()
@@ -1541,25 +1636,19 @@ function isRequest(msg) {
1541
1636
  function isNotification(msg) {
1542
1637
  return !("id" in msg) && "method" in msg;
1543
1638
  }
1544
- function extractHtmlFromResource(resource) {
1545
- if (resource.text) {
1546
- return resource.text;
1547
- }
1548
- if (resource.blob) {
1549
- return atob(resource.blob);
1550
- }
1551
- throw new Error("Resource has no text or blob content");
1552
- }
1553
- var MCPAppsActivityRenderer = ({ content, agent }) => {
1639
+ var MCPAppsActivityRenderer = function MCPAppsActivityRenderer2({ content, agent }) {
1554
1640
  const containerRef = (0, import_react6.useRef)(null);
1555
1641
  const iframeRef = (0, import_react6.useRef)(null);
1556
1642
  const [iframeReady, setIframeReady] = (0, import_react6.useState)(false);
1557
1643
  const [error, setError] = (0, import_react6.useState)(null);
1644
+ const [isLoading, setIsLoading] = (0, import_react6.useState)(true);
1558
1645
  const [iframeSize, setIframeSize] = (0, import_react6.useState)({});
1646
+ const [fetchedResource, setFetchedResource] = (0, import_react6.useState)(null);
1559
1647
  const contentRef = (0, import_react6.useRef)(content);
1560
1648
  contentRef.current = content;
1561
1649
  const agentRef = (0, import_react6.useRef)(agent);
1562
1650
  agentRef.current = agent;
1651
+ const fetchStateRef = (0, import_react6.useRef)({ inProgress: false, promise: null, resourceUri: null });
1563
1652
  const sendToIframe = (0, import_react6.useCallback)((msg) => {
1564
1653
  if (iframeRef.current?.contentWindow) {
1565
1654
  console.log("[MCPAppsRenderer] Sending to iframe:", msg);
@@ -1588,31 +1677,112 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1588
1677
  });
1589
1678
  }, [sendToIframe]);
1590
1679
  (0, import_react6.useEffect)(() => {
1591
- if (!containerRef.current) return;
1680
+ const { resourceUri, serverHash, serverId } = content;
1681
+ if (fetchStateRef.current.inProgress && fetchStateRef.current.resourceUri === resourceUri) {
1682
+ fetchStateRef.current.promise?.then((resource) => {
1683
+ if (resource) {
1684
+ setFetchedResource(resource);
1685
+ setIsLoading(false);
1686
+ }
1687
+ }).catch((err) => {
1688
+ setError(err instanceof Error ? err : new Error(String(err)));
1689
+ setIsLoading(false);
1690
+ });
1691
+ return;
1692
+ }
1693
+ if (!agent) {
1694
+ setError(new Error("No agent available to fetch resource"));
1695
+ setIsLoading(false);
1696
+ return;
1697
+ }
1698
+ fetchStateRef.current.inProgress = true;
1699
+ fetchStateRef.current.resourceUri = resourceUri;
1700
+ const fetchPromise = (async () => {
1701
+ try {
1702
+ const runResult = await mcpAppsRequestQueue.enqueue(
1703
+ agent,
1704
+ () => agent.runAgent({
1705
+ forwardedProps: {
1706
+ __proxiedMCPRequest: {
1707
+ serverHash,
1708
+ serverId,
1709
+ // optional, takes precedence if provided
1710
+ method: "resources/read",
1711
+ params: { uri: resourceUri }
1712
+ }
1713
+ }
1714
+ })
1715
+ );
1716
+ const resultData = runResult.result;
1717
+ const resource = resultData?.contents?.[0];
1718
+ if (!resource) {
1719
+ throw new Error("No resource content in response");
1720
+ }
1721
+ return resource;
1722
+ } catch (err) {
1723
+ console.error("[MCPAppsRenderer] Failed to fetch resource:", err);
1724
+ throw err;
1725
+ } finally {
1726
+ fetchStateRef.current.inProgress = false;
1727
+ }
1728
+ })();
1729
+ fetchStateRef.current.promise = fetchPromise;
1730
+ fetchPromise.then((resource) => {
1731
+ if (resource) {
1732
+ setFetchedResource(resource);
1733
+ setIsLoading(false);
1734
+ }
1735
+ }).catch((err) => {
1736
+ setError(err instanceof Error ? err : new Error(String(err)));
1737
+ setIsLoading(false);
1738
+ });
1739
+ }, [agent, content]);
1740
+ (0, import_react6.useEffect)(() => {
1741
+ if (isLoading || !fetchedResource) {
1742
+ return;
1743
+ }
1744
+ const container = containerRef.current;
1745
+ if (!container) {
1746
+ return;
1747
+ }
1592
1748
  let mounted = true;
1593
1749
  let messageHandler = null;
1750
+ let initialListener = null;
1751
+ let createdIframe = null;
1594
1752
  const setup = async () => {
1595
1753
  try {
1596
1754
  const iframe = document.createElement("iframe");
1755
+ createdIframe = iframe;
1597
1756
  iframe.style.width = "100%";
1598
- iframe.style.height = "300px";
1757
+ iframe.style.height = "100px";
1599
1758
  iframe.style.border = "none";
1600
1759
  iframe.style.backgroundColor = "transparent";
1760
+ iframe.style.display = "block";
1601
1761
  iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
1602
1762
  const sandboxReady = new Promise((resolve) => {
1603
- const initialListener = (event) => {
1763
+ initialListener = (event) => {
1604
1764
  if (event.source === iframe.contentWindow) {
1605
1765
  if (event.data?.method === "ui/notifications/sandbox-proxy-ready") {
1606
- window.removeEventListener("message", initialListener);
1766
+ if (initialListener) {
1767
+ window.removeEventListener("message", initialListener);
1768
+ initialListener = null;
1769
+ }
1607
1770
  resolve();
1608
1771
  }
1609
1772
  }
1610
1773
  };
1611
1774
  window.addEventListener("message", initialListener);
1612
1775
  });
1613
- iframe.src = "/sandbox.html";
1776
+ if (!mounted) {
1777
+ if (initialListener) {
1778
+ window.removeEventListener("message", initialListener);
1779
+ initialListener = null;
1780
+ }
1781
+ return;
1782
+ }
1783
+ iframe.srcdoc = SANDBOX_HTML;
1614
1784
  iframeRef.current = iframe;
1615
- containerRef.current?.appendChild(iframe);
1785
+ container.appendChild(iframe);
1616
1786
  await sandboxReady;
1617
1787
  if (!mounted) return;
1618
1788
  console.log("[MCPAppsRenderer] Sandbox proxy ready");
@@ -1642,8 +1812,27 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1642
1812
  break;
1643
1813
  }
1644
1814
  case "ui/message": {
1645
- console.log("[MCPAppsRenderer] ui/message request:", msg.params);
1646
- sendResponse(msg.id, { isError: false });
1815
+ const currentAgent = agentRef.current;
1816
+ if (!currentAgent) {
1817
+ console.warn("[MCPAppsRenderer] ui/message: No agent available");
1818
+ sendResponse(msg.id, { isError: false });
1819
+ break;
1820
+ }
1821
+ try {
1822
+ const params = msg.params;
1823
+ const textContent = params.content?.filter((c) => c.type === "text" && c.text).map((c) => c.text).join("\n") || "";
1824
+ if (textContent) {
1825
+ currentAgent.addMessage({
1826
+ id: crypto.randomUUID(),
1827
+ role: params.role || "user",
1828
+ content: textContent
1829
+ });
1830
+ }
1831
+ sendResponse(msg.id, { isError: false });
1832
+ } catch (err) {
1833
+ console.error("[MCPAppsRenderer] ui/message error:", err);
1834
+ sendResponse(msg.id, { isError: true });
1835
+ }
1647
1836
  break;
1648
1837
  }
1649
1838
  case "ui/open-link": {
@@ -1657,10 +1846,10 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1657
1846
  break;
1658
1847
  }
1659
1848
  case "tools/call": {
1660
- const { serverId } = contentRef.current;
1849
+ const { serverHash, serverId } = contentRef.current;
1661
1850
  const currentAgent = agentRef.current;
1662
- if (!serverId) {
1663
- sendErrorResponse(msg.id, -32603, "No server ID available for proxying");
1851
+ if (!serverHash) {
1852
+ sendErrorResponse(msg.id, -32603, "No server hash available for proxying");
1664
1853
  break;
1665
1854
  }
1666
1855
  if (!currentAgent) {
@@ -1668,15 +1857,20 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1668
1857
  break;
1669
1858
  }
1670
1859
  try {
1671
- const runResult = await currentAgent.runAgent({
1672
- forwardedProps: {
1673
- __proxiedMCPRequest: {
1674
- serverId,
1675
- method: "tools/call",
1676
- params: msg.params
1860
+ const runResult = await mcpAppsRequestQueue.enqueue(
1861
+ currentAgent,
1862
+ () => currentAgent.runAgent({
1863
+ forwardedProps: {
1864
+ __proxiedMCPRequest: {
1865
+ serverHash,
1866
+ serverId,
1867
+ // optional, takes precedence if provided
1868
+ method: "tools/call",
1869
+ params: msg.params
1870
+ }
1677
1871
  }
1678
- }
1679
- });
1872
+ })
1873
+ );
1680
1874
  sendResponse(msg.id, runResult.result || {});
1681
1875
  } catch (err) {
1682
1876
  console.error("[MCPAppsRenderer] tools/call error:", err);
@@ -1697,7 +1891,7 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1697
1891
  }
1698
1892
  break;
1699
1893
  }
1700
- case "ui/notifications/size-change": {
1894
+ case "ui/notifications/size-changed": {
1701
1895
  const { width, height } = msg.params || {};
1702
1896
  console.log("[MCPAppsRenderer] Size change:", { width, height });
1703
1897
  if (mounted) {
@@ -1716,7 +1910,14 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1716
1910
  }
1717
1911
  };
1718
1912
  window.addEventListener("message", messageHandler);
1719
- const html = extractHtmlFromResource(content.resource);
1913
+ let html;
1914
+ if (fetchedResource.text) {
1915
+ html = fetchedResource.text;
1916
+ } else if (fetchedResource.blob) {
1917
+ html = atob(fetchedResource.blob);
1918
+ } else {
1919
+ throw new Error("Resource has no text or blob content");
1920
+ }
1720
1921
  sendNotification("ui/notifications/sandbox-resource-ready", { html });
1721
1922
  } catch (err) {
1722
1923
  console.error("[MCPAppsRenderer] Setup error:", err);
@@ -1728,19 +1929,25 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1728
1929
  setup();
1729
1930
  return () => {
1730
1931
  mounted = false;
1932
+ if (initialListener) {
1933
+ window.removeEventListener("message", initialListener);
1934
+ initialListener = null;
1935
+ }
1731
1936
  if (messageHandler) {
1732
1937
  window.removeEventListener("message", messageHandler);
1733
1938
  }
1734
- if (iframeRef.current && containerRef.current?.contains(iframeRef.current)) {
1735
- containerRef.current.removeChild(iframeRef.current);
1939
+ if (createdIframe) {
1940
+ createdIframe.remove();
1941
+ createdIframe = null;
1736
1942
  }
1737
1943
  iframeRef.current = null;
1738
1944
  };
1739
- }, [content.resource, sendNotification, sendResponse, sendErrorResponse]);
1945
+ }, [isLoading, fetchedResource, sendNotification, sendResponse, sendErrorResponse]);
1740
1946
  (0, import_react6.useEffect)(() => {
1741
1947
  if (iframeRef.current) {
1742
1948
  if (iframeSize.width !== void 0) {
1743
- iframeRef.current.style.width = `${iframeSize.width}px`;
1949
+ iframeRef.current.style.minWidth = `min(${iframeSize.width}px, 100%)`;
1950
+ iframeRef.current.style.width = "100%";
1744
1951
  }
1745
1952
  if (iframeSize.height !== void 0) {
1746
1953
  iframeRef.current.style.height = `${iframeSize.height}px`;
@@ -1761,22 +1968,31 @@ var MCPAppsActivityRenderer = ({ content, agent }) => {
1761
1968
  sendNotification("ui/notifications/tool-result", content.result);
1762
1969
  }
1763
1970
  }, [iframeReady, content.result, sendNotification]);
1764
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1971
+ const prefersBorder = fetchedResource?._meta?.ui?.prefersBorder;
1972
+ const borderStyle = prefersBorder === true ? {
1973
+ borderRadius: "8px",
1974
+ backgroundColor: "#f9f9f9",
1975
+ border: "1px solid #e0e0e0"
1976
+ } : {};
1977
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1765
1978
  "div",
1766
1979
  {
1767
1980
  ref: containerRef,
1768
1981
  style: {
1769
1982
  width: "100%",
1983
+ height: iframeSize.height ? `${iframeSize.height}px` : "auto",
1770
1984
  minHeight: "100px",
1771
- borderRadius: "8px",
1772
1985
  overflow: "hidden",
1773
- backgroundColor: "#f9f9f9",
1774
- border: "1px solid #e0e0e0"
1986
+ position: "relative",
1987
+ ...borderStyle
1775
1988
  },
1776
- children: error && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { color: "red", padding: "1rem" }, children: [
1777
- "Error: ",
1778
- error.message
1779
- ] })
1989
+ children: [
1990
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { style: { padding: "1rem", color: "#666" }, children: "Loading..." }),
1991
+ error && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { color: "red", padding: "1rem" }, children: [
1992
+ "Error: ",
1993
+ error.message
1994
+ ] })
1995
+ ]
1780
1996
  }
1781
1997
  );
1782
1998
  };
@@ -2205,15 +2421,21 @@ function useRenderActivityMessage() {
2205
2421
  const config = useCopilotChatConfiguration();
2206
2422
  const agentId = config?.agentId ?? import_shared4.DEFAULT_AGENT_ID;
2207
2423
  const renderers = copilotkit.renderActivityMessages;
2208
- return (0, import_react9.useCallback)(
2209
- (message) => {
2424
+ const findRenderer = (0, import_react9.useCallback)(
2425
+ (activityType) => {
2210
2426
  if (!renderers.length) {
2211
2427
  return null;
2212
2428
  }
2213
2429
  const matches = renderers.filter(
2214
- (renderer2) => renderer2.activityType === message.activityType
2430
+ (renderer) => renderer.activityType === activityType
2215
2431
  );
2216
- const renderer = matches.find((candidate) => candidate.agentId === agentId) ?? matches.find((candidate) => candidate.agentId === void 0) ?? renderers.find((candidate) => candidate.activityType === "*");
2432
+ return matches.find((candidate) => candidate.agentId === agentId) ?? matches.find((candidate) => candidate.agentId === void 0) ?? renderers.find((candidate) => candidate.activityType === "*") ?? null;
2433
+ },
2434
+ [agentId, renderers]
2435
+ );
2436
+ const renderActivityMessage = (0, import_react9.useCallback)(
2437
+ (message) => {
2438
+ const renderer = findRenderer(message.activityType);
2217
2439
  if (!renderer) {
2218
2440
  return null;
2219
2441
  }
@@ -2238,7 +2460,11 @@ function useRenderActivityMessage() {
2238
2460
  message.id
2239
2461
  );
2240
2462
  },
2241
- [agentId, copilotkit, renderers]
2463
+ [agentId, copilotkit, findRenderer]
2464
+ );
2465
+ return (0, import_react9.useMemo)(
2466
+ () => ({ renderActivityMessage, findRenderer }),
2467
+ [renderActivityMessage, findRenderer]
2242
2468
  );
2243
2469
  }
2244
2470
 
@@ -2410,20 +2636,12 @@ function useAgent({ agentId, updates } = {}) {
2410
2636
  };
2411
2637
  }
2412
2638
  if (updateFlags.includes("OnStateChanged" /* OnStateChanged */)) {
2413
- handlers.onStateChanged = () => {
2414
- forceUpdate();
2415
- };
2639
+ handlers.onStateChanged = forceUpdate;
2416
2640
  }
2417
2641
  if (updateFlags.includes("OnRunStatusChanged" /* OnRunStatusChanged */)) {
2418
- handlers.onRunInitialized = () => {
2419
- forceUpdate();
2420
- };
2421
- handlers.onRunFinalized = () => {
2422
- forceUpdate();
2423
- };
2424
- handlers.onRunFailed = () => {
2425
- forceUpdate();
2426
- };
2642
+ handlers.onRunInitialized = forceUpdate;
2643
+ handlers.onRunFinalized = forceUpdate;
2644
+ handlers.onRunFailed = forceUpdate;
2427
2645
  }
2428
2646
  const subscription = agent.subscribe(handlers);
2429
2647
  return () => subscription.unsubscribe();
@@ -3382,7 +3600,7 @@ function CopilotChatMessageView({
3382
3600
  ...props
3383
3601
  }) {
3384
3602
  const renderCustomMessage = useRenderCustomMessages();
3385
- const renderActivityMessage = useRenderActivityMessage();
3603
+ const { renderActivityMessage } = useRenderActivityMessage();
3386
3604
  const { copilotkit } = useCopilotKit();
3387
3605
  const config = useCopilotChatConfiguration();
3388
3606
  const [, forceUpdate] = (0, import_react22.useReducer)((x) => x + 1, 0);
@@ -3391,10 +3609,10 @@ function CopilotChatMessageView({
3391
3609
  const agent = copilotkit.getAgent(config.agentId);
3392
3610
  if (!agent) return;
3393
3611
  const subscription = agent.subscribe({
3394
- onStateChanged: () => forceUpdate()
3612
+ onStateChanged: forceUpdate
3395
3613
  });
3396
3614
  return () => subscription.unsubscribe();
3397
- }, [config?.agentId, copilotkit]);
3615
+ }, [config?.agentId, copilotkit, forceUpdate]);
3398
3616
  const getStateSnapshotForMessage = (messageId) => {
3399
3617
  if (!config) return void 0;
3400
3618
  const runId = copilotkit.getRunIdForMessage(config.agentId, config.threadId, messageId);
@@ -3445,11 +3663,12 @@ function CopilotChatMessageView({
3445
3663
  )
3446
3664
  );
3447
3665
  } else if (message.role === "activity") {
3666
+ const activityMsg = message;
3448
3667
  elements.push(
3449
3668
  /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3450
3669
  MemoizedActivityMessage,
3451
3670
  {
3452
- message,
3671
+ message: activityMsg,
3453
3672
  renderActivityMessage
3454
3673
  },
3455
3674
  message.id
@@ -3912,8 +4131,9 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
3912
4131
  isRunning: agent.isRunning
3913
4132
  };
3914
4133
  finalInputProps.mode = agent.isRunning ? "processing" : finalInputProps.mode ?? "input";
4134
+ const messages = (0, import_react25.useMemo)(() => [...agent.messages], [JSON.stringify(agent.messages)]);
3915
4135
  const finalProps = (0, import_ts_deepmerge.merge)(mergedProps, {
3916
- messages: agent.messages,
4136
+ messages,
3917
4137
  inputProps: finalInputProps
3918
4138
  });
3919
4139
  const RenderedChatView = renderSlot(chatView, CopilotChatView, finalProps);
@@ -4581,7 +4801,6 @@ var WildcardToolCallRender = defineToolCallRenderer({
4581
4801
  useRenderCustomMessages,
4582
4802
  useRenderToolCall,
4583
4803
  useSuggestions,
4584
- ...require("@ag-ui/core"),
4585
4804
  ...require("@ag-ui/client")
4586
4805
  });
4587
4806
  //# sourceMappingURL=index.js.map