@copilotkit/react-core 1.76.0 → 1.77.1

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.
Files changed (42) hide show
  1. package/dist/{copilotkit-dHdNF7H5.cjs → copilotkit-BG1d4-qU.cjs} +326 -113
  2. package/dist/copilotkit-BG1d4-qU.cjs.map +1 -0
  3. package/dist/{copilotkit-W-bV_OSs.d.cts → copilotkit-BGHjMw0d.d.cts} +89 -3
  4. package/dist/copilotkit-BGHjMw0d.d.cts.map +1 -0
  5. package/dist/{copilotkit-B90cY0Zg.d.mts → copilotkit-BdH_CdBt.d.mts} +84 -3
  6. package/dist/copilotkit-BdH_CdBt.d.mts.map +1 -0
  7. package/dist/{copilotkit-LD7Gp2aV.mjs → copilotkit-C_Sy6Cc7.mjs} +315 -114
  8. package/dist/copilotkit-C_Sy6Cc7.mjs.map +1 -0
  9. package/dist/index.cjs +18 -8
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +8 -3
  12. package/dist/index.d.cts.map +1 -1
  13. package/dist/index.d.mts +8 -3
  14. package/dist/index.d.mts.map +1 -1
  15. package/dist/index.mjs +18 -8
  16. package/dist/index.mjs.map +1 -1
  17. package/dist/index.umd.js +88 -25
  18. package/dist/index.umd.js.map +1 -1
  19. package/dist/v2/context.cjs.map +1 -1
  20. package/dist/v2/context.d.cts +5 -0
  21. package/dist/v2/context.d.cts.map +1 -1
  22. package/dist/v2/context.d.mts +5 -0
  23. package/dist/v2/context.d.mts.map +1 -1
  24. package/dist/v2/context.mjs.map +1 -1
  25. package/dist/v2/headless.cjs +19 -0
  26. package/dist/v2/headless.cjs.map +1 -1
  27. package/dist/v2/headless.d.cts +5 -0
  28. package/dist/v2/headless.d.cts.map +1 -1
  29. package/dist/v2/headless.d.mts.map +1 -1
  30. package/dist/v2/headless.mjs +20 -1
  31. package/dist/v2/headless.mjs.map +1 -1
  32. package/dist/v2/index.cjs +3 -1
  33. package/dist/v2/index.d.cts +2 -2
  34. package/dist/v2/index.d.mts +2 -2
  35. package/dist/v2/index.mjs +2 -2
  36. package/dist/v2/index.umd.js +315 -112
  37. package/dist/v2/index.umd.js.map +1 -1
  38. package/package.json +22 -11
  39. package/dist/copilotkit-B90cY0Zg.d.mts.map +0 -1
  40. package/dist/copilotkit-LD7Gp2aV.mjs.map +0 -1
  41. package/dist/copilotkit-W-bV_OSs.d.cts.map +0 -1
  42. package/dist/copilotkit-dHdNF7H5.cjs.map +0 -1
@@ -171,6 +171,25 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
171
171
  parentConfig?.threadId,
172
172
  activeThreadOverride
173
173
  ]);
174
+ const copilotkit = (0, react.useContext)(_copilotkit_react_core_v2_context.CopilotKitContext)?.copilotkit;
175
+ const openThreadRef = (0, react.useRef)(null);
176
+ const latestThreadIdRef = (0, react.useRef)(resolvedThreadId);
177
+ latestThreadIdRef.current = resolvedThreadId;
178
+ (0, react.useEffect)(() => {
179
+ if (copilotkit === void 0) return;
180
+ const registration = copilotkit.registerOpenThread({
181
+ agentId: resolvedAgentId,
182
+ threadId: latestThreadIdRef.current
183
+ });
184
+ openThreadRef.current = registration;
185
+ return () => {
186
+ registration.unregister();
187
+ openThreadRef.current = null;
188
+ };
189
+ }, [copilotkit, resolvedAgentId]);
190
+ (0, react.useEffect)(() => {
191
+ openThreadRef.current?.update(resolvedThreadId);
192
+ }, [resolvedThreadId]);
174
193
  const resolvedHasExplicitThreadId = (threadIdPropIsAuthoritative ? true : activeThreadOverride?.explicit ?? hasExplicitThreadId ?? false) || !!parentConfig?.hasExplicitThreadId;
175
194
  const [internalModalOpen, setInternalModalOpen] = (0, react.useState)(isModalDefaultOpen ?? true);
176
195
  const hasExplicitDefault = isModalDefaultOpen !== void 0;
