@copilotkitnext/react 0.0.29 → 0.0.31
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 +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +49 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +107 -86
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
package/dist/index.mjs
CHANGED
|
@@ -1364,7 +1364,7 @@ CopilotChatInput.AddMenuButton.displayName = "CopilotChatInput.AddMenuButton";
|
|
|
1364
1364
|
var CopilotChatInput_default = CopilotChatInput;
|
|
1365
1365
|
|
|
1366
1366
|
// src/components/chat/CopilotChatAssistantMessage.tsx
|
|
1367
|
-
import { useState as
|
|
1367
|
+
import { useState as useState7 } from "react";
|
|
1368
1368
|
import {
|
|
1369
1369
|
Copy,
|
|
1370
1370
|
Check as Check2,
|
|
@@ -1378,19 +1378,11 @@ 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 useEffect5, useMemo as useMemo4, useState as useState5, useSyncExternalStore } from "react";
|
|
1382
1382
|
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
1383
1383
|
|
|
1384
1384
|
// src/providers/CopilotKitProvider.tsx
|
|
1385
|
-
import {
|
|
1386
|
-
createContext as createContext2,
|
|
1387
|
-
useContext as useContext2,
|
|
1388
|
-
useMemo as useMemo3,
|
|
1389
|
-
useEffect as useEffect3,
|
|
1390
|
-
useReducer,
|
|
1391
|
-
useRef as useRef3,
|
|
1392
|
-
useState as useState3
|
|
1393
|
-
} from "react";
|
|
1385
|
+
import { createContext as createContext2, useContext as useContext2, useMemo as useMemo3, useEffect as useEffect4, useReducer, useRef as useRef3, useState as useState4 } from "react";
|
|
1394
1386
|
import { z } from "zod";
|
|
1395
1387
|
|
|
1396
1388
|
// src/lib/react-core.ts
|
|
@@ -1439,26 +1431,34 @@ var CopilotKitCoreReact = class extends CopilotKitCore {
|
|
|
1439
1431
|
import * as React4 from "react";
|
|
1440
1432
|
import { createComponent } from "@lit-labs/react";
|
|
1441
1433
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
1442
|
-
var
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1434
|
+
var CopilotKitInspector = ({ core, ...rest }) => {
|
|
1435
|
+
const [InspectorComponent, setInspectorComponent] = React4.useState(null);
|
|
1436
|
+
React4.useEffect(() => {
|
|
1437
|
+
let mounted = true;
|
|
1438
|
+
import("@copilotkitnext/web-inspector").then((mod) => {
|
|
1439
|
+
mod.defineWebInspector?.();
|
|
1440
|
+
const Component = createComponent({
|
|
1441
|
+
tagName: mod.WEB_INSPECTOR_TAG,
|
|
1442
|
+
elementClass: mod.WebInspectorElement,
|
|
1443
|
+
react: React4
|
|
1444
|
+
});
|
|
1445
|
+
if (mounted) {
|
|
1446
|
+
setInspectorComponent(() => Component);
|
|
1447
|
+
}
|
|
1453
1448
|
});
|
|
1454
|
-
return
|
|
1455
|
-
|
|
1456
|
-
}
|
|
1457
|
-
|
|
1449
|
+
return () => {
|
|
1450
|
+
mounted = false;
|
|
1451
|
+
};
|
|
1452
|
+
}, []);
|
|
1453
|
+
if (!InspectorComponent) return null;
|
|
1454
|
+
return /* @__PURE__ */ jsx7(InspectorComponent, { ...rest, core: core ?? null });
|
|
1455
|
+
};
|
|
1458
1456
|
CopilotKitInspector.displayName = "CopilotKitInspector";
|
|
1459
1457
|
|
|
1460
1458
|
// src/providers/CopilotKitProvider.tsx
|
|
1461
1459
|
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1460
|
+
var HEADER_NAME = "X-CopilotCloud-Public-Api-Key";
|
|
1461
|
+
var COPILOT_CLOUD_CHAT_URL = "https://api.cloud.copilotkit.ai/copilotkit/v1";
|
|
1462
1462
|
var CopilotKitContext = createContext2({
|
|
1463
1463
|
copilotkit: null
|
|
1464
1464
|
});
|
|
@@ -1466,7 +1466,7 @@ function useStableArrayProp(prop, warningMessage, isMeaningfulChange) {
|
|
|
1466
1466
|
const empty = useMemo3(() => [], []);
|
|
1467
1467
|
const value = prop ?? empty;
|
|
1468
1468
|
const initial = useRef3(value);
|
|
1469
|
-
|
|
1469
|
+
useEffect4(() => {
|
|
1470
1470
|
if (warningMessage && value !== initial.current && (isMeaningfulChange ? isMeaningfulChange(initial.current, value) : true)) {
|
|
1471
1471
|
console.error(warningMessage);
|
|
1472
1472
|
}
|
|
@@ -1477,6 +1477,8 @@ var CopilotKitProvider = ({
|
|
|
1477
1477
|
children,
|
|
1478
1478
|
runtimeUrl,
|
|
1479
1479
|
headers = {},
|
|
1480
|
+
publicApiKey,
|
|
1481
|
+
publicLicenseKey,
|
|
1480
1482
|
properties = {},
|
|
1481
1483
|
agents__unsafe_dev_only: agents = {},
|
|
1482
1484
|
renderToolCalls,
|
|
@@ -1487,8 +1489,8 @@ var CopilotKitProvider = ({
|
|
|
1487
1489
|
showDevConsole = false,
|
|
1488
1490
|
useSingleEndpoint = false
|
|
1489
1491
|
}) => {
|
|
1490
|
-
const [shouldRenderInspector, setShouldRenderInspector] =
|
|
1491
|
-
|
|
1492
|
+
const [shouldRenderInspector, setShouldRenderInspector] = useState4(false);
|
|
1493
|
+
useEffect4(() => {
|
|
1492
1494
|
if (typeof window === "undefined") {
|
|
1493
1495
|
return;
|
|
1494
1496
|
}
|
|
@@ -1526,6 +1528,25 @@ var CopilotKitProvider = ({
|
|
|
1526
1528
|
renderActivityMessages,
|
|
1527
1529
|
"renderActivityMessages must be a stable array."
|
|
1528
1530
|
);
|
|
1531
|
+
const resolvedPublicKey = publicApiKey ?? publicLicenseKey;
|
|
1532
|
+
const hasLocalAgents = agents && Object.keys(agents).length > 0;
|
|
1533
|
+
const mergedHeaders = useMemo3(() => {
|
|
1534
|
+
if (!resolvedPublicKey) return headers;
|
|
1535
|
+
if (headers[HEADER_NAME]) return headers;
|
|
1536
|
+
return {
|
|
1537
|
+
...headers,
|
|
1538
|
+
[HEADER_NAME]: resolvedPublicKey
|
|
1539
|
+
};
|
|
1540
|
+
}, [headers, resolvedPublicKey]);
|
|
1541
|
+
if (!runtimeUrl && !resolvedPublicKey && !hasLocalAgents) {
|
|
1542
|
+
const message = "Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'";
|
|
1543
|
+
if (process.env.NODE_ENV === "production") {
|
|
1544
|
+
throw new Error(message);
|
|
1545
|
+
} else {
|
|
1546
|
+
console.warn(message);
|
|
1547
|
+
}
|
|
1548
|
+
}
|
|
1549
|
+
const chatApiEndpoint = runtimeUrl ?? (resolvedPublicKey ? COPILOT_CLOUD_CHAT_URL : void 0);
|
|
1529
1550
|
const frontendToolsList = useStableArrayProp(
|
|
1530
1551
|
frontendTools,
|
|
1531
1552
|
"frontendTools must be a stable array. If you want to dynamically add or remove tools, use `useFrontendTool` instead."
|
|
@@ -1588,9 +1609,9 @@ var CopilotKitProvider = ({
|
|
|
1588
1609
|
}, [renderToolCallsList, frontendToolsList, processedHumanInTheLoopTools]);
|
|
1589
1610
|
const copilotkit = useMemo3(() => {
|
|
1590
1611
|
const copilotkit2 = new CopilotKitCoreReact({
|
|
1591
|
-
runtimeUrl,
|
|
1612
|
+
runtimeUrl: chatApiEndpoint,
|
|
1592
1613
|
runtimeTransport: useSingleEndpoint ? "single" : "rest",
|
|
1593
|
-
headers,
|
|
1614
|
+
headers: mergedHeaders,
|
|
1594
1615
|
properties,
|
|
1595
1616
|
agents__unsafe_dev_only: agents,
|
|
1596
1617
|
tools: allTools,
|
|
@@ -1601,7 +1622,7 @@ var CopilotKitProvider = ({
|
|
|
1601
1622
|
return copilotkit2;
|
|
1602
1623
|
}, [allTools, allRenderToolCalls, renderActivityMessagesList, renderCustomMessagesList, useSingleEndpoint]);
|
|
1603
1624
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
1604
|
-
|
|
1625
|
+
useEffect4(() => {
|
|
1605
1626
|
const subscription = copilotkit.subscribe({
|
|
1606
1627
|
onRenderToolCallsChanged: () => {
|
|
1607
1628
|
forceUpdate();
|
|
@@ -1611,13 +1632,13 @@ var CopilotKitProvider = ({
|
|
|
1611
1632
|
subscription.unsubscribe();
|
|
1612
1633
|
};
|
|
1613
1634
|
}, [copilotkit]);
|
|
1614
|
-
|
|
1615
|
-
copilotkit.setRuntimeUrl(
|
|
1635
|
+
useEffect4(() => {
|
|
1636
|
+
copilotkit.setRuntimeUrl(chatApiEndpoint);
|
|
1616
1637
|
copilotkit.setRuntimeTransport(useSingleEndpoint ? "single" : "rest");
|
|
1617
|
-
copilotkit.setHeaders(
|
|
1638
|
+
copilotkit.setHeaders(mergedHeaders);
|
|
1618
1639
|
copilotkit.setProperties(properties);
|
|
1619
1640
|
copilotkit.setAgents__unsafe_dev_only(agents);
|
|
1620
|
-
}, [
|
|
1641
|
+
}, [chatApiEndpoint, mergedHeaders, properties, agents, useSingleEndpoint]);
|
|
1621
1642
|
return /* @__PURE__ */ jsxs4(
|
|
1622
1643
|
CopilotKitContext.Provider,
|
|
1623
1644
|
{
|
|
@@ -1637,7 +1658,7 @@ var useCopilotKit = () => {
|
|
|
1637
1658
|
if (!context) {
|
|
1638
1659
|
throw new Error("useCopilotKit must be used within CopilotKitProvider");
|
|
1639
1660
|
}
|
|
1640
|
-
|
|
1661
|
+
useEffect4(() => {
|
|
1641
1662
|
const subscription = context.copilotkit.subscribe({
|
|
1642
1663
|
onRuntimeConnectionStatusChanged: () => {
|
|
1643
1664
|
forceUpdate();
|
|
@@ -1715,7 +1736,7 @@ function useRenderToolCall() {
|
|
|
1715
1736
|
const { copilotkit } = useCopilotKit();
|
|
1716
1737
|
const config = useCopilotChatConfiguration();
|
|
1717
1738
|
const agentId = config?.agentId ?? DEFAULT_AGENT_ID2;
|
|
1718
|
-
const [executingToolCallIds, setExecutingToolCallIds] =
|
|
1739
|
+
const [executingToolCallIds, setExecutingToolCallIds] = useState5(() => /* @__PURE__ */ new Set());
|
|
1719
1740
|
const renderToolCalls = useSyncExternalStore(
|
|
1720
1741
|
(callback) => {
|
|
1721
1742
|
return copilotkit.subscribe({
|
|
@@ -1725,7 +1746,7 @@ function useRenderToolCall() {
|
|
|
1725
1746
|
() => copilotkit.renderToolCalls,
|
|
1726
1747
|
() => copilotkit.renderToolCalls
|
|
1727
1748
|
);
|
|
1728
|
-
|
|
1749
|
+
useEffect5(() => {
|
|
1729
1750
|
const subscription = copilotkit.subscribe({
|
|
1730
1751
|
onToolExecutionStart: ({ toolCallId }) => {
|
|
1731
1752
|
setExecutingToolCallIds((prev) => {
|
|
@@ -1881,12 +1902,12 @@ function useRenderActivityMessage() {
|
|
|
1881
1902
|
}
|
|
1882
1903
|
|
|
1883
1904
|
// src/hooks/use-frontend-tool.tsx
|
|
1884
|
-
import { useEffect as
|
|
1905
|
+
import { useEffect as useEffect6 } from "react";
|
|
1885
1906
|
var EMPTY_DEPS = [];
|
|
1886
1907
|
function useFrontendTool(tool, deps) {
|
|
1887
1908
|
const { copilotkit } = useCopilotKit();
|
|
1888
1909
|
const extraDeps = deps ?? EMPTY_DEPS;
|
|
1889
|
-
|
|
1910
|
+
useEffect6(() => {
|
|
1890
1911
|
const name = tool.name;
|
|
1891
1912
|
if (copilotkit.getTool({ toolName: name, agentId: tool.agentId })) {
|
|
1892
1913
|
console.warn(
|
|
@@ -1918,7 +1939,7 @@ function useFrontendTool(tool, deps) {
|
|
|
1918
1939
|
}
|
|
1919
1940
|
|
|
1920
1941
|
// src/hooks/use-human-in-the-loop.tsx
|
|
1921
|
-
import { useCallback as useCallback4, useRef as useRef4, useEffect as
|
|
1942
|
+
import { useCallback as useCallback4, useRef as useRef4, useEffect as useEffect7 } from "react";
|
|
1922
1943
|
import React7 from "react";
|
|
1923
1944
|
function useHumanInTheLoop(tool, deps) {
|
|
1924
1945
|
const { copilotkit } = useCopilotKit();
|
|
@@ -1972,7 +1993,7 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
1972
1993
|
render: RenderComponent
|
|
1973
1994
|
};
|
|
1974
1995
|
useFrontendTool(frontendTool, deps);
|
|
1975
|
-
|
|
1996
|
+
useEffect7(() => {
|
|
1976
1997
|
return () => {
|
|
1977
1998
|
const keyOf = (rc) => `${rc.agentId ?? ""}:${rc.name}`;
|
|
1978
1999
|
const currentRenderToolCalls = copilotkit.renderToolCalls;
|
|
@@ -1985,7 +2006,7 @@ function useHumanInTheLoop(tool, deps) {
|
|
|
1985
2006
|
}
|
|
1986
2007
|
|
|
1987
2008
|
// src/hooks/use-agent.tsx
|
|
1988
|
-
import { useMemo as useMemo5, useEffect as
|
|
2009
|
+
import { useMemo as useMemo5, useEffect as useEffect8, useReducer as useReducer2 } from "react";
|
|
1989
2010
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4 } from "@copilotkitnext/shared";
|
|
1990
2011
|
import { ProxiedCopilotRuntimeAgent, CopilotKitCoreRuntimeConnectionStatus } from "@copilotkitnext/core";
|
|
1991
2012
|
var ALL_UPDATES = [
|
|
@@ -2031,7 +2052,7 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
2031
2052
|
JSON.stringify(copilotkit.headers),
|
|
2032
2053
|
copilotkit
|
|
2033
2054
|
]);
|
|
2034
|
-
|
|
2055
|
+
useEffect8(() => {
|
|
2035
2056
|
if (updateFlags.length === 0) {
|
|
2036
2057
|
return;
|
|
2037
2058
|
}
|
|
@@ -2066,7 +2087,7 @@ function useAgent({ agentId, updates } = {}) {
|
|
|
2066
2087
|
}
|
|
2067
2088
|
|
|
2068
2089
|
// src/hooks/use-agent-context.tsx
|
|
2069
|
-
import { useEffect as
|
|
2090
|
+
import { useEffect as useEffect9, useMemo as useMemo6 } from "react";
|
|
2070
2091
|
function useAgentContext(context) {
|
|
2071
2092
|
const { description, value } = context;
|
|
2072
2093
|
const { copilotkit } = useCopilotKit();
|
|
@@ -2076,7 +2097,7 @@ function useAgentContext(context) {
|
|
|
2076
2097
|
}
|
|
2077
2098
|
return JSON.stringify(value);
|
|
2078
2099
|
}, [value]);
|
|
2079
|
-
|
|
2100
|
+
useEffect9(() => {
|
|
2080
2101
|
if (!copilotkit) return;
|
|
2081
2102
|
const id = copilotkit.addContext({ description, value: stringValue });
|
|
2082
2103
|
return () => {
|
|
@@ -2086,26 +2107,26 @@ function useAgentContext(context) {
|
|
|
2086
2107
|
}
|
|
2087
2108
|
|
|
2088
2109
|
// src/hooks/use-suggestions.tsx
|
|
2089
|
-
import { useCallback as useCallback5, useEffect as
|
|
2110
|
+
import { useCallback as useCallback5, useEffect as useEffect10, useMemo as useMemo7, useState as useState6 } from "react";
|
|
2090
2111
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID5 } from "@copilotkitnext/shared";
|
|
2091
2112
|
function useSuggestions({ agentId } = {}) {
|
|
2092
2113
|
const { copilotkit } = useCopilotKit();
|
|
2093
2114
|
const config = useCopilotChatConfiguration();
|
|
2094
2115
|
const resolvedAgentId = useMemo7(() => agentId ?? config?.agentId ?? DEFAULT_AGENT_ID5, [agentId, config?.agentId]);
|
|
2095
|
-
const [suggestions, setSuggestions] =
|
|
2116
|
+
const [suggestions, setSuggestions] = useState6(() => {
|
|
2096
2117
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2097
2118
|
return result.suggestions;
|
|
2098
2119
|
});
|
|
2099
|
-
const [isLoading, setIsLoading] =
|
|
2120
|
+
const [isLoading, setIsLoading] = useState6(() => {
|
|
2100
2121
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2101
2122
|
return result.isLoading;
|
|
2102
2123
|
});
|
|
2103
|
-
|
|
2124
|
+
useEffect10(() => {
|
|
2104
2125
|
const result = copilotkit.getSuggestions(resolvedAgentId);
|
|
2105
2126
|
setSuggestions(result.suggestions);
|
|
2106
2127
|
setIsLoading(result.isLoading);
|
|
2107
2128
|
}, [copilotkit, resolvedAgentId]);
|
|
2108
|
-
|
|
2129
|
+
useEffect10(() => {
|
|
2109
2130
|
const subscription = copilotkit.subscribe({
|
|
2110
2131
|
onSuggestionsChanged: ({ agentId: changedAgentId, suggestions: suggestions2 }) => {
|
|
2111
2132
|
if (changedAgentId !== resolvedAgentId) {
|
|
@@ -2150,7 +2171,7 @@ function useSuggestions({ agentId } = {}) {
|
|
|
2150
2171
|
}
|
|
2151
2172
|
|
|
2152
2173
|
// src/hooks/use-configure-suggestions.tsx
|
|
2153
|
-
import { useCallback as useCallback6, useEffect as
|
|
2174
|
+
import { useCallback as useCallback6, useEffect as useEffect11, useMemo as useMemo8, useRef as useRef5 } from "react";
|
|
2154
2175
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID6 } from "@copilotkitnext/shared";
|
|
2155
2176
|
function useConfigureSuggestions(config, deps) {
|
|
2156
2177
|
const { copilotkit } = useCopilotKit();
|
|
@@ -2228,7 +2249,7 @@ function useConfigureSuggestions(config, deps) {
|
|
|
2228
2249
|
}
|
|
2229
2250
|
copilotkit.reloadSuggestions(targetAgentId);
|
|
2230
2251
|
}, [copilotkit, isGlobalConfig, normalizedConfig, targetAgentId]);
|
|
2231
|
-
|
|
2252
|
+
useEffect11(() => {
|
|
2232
2253
|
if (!serializedConfig || !latestConfigRef.current) {
|
|
2233
2254
|
return;
|
|
2234
2255
|
}
|
|
@@ -2238,7 +2259,7 @@ function useConfigureSuggestions(config, deps) {
|
|
|
2238
2259
|
copilotkit.removeSuggestionsConfig(id);
|
|
2239
2260
|
};
|
|
2240
2261
|
}, [copilotkit, serializedConfig, requestReload]);
|
|
2241
|
-
|
|
2262
|
+
useEffect11(() => {
|
|
2242
2263
|
if (!normalizedConfig) {
|
|
2243
2264
|
previousSerializedConfigRef.current = null;
|
|
2244
2265
|
return;
|
|
@@ -2251,7 +2272,7 @@ function useConfigureSuggestions(config, deps) {
|
|
|
2251
2272
|
}
|
|
2252
2273
|
requestReload();
|
|
2253
2274
|
}, [normalizedConfig, requestReload, serializedConfig]);
|
|
2254
|
-
|
|
2275
|
+
useEffect11(() => {
|
|
2255
2276
|
if (!normalizedConfig || extraDeps.length === 0) {
|
|
2256
2277
|
return;
|
|
2257
2278
|
}
|
|
@@ -2461,7 +2482,7 @@ function CopilotChatAssistantMessage({
|
|
|
2461
2482
|
CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2462
2483
|
const config = useCopilotChatConfiguration();
|
|
2463
2484
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2464
|
-
const [copied, setCopied] =
|
|
2485
|
+
const [copied, setCopied] = useState7(false);
|
|
2465
2486
|
const handleClick = (event) => {
|
|
2466
2487
|
setCopied(true);
|
|
2467
2488
|
setTimeout(() => setCopied(false), 2e3);
|
|
@@ -2539,7 +2560,7 @@ CopilotChatAssistantMessage.RegenerateButton.displayName = "CopilotChatAssistant
|
|
|
2539
2560
|
var CopilotChatAssistantMessage_default = CopilotChatAssistantMessage;
|
|
2540
2561
|
|
|
2541
2562
|
// src/components/chat/CopilotChatUserMessage.tsx
|
|
2542
|
-
import { useMemo as useMemo9, useState as
|
|
2563
|
+
import { useMemo as useMemo9, useState as useState8 } from "react";
|
|
2543
2564
|
import { Copy as Copy2, Check as Check3, Edit, ChevronLeft, ChevronRight } from "lucide-react";
|
|
2544
2565
|
import { twMerge as twMerge5 } from "tailwind-merge";
|
|
2545
2566
|
import { Fragment as Fragment4, jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
@@ -2702,7 +2723,7 @@ function CopilotChatUserMessage({
|
|
|
2702
2723
|
CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
2703
2724
|
const config = useCopilotChatConfiguration();
|
|
2704
2725
|
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2705
|
-
const [copied, setCopied] =
|
|
2726
|
+
const [copied, setCopied] = useState8(false);
|
|
2706
2727
|
const handleClick = (event) => {
|
|
2707
2728
|
setCopied(true);
|
|
2708
2729
|
setTimeout(() => setCopied(false), 2e3);
|
|
@@ -3102,21 +3123,21 @@ CopilotChatMessageView.Cursor = function Cursor({ className, ...props }) {
|
|
|
3102
3123
|
var CopilotChatMessageView_default = CopilotChatMessageView;
|
|
3103
3124
|
|
|
3104
3125
|
// src/components/chat/CopilotChatView.tsx
|
|
3105
|
-
import React12, { useRef as useRef6, useState as
|
|
3126
|
+
import React12, { useRef as useRef6, useState as useState10, useEffect as useEffect13 } from "react";
|
|
3106
3127
|
import { twMerge as twMerge7 } from "tailwind-merge";
|
|
3107
3128
|
import { StickToBottom, useStickToBottom, useStickToBottomContext } from "use-stick-to-bottom";
|
|
3108
3129
|
import { ChevronDown } from "lucide-react";
|
|
3109
3130
|
|
|
3110
3131
|
// src/hooks/use-keyboard-height.tsx
|
|
3111
|
-
import { useState as
|
|
3132
|
+
import { useState as useState9, useEffect as useEffect12 } from "react";
|
|
3112
3133
|
function useKeyboardHeight() {
|
|
3113
|
-
const [keyboardState, setKeyboardState] =
|
|
3134
|
+
const [keyboardState, setKeyboardState] = useState9({
|
|
3114
3135
|
isKeyboardOpen: false,
|
|
3115
3136
|
keyboardHeight: 0,
|
|
3116
3137
|
availableHeight: typeof window !== "undefined" ? window.innerHeight : 0,
|
|
3117
3138
|
viewportHeight: typeof window !== "undefined" ? window.innerHeight : 0
|
|
3118
3139
|
});
|
|
3119
|
-
|
|
3140
|
+
useEffect12(() => {
|
|
3120
3141
|
if (typeof window === "undefined") {
|
|
3121
3142
|
return;
|
|
3122
3143
|
}
|
|
@@ -3170,11 +3191,11 @@ function CopilotChatView({
|
|
|
3170
3191
|
...props
|
|
3171
3192
|
}) {
|
|
3172
3193
|
const inputContainerRef = useRef6(null);
|
|
3173
|
-
const [inputContainerHeight, setInputContainerHeight] =
|
|
3174
|
-
const [isResizing, setIsResizing] =
|
|
3194
|
+
const [inputContainerHeight, setInputContainerHeight] = useState10(0);
|
|
3195
|
+
const [isResizing, setIsResizing] = useState10(false);
|
|
3175
3196
|
const resizeTimeoutRef = useRef6(null);
|
|
3176
3197
|
const { isKeyboardOpen, keyboardHeight, availableHeight } = useKeyboardHeight();
|
|
3177
|
-
|
|
3198
|
+
useEffect13(() => {
|
|
3178
3199
|
const element = inputContainerRef.current;
|
|
3179
3200
|
if (!element) return;
|
|
3180
3201
|
const resizeObserver = new ResizeObserver((entries) => {
|
|
@@ -3283,13 +3304,13 @@ function CopilotChatView({
|
|
|
3283
3304
|
className,
|
|
3284
3305
|
...props
|
|
3285
3306
|
}) => {
|
|
3286
|
-
const [hasMounted, setHasMounted] =
|
|
3307
|
+
const [hasMounted, setHasMounted] = useState10(false);
|
|
3287
3308
|
const { scrollRef, contentRef, scrollToBottom } = useStickToBottom();
|
|
3288
|
-
const [showScrollButton, setShowScrollButton] =
|
|
3289
|
-
|
|
3309
|
+
const [showScrollButton, setShowScrollButton] = useState10(false);
|
|
3310
|
+
useEffect13(() => {
|
|
3290
3311
|
setHasMounted(true);
|
|
3291
3312
|
}, []);
|
|
3292
|
-
|
|
3313
|
+
useEffect13(() => {
|
|
3293
3314
|
if (autoScroll) return;
|
|
3294
3315
|
const scrollElement = scrollRef.current;
|
|
3295
3316
|
if (!scrollElement) return;
|
|
@@ -3421,7 +3442,7 @@ var CopilotChatView_default = CopilotChatView;
|
|
|
3421
3442
|
|
|
3422
3443
|
// src/components/chat/CopilotChat.tsx
|
|
3423
3444
|
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID7, randomUUID as randomUUID2 } from "@copilotkitnext/shared";
|
|
3424
|
-
import { useCallback as useCallback7, useEffect as
|
|
3445
|
+
import { useCallback as useCallback7, useEffect as useEffect14, useMemo as useMemo10 } from "react";
|
|
3425
3446
|
import { merge } from "ts-deepmerge";
|
|
3426
3447
|
import { AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
3427
3448
|
import { jsx as jsx19 } from "react/jsx-runtime";
|
|
@@ -3441,7 +3462,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3441
3462
|
suggestionView: providedSuggestionView,
|
|
3442
3463
|
...restProps
|
|
3443
3464
|
} = props;
|
|
3444
|
-
|
|
3465
|
+
useEffect14(() => {
|
|
3445
3466
|
const connect = async (agent2) => {
|
|
3446
3467
|
try {
|
|
3447
3468
|
await copilotkit.connectAgent({ agent: agent2 });
|
|
@@ -3543,7 +3564,7 @@ function CopilotChat({ agentId, threadId, labels, chatView, isModalDefaultOpen,
|
|
|
3543
3564
|
})(CopilotChat || (CopilotChat = {}));
|
|
3544
3565
|
|
|
3545
3566
|
// src/components/chat/CopilotChatToggleButton.tsx
|
|
3546
|
-
import React13, { useState as
|
|
3567
|
+
import React13, { useState as useState11 } from "react";
|
|
3547
3568
|
import { MessageCircle, X as X2 } from "lucide-react";
|
|
3548
3569
|
import { jsx as jsx20, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
3549
3570
|
var DefaultOpenIcon = ({
|
|
@@ -3574,7 +3595,7 @@ var CopilotChatToggleButton = React13.forwardRef(function CopilotChatToggleButto
|
|
|
3574
3595
|
const { onClick, type, disabled, ...restProps } = buttonProps;
|
|
3575
3596
|
const configuration = useCopilotChatConfiguration();
|
|
3576
3597
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3577
|
-
const [fallbackOpen, setFallbackOpen] =
|
|
3598
|
+
const [fallbackOpen, setFallbackOpen] = useState11(false);
|
|
3578
3599
|
const isOpen = configuration?.isModalOpen ?? fallbackOpen;
|
|
3579
3600
|
const setModalOpen = configuration?.setModalOpen ?? setFallbackOpen;
|
|
3580
3601
|
const handleClick = (event) => {
|
|
@@ -3660,7 +3681,7 @@ CopilotChatToggleButton.displayName = "CopilotChatToggleButton";
|
|
|
3660
3681
|
var CopilotChatToggleButton_default = CopilotChatToggleButton;
|
|
3661
3682
|
|
|
3662
3683
|
// src/components/chat/CopilotSidebarView.tsx
|
|
3663
|
-
import { useEffect as
|
|
3684
|
+
import { useEffect as useEffect15, useRef as useRef7, useState as useState12 } from "react";
|
|
3664
3685
|
|
|
3665
3686
|
// src/components/chat/CopilotModalHeader.tsx
|
|
3666
3687
|
import { useCallback as useCallback8 } from "react";
|
|
@@ -3754,7 +3775,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3754
3775
|
const configuration = useCopilotChatConfiguration();
|
|
3755
3776
|
const isSidebarOpen = configuration?.isModalOpen ?? false;
|
|
3756
3777
|
const sidebarRef = useRef7(null);
|
|
3757
|
-
const [sidebarWidth, setSidebarWidth] =
|
|
3778
|
+
const [sidebarWidth, setSidebarWidth] = useState12(width ?? DEFAULT_SIDEBAR_WIDTH);
|
|
3758
3779
|
const widthToCss = (w) => {
|
|
3759
3780
|
return typeof w === "number" ? `${w}px` : w;
|
|
3760
3781
|
};
|
|
@@ -3764,7 +3785,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3764
3785
|
}
|
|
3765
3786
|
return w;
|
|
3766
3787
|
};
|
|
3767
|
-
|
|
3788
|
+
useEffect15(() => {
|
|
3768
3789
|
if (width !== void 0) {
|
|
3769
3790
|
return;
|
|
3770
3791
|
}
|
|
@@ -3843,7 +3864,7 @@ function CopilotSidebarView({ header, width, ...props }) {
|
|
|
3843
3864
|
CopilotSidebarView.displayName = "CopilotSidebarView";
|
|
3844
3865
|
|
|
3845
3866
|
// src/components/chat/CopilotPopupView.tsx
|
|
3846
|
-
import { useEffect as
|
|
3867
|
+
import { useEffect as useEffect16, useMemo as useMemo11, useRef as useRef8, useState as useState13 } from "react";
|
|
3847
3868
|
import { Fragment as Fragment8, jsx as jsx23, jsxs as jsxs14 } from "react/jsx-runtime";
|
|
3848
3869
|
var DEFAULT_POPUP_WIDTH = 420;
|
|
3849
3870
|
var DEFAULT_POPUP_HEIGHT = 560;
|
|
@@ -3869,9 +3890,9 @@ function CopilotPopupView({
|
|
|
3869
3890
|
const setModalOpen = configuration?.setModalOpen;
|
|
3870
3891
|
const labels = configuration?.labels ?? CopilotChatDefaultLabels;
|
|
3871
3892
|
const containerRef = useRef8(null);
|
|
3872
|
-
const [isRendered, setIsRendered] =
|
|
3873
|
-
const [isAnimatingOut, setIsAnimatingOut] =
|
|
3874
|
-
|
|
3893
|
+
const [isRendered, setIsRendered] = useState13(isPopupOpen);
|
|
3894
|
+
const [isAnimatingOut, setIsAnimatingOut] = useState13(false);
|
|
3895
|
+
useEffect16(() => {
|
|
3875
3896
|
if (isPopupOpen) {
|
|
3876
3897
|
setIsRendered(true);
|
|
3877
3898
|
setIsAnimatingOut(false);
|
|
@@ -3887,7 +3908,7 @@ function CopilotPopupView({
|
|
|
3887
3908
|
}, 200);
|
|
3888
3909
|
return () => clearTimeout(timeout);
|
|
3889
3910
|
}, [isPopupOpen, isRendered]);
|
|
3890
|
-
|
|
3911
|
+
useEffect16(() => {
|
|
3891
3912
|
if (!isPopupOpen) {
|
|
3892
3913
|
return;
|
|
3893
3914
|
}
|
|
@@ -3903,7 +3924,7 @@ function CopilotPopupView({
|
|
|
3903
3924
|
window.addEventListener("keydown", handleKeyDown);
|
|
3904
3925
|
return () => window.removeEventListener("keydown", handleKeyDown);
|
|
3905
3926
|
}, [isPopupOpen, setModalOpen]);
|
|
3906
|
-
|
|
3927
|
+
useEffect16(() => {
|
|
3907
3928
|
if (!isPopupOpen) {
|
|
3908
3929
|
return;
|
|
3909
3930
|
}
|
|
@@ -3912,7 +3933,7 @@ function CopilotPopupView({
|
|
|
3912
3933
|
}, 200);
|
|
3913
3934
|
return () => clearTimeout(focusTimer);
|
|
3914
3935
|
}, [isPopupOpen]);
|
|
3915
|
-
|
|
3936
|
+
useEffect16(() => {
|
|
3916
3937
|
if (!isPopupOpen || !clickOutsideToClose) {
|
|
3917
3938
|
return;
|
|
3918
3939
|
}
|
|
@@ -4087,12 +4108,12 @@ function defineToolCallRenderer(def) {
|
|
|
4087
4108
|
}
|
|
4088
4109
|
|
|
4089
4110
|
// src/components/WildcardToolCallRender.tsx
|
|
4090
|
-
import { useState as
|
|
4111
|
+
import { useState as useState14 } from "react";
|
|
4091
4112
|
import { jsx as jsx26, jsxs as jsxs15 } from "react/jsx-runtime";
|
|
4092
4113
|
var WildcardToolCallRender = defineToolCallRenderer({
|
|
4093
4114
|
name: "*",
|
|
4094
4115
|
render: ({ args, result, name, status }) => {
|
|
4095
|
-
const [isExpanded, setIsExpanded] =
|
|
4116
|
+
const [isExpanded, setIsExpanded] = useState14(false);
|
|
4096
4117
|
const statusString = String(status);
|
|
4097
4118
|
const isActive = statusString === "inProgress" || statusString === "executing";
|
|
4098
4119
|
const isComplete = statusString === "complete";
|