@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
|
@@ -3,7 +3,11 @@ import { act, render, screen, waitFor, within } from "@testing-library/react";
|
|
|
3
3
|
import { useCoAgentStateRender } from "../use-coagent-state-render";
|
|
4
4
|
import { CoAgentStateRenderBridge } from "../use-coagent-state-render-bridge";
|
|
5
5
|
import { useCopilotChatInternal } from "../use-copilot-chat_internal";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
CoAgentStateRendersProvider,
|
|
8
|
+
CopilotContext,
|
|
9
|
+
useCoAgentStateRenders,
|
|
10
|
+
} from "../../context";
|
|
7
11
|
import type { Claim } from "../use-coagent-state-render-bridge.helpers";
|
|
8
12
|
import { createTestCopilotContext } from "../../test-helpers/copilot-context";
|
|
9
13
|
|
|
@@ -72,7 +76,9 @@ jest.mock("../use-lazy-tool-renderer", () => ({
|
|
|
72
76
|
function TestHarness({ snapshot }: { snapshot: string }) {
|
|
73
77
|
useCoAgentStateRender<{ current_step?: string }>({
|
|
74
78
|
name: "test-agent",
|
|
75
|
-
render: ({ state }) =>
|
|
79
|
+
render: ({ state }) => (
|
|
80
|
+
<div data-testid="state">{state.current_step ?? "none"}</div>
|
|
81
|
+
),
|
|
76
82
|
});
|
|
77
83
|
|
|
78
84
|
return (
|
|
@@ -89,10 +95,18 @@ function TestHarness({ snapshot }: { snapshot: string }) {
|
|
|
89
95
|
);
|
|
90
96
|
}
|
|
91
97
|
|
|
92
|
-
function SnapshotHarness({
|
|
98
|
+
function SnapshotHarness({
|
|
99
|
+
snapshot,
|
|
100
|
+
message,
|
|
101
|
+
}: {
|
|
102
|
+
snapshot: string;
|
|
103
|
+
message: TestMessage;
|
|
104
|
+
}) {
|
|
93
105
|
useCoAgentStateRender<{ current_step?: string }>({
|
|
94
106
|
name: "test-agent",
|
|
95
|
-
render: ({ state }) =>
|
|
107
|
+
render: ({ state }) => (
|
|
108
|
+
<div data-testid="state">{state.current_step ?? "none"}</div>
|
|
109
|
+
),
|
|
96
110
|
});
|
|
97
111
|
|
|
98
112
|
return (
|
|
@@ -109,10 +123,16 @@ function SnapshotHarness({ snapshot, message }: { snapshot: string; message: Tes
|
|
|
109
123
|
);
|
|
110
124
|
}
|
|
111
125
|
|
|
112
|
-
function LiveStateHarness({
|
|
126
|
+
function LiveStateHarness({
|
|
127
|
+
message,
|
|
128
|
+
}: {
|
|
129
|
+
message: Pick<TestMessage, "id" | "role">;
|
|
130
|
+
}) {
|
|
113
131
|
useCoAgentStateRender<{ current_step?: string }>({
|
|
114
132
|
name: "test-agent",
|
|
115
|
-
render: ({ state }) =>
|
|
133
|
+
render: ({ state }) => (
|
|
134
|
+
<div data-testid="state">{state.current_step ?? "none"}</div>
|
|
135
|
+
),
|
|
116
136
|
});
|
|
117
137
|
|
|
118
138
|
return (
|
|
@@ -132,7 +152,9 @@ function LiveStateHarness({ message }: { message: Pick<TestMessage, "id" | "role
|
|
|
132
152
|
function NonFirstMessageHarness({ snapshot }: { snapshot: string }) {
|
|
133
153
|
useCoAgentStateRender<{ current_step?: string }>({
|
|
134
154
|
name: "test-agent",
|
|
135
|
-
render: ({ state }) =>
|
|
155
|
+
render: ({ state }) => (
|
|
156
|
+
<div data-testid="state">{state.current_step ?? "none"}</div>
|
|
157
|
+
),
|
|
136
158
|
});
|
|
137
159
|
|
|
138
160
|
return (
|
|
@@ -162,7 +184,9 @@ function MultiRunHarness({
|
|
|
162
184
|
}) {
|
|
163
185
|
useCoAgentStateRender<{ current_step?: string }>({
|
|
164
186
|
name: "test-agent",
|
|
165
|
-
render: ({ state }) =>
|
|
187
|
+
render: ({ state }) => (
|
|
188
|
+
<div data-testid="state">{state.current_step ?? "none"}</div>
|
|
189
|
+
),
|
|
166
190
|
});
|
|
167
191
|
|
|
168
192
|
return (
|
|
@@ -179,7 +203,11 @@ function MultiRunHarness({
|
|
|
179
203
|
);
|
|
180
204
|
}
|
|
181
205
|
|
|
182
|
-
function ClaimsObserver({
|
|
206
|
+
function ClaimsObserver({
|
|
207
|
+
onChange,
|
|
208
|
+
}: {
|
|
209
|
+
onChange: (claims: Record<string, Claim>) => void;
|
|
210
|
+
}) {
|
|
183
211
|
const { claimsRef } = useCoAgentStateRenders();
|
|
184
212
|
React.useEffect(() => {
|
|
185
213
|
onChange(claimsRef.current as Record<string, Claim>);
|
|
@@ -190,7 +218,9 @@ function ClaimsObserver({ onChange }: { onChange: (claims: Record<string, Claim>
|
|
|
190
218
|
function ChatHarness({ tick }: { tick: number }) {
|
|
191
219
|
useCoAgentStateRender<{ current_step?: string }>({
|
|
192
220
|
name: "test-agent",
|
|
193
|
-
render: ({ state }) =>
|
|
221
|
+
render: ({ state }) => (
|
|
222
|
+
<div data-testid="state">{state.current_step ?? "none"}</div>
|
|
223
|
+
),
|
|
194
224
|
});
|
|
195
225
|
|
|
196
226
|
const { messages } = useCopilotChatInternal();
|
|
@@ -214,10 +244,12 @@ describe("useCoAgentStateRender", () => {
|
|
|
214
244
|
lastSubscriber = null;
|
|
215
245
|
mockAgent.state = {};
|
|
216
246
|
mockAgent.messages = [];
|
|
217
|
-
mockAgent.subscribe.mockImplementation(
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
247
|
+
mockAgent.subscribe.mockImplementation(
|
|
248
|
+
(subscriber: TestAgentSubscriber) => {
|
|
249
|
+
lastSubscriber = subscriber;
|
|
250
|
+
return { unsubscribe: jest.fn() };
|
|
251
|
+
},
|
|
252
|
+
);
|
|
221
253
|
});
|
|
222
254
|
|
|
223
255
|
it("re-renders when state snapshots change", async () => {
|
|
@@ -226,7 +258,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
226
258
|
const { rerender } = render(
|
|
227
259
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
228
260
|
<CoAgentStateRendersProvider>
|
|
229
|
-
<TestHarness
|
|
261
|
+
<TestHarness
|
|
262
|
+
snapshot={JSON.stringify({ current_step: "Processing..." })}
|
|
263
|
+
/>
|
|
230
264
|
</CoAgentStateRendersProvider>
|
|
231
265
|
</CopilotContext.Provider>,
|
|
232
266
|
);
|
|
@@ -238,7 +272,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
238
272
|
rerender(
|
|
239
273
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
240
274
|
<CoAgentStateRendersProvider>
|
|
241
|
-
<TestHarness
|
|
275
|
+
<TestHarness
|
|
276
|
+
snapshot={JSON.stringify({ current_step: "Thinking..." })}
|
|
277
|
+
/>
|
|
242
278
|
</CoAgentStateRendersProvider>
|
|
243
279
|
</CopilotContext.Provider>,
|
|
244
280
|
);
|
|
@@ -347,7 +383,8 @@ describe("useCoAgentStateRender", () => {
|
|
|
347
383
|
</CopilotContext.Provider>,
|
|
348
384
|
);
|
|
349
385
|
|
|
350
|
-
const placeholderTestId =
|
|
386
|
+
const placeholderTestId =
|
|
387
|
+
"message-coagent-state-render-test-agent-pending:msg-user-1";
|
|
351
388
|
expect(screen.queryByTestId(placeholderTestId)).toBeNull();
|
|
352
389
|
|
|
353
390
|
mockAgent.isRunning = true;
|
|
@@ -411,7 +448,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
411
448
|
|
|
412
449
|
await waitFor(() => {
|
|
413
450
|
expect(
|
|
414
|
-
screen.queryByTestId(
|
|
451
|
+
screen.queryByTestId(
|
|
452
|
+
"message-coagent-state-render-test-agent-pending:msg-user-1",
|
|
453
|
+
),
|
|
415
454
|
).toBeNull();
|
|
416
455
|
});
|
|
417
456
|
});
|
|
@@ -422,7 +461,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
422
461
|
render(
|
|
423
462
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
424
463
|
<CoAgentStateRendersProvider>
|
|
425
|
-
<NonFirstMessageHarness
|
|
464
|
+
<NonFirstMessageHarness
|
|
465
|
+
snapshot={JSON.stringify({ current_step: "Processing..." })}
|
|
466
|
+
/>
|
|
426
467
|
</CoAgentStateRendersProvider>
|
|
427
468
|
</CopilotContext.Provider>,
|
|
428
469
|
);
|
|
@@ -433,7 +474,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
433
474
|
});
|
|
434
475
|
|
|
435
476
|
it("falls back to legacy renderer when renderCustomMessages throws", async () => {
|
|
436
|
-
const { useRenderCustomMessages } = jest.requireMock(
|
|
477
|
+
const { useRenderCustomMessages } = jest.requireMock(
|
|
478
|
+
"@copilotkitnext/react",
|
|
479
|
+
);
|
|
437
480
|
useRenderCustomMessages.mockImplementationOnce(() => () => {
|
|
438
481
|
throw new Error("boom");
|
|
439
482
|
});
|
|
@@ -464,7 +507,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
464
507
|
});
|
|
465
508
|
|
|
466
509
|
it("prefers legacy renderer over renderCustomMessages when both exist", async () => {
|
|
467
|
-
const { useRenderCustomMessages } = jest.requireMock(
|
|
510
|
+
const { useRenderCustomMessages } = jest.requireMock(
|
|
511
|
+
"@copilotkitnext/react",
|
|
512
|
+
);
|
|
468
513
|
const renderCustomSpy = jest.fn(() => null);
|
|
469
514
|
useRenderCustomMessages.mockImplementationOnce(() => renderCustomSpy);
|
|
470
515
|
|
|
@@ -544,8 +589,18 @@ describe("useCoAgentStateRender", () => {
|
|
|
544
589
|
render(
|
|
545
590
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
546
591
|
<CoAgentStateRendersProvider>
|
|
547
|
-
<MultiRunHarness
|
|
548
|
-
|
|
592
|
+
<MultiRunHarness
|
|
593
|
+
snapshot={snapshot}
|
|
594
|
+
runId="run-1"
|
|
595
|
+
messageId="msg-1"
|
|
596
|
+
messageIndex={0}
|
|
597
|
+
/>
|
|
598
|
+
<MultiRunHarness
|
|
599
|
+
snapshot={snapshot}
|
|
600
|
+
runId="run-2"
|
|
601
|
+
messageId="msg-2"
|
|
602
|
+
messageIndex={1}
|
|
603
|
+
/>
|
|
549
604
|
</CoAgentStateRendersProvider>
|
|
550
605
|
</CopilotContext.Provider>,
|
|
551
606
|
);
|
|
@@ -566,8 +621,18 @@ describe("useCoAgentStateRender", () => {
|
|
|
566
621
|
render(
|
|
567
622
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
568
623
|
<CoAgentStateRendersProvider>
|
|
569
|
-
<MultiRunHarness
|
|
570
|
-
|
|
624
|
+
<MultiRunHarness
|
|
625
|
+
snapshot={snapshot}
|
|
626
|
+
runId="run-1"
|
|
627
|
+
messageId="msg-1"
|
|
628
|
+
messageIndex={0}
|
|
629
|
+
/>
|
|
630
|
+
<MultiRunHarness
|
|
631
|
+
snapshot={snapshot}
|
|
632
|
+
runId="run-1"
|
|
633
|
+
messageId="msg-2"
|
|
634
|
+
messageIndex={1}
|
|
635
|
+
/>
|
|
571
636
|
</CoAgentStateRendersProvider>
|
|
572
637
|
</CopilotContext.Provider>,
|
|
573
638
|
);
|
|
@@ -590,8 +655,18 @@ describe("useCoAgentStateRender", () => {
|
|
|
590
655
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
591
656
|
<CoAgentStateRendersProvider>
|
|
592
657
|
<ClaimsObserver onChange={(claims) => (latestClaims = claims)} />
|
|
593
|
-
<MultiRunHarness
|
|
594
|
-
|
|
658
|
+
<MultiRunHarness
|
|
659
|
+
snapshot={snapshot}
|
|
660
|
+
runId="run-1"
|
|
661
|
+
messageId="msg-1"
|
|
662
|
+
messageIndex={0}
|
|
663
|
+
/>
|
|
664
|
+
<MultiRunHarness
|
|
665
|
+
snapshot={snapshot}
|
|
666
|
+
runId="run-1"
|
|
667
|
+
messageId="msg-2"
|
|
668
|
+
messageIndex={1}
|
|
669
|
+
/>
|
|
595
670
|
</CoAgentStateRendersProvider>
|
|
596
671
|
</CopilotContext.Provider>,
|
|
597
672
|
);
|
|
@@ -613,28 +688,49 @@ describe("useCoAgentStateRender", () => {
|
|
|
613
688
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
614
689
|
<CoAgentStateRendersProvider>
|
|
615
690
|
<ClaimsObserver onChange={(claims) => (latestClaims = claims)} />
|
|
616
|
-
<MultiRunHarness
|
|
691
|
+
<MultiRunHarness
|
|
692
|
+
snapshot={snapshot}
|
|
693
|
+
runId="run-1"
|
|
694
|
+
messageId="msg-1"
|
|
695
|
+
messageIndex={0}
|
|
696
|
+
/>
|
|
617
697
|
</CoAgentStateRendersProvider>
|
|
618
698
|
</CopilotContext.Provider>,
|
|
619
699
|
);
|
|
620
700
|
|
|
621
701
|
await waitFor(() => {
|
|
622
|
-
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
702
|
+
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
703
|
+
"Processing...",
|
|
704
|
+
);
|
|
623
705
|
});
|
|
624
706
|
|
|
625
707
|
rerender(
|
|
626
708
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
627
709
|
<CoAgentStateRendersProvider>
|
|
628
710
|
<ClaimsObserver onChange={(claims) => (latestClaims = claims)} />
|
|
629
|
-
<MultiRunHarness
|
|
630
|
-
|
|
711
|
+
<MultiRunHarness
|
|
712
|
+
snapshot={snapshot}
|
|
713
|
+
runId="run-1"
|
|
714
|
+
messageId="msg-1"
|
|
715
|
+
messageIndex={0}
|
|
716
|
+
/>
|
|
717
|
+
<MultiRunHarness
|
|
718
|
+
snapshot={snapshot}
|
|
719
|
+
runId="run-2"
|
|
720
|
+
messageId="msg-2"
|
|
721
|
+
messageIndex={1}
|
|
722
|
+
/>
|
|
631
723
|
</CoAgentStateRendersProvider>
|
|
632
724
|
</CopilotContext.Provider>,
|
|
633
725
|
);
|
|
634
726
|
|
|
635
727
|
await waitFor(() => {
|
|
636
|
-
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
637
|
-
|
|
728
|
+
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
729
|
+
"Processing...",
|
|
730
|
+
);
|
|
731
|
+
expect(latestClaims["msg-2"]?.stateSnapshot?.current_step).toBe(
|
|
732
|
+
"Processing...",
|
|
733
|
+
);
|
|
638
734
|
});
|
|
639
735
|
});
|
|
640
736
|
|
|
@@ -660,7 +756,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
660
756
|
);
|
|
661
757
|
|
|
662
758
|
await waitFor(() => {
|
|
663
|
-
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
759
|
+
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
760
|
+
"Processing...",
|
|
761
|
+
);
|
|
664
762
|
});
|
|
665
763
|
|
|
666
764
|
rerender(
|
|
@@ -684,8 +782,12 @@ describe("useCoAgentStateRender", () => {
|
|
|
684
782
|
);
|
|
685
783
|
|
|
686
784
|
await waitFor(() => {
|
|
687
|
-
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
688
|
-
|
|
785
|
+
expect(latestClaims["msg-1"]?.stateSnapshot?.current_step).toBe(
|
|
786
|
+
"Processing...",
|
|
787
|
+
);
|
|
788
|
+
expect(latestClaims["msg-2"]?.stateSnapshot?.current_step).toBe(
|
|
789
|
+
"Finalizing...",
|
|
790
|
+
);
|
|
689
791
|
});
|
|
690
792
|
});
|
|
691
793
|
|
|
@@ -704,7 +806,12 @@ describe("useCoAgentStateRender", () => {
|
|
|
704
806
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
705
807
|
<CoAgentStateRendersProvider>
|
|
706
808
|
<ClaimsObserver onChange={(claims) => (latestClaims = claims)} />
|
|
707
|
-
<MultiRunHarness
|
|
809
|
+
<MultiRunHarness
|
|
810
|
+
snapshot={snapshot}
|
|
811
|
+
runId="run-1"
|
|
812
|
+
messageId="msg-1"
|
|
813
|
+
messageIndex={0}
|
|
814
|
+
/>
|
|
708
815
|
</CoAgentStateRendersProvider>
|
|
709
816
|
</CopilotContext.Provider>,
|
|
710
817
|
);
|
|
@@ -739,7 +846,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
739
846
|
);
|
|
740
847
|
|
|
741
848
|
await waitFor(() => {
|
|
742
|
-
expect(latestClaims["msg-assistant-1"]?.stateSnapshot?.current_step).toBe(
|
|
849
|
+
expect(latestClaims["msg-assistant-1"]?.stateSnapshot?.current_step).toBe(
|
|
850
|
+
"First",
|
|
851
|
+
);
|
|
743
852
|
});
|
|
744
853
|
|
|
745
854
|
mockAgent.messages = [
|
|
@@ -759,7 +868,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
759
868
|
);
|
|
760
869
|
|
|
761
870
|
await waitFor(() => {
|
|
762
|
-
expect(latestClaims["msg-assistant-1"]?.stateSnapshot?.current_step).toBe(
|
|
871
|
+
expect(latestClaims["msg-assistant-1"]?.stateSnapshot?.current_step).toBe(
|
|
872
|
+
"First",
|
|
873
|
+
);
|
|
763
874
|
});
|
|
764
875
|
});
|
|
765
876
|
|
|
@@ -883,7 +994,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
883
994
|
|
|
884
995
|
await waitFor(() => {
|
|
885
996
|
const message = screen.getByTestId("message-msg-assistant-1");
|
|
886
|
-
expect(within(message).getByTestId("state").textContent).toBe(
|
|
997
|
+
expect(within(message).getByTestId("state").textContent).toBe(
|
|
998
|
+
"First run",
|
|
999
|
+
);
|
|
887
1000
|
});
|
|
888
1001
|
|
|
889
1002
|
mockAgent.messages = [
|
|
@@ -912,7 +1025,12 @@ describe("useCoAgentStateRender", () => {
|
|
|
912
1025
|
{ id: "msg-user-1", role: "user", content: "Hi" },
|
|
913
1026
|
{ id: "msg-assistant-1", role: "assistant", content: "" },
|
|
914
1027
|
{ id: "msg-user-2", role: "user", content: "Next" },
|
|
915
|
-
{
|
|
1028
|
+
{
|
|
1029
|
+
id: "msg-assistant-2",
|
|
1030
|
+
role: "assistant",
|
|
1031
|
+
content: "",
|
|
1032
|
+
state: '{"current_step":"Second run"}',
|
|
1033
|
+
},
|
|
916
1034
|
];
|
|
917
1035
|
|
|
918
1036
|
rerender(
|
|
@@ -925,7 +1043,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
925
1043
|
|
|
926
1044
|
await waitFor(() => {
|
|
927
1045
|
const message = screen.getByTestId("message-msg-assistant-2");
|
|
928
|
-
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1046
|
+
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1047
|
+
"Second run",
|
|
1048
|
+
);
|
|
929
1049
|
});
|
|
930
1050
|
});
|
|
931
1051
|
|
|
@@ -952,7 +1072,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
952
1072
|
|
|
953
1073
|
await waitFor(() => {
|
|
954
1074
|
const message = screen.getByTestId("message-msg-assistant-1");
|
|
955
|
-
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1075
|
+
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1076
|
+
"First run",
|
|
1077
|
+
);
|
|
956
1078
|
});
|
|
957
1079
|
|
|
958
1080
|
mockAgent.messages = [
|
|
@@ -985,7 +1107,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
985
1107
|
|
|
986
1108
|
await waitFor(() => {
|
|
987
1109
|
const message = screen.getByTestId("message-msg-assistant-2");
|
|
988
|
-
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1110
|
+
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1111
|
+
"Second run",
|
|
1112
|
+
);
|
|
989
1113
|
});
|
|
990
1114
|
});
|
|
991
1115
|
|
|
@@ -1005,7 +1129,7 @@ describe("useCoAgentStateRender", () => {
|
|
|
1005
1129
|
id: "msg-assistant-1",
|
|
1006
1130
|
role: "assistant",
|
|
1007
1131
|
content: "",
|
|
1008
|
-
state:
|
|
1132
|
+
state: '{"current_step":"Processing..."}',
|
|
1009
1133
|
},
|
|
1010
1134
|
];
|
|
1011
1135
|
mockAgent.isRunning = true;
|
|
@@ -1021,7 +1145,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
1021
1145
|
|
|
1022
1146
|
await waitFor(() => {
|
|
1023
1147
|
const message = screen.getByTestId("message-msg-assistant-1");
|
|
1024
|
-
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1148
|
+
expect(within(message).getByTestId("state").textContent).toBe(
|
|
1149
|
+
"Processing...",
|
|
1150
|
+
);
|
|
1025
1151
|
});
|
|
1026
1152
|
|
|
1027
1153
|
mockAgent.messages = [
|
|
@@ -1058,7 +1184,9 @@ describe("useCoAgentStateRender", () => {
|
|
|
1058
1184
|
render(
|
|
1059
1185
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
1060
1186
|
<CoAgentStateRendersProvider>
|
|
1061
|
-
<LiveStateHarness
|
|
1187
|
+
<LiveStateHarness
|
|
1188
|
+
message={{ id: "msg-live-empty", role: "assistant" }}
|
|
1189
|
+
/>
|
|
1062
1190
|
</CoAgentStateRendersProvider>
|
|
1063
1191
|
</CopilotContext.Provider>,
|
|
1064
1192
|
);
|
|
@@ -20,7 +20,9 @@ jest.mock("../../components/toast/toast-provider", () => ({
|
|
|
20
20
|
}),
|
|
21
21
|
}));
|
|
22
22
|
|
|
23
|
-
function createWrapper(
|
|
23
|
+
function createWrapper(
|
|
24
|
+
copilotContextValue: ReturnType<typeof createTestCopilotContext>,
|
|
25
|
+
) {
|
|
24
26
|
return function Wrapper({ children }: { children: ReactNode }) {
|
|
25
27
|
return (
|
|
26
28
|
<CopilotContext.Provider value={copilotContextValue}>
|
|
@@ -30,7 +32,10 @@ function createWrapper(copilotContextValue: ReturnType<typeof createTestCopilotC
|
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
function useHarness<T>(
|
|
35
|
+
function useHarness<T>(
|
|
36
|
+
action: Parameters<typeof useCoAgentStateRender<T>>[0],
|
|
37
|
+
deps?: unknown[],
|
|
38
|
+
) {
|
|
34
39
|
useCoAgentStateRender(action, deps);
|
|
35
40
|
return useCoAgentStateRenders();
|
|
36
41
|
}
|
|
@@ -58,11 +63,15 @@ describe("useCoAgentStateRender (hook behaviors)", () => {
|
|
|
58
63
|
beforeEach(() => {
|
|
59
64
|
jest.clearAllMocks();
|
|
60
65
|
idCounter = 0;
|
|
61
|
-
(randomId as jest.Mock).mockImplementation(
|
|
66
|
+
(randomId as jest.Mock).mockImplementation(
|
|
67
|
+
() => `test-random-id-${++idCounter}`,
|
|
68
|
+
);
|
|
62
69
|
});
|
|
63
70
|
|
|
64
71
|
it("registers state render and writes to the render cache", async () => {
|
|
65
|
-
const chatComponentsCache = {
|
|
72
|
+
const chatComponentsCache = {
|
|
73
|
+
current: { actions: {}, coAgentStateRenders: {} },
|
|
74
|
+
};
|
|
66
75
|
const wrapper = createWrapper(
|
|
67
76
|
createTestCopilotContext({
|
|
68
77
|
chatComponentsCache,
|
|
@@ -85,11 +94,15 @@ describe("useCoAgentStateRender (hook behaviors)", () => {
|
|
|
85
94
|
expect(Object.keys(result.current.coAgentStateRenders)).toHaveLength(1);
|
|
86
95
|
});
|
|
87
96
|
|
|
88
|
-
expect(
|
|
97
|
+
expect(
|
|
98
|
+
chatComponentsCache.current.coAgentStateRenders["agent-a-node-1"],
|
|
99
|
+
).toBe(renderFn);
|
|
89
100
|
});
|
|
90
101
|
|
|
91
102
|
it("mutates handler + cache in place when dependencies are omitted", async () => {
|
|
92
|
-
const chatComponentsCache = {
|
|
103
|
+
const chatComponentsCache = {
|
|
104
|
+
current: { actions: {}, coAgentStateRenders: {} },
|
|
105
|
+
};
|
|
93
106
|
const wrapper = createWrapper(
|
|
94
107
|
createTestCopilotContext({
|
|
95
108
|
chatComponentsCache,
|
|
@@ -122,13 +135,17 @@ describe("useCoAgentStateRender (hook behaviors)", () => {
|
|
|
122
135
|
const [id, initialRender] = getSingleEntry(initialRenders);
|
|
123
136
|
|
|
124
137
|
expect(initialRender.handler).toBe(handlerOne);
|
|
125
|
-
expect(
|
|
138
|
+
expect(
|
|
139
|
+
chatComponentsCache.current.coAgentStateRenders["agent-b-global"],
|
|
140
|
+
).toBe(renderOne);
|
|
126
141
|
|
|
127
142
|
rerender({ handler: handlerTwo, renderFn: renderTwo });
|
|
128
143
|
|
|
129
144
|
expect(result.current.coAgentStateRenders).toBe(initialRenders);
|
|
130
145
|
expect(result.current.coAgentStateRenders[id].handler).toBe(handlerTwo);
|
|
131
|
-
expect(
|
|
146
|
+
expect(
|
|
147
|
+
chatComponentsCache.current.coAgentStateRenders["agent-b-global"],
|
|
148
|
+
).toBe(renderTwo);
|
|
132
149
|
});
|
|
133
150
|
|
|
134
151
|
it("re-registers when dependencies change", async () => {
|
|
@@ -169,7 +186,9 @@ describe("useCoAgentStateRender (hook behaviors)", () => {
|
|
|
169
186
|
});
|
|
170
187
|
|
|
171
188
|
it("re-registers when string render changes", async () => {
|
|
172
|
-
const chatComponentsCache = {
|
|
189
|
+
const chatComponentsCache = {
|
|
190
|
+
current: { actions: {}, coAgentStateRenders: {} },
|
|
191
|
+
};
|
|
173
192
|
const wrapper = createWrapper(
|
|
174
193
|
createTestCopilotContext({
|
|
175
194
|
chatComponentsCache,
|
|
@@ -199,7 +218,9 @@ describe("useCoAgentStateRender (hook behaviors)", () => {
|
|
|
199
218
|
expect(result.current.coAgentStateRenders).not.toBe(initialRenders);
|
|
200
219
|
});
|
|
201
220
|
|
|
202
|
-
expect(
|
|
221
|
+
expect(
|
|
222
|
+
chatComponentsCache.current.coAgentStateRenders["agent-d-global"],
|
|
223
|
+
).toBe("Step 2");
|
|
203
224
|
});
|
|
204
225
|
|
|
205
226
|
it("warns when duplicate registrations target the same agent + node", async () => {
|
|
@@ -49,7 +49,13 @@ function ToolRenderHost() {
|
|
|
49
49
|
);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function RunActionButton({
|
|
52
|
+
function RunActionButton({
|
|
53
|
+
onMount,
|
|
54
|
+
onUnmount,
|
|
55
|
+
}: {
|
|
56
|
+
onMount: jest.Mock;
|
|
57
|
+
onUnmount: jest.Mock;
|
|
58
|
+
}) {
|
|
53
59
|
useEffect(() => {
|
|
54
60
|
onMount();
|
|
55
61
|
return () => onUnmount();
|
|
@@ -68,7 +74,9 @@ describe("useFrontendTool dependency changes", () => {
|
|
|
68
74
|
{
|
|
69
75
|
name: "actionOne",
|
|
70
76
|
description: "Execute action one",
|
|
71
|
-
render: () =>
|
|
77
|
+
render: () => (
|
|
78
|
+
<RunActionButton onMount={mounted} onUnmount={unmounted} />
|
|
79
|
+
),
|
|
72
80
|
},
|
|
73
81
|
[version],
|
|
74
82
|
);
|