@@ -1636,7 +1655,7 @@ function useRenderToolCall() {
1636
1655
 
1637
1656
  //#endregion
1638
1657
  //#region package.json
1639
- var version = "1.76.0";
1658
+ var version = "1.77.1";
1640
1659
 
1641
1660
  //#endregion
1642
1661
  //#region src/v2/components/CopilotKitInspector.tsx
@@ -1872,12 +1891,14 @@ function InlineFeatureWarning({ featureName }) {
1872
1891
  * Fetches resource content on-demand via proxied MCP requests. The React shell
1873
1892
  * owns the iframe; `bindMcpApp` owns the protocol.
1874
1893
  */
1875
- const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
1894
+ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent }) {
1876
1895
  const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
1896
+ const messageId = message?.id;
1877
1897
  const containerRef = (0, react.useRef)(null);
1878
1898
  const iframeRef = (0, react.useRef)(null);
1879
1899
  const sessionRef = (0, react.useRef)(null);
1880
1900
  const [error, setError] = (0, react.useState)(null);
1901
+ const [contentError, setContentError] = (0, react.useState)(null);
1881
1902
  const [isLoading, setIsLoading] = (0, react.useState)(true);
1882
1903
  const [iframeSize, setIframeSize] = (0, react.useState)({});
1883
1904
  const [fetchedResource, setFetchedResource] = (0, react.useState)(null);
@@ -1896,6 +1917,7 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
1896
1917
  let mounted = true;
1897
1918
  setIsLoading(true);
1898
1919
  setError(null);
1920
+ setContentError(null);
1899
1921
  const iframe = document.createElement("iframe");
1900
1922
  iframe.style.width = "100%";
1901
1923
  iframe.style.height = "100px";
@@ -1918,6 +1940,7 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
1918
1940
  getContent: () => contentRef.current,
1919
1941
  getAgent: () => agentRef.current,
1920
1942
  host: copilotkit,
1943
+ messageId,
1921
1944
  hooks: {
1922
1945
  onResource: (resource) => {
1923
1946
  if (!mounted) return;
@@ -1927,6 +1950,9 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
1927
1950
  onSizeChanged: (size) => {
1928
1951
  if (mounted) setIframeSize(size);
1929
1952
  },
1953
+ onContentError: (err) => {
1954
+ if (mounted) setContentError(err);
1955
+ },
1930
1956
  onError: (err) => {
1931
1957
  if (!mounted) return;
1932
1958
  setError(err);
@@ -1935,9 +1961,7 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
1935
1961
  }
1936
1962
  });
1937
1963
  sessionRef.current = session;
1938
- const current = contentRef.current;
1939
- if (current.toolInput) session.sendToolInput(current.toolInput);
1940
- if (current.result) session.sendToolResult(current.result);
1964
+ session.syncContent(contentRef.current);
1941
1965
  } catch (err) {
1942
1966
  console.error("[MCPAppsRenderer] Setup error:", err);
1943
1967
  if (mounted) {
@@ -1957,6 +1981,7 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
1957
1981
  }, [
1958
1982
  agent,
1959
1983
  copilotkit,
1984
+ messageId,
1960
1985
  content.resourceUri,
1961
1986
  content.serverHash,
1962
1987
  content.serverId
@@ -1971,11 +1996,8 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
1971
1996
  }
1972
1997
  }, [iframeSize]);
1973
1998
  (0, react.useEffect)(() => {
1974
- if (content.toolInput) sessionRef.current?.sendToolInput(content.toolInput);
1975
- }, [content.toolInput]);
1976
- (0, react.useEffect)(() => {
1977
- if (content.result) sessionRef.current?.sendToolResult(content.result);
1978
- }, [content.result]);
1999
+ sessionRef.current?.syncContent(contentRef.current);
2000
+ }, [content.toolInput, content.result]);
1979
2001
  const borderStyle = fetchedResource?._meta?.ui?.prefersBorder === true ? {
1980
2002
  borderRadius: "8px",
1981
2003
  backgroundColor: "#f9f9f9",
@@ -1997,12 +2019,12 @@ const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agen
1997
2019
  color: "#666"
1998
2020
  },
1999
2021
  children: "Loading..."
2000
- }), error && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2022
+ }), (error ?? contentError) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
2001
2023
  style: {
2002
2024
  color: "red",
2003
2025
  padding: "1rem"
2004
2026
  },
2005
- children: ["Error: ", error.message]
2027
+ children: ["Error: ", (error ?? contentError).message]
2006
2028
  })]
2007
2029
  });
2008
2030
  };
