@copilotkit/react-core 1.51.4 → 1.51.5-next.1
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/.attw.json +3 -0
- package/CHANGELOG.md +21 -0
- package/dist/index.cjs +4010 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1327 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +1327 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +3944 -148
- package/dist/index.mjs.map +1 -1
- package/dist/index.umd.js +4075 -39
- package/dist/index.umd.js.map +1 -1
- package/dist/v2/index.cjs +17 -0
- package/dist/v2/index.css +2 -3
- package/dist/v2/index.css.map +1 -1
- package/dist/v2/index.d.cts +2 -0
- package/dist/v2/index.d.mts +2 -0
- package/dist/v2/index.mjs +4 -5
- package/dist/v2/index.umd.js +24 -2
- package/package.json +22 -22
- package/src/components/copilot-provider/__tests__/copilotkit-error.test.tsx +3 -3
- package/src/hooks/__tests__/use-coagent-config.test.ts +23 -22
- package/src/hooks/__tests__/use-coagent-state-render.e2e.test.tsx +33 -35
- package/src/hooks/__tests__/use-coagent-state-render.test.tsx +19 -18
- package/src/hooks/__tests__/use-frontend-tool-available.test.tsx +72 -0
- package/src/hooks/__tests__/use-frontend-tool-remount.e2e.test.tsx +9 -7
- package/src/hooks/use-copilot-chat.ts +1 -1
- package/src/hooks/use-frontend-tool.ts +2 -1
- package/src/lib/copilot-task.ts +1 -1
- package/src/setupTests.ts +17 -16
- package/tsconfig.json +1 -1
- package/tsdown.config.ts +94 -0
- package/vitest.config.mjs +30 -0
- package/dist/chunk-2IDV5OHF.mjs +0 -11
- package/dist/chunk-2IDV5OHF.mjs.map +0 -1
- package/dist/chunk-2RSAYTXH.mjs +0 -137
- package/dist/chunk-2RSAYTXH.mjs.map +0 -1
- package/dist/chunk-36KQV2NA.mjs +0 -1
- package/dist/chunk-36KQV2NA.mjs.map +0 -1
- package/dist/chunk-3LZZ4RVM.mjs +0 -37
- package/dist/chunk-3LZZ4RVM.mjs.map +0 -1
- package/dist/chunk-4ZQYMC5F.mjs +0 -36
- package/dist/chunk-4ZQYMC5F.mjs.map +0 -1
- package/dist/chunk-6ABVYB2U.mjs +0 -95
- package/dist/chunk-6ABVYB2U.mjs.map +0 -1
- package/dist/chunk-6AWG5FWL.mjs +0 -102
- package/dist/chunk-6AWG5FWL.mjs.map +0 -1
- package/dist/chunk-6YOKPWQ7.mjs +0 -1
- package/dist/chunk-6YOKPWQ7.mjs.map +0 -1
- package/dist/chunk-7GIBHX6X.mjs +0 -195
- package/dist/chunk-7GIBHX6X.mjs.map +0 -1
- package/dist/chunk-7PJKPWMD.mjs +0 -112
- package/dist/chunk-7PJKPWMD.mjs.map +0 -1
- package/dist/chunk-7U3DNFBF.mjs +0 -20
- package/dist/chunk-7U3DNFBF.mjs.map +0 -1
- package/dist/chunk-A6NKSGH3.mjs +0 -1
- package/dist/chunk-A6NKSGH3.mjs.map +0 -1
- package/dist/chunk-AAGMWZCN.mjs +0 -439
- package/dist/chunk-AAGMWZCN.mjs.map +0 -1
- package/dist/chunk-C7HSVDHD.mjs +0 -116
- package/dist/chunk-C7HSVDHD.mjs.map +0 -1
- package/dist/chunk-CYDWEPFL.mjs +0 -1
- package/dist/chunk-CYDWEPFL.mjs.map +0 -1
- package/dist/chunk-CZT7JUIM.mjs +0 -153
- package/dist/chunk-CZT7JUIM.mjs.map +0 -1
- package/dist/chunk-DMLQZG75.mjs +0 -25
- package/dist/chunk-DMLQZG75.mjs.map +0 -1
- package/dist/chunk-FD6FGKYY.mjs +0 -1
- package/dist/chunk-FD6FGKYY.mjs.map +0 -1
- package/dist/chunk-G7SUZGGB.mjs +0 -126
- package/dist/chunk-G7SUZGGB.mjs.map +0 -1
- package/dist/chunk-GY3FQICF.mjs +0 -23
- package/dist/chunk-GY3FQICF.mjs.map +0 -1
- package/dist/chunk-I76HKHPJ.mjs +0 -32
- package/dist/chunk-I76HKHPJ.mjs.map +0 -1
- package/dist/chunk-ICIK2BSB.mjs +0 -17
- package/dist/chunk-ICIK2BSB.mjs.map +0 -1
- package/dist/chunk-IHMMKEFG.mjs +0 -64
- package/dist/chunk-IHMMKEFG.mjs.map +0 -1
- package/dist/chunk-JD7BAH7U.mjs +0 -1
- package/dist/chunk-JD7BAH7U.mjs.map +0 -1
- package/dist/chunk-K5OXUXCG.mjs +0 -76
- package/dist/chunk-K5OXUXCG.mjs.map +0 -1
- package/dist/chunk-L7GPCF2V.mjs +0 -229
- package/dist/chunk-L7GPCF2V.mjs.map +0 -1
- package/dist/chunk-LD34IXVT.mjs +0 -86
- package/dist/chunk-LD34IXVT.mjs.map +0 -1
- package/dist/chunk-LNGBARXE.mjs +0 -86
- package/dist/chunk-LNGBARXE.mjs.map +0 -1
- package/dist/chunk-LRPWSPXG.mjs +0 -628
- package/dist/chunk-LRPWSPXG.mjs.map +0 -1
- package/dist/chunk-LUGEI4YQ.mjs +0 -1
- package/dist/chunk-LUGEI4YQ.mjs.map +0 -1
- package/dist/chunk-MBJ7OLYI.mjs +0 -58
- package/dist/chunk-MBJ7OLYI.mjs.map +0 -1
- package/dist/chunk-NB2FKV2V.mjs +0 -1
- package/dist/chunk-NB2FKV2V.mjs.map +0 -1
- package/dist/chunk-O7ARI5CV.mjs +0 -31
- package/dist/chunk-O7ARI5CV.mjs.map +0 -1
- package/dist/chunk-P6ZPE4XJ.mjs +0 -86
- package/dist/chunk-P6ZPE4XJ.mjs.map +0 -1
- package/dist/chunk-QXZTCGF4.mjs +0 -163
- package/dist/chunk-QXZTCGF4.mjs.map +0 -1
- package/dist/chunk-R2DP4APC.mjs +0 -125
- package/dist/chunk-R2DP4APC.mjs.map +0 -1
- package/dist/chunk-R7BV32X4.mjs +0 -146
- package/dist/chunk-R7BV32X4.mjs.map +0 -1
- package/dist/chunk-SBRCWA4S.mjs +0 -913
- package/dist/chunk-SBRCWA4S.mjs.map +0 -1
- package/dist/chunk-SK2XMJUD.mjs +0 -42
- package/dist/chunk-SK2XMJUD.mjs.map +0 -1
- package/dist/chunk-SKC7AJIV.mjs +0 -61
- package/dist/chunk-SKC7AJIV.mjs.map +0 -1
- package/dist/chunk-SLM6CLAH.mjs +0 -195
- package/dist/chunk-SLM6CLAH.mjs.map +0 -1
- package/dist/chunk-SPCZTZCY.mjs +0 -1
- package/dist/chunk-SPCZTZCY.mjs.map +0 -1
- package/dist/chunk-SYGQHN3H.mjs +0 -27
- package/dist/chunk-SYGQHN3H.mjs.map +0 -1
- package/dist/chunk-SYMT73HM.mjs +0 -43
- package/dist/chunk-SYMT73HM.mjs.map +0 -1
- package/dist/chunk-TFZXOEY4.mjs +0 -61
- package/dist/chunk-TFZXOEY4.mjs.map +0 -1
- package/dist/chunk-TPN7WC53.mjs +0 -33
- package/dist/chunk-TPN7WC53.mjs.map +0 -1
- package/dist/chunk-UA23VX5J.mjs +0 -65
- package/dist/chunk-UA23VX5J.mjs.map +0 -1
- package/dist/chunk-V42VL2JR.mjs +0 -136
- package/dist/chunk-V42VL2JR.mjs.map +0 -1
- package/dist/chunk-VZ4NSOFQ.mjs +0 -80
- package/dist/chunk-VZ4NSOFQ.mjs.map +0 -1
- package/dist/chunk-WRALJIW5.mjs +0 -79
- package/dist/chunk-WRALJIW5.mjs.map +0 -1
- package/dist/chunk-WV2EA7SX.mjs +0 -65
- package/dist/chunk-WV2EA7SX.mjs.map +0 -1
- package/dist/chunk-Z6JV2LRY.mjs +0 -37
- package/dist/chunk-Z6JV2LRY.mjs.map +0 -1
- package/dist/chunk-ZP2IMXFY.mjs +0 -316
- package/dist/chunk-ZP2IMXFY.mjs.map +0 -1
- package/dist/chunk-ZVF5Q6IH.mjs +0 -29
- package/dist/chunk-ZVF5Q6IH.mjs.map +0 -1
- package/dist/components/CopilotListeners.d.ts +0 -3
- package/dist/components/CopilotListeners.js +0 -110
- package/dist/components/CopilotListeners.js.map +0 -1
- package/dist/components/CopilotListeners.mjs +0 -9
- package/dist/components/CopilotListeners.mjs.map +0 -1
- package/dist/components/copilot-provider/copilot-messages.d.ts +0 -24
- package/dist/components/copilot-provider/copilot-messages.js +0 -366
- package/dist/components/copilot-provider/copilot-messages.js.map +0 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +0 -16
- package/dist/components/copilot-provider/copilot-messages.mjs.map +0 -1
- package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -180
- package/dist/components/copilot-provider/copilotkit-props.js +0 -19
- package/dist/components/copilot-provider/copilotkit-props.js.map +0 -1
- package/dist/components/copilot-provider/copilotkit-props.mjs +0 -1
- package/dist/components/copilot-provider/copilotkit-props.mjs.map +0 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +0 -19
- package/dist/components/copilot-provider/copilotkit.js +0 -2348
- package/dist/components/copilot-provider/copilotkit.js.map +0 -1
- package/dist/components/copilot-provider/copilotkit.mjs +0 -33
- package/dist/components/copilot-provider/copilotkit.mjs.map +0 -1
- package/dist/components/copilot-provider/index.d.ts +0 -14
- package/dist/components/copilot-provider/index.js +0 -2348
- package/dist/components/copilot-provider/index.js.map +0 -1
- package/dist/components/copilot-provider/index.mjs +0 -32
- package/dist/components/copilot-provider/index.mjs.map +0 -1
- package/dist/components/dev-console/console-trigger.d.ts +0 -8
- package/dist/components/dev-console/console-trigger.js +0 -1387
- package/dist/components/dev-console/console-trigger.js.map +0 -1
- package/dist/components/dev-console/console-trigger.mjs +0 -249
- package/dist/components/dev-console/console-trigger.mjs.map +0 -1
- package/dist/components/dev-console/developer-console-modal.d.ts +0 -10
- package/dist/components/dev-console/developer-console-modal.js +0 -1156
- package/dist/components/dev-console/developer-console-modal.js.map +0 -1
- package/dist/components/dev-console/developer-console-modal.mjs +0 -12
- package/dist/components/dev-console/developer-console-modal.mjs.map +0 -1
- package/dist/components/dev-console/icons.d.ts +0 -9
- package/dist/components/dev-console/icons.js +0 -140
- package/dist/components/dev-console/icons.js.map +0 -1
- package/dist/components/dev-console/icons.mjs +0 -16
- package/dist/components/dev-console/icons.mjs.map +0 -1
- package/dist/components/error-boundary/error-boundary.d.ts +0 -31
- package/dist/components/error-boundary/error-boundary.js +0 -507
- package/dist/components/error-boundary/error-boundary.js.map +0 -1
- package/dist/components/error-boundary/error-boundary.mjs +0 -15
- package/dist/components/error-boundary/error-boundary.mjs.map +0 -1
- package/dist/components/error-boundary/error-utils.d.ts +0 -11
- package/dist/components/error-boundary/error-utils.js +0 -190
- package/dist/components/error-boundary/error-utils.js.map +0 -1
- package/dist/components/error-boundary/error-utils.mjs +0 -14
- package/dist/components/error-boundary/error-utils.mjs.map +0 -1
- package/dist/components/index.d.ts +0 -14
- package/dist/components/index.js +0 -2348
- package/dist/components/index.js.map +0 -1
- package/dist/components/index.mjs +0 -33
- package/dist/components/index.mjs.map +0 -1
- package/dist/components/toast/exclamation-mark-icon.d.ts +0 -9
- package/dist/components/toast/exclamation-mark-icon.js +0 -55
- package/dist/components/toast/exclamation-mark-icon.js.map +0 -1
- package/dist/components/toast/exclamation-mark-icon.mjs +0 -8
- package/dist/components/toast/exclamation-mark-icon.mjs.map +0 -1
- package/dist/components/toast/toast-provider.d.ts +0 -27
- package/dist/components/toast/toast-provider.js +0 -353
- package/dist/components/toast/toast-provider.js.map +0 -1
- package/dist/components/toast/toast-provider.mjs +0 -10
- package/dist/components/toast/toast-provider.mjs.map +0 -1
- package/dist/components/usage-banner.d.ts +0 -29
- package/dist/components/usage-banner.js +0 -251
- package/dist/components/usage-banner.js.map +0 -1
- package/dist/components/usage-banner.mjs +0 -12
- package/dist/components/usage-banner.mjs.map +0 -1
- package/dist/context/coagent-state-renders-context.d.ts +0 -25
- package/dist/context/coagent-state-renders-context.js +0 -96
- package/dist/context/coagent-state-renders-context.js.map +0 -1
- package/dist/context/coagent-state-renders-context.mjs +0 -12
- package/dist/context/coagent-state-renders-context.mjs.map +0 -1
- package/dist/context/copilot-context.d.ts +0 -10
- package/dist/context/copilot-context.js +0 -167
- package/dist/context/copilot-context.js.map +0 -1
- package/dist/context/copilot-context.mjs +0 -10
- package/dist/context/copilot-context.mjs.map +0 -1
- package/dist/context/copilot-messages-context.d.ts +0 -18
- package/dist/context/copilot-messages-context.js +0 -60
- package/dist/context/copilot-messages-context.js.map +0 -1
- package/dist/context/copilot-messages-context.mjs +0 -10
- package/dist/context/copilot-messages-context.mjs.map +0 -1
- package/dist/context/index.d.ts +0 -15
- package/dist/context/index.js +0 -301
- package/dist/context/index.js.map +0 -1
- package/dist/context/index.mjs +0 -33
- package/dist/context/index.mjs.map +0 -1
- package/dist/context/threads-context.d.ts +0 -16
- package/dist/context/threads-context.js +0 -64
- package/dist/context/threads-context.js.map +0 -1
- package/dist/context/threads-context.mjs +0 -12
- package/dist/context/threads-context.mjs.map +0 -1
- package/dist/copilot-context-ec77e921.d.ts +0 -209
- package/dist/hooks/index.d.ts +0 -33
- package/dist/hooks/index.js +0 -2190
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/index.mjs +0 -93
- package/dist/hooks/index.mjs.map +0 -1
- package/dist/hooks/use-agent-nodename.d.ts +0 -3
- package/dist/hooks/use-agent-nodename.js +0 -56
- package/dist/hooks/use-agent-nodename.js.map +0 -1
- package/dist/hooks/use-agent-nodename.mjs +0 -8
- package/dist/hooks/use-agent-nodename.mjs.map +0 -1
- package/dist/hooks/use-coagent-state-render-bridge.d.ts +0 -100
- package/dist/hooks/use-coagent-state-render-bridge.helpers.d.ts +0 -92
- package/dist/hooks/use-coagent-state-render-bridge.helpers.js +0 -237
- package/dist/hooks/use-coagent-state-render-bridge.helpers.js.map +0 -1
- package/dist/hooks/use-coagent-state-render-bridge.helpers.mjs +0 -24
- package/dist/hooks/use-coagent-state-render-bridge.helpers.mjs.map +0 -1
- package/dist/hooks/use-coagent-state-render-bridge.js +0 -498
- package/dist/hooks/use-coagent-state-render-bridge.js.map +0 -1
- package/dist/hooks/use-coagent-state-render-bridge.mjs +0 -17
- package/dist/hooks/use-coagent-state-render-bridge.mjs.map +0 -1
- package/dist/hooks/use-coagent-state-render-registry.d.ts +0 -25
- package/dist/hooks/use-coagent-state-render-registry.js +0 -369
- package/dist/hooks/use-coagent-state-render-registry.js.map +0 -1
- package/dist/hooks/use-coagent-state-render-registry.mjs +0 -9
- package/dist/hooks/use-coagent-state-render-registry.mjs.map +0 -1
- package/dist/hooks/use-coagent-state-render.d.ts +0 -55
- package/dist/hooks/use-coagent-state-render.js +0 -268
- package/dist/hooks/use-coagent-state-render.js.map +0 -1
- package/dist/hooks/use-coagent-state-render.mjs +0 -11
- package/dist/hooks/use-coagent-state-render.mjs.map +0 -1
- package/dist/hooks/use-coagent.d.ts +0 -192
- package/dist/hooks/use-coagent.js +0 -235
- package/dist/hooks/use-coagent.js.map +0 -1
- package/dist/hooks/use-coagent.mjs +0 -9
- package/dist/hooks/use-coagent.mjs.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.d.ts +0 -36
- package/dist/hooks/use-configure-chat-suggestions.js +0 -79
- package/dist/hooks/use-configure-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-configure-chat-suggestions.mjs +0 -47
- package/dist/hooks/use-configure-chat-suggestions.mjs.map +0 -1
- package/dist/hooks/use-copilot-action.d.ts +0 -103
- package/dist/hooks/use-copilot-action.js +0 -302
- package/dist/hooks/use-copilot-action.js.map +0 -1
- package/dist/hooks/use-copilot-action.mjs +0 -11
- package/dist/hooks/use-copilot-action.mjs.map +0 -1
- package/dist/hooks/use-copilot-additional-instructions.d.ts +0 -26
- package/dist/hooks/use-copilot-additional-instructions.js +0 -196
- package/dist/hooks/use-copilot-additional-instructions.js.map +0 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +0 -9
- package/dist/hooks/use-copilot-additional-instructions.mjs.map +0 -1
- package/dist/hooks/use-copilot-authenticated-action.d.ts +0 -18
- package/dist/hooks/use-copilot-authenticated-action.js +0 -477
- package/dist/hooks/use-copilot-authenticated-action.js.map +0 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +0 -13
- package/dist/hooks/use-copilot-authenticated-action.mjs.map +0 -1
- package/dist/hooks/use-copilot-chat-headless_c.d.ts +0 -25
- package/dist/hooks/use-copilot-chat-headless_c.js +0 -1410
- package/dist/hooks/use-copilot-chat-headless_c.js.map +0 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +0 -26
- package/dist/hooks/use-copilot-chat-headless_c.mjs.map +0 -1
- package/dist/hooks/use-copilot-chat-suggestions.d.ts +0 -35
- package/dist/hooks/use-copilot-chat-suggestions.js +0 -60
- package/dist/hooks/use-copilot-chat-suggestions.js.map +0 -1
- package/dist/hooks/use-copilot-chat-suggestions.mjs +0 -8
- package/dist/hooks/use-copilot-chat-suggestions.mjs.map +0 -1
- package/dist/hooks/use-copilot-chat.d.ts +0 -92
- package/dist/hooks/use-copilot-chat.js +0 -1344
- package/dist/hooks/use-copilot-chat.js.map +0 -1
- package/dist/hooks/use-copilot-chat.mjs +0 -23
- package/dist/hooks/use-copilot-chat.mjs.map +0 -1
- package/dist/hooks/use-copilot-chat_internal.d.ts +0 -244
- package/dist/hooks/use-copilot-chat_internal.js +0 -1342
- package/dist/hooks/use-copilot-chat_internal.js.map +0 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +0 -24
- package/dist/hooks/use-copilot-chat_internal.mjs.map +0 -1
- package/dist/hooks/use-copilot-readable.d.ts +0 -37
- package/dist/hooks/use-copilot-readable.js +0 -61
- package/dist/hooks/use-copilot-readable.js.map +0 -1
- package/dist/hooks/use-copilot-readable.mjs +0 -8
- package/dist/hooks/use-copilot-readable.mjs.map +0 -1
- package/dist/hooks/use-copilot-runtime-client.d.ts +0 -10
- package/dist/hooks/use-copilot-runtime-client.js +0 -206
- package/dist/hooks/use-copilot-runtime-client.js.map +0 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +0 -9
- package/dist/hooks/use-copilot-runtime-client.mjs.map +0 -1
- package/dist/hooks/use-default-tool.d.ts +0 -8
- package/dist/hooks/use-default-tool.js +0 -312
- package/dist/hooks/use-default-tool.js.map +0 -1
- package/dist/hooks/use-default-tool.mjs +0 -12
- package/dist/hooks/use-default-tool.mjs.map +0 -1
- package/dist/hooks/use-flat-category-store.d.ts +0 -9
- package/dist/hooks/use-flat-category-store.js +0 -96
- package/dist/hooks/use-flat-category-store.js.map +0 -1
- package/dist/hooks/use-flat-category-store.mjs +0 -8
- package/dist/hooks/use-flat-category-store.mjs.map +0 -1
- package/dist/hooks/use-frontend-tool.d.ts +0 -11
- package/dist/hooks/use-frontend-tool.js +0 -107
- package/dist/hooks/use-frontend-tool.js.map +0 -1
- package/dist/hooks/use-frontend-tool.mjs +0 -8
- package/dist/hooks/use-frontend-tool.mjs.map +0 -1
- package/dist/hooks/use-human-in-the-loop.d.ts +0 -13
- package/dist/hooks/use-human-in-the-loop.js +0 -122
- package/dist/hooks/use-human-in-the-loop.js.map +0 -1
- package/dist/hooks/use-human-in-the-loop.mjs +0 -8
- package/dist/hooks/use-human-in-the-loop.mjs.map +0 -1
- package/dist/hooks/use-langgraph-interrupt-render.d.ts +0 -6
- package/dist/hooks/use-langgraph-interrupt-render.js +0 -335
- package/dist/hooks/use-langgraph-interrupt-render.js.map +0 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +0 -14
- package/dist/hooks/use-langgraph-interrupt-render.mjs.map +0 -1
- package/dist/hooks/use-langgraph-interrupt.d.ts +0 -14
- package/dist/hooks/use-langgraph-interrupt.js +0 -216
- package/dist/hooks/use-langgraph-interrupt.js.map +0 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +0 -10
- package/dist/hooks/use-langgraph-interrupt.mjs.map +0 -1
- package/dist/hooks/use-lazy-tool-renderer.d.ts +0 -6
- package/dist/hooks/use-lazy-tool-renderer.js +0 -53
- package/dist/hooks/use-lazy-tool-renderer.js.map +0 -1
- package/dist/hooks/use-lazy-tool-renderer.mjs +0 -8
- package/dist/hooks/use-lazy-tool-renderer.mjs.map +0 -1
- package/dist/hooks/use-make-copilot-document-readable.d.ts +0 -12
- package/dist/hooks/use-make-copilot-document-readable.js +0 -182
- package/dist/hooks/use-make-copilot-document-readable.js.map +0 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +0 -9
- package/dist/hooks/use-make-copilot-document-readable.mjs.map +0 -1
- package/dist/hooks/use-render-tool-call.d.ts +0 -12
- package/dist/hooks/use-render-tool-call.js +0 -94
- package/dist/hooks/use-render-tool-call.js.map +0 -1
- package/dist/hooks/use-render-tool-call.mjs +0 -8
- package/dist/hooks/use-render-tool-call.mjs.map +0 -1
- package/dist/hooks/use-tree.d.ts +0 -19
- package/dist/hooks/use-tree.js +0 -178
- package/dist/hooks/use-tree.js.map +0 -1
- package/dist/hooks/use-tree.mjs +0 -8
- package/dist/hooks/use-tree.mjs.map +0 -1
- package/dist/index.d.ts +0 -43
- package/dist/index.js +0 -4064
- package/dist/index.js.map +0 -1
- package/dist/lib/copilot-task.d.ts +0 -97
- package/dist/lib/copilot-task.js +0 -201
- package/dist/lib/copilot-task.js.map +0 -1
- package/dist/lib/copilot-task.mjs +0 -33
- package/dist/lib/copilot-task.mjs.map +0 -1
- package/dist/lib/index.d.ts +0 -11
- package/dist/lib/index.js +0 -203
- package/dist/lib/index.js.map +0 -1
- package/dist/lib/index.mjs +0 -34
- package/dist/lib/index.mjs.map +0 -1
- package/dist/lib/status-checker.d.ts +0 -17
- package/dist/lib/status-checker.js +0 -102
- package/dist/lib/status-checker.js.map +0 -1
- package/dist/lib/status-checker.mjs +0 -8
- package/dist/lib/status-checker.mjs.map +0 -1
- package/dist/setupTests.d.ts +0 -2
- package/dist/setupTests.js +0 -31
- package/dist/setupTests.js.map +0 -1
- package/dist/setupTests.mjs +0 -29
- package/dist/setupTests.mjs.map +0 -1
- package/dist/test-helpers/copilot-context.d.ts +0 -14
- package/dist/test-helpers/copilot-context.js +0 -128
- package/dist/test-helpers/copilot-context.js.map +0 -1
- package/dist/test-helpers/copilot-context.mjs +0 -74
- package/dist/test-helpers/copilot-context.mjs.map +0 -1
- package/dist/types/chat-suggestion-configuration.d.ts +0 -22
- package/dist/types/chat-suggestion-configuration.js +0 -19
- package/dist/types/chat-suggestion-configuration.js.map +0 -1
- package/dist/types/chat-suggestion-configuration.mjs +0 -1
- package/dist/types/chat-suggestion-configuration.mjs.map +0 -1
- package/dist/types/coagent-action.d.ts +0 -29
- package/dist/types/coagent-action.js +0 -19
- package/dist/types/coagent-action.js.map +0 -1
- package/dist/types/coagent-action.mjs +0 -1
- package/dist/types/coagent-action.mjs.map +0 -1
- package/dist/types/coagent-state.d.ts +0 -15
- package/dist/types/coagent-state.js +0 -19
- package/dist/types/coagent-state.js.map +0 -1
- package/dist/types/coagent-state.mjs +0 -1
- package/dist/types/coagent-state.mjs.map +0 -1
- package/dist/types/crew.d.ts +0 -79
- package/dist/types/crew.js +0 -19
- package/dist/types/crew.js.map +0 -1
- package/dist/types/crew.mjs +0 -2
- package/dist/types/crew.mjs.map +0 -1
- package/dist/types/document-pointer.d.ts +0 -9
- package/dist/types/document-pointer.js +0 -19
- package/dist/types/document-pointer.js.map +0 -1
- package/dist/types/document-pointer.mjs +0 -1
- package/dist/types/document-pointer.mjs.map +0 -1
- package/dist/types/frontend-action.d.ts +0 -127
- package/dist/types/frontend-action.js +0 -55
- package/dist/types/frontend-action.js.map +0 -1
- package/dist/types/frontend-action.mjs +0 -8
- package/dist/types/frontend-action.mjs.map +0 -1
- package/dist/types/index.d.ts +0 -12
- package/dist/types/index.js +0 -19
- package/dist/types/index.js.map +0 -1
- package/dist/types/index.mjs +0 -4
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/interrupt-action.d.ts +0 -10
- package/dist/types/interrupt-action.js +0 -19
- package/dist/types/interrupt-action.js.map +0 -1
- package/dist/types/interrupt-action.mjs +0 -2
- package/dist/types/interrupt-action.mjs.map +0 -1
- package/dist/types/system-message.d.ts +0 -3
- package/dist/types/system-message.js +0 -19
- package/dist/types/system-message.js.map +0 -1
- package/dist/types/system-message.mjs +0 -1
- package/dist/types/system-message.mjs.map +0 -1
- package/dist/utils/dev-console.d.ts +0 -3
- package/dist/utils/dev-console.js +0 -41
- package/dist/utils/dev-console.js.map +0 -1
- package/dist/utils/dev-console.mjs +0 -8
- package/dist/utils/dev-console.mjs.map +0 -1
- package/dist/utils/index.d.ts +0 -2
- package/dist/utils/index.js +0 -52
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/index.mjs +0 -13
- package/dist/utils/index.mjs.map +0 -1
- package/dist/utils/suggestions-constants.d.ts +0 -9
- package/dist/utils/suggestions-constants.js +0 -35
- package/dist/utils/suggestions-constants.js.map +0 -1
- package/dist/utils/suggestions-constants.mjs +0 -8
- package/dist/utils/suggestions-constants.mjs.map +0 -1
- package/dist/utils/utils.d.ts +0 -2
- package/dist/utils/utils.js +0 -19
- package/dist/utils/utils.js.map +0 -1
- package/dist/utils/utils.mjs +0 -1
- package/dist/utils/utils.mjs.map +0 -1
- package/dist/v2/index.d.ts +0 -2
- package/dist/v2/index.js +0 -27
- package/dist/v2/index.js.map +0 -1
- package/dist/v2/index.mjs.map +0 -1
- package/dist/v2/index.umd.js.map +0 -1
- package/jest.config.js +0 -26
- package/rollup.config.mjs +0 -92
- package/src/__mocks__/analytics-node.js +0 -9
- package/tsup.config.ts +0 -16
package/dist/hooks/index.js
DELETED
|
@@ -1,2190 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __objRest = (source, exclude) => {
|
|
26
|
-
var target = {};
|
|
27
|
-
for (var prop in source)
|
|
28
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
-
target[prop] = source[prop];
|
|
30
|
-
if (source != null && __getOwnPropSymbols)
|
|
31
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
-
target[prop] = source[prop];
|
|
34
|
-
}
|
|
35
|
-
return target;
|
|
36
|
-
};
|
|
37
|
-
var __export = (target, all) => {
|
|
38
|
-
for (var name in all)
|
|
39
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
-
};
|
|
41
|
-
var __copyProps = (to, from, except, desc) => {
|
|
42
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
-
for (let key of __getOwnPropNames(from))
|
|
44
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
-
}
|
|
47
|
-
return to;
|
|
48
|
-
};
|
|
49
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
-
mod
|
|
56
|
-
));
|
|
57
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
-
var __async = (__this, __arguments, generator) => {
|
|
59
|
-
return new Promise((resolve, reject) => {
|
|
60
|
-
var fulfilled = (value) => {
|
|
61
|
-
try {
|
|
62
|
-
step(generator.next(value));
|
|
63
|
-
} catch (e) {
|
|
64
|
-
reject(e);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
var rejected = (value) => {
|
|
68
|
-
try {
|
|
69
|
-
step(generator.throw(value));
|
|
70
|
-
} catch (e) {
|
|
71
|
-
reject(e);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
75
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
// src/hooks/index.ts
|
|
80
|
-
var hooks_exports = {};
|
|
81
|
-
__export(hooks_exports, {
|
|
82
|
-
useCoAgent: () => useCoAgent,
|
|
83
|
-
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
84
|
-
useCopilotAction: () => useCopilotAction,
|
|
85
|
-
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
86
|
-
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
87
|
-
useCopilotChat: () => useCopilotChat,
|
|
88
|
-
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
|
|
89
|
-
useCopilotChatInternal: () => useCopilotChatInternal,
|
|
90
|
-
useCopilotChatSuggestions: () => useCopilotChatSuggestions,
|
|
91
|
-
useCopilotReadable: () => useCopilotReadable,
|
|
92
|
-
useCopilotRuntimeClient: () => useCopilotRuntimeClient,
|
|
93
|
-
useDefaultTool: () => useDefaultTool,
|
|
94
|
-
useFrontendTool: () => useFrontendTool,
|
|
95
|
-
useHumanInTheLoop: () => useHumanInTheLoop,
|
|
96
|
-
useLangGraphInterrupt: () => useLangGraphInterrupt,
|
|
97
|
-
useLangGraphInterruptRender: () => useLangGraphInterruptRender,
|
|
98
|
-
useLazyToolRenderer: () => useLazyToolRenderer,
|
|
99
|
-
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
100
|
-
useRenderToolCall: () => useRenderToolCall2
|
|
101
|
-
});
|
|
102
|
-
module.exports = __toCommonJS(hooks_exports);
|
|
103
|
-
|
|
104
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
105
|
-
var import_react14 = require("react");
|
|
106
|
-
|
|
107
|
-
// src/context/copilot-context.tsx
|
|
108
|
-
var import_react = __toESM(require("react"));
|
|
109
|
-
var emptyCopilotContext = {
|
|
110
|
-
actions: {},
|
|
111
|
-
setAction: () => {
|
|
112
|
-
},
|
|
113
|
-
removeAction: () => {
|
|
114
|
-
},
|
|
115
|
-
setRegisteredActions: () => "",
|
|
116
|
-
removeRegisteredAction: () => {
|
|
117
|
-
},
|
|
118
|
-
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
119
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
120
|
-
addContext: () => "",
|
|
121
|
-
removeContext: () => {
|
|
122
|
-
},
|
|
123
|
-
getAllContext: () => [],
|
|
124
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
125
|
-
})),
|
|
126
|
-
isLoading: false,
|
|
127
|
-
setIsLoading: () => returnAndThrowInDebug(false),
|
|
128
|
-
chatInstructions: "",
|
|
129
|
-
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
130
|
-
additionalInstructions: [],
|
|
131
|
-
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
132
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
133
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
134
|
-
removeDocumentContext: () => {
|
|
135
|
-
},
|
|
136
|
-
copilotApiConfig: new class {
|
|
137
|
-
get chatApiEndpoint() {
|
|
138
|
-
throw new Error(
|
|
139
|
-
"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!"
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
get headers() {
|
|
143
|
-
return {};
|
|
144
|
-
}
|
|
145
|
-
get body() {
|
|
146
|
-
return {};
|
|
147
|
-
}
|
|
148
|
-
}(),
|
|
149
|
-
chatSuggestionConfiguration: {},
|
|
150
|
-
addChatSuggestionConfiguration: () => {
|
|
151
|
-
},
|
|
152
|
-
removeChatSuggestionConfiguration: () => {
|
|
153
|
-
},
|
|
154
|
-
showDevConsole: false,
|
|
155
|
-
coagentStates: {},
|
|
156
|
-
setCoagentStates: () => {
|
|
157
|
-
},
|
|
158
|
-
coagentStatesRef: { current: {} },
|
|
159
|
-
setCoagentStatesWithRef: () => {
|
|
160
|
-
},
|
|
161
|
-
agentSession: null,
|
|
162
|
-
setAgentSession: () => {
|
|
163
|
-
},
|
|
164
|
-
forwardedParameters: {},
|
|
165
|
-
agentLock: null,
|
|
166
|
-
threadId: "",
|
|
167
|
-
setThreadId: () => {
|
|
168
|
-
},
|
|
169
|
-
runId: null,
|
|
170
|
-
setRunId: () => {
|
|
171
|
-
},
|
|
172
|
-
chatAbortControllerRef: { current: null },
|
|
173
|
-
availableAgents: [],
|
|
174
|
-
extensions: {},
|
|
175
|
-
setExtensions: () => {
|
|
176
|
-
},
|
|
177
|
-
interruptActions: {},
|
|
178
|
-
setInterruptAction: () => {
|
|
179
|
-
},
|
|
180
|
-
removeInterruptAction: () => {
|
|
181
|
-
},
|
|
182
|
-
interruptEventQueue: {},
|
|
183
|
-
addInterruptEvent: () => {
|
|
184
|
-
},
|
|
185
|
-
resolveInterruptEvent: () => {
|
|
186
|
-
},
|
|
187
|
-
onError: () => {
|
|
188
|
-
},
|
|
189
|
-
bannerError: null,
|
|
190
|
-
setBannerError: () => {
|
|
191
|
-
},
|
|
192
|
-
internalErrorHandlers: {},
|
|
193
|
-
setInternalErrorHandler: () => {
|
|
194
|
-
},
|
|
195
|
-
removeInternalErrorHandler: () => {
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
199
|
-
function useCopilotContext() {
|
|
200
|
-
const context = import_react.default.useContext(CopilotContext);
|
|
201
|
-
if (context === emptyCopilotContext) {
|
|
202
|
-
throw new Error(
|
|
203
|
-
"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!"
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
return context;
|
|
207
|
-
}
|
|
208
|
-
function returnAndThrowInDebug(_value) {
|
|
209
|
-
throw new Error(
|
|
210
|
-
"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!"
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// src/components/error-boundary/error-utils.tsx
|
|
215
|
-
var import_react3 = require("react");
|
|
216
|
-
|
|
217
|
-
// src/components/toast/toast-provider.tsx
|
|
218
|
-
var import_react2 = require("react");
|
|
219
|
-
var import_shared = require("@copilotkit/shared");
|
|
220
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
221
|
-
var ToastContext = (0, import_react2.createContext)(void 0);
|
|
222
|
-
function useToast() {
|
|
223
|
-
const context = (0, import_react2.useContext)(ToastContext);
|
|
224
|
-
if (!context) {
|
|
225
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
226
|
-
}
|
|
227
|
-
return context;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
// src/components/toast/exclamation-mark-icon.tsx
|
|
231
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
232
|
-
var ExclamationMarkIcon = ({
|
|
233
|
-
className,
|
|
234
|
-
style
|
|
235
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
236
|
-
"svg",
|
|
237
|
-
{
|
|
238
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
239
|
-
width: "24",
|
|
240
|
-
height: "24",
|
|
241
|
-
viewBox: "0 0 24 24",
|
|
242
|
-
fill: "none",
|
|
243
|
-
stroke: "currentColor",
|
|
244
|
-
strokeWidth: "2",
|
|
245
|
-
strokeLinecap: "round",
|
|
246
|
-
strokeLinejoin: "round",
|
|
247
|
-
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
248
|
-
style,
|
|
249
|
-
children: [
|
|
250
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
251
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
252
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
253
|
-
]
|
|
254
|
-
}
|
|
255
|
-
);
|
|
256
|
-
|
|
257
|
-
// src/components/error-boundary/error-utils.tsx
|
|
258
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
259
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
260
|
-
function ErrorToast({ errors }) {
|
|
261
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
262
|
-
var _a, _b, _c;
|
|
263
|
-
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
264
|
-
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
265
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
266
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
267
|
-
"div",
|
|
268
|
-
{
|
|
269
|
-
style: {
|
|
270
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
271
|
-
marginBottom: 14
|
|
272
|
-
},
|
|
273
|
-
children: [
|
|
274
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
275
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
276
|
-
"div",
|
|
277
|
-
{
|
|
278
|
-
style: {
|
|
279
|
-
fontWeight: "600",
|
|
280
|
-
marginBottom: 4
|
|
281
|
-
},
|
|
282
|
-
children: [
|
|
283
|
-
"Copilot Runtime Error:",
|
|
284
|
-
" ",
|
|
285
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
286
|
-
]
|
|
287
|
-
}
|
|
288
|
-
),
|
|
289
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
290
|
-
]
|
|
291
|
-
},
|
|
292
|
-
idx
|
|
293
|
-
);
|
|
294
|
-
});
|
|
295
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
296
|
-
"div",
|
|
297
|
-
{
|
|
298
|
-
style: {
|
|
299
|
-
fontSize: "13px",
|
|
300
|
-
maxWidth: "600px"
|
|
301
|
-
},
|
|
302
|
-
children: [
|
|
303
|
-
errorsToRender,
|
|
304
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
305
|
-
]
|
|
306
|
-
}
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
|
-
function useErrorToast() {
|
|
310
|
-
const { addToast } = useToast();
|
|
311
|
-
return (0, import_react3.useCallback)(
|
|
312
|
-
(errors) => {
|
|
313
|
-
const errorId = errors.map((err) => {
|
|
314
|
-
var _a, _b;
|
|
315
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
316
|
-
const stack = err.stack || "";
|
|
317
|
-
return btoa(message + stack).slice(0, 32);
|
|
318
|
-
}).join("|");
|
|
319
|
-
addToast({
|
|
320
|
-
type: "error",
|
|
321
|
-
id: errorId,
|
|
322
|
-
// Toast libraries typically dedupe by id
|
|
323
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors })
|
|
324
|
-
});
|
|
325
|
-
},
|
|
326
|
-
[addToast]
|
|
327
|
-
);
|
|
328
|
-
}
|
|
329
|
-
function useAsyncCallback(callback, deps) {
|
|
330
|
-
const addErrorToast = useErrorToast();
|
|
331
|
-
return (0, import_react3.useCallback)((...args) => __async(this, null, function* () {
|
|
332
|
-
try {
|
|
333
|
-
return yield callback(...args);
|
|
334
|
-
} catch (error) {
|
|
335
|
-
console.error("Error in async callback:", error);
|
|
336
|
-
addErrorToast([error]);
|
|
337
|
-
throw error;
|
|
338
|
-
}
|
|
339
|
-
}), deps);
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
343
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
344
|
-
|
|
345
|
-
// src/context/coagent-state-renders-context.tsx
|
|
346
|
-
var import_react4 = require("react");
|
|
347
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
348
|
-
var CoAgentStateRendersContext = (0, import_react4.createContext)(void 0);
|
|
349
|
-
function useCoAgentStateRenders() {
|
|
350
|
-
const context = (0, import_react4.useContext)(CoAgentStateRendersContext);
|
|
351
|
-
if (!context) {
|
|
352
|
-
throw new Error(
|
|
353
|
-
"useCoAgentStateRenders must be used within CoAgentStateRendersProvider"
|
|
354
|
-
);
|
|
355
|
-
}
|
|
356
|
-
return context;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
// src/hooks/use-langgraph-interrupt-render.ts
|
|
360
|
-
var import_react7 = __toESM(require("react"));
|
|
361
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
362
|
-
var import_shared2 = require("@copilotkit/shared");
|
|
363
|
-
|
|
364
|
-
// src/hooks/use-agent-nodename.ts
|
|
365
|
-
var import_react5 = require("react");
|
|
366
|
-
var import_react6 = require("@copilotkitnext/react");
|
|
367
|
-
function useAgentNodeName(agentName) {
|
|
368
|
-
const { agent } = (0, import_react6.useAgent)({ agentId: agentName });
|
|
369
|
-
const nodeNameRef = (0, import_react5.useRef)("start");
|
|
370
|
-
(0, import_react5.useEffect)(() => {
|
|
371
|
-
if (!agent)
|
|
372
|
-
return;
|
|
373
|
-
const subscriber = {
|
|
374
|
-
onStepStartedEvent: ({ event }) => {
|
|
375
|
-
nodeNameRef.current = event.stepName;
|
|
376
|
-
},
|
|
377
|
-
onRunStartedEvent: () => {
|
|
378
|
-
nodeNameRef.current = "start";
|
|
379
|
-
},
|
|
380
|
-
onRunFinishedEvent: () => {
|
|
381
|
-
nodeNameRef.current = "end";
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
const subscription = agent.subscribe(subscriber);
|
|
385
|
-
return () => {
|
|
386
|
-
subscription.unsubscribe();
|
|
387
|
-
};
|
|
388
|
-
}, [agent]);
|
|
389
|
-
return nodeNameRef.current;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
// src/hooks/use-langgraph-interrupt-render.ts
|
|
393
|
-
var import_react8 = require("@copilotkitnext/react");
|
|
394
|
-
var InterruptRenderer = ({
|
|
395
|
-
event,
|
|
396
|
-
result,
|
|
397
|
-
render,
|
|
398
|
-
resolve
|
|
399
|
-
}) => {
|
|
400
|
-
return render({ event, result, resolve });
|
|
401
|
-
};
|
|
402
|
-
function useLangGraphInterruptRender(agent) {
|
|
403
|
-
var _a;
|
|
404
|
-
const {
|
|
405
|
-
interruptActions,
|
|
406
|
-
agentSession,
|
|
407
|
-
threadId,
|
|
408
|
-
interruptEventQueue,
|
|
409
|
-
addInterruptEvent,
|
|
410
|
-
resolveInterruptEvent
|
|
411
|
-
} = useCopilotContext();
|
|
412
|
-
const existingConfig = (0, import_react8.useCopilotChatConfiguration)();
|
|
413
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
414
|
-
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
415
|
-
(0, import_react7.useEffect)(() => {
|
|
416
|
-
if (!agent)
|
|
417
|
-
return;
|
|
418
|
-
let localInterrupt = null;
|
|
419
|
-
const subscriber = {
|
|
420
|
-
onCustomEvent: ({ event }) => {
|
|
421
|
-
if (event.name === "on_interrupt") {
|
|
422
|
-
const eventData = {
|
|
423
|
-
name: import_runtime_client_gql.MetaEventName.LangGraphInterruptEvent,
|
|
424
|
-
type: event.type,
|
|
425
|
-
value: (0, import_shared2.parseJson)(event.value, event.value)
|
|
426
|
-
};
|
|
427
|
-
const eventId = (0, import_shared2.dataToUUID)(eventData, "interruptEvents");
|
|
428
|
-
localInterrupt = {
|
|
429
|
-
eventId,
|
|
430
|
-
threadId,
|
|
431
|
-
event: eventData
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
},
|
|
435
|
-
onRunStartedEvent: () => {
|
|
436
|
-
localInterrupt = null;
|
|
437
|
-
},
|
|
438
|
-
onRunFinalized: () => {
|
|
439
|
-
if (localInterrupt) {
|
|
440
|
-
addInterruptEvent(localInterrupt);
|
|
441
|
-
localInterrupt = null;
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
};
|
|
445
|
-
const { unsubscribe } = agent.subscribe(subscriber);
|
|
446
|
-
return () => {
|
|
447
|
-
unsubscribe();
|
|
448
|
-
};
|
|
449
|
-
}, [agent, threadId]);
|
|
450
|
-
const handleResolve = (0, import_react7.useCallback)(
|
|
451
|
-
(eventId, response) => {
|
|
452
|
-
agent == null ? void 0 : agent.runAgent({
|
|
453
|
-
forwardedProps: {
|
|
454
|
-
command: {
|
|
455
|
-
resume: response
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
460
|
-
},
|
|
461
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
462
|
-
[agent, threadId]
|
|
463
|
-
);
|
|
464
|
-
return (0, import_react7.useMemo)(() => {
|
|
465
|
-
const eventQueue = interruptEventQueue[threadId] || [];
|
|
466
|
-
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
467
|
-
if (!currentQueuedEvent || !agentSession)
|
|
468
|
-
return null;
|
|
469
|
-
const allActions = Object.values(interruptActions);
|
|
470
|
-
const matchingAction = allActions.find((action) => {
|
|
471
|
-
if (!action.enabled)
|
|
472
|
-
return true;
|
|
473
|
-
return action.enabled({
|
|
474
|
-
eventValue: currentQueuedEvent.event.value,
|
|
475
|
-
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
476
|
-
nodeName
|
|
477
|
-
})
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
if (!matchingAction)
|
|
481
|
-
return null;
|
|
482
|
-
const { render, handler } = matchingAction;
|
|
483
|
-
const resolveInterrupt = (response) => {
|
|
484
|
-
handleResolve(currentQueuedEvent.eventId, response);
|
|
485
|
-
};
|
|
486
|
-
let result = null;
|
|
487
|
-
if (handler) {
|
|
488
|
-
result = handler({
|
|
489
|
-
event: currentQueuedEvent.event,
|
|
490
|
-
resolve: resolveInterrupt
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
if (!render)
|
|
494
|
-
return null;
|
|
495
|
-
return import_react7.default.createElement(InterruptRenderer, {
|
|
496
|
-
event: currentQueuedEvent.event,
|
|
497
|
-
result,
|
|
498
|
-
render,
|
|
499
|
-
resolve: resolveInterrupt
|
|
500
|
-
});
|
|
501
|
-
}, [
|
|
502
|
-
interruptActions,
|
|
503
|
-
interruptEventQueue,
|
|
504
|
-
threadId,
|
|
505
|
-
agentSession,
|
|
506
|
-
handleResolve
|
|
507
|
-
]);
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
511
|
-
var import_react15 = require("@copilotkitnext/react");
|
|
512
|
-
|
|
513
|
-
// src/hooks/use-lazy-tool-renderer.tsx
|
|
514
|
-
var import_react9 = require("@copilotkitnext/react");
|
|
515
|
-
var import_react10 = require("react");
|
|
516
|
-
function useLazyToolRenderer() {
|
|
517
|
-
const renderToolCall = (0, import_react9.useRenderToolCall)();
|
|
518
|
-
return (0, import_react10.useCallback)(
|
|
519
|
-
(message, messages) => {
|
|
520
|
-
var _a;
|
|
521
|
-
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
522
|
-
return null;
|
|
523
|
-
const toolCall = message.toolCalls[0];
|
|
524
|
-
if (!toolCall)
|
|
525
|
-
return null;
|
|
526
|
-
const toolMessage = messages == null ? void 0 : messages.find(
|
|
527
|
-
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
528
|
-
);
|
|
529
|
-
return () => renderToolCall({
|
|
530
|
-
toolCall,
|
|
531
|
-
toolMessage
|
|
532
|
-
});
|
|
533
|
-
},
|
|
534
|
-
[renderToolCall]
|
|
535
|
-
);
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
539
|
-
var import_client = require("@ag-ui/client");
|
|
540
|
-
|
|
541
|
-
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
542
|
-
var import_react12 = require("@copilotkitnext/react");
|
|
543
|
-
var import_react13 = require("react");
|
|
544
|
-
var import_shared4 = require("@copilotkit/shared");
|
|
545
|
-
|
|
546
|
-
// src/hooks/use-coagent-state-render-bridge.helpers.ts
|
|
547
|
-
var import_shared3 = require("@copilotkit/shared");
|
|
548
|
-
function getStateWithoutConstantKeys(state) {
|
|
549
|
-
if (!state)
|
|
550
|
-
return {};
|
|
551
|
-
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
552
|
-
return stateWithoutConstantKeys;
|
|
553
|
-
}
|
|
554
|
-
function areStatesEquals(a, b) {
|
|
555
|
-
if (a && !b || !a && b)
|
|
556
|
-
return false;
|
|
557
|
-
const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
558
|
-
const _b = b, {
|
|
559
|
-
messages: bMessages,
|
|
560
|
-
tools: bTools,
|
|
561
|
-
copilotkit: bCopilotkit
|
|
562
|
-
} = _b, bWithoutConstantKeys = __objRest(_b, [
|
|
563
|
-
"messages",
|
|
564
|
-
"tools",
|
|
565
|
-
"copilotkit"
|
|
566
|
-
]);
|
|
567
|
-
return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
|
|
568
|
-
}
|
|
569
|
-
function isPlaceholderMessageId(messageId) {
|
|
570
|
-
return !!messageId && messageId.startsWith("coagent-state-render-");
|
|
571
|
-
}
|
|
572
|
-
function isPlaceholderMessageName(messageName) {
|
|
573
|
-
return messageName === "coagent-state-render";
|
|
574
|
-
}
|
|
575
|
-
function readCachedMessageEntry(entry) {
|
|
576
|
-
if (!entry || typeof entry !== "object") {
|
|
577
|
-
return { snapshot: entry, runId: void 0 };
|
|
578
|
-
}
|
|
579
|
-
const snapshot = "snapshot" in entry ? entry.snapshot : entry;
|
|
580
|
-
const runId = "runId" in entry ? entry.runId : void 0;
|
|
581
|
-
return { snapshot, runId };
|
|
582
|
-
}
|
|
583
|
-
function getEffectiveRunId({
|
|
584
|
-
existingClaimRunId,
|
|
585
|
-
cachedMessageRunId,
|
|
586
|
-
runId
|
|
587
|
-
}) {
|
|
588
|
-
return existingClaimRunId || cachedMessageRunId || runId || "pending";
|
|
589
|
-
}
|
|
590
|
-
function resolveClaim({
|
|
591
|
-
claims,
|
|
592
|
-
context,
|
|
593
|
-
stateSnapshot
|
|
594
|
-
}) {
|
|
595
|
-
const { messageId, stateRenderId, runId, messageIndex } = context;
|
|
596
|
-
const existing = claims[messageId];
|
|
597
|
-
if (existing) {
|
|
598
|
-
const canRender = existing.stateRenderId === stateRenderId;
|
|
599
|
-
const shouldUpdateRunId = canRender && runId && (!existing.runId || existing.runId === "pending");
|
|
600
|
-
return {
|
|
601
|
-
canRender,
|
|
602
|
-
action: canRender ? "existing" /* Existing */ : "block" /* Block */,
|
|
603
|
-
updateRunId: shouldUpdateRunId ? runId : void 0
|
|
604
|
-
};
|
|
605
|
-
}
|
|
606
|
-
const normalizedRunId = runId != null ? runId : "pending";
|
|
607
|
-
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(
|
|
608
|
-
([, claim]) => {
|
|
609
|
-
var _a;
|
|
610
|
-
return claim.stateRenderId === stateRenderId && ((_a = claim.runId) != null ? _a : "pending") === normalizedRunId && (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(claim.stateSnapshot)) === (0, import_shared3.dataToUUID)(getStateWithoutConstantKeys(stateSnapshot));
|
|
611
|
-
}
|
|
612
|
-
);
|
|
613
|
-
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry == null ? void 0 : renderClaimedByOtherMessageEntry[1];
|
|
614
|
-
const claimedMessageId = renderClaimedByOtherMessageEntry == null ? void 0 : renderClaimedByOtherMessageEntry[0];
|
|
615
|
-
if (renderClaimedByOtherMessage) {
|
|
616
|
-
if (messageIndex !== void 0 && renderClaimedByOtherMessage.messageIndex !== void 0 && messageIndex > renderClaimedByOtherMessage.messageIndex) {
|
|
617
|
-
return {
|
|
618
|
-
canRender: true,
|
|
619
|
-
action: "override" /* Override */,
|
|
620
|
-
nextClaim: { stateRenderId, runId, messageIndex },
|
|
621
|
-
lockOthers: runId === renderClaimedByOtherMessage.runId || isPlaceholderMessageId(claimedMessageId)
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
if (runId && renderClaimedByOtherMessage.runId && runId !== renderClaimedByOtherMessage.runId) {
|
|
625
|
-
return {
|
|
626
|
-
canRender: true,
|
|
627
|
-
action: "override" /* Override */,
|
|
628
|
-
nextClaim: { stateRenderId, runId, messageIndex },
|
|
629
|
-
lockOthers: isPlaceholderMessageId(claimedMessageId)
|
|
630
|
-
};
|
|
631
|
-
}
|
|
632
|
-
if (isPlaceholderMessageId(claimedMessageId)) {
|
|
633
|
-
return {
|
|
634
|
-
canRender: true,
|
|
635
|
-
action: "override" /* Override */,
|
|
636
|
-
nextClaim: { stateRenderId, runId, messageIndex },
|
|
637
|
-
lockOthers: true
|
|
638
|
-
};
|
|
639
|
-
}
|
|
640
|
-
if (stateSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, stateSnapshot)) {
|
|
641
|
-
return {
|
|
642
|
-
canRender: true,
|
|
643
|
-
action: "override" /* Override */,
|
|
644
|
-
nextClaim: { stateRenderId, runId }
|
|
645
|
-
};
|
|
646
|
-
}
|
|
647
|
-
return { canRender: false, action: "block" /* Block */ };
|
|
648
|
-
}
|
|
649
|
-
if (!runId) {
|
|
650
|
-
return { canRender: false, action: "block" /* Block */ };
|
|
651
|
-
}
|
|
652
|
-
return {
|
|
653
|
-
canRender: true,
|
|
654
|
-
action: "create" /* Create */,
|
|
655
|
-
nextClaim: { stateRenderId, runId, messageIndex }
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
function selectSnapshot({
|
|
659
|
-
messageId,
|
|
660
|
-
messageName,
|
|
661
|
-
allowLiveState,
|
|
662
|
-
skipLatestCache,
|
|
663
|
-
stateRenderId,
|
|
664
|
-
effectiveRunId,
|
|
665
|
-
stateSnapshotProp,
|
|
666
|
-
agentState,
|
|
667
|
-
agentMessages,
|
|
668
|
-
existingClaim,
|
|
669
|
-
caches
|
|
670
|
-
}) {
|
|
671
|
-
var _a, _b, _c, _d, _e, _f;
|
|
672
|
-
const lastAssistantId = agentMessages ? (_a = [...agentMessages].reverse().find((msg) => msg.role === "assistant")) == null ? void 0 : _a.id : void 0;
|
|
673
|
-
const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
|
|
674
|
-
const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
|
|
675
|
-
const messageRole = messageIndex >= 0 && agentMessages ? (_b = agentMessages[messageIndex]) == null ? void 0 : _b.role : void 0;
|
|
676
|
-
let previousUserMessageId;
|
|
677
|
-
if (messageIndex > 0 && agentMessages) {
|
|
678
|
-
for (let i = messageIndex - 1; i >= 0; i -= 1) {
|
|
679
|
-
if (((_c = agentMessages[i]) == null ? void 0 : _c.role) === "user") {
|
|
680
|
-
previousUserMessageId = (_d = agentMessages[i]) == null ? void 0 : _d.id;
|
|
681
|
-
break;
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
const liveStateIsStale = stateSnapshotProp === void 0 && latestSnapshot !== void 0 && agentState !== void 0 && areStatesEquals(latestSnapshot, agentState);
|
|
686
|
-
const shouldUseLiveState = (Boolean(allowLiveState) || !lastAssistantId || messageId === lastAssistantId) && !liveStateIsStale;
|
|
687
|
-
const snapshot = stateSnapshotProp ? (0, import_shared3.parseJson)(stateSnapshotProp, stateSnapshotProp) : shouldUseLiveState ? agentState : void 0;
|
|
688
|
-
const hasSnapshotKeys = !!(snapshot && Object.keys(snapshot).length > 0);
|
|
689
|
-
const allowEmptySnapshot = snapshot !== void 0 && !hasSnapshotKeys && (stateSnapshotProp !== void 0 || shouldUseLiveState);
|
|
690
|
-
const messageCacheEntry = caches.byMessageId[messageId];
|
|
691
|
-
const cachedMessageSnapshot = readCachedMessageEntry(messageCacheEntry).snapshot;
|
|
692
|
-
const cacheKey = stateRenderId !== void 0 ? `${stateRenderId}::${effectiveRunId}` : void 0;
|
|
693
|
-
let cachedSnapshot = cachedMessageSnapshot != null ? cachedMessageSnapshot : caches.byMessageId[messageId];
|
|
694
|
-
if (cachedSnapshot === void 0 && cacheKey && caches.byStateRenderAndRun[cacheKey] !== void 0) {
|
|
695
|
-
cachedSnapshot = caches.byStateRenderAndRun[cacheKey];
|
|
696
|
-
}
|
|
697
|
-
if (cachedSnapshot === void 0 && stateRenderId && previousUserMessageId && caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`] !== void 0) {
|
|
698
|
-
cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`];
|
|
699
|
-
}
|
|
700
|
-
if (cachedSnapshot === void 0 && !skipLatestCache && stateRenderId && messageRole !== "assistant" && (stateSnapshotProp !== void 0 || agentState && Object.keys(agentState).length > 0)) {
|
|
701
|
-
cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::latest`];
|
|
702
|
-
}
|
|
703
|
-
const snapshotForClaim = (existingClaim == null ? void 0 : existingClaim.locked) ? (_e = existingClaim.stateSnapshot) != null ? _e : cachedSnapshot : hasSnapshotKeys ? snapshot : (_f = existingClaim == null ? void 0 : existingClaim.stateSnapshot) != null ? _f : cachedSnapshot;
|
|
704
|
-
return {
|
|
705
|
-
snapshot,
|
|
706
|
-
hasSnapshotKeys,
|
|
707
|
-
cachedSnapshot,
|
|
708
|
-
allowEmptySnapshot,
|
|
709
|
-
snapshotForClaim
|
|
710
|
-
};
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
// src/hooks/use-coagent-state-render-registry.ts
|
|
714
|
-
var import_react11 = require("react");
|
|
715
|
-
var LAST_SNAPSHOTS_BY_RENDER_AND_RUN = "__lastSnapshotsByStateRenderIdAndRun";
|
|
716
|
-
var LAST_SNAPSHOTS_BY_MESSAGE = "__lastSnapshotsByMessageId";
|
|
717
|
-
function getClaimsStore(claimsRef) {
|
|
718
|
-
return claimsRef.current;
|
|
719
|
-
}
|
|
720
|
-
function getSnapshotCaches(claimsRef) {
|
|
721
|
-
var _a, _b;
|
|
722
|
-
const store = getClaimsStore(claimsRef);
|
|
723
|
-
return {
|
|
724
|
-
byStateRenderAndRun: (_a = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _a : {},
|
|
725
|
-
byMessageId: (_b = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _b : {}
|
|
726
|
-
};
|
|
727
|
-
}
|
|
728
|
-
function useStateRenderRegistry({
|
|
729
|
-
agentId,
|
|
730
|
-
stateRenderId,
|
|
731
|
-
message,
|
|
732
|
-
messageIndex,
|
|
733
|
-
stateSnapshot,
|
|
734
|
-
agentState,
|
|
735
|
-
agentMessages,
|
|
736
|
-
claimsRef
|
|
737
|
-
}) {
|
|
738
|
-
var _a, _b, _c, _d, _e, _f;
|
|
739
|
-
const store = getClaimsStore(claimsRef);
|
|
740
|
-
const runId = message.runId;
|
|
741
|
-
const cachedMessageEntry = (_a = store[LAST_SNAPSHOTS_BY_MESSAGE]) == null ? void 0 : _a[message.id];
|
|
742
|
-
const { runId: cachedMessageRunId } = readCachedMessageEntry(cachedMessageEntry);
|
|
743
|
-
const existingClaimRunId = (_b = claimsRef.current[message.id]) == null ? void 0 : _b.runId;
|
|
744
|
-
const effectiveRunId = getEffectiveRunId({
|
|
745
|
-
existingClaimRunId,
|
|
746
|
-
cachedMessageRunId,
|
|
747
|
-
runId
|
|
748
|
-
});
|
|
749
|
-
(0, import_react11.useEffect)(() => {
|
|
750
|
-
return () => {
|
|
751
|
-
var _a2, _b2, _c2, _d2;
|
|
752
|
-
const existingClaim2 = claimsRef.current[message.id];
|
|
753
|
-
if ((existingClaim2 == null ? void 0 : existingClaim2.stateSnapshot) && Object.keys(existingClaim2.stateSnapshot).length > 0) {
|
|
754
|
-
const snapshotCache = __spreadValues({}, (_a2 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _a2 : {});
|
|
755
|
-
const cacheKey = `${existingClaim2.stateRenderId}::${(_b2 = existingClaim2.runId) != null ? _b2 : "pending"}`;
|
|
756
|
-
snapshotCache[cacheKey] = existingClaim2.stateSnapshot;
|
|
757
|
-
snapshotCache[`${existingClaim2.stateRenderId}::latest`] = existingClaim2.stateSnapshot;
|
|
758
|
-
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
759
|
-
const messageCache = __spreadValues({}, (_c2 = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _c2 : {});
|
|
760
|
-
messageCache[message.id] = {
|
|
761
|
-
snapshot: existingClaim2.stateSnapshot,
|
|
762
|
-
runId: (_d2 = existingClaim2.runId) != null ? _d2 : effectiveRunId
|
|
763
|
-
};
|
|
764
|
-
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
765
|
-
}
|
|
766
|
-
delete claimsRef.current[message.id];
|
|
767
|
-
};
|
|
768
|
-
}, [claimsRef, effectiveRunId, message.id]);
|
|
769
|
-
if (!stateRenderId) {
|
|
770
|
-
return { canRender: false };
|
|
771
|
-
}
|
|
772
|
-
const caches = getSnapshotCaches(claimsRef);
|
|
773
|
-
const existingClaim = claimsRef.current[message.id];
|
|
774
|
-
const { snapshot, hasSnapshotKeys, allowEmptySnapshot, snapshotForClaim } = selectSnapshot({
|
|
775
|
-
messageId: message.id,
|
|
776
|
-
messageName: message.name,
|
|
777
|
-
allowLiveState: isPlaceholderMessageName(message.name) || isPlaceholderMessageId(message.id),
|
|
778
|
-
skipLatestCache: isPlaceholderMessageName(message.name) || isPlaceholderMessageId(message.id),
|
|
779
|
-
stateRenderId,
|
|
780
|
-
effectiveRunId,
|
|
781
|
-
stateSnapshotProp: stateSnapshot,
|
|
782
|
-
agentState,
|
|
783
|
-
agentMessages,
|
|
784
|
-
existingClaim,
|
|
785
|
-
caches
|
|
786
|
-
});
|
|
787
|
-
const resolution = resolveClaim({
|
|
788
|
-
claims: claimsRef.current,
|
|
789
|
-
context: {
|
|
790
|
-
agentId,
|
|
791
|
-
messageId: message.id,
|
|
792
|
-
stateRenderId,
|
|
793
|
-
runId: effectiveRunId,
|
|
794
|
-
messageIndex
|
|
795
|
-
},
|
|
796
|
-
stateSnapshot: snapshotForClaim
|
|
797
|
-
});
|
|
798
|
-
if (resolution.action === "block" /* Block */) {
|
|
799
|
-
return { canRender: false };
|
|
800
|
-
}
|
|
801
|
-
if (resolution.updateRunId && claimsRef.current[message.id]) {
|
|
802
|
-
claimsRef.current[message.id].runId = resolution.updateRunId;
|
|
803
|
-
}
|
|
804
|
-
if (resolution.nextClaim) {
|
|
805
|
-
claimsRef.current[message.id] = resolution.nextClaim;
|
|
806
|
-
}
|
|
807
|
-
if (resolution.lockOthers) {
|
|
808
|
-
Object.entries(claimsRef.current).forEach(([id, claim]) => {
|
|
809
|
-
if (id !== message.id && claim.stateRenderId === stateRenderId) {
|
|
810
|
-
claim.locked = true;
|
|
811
|
-
}
|
|
812
|
-
});
|
|
813
|
-
}
|
|
814
|
-
if (existingClaim && !existingClaim.locked && (agentMessages == null ? void 0 : agentMessages.length)) {
|
|
815
|
-
const indexInAgentMessages = agentMessages.findIndex(
|
|
816
|
-
(msg) => msg.id === message.id
|
|
817
|
-
);
|
|
818
|
-
if (indexInAgentMessages >= 0 && indexInAgentMessages < agentMessages.length - 1) {
|
|
819
|
-
existingClaim.locked = true;
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
const existingSnapshot = claimsRef.current[message.id].stateSnapshot;
|
|
823
|
-
const snapshotChanged = stateSnapshot && existingSnapshot !== void 0 && !areStatesEquals(existingSnapshot, snapshot);
|
|
824
|
-
if (snapshot && (stateSnapshot || hasSnapshotKeys || allowEmptySnapshot) && (!claimsRef.current[message.id].locked || snapshotChanged)) {
|
|
825
|
-
if (!claimsRef.current[message.id].locked || snapshotChanged) {
|
|
826
|
-
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
827
|
-
const snapshotCache = __spreadValues({}, (_c = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _c : {});
|
|
828
|
-
const cacheKey = `${stateRenderId}::${effectiveRunId}`;
|
|
829
|
-
snapshotCache[cacheKey] = snapshot;
|
|
830
|
-
snapshotCache[`${stateRenderId}::latest`] = snapshot;
|
|
831
|
-
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
832
|
-
const messageCache = __spreadValues({}, (_d = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _d : {});
|
|
833
|
-
messageCache[message.id] = { snapshot, runId: effectiveRunId };
|
|
834
|
-
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
835
|
-
if (stateSnapshot) {
|
|
836
|
-
claimsRef.current[message.id].locked = true;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
} else if (snapshotForClaim) {
|
|
840
|
-
const existingSnapshot2 = claimsRef.current[message.id].stateSnapshot;
|
|
841
|
-
if (!existingSnapshot2) {
|
|
842
|
-
claimsRef.current[message.id].stateSnapshot = snapshotForClaim;
|
|
843
|
-
const snapshotCache = __spreadValues({}, (_e = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _e : {});
|
|
844
|
-
const cacheKey = `${stateRenderId}::${effectiveRunId}`;
|
|
845
|
-
snapshotCache[cacheKey] = snapshotForClaim;
|
|
846
|
-
snapshotCache[`${stateRenderId}::latest`] = snapshotForClaim;
|
|
847
|
-
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
848
|
-
const messageCache = __spreadValues({}, (_f = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _f : {});
|
|
849
|
-
messageCache[message.id] = {
|
|
850
|
-
snapshot: snapshotForClaim,
|
|
851
|
-
runId: effectiveRunId
|
|
852
|
-
};
|
|
853
|
-
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
return { canRender: true };
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
860
|
-
function useCoagentStateRenderBridge(agentId, props) {
|
|
861
|
-
var _a;
|
|
862
|
-
const { stateSnapshot, message } = props;
|
|
863
|
-
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
864
|
-
const { agent } = (0, import_react12.useAgent)({ agentId });
|
|
865
|
-
const [nodeName, setNodeName] = (0, import_react13.useState)(void 0);
|
|
866
|
-
const [, forceUpdate] = (0, import_react13.useState)(0);
|
|
867
|
-
(0, import_react13.useEffect)(() => {
|
|
868
|
-
if (!agent)
|
|
869
|
-
return;
|
|
870
|
-
const subscriber = {
|
|
871
|
-
onStateChanged: () => {
|
|
872
|
-
forceUpdate((value) => value + 1);
|
|
873
|
-
},
|
|
874
|
-
onStepStartedEvent: ({ event }) => {
|
|
875
|
-
if (event.stepName !== nodeName) {
|
|
876
|
-
setNodeName(event.stepName);
|
|
877
|
-
}
|
|
878
|
-
},
|
|
879
|
-
onStepFinishedEvent: ({ event }) => {
|
|
880
|
-
if (event.stepName === nodeName) {
|
|
881
|
-
setNodeName(void 0);
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
};
|
|
885
|
-
const { unsubscribe } = agent.subscribe(subscriber);
|
|
886
|
-
return () => {
|
|
887
|
-
unsubscribe();
|
|
888
|
-
};
|
|
889
|
-
}, [agentId, nodeName]);
|
|
890
|
-
const getStateRender = (0, import_react13.useCallback)(
|
|
891
|
-
(messageId) => {
|
|
892
|
-
return Object.entries(coAgentStateRenders).find(
|
|
893
|
-
([stateRenderId2, stateRender2]) => {
|
|
894
|
-
if (claimsRef.current[messageId]) {
|
|
895
|
-
return stateRenderId2 === claimsRef.current[messageId].stateRenderId;
|
|
896
|
-
}
|
|
897
|
-
const matchingAgentName = stateRender2.name === agentId;
|
|
898
|
-
const matchesNodeContext = stateRender2.nodeName ? stateRender2.nodeName === nodeName : true;
|
|
899
|
-
return matchingAgentName && matchesNodeContext;
|
|
900
|
-
}
|
|
901
|
-
);
|
|
902
|
-
},
|
|
903
|
-
[coAgentStateRenders, nodeName, agentId]
|
|
904
|
-
);
|
|
905
|
-
const stateRenderEntry = (0, import_react13.useMemo)(
|
|
906
|
-
() => getStateRender(message.id),
|
|
907
|
-
[getStateRender, message.id]
|
|
908
|
-
);
|
|
909
|
-
const stateRenderId = stateRenderEntry == null ? void 0 : stateRenderEntry[0];
|
|
910
|
-
const stateRender = stateRenderEntry == null ? void 0 : stateRenderEntry[1];
|
|
911
|
-
const registryMessage = __spreadProps(__spreadValues({}, message), {
|
|
912
|
-
runId: (_a = props.runId) != null ? _a : message.runId
|
|
913
|
-
});
|
|
914
|
-
const { canRender } = useStateRenderRegistry({
|
|
915
|
-
agentId,
|
|
916
|
-
stateRenderId,
|
|
917
|
-
message: registryMessage,
|
|
918
|
-
messageIndex: props.messageIndex,
|
|
919
|
-
stateSnapshot,
|
|
920
|
-
agentState: agent == null ? void 0 : agent.state,
|
|
921
|
-
agentMessages: agent == null ? void 0 : agent.messages,
|
|
922
|
-
claimsRef
|
|
923
|
-
});
|
|
924
|
-
return (0, import_react13.useMemo)(() => {
|
|
925
|
-
var _a2, _b;
|
|
926
|
-
if (!stateRender || !stateRenderId) {
|
|
927
|
-
return null;
|
|
928
|
-
}
|
|
929
|
-
if (!canRender) {
|
|
930
|
-
return null;
|
|
931
|
-
}
|
|
932
|
-
if (stateRender.handler) {
|
|
933
|
-
stateRender.handler({
|
|
934
|
-
state: stateSnapshot ? (0, import_shared4.parseJson)(stateSnapshot, stateSnapshot) : (_a2 = agent == null ? void 0 : agent.state) != null ? _a2 : {},
|
|
935
|
-
nodeName: nodeName != null ? nodeName : ""
|
|
936
|
-
});
|
|
937
|
-
}
|
|
938
|
-
if (stateRender.render) {
|
|
939
|
-
const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" /* InProgress */ : "complete" /* Complete */;
|
|
940
|
-
if (typeof stateRender.render === "string")
|
|
941
|
-
return stateRender.render;
|
|
942
|
-
return stateRender.render({
|
|
943
|
-
status,
|
|
944
|
-
// Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
|
|
945
|
-
state: (_b = claimsRef.current[message.id].stateSnapshot) != null ? _b : {},
|
|
946
|
-
nodeName: nodeName != null ? nodeName : ""
|
|
947
|
-
});
|
|
948
|
-
}
|
|
949
|
-
}, [
|
|
950
|
-
stateRender,
|
|
951
|
-
stateRenderId,
|
|
952
|
-
agent == null ? void 0 : agent.state,
|
|
953
|
-
agent == null ? void 0 : agent.isRunning,
|
|
954
|
-
nodeName,
|
|
955
|
-
message.id,
|
|
956
|
-
stateSnapshot,
|
|
957
|
-
canRender
|
|
958
|
-
]);
|
|
959
|
-
}
|
|
960
|
-
function CoAgentStateRenderBridge(props) {
|
|
961
|
-
return useCoagentStateRenderBridge(props.agentId, props);
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
965
|
-
function useCopilotChatInternal({
|
|
966
|
-
suggestions,
|
|
967
|
-
onInProgress,
|
|
968
|
-
onSubmitMessage,
|
|
969
|
-
onStopGeneration,
|
|
970
|
-
onReloadMessages
|
|
971
|
-
} = {}) {
|
|
972
|
-
var _a, _b, _c;
|
|
973
|
-
const { copilotkit } = (0, import_react15.useCopilotKit)();
|
|
974
|
-
const { threadId, agentSession } = useCopilotContext();
|
|
975
|
-
const existingConfig = (0, import_react15.useCopilotChatConfiguration)();
|
|
976
|
-
const [agentAvailable, setAgentAvailable] = (0, import_react14.useState)(false);
|
|
977
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
978
|
-
const { agent } = (0, import_react15.useAgent)({ agentId: resolvedAgentId });
|
|
979
|
-
(0, import_react14.useEffect)(() => {
|
|
980
|
-
const connect = (agent2) => __async(this, null, function* () {
|
|
981
|
-
setAgentAvailable(false);
|
|
982
|
-
try {
|
|
983
|
-
yield copilotkit.connectAgent({ agent: agent2 });
|
|
984
|
-
setAgentAvailable(true);
|
|
985
|
-
} catch (error) {
|
|
986
|
-
if (error instanceof import_client.AGUIConnectNotImplementedError) {
|
|
987
|
-
} else {
|
|
988
|
-
console.error("CopilotChat: connectAgent failed", error);
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
});
|
|
992
|
-
if (agent && (existingConfig == null ? void 0 : existingConfig.threadId) && agent.threadId !== existingConfig.threadId) {
|
|
993
|
-
agent.threadId = existingConfig.threadId;
|
|
994
|
-
connect(agent);
|
|
995
|
-
}
|
|
996
|
-
return () => {
|
|
997
|
-
};
|
|
998
|
-
}, [existingConfig == null ? void 0 : existingConfig.threadId, agent, copilotkit, resolvedAgentId]);
|
|
999
|
-
(0, import_react14.useEffect)(() => {
|
|
1000
|
-
onInProgress == null ? void 0 : onInProgress(Boolean(agent == null ? void 0 : agent.isRunning));
|
|
1001
|
-
}, [agent == null ? void 0 : agent.isRunning, onInProgress]);
|
|
1002
|
-
const interrupt = useLangGraphInterruptRender(agent);
|
|
1003
|
-
const reset = () => {
|
|
1004
|
-
agent == null ? void 0 : agent.setMessages([]);
|
|
1005
|
-
agent == null ? void 0 : agent.setState(null);
|
|
1006
|
-
};
|
|
1007
|
-
const deleteMessage = (0, import_react14.useCallback)(
|
|
1008
|
-
(messageId) => {
|
|
1009
|
-
var _a2;
|
|
1010
|
-
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
1011
|
-
(message) => message.id !== messageId
|
|
1012
|
-
);
|
|
1013
|
-
agent == null ? void 0 : agent.setMessages(filteredMessages);
|
|
1014
|
-
},
|
|
1015
|
-
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
1016
|
-
);
|
|
1017
|
-
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1018
|
-
const latestDeleteFunc = (0, import_react14.useCallback)(
|
|
1019
|
-
(messageId) => {
|
|
1020
|
-
return latestDelete.current(messageId);
|
|
1021
|
-
},
|
|
1022
|
-
[latestDelete]
|
|
1023
|
-
);
|
|
1024
|
-
const currentSuggestions = (0, import_react15.useSuggestions)({ agentId: resolvedAgentId });
|
|
1025
|
-
const reload = useAsyncCallback(
|
|
1026
|
-
(reloadMessageId) => __async(this, null, function* () {
|
|
1027
|
-
var _a2;
|
|
1028
|
-
if (!agent)
|
|
1029
|
-
return;
|
|
1030
|
-
const messages = (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : [];
|
|
1031
|
-
const isLoading = agent.isRunning;
|
|
1032
|
-
if (isLoading || messages.length === 0) {
|
|
1033
|
-
return;
|
|
1034
|
-
}
|
|
1035
|
-
const reloadMessageIndex = messages.findIndex(
|
|
1036
|
-
(msg) => msg.id === reloadMessageId
|
|
1037
|
-
);
|
|
1038
|
-
if (reloadMessageIndex === -1) {
|
|
1039
|
-
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
1040
|
-
return;
|
|
1041
|
-
}
|
|
1042
|
-
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
1043
|
-
if (reloadMessageRole !== "assistant") {
|
|
1044
|
-
console.warn(
|
|
1045
|
-
`Regenerate cannot be performed on ${reloadMessageRole} role`
|
|
1046
|
-
);
|
|
1047
|
-
return;
|
|
1048
|
-
}
|
|
1049
|
-
let historyCutoff = [messages[0]];
|
|
1050
|
-
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
1051
|
-
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find((msg) => msg.role === "user");
|
|
1052
|
-
if (!lastUserMessageBeforeRegenerate) {
|
|
1053
|
-
historyCutoff = [messages[0]];
|
|
1054
|
-
} else {
|
|
1055
|
-
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
1056
|
-
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
1057
|
-
);
|
|
1058
|
-
historyCutoff = messages.slice(
|
|
1059
|
-
0,
|
|
1060
|
-
indexOfLastUserMessageBeforeRegenerate + 1
|
|
1061
|
-
);
|
|
1062
|
-
}
|
|
1063
|
-
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
1064
|
-
historyCutoff = [messages[0], messages[1]];
|
|
1065
|
-
}
|
|
1066
|
-
agent == null ? void 0 : agent.setMessages(historyCutoff);
|
|
1067
|
-
if (agent) {
|
|
1068
|
-
try {
|
|
1069
|
-
yield copilotkit.runAgent({ agent });
|
|
1070
|
-
} catch (error) {
|
|
1071
|
-
console.error("CopilotChat: runAgent failed during reload", error);
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
return;
|
|
1075
|
-
}),
|
|
1076
|
-
[
|
|
1077
|
-
agent == null ? void 0 : agent.messages.length,
|
|
1078
|
-
agent == null ? void 0 : agent.isRunning,
|
|
1079
|
-
agent == null ? void 0 : agent.setMessages,
|
|
1080
|
-
copilotkit == null ? void 0 : copilotkit.runAgent
|
|
1081
|
-
]
|
|
1082
|
-
);
|
|
1083
|
-
const latestSendMessageFunc = useAsyncCallback(
|
|
1084
|
-
(message, options) => __async(this, null, function* () {
|
|
1085
|
-
var _a2;
|
|
1086
|
-
if (!agent)
|
|
1087
|
-
return;
|
|
1088
|
-
const followUp = (_a2 = options == null ? void 0 : options.followUp) != null ? _a2 : true;
|
|
1089
|
-
if (options == null ? void 0 : options.clearSuggestions) {
|
|
1090
|
-
copilotkit.clearSuggestions(resolvedAgentId);
|
|
1091
|
-
}
|
|
1092
|
-
if (onSubmitMessage) {
|
|
1093
|
-
const content = typeof message.content === "string" ? message.content : message.content && "text" in message.content ? message.content.text : message.content && "filename" in message.content ? message.content.filename : "";
|
|
1094
|
-
try {
|
|
1095
|
-
yield onSubmitMessage(content);
|
|
1096
|
-
} catch (error) {
|
|
1097
|
-
console.error("Error in onSubmitMessage:", error);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
agent == null ? void 0 : agent.addMessage(message);
|
|
1101
|
-
if (followUp) {
|
|
1102
|
-
try {
|
|
1103
|
-
yield copilotkit.runAgent({ agent });
|
|
1104
|
-
} catch (error) {
|
|
1105
|
-
console.error("CopilotChat: runAgent failed", error);
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
}),
|
|
1109
|
-
[agent, copilotkit, resolvedAgentId, onSubmitMessage]
|
|
1110
|
-
);
|
|
1111
|
-
const latestAppendFunc = useAsyncCallback(
|
|
1112
|
-
(message, options) => __async(this, null, function* () {
|
|
1113
|
-
return latestSendMessageFunc((0, import_runtime_client_gql2.gqlToAGUI)([message])[0], options);
|
|
1114
|
-
}),
|
|
1115
|
-
[latestSendMessageFunc]
|
|
1116
|
-
);
|
|
1117
|
-
const latestSetMessagesFunc = (0, import_react14.useCallback)(
|
|
1118
|
-
(messages) => {
|
|
1119
|
-
var _a2, _b2;
|
|
1120
|
-
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
1121
|
-
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
1122
|
-
}
|
|
1123
|
-
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
1124
|
-
},
|
|
1125
|
-
[agent == null ? void 0 : agent.setMessages, agent]
|
|
1126
|
-
);
|
|
1127
|
-
const latestReload = useUpdatedRef(reload);
|
|
1128
|
-
const latestReloadFunc = useAsyncCallback(
|
|
1129
|
-
(messageId) => __async(this, null, function* () {
|
|
1130
|
-
var _a2;
|
|
1131
|
-
onReloadMessages == null ? void 0 : onReloadMessages({
|
|
1132
|
-
messageId,
|
|
1133
|
-
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
1134
|
-
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
1135
|
-
});
|
|
1136
|
-
return yield latestReload.current(messageId);
|
|
1137
|
-
}),
|
|
1138
|
-
[latestReload, agent, onReloadMessages]
|
|
1139
|
-
);
|
|
1140
|
-
const latestStopFunc = (0, import_react14.useCallback)(() => {
|
|
1141
|
-
var _a2, _b2;
|
|
1142
|
-
onStopGeneration == null ? void 0 : onStopGeneration({
|
|
1143
|
-
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
1144
|
-
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
1145
|
-
});
|
|
1146
|
-
return (_b2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _b2.call(agent);
|
|
1147
|
-
}, [onStopGeneration, agent]);
|
|
1148
|
-
const latestReset = useUpdatedRef(reset);
|
|
1149
|
-
const latestResetFunc = (0, import_react14.useCallback)(() => {
|
|
1150
|
-
return latestReset.current();
|
|
1151
|
-
}, [latestReset]);
|
|
1152
|
-
const lazyToolRendered = useLazyToolRenderer();
|
|
1153
|
-
const renderCustomMessage = (0, import_react15.useRenderCustomMessages)();
|
|
1154
|
-
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
1155
|
-
copilotkit,
|
|
1156
|
-
agent,
|
|
1157
|
-
agentId: resolvedAgentId,
|
|
1158
|
-
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
1159
|
-
});
|
|
1160
|
-
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
1161
|
-
const resolvedMessages = (0, import_react14.useMemo)(() => {
|
|
1162
|
-
var _a2, _b2;
|
|
1163
|
-
let processedMessages = allMessages.map((message) => {
|
|
1164
|
-
if (message.role !== "assistant") {
|
|
1165
|
-
return message;
|
|
1166
|
-
}
|
|
1167
|
-
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
1168
|
-
if (lazyRendered) {
|
|
1169
|
-
const renderedGenUi = lazyRendered();
|
|
1170
|
-
if (renderedGenUi) {
|
|
1171
|
-
return __spreadProps(__spreadValues({}, message), { generativeUI: () => renderedGenUi });
|
|
1172
|
-
}
|
|
1173
|
-
}
|
|
1174
|
-
const bridgeRenderer = legacyCustomMessageRenderer || renderCustomMessage ? () => {
|
|
1175
|
-
var _a3;
|
|
1176
|
-
if (legacyCustomMessageRenderer) {
|
|
1177
|
-
return legacyCustomMessageRenderer({
|
|
1178
|
-
message,
|
|
1179
|
-
position: "before"
|
|
1180
|
-
});
|
|
1181
|
-
}
|
|
1182
|
-
try {
|
|
1183
|
-
return (_a3 = renderCustomMessage == null ? void 0 : renderCustomMessage({ message, position: "before" })) != null ? _a3 : null;
|
|
1184
|
-
} catch (error) {
|
|
1185
|
-
console.warn(
|
|
1186
|
-
"[CopilotKit] renderCustomMessages failed, falling back to legacy renderer",
|
|
1187
|
-
error
|
|
1188
|
-
);
|
|
1189
|
-
return null;
|
|
1190
|
-
}
|
|
1191
|
-
} : null;
|
|
1192
|
-
if (bridgeRenderer) {
|
|
1193
|
-
return __spreadProps(__spreadValues({}, message), {
|
|
1194
|
-
generativeUI: bridgeRenderer,
|
|
1195
|
-
generativeUIPosition: "before"
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
return message;
|
|
1199
|
-
});
|
|
1200
|
-
const hasAssistantMessages = processedMessages.some(
|
|
1201
|
-
(msg) => msg.role === "assistant"
|
|
1202
|
-
);
|
|
1203
|
-
const canUseCustomRenderer = Boolean(
|
|
1204
|
-
renderCustomMessage && ((_a2 = copilotkit == null ? void 0 : copilotkit.getAgent) == null ? void 0 : _a2.call(copilotkit, resolvedAgentId))
|
|
1205
|
-
);
|
|
1206
|
-
const placeholderRenderer = legacyCustomMessageRenderer ? legacyCustomMessageRenderer : canUseCustomRenderer ? renderCustomMessage : null;
|
|
1207
|
-
const shouldRenderPlaceholder = Boolean(agent == null ? void 0 : agent.isRunning) || Boolean((agent == null ? void 0 : agent.state) && Object.keys(agent.state).length);
|
|
1208
|
-
const effectiveThreadId = (_b2 = threadId != null ? threadId : agent == null ? void 0 : agent.threadId) != null ? _b2 : "default";
|
|
1209
|
-
let latestUserIndex = -1;
|
|
1210
|
-
for (let i = processedMessages.length - 1; i >= 0; i -= 1) {
|
|
1211
|
-
if (processedMessages[i].role === "user") {
|
|
1212
|
-
latestUserIndex = i;
|
|
1213
|
-
break;
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
const latestUserMessageId = latestUserIndex >= 0 ? processedMessages[latestUserIndex].id : void 0;
|
|
1217
|
-
const currentRunId = latestUserMessageId ? copilotkit.getRunIdForMessage(
|
|
1218
|
-
resolvedAgentId,
|
|
1219
|
-
effectiveThreadId,
|
|
1220
|
-
latestUserMessageId
|
|
1221
|
-
) || `pending:${latestUserMessageId}` : void 0;
|
|
1222
|
-
const hasAssistantForCurrentRun = latestUserIndex >= 0 ? processedMessages.slice(latestUserIndex + 1).some((msg) => msg.role === "assistant") : hasAssistantMessages;
|
|
1223
|
-
if (placeholderRenderer && shouldRenderPlaceholder && !hasAssistantForCurrentRun) {
|
|
1224
|
-
const placeholderId = currentRunId ? `coagent-state-render-${resolvedAgentId}-${currentRunId}` : `coagent-state-render-${resolvedAgentId}`;
|
|
1225
|
-
const placeholderMessage = {
|
|
1226
|
-
id: placeholderId,
|
|
1227
|
-
role: "assistant",
|
|
1228
|
-
content: "",
|
|
1229
|
-
name: "coagent-state-render",
|
|
1230
|
-
runId: currentRunId
|
|
1231
|
-
};
|
|
1232
|
-
processedMessages = [
|
|
1233
|
-
...processedMessages,
|
|
1234
|
-
__spreadProps(__spreadValues({}, placeholderMessage), {
|
|
1235
|
-
generativeUIPosition: "before",
|
|
1236
|
-
generativeUI: () => placeholderRenderer({
|
|
1237
|
-
message: placeholderMessage,
|
|
1238
|
-
position: "before"
|
|
1239
|
-
})
|
|
1240
|
-
})
|
|
1241
|
-
];
|
|
1242
|
-
}
|
|
1243
|
-
return processedMessages;
|
|
1244
|
-
}, [
|
|
1245
|
-
agent == null ? void 0 : agent.messages,
|
|
1246
|
-
lazyToolRendered,
|
|
1247
|
-
allMessages,
|
|
1248
|
-
renderCustomMessage,
|
|
1249
|
-
legacyCustomMessageRenderer,
|
|
1250
|
-
resolvedAgentId,
|
|
1251
|
-
copilotkit,
|
|
1252
|
-
agent == null ? void 0 : agent.isRunning,
|
|
1253
|
-
agent == null ? void 0 : agent.state
|
|
1254
|
-
]);
|
|
1255
|
-
const renderedSuggestions = (0, import_react14.useMemo)(() => {
|
|
1256
|
-
if (Array.isArray(suggestions)) {
|
|
1257
|
-
return {
|
|
1258
|
-
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
1259
|
-
isLoading: false
|
|
1260
|
-
};
|
|
1261
|
-
}
|
|
1262
|
-
return currentSuggestions;
|
|
1263
|
-
}, [suggestions, currentSuggestions]);
|
|
1264
|
-
return {
|
|
1265
|
-
messages: resolvedMessages,
|
|
1266
|
-
sendMessage: latestSendMessageFunc,
|
|
1267
|
-
appendMessage: latestAppendFunc,
|
|
1268
|
-
setMessages: latestSetMessagesFunc,
|
|
1269
|
-
reloadMessages: latestReloadFunc,
|
|
1270
|
-
stopGeneration: latestStopFunc,
|
|
1271
|
-
reset: latestResetFunc,
|
|
1272
|
-
deleteMessage: latestDeleteFunc,
|
|
1273
|
-
isAvailable: agentAvailable,
|
|
1274
|
-
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
1275
|
-
// mcpServers,
|
|
1276
|
-
// setMcpServers,
|
|
1277
|
-
suggestions: renderedSuggestions.suggestions,
|
|
1278
|
-
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
1279
|
-
generateSuggestions: () => __async(this, null, function* () {
|
|
1280
|
-
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
1281
|
-
}),
|
|
1282
|
-
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
1283
|
-
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
1284
|
-
interrupt,
|
|
1285
|
-
agent,
|
|
1286
|
-
threadId
|
|
1287
|
-
};
|
|
1288
|
-
}
|
|
1289
|
-
function useUpdatedRef(value) {
|
|
1290
|
-
const ref = (0, import_react14.useRef)(value);
|
|
1291
|
-
(0, import_react14.useEffect)(() => {
|
|
1292
|
-
ref.current = value;
|
|
1293
|
-
}, [value]);
|
|
1294
|
-
return ref;
|
|
1295
|
-
}
|
|
1296
|
-
function useLegacyCoagentRenderer({
|
|
1297
|
-
copilotkit,
|
|
1298
|
-
agent,
|
|
1299
|
-
agentId,
|
|
1300
|
-
threadId
|
|
1301
|
-
}) {
|
|
1302
|
-
return (0, import_react14.useMemo)(() => {
|
|
1303
|
-
if (!copilotkit || !agent) {
|
|
1304
|
-
return null;
|
|
1305
|
-
}
|
|
1306
|
-
return ({ message, position }) => {
|
|
1307
|
-
var _a;
|
|
1308
|
-
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
1309
|
-
const providedRunId = message.runId;
|
|
1310
|
-
const existingRunId = providedRunId ? providedRunId : copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
1311
|
-
const runId = existingRunId || `pending:${message.id}`;
|
|
1312
|
-
const messageIndex = Math.max(
|
|
1313
|
-
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
1314
|
-
0
|
|
1315
|
-
);
|
|
1316
|
-
const bridgeProps = {
|
|
1317
|
-
message,
|
|
1318
|
-
position,
|
|
1319
|
-
runId,
|
|
1320
|
-
messageIndex,
|
|
1321
|
-
messageIndexInRun: 0,
|
|
1322
|
-
numberOfMessagesInRun: 1,
|
|
1323
|
-
agentId,
|
|
1324
|
-
stateSnapshot: message.state
|
|
1325
|
-
};
|
|
1326
|
-
return (0, import_react14.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
1327
|
-
};
|
|
1328
|
-
}, [agent, agentId, copilotkit, threadId]);
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
// src/hooks/use-copilot-chat.ts
|
|
1332
|
-
function useCopilotChat(options = {}) {
|
|
1333
|
-
const {
|
|
1334
|
-
visibleMessages,
|
|
1335
|
-
appendMessage,
|
|
1336
|
-
reloadMessages,
|
|
1337
|
-
stopGeneration,
|
|
1338
|
-
reset,
|
|
1339
|
-
isLoading,
|
|
1340
|
-
isAvailable,
|
|
1341
|
-
runChatCompletion,
|
|
1342
|
-
mcpServers,
|
|
1343
|
-
setMcpServers
|
|
1344
|
-
} = useCopilotChatInternal(options);
|
|
1345
|
-
return {
|
|
1346
|
-
visibleMessages,
|
|
1347
|
-
appendMessage,
|
|
1348
|
-
reloadMessages,
|
|
1349
|
-
stopGeneration,
|
|
1350
|
-
reset,
|
|
1351
|
-
isLoading,
|
|
1352
|
-
isAvailable,
|
|
1353
|
-
runChatCompletion,
|
|
1354
|
-
mcpServers,
|
|
1355
|
-
setMcpServers
|
|
1356
|
-
};
|
|
1357
|
-
}
|
|
1358
|
-
|
|
1359
|
-
// src/hooks/use-copilot-chat-headless_c.ts
|
|
1360
|
-
var import_react16 = require("react");
|
|
1361
|
-
var import_shared5 = require("@copilotkit/shared");
|
|
1362
|
-
var createNonFunctionalReturn = () => ({
|
|
1363
|
-
visibleMessages: [],
|
|
1364
|
-
messages: [],
|
|
1365
|
-
sendMessage: () => __async(void 0, null, function* () {
|
|
1366
|
-
}),
|
|
1367
|
-
appendMessage: () => __async(void 0, null, function* () {
|
|
1368
|
-
}),
|
|
1369
|
-
setMessages: () => {
|
|
1370
|
-
},
|
|
1371
|
-
deleteMessage: () => {
|
|
1372
|
-
},
|
|
1373
|
-
reloadMessages: () => __async(void 0, null, function* () {
|
|
1374
|
-
}),
|
|
1375
|
-
stopGeneration: () => {
|
|
1376
|
-
},
|
|
1377
|
-
reset: () => {
|
|
1378
|
-
},
|
|
1379
|
-
isLoading: false,
|
|
1380
|
-
isAvailable: false,
|
|
1381
|
-
runChatCompletion: () => __async(void 0, null, function* () {
|
|
1382
|
-
return [];
|
|
1383
|
-
}),
|
|
1384
|
-
mcpServers: [],
|
|
1385
|
-
setMcpServers: () => {
|
|
1386
|
-
},
|
|
1387
|
-
suggestions: [],
|
|
1388
|
-
setSuggestions: () => {
|
|
1389
|
-
},
|
|
1390
|
-
generateSuggestions: () => __async(void 0, null, function* () {
|
|
1391
|
-
}),
|
|
1392
|
-
resetSuggestions: () => {
|
|
1393
|
-
},
|
|
1394
|
-
isLoadingSuggestions: false,
|
|
1395
|
-
interrupt: null
|
|
1396
|
-
});
|
|
1397
|
-
function useCopilotChatHeadless_c(options = {}) {
|
|
1398
|
-
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
1399
|
-
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
1400
|
-
const internalResult = useCopilotChatInternal(options);
|
|
1401
|
-
(0, import_react16.useEffect)(() => {
|
|
1402
|
-
if (!hasPublicApiKey) {
|
|
1403
|
-
setBannerError(
|
|
1404
|
-
new import_shared5.CopilotKitError({
|
|
1405
|
-
message: (
|
|
1406
|
-
// add link to documentation here
|
|
1407
|
-
"You're using useCopilotChatHeadless_c, a premium-only feature, which offers extensive headless chat capabilities. To continue, you'll need to provide a free public license key."
|
|
1408
|
-
),
|
|
1409
|
-
code: import_shared5.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
1410
|
-
severity: import_shared5.Severity.WARNING,
|
|
1411
|
-
visibility: import_shared5.ErrorVisibility.BANNER
|
|
1412
|
-
})
|
|
1413
|
-
);
|
|
1414
|
-
import_shared5.styledConsole.logCopilotKitPlatformMessage();
|
|
1415
|
-
} else {
|
|
1416
|
-
setBannerError(null);
|
|
1417
|
-
}
|
|
1418
|
-
}, [hasPublicApiKey]);
|
|
1419
|
-
if (hasPublicApiKey) {
|
|
1420
|
-
return internalResult;
|
|
1421
|
-
}
|
|
1422
|
-
return createNonFunctionalReturn();
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
// src/hooks/use-copilot-action.ts
|
|
1426
|
-
var import_react23 = require("react");
|
|
1427
|
-
|
|
1428
|
-
// src/hooks/use-frontend-tool.ts
|
|
1429
|
-
var import_react17 = __toESM(require("react"));
|
|
1430
|
-
var import_shared6 = require("@copilotkit/shared");
|
|
1431
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1432
|
-
var import_react18 = require("@copilotkitnext/react");
|
|
1433
|
-
function useFrontendTool(tool, dependencies) {
|
|
1434
|
-
const { name, description, parameters, render, followUp } = tool;
|
|
1435
|
-
const zodParameters = (0, import_shared6.getZodParameters)(parameters);
|
|
1436
|
-
const renderRef = (0, import_react17.useRef)(render);
|
|
1437
|
-
(0, import_react17.useEffect)(() => {
|
|
1438
|
-
renderRef.current = render;
|
|
1439
|
-
}, [render, ...dependencies != null ? dependencies : []]);
|
|
1440
|
-
const normalizedRender = (0, import_react17.useMemo)(() => {
|
|
1441
|
-
if (typeof render === "undefined") {
|
|
1442
|
-
return void 0;
|
|
1443
|
-
}
|
|
1444
|
-
return (args) => {
|
|
1445
|
-
const currentRender = renderRef.current;
|
|
1446
|
-
if (typeof currentRender === "undefined") {
|
|
1447
|
-
return null;
|
|
1448
|
-
}
|
|
1449
|
-
if (typeof currentRender === "string") {
|
|
1450
|
-
return import_react17.default.createElement(import_react17.default.Fragment, null, currentRender);
|
|
1451
|
-
}
|
|
1452
|
-
const renderArgs = __spreadProps(__spreadValues({}, args), {
|
|
1453
|
-
result: typeof args.result === "string" ? (0, import_shared7.parseJson)(args.result, args.result) : args.result
|
|
1454
|
-
});
|
|
1455
|
-
const rendered = currentRender(renderArgs);
|
|
1456
|
-
if (typeof rendered === "string") {
|
|
1457
|
-
return import_react17.default.createElement(import_react17.default.Fragment, null, rendered);
|
|
1458
|
-
}
|
|
1459
|
-
return rendered != null ? rendered : null;
|
|
1460
|
-
};
|
|
1461
|
-
}, []);
|
|
1462
|
-
const handlerRef = (0, import_react17.useRef)(tool.handler);
|
|
1463
|
-
(0, import_react17.useEffect)(() => {
|
|
1464
|
-
handlerRef.current = tool.handler;
|
|
1465
|
-
}, [tool.handler, ...dependencies != null ? dependencies : []]);
|
|
1466
|
-
const normalizedHandler = tool.handler ? (args) => {
|
|
1467
|
-
var _a;
|
|
1468
|
-
return (_a = handlerRef.current) == null ? void 0 : _a.call(handlerRef, args);
|
|
1469
|
-
} : void 0;
|
|
1470
|
-
(0, import_react18.useFrontendTool)({
|
|
1471
|
-
name,
|
|
1472
|
-
description,
|
|
1473
|
-
parameters: zodParameters,
|
|
1474
|
-
handler: normalizedHandler,
|
|
1475
|
-
followUp,
|
|
1476
|
-
render: normalizedRender
|
|
1477
|
-
});
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
// src/hooks/use-render-tool-call.ts
|
|
1481
|
-
var import_shared8 = require("@copilotkit/shared");
|
|
1482
|
-
var import_shared9 = require("@copilotkit/shared");
|
|
1483
|
-
var import_react19 = require("@copilotkitnext/react");
|
|
1484
|
-
var import_react20 = require("react");
|
|
1485
|
-
function useRenderToolCall2(tool, dependencies) {
|
|
1486
|
-
const { copilotkit } = (0, import_react19.useCopilotKit)();
|
|
1487
|
-
const hasAddedRef = (0, import_react20.useRef)(false);
|
|
1488
|
-
(0, import_react20.useEffect)(() => {
|
|
1489
|
-
const { name, parameters, render } = tool;
|
|
1490
|
-
const zodParameters = (0, import_shared8.getZodParameters)(parameters);
|
|
1491
|
-
const renderToolCall = name === "*" ? (0, import_react19.defineToolCallRenderer)({
|
|
1492
|
-
name: "*",
|
|
1493
|
-
render: (args) => {
|
|
1494
|
-
return render(__spreadProps(__spreadValues({}, args), {
|
|
1495
|
-
result: args.result ? (0, import_shared9.parseJson)(args.result, args.result) : args.result
|
|
1496
|
-
}));
|
|
1497
|
-
}
|
|
1498
|
-
}) : (0, import_react19.defineToolCallRenderer)({
|
|
1499
|
-
name,
|
|
1500
|
-
args: zodParameters,
|
|
1501
|
-
render: (args) => {
|
|
1502
|
-
return render(__spreadProps(__spreadValues({}, args), {
|
|
1503
|
-
result: args.result ? (0, import_shared9.parseJson)(args.result, args.result) : args.result
|
|
1504
|
-
}));
|
|
1505
|
-
}
|
|
1506
|
-
});
|
|
1507
|
-
const existingIndex = copilotkit.renderToolCalls.findIndex(
|
|
1508
|
-
(r) => r.name === name
|
|
1509
|
-
);
|
|
1510
|
-
if (existingIndex !== -1) {
|
|
1511
|
-
copilotkit.renderToolCalls.splice(existingIndex, 1);
|
|
1512
|
-
}
|
|
1513
|
-
copilotkit.renderToolCalls.push(renderToolCall);
|
|
1514
|
-
hasAddedRef.current = true;
|
|
1515
|
-
return () => {
|
|
1516
|
-
if (hasAddedRef.current) {
|
|
1517
|
-
const index = copilotkit.renderToolCalls.findIndex(
|
|
1518
|
-
(r) => r.name === name
|
|
1519
|
-
);
|
|
1520
|
-
if (index !== -1) {
|
|
1521
|
-
copilotkit.renderToolCalls.splice(index, 1);
|
|
1522
|
-
}
|
|
1523
|
-
hasAddedRef.current = false;
|
|
1524
|
-
}
|
|
1525
|
-
};
|
|
1526
|
-
}, [tool, ...dependencies != null ? dependencies : []]);
|
|
1527
|
-
}
|
|
1528
|
-
|
|
1529
|
-
// src/hooks/use-human-in-the-loop.ts
|
|
1530
|
-
var import_shared10 = require("@copilotkit/shared");
|
|
1531
|
-
var import_react21 = require("@copilotkitnext/react");
|
|
1532
|
-
var import_core = require("@copilotkitnext/core");
|
|
1533
|
-
var import_react22 = __toESM(require("react"));
|
|
1534
|
-
function useHumanInTheLoop(tool, dependencies) {
|
|
1535
|
-
const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
|
|
1536
|
-
const { name, description, parameters, followUp } = toolRest;
|
|
1537
|
-
const zodParameters = (0, import_shared10.getZodParameters)(parameters);
|
|
1538
|
-
const renderRef = (0, import_react22.useRef)(null);
|
|
1539
|
-
(0, import_react22.useEffect)(() => {
|
|
1540
|
-
renderRef.current = (args) => {
|
|
1541
|
-
if (typeof render === "string") {
|
|
1542
|
-
return import_react22.default.createElement(import_react22.default.Fragment, null, render);
|
|
1543
|
-
}
|
|
1544
|
-
if (!render) {
|
|
1545
|
-
return null;
|
|
1546
|
-
}
|
|
1547
|
-
const renderProps = (() => {
|
|
1548
|
-
const mappedArgs = args.args;
|
|
1549
|
-
switch (args.status) {
|
|
1550
|
-
case import_core.ToolCallStatus.InProgress:
|
|
1551
|
-
return {
|
|
1552
|
-
args: mappedArgs,
|
|
1553
|
-
respond: args.respond,
|
|
1554
|
-
status: args.status,
|
|
1555
|
-
handler: void 0
|
|
1556
|
-
};
|
|
1557
|
-
case import_core.ToolCallStatus.Executing:
|
|
1558
|
-
return {
|
|
1559
|
-
args: mappedArgs,
|
|
1560
|
-
respond: args.respond,
|
|
1561
|
-
status: args.status,
|
|
1562
|
-
handler: () => {
|
|
1563
|
-
}
|
|
1564
|
-
};
|
|
1565
|
-
case import_core.ToolCallStatus.Complete:
|
|
1566
|
-
return {
|
|
1567
|
-
args: mappedArgs,
|
|
1568
|
-
respond: args.respond,
|
|
1569
|
-
status: args.status,
|
|
1570
|
-
result: args.result ? (0, import_shared10.parseJson)(args.result, args.result) : args.result,
|
|
1571
|
-
handler: void 0
|
|
1572
|
-
};
|
|
1573
|
-
default:
|
|
1574
|
-
throw new import_shared10.CopilotKitError({
|
|
1575
|
-
code: import_shared10.CopilotKitErrorCode.UNKNOWN,
|
|
1576
|
-
message: `Invalid tool call status: ${args.status}`
|
|
1577
|
-
});
|
|
1578
|
-
}
|
|
1579
|
-
})();
|
|
1580
|
-
const rendered = render(renderProps);
|
|
1581
|
-
if (typeof rendered === "string") {
|
|
1582
|
-
return import_react22.default.createElement(import_react22.default.Fragment, null, rendered);
|
|
1583
|
-
}
|
|
1584
|
-
return rendered != null ? rendered : null;
|
|
1585
|
-
};
|
|
1586
|
-
}, [render, ...dependencies != null ? dependencies : []]);
|
|
1587
|
-
(0, import_react21.useHumanInTheLoop)({
|
|
1588
|
-
name,
|
|
1589
|
-
description,
|
|
1590
|
-
followUp,
|
|
1591
|
-
parameters: zodParameters,
|
|
1592
|
-
render: (args) => {
|
|
1593
|
-
var _a2, _b;
|
|
1594
|
-
return (_b = (_a2 = renderRef.current) == null ? void 0 : _a2.call(renderRef, args)) != null ? _b : null;
|
|
1595
|
-
}
|
|
1596
|
-
});
|
|
1597
|
-
}
|
|
1598
|
-
|
|
1599
|
-
// src/hooks/use-copilot-action.ts
|
|
1600
|
-
function getActionConfig(action) {
|
|
1601
|
-
if (action.name === "*") {
|
|
1602
|
-
return {
|
|
1603
|
-
type: "render",
|
|
1604
|
-
action
|
|
1605
|
-
};
|
|
1606
|
-
}
|
|
1607
|
-
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
|
|
1608
|
-
let render = action.render;
|
|
1609
|
-
if (!render && "renderAndWaitForResponse" in action) {
|
|
1610
|
-
render = action.renderAndWaitForResponse;
|
|
1611
|
-
}
|
|
1612
|
-
if (!render && "renderAndWait" in action) {
|
|
1613
|
-
render = action.renderAndWait;
|
|
1614
|
-
}
|
|
1615
|
-
return {
|
|
1616
|
-
type: "hitl",
|
|
1617
|
-
action: __spreadProps(__spreadValues({}, action), { render })
|
|
1618
|
-
};
|
|
1619
|
-
}
|
|
1620
|
-
if ("available" in action) {
|
|
1621
|
-
if (action.available === "enabled" || action.available === "remote") {
|
|
1622
|
-
return {
|
|
1623
|
-
type: "frontend",
|
|
1624
|
-
action
|
|
1625
|
-
};
|
|
1626
|
-
}
|
|
1627
|
-
if (action.available === "frontend" || action.available === "disabled") {
|
|
1628
|
-
return {
|
|
1629
|
-
type: "render",
|
|
1630
|
-
action
|
|
1631
|
-
};
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
if ("handler" in action) {
|
|
1635
|
-
return {
|
|
1636
|
-
type: "frontend",
|
|
1637
|
-
action
|
|
1638
|
-
};
|
|
1639
|
-
}
|
|
1640
|
-
throw new Error("Invalid action configuration");
|
|
1641
|
-
}
|
|
1642
|
-
function useCopilotAction(action, dependencies) {
|
|
1643
|
-
const [initialActionConfig] = (0, import_react23.useState)(getActionConfig(action));
|
|
1644
|
-
const currentActionConfig = getActionConfig(action);
|
|
1645
|
-
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
1646
|
-
throw new Error("Action configuration changed between renders");
|
|
1647
|
-
}
|
|
1648
|
-
switch (currentActionConfig.type) {
|
|
1649
|
-
case "render":
|
|
1650
|
-
return useRenderToolCall2(currentActionConfig.action, dependencies);
|
|
1651
|
-
case "hitl":
|
|
1652
|
-
return useHumanInTheLoop(currentActionConfig.action, dependencies);
|
|
1653
|
-
case "frontend":
|
|
1654
|
-
return useFrontendTool(currentActionConfig.action, dependencies);
|
|
1655
|
-
default:
|
|
1656
|
-
throw new Error("Invalid action configuration");
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
|
|
1660
|
-
// src/hooks/use-coagent-state-render.ts
|
|
1661
|
-
var import_react24 = require("react");
|
|
1662
|
-
var import_shared11 = require("@copilotkit/shared");
|
|
1663
|
-
function useCoAgentStateRender(action, dependencies) {
|
|
1664
|
-
const { chatComponentsCache, availableAgents } = (0, import_react24.useContext)(CopilotContext);
|
|
1665
|
-
const {
|
|
1666
|
-
setCoAgentStateRender,
|
|
1667
|
-
removeCoAgentStateRender,
|
|
1668
|
-
coAgentStateRenders
|
|
1669
|
-
} = useCoAgentStateRenders();
|
|
1670
|
-
const idRef = (0, import_react24.useRef)((0, import_shared11.randomId)());
|
|
1671
|
-
const { setBannerError, addToast } = useToast();
|
|
1672
|
-
(0, import_react24.useEffect)(() => {
|
|
1673
|
-
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
1674
|
-
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
1675
|
-
const agentError = new import_shared11.CopilotKitAgentDiscoveryError({
|
|
1676
|
-
agentName: action.name,
|
|
1677
|
-
availableAgents: availableAgents.map((a) => ({
|
|
1678
|
-
name: a.name,
|
|
1679
|
-
id: a.id
|
|
1680
|
-
}))
|
|
1681
|
-
});
|
|
1682
|
-
setBannerError(agentError);
|
|
1683
|
-
}
|
|
1684
|
-
}, [availableAgents]);
|
|
1685
|
-
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1686
|
-
if (dependencies === void 0) {
|
|
1687
|
-
if (coAgentStateRenders[idRef.current]) {
|
|
1688
|
-
coAgentStateRenders[idRef.current].handler = action.handler;
|
|
1689
|
-
if (typeof action.render === "function") {
|
|
1690
|
-
if (chatComponentsCache.current !== null) {
|
|
1691
|
-
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
1692
|
-
}
|
|
1693
|
-
}
|
|
1694
|
-
}
|
|
1695
|
-
}
|
|
1696
|
-
(0, import_react24.useEffect)(() => {
|
|
1697
|
-
const currentId = idRef.current;
|
|
1698
|
-
const hasDuplicate = Object.entries(coAgentStateRenders).some(
|
|
1699
|
-
([id, otherAction]) => {
|
|
1700
|
-
if (id === currentId)
|
|
1701
|
-
return false;
|
|
1702
|
-
if (otherAction.name !== action.name)
|
|
1703
|
-
return false;
|
|
1704
|
-
const hasNodeName = !!action.nodeName;
|
|
1705
|
-
const hasOtherNodeName = !!otherAction.nodeName;
|
|
1706
|
-
if (!hasNodeName && !hasOtherNodeName)
|
|
1707
|
-
return true;
|
|
1708
|
-
if (hasNodeName !== hasOtherNodeName)
|
|
1709
|
-
return false;
|
|
1710
|
-
return action.nodeName === otherAction.nodeName;
|
|
1711
|
-
}
|
|
1712
|
-
);
|
|
1713
|
-
if (hasDuplicate) {
|
|
1714
|
-
const message = action.nodeName ? `Found multiple state renders for agent ${action.name} and node ${action.nodeName}. State renders might get overridden` : `Found multiple state renders for agent ${action.name}. State renders might get overridden`;
|
|
1715
|
-
addToast({
|
|
1716
|
-
type: "warning",
|
|
1717
|
-
message,
|
|
1718
|
-
id: `dup-action-${action.name}`
|
|
1719
|
-
});
|
|
1720
|
-
}
|
|
1721
|
-
}, [coAgentStateRenders]);
|
|
1722
|
-
(0, import_react24.useEffect)(() => {
|
|
1723
|
-
setCoAgentStateRender(idRef.current, action);
|
|
1724
|
-
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1725
|
-
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
1726
|
-
}
|
|
1727
|
-
return () => {
|
|
1728
|
-
removeCoAgentStateRender(idRef.current);
|
|
1729
|
-
};
|
|
1730
|
-
}, [
|
|
1731
|
-
setCoAgentStateRender,
|
|
1732
|
-
removeCoAgentStateRender,
|
|
1733
|
-
action.name,
|
|
1734
|
-
// include render only if it's a string
|
|
1735
|
-
typeof action.render === "string" ? action.render : void 0,
|
|
1736
|
-
// dependencies set by the developer
|
|
1737
|
-
...dependencies || []
|
|
1738
|
-
]);
|
|
1739
|
-
}
|
|
1740
|
-
|
|
1741
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
1742
|
-
var import_react25 = require("react");
|
|
1743
|
-
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1744
|
-
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1745
|
-
const idRef = (0, import_react25.useRef)(void 0);
|
|
1746
|
-
(0, import_react25.useEffect)(() => {
|
|
1747
|
-
const id = addDocumentContext(document, categories);
|
|
1748
|
-
idRef.current = id;
|
|
1749
|
-
return () => {
|
|
1750
|
-
removeDocumentContext(id);
|
|
1751
|
-
};
|
|
1752
|
-
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
1753
|
-
return idRef.current;
|
|
1754
|
-
}
|
|
1755
|
-
|
|
1756
|
-
// src/hooks/use-copilot-readable.ts
|
|
1757
|
-
var import_react26 = require("@copilotkitnext/react");
|
|
1758
|
-
var import_react27 = require("react");
|
|
1759
|
-
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
1760
|
-
const { copilotkit } = (0, import_react26.useCopilotKit)();
|
|
1761
|
-
const ctxIdRef = (0, import_react27.useRef)(void 0);
|
|
1762
|
-
(0, import_react27.useEffect)(() => {
|
|
1763
|
-
if (!copilotkit)
|
|
1764
|
-
return;
|
|
1765
|
-
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
1766
|
-
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
1767
|
-
});
|
|
1768
|
-
if (found) {
|
|
1769
|
-
ctxIdRef.current = found[0];
|
|
1770
|
-
if (available === "disabled")
|
|
1771
|
-
copilotkit.removeContext(ctxIdRef.current);
|
|
1772
|
-
return;
|
|
1773
|
-
}
|
|
1774
|
-
if (!found && available === "disabled")
|
|
1775
|
-
return;
|
|
1776
|
-
ctxIdRef.current = copilotkit.addContext({
|
|
1777
|
-
description,
|
|
1778
|
-
value: (convert != null ? convert : JSON.stringify)(value)
|
|
1779
|
-
});
|
|
1780
|
-
return () => {
|
|
1781
|
-
if (!ctxIdRef.current)
|
|
1782
|
-
return;
|
|
1783
|
-
copilotkit.removeContext(ctxIdRef.current);
|
|
1784
|
-
};
|
|
1785
|
-
}, [description, value, convert]);
|
|
1786
|
-
return ctxIdRef.current;
|
|
1787
|
-
}
|
|
1788
|
-
|
|
1789
|
-
// src/hooks/use-coagent.ts
|
|
1790
|
-
var import_react28 = require("react");
|
|
1791
|
-
var import_react29 = require("@copilotkitnext/react");
|
|
1792
|
-
function useCoAgent(options) {
|
|
1793
|
-
const { agent } = (0, import_react29.useAgent)({ agentId: options.name });
|
|
1794
|
-
const { copilotkit } = (0, import_react29.useCopilotKit)();
|
|
1795
|
-
const nodeName = useAgentNodeName(options.name);
|
|
1796
|
-
const handleStateUpdate = (0, import_react28.useCallback)(
|
|
1797
|
-
(newState) => {
|
|
1798
|
-
if (!agent)
|
|
1799
|
-
return;
|
|
1800
|
-
if (typeof newState === "function") {
|
|
1801
|
-
const updater = newState;
|
|
1802
|
-
agent.setState(updater(agent.state));
|
|
1803
|
-
} else {
|
|
1804
|
-
agent.setState(__spreadValues(__spreadValues({}, agent.state), newState));
|
|
1805
|
-
}
|
|
1806
|
-
},
|
|
1807
|
-
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
1808
|
-
);
|
|
1809
|
-
(0, import_react28.useEffect)(() => {
|
|
1810
|
-
var _a;
|
|
1811
|
-
if (!options.config && !options.configurable)
|
|
1812
|
-
return;
|
|
1813
|
-
let config = (_a = options.config) != null ? _a : {};
|
|
1814
|
-
if (options.configurable) {
|
|
1815
|
-
config = __spreadProps(__spreadValues({}, config), {
|
|
1816
|
-
configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
|
|
1817
|
-
});
|
|
1818
|
-
}
|
|
1819
|
-
copilotkit.setProperties(config);
|
|
1820
|
-
}, [options.config, options.configurable]);
|
|
1821
|
-
const externalStateStr = (0, import_react28.useMemo)(
|
|
1822
|
-
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
1823
|
-
[
|
|
1824
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0
|
|
1825
|
-
]
|
|
1826
|
-
);
|
|
1827
|
-
(0, import_react28.useEffect)(() => {
|
|
1828
|
-
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
1829
|
-
handleStateUpdate(options.state);
|
|
1830
|
-
}
|
|
1831
|
-
}, [agent, externalStateStr, handleStateUpdate]);
|
|
1832
|
-
const hasStateValues = (0, import_react28.useCallback)((value) => {
|
|
1833
|
-
return Boolean(value && Object.keys(value).length);
|
|
1834
|
-
}, []);
|
|
1835
|
-
const initialStateRef = (0, import_react28.useRef)(
|
|
1836
|
-
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
1837
|
-
);
|
|
1838
|
-
(0, import_react28.useEffect)(() => {
|
|
1839
|
-
if (isExternalStateManagement(options)) {
|
|
1840
|
-
initialStateRef.current = options.state;
|
|
1841
|
-
} else if ("initialState" in options) {
|
|
1842
|
-
initialStateRef.current = options.initialState;
|
|
1843
|
-
}
|
|
1844
|
-
}, [
|
|
1845
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
1846
|
-
]);
|
|
1847
|
-
(0, import_react28.useEffect)(() => {
|
|
1848
|
-
if (!agent)
|
|
1849
|
-
return;
|
|
1850
|
-
const subscriber = {
|
|
1851
|
-
onStateChanged: (args) => {
|
|
1852
|
-
if (isExternalStateManagement(options)) {
|
|
1853
|
-
options.setState(args.state);
|
|
1854
|
-
}
|
|
1855
|
-
},
|
|
1856
|
-
onRunInitialized: (args) => {
|
|
1857
|
-
const runHasState = hasStateValues(args.state);
|
|
1858
|
-
if (runHasState) {
|
|
1859
|
-
handleStateUpdate(args.state);
|
|
1860
|
-
return;
|
|
1861
|
-
}
|
|
1862
|
-
if (hasStateValues(agent.state)) {
|
|
1863
|
-
return;
|
|
1864
|
-
}
|
|
1865
|
-
if (initialStateRef.current !== void 0) {
|
|
1866
|
-
handleStateUpdate(initialStateRef.current);
|
|
1867
|
-
}
|
|
1868
|
-
}
|
|
1869
|
-
};
|
|
1870
|
-
const subscription = agent.subscribe(subscriber);
|
|
1871
|
-
return () => {
|
|
1872
|
-
subscription.unsubscribe();
|
|
1873
|
-
};
|
|
1874
|
-
}, [agent, handleStateUpdate, hasStateValues]);
|
|
1875
|
-
return (0, import_react28.useMemo)(() => {
|
|
1876
|
-
var _a, _b, _c;
|
|
1877
|
-
if (!agent) {
|
|
1878
|
-
const noop = () => {
|
|
1879
|
-
};
|
|
1880
|
-
const noopAsync = () => __async(this, null, function* () {
|
|
1881
|
-
});
|
|
1882
|
-
const initialState = (
|
|
1883
|
-
// prefer externally provided state if available
|
|
1884
|
-
(_b = (_a = "state" in options && options.state) != null ? _a : (
|
|
1885
|
-
// then initialState if provided
|
|
1886
|
-
"initialState" in options && options.initialState
|
|
1887
|
-
)) != null ? _b : {}
|
|
1888
|
-
);
|
|
1889
|
-
return {
|
|
1890
|
-
name: options.name,
|
|
1891
|
-
nodeName,
|
|
1892
|
-
threadId: void 0,
|
|
1893
|
-
running: false,
|
|
1894
|
-
state: initialState,
|
|
1895
|
-
setState: noop,
|
|
1896
|
-
start: noop,
|
|
1897
|
-
stop: noop,
|
|
1898
|
-
run: noopAsync
|
|
1899
|
-
};
|
|
1900
|
-
}
|
|
1901
|
-
return {
|
|
1902
|
-
name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
|
|
1903
|
-
nodeName,
|
|
1904
|
-
threadId: agent.threadId,
|
|
1905
|
-
running: agent.isRunning,
|
|
1906
|
-
state: agent.state,
|
|
1907
|
-
setState: handleStateUpdate,
|
|
1908
|
-
// TODO: start and run both have same thing. need to figure out
|
|
1909
|
-
start: agent.runAgent,
|
|
1910
|
-
stop: agent.abortRun,
|
|
1911
|
-
run: agent.runAgent
|
|
1912
|
-
};
|
|
1913
|
-
}, [
|
|
1914
|
-
agent == null ? void 0 : agent.state,
|
|
1915
|
-
agent == null ? void 0 : agent.runAgent,
|
|
1916
|
-
agent == null ? void 0 : agent.abortRun,
|
|
1917
|
-
agent == null ? void 0 : agent.runAgent,
|
|
1918
|
-
agent == null ? void 0 : agent.threadId,
|
|
1919
|
-
agent == null ? void 0 : agent.isRunning,
|
|
1920
|
-
agent == null ? void 0 : agent.agentId,
|
|
1921
|
-
handleStateUpdate,
|
|
1922
|
-
options.name
|
|
1923
|
-
]);
|
|
1924
|
-
}
|
|
1925
|
-
var isExternalStateManagement = (options) => {
|
|
1926
|
-
return "state" in options && "setState" in options;
|
|
1927
|
-
};
|
|
1928
|
-
|
|
1929
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
1930
|
-
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
1931
|
-
var import_react30 = require("react");
|
|
1932
|
-
var import_shared12 = require("@copilotkit/shared");
|
|
1933
|
-
var useCopilotRuntimeClient = (options) => {
|
|
1934
|
-
const { setBannerError } = useToast();
|
|
1935
|
-
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
1936
|
-
const lastStructuredErrorRef = (0, import_react30.useRef)(null);
|
|
1937
|
-
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
1938
|
-
try {
|
|
1939
|
-
const errorEvent = {
|
|
1940
|
-
type: "error",
|
|
1941
|
-
timestamp: Date.now(),
|
|
1942
|
-
context: {
|
|
1943
|
-
source: "ui",
|
|
1944
|
-
request: {
|
|
1945
|
-
operation: "runtimeClient",
|
|
1946
|
-
url: runtimeOptions.url,
|
|
1947
|
-
startTime: Date.now()
|
|
1948
|
-
},
|
|
1949
|
-
technical: {
|
|
1950
|
-
environment: "browser",
|
|
1951
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
1952
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
1953
|
-
}
|
|
1954
|
-
},
|
|
1955
|
-
error
|
|
1956
|
-
};
|
|
1957
|
-
yield onError(errorEvent);
|
|
1958
|
-
} catch (error2) {
|
|
1959
|
-
console.error("Error in onError handler:", error2);
|
|
1960
|
-
}
|
|
1961
|
-
});
|
|
1962
|
-
const runtimeClient = (0, import_react30.useMemo)(() => {
|
|
1963
|
-
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
1964
|
-
handleGQLErrors: (error) => {
|
|
1965
|
-
var _a2;
|
|
1966
|
-
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
1967
|
-
const graphQLErrors = error.graphQLErrors;
|
|
1968
|
-
const routeError = (gqlError) => {
|
|
1969
|
-
const extensions = gqlError.extensions;
|
|
1970
|
-
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
1971
|
-
if (visibility === import_shared12.ErrorVisibility.SILENT) {
|
|
1972
|
-
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
1973
|
-
return;
|
|
1974
|
-
}
|
|
1975
|
-
const now = Date.now();
|
|
1976
|
-
const errorMessage = gqlError.message;
|
|
1977
|
-
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
1978
|
-
return;
|
|
1979
|
-
}
|
|
1980
|
-
lastStructuredErrorRef.current = {
|
|
1981
|
-
message: errorMessage,
|
|
1982
|
-
timestamp: now
|
|
1983
|
-
};
|
|
1984
|
-
const ckError = createStructuredError(gqlError);
|
|
1985
|
-
if (ckError) {
|
|
1986
|
-
setBannerError(ckError);
|
|
1987
|
-
traceUIError(ckError, gqlError);
|
|
1988
|
-
} else {
|
|
1989
|
-
const fallbackError = new import_shared12.CopilotKitError({
|
|
1990
|
-
message: gqlError.message,
|
|
1991
|
-
code: import_shared12.CopilotKitErrorCode.UNKNOWN
|
|
1992
|
-
});
|
|
1993
|
-
setBannerError(fallbackError);
|
|
1994
|
-
traceUIError(fallbackError, gqlError);
|
|
1995
|
-
}
|
|
1996
|
-
};
|
|
1997
|
-
graphQLErrors.forEach(routeError);
|
|
1998
|
-
} else {
|
|
1999
|
-
const fallbackError = new import_shared12.CopilotKitError({
|
|
2000
|
-
message: (error == null ? void 0 : error.message) || String(error),
|
|
2001
|
-
code: import_shared12.CopilotKitErrorCode.UNKNOWN
|
|
2002
|
-
});
|
|
2003
|
-
setBannerError(fallbackError);
|
|
2004
|
-
traceUIError(fallbackError, error);
|
|
2005
|
-
}
|
|
2006
|
-
},
|
|
2007
|
-
handleGQLWarning: (message) => {
|
|
2008
|
-
console.warn(message);
|
|
2009
|
-
const warningError = new import_shared12.CopilotKitError({
|
|
2010
|
-
message,
|
|
2011
|
-
code: import_shared12.CopilotKitErrorCode.UNKNOWN
|
|
2012
|
-
});
|
|
2013
|
-
setBannerError(warningError);
|
|
2014
|
-
}
|
|
2015
|
-
}));
|
|
2016
|
-
}, [runtimeOptions, setBannerError, onError]);
|
|
2017
|
-
return runtimeClient;
|
|
2018
|
-
};
|
|
2019
|
-
function createStructuredError(gqlError) {
|
|
2020
|
-
var _a, _b, _c;
|
|
2021
|
-
const extensions = gqlError.extensions;
|
|
2022
|
-
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
2023
|
-
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
2024
|
-
const code = extensions == null ? void 0 : extensions.code;
|
|
2025
|
-
if (code) {
|
|
2026
|
-
return new import_shared12.CopilotKitError({ message, code });
|
|
2027
|
-
}
|
|
2028
|
-
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
2029
|
-
return new import_shared12.CopilotKitApiDiscoveryError({ message });
|
|
2030
|
-
}
|
|
2031
|
-
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
2032
|
-
return new import_shared12.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
2033
|
-
}
|
|
2034
|
-
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
2035
|
-
return new import_shared12.CopilotKitAgentDiscoveryError({
|
|
2036
|
-
agentName: "",
|
|
2037
|
-
availableAgents: []
|
|
2038
|
-
});
|
|
2039
|
-
}
|
|
2040
|
-
return null;
|
|
2041
|
-
}
|
|
2042
|
-
|
|
2043
|
-
// src/hooks/use-copilot-authenticated-action.ts
|
|
2044
|
-
var import_react31 = require("react");
|
|
2045
|
-
var import_react32 = __toESM(require("react"));
|
|
2046
|
-
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
2047
|
-
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
2048
|
-
const pendingActionRef = (0, import_react31.useRef)(null);
|
|
2049
|
-
const executeAction = (0, import_react31.useCallback)(
|
|
2050
|
-
(props) => {
|
|
2051
|
-
if (typeof action.render === "function") {
|
|
2052
|
-
return action.render(props);
|
|
2053
|
-
}
|
|
2054
|
-
return action.render || import_react32.default.createElement(import_react31.Fragment);
|
|
2055
|
-
},
|
|
2056
|
-
[action]
|
|
2057
|
-
);
|
|
2058
|
-
const wrappedRender = (0, import_react31.useCallback)(
|
|
2059
|
-
(props) => {
|
|
2060
|
-
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
2061
|
-
(state) => state.status === "authenticated"
|
|
2062
|
-
);
|
|
2063
|
-
if (!isAuthenticated) {
|
|
2064
|
-
pendingActionRef.current = props;
|
|
2065
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react32.default.createElement(authConfig_c.SignInComponent, {
|
|
2066
|
-
onSignInComplete: (authState) => {
|
|
2067
|
-
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
2068
|
-
[action.name]: authState
|
|
2069
|
-
}));
|
|
2070
|
-
if (pendingActionRef.current) {
|
|
2071
|
-
executeAction(pendingActionRef.current);
|
|
2072
|
-
pendingActionRef.current = null;
|
|
2073
|
-
}
|
|
2074
|
-
}
|
|
2075
|
-
}) : import_react32.default.createElement(import_react31.Fragment);
|
|
2076
|
-
}
|
|
2077
|
-
return executeAction(props);
|
|
2078
|
-
},
|
|
2079
|
-
[action, authStates_c, setAuthStates_c]
|
|
2080
|
-
);
|
|
2081
|
-
useCopilotAction(
|
|
2082
|
-
__spreadProps(__spreadValues({}, action), {
|
|
2083
|
-
render: wrappedRender
|
|
2084
|
-
}),
|
|
2085
|
-
dependencies
|
|
2086
|
-
);
|
|
2087
|
-
}
|
|
2088
|
-
|
|
2089
|
-
// src/hooks/use-langgraph-interrupt.ts
|
|
2090
|
-
var import_react33 = require("react");
|
|
2091
|
-
var import_shared13 = require("@copilotkit/shared");
|
|
2092
|
-
function useLangGraphInterrupt(action, dependencies) {
|
|
2093
|
-
const {
|
|
2094
|
-
setInterruptAction,
|
|
2095
|
-
removeInterruptAction,
|
|
2096
|
-
interruptActions,
|
|
2097
|
-
threadId
|
|
2098
|
-
} = (0, import_react33.useContext)(CopilotContext);
|
|
2099
|
-
const { addToast } = useToast();
|
|
2100
|
-
const actionId = (0, import_shared13.dataToUUID)(action, "lgAction");
|
|
2101
|
-
(0, import_react33.useEffect)(() => {
|
|
2102
|
-
if (!action)
|
|
2103
|
-
return;
|
|
2104
|
-
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
2105
|
-
return () => {
|
|
2106
|
-
removeInterruptAction(actionId);
|
|
2107
|
-
};
|
|
2108
|
-
}, [
|
|
2109
|
-
setInterruptAction,
|
|
2110
|
-
removeInterruptAction,
|
|
2111
|
-
threadId,
|
|
2112
|
-
actionId,
|
|
2113
|
-
...dependencies || []
|
|
2114
|
-
]);
|
|
2115
|
-
}
|
|
2116
|
-
|
|
2117
|
-
// src/hooks/use-copilot-additional-instructions.ts
|
|
2118
|
-
var import_react34 = require("react");
|
|
2119
|
-
function useCopilotAdditionalInstructions({
|
|
2120
|
-
instructions,
|
|
2121
|
-
available = "enabled"
|
|
2122
|
-
}, dependencies) {
|
|
2123
|
-
const { setAdditionalInstructions } = useCopilotContext();
|
|
2124
|
-
(0, import_react34.useEffect)(() => {
|
|
2125
|
-
if (available === "disabled")
|
|
2126
|
-
return;
|
|
2127
|
-
setAdditionalInstructions((prevInstructions) => [
|
|
2128
|
-
...prevInstructions || [],
|
|
2129
|
-
instructions
|
|
2130
|
-
]);
|
|
2131
|
-
return () => {
|
|
2132
|
-
setAdditionalInstructions(
|
|
2133
|
-
(prevInstructions) => (prevInstructions == null ? void 0 : prevInstructions.filter(
|
|
2134
|
-
(instruction) => instruction !== instructions
|
|
2135
|
-
)) || []
|
|
2136
|
-
);
|
|
2137
|
-
};
|
|
2138
|
-
}, [
|
|
2139
|
-
available,
|
|
2140
|
-
instructions,
|
|
2141
|
-
setAdditionalInstructions,
|
|
2142
|
-
...dependencies || []
|
|
2143
|
-
]);
|
|
2144
|
-
}
|
|
2145
|
-
|
|
2146
|
-
// src/hooks/use-default-tool.ts
|
|
2147
|
-
function useDefaultTool(tool, dependencies) {
|
|
2148
|
-
useCopilotAction(
|
|
2149
|
-
__spreadProps(__spreadValues({}, tool), { name: "*" }),
|
|
2150
|
-
dependencies
|
|
2151
|
-
);
|
|
2152
|
-
}
|
|
2153
|
-
|
|
2154
|
-
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
2155
|
-
var import_react35 = require("@copilotkitnext/react");
|
|
2156
|
-
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
2157
|
-
var _a, _b;
|
|
2158
|
-
const existingConfig = (0, import_react35.useCopilotChatConfiguration)();
|
|
2159
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
2160
|
-
const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
|
|
2161
|
-
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
2162
|
-
available,
|
|
2163
|
-
consumerAgentId: resolvedAgentId
|
|
2164
|
-
// Use chatConfig.agentId here
|
|
2165
|
-
});
|
|
2166
|
-
(0, import_react35.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
2167
|
-
}
|
|
2168
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
2169
|
-
0 && (module.exports = {
|
|
2170
|
-
useCoAgent,
|
|
2171
|
-
useCoAgentStateRender,
|
|
2172
|
-
useCopilotAction,
|
|
2173
|
-
useCopilotAdditionalInstructions,
|
|
2174
|
-
useCopilotAuthenticatedAction_c,
|
|
2175
|
-
useCopilotChat,
|
|
2176
|
-
useCopilotChatHeadless_c,
|
|
2177
|
-
useCopilotChatInternal,
|
|
2178
|
-
useCopilotChatSuggestions,
|
|
2179
|
-
useCopilotReadable,
|
|
2180
|
-
useCopilotRuntimeClient,
|
|
2181
|
-
useDefaultTool,
|
|
2182
|
-
useFrontendTool,
|
|
2183
|
-
useHumanInTheLoop,
|
|
2184
|
-
useLangGraphInterrupt,
|
|
2185
|
-
useLangGraphInterruptRender,
|
|
2186
|
-
useLazyToolRenderer,
|
|
2187
|
-
useMakeCopilotDocumentReadable,
|
|
2188
|
-
useRenderToolCall
|
|
2189
|
-
});
|
|
2190
|
-
//# sourceMappingURL=index.js.map
|