@copilotkit/react-core 1.51.4-next.7 → 1.51.4
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/CHANGELOG.md +26 -0
- package/README.md +18 -12
- package/dist/{chunk-6ESSSQ7Q.mjs → chunk-2RSAYTXH.mjs} +6 -3
- package/dist/chunk-2RSAYTXH.mjs.map +1 -0
- package/dist/chunk-3LZZ4RVM.mjs +37 -0
- package/dist/{chunk-ABWT4DRT.mjs.map → chunk-3LZZ4RVM.mjs.map} +1 -1
- package/dist/{chunk-QDES5PDW.mjs → chunk-4ZQYMC5F.mjs} +2 -2
- package/dist/{chunk-QDES5PDW.mjs.map → chunk-4ZQYMC5F.mjs.map} +1 -1
- package/dist/{chunk-VKNLTZJE.mjs → chunk-6ABVYB2U.mjs} +28 -19
- package/dist/chunk-6ABVYB2U.mjs.map +1 -0
- package/dist/{chunk-6PUNP7CD.mjs → chunk-6AWG5FWL.mjs} +2 -2
- package/dist/chunk-6AWG5FWL.mjs.map +1 -0
- package/dist/{chunk-C3YJYDK4.mjs → chunk-7GIBHX6X.mjs} +8 -2
- package/dist/chunk-7GIBHX6X.mjs.map +1 -0
- package/dist/{chunk-PIF5KJYI.mjs → chunk-7PJKPWMD.mjs} +15 -6
- package/dist/chunk-7PJKPWMD.mjs.map +1 -0
- package/dist/{chunk-7JTI6ZL4.mjs → chunk-7U3DNFBF.mjs} +6 -3
- package/dist/chunk-7U3DNFBF.mjs.map +1 -0
- package/dist/{chunk-KNJHRVKW.mjs → chunk-AAGMWZCN.mjs} +45 -14
- package/dist/chunk-AAGMWZCN.mjs.map +1 -0
- package/dist/{chunk-AFNWX62Q.mjs → chunk-C7HSVDHD.mjs} +10 -4
- package/dist/chunk-C7HSVDHD.mjs.map +1 -0
- package/dist/{chunk-ZYTXB6HH.mjs → chunk-CZT7JUIM.mjs} +4 -2
- package/dist/chunk-CZT7JUIM.mjs.map +1 -0
- package/dist/{chunk-BKMJ4LC7.mjs → chunk-G7SUZGGB.mjs} +19 -12
- package/dist/chunk-G7SUZGGB.mjs.map +1 -0
- package/dist/{chunk-7IBF6RBW.mjs → chunk-GY3FQICF.mjs} +2 -2
- package/dist/{chunk-QD7EID4N.mjs → chunk-IHMMKEFG.mjs} +16 -11
- package/dist/chunk-IHMMKEFG.mjs.map +1 -0
- package/dist/{chunk-YYN33GSG.mjs → chunk-K5OXUXCG.mjs} +14 -11
- package/dist/chunk-K5OXUXCG.mjs.map +1 -0
- package/dist/{chunk-6ZLPNY7X.mjs → chunk-L7GPCF2V.mjs} +6 -2
- package/dist/{chunk-6ZLPNY7X.mjs.map → chunk-L7GPCF2V.mjs.map} +1 -1
- package/dist/{chunk-LHERIF3L.mjs → chunk-LD34IXVT.mjs} +8 -5
- package/dist/chunk-LD34IXVT.mjs.map +1 -0
- package/dist/{chunk-7DTB7S5V.mjs → chunk-LNGBARXE.mjs} +5 -2
- package/dist/chunk-LNGBARXE.mjs.map +1 -0
- package/dist/{chunk-DQXCQWSG.mjs → chunk-LRPWSPXG.mjs} +85 -50
- package/dist/chunk-LRPWSPXG.mjs.map +1 -0
- package/dist/{chunk-NBK4KBLX.mjs → chunk-MBJ7OLYI.mjs} +9 -5
- package/dist/chunk-MBJ7OLYI.mjs.map +1 -0
- package/dist/{chunk-MA3CUMCY.mjs → chunk-P6ZPE4XJ.mjs} +3 -3
- package/dist/{chunk-MA3CUMCY.mjs.map → chunk-P6ZPE4XJ.mjs.map} +1 -1
- package/dist/{chunk-77IVITG3.mjs → chunk-QXZTCGF4.mjs} +9 -4
- package/dist/chunk-QXZTCGF4.mjs.map +1 -0
- package/dist/{chunk-VP43SLSZ.mjs → chunk-R2DP4APC.mjs} +10 -5
- package/dist/chunk-R2DP4APC.mjs.map +1 -0
- package/dist/{chunk-RKTVJRK7.mjs → chunk-R7BV32X4.mjs} +5 -2
- package/dist/chunk-R7BV32X4.mjs.map +1 -0
- package/dist/{chunk-YCG6SNAU.mjs → chunk-SBRCWA4S.mjs} +186 -32
- package/dist/chunk-SBRCWA4S.mjs.map +1 -0
- package/dist/{chunk-LMHB2D4J.mjs → chunk-SK2XMJUD.mjs} +13 -4
- package/dist/chunk-SK2XMJUD.mjs.map +1 -0
- package/dist/{chunk-HE22TZMF.mjs → chunk-SLM6CLAH.mjs} +16 -7
- package/dist/chunk-SLM6CLAH.mjs.map +1 -0
- package/dist/{chunk-XDFVCQD3.mjs → chunk-SYGQHN3H.mjs} +1 -1
- package/dist/{chunk-XDFVCQD3.mjs.map → chunk-SYGQHN3H.mjs.map} +1 -1
- package/dist/{chunk-4RRMC7L2.mjs → chunk-SYMT73HM.mjs} +16 -5
- package/dist/chunk-SYMT73HM.mjs.map +1 -0
- package/dist/{chunk-SRJT5VVY.mjs → chunk-TFZXOEY4.mjs} +6 -4
- package/dist/{chunk-SRJT5VVY.mjs.map → chunk-TFZXOEY4.mjs.map} +1 -1
- package/dist/{chunk-4CEQJ2X6.mjs → chunk-TPN7WC53.mjs} +4 -2
- package/dist/{chunk-4CEQJ2X6.mjs.map → chunk-TPN7WC53.mjs.map} +1 -1
- package/dist/{chunk-VGL3DGUW.mjs → chunk-UA23VX5J.mjs} +4 -2
- package/dist/chunk-UA23VX5J.mjs.map +1 -0
- package/dist/{chunk-VV56AVPB.mjs → chunk-V42VL2JR.mjs} +15 -4
- package/dist/chunk-V42VL2JR.mjs.map +1 -0
- package/dist/{chunk-RBGVEVWY.mjs → chunk-VZ4NSOFQ.mjs} +4 -4
- package/dist/chunk-VZ4NSOFQ.mjs.map +1 -0
- package/dist/{chunk-WF65O6HX.mjs → chunk-WRALJIW5.mjs} +18 -5
- package/dist/chunk-WRALJIW5.mjs.map +1 -0
- package/dist/{chunk-PMAFHQ7P.mjs → chunk-WV2EA7SX.mjs} +1 -1
- package/dist/chunk-WV2EA7SX.mjs.map +1 -0
- package/dist/{chunk-EFL5OBKN.mjs → chunk-ZP2IMXFY.mjs} +10 -4
- package/dist/chunk-ZP2IMXFY.mjs.map +1 -0
- package/dist/components/CopilotListeners.js +11 -2
- package/dist/components/CopilotListeners.js.map +1 -1
- package/dist/components/CopilotListeners.mjs +2 -2
- package/dist/components/copilot-provider/copilot-messages.d.ts +1 -1
- package/dist/components/copilot-provider/copilot-messages.js +22 -7
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +179 -84
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +16 -16
- package/dist/components/copilot-provider/index.js +179 -84
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +16 -16
- package/dist/components/dev-console/console-trigger.d.ts +1 -1
- package/dist/components/dev-console/console-trigger.js +227 -42
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +24 -8
- package/dist/components/dev-console/console-trigger.mjs.map +1 -1
- package/dist/components/dev-console/developer-console-modal.d.ts +1 -1
- package/dist/components/dev-console/developer-console-modal.js +206 -37
- package/dist/components/dev-console/developer-console-modal.js.map +1 -1
- package/dist/components/dev-console/developer-console-modal.mjs +3 -3
- package/dist/components/dev-console/icons.js +14 -5
- package/dist/components/dev-console/icons.js.map +1 -1
- package/dist/components/dev-console/icons.mjs +1 -1
- package/dist/components/error-boundary/error-boundary.d.ts +1 -1
- package/dist/components/error-boundary/error-boundary.js +9 -2
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +5 -5
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -2
- package/dist/components/index.js +179 -84
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +16 -16
- package/dist/components/toast/toast-provider.js +9 -3
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.js +5 -1
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +1 -1
- package/dist/context/coagent-state-renders-context.d.ts +1 -1
- package/dist/context/coagent-state-renders-context.js +15 -10
- package/dist/context/coagent-state-renders-context.js.map +1 -1
- package/dist/context/coagent-state-renders-context.mjs +1 -1
- package/dist/context/copilot-context.js +9 -3
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +31 -15
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +3 -3
- package/dist/context/threads-context.d.ts +1 -1
- package/dist/context/threads-context.js +7 -2
- package/dist/context/threads-context.js.map +1 -1
- package/dist/context/threads-context.mjs +1 -1
- package/dist/hooks/index.js +162 -61
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +25 -25
- package/dist/hooks/use-coagent-state-render-bridge.helpers.js +7 -1
- package/dist/hooks/use-coagent-state-render-bridge.helpers.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.helpers.mjs +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.js +31 -15
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-bridge.mjs +6 -6
- package/dist/hooks/use-coagent-state-render-registry.js +14 -3
- package/dist/hooks/use-coagent-state-render-registry.js.map +1 -1
- package/dist/hooks/use-coagent-state-render-registry.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +34 -21
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +4 -4
- package/dist/hooks/use-coagent.js +3 -1
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +1 -1
- package/dist/hooks/use-configure-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -1
- package/dist/hooks/use-copilot-action.js +13 -9
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -4
- package/dist/hooks/use-copilot-additional-instructions.d.ts +1 -1
- package/dist/hooks/use-copilot-additional-instructions.js +26 -7
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +25 -13
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
- package/dist/hooks/use-copilot-chat-headless_c.js +81 -27
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +11 -11
- package/dist/hooks/use-copilot-chat-suggestions.js.map +1 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +1 -1
- package/dist/hooks/use-copilot-chat.js +81 -27
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +11 -11
- package/dist/hooks/use-copilot-chat_internal.js +81 -27
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +10 -10
- package/dist/hooks/use-copilot-runtime-client.js +4 -1
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-default-tool.js +17 -10
- package/dist/hooks/use-default-tool.js.map +1 -1
- package/dist/hooks/use-default-tool.mjs +5 -5
- package/dist/hooks/use-flat-category-store.js +13 -10
- package/dist/hooks/use-flat-category-store.js.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +1 -1
- package/dist/hooks/use-frontend-tool.js.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +1 -1
- package/dist/hooks/use-human-in-the-loop.js.map +1 -1
- package/dist/hooks/use-human-in-the-loop.mjs +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.js +22 -5
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +4 -4
- package/dist/hooks/use-langgraph-interrupt.js +19 -4
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +3 -3
- package/dist/hooks/use-make-copilot-document-readable.js +9 -3
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/hooks/use-render-tool-call.d.ts +1 -1
- package/dist/hooks/use-render-tool-call.js +13 -9
- package/dist/hooks/use-render-tool-call.js.map +1 -1
- package/dist/hooks/use-render-tool-call.mjs +1 -1
- package/dist/hooks/use-tree.js +4 -1
- package/dist/hooks/use-tree.js.map +1 -1
- package/dist/hooks/use-tree.mjs +1 -1
- package/dist/index.js +311 -130
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -35
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/lib/copilot-task.js +10 -3
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +18 -18
- package/dist/lib/index.js +10 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +18 -18
- package/dist/lib/status-checker.js.map +1 -1
- package/dist/lib/status-checker.mjs +1 -1
- package/dist/types/coagent-action.js.map +1 -1
- package/dist/types/frontend-action.js +3 -1
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/v2/index.umd.js.map +1 -1
- package/jest.config.js +1 -0
- package/package.json +7 -8
- package/src/__mocks__/analytics-node.js +9 -0
- package/src/components/CopilotListeners.tsx +21 -5
- package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +3 -1
- package/src/components/copilot-provider/copilot-messages.tsx +36 -11
- package/src/components/copilot-provider/copilotkit-props.tsx +4 -1
- package/src/components/copilot-provider/copilotkit.tsx +116 -50
- package/src/components/dev-console/console-trigger.tsx +39 -10
- package/src/components/dev-console/developer-console-modal.tsx +207 -57
- package/src/components/dev-console/icons.tsx +6 -1
- package/src/components/error-boundary/error-boundary.tsx +10 -2
- package/src/components/error-boundary/error-utils.tsx +8 -3
- package/src/components/toast/toast-provider.tsx +16 -6
- package/src/components/usage-banner.tsx +9 -2
- package/src/context/coagent-state-renders-context.tsx +24 -12
- package/src/context/copilot-context.tsx +48 -15
- package/src/context/index.ts +8 -2
- package/src/context/threads-context.tsx +14 -3
- package/src/hooks/__tests__/use-coagent-state-render-bridge.helpers.test.ts +11 -4
- package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +175 -47
- package/src/hooks/__tests__/use-coagent-state-render.test.tsx +31 -10
- package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +10 -2
- package/src/hooks/use-coagent-state-render-bridge.helpers.ts +49 -16
- package/src/hooks/use-coagent-state-render-bridge.tsx +30 -13
- package/src/hooks/use-coagent-state-render-registry.ts +36 -21
- package/src/hooks/use-coagent-state-render.ts +30 -19
- package/src/hooks/use-coagent.ts +15 -4
- package/src/hooks/use-configure-chat-suggestions.tsx +14 -4
- package/src/hooks/use-copilot-action.ts +12 -3
- package/src/hooks/use-copilot-additional-instructions.ts +17 -4
- package/src/hooks/use-copilot-authenticated-action.ts +4 -1
- package/src/hooks/use-copilot-chat-headless_c.ts +8 -2
- package/src/hooks/use-copilot-chat-suggestions.tsx +14 -4
- package/src/hooks/use-copilot-chat.ts +3 -1
- package/src/hooks/use-copilot-chat_internal.ts +72 -19
- package/src/hooks/use-copilot-runtime-client.ts +20 -6
- package/src/hooks/use-default-tool.ts +8 -2
- package/src/hooks/use-flat-category-store.ts +15 -11
- package/src/hooks/use-frontend-tool.ts +35 -25
- package/src/hooks/use-human-in-the-loop.ts +21 -5
- package/src/hooks/use-langgraph-interrupt-render.ts +13 -2
- package/src/hooks/use-langgraph-interrupt.ts +13 -3
- package/src/hooks/use-render-tool-call.ts +20 -11
- package/src/hooks/use-tree.ts +20 -5
- package/src/lib/copilot-task.ts +20 -6
- package/src/lib/status-checker.ts +4 -1
- package/src/types/coagent-action.ts +6 -2
- package/src/types/frontend-action.ts +16 -5
- package/src/types/interrupt-action.ts +15 -5
- package/tsconfig.json +1 -1
- package/dist/chunk-4RRMC7L2.mjs.map +0 -1
- package/dist/chunk-6ESSSQ7Q.mjs.map +0 -1
- package/dist/chunk-6PUNP7CD.mjs.map +0 -1
- package/dist/chunk-77IVITG3.mjs.map +0 -1
- package/dist/chunk-7DTB7S5V.mjs.map +0 -1
- package/dist/chunk-7JTI6ZL4.mjs.map +0 -1
- package/dist/chunk-ABWT4DRT.mjs +0 -24
- package/dist/chunk-AFNWX62Q.mjs.map +0 -1
- package/dist/chunk-BKMJ4LC7.mjs.map +0 -1
- package/dist/chunk-C3YJYDK4.mjs.map +0 -1
- package/dist/chunk-DQXCQWSG.mjs.map +0 -1
- package/dist/chunk-EFL5OBKN.mjs.map +0 -1
- package/dist/chunk-HE22TZMF.mjs.map +0 -1
- package/dist/chunk-KNJHRVKW.mjs.map +0 -1
- package/dist/chunk-LHERIF3L.mjs.map +0 -1
- package/dist/chunk-LMHB2D4J.mjs.map +0 -1
- package/dist/chunk-NBK4KBLX.mjs.map +0 -1
- package/dist/chunk-PIF5KJYI.mjs.map +0 -1
- package/dist/chunk-PMAFHQ7P.mjs.map +0 -1
- package/dist/chunk-QD7EID4N.mjs.map +0 -1
- package/dist/chunk-RBGVEVWY.mjs.map +0 -1
- package/dist/chunk-RKTVJRK7.mjs.map +0 -1
- package/dist/chunk-VGL3DGUW.mjs.map +0 -1
- package/dist/chunk-VKNLTZJE.mjs.map +0 -1
- package/dist/chunk-VP43SLSZ.mjs.map +0 -1
- package/dist/chunk-VV56AVPB.mjs.map +0 -1
- package/dist/chunk-WF65O6HX.mjs.map +0 -1
- package/dist/chunk-YCG6SNAU.mjs.map +0 -1
- package/dist/chunk-YYN33GSG.mjs.map +0 -1
- package/dist/chunk-ZYTXB6HH.mjs.map +0 -1
- /package/dist/{chunk-7IBF6RBW.mjs.map → chunk-GY3FQICF.mjs.map} +0 -0
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
useRef,
|
|
3
|
+
useEffect,
|
|
4
|
+
useCallback,
|
|
5
|
+
useMemo,
|
|
6
|
+
useState,
|
|
7
|
+
createElement,
|
|
8
|
+
} from "react";
|
|
2
9
|
import { useCopilotContext } from "../context/copilot-context";
|
|
3
10
|
import { SystemMessageFunction } from "../types";
|
|
4
11
|
import { useAsyncCallback } from "../components/error-boundary/error-utils";
|
|
5
12
|
import { Message } from "@copilotkit/shared";
|
|
6
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
gqlToAGUI,
|
|
15
|
+
Message as DeprecatedGqlMessage,
|
|
16
|
+
} from "@copilotkit/runtime-client-gql";
|
|
7
17
|
import { useLangGraphInterruptRender } from "./use-langgraph-interrupt-render";
|
|
8
18
|
import {
|
|
9
19
|
useAgent,
|
|
@@ -27,7 +37,10 @@ import {
|
|
|
27
37
|
* `manual` - Suggestions are controlled programmatically.
|
|
28
38
|
* `SuggestionItem[]` - Static suggestions array.
|
|
29
39
|
*/
|
|
30
|
-
export type ChatSuggestions =
|
|
40
|
+
export type ChatSuggestions =
|
|
41
|
+
| "auto"
|
|
42
|
+
| "manual"
|
|
43
|
+
| Omit<Suggestion, "isLoading">[];
|
|
31
44
|
|
|
32
45
|
export interface AppendMessageOptions {
|
|
33
46
|
/**
|
|
@@ -143,7 +156,10 @@ export interface UseCopilotChatReturn {
|
|
|
143
156
|
messages: Message[];
|
|
144
157
|
|
|
145
158
|
/** @deprecated use `sendMessage` in `useCopilotChatHeadless_c` instead. This will be removed in a future major version. */
|
|
146
|
-
appendMessage: (
|
|
159
|
+
appendMessage: (
|
|
160
|
+
message: DeprecatedGqlMessage,
|
|
161
|
+
options?: AppendMessageOptions,
|
|
162
|
+
) => Promise<void>;
|
|
147
163
|
|
|
148
164
|
/**
|
|
149
165
|
* Send a new message to the chat
|
|
@@ -156,7 +172,10 @@ export interface UseCopilotChatReturn {
|
|
|
156
172
|
* });
|
|
157
173
|
* ```
|
|
158
174
|
*/
|
|
159
|
-
sendMessage: (
|
|
175
|
+
sendMessage: (
|
|
176
|
+
message: Message,
|
|
177
|
+
options?: AppendMessageOptions,
|
|
178
|
+
) => Promise<void>;
|
|
160
179
|
|
|
161
180
|
/**
|
|
162
181
|
* Replace all messages in the chat
|
|
@@ -329,7 +348,11 @@ export function useCopilotChatInternal({
|
|
|
329
348
|
}
|
|
330
349
|
}
|
|
331
350
|
};
|
|
332
|
-
if (
|
|
351
|
+
if (
|
|
352
|
+
agent &&
|
|
353
|
+
existingConfig?.threadId &&
|
|
354
|
+
agent.threadId !== existingConfig.threadId
|
|
355
|
+
) {
|
|
333
356
|
agent.threadId = existingConfig.threadId;
|
|
334
357
|
connect(agent);
|
|
335
358
|
}
|
|
@@ -376,7 +399,9 @@ export function useCopilotChatInternal({
|
|
|
376
399
|
return;
|
|
377
400
|
}
|
|
378
401
|
|
|
379
|
-
const reloadMessageIndex = messages.findIndex(
|
|
402
|
+
const reloadMessageIndex = messages.findIndex(
|
|
403
|
+
(msg) => msg.id === reloadMessageId,
|
|
404
|
+
);
|
|
380
405
|
if (reloadMessageIndex === -1) {
|
|
381
406
|
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
382
407
|
return;
|
|
@@ -384,7 +409,9 @@ export function useCopilotChatInternal({
|
|
|
384
409
|
|
|
385
410
|
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
386
411
|
if (reloadMessageRole !== "assistant") {
|
|
387
|
-
console.warn(
|
|
412
|
+
console.warn(
|
|
413
|
+
`Regenerate cannot be performed on ${reloadMessageRole} role`,
|
|
414
|
+
);
|
|
388
415
|
return;
|
|
389
416
|
}
|
|
390
417
|
let historyCutoff: Message[] = [messages[0]];
|
|
@@ -404,7 +431,10 @@ export function useCopilotChatInternal({
|
|
|
404
431
|
(msg) => msg.id === lastUserMessageBeforeRegenerate.id,
|
|
405
432
|
);
|
|
406
433
|
// Include the user message, remove everything after it
|
|
407
|
-
historyCutoff = messages.slice(
|
|
434
|
+
historyCutoff = messages.slice(
|
|
435
|
+
0,
|
|
436
|
+
indexOfLastUserMessageBeforeRegenerate + 1,
|
|
437
|
+
);
|
|
408
438
|
}
|
|
409
439
|
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
410
440
|
historyCutoff = [messages[0], messages[1]];
|
|
@@ -422,7 +452,12 @@ export function useCopilotChatInternal({
|
|
|
422
452
|
}
|
|
423
453
|
return;
|
|
424
454
|
},
|
|
425
|
-
[
|
|
455
|
+
[
|
|
456
|
+
agent?.messages.length,
|
|
457
|
+
agent?.isRunning,
|
|
458
|
+
agent?.setMessages,
|
|
459
|
+
copilotkit?.runAgent,
|
|
460
|
+
],
|
|
426
461
|
);
|
|
427
462
|
|
|
428
463
|
const latestSendMessageFunc = useAsyncCallback(
|
|
@@ -473,7 +508,9 @@ export function useCopilotChatInternal({
|
|
|
473
508
|
|
|
474
509
|
const latestSetMessagesFunc = useCallback(
|
|
475
510
|
(messages: Message[] | DeprecatedGqlMessage[]) => {
|
|
476
|
-
if (
|
|
511
|
+
if (
|
|
512
|
+
messages.every((message) => message instanceof DeprecatedGqlMessage)
|
|
513
|
+
) {
|
|
477
514
|
return agent?.setMessages?.(gqlToAGUI(messages));
|
|
478
515
|
}
|
|
479
516
|
return agent?.setMessages?.(messages);
|
|
@@ -534,10 +571,15 @@ export function useCopilotChatInternal({
|
|
|
534
571
|
legacyCustomMessageRenderer || renderCustomMessage
|
|
535
572
|
? () => {
|
|
536
573
|
if (legacyCustomMessageRenderer) {
|
|
537
|
-
return legacyCustomMessageRenderer({
|
|
574
|
+
return legacyCustomMessageRenderer({
|
|
575
|
+
message,
|
|
576
|
+
position: "before",
|
|
577
|
+
});
|
|
538
578
|
}
|
|
539
579
|
try {
|
|
540
|
-
return
|
|
580
|
+
return (
|
|
581
|
+
renderCustomMessage?.({ message, position: "before" }) ?? null
|
|
582
|
+
);
|
|
541
583
|
} catch (error) {
|
|
542
584
|
console.warn(
|
|
543
585
|
"[CopilotKit] renderCustomMessages failed, falling back to legacy renderer",
|
|
@@ -559,7 +601,9 @@ export function useCopilotChatInternal({
|
|
|
559
601
|
return message;
|
|
560
602
|
});
|
|
561
603
|
|
|
562
|
-
const hasAssistantMessages = processedMessages.some(
|
|
604
|
+
const hasAssistantMessages = processedMessages.some(
|
|
605
|
+
(msg) => msg.role === "assistant",
|
|
606
|
+
);
|
|
563
607
|
const canUseCustomRenderer = Boolean(
|
|
564
608
|
renderCustomMessage && copilotkit?.getAgent?.(resolvedAgentId),
|
|
565
609
|
);
|
|
@@ -570,7 +614,8 @@ export function useCopilotChatInternal({
|
|
|
570
614
|
: null;
|
|
571
615
|
|
|
572
616
|
const shouldRenderPlaceholder =
|
|
573
|
-
Boolean(agent?.isRunning) ||
|
|
617
|
+
Boolean(agent?.isRunning) ||
|
|
618
|
+
Boolean(agent?.state && Object.keys(agent.state).length);
|
|
574
619
|
|
|
575
620
|
const effectiveThreadId = threadId ?? agent?.threadId ?? "default";
|
|
576
621
|
let latestUserIndex = -1;
|
|
@@ -583,8 +628,11 @@ export function useCopilotChatInternal({
|
|
|
583
628
|
const latestUserMessageId =
|
|
584
629
|
latestUserIndex >= 0 ? processedMessages[latestUserIndex].id : undefined;
|
|
585
630
|
const currentRunId = latestUserMessageId
|
|
586
|
-
? copilotkit.getRunIdForMessage(
|
|
587
|
-
|
|
631
|
+
? copilotkit.getRunIdForMessage(
|
|
632
|
+
resolvedAgentId,
|
|
633
|
+
effectiveThreadId,
|
|
634
|
+
latestUserMessageId,
|
|
635
|
+
) || `pending:${latestUserMessageId}`
|
|
588
636
|
: undefined;
|
|
589
637
|
const hasAssistantForCurrentRun =
|
|
590
638
|
latestUserIndex >= 0
|
|
@@ -595,7 +643,11 @@ export function useCopilotChatInternal({
|
|
|
595
643
|
|
|
596
644
|
// Insert a placeholder assistant message so state snapshots can render before any
|
|
597
645
|
// assistant text exists for the current run.
|
|
598
|
-
if (
|
|
646
|
+
if (
|
|
647
|
+
placeholderRenderer &&
|
|
648
|
+
shouldRenderPlaceholder &&
|
|
649
|
+
!hasAssistantForCurrentRun
|
|
650
|
+
) {
|
|
599
651
|
const placeholderId = currentRunId
|
|
600
652
|
? `coagent-state-render-${resolvedAgentId}-${currentRunId}`
|
|
601
653
|
: `coagent-state-render-${resolvedAgentId}`;
|
|
@@ -660,7 +712,8 @@ export function useCopilotChatInternal({
|
|
|
660
712
|
suggestions: renderedSuggestions.suggestions,
|
|
661
713
|
setSuggestions: (suggestions: Omit<Suggestion, "isLoading">[]) =>
|
|
662
714
|
copilotkit.addSuggestionsConfig({ suggestions }),
|
|
663
|
-
generateSuggestions: async () =>
|
|
715
|
+
generateSuggestions: async () =>
|
|
716
|
+
copilotkit.reloadSuggestions(resolvedAgentId),
|
|
664
717
|
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
665
718
|
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
666
719
|
interrupt,
|
|
@@ -22,12 +22,17 @@ export interface CopilotRuntimeClientHookOptions extends CopilotRuntimeClientOpt
|
|
|
22
22
|
onError: CopilotErrorHandler;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const useCopilotRuntimeClient = (
|
|
25
|
+
export const useCopilotRuntimeClient = (
|
|
26
|
+
options: CopilotRuntimeClientHookOptions,
|
|
27
|
+
) => {
|
|
26
28
|
const { setBannerError } = useToast();
|
|
27
29
|
const { showDevConsole, onError, ...runtimeOptions } = options;
|
|
28
30
|
|
|
29
31
|
// Deduplication state for structured errors
|
|
30
|
-
const lastStructuredErrorRef = useRef<{
|
|
32
|
+
const lastStructuredErrorRef = useRef<{
|
|
33
|
+
message: string;
|
|
34
|
+
timestamp: number;
|
|
35
|
+
} | null>(null);
|
|
31
36
|
|
|
32
37
|
// Helper function to trace UI errors
|
|
33
38
|
const traceUIError = async (error: CopilotKitError, originalError?: any) => {
|
|
@@ -44,8 +49,12 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
|
|
|
44
49
|
},
|
|
45
50
|
technical: {
|
|
46
51
|
environment: "browser",
|
|
47
|
-
userAgent:
|
|
48
|
-
|
|
52
|
+
userAgent:
|
|
53
|
+
typeof navigator !== "undefined"
|
|
54
|
+
? navigator.userAgent
|
|
55
|
+
: undefined,
|
|
56
|
+
stackTrace:
|
|
57
|
+
originalError instanceof Error ? originalError.stack : undefined,
|
|
49
58
|
},
|
|
50
59
|
},
|
|
51
60
|
error,
|
|
@@ -85,7 +94,10 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
|
|
|
85
94
|
) {
|
|
86
95
|
return; // Skip duplicate
|
|
87
96
|
}
|
|
88
|
-
lastStructuredErrorRef.current = {
|
|
97
|
+
lastStructuredErrorRef.current = {
|
|
98
|
+
message: errorMessage,
|
|
99
|
+
timestamp: now,
|
|
100
|
+
};
|
|
89
101
|
|
|
90
102
|
const ckError = createStructuredError(gqlError);
|
|
91
103
|
if (ckError) {
|
|
@@ -150,7 +162,9 @@ function createStructuredError(gqlError: GraphQLError): CopilotKitError | null {
|
|
|
150
162
|
if (originalError?.stack?.includes("CopilotApiDiscoveryError")) {
|
|
151
163
|
return new CopilotKitApiDiscoveryError({ message });
|
|
152
164
|
}
|
|
153
|
-
if (
|
|
165
|
+
if (
|
|
166
|
+
originalError?.stack?.includes("CopilotKitRemoteEndpointDiscoveryError")
|
|
167
|
+
) {
|
|
154
168
|
return new CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
155
169
|
}
|
|
156
170
|
if (originalError?.stack?.includes("CopilotKitAgentDiscoveryError")) {
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { useCopilotAction } from "./use-copilot-action";
|
|
2
2
|
import { CatchAllFrontendAction } from "../types/frontend-action";
|
|
3
3
|
|
|
4
|
-
export function useDefaultTool(
|
|
4
|
+
export function useDefaultTool(
|
|
5
|
+
tool: Omit<CatchAllFrontendAction, "name">,
|
|
6
|
+
dependencies?: any[],
|
|
7
|
+
) {
|
|
5
8
|
// Use the existing useCopilotAction hook
|
|
6
|
-
useCopilotAction(
|
|
9
|
+
useCopilotAction(
|
|
10
|
+
{ ...tool, name: "*" } satisfies CatchAllFrontendAction,
|
|
11
|
+
dependencies,
|
|
12
|
+
);
|
|
7
13
|
}
|
|
@@ -21,16 +21,19 @@ const useFlatCategoryStore = <T>(): UseFlatCategoryStoreReturn<T> => {
|
|
|
21
21
|
new Map<FlatCategoryStoreId, FlatCategoryStoreElement<T>>(),
|
|
22
22
|
);
|
|
23
23
|
|
|
24
|
-
const addElement = useCallback(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
24
|
+
const addElement = useCallback(
|
|
25
|
+
(value: T, categories: string[]): FlatCategoryStoreId => {
|
|
26
|
+
const newId = randomId();
|
|
27
|
+
dispatch({
|
|
28
|
+
type: "ADD_ELEMENT",
|
|
29
|
+
value,
|
|
30
|
+
id: newId,
|
|
31
|
+
categories,
|
|
32
|
+
});
|
|
33
|
+
return newId;
|
|
34
|
+
},
|
|
35
|
+
[],
|
|
36
|
+
);
|
|
34
37
|
|
|
35
38
|
const removeElement = useCallback((id: FlatCategoryStoreId): void => {
|
|
36
39
|
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
@@ -93,7 +96,8 @@ function flatCategoryStoreReducer<T>(
|
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
function setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {
|
|
96
|
-
const [smallerSet, largerSet] =
|
|
99
|
+
const [smallerSet, largerSet] =
|
|
100
|
+
setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
97
101
|
|
|
98
102
|
for (let item of smallerSet) {
|
|
99
103
|
if (largerSet.has(item)) {
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { ActionRenderProps, FrontendAction } from "../types/frontend-action";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Parameter,
|
|
5
|
+
getZodParameters,
|
|
6
|
+
MappedParameterTypes,
|
|
7
|
+
} from "@copilotkit/shared";
|
|
4
8
|
import { parseJson } from "@copilotkit/shared";
|
|
5
9
|
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
6
10
|
import {
|
|
@@ -8,7 +12,9 @@ import {
|
|
|
8
12
|
useFrontendTool as useFrontendToolVNext,
|
|
9
13
|
} from "@copilotkitnext/react";
|
|
10
14
|
|
|
11
|
-
type FrontendToolOptions<T extends Parameter[] | []> = ReactFrontendTool<
|
|
15
|
+
type FrontendToolOptions<T extends Parameter[] | []> = ReactFrontendTool<
|
|
16
|
+
MappedParameterTypes<T>
|
|
17
|
+
>;
|
|
12
18
|
type FrontendToolRenderArgs<T extends Parameter[] | []> =
|
|
13
19
|
| {
|
|
14
20
|
name: string;
|
|
@@ -49,36 +55,40 @@ export function useFrontendTool<const T extends Parameter[] = []>(
|
|
|
49
55
|
renderRef.current = render;
|
|
50
56
|
}, [render, ...(dependencies ?? [])]);
|
|
51
57
|
|
|
52
|
-
const normalizedRender: FrontendToolOptions<T>["render"] | undefined =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
58
|
+
const normalizedRender: FrontendToolOptions<T>["render"] | undefined =
|
|
59
|
+
useMemo(() => {
|
|
60
|
+
if (typeof render === "undefined") {
|
|
61
|
+
return undefined;
|
|
62
|
+
}
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
return ((args: FrontendToolRenderArgs<T>) => {
|
|
65
|
+
const currentRender = renderRef.current;
|
|
59
66
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
67
|
+
if (typeof currentRender === "undefined") {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
63
70
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
71
|
+
if (typeof currentRender === "string") {
|
|
72
|
+
return React.createElement(React.Fragment, null, currentRender);
|
|
73
|
+
}
|
|
67
74
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
const renderArgs = {
|
|
76
|
+
...args,
|
|
77
|
+
result:
|
|
78
|
+
typeof args.result === "string"
|
|
79
|
+
? parseJson(args.result, args.result)
|
|
80
|
+
: args.result,
|
|
81
|
+
} as ActionRenderProps<T>;
|
|
72
82
|
|
|
73
|
-
|
|
83
|
+
const rendered = currentRender(renderArgs);
|
|
74
84
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
if (typeof rendered === "string") {
|
|
86
|
+
return React.createElement(React.Fragment, null, rendered);
|
|
87
|
+
}
|
|
78
88
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
89
|
+
return rendered ?? null;
|
|
90
|
+
}) as FrontendToolOptions<T>["render"];
|
|
91
|
+
}, []);
|
|
82
92
|
|
|
83
93
|
// Handler ref to avoid stale closures
|
|
84
94
|
const handlerRef = useRef<typeof tool.handler>(tool.handler);
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ActionRenderProps,
|
|
3
|
+
ActionRenderPropsWait,
|
|
4
|
+
FrontendAction,
|
|
5
|
+
} from "../types";
|
|
2
6
|
import {
|
|
3
7
|
CopilotKitError,
|
|
4
8
|
CopilotKitErrorCode,
|
|
@@ -9,11 +13,20 @@ import {
|
|
|
9
13
|
} from "@copilotkit/shared";
|
|
10
14
|
import { useHumanInTheLoop as useHumanInTheLoopVNext } from "@copilotkitnext/react";
|
|
11
15
|
import { ToolCallStatus } from "@copilotkitnext/core";
|
|
12
|
-
import React, {
|
|
16
|
+
import React, {
|
|
17
|
+
ComponentType,
|
|
18
|
+
FunctionComponent,
|
|
19
|
+
useEffect,
|
|
20
|
+
useRef,
|
|
21
|
+
} from "react";
|
|
13
22
|
|
|
14
23
|
type HumanInTheLoopOptions = Parameters<typeof useHumanInTheLoopVNext>[0];
|
|
15
24
|
type HumanInTheLoopRender = HumanInTheLoopOptions["render"];
|
|
16
|
-
type HumanInTheLoopRenderArgs = HumanInTheLoopRender extends (
|
|
25
|
+
type HumanInTheLoopRenderArgs = HumanInTheLoopRender extends (
|
|
26
|
+
props: infer P,
|
|
27
|
+
) => any
|
|
28
|
+
? P
|
|
29
|
+
: never;
|
|
17
30
|
|
|
18
31
|
export type UseHumanInTheLoopArgs<T extends Parameter[] | [] = []> = {
|
|
19
32
|
available?: "disabled" | "enabled";
|
|
@@ -90,7 +103,9 @@ export function useHumanInTheLoop<const T extends Parameter[] | [] = []>(
|
|
|
90
103
|
args: mappedArgs,
|
|
91
104
|
respond: args.respond,
|
|
92
105
|
status: args.status,
|
|
93
|
-
result: args.result
|
|
106
|
+
result: args.result
|
|
107
|
+
? parseJson(args.result, args.result)
|
|
108
|
+
: args.result,
|
|
94
109
|
handler: undefined,
|
|
95
110
|
};
|
|
96
111
|
default:
|
|
@@ -117,6 +132,7 @@ export function useHumanInTheLoop<const T extends Parameter[] | [] = []>(
|
|
|
117
132
|
followUp,
|
|
118
133
|
parameters: zodParameters,
|
|
119
134
|
render: ((args: HumanInTheLoopRenderArgs) =>
|
|
120
|
-
renderRef.current?.(args as HitlRendererArgs) ??
|
|
135
|
+
renderRef.current?.(args as HitlRendererArgs) ??
|
|
136
|
+
null) as HumanInTheLoopOptions["render"],
|
|
121
137
|
});
|
|
122
138
|
}
|
|
@@ -17,7 +17,12 @@ type InterruptProps = {
|
|
|
17
17
|
resolve: (response: string) => void;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
-
const InterruptRenderer: React.FC<InterruptProps> = ({
|
|
20
|
+
const InterruptRenderer: React.FC<InterruptProps> = ({
|
|
21
|
+
event,
|
|
22
|
+
result,
|
|
23
|
+
render,
|
|
24
|
+
resolve,
|
|
25
|
+
}) => {
|
|
21
26
|
return render({ event, result, resolve });
|
|
22
27
|
};
|
|
23
28
|
|
|
@@ -132,5 +137,11 @@ export function useLangGraphInterruptRender(
|
|
|
132
137
|
render,
|
|
133
138
|
resolve: resolveInterrupt,
|
|
134
139
|
});
|
|
135
|
-
}, [
|
|
140
|
+
}, [
|
|
141
|
+
interruptActions,
|
|
142
|
+
interruptEventQueue,
|
|
143
|
+
threadId,
|
|
144
|
+
agentSession,
|
|
145
|
+
handleResolve,
|
|
146
|
+
]);
|
|
136
147
|
}
|
|
@@ -8,8 +8,12 @@ export function useLangGraphInterrupt<TEventValue = any>(
|
|
|
8
8
|
action: Omit<LangGraphInterruptRender<TEventValue>, "id">,
|
|
9
9
|
dependencies?: any[],
|
|
10
10
|
) {
|
|
11
|
-
const {
|
|
12
|
-
|
|
11
|
+
const {
|
|
12
|
+
setInterruptAction,
|
|
13
|
+
removeInterruptAction,
|
|
14
|
+
interruptActions,
|
|
15
|
+
threadId,
|
|
16
|
+
} = useContext(CopilotContext);
|
|
13
17
|
const { addToast } = useToast();
|
|
14
18
|
|
|
15
19
|
const actionId = dataToUUID(action, "lgAction");
|
|
@@ -32,5 +36,11 @@ export function useLangGraphInterrupt<TEventValue = any>(
|
|
|
32
36
|
return () => {
|
|
33
37
|
removeInterruptAction(actionId);
|
|
34
38
|
};
|
|
35
|
-
}, [
|
|
39
|
+
}, [
|
|
40
|
+
setInterruptAction,
|
|
41
|
+
removeInterruptAction,
|
|
42
|
+
threadId,
|
|
43
|
+
actionId,
|
|
44
|
+
...(dependencies || []),
|
|
45
|
+
]);
|
|
36
46
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
+
import { type Parameter, getZodParameters } from "@copilotkit/shared";
|
|
2
|
+
import { parseJson } from "@copilotkit/shared";
|
|
3
|
+
import { defineToolCallRenderer, useCopilotKit } from "@copilotkitnext/react";
|
|
4
|
+
import type React from "react";
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
1
6
|
import {
|
|
2
|
-
ActionRenderProps,
|
|
3
|
-
ActionRenderPropsNoArgs,
|
|
7
|
+
type ActionRenderProps,
|
|
8
|
+
type ActionRenderPropsNoArgs,
|
|
4
9
|
ActionRenderPropsWait,
|
|
5
|
-
FrontendAction,
|
|
10
|
+
type FrontendAction,
|
|
6
11
|
} from "../types";
|
|
7
|
-
import { Parameter, getZodParameters } from "@copilotkit/shared";
|
|
8
|
-
import React, { useEffect, useRef } from "react";
|
|
9
|
-
import { defineToolCallRenderer, useCopilotKit } from "@copilotkitnext/react";
|
|
10
|
-
import { parseJson } from "@copilotkit/shared";
|
|
11
12
|
|
|
12
13
|
type ToolCallRendererDefinition = Parameters<typeof defineToolCallRenderer>[0];
|
|
13
14
|
|
|
@@ -41,7 +42,9 @@ export function useRenderToolCall<const T extends Parameter[] | [] = []>(
|
|
|
41
42
|
render: ((args) => {
|
|
42
43
|
return render({
|
|
43
44
|
...args,
|
|
44
|
-
result: args.result
|
|
45
|
+
result: args.result
|
|
46
|
+
? parseJson(args.result, args.result)
|
|
47
|
+
: args.result,
|
|
45
48
|
});
|
|
46
49
|
}) as ToolCallRendererDefinition["render"],
|
|
47
50
|
})
|
|
@@ -51,13 +54,17 @@ export function useRenderToolCall<const T extends Parameter[] | [] = []>(
|
|
|
51
54
|
render: ((args) => {
|
|
52
55
|
return render({
|
|
53
56
|
...args,
|
|
54
|
-
result: args.result
|
|
57
|
+
result: args.result
|
|
58
|
+
? parseJson(args.result, args.result)
|
|
59
|
+
: args.result,
|
|
55
60
|
});
|
|
56
61
|
}) as ToolCallRendererDefinition["render"],
|
|
57
62
|
});
|
|
58
63
|
|
|
59
64
|
// Remove any existing renderer with the same name
|
|
60
|
-
const existingIndex = copilotkit.renderToolCalls.findIndex(
|
|
65
|
+
const existingIndex = copilotkit.renderToolCalls.findIndex(
|
|
66
|
+
(r) => r.name === name,
|
|
67
|
+
);
|
|
61
68
|
if (existingIndex !== -1) {
|
|
62
69
|
copilotkit.renderToolCalls.splice(existingIndex, 1);
|
|
63
70
|
}
|
|
@@ -69,7 +76,9 @@ export function useRenderToolCall<const T extends Parameter[] | [] = []>(
|
|
|
69
76
|
// Cleanup: remove this renderer when the component unmounts or tool changes
|
|
70
77
|
return () => {
|
|
71
78
|
if (hasAddedRef.current) {
|
|
72
|
-
const index = copilotkit.renderToolCalls.findIndex(
|
|
79
|
+
const index = copilotkit.renderToolCalls.findIndex(
|
|
80
|
+
(r) => r.name === name,
|
|
81
|
+
);
|
|
73
82
|
if (index !== -1) {
|
|
74
83
|
copilotkit.renderToolCalls.splice(index, 1);
|
|
75
84
|
}
|
package/src/hooks/use-tree.ts
CHANGED
|
@@ -15,7 +15,11 @@ export type Tree = TreeNode[];
|
|
|
15
15
|
|
|
16
16
|
export interface UseTreeReturn {
|
|
17
17
|
tree: Tree;
|
|
18
|
-
addElement: (
|
|
18
|
+
addElement: (
|
|
19
|
+
value: string,
|
|
20
|
+
categories: string[],
|
|
21
|
+
parentId?: TreeNodeId,
|
|
22
|
+
) => TreeNodeId;
|
|
19
23
|
printTree: (categories: string[]) => string;
|
|
20
24
|
removeElement: (id: TreeNodeId) => void;
|
|
21
25
|
getAllElements: () => Tree;
|
|
@@ -44,7 +48,11 @@ const removeNode = (nodes: Tree, id: TreeNodeId): Tree => {
|
|
|
44
48
|
}, []);
|
|
45
49
|
};
|
|
46
50
|
|
|
47
|
-
const addNode = (
|
|
51
|
+
const addNode = (
|
|
52
|
+
nodes: Tree,
|
|
53
|
+
newNode: TreeNode,
|
|
54
|
+
parentId?: TreeNodeId,
|
|
55
|
+
): Tree => {
|
|
48
56
|
if (!parentId) {
|
|
49
57
|
return [...nodes, newNode];
|
|
50
58
|
}
|
|
@@ -58,7 +66,10 @@ const addNode = (nodes: Tree, newNode: TreeNode, parentId?: TreeNodeId): Tree =>
|
|
|
58
66
|
});
|
|
59
67
|
};
|
|
60
68
|
|
|
61
|
-
const treeIndentationRepresentation = (
|
|
69
|
+
const treeIndentationRepresentation = (
|
|
70
|
+
index: number,
|
|
71
|
+
indentLevel: number,
|
|
72
|
+
): string => {
|
|
62
73
|
if (indentLevel === 0) {
|
|
63
74
|
return (index + 1).toString();
|
|
64
75
|
} else if (indentLevel === 1) {
|
|
@@ -182,7 +193,10 @@ const useTree = (): UseTreeReturn => {
|
|
|
182
193
|
output += "\n";
|
|
183
194
|
}
|
|
184
195
|
|
|
185
|
-
output += printNode(
|
|
196
|
+
output += printNode(
|
|
197
|
+
node,
|
|
198
|
+
`${treeIndentationRepresentation(index, 0)}. `,
|
|
199
|
+
);
|
|
186
200
|
});
|
|
187
201
|
return output;
|
|
188
202
|
},
|
|
@@ -195,7 +209,8 @@ const useTree = (): UseTreeReturn => {
|
|
|
195
209
|
export default useTree;
|
|
196
210
|
|
|
197
211
|
function setsHaveIntersection<T>(setA: Set<T>, setB: Set<T>): boolean {
|
|
198
|
-
const [smallerSet, largerSet] =
|
|
212
|
+
const [smallerSet, largerSet] =
|
|
213
|
+
setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
199
214
|
|
|
200
215
|
for (let item of smallerSet) {
|
|
201
216
|
if (largerSet.has(item)) {
|