@copilotkit/react-core 1.51.4-next.7 → 1.51.4-next.8
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 +10 -0
- package/README.md +18 -12
- package/dist/{chunk-DQXCQWSG.mjs → chunk-2JZZD4RP.mjs} +93 -58
- package/dist/chunk-2JZZD4RP.mjs.map +1 -0
- 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-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-VP43SLSZ.mjs → chunk-DAQORGBP.mjs} +10 -5
- package/dist/chunk-DAQORGBP.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-4RRMC7L2.mjs → chunk-IGYMBU43.mjs} +18 -7
- package/dist/chunk-IGYMBU43.mjs.map +1 -0
- 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-7DTB7S5V.mjs → chunk-LNGBARXE.mjs} +5 -2
- package/dist/chunk-LNGBARXE.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-LHERIF3L.mjs → chunk-NINJMAND.mjs} +10 -7
- package/dist/chunk-NINJMAND.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-RKTVJRK7.mjs → chunk-R7BV32X4.mjs} +5 -2
- package/dist/chunk-R7BV32X4.mjs.map +1 -0
- package/dist/{chunk-VKNLTZJE.mjs → chunk-S65UEHGI.mjs} +30 -21
- package/dist/chunk-S65UEHGI.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-HE22TZMF.mjs → chunk-SFOKX4MH.mjs} +18 -9
- package/dist/chunk-SFOKX4MH.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-XDFVCQD3.mjs → chunk-SYGQHN3H.mjs} +1 -1
- package/dist/{chunk-XDFVCQD3.mjs.map → chunk-SYGQHN3H.mjs.map} +1 -1
- 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 +7 -7
- 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 +26 -26
- 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 +12 -12
- 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 +12 -12
- 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 +11 -11
- 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 +52 -52
- 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 +5 -6
- 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
|
@@ -82,7 +82,10 @@ export function areStatesEquals(a: any, b: any) {
|
|
|
82
82
|
...bWithoutConstantKeys
|
|
83
83
|
} = b;
|
|
84
84
|
|
|
85
|
-
return
|
|
85
|
+
return (
|
|
86
|
+
JSON.stringify(aWithoutConstantKeys) ===
|
|
87
|
+
JSON.stringify(bWithoutConstantKeys)
|
|
88
|
+
);
|
|
86
89
|
}
|
|
87
90
|
|
|
88
91
|
export function isPlaceholderMessageId(messageId: string | undefined) {
|
|
@@ -93,7 +96,10 @@ export function isPlaceholderMessageName(messageName: string | undefined) {
|
|
|
93
96
|
return messageName === "coagent-state-render";
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
export function readCachedMessageEntry(entry: any): {
|
|
99
|
+
export function readCachedMessageEntry(entry: any): {
|
|
100
|
+
snapshot?: any;
|
|
101
|
+
runId?: string;
|
|
102
|
+
} {
|
|
97
103
|
if (!entry || typeof entry !== "object") {
|
|
98
104
|
return { snapshot: entry, runId: undefined };
|
|
99
105
|
}
|
|
@@ -164,11 +170,16 @@ export function resolveClaim({
|
|
|
164
170
|
action: ClaimAction.Override,
|
|
165
171
|
nextClaim: { stateRenderId, runId, messageIndex },
|
|
166
172
|
lockOthers:
|
|
167
|
-
runId === renderClaimedByOtherMessage.runId ||
|
|
173
|
+
runId === renderClaimedByOtherMessage.runId ||
|
|
174
|
+
isPlaceholderMessageId(claimedMessageId),
|
|
168
175
|
};
|
|
169
176
|
}
|
|
170
177
|
|
|
171
|
-
if (
|
|
178
|
+
if (
|
|
179
|
+
runId &&
|
|
180
|
+
renderClaimedByOtherMessage.runId &&
|
|
181
|
+
runId !== renderClaimedByOtherMessage.runId
|
|
182
|
+
) {
|
|
172
183
|
return {
|
|
173
184
|
canRender: true,
|
|
174
185
|
action: ClaimAction.Override,
|
|
@@ -238,12 +249,16 @@ export function selectSnapshot({
|
|
|
238
249
|
? [...agentMessages].reverse().find((msg) => msg.role === "assistant")?.id
|
|
239
250
|
: undefined;
|
|
240
251
|
const latestSnapshot =
|
|
241
|
-
stateRenderId !== undefined
|
|
252
|
+
stateRenderId !== undefined
|
|
253
|
+
? caches.byStateRenderAndRun[`${stateRenderId}::latest`]
|
|
254
|
+
: undefined;
|
|
242
255
|
const messageIndex = agentMessages
|
|
243
256
|
? agentMessages.findIndex((msg) => msg.id === messageId)
|
|
244
257
|
: -1;
|
|
245
258
|
const messageRole =
|
|
246
|
-
messageIndex >= 0 && agentMessages
|
|
259
|
+
messageIndex >= 0 && agentMessages
|
|
260
|
+
? agentMessages[messageIndex]?.role
|
|
261
|
+
: undefined;
|
|
247
262
|
let previousUserMessageId: string | undefined;
|
|
248
263
|
if (messageIndex > 0 && agentMessages) {
|
|
249
264
|
for (let i = messageIndex - 1; i >= 0; i -= 1) {
|
|
@@ -259,7 +274,9 @@ export function selectSnapshot({
|
|
|
259
274
|
agentState !== undefined &&
|
|
260
275
|
areStatesEquals(latestSnapshot, agentState);
|
|
261
276
|
const shouldUseLiveState =
|
|
262
|
-
(Boolean(allowLiveState) ||
|
|
277
|
+
(Boolean(allowLiveState) ||
|
|
278
|
+
!lastAssistantId ||
|
|
279
|
+
messageId === lastAssistantId) &&
|
|
263
280
|
!liveStateIsStale;
|
|
264
281
|
const snapshot = stateSnapshotProp
|
|
265
282
|
? parseJson(stateSnapshotProp, stateSnapshotProp)
|
|
@@ -273,22 +290,32 @@ export function selectSnapshot({
|
|
|
273
290
|
(stateSnapshotProp !== undefined || shouldUseLiveState);
|
|
274
291
|
|
|
275
292
|
const messageCacheEntry = caches.byMessageId[messageId];
|
|
276
|
-
const cachedMessageSnapshot =
|
|
293
|
+
const cachedMessageSnapshot =
|
|
294
|
+
readCachedMessageEntry(messageCacheEntry).snapshot;
|
|
277
295
|
const cacheKey =
|
|
278
|
-
stateRenderId !== undefined
|
|
296
|
+
stateRenderId !== undefined
|
|
297
|
+
? `${stateRenderId}::${effectiveRunId}`
|
|
298
|
+
: undefined;
|
|
279
299
|
let cachedSnapshot = cachedMessageSnapshot ?? caches.byMessageId[messageId];
|
|
280
|
-
if (
|
|
300
|
+
if (
|
|
301
|
+
cachedSnapshot === undefined &&
|
|
302
|
+
cacheKey &&
|
|
303
|
+
caches.byStateRenderAndRun[cacheKey] !== undefined
|
|
304
|
+
) {
|
|
281
305
|
cachedSnapshot = caches.byStateRenderAndRun[cacheKey];
|
|
282
306
|
}
|
|
283
307
|
if (
|
|
284
308
|
cachedSnapshot === undefined &&
|
|
285
309
|
stateRenderId &&
|
|
286
310
|
previousUserMessageId &&
|
|
287
|
-
caches.byStateRenderAndRun[
|
|
288
|
-
|
|
311
|
+
caches.byStateRenderAndRun[
|
|
312
|
+
`${stateRenderId}::pending:${previousUserMessageId}`
|
|
313
|
+
] !== undefined
|
|
289
314
|
) {
|
|
290
315
|
cachedSnapshot =
|
|
291
|
-
caches.byStateRenderAndRun[
|
|
316
|
+
caches.byStateRenderAndRun[
|
|
317
|
+
`${stateRenderId}::pending:${previousUserMessageId}`
|
|
318
|
+
];
|
|
292
319
|
}
|
|
293
320
|
if (
|
|
294
321
|
cachedSnapshot === undefined &&
|
|
@@ -302,10 +329,16 @@ export function selectSnapshot({
|
|
|
302
329
|
}
|
|
303
330
|
|
|
304
331
|
const snapshotForClaim = existingClaim?.locked
|
|
305
|
-
? existingClaim.stateSnapshot ?? cachedSnapshot
|
|
332
|
+
? (existingClaim.stateSnapshot ?? cachedSnapshot)
|
|
306
333
|
: hasSnapshotKeys
|
|
307
334
|
? snapshot
|
|
308
|
-
: existingClaim?.stateSnapshot ?? cachedSnapshot;
|
|
335
|
+
: (existingClaim?.stateSnapshot ?? cachedSnapshot);
|
|
309
336
|
|
|
310
|
-
return {
|
|
337
|
+
return {
|
|
338
|
+
snapshot,
|
|
339
|
+
hasSnapshotKeys,
|
|
340
|
+
cachedSnapshot,
|
|
341
|
+
allowEmptySnapshot,
|
|
342
|
+
snapshotForClaim,
|
|
343
|
+
};
|
|
311
344
|
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
ReactCustomMessageRendererPosition,
|
|
3
|
+
useAgent,
|
|
4
|
+
} from "@copilotkitnext/react";
|
|
2
5
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
3
6
|
import type { AgentSubscriber } from "@ag-ui/client";
|
|
4
7
|
import { useCoAgentStateRenders } from "../context";
|
|
@@ -100,7 +103,10 @@ export interface CoAgentStateRenderBridgeProps {
|
|
|
100
103
|
stateSnapshot: any;
|
|
101
104
|
}
|
|
102
105
|
|
|
103
|
-
export function useCoagentStateRenderBridge(
|
|
106
|
+
export function useCoagentStateRenderBridge(
|
|
107
|
+
agentId: string,
|
|
108
|
+
props: CoAgentStateRenderBridgeProps,
|
|
109
|
+
) {
|
|
104
110
|
const { stateSnapshot, message } = props;
|
|
105
111
|
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
106
112
|
const { agent } = useAgent({ agentId });
|
|
@@ -134,18 +140,25 @@ export function useCoagentStateRenderBridge(agentId: string, props: CoAgentState
|
|
|
134
140
|
|
|
135
141
|
const getStateRender = useCallback(
|
|
136
142
|
(messageId: string) => {
|
|
137
|
-
return Object.entries(coAgentStateRenders).find(
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
return Object.entries(coAgentStateRenders).find(
|
|
144
|
+
([stateRenderId, stateRender]) => {
|
|
145
|
+
if (claimsRef.current[messageId]) {
|
|
146
|
+
return stateRenderId === claimsRef.current[messageId].stateRenderId;
|
|
147
|
+
}
|
|
148
|
+
const matchingAgentName = stateRender.name === agentId;
|
|
149
|
+
const matchesNodeContext = stateRender.nodeName
|
|
150
|
+
? stateRender.nodeName === nodeName
|
|
151
|
+
: true;
|
|
152
|
+
return matchingAgentName && matchesNodeContext;
|
|
153
|
+
},
|
|
154
|
+
);
|
|
145
155
|
},
|
|
146
156
|
[coAgentStateRenders, nodeName, agentId],
|
|
147
157
|
);
|
|
148
|
-
const stateRenderEntry = useMemo(
|
|
158
|
+
const stateRenderEntry = useMemo(
|
|
159
|
+
() => getStateRender(message.id),
|
|
160
|
+
[getStateRender, message.id],
|
|
161
|
+
);
|
|
149
162
|
const stateRenderId = stateRenderEntry?.[0];
|
|
150
163
|
const stateRender = stateRenderEntry?.[1];
|
|
151
164
|
|
|
@@ -174,13 +187,17 @@ export function useCoagentStateRenderBridge(agentId: string, props: CoAgentState
|
|
|
174
187
|
|
|
175
188
|
if (stateRender.handler) {
|
|
176
189
|
stateRender.handler({
|
|
177
|
-
state: stateSnapshot
|
|
190
|
+
state: stateSnapshot
|
|
191
|
+
? parseJson(stateSnapshot, stateSnapshot)
|
|
192
|
+
: (agent?.state ?? {}),
|
|
178
193
|
nodeName: nodeName ?? "",
|
|
179
194
|
});
|
|
180
195
|
}
|
|
181
196
|
|
|
182
197
|
if (stateRender.render) {
|
|
183
|
-
const status = agent?.isRunning
|
|
198
|
+
const status = agent?.isRunning
|
|
199
|
+
? RenderStatus.InProgress
|
|
200
|
+
: RenderStatus.Complete;
|
|
184
201
|
|
|
185
202
|
if (typeof stateRender.render === "string") return stateRender.render;
|
|
186
203
|
|
|
@@ -44,7 +44,9 @@ function getClaimsStore(
|
|
|
44
44
|
return claimsRef.current as ClaimsStore;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function getSnapshotCaches(
|
|
47
|
+
function getSnapshotCaches(
|
|
48
|
+
claimsRef: React.MutableRefObject<Record<string, Claim>>,
|
|
49
|
+
): SnapshotCaches {
|
|
48
50
|
const store = getClaimsStore(claimsRef);
|
|
49
51
|
return {
|
|
50
52
|
byStateRenderAndRun: store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] ?? {},
|
|
@@ -65,7 +67,8 @@ export function useStateRenderRegistry({
|
|
|
65
67
|
const store = getClaimsStore(claimsRef);
|
|
66
68
|
const runId = message.runId;
|
|
67
69
|
const cachedMessageEntry = store[LAST_SNAPSHOTS_BY_MESSAGE]?.[message.id];
|
|
68
|
-
const { runId: cachedMessageRunId } =
|
|
70
|
+
const { runId: cachedMessageRunId } =
|
|
71
|
+
readCachedMessageEntry(cachedMessageEntry);
|
|
69
72
|
const existingClaimRunId = claimsRef.current[message.id]?.runId;
|
|
70
73
|
const effectiveRunId = getEffectiveRunId({
|
|
71
74
|
existingClaimRunId,
|
|
@@ -85,7 +88,8 @@ export function useStateRenderRegistry({
|
|
|
85
88
|
};
|
|
86
89
|
const cacheKey = `${existingClaim.stateRenderId}::${existingClaim.runId ?? "pending"}`;
|
|
87
90
|
snapshotCache[cacheKey] = existingClaim.stateSnapshot;
|
|
88
|
-
snapshotCache[`${existingClaim.stateRenderId}::latest`] =
|
|
91
|
+
snapshotCache[`${existingClaim.stateRenderId}::latest`] =
|
|
92
|
+
existingClaim.stateSnapshot;
|
|
89
93
|
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
90
94
|
|
|
91
95
|
const messageCache = {
|
|
@@ -108,21 +112,24 @@ export function useStateRenderRegistry({
|
|
|
108
112
|
const caches = getSnapshotCaches(claimsRef);
|
|
109
113
|
const existingClaim = claimsRef.current[message.id] as Claim | undefined;
|
|
110
114
|
|
|
111
|
-
const { snapshot, hasSnapshotKeys, allowEmptySnapshot, snapshotForClaim } =
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
const { snapshot, hasSnapshotKeys, allowEmptySnapshot, snapshotForClaim } =
|
|
116
|
+
selectSnapshot({
|
|
117
|
+
messageId: message.id,
|
|
118
|
+
messageName: message.name,
|
|
119
|
+
allowLiveState:
|
|
120
|
+
isPlaceholderMessageName(message.name) ||
|
|
121
|
+
isPlaceholderMessageId(message.id),
|
|
122
|
+
skipLatestCache:
|
|
123
|
+
isPlaceholderMessageName(message.name) ||
|
|
124
|
+
isPlaceholderMessageId(message.id),
|
|
125
|
+
stateRenderId,
|
|
126
|
+
effectiveRunId,
|
|
127
|
+
stateSnapshotProp: stateSnapshot,
|
|
128
|
+
agentState,
|
|
129
|
+
agentMessages,
|
|
130
|
+
existingClaim,
|
|
131
|
+
caches,
|
|
132
|
+
});
|
|
126
133
|
|
|
127
134
|
const resolution = resolveClaim({
|
|
128
135
|
claims: claimsRef.current as ClaimsByMessageId,
|
|
@@ -157,8 +164,13 @@ export function useStateRenderRegistry({
|
|
|
157
164
|
}
|
|
158
165
|
|
|
159
166
|
if (existingClaim && !existingClaim.locked && agentMessages?.length) {
|
|
160
|
-
const indexInAgentMessages = agentMessages.findIndex(
|
|
161
|
-
|
|
167
|
+
const indexInAgentMessages = agentMessages.findIndex(
|
|
168
|
+
(msg: any) => msg.id === message.id,
|
|
169
|
+
);
|
|
170
|
+
if (
|
|
171
|
+
indexInAgentMessages >= 0 &&
|
|
172
|
+
indexInAgentMessages < agentMessages.length - 1
|
|
173
|
+
) {
|
|
162
174
|
existingClaim.locked = true;
|
|
163
175
|
}
|
|
164
176
|
}
|
|
@@ -206,7 +218,10 @@ export function useStateRenderRegistry({
|
|
|
206
218
|
const messageCache = {
|
|
207
219
|
...(store[LAST_SNAPSHOTS_BY_MESSAGE] ?? {}),
|
|
208
220
|
};
|
|
209
|
-
messageCache[message.id] = {
|
|
221
|
+
messageCache[message.id] = {
|
|
222
|
+
snapshot: snapshotForClaim,
|
|
223
|
+
runId: effectiveRunId,
|
|
224
|
+
};
|
|
210
225
|
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
211
226
|
}
|
|
212
227
|
}
|
|
@@ -64,19 +64,28 @@ export function useCoAgentStateRender<T = any>(
|
|
|
64
64
|
dependencies?: any[],
|
|
65
65
|
): void {
|
|
66
66
|
const { chatComponentsCache, availableAgents } = useContext(CopilotContext);
|
|
67
|
-
const {
|
|
68
|
-
|
|
67
|
+
const {
|
|
68
|
+
setCoAgentStateRender,
|
|
69
|
+
removeCoAgentStateRender,
|
|
70
|
+
coAgentStateRenders,
|
|
71
|
+
} = useCoAgentStateRenders();
|
|
69
72
|
const idRef = useRef<string>(randomId());
|
|
70
73
|
const { setBannerError, addToast } = useToast();
|
|
71
74
|
|
|
72
75
|
useEffect(() => {
|
|
73
|
-
if (
|
|
76
|
+
if (
|
|
77
|
+
availableAgents?.length &&
|
|
78
|
+
!availableAgents.some((a) => a.name === action.name)
|
|
79
|
+
) {
|
|
74
80
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
75
81
|
|
|
76
82
|
// Route to banner instead of toast for consistency
|
|
77
83
|
const agentError = new CopilotKitAgentDiscoveryError({
|
|
78
84
|
agentName: action.name,
|
|
79
|
-
availableAgents: availableAgents.map((a) => ({
|
|
85
|
+
availableAgents: availableAgents.map((a) => ({
|
|
86
|
+
name: a.name,
|
|
87
|
+
id: a.id,
|
|
88
|
+
})),
|
|
80
89
|
});
|
|
81
90
|
setBannerError(agentError);
|
|
82
91
|
}
|
|
@@ -98,26 +107,28 @@ export function useCoAgentStateRender<T = any>(
|
|
|
98
107
|
useEffect(() => {
|
|
99
108
|
// Check for duplicates by comparing against all other actions
|
|
100
109
|
const currentId = idRef.current;
|
|
101
|
-
const hasDuplicate = Object.entries(coAgentStateRenders).some(
|
|
102
|
-
|
|
103
|
-
|
|
110
|
+
const hasDuplicate = Object.entries(coAgentStateRenders).some(
|
|
111
|
+
([id, otherAction]) => {
|
|
112
|
+
// Skip comparing with self
|
|
113
|
+
if (id === currentId) return false;
|
|
104
114
|
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
// Different agent names are never duplicates
|
|
116
|
+
if (otherAction.name !== action.name) return false;
|
|
107
117
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
118
|
+
// Same agent names:
|
|
119
|
+
const hasNodeName = !!action.nodeName;
|
|
120
|
+
const hasOtherNodeName = !!otherAction.nodeName;
|
|
111
121
|
|
|
112
|
-
|
|
113
|
-
|
|
122
|
+
// If neither has nodeName, they're duplicates
|
|
123
|
+
if (!hasNodeName && !hasOtherNodeName) return true;
|
|
114
124
|
|
|
115
|
-
|
|
116
|
-
|
|
125
|
+
// If one has nodeName and other doesn't, they're not duplicates
|
|
126
|
+
if (hasNodeName !== hasOtherNodeName) return false;
|
|
117
127
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
128
|
+
// If both have nodeName, they're duplicates only if the names match
|
|
129
|
+
return action.nodeName === otherAction.nodeName;
|
|
130
|
+
},
|
|
131
|
+
);
|
|
121
132
|
|
|
122
133
|
if (hasDuplicate) {
|
|
123
134
|
const message = action.nodeName
|
package/src/hooks/use-coagent.ts
CHANGED
|
@@ -113,7 +113,9 @@ interface UseCoagentOptionsBase {
|
|
|
113
113
|
};
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
interface WithInternalStateManagementAndInitial<
|
|
116
|
+
interface WithInternalStateManagementAndInitial<
|
|
117
|
+
T,
|
|
118
|
+
> extends UseCoagentOptionsBase {
|
|
117
119
|
/**
|
|
118
120
|
* The initial state of the agent.
|
|
119
121
|
*/
|
|
@@ -202,7 +204,9 @@ export type HintFunction = (params: HintFunctionParams) => Message | undefined;
|
|
|
202
204
|
* We call these shared state experiences "agentic copilots". To get started using agentic copilots, which
|
|
203
205
|
* we refer to as CoAgents, checkout the documentation at https://docs.copilotkit.ai/coagents/quickstart/langgraph.
|
|
204
206
|
*/
|
|
205
|
-
export function useCoAgent<T = any>(
|
|
207
|
+
export function useCoAgent<T = any>(
|
|
208
|
+
options: UseCoagentOptions<T>,
|
|
209
|
+
): UseCoagentReturnType<T> {
|
|
206
210
|
const { agent } = useAgent({ agentId: options.name });
|
|
207
211
|
const { copilotkit } = useCopilotKit();
|
|
208
212
|
const nodeName = useAgentNodeName(options.name);
|
|
@@ -238,8 +242,15 @@ export function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentRe
|
|
|
238
242
|
}, [options.config, options.configurable]);
|
|
239
243
|
|
|
240
244
|
const externalStateStr = useMemo(
|
|
241
|
-
() =>
|
|
242
|
-
|
|
245
|
+
() =>
|
|
246
|
+
isExternalStateManagement(options)
|
|
247
|
+
? JSON.stringify(options.state)
|
|
248
|
+
: undefined,
|
|
249
|
+
[
|
|
250
|
+
isExternalStateManagement(options)
|
|
251
|
+
? JSON.stringify(options.state)
|
|
252
|
+
: undefined,
|
|
253
|
+
],
|
|
243
254
|
);
|
|
244
255
|
|
|
245
256
|
// Sync internal state with external state if state management is external
|
|
@@ -8,9 +8,13 @@ import { StaticSuggestionsConfig, Suggestion } from "@copilotkitnext/core";
|
|
|
8
8
|
import { useCopilotContext } from "../context";
|
|
9
9
|
import { useEffect, useMemo } from "react";
|
|
10
10
|
|
|
11
|
-
type StaticSuggestionInput = Omit<Suggestion, "isLoading"> &
|
|
11
|
+
type StaticSuggestionInput = Omit<Suggestion, "isLoading"> &
|
|
12
|
+
Partial<Pick<Suggestion, "isLoading">>;
|
|
12
13
|
|
|
13
|
-
type StaticSuggestionsConfigInput = Omit<
|
|
14
|
+
type StaticSuggestionsConfigInput = Omit<
|
|
15
|
+
StaticSuggestionsConfig,
|
|
16
|
+
"suggestions"
|
|
17
|
+
> & {
|
|
14
18
|
suggestions: StaticSuggestionInput[];
|
|
15
19
|
};
|
|
16
20
|
|
|
@@ -34,7 +38,12 @@ type DynamicSuggestionsConfigInput = {
|
|
|
34
38
|
* Whether the suggestions are available. Defaults to `enabled`.
|
|
35
39
|
* @default enabled
|
|
36
40
|
*/
|
|
37
|
-
available?:
|
|
41
|
+
available?:
|
|
42
|
+
| "enabled"
|
|
43
|
+
| "disabled"
|
|
44
|
+
| "always"
|
|
45
|
+
| "before-first-message"
|
|
46
|
+
| "after-first-message";
|
|
38
47
|
|
|
39
48
|
/**
|
|
40
49
|
* An optional class name to apply to the suggestions.
|
|
@@ -54,7 +63,8 @@ export function useConfigureChatSuggestions(
|
|
|
54
63
|
const resolvedAgentId = existingConfig?.agentId ?? "default";
|
|
55
64
|
const { copilotkit } = useCopilotKit();
|
|
56
65
|
|
|
57
|
-
const available =
|
|
66
|
+
const available =
|
|
67
|
+
config.available === "enabled" ? "always" : config.available;
|
|
58
68
|
|
|
59
69
|
const finalSuggestionConfig = {
|
|
60
70
|
...config,
|
|
@@ -132,10 +132,19 @@
|
|
|
132
132
|
*/
|
|
133
133
|
import { useEffect, useRef, useState } from "react";
|
|
134
134
|
import { Parameter } from "@copilotkit/shared";
|
|
135
|
-
import {
|
|
135
|
+
import {
|
|
136
|
+
CatchAllFrontendAction,
|
|
137
|
+
FrontendAction,
|
|
138
|
+
} from "../types/frontend-action";
|
|
136
139
|
import { useFrontendTool, UseFrontendToolArgs } from "./use-frontend-tool";
|
|
137
|
-
import {
|
|
138
|
-
|
|
140
|
+
import {
|
|
141
|
+
useRenderToolCall,
|
|
142
|
+
UseRenderToolCallArgs,
|
|
143
|
+
} from "./use-render-tool-call";
|
|
144
|
+
import {
|
|
145
|
+
useHumanInTheLoop,
|
|
146
|
+
UseHumanInTheLoopArgs,
|
|
147
|
+
} from "./use-human-in-the-loop";
|
|
139
148
|
import { useCopilotContext } from "../context";
|
|
140
149
|
|
|
141
150
|
// Helper to determine which component and action config to use
|
|
@@ -65,7 +65,10 @@ export interface UseCopilotAdditionalInstructionsOptions {
|
|
|
65
65
|
* Adds the given instructions to the Copilot context.
|
|
66
66
|
*/
|
|
67
67
|
export function useCopilotAdditionalInstructions(
|
|
68
|
-
{
|
|
68
|
+
{
|
|
69
|
+
instructions,
|
|
70
|
+
available = "enabled",
|
|
71
|
+
}: UseCopilotAdditionalInstructionsOptions,
|
|
69
72
|
dependencies?: any[],
|
|
70
73
|
) {
|
|
71
74
|
const { setAdditionalInstructions } = useCopilotContext();
|
|
@@ -73,13 +76,23 @@ export function useCopilotAdditionalInstructions(
|
|
|
73
76
|
useEffect(() => {
|
|
74
77
|
if (available === "disabled") return;
|
|
75
78
|
|
|
76
|
-
setAdditionalInstructions((prevInstructions) => [
|
|
79
|
+
setAdditionalInstructions((prevInstructions) => [
|
|
80
|
+
...(prevInstructions || []),
|
|
81
|
+
instructions,
|
|
82
|
+
]);
|
|
77
83
|
|
|
78
84
|
return () => {
|
|
79
85
|
setAdditionalInstructions(
|
|
80
86
|
(prevInstructions) =>
|
|
81
|
-
prevInstructions?.filter(
|
|
87
|
+
prevInstructions?.filter(
|
|
88
|
+
(instruction) => instruction !== instructions,
|
|
89
|
+
) || [],
|
|
82
90
|
);
|
|
83
91
|
};
|
|
84
|
-
}, [
|
|
92
|
+
}, [
|
|
93
|
+
available,
|
|
94
|
+
instructions,
|
|
95
|
+
setAdditionalInstructions,
|
|
96
|
+
...(dependencies || []),
|
|
97
|
+
]);
|
|
85
98
|
}
|
|
@@ -45,7 +45,10 @@ export function useCopilotAuthenticatedAction_c<T extends Parameter[]>(
|
|
|
45
45
|
return authConfig_c?.SignInComponent
|
|
46
46
|
? React.createElement(authConfig_c.SignInComponent, {
|
|
47
47
|
onSignInComplete: (authState) => {
|
|
48
|
-
setAuthStates_c?.((prev) => ({
|
|
48
|
+
setAuthStates_c?.((prev) => ({
|
|
49
|
+
...prev,
|
|
50
|
+
[action.name]: authState,
|
|
51
|
+
}));
|
|
49
52
|
if (pendingActionRef.current) {
|
|
50
53
|
executeAction(pendingActionRef.current);
|
|
51
54
|
pendingActionRef.current = null;
|
|
@@ -213,7 +213,9 @@ const createNonFunctionalReturn = (): UseCopilotChatReturn_c => ({
|
|
|
213
213
|
* const { messages, sendMessage, suggestions, interrupt } = useCopilotChatHeadless_c();
|
|
214
214
|
* ```
|
|
215
215
|
*/
|
|
216
|
-
function useCopilotChatHeadless_c(
|
|
216
|
+
function useCopilotChatHeadless_c(
|
|
217
|
+
options: UseCopilotChatOptions_c = {},
|
|
218
|
+
): UseCopilotChatReturn_c {
|
|
217
219
|
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
218
220
|
|
|
219
221
|
// Check if publicApiKey is available
|
|
@@ -251,7 +253,11 @@ function useCopilotChatHeadless_c(options: UseCopilotChatOptions_c = {}): UseCop
|
|
|
251
253
|
}
|
|
252
254
|
|
|
253
255
|
export { defaultSystemMessage, useCopilotChatHeadless_c };
|
|
254
|
-
export type {
|
|
256
|
+
export type {
|
|
257
|
+
UseCopilotChatOptions_c,
|
|
258
|
+
UseCopilotChatReturn_c,
|
|
259
|
+
MCPServerConfig,
|
|
260
|
+
};
|
|
255
261
|
|
|
256
262
|
const noKeyWarning = () => {
|
|
257
263
|
styledConsole.logCopilotKitPlatformMessage();
|
|
@@ -67,9 +67,13 @@ import {
|
|
|
67
67
|
import { useEffect } from "react";
|
|
68
68
|
import { StaticSuggestionsConfig, Suggestion } from "@copilotkitnext/core";
|
|
69
69
|
|
|
70
|
-
type StaticSuggestionInput = Omit<Suggestion, "isLoading"> &
|
|
70
|
+
type StaticSuggestionInput = Omit<Suggestion, "isLoading"> &
|
|
71
|
+
Partial<Pick<Suggestion, "isLoading">>;
|
|
71
72
|
|
|
72
|
-
type StaticSuggestionsConfigInput = Omit<
|
|
73
|
+
type StaticSuggestionsConfigInput = Omit<
|
|
74
|
+
StaticSuggestionsConfig,
|
|
75
|
+
"suggestions"
|
|
76
|
+
> & {
|
|
73
77
|
suggestions: StaticSuggestionInput[];
|
|
74
78
|
};
|
|
75
79
|
|
|
@@ -93,7 +97,12 @@ type DynamicSuggestionsConfigInput = {
|
|
|
93
97
|
* Whether the suggestions are available. Defaults to `enabled`.
|
|
94
98
|
* @default enabled
|
|
95
99
|
*/
|
|
96
|
-
available?:
|
|
100
|
+
available?:
|
|
101
|
+
| "enabled"
|
|
102
|
+
| "disabled"
|
|
103
|
+
| "always"
|
|
104
|
+
| "before-first-message"
|
|
105
|
+
| "after-first-message";
|
|
97
106
|
|
|
98
107
|
/**
|
|
99
108
|
* An optional class name to apply to the suggestions.
|
|
@@ -113,7 +122,8 @@ export function useCopilotChatSuggestions(
|
|
|
113
122
|
const resolvedAgentId = existingConfig?.agentId ?? "default";
|
|
114
123
|
|
|
115
124
|
const available =
|
|
116
|
-
(config.available === "enabled" ? "always" : config.available) ??
|
|
125
|
+
(config.available === "enabled" ? "always" : config.available) ??
|
|
126
|
+
"before-first-message";
|
|
117
127
|
|
|
118
128
|
const finalSuggestionConfig = {
|
|
119
129
|
...config,
|
|
@@ -101,7 +101,9 @@ export type UseCopilotChatReturn = Omit<
|
|
|
101
101
|
* **Open Source Friendly** - Works without requiring a `publicApiKey`.
|
|
102
102
|
*/
|
|
103
103
|
// TODO: Do we need this? If so, does it work properly? test.
|
|
104
|
-
export function useCopilotChat(
|
|
104
|
+
export function useCopilotChat(
|
|
105
|
+
options: UseCopilotChatOptions = {},
|
|
106
|
+
): UseCopilotChatReturn {
|
|
105
107
|
const {
|
|
106
108
|
visibleMessages,
|
|
107
109
|
appendMessage,
|