@@ -3390,7 +3412,6 @@ const DEFAULT_DESIGN_SKILL = `When generating UI with generateSandboxedUi, follo
3390
3412
  - Use CSS Grid or Flexbox for layout. Ensure the UI looks good at any width.
3391
3413
  - Minimal transitions (150ms) for hover/focus states only. No decorative animations.
3392
3414
  - Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
3393
- const GENERATE_SANDBOXED_UI_DESCRIPTION = "Generate sandboxed UI. IMPORTANT: The generated code runs in a sandboxed iframe WITHOUT same-origin access. Do NOT use localStorage, sessionStorage, document.cookie, IndexedDB, or fetch/XMLHttpRequest to same-origin URLs. To communicate with the host application, use Websandbox.connection.remote.<functionName>(args) which returns a Promise.\n\nYou CAN use external libraries from CDNs by including <script> or <link> tags in the HTML <head> (e.g., Chart.js, D3, Three.js, x-data-spreadsheet, etc.). CDN resources load normally inside the sandbox.\n\nPARAMETER ORDER IS CRITICAL — generate parameters in exactly this order:\n1. initialHeight + placeholderMessages (shown to user while generating)\n2. css (all styles FIRST — the user sees a placeholder until CSS is complete)\n3. html (streams in live — the user watches the UI build as HTML is generated)\n4. jsFunctions (reusable helper functions)\n5. jsExpressions (applied one-by-one — the user sees each expression take effect)";
3394
3415
  function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
3395
3416
  const empty = (0, react.useMemo)(() => [], []);
3396
3417
  const value = prop ?? empty;
@@ -3400,7 +3421,7 @@ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
3400
3421
  }, [value, warningMessage]);
3401
3422
  return value;
3402
3423
  }
3403
- const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, messageFilter, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, agentId, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug }) => {
3424
+ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY_HEADERS, credentials, messageFilter, publicApiKey, publicLicenseKey, licenseToken, properties = EMPTY_PROPERTIES, agents__unsafe_dev_only: agents = EMPTY_AGENTS, selfManagedAgents = EMPTY_AGENTS, renderToolCalls, renderActivityMessages, renderCustomMessages, frontendTools, humanInTheLoop, openGenerativeUI, enableInspector, agentId, showIntelligenceIndicator = true, useSingleEndpoint, onError, a2ui, defaultThrottleMs, debug, learning }) => {
3404
3425
  const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
3405
3426
  const [inspectorVisible, setInspectorVisible] = (0, react.useState)(false);
3406
3427
  (0, react.useEffect)(() => {
@@ -3583,7 +3604,7 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3583
3604
  if (!openGenUIActive) return [];
3584
3605
  return [{
3585
3606
  name: "generateSandboxedUi",
3586
- description: GENERATE_SANDBOXED_UI_DESCRIPTION,
3607
+ description: _copilotkit_shared.GENERATE_SANDBOXED_UI_DESCRIPTION,
3587
3608
  parameters: GenerateSandboxedUiArgsSchema,
3588
3609
  handler: async () => "UI generated",
3589
3610
  followUp: true,
@@ -3635,7 +3656,8 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3635
3656
  renderToolCalls: allRenderToolCalls,
3636
3657
  renderActivityMessages: allActivityRenderers,
3637
3658
  renderCustomMessages: renderCustomMessagesList,
3638
- debug
3659
+ debug,
3660
+ learning
3639
3661
  });
3640
3662
  if (defaultThrottleMs !== void 0) copilotkitRef.current.setDefaultThrottleMs(defaultThrottleMs);
3641
3663
  }
@@ -3740,6 +3762,32 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3740
3762
  useSingleEndpoint,
3741
3763
  debug
3742
3764
  ]);
3765
+ const learningEnabled = learning !== void 0;
3766
+ const trajectoryId = learning?.trajectoryId;
3767
+ const learningContainerIdsRef = (0, react.useRef)(learning?.learningContainerIds);
3768
+ (0, react.useEffect)(() => {
3769
+ copilotkit.setLearningConfig(learning);
3770
+ learningContainerIdsRef.current = learning?.learningContainerIds;
3771
+ if (learning?.sink === void 0 && learning?.trajectoryId === void 0 && learning?.learningContainerIds !== void 0) console.warn("[CopilotKit] learningContainerIds is supported only with a custom sink. Authenticated Trajectory capture does not assign Learning Containers; remove learningContainerIds from the capture options.");
3772
+ }, [copilotkit, learning]);
3773
+ (0, react.useEffect)(() => {
3774
+ if (!learningEnabled) return;
3775
+ let disposed = false;
3776
+ if (trajectoryId !== void 0) copilotkit.startTrajectory({
3777
+ trajectoryId,
3778
+ learningContainerIds: learningContainerIdsRef.current
3779
+ }).catch(() => {
3780
+ if (!disposed) console.warn("[CopilotKit] Failed to start interaction capture.");
3781
+ });
3782
+ return () => {
3783
+ disposed = true;
3784
+ copilotkit.stopTrajectory();
3785
+ };
3786
+ }, [
3787
+ copilotkit,
3788
+ learningEnabled,
3789
+ trajectoryId
3790
+ ]);
3743
3791
  const didMountRef = (0, react.useRef)(false);
3744
3792
  (0, react.useEffect)(() => {
3745
3793
  if (!didMountRef.current) return;
@@ -3802,8 +3850,13 @@ const CopilotKitProvider = ({ children, runtimeUrl, headers: headersProp = EMPTY
3802
3850
  ]);
3803
3851
  const contextValue = (0, react.useMemo)(() => ({
3804
3852
  copilotkit,
3805
- executingToolCallIds
3806
- }), [copilotkit, executingToolCallIds]);
3853
+ executingToolCallIds,
3854
+ showIntelligenceIndicator
3855
+ }), [
3856
+ copilotkit,
3857
+ executingToolCallIds,
3858
+ showIntelligenceIndicator
3859
+ ]);
3807
3860
  const retryableRuntimeEntitlementFailure = runtimeEntitlements?.status !== "ready" && runtimeEntitlements?.error.retryable === true;
3808
3861
  const hasNonReadyRuntimeEntitlement = runtimeEntitlements !== void 0 && runtimeEntitlements.status !== "ready";
3809
3862
  const hasLegacyRuntimeEntitlementFallback = runtimeLicenseStatus === "valid" || runtimeLicenseStatus === "expiring";
@@ -6037,13 +6090,23 @@ function useLearningContainersInCurrentThread({ learningContainers }) {
6037
6090
  //#region src/v2/components/chat/CopilotChatToolCallsView.tsx
6038
6091
  function CopilotChatToolCallsView({ message, messages = [] }) {
6039
6092
  const renderToolCall = useRenderToolCall();
6093
+ const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
6094
+ const subscribe = (0, react.useCallback)((onChange) => copilotkit.ɵsubscribeToLearningConfigured(onChange), [copilotkit]);
6095
+ const getSnapshot = () => copilotkit.ɵlearningConfigured;
6096
+ const learningConfigured = (0, react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
6040
6097
  if (!message.toolCalls || message.toolCalls.length === 0) return null;
6041
6098
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: message.toolCalls.map((toolCall) => {
6042
- const toolMessage = messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id);
6043
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: renderToolCall({
6099
+ const rendered = renderToolCall({
6044
6100
  toolCall,
6045
- toolMessage
6046
- }) }, toolCall.id);
6101
+ toolMessage: messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id)
6102
+ });
6103
+ if (rendered === null) return null;
6104
+ if (!learningConfigured) return rendered;
6105
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6106
+ "data-tool-call-id": toolCall.id,
6107
+ style: { display: "contents" },
6108
+ children: rendered
6109
+ }, toolCall.id);
6047
6110
  }) });
6048
6111
  }
6049
6112
 
@@ -6387,6 +6450,7 @@ function CopilotChatAssistantMessage({ message, messages, isRunning, isLatest, o
6387
6450
  const shouldShowToolbar = toolbarVisible && (hasContent || showInspectorShortcut) && !(isRunning && isLatestAssistantMessage);
6388
6451
  if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
6389
6452
  "data-copilotkit": true,
6453
+ "data-message-id": message.id,
6390
6454
  style: { display: "contents" },
6391
6455
  children: children({
6392
6456
  markdownRenderer: boundMarkdownRenderer,
@@ -7619,12 +7683,27 @@ function deduplicateMessages(messages) {
7619
7683
  }
7620
7684
  return [...acc.values()];
7621
7685
  }
7686
+ /** A row holding a single message, rendered as it would be ungrouped. */
7687
+ function messageRow(message) {
7688
+ return {
7689
+ type: "message",
7690
+ message
7691
+ };
7692
+ }
7693
+ /** A row holding a group of messages, rendered inside `wrapper`. */
7694
+ function messageGroup(group) {
7695
+ return {
7696
+ type: "group",
7697
+ ...group
7698
+ };
7699
+ }
7700
+ const GROUP_ROW_KEY_PREFIX = "copilotkit-group:";
7622
7701
  const VIRTUALIZE_THRESHOLD = 50;
7623
- function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, isRunning = false, transformMessages, children, className, ...props }) {
7702
+ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, isRunning = false, transformMessages, groupMessages, children, className, ...props }) {
7624
7703
  const isPinnedToBottom = (0, react.useContext)(ScrollPinnedContext);
7625
7704
  const renderCustomMessage = useRenderCustomMessages();
7626
7705
  const { renderActivityMessage } = useRenderActivityMessage();
7627
- const { copilotkit } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
7706
+ const { copilotkit, showIntelligenceIndicator = true } = (0, _copilotkit_react_core_v2_context.useCopilotKit)();
7628
7707
  const config = useCopilotChatConfiguration();
7629
7708
  const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
7630
7709
  (0, react.useEffect)(() => {
@@ -7653,20 +7732,43 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7653
7732
  return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
7654
7733
  };
7655
7734
  const deduplicatedMessages = (0, react.useMemo)(() => deduplicateMessages(messages), [messages]);
7656
- const renderedMessages = (0, react.useMemo)(() => transformMessages ? transformMessages(deduplicatedMessages) : deduplicatedMessages, [deduplicatedMessages, transformMessages]);
7735
+ const transformedMessages = (0, react.useMemo)(() => transformMessages ? transformMessages(deduplicatedMessages) : deduplicatedMessages, [deduplicatedMessages, transformMessages]);
7736
+ const rows = (0, react.useMemo)(() => groupMessages ? groupMessages(transformedMessages) : transformedMessages.map(messageRow), [transformedMessages, groupMessages]);
7737
+ const renderedMessages = (0, react.useMemo)(() => groupMessages ? rows.flatMap((row) => row.type === "group" ? row.messages : [row.message]) : transformedMessages, [
7738
+ rows,
7739
+ groupMessages,
7740
+ transformedMessages
7741
+ ]);
7657
7742
  const latestRenderedId = renderedMessages[renderedMessages.length - 1]?.id;
7658
7743
  const transformDuplicateId = (0, react.useMemo)(() => {
7659
- if (process.env.NODE_ENV === "production" || !transformMessages) return;
7744
+ if (process.env.NODE_ENV === "production" || !transformMessages && !groupMessages) return;
7660
7745
  const seen = /* @__PURE__ */ new Set();
7661
7746
  for (const message of renderedMessages) {
7662
7747
  if (seen.has(message.id)) return message.id;
7663
7748
  seen.add(message.id);
7664
7749
  }
7665
- }, [renderedMessages, transformMessages]);
7750
+ }, [
7751
+ renderedMessages,
7752
+ transformMessages,
7753
+ groupMessages
7754
+ ]);
7666
7755
  (0, react.useEffect)(() => {
7667
7756
  if (transformDuplicateId === void 0) return;
7668
- console.warn(`[CopilotKit] CopilotChatMessageView: \`transformMessages\` returned more than one message with id "${transformDuplicateId}". Return each id at most once; a message you create needs its own id, stable across renders.`);
7669
- }, [transformDuplicateId]);
7757
+ console.warn(groupMessages ? `[CopilotKit] CopilotChatMessageView: the message with id "${transformDuplicateId}" renders more than once. \`groupMessages\` should place each message in at most one row, and \`transformMessages\` return each id at most once.` : `[CopilotKit] CopilotChatMessageView: \`transformMessages\` returned more than one message with id "${transformDuplicateId}". Return each id at most once; a message you create needs its own id, stable across renders.`);
7758
+ }, [transformDuplicateId, groupMessages]);
7759
+ const duplicateGroupKey = (0, react.useMemo)(() => {
7760
+ if (process.env.NODE_ENV === "production" || !groupMessages) return;
7761
+ const seen = /* @__PURE__ */ new Set();
7762
+ for (const row of rows) {
7763
+ if (row.type !== "group") continue;
7764
+ if (seen.has(row.key)) return row.key;
7765
+ seen.add(row.key);
7766
+ }
7767
+ }, [rows, groupMessages]);
7768
+ (0, react.useEffect)(() => {
7769
+ if (duplicateGroupKey === void 0) return;
7770
+ console.warn(`[CopilotKit] CopilotChatMessageView: \`groupMessages\` returned more than one group with key "${duplicateGroupKey}". Give each group its own key, stable across renders.`);
7771
+ }, [duplicateGroupKey]);
7670
7772
  const rowKeyStoreRef = (0, react.useRef)(null);
