@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.
- package/dist/{copilotkit-dHdNF7H5.cjs → copilotkit-BG1d4-qU.cjs} +326 -113
- package/dist/copilotkit-BG1d4-qU.cjs.map +1 -0
- package/dist/{copilotkit-W-bV_OSs.d.cts → copilotkit-BGHjMw0d.d.cts} +89 -3
- package/dist/copilotkit-BGHjMw0d.d.cts.map +1 -0
- package/dist/{copilotkit-B90cY0Zg.d.mts → copilotkit-BdH_CdBt.d.mts} +84 -3
- package/dist/copilotkit-BdH_CdBt.d.mts.map +1 -0
- package/dist/{copilotkit-LD7Gp2aV.mjs → copilotkit-C_Sy6Cc7.mjs} +315 -114
- 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 +88 -25
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/context.cjs.map +1 -1
- package/dist/v2/context.d.cts +5 -0
- package/dist/v2/context.d.cts.map +1 -1
- package/dist/v2/context.d.mts +5 -0
- package/dist/v2/context.d.mts.map +1 -1
- package/dist/v2/context.mjs.map +1 -1
- package/dist/v2/headless.cjs +19 -0
- package/dist/v2/headless.cjs.map +1 -1
- package/dist/v2/headless.d.cts +5 -0
- package/dist/v2/headless.d.cts.map +1 -1
- package/dist/v2/headless.d.mts.map +1 -1
- package/dist/v2/headless.mjs +20 -1
- package/dist/v2/headless.mjs.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 +315 -112
- package/dist/v2/index.umd.js.map +1 -1
- package/package.json +22 -11
- package/dist/copilotkit-B90cY0Zg.d.mts.map +0 -1
- package/dist/copilotkit-LD7Gp2aV.mjs.map +0 -1
- package/dist/copilotkit-W-bV_OSs.d.cts.map +0 -1
- package/dist/copilotkit-dHdNF7H5.cjs.map +0 -1
package/dist/v2/index.umd.js
CHANGED
|
@@ -282,6 +282,25 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
282
282
|
parentConfig?.threadId,
|
|
283
283
|
activeThreadOverride
|
|
284
284
|
]);
|
|
285
|
+
const copilotkit = (0, react.useContext)(CopilotKitContext)?.copilotkit;
|
|
286
|
+
const openThreadRef = (0, react.useRef)(null);
|
|
287
|
+
const latestThreadIdRef = (0, react.useRef)(resolvedThreadId);
|
|
288
|
+
latestThreadIdRef.current = resolvedThreadId;
|
|
289
|
+
(0, react.useEffect)(() => {
|
|
290
|
+
if (copilotkit === void 0) return;
|
|
291
|
+
const registration = copilotkit.registerOpenThread({
|
|
292
|
+
agentId: resolvedAgentId,
|
|
293
|
+
threadId: latestThreadIdRef.current
|
|
294
|
+
});
|
|
295
|
+
openThreadRef.current = registration;
|
|
296
|
+
return () => {
|
|
297
|
+
registration.unregister();
|
|
298
|
+
openThreadRef.current = null;
|
|
299
|
+
};
|
|
300
|
+
}, [copilotkit, resolvedAgentId]);
|
|
301
|
+
(0, react.useEffect)(() => {
|
|
302
|
+
openThreadRef.current?.update(resolvedThreadId);
|
|
303
|
+
}, [resolvedThreadId]);
|
|
285
304
|
const resolvedHasExplicitThreadId = (threadIdPropIsAuthoritative ? true : activeThreadOverride?.explicit ?? hasExplicitThreadId ?? false) || !!parentConfig?.hasExplicitThreadId;
|
|
286
305
|
const [internalModalOpen, setInternalModalOpen] = (0, react.useState)(isModalDefaultOpen ?? true);
|
|
287
306
|
const hasExplicitDefault = isModalDefaultOpen !== void 0;
|
|
@@ -1747,7 +1766,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1747
1766
|
|
|
1748
1767
|
//#endregion
|
|
1749
1768
|
//#region package.json
|
|
1750
|
-
var version = "1.
|
|
1769
|
+
var version = "1.77.1";
|
|
1751
1770
|
|
|
1752
1771
|
//#endregion
|
|
1753
1772
|
//#region src/v2/components/CopilotKitInspector.tsx
|
|
@@ -1983,12 +2002,14 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
1983
2002
|
* Fetches resource content on-demand via proxied MCP requests. The React shell
|
|
1984
2003
|
* owns the iframe; `bindMcpApp` owns the protocol.
|
|
1985
2004
|
*/
|
|
1986
|
-
const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, agent }) {
|
|
2005
|
+
const MCPAppsActivityRenderer = function MCPAppsActivityRenderer({ content, message, agent }) {
|
|
1987
2006
|
const { copilotkit } = useCopilotKit();
|
|
2007
|
+
const messageId = message?.id;
|
|
1988
2008
|
const containerRef = (0, react.useRef)(null);
|
|
1989
2009
|
const iframeRef = (0, react.useRef)(null);
|
|
1990
2010
|
const sessionRef = (0, react.useRef)(null);
|
|
1991
2011
|
const [error, setError] = (0, react.useState)(null);
|
|
2012
|
+
const [contentError, setContentError] = (0, react.useState)(null);
|
|
1992
2013
|
const [isLoading, setIsLoading] = (0, react.useState)(true);
|
|
1993
2014
|
const [iframeSize, setIframeSize] = (0, react.useState)({});
|
|
1994
2015
|
const [fetchedResource, setFetchedResource] = (0, react.useState)(null);
|
|
@@ -2007,6 +2028,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2007
2028
|
let mounted = true;
|
|
2008
2029
|
setIsLoading(true);
|
|
2009
2030
|
setError(null);
|
|
2031
|
+
setContentError(null);
|
|
2010
2032
|
const iframe = document.createElement("iframe");
|
|
2011
2033
|
iframe.style.width = "100%";
|
|
2012
2034
|
iframe.style.height = "100px";
|
|
@@ -2029,6 +2051,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2029
2051
|
getContent: () => contentRef.current,
|
|
2030
2052
|
getAgent: () => agentRef.current,
|
|
2031
2053
|
host: copilotkit,
|
|
2054
|
+
messageId,
|
|
2032
2055
|
hooks: {
|
|
2033
2056
|
onResource: (resource) => {
|
|
2034
2057
|
if (!mounted) return;
|
|
@@ -2038,6 +2061,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2038
2061
|
onSizeChanged: (size) => {
|
|
2039
2062
|
if (mounted) setIframeSize(size);
|
|
2040
2063
|
},
|
|
2064
|
+
onContentError: (err) => {
|
|
2065
|
+
if (mounted) setContentError(err);
|
|
2066
|
+
},
|
|
2041
2067
|
onError: (err) => {
|
|
2042
2068
|
if (!mounted) return;
|
|
2043
2069
|
setError(err);
|
|
@@ -2046,9 +2072,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2046
2072
|
}
|
|
2047
2073
|
});
|
|
2048
2074
|
sessionRef.current = session;
|
|
2049
|
-
|
|
2050
|
-
if (current.toolInput) session.sendToolInput(current.toolInput);
|
|
2051
|
-
if (current.result) session.sendToolResult(current.result);
|
|
2075
|
+
session.syncContent(contentRef.current);
|
|
2052
2076
|
} catch (err) {
|
|
2053
2077
|
console.error("[MCPAppsRenderer] Setup error:", err);
|
|
2054
2078
|
if (mounted) {
|
|
@@ -2068,6 +2092,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2068
2092
|
}, [
|
|
2069
2093
|
agent,
|
|
2070
2094
|
copilotkit,
|
|
2095
|
+
messageId,
|
|
2071
2096
|
content.resourceUri,
|
|
2072
2097
|
content.serverHash,
|
|
2073
2098
|
content.serverId
|
|
@@ -2082,11 +2107,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2082
2107
|
}
|
|
2083
2108
|
}, [iframeSize]);
|
|
2084
2109
|
(0, react.useEffect)(() => {
|
|
2085
|
-
|
|
2086
|
-
}, [content.toolInput]);
|
|
2087
|
-
(0, react.useEffect)(() => {
|
|
2088
|
-
if (content.result) sessionRef.current?.sendToolResult(content.result);
|
|
2089
|
-
}, [content.result]);
|
|
2110
|
+
sessionRef.current?.syncContent(contentRef.current);
|
|
2111
|
+
}, [content.toolInput, content.result]);
|
|
2090
2112
|
const borderStyle = fetchedResource?._meta?.ui?.prefersBorder === true ? {
|
|
2091
2113
|
borderRadius: "8px",
|
|
2092
2114
|
backgroundColor: "#f9f9f9",
|
|
@@ -2108,12 +2130,12 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
2108
2130
|
color: "#666"
|
|
2109
2131
|
},
|
|
2110
2132
|
children: "Loading..."
|
|
2111
|
-
}), error && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2133
|
+
}), (error ?? contentError) && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2112
2134
|
style: {
|
|
2113
2135
|
color: "red",
|
|
2114
2136
|
padding: "1rem"
|
|
2115
2137
|
},
|
|
2116
|
-
children: ["Error: ", error.message]
|
|
2138
|
+
children: ["Error: ", (error ?? contentError).message]
|
|
2117
2139
|
})]
|
|
2118
2140
|
});
|
|
2119
2141
|
};
|
|
@@ -3405,7 +3427,6 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3405
3427
|
- Use CSS Grid or Flexbox for layout. Ensure the UI looks good at any width.
|
|
3406
3428
|
- Minimal transitions (150ms) for hover/focus states only. No decorative animations.
|
|
3407
3429
|
- Keep the UI focused and dense — avoid excessive padding. Use compact spacing (8–12px gaps, 10–14px padding in controls).`;
|
|
3408
|
-
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)";
|
|
3409
3430
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
3410
3431
|
const empty = (0, react.useMemo)(() => [], []);
|
|
3411
3432
|
const value = prop ?? empty;
|
|
@@ -3415,7 +3436,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3415
3436
|
}, [value, warningMessage]);
|
|
3416
3437
|
return value;
|
|
3417
3438
|
}
|
|
3418
|
-
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 }) => {
|
|
3439
|
+
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 }) => {
|
|
3419
3440
|
const [shouldRenderInspector, setShouldRenderInspector] = (0, react.useState)(false);
|
|
3420
3441
|
const [inspectorVisible, setInspectorVisible] = (0, react.useState)(false);
|
|
3421
3442
|
(0, react.useEffect)(() => {
|
|
@@ -3598,7 +3619,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3598
3619
|
if (!openGenUIActive) return [];
|
|
3599
3620
|
return [{
|
|
3600
3621
|
name: "generateSandboxedUi",
|
|
3601
|
-
description: GENERATE_SANDBOXED_UI_DESCRIPTION,
|
|
3622
|
+
description: _copilotkit_shared.GENERATE_SANDBOXED_UI_DESCRIPTION,
|
|
3602
3623
|
parameters: GenerateSandboxedUiArgsSchema,
|
|
3603
3624
|
handler: async () => "UI generated",
|
|
3604
3625
|
followUp: true,
|
|
@@ -3650,7 +3671,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3650
3671
|
renderToolCalls: allRenderToolCalls,
|
|
3651
3672
|
renderActivityMessages: allActivityRenderers,
|
|
3652
3673
|
renderCustomMessages: renderCustomMessagesList,
|
|
3653
|
-
debug
|
|
3674
|
+
debug,
|
|
3675
|
+
learning
|
|
3654
3676
|
});
|
|
3655
3677
|
if (defaultThrottleMs !== void 0) copilotkitRef.current.setDefaultThrottleMs(defaultThrottleMs);
|
|
3656
3678
|
}
|
|
@@ -3755,6 +3777,32 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3755
3777
|
useSingleEndpoint,
|
|
3756
3778
|
debug
|
|
3757
3779
|
]);
|
|
3780
|
+
const learningEnabled = learning !== void 0;
|
|
3781
|
+
const trajectoryId = learning?.trajectoryId;
|
|
3782
|
+
const learningContainerIdsRef = (0, react.useRef)(learning?.learningContainerIds);
|
|
3783
|
+
(0, react.useEffect)(() => {
|
|
3784
|
+
copilotkit.setLearningConfig(learning);
|
|
3785
|
+
learningContainerIdsRef.current = learning?.learningContainerIds;
|
|
3786
|
+
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.");
|
|
3787
|
+
}, [copilotkit, learning]);
|
|
3788
|
+
(0, react.useEffect)(() => {
|
|
3789
|
+
if (!learningEnabled) return;
|
|
3790
|
+
let disposed = false;
|
|
3791
|
+
if (trajectoryId !== void 0) copilotkit.startTrajectory({
|
|
3792
|
+
trajectoryId,
|
|
3793
|
+
learningContainerIds: learningContainerIdsRef.current
|
|
3794
|
+
}).catch(() => {
|
|
3795
|
+
if (!disposed) console.warn("[CopilotKit] Failed to start interaction capture.");
|
|
3796
|
+
});
|
|
3797
|
+
return () => {
|
|
3798
|
+
disposed = true;
|
|
3799
|
+
copilotkit.stopTrajectory();
|
|
3800
|
+
};
|
|
3801
|
+
}, [
|
|
3802
|
+
copilotkit,
|
|
3803
|
+
learningEnabled,
|
|
3804
|
+
trajectoryId
|
|
3805
|
+
]);
|
|
3758
3806
|
const didMountRef = (0, react.useRef)(false);
|
|
3759
3807
|
(0, react.useEffect)(() => {
|
|
3760
3808
|
if (!didMountRef.current) return;
|
|
@@ -3817,8 +3865,13 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
3817
3865
|
]);
|
|
3818
3866
|
const contextValue = (0, react.useMemo)(() => ({
|
|
3819
3867
|
copilotkit,
|
|
3820
|
-
executingToolCallIds
|
|
3821
|
-
|
|
3868
|
+
executingToolCallIds,
|
|
3869
|
+
showIntelligenceIndicator
|
|
3870
|
+
}), [
|
|
3871
|
+
copilotkit,
|
|
3872
|
+
executingToolCallIds,
|
|
3873
|
+
showIntelligenceIndicator
|
|
3874
|
+
]);
|
|
3822
3875
|
const retryableRuntimeEntitlementFailure = runtimeEntitlements?.status !== "ready" && runtimeEntitlements?.error.retryable === true;
|
|
3823
3876
|
const hasNonReadyRuntimeEntitlement = runtimeEntitlements !== void 0 && runtimeEntitlements.status !== "ready";
|
|
3824
3877
|
const hasLegacyRuntimeEntitlementFallback = runtimeLicenseStatus === "valid" || runtimeLicenseStatus === "expiring";
|
|
@@ -6052,13 +6105,23 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
6052
6105
|
//#region src/v2/components/chat/CopilotChatToolCallsView.tsx
|
|
6053
6106
|
function CopilotChatToolCallsView({ message, messages = [] }) {
|
|
6054
6107
|
const renderToolCall = useRenderToolCall();
|
|
6108
|
+
const { copilotkit } = useCopilotKit();
|
|
6109
|
+
const subscribe = (0, react.useCallback)((onChange) => copilotkit.ɵsubscribeToLearningConfigured(onChange), [copilotkit]);
|
|
6110
|
+
const getSnapshot = () => copilotkit.ɵlearningConfigured;
|
|
6111
|
+
const learningConfigured = (0, react.useSyncExternalStore)(subscribe, getSnapshot, getSnapshot);
|
|
6055
6112
|
if (!message.toolCalls || message.toolCalls.length === 0) return null;
|
|
6056
6113
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: message.toolCalls.map((toolCall) => {
|
|
6057
|
-
const
|
|
6058
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: renderToolCall({
|
|
6114
|
+
const rendered = renderToolCall({
|
|
6059
6115
|
toolCall,
|
|
6060
|
-
toolMessage
|
|
6061
|
-
})
|
|
6116
|
+
toolMessage: messages.find((m) => m.role === "tool" && m.toolCallId === toolCall.id)
|
|
6117
|
+
});
|
|
6118
|
+
if (rendered === null) return null;
|
|
6119
|
+
if (!learningConfigured) return rendered;
|
|
6120
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6121
|
+
"data-tool-call-id": toolCall.id,
|
|
6122
|
+
style: { display: "contents" },
|
|
6123
|
+
children: rendered
|
|
6124
|
+
}, toolCall.id);
|
|
6062
6125
|
}) });
|
|
6063
6126
|
}
|
|
6064
6127
|
|
|
@@ -6402,6 +6465,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
6402
6465
|
const shouldShowToolbar = toolbarVisible && (hasContent || showInspectorShortcut) && !(isRunning && isLatestAssistantMessage);
|
|
6403
6466
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
6404
6467
|
"data-copilotkit": true,
|
|
6468
|
+
"data-message-id": message.id,
|
|
6405
6469
|
style: { display: "contents" },
|
|
6406
6470
|
children: children({
|
|
6407
6471
|
markdownRenderer: boundMarkdownRenderer,
|
|
@@ -7634,12 +7698,27 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7634
7698
|
}
|
|
7635
7699
|
return [...acc.values()];
|
|
7636
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:";
|
|
7637
7716
|
const VIRTUALIZE_THRESHOLD = 50;
|
|
7638
|
-
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 }) {
|
|
7639
7718
|
const isPinnedToBottom = (0, react.useContext)(ScrollPinnedContext);
|
|
7640
7719
|
const renderCustomMessage = useRenderCustomMessages();
|
|
7641
7720
|
const { renderActivityMessage } = useRenderActivityMessage();
|
|
7642
|
-
const { copilotkit } = useCopilotKit();
|
|
7721
|
+
const { copilotkit, showIntelligenceIndicator = true } = useCopilotKit();
|
|
7643
7722
|
const config = useCopilotChatConfiguration();
|
|
7644
7723
|
const [, forceUpdate] = (0, react.useReducer)((x) => x + 1, 0);
|
|
7645
7724
|
(0, react.useEffect)(() => {
|
|
@@ -7668,20 +7747,43 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7668
7747
|
return copilotkit.getStateByRun(config.agentId, config.threadId, resolvedRunId);
|
|
7669
7748
|
};
|
|
7670
7749
|
const deduplicatedMessages = (0, react.useMemo)(() => deduplicateMessages(messages), [messages]);
|
|
7671
|
-
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
|
+
]);
|
|
7672
7757
|
const latestRenderedId = renderedMessages[renderedMessages.length - 1]?.id;
|
|
7673
7758
|
const transformDuplicateId = (0, react.useMemo)(() => {
|
|
7674
|
-
if (process.env.NODE_ENV === "production" || !transformMessages) return;
|
|
7759
|
+
if (process.env.NODE_ENV === "production" || !transformMessages && !groupMessages) return;
|
|
7675
7760
|
const seen = /* @__PURE__ */ new Set();
|
|
7676
7761
|
for (const message of renderedMessages) {
|
|
7677
7762
|
if (seen.has(message.id)) return message.id;
|
|
7678
7763
|
seen.add(message.id);
|
|
7679
7764
|
}
|
|
7680
|
-
}, [
|
|
7765
|
+
}, [
|
|
7766
|
+
renderedMessages,
|
|
7767
|
+
transformMessages,
|
|
7768
|
+
groupMessages
|
|
7769
|
+
]);
|
|
7681
7770
|
(0, react.useEffect)(() => {
|
|
7682
7771
|
if (transformDuplicateId === void 0) return;
|
|
7683
|
-
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.`);
|
|
7684
|
-
}, [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]);
|
|
7685
7787
|
const rowKeyStoreRef = (0, react.useRef)(null);
|
|
7686
7788
|
rowKeyStoreRef.current ?? (rowKeyStoreRef.current = (0, _copilotkit_shared.createRowKeyStore)());
|
|
7687
7789
|
const rowKeyStore = rowKeyStoreRef.current;
|
|
@@ -7689,6 +7791,31 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7689
7791
|
(0, react.useLayoutEffect)(() => {
|
|
7690
7792
|
(0, _copilotkit_shared.commitRowKeyStore)(rowKeyStore, renderedMessages);
|
|
7691
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]);
|
|
7692
7819
|
if (process.env.NODE_ENV === "development" && deduplicatedMessages.length < messages.length) console.warn(`CopilotChatMessageView: Merged ${messages.length - deduplicatedMessages.length} message(s) with duplicate IDs.`);
|
|
7693
7820
|
const { Component: AssistantComponent, slotProps: assistantSlotProps } = (0, react.useMemo)(() => resolveSlotComponent(assistantMessage, CopilotChatAssistantMessage_default), [assistantMessage]);
|
|
7694
7821
|
const agentId = config?.agentId;
|
|
@@ -7728,7 +7855,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7728
7855
|
(0, react.useEffect)(() => {
|
|
7729
7856
|
if (process.env.NODE_ENV === "production" || !childrenDisabledVirtualization || warnedChildrenRef.current) return;
|
|
7730
7857
|
warnedChildrenRef.current = true;
|
|
7731
|
-
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."));
|
|
7732
7859
|
}, [
|
|
7733
7860
|
childrenDisabledVirtualization,
|
|
7734
7861
|
renderedMessages.length,
|
|
@@ -7768,7 +7895,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7768
7895
|
return item.start < (instance.scrollOffset ?? 0) + scrollAdjustments;
|
|
7769
7896
|
}, []);
|
|
7770
7897
|
const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
|
|
7771
|
-
count: shouldVirtualize ?
|
|
7898
|
+
count: shouldVirtualize ? rows.length : 0,
|
|
7772
7899
|
getScrollElement: () => scrollElement,
|
|
7773
7900
|
estimateSize: estimateRowSize,
|
|
7774
7901
|
overscan: 5,
|
|
@@ -7781,8 +7908,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7781
7908
|
isPinnedToBottomRef.current = isPinnedToBottom;
|
|
7782
7909
|
virtualizer.shouldAdjustScrollPositionOnItemSizeChange = shouldAdjustScrollOnResize;
|
|
7783
7910
|
(0, react.useLayoutEffect)(() => {
|
|
7784
|
-
if (!shouldVirtualize || !
|
|
7785
|
-
virtualizer.scrollToIndex(
|
|
7911
|
+
if (!shouldVirtualize || !rows.length) return;
|
|
7912
|
+
virtualizer.scrollToIndex(rows.length - 1, { align: "end" });
|
|
7786
7913
|
}, [shouldVirtualize, firstMessageId]);
|
|
7787
7914
|
const intelligenceTurnAnchors = (0, react.useMemo)(() => getIntelligenceTurnAnchors(deduplicatedMessages, renderedMessages), [deduplicatedMessages, renderedMessages]);
|
|
7788
7915
|
const renderMessageBlock = (message) => {
|
|
@@ -7826,7 +7953,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7826
7953
|
renderCustomMessage,
|
|
7827
7954
|
stateSnapshot
|
|
7828
7955
|
}, `${rowKey}-custom-after`));
|
|
7829
|
-
const intelligenceTurnId = intelligenceTurnAnchors.get(message.id);
|
|
7956
|
+
const intelligenceTurnId = showIntelligenceIndicator ? intelligenceTurnAnchors.get(message.id) : void 0;
|
|
7830
7957
|
if (intelligenceTurnId !== void 0) elements.push(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(IntelligenceIndicator, {
|
|
7831
7958
|
message,
|
|
7832
7959
|
agentId: config?.agentId ?? _copilotkit_shared.DEFAULT_AGENT_ID,
|
|
@@ -7834,7 +7961,20 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7834
7961
|
}, `intelligence-${intelligenceTurnId}`));
|
|
7835
7962
|
return elements.filter(Boolean);
|
|
7836
7963
|
};
|
|
7837
|
-
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);
|
|
7838
7978
|
if (children) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
7839
7979
|
"data-copilotkit": true,
|
|
7840
7980
|
style: { display: "contents" },
|
|
@@ -7859,7 +7999,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7859
7999
|
position: "relative"
|
|
7860
8000
|
},
|
|
7861
8001
|
children: virtualizer.getVirtualItems().map((virtualItem) => {
|
|
7862
|
-
const
|
|
8002
|
+
const row = rows[virtualItem.index];
|
|
7863
8003
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
7864
8004
|
"data-index": virtualItem.index,
|
|
7865
8005
|
ref: virtualizer.measureElement,
|
|
@@ -7870,8 +8010,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
7870
8010
|
width: "100%",
|
|
7871
8011
|
transform: `translateY(${virtualItem.start}px)`
|
|
7872
8012
|
},
|
|
7873
|
-
children:
|
|
7874
|
-
},
|
|
8013
|
+
children: renderRow(row)
|
|
8014
|
+
}, rowKey(row));
|
|
7875
8015
|
})
|
|
7876
8016
|
}) : messageElements,
|
|
7877
8017
|
interruptElement,
|
|
@@ -8939,6 +9079,29 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
8939
9079
|
const [lastConnectedThreadId, setLastConnectedThreadId] = (0, react.useState)(null);
|
|
8940
9080
|
const isConnecting = hasExplicitThreadId && lastConnectedThreadId !== resolvedThreadId;
|
|
8941
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]);
|
|
8942
9105
|
const pendingRunActivityReconnectRef = (0, react.useRef)(false);
|
|
8943
9106
|
const runActivityReconnectGenerationRef = (0, react.useRef)(0);
|
|
8944
9107
|
const activeLocalRunIdsRef = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
@@ -8998,9 +9161,12 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
8998
9161
|
const selection = {
|
|
8999
9162
|
threadId: resolvedThreadId,
|
|
9000
9163
|
inspectorRequestId,
|
|
9001
|
-
agent
|
|
9164
|
+
agent,
|
|
9165
|
+
active: true
|
|
9002
9166
|
};
|
|
9003
9167
|
previousThreadRef.current = selection;
|
|
9168
|
+
submissionQueueRef.current = Promise.resolve();
|
|
9169
|
+
failedConnectionsRef.current.delete(agent);
|
|
9004
9170
|
const discardedThreadId = previousThread?.agent === agent ? previousThread.threadId : agent.threadId;
|
|
9005
9171
|
if (inspectorTransition) if (typeof copilotkit.stopAgent === "function") copilotkit.stopAgent({ agent });
|
|
9006
9172
|
else agent.abortRun?.();
|
|
@@ -9038,6 +9204,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9038
9204
|
}
|
|
9039
9205
|
return () => {
|
|
9040
9206
|
active = false;
|
|
9207
|
+
selection.active = false;
|
|
9041
9208
|
};
|
|
9042
9209
|
}
|
|
9043
9210
|
let detached = false;
|
|
@@ -9051,8 +9218,8 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9051
9218
|
await copilotkit.connectAgent({ agent: agentToConnect });
|
|
9052
9219
|
} catch (error) {
|
|
9053
9220
|
if (detached) return;
|
|
9054
|
-
console.error("CopilotChat: connectAgent failed", error);
|
|
9055
9221
|
if (inspectorRequestId) failInspectorOverride(inspectorRequestId);
|
|
9222
|
+
throw error;
|
|
9056
9223
|
} finally {
|
|
9057
9224
|
if (!detached) (typeof requestAnimationFrame === "function" ? requestAnimationFrame : (cb) => setTimeout(cb, 16))(() => {
|
|
9058
9225
|
if (!detached) setLastConnectedThreadId(resolvedThreadId);
|
|
@@ -9068,8 +9235,9 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9068
9235
|
}
|
|
9069
9236
|
}
|
|
9070
9237
|
};
|
|
9071
|
-
connect(agent);
|
|
9238
|
+
trackConnection(agent, () => connect(agent));
|
|
9072
9239
|
return () => {
|
|
9240
|
+
selection.active = false;
|
|
9073
9241
|
detached = true;
|
|
9074
9242
|
connectAbortController.abort();
|
|
9075
9243
|
const detach = agent.detachActiveRun().catch(() => {});
|
|
@@ -9132,7 +9300,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9132
9300
|
await copilotkit.connectAgent({ agent });
|
|
9133
9301
|
didConnect = true;
|
|
9134
9302
|
} catch (error) {
|
|
9135
|
-
if (!detached)
|
|
9303
|
+
if (!detached) throw error;
|
|
9136
9304
|
} finally {
|
|
9137
9305
|
if (wakeRunId) {
|
|
9138
9306
|
activeWakeRunIdsRef.current.delete(wakeRunId);
|
|
@@ -9142,7 +9310,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9142
9310
|
wakeReconnectActive = false;
|
|
9143
9311
|
if (!detached && runActivityReconnectGenerationRef.current === generation && activeConnectCountRef.current === 0 && pendingRunActivityReconnectRef.current) {
|
|
9144
9312
|
pendingRunActivityReconnectRef.current = false;
|
|
9145
|
-
connect
|
|
9313
|
+
trackConnection(agent, connect);
|
|
9146
9314
|
}
|
|
9147
9315
|
}
|
|
9148
9316
|
};
|
|
@@ -9158,7 +9326,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9158
9326
|
return;
|
|
9159
9327
|
}
|
|
9160
9328
|
pendingRunActivityReconnectRef.current = false;
|
|
9161
|
-
connect
|
|
9329
|
+
trackConnection(agent, connect);
|
|
9162
9330
|
};
|
|
9163
9331
|
const subscription = threadStore.subscribeToRunActivity((notification) => {
|
|
9164
9332
|
if (notification.threadId !== resolvedThreadId) return;
|
|
@@ -9201,6 +9369,18 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9201
9369
|
rememberRecentlyWakeRunId
|
|
9202
9370
|
]);
|
|
9203
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
|
+
}
|
|
9204
9384
|
const maybeAware = agent;
|
|
9205
9385
|
const activeRunCompletionPromise = (0, _copilotkit_core.isRunCompletionAware)(maybeAware) ? maybeAware.activeRunCompletionPromise : void 0;
|
|
9206
9386
|
if (agent.isRunning && activeRunCompletionPromise) try {
|
|
@@ -9208,7 +9388,18 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9208
9388
|
} catch (error) {
|
|
9209
9389
|
console.error("CopilotChat: in-flight run rejected while queuing send", error);
|
|
9210
9390
|
}
|
|
9391
|
+
return isCurrentSelection();
|
|
9211
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
|
+
}, []);
|
|
9212
9403
|
const onSubmitInput = (0, react.useCallback)(async (value) => {
|
|
9213
9404
|
if (selectedAttachmentsRef.current.some((a) => a.status === "uploading")) {
|
|
9214
9405
|
console.error("[CopilotKit] Cannot send while attachments are uploading (pre-await guard)");
|
|
@@ -9216,92 +9407,102 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9216
9407
|
return;
|
|
9217
9408
|
}
|
|
9218
9409
|
setInputValue("");
|
|
9219
|
-
await
|
|
9220
|
-
|
|
9221
|
-
|
|
9222
|
-
|
|
9223
|
-
|
|
9224
|
-
|
|
9225
|
-
|
|
9226
|
-
|
|
9227
|
-
|
|
9228
|
-
|
|
9229
|
-
|
|
9230
|
-
|
|
9231
|
-
|
|
9232
|
-
|
|
9233
|
-
|
|
9234
|
-
|
|
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({
|
|
9235
9436
|
id: (0, _copilotkit_shared.randomUUID)(),
|
|
9236
9437
|
role: "user",
|
|
9237
|
-
content:
|
|
9438
|
+
content: value
|
|
9238
9439
|
});
|
|
9239
|
-
|
|
9240
|
-
|
|
9241
|
-
|
|
9242
|
-
|
|
9243
|
-
|
|
9244
|
-
|
|
9245
|
-
|
|
9246
|
-
|
|
9247
|
-
|
|
9248
|
-
|
|
9249
|
-
|
|
9250
|
-
|
|
9251
|
-
|
|
9252
|
-
|
|
9253
|
-
|
|
9254
|
-
|
|
9255
|
-
|
|
9256
|
-
|
|
9257
|
-
|
|
9258
|
-
|
|
9259
|
-
const startReconnect = startRunActivityReconnectRef.current;
|
|
9260
|
-
if (startReconnect) {
|
|
9261
|
-
pendingRunActivityReconnectRef.current = false;
|
|
9262
|
-
startReconnect(runActivityReconnectGenerationRef.current);
|
|
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
|
+
}
|
|
9263
9460
|
}
|
|
9264
9461
|
}
|
|
9265
|
-
}
|
|
9462
|
+
});
|
|
9266
9463
|
}, [
|
|
9267
9464
|
agent,
|
|
9268
9465
|
consumeAttachments,
|
|
9269
9466
|
waitForActiveRunToSettle,
|
|
9467
|
+
enqueueSubmission,
|
|
9270
9468
|
hasNativeIntelligenceRunActivity,
|
|
9271
9469
|
rememberRecentlyLocalRunId
|
|
9272
9470
|
]);
|
|
9273
9471
|
const handleSelectSuggestion = (0, react.useCallback)(async (suggestion) => {
|
|
9274
|
-
await
|
|
9275
|
-
|
|
9276
|
-
|
|
9277
|
-
|
|
9278
|
-
|
|
9279
|
-
|
|
9280
|
-
const localRunId = hasNativeIntelligenceRunActivity ? (0, _copilotkit_shared.randomUUID)() : void 0;
|
|
9281
|
-
if (localRunId) activeLocalRunIdsRef.current.add(localRunId);
|
|
9282
|
-
try {
|
|
9283
|
-
await copilotkit.runAgent({
|
|
9284
|
-
agent,
|
|
9285
|
-
...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
|
|
9286
9478
|
});
|
|
9287
|
-
|
|
9288
|
-
|
|
9289
|
-
|
|
9290
|
-
|
|
9291
|
-
|
|
9292
|
-
|
|
9293
|
-
|
|
9294
|
-
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
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
|
+
}
|
|
9299
9499
|
}
|
|
9300
9500
|
}
|
|
9301
|
-
}
|
|
9501
|
+
});
|
|
9302
9502
|
}, [
|
|
9303
9503
|
agent,
|
|
9304
9504
|
waitForActiveRunToSettle,
|
|
9505
|
+
enqueueSubmission,
|
|
9305
9506
|
hasNativeIntelligenceRunActivity,
|
|
9306
9507
|
rememberRecentlyLocalRunId
|
|
9307
9508
|
]);
|
|
@@ -9953,7 +10154,7 @@ _radix_ui_react_dropdown_menu = __toESM(_radix_ui_react_dropdown_menu);
|
|
|
9953
10154
|
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]";
|
|
9954
10155
|
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [toggleButtonElement, isRendered ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
9955
10156
|
"data-copilotkit": true,
|
|
9956
|
-
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"),
|
|
10157
|
+
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"),
|
|
9957
10158
|
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
9958
10159
|
ref: containerRef,
|
|
9959
10160
|
tabIndex: -1,
|
|
@@ -13682,6 +13883,8 @@ Object.defineProperty(exports, 'mergeMetadata', {
|
|
|
13682
13883
|
return _ag_ui_client.mergeMetadata;
|
|
13683
13884
|
}
|
|
13684
13885
|
});
|
|
13886
|
+
exports.messageGroup = messageGroup;
|
|
13887
|
+
exports.messageRow = messageRow;
|
|
13685
13888
|
Object.defineProperty(exports, 'ofType', {
|
|
13686
13889
|
enumerable: true,
|
|
13687
13890
|
get: function () {
|