@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/CHANGELOG.md +11 -0
- package/dist/copilotkit-BuhSUZHb.d.mts.map +1 -1
- package/dist/{copilotkit-OhEIYGcY.mjs → copilotkit-Cd-NrDyp.mjs} +42 -15
- package/dist/copilotkit-Cd-NrDyp.mjs.map +1 -0
- package/dist/{copilotkit-7z4C8joY.cjs → copilotkit-Dgdpbqjt.cjs} +42 -15
- package/dist/copilotkit-Dgdpbqjt.cjs.map +1 -0
- package/dist/copilotkit-dwDWYpya.d.cts.map +1 -1
- package/dist/index.cjs +6 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +6 -3
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +23 -27
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +1 -1
- package/dist/v2/index.mjs +1 -1
- package/dist/v2/index.umd.js +47 -26
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +6 -6
- package/src/components/copilot-provider/copilotkit.tsx +2 -2
- package/src/hooks/use-agent-nodename.ts +3 -0
- package/src/hooks/use-coagent-state-render-bridge.helpers.ts +2 -1
- package/src/hooks/use-coagent-state-render-registry.ts +6 -6
- package/src/hooks/use-copilot-chat_internal.ts +1 -1
- package/src/lib/copilot-task.ts +1 -1
- package/src/utils/utils.ts +0 -2
- package/src/v2/a2ui/A2UIMessageRenderer.tsx +1 -1
- package/src/v2/components/chat/CopilotChatMessageView.tsx +41 -5
- package/src/v2/components/chat/__tests__/CopilotChatMessageView.test.tsx +192 -82
- package/src/v2/providers/CopilotChatConfigurationProvider.tsx +2 -2
- package/dist/copilotkit-7z4C8joY.cjs.map +0 -1
- package/dist/copilotkit-OhEIYGcY.mjs.map +0 -1
|
@@ -180,8 +180,8 @@ const CopilotChatConfigurationProvider = ({ children, labels, agentId, threadId,
|
|
|
180
180
|
const stableLabels = useShallowStableRef(labels);
|
|
181
181
|
const mergedLabels = (0, react.useMemo)(() => ({
|
|
182
182
|
...CopilotChatDefaultLabels,
|
|
183
|
-
...parentConfig?.labels
|
|
184
|
-
...stableLabels
|
|
183
|
+
...parentConfig?.labels,
|
|
184
|
+
...stableLabels
|
|
185
185
|
}), [stableLabels, parentConfig?.labels]);
|
|
186
186
|
const resolvedAgentId = agentId ?? parentConfig?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID;
|
|
187
187
|
const resolvedThreadId = (0, react.useMemo)(() => {
|
|
@@ -2438,7 +2438,7 @@ function ReactSurfaceHost({ surfaceId, operations, theme, agent, copilotkit, cat
|
|
|
2438
2438
|
message.userAction;
|
|
2439
2439
|
try {
|
|
2440
2440
|
copilotkit.setProperties({
|
|
2441
|
-
...copilotkit.properties
|
|
2441
|
+
...copilotkit.properties,
|
|
2442
2442
|
a2uiAction: message
|
|
2443
2443
|
});
|
|
2444
2444
|
await copilotkit.runAgent({ agent });
|
|
@@ -5620,6 +5620,33 @@ const MemoizedCustomMessage = react.default.memo(function MemoizedCustomMessage(
|
|
|
5620
5620
|
if (JSON.stringify(prevProps.stateSnapshot) !== JSON.stringify(nextProps.stateSnapshot)) return false;
|
|
5621
5621
|
return true;
|
|
5622
5622
|
});
|
|
5623
|
+
/**
|
|
5624
|
+
* Deduplicates messages by ID. For assistant messages, merges occurrences:
|
|
5625
|
+
* recovers non-empty content from any earlier occurrence if the latest wiped it
|
|
5626
|
+
* (empty string means the streaming update cleared the field, not blank text),
|
|
5627
|
+
* and similarly recovers toolCalls from earlier occurrences if the latest is
|
|
5628
|
+
* undefined (an empty array [] is treated as intentional and kept as-is).
|
|
5629
|
+
* For all other roles, keeps the last entry.
|
|
5630
|
+
*
|
|
5631
|
+
* @internal Exported for unit testing only — not part of the public API.
|
|
5632
|
+
*/
|
|
5633
|
+
function deduplicateMessages(messages) {
|
|
5634
|
+
const acc = /* @__PURE__ */ new Map();
|
|
5635
|
+
for (const message of messages) {
|
|
5636
|
+
const existing = acc.get(message.id);
|
|
5637
|
+
if (existing && message.role === "assistant" && existing.role === "assistant") {
|
|
5638
|
+
const content = message.content || existing.content;
|
|
5639
|
+
const toolCalls = message.toolCalls ?? existing.toolCalls;
|
|
5640
|
+
acc.set(message.id, {
|
|
5641
|
+
...existing,
|
|
5642
|
+
...message,
|
|
5643
|
+
content,
|
|
5644
|
+
toolCalls
|
|
5645
|
+
});
|
|
5646
|
+
} else acc.set(message.id, message);
|
|
5647
|
+
}
|
|
5648
|
+
return [...acc.values()];
|
|
5649
|
+
}
|
|
5623
5650
|
const VIRTUALIZE_THRESHOLD = 50;
|
|
5624
5651
|
function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, isRunning = false, children, className, ...props }) {
|
|
5625
5652
|
const renderCustomMessage = useRenderCustomMessages();
|
|
@@ -5654,8 +5681,8 @@ function CopilotChatMessageView({ messages = [], assistantMessage, userMessage,
|
|
|
5654
5681
|
if (!resolvedRunId) return void 0;
|
|
5655
5682
|
return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
|
|
5656
5683
|
};
|
|
5657
|
-
const deduplicatedMessages = (0, react.useMemo)(() =>
|
|
5658
|
-
if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView:
|
|
5684
|
+
const deduplicatedMessages = (0, react.useMemo)(() => deduplicateMessages(messages), [messages]);
|
|
5685
|
+
if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView: Merged ${messages.length - deduplicatedMessages.length} message(s) with duplicate IDs.`);
|
|
5659
5686
|
const { Component: AssistantComponent, slotProps: assistantSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(assistantMessage, CopilotChatAssistantMessage_default), [assistantMessage]);
|
|
5660
5687
|
const { Component: UserComponent, slotProps: userSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(userMessage, CopilotChatUserMessage_default), [userMessage]);
|
|
5661
5688
|
const { Component: ReasoningComponent, slotProps: reasoningSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(reasoningMessage, CopilotChatReasoningMessage_default), [reasoningMessage]);
|
|
@@ -8702,7 +8729,7 @@ function resolveClaim({ claims, context, stateSnapshot }) {
|
|
|
8702
8729
|
* 5) last cached snapshot for stateRenderId
|
|
8703
8730
|
*/
|
|
8704
8731
|
function selectSnapshot({ messageId, messageName, allowLiveState, skipLatestCache, stateRenderId, effectiveRunId, stateSnapshotProp, agentState, agentMessages, existingClaim, caches }) {
|
|
8705
|
-
const lastAssistantId = agentMessages ? [...agentMessages].
|
|
8732
|
+
const lastAssistantId = agentMessages ? [...agentMessages].toReversed().find((msg) => msg.role === "assistant")?.id : void 0;
|
|
8706
8733
|
const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
|
|
8707
8734
|
const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
|
|
8708
8735
|
const messageRole = messageIndex >= 0 && agentMessages ? agentMessages[messageIndex]?.role : void 0;
|
|
@@ -8764,12 +8791,12 @@ function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex,
|
|
|
8764
8791
|
return () => {
|
|
8765
8792
|
const existingClaim = claimsRef.current[message.id];
|
|
8766
8793
|
if (existingClaim?.stateSnapshot && Object.keys(existingClaim.stateSnapshot).length > 0) {
|
|
8767
|
-
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]
|
|
8794
|
+
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
|
|
8768
8795
|
const cacheKey = `${existingClaim.stateRenderId}::${existingClaim.runId ?? "pending"}`;
|
|
8769
8796
|
snapshotCache[cacheKey] = existingClaim.stateSnapshot;
|
|
8770
8797
|
snapshotCache[`${existingClaim.stateRenderId}::latest`] = existingClaim.stateSnapshot;
|
|
8771
8798
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
8772
|
-
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE]
|
|
8799
|
+
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
|
|
8773
8800
|
messageCache[message.id] = {
|
|
8774
8801
|
snapshot: existingClaim.stateSnapshot,
|
|
8775
8802
|
runId: existingClaim.runId ?? effectiveRunId
|
|
@@ -8825,12 +8852,12 @@ function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex,
|
|
|
8825
8852
|
if (snapshot && (stateSnapshot || hasSnapshotKeys || allowEmptySnapshot) && (!claimsRef.current[message.id].locked || snapshotChanged)) {
|
|
8826
8853
|
if (!claimsRef.current[message.id].locked || snapshotChanged) {
|
|
8827
8854
|
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
8828
|
-
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]
|
|
8855
|
+
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
|
|
8829
8856
|
const cacheKey = `${stateRenderId}::${effectiveRunId}`;
|
|
8830
8857
|
snapshotCache[cacheKey] = snapshot;
|
|
8831
8858
|
snapshotCache[`${stateRenderId}::latest`] = snapshot;
|
|
8832
8859
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
8833
|
-
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE]
|
|
8860
|
+
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
|
|
8834
8861
|
messageCache[message.id] = {
|
|
8835
8862
|
snapshot,
|
|
8836
8863
|
runId: effectiveRunId
|
|
@@ -8841,12 +8868,12 @@ function useStateRenderRegistry({ agentId, stateRenderId, message, messageIndex,
|
|
|
8841
8868
|
} else if (snapshotForClaim) {
|
|
8842
8869
|
if (!claimsRef.current[message.id].stateSnapshot) {
|
|
8843
8870
|
claimsRef.current[message.id].stateSnapshot = snapshotForClaim;
|
|
8844
|
-
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]
|
|
8871
|
+
const snapshotCache = { ...store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] };
|
|
8845
8872
|
const cacheKey = `${stateRenderId}::${effectiveRunId}`;
|
|
8846
8873
|
snapshotCache[cacheKey] = snapshotForClaim;
|
|
8847
8874
|
snapshotCache[`${stateRenderId}::latest`] = snapshotForClaim;
|
|
8848
8875
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
8849
|
-
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE]
|
|
8876
|
+
const messageCache = { ...store[LAST_SNAPSHOTS_BY_MESSAGE] };
|
|
8850
8877
|
messageCache[message.id] = {
|
|
8851
8878
|
snapshot: snapshotForClaim,
|
|
8852
8879
|
runId: effectiveRunId
|
|
@@ -9187,7 +9214,7 @@ function CopilotKitInternal(cpkProps) {
|
|
|
9187
9214
|
return acc;
|
|
9188
9215
|
}, {});
|
|
9189
9216
|
return {
|
|
9190
|
-
...copilotApiConfig.headers
|
|
9217
|
+
...copilotApiConfig.headers,
|
|
9191
9218
|
...copilotApiConfig.publicApiKey ? { [_copilotkit_shared.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {},
|
|
9192
9219
|
...authHeaders
|
|
9193
9220
|
};
|
|
@@ -9271,7 +9298,7 @@ function CopilotKitInternal(cpkProps) {
|
|
|
9271
9298
|
return {
|
|
9272
9299
|
...prev,
|
|
9273
9300
|
[action.id]: {
|
|
9274
|
-
...prev[action.id]
|
|
9301
|
+
...prev[action.id],
|
|
9275
9302
|
...action
|
|
9276
9303
|
}
|
|
9277
9304
|
};
|
|
@@ -9919,4 +9946,4 @@ Object.defineProperty(exports, 'useToast', {
|
|
|
9919
9946
|
return useToast;
|
|
9920
9947
|
}
|
|
9921
9948
|
});
|
|
9922
|
-
//# sourceMappingURL=copilotkit-
|
|
9949
|
+
//# sourceMappingURL=copilotkit-Dgdpbqjt.cjs.map
|