@copilotkit/react-core 1.55.1 → 1.55.2-next.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 (34) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/copilotkit-BuhSUZHb.d.mts.map +1 -1
  3. package/dist/{copilotkit-BY5S1-0P.mjs → copilotkit-Cd-NrDyp.mjs} +46 -16
  4. package/dist/copilotkit-Cd-NrDyp.mjs.map +1 -0
  5. package/dist/{copilotkit-Bz5-ImDl.cjs → copilotkit-Dgdpbqjt.cjs} +46 -16
  6. package/dist/copilotkit-Dgdpbqjt.cjs.map +1 -0
  7. package/dist/copilotkit-dwDWYpya.d.cts.map +1 -1
  8. package/dist/index.cjs +6 -3
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.mjs +6 -3
  11. package/dist/index.mjs.map +1 -1
  12. package/dist/index.umd.js +28 -29
  13. package/dist/index.umd.js.map +1 -1
  14. package/dist/v2/index.cjs +1 -1
  15. package/dist/v2/index.mjs +1 -1
  16. package/dist/v2/index.umd.js +52 -28
  17. package/dist/v2/index.umd.js.map +1 -1
  18. package/package.json +6 -6
  19. package/src/components/copilot-provider/copilotkit.tsx +2 -2
  20. package/src/hooks/use-agent-nodename.ts +3 -0
  21. package/src/hooks/use-coagent-state-render-bridge.helpers.ts +2 -1
  22. package/src/hooks/use-coagent-state-render-registry.ts +6 -6
  23. package/src/hooks/use-copilot-chat_internal.ts +1 -1
  24. package/src/lib/copilot-task.ts +1 -1
  25. package/src/utils/utils.ts +0 -2
  26. package/src/v2/a2ui/A2UIMessageRenderer.tsx +1 -1
  27. package/src/v2/components/MCPAppsActivityRenderer.tsx +32 -2
  28. package/src/v2/components/chat/CopilotChatMessageView.tsx +41 -5
  29. package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +192 -82
  30. package/src/v2/components/chat/__tests__/MCPAppsProxy.e2e.test.tsx +589 -0
  31. package/src/v2/components/chat/__tests__/MCPAppsUiMessage.e2e.test.tsx +458 -0
  32. package/src/v2/providers/CopilotChatConfigurationProvider.tsx +2 -2
  33. package/dist/copilotkit-BY5S1-0P.mjs.map +0 -1
  34. package/dist/copilotkit-Bz5-ImDl.cjs.map +0 -1
package/dist/v2/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
- const require_copilotkit = require('../copilotkit-Bz5-ImDl.cjs');
4
+ const require_copilotkit = require('../copilotkit-Dgdpbqjt.cjs');
5
5
  require("./index.css");
6
6
  let _copilotkit_a2ui_renderer = require("@copilotkit/a2ui-renderer");
7
7
 
package/dist/v2/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
 
