@copilotkitnext/react 0.0.27 → 0.0.29
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/index.d.mts +24 -9
- package/dist/index.d.ts +24 -9
- package/dist/index.js +23 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +85 -92
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.mjs
CHANGED
|
@@ -1378,7 +1378,7 @@ import "katex/dist/katex.min.css";
|
|
|
1378
1378
|
import { Streamdown } from "streamdown";
|
|
1379
1379
|
|
|
1380
1380
|
// src/hooks/use-render-tool-call.tsx
|
|
1381
|
-
import React6, { useCallback as useCallback2, useEffect as
|
|
1381
|
+
import React6, { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo4, useState as useState4, useSyncExternalStore } from "react";
|
|
1382
1382
|
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
1383
1383
|
|
|
1384
1384
|
// src/providers/CopilotKitProvider.tsx
|
|
@@ -1386,9 +1386,9 @@ import {
|
|
|
1386
1386
|
createContext as createContext2,
|
|
1387
1387
|
useContext as useContext2,
|
|
1388
1388
|
useMemo as useMemo3,
|
|
1389
|
-
useEffect as
|
|
1389
|
+
useEffect as useEffect3,
|
|
1390
1390
|
useReducer,
|
|
1391
|
-
useRef as
|
|
1391
|
+
useRef as useRef3,
|
|
1392
1392
|
useState as useState3
|
|
1393
1393
|
} from "react";
|
|
1394
1394
|
import { z } from "zod";
|
|
@@ -1438,36 +1438,23 @@ var CopilotKitCoreReact = class extends CopilotKitCore {
|
|
|
1438
1438
|
// src/components/CopilotKitInspector.tsx
|
|
1439
1439
|
import * as React4 from "react";
|
|
1440
1440
|
import { createComponent } from "@lit-labs/react";
|
|
1441
|
-
import {
|
|
1442
|
-
WEB_INSPECTOR_TAG,
|
|
1443
|
-
WebInspectorElement,
|
|
1444
|
-
defineWebInspector
|
|
1445
|
-
} from "@copilotkitnext/web-inspector";
|
|
1446
1441
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
react: React4
|
|
1452
|
-
});
|
|
1453
|
-
var CopilotKitInspector = React4.forwardRef(
|
|
1454
|
-
({ core, ...rest }, ref) => {
|
|
1455
|
-
const innerRef = React4.useRef(null);
|
|
1456
|
-
React4.useImperativeHandle(ref, () => innerRef.current, []);
|
|
1457
|
-
React4.useEffect(() => {
|
|
1458
|
-
if (innerRef.current) {
|
|
1459
|
-
innerRef.current.core = core ?? null;
|
|
1460
|
-
}
|
|
1461
|
-
}, [core]);
|
|
1462
|
-
return /* @__PURE__ */ jsx7(
|
|
1463
|
-
CopilotKitInspectorBase,
|
|
1464
|
-
{
|
|
1465
|
-
...rest,
|
|
1466
|
-
ref: innerRef
|
|
1467
|
-
}
|
|
1468
|
-
);
|
|
1442
|
+
var CopilotKitInspectorBase = React4.lazy(() => {
|
|
1443
|
+
if (typeof window === "undefined") {
|
|
1444
|
+
const NullComponent = () => null;
|
|
1445
|
+
return Promise.resolve({ default: NullComponent });
|
|
1469
1446
|
}
|
|
1470
|
-
)
|
|
1447
|
+
return import("@copilotkitnext/web-inspector").then((mod) => {
|
|
1448
|
+
mod.defineWebInspector?.();
|
|
1449
|
+
const Component = createComponent({
|
|
1450
|
+
tagName: mod.WEB_INSPECTOR_TAG,
|
|
1451
|
+
elementClass: mod.WebInspectorElement,
|
|
1452
|
+
react: React4
|
|
1453
|
+
});
|
|
1454
|
+
return { default: Component };
|
|
1455
|
+
});
|
|
1456
|
+
});
|
|
1457
|
+
var CopilotKitInspector = ({ core, ...rest }) => /* @__PURE__ */ jsx7(React4.Suspense, { fallback: null, children: /* @__PURE__ */ jsx7(CopilotKitInspectorBase, { ...rest, core: core ?? null }) });
|
|
1471
1458
|
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
1472
1459
|
|
|
1473
1460
|
// src/providers/CopilotKitProvider.tsx
|
|
@@ -1478,8 +1465,8 @@ var CopilotKitContext = createContext2({
|
|
|
1478
1465
|
function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
1479
1466
|
const empty = useMemo3(() => [], []);
|
|
1480
1467
|
const value = prop ?? empty;
|
|
1481
|
-
const initial =
|
|
1482
|
-
|
|
1468
|
+
const initial = useRef3(value);
|
|
1469
|
+
useEffect3(() => {
|
|
1483
1470
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) {
|
|
1484
1471
|
console.error(warningMessage);
|
|
1485
1472
|
}
|
|
@@ -1501,7 +1488,7 @@ var CopilotKitProvider = ({
|
|
|
1501
1488
|
useSingleEndpoint = false
|
|
1502
1489
|
}) => {
|
|
1503
1490
|
const [shouldRenderInspector, setShouldRenderInspector] = useState3(false);
|
|
1504
|
-
|
|
1491
|
+
useEffect3(() => {
|
|
1505
1492
|
if (typeof window === "undefined") {
|
|
1506
1493
|
return;
|
|
1507
1494
|
}
|
|
@@ -1614,7 +1601,7 @@ var CopilotKitProvider = ({
|
|
|
1614
1601
|
return copilotkit2;
|
|
1615
1602
|
}, [allTools, allRenderToolCalls, renderActivityMessagesList, renderCustomMessagesList, useSingleEndpoint]);
|
|
1616
1603
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
1617
|
-
|
|
1604
|
+
useEffect3(() => {
|
|
1618
1605
|
const subscription = copilotkit.subscribe({
|
|
1619
1606
|
onRenderToolCallsChanged: () => {
|
|
1620
1607
|
forceUpdate();
|
|
@@ -1624,7 +1611,7 @@ var CopilotKitProvider = ({
|
|
|
1624
1611
|
subscription.unsubscribe();
|
|
1625
1612
|
};
|
|
1626
1613
|
}, [copilotkit]);
|
|
1627
|
-
|
|
1614
|
+
useEffect3(() => {
|
|
1628
1615
|
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
1629
1616
|
copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
|
|
1630
1617
|
copilotkit.setHeaders(headers);
|
|
@@ -1650,7 +1637,7 @@ var useCopilotKit = () => {
|
|
|
1650
1637
|
if (!context) {
|
|
1651
1638
|
throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1652
1639
|
}
|
|
1653
|
-
|
|
1640
|
+
useEffect3(() => {
|
|
1654
1641
|
const subscription = context.copilotkit.subscribe({
|
|
1655
1642
|
onRuntimeConnectionStatusChanged: () => {
|
|
1656
1643
|
forceUpdate();
|
|
@@ -1738,7 +1725,7 @@ function useRenderToolCall() {
|
|
|
1738
1725
|
() => copilotkit.renderToolCalls,
|
|
1739
1726
|
() => copilotkit.renderToolCalls
|
|
1740
1727
|
);
|
|
1741
|
-
|
|
1728
|
+
useEffect4(() => {
|
|
1742
1729
|
const subscription = copilotkit.subscribe({
|
|
1743
1730
|
onToolExecutionStart: ({ toolCallId }) => {
|
|
1744
1731
|
setExecutingToolCallIds((prev) => {
|
|
@@ -1894,12 +1881,12 @@ function useRenderActivityMessage() {
|
|
|
1894
1881
|
}
|
|
1895
1882
|
|
|
1896
1883
|
// src/hooks/use-frontend-tool.tsx
|
|
1897
|
-
import { useEffect as
|
|
1884
|
+
import { useEffect as useEffect5 } from "react";
|
|
1898
1885
|
var EMPTY_DEPS = [];
|
|
1899
1886
|
function useFrontendTool(tool, deps) {
|
|
1900
1887
|
const { copilotkit } = useCopilotKit();
|
|
1901
1888
|
const extraDeps = deps ?? EMPTY_DEPS;
|
|
1902
|
-
|
|
1889
|
+
useEffect5(() => {
|
|
1903
1890
|
const name = tool.name;
|
|
1904
1891
|
if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
|
|
1905
1892
|
console.warn(
|
|
@@ -1931,11 +1918,11 @@ function useFrontendTool(tool, deps) {
|
|
|
1931
1918
|
}
|
|
1932
1919
|
|
|
1933
1920
|
// src/hooks/use-human-in-the-loop.tsx
|
|
1934
|
-
import { useCallback as useCallback4, useRef as
|
|
1921
|
+
import { useCallback as useCallback4, useRef as useRef4, useEffect as useEffect6 } from "react";
|
|
1935
1922
|
import React7 from "react";
|
|
1936
1923
|
function useHumanInTheLoop(tool, deps) {
|
|
1937
1924
|
const { copilotkit } = useCopilotKit();
|
|
1938
|
-
const resolvePromiseRef =
|
|
1925
|
+
const resolvePromiseRef = useRef4(null);
|
|
1939
1926
|
const respond = useCallback4(async (result) => {
|
|
1940
1927
|
if (resolvePromiseRef.current) {
|
|
1941
1928
|
resolvePromiseRef.current(result);
|
|
@@ -1985,7 +1972,7 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
1985
1972
|
render: RenderComponent
|
|
1986
1973
|
};
|
|
1987
1974
|
useFrontendTool(frontendTool, deps);
|
|
1988
|
-
|
|
1975
|
+
useEffect6(() => {
|
|
1989
1976
|
return () => {
|
|
1990
1977
|
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
1991
1978
|
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
@@ -1998,7 +1985,7 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
1998
1985
|
}
|
|
1999
1986
|
|
|
2000
1987
|
// src/hooks/use-agent.tsx
|
|
2001
|
-
import { useMemo as useMemo5, useEffect as
|
|
1988
|
+
import { useMemo as useMemo5, useEffect as useEffect7, useReducer as useReducer2 } from "react";
|
|
2002
1989
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4 } from "@copilotkitnext/shared";
|
|
2003
1990
|
import { ProxiedCopilotRuntimeAgent, CopilotKitCoreRuntimeConnectionStatus } from "@copilotkitnext/core";
|
|
2004
1991
|
var ALL_UPDATES = [
|
|
@@ -2044,7 +2031,7 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
2044
2031
|
JSON.stringify(copilotkit.headers),
|
|
2045
2032
|
copilotkit
|
|
2046
2033
|
]);
|
|
2047
|
-
|
|
2034
|
+
useEffect7(() => {
|
|
2048
2035
|
if (updateFlags.length === 0) {
|
|
2049
2036
|
return;
|
|
2050
2037
|
}
|
|
@@ -2079,26 +2066,32 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
2079
2066
|
}
|
|
2080
2067
|
|
|
2081
2068
|
// src/hooks/use-agent-context.tsx
|
|
2082
|
-
import { useEffect as
|
|
2069
|
+
import { useEffect as useEffect8, useMemo as useMemo6 } from "react";
|
|
2083
2070
|
function useAgentContext(context) {
|
|
2084
2071
|
const { description, value } = context;
|
|
2085
2072
|
const { copilotkit } = useCopilotKit();
|
|
2086
|
-
|
|
2073
|
+
const stringValue = useMemo6(() => {
|
|
2074
|
+
if (typeof value === "string") {
|
|
2075
|
+
return value;
|
|
2076
|
+
}
|
|
2077
|
+
return JSON.stringify(value);
|
|
2078
|
+
}, [value]);
|
|
2079
|
+
useEffect8(() => {
|
|
2087
2080
|
if (!copilotkit) return;
|
|
2088
|
-
const id = copilotkit.addContext(
|
|
2081
|
+
const id = copilotkit.addContext({ description, value: stringValue });
|
|
2089
2082
|
return () => {
|
|
2090
2083
|
copilotkit.removeContext(id);
|
|
2091
2084
|
};
|
|
2092
|
-
}, [description,
|
|
2085
|
+
}, [description, stringValue, copilotkit]);
|
|
2093
2086
|
}
|
|
2094
2087
|
|
|
2095
2088
|
// src/hooks/use-suggestions.tsx
|
|
2096
|
-
import { useCallback as useCallback5, useEffect as
|
|
2089
|
+
import { useCallback as useCallback5, useEffect as useEffect9, useMemo as useMemo7, useState as useState5 } from "react";
|
|
2097
2090
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID5 } from "@copilotkitnext/shared";
|
|
2098
2091
|
function useSuggestions({ agentId } = {}) {
|
|
2099
2092
|
const { copilotkit } = useCopilotKit();
|
|
2100
2093
|
const config = useCopilotChatConfiguration();
|
|
2101
|
-
const resolvedAgentId =
|
|
2094
|
+
const resolvedAgentId = useMemo7(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID5, [agentId, config?.agentId]);
|
|
2102
2095
|
const [suggestions, setSuggestions] = useState5(() => {
|
|
2103
2096
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2104
2097
|
return result.suggestions;
|
|
@@ -2107,12 +2100,12 @@ function useSuggestions({ agentId } = {}) {
|
|
|
2107
2100
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2108
2101
|
return result.isLoading;
|
|
2109
2102
|
});
|
|
2110
|
-
|
|
2103
|
+
useEffect9(() => {
|
|
2111
2104
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2112
2105
|
setSuggestions(result.suggestions);
|
|
2113
2106
|
setIsLoading(result.isLoading);
|
|
2114
2107
|
}, [copilotkit, resolvedAgentId]);
|
|
2115
|
-
|
|
2108
|
+
useEffect9(() => {
|
|
2116
2109
|
const subscription = copilotkit.subscribe({
|
|
2117
2110
|
onSuggestionsChanged: ({ agentId: changedAgentId, suggestions: suggestions2 }) => {
|
|
2118
2111
|
if (changedAgentId !== resolvedAgentId) {
|
|
@@ -2157,19 +2150,19 @@ function useSuggestions({ agentId } = {}) {
|
|
|
2157
2150
|
}
|
|
2158
2151
|
|
|
2159
2152
|
// src/hooks/use-configure-suggestions.tsx
|
|
2160
|
-
import { useCallback as useCallback6, useEffect as
|
|
2153
|
+
import { useCallback as useCallback6, useEffect as useEffect10, useMemo as useMemo8, useRef as useRef5 } from "react";
|
|
2161
2154
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID6 } from "@copilotkitnext/shared";
|
|
2162
2155
|
function useConfigureSuggestions(config, deps) {
|
|
2163
2156
|
const { copilotkit } = useCopilotKit();
|
|
2164
2157
|
const chatConfig = useCopilotChatConfiguration();
|
|
2165
2158
|
const extraDeps = deps ?? [];
|
|
2166
|
-
const resolvedConsumerAgentId =
|
|
2167
|
-
const rawConsumerAgentId =
|
|
2168
|
-
const normalizationCacheRef =
|
|
2159
|
+
const resolvedConsumerAgentId = useMemo8(() => chatConfig?.agentId ?? DEFAULT_AGENT_ID6, [chatConfig?.agentId]);
|
|
2160
|
+
const rawConsumerAgentId = useMemo8(() => config ? config.consumerAgentId : void 0, [config]);
|
|
2161
|
+
const normalizationCacheRef = useRef5({
|
|
2169
2162
|
serialized: null,
|
|
2170
2163
|
config: null
|
|
2171
2164
|
});
|
|
2172
|
-
const { normalizedConfig, serializedConfig } =
|
|
2165
|
+
const { normalizedConfig, serializedConfig } = useMemo8(() => {
|
|
2173
2166
|
if (!config) {
|
|
2174
2167
|
normalizationCacheRef.current = { serialized: null, config: null };
|
|
2175
2168
|
return { normalizedConfig: null, serializedConfig: null };
|
|
@@ -2199,10 +2192,10 @@ function useConfigureSuggestions(config, deps) {
|
|
|
2199
2192
|
normalizationCacheRef.current = { serialized, config: built };
|
|
2200
2193
|
return { normalizedConfig: built, serializedConfig: serialized };
|
|
2201
2194
|
}, [config, resolvedConsumerAgentId, ...extraDeps]);
|
|
2202
|
-
const latestConfigRef =
|
|
2195
|
+
const latestConfigRef = useRef5(null);
|
|
2203
2196
|
latestConfigRef.current = normalizedConfig;
|
|
2204
|
-
const previousSerializedConfigRef =
|
|
2205
|
-
const targetAgentId =
|
|
2197
|
+
const previousSerializedConfigRef = useRef5(null);
|
|
2198
|
+
const targetAgentId = useMemo8(() => {
|
|
2206
2199
|
if (!normalizedConfig) {
|
|
2207
2200
|
return resolvedConsumerAgentId;
|
|
2208
2201
|
}
|
|
@@ -2235,7 +2228,7 @@ function useConfigureSuggestions(config, deps) {
|
|
|
2235
2228
|
}
|
|
2236
2229
|
copilotkit.reloadSuggestions(targetAgentId);
|
|
2237
2230
|
}, [copilotkit, isGlobalConfig, normalizedConfig, targetAgentId]);
|
|
2238
|
-
|
|
2231
|
+
useEffect10(() => {
|
|
2239
2232
|
if (!serializedConfig || !latestConfigRef.current) {
|
|
2240
2233
|
return;
|
|
2241
2234
|
}
|
|
@@ -2245,7 +2238,7 @@ function useConfigureSuggestions(config, deps) {
|
|
|
2245
2238
|
copilotkit.removeSuggestionsConfig(id);
|
|
2246
2239
|
};
|
|
2247
2240
|
}, [copilotkit, serializedConfig, requestReload]);
|
|
2248
|
-
|
|
2241
|
+
useEffect10(() => {
|
|
2249
2242
|
if (!normalizedConfig) {
|
|
2250
2243
|
previousSerializedConfigRef.current = null;
|
|
2251
2244
|
return;
|
|
@@ -2258,7 +2251,7 @@ function useConfigureSuggestions(config, deps) {
|
|
|
2258
2251
|
}
|
|
2259
2252
|
requestReload();
|
|
2260
2253
|
}, [normalizedConfig, requestReload, serializedConfig]);
|
|
2261
|
-
|
|
2254
|
+
useEffect10(() => {
|
|
2262
2255
|
if (!normalizedConfig || extraDeps.length === 0) {
|
|
2263
2256
|
return;
|
|
2264
2257
|
}
|
|
@@ -2546,7 +2539,7 @@ CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistant
|
|
|
2546
2539
|
var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
|
|
2547
2540
|
|
|
2548
2541
|
// src/components/chat/CopilotChatUserMessage.tsx
|
|
2549
|
-
import { useMemo as
|
|
2542
|
+
import { useMemo as useMemo9, useState as useState7 } from "react";
|
|
2550
2543
|
import { Copy as Copy2, Check as Check3, Edit, ChevronLeft, ChevronRight } from "lucide-react";
|
|
2551
2544
|
import { twMerge as twMerge5 } from "tailwind-merge";
|
|
2552
2545
|
import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
@@ -2580,7 +2573,7 @@ function CopilotChatUserMessage({
|
|
|
2580
2573
|
className,
|
|
2581
2574
|
...props
|
|
2582
2575
|
}) {
|
|
2583
|
-
const flattenedContent =
|
|
2576
|
+
const flattenedContent = useMemo9(
|
|
2584
2577
|
() => flattenUserMessageContent(message.content),
|
|
2585
2578
|
[message.content]
|
|
2586
2579
|
);
|
|
@@ -3109,13 +3102,13 @@ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
|
3109
3102
|
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
3110
3103
|
|
|
3111
3104
|
// src/components/chat/CopilotChatView.tsx
|
|
3112
|
-
import React12, { useRef as
|
|
3105
|
+
import React12, { useRef as useRef6, useState as useState9, useEffect as useEffect12 } from "react";
|
|
3113
3106
|
import { twMerge as twMerge7 } from "tailwind-merge";
|
|
3114
3107
|
import { StickToBottom, useStickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
|
|
3115
3108
|
import { ChevronDown } from "lucide-react";
|
|
3116
3109
|
|
|
3117
3110
|
// src/hooks/use-keyboard-height.tsx
|
|
3118
|
-
import { useState as useState8, useEffect as
|
|
3111
|
+
import { useState as useState8, useEffect as useEffect11 } from "react";
|
|
3119
3112
|
function useKeyboardHeight() {
|
|
3120
3113
|
const [keyboardState, setKeyboardState] = useState8({
|
|
3121
3114
|
isKeyboardOpen: false,
|
|
@@ -3123,7 +3116,7 @@ function useKeyboardHeight() {
|
|
|
3123
3116
|
availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
3124
3117
|
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
3125
3118
|
});
|
|
3126
|
-
|
|
3119
|
+
useEffect11(() => {
|
|
3127
3120
|
if (typeof window === "undefined") {
|
|
3128
3121
|
return;
|
|
3129
3122
|
}
|
|
@@ -3176,12 +3169,12 @@ function CopilotChatView({
|
|
|
3176
3169
|
className,
|
|
3177
3170
|
...props
|
|
3178
3171
|
}) {
|
|
3179
|
-
const inputContainerRef =
|
|
3172
|
+
const inputContainerRef = useRef6(null);
|
|
3180
3173
|
const [inputContainerHeight, setInputContainerHeight] = useState9(0);
|
|
3181
3174
|
const [isResizing, setIsResizing] = useState9(false);
|
|
3182
|
-
const resizeTimeoutRef =
|
|
3175
|
+
const resizeTimeoutRef = useRef6(null);
|
|
3183
3176
|
const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
|
|
3184
|
-
|
|
3177
|
+
useEffect12(() => {
|
|
3185
3178
|
const element = inputContainerRef.current;
|
|
3186
3179
|
if (!element) return;
|
|
3187
3180
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -3293,10 +3286,10 @@ function CopilotChatView({
|
|
|
3293
3286
|
const [hasMounted, setHasMounted] = useState9(false);
|
|
3294
3287
|
const { scrollRef, contentRef, scrollToBottom } = useStickToBottom();
|
|
3295
3288
|
const [showScrollButton, setShowScrollButton] = useState9(false);
|
|
3296
|
-
|
|
3289
|
+
useEffect12(() => {
|
|
3297
3290
|
setHasMounted(true);
|
|
3298
3291
|
}, []);
|
|
3299
|
-
|
|
3292
|
+
useEffect12(() => {
|
|
3300
3293
|
if (autoScroll) return;
|
|
3301
3294
|
const scrollElement = scrollRef.current;
|
|
3302
3295
|
if (!scrollElement) return;
|
|
@@ -3428,14 +3421,14 @@ var CopilotChatView_default = CopilotChatView;
|
|
|
3428
3421
|
|
|
3429
3422
|
// src/components/chat/CopilotChat.tsx
|
|
3430
3423
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID7, randomUUID as randomUUID2 } from "@copilotkitnext/shared";
|
|
3431
|
-
import { useCallback as useCallback7, useEffect as
|
|
3424
|
+
import { useCallback as useCallback7, useEffect as useEffect13, useMemo as useMemo10 } from "react";
|
|
3432
3425
|
import { merge } from "ts-deepmerge";
|
|
3433
3426
|
import { AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
3434
3427
|
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
3435
3428
|
function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen, ...props }) {
|
|
3436
3429
|
const existingConfig = useCopilotChatConfiguration();
|
|
3437
3430
|
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID7;
|
|
3438
|
-
const resolvedThreadId =
|
|
3431
|
+
const resolvedThreadId = useMemo10(
|
|
3439
3432
|
() => threadId ?? existingConfig?.threadId ?? randomUUID2(),
|
|
3440
3433
|
[threadId, existingConfig?.threadId]
|
|
3441
3434
|
);
|
|
@@ -3448,7 +3441,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3448
3441
|
suggestionView: providedSuggestionView,
|
|
3449
3442
|
...restProps
|
|
3450
3443
|
} = props;
|
|
3451
|
-
|
|
3444
|
+
useEffect13(() => {
|
|
3452
3445
|
const connect = async (agent2) => {
|
|
3453
3446
|
try {
|
|
3454
3447
|
await copilotkit.connectAgent({ agent: agent2 });
|
|
@@ -3667,7 +3660,7 @@ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
|
3667
3660
|
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
3668
3661
|
|
|
3669
3662
|
// src/components/chat/CopilotSidebarView.tsx
|
|
3670
|
-
import { useEffect as
|
|
3663
|
+
import { useEffect as useEffect14, useRef as useRef7, useState as useState11 } from "react";
|
|
3671
3664
|
|
|
3672
3665
|
// src/components/chat/CopilotModalHeader.tsx
|
|
3673
3666
|
import { useCallback as useCallback8 } from "react";
|
|
@@ -3760,7 +3753,7 @@ var SIDEBAR_TRANSITION_MS = 260;
|
|
|
3760
3753
|
function CopilotSidebarView({ header, width, ...props }) {
|
|
3761
3754
|
const configuration = useCopilotChatConfiguration();
|
|
3762
3755
|
const isSidebarOpen = configuration?.isModalOpen ?? false;
|
|
3763
|
-
const sidebarRef =
|
|
3756
|
+
const sidebarRef = useRef7(null);
|
|
3764
3757
|
const [sidebarWidth, setSidebarWidth] = useState11(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
3765
3758
|
const widthToCss = (w) => {
|
|
3766
3759
|
return typeof w === "number" ? `${w}px` : w;
|
|
@@ -3771,7 +3764,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3771
3764
|
}
|
|
3772
3765
|
return w;
|
|
3773
3766
|
};
|
|
3774
|
-
|
|
3767
|
+
useEffect14(() => {
|
|
3775
3768
|
if (width !== void 0) {
|
|
3776
3769
|
return;
|
|
3777
3770
|
}
|
|
@@ -3850,7 +3843,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3850
3843
|
CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
3851
3844
|
|
|
3852
3845
|
// src/components/chat/CopilotPopupView.tsx
|
|
3853
|
-
import { useEffect as
|
|
3846
|
+
import { useEffect as useEffect15, useMemo as useMemo11, useRef as useRef8, useState as useState12 } from "react";
|
|
3854
3847
|
import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
3855
3848
|
var DEFAULT_POPUP_WIDTH = 420;
|
|
3856
3849
|
var DEFAULT_POPUP_HEIGHT = 560;
|
|
@@ -3875,10 +3868,10 @@ function CopilotPopupView({
|
|
|
3875
3868
|
const isPopupOpen = configuration?.isModalOpen ?? false;
|
|
3876
3869
|
const setModalOpen = configuration?.setModalOpen;
|
|
3877
3870
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3878
|
-
const containerRef =
|
|
3871
|
+
const containerRef = useRef8(null);
|
|
3879
3872
|
const [isRendered, setIsRendered] = useState12(isPopupOpen);
|
|
3880
3873
|
const [isAnimatingOut, setIsAnimatingOut] = useState12(false);
|
|
3881
|
-
|
|
3874
|
+
useEffect15(() => {
|
|
3882
3875
|
if (isPopupOpen) {
|
|
3883
3876
|
setIsRendered(true);
|
|
3884
3877
|
setIsAnimatingOut(false);
|
|
@@ -3894,7 +3887,7 @@ function CopilotPopupView({
|
|
|
3894
3887
|
}, 200);
|
|
3895
3888
|
return () => clearTimeout(timeout);
|
|
3896
3889
|
}, [isPopupOpen, isRendered]);
|
|
3897
|
-
|
|
3890
|
+
useEffect15(() => {
|
|
3898
3891
|
if (!isPopupOpen) {
|
|
3899
3892
|
return;
|
|
3900
3893
|
}
|
|
@@ -3910,7 +3903,7 @@ function CopilotPopupView({
|
|
|
3910
3903
|
window.addEventListener("keydown", handleKeyDown);
|
|
3911
3904
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3912
3905
|
}, [isPopupOpen, setModalOpen]);
|
|
3913
|
-
|
|
3906
|
+
useEffect15(() => {
|
|
3914
3907
|
if (!isPopupOpen) {
|
|
3915
3908
|
return;
|
|
3916
3909
|
}
|
|
@@ -3919,7 +3912,7 @@ function CopilotPopupView({
|
|
|
3919
3912
|
}, 200);
|
|
3920
3913
|
return () => clearTimeout(focusTimer);
|
|
3921
3914
|
}, [isPopupOpen]);
|
|
3922
|
-
|
|
3915
|
+
useEffect15(() => {
|
|
3923
3916
|
if (!isPopupOpen || !clickOutsideToClose) {
|
|
3924
3917
|
return;
|
|
3925
3918
|
}
|
|
@@ -3944,10 +3937,10 @@ function CopilotPopupView({
|
|
|
3944
3937
|
document.addEventListener("pointerdown", handlePointerDown);
|
|
3945
3938
|
return () => document.removeEventListener("pointerdown", handlePointerDown);
|
|
3946
3939
|
}, [isPopupOpen, clickOutsideToClose, setModalOpen]);
|
|
3947
|
-
const headerElement =
|
|
3940
|
+
const headerElement = useMemo11(() => renderSlot(header, CopilotModalHeader, {}), [header]);
|
|
3948
3941
|
const resolvedWidth = dimensionToCss(width, DEFAULT_POPUP_WIDTH);
|
|
3949
3942
|
const resolvedHeight = dimensionToCss(height, DEFAULT_POPUP_HEIGHT);
|
|
3950
|
-
const popupStyle =
|
|
3943
|
+
const popupStyle = useMemo11(
|
|
3951
3944
|
() => ({
|
|
3952
3945
|
"--copilot-popup-width": resolvedWidth,
|
|
3953
3946
|
"--copilot-popup-height": resolvedHeight,
|
|
@@ -4009,10 +4002,10 @@ function CopilotPopupView({
|
|
|
4009
4002
|
CopilotPopupView.displayName = "CopilotPopupView";
|
|
4010
4003
|
|
|
4011
4004
|
// src/components/chat/CopilotSidebar.tsx
|
|
4012
|
-
import { useMemo as
|
|
4005
|
+
import { useMemo as useMemo12 } from "react";
|
|
4013
4006
|
import { jsx as jsx24 } from "react/jsx-runtime";
|
|
4014
4007
|
function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
4015
|
-
const SidebarViewOverride =
|
|
4008
|
+
const SidebarViewOverride = useMemo12(() => {
|
|
4016
4009
|
const Component = (viewProps) => {
|
|
4017
4010
|
const { header: viewHeader, width: viewWidth, ...restProps } = viewProps;
|
|
4018
4011
|
return /* @__PURE__ */ jsx24(
|
|
@@ -4038,7 +4031,7 @@ function CopilotSidebar({ header, defaultOpen, width, ...chatProps }) {
|
|
|
4038
4031
|
CopilotSidebar.displayName = "CopilotSidebar";
|
|
4039
4032
|
|
|
4040
4033
|
// src/components/chat/CopilotPopup.tsx
|
|
4041
|
-
import { useMemo as
|
|
4034
|
+
import { useMemo as useMemo13 } from "react";
|
|
4042
4035
|
import { jsx as jsx25 } from "react/jsx-runtime";
|
|
4043
4036
|
function CopilotPopup({
|
|
4044
4037
|
header,
|
|
@@ -4048,7 +4041,7 @@ function CopilotPopup({
|
|
|
4048
4041
|
clickOutsideToClose,
|
|
4049
4042
|
...chatProps
|
|
4050
4043
|
}) {
|
|
4051
|
-
const PopupViewOverride =
|
|
4044
|
+
const PopupViewOverride = useMemo13(() => {
|
|
4052
4045
|
const Component = (viewProps) => {
|
|
4053
4046
|
const {
|
|
4054
4047
|
header: viewHeader,
|