7671
7773
  rowKeyStoreRef.current ??= (0, _copilotkit_shared.createRowKeyStore)();
7672
7774
  const rowKeyStore = rowKeyStoreRef.current;
@@ -7674,6 +7776,31 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7674
7776
  (0, react.useLayoutEffect)(() => {
7675
7777
  (0, _copilotkit_shared.commitRowKeyStore)(rowKeyStore, renderedMessages);
7676
7778
  }, [rowKeyStore, renderedMessages]);
7779
+ const stableGroupKey = (key) => rowRenderKeys.get(key) ?? key;
7780
+ const groupStateRef = (0, react.useRef)(/* @__PURE__ */ new Map());
7781
+ const groupSettersRef = (0, react.useRef)(/* @__PURE__ */ new Map());
7782
+ const groupStateThreadRef = (0, react.useRef)(config?.threadId);
7783
+ if (groupStateThreadRef.current !== config?.threadId) {
7784
+ groupStateThreadRef.current = config?.threadId;
7785
+ groupStateRef.current = /* @__PURE__ */ new Map();
7786
+ groupSettersRef.current = /* @__PURE__ */ new Map();
7787
+ }
7788
+ const groupSetter = (key) => {
7789
+ let setter = groupSettersRef.current.get(key);
7790
+ if (!setter) {
7791
+ setter = (next) => {
7792
+ groupStateRef.current.set(key, next);
7793
+ forceUpdate();
7794
+ };
7795
+ groupSettersRef.current.set(key, setter);
7796
+ }
7797
+ return setter;
7798
+ };
7799
+ (0, react.useLayoutEffect)(() => {
7800
+ const live = /* @__PURE__ */ new Set();
7801
+ for (const row of rows) if (row.type === "group") live.add(stableGroupKey(row.key));
7802
+ for (const store of [groupStateRef.current, groupSettersRef.current]) for (const key of store.keys()) if (!live.has(key)) store.delete(key);
7803
+ }, [rows, rowRenderKeys]);
7677
7804
  if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView: Merged ${messages.length - deduplicatedMessages.length} message(s) with duplicate IDs.`);
7678
7805
  const { Component: AssistantComponent, slotProps: assistantSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(assistantMessage, CopilotChatAssistantMessage_default), [assistantMessage]);
7679
7806
  const agentId = config?.agentId;
@@ -7713,7 +7840,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7713
7840
  (0, react.useEffect)(() => {
7714
7841
  if (process.env.NODE_ENV === "production" || !childrenDisabledVirtualization || warnedChildrenRef.current) return;
7715
7842
  warnedChildrenRef.current = true;
7716
- console.warn(`[CopilotKit] CopilotChatMessageView: the \`children\` render prop disables virtualization, so all ${renderedMessages.length} messages are mounted. ` + (transformMessages ? "`transformMessages` keeps virtualization on by itself; drop `children` to use it." : "To reshape the list and keep virtualization, use `transformMessages` instead."));
7843
+ console.warn(`[CopilotKit] CopilotChatMessageView: the \`children\` render prop disables virtualization, so all ${renderedMessages.length} messages are mounted. ` + (transformMessages || groupMessages ? "`transformMessages` and `groupMessages` keep virtualization on by themselves; drop `children` to use them." : "To reshape the list and keep virtualization, use `transformMessages` instead, or `groupMessages` to render several messages as one row."));
7717
7844
  }, [
7718
7845
  childrenDisabledVirtualization,
7719
7846
  renderedMessages.length,
@@ -7753,7 +7880,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7753
7880
  return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
7754
7881
  }, []);