3
- import { $ as useCopilotKit, A as CopilotChatSuggestionView, B as useConfigureSuggestions, C as CopilotChatToggleButton, D as CopilotChatView_default, E as CopilotChat, F as CopilotChatAssistantMessage_default, G as useComponent, H as useHumanInTheLoop, I as CopilotChatToolCallsView, J as useRenderCustomMessages, K as useFrontendTool, L as useAttachments, M as CopilotChatReasoningMessage_default, N as CopilotChatUserMessage_default, O as CopilotChatAttachmentQueue, P as CopilotChatAttachmentRenderer, Q as CopilotKitProvider, R as useThreads, S as CopilotModalHeader, T as DefaultOpenIcon, U as useDefaultRenderTool, V as useSuggestions, W as useRenderTool, X as useAgent, Y as UseAgentUpdate, Z as useRenderToolCall, _ as WildcardToolCallRender, at as useSandboxFunctions, b as CopilotPopupView, ct as MCPAppsActivityType, dt as AudioRecorderError, et as CopilotKitCoreReact, ft as CopilotChatAudioRecorder, it as SandboxFunctionsContext, j as CopilotChatSuggestionPill, k as CopilotChatMessageView, lt as CopilotKitInspector, mt as useCopilotChatConfiguration, nt as defineToolCallRenderer, ot as MCPAppsActivityContentSchema, pt as CopilotChatConfigurationProvider, q as useRenderActivityMessage, rt as createA2UIMessageRenderer, st as MCPAppsActivityRenderer, t as CopilotKit, tt as useAgentContext, ut as CopilotChatInput_default, v as CopilotPopup, w as DefaultCloseIcon, x as CopilotSidebarView, y as CopilotSidebar, z as useInterrupt } from "../copilotkit-BY5S1-0P.mjs";
3
+ import { $ as useCopilotKit, A as CopilotChatSuggestionView, B as useConfigureSuggestions, C as CopilotChatToggleButton, D as CopilotChatView_default, E as CopilotChat, F as CopilotChatAssistantMessage_default, G as useComponent, H as useHumanInTheLoop, I as CopilotChatToolCallsView, J as useRenderCustomMessages, K as useFrontendTool, L as useAttachments, M as CopilotChatReasoningMessage_default, N as CopilotChatUserMessage_default, O as CopilotChatAttachmentQueue, P as CopilotChatAttachmentRenderer, Q as CopilotKitProvider, R as useThreads, S as CopilotModalHeader, T as DefaultOpenIcon, U as useDefaultRenderTool, V as useSuggestions, W as useRenderTool, X as useAgent, Y as UseAgentUpdate, Z as useRenderToolCall, _ as WildcardToolCallRender, at as useSandboxFunctions, b as CopilotPopupView, ct as MCPAppsActivityType, dt as AudioRecorderError, et as CopilotKitCoreReact, ft as CopilotChatAudioRecorder, it as SandboxFunctionsContext, j as CopilotChatSuggestionPill, k as CopilotChatMessageView, lt as CopilotKitInspector, mt as useCopilotChatConfiguration, nt as defineToolCallRenderer, ot as MCPAppsActivityContentSchema, pt as CopilotChatConfigurationProvider, q as useRenderActivityMessage, rt as createA2UIMessageRenderer, st as MCPAppsActivityRenderer, t as CopilotKit, tt as useAgentContext, ut as CopilotChatInput_default, v as CopilotPopup, w as DefaultCloseIcon, x as CopilotSidebarView, y as CopilotSidebar, z as useInterrupt } from "../copilotkit-Cd-NrDyp.mjs";
4
4
  import "./index.css";
5
5
  import { defaultTheme as a2uiDefaultTheme } from "@copilotkit/a2ui-renderer";
6
6
 
@@ -165,14 +165,11 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
165
165
  var _ref, _parentConfig$isModal, _parentConfig$setModa;
166
166
  const parentConfig = (0, react.useContext)(CopilotChatConfiguration);
167
167
  const stableLabels = useShallowStableRef(labels);
168
- const mergedLabels = (0, react.useMemo)(() => {
169
- var _parentConfig$labels;
170
- return {
171
- ...CopilotChatDefaultLabels,
172
- ...(_parentConfig$labels = parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels) !== null && _parentConfig$labels !== void 0 ? _parentConfig$labels : {},
173
- ...stableLabels !== null && stableLabels !== void 0 ? stableLabels : {}
174
- };
175
- }, [stableLabels, parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels]);
168
+ const mergedLabels = (0, react.useMemo)(() => ({
169
+ ...CopilotChatDefaultLabels,
170
+ ...parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels,
171
+ ...stableLabels
172
+ }), [stableLabels, parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.labels]);
176
173
  const resolvedAgentId = (_ref = agentId !== null && agentId !== void 0 ? agentId : parentConfig === null || parentConfig === void 0 ? void 0 : parentConfig.agentId) !== null && _ref !== void 0 ? _ref : _copilotkit_shared.DEFAULT_AGENT_ID;
