@copilotkit/react-core 1.77.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.
- package/dist/{copilotkit-CFPkj9B9.cjs → copilotkit-BG1d4-qU.cjs} +239 -91
- package/dist/copilotkit-BG1d4-qU.cjs.map +1 -0
- package/dist/{copilotkit-DGc2YiW9.d.cts → copilotkit-BGHjMw0d.d.cts} +59 -3
- package/dist/copilotkit-BGHjMw0d.d.cts.map +1 -0
- package/dist/{copilotkit-Cqa0TfEo.d.mts → copilotkit-BdH_CdBt.d.mts} +59 -3
- package/dist/copilotkit-BdH_CdBt.d.mts.map +1 -0
- package/dist/{copilotkit-CP9qPAqV.mjs → copilotkit-C_Sy6Cc7.mjs} +228 -92
- package/dist/copilotkit-C_Sy6Cc7.mjs.map +1 -0
- package/dist/index.cjs +18 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +18 -8
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +19 -10
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +3 -1
- package/dist/v2/index.d.cts +2 -2
- package/dist/v2/index.d.mts +2 -2
- package/dist/v2/index.mjs +2 -2
- package/dist/v2/index.umd.js +228 -90
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +22 -11
- package/dist/copilotkit-CFPkj9B9.cjs.map +0 -1
- package/dist/copilotkit-CP9qPAqV.mjs.map +0 -1
- package/dist/copilotkit-Cqa0TfEo.d.mts.map +0 -1
- package/dist/copilotkit-DGc2YiW9.d.cts.map +0 -1
package/dist/v2/index.umd.js
CHANGED
|
@@ -1766,7 +1766,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1766
1766
|
|
|
1767
1767
|
//#endregion
|
|
1768
1768
|
//#region package.json
|
|
1769
|
-
var version = "1.77.
|
|
1769
|
+
var version = "1.77.1";
|
|
1770
1770
|
|
|
1771
1771
|
//#endregion
|
|
1772
1772
|
//#region src/v2/components/CopilotKitInspector.tsx
|
|
@@ -3427,7 +3427,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3427
3427
|
- Use CSS Grid or Flexbox for layout. Ensure the UI looks good at any width.
|
|
3428
3428
|
- Minimal transitions (150ms) for hover/focus states only. No decorative animations.
|
|
3429
3429
|
- Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
|
|
3430
|
-
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)";
|
|
3431
3430
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
3432
3431
|
const empty = (0, react.useMemo)(() => [], []);
|
|
3433
3432
|
const value = prop ?? empty;
|
|
@@ -3620,7 +3619,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3620
3619
|
if (!openGenUIActive) return [];
|
|
3621
3620
|
return [{
|
|
3622
3621
|
name: "generateSandboxedUi",
|
|
3623
|
-
description: GENERATE_SANDBOXED_UI_DESCRIPTION,
|
|
3622
|
+
description: _copilotkit_shared.GENERATE_SANDBOXED_UI_DESCRIPTION,
|
|
3624
3623
|
parameters: GenerateSandboxedUiArgsSchema,
|
|
3625
3624
|
handler: async () => "UI generated",
|
|
3626
3625
|
followUp: true,
|
|
@@ -7699,8 +7698,23 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7699
7698
|
}
|
|
7700
7699
|
return [...acc.values()];
|
|
7701
7700
|
}
|
|
7701
|
+
/** A row holding a single message, rendered as it would be ungrouped. */
|
|
7702
|
+
function messageRow(message) {
|
|
7703
|
+
return {
|
|
7704
|
+
type: "message",
|
|
7705
|
+
message
|
|
7706
|
+
};
|
|
7707
|
+
}
|
|
7708
|
+
/** A row holding a group of messages, rendered inside `wrapper`. */
|
|
7709
|
+
function messageGroup(group) {
|
|
7710
|
+
return {
|
|
7711
|
+
type: "group",
|
|
7712
|
+
...group
|
|
7713
|
+
};
|
|
7714
|
+
}
|
|
7715
|
+
const GROUP_ROW_KEY_PREFIX = "copilotkit-group:";
|
|
7702
7716
|
const VIRTUALIZE_THRESHOLD = 50;
|
|
7703
|
-
function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, isRunning = false, transformMessages, children, className, ...props }) {
|
|
7717
|
+
function CopilotChatMessageView({ messages = [], assistantMessage, userMessage, reasoningMessage, cursor, intelligenceIndicator, isRunning = false, transformMessages, groupMessages, children, className, ...props }) {
|
|
7704
7718
|
const isPinnedToBottom = (0, react.useContext)(ScrollPinnedContext);
|
|
7705
7719
|
const renderCustomMessage = useRenderCustomMessages();
|
|
7706
7720
|
const { renderActivityMessage } = useRenderActivityMessage();
|
|
@@ -7733,20 +7747,43 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7733
7747
|
return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
|
|
7734
7748
|
};
|
|
7735
7749
|
const deduplicatedMessages = (0, react.useMemo)(() => deduplicateMessages(messages), [messages]);
|
|
7736
|
-
const
|
|
7750
|
+
const transformedMessages = (0, react.useMemo)(() => transformMessages ? transformMessages(deduplicatedMessages) : deduplicatedMessages, [deduplicatedMessages, transformMessages]);
|
|
7751
|
+
const rows = (0, react.useMemo)(() => groupMessages ? groupMessages(transformedMessages) : transformedMessages.map(messageRow), [transformedMessages, groupMessages]);
|
|
7752
|
+
const renderedMessages = (0, react.useMemo)(() => groupMessages ? rows.flatMap((row) => row.type === "group" ? row.messages : [row.message]) : transformedMessages, [
|
|
7753
|
+
rows,
|
|
7754
|
+
groupMessages,
|
|
7755
|
+
transformedMessages
|
|
7756
|
+
]);
|
|
7737
7757
|
const latestRenderedId = renderedMessages[renderedMessages.length - 1]?.id;
|
|
7738
7758
|
const transformDuplicateId = (0, react.useMemo)(() => {
|
|
7739
|
-
if (process.env.NODE_ENV === "production" || !transformMessages) return;
|
|
7759
|
+
if (process.env.NODE_ENV === "production" || !transformMessages && !groupMessages) return;
|
|
7740
7760
|
const seen = /* @__PURE__ */ new Set();
|
|
7741
7761
|
for (const message of renderedMessages) {
|
|
7742
7762
|
if (seen.has(message.id)) return message.id;
|
|
7743
7763
|
seen.add(message.id);
|
|
7744
7764
|
}
|
|
7745
|
-
}, [
|
|
7765
|
+
}, [
|
|
7766
|
+
renderedMessages,
|
|
7767
|
+
transformMessages,
|
|
7768
|
+
groupMessages
|
|
7769
|
+
]);
|
|
7746
7770
|
(0, react.useEffect)(() => {
|
|
7747
7771
|
if (transformDuplicateId === void 0) return;
|
|
7748
|
-
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.`);
|
|
7749
|
-
}, [transformDuplicateId]);
|
|
7772
|
+
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.`);
|
|
7773
|
+
}, [transformDuplicateId, groupMessages]);
|
|
7774
|
+
const duplicateGroupKey = (0, react.useMemo)(() => {
|
|
7775
|
+
if (process.env.NODE_ENV === "production" || !groupMessages) return;
|
|
7776
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7777
|
+
for (const row of rows) {
|
|
7778
|
+
if (row.type !== "group") continue;
|
|
7779
|
+
if (seen.has(row.key)) return row.key;
|
|
7780
|
+
seen.add(row.key);
|
|
7781
|
+
}
|
|
7782
|
+
}, [rows, groupMessages]);
|
|
7783
|
+
(0, react.useEffect)(() => {
|
|
7784
|
+
if (duplicateGroupKey === void 0) return;
|
|
7785
|
+
console.warn(`[CopilotKit] CopilotChatMessageView: \`groupMessages\` returned more than one group with key "${duplicateGroupKey}". Give each group its own key, stable across renders.`);
|
|
7786
|
+
}, [duplicateGroupKey]);
|
|
7750
7787
|
const rowKeyStoreRef = (0, react.useRef)(null);
|
|
7751
7788
|
rowKeyStoreRef.current ?? (rowKeyStoreRef.current = (0, _copilotkit_shared.createRowKeyStore)());
|
|
7752
7789
|
const rowKeyStore = rowKeyStoreRef.current;
|
|
@@ -7754,6 +7791,31 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7754
7791
|
(0, react.useLayoutEffect)(() => {
|
|
7755
7792
|
(0, _copilotkit_shared.commitRowKeyStore)(rowKeyStore, renderedMessages);
|
|
7756
7793
|
}, [rowKeyStore, renderedMessages]);
|
|
7794
|
+
const stableGroupKey = (key) => rowRenderKeys.get(key) ?? key;
|
|
7795
|
+
const groupStateRef = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
7796
|
+
const groupSettersRef = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
7797
|
+
const groupStateThreadRef = (0, react.useRef)(config?.threadId);
|
|
7798
|
+
if (groupStateThreadRef.current !== config?.threadId) {
|
|
7799
|
+
groupStateThreadRef.current = config?.threadId;
|
|
7800
|
+
groupStateRef.current = /* @__PURE__ */ new Map();
|
|
7801
|
+
groupSettersRef.current = /* @__PURE__ */ new Map();
|
|
7802
|
+
}
|
|
7803
|
+
const groupSetter = (key) => {
|
|
7804
|
+
let setter = groupSettersRef.current.get(key);
|
|
7805
|
+
if (!setter) {
|
|
7806
|
+
setter = (next) => {
|
|
7807
|
+
groupStateRef.current.set(key, next);
|
|
7808
|
+
forceUpdate();
|
|
7809
|
+
};
|
|
7810
|
+
groupSettersRef.current.set(key, setter);
|
|
7811
|
+
}
|
|
7812
|
+
return setter;
|
|
7813
|
+
};
|
|
7814
|
+
(0, react.useLayoutEffect)(() => {
|
|
7815
|
+
const live = /* @__PURE__ */ new Set();
|
|
7816
|
+
for (const row of rows) if (row.type === "group") live.add(stableGroupKey(row.key));
|
|
7817
|
+
for (const store of [groupStateRef.current, groupSettersRef.current]) for (const key of store.keys()) if (!live.has(key)) store.delete(key);
|
|
7818
|
+
}, [rows, rowRenderKeys]);
|
|
7757
7819
|
if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView: Merged ${messages.length - deduplicatedMessages.length} message(s) with duplicate IDs.`);
|
|
7758
7820
|
const { Component: AssistantComponent, slotProps: assistantSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(assistantMessage, CopilotChatAssistantMessage_default), [assistantMessage]);
|
|
7759
7821
|
const agentId = config?.agentId;
|
|
@@ -7793,7 +7855,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7793
7855
|
(0, react.useEffect)(() => {
|
|
7794
7856
|
if (process.env.NODE_ENV === "production" || !childrenDisabledVirtualization || warnedChildrenRef.current) return;
|
|
7795
7857
|
warnedChildrenRef.current = true;
|
|
7796
|
-
console.warn(`[CopilotKit] CopilotChatMessageView: the \`children\` render prop disables virtualization, so all ${renderedMessages.length} messages are mounted. ` + (transformMessages ? "`transformMessages`
|
|
7858
|
+
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."));
|
|
7797
7859
|
}, [
|
|
7798
7860
|
childrenDisabledVirtualization,
|
|
7799
7861
|
renderedMessages.length,
|
|
@@ -7833,7 +7895,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7833
7895
|
return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
|
|
7834
7896
|
}, []);
|
|
7835
7897
|
const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
|
|
7836
|
-
count: shouldVirtualize ?
|
|
7898
|
+
count: shouldVirtualize ? rows.length : 0,
|
|
7837
7899
|
getScrollElement: () => scrollElement,
|
|
7838
7900
|
estimateSize: estimateRowSize,
|
|
7839
7901
|
overscan: 5,
|
|
@@ -7846,8 +7908,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7846
7908
|
isPinnedToBottomRef.current = isPinnedToBottom;
|
|
7847
7909
|
virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
|
|
7848
7910
|
(0, react.useLayoutEffect)(() => {
|
|
7849
|
-
if (!shouldVirtualize || !
|
|
7850
|
-
virtualizer.scrollToIndex(
|
|
7911
|
+
if (!shouldVirtualize || !rows.length) return;
|
|
7912
|
+
virtualizer.scrollToIndex(rows.length - 1, { align: "end" });
|
|
7851
7913
|
}, [shouldVirtualize, firstMessageId]);
|
|
7852
7914
|
const intelligenceTurnAnchors = (0, react.useMemo)(() => getIntelligenceTurnAnchors(deduplicatedMessages, renderedMessages), [deduplicatedMessages, renderedMessages]);
|
|
7853
7915
|
const renderMessageBlock = (message) => {
|
|
@@ -7899,7 +7961,20 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7899
7961
|
}, `intelligence-${intelligenceTurnId}`));
|
|
7900
7962
|
return elements.filter(Boolean);
|
|
7901
7963
|
};
|
|
7902
|
-
const
|
|
7964
|
+
const rowKey = (row) => row.type === "group" ? `${GROUP_ROW_KEY_PREFIX}${stableGroupKey(row.key)}` : rowRenderKeys.get(row.message.id) ?? row.message.id;
|
|
7965
|
+
const renderRow = (row) => {
|
|
7966
|
+
if (row.type === "message") return renderMessageBlock(row.message);
|
|
7967
|
+
const Wrapper = row.wrapper;
|
|
7968
|
+
const stateKey = stableGroupKey(row.key);
|
|
7969
|
+
return [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Wrapper, {
|
|
7970
|
+
groupKey: row.key,
|
|
7971
|
+
messages: row.messages,
|
|
7972
|
+
state: groupStateRef.current.get(stateKey),
|
|
7973
|
+
setState: groupSetter(stateKey),
|
|
7974
|
+
children: row.messages.flatMap(renderMessageBlock)
|
|
7975
|
+
}, rowKey(row))];
|
|
7976
|
+
};
|
|
7977
|
+
const messageElements = shouldVirtualize ? [] : rows.flatMap(renderRow);
|
|
7903
7978
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
7904
7979
|
"data-copilotkit": true,
|
|
7905
7980
|
style: { display: "contents" },
|
|
@@ -7924,7 +7999,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7924
7999
|
position: "relative"
|
|
7925
8000
|
},
|
|
7926
8001
|
children: virtualizer.getVirtualItems().map((virtualItem) => {
|
|
7927
|
-
const
|
|
8002
|
+
const row = rows[virtualItem.index];
|
|
7928
8003
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
7929
8004
|
"data-index": virtualItem.index,
|
|
7930
8005
|
ref: virtualizer.measureElement,
|
|
@@ -7935,8 +8010,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7935
8010
|
width: "100%",
|
|
7936
8011
|
transform: `translateY(${virtualItem.start}px)`
|
|
7937
8012
|
},
|
|
7938
|
-
children:
|
|
7939
|
-
},
|
|
8013
|
+
children: renderRow(row)
|
|
8014
|
+
}, rowKey(row));
|
|
7940
8015
|
})
|
|
7941
8016
|
}) : messageElements,
|
|
7942
8017
|
interruptElement,
|
|
@@ -9004,6 +9079,29 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9004
9079
|
const [lastConnectedThreadId, setLastConnectedThreadId] = (0, react.useState)(null);
|
|
9005
9080
|
const isConnecting = hasExplicitThreadId && lastConnectedThreadId !== resolvedThreadId;
|
|
9006
9081
|
const activeConnectCountRef = (0, react.useRef)(0);
|
|
9082
|
+
const pendingConnectionsRef = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
9083
|
+
const failedConnectionsRef = (0, react.useRef)(/* @__PURE__ */ new WeakSet());
|
|
9084
|
+
const submissionQueueRef = (0, react.useRef)(Promise.resolve());
|
|
9085
|
+
const trackConnection = (0, react.useCallback)((connectingAgent, connect) => {
|
|
9086
|
+
const selection = previousThreadRef.current;
|
|
9087
|
+
const connectingThreadId = connectingAgent.threadId;
|
|
9088
|
+
let failed = false;
|
|
9089
|
+
const subscription = copilotkit.subscribe({ onError: (event) => {
|
|
9090
|
+
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;
|
|
9091
|
+
} });
|
|
9092
|
+
const pending = connect().catch((error) => {
|
|
9093
|
+
failed = true;
|
|
9094
|
+
console.error("CopilotChat: connection failed", error);
|
|
9095
|
+
}).finally(() => {
|
|
9096
|
+
subscription.unsubscribe();
|
|
9097
|
+
if (pendingConnectionsRef.current.get(connectingAgent) === pending) {
|
|
9098
|
+
pendingConnectionsRef.current.delete(connectingAgent);
|
|
9099
|
+
if (selection?.active && previousThreadRef.current === selection) if (failed) failedConnectionsRef.current.add(connectingAgent);
|
|
9100
|
+
else failedConnectionsRef.current.delete(connectingAgent);
|
|
9101
|
+
}
|
|
9102
|
+
});
|
|
9103
|
+
pendingConnectionsRef.current.set(connectingAgent, pending);
|
|
9104
|
+
}, [copilotkit]);
|
|
9007
9105
|
const pendingRunActivityReconnectRef = (0, react.useRef)(false);
|
|
9008
9106
|
const runActivityReconnectGenerationRef = (0, react.useRef)(0);
|
|
9009
9107
|
const activeLocalRunIdsRef = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
@@ -9063,9 +9161,12 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9063
9161
|
const selection = {
|
|
9064
9162
|
threadId: resolvedThreadId,
|
|
9065
9163
|
inspectorRequestId,
|
|
9066
|
-
agent
|
|
9164
|
+
agent,
|
|
9165
|
+
active: true
|
|
9067
9166
|
};
|
|
9068
9167
|
previousThreadRef.current = selection;
|
|
9168
|
+
submissionQueueRef.current = Promise.resolve();
|
|
9169
|
+
failedConnectionsRef.current.delete(agent);
|
|
9069
9170
|
const discardedThreadId = previousThread?.agent === agent ? previousThread.threadId : agent.threadId;
|
|
9070
9171
|
if (inspectorTransition) if (typeof copilotkit.stopAgent === "function") copilotkit.stopAgent({ agent });
|
|
9071
9172
|
else agent.abortRun?.();
|
|
@@ -9103,6 +9204,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9103
9204
|
}
|
|
9104
9205
|
return () => {
|
|
9105
9206
|
active = false;
|
|
9207
|
+
selection.active = false;
|
|
9106
9208
|
};
|
|
9107
9209
|
}
|
|
9108
9210
|
let detached = false;
|
|
@@ -9116,8 +9218,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9116
9218
|
await copilotkit.connectAgent({ agent: agentToConnect });
|
|
9117
9219
|
} catch (error) {
|
|
9118
9220
|
if (detached) return;
|
|
9119
|
-
console.error("CopilotChat: connectAgent failed", error);
|
|
9120
9221
|
if (inspectorRequestId) failInspectorOverride(inspectorRequestId);
|
|
9222
|
+
throw error;
|
|
9121
9223
|
} finally {
|
|
9122
9224
|
if (!detached) (typeof requestAnimationFrame === "function" ? requestAnimationFrame : (cb) => setTimeout(cb, 16))(() => {
|
|
9123
9225
|
if (!detached) setLastConnectedThreadId(resolvedThreadId);
|
|
@@ -9133,8 +9235,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9133
9235
|
}
|
|
9134
9236
|
}
|
|
9135
9237
|
};
|
|
9136
|
-
connect(agent);
|
|
9238
|
+
trackConnection(agent, () => connect(agent));
|
|
9137
9239
|
return () => {
|
|
9240
|
+
selection.active = false;
|
|
9138
9241
|
detached = true;
|
|
9139
9242
|
connectAbortController.abort();
|
|
9140
9243
|
const detach = agent.detachActiveRun().catch(() => {});
|
|
@@ -9197,7 +9300,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9197
9300
|
await copilotkit.connectAgent({ agent });
|
|
9198
9301
|
didConnect = true;
|
|
9199
9302
|
} catch (error) {
|
|
9200
|
-
if (!detached)
|
|
9303
|
+
if (!detached) throw error;
|
|
9201
9304
|
} finally {
|
|
9202
9305
|
if (wakeRunId) {
|
|
9203
9306
|
activeWakeRunIdsRef.current.delete(wakeRunId);
|
|
@@ -9207,7 +9310,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9207
9310
|
wakeReconnectActive = false;
|
|
9208
9311
|
if (!detached && runActivityReconnectGenerationRef.current === generation && activeConnectCountRef.current === 0 && pendingRunActivityReconnectRef.current) {
|
|
9209
9312
|
pendingRunActivityReconnectRef.current = false;
|
|
9210
|
-
connect
|
|
9313
|
+
trackConnection(agent, connect);
|
|
9211
9314
|
}
|
|
9212
9315
|
}
|
|
9213
9316
|
};
|
|
@@ -9223,7 +9326,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9223
9326
|
return;
|
|
9224
9327
|
}
|
|
9225
9328
|
pendingRunActivityReconnectRef.current = false;
|
|
9226
|
-
connect
|
|
9329
|
+
trackConnection(agent, connect);
|
|
9227
9330
|
};
|
|
9228
9331
|
const subscription = threadStore.subscribeToRunActivity((notification) => {
|
|
9229
9332
|
if (notification.threadId !== resolvedThreadId) return;
|
|
@@ -9266,6 +9369,18 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9266
9369
|
rememberRecentlyWakeRunId
|
|
9267
9370
|
]);
|
|
9268
9371
|
const waitForActiveRunToSettle = (0, react.useCallback)(async () => {
|
|
9372
|
+
const selection = previousThreadRef.current;
|
|
9373
|
+
const isCurrentSelection = () => selection?.active && previousThreadRef.current === selection;
|
|
9374
|
+
let connection = pendingConnectionsRef.current.get(agent);
|
|
9375
|
+
while (connection && isCurrentSelection()) {
|
|
9376
|
+
await connection;
|
|
9377
|
+
connection = pendingConnectionsRef.current.get(agent);
|
|
9378
|
+
}
|
|
9379
|
+
if (!isCurrentSelection()) return false;
|
|
9380
|
+
if (failedConnectionsRef.current.has(agent)) {
|
|
9381
|
+
setTranscriptionError("Could not load saved conversation. Reopen the thread and try again.");
|
|
9382
|
+
return "failed";
|
|
9383
|
+
}
|
|
9269
9384
|
const maybeAware = agent;
|
|
9270
9385
|
const activeRunCompletionPromise = (0, _copilotkit_core.isRunCompletionAware)(maybeAware) ? maybeAware.activeRunCompletionPromise : void 0;
|
|
9271
9386
|
if (agent.isRunning && activeRunCompletionPromise) try {
|
|
@@ -9273,7 +9388,18 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9273
9388
|
} catch (error) {
|
|
9274
9389
|
console.error("CopilotChat: in-flight run rejected while queuing send", error);
|
|
9275
9390
|
}
|
|
9391
|
+
return isCurrentSelection();
|
|
9276
9392
|
}, [agent]);
|
|
9393
|
+
const enqueueSubmission = (0, react.useCallback)((submit) => {
|
|
9394
|
+
const selection = previousThreadRef.current;
|
|
9395
|
+
const pending = submissionQueueRef.current.then(async () => {
|
|
9396
|
+
if (selection?.active && previousThreadRef.current === selection) await submit();
|
|
9397
|
+
}).catch((error) => {
|
|
9398
|
+
console.error("CopilotChat: queued submission failed", error);
|
|
9399
|
+
});
|
|
9400
|
+
submissionQueueRef.current = pending;
|
|
9401
|
+
return pending;
|
|
9402
|
+
}, []);
|
|
9277
9403
|
const onSubmitInput = (0, react.useCallback)(async (value) => {
|
|
9278
9404
|
if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
|
|
9279
9405
|
console.error("[CopilotKit] Cannot send while attachments are uploading (pre-await guard)");
|
|
@@ -9281,92 +9407,102 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9281
9407
|
return;
|
|
9282
9408
|
}
|
|
9283
9409
|
setInputValue("");
|
|
9284
|
-
await
|
|
9285
|
-
|
|
9286
|
-
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9410
|
+
await enqueueSubmission(async () => {
|
|
9411
|
+
const ready = await waitForActiveRunToSettle();
|
|
9412
|
+
if (ready !== true) {
|
|
9413
|
+
if (ready === "failed") setInputValue(value);
|
|
9414
|
+
return;
|
|
9415
|
+
}
|
|
9416
|
+
if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
|
|
9417
|
+
console.error("[CopilotKit] Cannot send while attachments are uploading (post-await re-check)");
|
|
9418
|
+
setTranscriptionError("Cannot send while attachments are uploading.");
|
|
9419
|
+
setInputValue(value);
|
|
9420
|
+
return;
|
|
9421
|
+
}
|
|
9422
|
+
const readyAttachments = consumeAttachments();
|
|
9423
|
+
if (readyAttachments.length > 0) {
|
|
9424
|
+
const contentParts = [];
|
|
9425
|
+
if (value.trim()) contentParts.push({
|
|
9426
|
+
type: "text",
|
|
9427
|
+
text: value
|
|
9428
|
+
});
|
|
9429
|
+
for (const att of readyAttachments) contentParts.push((0, _copilotkit_shared.createAttachmentContent)(att));
|
|
9430
|
+
agent.addMessage({
|
|
9431
|
+
id: (0, _copilotkit_shared.randomUUID)(),
|
|
9432
|
+
role: "user",
|
|
9433
|
+
content: contentParts
|
|
9434
|
+
});
|
|
9435
|
+
} else agent.addMessage({
|
|
9300
9436
|
id: (0, _copilotkit_shared.randomUUID)(),
|
|
9301
9437
|
role: "user",
|
|
9302
|
-
content:
|
|
9303
|
-
});
|
|
9304
|
-
} else agent.addMessage({
|
|
9305
|
-
id: (0, _copilotkit_shared.randomUUID)(),
|
|
9306
|
-
role: "user",
|
|
9307
|
-
content: value
|
|
9308
|
-
});
|
|
9309
|
-
const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
|
|
9310
|
-
if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
|
|
9311
|
-
try {
|
|
9312
|
-
await copilotkit.runAgent({
|
|
9313
|
-
agent,
|
|
9314
|
-
...localRunId !== void 0 ? { runId: localRunId } : {}
|
|
9438
|
+
content: value
|
|
9315
9439
|
});
|
|
9316
|
-
|
|
9317
|
-
|
|
9318
|
-
|
|
9319
|
-
|
|
9320
|
-
|
|
9321
|
-
|
|
9322
|
-
|
|
9323
|
-
|
|
9324
|
-
|
|
9325
|
-
|
|
9326
|
-
|
|
9327
|
-
|
|
9440
|
+
const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
|
|
9441
|
+
if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
|
|
9442
|
+
try {
|
|
9443
|
+
await copilotkit.runAgent({
|
|
9444
|
+
agent,
|
|
9445
|
+
...localRunId !== void 0 ? { runId: localRunId } : {}
|
|
9446
|
+
});
|
|
9447
|
+
} catch (error) {
|
|
9448
|
+
console.error("CopilotChat: runAgent failed", error);
|
|
9449
|
+
} finally {
|
|
9450
|
+
if (localRunId) {
|
|
9451
|
+
activeLocalRunIdsRef.current.delete(localRunId);
|
|
9452
|
+
rememberRecentlyLocalRunId(localRunId);
|
|
9453
|
+
}
|
|
9454
|
+
if (pendingRunActivityReconnectRef.current && activeLocalRunIdsRef.current.size === 0 && activeConnectCountRef.current === 0) {
|
|
9455
|
+
const startReconnect = startRunActivityReconnectRef.current;
|
|
9456
|
+
if (startReconnect) {
|
|
9457
|
+
pendingRunActivityReconnectRef.current = false;
|
|
9458
|
+
startReconnect(runActivityReconnectGenerationRef.current);
|
|
9459
|
+
}
|
|
9328
9460
|
}
|
|
9329
9461
|
}
|
|
9330
|
-
}
|
|
9462
|
+
});
|
|
9331
9463
|
}, [
|
|
9332
9464
|
agent,
|
|
9333
9465
|
consumeAttachments,
|
|
9334
9466
|
waitForActiveRunToSettle,
|
|
9467
|
+
enqueueSubmission,
|
|
9335
9468
|
hasNativeIntelligenceRunActivity,
|
|
9336
9469
|
rememberRecentlyLocalRunId
|
|
9337
9470
|
]);
|
|
9338
9471
|
const handleSelectSuggestion = (0, react.useCallback)(async (suggestion) => {
|
|
9339
|
-
await
|
|
9340
|
-
|
|
9341
|
-
|
|
9342
|
-
|
|
9343
|
-
|
|
9344
|
-
|
|
9345
|
-
const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
|
|
9346
|
-
if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
|
|
9347
|
-
try {
|
|
9348
|
-
await copilotkit.runAgent({
|
|
9349
|
-
agent,
|
|
9350
|
-
...localRunId !== void 0 ? { runId: localRunId } : {}
|
|
9472
|
+
await enqueueSubmission(async () => {
|
|
9473
|
+
if (await waitForActiveRunToSettle() !== true) return;
|
|
9474
|
+
agent.addMessage({
|
|
9475
|
+
id: (0, _copilotkit_shared.randomUUID)(),
|
|
9476
|
+
role: "user",
|
|
9477
|
+
content: suggestion.message
|
|
9351
9478
|
});
|
|
9352
|
-
|
|
9353
|
-
|
|
9354
|
-
|
|
9355
|
-
|
|
9356
|
-
|
|
9357
|
-
|
|
9358
|
-
|
|
9359
|
-
|
|
9360
|
-
|
|
9361
|
-
|
|
9362
|
-
|
|
9363
|
-
|
|
9479
|
+
const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
|
|
9480
|
+
if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
|
|
9481
|
+
try {
|
|
9482
|
+
await copilotkit.runAgent({
|
|
9483
|
+
agent,
|
|
9484
|
+
...localRunId !== void 0 ? { runId: localRunId } : {}
|
|
9485
|
+
});
|
|
9486
|
+
} catch (error) {
|
|
9487
|
+
console.error("CopilotChat: runAgent failed after selecting suggestion", error);
|
|
9488
|
+
} finally {
|
|
9489
|
+
if (localRunId) {
|
|
9490
|
+
activeLocalRunIdsRef.current.delete(localRunId);
|
|
9491
|
+
rememberRecentlyLocalRunId(localRunId);
|
|
9492
|
+
}
|
|
9493
|
+
if (pendingRunActivityReconnectRef.current && activeLocalRunIdsRef.current.size === 0 && activeConnectCountRef.current === 0) {
|
|
9494
|
+
const startReconnect = startRunActivityReconnectRef.current;
|
|
9495
|
+
if (startReconnect) {
|
|
9496
|
+
pendingRunActivityReconnectRef.current = false;
|
|
9497
|
+
startReconnect(runActivityReconnectGenerationRef.current);
|
|
9498
|
+
}
|
|
9364
9499
|
}
|
|
9365
9500
|
}
|
|
9366
|
-
}
|
|
9501
|
+
});
|
|
9367
9502
|
}, [
|
|
9368
9503
|
agent,
|
|
9369
9504
|
waitForActiveRunToSettle,
|
|
9505
|
+
enqueueSubmission,
|
|
9370
9506
|
hasNativeIntelligenceRunActivity,
|
|
9371
9507
|
rememberRecentlyLocalRunId
|
|
9372
9508
|
]);
|
|
@@ -13747,6 +13883,8 @@ Object.defineProperty(exports, 'mergeMetadata', {
|
|
|
13747
13883
|
return _ag_ui_client.mergeMetadata;
|
|
13748
13884
|
}
|
|
13749
13885
|
});
|
|
13886
|
+
exports.messageGroup = messageGroup;
|
|
13887
|
+
exports.messageRow = messageRow;
|
|
13750
13888
|
Object.defineProperty(exports, 'ofType', {
|
|
13751
13889
|
enumerable: true,
|
|
13752
13890
|
get: function () {
|