@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/index.js
DELETED
|
@@ -1,4064 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __defProps = Object.defineProperties;
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
8
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
9
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
10
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
11
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
-
var __spreadValues = (a, b) => {
|
|
15
|
-
for (var prop in b || (b = {}))
|
|
16
|
-
if (__hasOwnProp.call(b, prop))
|
|
17
|
-
__defNormalProp(a, prop, b[prop]);
|
|
18
|
-
if (__getOwnPropSymbols)
|
|
19
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
21
|
-
__defNormalProp(a, prop, b[prop]);
|
|
22
|
-
}
|
|
23
|
-
return a;
|
|
24
|
-
};
|
|
25
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
-
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
27
|
-
var __objRest = (source, exclude) => {
|
|
28
|
-
var target = {};
|
|
29
|
-
for (var prop in source)
|
|
30
|
-
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
31
|
-
target[prop] = source[prop];
|
|
32
|
-
if (source != null && __getOwnPropSymbols)
|
|
33
|
-
for (var prop of __getOwnPropSymbols(source)) {
|
|
34
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
35
|
-
target[prop] = source[prop];
|
|
36
|
-
}
|
|
37
|
-
return target;
|
|
38
|
-
};
|
|
39
|
-
var __export = (target, all) => {
|
|
40
|
-
for (var name in all)
|
|
41
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
42
|
-
};
|
|
43
|
-
var __copyProps = (to, from, except, desc) => {
|
|
44
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
45
|
-
for (let key of __getOwnPropNames(from))
|
|
46
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
47
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
48
|
-
}
|
|
49
|
-
return to;
|
|
50
|
-
};
|
|
51
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
52
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
53
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
54
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
55
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
56
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
57
|
-
mod
|
|
58
|
-
));
|
|
59
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
60
|
-
var __async = (__this, __arguments, generator) => {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
var fulfilled = (value) => {
|
|
63
|
-
try {
|
|
64
|
-
step(generator.next(value));
|
|
65
|
-
} catch (e) {
|
|
66
|
-
reject(e);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
var rejected = (value) => {
|
|
70
|
-
try {
|
|
71
|
-
step(generator.throw(value));
|
|
72
|
-
} catch (e) {
|
|
73
|
-
reject(e);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
77
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// src/index.tsx
|
|
82
|
-
var src_exports = {};
|
|
83
|
-
__export(src_exports, {
|
|
84
|
-
CoAgentStateRendersContext: () => CoAgentStateRendersContext,
|
|
85
|
-
CoAgentStateRendersProvider: () => CoAgentStateRendersProvider,
|
|
86
|
-
CopilotContext: () => CopilotContext,
|
|
87
|
-
CopilotKit: () => CopilotKit,
|
|
88
|
-
CopilotMessagesContext: () => CopilotMessagesContext,
|
|
89
|
-
CopilotTask: () => CopilotTask,
|
|
90
|
-
SUGGESTION_RETRY_CONFIG: () => SUGGESTION_RETRY_CONFIG,
|
|
91
|
-
ThreadsContext: () => ThreadsContext,
|
|
92
|
-
ThreadsProvider: () => ThreadsProvider,
|
|
93
|
-
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
94
|
-
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
95
|
-
useCoAgent: () => useCoAgent,
|
|
96
|
-
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
97
|
-
useCoAgentStateRenders: () => useCoAgentStateRenders,
|
|
98
|
-
useCopilotAction: () => useCopilotAction,
|
|
99
|
-
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
100
|
-
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
101
|
-
useCopilotChat: () => useCopilotChat,
|
|
102
|
-
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
|
|
103
|
-
useCopilotChatInternal: () => useCopilotChatInternal,
|
|
104
|
-
useCopilotChatSuggestions: () => useCopilotChatSuggestions,
|
|
105
|
-
useCopilotContext: () => useCopilotContext,
|
|
106
|
-
useCopilotMessagesContext: () => useCopilotMessagesContext,
|
|
107
|
-
useCopilotReadable: () => useCopilotReadable,
|
|
108
|
-
useCopilotRuntimeClient: () => useCopilotRuntimeClient,
|
|
109
|
-
useDefaultTool: () => useDefaultTool,
|
|
110
|
-
useFrontendTool: () => useFrontendTool,
|
|
111
|
-
useHumanInTheLoop: () => useHumanInTheLoop,
|
|
112
|
-
useLangGraphInterrupt: () => useLangGraphInterrupt,
|
|
113
|
-
useLangGraphInterruptRender: () => useLangGraphInterruptRender,
|
|
114
|
-
useLazyToolRenderer: () => useLazyToolRenderer,
|
|
115
|
-
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable,
|
|
116
|
-
useRenderToolCall: () => useRenderToolCall2,
|
|
117
|
-
useThreads: () => useThreads
|
|
118
|
-
});
|
|
119
|
-
module.exports = __toCommonJS(src_exports);
|
|
120
|
-
|
|
121
|
-
// src/components/copilot-provider/copilotkit.tsx
|
|
122
|
-
var import_react16 = require("react");
|
|
123
|
-
var import_react17 = require("@copilotkitnext/react");
|
|
124
|
-
|
|
125
|
-
// src/context/copilot-context.tsx
|
|
126
|
-
var import_react = __toESM(require("react"));
|
|
127
|
-
var emptyCopilotContext = {
|
|
128
|
-
actions: {},
|
|
129
|
-
setAction: () => {
|
|
130
|
-
},
|
|
131
|
-
removeAction: () => {
|
|
132
|
-
},
|
|
133
|
-
setRegisteredActions: () => "",
|
|
134
|
-
removeRegisteredAction: () => {
|
|
135
|
-
},
|
|
136
|
-
chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },
|
|
137
|
-
getContextString: (documents, categories) => returnAndThrowInDebug(""),
|
|
138
|
-
addContext: () => "",
|
|
139
|
-
removeContext: () => {
|
|
140
|
-
},
|
|
141
|
-
getAllContext: () => [],
|
|
142
|
-
getFunctionCallHandler: () => returnAndThrowInDebug(() => __async(void 0, null, function* () {
|
|
143
|
-
})),
|
|
144
|
-
isLoading: false,
|
|
145
|
-
setIsLoading: () => returnAndThrowInDebug(false),
|
|
146
|
-
chatInstructions: "",
|
|
147
|
-
setChatInstructions: () => returnAndThrowInDebug(""),
|
|
148
|
-
additionalInstructions: [],
|
|
149
|
-
setAdditionalInstructions: () => returnAndThrowInDebug([]),
|
|
150
|
-
getDocumentsContext: (categories) => returnAndThrowInDebug([]),
|
|
151
|
-
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
152
|
-
removeDocumentContext: () => {
|
|
153
|
-
},
|
|
154
|
-
copilotApiConfig: new class {
|
|
155
|
-
get chatApiEndpoint() {
|
|
156
|
-
throw new Error(
|
|
157
|
-
"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!"
|
|
158
|
-
);
|
|
159
|
-
}
|
|
160
|
-
get headers() {
|
|
161
|
-
return {};
|
|
162
|
-
}
|
|
163
|
-
get body() {
|
|
164
|
-
return {};
|
|
165
|
-
}
|
|
166
|
-
}(),
|
|
167
|
-
chatSuggestionConfiguration: {},
|
|
168
|
-
addChatSuggestionConfiguration: () => {
|
|
169
|
-
},
|
|
170
|
-
removeChatSuggestionConfiguration: () => {
|
|
171
|
-
},
|
|
172
|
-
showDevConsole: false,
|
|
173
|
-
coagentStates: {},
|
|
174
|
-
setCoagentStates: () => {
|
|
175
|
-
},
|
|
176
|
-
coagentStatesRef: { current: {} },
|
|
177
|
-
setCoagentStatesWithRef: () => {
|
|
178
|
-
},
|
|
179
|
-
agentSession: null,
|
|
180
|
-
setAgentSession: () => {
|
|
181
|
-
},
|
|
182
|
-
forwardedParameters: {},
|
|
183
|
-
agentLock: null,
|
|
184
|
-
threadId: "",
|
|
185
|
-
setThreadId: () => {
|
|
186
|
-
},
|
|
187
|
-
runId: null,
|
|
188
|
-
setRunId: () => {
|
|
189
|
-
},
|
|
190
|
-
chatAbortControllerRef: { current: null },
|
|
191
|
-
availableAgents: [],
|
|
192
|
-
extensions: {},
|
|
193
|
-
setExtensions: () => {
|
|
194
|
-
},
|
|
195
|
-
interruptActions: {},
|
|
196
|
-
setInterruptAction: () => {
|
|
197
|
-
},
|
|
198
|
-
removeInterruptAction: () => {
|
|
199
|
-
},
|
|
200
|
-
interruptEventQueue: {},
|
|
201
|
-
addInterruptEvent: () => {
|
|
202
|
-
},
|
|
203
|
-
resolveInterruptEvent: () => {
|
|
204
|
-
},
|
|
205
|
-
onError: () => {
|
|
206
|
-
},
|
|
207
|
-
bannerError: null,
|
|
208
|
-
setBannerError: () => {
|
|
209
|
-
},
|
|
210
|
-
internalErrorHandlers: {},
|
|
211
|
-
setInternalErrorHandler: () => {
|
|
212
|
-
},
|
|
213
|
-
removeInternalErrorHandler: () => {
|
|
214
|
-
}
|
|
215
|
-
};
|
|
216
|
-
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
217
|
-
function useCopilotContext() {
|
|
218
|
-
const context = import_react.default.useContext(CopilotContext);
|
|
219
|
-
if (context === emptyCopilotContext) {
|
|
220
|
-
throw new Error(
|
|
221
|
-
"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!"
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
return context;
|
|
225
|
-
}
|
|
226
|
-
function returnAndThrowInDebug(_value) {
|
|
227
|
-
throw new Error(
|
|
228
|
-
"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!"
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// src/hooks/use-tree.ts
|
|
233
|
-
var import_shared = require("@copilotkit/shared");
|
|
234
|
-
var import_react2 = require("react");
|
|
235
|
-
var removeNode = (nodes, id) => {
|
|
236
|
-
return nodes.reduce((result, node) => {
|
|
237
|
-
if (node.id !== id) {
|
|
238
|
-
const newNode = __spreadProps(__spreadValues({}, node), { children: removeNode(node.children, id) });
|
|
239
|
-
result.push(newNode);
|
|
240
|
-
}
|
|
241
|
-
return result;
|
|
242
|
-
}, []);
|
|
243
|
-
};
|
|
244
|
-
var addNode = (nodes, newNode, parentId) => {
|
|
245
|
-
if (!parentId) {
|
|
246
|
-
return [...nodes, newNode];
|
|
247
|
-
}
|
|
248
|
-
return nodes.map((node) => {
|
|
249
|
-
if (node.id === parentId) {
|
|
250
|
-
return __spreadProps(__spreadValues({}, node), { children: [...node.children, newNode] });
|
|
251
|
-
} else if (node.children.length) {
|
|
252
|
-
return __spreadProps(__spreadValues({}, node), { children: addNode(node.children, newNode, parentId) });
|
|
253
|
-
}
|
|
254
|
-
return node;
|
|
255
|
-
});
|
|
256
|
-
};
|
|
257
|
-
var treeIndentationRepresentation = (index, indentLevel) => {
|
|
258
|
-
if (indentLevel === 0) {
|
|
259
|
-
return (index + 1).toString();
|
|
260
|
-
} else if (indentLevel === 1) {
|
|
261
|
-
return String.fromCharCode(65 + index);
|
|
262
|
-
} else if (indentLevel === 2) {
|
|
263
|
-
return String.fromCharCode(97 + index);
|
|
264
|
-
} else {
|
|
265
|
-
return "-";
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
var printNode = (node, prefix = "", indentLevel = 0) => {
|
|
269
|
-
const indent = " ".repeat(3).repeat(indentLevel);
|
|
270
|
-
const prefixPlusIndentLength = prefix.length + indent.length;
|
|
271
|
-
const subsequentLinesPrefix = " ".repeat(prefixPlusIndentLength);
|
|
272
|
-
const valueLines = node.value.split("\n");
|
|
273
|
-
const outputFirstLine = `${indent}${prefix}${valueLines[0]}`;
|
|
274
|
-
const outputSubsequentLines = valueLines.slice(1).map((line) => `${subsequentLinesPrefix}${line}`).join("\n");
|
|
275
|
-
let output = `${outputFirstLine}
|
|
276
|
-
`;
|
|
277
|
-
if (outputSubsequentLines) {
|
|
278
|
-
output += `${outputSubsequentLines}
|
|
279
|
-
`;
|
|
280
|
-
}
|
|
281
|
-
const childPrePrefix = " ".repeat(prefix.length);
|
|
282
|
-
node.children.forEach(
|
|
283
|
-
(child, index) => output += printNode(
|
|
284
|
-
child,
|
|
285
|
-
`${childPrePrefix}${treeIndentationRepresentation(index, indentLevel + 1)}. `,
|
|
286
|
-
indentLevel + 1
|
|
287
|
-
)
|
|
288
|
-
);
|
|
289
|
-
return output;
|
|
290
|
-
};
|
|
291
|
-
function treeReducer(state, action) {
|
|
292
|
-
switch (action.type) {
|
|
293
|
-
case "ADD_NODE": {
|
|
294
|
-
const { value, parentId, id: newNodeId } = action;
|
|
295
|
-
const newNode = {
|
|
296
|
-
id: newNodeId,
|
|
297
|
-
value,
|
|
298
|
-
children: [],
|
|
299
|
-
categories: new Set(action.categories)
|
|
300
|
-
};
|
|
301
|
-
try {
|
|
302
|
-
return addNode(state, newNode, parentId);
|
|
303
|
-
} catch (error) {
|
|
304
|
-
console.error(`Error while adding node with id ${newNodeId}: ${error}`);
|
|
305
|
-
return state;
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
case "REMOVE_NODE":
|
|
309
|
-
return removeNode(state, action.id);
|
|
310
|
-
default:
|
|
311
|
-
return state;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
var useTree = () => {
|
|
315
|
-
const [tree, dispatch] = (0, import_react2.useReducer)(treeReducer, []);
|
|
316
|
-
const addElement = (0, import_react2.useCallback)(
|
|
317
|
-
(value, categories, parentId) => {
|
|
318
|
-
const newNodeId = (0, import_shared.randomId)();
|
|
319
|
-
dispatch({
|
|
320
|
-
type: "ADD_NODE",
|
|
321
|
-
value,
|
|
322
|
-
parentId,
|
|
323
|
-
id: newNodeId,
|
|
324
|
-
categories
|
|
325
|
-
});
|
|
326
|
-
return newNodeId;
|
|
327
|
-
},
|
|
328
|
-
[]
|
|
329
|
-
);
|
|
330
|
-
const removeElement = (0, import_react2.useCallback)((id) => {
|
|
331
|
-
dispatch({ type: "REMOVE_NODE", id });
|
|
332
|
-
}, []);
|
|
333
|
-
const getAllElements = (0, import_react2.useCallback)(() => {
|
|
334
|
-
return tree;
|
|
335
|
-
}, [tree]);
|
|
336
|
-
const printTree = (0, import_react2.useCallback)(
|
|
337
|
-
(categories) => {
|
|
338
|
-
const categoriesSet = new Set(categories);
|
|
339
|
-
let output = "";
|
|
340
|
-
tree.forEach((node, index) => {
|
|
341
|
-
if (!setsHaveIntersection(categoriesSet, node.categories)) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
if (index !== 0) {
|
|
345
|
-
output += "\n";
|
|
346
|
-
}
|
|
347
|
-
output += printNode(
|
|
348
|
-
node,
|
|
349
|
-
`${treeIndentationRepresentation(index, 0)}. `
|
|
350
|
-
);
|
|
351
|
-
});
|
|
352
|
-
return output;
|
|
353
|
-
},
|
|
354
|
-
[tree]
|
|
355
|
-
);
|
|
356
|
-
return { tree, addElement, printTree, removeElement, getAllElements };
|
|
357
|
-
};
|
|
358
|
-
var use_tree_default = useTree;
|
|
359
|
-
function setsHaveIntersection(setA, setB) {
|
|
360
|
-
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
361
|
-
for (let item of smallerSet) {
|
|
362
|
-
if (largerSet.has(item)) {
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
return false;
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
// src/components/copilot-provider/copilotkit.tsx
|
|
370
|
-
var import_react_dom = require("react-dom");
|
|
371
|
-
var import_shared13 = require("@copilotkit/shared");
|
|
372
|
-
|
|
373
|
-
// src/hooks/use-flat-category-store.ts
|
|
374
|
-
var import_react3 = require("react");
|
|
375
|
-
var import_shared2 = require("@copilotkit/shared");
|
|
376
|
-
var useFlatCategoryStore = () => {
|
|
377
|
-
const [elements, dispatch] = (0, import_react3.useReducer)(
|
|
378
|
-
flatCategoryStoreReducer,
|
|
379
|
-
/* @__PURE__ */ new Map()
|
|
380
|
-
);
|
|
381
|
-
const addElement = (0, import_react3.useCallback)(
|
|
382
|
-
(value, categories) => {
|
|
383
|
-
const newId = (0, import_shared2.randomId)();
|
|
384
|
-
dispatch({
|
|
385
|
-
type: "ADD_ELEMENT",
|
|
386
|
-
value,
|
|
387
|
-
id: newId,
|
|
388
|
-
categories
|
|
389
|
-
});
|
|
390
|
-
return newId;
|
|
391
|
-
},
|
|
392
|
-
[]
|
|
393
|
-
);
|
|
394
|
-
const removeElement = (0, import_react3.useCallback)((id) => {
|
|
395
|
-
dispatch({ type: "REMOVE_ELEMENT", id });
|
|
396
|
-
}, []);
|
|
397
|
-
const allElements = (0, import_react3.useCallback)(
|
|
398
|
-
(categories) => {
|
|
399
|
-
const categoriesSet = new Set(categories);
|
|
400
|
-
const result = [];
|
|
401
|
-
elements.forEach((element) => {
|
|
402
|
-
if (setsHaveIntersection2(categoriesSet, element.categories)) {
|
|
403
|
-
result.push(element.value);
|
|
404
|
-
}
|
|
405
|
-
});
|
|
406
|
-
return result;
|
|
407
|
-
},
|
|
408
|
-
[elements]
|
|
409
|
-
);
|
|
410
|
-
return { addElement, removeElement, allElements };
|
|
411
|
-
};
|
|
412
|
-
var use_flat_category_store_default = useFlatCategoryStore;
|
|
413
|
-
function flatCategoryStoreReducer(state, action) {
|
|
414
|
-
switch (action.type) {
|
|
415
|
-
case "ADD_ELEMENT": {
|
|
416
|
-
const { value, id, categories } = action;
|
|
417
|
-
const newElement = {
|
|
418
|
-
id,
|
|
419
|
-
value,
|
|
420
|
-
categories: new Set(categories)
|
|
421
|
-
};
|
|
422
|
-
const newState = new Map(state);
|
|
423
|
-
newState.set(id, newElement);
|
|
424
|
-
return newState;
|
|
425
|
-
}
|
|
426
|
-
case "REMOVE_ELEMENT": {
|
|
427
|
-
const newState = new Map(state);
|
|
428
|
-
newState.delete(action.id);
|
|
429
|
-
return newState;
|
|
430
|
-
}
|
|
431
|
-
default:
|
|
432
|
-
return state;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
function setsHaveIntersection2(setA, setB) {
|
|
436
|
-
const [smallerSet, largerSet] = setA.size <= setB.size ? [setA, setB] : [setB, setA];
|
|
437
|
-
for (let item of smallerSet) {
|
|
438
|
-
if (largerSet.has(item)) {
|
|
439
|
-
return true;
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
return false;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
// src/components/copilot-provider/copilot-messages.tsx
|
|
446
|
-
var import_react6 = require("react");
|
|
447
|
-
|
|
448
|
-
// src/context/copilot-messages-context.tsx
|
|
449
|
-
var import_react4 = __toESM(require("react"));
|
|
450
|
-
var emptyCopilotContext2 = {
|
|
451
|
-
messages: [],
|
|
452
|
-
setMessages: () => [],
|
|
453
|
-
// suggestions state
|
|
454
|
-
suggestions: [],
|
|
455
|
-
setSuggestions: () => []
|
|
456
|
-
};
|
|
457
|
-
var CopilotMessagesContext = import_react4.default.createContext(emptyCopilotContext2);
|
|
458
|
-
function useCopilotMessagesContext() {
|
|
459
|
-
const context = import_react4.default.useContext(CopilotMessagesContext);
|
|
460
|
-
if (context === emptyCopilotContext2) {
|
|
461
|
-
throw new Error(
|
|
462
|
-
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
return context;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
// src/components/toast/toast-provider.tsx
|
|
469
|
-
var import_react5 = require("react");
|
|
470
|
-
var import_shared3 = require("@copilotkit/shared");
|
|
471
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
472
|
-
var ToastContext = (0, import_react5.createContext)(void 0);
|
|
473
|
-
function getErrorSeverity(error) {
|
|
474
|
-
if (error.severity) {
|
|
475
|
-
switch (error.severity) {
|
|
476
|
-
case import_shared3.Severity.CRITICAL:
|
|
477
|
-
return "critical";
|
|
478
|
-
case import_shared3.Severity.WARNING:
|
|
479
|
-
return "warning";
|
|
480
|
-
case import_shared3.Severity.INFO:
|
|
481
|
-
return "info";
|
|
482
|
-
default:
|
|
483
|
-
return "info";
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
const message = error.message.toLowerCase();
|
|
487
|
-
if (message.includes("api key") || message.includes("401") || message.includes("unauthorized") || message.includes("authentication") || message.includes("incorrect api key")) {
|
|
488
|
-
return "critical";
|
|
489
|
-
}
|
|
490
|
-
return "info";
|
|
491
|
-
}
|
|
492
|
-
function getErrorColors(severity) {
|
|
493
|
-
switch (severity) {
|
|
494
|
-
case "critical":
|
|
495
|
-
return {
|
|
496
|
-
background: "#fee2e2",
|
|
497
|
-
border: "#dc2626",
|
|
498
|
-
text: "#7f1d1d",
|
|
499
|
-
icon: "#dc2626"
|
|
500
|
-
};
|
|
501
|
-
case "warning":
|
|
502
|
-
return {
|
|
503
|
-
background: "#fef3c7",
|
|
504
|
-
border: "#d97706",
|
|
505
|
-
text: "#78350f",
|
|
506
|
-
icon: "#d97706"
|
|
507
|
-
};
|
|
508
|
-
case "info":
|
|
509
|
-
return {
|
|
510
|
-
background: "#dbeafe",
|
|
511
|
-
border: "#2563eb",
|
|
512
|
-
text: "#1e3a8a",
|
|
513
|
-
icon: "#2563eb"
|
|
514
|
-
};
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
function useToast() {
|
|
518
|
-
const context = (0, import_react5.useContext)(ToastContext);
|
|
519
|
-
if (!context) {
|
|
520
|
-
throw new Error("useToast must be used within a ToastProvider");
|
|
521
|
-
}
|
|
522
|
-
return context;
|
|
523
|
-
}
|
|
524
|
-
function ToastProvider({
|
|
525
|
-
enabled,
|
|
526
|
-
children
|
|
527
|
-
}) {
|
|
528
|
-
const [toasts, setToasts] = (0, import_react5.useState)([]);
|
|
529
|
-
const [bannerError, setBannerErrorState] = (0, import_react5.useState)(
|
|
530
|
-
null
|
|
531
|
-
);
|
|
532
|
-
const removeToast = (0, import_react5.useCallback)((id) => {
|
|
533
|
-
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
534
|
-
}, []);
|
|
535
|
-
const addToast = (0, import_react5.useCallback)(
|
|
536
|
-
(toast) => {
|
|
537
|
-
var _a;
|
|
538
|
-
if (!enabled) {
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
|
|
542
|
-
setToasts((currentToasts) => {
|
|
543
|
-
if (currentToasts.find((toast2) => toast2.id === id))
|
|
544
|
-
return currentToasts;
|
|
545
|
-
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
546
|
-
});
|
|
547
|
-
if (toast.duration) {
|
|
548
|
-
setTimeout(() => {
|
|
549
|
-
removeToast(id);
|
|
550
|
-
}, toast.duration);
|
|
551
|
-
}
|
|
552
|
-
},
|
|
553
|
-
[enabled, removeToast]
|
|
554
|
-
);
|
|
555
|
-
const setBannerError = (0, import_react5.useCallback)(
|
|
556
|
-
(error) => {
|
|
557
|
-
if (!enabled && error !== null) {
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
setBannerErrorState(error);
|
|
561
|
-
},
|
|
562
|
-
[enabled]
|
|
563
|
-
);
|
|
564
|
-
const addGraphQLErrorsToast = (0, import_react5.useCallback)((errors) => {
|
|
565
|
-
console.warn(
|
|
566
|
-
"addGraphQLErrorsToast is deprecated. All errors now show as banners."
|
|
567
|
-
);
|
|
568
|
-
}, []);
|
|
569
|
-
const value = {
|
|
570
|
-
toasts,
|
|
571
|
-
addToast,
|
|
572
|
-
addGraphQLErrorsToast,
|
|
573
|
-
removeToast,
|
|
574
|
-
enabled,
|
|
575
|
-
bannerError,
|
|
576
|
-
setBannerError
|
|
577
|
-
};
|
|
578
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(ToastContext.Provider, { value, children: [
|
|
579
|
-
bannerError && (() => {
|
|
580
|
-
const severity = getErrorSeverity(bannerError);
|
|
581
|
-
const colors = getErrorColors(severity);
|
|
582
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
583
|
-
"div",
|
|
584
|
-
{
|
|
585
|
-
style: {
|
|
586
|
-
position: "fixed",
|
|
587
|
-
bottom: "20px",
|
|
588
|
-
left: "50%",
|
|
589
|
-
transform: "translateX(-50%)",
|
|
590
|
-
zIndex: 9999,
|
|
591
|
-
backgroundColor: colors.background,
|
|
592
|
-
border: `1px solid ${colors.border}`,
|
|
593
|
-
borderLeft: `4px solid ${colors.border}`,
|
|
594
|
-
borderRadius: "8px",
|
|
595
|
-
padding: "12px 16px",
|
|
596
|
-
fontSize: "13px",
|
|
597
|
-
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.15)",
|
|
598
|
-
backdropFilter: "blur(8px)",
|
|
599
|
-
maxWidth: "min(90vw, 700px)",
|
|
600
|
-
width: "100%",
|
|
601
|
-
boxSizing: "border-box",
|
|
602
|
-
overflow: "hidden"
|
|
603
|
-
},
|
|
604
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
605
|
-
"div",
|
|
606
|
-
{
|
|
607
|
-
style: {
|
|
608
|
-
display: "flex",
|
|
609
|
-
justifyContent: "space-between",
|
|
610
|
-
alignItems: "center",
|
|
611
|
-
gap: "10px"
|
|
612
|
-
},
|
|
613
|
-
children: [
|
|
614
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
615
|
-
"div",
|
|
616
|
-
{
|
|
617
|
-
style: {
|
|
618
|
-
display: "flex",
|
|
619
|
-
alignItems: "center",
|
|
620
|
-
gap: "8px",
|
|
621
|
-
flex: 1,
|
|
622
|
-
minWidth: 0
|
|
623
|
-
},
|
|
624
|
-
children: [
|
|
625
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
626
|
-
"div",
|
|
627
|
-
{
|
|
628
|
-
style: {
|
|
629
|
-
width: "12px",
|
|
630
|
-
height: "12px",
|
|
631
|
-
borderRadius: "50%",
|
|
632
|
-
backgroundColor: colors.border,
|
|
633
|
-
flexShrink: 0
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
),
|
|
637
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
638
|
-
"div",
|
|
639
|
-
{
|
|
640
|
-
style: {
|
|
641
|
-
display: "flex",
|
|
642
|
-
alignItems: "center",
|
|
643
|
-
gap: "10px",
|
|
644
|
-
flex: 1,
|
|
645
|
-
minWidth: 0
|
|
646
|
-
},
|
|
647
|
-
children: [
|
|
648
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
649
|
-
"div",
|
|
650
|
-
{
|
|
651
|
-
style: {
|
|
652
|
-
color: colors.text,
|
|
653
|
-
lineHeight: "1.4",
|
|
654
|
-
fontWeight: "400",
|
|
655
|
-
fontSize: "13px",
|
|
656
|
-
flex: 1,
|
|
657
|
-
wordBreak: "break-all",
|
|
658
|
-
overflowWrap: "break-word",
|
|
659
|
-
maxWidth: "550px",
|
|
660
|
-
overflow: "hidden",
|
|
661
|
-
display: "-webkit-box",
|
|
662
|
-
WebkitLineClamp: 10,
|
|
663
|
-
WebkitBoxOrient: "vertical"
|
|
664
|
-
},
|
|
665
|
-
children: (() => {
|
|
666
|
-
let message = bannerError.message;
|
|
667
|
-
const jsonMatch = message.match(
|
|
668
|
-
/'message':\s*'([^']+)'/
|
|
669
|
-
);
|
|
670
|
-
if (jsonMatch) {
|
|
671
|
-
return jsonMatch[1];
|
|
672
|
-
}
|
|
673
|
-
message = message.split(" - ")[0];
|
|
674
|
-
message = message.split(": Error code")[0];
|
|
675
|
-
message = message.replace(/:\s*\d{3}$/, "");
|
|
676
|
-
message = message.replace(/See more:.*$/g, "");
|
|
677
|
-
message = message.trim();
|
|
678
|
-
return message || "Configuration error occurred.";
|
|
679
|
-
})()
|
|
680
|
-
}
|
|
681
|
-
),
|
|
682
|
-
(() => {
|
|
683
|
-
const message = bannerError.message;
|
|
684
|
-
const markdownLinkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
685
|
-
const plainUrlRegex = /(https?:\/\/[^\s)]+)/g;
|
|
686
|
-
let url = null;
|
|
687
|
-
let buttonText = "See More";
|
|
688
|
-
const markdownMatch = markdownLinkRegex.exec(message);
|
|
689
|
-
if (markdownMatch) {
|
|
690
|
-
url = markdownMatch[2];
|
|
691
|
-
buttonText = "See More";
|
|
692
|
-
} else {
|
|
693
|
-
const urlMatch = plainUrlRegex.exec(message);
|
|
694
|
-
if (urlMatch) {
|
|
695
|
-
url = urlMatch[0].replace(/[.,;:'"]*$/, "");
|
|
696
|
-
buttonText = "See More";
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
if (!url)
|
|
700
|
-
return null;
|
|
701
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
702
|
-
"button",
|
|
703
|
-
{
|
|
704
|
-
onClick: () => window.open(url, "_blank", "noopener,noreferrer"),
|
|
705
|
-
style: {
|
|
706
|
-
background: colors.border,
|
|
707
|
-
color: "white",
|
|
708
|
-
border: "none",
|
|
709
|
-
borderRadius: "5px",
|
|
710
|
-
padding: "4px 10px",
|
|
711
|
-
fontSize: "11px",
|
|
712
|
-
fontWeight: "500",
|
|
713
|
-
cursor: "pointer",
|
|
714
|
-
transition: "all 0.2s ease",
|
|
715
|
-
flexShrink: 0
|
|
716
|
-
},
|
|
717
|
-
onMouseEnter: (e) => {
|
|
718
|
-
e.currentTarget.style.opacity = "0.9";
|
|
719
|
-
e.currentTarget.style.transform = "translateY(-1px)";
|
|
720
|
-
},
|
|
721
|
-
onMouseLeave: (e) => {
|
|
722
|
-
e.currentTarget.style.opacity = "1";
|
|
723
|
-
e.currentTarget.style.transform = "translateY(0)";
|
|
724
|
-
},
|
|
725
|
-
children: buttonText
|
|
726
|
-
}
|
|
727
|
-
);
|
|
728
|
-
})()
|
|
729
|
-
]
|
|
730
|
-
}
|
|
731
|
-
)
|
|
732
|
-
]
|
|
733
|
-
}
|
|
734
|
-
),
|
|
735
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
736
|
-
"button",
|
|
737
|
-
{
|
|
738
|
-
onClick: () => setBannerError(null),
|
|
739
|
-
style: {
|
|
740
|
-
background: "transparent",
|
|
741
|
-
border: "none",
|
|
742
|
-
color: colors.text,
|
|
743
|
-
cursor: "pointer",
|
|
744
|
-
padding: "2px",
|
|
745
|
-
borderRadius: "3px",
|
|
746
|
-
fontSize: "14px",
|
|
747
|
-
lineHeight: "1",
|
|
748
|
-
opacity: 0.6,
|
|
749
|
-
transition: "all 0.2s ease",
|
|
750
|
-
flexShrink: 0
|
|
751
|
-
},
|
|
752
|
-
title: "Dismiss",
|
|
753
|
-
onMouseEnter: (e) => {
|
|
754
|
-
e.currentTarget.style.opacity = "1";
|
|
755
|
-
e.currentTarget.style.background = "rgba(0, 0, 0, 0.05)";
|
|
756
|
-
},
|
|
757
|
-
onMouseLeave: (e) => {
|
|
758
|
-
e.currentTarget.style.opacity = "0.6";
|
|
759
|
-
e.currentTarget.style.background = "transparent";
|
|
760
|
-
},
|
|
761
|
-
children: "\xD7"
|
|
762
|
-
}
|
|
763
|
-
)
|
|
764
|
-
]
|
|
765
|
-
}
|
|
766
|
-
)
|
|
767
|
-
}
|
|
768
|
-
);
|
|
769
|
-
})(),
|
|
770
|
-
children
|
|
771
|
-
] });
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// src/utils/dev-console.ts
|
|
775
|
-
function isLocalhost() {
|
|
776
|
-
if (typeof window === "undefined")
|
|
777
|
-
return false;
|
|
778
|
-
return window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "0.0.0.0";
|
|
779
|
-
}
|
|
780
|
-
function shouldShowDevConsole(showDevConsole) {
|
|
781
|
-
if (showDevConsole !== void 0) {
|
|
782
|
-
return showDevConsole;
|
|
783
|
-
}
|
|
784
|
-
return isLocalhost();
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
// src/components/copilot-provider/copilot-messages.tsx
|
|
788
|
-
var import_shared4 = require("@copilotkit/shared");
|
|
789
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
790
|
-
var MessagesTapContext = (0, import_react6.createContext)(null);
|
|
791
|
-
function useMessagesTap() {
|
|
792
|
-
const tap = (0, import_react6.useContext)(MessagesTapContext);
|
|
793
|
-
if (!tap)
|
|
794
|
-
throw new Error("useMessagesTap must be used inside <MessagesTapProvider>");
|
|
795
|
-
return tap;
|
|
796
|
-
}
|
|
797
|
-
function MessagesTapProvider({
|
|
798
|
-
children
|
|
799
|
-
}) {
|
|
800
|
-
const messagesRef = (0, import_react6.useRef)([]);
|
|
801
|
-
const tapRef = (0, import_react6.useRef)({
|
|
802
|
-
getMessagesFromTap: () => messagesRef.current,
|
|
803
|
-
updateTapMessages: (messages) => {
|
|
804
|
-
messagesRef.current = messages;
|
|
805
|
-
}
|
|
806
|
-
});
|
|
807
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MessagesTapContext.Provider, { value: tapRef.current, children });
|
|
808
|
-
}
|
|
809
|
-
function CopilotMessages({ children }) {
|
|
810
|
-
const [messages, setMessages] = (0, import_react6.useState)([]);
|
|
811
|
-
const lastLoadedThreadId = (0, import_react6.useRef)(void 0);
|
|
812
|
-
const lastLoadedAgentName = (0, import_react6.useRef)(void 0);
|
|
813
|
-
const lastLoadedMessages = (0, import_react6.useRef)(void 0);
|
|
814
|
-
const { updateTapMessages } = useMessagesTap();
|
|
815
|
-
const { threadId, agentSession, showDevConsole, onError, copilotApiConfig } = useCopilotContext();
|
|
816
|
-
const { setBannerError } = useToast();
|
|
817
|
-
const traceUIError = (0, import_react6.useCallback)(
|
|
818
|
-
(error, originalError) => __async(this, null, function* () {
|
|
819
|
-
if (!onError || !copilotApiConfig.publicApiKey)
|
|
820
|
-
return;
|
|
821
|
-
try {
|
|
822
|
-
const traceEvent = {
|
|
823
|
-
type: "error",
|
|
824
|
-
timestamp: Date.now(),
|
|
825
|
-
context: {
|
|
826
|
-
source: "ui",
|
|
827
|
-
request: {
|
|
828
|
-
operation: "loadAgentState",
|
|
829
|
-
url: copilotApiConfig.chatApiEndpoint,
|
|
830
|
-
startTime: Date.now()
|
|
831
|
-
},
|
|
832
|
-
technical: {
|
|
833
|
-
environment: "browser",
|
|
834
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
835
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
836
|
-
}
|
|
837
|
-
},
|
|
838
|
-
error
|
|
839
|
-
};
|
|
840
|
-
yield onError(traceEvent);
|
|
841
|
-
} catch (traceError) {
|
|
842
|
-
console.error("Error in CopilotMessages onError handler:", traceError);
|
|
843
|
-
}
|
|
844
|
-
}),
|
|
845
|
-
[onError, copilotApiConfig.publicApiKey, copilotApiConfig.chatApiEndpoint]
|
|
846
|
-
);
|
|
847
|
-
const createStructuredError2 = (gqlError) => {
|
|
848
|
-
const extensions = gqlError.extensions;
|
|
849
|
-
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
850
|
-
if (originalError == null ? void 0 : originalError.stack) {
|
|
851
|
-
if (originalError.stack.includes("CopilotApiDiscoveryError")) {
|
|
852
|
-
return new import_shared4.CopilotKitApiDiscoveryError({
|
|
853
|
-
message: originalError.message
|
|
854
|
-
});
|
|
855
|
-
}
|
|
856
|
-
if (originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
857
|
-
return new import_shared4.CopilotKitRemoteEndpointDiscoveryError({
|
|
858
|
-
message: originalError.message
|
|
859
|
-
});
|
|
860
|
-
}
|
|
861
|
-
if (originalError.stack.includes("CopilotKitAgentDiscoveryError")) {
|
|
862
|
-
return new import_shared4.CopilotKitAgentDiscoveryError({
|
|
863
|
-
agentName: "",
|
|
864
|
-
availableAgents: []
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
869
|
-
const code = extensions == null ? void 0 : extensions.code;
|
|
870
|
-
if (code) {
|
|
871
|
-
return new import_shared4.CopilotKitError({ message, code });
|
|
872
|
-
}
|
|
873
|
-
return null;
|
|
874
|
-
};
|
|
875
|
-
const handleGraphQLErrors = (0, import_react6.useCallback)(
|
|
876
|
-
(error) => {
|
|
877
|
-
var _a;
|
|
878
|
-
if ((_a = error.graphQLErrors) == null ? void 0 : _a.length) {
|
|
879
|
-
const graphQLErrors = error.graphQLErrors;
|
|
880
|
-
const routeError = (gqlError) => {
|
|
881
|
-
const extensions = gqlError.extensions;
|
|
882
|
-
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
883
|
-
const isDev = shouldShowDevConsole(showDevConsole);
|
|
884
|
-
if (!isDev) {
|
|
885
|
-
console.error(
|
|
886
|
-
"CopilotKit Error (hidden in production):",
|
|
887
|
-
gqlError.message
|
|
888
|
-
);
|
|
889
|
-
return;
|
|
890
|
-
}
|
|
891
|
-
if (visibility === import_shared4.ErrorVisibility.SILENT) {
|
|
892
|
-
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
893
|
-
return;
|
|
894
|
-
}
|
|
895
|
-
const ckError = createStructuredError2(gqlError);
|
|
896
|
-
if (ckError) {
|
|
897
|
-
setBannerError(ckError);
|
|
898
|
-
traceUIError(ckError, gqlError);
|
|
899
|
-
} else {
|
|
900
|
-
const fallbackError = new import_shared4.CopilotKitError({
|
|
901
|
-
message: gqlError.message,
|
|
902
|
-
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
903
|
-
});
|
|
904
|
-
setBannerError(fallbackError);
|
|
905
|
-
traceUIError(fallbackError, gqlError);
|
|
906
|
-
}
|
|
907
|
-
};
|
|
908
|
-
graphQLErrors.forEach(routeError);
|
|
909
|
-
} else {
|
|
910
|
-
const isDev = shouldShowDevConsole(showDevConsole);
|
|
911
|
-
if (!isDev) {
|
|
912
|
-
console.error("CopilotKit Error (hidden in production):", error);
|
|
913
|
-
} else {
|
|
914
|
-
const fallbackError = new import_shared4.CopilotKitError({
|
|
915
|
-
message: (error == null ? void 0 : error.message) || String(error),
|
|
916
|
-
code: import_shared4.CopilotKitErrorCode.UNKNOWN
|
|
917
|
-
});
|
|
918
|
-
setBannerError(fallbackError);
|
|
919
|
-
traceUIError(fallbackError, error);
|
|
920
|
-
}
|
|
921
|
-
}
|
|
922
|
-
},
|
|
923
|
-
[setBannerError, showDevConsole, traceUIError]
|
|
924
|
-
);
|
|
925
|
-
(0, import_react6.useEffect)(() => {
|
|
926
|
-
updateTapMessages(messages);
|
|
927
|
-
}, [messages, updateTapMessages]);
|
|
928
|
-
const memoizedChildren = (0, import_react6.useMemo)(() => children, [children]);
|
|
929
|
-
const [suggestions, setSuggestions] = (0, import_react6.useState)([]);
|
|
930
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
931
|
-
CopilotMessagesContext.Provider,
|
|
932
|
-
{
|
|
933
|
-
value: {
|
|
934
|
-
messages,
|
|
935
|
-
setMessages,
|
|
936
|
-
suggestions,
|
|
937
|
-
setSuggestions
|
|
938
|
-
},
|
|
939
|
-
children: memoizedChildren
|
|
940
|
-
}
|
|
941
|
-
);
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
// src/components/usage-banner.tsx
|
|
945
|
-
var import_shared5 = require("@copilotkit/shared");
|
|
946
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
947
|
-
function UsageBanner({
|
|
948
|
-
severity = import_shared5.Severity.CRITICAL,
|
|
949
|
-
message = "",
|
|
950
|
-
onClose,
|
|
951
|
-
actions
|
|
952
|
-
}) {
|
|
953
|
-
if (!message || !severity) {
|
|
954
|
-
return null;
|
|
955
|
-
}
|
|
956
|
-
const themes = {
|
|
957
|
-
[import_shared5.Severity.INFO]: {
|
|
958
|
-
bg: "#f8fafc",
|
|
959
|
-
border: "#e2e8f0",
|
|
960
|
-
text: "#475569",
|
|
961
|
-
accent: "#3b82f6"
|
|
962
|
-
},
|
|
963
|
-
[import_shared5.Severity.WARNING]: {
|
|
964
|
-
bg: "#fffbeb",
|
|
965
|
-
border: "#fbbf24",
|
|
966
|
-
text: "#92400e",
|
|
967
|
-
accent: "#f59e0b"
|
|
968
|
-
},
|
|
969
|
-
[import_shared5.Severity.CRITICAL]: {
|
|
970
|
-
bg: "#fef2f2",
|
|
971
|
-
border: "#fecaca",
|
|
972
|
-
text: "#dc2626",
|
|
973
|
-
accent: "#ef4444"
|
|
974
|
-
}
|
|
975
|
-
};
|
|
976
|
-
const theme = themes[severity];
|
|
977
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
|
|
978
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("style", { children: `
|
|
979
|
-
@keyframes slideUp {
|
|
980
|
-
from { opacity: 0; transform: translateX(-50%) translateY(8px); }
|
|
981
|
-
to { opacity: 1; transform: translateX(-50%) translateY(0); }
|
|
982
|
-
}
|
|
983
|
-
|
|
984
|
-
.usage-banner {
|
|
985
|
-
position: fixed;
|
|
986
|
-
bottom: 24px;
|
|
987
|
-
left: 50%;
|
|
988
|
-
transform: translateX(-50%);
|
|
989
|
-
width: min(600px, calc(100vw - 32px));
|
|
990
|
-
z-index: 10000;
|
|
991
|
-
animation: slideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
.banner-content {
|
|
995
|
-
background: linear-gradient(135deg, ${theme.bg} 0%, ${theme.bg}f5 100%);
|
|
996
|
-
border: 1px solid ${theme.border};
|
|
997
|
-
border-radius: 12px;
|
|
998
|
-
padding: 18px 20px;
|
|
999
|
-
box-shadow:
|
|
1000
|
-
0 4px 24px rgba(0, 0, 0, 0.08),
|
|
1001
|
-
0 2px 8px rgba(0, 0, 0, 0.04),
|
|
1002
|
-
inset 0 1px 0 rgba(255, 255, 255, 0.7);
|
|
1003
|
-
display: flex;
|
|
1004
|
-
align-items: center;
|
|
1005
|
-
gap: 16px;
|
|
1006
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
|
|
1007
|
-
backdrop-filter: blur(12px);
|
|
1008
|
-
position: relative;
|
|
1009
|
-
overflow: hidden;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
.banner-content::before {
|
|
1013
|
-
content: '';
|
|
1014
|
-
position: absolute;
|
|
1015
|
-
top: 0;
|
|
1016
|
-
left: 0;
|
|
1017
|
-
right: 0;
|
|
1018
|
-
height: 1px;
|
|
1019
|
-
background: linear-gradient(90deg, transparent, ${theme.accent}40, transparent);
|
|
1020
|
-
}
|
|
1021
|
-
|
|
1022
|
-
.banner-message {
|
|
1023
|
-
color: ${theme.text};
|
|
1024
|
-
font-size: 14px;
|
|
1025
|
-
line-height: 1.5;
|
|
1026
|
-
font-weight: 500;
|
|
1027
|
-
flex: 1;
|
|
1028
|
-
letter-spacing: -0.01em;
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
.close-btn {
|
|
1032
|
-
background: rgba(0, 0, 0, 0.05);
|
|
1033
|
-
border: none;
|
|
1034
|
-
color: ${theme.text};
|
|
1035
|
-
cursor: pointer;
|
|
1036
|
-
padding: 0;
|
|
1037
|
-
border-radius: 6px;
|
|
1038
|
-
opacity: 0.6;
|
|
1039
|
-
transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1040
|
-
font-size: 14px;
|
|
1041
|
-
line-height: 1;
|
|
1042
|
-
flex-shrink: 0;
|
|
1043
|
-
width: 24px;
|
|
1044
|
-
height: 24px;
|
|
1045
|
-
display: flex;
|
|
1046
|
-
align-items: center;
|
|
1047
|
-
justify-content: center;
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
.close-btn:hover {
|
|
1051
|
-
opacity: 1;
|
|
1052
|
-
background: rgba(0, 0, 0, 0.08);
|
|
1053
|
-
transform: scale(1.05);
|
|
1054
|
-
}
|
|
1055
|
-
|
|
1056
|
-
.btn-primary {
|
|
1057
|
-
background: linear-gradient(135deg, ${theme.accent} 0%, ${theme.accent}e6 100%);
|
|
1058
|
-
color: white;
|
|
1059
|
-
border: none;
|
|
1060
|
-
border-radius: 8px;
|
|
1061
|
-
padding: 10px 18px;
|
|
1062
|
-
font-size: 13px;
|
|
1063
|
-
font-weight: 600;
|
|
1064
|
-
cursor: pointer;
|
|
1065
|
-
transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1066
|
-
font-family: inherit;
|
|
1067
|
-
flex-shrink: 0;
|
|
1068
|
-
box-shadow:
|
|
1069
|
-
0 2px 8px ${theme.accent}30,
|
|
1070
|
-
inset 0 1px 0 rgba(255, 255, 255, 0.2);
|
|
1071
|
-
letter-spacing: -0.01em;
|
|
1072
|
-
}
|
|
1073
|
-
|
|
1074
|
-
.btn-primary:hover {
|
|
1075
|
-
transform: translateY(-1px) scale(1.02);
|
|
1076
|
-
box-shadow:
|
|
1077
|
-
0 4px 12px ${theme.accent}40,
|
|
1078
|
-
inset 0 1px 0 rgba(255, 255, 255, 0.25);
|
|
1079
|
-
}
|
|
1080
|
-
|
|
1081
|
-
.btn-primary:active {
|
|
1082
|
-
transform: translateY(0) scale(0.98);
|
|
1083
|
-
transition: all 0.08s cubic-bezier(0.16, 1, 0.3, 1);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
@media (max-width: 640px) {
|
|
1087
|
-
.usage-banner {
|
|
1088
|
-
width: calc(100vw - 24px);
|
|
1089
|
-
}
|
|
1090
|
-
|
|
1091
|
-
.banner-content {
|
|
1092
|
-
padding: 16px;
|
|
1093
|
-
gap: 12px;
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
.banner-message {
|
|
1097
|
-
font-size: 13px;
|
|
1098
|
-
line-height: 1.45;
|
|
1099
|
-
}
|
|
1100
|
-
|
|
1101
|
-
.btn-primary {
|
|
1102
|
-
padding: 8px 14px;
|
|
1103
|
-
font-size: 12px;
|
|
1104
|
-
}
|
|
1105
|
-
|
|
1106
|
-
.close-btn {
|
|
1107
|
-
width: 22px;
|
|
1108
|
-
height: 22px;
|
|
1109
|
-
font-size: 12px;
|
|
1110
|
-
}
|
|
1111
|
-
}
|
|
1112
|
-
` }),
|
|
1113
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "usage-banner", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "banner-content", children: [
|
|
1114
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "banner-message", children: message }),
|
|
1115
|
-
(actions == null ? void 0 : actions.primary) && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "btn-primary", onClick: actions.primary.onClick, children: actions.primary.label }),
|
|
1116
|
-
onClose && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("button", { className: "close-btn", onClick: onClose, title: "Close", children: "\xD7" })
|
|
1117
|
-
] }) })
|
|
1118
|
-
] });
|
|
1119
|
-
}
|
|
1120
|
-
var getErrorActions = (error) => {
|
|
1121
|
-
switch (error.code) {
|
|
1122
|
-
case import_shared5.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR:
|
|
1123
|
-
return {
|
|
1124
|
-
primary: {
|
|
1125
|
-
label: "Show me how",
|
|
1126
|
-
onClick: () => window.open(
|
|
1127
|
-
"https://docs.copilotkit.ai/premium#how-do-i-get-access-to-premium-features",
|
|
1128
|
-
"_blank",
|
|
1129
|
-
"noopener,noreferrer"
|
|
1130
|
-
)
|
|
1131
|
-
}
|
|
1132
|
-
};
|
|
1133
|
-
case import_shared5.CopilotKitErrorCode.UPGRADE_REQUIRED_ERROR:
|
|
1134
|
-
return {
|
|
1135
|
-
primary: {
|
|
1136
|
-
label: "Upgrade",
|
|
1137
|
-
onClick: () => window.open(
|
|
1138
|
-
"https://cloud.copilotkit.ai",
|
|
1139
|
-
"_blank",
|
|
1140
|
-
"noopener,noreferrer"
|
|
1141
|
-
)
|
|
1142
|
-
}
|
|
1143
|
-
};
|
|
1144
|
-
default:
|
|
1145
|
-
return void 0;
|
|
1146
|
-
}
|
|
1147
|
-
};
|
|
1148
|
-
|
|
1149
|
-
// src/utils/suggestions-constants.ts
|
|
1150
|
-
var SUGGESTION_RETRY_CONFIG = {
|
|
1151
|
-
MAX_RETRIES: 3,
|
|
1152
|
-
COOLDOWN_MS: 5e3
|
|
1153
|
-
// 5 seconds
|
|
1154
|
-
};
|
|
1155
|
-
|
|
1156
|
-
// src/components/error-boundary/error-boundary.tsx
|
|
1157
|
-
var import_react8 = __toESM(require("react"));
|
|
1158
|
-
var import_shared7 = require("@copilotkit/shared");
|
|
1159
|
-
|
|
1160
|
-
// src/lib/status-checker.ts
|
|
1161
|
-
var import_shared6 = require("@copilotkit/shared");
|
|
1162
|
-
var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
1163
|
-
var StatusChecker = class {
|
|
1164
|
-
constructor() {
|
|
1165
|
-
this.activeKey = null;
|
|
1166
|
-
this.intervalId = null;
|
|
1167
|
-
this.instanceCount = 0;
|
|
1168
|
-
this.lastResponse = null;
|
|
1169
|
-
}
|
|
1170
|
-
start(publicApiKey, onUpdate) {
|
|
1171
|
-
return __async(this, null, function* () {
|
|
1172
|
-
this.instanceCount++;
|
|
1173
|
-
if (this.activeKey === publicApiKey)
|
|
1174
|
-
return;
|
|
1175
|
-
if (this.intervalId)
|
|
1176
|
-
clearInterval(this.intervalId);
|
|
1177
|
-
const checkStatus = () => __async(this, null, function* () {
|
|
1178
|
-
try {
|
|
1179
|
-
const response = yield fetch(`${import_shared6.COPILOT_CLOUD_API_URL}/ciu`, {
|
|
1180
|
-
method: "GET",
|
|
1181
|
-
headers: {
|
|
1182
|
-
[import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
1183
|
-
}
|
|
1184
|
-
}).then((response2) => response2.json());
|
|
1185
|
-
this.lastResponse = response;
|
|
1186
|
-
onUpdate == null ? void 0 : onUpdate(response);
|
|
1187
|
-
return response;
|
|
1188
|
-
} catch (error) {
|
|
1189
|
-
return null;
|
|
1190
|
-
}
|
|
1191
|
-
});
|
|
1192
|
-
const initialResponse = yield checkStatus();
|
|
1193
|
-
this.intervalId = setInterval(checkStatus, STATUS_CHECK_INTERVAL);
|
|
1194
|
-
this.activeKey = publicApiKey;
|
|
1195
|
-
return initialResponse;
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
getLastResponse() {
|
|
1199
|
-
return this.lastResponse;
|
|
1200
|
-
}
|
|
1201
|
-
stop() {
|
|
1202
|
-
this.instanceCount--;
|
|
1203
|
-
if (this.instanceCount === 0) {
|
|
1204
|
-
if (this.intervalId) {
|
|
1205
|
-
clearInterval(this.intervalId);
|
|
1206
|
-
this.intervalId = null;
|
|
1207
|
-
this.activeKey = null;
|
|
1208
|
-
this.lastResponse = null;
|
|
1209
|
-
}
|
|
1210
|
-
}
|
|
1211
|
-
}
|
|
1212
|
-
};
|
|
1213
|
-
|
|
1214
|
-
// src/components/error-boundary/error-utils.tsx
|
|
1215
|
-
var import_react7 = require("react");
|
|
1216
|
-
|
|
1217
|
-
// src/components/toast/exclamation-mark-icon.tsx
|
|
1218
|
-
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1219
|
-
var ExclamationMarkIcon = ({
|
|
1220
|
-
className,
|
|
1221
|
-
style
|
|
1222
|
-
}) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
1223
|
-
"svg",
|
|
1224
|
-
{
|
|
1225
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
1226
|
-
width: "24",
|
|
1227
|
-
height: "24",
|
|
1228
|
-
viewBox: "0 0 24 24",
|
|
1229
|
-
fill: "none",
|
|
1230
|
-
stroke: "currentColor",
|
|
1231
|
-
strokeWidth: "2",
|
|
1232
|
-
strokeLinecap: "round",
|
|
1233
|
-
strokeLinejoin: "round",
|
|
1234
|
-
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
1235
|
-
style,
|
|
1236
|
-
children: [
|
|
1237
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
1238
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
1239
|
-
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
1240
|
-
]
|
|
1241
|
-
}
|
|
1242
|
-
);
|
|
1243
|
-
|
|
1244
|
-
// src/components/error-boundary/error-utils.tsx
|
|
1245
|
-
var import_react_markdown = __toESM(require("react-markdown"));
|
|
1246
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1247
|
-
function ErrorToast({ errors }) {
|
|
1248
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
1249
|
-
var _a, _b, _c;
|
|
1250
|
-
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
1251
|
-
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
1252
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
1253
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1254
|
-
"div",
|
|
1255
|
-
{
|
|
1256
|
-
style: {
|
|
1257
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
1258
|
-
marginBottom: 14
|
|
1259
|
-
},
|
|
1260
|
-
children: [
|
|
1261
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
1262
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1263
|
-
"div",
|
|
1264
|
-
{
|
|
1265
|
-
style: {
|
|
1266
|
-
fontWeight: "600",
|
|
1267
|
-
marginBottom: 4
|
|
1268
|
-
},
|
|
1269
|
-
children: [
|
|
1270
|
-
"Copilot Runtime Error:",
|
|
1271
|
-
" ",
|
|
1272
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
1273
|
-
]
|
|
1274
|
-
}
|
|
1275
|
-
),
|
|
1276
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_markdown.default, { children: message })
|
|
1277
|
-
]
|
|
1278
|
-
},
|
|
1279
|
-
idx
|
|
1280
|
-
);
|
|
1281
|
-
});
|
|
1282
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1283
|
-
"div",
|
|
1284
|
-
{
|
|
1285
|
-
style: {
|
|
1286
|
-
fontSize: "13px",
|
|
1287
|
-
maxWidth: "600px"
|
|
1288
|
-
},
|
|
1289
|
-
children: [
|
|
1290
|
-
errorsToRender,
|
|
1291
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
1292
|
-
]
|
|
1293
|
-
}
|
|
1294
|
-
);
|
|
1295
|
-
}
|
|
1296
|
-
function useErrorToast() {
|
|
1297
|
-
const { addToast } = useToast();
|
|
1298
|
-
return (0, import_react7.useCallback)(
|
|
1299
|
-
(errors) => {
|
|
1300
|
-
const errorId = errors.map((err) => {
|
|
1301
|
-
var _a, _b;
|
|
1302
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
1303
|
-
const stack = err.stack || "";
|
|
1304
|
-
return btoa(message + stack).slice(0, 32);
|
|
1305
|
-
}).join("|");
|
|
1306
|
-
addToast({
|
|
1307
|
-
type: "error",
|
|
1308
|
-
id: errorId,
|
|
1309
|
-
// Toast libraries typically dedupe by id
|
|
1310
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast, { errors })
|
|
1311
|
-
});
|
|
1312
|
-
},
|
|
1313
|
-
[addToast]
|
|
1314
|
-
);
|
|
1315
|
-
}
|
|
1316
|
-
function useAsyncCallback(callback, deps) {
|
|
1317
|
-
const addErrorToast = useErrorToast();
|
|
1318
|
-
return (0, import_react7.useCallback)((...args) => __async(this, null, function* () {
|
|
1319
|
-
try {
|
|
1320
|
-
return yield callback(...args);
|
|
1321
|
-
} catch (error) {
|
|
1322
|
-
console.error("Error in async callback:", error);
|
|
1323
|
-
addErrorToast([error]);
|
|
1324
|
-
throw error;
|
|
1325
|
-
}
|
|
1326
|
-
}), deps);
|
|
1327
|
-
}
|
|
1328
|
-
|
|
1329
|
-
// src/components/error-boundary/error-boundary.tsx
|
|
1330
|
-
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
1331
|
-
var statusChecker = new StatusChecker();
|
|
1332
|
-
var CopilotErrorBoundary = class extends import_react8.default.Component {
|
|
1333
|
-
constructor(props) {
|
|
1334
|
-
super(props);
|
|
1335
|
-
this.state = {
|
|
1336
|
-
hasError: false
|
|
1337
|
-
};
|
|
1338
|
-
}
|
|
1339
|
-
static getDerivedStateFromError(error) {
|
|
1340
|
-
return { hasError: true, error };
|
|
1341
|
-
}
|
|
1342
|
-
componentDidMount() {
|
|
1343
|
-
if (this.props.publicApiKey) {
|
|
1344
|
-
statusChecker.start(this.props.publicApiKey, (newStatus) => {
|
|
1345
|
-
this.setState((prevState) => {
|
|
1346
|
-
var _a;
|
|
1347
|
-
if ((newStatus == null ? void 0 : newStatus.severity) !== ((_a = prevState.status) == null ? void 0 : _a.severity)) {
|
|
1348
|
-
return { status: newStatus != null ? newStatus : void 0 };
|
|
1349
|
-
}
|
|
1350
|
-
return null;
|
|
1351
|
-
});
|
|
1352
|
-
});
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
componentWillUnmount() {
|
|
1356
|
-
statusChecker.stop();
|
|
1357
|
-
}
|
|
1358
|
-
componentDidCatch(error, errorInfo) {
|
|
1359
|
-
console.error("CopilotKit Error:", error, errorInfo);
|
|
1360
|
-
}
|
|
1361
|
-
render() {
|
|
1362
|
-
var _a, _b, _c, _d;
|
|
1363
|
-
if (this.state.hasError) {
|
|
1364
|
-
if (this.state.error instanceof import_shared7.CopilotKitError) {
|
|
1365
|
-
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [
|
|
1366
|
-
this.props.children,
|
|
1367
|
-
this.props.showUsageBanner && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
1368
|
-
UsageBanner,
|
|
1369
|
-
{
|
|
1370
|
-
severity: (_b = (_a = this.state.status) == null ? void 0 : _a.severity) != null ? _b : this.state.error.severity,
|
|
1371
|
-
message: (_d = (_c = this.state.status) == null ? void 0 : _c.message) != null ? _d : this.state.error.message,
|
|
1372
|
-
actions: getErrorActions(this.state.error)
|
|
1373
|
-
}
|
|
1374
|
-
)
|
|
1375
|
-
] });
|
|
1376
|
-
}
|
|
1377
|
-
throw this.state.error;
|
|
1378
|
-
}
|
|
1379
|
-
return this.props.children;
|
|
1380
|
-
}
|
|
1381
|
-
};
|
|
1382
|
-
|
|
1383
|
-
// src/context/coagent-state-renders-context.tsx
|
|
1384
|
-
var import_react9 = require("react");
|
|
1385
|
-
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
1386
|
-
var CoAgentStateRendersContext = (0, import_react9.createContext)(void 0);
|
|
1387
|
-
function CoAgentStateRendersProvider({
|
|
1388
|
-
children
|
|
1389
|
-
}) {
|
|
1390
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react9.useState)({});
|
|
1391
|
-
const setCoAgentStateRender = (0, import_react9.useCallback)(
|
|
1392
|
-
(id, stateRender) => {
|
|
1393
|
-
setCoAgentStateRenders((prevPoints) => __spreadProps(__spreadValues({}, prevPoints), {
|
|
1394
|
-
[id]: stateRender
|
|
1395
|
-
}));
|
|
1396
|
-
},
|
|
1397
|
-
[]
|
|
1398
|
-
);
|
|
1399
|
-
const removeCoAgentStateRender = (0, import_react9.useCallback)((id) => {
|
|
1400
|
-
setCoAgentStateRenders((prevPoints) => {
|
|
1401
|
-
const newPoints = __spreadValues({}, prevPoints);
|
|
1402
|
-
delete newPoints[id];
|
|
1403
|
-
return newPoints;
|
|
1404
|
-
});
|
|
1405
|
-
}, []);
|
|
1406
|
-
const claimsRef = (0, import_react9.useRef)({});
|
|
1407
|
-
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
1408
|
-
CoAgentStateRendersContext.Provider,
|
|
1409
|
-
{
|
|
1410
|
-
value: {
|
|
1411
|
-
coAgentStateRenders,
|
|
1412
|
-
setCoAgentStateRender,
|
|
1413
|
-
removeCoAgentStateRender,
|
|
1414
|
-
claimsRef
|
|
1415
|
-
},
|
|
1416
|
-
children
|
|
1417
|
-
}
|
|
1418
|
-
);
|
|
1419
|
-
}
|
|
1420
|
-
function useCoAgentStateRenders() {
|
|
1421
|
-
const context = (0, import_react9.useContext)(CoAgentStateRendersContext);
|
|
1422
|
-
if (!context) {
|
|
1423
|
-
throw new Error(
|
|
1424
|
-
"useCoAgentStateRenders must be used within CoAgentStateRendersProvider"
|
|
1425
|
-
);
|
|
1426
|
-
}
|
|
1427
|
-
return context;
|
|
1428
|
-
}
|
|
1429
|
-
|
|
1430
|
-
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
1431
|
-
var import_react12 = require("@copilotkitnext/react");
|
|
1432
|
-
var import_react13 = require("react");
|
|
1433
|
-
|
|
1434
|
-
// src/context/threads-context.tsx
|
|
1435
|
-
var import_react10 = require("react");
|
|
1436
|
-
var import_shared8 = require("@copilotkit/shared");
|
|
1437
|
-
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1438
|
-
var ThreadsContext = (0, import_react10.createContext)(
|
|
1439
|
-
void 0
|
|
1440
|
-
);
|
|
1441
|
-
function ThreadsProvider({
|
|
1442
|
-
children,
|
|
1443
|
-
threadId: explicitThreadId
|
|
1444
|
-
}) {
|
|
1445
|
-
const [internalThreadId, setThreadId] = (0, import_react10.useState)(() => (0, import_shared8.randomUUID)());
|
|
1446
|
-
const threadId = explicitThreadId != null ? explicitThreadId : internalThreadId;
|
|
1447
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
1448
|
-
ThreadsContext.Provider,
|
|
1449
|
-
{
|
|
1450
|
-
value: {
|
|
1451
|
-
threadId,
|
|
1452
|
-
setThreadId
|
|
1453
|
-
},
|
|
1454
|
-
children
|
|
1455
|
-
}
|
|
1456
|
-
);
|
|
1457
|
-
}
|
|
1458
|
-
function useThreads() {
|
|
1459
|
-
const context = (0, import_react10.useContext)(ThreadsContext);
|
|
1460
|
-
if (!context) {
|
|
1461
|
-
throw new Error("useThreads must be used within ThreadsProvider");
|
|
1462
|
-
}
|
|
1463
|
-
return context;
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
1467
|
-
var import_shared10 = require("@copilotkit/shared");
|
|
1468
|
-
|
|
1469
|
-
// src/hooks/use-coagent-state-render-bridge.helpers.ts
|
|
1470
|
-
var import_shared9 = require("@copilotkit/shared");
|
|
1471
|
-
function getStateWithoutConstantKeys(state) {
|
|
1472
|
-
if (!state)
|
|
1473
|
-
return {};
|
|
1474
|
-
const _a = state, { messages, tools, copilotkit } = _a, stateWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
1475
|
-
return stateWithoutConstantKeys;
|
|
1476
|
-
}
|
|
1477
|
-
function areStatesEquals(a, b) {
|
|
1478
|
-
if (a && !b || !a && b)
|
|
1479
|
-
return false;
|
|
1480
|
-
const _a = a, { messages, tools, copilotkit } = _a, aWithoutConstantKeys = __objRest(_a, ["messages", "tools", "copilotkit"]);
|
|
1481
|
-
const _b = b, {
|
|
1482
|
-
messages: bMessages,
|
|
1483
|
-
tools: bTools,
|
|
1484
|
-
copilotkit: bCopilotkit
|
|
1485
|
-
} = _b, bWithoutConstantKeys = __objRest(_b, [
|
|
1486
|
-
"messages",
|
|
1487
|
-
"tools",
|
|
1488
|
-
"copilotkit"
|
|
1489
|
-
]);
|
|
1490
|
-
return JSON.stringify(aWithoutConstantKeys) === JSON.stringify(bWithoutConstantKeys);
|
|
1491
|
-
}
|
|
1492
|
-
function isPlaceholderMessageId(messageId) {
|
|
1493
|
-
return !!messageId && messageId.startsWith("coagent-state-render-");
|
|
1494
|
-
}
|
|
1495
|
-
function isPlaceholderMessageName(messageName) {
|
|
1496
|
-
return messageName === "coagent-state-render";
|
|
1497
|
-
}
|
|
1498
|
-
function readCachedMessageEntry(entry) {
|
|
1499
|
-
if (!entry || typeof entry !== "object") {
|
|
1500
|
-
return { snapshot: entry, runId: void 0 };
|
|
1501
|
-
}
|
|
1502
|
-
const snapshot = "snapshot" in entry ? entry.snapshot : entry;
|
|
1503
|
-
const runId = "runId" in entry ? entry.runId : void 0;
|
|
1504
|
-
return { snapshot, runId };
|
|
1505
|
-
}
|
|
1506
|
-
function getEffectiveRunId({
|
|
1507
|
-
existingClaimRunId,
|
|
1508
|
-
cachedMessageRunId,
|
|
1509
|
-
runId
|
|
1510
|
-
}) {
|
|
1511
|
-
return existingClaimRunId || cachedMessageRunId || runId || "pending";
|
|
1512
|
-
}
|
|
1513
|
-
function resolveClaim({
|
|
1514
|
-
claims,
|
|
1515
|
-
context,
|
|
1516
|
-
stateSnapshot
|
|
1517
|
-
}) {
|
|
1518
|
-
const { messageId, stateRenderId, runId, messageIndex } = context;
|
|
1519
|
-
const existing = claims[messageId];
|
|
1520
|
-
if (existing) {
|
|
1521
|
-
const canRender = existing.stateRenderId === stateRenderId;
|
|
1522
|
-
const shouldUpdateRunId = canRender && runId && (!existing.runId || existing.runId === "pending");
|
|
1523
|
-
return {
|
|
1524
|
-
canRender,
|
|
1525
|
-
action: canRender ? "existing" /* Existing */ : "block" /* Block */,
|
|
1526
|
-
updateRunId: shouldUpdateRunId ? runId : void 0
|
|
1527
|
-
};
|
|
1528
|
-
}
|
|
1529
|
-
const normalizedRunId = runId != null ? runId : "pending";
|
|
1530
|
-
const renderClaimedByOtherMessageEntry = Object.entries(claims).find(
|
|
1531
|
-
([, claim]) => {
|
|
1532
|
-
var _a;
|
|
1533
|
-
return claim.stateRenderId === stateRenderId && ((_a = claim.runId) != null ? _a : "pending") === normalizedRunId && (0, import_shared9.dataToUUID)(getStateWithoutConstantKeys(claim.stateSnapshot)) === (0, import_shared9.dataToUUID)(getStateWithoutConstantKeys(stateSnapshot));
|
|
1534
|
-
}
|
|
1535
|
-
);
|
|
1536
|
-
const renderClaimedByOtherMessage = renderClaimedByOtherMessageEntry == null ? void 0 : renderClaimedByOtherMessageEntry[1];
|
|
1537
|
-
const claimedMessageId = renderClaimedByOtherMessageEntry == null ? void 0 : renderClaimedByOtherMessageEntry[0];
|
|
1538
|
-
if (renderClaimedByOtherMessage) {
|
|
1539
|
-
if (messageIndex !== void 0 && renderClaimedByOtherMessage.messageIndex !== void 0 && messageIndex > renderClaimedByOtherMessage.messageIndex) {
|
|
1540
|
-
return {
|
|
1541
|
-
canRender: true,
|
|
1542
|
-
action: "override" /* Override */,
|
|
1543
|
-
nextClaim: { stateRenderId, runId, messageIndex },
|
|
1544
|
-
lockOthers: runId === renderClaimedByOtherMessage.runId || isPlaceholderMessageId(claimedMessageId)
|
|
1545
|
-
};
|
|
1546
|
-
}
|
|
1547
|
-
if (runId && renderClaimedByOtherMessage.runId && runId !== renderClaimedByOtherMessage.runId) {
|
|
1548
|
-
return {
|
|
1549
|
-
canRender: true,
|
|
1550
|
-
action: "override" /* Override */,
|
|
1551
|
-
nextClaim: { stateRenderId, runId, messageIndex },
|
|
1552
|
-
lockOthers: isPlaceholderMessageId(claimedMessageId)
|
|
1553
|
-
};
|
|
1554
|
-
}
|
|
1555
|
-
if (isPlaceholderMessageId(claimedMessageId)) {
|
|
1556
|
-
return {
|
|
1557
|
-
canRender: true,
|
|
1558
|
-
action: "override" /* Override */,
|
|
1559
|
-
nextClaim: { stateRenderId, runId, messageIndex },
|
|
1560
|
-
lockOthers: true
|
|
1561
|
-
};
|
|
1562
|
-
}
|
|
1563
|
-
if (stateSnapshot && renderClaimedByOtherMessage.stateSnapshot && !areStatesEquals(renderClaimedByOtherMessage.stateSnapshot, stateSnapshot)) {
|
|
1564
|
-
return {
|
|
1565
|
-
canRender: true,
|
|
1566
|
-
action: "override" /* Override */,
|
|
1567
|
-
nextClaim: { stateRenderId, runId }
|
|
1568
|
-
};
|
|
1569
|
-
}
|
|
1570
|
-
return { canRender: false, action: "block" /* Block */ };
|
|
1571
|
-
}
|
|
1572
|
-
if (!runId) {
|
|
1573
|
-
return { canRender: false, action: "block" /* Block */ };
|
|
1574
|
-
}
|
|
1575
|
-
return {
|
|
1576
|
-
canRender: true,
|
|
1577
|
-
action: "create" /* Create */,
|
|
1578
|
-
nextClaim: { stateRenderId, runId, messageIndex }
|
|
1579
|
-
};
|
|
1580
|
-
}
|
|
1581
|
-
function selectSnapshot({
|
|
1582
|
-
messageId,
|
|
1583
|
-
messageName,
|
|
1584
|
-
allowLiveState,
|
|
1585
|
-
skipLatestCache,
|
|
1586
|
-
stateRenderId,
|
|
1587
|
-
effectiveRunId,
|
|
1588
|
-
stateSnapshotProp,
|
|
1589
|
-
agentState,
|
|
1590
|
-
agentMessages,
|
|
1591
|
-
existingClaim,
|
|
1592
|
-
caches
|
|
1593
|
-
}) {
|
|
1594
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1595
|
-
const lastAssistantId = agentMessages ? (_a = [...agentMessages].reverse().find((msg) => msg.role === "assistant")) == null ? void 0 : _a.id : void 0;
|
|
1596
|
-
const latestSnapshot = stateRenderId !== void 0 ? caches.byStateRenderAndRun[`${stateRenderId}::latest`] : void 0;
|
|
1597
|
-
const messageIndex = agentMessages ? agentMessages.findIndex((msg) => msg.id === messageId) : -1;
|
|
1598
|
-
const messageRole = messageIndex >= 0 && agentMessages ? (_b = agentMessages[messageIndex]) == null ? void 0 : _b.role : void 0;
|
|
1599
|
-
let previousUserMessageId;
|
|
1600
|
-
if (messageIndex > 0 && agentMessages) {
|
|
1601
|
-
for (let i = messageIndex - 1; i >= 0; i -= 1) {
|
|
1602
|
-
if (((_c = agentMessages[i]) == null ? void 0 : _c.role) === "user") {
|
|
1603
|
-
previousUserMessageId = (_d = agentMessages[i]) == null ? void 0 : _d.id;
|
|
1604
|
-
break;
|
|
1605
|
-
}
|
|
1606
|
-
}
|
|
1607
|
-
}
|
|
1608
|
-
const liveStateIsStale = stateSnapshotProp === void 0 && latestSnapshot !== void 0 && agentState !== void 0 && areStatesEquals(latestSnapshot, agentState);
|
|
1609
|
-
const shouldUseLiveState = (Boolean(allowLiveState) || !lastAssistantId || messageId === lastAssistantId) && !liveStateIsStale;
|
|
1610
|
-
const snapshot = stateSnapshotProp ? (0, import_shared9.parseJson)(stateSnapshotProp, stateSnapshotProp) : shouldUseLiveState ? agentState : void 0;
|
|
1611
|
-
const hasSnapshotKeys = !!(snapshot && Object.keys(snapshot).length > 0);
|
|
1612
|
-
const allowEmptySnapshot = snapshot !== void 0 && !hasSnapshotKeys && (stateSnapshotProp !== void 0 || shouldUseLiveState);
|
|
1613
|
-
const messageCacheEntry = caches.byMessageId[messageId];
|
|
1614
|
-
const cachedMessageSnapshot = readCachedMessageEntry(messageCacheEntry).snapshot;
|
|
1615
|
-
const cacheKey = stateRenderId !== void 0 ? `${stateRenderId}::${effectiveRunId}` : void 0;
|
|
1616
|
-
let cachedSnapshot = cachedMessageSnapshot != null ? cachedMessageSnapshot : caches.byMessageId[messageId];
|
|
1617
|
-
if (cachedSnapshot === void 0 && cacheKey && caches.byStateRenderAndRun[cacheKey] !== void 0) {
|
|
1618
|
-
cachedSnapshot = caches.byStateRenderAndRun[cacheKey];
|
|
1619
|
-
}
|
|
1620
|
-
if (cachedSnapshot === void 0 && stateRenderId && previousUserMessageId && caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`] !== void 0) {
|
|
1621
|
-
cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::pending:${previousUserMessageId}`];
|
|
1622
|
-
}
|
|
1623
|
-
if (cachedSnapshot === void 0 && !skipLatestCache && stateRenderId && messageRole !== "assistant" && (stateSnapshotProp !== void 0 || agentState && Object.keys(agentState).length > 0)) {
|
|
1624
|
-
cachedSnapshot = caches.byStateRenderAndRun[`${stateRenderId}::latest`];
|
|
1625
|
-
}
|
|
1626
|
-
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;
|
|
1627
|
-
return {
|
|
1628
|
-
snapshot,
|
|
1629
|
-
hasSnapshotKeys,
|
|
1630
|
-
cachedSnapshot,
|
|
1631
|
-
allowEmptySnapshot,
|
|
1632
|
-
snapshotForClaim
|
|
1633
|
-
};
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
// src/hooks/use-coagent-state-render-registry.ts
|
|
1637
|
-
var import_react11 = require("react");
|
|
1638
|
-
var LAST_SNAPSHOTS_BY_RENDER_AND_RUN = "__lastSnapshotsByStateRenderIdAndRun";
|
|
1639
|
-
var LAST_SNAPSHOTS_BY_MESSAGE = "__lastSnapshotsByMessageId";
|
|
1640
|
-
function getClaimsStore(claimsRef) {
|
|
1641
|
-
return claimsRef.current;
|
|
1642
|
-
}
|
|
1643
|
-
function getSnapshotCaches(claimsRef) {
|
|
1644
|
-
var _a, _b;
|
|
1645
|
-
const store = getClaimsStore(claimsRef);
|
|
1646
|
-
return {
|
|
1647
|
-
byStateRenderAndRun: (_a = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _a : {},
|
|
1648
|
-
byMessageId: (_b = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _b : {}
|
|
1649
|
-
};
|
|
1650
|
-
}
|
|
1651
|
-
function useStateRenderRegistry({
|
|
1652
|
-
agentId,
|
|
1653
|
-
stateRenderId,
|
|
1654
|
-
message,
|
|
1655
|
-
messageIndex,
|
|
1656
|
-
stateSnapshot,
|
|
1657
|
-
agentState,
|
|
1658
|
-
agentMessages,
|
|
1659
|
-
claimsRef
|
|
1660
|
-
}) {
|
|
1661
|
-
var _a, _b, _c, _d, _e, _f;
|
|
1662
|
-
const store = getClaimsStore(claimsRef);
|
|
1663
|
-
const runId = message.runId;
|
|
1664
|
-
const cachedMessageEntry = (_a = store[LAST_SNAPSHOTS_BY_MESSAGE]) == null ? void 0 : _a[message.id];
|
|
1665
|
-
const { runId: cachedMessageRunId } = readCachedMessageEntry(cachedMessageEntry);
|
|
1666
|
-
const existingClaimRunId = (_b = claimsRef.current[message.id]) == null ? void 0 : _b.runId;
|
|
1667
|
-
const effectiveRunId = getEffectiveRunId({
|
|
1668
|
-
existingClaimRunId,
|
|
1669
|
-
cachedMessageRunId,
|
|
1670
|
-
runId
|
|
1671
|
-
});
|
|
1672
|
-
(0, import_react11.useEffect)(() => {
|
|
1673
|
-
return () => {
|
|
1674
|
-
var _a2, _b2, _c2, _d2;
|
|
1675
|
-
const existingClaim2 = claimsRef.current[message.id];
|
|
1676
|
-
if ((existingClaim2 == null ? void 0 : existingClaim2.stateSnapshot) && Object.keys(existingClaim2.stateSnapshot).length > 0) {
|
|
1677
|
-
const snapshotCache = __spreadValues({}, (_a2 = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _a2 : {});
|
|
1678
|
-
const cacheKey = `${existingClaim2.stateRenderId}::${(_b2 = existingClaim2.runId) != null ? _b2 : "pending"}`;
|
|
1679
|
-
snapshotCache[cacheKey] = existingClaim2.stateSnapshot;
|
|
1680
|
-
snapshotCache[`${existingClaim2.stateRenderId}::latest`] = existingClaim2.stateSnapshot;
|
|
1681
|
-
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
1682
|
-
const messageCache = __spreadValues({}, (_c2 = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _c2 : {});
|
|
1683
|
-
messageCache[message.id] = {
|
|
1684
|
-
snapshot: existingClaim2.stateSnapshot,
|
|
1685
|
-
runId: (_d2 = existingClaim2.runId) != null ? _d2 : effectiveRunId
|
|
1686
|
-
};
|
|
1687
|
-
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
1688
|
-
}
|
|
1689
|
-
delete claimsRef.current[message.id];
|
|
1690
|
-
};
|
|
1691
|
-
}, [claimsRef, effectiveRunId, message.id]);
|
|
1692
|
-
if (!stateRenderId) {
|
|
1693
|
-
return { canRender: false };
|
|
1694
|
-
}
|
|
1695
|
-
const caches = getSnapshotCaches(claimsRef);
|
|
1696
|
-
const existingClaim = claimsRef.current[message.id];
|
|
1697
|
-
const { snapshot, hasSnapshotKeys, allowEmptySnapshot, snapshotForClaim } = selectSnapshot({
|
|
1698
|
-
messageId: message.id,
|
|
1699
|
-
messageName: message.name,
|
|
1700
|
-
allowLiveState: isPlaceholderMessageName(message.name) || isPlaceholderMessageId(message.id),
|
|
1701
|
-
skipLatestCache: isPlaceholderMessageName(message.name) || isPlaceholderMessageId(message.id),
|
|
1702
|
-
stateRenderId,
|
|
1703
|
-
effectiveRunId,
|
|
1704
|
-
stateSnapshotProp: stateSnapshot,
|
|
1705
|
-
agentState,
|
|
1706
|
-
agentMessages,
|
|
1707
|
-
existingClaim,
|
|
1708
|
-
caches
|
|
1709
|
-
});
|
|
1710
|
-
const resolution = resolveClaim({
|
|
1711
|
-
claims: claimsRef.current,
|
|
1712
|
-
context: {
|
|
1713
|
-
agentId,
|
|
1714
|
-
messageId: message.id,
|
|
1715
|
-
stateRenderId,
|
|
1716
|
-
runId: effectiveRunId,
|
|
1717
|
-
messageIndex
|
|
1718
|
-
},
|
|
1719
|
-
stateSnapshot: snapshotForClaim
|
|
1720
|
-
});
|
|
1721
|
-
if (resolution.action === "block" /* Block */) {
|
|
1722
|
-
return { canRender: false };
|
|
1723
|
-
}
|
|
1724
|
-
if (resolution.updateRunId && claimsRef.current[message.id]) {
|
|
1725
|
-
claimsRef.current[message.id].runId = resolution.updateRunId;
|
|
1726
|
-
}
|
|
1727
|
-
if (resolution.nextClaim) {
|
|
1728
|
-
claimsRef.current[message.id] = resolution.nextClaim;
|
|
1729
|
-
}
|
|
1730
|
-
if (resolution.lockOthers) {
|
|
1731
|
-
Object.entries(claimsRef.current).forEach(([id, claim]) => {
|
|
1732
|
-
if (id !== message.id && claim.stateRenderId === stateRenderId) {
|
|
1733
|
-
claim.locked = true;
|
|
1734
|
-
}
|
|
1735
|
-
});
|
|
1736
|
-
}
|
|
1737
|
-
if (existingClaim && !existingClaim.locked && (agentMessages == null ? void 0 : agentMessages.length)) {
|
|
1738
|
-
const indexInAgentMessages = agentMessages.findIndex(
|
|
1739
|
-
(msg) => msg.id === message.id
|
|
1740
|
-
);
|
|
1741
|
-
if (indexInAgentMessages >= 0 && indexInAgentMessages < agentMessages.length - 1) {
|
|
1742
|
-
existingClaim.locked = true;
|
|
1743
|
-
}
|
|
1744
|
-
}
|
|
1745
|
-
const existingSnapshot = claimsRef.current[message.id].stateSnapshot;
|
|
1746
|
-
const snapshotChanged = stateSnapshot && existingSnapshot !== void 0 && !areStatesEquals(existingSnapshot, snapshot);
|
|
1747
|
-
if (snapshot && (stateSnapshot || hasSnapshotKeys || allowEmptySnapshot) && (!claimsRef.current[message.id].locked || snapshotChanged)) {
|
|
1748
|
-
if (!claimsRef.current[message.id].locked || snapshotChanged) {
|
|
1749
|
-
claimsRef.current[message.id].stateSnapshot = snapshot;
|
|
1750
|
-
const snapshotCache = __spreadValues({}, (_c = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _c : {});
|
|
1751
|
-
const cacheKey = `${stateRenderId}::${effectiveRunId}`;
|
|
1752
|
-
snapshotCache[cacheKey] = snapshot;
|
|
1753
|
-
snapshotCache[`${stateRenderId}::latest`] = snapshot;
|
|
1754
|
-
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
1755
|
-
const messageCache = __spreadValues({}, (_d = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _d : {});
|
|
1756
|
-
messageCache[message.id] = { snapshot, runId: effectiveRunId };
|
|
1757
|
-
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
1758
|
-
if (stateSnapshot) {
|
|
1759
|
-
claimsRef.current[message.id].locked = true;
|
|
1760
|
-
}
|
|
1761
|
-
}
|
|
1762
|
-
} else if (snapshotForClaim) {
|
|
1763
|
-
const existingSnapshot2 = claimsRef.current[message.id].stateSnapshot;
|
|
1764
|
-
if (!existingSnapshot2) {
|
|
1765
|
-
claimsRef.current[message.id].stateSnapshot = snapshotForClaim;
|
|
1766
|
-
const snapshotCache = __spreadValues({}, (_e = store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN]) != null ? _e : {});
|
|
1767
|
-
const cacheKey = `${stateRenderId}::${effectiveRunId}`;
|
|
1768
|
-
snapshotCache[cacheKey] = snapshotForClaim;
|
|
1769
|
-
snapshotCache[`${stateRenderId}::latest`] = snapshotForClaim;
|
|
1770
|
-
store[LAST_SNAPSHOTS_BY_RENDER_AND_RUN] = snapshotCache;
|
|
1771
|
-
const messageCache = __spreadValues({}, (_f = store[LAST_SNAPSHOTS_BY_MESSAGE]) != null ? _f : {});
|
|
1772
|
-
messageCache[message.id] = {
|
|
1773
|
-
snapshot: snapshotForClaim,
|
|
1774
|
-
runId: effectiveRunId
|
|
1775
|
-
};
|
|
1776
|
-
store[LAST_SNAPSHOTS_BY_MESSAGE] = messageCache;
|
|
1777
|
-
}
|
|
1778
|
-
}
|
|
1779
|
-
return { canRender: true };
|
|
1780
|
-
}
|
|
1781
|
-
|
|
1782
|
-
// src/hooks/use-coagent-state-render-bridge.tsx
|
|
1783
|
-
function useCoagentStateRenderBridge(agentId, props) {
|
|
1784
|
-
var _a;
|
|
1785
|
-
const { stateSnapshot, message } = props;
|
|
1786
|
-
const { coAgentStateRenders, claimsRef } = useCoAgentStateRenders();
|
|
1787
|
-
const { agent } = (0, import_react12.useAgent)({ agentId });
|
|
1788
|
-
const [nodeName, setNodeName] = (0, import_react13.useState)(void 0);
|
|
1789
|
-
const [, forceUpdate] = (0, import_react13.useState)(0);
|
|
1790
|
-
(0, import_react13.useEffect)(() => {
|
|
1791
|
-
if (!agent)
|
|
1792
|
-
return;
|
|
1793
|
-
const subscriber = {
|
|
1794
|
-
onStateChanged: () => {
|
|
1795
|
-
forceUpdate((value) => value + 1);
|
|
1796
|
-
},
|
|
1797
|
-
onStepStartedEvent: ({ event }) => {
|
|
1798
|
-
if (event.stepName !== nodeName) {
|
|
1799
|
-
setNodeName(event.stepName);
|
|
1800
|
-
}
|
|
1801
|
-
},
|
|
1802
|
-
onStepFinishedEvent: ({ event }) => {
|
|
1803
|
-
if (event.stepName === nodeName) {
|
|
1804
|
-
setNodeName(void 0);
|
|
1805
|
-
}
|
|
1806
|
-
}
|
|
1807
|
-
};
|
|
1808
|
-
const { unsubscribe } = agent.subscribe(subscriber);
|
|
1809
|
-
return () => {
|
|
1810
|
-
unsubscribe();
|
|
1811
|
-
};
|
|
1812
|
-
}, [agentId, nodeName]);
|
|
1813
|
-
const getStateRender = (0, import_react13.useCallback)(
|
|
1814
|
-
(messageId) => {
|
|
1815
|
-
return Object.entries(coAgentStateRenders).find(
|
|
1816
|
-
([stateRenderId2, stateRender2]) => {
|
|
1817
|
-
if (claimsRef.current[messageId]) {
|
|
1818
|
-
return stateRenderId2 === claimsRef.current[messageId].stateRenderId;
|
|
1819
|
-
}
|
|
1820
|
-
const matchingAgentName = stateRender2.name === agentId;
|
|
1821
|
-
const matchesNodeContext = stateRender2.nodeName ? stateRender2.nodeName === nodeName : true;
|
|
1822
|
-
return matchingAgentName && matchesNodeContext;
|
|
1823
|
-
}
|
|
1824
|
-
);
|
|
1825
|
-
},
|
|
1826
|
-
[coAgentStateRenders, nodeName, agentId]
|
|
1827
|
-
);
|
|
1828
|
-
const stateRenderEntry = (0, import_react13.useMemo)(
|
|
1829
|
-
() => getStateRender(message.id),
|
|
1830
|
-
[getStateRender, message.id]
|
|
1831
|
-
);
|
|
1832
|
-
const stateRenderId = stateRenderEntry == null ? void 0 : stateRenderEntry[0];
|
|
1833
|
-
const stateRender = stateRenderEntry == null ? void 0 : stateRenderEntry[1];
|
|
1834
|
-
const registryMessage = __spreadProps(__spreadValues({}, message), {
|
|
1835
|
-
runId: (_a = props.runId) != null ? _a : message.runId
|
|
1836
|
-
});
|
|
1837
|
-
const { canRender } = useStateRenderRegistry({
|
|
1838
|
-
agentId,
|
|
1839
|
-
stateRenderId,
|
|
1840
|
-
message: registryMessage,
|
|
1841
|
-
messageIndex: props.messageIndex,
|
|
1842
|
-
stateSnapshot,
|
|
1843
|
-
agentState: agent == null ? void 0 : agent.state,
|
|
1844
|
-
agentMessages: agent == null ? void 0 : agent.messages,
|
|
1845
|
-
claimsRef
|
|
1846
|
-
});
|
|
1847
|
-
return (0, import_react13.useMemo)(() => {
|
|
1848
|
-
var _a2, _b;
|
|
1849
|
-
if (!stateRender || !stateRenderId) {
|
|
1850
|
-
return null;
|
|
1851
|
-
}
|
|
1852
|
-
if (!canRender) {
|
|
1853
|
-
return null;
|
|
1854
|
-
}
|
|
1855
|
-
if (stateRender.handler) {
|
|
1856
|
-
stateRender.handler({
|
|
1857
|
-
state: stateSnapshot ? (0, import_shared10.parseJson)(stateSnapshot, stateSnapshot) : (_a2 = agent == null ? void 0 : agent.state) != null ? _a2 : {},
|
|
1858
|
-
nodeName: nodeName != null ? nodeName : ""
|
|
1859
|
-
});
|
|
1860
|
-
}
|
|
1861
|
-
if (stateRender.render) {
|
|
1862
|
-
const status = (agent == null ? void 0 : agent.isRunning) ? "inProgress" /* InProgress */ : "complete" /* Complete */;
|
|
1863
|
-
if (typeof stateRender.render === "string")
|
|
1864
|
-
return stateRender.render;
|
|
1865
|
-
return stateRender.render({
|
|
1866
|
-
status,
|
|
1867
|
-
// Always use state from claim, to make sure the state does not seem "wiped" for a fraction of a second
|
|
1868
|
-
state: (_b = claimsRef.current[message.id].stateSnapshot) != null ? _b : {},
|
|
1869
|
-
nodeName: nodeName != null ? nodeName : ""
|
|
1870
|
-
});
|
|
1871
|
-
}
|
|
1872
|
-
}, [
|
|
1873
|
-
stateRender,
|
|
1874
|
-
stateRenderId,
|
|
1875
|
-
agent == null ? void 0 : agent.state,
|
|
1876
|
-
agent == null ? void 0 : agent.isRunning,
|
|
1877
|
-
nodeName,
|
|
1878
|
-
message.id,
|
|
1879
|
-
stateSnapshot,
|
|
1880
|
-
canRender
|
|
1881
|
-
]);
|
|
1882
|
-
}
|
|
1883
|
-
function CoAgentStateRenderBridge(props) {
|
|
1884
|
-
return useCoagentStateRenderBridge(props.agentId, props);
|
|
1885
|
-
}
|
|
1886
|
-
|
|
1887
|
-
// src/components/CopilotListeners.tsx
|
|
1888
|
-
var import_react14 = require("react");
|
|
1889
|
-
var import_react15 = require("@copilotkitnext/react");
|
|
1890
|
-
var import_shared11 = require("@copilotkit/shared");
|
|
1891
|
-
var import_shared12 = require("@copilotkit/shared");
|
|
1892
|
-
var usePredictStateSubscription = (agent) => {
|
|
1893
|
-
const predictStateToolsRef = (0, import_react14.useRef)([]);
|
|
1894
|
-
const getSubscriber = (0, import_react14.useCallback)(
|
|
1895
|
-
(agent2) => ({
|
|
1896
|
-
onCustomEvent: ({ event }) => {
|
|
1897
|
-
if (event.name === "PredictState") {
|
|
1898
|
-
predictStateToolsRef.current = event.value;
|
|
1899
|
-
}
|
|
1900
|
-
},
|
|
1901
|
-
onToolCallArgsEvent: ({ partialToolCallArgs, toolCallName }) => {
|
|
1902
|
-
predictStateToolsRef.current.forEach((t) => {
|
|
1903
|
-
if ((t == null ? void 0 : t.tool) !== toolCallName)
|
|
1904
|
-
return;
|
|
1905
|
-
const emittedState = typeof partialToolCallArgs === "string" ? (0, import_shared11.parseJson)(
|
|
1906
|
-
partialToolCallArgs,
|
|
1907
|
-
partialToolCallArgs
|
|
1908
|
-
) : partialToolCallArgs;
|
|
1909
|
-
agent2.setState({
|
|
1910
|
-
[t.state_key]: emittedState[t.state_key]
|
|
1911
|
-
});
|
|
1912
|
-
});
|
|
1913
|
-
}
|
|
1914
|
-
}),
|
|
1915
|
-
[]
|
|
1916
|
-
);
|
|
1917
|
-
(0, import_react14.useEffect)(() => {
|
|
1918
|
-
if (!agent)
|
|
1919
|
-
return;
|
|
1920
|
-
const subscriber = getSubscriber(agent);
|
|
1921
|
-
const { unsubscribe } = agent.subscribe(subscriber);
|
|
1922
|
-
return () => {
|
|
1923
|
-
unsubscribe();
|
|
1924
|
-
};
|
|
1925
|
-
}, [agent, getSubscriber]);
|
|
1926
|
-
};
|
|
1927
|
-
function CopilotListeners() {
|
|
1928
|
-
const { copilotkit } = (0, import_react15.useCopilotKit)();
|
|
1929
|
-
const existingConfig = (0, import_react15.useCopilotChatConfiguration)();
|
|
1930
|
-
const resolvedAgentId = existingConfig == null ? void 0 : existingConfig.agentId;
|
|
1931
|
-
const { setBannerError } = useToast();
|
|
1932
|
-
const { agent } = (0, import_react15.useAgent)({ agentId: resolvedAgentId });
|
|
1933
|
-
usePredictStateSubscription(agent);
|
|
1934
|
-
(0, import_react14.useEffect)(() => {
|
|
1935
|
-
const subscriber = {
|
|
1936
|
-
onError: ({ error }) => {
|
|
1937
|
-
setBannerError(
|
|
1938
|
-
new import_shared12.CopilotKitLowLevelError({
|
|
1939
|
-
error,
|
|
1940
|
-
message: error.message,
|
|
1941
|
-
url: typeof window !== "undefined" ? window.location.href : ""
|
|
1942
|
-
})
|
|
1943
|
-
);
|
|
1944
|
-
}
|
|
1945
|
-
};
|
|
1946
|
-
const subscription = copilotkit.subscribe(subscriber);
|
|
1947
|
-
return () => {
|
|
1948
|
-
subscription.unsubscribe();
|
|
1949
|
-
};
|
|
1950
|
-
}, [copilotkit == null ? void 0 : copilotkit.subscribe]);
|
|
1951
|
-
return null;
|
|
1952
|
-
}
|
|
1953
|
-
|
|
1954
|
-
// src/components/copilot-provider/copilotkit.tsx
|
|
1955
|
-
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1956
|
-
function CopilotKit(_a) {
|
|
1957
|
-
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
1958
|
-
const enabled = shouldShowDevConsole(props.showDevConsole);
|
|
1959
|
-
const showInspector = shouldShowDevConsole(props.enableInspector);
|
|
1960
|
-
const publicApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
1961
|
-
const renderArr = (0, import_react16.useMemo)(() => [{ render: CoAgentStateRenderBridge }], []);
|
|
1962
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1963
|
-
CopilotErrorBoundary,
|
|
1964
|
-
{
|
|
1965
|
-
publicApiKey,
|
|
1966
|
-
showUsageBanner: enabled,
|
|
1967
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ThreadsProvider, { threadId: props.threadId, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1968
|
-
import_react17.CopilotKitProvider,
|
|
1969
|
-
__spreadProps(__spreadValues({}, props), {
|
|
1970
|
-
showDevConsole: showInspector,
|
|
1971
|
-
renderCustomMessages: renderArr,
|
|
1972
|
-
useSingleEndpoint: true,
|
|
1973
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children }))
|
|
1974
|
-
})
|
|
1975
|
-
) })
|
|
1976
|
-
}
|
|
1977
|
-
) });
|
|
1978
|
-
}
|
|
1979
|
-
function CopilotKitErrorBridge() {
|
|
1980
|
-
const { copilotkit } = (0, import_react17.useCopilotKit)();
|
|
1981
|
-
const { onError, copilotApiConfig } = useCopilotContext();
|
|
1982
|
-
(0, import_react16.useEffect)(() => {
|
|
1983
|
-
if (!copilotkit)
|
|
1984
|
-
return;
|
|
1985
|
-
const subscription = copilotkit.subscribe({
|
|
1986
|
-
onError: (event) => __async(this, null, function* () {
|
|
1987
|
-
const errorEvent = {
|
|
1988
|
-
type: "error",
|
|
1989
|
-
timestamp: Date.now(),
|
|
1990
|
-
context: __spreadValues({
|
|
1991
|
-
source: "agent",
|
|
1992
|
-
request: {
|
|
1993
|
-
operation: event.code || "unknown",
|
|
1994
|
-
url: copilotApiConfig == null ? void 0 : copilotApiConfig.chatApiEndpoint,
|
|
1995
|
-
startTime: Date.now()
|
|
1996
|
-
},
|
|
1997
|
-
technical: {
|
|
1998
|
-
environment: "browser",
|
|
1999
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
2000
|
-
stackTrace: event.error.stack
|
|
2001
|
-
}
|
|
2002
|
-
}, event.context),
|
|
2003
|
-
error: event.error
|
|
2004
|
-
};
|
|
2005
|
-
try {
|
|
2006
|
-
yield onError(errorEvent);
|
|
2007
|
-
} catch (handlerError) {
|
|
2008
|
-
console.error("Error in onError handler:", handlerError);
|
|
2009
|
-
}
|
|
2010
|
-
})
|
|
2011
|
-
});
|
|
2012
|
-
return () => {
|
|
2013
|
-
subscription.unsubscribe();
|
|
2014
|
-
};
|
|
2015
|
-
}, [copilotkit, onError, copilotApiConfig]);
|
|
2016
|
-
return null;
|
|
2017
|
-
}
|
|
2018
|
-
function CopilotKitInternal(cpkProps) {
|
|
2019
|
-
var _b;
|
|
2020
|
-
const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
|
|
2021
|
-
validateProps(cpkProps);
|
|
2022
|
-
const publicApiKey = props.publicLicenseKey || props.publicApiKey;
|
|
2023
|
-
const chatApiEndpoint = props.runtimeUrl || import_shared13.COPILOT_CLOUD_CHAT_URL;
|
|
2024
|
-
const [actions, setActions] = (0, import_react16.useState)(
|
|
2025
|
-
{}
|
|
2026
|
-
);
|
|
2027
|
-
const [registeredActionConfigs, setRegisteredActionConfigs] = (0, import_react16.useState)(/* @__PURE__ */ new Map());
|
|
2028
|
-
const chatComponentsCache = (0, import_react16.useRef)({
|
|
2029
|
-
actions: {},
|
|
2030
|
-
coAgentStateRenders: {}
|
|
2031
|
-
});
|
|
2032
|
-
const { addElement, removeElement, printTree, getAllElements } = use_tree_default();
|
|
2033
|
-
const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
|
|
2034
|
-
const [chatInstructions, setChatInstructions] = (0, import_react16.useState)("");
|
|
2035
|
-
const [authStates, setAuthStates] = (0, import_react16.useState)({});
|
|
2036
|
-
const [extensions, setExtensions] = (0, import_react16.useState)({});
|
|
2037
|
-
const [additionalInstructions, setAdditionalInstructions] = (0, import_react16.useState)([]);
|
|
2038
|
-
const {
|
|
2039
|
-
addElement: addDocument,
|
|
2040
|
-
removeElement: removeDocument,
|
|
2041
|
-
allElements: allDocuments
|
|
2042
|
-
} = use_flat_category_store_default();
|
|
2043
|
-
const setAction = (0, import_react16.useCallback)((id, action) => {
|
|
2044
|
-
setActions((prevPoints) => {
|
|
2045
|
-
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
2046
|
-
[id]: action
|
|
2047
|
-
});
|
|
2048
|
-
});
|
|
2049
|
-
}, []);
|
|
2050
|
-
const removeAction = (0, import_react16.useCallback)((id) => {
|
|
2051
|
-
setActions((prevPoints) => {
|
|
2052
|
-
const newPoints = __spreadValues({}, prevPoints);
|
|
2053
|
-
delete newPoints[id];
|
|
2054
|
-
return newPoints;
|
|
2055
|
-
});
|
|
2056
|
-
}, []);
|
|
2057
|
-
const getContextString = (0, import_react16.useCallback)(
|
|
2058
|
-
(documents, categories) => {
|
|
2059
|
-
const documentsString = documents.map((document) => {
|
|
2060
|
-
return `${document.name} (${document.sourceApplication}):
|
|
2061
|
-
${document.getContents()}`;
|
|
2062
|
-
}).join("\n\n");
|
|
2063
|
-
const nonDocumentStrings = printTree(categories);
|
|
2064
|
-
return `${documentsString}
|
|
2065
|
-
|
|
2066
|
-
${nonDocumentStrings}`;
|
|
2067
|
-
},
|
|
2068
|
-
[printTree]
|
|
2069
|
-
);
|
|
2070
|
-
const addContext = (0, import_react16.useCallback)(
|
|
2071
|
-
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
2072
|
-
return addElement(context, categories, parentId);
|
|
2073
|
-
},
|
|
2074
|
-
[addElement]
|
|
2075
|
-
);
|
|
2076
|
-
const removeContext = (0, import_react16.useCallback)(
|
|
2077
|
-
(id) => {
|
|
2078
|
-
removeElement(id);
|
|
2079
|
-
},
|
|
2080
|
-
[removeElement]
|
|
2081
|
-
);
|
|
2082
|
-
const getAllContext = (0, import_react16.useCallback)(() => {
|
|
2083
|
-
return getAllElements();
|
|
2084
|
-
}, [getAllElements]);
|
|
2085
|
-
const getFunctionCallHandler = (0, import_react16.useCallback)(
|
|
2086
|
-
(customEntryPoints) => {
|
|
2087
|
-
return entryPointsToFunctionCallHandler(
|
|
2088
|
-
Object.values(customEntryPoints || actions)
|
|
2089
|
-
);
|
|
2090
|
-
},
|
|
2091
|
-
[actions]
|
|
2092
|
-
);
|
|
2093
|
-
const getDocumentsContext = (0, import_react16.useCallback)(
|
|
2094
|
-
(categories) => {
|
|
2095
|
-
return allDocuments(categories);
|
|
2096
|
-
},
|
|
2097
|
-
[allDocuments]
|
|
2098
|
-
);
|
|
2099
|
-
const addDocumentContext = (0, import_react16.useCallback)(
|
|
2100
|
-
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
2101
|
-
return addDocument(documentPointer, categories);
|
|
2102
|
-
},
|
|
2103
|
-
[addDocument]
|
|
2104
|
-
);
|
|
2105
|
-
const removeDocumentContext = (0, import_react16.useCallback)(
|
|
2106
|
-
(documentId) => {
|
|
2107
|
-
removeDocument(documentId);
|
|
2108
|
-
},
|
|
2109
|
-
[removeDocument]
|
|
2110
|
-
);
|
|
2111
|
-
const copilotApiConfig = (0, import_react16.useMemo)(() => {
|
|
2112
|
-
var _a2, _b2;
|
|
2113
|
-
let cloud = void 0;
|
|
2114
|
-
if (publicApiKey) {
|
|
2115
|
-
cloud = {
|
|
2116
|
-
guardrails: {
|
|
2117
|
-
input: {
|
|
2118
|
-
restrictToTopic: {
|
|
2119
|
-
enabled: Boolean(props.guardrails_c),
|
|
2120
|
-
validTopics: ((_a2 = props.guardrails_c) == null ? void 0 : _a2.validTopics) || [],
|
|
2121
|
-
invalidTopics: ((_b2 = props.guardrails_c) == null ? void 0 : _b2.invalidTopics) || []
|
|
2122
|
-
}
|
|
2123
|
-
}
|
|
2124
|
-
}
|
|
2125
|
-
};
|
|
2126
|
-
}
|
|
2127
|
-
return __spreadProps(__spreadValues({
|
|
2128
|
-
publicApiKey
|
|
2129
|
-
}, cloud ? { cloud } : {}), {
|
|
2130
|
-
chatApiEndpoint,
|
|
2131
|
-
headers: props.headers || {},
|
|
2132
|
-
properties: props.properties || {},
|
|
2133
|
-
transcribeAudioUrl: props.transcribeAudioUrl,
|
|
2134
|
-
textToSpeechUrl: props.textToSpeechUrl,
|
|
2135
|
-
credentials: props.credentials
|
|
2136
|
-
});
|
|
2137
|
-
}, [
|
|
2138
|
-
publicApiKey,
|
|
2139
|
-
props.headers,
|
|
2140
|
-
props.properties,
|
|
2141
|
-
props.transcribeAudioUrl,
|
|
2142
|
-
props.textToSpeechUrl,
|
|
2143
|
-
props.credentials,
|
|
2144
|
-
props.cloudRestrictToTopic,
|
|
2145
|
-
props.guardrails_c
|
|
2146
|
-
]);
|
|
2147
|
-
const headers = (0, import_react16.useMemo)(() => {
|
|
2148
|
-
const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
|
|
2149
|
-
if (state.status === "authenticated" && state.authHeaders) {
|
|
2150
|
-
return __spreadValues(__spreadValues({}, acc), Object.entries(state.authHeaders).reduce(
|
|
2151
|
-
(headers2, [key, value]) => __spreadProps(__spreadValues({}, headers2), {
|
|
2152
|
-
[key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
|
|
2153
|
-
}),
|
|
2154
|
-
{}
|
|
2155
|
-
));
|
|
2156
|
-
}
|
|
2157
|
-
return acc;
|
|
2158
|
-
}, {});
|
|
2159
|
-
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? {
|
|
2160
|
-
[import_shared13.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey
|
|
2161
|
-
} : {}), authHeaders);
|
|
2162
|
-
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
2163
|
-
const [internalErrorHandlers, _setInternalErrorHandler] = (0, import_react16.useState)({});
|
|
2164
|
-
const setInternalErrorHandler = (0, import_react16.useCallback)(
|
|
2165
|
-
(handler) => {
|
|
2166
|
-
_setInternalErrorHandler((prev) => __spreadValues(__spreadValues({}, prev), handler));
|
|
2167
|
-
},
|
|
2168
|
-
[]
|
|
2169
|
-
);
|
|
2170
|
-
const removeInternalErrorHandler = (0, import_react16.useCallback)((key) => {
|
|
2171
|
-
_setInternalErrorHandler((prev) => {
|
|
2172
|
-
const _a2 = prev, { [key]: _removed } = _a2, rest = __objRest(_a2, [__restKey(key)]);
|
|
2173
|
-
return rest;
|
|
2174
|
-
});
|
|
2175
|
-
}, []);
|
|
2176
|
-
const onErrorRef = (0, import_react16.useRef)(props.onError);
|
|
2177
|
-
(0, import_react16.useEffect)(() => {
|
|
2178
|
-
onErrorRef.current = props.onError;
|
|
2179
|
-
}, [props.onError]);
|
|
2180
|
-
const internalHandlersRef = (0, import_react16.useRef)({});
|
|
2181
|
-
(0, import_react16.useEffect)(() => {
|
|
2182
|
-
internalHandlersRef.current = internalErrorHandlers;
|
|
2183
|
-
}, [internalErrorHandlers]);
|
|
2184
|
-
const handleErrors = (0, import_react16.useCallback)(
|
|
2185
|
-
(error) => __async(this, null, function* () {
|
|
2186
|
-
if (copilotApiConfig.publicApiKey && onErrorRef.current) {
|
|
2187
|
-
try {
|
|
2188
|
-
yield onErrorRef.current(error);
|
|
2189
|
-
} catch (e) {
|
|
2190
|
-
console.error("Error in public onError handler:", e);
|
|
2191
|
-
}
|
|
2192
|
-
}
|
|
2193
|
-
const handlers = Object.values(internalHandlersRef.current);
|
|
2194
|
-
yield Promise.all(
|
|
2195
|
-
handlers.map(
|
|
2196
|
-
(h) => Promise.resolve(h(error)).catch(
|
|
2197
|
-
(e) => console.error("Error in internal error handler:", e)
|
|
2198
|
-
)
|
|
2199
|
-
)
|
|
2200
|
-
);
|
|
2201
|
-
}),
|
|
2202
|
-
[copilotApiConfig.publicApiKey]
|
|
2203
|
-
);
|
|
2204
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react16.useState)({});
|
|
2205
|
-
const addChatSuggestionConfiguration = (0, import_react16.useCallback)(
|
|
2206
|
-
(id, suggestion) => {
|
|
2207
|
-
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
2208
|
-
},
|
|
2209
|
-
[setChatSuggestionConfiguration]
|
|
2210
|
-
);
|
|
2211
|
-
const removeChatSuggestionConfiguration = (0, import_react16.useCallback)(
|
|
2212
|
-
(id) => {
|
|
2213
|
-
setChatSuggestionConfiguration((prev) => {
|
|
2214
|
-
const _a2 = prev, { [id]: _ } = _a2, rest = __objRest(_a2, [__restKey(id)]);
|
|
2215
|
-
return rest;
|
|
2216
|
-
});
|
|
2217
|
-
},
|
|
2218
|
-
[setChatSuggestionConfiguration]
|
|
2219
|
-
);
|
|
2220
|
-
const [availableAgents, setAvailableAgents] = (0, import_react16.useState)([]);
|
|
2221
|
-
const [coagentStates, setCoagentStates] = (0, import_react16.useState)({});
|
|
2222
|
-
const coagentStatesRef = (0, import_react16.useRef)({});
|
|
2223
|
-
const setCoagentStatesWithRef = (0, import_react16.useCallback)(
|
|
2224
|
-
(value) => {
|
|
2225
|
-
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
2226
|
-
coagentStatesRef.current = newValue;
|
|
2227
|
-
setCoagentStates((prev) => {
|
|
2228
|
-
return newValue;
|
|
2229
|
-
});
|
|
2230
|
-
},
|
|
2231
|
-
[]
|
|
2232
|
-
);
|
|
2233
|
-
let initialAgentSession = null;
|
|
2234
|
-
if (props.agent) {
|
|
2235
|
-
initialAgentSession = {
|
|
2236
|
-
agentName: props.agent
|
|
2237
|
-
};
|
|
2238
|
-
}
|
|
2239
|
-
const [agentSession, setAgentSession] = (0, import_react16.useState)(
|
|
2240
|
-
initialAgentSession
|
|
2241
|
-
);
|
|
2242
|
-
(0, import_react16.useEffect)(() => {
|
|
2243
|
-
if (props.agent) {
|
|
2244
|
-
setAgentSession({
|
|
2245
|
-
agentName: props.agent
|
|
2246
|
-
});
|
|
2247
|
-
} else {
|
|
2248
|
-
setAgentSession(null);
|
|
2249
|
-
}
|
|
2250
|
-
}, [props.agent]);
|
|
2251
|
-
const { threadId, setThreadId: setInternalThreadId } = useThreads();
|
|
2252
|
-
const setThreadId = (0, import_react16.useCallback)(
|
|
2253
|
-
(value) => {
|
|
2254
|
-
if (props.threadId) {
|
|
2255
|
-
throw new Error(
|
|
2256
|
-
"Cannot call setThreadId() when threadId is provided via props."
|
|
2257
|
-
);
|
|
2258
|
-
}
|
|
2259
|
-
setInternalThreadId(value);
|
|
2260
|
-
},
|
|
2261
|
-
[props.threadId]
|
|
2262
|
-
);
|
|
2263
|
-
const [runId, setRunId] = (0, import_react16.useState)(null);
|
|
2264
|
-
const chatAbortControllerRef = (0, import_react16.useRef)(null);
|
|
2265
|
-
const showDevConsole = shouldShowDevConsole(props.showDevConsole);
|
|
2266
|
-
const [interruptActions, _setInterruptActions] = (0, import_react16.useState)({});
|
|
2267
|
-
const setInterruptAction = (0, import_react16.useCallback)(
|
|
2268
|
-
(action) => {
|
|
2269
|
-
_setInterruptActions((prev) => {
|
|
2270
|
-
var _a2;
|
|
2271
|
-
if (action == null || !action.id) {
|
|
2272
|
-
return prev;
|
|
2273
|
-
}
|
|
2274
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
2275
|
-
[action.id]: __spreadValues(__spreadValues({}, (_a2 = prev[action.id]) != null ? _a2 : {}), action)
|
|
2276
|
-
});
|
|
2277
|
-
});
|
|
2278
|
-
},
|
|
2279
|
-
[]
|
|
2280
|
-
);
|
|
2281
|
-
const removeInterruptAction = (0, import_react16.useCallback)((actionId) => {
|
|
2282
|
-
_setInterruptActions((prev) => {
|
|
2283
|
-
const _a2 = prev, { [actionId]: _ } = _a2, rest = __objRest(_a2, [__restKey(actionId)]);
|
|
2284
|
-
return rest;
|
|
2285
|
-
});
|
|
2286
|
-
}, []);
|
|
2287
|
-
const [interruptEventQueue, setInterruptEventQueue] = (0, import_react16.useState)({});
|
|
2288
|
-
const addInterruptEvent = (0, import_react16.useCallback)((queuedEvent) => {
|
|
2289
|
-
setInterruptEventQueue((prev) => {
|
|
2290
|
-
const threadQueue = prev[queuedEvent.threadId] || [];
|
|
2291
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
2292
|
-
[queuedEvent.threadId]: [...threadQueue, queuedEvent]
|
|
2293
|
-
});
|
|
2294
|
-
});
|
|
2295
|
-
}, []);
|
|
2296
|
-
const resolveInterruptEvent = (0, import_react16.useCallback)(
|
|
2297
|
-
(threadId2, eventId, response) => {
|
|
2298
|
-
setInterruptEventQueue((prev) => {
|
|
2299
|
-
const threadQueue = prev[threadId2] || [];
|
|
2300
|
-
return __spreadProps(__spreadValues({}, prev), {
|
|
2301
|
-
[threadId2]: threadQueue.map(
|
|
2302
|
-
(queuedEvent) => queuedEvent.eventId === eventId ? __spreadProps(__spreadValues({}, queuedEvent), { event: __spreadProps(__spreadValues({}, queuedEvent.event), { response }) }) : queuedEvent
|
|
2303
|
-
)
|
|
2304
|
-
});
|
|
2305
|
-
});
|
|
2306
|
-
},
|
|
2307
|
-
[]
|
|
2308
|
-
);
|
|
2309
|
-
const memoizedChildren = (0, import_react16.useMemo)(() => children, [children]);
|
|
2310
|
-
const [bannerError, setBannerError] = (0, import_react16.useState)(null);
|
|
2311
|
-
const agentLock = (0, import_react16.useMemo)(() => {
|
|
2312
|
-
var _a2;
|
|
2313
|
-
return (_a2 = props.agent) != null ? _a2 : null;
|
|
2314
|
-
}, [props.agent]);
|
|
2315
|
-
const forwardedParameters = (0, import_react16.useMemo)(
|
|
2316
|
-
() => {
|
|
2317
|
-
var _a2;
|
|
2318
|
-
return (_a2 = props.forwardedParameters) != null ? _a2 : {};
|
|
2319
|
-
},
|
|
2320
|
-
[props.forwardedParameters]
|
|
2321
|
-
);
|
|
2322
|
-
const updateExtensions = (0, import_react16.useCallback)(
|
|
2323
|
-
(newExtensions) => {
|
|
2324
|
-
setExtensions((prev) => {
|
|
2325
|
-
const resolved = typeof newExtensions === "function" ? newExtensions(prev) : newExtensions;
|
|
2326
|
-
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
2327
|
-
const isEqual = isSameLength && // @ts-ignore
|
|
2328
|
-
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
2329
|
-
return isEqual ? prev : resolved;
|
|
2330
|
-
});
|
|
2331
|
-
},
|
|
2332
|
-
[setExtensions]
|
|
2333
|
-
);
|
|
2334
|
-
const updateAuthStates = (0, import_react16.useCallback)(
|
|
2335
|
-
(newAuthStates) => {
|
|
2336
|
-
setAuthStates((prev) => {
|
|
2337
|
-
const resolved = typeof newAuthStates === "function" ? newAuthStates(prev) : newAuthStates;
|
|
2338
|
-
const isSameLength = Object.keys(resolved).length === Object.keys(prev).length;
|
|
2339
|
-
const isEqual = isSameLength && // @ts-ignore
|
|
2340
|
-
Object.entries(resolved).every(([key, value]) => prev[key] === value);
|
|
2341
|
-
return isEqual ? prev : resolved;
|
|
2342
|
-
});
|
|
2343
|
-
},
|
|
2344
|
-
[setAuthStates]
|
|
2345
|
-
);
|
|
2346
|
-
const handleSetRegisteredActions = (0, import_react16.useCallback)(
|
|
2347
|
-
(actionConfig) => {
|
|
2348
|
-
const key = actionConfig.action.name || (0, import_shared13.randomUUID)();
|
|
2349
|
-
setRegisteredActionConfigs((prev) => {
|
|
2350
|
-
const newMap = new Map(prev);
|
|
2351
|
-
newMap.set(key, actionConfig);
|
|
2352
|
-
return newMap;
|
|
2353
|
-
});
|
|
2354
|
-
return key;
|
|
2355
|
-
},
|
|
2356
|
-
[]
|
|
2357
|
-
);
|
|
2358
|
-
const handleRemoveRegisteredAction = (0, import_react16.useCallback)((actionKey) => {
|
|
2359
|
-
setRegisteredActionConfigs((prev) => {
|
|
2360
|
-
const newMap = new Map(prev);
|
|
2361
|
-
newMap.delete(actionKey);
|
|
2362
|
-
return newMap;
|
|
2363
|
-
});
|
|
2364
|
-
}, []);
|
|
2365
|
-
const RegisteredActionsRenderer = (0, import_react16.useMemo)(() => {
|
|
2366
|
-
return () => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: Array.from(registeredActionConfigs.entries()).map(([key, config]) => {
|
|
2367
|
-
const Component = config.component;
|
|
2368
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Component, { action: config.action }, key);
|
|
2369
|
-
}) });
|
|
2370
|
-
}, [registeredActionConfigs]);
|
|
2371
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2372
|
-
import_react17.CopilotChatConfigurationProvider,
|
|
2373
|
-
{
|
|
2374
|
-
agentId: (_b = props.agent) != null ? _b : "default",
|
|
2375
|
-
threadId,
|
|
2376
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
2377
|
-
CopilotContext.Provider,
|
|
2378
|
-
{
|
|
2379
|
-
value: {
|
|
2380
|
-
actions,
|
|
2381
|
-
chatComponentsCache,
|
|
2382
|
-
getFunctionCallHandler,
|
|
2383
|
-
setAction,
|
|
2384
|
-
removeAction,
|
|
2385
|
-
setRegisteredActions: handleSetRegisteredActions,
|
|
2386
|
-
removeRegisteredAction: handleRemoveRegisteredAction,
|
|
2387
|
-
getContextString,
|
|
2388
|
-
addContext,
|
|
2389
|
-
removeContext,
|
|
2390
|
-
getAllContext,
|
|
2391
|
-
getDocumentsContext,
|
|
2392
|
-
addDocumentContext,
|
|
2393
|
-
removeDocumentContext,
|
|
2394
|
-
copilotApiConfig,
|
|
2395
|
-
isLoading,
|
|
2396
|
-
setIsLoading,
|
|
2397
|
-
chatSuggestionConfiguration,
|
|
2398
|
-
addChatSuggestionConfiguration,
|
|
2399
|
-
removeChatSuggestionConfiguration,
|
|
2400
|
-
chatInstructions,
|
|
2401
|
-
setChatInstructions,
|
|
2402
|
-
additionalInstructions,
|
|
2403
|
-
setAdditionalInstructions,
|
|
2404
|
-
showDevConsole,
|
|
2405
|
-
coagentStates,
|
|
2406
|
-
setCoagentStates,
|
|
2407
|
-
coagentStatesRef,
|
|
2408
|
-
setCoagentStatesWithRef,
|
|
2409
|
-
agentSession,
|
|
2410
|
-
setAgentSession,
|
|
2411
|
-
forwardedParameters,
|
|
2412
|
-
agentLock,
|
|
2413
|
-
threadId,
|
|
2414
|
-
setThreadId,
|
|
2415
|
-
runId,
|
|
2416
|
-
setRunId,
|
|
2417
|
-
chatAbortControllerRef,
|
|
2418
|
-
availableAgents,
|
|
2419
|
-
authConfig_c: props.authConfig_c,
|
|
2420
|
-
authStates_c: authStates,
|
|
2421
|
-
setAuthStates_c: updateAuthStates,
|
|
2422
|
-
extensions,
|
|
2423
|
-
setExtensions: updateExtensions,
|
|
2424
|
-
interruptActions,
|
|
2425
|
-
setInterruptAction,
|
|
2426
|
-
removeInterruptAction,
|
|
2427
|
-
interruptEventQueue,
|
|
2428
|
-
addInterruptEvent,
|
|
2429
|
-
resolveInterruptEvent,
|
|
2430
|
-
bannerError,
|
|
2431
|
-
setBannerError,
|
|
2432
|
-
onError: handleErrors,
|
|
2433
|
-
internalErrorHandlers,
|
|
2434
|
-
setInternalErrorHandler,
|
|
2435
|
-
removeInternalErrorHandler
|
|
2436
|
-
},
|
|
2437
|
-
children: [
|
|
2438
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotListeners, {}),
|
|
2439
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(CopilotKitErrorBridge, {}),
|
|
2440
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(CoAgentStateRendersProvider, { children: [
|
|
2441
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MessagesTapProvider, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(CopilotMessages, { children: [
|
|
2442
|
-
memoizedChildren,
|
|
2443
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(RegisteredActionsRenderer, {})
|
|
2444
|
-
] }) }),
|
|
2445
|
-
bannerError && showDevConsole && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2446
|
-
UsageBanner,
|
|
2447
|
-
{
|
|
2448
|
-
severity: bannerError.severity,
|
|
2449
|
-
message: bannerError.message,
|
|
2450
|
-
onClose: () => setBannerError(null),
|
|
2451
|
-
actions: getErrorActions(bannerError)
|
|
2452
|
-
}
|
|
2453
|
-
)
|
|
2454
|
-
] })
|
|
2455
|
-
]
|
|
2456
|
-
}
|
|
2457
|
-
)
|
|
2458
|
-
}
|
|
2459
|
-
);
|
|
2460
|
-
}
|
|
2461
|
-
var defaultCopilotContextCategories = ["global"];
|
|
2462
|
-
function entryPointsToFunctionCallHandler(actions) {
|
|
2463
|
-
return (_0) => __async(this, [_0], function* ({
|
|
2464
|
-
name,
|
|
2465
|
-
args
|
|
2466
|
-
}) {
|
|
2467
|
-
let actionsByFunctionName = {};
|
|
2468
|
-
for (let action2 of actions) {
|
|
2469
|
-
actionsByFunctionName[action2.name] = action2;
|
|
2470
|
-
}
|
|
2471
|
-
const action = actionsByFunctionName[name];
|
|
2472
|
-
let result = void 0;
|
|
2473
|
-
if (action) {
|
|
2474
|
-
yield new Promise((resolve, reject) => {
|
|
2475
|
-
(0, import_react_dom.flushSync)(() => __async(this, null, function* () {
|
|
2476
|
-
var _a;
|
|
2477
|
-
try {
|
|
2478
|
-
result = yield (_a = action.handler) == null ? void 0 : _a.call(action, args);
|
|
2479
|
-
resolve();
|
|
2480
|
-
} catch (error) {
|
|
2481
|
-
reject(error);
|
|
2482
|
-
}
|
|
2483
|
-
}));
|
|
2484
|
-
});
|
|
2485
|
-
yield new Promise((resolve) => setTimeout(resolve, 20));
|
|
2486
|
-
}
|
|
2487
|
-
return result;
|
|
2488
|
-
});
|
|
2489
|
-
}
|
|
2490
|
-
function formatFeatureName(featureName) {
|
|
2491
|
-
return featureName.replace(/_c$/, "").split("_").map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(" ");
|
|
2492
|
-
}
|
|
2493
|
-
function validateProps(props) {
|
|
2494
|
-
const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
|
|
2495
|
-
const hasApiKey = props.publicApiKey || props.publicLicenseKey;
|
|
2496
|
-
if (!props.runtimeUrl && !hasApiKey) {
|
|
2497
|
-
throw new import_shared13.ConfigurationError(
|
|
2498
|
-
"Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'"
|
|
2499
|
-
);
|
|
2500
|
-
}
|
|
2501
|
-
if (cloudFeatures.length > 0 && !hasApiKey) {
|
|
2502
|
-
throw new import_shared13.MissingPublicApiKeyError(
|
|
2503
|
-
`Missing required prop: 'publicApiKey' or 'publicLicenseKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
|
|
2504
|
-
);
|
|
2505
|
-
}
|
|
2506
|
-
}
|
|
2507
|
-
|
|
2508
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
2509
|
-
var import_react24 = require("react");
|
|
2510
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
2511
|
-
|
|
2512
|
-
// src/hooks/use-langgraph-interrupt-render.ts
|
|
2513
|
-
var import_react20 = __toESM(require("react"));
|
|
2514
|
-
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
2515
|
-
var import_shared14 = require("@copilotkit/shared");
|
|
2516
|
-
|
|
2517
|
-
// src/hooks/use-agent-nodename.ts
|
|
2518
|
-
var import_react18 = require("react");
|
|
2519
|
-
var import_react19 = require("@copilotkitnext/react");
|
|
2520
|
-
function useAgentNodeName(agentName) {
|
|
2521
|
-
const { agent } = (0, import_react19.useAgent)({ agentId: agentName });
|
|
2522
|
-
const nodeNameRef = (0, import_react18.useRef)("start");
|
|
2523
|
-
(0, import_react18.useEffect)(() => {
|
|
2524
|
-
if (!agent)
|
|
2525
|
-
return;
|
|
2526
|
-
const subscriber = {
|
|
2527
|
-
onStepStartedEvent: ({ event }) => {
|
|
2528
|
-
nodeNameRef.current = event.stepName;
|
|
2529
|
-
},
|
|
2530
|
-
onRunStartedEvent: () => {
|
|
2531
|
-
nodeNameRef.current = "start";
|
|
2532
|
-
},
|
|
2533
|
-
onRunFinishedEvent: () => {
|
|
2534
|
-
nodeNameRef.current = "end";
|
|
2535
|
-
}
|
|
2536
|
-
};
|
|
2537
|
-
const subscription = agent.subscribe(subscriber);
|
|
2538
|
-
return () => {
|
|
2539
|
-
subscription.unsubscribe();
|
|
2540
|
-
};
|
|
2541
|
-
}, [agent]);
|
|
2542
|
-
return nodeNameRef.current;
|
|
2543
|
-
}
|
|
2544
|
-
|
|
2545
|
-
// src/hooks/use-langgraph-interrupt-render.ts
|
|
2546
|
-
var import_react21 = require("@copilotkitnext/react");
|
|
2547
|
-
var InterruptRenderer = ({
|
|
2548
|
-
event,
|
|
2549
|
-
result,
|
|
2550
|
-
render,
|
|
2551
|
-
resolve
|
|
2552
|
-
}) => {
|
|
2553
|
-
return render({ event, result, resolve });
|
|
2554
|
-
};
|
|
2555
|
-
function useLangGraphInterruptRender(agent) {
|
|
2556
|
-
var _a;
|
|
2557
|
-
const {
|
|
2558
|
-
interruptActions,
|
|
2559
|
-
agentSession,
|
|
2560
|
-
threadId,
|
|
2561
|
-
interruptEventQueue,
|
|
2562
|
-
addInterruptEvent,
|
|
2563
|
-
resolveInterruptEvent
|
|
2564
|
-
} = useCopilotContext();
|
|
2565
|
-
const existingConfig = (0, import_react21.useCopilotChatConfiguration)();
|
|
2566
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
2567
|
-
const nodeName = useAgentNodeName(resolvedAgentId);
|
|
2568
|
-
(0, import_react20.useEffect)(() => {
|
|
2569
|
-
if (!agent)
|
|
2570
|
-
return;
|
|
2571
|
-
let localInterrupt = null;
|
|
2572
|
-
const subscriber = {
|
|
2573
|
-
onCustomEvent: ({ event }) => {
|
|
2574
|
-
if (event.name === "on_interrupt") {
|
|
2575
|
-
const eventData = {
|
|
2576
|
-
name: import_runtime_client_gql.MetaEventName.LangGraphInterruptEvent,
|
|
2577
|
-
type: event.type,
|
|
2578
|
-
value: (0, import_shared14.parseJson)(event.value, event.value)
|
|
2579
|
-
};
|
|
2580
|
-
const eventId = (0, import_shared14.dataToUUID)(eventData, "interruptEvents");
|
|
2581
|
-
localInterrupt = {
|
|
2582
|
-
eventId,
|
|
2583
|
-
threadId,
|
|
2584
|
-
event: eventData
|
|
2585
|
-
};
|
|
2586
|
-
}
|
|
2587
|
-
},
|
|
2588
|
-
onRunStartedEvent: () => {
|
|
2589
|
-
localInterrupt = null;
|
|
2590
|
-
},
|
|
2591
|
-
onRunFinalized: () => {
|
|
2592
|
-
if (localInterrupt) {
|
|
2593
|
-
addInterruptEvent(localInterrupt);
|
|
2594
|
-
localInterrupt = null;
|
|
2595
|
-
}
|
|
2596
|
-
}
|
|
2597
|
-
};
|
|
2598
|
-
const { unsubscribe } = agent.subscribe(subscriber);
|
|
2599
|
-
return () => {
|
|
2600
|
-
unsubscribe();
|
|
2601
|
-
};
|
|
2602
|
-
}, [agent, threadId]);
|
|
2603
|
-
const handleResolve = (0, import_react20.useCallback)(
|
|
2604
|
-
(eventId, response) => {
|
|
2605
|
-
agent == null ? void 0 : agent.runAgent({
|
|
2606
|
-
forwardedProps: {
|
|
2607
|
-
command: {
|
|
2608
|
-
resume: response
|
|
2609
|
-
}
|
|
2610
|
-
}
|
|
2611
|
-
});
|
|
2612
|
-
resolveInterruptEvent(threadId, eventId, response != null ? response : "");
|
|
2613
|
-
},
|
|
2614
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2615
|
-
[agent, threadId]
|
|
2616
|
-
);
|
|
2617
|
-
return (0, import_react20.useMemo)(() => {
|
|
2618
|
-
const eventQueue = interruptEventQueue[threadId] || [];
|
|
2619
|
-
const currentQueuedEvent = eventQueue.find((qe) => !qe.event.response);
|
|
2620
|
-
if (!currentQueuedEvent || !agentSession)
|
|
2621
|
-
return null;
|
|
2622
|
-
const allActions = Object.values(interruptActions);
|
|
2623
|
-
const matchingAction = allActions.find((action) => {
|
|
2624
|
-
if (!action.enabled)
|
|
2625
|
-
return true;
|
|
2626
|
-
return action.enabled({
|
|
2627
|
-
eventValue: currentQueuedEvent.event.value,
|
|
2628
|
-
agentMetadata: __spreadProps(__spreadValues({}, agentSession), {
|
|
2629
|
-
nodeName
|
|
2630
|
-
})
|
|
2631
|
-
});
|
|
2632
|
-
});
|
|
2633
|
-
if (!matchingAction)
|
|
2634
|
-
return null;
|
|
2635
|
-
const { render, handler } = matchingAction;
|
|
2636
|
-
const resolveInterrupt = (response) => {
|
|
2637
|
-
handleResolve(currentQueuedEvent.eventId, response);
|
|
2638
|
-
};
|
|
2639
|
-
let result = null;
|
|
2640
|
-
if (handler) {
|
|
2641
|
-
result = handler({
|
|
2642
|
-
event: currentQueuedEvent.event,
|
|
2643
|
-
resolve: resolveInterrupt
|
|
2644
|
-
});
|
|
2645
|
-
}
|
|
2646
|
-
if (!render)
|
|
2647
|
-
return null;
|
|
2648
|
-
return import_react20.default.createElement(InterruptRenderer, {
|
|
2649
|
-
event: currentQueuedEvent.event,
|
|
2650
|
-
result,
|
|
2651
|
-
render,
|
|
2652
|
-
resolve: resolveInterrupt
|
|
2653
|
-
});
|
|
2654
|
-
}, [
|
|
2655
|
-
interruptActions,
|
|
2656
|
-
interruptEventQueue,
|
|
2657
|
-
threadId,
|
|
2658
|
-
agentSession,
|
|
2659
|
-
handleResolve
|
|
2660
|
-
]);
|
|
2661
|
-
}
|
|
2662
|
-
|
|
2663
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
2664
|
-
var import_react25 = require("@copilotkitnext/react");
|
|
2665
|
-
|
|
2666
|
-
// src/hooks/use-lazy-tool-renderer.tsx
|
|
2667
|
-
var import_react22 = require("@copilotkitnext/react");
|
|
2668
|
-
var import_react23 = require("react");
|
|
2669
|
-
function useLazyToolRenderer() {
|
|
2670
|
-
const renderToolCall = (0, import_react22.useRenderToolCall)();
|
|
2671
|
-
return (0, import_react23.useCallback)(
|
|
2672
|
-
(message, messages) => {
|
|
2673
|
-
var _a;
|
|
2674
|
-
if (!((_a = message == null ? void 0 : message.toolCalls) == null ? void 0 : _a.length))
|
|
2675
|
-
return null;
|
|
2676
|
-
const toolCall = message.toolCalls[0];
|
|
2677
|
-
if (!toolCall)
|
|
2678
|
-
return null;
|
|
2679
|
-
const toolMessage = messages == null ? void 0 : messages.find(
|
|
2680
|
-
(m) => m.role === "tool" && m.toolCallId === toolCall.id
|
|
2681
|
-
);
|
|
2682
|
-
return () => renderToolCall({
|
|
2683
|
-
toolCall,
|
|
2684
|
-
toolMessage
|
|
2685
|
-
});
|
|
2686
|
-
},
|
|
2687
|
-
[renderToolCall]
|
|
2688
|
-
);
|
|
2689
|
-
}
|
|
2690
|
-
|
|
2691
|
-
// src/hooks/use-copilot-chat_internal.ts
|
|
2692
|
-
var import_client = require("@ag-ui/client");
|
|
2693
|
-
function useCopilotChatInternal({
|
|
2694
|
-
suggestions,
|
|
2695
|
-
onInProgress,
|
|
2696
|
-
onSubmitMessage,
|
|
2697
|
-
onStopGeneration,
|
|
2698
|
-
onReloadMessages
|
|
2699
|
-
} = {}) {
|
|
2700
|
-
var _a, _b, _c;
|
|
2701
|
-
const { copilotkit } = (0, import_react25.useCopilotKit)();
|
|
2702
|
-
const { threadId, agentSession } = useCopilotContext();
|
|
2703
|
-
const existingConfig = (0, import_react25.useCopilotChatConfiguration)();
|
|
2704
|
-
const [agentAvailable, setAgentAvailable] = (0, import_react24.useState)(false);
|
|
2705
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
2706
|
-
const { agent } = (0, import_react25.useAgent)({ agentId: resolvedAgentId });
|
|
2707
|
-
(0, import_react24.useEffect)(() => {
|
|
2708
|
-
const connect = (agent2) => __async(this, null, function* () {
|
|
2709
|
-
setAgentAvailable(false);
|
|
2710
|
-
try {
|
|
2711
|
-
yield copilotkit.connectAgent({ agent: agent2 });
|
|
2712
|
-
setAgentAvailable(true);
|
|
2713
|
-
} catch (error) {
|
|
2714
|
-
if (error instanceof import_client.AGUIConnectNotImplementedError) {
|
|
2715
|
-
} else {
|
|
2716
|
-
console.error("CopilotChat: connectAgent failed", error);
|
|
2717
|
-
}
|
|
2718
|
-
}
|
|
2719
|
-
});
|
|
2720
|
-
if (agent && (existingConfig == null ? void 0 : existingConfig.threadId) && agent.threadId !== existingConfig.threadId) {
|
|
2721
|
-
agent.threadId = existingConfig.threadId;
|
|
2722
|
-
connect(agent);
|
|
2723
|
-
}
|
|
2724
|
-
return () => {
|
|
2725
|
-
};
|
|
2726
|
-
}, [existingConfig == null ? void 0 : existingConfig.threadId, agent, copilotkit, resolvedAgentId]);
|
|
2727
|
-
(0, import_react24.useEffect)(() => {
|
|
2728
|
-
onInProgress == null ? void 0 : onInProgress(Boolean(agent == null ? void 0 : agent.isRunning));
|
|
2729
|
-
}, [agent == null ? void 0 : agent.isRunning, onInProgress]);
|
|
2730
|
-
const interrupt = useLangGraphInterruptRender(agent);
|
|
2731
|
-
const reset = () => {
|
|
2732
|
-
agent == null ? void 0 : agent.setMessages([]);
|
|
2733
|
-
agent == null ? void 0 : agent.setState(null);
|
|
2734
|
-
};
|
|
2735
|
-
const deleteMessage = (0, import_react24.useCallback)(
|
|
2736
|
-
(messageId) => {
|
|
2737
|
-
var _a2;
|
|
2738
|
-
const filteredMessages = ((_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []).filter(
|
|
2739
|
-
(message) => message.id !== messageId
|
|
2740
|
-
);
|
|
2741
|
-
agent == null ? void 0 : agent.setMessages(filteredMessages);
|
|
2742
|
-
},
|
|
2743
|
-
[agent == null ? void 0 : agent.setMessages, agent == null ? void 0 : agent.messages]
|
|
2744
|
-
);
|
|
2745
|
-
const latestDelete = useUpdatedRef(deleteMessage);
|
|
2746
|
-
const latestDeleteFunc = (0, import_react24.useCallback)(
|
|
2747
|
-
(messageId) => {
|
|
2748
|
-
return latestDelete.current(messageId);
|
|
2749
|
-
},
|
|
2750
|
-
[latestDelete]
|
|
2751
|
-
);
|
|
2752
|
-
const currentSuggestions = (0, import_react25.useSuggestions)({ agentId: resolvedAgentId });
|
|
2753
|
-
const reload = useAsyncCallback(
|
|
2754
|
-
(reloadMessageId) => __async(this, null, function* () {
|
|
2755
|
-
var _a2;
|
|
2756
|
-
if (!agent)
|
|
2757
|
-
return;
|
|
2758
|
-
const messages = (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : [];
|
|
2759
|
-
const isLoading = agent.isRunning;
|
|
2760
|
-
if (isLoading || messages.length === 0) {
|
|
2761
|
-
return;
|
|
2762
|
-
}
|
|
2763
|
-
const reloadMessageIndex = messages.findIndex(
|
|
2764
|
-
(msg) => msg.id === reloadMessageId
|
|
2765
|
-
);
|
|
2766
|
-
if (reloadMessageIndex === -1) {
|
|
2767
|
-
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
2768
|
-
return;
|
|
2769
|
-
}
|
|
2770
|
-
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
2771
|
-
if (reloadMessageRole !== "assistant") {
|
|
2772
|
-
console.warn(
|
|
2773
|
-
`Regenerate cannot be performed on ${reloadMessageRole} role`
|
|
2774
|
-
);
|
|
2775
|
-
return;
|
|
2776
|
-
}
|
|
2777
|
-
let historyCutoff = [messages[0]];
|
|
2778
|
-
if (messages.length > 2 && reloadMessageIndex !== 0) {
|
|
2779
|
-
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find((msg) => msg.role === "user");
|
|
2780
|
-
if (!lastUserMessageBeforeRegenerate) {
|
|
2781
|
-
historyCutoff = [messages[0]];
|
|
2782
|
-
} else {
|
|
2783
|
-
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
2784
|
-
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
2785
|
-
);
|
|
2786
|
-
historyCutoff = messages.slice(
|
|
2787
|
-
0,
|
|
2788
|
-
indexOfLastUserMessageBeforeRegenerate + 1
|
|
2789
|
-
);
|
|
2790
|
-
}
|
|
2791
|
-
} else if (messages.length > 2 && reloadMessageIndex === 0) {
|
|
2792
|
-
historyCutoff = [messages[0], messages[1]];
|
|
2793
|
-
}
|
|
2794
|
-
agent == null ? void 0 : agent.setMessages(historyCutoff);
|
|
2795
|
-
if (agent) {
|
|
2796
|
-
try {
|
|
2797
|
-
yield copilotkit.runAgent({ agent });
|
|
2798
|
-
} catch (error) {
|
|
2799
|
-
console.error("CopilotChat: runAgent failed during reload", error);
|
|
2800
|
-
}
|
|
2801
|
-
}
|
|
2802
|
-
return;
|
|
2803
|
-
}),
|
|
2804
|
-
[
|
|
2805
|
-
agent == null ? void 0 : agent.messages.length,
|
|
2806
|
-
agent == null ? void 0 : agent.isRunning,
|
|
2807
|
-
agent == null ? void 0 : agent.setMessages,
|
|
2808
|
-
copilotkit == null ? void 0 : copilotkit.runAgent
|
|
2809
|
-
]
|
|
2810
|
-
);
|
|
2811
|
-
const latestSendMessageFunc = useAsyncCallback(
|
|
2812
|
-
(message, options) => __async(this, null, function* () {
|
|
2813
|
-
var _a2;
|
|
2814
|
-
if (!agent)
|
|
2815
|
-
return;
|
|
2816
|
-
const followUp = (_a2 = options == null ? void 0 : options.followUp) != null ? _a2 : true;
|
|
2817
|
-
if (options == null ? void 0 : options.clearSuggestions) {
|
|
2818
|
-
copilotkit.clearSuggestions(resolvedAgentId);
|
|
2819
|
-
}
|
|
2820
|
-
if (onSubmitMessage) {
|
|
2821
|
-
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 : "";
|
|
2822
|
-
try {
|
|
2823
|
-
yield onSubmitMessage(content);
|
|
2824
|
-
} catch (error) {
|
|
2825
|
-
console.error("Error in onSubmitMessage:", error);
|
|
2826
|
-
}
|
|
2827
|
-
}
|
|
2828
|
-
agent == null ? void 0 : agent.addMessage(message);
|
|
2829
|
-
if (followUp) {
|
|
2830
|
-
try {
|
|
2831
|
-
yield copilotkit.runAgent({ agent });
|
|
2832
|
-
} catch (error) {
|
|
2833
|
-
console.error("CopilotChat: runAgent failed", error);
|
|
2834
|
-
}
|
|
2835
|
-
}
|
|
2836
|
-
}),
|
|
2837
|
-
[agent, copilotkit, resolvedAgentId, onSubmitMessage]
|
|
2838
|
-
);
|
|
2839
|
-
const latestAppendFunc = useAsyncCallback(
|
|
2840
|
-
(message, options) => __async(this, null, function* () {
|
|
2841
|
-
return latestSendMessageFunc((0, import_runtime_client_gql2.gqlToAGUI)([message])[0], options);
|
|
2842
|
-
}),
|
|
2843
|
-
[latestSendMessageFunc]
|
|
2844
|
-
);
|
|
2845
|
-
const latestSetMessagesFunc = (0, import_react24.useCallback)(
|
|
2846
|
-
(messages) => {
|
|
2847
|
-
var _a2, _b2;
|
|
2848
|
-
if (messages.every((message) => message instanceof import_runtime_client_gql2.Message)) {
|
|
2849
|
-
return (_a2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _a2.call(agent, (0, import_runtime_client_gql2.gqlToAGUI)(messages));
|
|
2850
|
-
}
|
|
2851
|
-
return (_b2 = agent == null ? void 0 : agent.setMessages) == null ? void 0 : _b2.call(agent, messages);
|
|
2852
|
-
},
|
|
2853
|
-
[agent == null ? void 0 : agent.setMessages, agent]
|
|
2854
|
-
);
|
|
2855
|
-
const latestReload = useUpdatedRef(reload);
|
|
2856
|
-
const latestReloadFunc = useAsyncCallback(
|
|
2857
|
-
(messageId) => __async(this, null, function* () {
|
|
2858
|
-
var _a2;
|
|
2859
|
-
onReloadMessages == null ? void 0 : onReloadMessages({
|
|
2860
|
-
messageId,
|
|
2861
|
-
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
2862
|
-
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
2863
|
-
});
|
|
2864
|
-
return yield latestReload.current(messageId);
|
|
2865
|
-
}),
|
|
2866
|
-
[latestReload, agent, onReloadMessages]
|
|
2867
|
-
);
|
|
2868
|
-
const latestStopFunc = (0, import_react24.useCallback)(() => {
|
|
2869
|
-
var _a2, _b2;
|
|
2870
|
-
onStopGeneration == null ? void 0 : onStopGeneration({
|
|
2871
|
-
currentAgentName: agent == null ? void 0 : agent.agentId,
|
|
2872
|
-
messages: (_a2 = agent == null ? void 0 : agent.messages) != null ? _a2 : []
|
|
2873
|
-
});
|
|
2874
|
-
return (_b2 = agent == null ? void 0 : agent.abortRun) == null ? void 0 : _b2.call(agent);
|
|
2875
|
-
}, [onStopGeneration, agent]);
|
|
2876
|
-
const latestReset = useUpdatedRef(reset);
|
|
2877
|
-
const latestResetFunc = (0, import_react24.useCallback)(() => {
|
|
2878
|
-
return latestReset.current();
|
|
2879
|
-
}, [latestReset]);
|
|
2880
|
-
const lazyToolRendered = useLazyToolRenderer();
|
|
2881
|
-
const renderCustomMessage = (0, import_react25.useRenderCustomMessages)();
|
|
2882
|
-
const legacyCustomMessageRenderer = useLegacyCoagentRenderer({
|
|
2883
|
-
copilotkit,
|
|
2884
|
-
agent,
|
|
2885
|
-
agentId: resolvedAgentId,
|
|
2886
|
-
threadId: (_b = existingConfig == null ? void 0 : existingConfig.threadId) != null ? _b : threadId
|
|
2887
|
-
});
|
|
2888
|
-
const allMessages = (_c = agent == null ? void 0 : agent.messages) != null ? _c : [];
|
|
2889
|
-
const resolvedMessages = (0, import_react24.useMemo)(() => {
|
|
2890
|
-
var _a2, _b2;
|
|
2891
|
-
let processedMessages = allMessages.map((message) => {
|
|
2892
|
-
if (message.role !== "assistant") {
|
|
2893
|
-
return message;
|
|
2894
|
-
}
|
|
2895
|
-
const lazyRendered = lazyToolRendered(message, allMessages);
|
|
2896
|
-
if (lazyRendered) {
|
|
2897
|
-
const renderedGenUi = lazyRendered();
|
|
2898
|
-
if (renderedGenUi) {
|
|
2899
|
-
return __spreadProps(__spreadValues({}, message), { generativeUI: () => renderedGenUi });
|
|
2900
|
-
}
|
|
2901
|
-
}
|
|
2902
|
-
const bridgeRenderer = legacyCustomMessageRenderer || renderCustomMessage ? () => {
|
|
2903
|
-
var _a3;
|
|
2904
|
-
if (legacyCustomMessageRenderer) {
|
|
2905
|
-
return legacyCustomMessageRenderer({
|
|
2906
|
-
message,
|
|
2907
|
-
position: "before"
|
|
2908
|
-
});
|
|
2909
|
-
}
|
|
2910
|
-
try {
|
|
2911
|
-
return (_a3 = renderCustomMessage == null ? void 0 : renderCustomMessage({ message, position: "before" })) != null ? _a3 : null;
|
|
2912
|
-
} catch (error) {
|
|
2913
|
-
console.warn(
|
|
2914
|
-
"[CopilotKit] renderCustomMessages failed, falling back to legacy renderer",
|
|
2915
|
-
error
|
|
2916
|
-
);
|
|
2917
|
-
return null;
|
|
2918
|
-
}
|
|
2919
|
-
} : null;
|
|
2920
|
-
if (bridgeRenderer) {
|
|
2921
|
-
return __spreadProps(__spreadValues({}, message), {
|
|
2922
|
-
generativeUI: bridgeRenderer,
|
|
2923
|
-
generativeUIPosition: "before"
|
|
2924
|
-
});
|
|
2925
|
-
}
|
|
2926
|
-
return message;
|
|
2927
|
-
});
|
|
2928
|
-
const hasAssistantMessages = processedMessages.some(
|
|
2929
|
-
(msg) => msg.role === "assistant"
|
|
2930
|
-
);
|
|
2931
|
-
const canUseCustomRenderer = Boolean(
|
|
2932
|
-
renderCustomMessage && ((_a2 = copilotkit == null ? void 0 : copilotkit.getAgent) == null ? void 0 : _a2.call(copilotkit, resolvedAgentId))
|
|
2933
|
-
);
|
|
2934
|
-
const placeholderRenderer = legacyCustomMessageRenderer ? legacyCustomMessageRenderer : canUseCustomRenderer ? renderCustomMessage : null;
|
|
2935
|
-
const shouldRenderPlaceholder = Boolean(agent == null ? void 0 : agent.isRunning) || Boolean((agent == null ? void 0 : agent.state) && Object.keys(agent.state).length);
|
|
2936
|
-
const effectiveThreadId = (_b2 = threadId != null ? threadId : agent == null ? void 0 : agent.threadId) != null ? _b2 : "default";
|
|
2937
|
-
let latestUserIndex = -1;
|
|
2938
|
-
for (let i = processedMessages.length - 1; i >= 0; i -= 1) {
|
|
2939
|
-
if (processedMessages[i].role === "user") {
|
|
2940
|
-
latestUserIndex = i;
|
|
2941
|
-
break;
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
const latestUserMessageId = latestUserIndex >= 0 ? processedMessages[latestUserIndex].id : void 0;
|
|
2945
|
-
const currentRunId = latestUserMessageId ? copilotkit.getRunIdForMessage(
|
|
2946
|
-
resolvedAgentId,
|
|
2947
|
-
effectiveThreadId,
|
|
2948
|
-
latestUserMessageId
|
|
2949
|
-
) || `pending:${latestUserMessageId}` : void 0;
|
|
2950
|
-
const hasAssistantForCurrentRun = latestUserIndex >= 0 ? processedMessages.slice(latestUserIndex + 1).some((msg) => msg.role === "assistant") : hasAssistantMessages;
|
|
2951
|
-
if (placeholderRenderer && shouldRenderPlaceholder && !hasAssistantForCurrentRun) {
|
|
2952
|
-
const placeholderId = currentRunId ? `coagent-state-render-${resolvedAgentId}-${currentRunId}` : `coagent-state-render-${resolvedAgentId}`;
|
|
2953
|
-
const placeholderMessage = {
|
|
2954
|
-
id: placeholderId,
|
|
2955
|
-
role: "assistant",
|
|
2956
|
-
content: "",
|
|
2957
|
-
name: "coagent-state-render",
|
|
2958
|
-
runId: currentRunId
|
|
2959
|
-
};
|
|
2960
|
-
processedMessages = [
|
|
2961
|
-
...processedMessages,
|
|
2962
|
-
__spreadProps(__spreadValues({}, placeholderMessage), {
|
|
2963
|
-
generativeUIPosition: "before",
|
|
2964
|
-
generativeUI: () => placeholderRenderer({
|
|
2965
|
-
message: placeholderMessage,
|
|
2966
|
-
position: "before"
|
|
2967
|
-
})
|
|
2968
|
-
})
|
|
2969
|
-
];
|
|
2970
|
-
}
|
|
2971
|
-
return processedMessages;
|
|
2972
|
-
}, [
|
|
2973
|
-
agent == null ? void 0 : agent.messages,
|
|
2974
|
-
lazyToolRendered,
|
|
2975
|
-
allMessages,
|
|
2976
|
-
renderCustomMessage,
|
|
2977
|
-
legacyCustomMessageRenderer,
|
|
2978
|
-
resolvedAgentId,
|
|
2979
|
-
copilotkit,
|
|
2980
|
-
agent == null ? void 0 : agent.isRunning,
|
|
2981
|
-
agent == null ? void 0 : agent.state
|
|
2982
|
-
]);
|
|
2983
|
-
const renderedSuggestions = (0, import_react24.useMemo)(() => {
|
|
2984
|
-
if (Array.isArray(suggestions)) {
|
|
2985
|
-
return {
|
|
2986
|
-
suggestions: suggestions.map((s) => __spreadProps(__spreadValues({}, s), { isLoading: false })),
|
|
2987
|
-
isLoading: false
|
|
2988
|
-
};
|
|
2989
|
-
}
|
|
2990
|
-
return currentSuggestions;
|
|
2991
|
-
}, [suggestions, currentSuggestions]);
|
|
2992
|
-
return {
|
|
2993
|
-
messages: resolvedMessages,
|
|
2994
|
-
sendMessage: latestSendMessageFunc,
|
|
2995
|
-
appendMessage: latestAppendFunc,
|
|
2996
|
-
setMessages: latestSetMessagesFunc,
|
|
2997
|
-
reloadMessages: latestReloadFunc,
|
|
2998
|
-
stopGeneration: latestStopFunc,
|
|
2999
|
-
reset: latestResetFunc,
|
|
3000
|
-
deleteMessage: latestDeleteFunc,
|
|
3001
|
-
isAvailable: agentAvailable,
|
|
3002
|
-
isLoading: Boolean(agent == null ? void 0 : agent.isRunning),
|
|
3003
|
-
// mcpServers,
|
|
3004
|
-
// setMcpServers,
|
|
3005
|
-
suggestions: renderedSuggestions.suggestions,
|
|
3006
|
-
setSuggestions: (suggestions2) => copilotkit.addSuggestionsConfig({ suggestions: suggestions2 }),
|
|
3007
|
-
generateSuggestions: () => __async(this, null, function* () {
|
|
3008
|
-
return copilotkit.reloadSuggestions(resolvedAgentId);
|
|
3009
|
-
}),
|
|
3010
|
-
resetSuggestions: () => copilotkit.clearSuggestions(resolvedAgentId),
|
|
3011
|
-
isLoadingSuggestions: renderedSuggestions.isLoading,
|
|
3012
|
-
interrupt,
|
|
3013
|
-
agent,
|
|
3014
|
-
threadId
|
|
3015
|
-
};
|
|
3016
|
-
}
|
|
3017
|
-
function useUpdatedRef(value) {
|
|
3018
|
-
const ref = (0, import_react24.useRef)(value);
|
|
3019
|
-
(0, import_react24.useEffect)(() => {
|
|
3020
|
-
ref.current = value;
|
|
3021
|
-
}, [value]);
|
|
3022
|
-
return ref;
|
|
3023
|
-
}
|
|
3024
|
-
function useLegacyCoagentRenderer({
|
|
3025
|
-
copilotkit,
|
|
3026
|
-
agent,
|
|
3027
|
-
agentId,
|
|
3028
|
-
threadId
|
|
3029
|
-
}) {
|
|
3030
|
-
return (0, import_react24.useMemo)(() => {
|
|
3031
|
-
if (!copilotkit || !agent) {
|
|
3032
|
-
return null;
|
|
3033
|
-
}
|
|
3034
|
-
return ({ message, position }) => {
|
|
3035
|
-
var _a;
|
|
3036
|
-
const effectiveThreadId = (_a = threadId != null ? threadId : agent.threadId) != null ? _a : "default";
|
|
3037
|
-
const providedRunId = message.runId;
|
|
3038
|
-
const existingRunId = providedRunId ? providedRunId : copilotkit.getRunIdForMessage(agentId, effectiveThreadId, message.id);
|
|
3039
|
-
const runId = existingRunId || `pending:${message.id}`;
|
|
3040
|
-
const messageIndex = Math.max(
|
|
3041
|
-
agent.messages.findIndex((msg) => msg.id === message.id),
|
|
3042
|
-
0
|
|
3043
|
-
);
|
|
3044
|
-
const bridgeProps = {
|
|
3045
|
-
message,
|
|
3046
|
-
position,
|
|
3047
|
-
runId,
|
|
3048
|
-
messageIndex,
|
|
3049
|
-
messageIndexInRun: 0,
|
|
3050
|
-
numberOfMessagesInRun: 1,
|
|
3051
|
-
agentId,
|
|
3052
|
-
stateSnapshot: message.state
|
|
3053
|
-
};
|
|
3054
|
-
return (0, import_react24.createElement)(CoAgentStateRenderBridge, bridgeProps);
|
|
3055
|
-
};
|
|
3056
|
-
}, [agent, agentId, copilotkit, threadId]);
|
|
3057
|
-
}
|
|
3058
|
-
|
|
3059
|
-
// src/hooks/use-copilot-chat.ts
|
|
3060
|
-
function useCopilotChat(options = {}) {
|
|
3061
|
-
const {
|
|
3062
|
-
visibleMessages,
|
|
3063
|
-
appendMessage,
|
|
3064
|
-
reloadMessages,
|
|
3065
|
-
stopGeneration,
|
|
3066
|
-
reset,
|
|
3067
|
-
isLoading,
|
|
3068
|
-
isAvailable,
|
|
3069
|
-
runChatCompletion,
|
|
3070
|
-
mcpServers,
|
|
3071
|
-
setMcpServers
|
|
3072
|
-
} = useCopilotChatInternal(options);
|
|
3073
|
-
return {
|
|
3074
|
-
visibleMessages,
|
|
3075
|
-
appendMessage,
|
|
3076
|
-
reloadMessages,
|
|
3077
|
-
stopGeneration,
|
|
3078
|
-
reset,
|
|
3079
|
-
isLoading,
|
|
3080
|
-
isAvailable,
|
|
3081
|
-
runChatCompletion,
|
|
3082
|
-
mcpServers,
|
|
3083
|
-
setMcpServers
|
|
3084
|
-
};
|
|
3085
|
-
}
|
|
3086
|
-
|
|
3087
|
-
// src/hooks/use-copilot-chat-headless_c.ts
|
|
3088
|
-
var import_react26 = require("react");
|
|
3089
|
-
var import_shared15 = require("@copilotkit/shared");
|
|
3090
|
-
var createNonFunctionalReturn = () => ({
|
|
3091
|
-
visibleMessages: [],
|
|
3092
|
-
messages: [],
|
|
3093
|
-
sendMessage: () => __async(void 0, null, function* () {
|
|
3094
|
-
}),
|
|
3095
|
-
appendMessage: () => __async(void 0, null, function* () {
|
|
3096
|
-
}),
|
|
3097
|
-
setMessages: () => {
|
|
3098
|
-
},
|
|
3099
|
-
deleteMessage: () => {
|
|
3100
|
-
},
|
|
3101
|
-
reloadMessages: () => __async(void 0, null, function* () {
|
|
3102
|
-
}),
|
|
3103
|
-
stopGeneration: () => {
|
|
3104
|
-
},
|
|
3105
|
-
reset: () => {
|
|
3106
|
-
},
|
|
3107
|
-
isLoading: false,
|
|
3108
|
-
isAvailable: false,
|
|
3109
|
-
runChatCompletion: () => __async(void 0, null, function* () {
|
|
3110
|
-
return [];
|
|
3111
|
-
}),
|
|
3112
|
-
mcpServers: [],
|
|
3113
|
-
setMcpServers: () => {
|
|
3114
|
-
},
|
|
3115
|
-
suggestions: [],
|
|
3116
|
-
setSuggestions: () => {
|
|
3117
|
-
},
|
|
3118
|
-
generateSuggestions: () => __async(void 0, null, function* () {
|
|
3119
|
-
}),
|
|
3120
|
-
resetSuggestions: () => {
|
|
3121
|
-
},
|
|
3122
|
-
isLoadingSuggestions: false,
|
|
3123
|
-
interrupt: null
|
|
3124
|
-
});
|
|
3125
|
-
function useCopilotChatHeadless_c(options = {}) {
|
|
3126
|
-
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
3127
|
-
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
3128
|
-
const internalResult = useCopilotChatInternal(options);
|
|
3129
|
-
(0, import_react26.useEffect)(() => {
|
|
3130
|
-
if (!hasPublicApiKey) {
|
|
3131
|
-
setBannerError(
|
|
3132
|
-
new import_shared15.CopilotKitError({
|
|
3133
|
-
message: (
|
|
3134
|
-
// add link to documentation here
|
|
3135
|
-
"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."
|
|
3136
|
-
),
|
|
3137
|
-
code: import_shared15.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
3138
|
-
severity: import_shared15.Severity.WARNING,
|
|
3139
|
-
visibility: import_shared15.ErrorVisibility.BANNER
|
|
3140
|
-
})
|
|
3141
|
-
);
|
|
3142
|
-
import_shared15.styledConsole.logCopilotKitPlatformMessage();
|
|
3143
|
-
} else {
|
|
3144
|
-
setBannerError(null);
|
|
3145
|
-
}
|
|
3146
|
-
}, [hasPublicApiKey]);
|
|
3147
|
-
if (hasPublicApiKey) {
|
|
3148
|
-
return internalResult;
|
|
3149
|
-
}
|
|
3150
|
-
return createNonFunctionalReturn();
|
|
3151
|
-
}
|
|
3152
|
-
|
|
3153
|
-
// src/hooks/use-copilot-action.ts
|
|
3154
|
-
var import_react33 = require("react");
|
|
3155
|
-
|
|
3156
|
-
// src/hooks/use-frontend-tool.ts
|
|
3157
|
-
var import_react27 = __toESM(require("react"));
|
|
3158
|
-
var import_shared16 = require("@copilotkit/shared");
|
|
3159
|
-
var import_shared17 = require("@copilotkit/shared");
|
|
3160
|
-
var import_react28 = require("@copilotkitnext/react");
|
|
3161
|
-
function useFrontendTool(tool, dependencies) {
|
|
3162
|
-
const { name, description, parameters, render, followUp } = tool;
|
|
3163
|
-
const zodParameters = (0, import_shared16.getZodParameters)(parameters);
|
|
3164
|
-
const renderRef = (0, import_react27.useRef)(render);
|
|
3165
|
-
(0, import_react27.useEffect)(() => {
|
|
3166
|
-
renderRef.current = render;
|
|
3167
|
-
}, [render, ...dependencies != null ? dependencies : []]);
|
|
3168
|
-
const normalizedRender = (0, import_react27.useMemo)(() => {
|
|
3169
|
-
if (typeof render === "undefined") {
|
|
3170
|
-
return void 0;
|
|
3171
|
-
}
|
|
3172
|
-
return (args) => {
|
|
3173
|
-
const currentRender = renderRef.current;
|
|
3174
|
-
if (typeof currentRender === "undefined") {
|
|
3175
|
-
return null;
|
|
3176
|
-
}
|
|
3177
|
-
if (typeof currentRender === "string") {
|
|
3178
|
-
return import_react27.default.createElement(import_react27.default.Fragment, null, currentRender);
|
|
3179
|
-
}
|
|
3180
|
-
const renderArgs = __spreadProps(__spreadValues({}, args), {
|
|
3181
|
-
result: typeof args.result === "string" ? (0, import_shared17.parseJson)(args.result, args.result) : args.result
|
|
3182
|
-
});
|
|
3183
|
-
const rendered = currentRender(renderArgs);
|
|
3184
|
-
if (typeof rendered === "string") {
|
|
3185
|
-
return import_react27.default.createElement(import_react27.default.Fragment, null, rendered);
|
|
3186
|
-
}
|
|
3187
|
-
return rendered != null ? rendered : null;
|
|
3188
|
-
};
|
|
3189
|
-
}, []);
|
|
3190
|
-
const handlerRef = (0, import_react27.useRef)(tool.handler);
|
|
3191
|
-
(0, import_react27.useEffect)(() => {
|
|
3192
|
-
handlerRef.current = tool.handler;
|
|
3193
|
-
}, [tool.handler, ...dependencies != null ? dependencies : []]);
|
|
3194
|
-
const normalizedHandler = tool.handler ? (args) => {
|
|
3195
|
-
var _a;
|
|
3196
|
-
return (_a = handlerRef.current) == null ? void 0 : _a.call(handlerRef, args);
|
|
3197
|
-
} : void 0;
|
|
3198
|
-
(0, import_react28.useFrontendTool)({
|
|
3199
|
-
name,
|
|
3200
|
-
description,
|
|
3201
|
-
parameters: zodParameters,
|
|
3202
|
-
handler: normalizedHandler,
|
|
3203
|
-
followUp,
|
|
3204
|
-
render: normalizedRender
|
|
3205
|
-
});
|
|
3206
|
-
}
|
|
3207
|
-
|
|
3208
|
-
// src/hooks/use-render-tool-call.ts
|
|
3209
|
-
var import_shared18 = require("@copilotkit/shared");
|
|
3210
|
-
var import_shared19 = require("@copilotkit/shared");
|
|
3211
|
-
var import_react29 = require("@copilotkitnext/react");
|
|
3212
|
-
var import_react30 = require("react");
|
|
3213
|
-
function useRenderToolCall2(tool, dependencies) {
|
|
3214
|
-
const { copilotkit } = (0, import_react29.useCopilotKit)();
|
|
3215
|
-
const hasAddedRef = (0, import_react30.useRef)(false);
|
|
3216
|
-
(0, import_react30.useEffect)(() => {
|
|
3217
|
-
const { name, parameters, render } = tool;
|
|
3218
|
-
const zodParameters = (0, import_shared18.getZodParameters)(parameters);
|
|
3219
|
-
const renderToolCall = name === "*" ? (0, import_react29.defineToolCallRenderer)({
|
|
3220
|
-
name: "*",
|
|
3221
|
-
render: (args) => {
|
|
3222
|
-
return render(__spreadProps(__spreadValues({}, args), {
|
|
3223
|
-
result: args.result ? (0, import_shared19.parseJson)(args.result, args.result) : args.result
|
|
3224
|
-
}));
|
|
3225
|
-
}
|
|
3226
|
-
}) : (0, import_react29.defineToolCallRenderer)({
|
|
3227
|
-
name,
|
|
3228
|
-
args: zodParameters,
|
|
3229
|
-
render: (args) => {
|
|
3230
|
-
return render(__spreadProps(__spreadValues({}, args), {
|
|
3231
|
-
result: args.result ? (0, import_shared19.parseJson)(args.result, args.result) : args.result
|
|
3232
|
-
}));
|
|
3233
|
-
}
|
|
3234
|
-
});
|
|
3235
|
-
const existingIndex = copilotkit.renderToolCalls.findIndex(
|
|
3236
|
-
(r) => r.name === name
|
|
3237
|
-
);
|
|
3238
|
-
if (existingIndex !== -1) {
|
|
3239
|
-
copilotkit.renderToolCalls.splice(existingIndex, 1);
|
|
3240
|
-
}
|
|
3241
|
-
copilotkit.renderToolCalls.push(renderToolCall);
|
|
3242
|
-
hasAddedRef.current = true;
|
|
3243
|
-
return () => {
|
|
3244
|
-
if (hasAddedRef.current) {
|
|
3245
|
-
const index = copilotkit.renderToolCalls.findIndex(
|
|
3246
|
-
(r) => r.name === name
|
|
3247
|
-
);
|
|
3248
|
-
if (index !== -1) {
|
|
3249
|
-
copilotkit.renderToolCalls.splice(index, 1);
|
|
3250
|
-
}
|
|
3251
|
-
hasAddedRef.current = false;
|
|
3252
|
-
}
|
|
3253
|
-
};
|
|
3254
|
-
}, [tool, ...dependencies != null ? dependencies : []]);
|
|
3255
|
-
}
|
|
3256
|
-
|
|
3257
|
-
// src/hooks/use-human-in-the-loop.ts
|
|
3258
|
-
var import_shared20 = require("@copilotkit/shared");
|
|
3259
|
-
var import_react31 = require("@copilotkitnext/react");
|
|
3260
|
-
var import_core = require("@copilotkitnext/core");
|
|
3261
|
-
var import_react32 = __toESM(require("react"));
|
|
3262
|
-
function useHumanInTheLoop(tool, dependencies) {
|
|
3263
|
-
const _a = tool, { render } = _a, toolRest = __objRest(_a, ["render"]);
|
|
3264
|
-
const { name, description, parameters, followUp } = toolRest;
|
|
3265
|
-
const zodParameters = (0, import_shared20.getZodParameters)(parameters);
|
|
3266
|
-
const renderRef = (0, import_react32.useRef)(null);
|
|
3267
|
-
(0, import_react32.useEffect)(() => {
|
|
3268
|
-
renderRef.current = (args) => {
|
|
3269
|
-
if (typeof render === "string") {
|
|
3270
|
-
return import_react32.default.createElement(import_react32.default.Fragment, null, render);
|
|
3271
|
-
}
|
|
3272
|
-
if (!render) {
|
|
3273
|
-
return null;
|
|
3274
|
-
}
|
|
3275
|
-
const renderProps = (() => {
|
|
3276
|
-
const mappedArgs = args.args;
|
|
3277
|
-
switch (args.status) {
|
|
3278
|
-
case import_core.ToolCallStatus.InProgress:
|
|
3279
|
-
return {
|
|
3280
|
-
args: mappedArgs,
|
|
3281
|
-
respond: args.respond,
|
|
3282
|
-
status: args.status,
|
|
3283
|
-
handler: void 0
|
|
3284
|
-
};
|
|
3285
|
-
case import_core.ToolCallStatus.Executing:
|
|
3286
|
-
return {
|
|
3287
|
-
args: mappedArgs,
|
|
3288
|
-
respond: args.respond,
|
|
3289
|
-
status: args.status,
|
|
3290
|
-
handler: () => {
|
|
3291
|
-
}
|
|
3292
|
-
};
|
|
3293
|
-
case import_core.ToolCallStatus.Complete:
|
|
3294
|
-
return {
|
|
3295
|
-
args: mappedArgs,
|
|
3296
|
-
respond: args.respond,
|
|
3297
|
-
status: args.status,
|
|
3298
|
-
result: args.result ? (0, import_shared20.parseJson)(args.result, args.result) : args.result,
|
|
3299
|
-
handler: void 0
|
|
3300
|
-
};
|
|
3301
|
-
default:
|
|
3302
|
-
throw new import_shared20.CopilotKitError({
|
|
3303
|
-
code: import_shared20.CopilotKitErrorCode.UNKNOWN,
|
|
3304
|
-
message: `Invalid tool call status: ${args.status}`
|
|
3305
|
-
});
|
|
3306
|
-
}
|
|
3307
|
-
})();
|
|
3308
|
-
const rendered = render(renderProps);
|
|
3309
|
-
if (typeof rendered === "string") {
|
|
3310
|
-
return import_react32.default.createElement(import_react32.default.Fragment, null, rendered);
|
|
3311
|
-
}
|
|
3312
|
-
return rendered != null ? rendered : null;
|
|
3313
|
-
};
|
|
3314
|
-
}, [render, ...dependencies != null ? dependencies : []]);
|
|
3315
|
-
(0, import_react31.useHumanInTheLoop)({
|
|
3316
|
-
name,
|
|
3317
|
-
description,
|
|
3318
|
-
followUp,
|
|
3319
|
-
parameters: zodParameters,
|
|
3320
|
-
render: (args) => {
|
|
3321
|
-
var _a2, _b;
|
|
3322
|
-
return (_b = (_a2 = renderRef.current) == null ? void 0 : _a2.call(renderRef, args)) != null ? _b : null;
|
|
3323
|
-
}
|
|
3324
|
-
});
|
|
3325
|
-
}
|
|
3326
|
-
|
|
3327
|
-
// src/hooks/use-copilot-action.ts
|
|
3328
|
-
function getActionConfig(action) {
|
|
3329
|
-
if (action.name === "*") {
|
|
3330
|
-
return {
|
|
3331
|
-
type: "render",
|
|
3332
|
-
action
|
|
3333
|
-
};
|
|
3334
|
-
}
|
|
3335
|
-
if ("renderAndWaitForResponse" in action || "renderAndWait" in action) {
|
|
3336
|
-
let render = action.render;
|
|
3337
|
-
if (!render && "renderAndWaitForResponse" in action) {
|
|
3338
|
-
render = action.renderAndWaitForResponse;
|
|
3339
|
-
}
|
|
3340
|
-
if (!render && "renderAndWait" in action) {
|
|
3341
|
-
render = action.renderAndWait;
|
|
3342
|
-
}
|
|
3343
|
-
return {
|
|
3344
|
-
type: "hitl",
|
|
3345
|
-
action: __spreadProps(__spreadValues({}, action), { render })
|
|
3346
|
-
};
|
|
3347
|
-
}
|
|
3348
|
-
if ("available" in action) {
|
|
3349
|
-
if (action.available === "enabled" || action.available === "remote") {
|
|
3350
|
-
return {
|
|
3351
|
-
type: "frontend",
|
|
3352
|
-
action
|
|
3353
|
-
};
|
|
3354
|
-
}
|
|
3355
|
-
if (action.available === "frontend" || action.available === "disabled") {
|
|
3356
|
-
return {
|
|
3357
|
-
type: "render",
|
|
3358
|
-
action
|
|
3359
|
-
};
|
|
3360
|
-
}
|
|
3361
|
-
}
|
|
3362
|
-
if ("handler" in action) {
|
|
3363
|
-
return {
|
|
3364
|
-
type: "frontend",
|
|
3365
|
-
action
|
|
3366
|
-
};
|
|
3367
|
-
}
|
|
3368
|
-
throw new Error("Invalid action configuration");
|
|
3369
|
-
}
|
|
3370
|
-
function useCopilotAction(action, dependencies) {
|
|
3371
|
-
const [initialActionConfig] = (0, import_react33.useState)(getActionConfig(action));
|
|
3372
|
-
const currentActionConfig = getActionConfig(action);
|
|
3373
|
-
if (initialActionConfig.type !== currentActionConfig.type) {
|
|
3374
|
-
throw new Error("Action configuration changed between renders");
|
|
3375
|
-
}
|
|
3376
|
-
switch (currentActionConfig.type) {
|
|
3377
|
-
case "render":
|
|
3378
|
-
return useRenderToolCall2(currentActionConfig.action, dependencies);
|
|
3379
|
-
case "hitl":
|
|
3380
|
-
return useHumanInTheLoop(currentActionConfig.action, dependencies);
|
|
3381
|
-
case "frontend":
|
|
3382
|
-
return useFrontendTool(currentActionConfig.action, dependencies);
|
|
3383
|
-
default:
|
|
3384
|
-
throw new Error("Invalid action configuration");
|
|
3385
|
-
}
|
|
3386
|
-
}
|
|
3387
|
-
|
|
3388
|
-
// src/hooks/use-coagent-state-render.ts
|
|
3389
|
-
var import_react34 = require("react");
|
|
3390
|
-
var import_shared21 = require("@copilotkit/shared");
|
|
3391
|
-
function useCoAgentStateRender(action, dependencies) {
|
|
3392
|
-
const { chatComponentsCache, availableAgents } = (0, import_react34.useContext)(CopilotContext);
|
|
3393
|
-
const {
|
|
3394
|
-
setCoAgentStateRender,
|
|
3395
|
-
removeCoAgentStateRender,
|
|
3396
|
-
coAgentStateRenders
|
|
3397
|
-
} = useCoAgentStateRenders();
|
|
3398
|
-
const idRef = (0, import_react34.useRef)((0, import_shared21.randomId)());
|
|
3399
|
-
const { setBannerError, addToast } = useToast();
|
|
3400
|
-
(0, import_react34.useEffect)(() => {
|
|
3401
|
-
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
3402
|
-
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
3403
|
-
const agentError = new import_shared21.CopilotKitAgentDiscoveryError({
|
|
3404
|
-
agentName: action.name,
|
|
3405
|
-
availableAgents: availableAgents.map((a) => ({
|
|
3406
|
-
name: a.name,
|
|
3407
|
-
id: a.id
|
|
3408
|
-
}))
|
|
3409
|
-
});
|
|
3410
|
-
setBannerError(agentError);
|
|
3411
|
-
}
|
|
3412
|
-
}, [availableAgents]);
|
|
3413
|
-
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
3414
|
-
if (dependencies === void 0) {
|
|
3415
|
-
if (coAgentStateRenders[idRef.current]) {
|
|
3416
|
-
coAgentStateRenders[idRef.current].handler = action.handler;
|
|
3417
|
-
if (typeof action.render === "function") {
|
|
3418
|
-
if (chatComponentsCache.current !== null) {
|
|
3419
|
-
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
3420
|
-
}
|
|
3421
|
-
}
|
|
3422
|
-
}
|
|
3423
|
-
}
|
|
3424
|
-
(0, import_react34.useEffect)(() => {
|
|
3425
|
-
const currentId = idRef.current;
|
|
3426
|
-
const hasDuplicate = Object.entries(coAgentStateRenders).some(
|
|
3427
|
-
([id, otherAction]) => {
|
|
3428
|
-
if (id === currentId)
|
|
3429
|
-
return false;
|
|
3430
|
-
if (otherAction.name !== action.name)
|
|
3431
|
-
return false;
|
|
3432
|
-
const hasNodeName = !!action.nodeName;
|
|
3433
|
-
const hasOtherNodeName = !!otherAction.nodeName;
|
|
3434
|
-
if (!hasNodeName && !hasOtherNodeName)
|
|
3435
|
-
return true;
|
|
3436
|
-
if (hasNodeName !== hasOtherNodeName)
|
|
3437
|
-
return false;
|
|
3438
|
-
return action.nodeName === otherAction.nodeName;
|
|
3439
|
-
}
|
|
3440
|
-
);
|
|
3441
|
-
if (hasDuplicate) {
|
|
3442
|
-
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`;
|
|
3443
|
-
addToast({
|
|
3444
|
-
type: "warning",
|
|
3445
|
-
message,
|
|
3446
|
-
id: `dup-action-${action.name}`
|
|
3447
|
-
});
|
|
3448
|
-
}
|
|
3449
|
-
}, [coAgentStateRenders]);
|
|
3450
|
-
(0, import_react34.useEffect)(() => {
|
|
3451
|
-
setCoAgentStateRender(idRef.current, action);
|
|
3452
|
-
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
3453
|
-
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
3454
|
-
}
|
|
3455
|
-
return () => {
|
|
3456
|
-
removeCoAgentStateRender(idRef.current);
|
|
3457
|
-
};
|
|
3458
|
-
}, [
|
|
3459
|
-
setCoAgentStateRender,
|
|
3460
|
-
removeCoAgentStateRender,
|
|
3461
|
-
action.name,
|
|
3462
|
-
// include render only if it's a string
|
|
3463
|
-
typeof action.render === "string" ? action.render : void 0,
|
|
3464
|
-
// dependencies set by the developer
|
|
3465
|
-
...dependencies || []
|
|
3466
|
-
]);
|
|
3467
|
-
}
|
|
3468
|
-
|
|
3469
|
-
// src/hooks/use-make-copilot-document-readable.ts
|
|
3470
|
-
var import_react35 = require("react");
|
|
3471
|
-
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
3472
|
-
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
3473
|
-
const idRef = (0, import_react35.useRef)(void 0);
|
|
3474
|
-
(0, import_react35.useEffect)(() => {
|
|
3475
|
-
const id = addDocumentContext(document, categories);
|
|
3476
|
-
idRef.current = id;
|
|
3477
|
-
return () => {
|
|
3478
|
-
removeDocumentContext(id);
|
|
3479
|
-
};
|
|
3480
|
-
}, [addDocumentContext, removeDocumentContext, ...dependencies]);
|
|
3481
|
-
return idRef.current;
|
|
3482
|
-
}
|
|
3483
|
-
|
|
3484
|
-
// src/hooks/use-copilot-readable.ts
|
|
3485
|
-
var import_react36 = require("@copilotkitnext/react");
|
|
3486
|
-
var import_react37 = require("react");
|
|
3487
|
-
function useCopilotReadable({ description, value, convert, available }, dependencies) {
|
|
3488
|
-
const { copilotkit } = (0, import_react36.useCopilotKit)();
|
|
3489
|
-
const ctxIdRef = (0, import_react37.useRef)(void 0);
|
|
3490
|
-
(0, import_react37.useEffect)(() => {
|
|
3491
|
-
if (!copilotkit)
|
|
3492
|
-
return;
|
|
3493
|
-
const found = Object.entries(copilotkit.context).find(([id, ctxItem]) => {
|
|
3494
|
-
return JSON.stringify({ description, value }) == JSON.stringify(ctxItem);
|
|
3495
|
-
});
|
|
3496
|
-
if (found) {
|
|
3497
|
-
ctxIdRef.current = found[0];
|
|
3498
|
-
if (available === "disabled")
|
|
3499
|
-
copilotkit.removeContext(ctxIdRef.current);
|
|
3500
|
-
return;
|
|
3501
|
-
}
|
|
3502
|
-
if (!found && available === "disabled")
|
|
3503
|
-
return;
|
|
3504
|
-
ctxIdRef.current = copilotkit.addContext({
|
|
3505
|
-
description,
|
|
3506
|
-
value: (convert != null ? convert : JSON.stringify)(value)
|
|
3507
|
-
});
|
|
3508
|
-
return () => {
|
|
3509
|
-
if (!ctxIdRef.current)
|
|
3510
|
-
return;
|
|
3511
|
-
copilotkit.removeContext(ctxIdRef.current);
|
|
3512
|
-
};
|
|
3513
|
-
}, [description, value, convert]);
|
|
3514
|
-
return ctxIdRef.current;
|
|
3515
|
-
}
|
|
3516
|
-
|
|
3517
|
-
// src/hooks/use-coagent.ts
|
|
3518
|
-
var import_react38 = require("react");
|
|
3519
|
-
var import_react39 = require("@copilotkitnext/react");
|
|
3520
|
-
function useCoAgent(options) {
|
|
3521
|
-
const { agent } = (0, import_react39.useAgent)({ agentId: options.name });
|
|
3522
|
-
const { copilotkit } = (0, import_react39.useCopilotKit)();
|
|
3523
|
-
const nodeName = useAgentNodeName(options.name);
|
|
3524
|
-
const handleStateUpdate = (0, import_react38.useCallback)(
|
|
3525
|
-
(newState) => {
|
|
3526
|
-
if (!agent)
|
|
3527
|
-
return;
|
|
3528
|
-
if (typeof newState === "function") {
|
|
3529
|
-
const updater = newState;
|
|
3530
|
-
agent.setState(updater(agent.state));
|
|
3531
|
-
} else {
|
|
3532
|
-
agent.setState(__spreadValues(__spreadValues({}, agent.state), newState));
|
|
3533
|
-
}
|
|
3534
|
-
},
|
|
3535
|
-
[agent == null ? void 0 : agent.state, agent == null ? void 0 : agent.setState]
|
|
3536
|
-
);
|
|
3537
|
-
(0, import_react38.useEffect)(() => {
|
|
3538
|
-
var _a;
|
|
3539
|
-
if (!options.config && !options.configurable)
|
|
3540
|
-
return;
|
|
3541
|
-
let config = (_a = options.config) != null ? _a : {};
|
|
3542
|
-
if (options.configurable) {
|
|
3543
|
-
config = __spreadProps(__spreadValues({}, config), {
|
|
3544
|
-
configurable: __spreadValues(__spreadValues({}, options.configurable), config.configurable)
|
|
3545
|
-
});
|
|
3546
|
-
}
|
|
3547
|
-
copilotkit.setProperties(config);
|
|
3548
|
-
}, [options.config, options.configurable]);
|
|
3549
|
-
const externalStateStr = (0, import_react38.useMemo)(
|
|
3550
|
-
() => isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
3551
|
-
[
|
|
3552
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0
|
|
3553
|
-
]
|
|
3554
|
-
);
|
|
3555
|
-
(0, import_react38.useEffect)(() => {
|
|
3556
|
-
if ((agent == null ? void 0 : agent.state) && isExternalStateManagement(options) && JSON.stringify(options.state) !== JSON.stringify(agent.state)) {
|
|
3557
|
-
handleStateUpdate(options.state);
|
|
3558
|
-
}
|
|
3559
|
-
}, [agent, externalStateStr, handleStateUpdate]);
|
|
3560
|
-
const hasStateValues = (0, import_react38.useCallback)((value) => {
|
|
3561
|
-
return Boolean(value && Object.keys(value).length);
|
|
3562
|
-
}, []);
|
|
3563
|
-
const initialStateRef = (0, import_react38.useRef)(
|
|
3564
|
-
isExternalStateManagement(options) ? options.state : "initialState" in options ? options.initialState : void 0
|
|
3565
|
-
);
|
|
3566
|
-
(0, import_react38.useEffect)(() => {
|
|
3567
|
-
if (isExternalStateManagement(options)) {
|
|
3568
|
-
initialStateRef.current = options.state;
|
|
3569
|
-
} else if ("initialState" in options) {
|
|
3570
|
-
initialStateRef.current = options.initialState;
|
|
3571
|
-
}
|
|
3572
|
-
}, [
|
|
3573
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : "initialState" in options ? JSON.stringify(options.initialState) : void 0
|
|
3574
|
-
]);
|
|
3575
|
-
(0, import_react38.useEffect)(() => {
|
|
3576
|
-
if (!agent)
|
|
3577
|
-
return;
|
|
3578
|
-
const subscriber = {
|
|
3579
|
-
onStateChanged: (args) => {
|
|
3580
|
-
if (isExternalStateManagement(options)) {
|
|
3581
|
-
options.setState(args.state);
|
|
3582
|
-
}
|
|
3583
|
-
},
|
|
3584
|
-
onRunInitialized: (args) => {
|
|
3585
|
-
const runHasState = hasStateValues(args.state);
|
|
3586
|
-
if (runHasState) {
|
|
3587
|
-
handleStateUpdate(args.state);
|
|
3588
|
-
return;
|
|
3589
|
-
}
|
|
3590
|
-
if (hasStateValues(agent.state)) {
|
|
3591
|
-
return;
|
|
3592
|
-
}
|
|
3593
|
-
if (initialStateRef.current !== void 0) {
|
|
3594
|
-
handleStateUpdate(initialStateRef.current);
|
|
3595
|
-
}
|
|
3596
|
-
}
|
|
3597
|
-
};
|
|
3598
|
-
const subscription = agent.subscribe(subscriber);
|
|
3599
|
-
return () => {
|
|
3600
|
-
subscription.unsubscribe();
|
|
3601
|
-
};
|
|
3602
|
-
}, [agent, handleStateUpdate, hasStateValues]);
|
|
3603
|
-
return (0, import_react38.useMemo)(() => {
|
|
3604
|
-
var _a, _b, _c;
|
|
3605
|
-
if (!agent) {
|
|
3606
|
-
const noop = () => {
|
|
3607
|
-
};
|
|
3608
|
-
const noopAsync = () => __async(this, null, function* () {
|
|
3609
|
-
});
|
|
3610
|
-
const initialState = (
|
|
3611
|
-
// prefer externally provided state if available
|
|
3612
|
-
(_b = (_a = "state" in options && options.state) != null ? _a : (
|
|
3613
|
-
// then initialState if provided
|
|
3614
|
-
"initialState" in options && options.initialState
|
|
3615
|
-
)) != null ? _b : {}
|
|
3616
|
-
);
|
|
3617
|
-
return {
|
|
3618
|
-
name: options.name,
|
|
3619
|
-
nodeName,
|
|
3620
|
-
threadId: void 0,
|
|
3621
|
-
running: false,
|
|
3622
|
-
state: initialState,
|
|
3623
|
-
setState: noop,
|
|
3624
|
-
start: noop,
|
|
3625
|
-
stop: noop,
|
|
3626
|
-
run: noopAsync
|
|
3627
|
-
};
|
|
3628
|
-
}
|
|
3629
|
-
return {
|
|
3630
|
-
name: (_c = agent == null ? void 0 : agent.agentId) != null ? _c : options.name,
|
|
3631
|
-
nodeName,
|
|
3632
|
-
threadId: agent.threadId,
|
|
3633
|
-
running: agent.isRunning,
|
|
3634
|
-
state: agent.state,
|
|
3635
|
-
setState: handleStateUpdate,
|
|
3636
|
-
// TODO: start and run both have same thing. need to figure out
|
|
3637
|
-
start: agent.runAgent,
|
|
3638
|
-
stop: agent.abortRun,
|
|
3639
|
-
run: agent.runAgent
|
|
3640
|
-
};
|
|
3641
|
-
}, [
|
|
3642
|
-
agent == null ? void 0 : agent.state,
|
|
3643
|
-
agent == null ? void 0 : agent.runAgent,
|
|
3644
|
-
agent == null ? void 0 : agent.abortRun,
|
|
3645
|
-
agent == null ? void 0 : agent.runAgent,
|
|
3646
|
-
agent == null ? void 0 : agent.threadId,
|
|
3647
|
-
agent == null ? void 0 : agent.isRunning,
|
|
3648
|
-
agent == null ? void 0 : agent.agentId,
|
|
3649
|
-
handleStateUpdate,
|
|
3650
|
-
options.name
|
|
3651
|
-
]);
|
|
3652
|
-
}
|
|
3653
|
-
var isExternalStateManagement = (options) => {
|
|
3654
|
-
return "state" in options && "setState" in options;
|
|
3655
|
-
};
|
|
3656
|
-
|
|
3657
|
-
// src/hooks/use-copilot-runtime-client.ts
|
|
3658
|
-
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
3659
|
-
var import_react40 = require("react");
|
|
3660
|
-
var import_shared22 = require("@copilotkit/shared");
|
|
3661
|
-
var useCopilotRuntimeClient = (options) => {
|
|
3662
|
-
const { setBannerError } = useToast();
|
|
3663
|
-
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
3664
|
-
const lastStructuredErrorRef = (0, import_react40.useRef)(null);
|
|
3665
|
-
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
3666
|
-
try {
|
|
3667
|
-
const errorEvent = {
|
|
3668
|
-
type: "error",
|
|
3669
|
-
timestamp: Date.now(),
|
|
3670
|
-
context: {
|
|
3671
|
-
source: "ui",
|
|
3672
|
-
request: {
|
|
3673
|
-
operation: "runtimeClient",
|
|
3674
|
-
url: runtimeOptions.url,
|
|
3675
|
-
startTime: Date.now()
|
|
3676
|
-
},
|
|
3677
|
-
technical: {
|
|
3678
|
-
environment: "browser",
|
|
3679
|
-
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
3680
|
-
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
3681
|
-
}
|
|
3682
|
-
},
|
|
3683
|
-
error
|
|
3684
|
-
};
|
|
3685
|
-
yield onError(errorEvent);
|
|
3686
|
-
} catch (error2) {
|
|
3687
|
-
console.error("Error in onError handler:", error2);
|
|
3688
|
-
}
|
|
3689
|
-
});
|
|
3690
|
-
const runtimeClient = (0, import_react40.useMemo)(() => {
|
|
3691
|
-
return new import_runtime_client_gql3.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
3692
|
-
handleGQLErrors: (error) => {
|
|
3693
|
-
var _a2;
|
|
3694
|
-
if ((_a2 = error.graphQLErrors) == null ? void 0 : _a2.length) {
|
|
3695
|
-
const graphQLErrors = error.graphQLErrors;
|
|
3696
|
-
const routeError = (gqlError) => {
|
|
3697
|
-
const extensions = gqlError.extensions;
|
|
3698
|
-
const visibility = extensions == null ? void 0 : extensions.visibility;
|
|
3699
|
-
if (visibility === import_shared22.ErrorVisibility.SILENT) {
|
|
3700
|
-
console.error("CopilotKit Silent Error:", gqlError.message);
|
|
3701
|
-
return;
|
|
3702
|
-
}
|
|
3703
|
-
const now = Date.now();
|
|
3704
|
-
const errorMessage = gqlError.message;
|
|
3705
|
-
if (lastStructuredErrorRef.current && lastStructuredErrorRef.current.message === errorMessage && now - lastStructuredErrorRef.current.timestamp < 150) {
|
|
3706
|
-
return;
|
|
3707
|
-
}
|
|
3708
|
-
lastStructuredErrorRef.current = {
|
|
3709
|
-
message: errorMessage,
|
|
3710
|
-
timestamp: now
|
|
3711
|
-
};
|
|
3712
|
-
const ckError = createStructuredError(gqlError);
|
|
3713
|
-
if (ckError) {
|
|
3714
|
-
setBannerError(ckError);
|
|
3715
|
-
traceUIError(ckError, gqlError);
|
|
3716
|
-
} else {
|
|
3717
|
-
const fallbackError = new import_shared22.CopilotKitError({
|
|
3718
|
-
message: gqlError.message,
|
|
3719
|
-
code: import_shared22.CopilotKitErrorCode.UNKNOWN
|
|
3720
|
-
});
|
|
3721
|
-
setBannerError(fallbackError);
|
|
3722
|
-
traceUIError(fallbackError, gqlError);
|
|
3723
|
-
}
|
|
3724
|
-
};
|
|
3725
|
-
graphQLErrors.forEach(routeError);
|
|
3726
|
-
} else {
|
|
3727
|
-
const fallbackError = new import_shared22.CopilotKitError({
|
|
3728
|
-
message: (error == null ? void 0 : error.message) || String(error),
|
|
3729
|
-
code: import_shared22.CopilotKitErrorCode.UNKNOWN
|
|
3730
|
-
});
|
|
3731
|
-
setBannerError(fallbackError);
|
|
3732
|
-
traceUIError(fallbackError, error);
|
|
3733
|
-
}
|
|
3734
|
-
},
|
|
3735
|
-
handleGQLWarning: (message) => {
|
|
3736
|
-
console.warn(message);
|
|
3737
|
-
const warningError = new import_shared22.CopilotKitError({
|
|
3738
|
-
message,
|
|
3739
|
-
code: import_shared22.CopilotKitErrorCode.UNKNOWN
|
|
3740
|
-
});
|
|
3741
|
-
setBannerError(warningError);
|
|
3742
|
-
}
|
|
3743
|
-
}));
|
|
3744
|
-
}, [runtimeOptions, setBannerError, onError]);
|
|
3745
|
-
return runtimeClient;
|
|
3746
|
-
};
|
|
3747
|
-
function createStructuredError(gqlError) {
|
|
3748
|
-
var _a, _b, _c;
|
|
3749
|
-
const extensions = gqlError.extensions;
|
|
3750
|
-
const originalError = extensions == null ? void 0 : extensions.originalError;
|
|
3751
|
-
const message = (originalError == null ? void 0 : originalError.message) || gqlError.message;
|
|
3752
|
-
const code = extensions == null ? void 0 : extensions.code;
|
|
3753
|
-
if (code) {
|
|
3754
|
-
return new import_shared22.CopilotKitError({ message, code });
|
|
3755
|
-
}
|
|
3756
|
-
if ((_a = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _a.includes("CopilotApiDiscoveryError")) {
|
|
3757
|
-
return new import_shared22.CopilotKitApiDiscoveryError({ message });
|
|
3758
|
-
}
|
|
3759
|
-
if ((_b = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _b.includes("CopilotKitRemoteEndpointDiscoveryError")) {
|
|
3760
|
-
return new import_shared22.CopilotKitRemoteEndpointDiscoveryError({ message });
|
|
3761
|
-
}
|
|
3762
|
-
if ((_c = originalError == null ? void 0 : originalError.stack) == null ? void 0 : _c.includes("CopilotKitAgentDiscoveryError")) {
|
|
3763
|
-
return new import_shared22.CopilotKitAgentDiscoveryError({
|
|
3764
|
-
agentName: "",
|
|
3765
|
-
availableAgents: []
|
|
3766
|
-
});
|
|
3767
|
-
}
|
|
3768
|
-
return null;
|
|
3769
|
-
}
|
|
3770
|
-
|
|
3771
|
-
// src/hooks/use-copilot-authenticated-action.ts
|
|
3772
|
-
var import_react41 = require("react");
|
|
3773
|
-
var import_react42 = __toESM(require("react"));
|
|
3774
|
-
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
3775
|
-
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
3776
|
-
const pendingActionRef = (0, import_react41.useRef)(null);
|
|
3777
|
-
const executeAction = (0, import_react41.useCallback)(
|
|
3778
|
-
(props) => {
|
|
3779
|
-
if (typeof action.render === "function") {
|
|
3780
|
-
return action.render(props);
|
|
3781
|
-
}
|
|
3782
|
-
return action.render || import_react42.default.createElement(import_react41.Fragment);
|
|
3783
|
-
},
|
|
3784
|
-
[action]
|
|
3785
|
-
);
|
|
3786
|
-
const wrappedRender = (0, import_react41.useCallback)(
|
|
3787
|
-
(props) => {
|
|
3788
|
-
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
3789
|
-
(state) => state.status === "authenticated"
|
|
3790
|
-
);
|
|
3791
|
-
if (!isAuthenticated) {
|
|
3792
|
-
pendingActionRef.current = props;
|
|
3793
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react42.default.createElement(authConfig_c.SignInComponent, {
|
|
3794
|
-
onSignInComplete: (authState) => {
|
|
3795
|
-
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), {
|
|
3796
|
-
[action.name]: authState
|
|
3797
|
-
}));
|
|
3798
|
-
if (pendingActionRef.current) {
|
|
3799
|
-
executeAction(pendingActionRef.current);
|
|
3800
|
-
pendingActionRef.current = null;
|
|
3801
|
-
}
|
|
3802
|
-
}
|
|
3803
|
-
}) : import_react42.default.createElement(import_react41.Fragment);
|
|
3804
|
-
}
|
|
3805
|
-
return executeAction(props);
|
|
3806
|
-
},
|
|
3807
|
-
[action, authStates_c, setAuthStates_c]
|
|
3808
|
-
);
|
|
3809
|
-
useCopilotAction(
|
|
3810
|
-
__spreadProps(__spreadValues({}, action), {
|
|
3811
|
-
render: wrappedRender
|
|
3812
|
-
}),
|
|
3813
|
-
dependencies
|
|
3814
|
-
);
|
|
3815
|
-
}
|
|
3816
|
-
|
|
3817
|
-
// src/hooks/use-langgraph-interrupt.ts
|
|
3818
|
-
var import_react43 = require("react");
|
|
3819
|
-
var import_shared23 = require("@copilotkit/shared");
|
|
3820
|
-
function useLangGraphInterrupt(action, dependencies) {
|
|
3821
|
-
const {
|
|
3822
|
-
setInterruptAction,
|
|
3823
|
-
removeInterruptAction,
|
|
3824
|
-
interruptActions,
|
|
3825
|
-
threadId
|
|
3826
|
-
} = (0, import_react43.useContext)(CopilotContext);
|
|
3827
|
-
const { addToast } = useToast();
|
|
3828
|
-
const actionId = (0, import_shared23.dataToUUID)(action, "lgAction");
|
|
3829
|
-
(0, import_react43.useEffect)(() => {
|
|
3830
|
-
if (!action)
|
|
3831
|
-
return;
|
|
3832
|
-
setInterruptAction(__spreadProps(__spreadValues({}, action), { id: actionId }));
|
|
3833
|
-
return () => {
|
|
3834
|
-
removeInterruptAction(actionId);
|
|
3835
|
-
};
|
|
3836
|
-
}, [
|
|
3837
|
-
setInterruptAction,
|
|
3838
|
-
removeInterruptAction,
|
|
3839
|
-
threadId,
|
|
3840
|
-
actionId,
|
|
3841
|
-
...dependencies || []
|
|
3842
|
-
]);
|
|
3843
|
-
}
|
|
3844
|
-
|
|
3845
|
-
// src/hooks/use-copilot-additional-instructions.ts
|
|
3846
|
-
var import_react44 = require("react");
|
|
3847
|
-
function useCopilotAdditionalInstructions({
|
|
3848
|
-
instructions,
|
|
3849
|
-
available = "enabled"
|
|
3850
|
-
}, dependencies) {
|
|
3851
|
-
const { setAdditionalInstructions } = useCopilotContext();
|
|
3852
|
-
(0, import_react44.useEffect)(() => {
|
|
3853
|
-
if (available === "disabled")
|
|
3854
|
-
return;
|
|
3855
|
-
setAdditionalInstructions((prevInstructions) => [
|
|
3856
|
-
...prevInstructions || [],
|
|
3857
|
-
instructions
|
|
3858
|
-
]);
|
|
3859
|
-
return () => {
|
|
3860
|
-
setAdditionalInstructions(
|
|
3861
|
-
(prevInstructions) => (prevInstructions == null ? void 0 : prevInstructions.filter(
|
|
3862
|
-
(instruction) => instruction !== instructions
|
|
3863
|
-
)) || []
|
|
3864
|
-
);
|
|
3865
|
-
};
|
|
3866
|
-
}, [
|
|
3867
|
-
available,
|
|
3868
|
-
instructions,
|
|
3869
|
-
setAdditionalInstructions,
|
|
3870
|
-
...dependencies || []
|
|
3871
|
-
]);
|
|
3872
|
-
}
|
|
3873
|
-
|
|
3874
|
-
// src/hooks/use-default-tool.ts
|
|
3875
|
-
function useDefaultTool(tool, dependencies) {
|
|
3876
|
-
useCopilotAction(
|
|
3877
|
-
__spreadProps(__spreadValues({}, tool), { name: "*" }),
|
|
3878
|
-
dependencies
|
|
3879
|
-
);
|
|
3880
|
-
}
|
|
3881
|
-
|
|
3882
|
-
// src/hooks/use-copilot-chat-suggestions.tsx
|
|
3883
|
-
var import_react45 = require("@copilotkitnext/react");
|
|
3884
|
-
function useCopilotChatSuggestions(config, dependencies = []) {
|
|
3885
|
-
var _a, _b;
|
|
3886
|
-
const existingConfig = (0, import_react45.useCopilotChatConfiguration)();
|
|
3887
|
-
const resolvedAgentId = (_a = existingConfig == null ? void 0 : existingConfig.agentId) != null ? _a : "default";
|
|
3888
|
-
const available = (_b = config.available === "enabled" ? "always" : config.available) != null ? _b : "before-first-message";
|
|
3889
|
-
const finalSuggestionConfig = __spreadProps(__spreadValues({}, config), {
|
|
3890
|
-
available,
|
|
3891
|
-
consumerAgentId: resolvedAgentId
|
|
3892
|
-
// Use chatConfig.agentId here
|
|
3893
|
-
});
|
|
3894
|
-
(0, import_react45.useConfigureSuggestions)(finalSuggestionConfig, dependencies);
|
|
3895
|
-
}
|
|
3896
|
-
|
|
3897
|
-
// src/lib/copilot-task.ts
|
|
3898
|
-
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
3899
|
-
|
|
3900
|
-
// src/types/frontend-action.ts
|
|
3901
|
-
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
3902
|
-
var import_shared24 = require("@copilotkit/shared");
|
|
3903
|
-
function processActionsForRuntimeRequest(actions) {
|
|
3904
|
-
const filteredActions = actions.filter(
|
|
3905
|
-
(action) => action.available !== import_runtime_client_gql4.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
3906
|
-
).map((action) => {
|
|
3907
|
-
let available = import_runtime_client_gql4.ActionInputAvailability.Enabled;
|
|
3908
|
-
if (action.disabled) {
|
|
3909
|
-
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
3910
|
-
} else if (action.available === "disabled") {
|
|
3911
|
-
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
3912
|
-
} else if (action.available === "remote") {
|
|
3913
|
-
available = import_runtime_client_gql4.ActionInputAvailability.Remote;
|
|
3914
|
-
}
|
|
3915
|
-
return {
|
|
3916
|
-
name: action.name,
|
|
3917
|
-
description: action.description || "",
|
|
3918
|
-
jsonSchema: JSON.stringify(
|
|
3919
|
-
(0, import_shared24.actionParametersToJsonSchema)(action.parameters || [])
|
|
3920
|
-
),
|
|
3921
|
-
available
|
|
3922
|
-
};
|
|
3923
|
-
});
|
|
3924
|
-
return filteredActions;
|
|
3925
|
-
}
|
|
3926
|
-
|
|
3927
|
-
// src/lib/copilot-task.ts
|
|
3928
|
-
var CopilotTask = class {
|
|
3929
|
-
constructor(config) {
|
|
3930
|
-
this.instructions = config.instructions;
|
|
3931
|
-
this.actions = config.actions || [];
|
|
3932
|
-
this.includeCopilotReadable = config.includeCopilotReadable !== false;
|
|
3933
|
-
this.includeCopilotActions = config.includeCopilotActions !== false;
|
|
3934
|
-
this.forwardedParameters = config.forwardedParameters;
|
|
3935
|
-
}
|
|
3936
|
-
/**
|
|
3937
|
-
* Run the task.
|
|
3938
|
-
* @param context The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.
|
|
3939
|
-
* @param data The data to use for the task.
|
|
3940
|
-
*/
|
|
3941
|
-
run(context, data) {
|
|
3942
|
-
return __async(this, null, function* () {
|
|
3943
|
-
var _a, _b, _c;
|
|
3944
|
-
const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};
|
|
3945
|
-
for (const fn of this.actions) {
|
|
3946
|
-
actions[fn.name] = fn;
|
|
3947
|
-
}
|
|
3948
|
-
let contextString = "";
|
|
3949
|
-
if (data) {
|
|
3950
|
-
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
3951
|
-
}
|
|
3952
|
-
if (this.includeCopilotReadable) {
|
|
3953
|
-
contextString += context.getContextString(
|
|
3954
|
-
[],
|
|
3955
|
-
defaultCopilotContextCategories
|
|
3956
|
-
);
|
|
3957
|
-
}
|
|
3958
|
-
const systemMessage = new import_runtime_client_gql5.TextMessage({
|
|
3959
|
-
content: taskSystemMessage(contextString, this.instructions),
|
|
3960
|
-
role: import_runtime_client_gql5.Role.System
|
|
3961
|
-
});
|
|
3962
|
-
const messages = [systemMessage];
|
|
3963
|
-
const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
3964
|
-
url: context.copilotApiConfig.chatApiEndpoint,
|
|
3965
|
-
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
3966
|
-
headers: context.copilotApiConfig.headers,
|
|
3967
|
-
credentials: context.copilotApiConfig.credentials
|
|
3968
|
-
});
|
|
3969
|
-
const response = yield runtimeClient.generateCopilotResponse({
|
|
3970
|
-
data: {
|
|
3971
|
-
frontend: {
|
|
3972
|
-
actions: processActionsForRuntimeRequest(Object.values(actions)),
|
|
3973
|
-
url: window.location.href
|
|
3974
|
-
},
|
|
3975
|
-
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(
|
|
3976
|
-
(0, import_runtime_client_gql5.filterAgentStateMessages)(messages)
|
|
3977
|
-
),
|
|
3978
|
-
metadata: {
|
|
3979
|
-
requestType: import_runtime_client_gql5.CopilotRequestType.Task
|
|
3980
|
-
},
|
|
3981
|
-
forwardedParameters: __spreadValues({
|
|
3982
|
-
// if forwardedParameters is provided, use it
|
|
3983
|
-
toolChoice: "required"
|
|
3984
|
-
}, (_a = this.forwardedParameters) != null ? _a : {})
|
|
3985
|
-
},
|
|
3986
|
-
properties: context.copilotApiConfig.properties
|
|
3987
|
-
}).toPromise();
|
|
3988
|
-
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
3989
|
-
const functionCalls = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
|
|
3990
|
-
((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
|
|
3991
|
-
).filter((m) => m.isActionExecutionMessage());
|
|
3992
|
-
for (const functionCall of functionCalls) {
|
|
3993
|
-
yield functionCallHandler({
|
|
3994
|
-
messages,
|
|
3995
|
-
name: functionCall.name,
|
|
3996
|
-
args: functionCall.arguments
|
|
3997
|
-
});
|
|
3998
|
-
}
|
|
3999
|
-
});
|
|
4000
|
-
}
|
|
4001
|
-
};
|
|
4002
|
-
function taskSystemMessage(contextString, instructions) {
|
|
4003
|
-
return `
|
|
4004
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
4005
|
-
|
|
4006
|
-
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
4007
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
4008
|
-
|
|
4009
|
-
The user has provided you with the following context:
|
|
4010
|
-
\`\`\`
|
|
4011
|
-
${contextString}
|
|
4012
|
-
\`\`\`
|
|
4013
|
-
|
|
4014
|
-
They have also provided you with functions you can call to initiate actions on their behalf.
|
|
4015
|
-
|
|
4016
|
-
Please assist them as best you can.
|
|
4017
|
-
|
|
4018
|
-
This is not a conversation, so please do not ask questions. Just call a function without saying anything else.
|
|
4019
|
-
|
|
4020
|
-
The user has given you the following task to complete:
|
|
4021
|
-
|
|
4022
|
-
\`\`\`
|
|
4023
|
-
${instructions}
|
|
4024
|
-
\`\`\`
|
|
4025
|
-
`;
|
|
4026
|
-
}
|
|
4027
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
4028
|
-
0 && (module.exports = {
|
|
4029
|
-
CoAgentStateRendersContext,
|
|
4030
|
-
CoAgentStateRendersProvider,
|
|
4031
|
-
CopilotContext,
|
|
4032
|
-
CopilotKit,
|
|
4033
|
-
CopilotMessagesContext,
|
|
4034
|
-
CopilotTask,
|
|
4035
|
-
SUGGESTION_RETRY_CONFIG,
|
|
4036
|
-
ThreadsContext,
|
|
4037
|
-
ThreadsProvider,
|
|
4038
|
-
defaultCopilotContextCategories,
|
|
4039
|
-
shouldShowDevConsole,
|
|
4040
|
-
useCoAgent,
|
|
4041
|
-
useCoAgentStateRender,
|
|
4042
|
-
useCoAgentStateRenders,
|
|
4043
|
-
useCopilotAction,
|
|
4044
|
-
useCopilotAdditionalInstructions,
|
|
4045
|
-
useCopilotAuthenticatedAction_c,
|
|
4046
|
-
useCopilotChat,
|
|
4047
|
-
useCopilotChatHeadless_c,
|
|
4048
|
-
useCopilotChatInternal,
|
|
4049
|
-
useCopilotChatSuggestions,
|
|
4050
|
-
useCopilotContext,
|
|
4051
|
-
useCopilotMessagesContext,
|
|
4052
|
-
useCopilotReadable,
|
|
4053
|
-
useCopilotRuntimeClient,
|
|
4054
|
-
useDefaultTool,
|
|
4055
|
-
useFrontendTool,
|
|
4056
|
-
useHumanInTheLoop,
|
|
4057
|
-
useLangGraphInterrupt,
|
|
4058
|
-
useLangGraphInterruptRender,
|
|
4059
|
-
useLazyToolRenderer,
|
|
4060
|
-
useMakeCopilotDocumentReadable,
|
|
4061
|
-
useRenderToolCall,
|
|
4062
|
-
useThreads
|
|
4063
|
-
});
|
|
4064
|
-
//# sourceMappingURL=index.js.map
|