177
174
  const resolvedThreadId = (0, react.useMemo)(() => {
178
175
  if (threadId) return threadId;
@@ -1646,6 +1643,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
1646
1643
  */
1647
1644
  const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
1648
1645
  var _fetchedResource$_met2;
1646
+ const { copilotkit } = useCopilotKit();
1649
1647
  const containerRef = (0, react.useRef)(null);
1650
1648
  const iframeRef = (0, react.useRef)(null);
1651
1649
  const [iframeReady, setIframeReady] = (0, react.useState)(false);
@@ -1823,15 +1821,17 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
1823
1821
  break;
1824
1822
  }
1825
1823
  try {
1826
- var _params$content;
1824
+ var _params$content, _params$followUp;
1827
1825
  const params = msg.params;
1826
+ const role = params.role || "user";
1828
1827
  const textContent = ((_params$content = params.content) === null || _params$content === void 0 ? void 0 : _params$content.filter((c) => c.type === "text" && c.text).map((c) => c.text).join("\n")) || "";
1829
1828
  if (textContent) currentAgent.addMessage({
1830
1829
  id: crypto.randomUUID(),
1831
- role: params.role || "user",
1830
+ role,
1832
1831
  content: textContent
1833
1832
  });
1834
1833
  sendResponse(msg.id, { isError: false });
1834
+ if (((_params$followUp = params.followUp) !== null && _params$followUp !== void 0 ? _params$followUp : role === "user") && textContent) mcpAppsRequestQueue.enqueue(currentAgent, () => copilotkit.runAgent({ agent: currentAgent })).catch((err) => console.error("[MCPAppsRenderer] ui/message agent run failed:", err));
1835
1835
  } catch (err) {
1836
1836
  console.error("[MCPAppsRenderer] ui/message error:", err);
1837
1837
  sendResponse(msg.id, { isError: true });
@@ -2464,9 +2464,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2464
2464
  if (!agent) return;
2465
2465
  message.userAction;
2466
2466
  try {
2467
- var _copilotkit$propertie;
2468
2467
  copilotkit.setProperties({
2469
- ...(_copilotkit$propertie = copilotkit.properties) !== null && _copilotkit$propertie !== void 0 ? _copilotkit$propertie : {},
2468
+ ...copilotkit.properties,
2470
2469
  a2uiAction: message
2471
2470
  });
2472
2471
  await copilotkit.runAgent({ agent });
@@ -5722,6 +5721,34 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5722
5721
  if (JSON.stringify(prevProps.stateSnapshot) !== JSON.stringify(nextProps.stateSnapshot)) return false;
5723
5722
  return true;
5724
5723
  });
5724
+ /**
5725
+ * Deduplicates messages by ID. For assistant messages, merges occurrences:
5726
+ * recovers non-empty content from any earlier occurrence if the latest wiped it
5727
+ * (empty string means the streaming update cleared the field, not blank text),
5728
+ * and similarly recovers toolCalls from earlier occurrences if the latest is
5729
+ * undefined (an empty array [] is treated as intentional and kept as-is).
5730
+ * For all other roles, keeps the last entry.
5731
+ *
5732
+ * @internal Exported for unit testing only — not part of the public API.
5733
+ */
5734
+ function deduplicateMessages(messages) {
5735
+ const acc = /* @__PURE__ */ new Map();
5736
+ for (const message of messages) {
5737
+ const existing = acc.get(message.id);
5738
+ if (existing && message.role === "assistant" && existing.role === "assistant") {
5739
+ var _message$toolCalls;
5740
+ const content = message.content || existing.content;
5741
+ const toolCalls = (_message$toolCalls = message.toolCalls) !== null && _message$toolCalls !== void 0 ? _message$toolCalls : existing.toolCalls;
5742
+ acc.set(message.id, {
5743
+ ...existing,
5744
+ ...message,
5745
+ content,
5746
+ toolCalls
5747
+ });
5748
+ } else acc.set(message.id, message);
5749
+ }
5750
+ return [...acc.values()];
5751
+ }
5725
5752
  const VIRTUALIZE_THRESHOLD = 50;
5726
5753
  function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, isRunning = false, children, className, ...props }) {
5727
5754
  var _deduplicatedMessages;
@@ -5759,8 +5786,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5759
5786
  if (!resolvedRunId) return void 0;
5760
5787
  return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
5761
5788
  };