7755
7882
  const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
7756
- count: shouldVirtualize ? renderedMessages.length : 0,
7883
+ count: shouldVirtualize ? rows.length : 0,
7757
7884
  getScrollElement: () => scrollElement,
7758
7885
  estimateSize: estimateRowSize,
7759
7886
  overscan: 5,
@@ -7766,8 +7893,8 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7766
7893
  isPinnedToBottomRef.current = isPinnedToBottom;
7767
7894
  virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
7768
7895
  (0, react.useLayoutEffect)(() => {
7769
- if (!shouldVirtualize || !renderedMessages.length) return;
7770
- virtualizer.scrollToIndex(renderedMessages.length - 1, { align: "end" });
7896
+ if (!shouldVirtualize || !rows.length) return;
7897
+ virtualizer.scrollToIndex(rows.length - 1, { align: "end" });
7771
7898
  }, [shouldVirtualize, firstMessageId]);
7772
7899
  const intelligenceTurnAnchors = (0, react.useMemo)(() => getIntelligenceTurnAnchors(deduplicatedMessages, renderedMessages), [deduplicatedMessages, renderedMessages]);
7773
7900
  const renderMessageBlock = (message) => {
@@ -7811,7 +7938,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7811
7938
  renderCustomMessage,
7812
7939
  stateSnapshot
7813
7940
  }, `${rowKey}-custom-after`));
7814
- const intelligenceTurnId = intelligenceTurnAnchors.get(message.id);
7941
+ const intelligenceTurnId = showIntelligenceIndicator ? intelligenceTurnAnchors.get(message.id) : void 0;
7815
7942
  if (intelligenceTurnId !== void 0) elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntelligenceIndicator, {
7816
7943
  message,
7817
7944
  agentId: config?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID,
@@ -7819,7 +7946,20 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7819
7946
  }, `intelligence-${intelligenceTurnId}`));
7820
7947
  return elements.filter(Boolean);
7821
7948
  };
7822
- const messageElements = shouldVirtualize ? [] : renderedMessages.flatMap(renderMessageBlock);
7949
+ const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : rowRenderKeys.get(row.message.id) ?? row.message.id;
7950
+ const renderRow = (row) => {
7951
+ if (row.type === "message") return renderMessageBlock(row.message);
7952
+ const Wrapper = row.wrapper;
7953
+ const stateKey = stableGroupKey(row.key);
7954
+ return [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
7955
+ groupKey: row.key,
7956
+ messages: row.messages,
7957
+ state: groupStateRef.current.get(stateKey),
7958
+ setState: groupSetter(stateKey),
7959
+ children: row.messages.flatMap(renderMessageBlock)
7960
+ }, rowKey(row))];
7961
+ };
7962
+ const messageElements = shouldVirtualize ? [] : rows.flatMap(renderRow);
7823
7963
  if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
7824
7964
  "data-copilotkit": true,
7825
7965
  style: { display: "contents" },
@@ -7844,7 +7984,7 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7844
7984
  position: "relative"
7845
7985
  },
7846
7986
  children: virtualizer.getVirtualItems().map((virtualItem) => {
7847
- const message = renderedMessages[virtualItem.index];
7987
+ const row = rows[virtualItem.index];
7848
7988
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
7849
7989
  "data-index": virtualItem.index,
7850
7990
  ref: virtualizer.measureElement,
@@ -7855,8 +7995,8 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
7855
7995
  width: "100%",
7856
7996
  transform: `translateY(${virtualItem.start}px)`
7857
7997
  },
7858
- children: renderMessageBlock(message)
7859
- }, rowRenderKeys.get(message.id) ?? message.id);
7998
+ children: renderRow(row)
7999
+ }, rowKey(row));
7860
8000
  })
7861
8001
  }) : messageElements,
