@copilotkit/react-core 1.55.2-next.0 → 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.
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-7z4C8joY.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-OhEIYGcY.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;
@@ -2467,9 +2464,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
2467
2464
  if (!agent) return;
2468
2465
  message.userAction;
2469
2466
  try {
2470
- var _copilotkit$propertie;
2471
2467
  copilotkit.setProperties({
2472
- ...(_copilotkit$propertie = copilotkit.properties) !== null && _copilotkit$propertie !== void 0 ? _copilotkit$propertie : {},
2468
+ ...copilotkit.properties,
2473
2469
  a2uiAction: message
2474
2470
  });
2475
2471
  await copilotkit.runAgent({ agent });
@@ -5725,6 +5721,34 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5725
5721
  if (JSON.stringify(prevProps.stateSnapshot) !== JSON.stringify(nextProps.stateSnapshot)) return false;
5726
5722
  return true;
5727
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
+ }
5728
5752
  const VIRTUALIZE_THRESHOLD = 50;
5729
5753
  function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, isRunning = false, children, className, ...props }) {
5730
5754
  var _deduplicatedMessages;
@@ -5762,8 +5786,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
5762
5786
  if (!resolvedRunId) return void 0;
5763
5787
  return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
5764
5788
  };
5765
- const deduplicatedMessages = (0, react.useMemo)(() => [...new Map(messages.map((m) => [m.id, m])).values()], [messages]);
5766
- 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.`);
5767
5791
  const { Component: AssistantComponent, slotProps: assistantSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(assistantMessage, CopilotChatAssistantMessage_default), [assistantMessage]);
5768
5792
  const { Component: UserComponent, slotProps: userSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(userMessage, CopilotChatUserMessage_default), [userMessage]);
5769
5793
  const { Component: ReasoningComponent, slotProps: reasoningSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(reasoningMessage, CopilotChatReasoningMessage_default), [reasoningMessage]);
@@ -8731,8 +8755,8 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8731
8755
  * 5) last cached snapshot for stateRenderId
8732
8756
  */
8733
8757
  function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
8734
- var _reverse$find, _agentMessages$messag, _existingClaim$stateS, _existingClaim$stateS2;
8735
- 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;
8736
8760
  const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
8737
8761
  const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
8738
8762
  const messageRole = messageIndex >= 0 && agentMessages ? (_agentMessages$messag = agentMessages[messageIndex]) === null || _agentMessages$messag === void 0 ? void 0 : _agentMessages$messag.role : void 0;
@@ -8796,13 +8820,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8796
8820
  return () => {
8797
8821
  const existingClaim = claimsRef.current[message.id];
8798
8822
  if ((existingClaim === null || existingClaim === void 0 ? void 0 : existingClaim.stateSnapshot) && Object.keys(existingClaim.stateSnapshot).length > 0) {
8799
- var _store$LAST_SNAPSHOTS4, _existingClaim$runId, _store$LAST_SNAPSHOTS5, _existingClaim$runId2;
8800
- 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] };
8801
8825
  const cacheKey = `${existingClaim.stateRenderId}::${(_existingClaim$runId = existingClaim.runId) !== null && _existingClaim$runId !== void 0 ? _existingClaim$runId : "pending"}`;
8802
8826
  snapshotCache[cacheKey] = existingClaim.stateSnapshot;
8803
8827
  snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
8804
8828
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
8805
- 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] };
8806
8830
  messageCache[message.id] = {
8807
8831
  snapshot: existingClaim.stateSnapshot,
8808
8832
  runId: (_existingClaim$runId2 = existingClaim.runId) !== null && _existingClaim$runId2 !== void 0 ? _existingClaim$runId2 : effectiveRunId
@@ -8857,14 +8881,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8857
8881
  const snapshotChanged = stateSnapshot && existingSnapshot !== void 0 && !areStatesEquals(existingSnapshot, snapshot);
8858
8882
  if (snapshot && (stateSnapshot || hasSnapshotKeys || allowEmptySnapshot) && (!claimsRef.current[message.id].locked || snapshotChanged)) {
8859
8883
  if (!claimsRef.current[message.id].locked || snapshotChanged) {
8860
- var _store$LAST_SNAPSHOTS6, _store$LAST_SNAPSHOTS7;
8861
8884
  claimsRef.current[message.id].stateSnapshot = snapshot;
8862
- 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] };
8863
8886
  const cacheKey = `${stateRenderId}::${effectiveRunId}`;
8864
8887
  snapshotCache[cacheKey] = snapshot;
8865
8888
  snapshotCache[`${stateRenderId}::latest`] = snapshot;
8866
8889
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
8867
- 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] };
8868
8891
  messageCache[message.id] = {
8869
8892
  snapshot,
8870
8893
  runId: effectiveRunId
@@ -8874,14 +8897,13 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
8874
8897
  }
8875
8898
  } else if (snapshotForClaim) {
8876
8899
  if (!claimsRef.current[message.id].stateSnapshot) {
8877
- var _store$LAST_SNAPSHOTS8, _store$LAST_SNAPSHOTS9;
8878
8900
  claimsRef.current[message.id].stateSnapshot = snapshotForClaim;
8879
- 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] };
8880
8902
  const cacheKey = `${stateRenderId}::${effectiveRunId}`;
8881
8903
  snapshotCache[cacheKey] = snapshotForClaim;
8882
8904
  snapshotCache[`${stateRenderId}::latest`] = snapshotForClaim;
8883
8905
  store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
8884
- 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] };
8885
8907
  messageCache[message.id] = {
8886
8908
  snapshot: snapshotForClaim,
8887
8909
  runId: effectiveRunId
@@ -9233,7 +9255,7 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
9233
9255
  return acc;
9234
9256
  }, {});
9235
9257
  return {
9236
- ...copilotApiConfig.headers || {},
9258
+ ...copilotApiConfig.headers,
9237
9259
  ...copilotApiConfig.publicApiKey ? { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {},
9238
9260
  ...authHeaders
9239
9261
  };
@@ -9313,12 +9335,11 @@ window.parent.postMessage({jsonrpc:"2.0",method:"ui/notifications/sandbox-proxy-
9313
9335
  const [interruptActions, _setInterruptActions] = (0, react.useState)({});
9314
9336
  const setInterruptAction = (0, react.useCallback)((action) => {
9315
9337
  _setInterruptActions((prev) => {
9316
- var _prev$action$id;
9317
9338
  if (action == null || !action.id) return prev;
9318
9339
  return {
9319
9340
  ...prev,
9320
9341
  [action.id]: {
9321
- ...(_prev$action$id = prev[action.id]) !== null && _prev$action$id !== void 0 ? _prev$action$id : {},
9342
+ ...prev[action.id],
9322
9343
  ...action
9323
9344
  }
9324
9345
  };