5762
- const deduplicatedMessages = (0, react.useMemo)(() => [...new Map(messages.map((m) => [m.id, m])).values()], [messages]);
5763
- if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView: Deduplicated ${messages.length - deduplicatedMessages.length} message(s) with duplicate IDs.`);
5789
+ const deduplicatedMessages = (0, react.useMemo)(() => deduplicateMessages(messages), [messages]);
5790
+ if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView: Merged ${messages.length - deduplicatedMessages.length} message(s) with duplicate IDs.`);
5764
5791
  const { Component: AssistantComponent, slotProps: assistantSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(assistantMessage, CopilotChatAssistantMessage_default), [assistantMessage]);
5765
5792
  const { Component: UserComponent, slotProps: userSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(userMessage, CopilotChatUserMessage_default), [userMessage]);
5766
5793
  const { Component: ReasoningComponent, slotProps: reasoningSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(reasoningMessage, CopilotChatReasoningMessage_default), [reasoningMessage]);
@@ -8728,8 +8755,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8728
8755
  * 5) last cached snapshot for stateRenderId
8729
8756
  */
8730
8757
  function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
8731
- var _reverse$find, _agentMessages$messag, _existingClaim$stateS, _existingClaim$stateS2;
8732
- const lastAssistantId = agentMessages ? (_reverse$find = [...agentMessages].reverse().find((msg) => msg.role === "assistant")) === null || _reverse$find === void 0 ? void 0 : _reverse$find.id : void 0;
8758
+ var _toReversed$find, _agentMessages$messag, _existingClaim$stateS, _existingClaim$stateS2;
8759
+ const lastAssistantId = agentMessages ? (_toReversed$find = [...agentMessages].toReversed().find((msg) => msg.role === "assistant")) === null || _toReversed$find === void 0 ? void 0 : _toReversed$find.id : void 0;
8733
8760
  const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
8734
8761
  const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
8735
8762
  const messageRole = messageIndex >= 0 && agentMessages ? (_agentMessages$messag = agentMessages[messageIndex]) === null || _agentMessages$messag === void 0 ? void 0 : _agentMessages$messag.role : void 0;