7862
8002
  interruptElement,
@@ -8924,6 +9064,29 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
8924
9064
  const [lastConnectedThreadId, setLastConnectedThreadId] = (0, react.useState)(null);
8925
9065
  const isConnecting = hasExplicitThreadId && lastConnectedThreadId !== resolvedThreadId;
8926
9066
  const activeConnectCountRef = (0, react.useRef)(0);
9067
+ const pendingConnectionsRef = (0, react.useRef)(/* @__PURE__ */ new Map());
9068
+ const failedConnectionsRef = (0, react.useRef)(/* @__PURE__ */ new WeakSet());
9069
+ const submissionQueueRef = (0, react.useRef)(Promise.resolve());
9070
+ const trackConnection = (0, react.useCallback)((connectingAgent, connect) => {
9071
+ const selection = previousThreadRef.current;
9072
+ const connectingThreadId = connectingAgent.threadId;
9073
+ let failed = false;
9074
+ const subscription = copilotkit.subscribe({ onError: (event) => {
9075
+ if (selection?.active && previousThreadRef.current === selection && event.context?.agentId === connectingAgent.agentId && (!event.context.threadId || event.context.threadId === connectingThreadId) && (event.code === _copilotkit_core.CopilotKitCoreErrorCode.AGENT_CONNECT_FAILED || event.code === _copilotkit_core.CopilotKitCoreErrorCode.AGENT_RUN_FAILED_EVENT)) failed = true;
9076
+ } });
9077
+ const pending = connect().catch((error) => {
9078
+ failed = true;
9079
+ console.error("CopilotChat: connection failed", error);
9080
+ }).finally(() => {
9081
+ subscription.unsubscribe();
9082
+ if (pendingConnectionsRef.current.get(connectingAgent) === pending) {
9083
+ pendingConnectionsRef.current.delete(connectingAgent);
9084
+ if (selection?.active && previousThreadRef.current === selection) if (failed) failedConnectionsRef.current.add(connectingAgent);
9085
+ else failedConnectionsRef.current.delete(connectingAgent);
9086
+ }
9087
+ });
9088
+ pendingConnectionsRef.current.set(connectingAgent, pending);
9089
+ }, [copilotkit]);
8927
9090
  const pendingRunActivityReconnectRef = (0, react.useRef)(false);
8928
9091
  const runActivityReconnectGenerationRef = (0, react.useRef)(0);
8929
9092
  const activeLocalRunIdsRef = (0, react.useRef)(/* @__PURE__ */ new Set());
@@ -8983,9 +9146,12 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
8983
9146
  const selection = {
8984
9147
  threadId: resolvedThreadId,
8985
9148
  inspectorRequestId,
8986
- agent
9149
+ agent,
9150
+ active: true
8987
9151
  };
8988
9152
  previousThreadRef.current = selection;
9153
+ submissionQueueRef.current = Promise.resolve();
9154
+ failedConnectionsRef.current.delete(agent);
8989
9155
  const discardedThreadId = previousThread?.agent === agent ? previousThread.threadId : agent.threadId;
8990
9156
  if (inspectorTransition) if (typeof copilotkit.stopAgent === "function") copilotkit.stopAgent({ agent });
8991
9157
  else agent.abortRun?.();
@@ -9023,6 +9189,7 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9023
9189
  }
9024
9190
  return () => {
9025
9191
  active = false;
9192
+ selection.active = false;
9026
9193
  };
9027
9194
  }
9028
9195
  let detached = false;
@@ -9036,8 +9203,8 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9036
9203
  await copilotkit.connectAgent({ agent: agentToConnect });
9037
9204
  } catch (error) {
9038
9205
  if (detached) return;
9039
- console.error("CopilotChat: connectAgent failed", error);
9040
9206
  if (inspectorRequestId) failInspectorOverride(inspectorRequestId);
9207
+ throw error;
9041
9208
  } finally {
9042
9209
  if (!detached) (typeof requestAnimationFrame === "function" ? requestAnimationFrame : (cb) => setTimeout(cb, 16))(() => {
9043
9210
  if (!detached) setLastConnectedThreadId(resolvedThreadId);
@@ -9053,8 +9220,9 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9053
9220
  }
9054
9221
  }
9055
9222
  };
9056
- connect(agent);
9223
+ trackConnection(agent, () => connect(agent));
9057
9224
  return () => {
9225
+ selection.active = false;
9058
9226
  detached = true;
9059
9227
  connectAbortController.abort();
9060
9228
  const detach = agent.detachActiveRun().catch(() => {});
@@ -9117,7 +9285,7 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9117
9285
  await copilotkit.connectAgent({ agent });
9118
9286
  didConnect = true;
9119
9287
  } catch (error) {
9120
- if (!detached) console.error("CopilotChat: run activity reconnect failed", error);
9288
+ if (!detached) throw error;
9121
9289
  } finally {
9122
9290
  if (wakeRunId) {
9123
9291
  activeWakeRunIdsRef.current.delete(wakeRunId);
@@ -9127,7 +9295,7 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9127
9295
  wakeReconnectActive = false;
9128
9296
  if (!detached && runActivityReconnectGenerationRef.current === generation && activeConnectCountRef.current === 0 && pendingRunActivityReconnectRef.current) {
9129
9297
  pendingRunActivityReconnectRef.current = false;
9130
- connect();
9298
+ trackConnection(agent, connect);
9131
9299
  }
9132
9300
  }
9133
9301
  };
@@ -9143,7 +9311,7 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9143
9311
  return;
9144
9312
  }
9145
9313
  pendingRunActivityReconnectRef.current = false;
9146
- connect();
9314
+ trackConnection(agent, connect);
9147
9315
  };
9148
9316
  const subscription = threadStore.subscribeToRunActivity((notification) => {
9149
9317
  if (notification.threadId !== resolvedThreadId) return;
@@ -9186,6 +9354,18 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9186
9354
  rememberRecentlyWakeRunId
9187
9355
  ]);
