@copilotkit/react-core 1.62.3 → 1.63.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.
@@ -1815,6 +1815,34 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
1815
1815
 
1816
1816
  //#endregion
1817
1817
  //#region src/v2/components/MCPAppsActivityRenderer.tsx
1818
+ /**
1819
+ * Run an MCP app `ui/message` follow-up, scoped to the thread it was enqueued
1820
+ * for (issue #5819).
1821
+ *
1822
+ * The MCP request queue delays follow-up work until the agent is idle. There is
1823
+ * a single shared registry agent per id, and switching threads overwrites its
1824
+ * `threadId`/`messages` in place. So if the host switches threads while a
1825
+ * follow-up is queued, running it now would execute against — and stream into —
1826
+ * the now-foreground thread.
1827
+ *
1828
+ * - **Same thread** (the common case): run on the shared agent, unchanged.
1829
+ * - **Thread changed**: the shared agent has moved on, so the follow-up can no
1830
+ * longer run in its originating thread's context. Drop it rather than leak it
1831
+ * into the current thread. (The MCP app already received its `ui/message` ack
1832
+ * at enqueue time; only the optional agent turn is skipped.)
1833
+ *
1834
+ * @internal exported for testing.
1835
+ */
1836
+ async function ɵrunMcpFollowUp({ host, agent, capturedThreadId }) {
1837
+ const currentThreadId = agent.threadId || "default";
1838
+ const originThreadId = capturedThreadId || "default";
1839
+ if (currentThreadId === originThreadId) return host.runAgent({ agent });
1840
+ 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.`);
1841
+ return {
1842
+ result: void 0,
1843
+ newMessages: []
1844
+ };
1845
+ }
1818
1846
  const PROTOCOL_VERSION = "2025-06-18";
1819
1847
  function buildSandboxHTML(extraCspDomains) {
1820
1848
  const baseScriptSrc = "'self' 'wasm-unsafe-eval' 'unsafe-inline' 'unsafe-eval' blob: data: http://localhost:* https://localhost:*";
@@ -2137,7 +2165,14 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2137
2165
  content: textContent
2138
2166
  });
2139
2167
  sendResponse(msg.id, { isError: false });
2140
- if ((params.followUp ?? role === "user") && textContent) mcpAppsRequestQueue.enqueue(currentAgent, () => copilotkit.runAgent({ agent: currentAgent })).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
2168
+ if ((params.followUp ?? role === "user") && textContent) {
2169
+ const capturedThreadId = currentAgent.threadId || "default";
2170
+ mcpAppsRequestQueue.enqueue(currentAgent, () => ɵrunMcpFollowUp({
2171
+ host: copilotkit,
2172
+ agent: currentAgent,
2173
+ capturedThreadId
2174
+ })).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
2175
+ }
2141
2176
  } catch (err) {
2142
2177
  console.error("[MCPAppsRenderer] ui/message error:", err);
2143
2178
  sendResponse(msg.id, { isError: true });
@@ -3620,6 +3655,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3620
3655
  if (copilotkitRef.current === null) {
3621
3656
  copilotkitRef.current = new CopilotKitCoreReact({
3622
3657
  runtimeUrl: chatApiEndpoint,
3658
+ deferInitialConnection: true,
3623
3659
  runtimeTransport: useSingleEndpoint === true ? "single" : useSingleEndpoint === false ? "rest" : "auto",
3624
3660
  headers: mergedHeaders,
3625
3661
  credentials,
@@ -3703,6 +3739,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
3703
3739
  } : properties);
3704
3740
  copilotkit.setAgents__unsafe_dev_only(mergedAgents);
3705
3741
  copilotkit.setDebug(debug);
3742
+ copilotkit.connect();
3706
3743
  }, [
3707
3744
  copilotkit,
3708
3745
  chatApiEndpoint,
@@ -11514,12 +11551,17 @@ Object.defineProperty(exports, 'CopilotSidebarView', {
11514
11551
  }
11515
11552
  });
11516
11553
  exports.CopilotThreadsDrawer = CopilotThreadsDrawer;
11554
+ exports.GenerateSandboxedUiArgsSchema = GenerateSandboxedUiArgsSchema;
11517
11555
  exports.INTELLIGENCE_TURN_HEAD = INTELLIGENCE_TURN_HEAD;
11518
11556
  exports.IntelligenceIndicator = IntelligenceIndicator;
11519
11557
  exports.IntelligenceIndicatorView = IntelligenceIndicatorView;
11520
11558
  exports.MCPAppsActivityContentSchema = MCPAppsActivityContentSchema;
11521
11559
  exports.MCPAppsActivityRenderer = MCPAppsActivityRenderer;
11522
11560
  exports.MCPAppsActivityType = MCPAppsActivityType;
11561
+ exports.OpenGenerativeUIActivityRenderer = OpenGenerativeUIActivityRenderer;
11562
+ exports.OpenGenerativeUIActivityType = OpenGenerativeUIActivityType;
11563
+ exports.OpenGenerativeUIContentSchema = OpenGenerativeUIContentSchema;
11564
+ exports.OpenGenerativeUIToolRenderer = OpenGenerativeUIToolRenderer;
11523
11565
  exports.SandboxFunctionsContext = SandboxFunctionsContext;
11524
11566
  exports.UseAgentUpdate = UseAgentUpdate;
11525
11567
  exports.WildcardToolCallRender = WildcardToolCallRender;
@@ -11556,6 +11598,7 @@ exports.useRenderToolCall = useRenderToolCall;
11556
11598
  exports.useSandboxFunctions = useSandboxFunctions;
11557
11599
  exports.useSuggestions = useSuggestions;
11558
11600
  exports.useThreads = useThreads;
11601
+ exports.ɵrunMcpFollowUp = ɵrunMcpFollowUp;
11559
11602
  Object.keys(_copilotkit_core).forEach(function (k) {
11560
11603
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
11561
11604
  enumerable: true,