@copilotkitnext/react 0.0.11 → 0.0.12
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 +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +67 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +67 -72
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -51,11 +51,6 @@ var CopilotChatConfigurationProvider = ({
|
|
|
51
51
|
};
|
|
52
52
|
var useCopilotChatConfiguration = () => {
|
|
53
53
|
const configuration = useContext(CopilotChatConfiguration);
|
|
54
|
-
if (!configuration) {
|
|
55
|
-
throw new Error(
|
|
56
|
-
"useCopilotChatConfiguration must be used within CopilotChatConfigurationProvider"
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
54
|
return configuration;
|
|
60
55
|
};
|
|
61
56
|
|
|
@@ -685,7 +680,8 @@ function CopilotChatInput({
|
|
|
685
680
|
}
|
|
686
681
|
) });
|
|
687
682
|
CopilotChatInput2.ToolbarButton = ({ icon, labelKey, defaultClassName, className, ...props }) => {
|
|
688
|
-
const
|
|
683
|
+
const config = useCopilotChatConfiguration();
|
|
684
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
689
685
|
return /* @__PURE__ */ jsxs3(Tooltip, { children: [
|
|
690
686
|
/* @__PURE__ */ jsx6(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsx6(
|
|
691
687
|
Button,
|
|
@@ -738,7 +734,8 @@ function CopilotChatInput({
|
|
|
738
734
|
}
|
|
739
735
|
);
|
|
740
736
|
CopilotChatInput2.ToolsButton = ({ className, toolsMenu, ...props }) => {
|
|
741
|
-
const
|
|
737
|
+
const config = useCopilotChatConfiguration();
|
|
738
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
742
739
|
const renderMenuItems = (items) => {
|
|
743
740
|
return items.map((item, index) => {
|
|
744
741
|
if (item === "-") {
|
|
@@ -791,7 +788,8 @@ function CopilotChatInput({
|
|
|
791
788
|
function TextArea2({ maxRows = 5, style, className, ...props }, ref) {
|
|
792
789
|
const internalTextareaRef = useRef2(null);
|
|
793
790
|
const [maxHeight, setMaxHeight] = useState(0);
|
|
794
|
-
const
|
|
791
|
+
const config = useCopilotChatConfiguration();
|
|
792
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
795
793
|
useImperativeHandle2(
|
|
796
794
|
ref,
|
|
797
795
|
() => internalTextareaRef.current
|
|
@@ -904,19 +902,9 @@ import { useCallback, useEffect as useEffect4, useState as useState3 } from "rea
|
|
|
904
902
|
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
905
903
|
|
|
906
904
|
// src/providers/CopilotKitProvider.tsx
|
|
907
|
-
import {
|
|
908
|
-
createContext as createContext2,
|
|
909
|
-
useContext as useContext2,
|
|
910
|
-
useMemo,
|
|
911
|
-
useEffect as useEffect3,
|
|
912
|
-
useState as useState2,
|
|
913
|
-
useReducer,
|
|
914
|
-
useRef as useRef3
|
|
915
|
-
} from "react";
|
|
905
|
+
import { createContext as createContext2, useContext as useContext2, useMemo, useEffect as useEffect3, useState as useState2, useReducer, useRef as useRef3 } from "react";
|
|
916
906
|
import { z } from "zod";
|
|
917
|
-
import {
|
|
918
|
-
CopilotKitCore
|
|
919
|
-
} from "@copilotkitnext/core";
|
|
907
|
+
import { CopilotKitCore } from "@copilotkitnext/core";
|
|
920
908
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
921
909
|
var CopilotKitContext = createContext2({
|
|
922
910
|
copilotkit: null,
|
|
@@ -981,9 +969,7 @@ var CopilotKitProvider = ({
|
|
|
981
969
|
...tool.agentId && { agentId: tool.agentId },
|
|
982
970
|
handler: async () => {
|
|
983
971
|
return new Promise((resolve) => {
|
|
984
|
-
console.warn(
|
|
985
|
-
`Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`
|
|
986
|
-
);
|
|
972
|
+
console.warn(`Human-in-the-loop tool '${tool.name}' called but no interactive handler is set up.`);
|
|
987
973
|
resolve(void 0);
|
|
988
974
|
});
|
|
989
975
|
}
|
|
@@ -1029,7 +1015,7 @@ var CopilotKitProvider = ({
|
|
|
1029
1015
|
runtimeUrl: void 0,
|
|
1030
1016
|
headers,
|
|
1031
1017
|
properties,
|
|
1032
|
-
agents,
|
|
1018
|
+
agents__unsafe_dev_only: agents,
|
|
1033
1019
|
tools: allTools
|
|
1034
1020
|
};
|
|
1035
1021
|
const copilotkit2 = new CopilotKitCore(config);
|
|
@@ -1065,7 +1051,7 @@ var CopilotKitProvider = ({
|
|
|
1065
1051
|
copilotkit.setRuntimeUrl(runtimeUrl);
|
|
1066
1052
|
copilotkit.setHeaders(headers);
|
|
1067
1053
|
copilotkit.setProperties(properties);
|
|
1068
|
-
copilotkit.
|
|
1054
|
+
copilotkit.setAgents__unsafe_dev_only(agents);
|
|
1069
1055
|
}, [runtimeUrl, headers, properties, agents]);
|
|
1070
1056
|
return /* @__PURE__ */ jsx7(
|
|
1071
1057
|
CopilotKitContext.Provider,
|
|
@@ -1100,11 +1086,13 @@ var useCopilotKit = () => {
|
|
|
1100
1086
|
};
|
|
1101
1087
|
|
|
1102
1088
|
// src/hooks/use-render-tool-call.tsx
|
|
1089
|
+
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID2 } from "@copilotkitnext/shared";
|
|
1103
1090
|
import { partialJSONParse } from "@copilotkitnext/shared";
|
|
1104
1091
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1105
1092
|
function useRenderToolCall() {
|
|
1106
1093
|
const { currentRenderToolCalls, copilotkit } = useCopilotKit();
|
|
1107
|
-
const
|
|
1094
|
+
const config = useCopilotChatConfiguration();
|
|
1095
|
+
const agentId = config?.agentId ?? DEFAULT_AGENT_ID2;
|
|
1108
1096
|
const [executingToolCallIds, setExecutingToolCallIds] = useState3(() => /* @__PURE__ */ new Set());
|
|
1109
1097
|
useEffect4(() => {
|
|
1110
1098
|
const unsubscribe = copilotkit.subscribe({
|
|
@@ -1293,14 +1281,14 @@ function useHumanInTheLoop(tool) {
|
|
|
1293
1281
|
|
|
1294
1282
|
// src/hooks/use-agent.tsx
|
|
1295
1283
|
import { useMemo as useMemo2, useEffect as useEffect7, useReducer as useReducer2 } from "react";
|
|
1296
|
-
import { DEFAULT_AGENT_ID as
|
|
1284
|
+
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID3 } from "@copilotkitnext/shared";
|
|
1297
1285
|
var ALL_UPDATES = [
|
|
1298
1286
|
"OnMessagesChanged" /* OnMessagesChanged */,
|
|
1299
1287
|
"OnStateChanged" /* OnStateChanged */,
|
|
1300
1288
|
"OnRunStatusChanged" /* OnRunStatusChanged */
|
|
1301
1289
|
];
|
|
1302
1290
|
function useAgent({ agentId, updates } = {}) {
|
|
1303
|
-
agentId ??=
|
|
1291
|
+
agentId ??= DEFAULT_AGENT_ID3;
|
|
1304
1292
|
const { copilotkit } = useCopilotKit();
|
|
1305
1293
|
const [, forceUpdate] = useReducer2((x) => x + 1, 0);
|
|
1306
1294
|
const updateFlags = useMemo2(
|
|
@@ -1540,7 +1528,8 @@ function CopilotChatAssistantMessage({
|
|
|
1540
1528
|
);
|
|
1541
1529
|
};
|
|
1542
1530
|
const CodeBlock = ({ children, className, onClick, ...props }) => {
|
|
1543
|
-
const
|
|
1531
|
+
const config = useCopilotChatConfiguration();
|
|
1532
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1544
1533
|
const [copied, setCopied] = useState5(false);
|
|
1545
1534
|
const getCodeContent = (node) => {
|
|
1546
1535
|
if (typeof node === "string") return node;
|
|
@@ -1653,7 +1642,8 @@ function CopilotChatAssistantMessage({
|
|
|
1653
1642
|
] });
|
|
1654
1643
|
};
|
|
1655
1644
|
CopilotChatAssistantMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
1656
|
-
const
|
|
1645
|
+
const config = useCopilotChatConfiguration();
|
|
1646
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1657
1647
|
const [copied, setCopied] = useState5(false);
|
|
1658
1648
|
const handleClick = (event) => {
|
|
1659
1649
|
setCopied(true);
|
|
@@ -1674,7 +1664,8 @@ function CopilotChatAssistantMessage({
|
|
|
1674
1664
|
);
|
|
1675
1665
|
};
|
|
1676
1666
|
CopilotChatAssistantMessage2.ThumbsUpButton = ({ title, ...props }) => {
|
|
1677
|
-
const
|
|
1667
|
+
const config = useCopilotChatConfiguration();
|
|
1668
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1678
1669
|
return /* @__PURE__ */ jsx10(
|
|
1679
1670
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1680
1671
|
{
|
|
@@ -1685,7 +1676,8 @@ function CopilotChatAssistantMessage({
|
|
|
1685
1676
|
);
|
|
1686
1677
|
};
|
|
1687
1678
|
CopilotChatAssistantMessage2.ThumbsDownButton = ({ title, ...props }) => {
|
|
1688
|
-
const
|
|
1679
|
+
const config = useCopilotChatConfiguration();
|
|
1680
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1689
1681
|
return /* @__PURE__ */ jsx10(
|
|
1690
1682
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1691
1683
|
{
|
|
@@ -1696,7 +1688,8 @@ function CopilotChatAssistantMessage({
|
|
|
1696
1688
|
);
|
|
1697
1689
|
};
|
|
1698
1690
|
CopilotChatAssistantMessage2.ReadAloudButton = ({ title, ...props }) => {
|
|
1699
|
-
const
|
|
1691
|
+
const config = useCopilotChatConfiguration();
|
|
1692
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1700
1693
|
return /* @__PURE__ */ jsx10(
|
|
1701
1694
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1702
1695
|
{
|
|
@@ -1707,7 +1700,8 @@ function CopilotChatAssistantMessage({
|
|
|
1707
1700
|
);
|
|
1708
1701
|
};
|
|
1709
1702
|
CopilotChatAssistantMessage2.RegenerateButton = ({ title, ...props }) => {
|
|
1710
|
-
const
|
|
1703
|
+
const config = useCopilotChatConfiguration();
|
|
1704
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1711
1705
|
return /* @__PURE__ */ jsx10(
|
|
1712
1706
|
CopilotChatAssistantMessage2.ToolbarButton,
|
|
1713
1707
|
{
|
|
@@ -1871,7 +1865,8 @@ function CopilotChatUserMessage({
|
|
|
1871
1865
|
] });
|
|
1872
1866
|
};
|
|
1873
1867
|
CopilotChatUserMessage2.CopyButton = ({ className, title, onClick, ...props }) => {
|
|
1874
|
-
const
|
|
1868
|
+
const config = useCopilotChatConfiguration();
|
|
1869
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1875
1870
|
const [copied, setCopied] = useState6(false);
|
|
1876
1871
|
const handleClick = (event) => {
|
|
1877
1872
|
setCopied(true);
|
|
@@ -1892,7 +1887,8 @@ function CopilotChatUserMessage({
|
|
|
1892
1887
|
);
|
|
1893
1888
|
};
|
|
1894
1889
|
CopilotChatUserMessage2.EditButton = ({ className, title, ...props }) => {
|
|
1895
|
-
const
|
|
1890
|
+
const config = useCopilotChatConfiguration();
|
|
1891
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
1896
1892
|
return /* @__PURE__ */ jsx11(
|
|
1897
1893
|
CopilotChatUserMessage2.ToolbarButton,
|
|
1898
1894
|
{
|
|
@@ -2283,7 +2279,8 @@ function CopilotChatView({
|
|
|
2283
2279
|
className,
|
|
2284
2280
|
...props
|
|
2285
2281
|
}) => {
|
|
2286
|
-
const
|
|
2282
|
+
const config = useCopilotChatConfiguration();
|
|
2283
|
+
const labels = config?.labels ?? CopilotChatDefaultLabels;
|
|
2287
2284
|
return /* @__PURE__ */ jsx13(
|
|
2288
2285
|
"div",
|
|
2289
2286
|
{
|
|
@@ -2300,23 +2297,32 @@ function CopilotChatView({
|
|
|
2300
2297
|
var CopilotChatView_default = CopilotChatView;
|
|
2301
2298
|
|
|
2302
2299
|
// src/components/chat/CopilotChat.tsx
|
|
2303
|
-
import { DEFAULT_AGENT_ID as
|
|
2300
|
+
import { DEFAULT_AGENT_ID as DEFAULT_AGENT_ID4, randomUUID } from "@copilotkitnext/shared";
|
|
2304
2301
|
import { useCallback as useCallback3, useEffect as useEffect10, useMemo as useMemo3 } from "react";
|
|
2305
2302
|
import { merge } from "ts-deepmerge";
|
|
2306
2303
|
import { AGUIConnectNotImplementedError } from "@ag-ui/client";
|
|
2307
2304
|
import { jsx as jsx14 } from "react/jsx-runtime";
|
|
2308
|
-
function CopilotChat({
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
|
|
2313
|
-
|
|
2305
|
+
function CopilotChat({ agentId, threadId, labels, ...props }) {
|
|
2306
|
+
const existingConfig = useCopilotChatConfiguration();
|
|
2307
|
+
const resolvedAgentId = agentId ?? existingConfig?.agentId ?? DEFAULT_AGENT_ID4;
|
|
2308
|
+
const resolvedThreadId = useMemo3(
|
|
2309
|
+
() => threadId ?? existingConfig?.threadId ?? randomUUID(),
|
|
2310
|
+
[threadId, existingConfig?.threadId]
|
|
2311
|
+
);
|
|
2312
|
+
const resolvedLabels = useMemo3(
|
|
2313
|
+
() => ({
|
|
2314
|
+
...CopilotChatDefaultLabels,
|
|
2315
|
+
...existingConfig?.labels || {},
|
|
2316
|
+
...labels || {}
|
|
2317
|
+
}),
|
|
2318
|
+
[existingConfig?.labels, labels]
|
|
2319
|
+
);
|
|
2320
|
+
const { agent } = useAgent({ agentId: resolvedAgentId });
|
|
2314
2321
|
const { copilotkit } = useCopilotKit();
|
|
2315
|
-
const resolvedThreadId = useMemo3(() => threadId ?? randomUUID(), [threadId]);
|
|
2316
2322
|
useEffect10(() => {
|
|
2317
2323
|
const connect = async (agent2) => {
|
|
2318
2324
|
try {
|
|
2319
|
-
await copilotkit.connectAgent({ agent: agent2, agentId });
|
|
2325
|
+
await copilotkit.connectAgent({ agent: agent2, agentId: resolvedAgentId });
|
|
2320
2326
|
} catch (error) {
|
|
2321
2327
|
if (error instanceof AGUIConnectNotImplementedError) {
|
|
2322
2328
|
} else {
|
|
@@ -2330,7 +2336,7 @@ function CopilotChat({
|
|
|
2330
2336
|
}
|
|
2331
2337
|
return () => {
|
|
2332
2338
|
};
|
|
2333
|
-
}, [resolvedThreadId, agent, copilotkit,
|
|
2339
|
+
}, [resolvedThreadId, agent, copilotkit, resolvedAgentId]);
|
|
2334
2340
|
const onSubmitInput = useCallback3(
|
|
2335
2341
|
async (value) => {
|
|
2336
2342
|
agent?.addMessage({
|
|
@@ -2340,19 +2346,15 @@ function CopilotChat({
|
|
|
2340
2346
|
});
|
|
2341
2347
|
if (agent) {
|
|
2342
2348
|
try {
|
|
2343
|
-
await copilotkit.runAgent({ agent, agentId });
|
|
2349
|
+
await copilotkit.runAgent({ agent, agentId: resolvedAgentId });
|
|
2344
2350
|
} catch (error) {
|
|
2345
2351
|
console.error("CopilotChat: runAgent failed", error);
|
|
2346
2352
|
}
|
|
2347
2353
|
}
|
|
2348
2354
|
},
|
|
2349
|
-
[agent, copilotkit,
|
|
2355
|
+
[agent, copilotkit, resolvedAgentId]
|
|
2350
2356
|
);
|
|
2351
|
-
const {
|
|
2352
|
-
inputProps: providedInputProps,
|
|
2353
|
-
messageView: providedMessageView,
|
|
2354
|
-
...restProps
|
|
2355
|
-
} = props;
|
|
2357
|
+
const { inputProps: providedInputProps, messageView: providedMessageView, ...restProps } = props;
|
|
2356
2358
|
const mergedProps = merge(
|
|
2357
2359
|
{
|
|
2358
2360
|
isRunning: agent?.isRunning ?? false
|
|
@@ -2362,26 +2364,19 @@ function CopilotChat({
|
|
|
2362
2364
|
...typeof providedMessageView === "string" ? { messageView: { className: providedMessageView } } : providedMessageView !== void 0 ? { messageView: providedMessageView } : {}
|
|
2363
2365
|
}
|
|
2364
2366
|
);
|
|
2365
|
-
return /* @__PURE__ */ jsx14(
|
|
2366
|
-
|
|
2367
|
+
return /* @__PURE__ */ jsx14(CopilotChatConfigurationProvider, { agentId: resolvedAgentId, threadId: resolvedThreadId, labels: resolvedLabels, children: /* @__PURE__ */ jsx14(
|
|
2368
|
+
CopilotChatView,
|
|
2367
2369
|
{
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
onSubmitMessage: onSubmitInput,
|
|
2377
|
-
...providedInputProps
|
|
2378
|
-
},
|
|
2379
|
-
...mergedProps
|
|
2380
|
-
}
|
|
2381
|
-
}
|
|
2382
|
-
)
|
|
2370
|
+
...{
|
|
2371
|
+
messages: agent?.messages ?? [],
|
|
2372
|
+
inputProps: {
|
|
2373
|
+
onSubmitMessage: onSubmitInput,
|
|
2374
|
+
...providedInputProps
|
|
2375
|
+
},
|
|
2376
|
+
...mergedProps
|
|
2377
|
+
}
|
|
2383
2378
|
}
|
|
2384
|
-
);
|
|
2379
|
+
) });
|
|
2385
2380
|
}
|
|
2386
2381
|
|
|
2387
2382
|
// src/types/defineToolCallRender.ts
|