9188
9356
  const waitForActiveRunToSettle = (0, react.useCallback)(async () => {
9357
+ const selection = previousThreadRef.current;
9358
+ const isCurrentSelection = () => selection?.active && previousThreadRef.current === selection;
9359
+ let connection = pendingConnectionsRef.current.get(agent);
9360
+ while (connection && isCurrentSelection()) {
9361
+ await connection;
9362
+ connection = pendingConnectionsRef.current.get(agent);
9363
+ }
9364
+ if (!isCurrentSelection()) return false;
9365
+ if (failedConnectionsRef.current.has(agent)) {
9366
+ setTranscriptionError("Could not load saved conversation. Reopen the thread and try again.");
9367
+ return "failed";
9368
+ }
9189
9369
  const maybeAware = agent;
9190
9370
  const activeRunCompletionPromise = (0, _copilotkit_core.isRunCompletionAware)(maybeAware) ? maybeAware.activeRunCompletionPromise : void 0;
9191
9371
  if (agent.isRunning && activeRunCompletionPromise) try {
@@ -9193,7 +9373,18 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9193
9373
  } catch (error) {
9194
9374
  console.error("CopilotChat: in-flight run rejected while queuing send", error);
9195
9375
  }
9376
+ return isCurrentSelection();
9196
9377
  }, [agent]);