@@ -8793,13 +8820,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8793
8820
  return () => {
8794
8821
  const existingClaim = claimsRef.current[message.id];
8795
8822
  if ((existingClaim === null || existingClaim === void 0 ? void 0 : existingClaim.stateSnapshot) && Object.keys(existingClaim.stateSnapshot).length > 0) {
8796
- var _store$LAST_SNAPSHOTS4, _existingClaim$runId, _store$LAST_SNAPSHOTS5, _existingClaim$runId2;
8797
- const snapshotCache = { ...(_store$LAST_SNAPSHOTS4 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) !== null && _store$LAST_SNAPSHOTS4 !== void 0 ? _store$LAST_SNAPSHOTS4 : {} };
8823
+ var _existingClaim$runId, _existingClaim$runId2;
8824
+ const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
8798
8825
  const cacheKey = `${existingClaim.stateRenderId}::${(_existingClaim$runId = existingClaim.runId) !== null && _existingClaim$runId !== void 0 ? _existingClaim$runId : "pending"}`;
8799
8826
  snapshotCache[cacheKey] = existingClaim.stateSnapshot;
8800
8827
  snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
8801
8828
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
8802
- const messageCache = { ...(_store$LAST_SNAPSHOTS5 = store[LAST_SNAPSHOTS_BY_MESSAGE]) !== null && _store$LAST_SNAPSHOTS5 !== void 0 ? _store$LAST_SNAPSHOTS5 : {} };
8829
+ const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
8803
8830
  messageCache[message.id] = {
8804
8831
  snapshot: existingClaim.stateSnapshot,
8805
8832
  runId: (_existingClaim$runId2 = existingClaim.runId) !== null && _existingClaim$runId2 !== void 0 ? _existingClaim$runId2 : effectiveRunId
@@ -8854,14 +8881,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8854
8881
  const snapshotChanged = stateSnapshot && existingSnapshot !== void 0 && !areStatesEquals(existingSnapshot, snapshot);
8855
8882
  if (snapshot && (stateSnapshot || hasSnapshotKeys || allowEmptySnapshot) && (!claimsRef.current[message.id].locked || snapshotChanged)) {
8856
8883
  if (!claimsRef.current[message.id].locked || snapshotChanged) {
8857
- var _store$LAST_SNAPSHOTS6, _store$LAST_SNAPSHOTS7;
8858
8884
  claimsRef.current[message.id].stateSnapshot = snapshot;
8859
- const snapshotCache = { ...(_store$LAST_SNAPSHOTS6 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) !== null && _store$LAST_SNAPSHOTS6 !== void 0 ? _store$LAST_SNAPSHOTS6 : {} };
8885
+ const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
8860
8886
  const cacheKey = `${stateRenderId}::${effectiveRunId}`;
8861
8887
  snapshotCache[cacheKey] = snapshot;
8862
8888
  snapshotCache[`${stateRenderId}::latest`] = snapshot;
8863
8889
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
8864
- const messageCache = { ...(_store$LAST_SNAPSHOTS7 = store[LAST_SNAPSHOTS_BY_MESSAGE]) !== null && _store$LAST_SNAPSHOTS7 !== void 0 ? _store$LAST_SNAPSHOTS7 : {} };
8890
+ const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
8865
8891
  messageCache[message.id] = {
8866
8892
  snapshot,
8867
8893
  runId: effectiveRunId
@@ -8871,14 +8897,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8871
8897
  }
8872
8898
  } else if (snapshotForClaim) {
8873
8899
  if (!claimsRef.current[message.id].stateSnapshot) {
8874
- var _store$LAST_SNAPSHOTS8, _store$LAST_SNAPSHOTS9;
8875
8900
  claimsRef.current[message.id].stateSnapshot = snapshotForClaim;
8876
- const snapshotCache = { ...(_store$LAST_SNAPSHOTS8 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) !== null && _store$LAST_SNAPSHOTS8 !== void 0 ? _store$LAST_SNAPSHOTS8 : {} };
8901
+ const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
8877
8902
  const cacheKey = `${stateRenderId}::${effectiveRunId}`;
8878
8903
  snapshotCache[cacheKey] = snapshotForClaim;
8879
8904
  snapshotCache[`${stateRenderId}::latest`] = snapshotForClaim;
8880
8905
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
8881
- const messageCache = { ...(_store$LAST_SNAPSHOTS9 = store[LAST_SNAPSHOTS_BY_MESSAGE]) !== null && _store$LAST_SNAPSHOTS9 !== void 0 ? _store$LAST_SNAPSHOTS9 : {} };
8906
+ const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
8882
8907
  messageCache[message.id] = {
8883
8908
  snapshot: snapshotForClaim,
8884
8909
  runId: effectiveRunId
@@ -9230,7 +9255,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
9230
9255
  return acc;
9231
9256
  }, {});
9232
9257
  return {
9233
- ...copilotApiConfig.headers || {},
9258
+ ...copilotApiConfig.headers,
9234
9259
  ...copilotApiConfig.publicApiKey ? { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {},
9235
9260
  ...authHeaders
9236
9261
  };
@@ -9310,12 +9335,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
9310
9335
  const [interruptActions, _setInterruptActions] = (0, react.useState)({});
9311
9336
  const setInterruptAction = (0, react.useCallback)((action) => {
9312
9337
  _setInterruptActions((prev) => {
9313
- var _prev$action$id;
9314
9338
  if (action == null || !action.id) return prev;
9315
9339
  return {
9316
9340
  ...prev,
9317
9341
  [action.id]: {
9318
- ...(_prev$action$id = prev[action.id]) !== null && _prev$action$id !== void 0 ? _prev$action$id : {},
9342
+ ...prev[action.id],
9319
9343
  ...action
9320
9344
  }
9321
9345
  };