9378
+ const enqueueSubmission = (0, react.useCallback)((submit) => {
9379
+ const selection = previousThreadRef.current;
9380
+ const pending = submissionQueueRef.current.then(async () => {
9381
+ if (selection?.active && previousThreadRef.current === selection) await submit();
9382
+ }).catch((error) => {
9383
+ console.error("CopilotChat: queued submission failed", error);
9384
+ });
9385
+ submissionQueueRef.current = pending;
9386
+ return pending;
9387
+ }, []);
9197
9388
  const onSubmitInput = (0, react.useCallback)(async (value) => {
9198
9389
  if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
9199
9390
  console.error("[CopilotKit] Cannot send while attachments are uploading (pre-await guard)");
@@ -9201,92 +9392,102 @@ function CopilotChat({ agentId, threadId, labels, inspectorTools, chatView, isMo
9201
9392
  return;
9202
9393
  }
9203
9394
  setInputValue("");
9204
- await waitForActiveRunToSettle();
9205
- if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
9206
- console.error("[CopilotKit] Cannot send while attachments are uploading (post-await re-check)");
9207
- setTranscriptionError("Cannot send while attachments are uploading.");
9208
- setInputValue(value);
9209
- return;
9210
- }
9211
- const readyAttachments = consumeAttachments();
9212
- if (readyAttachments.length > 0) {
9213
- const contentParts = [];
9214
- if (value.trim()) contentParts.push({
9215
- type: "text",
9216
- text: value
9217
- });
9218
- for (const att of readyAttachments) contentParts.push((0, _copilotkit_shared.createAttachmentContent)(att));
9219
- agent.addMessage({
9395
+ await enqueueSubmission(async () => {
9396
+ const ready = await waitForActiveRunToSettle();
9397
+ if (ready !== true) {
9398
+ if (ready === "failed") setInputValue(value);
9399
+ return;
9400
+ }
9401
+ if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
9402
+ console.error("[CopilotKit] Cannot send while attachments are uploading (post-await re-check)");
9403
+ setTranscriptionError("Cannot send while attachments are uploading.");
9404
+ setInputValue(value);
9405
+ return;
9406
+ }
9407
+ const readyAttachments = consumeAttachments();
9408
+ if (readyAttachments.length > 0) {
9409
+ const contentParts = [];
9410
+ if (value.trim()) contentParts.push({
9411
+ type: "text",
9412
+ text: value
9413
+ });
9414
+ for (const att of readyAttachments) contentParts.push((0, _copilotkit_shared.createAttachmentContent)(att));
9415
+ agent.addMessage({
9416
+ id: (0, _copilotkit_shared.randomUUID)(),
9417
+ role: "user",
9418
+ content: contentParts
9419
+ });
9420
+ } else agent.addMessage({
9220
9421
  id: (0, _copilotkit_shared.randomUUID)(),
9221
9422
  role: "user",
9222
- content: contentParts
9223
- });
9224
- } else agent.addMessage({
9225
- id: (0, _copilotkit_shared.randomUUID)(),
9226
- role: "user",
9227
- content: value
9228
- });
9229
- const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
9230
- if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
9231
- try {
9232
- await copilotkit.runAgent({
9233
- agent,
9234
- ...localRunId !== void 0 ? { runId: localRunId } : {}
9423
+ content: value
9235
9424
  });
9236
- } catch (error) {
9237
- console.error("CopilotChat: runAgent failed", error);
9238
- } finally {
9239
- if (localRunId) {
9240
- activeLocalRunIdsRef.current.delete(localRunId);
9241
- rememberRecentlyLocalRunId(localRunId);
9242
- }
9243
- if (pendingRunActivityReconnectRef.current && activeLocalRunIdsRef.current.size === 0 && activeConnectCountRef.current === 0) {
9244
- const startReconnect = startRunActivityReconnectRef.current;
9245
- if (startReconnect) {
9246
- pendingRunActivityReconnectRef.current = false;
9247
- startReconnect(runActivityReconnectGenerationRef.current);
9425
+ const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
9426
+ if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
9427
+ try {
9428
+ await copilotkit.runAgent({
9429
+ agent,
9430
+ ...localRunId !== void 0 ? { runId: localRunId } : {}
9431
+ });
9432
+ } catch (error) {
9433
+ console.error("CopilotChat: runAgent failed", error);
9434
+ } finally {
9435
+ if (localRunId) {
9436
+ activeLocalRunIdsRef.current.delete(localRunId);
9437
+ rememberRecentlyLocalRunId(localRunId);
9438
+ }
9439
+ if (pendingRunActivityReconnectRef.current && activeLocalRunIdsRef.current.size === 0 && activeConnectCountRef.current === 0) {
9440
+ const startReconnect = startRunActivityReconnectRef.current;
9441
+ if (startReconnect) {
9442
+ pendingRunActivityReconnectRef.current = false;
9443
+ startReconnect(runActivityReconnectGenerationRef.current);
9444
+ }
9248
9445
  }
9249
9446
  }
9250
- }
9447
+ });
9251
9448
  }, [
9252
9449
  agent,
9253
9450
  consumeAttachments,
9254
9451
  waitForActiveRunToSettle,
9452
+ enqueueSubmission,
9255
9453
  hasNativeIntelligenceRunActivity,
9256
9454
  rememberRecentlyLocalRunId
9257
9455
  ]);
9258
9456
  const handleSelectSuggestion = (0, react.useCallback)(async (suggestion) => {
9259
- await waitForActiveRunToSettle();
9260
- agent.addMessage({
9261
- id: (0, _copilotkit_shared.randomUUID)(),
9262
- role: "user",
9263
- content: suggestion.message
9264
- });
9265
- const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
9266
- if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
9267
- try {
9268
- await copilotkit.runAgent({
9269
- agent,
9270
- ...localRunId !== void 0 ? { runId: localRunId } : {}
9457
+ await enqueueSubmission(async () => {
9458
+ if (await waitForActiveRunToSettle() !== true) return;
9459
+ agent.addMessage({
9460
+ id: (0, _copilotkit_shared.randomUUID)(),
9461
+ role: "user",
9462
+ content: suggestion.message
9271
9463
  });
9272
- } catch (error) {
9273
- console.error("CopilotChat: runAgent failed after selecting suggestion", error);
9274
- } finally {
9275
- if (localRunId) {
9276
- activeLocalRunIdsRef.current.delete(localRunId);
9277
- rememberRecentlyLocalRunId(localRunId);
9278
- }
9279
- if (pendingRunActivityReconnectRef.current && activeLocalRunIdsRef.current.size === 0 && activeConnectCountRef.current === 0) {
9280
- const startReconnect = startRunActivityReconnectRef.current;
9281
- if (startReconnect) {
9282
- pendingRunActivityReconnectRef.current = false;
9283
- startReconnect(runActivityReconnectGenerationRef.current);
9464
+ const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
9465
+ if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
9466
+ try {
9467
+ await copilotkit.runAgent({
9468
+ agent,
9469
+ ...localRunId !== void 0 ? { runId: localRunId } : {}
9470
+ });
9471
+ } catch (error) {
9472
+ console.error("CopilotChat: runAgent failed after selecting suggestion", error);
9473
+ } finally {
9474
+ if (localRunId) {
9475
+ activeLocalRunIdsRef.current.delete(localRunId);
9476
+ rememberRecentlyLocalRunId(localRunId);
9477
+ }
9478
+ if (pendingRunActivityReconnectRef.current && activeLocalRunIdsRef.current.size === 0 && activeConnectCountRef.current === 0) {
9479
+ const startReconnect = startRunActivityReconnectRef.current;
9480
+ if (startReconnect) {
9481
+ pendingRunActivityReconnectRef.current = false;
9482
+ startReconnect(runActivityReconnectGenerationRef.current);
9483
+ }
9284
9484
  }
9285
9485
  }
9286
- }
9486
+ });
9287
9487
  }, [
9288
9488
  agent,
9289
9489
  waitForActiveRunToSettle,
9490
+ enqueueSubmission,
9290
9491
  hasNativeIntelligenceRunActivity,
9291
9492
  rememberRecentlyLocalRunId
9292
9493
  ]);
@@ -9938,7 +10139,7 @@ function CopilotPopupViewInternal({ header, toggleButton, width, height, clickOu
9938
10139
  const popupAnimationClass = isPopupOpen && !isAnimatingOut ? "cpk:pointer-events-auto cpk:translate-y-0 cpk:opacity-100 cpk:md:scale-100" : "cpk:pointer-events-none cpk:translate-y-4 cpk:opacity-0 cpk:md:translate-y-5 cpk:md:scale-[0.95]";
9939
10140
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [toggleButtonElement, isRendered ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
9940
10141
  "data-copilotkit": true,
9941
- className: cn("cpk:fixed cpk:inset-0 cpk:z-[1200] cpk:flex cpk:max-w-full cpk:flex-col cpk:items-stretch", "cpk:md:inset-auto cpk:md:bottom-24 cpk:md:right-6 cpk:md:items-end cpk:md:gap-4"),
10142
+ className: cn("cpk:fixed cpk:inset-0 cpk:z-[1200] cpk:flex cpk:max-w-full cpk:flex-col cpk:items-stretch cpk:bg-transparent", "cpk:md:inset-auto cpk:md:bottom-24 cpk:md:right-6 cpk:md:items-end cpk:md:gap-4"),
9942
10143
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
9943
10144
  ref: containerRef,
9944
10145
  tabIndex: -1,
@@ -12955,6 +13156,18 @@ Object.defineProperty(exports, 'getIntelligenceTurnAnchors', {
12955
13156
  return getIntelligenceTurnAnchors;
12956
13157
  }
12957
13158
  });
13159
+ Object.defineProperty(exports, 'messageGroup', {
13160
+ enumerable: true,
13161
+ get: function () {
13162
+ return messageGroup;
13163
+ }
13164
+ });
13165
+ Object.defineProperty(exports, 'messageRow', {
13166
+ enumerable: true,
13167
+ get: function () {
13168
+ return messageRow;
13169
+ }
13170
+ });
12958
13171
  Object.defineProperty(exports, 'shouldShowDevConsole', {
12959
13172
  enumerable: true,
12960
13173
  get: function () {
@@ -13141,4 +13354,4 @@ Object.defineProperty(exports, 'useToast', {
13141
13354
  return useToast;
13142
13355
  }
13143
13356
  });
13144
- //# sourceMappingURL=copilotkit-dHdNF7H5.cjs.map
13357
+ //# sourceMappingURL=copilotkit-BG1d4-qU.cjs.map