@copilotkit/react-core 1.10.7-next.0 → 1.50.0-beta.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/CHANGELOG.md +0 -7
- package/dist/chunk-24SCZAB4.mjs +143 -0
- package/dist/chunk-24SCZAB4.mjs.map +1 -0
- package/dist/chunk-36KQV2NA.mjs +1 -0
- package/dist/{chunk-U7QULEVO.mjs → chunk-3GURHDG7.mjs} +3 -3
- package/dist/{chunk-OAGAFMUM.mjs → chunk-3R423LZT.mjs} +6 -5
- package/dist/{chunk-OAGAFMUM.mjs.map → chunk-3R423LZT.mjs.map} +1 -1
- package/dist/chunk-5X5DJRQQ.mjs +71 -0
- package/dist/chunk-5X5DJRQQ.mjs.map +1 -0
- package/dist/{chunk-N4WEHORG.mjs → chunk-6PUNP7CD.mjs} +4 -4
- package/dist/chunk-6PUNP7CD.mjs.map +1 -0
- package/dist/chunk-7BYHZLPL.mjs +32 -0
- package/dist/chunk-7BYHZLPL.mjs.map +1 -0
- package/dist/chunk-7DTB7S5V.mjs +83 -0
- package/dist/chunk-7DTB7S5V.mjs.map +1 -0
- package/dist/chunk-A6NKSGH3.mjs +1 -0
- package/dist/{chunk-GT5WI3AF.mjs → chunk-BR5YEYZJ.mjs} +7 -9
- package/dist/chunk-BR5YEYZJ.mjs.map +1 -0
- package/dist/chunk-CB7CRBDG.mjs +48 -0
- package/dist/chunk-CB7CRBDG.mjs.map +1 -0
- package/dist/chunk-CYDWEPFL.mjs +1 -0
- package/dist/{chunk-BBUQMG45.mjs → chunk-D3QSYDJR.mjs} +3 -3
- package/dist/{chunk-BBUQMG45.mjs.map → chunk-D3QSYDJR.mjs.map} +1 -1
- package/dist/chunk-DCHSCK62.mjs +549 -0
- package/dist/chunk-DCHSCK62.mjs.map +1 -0
- package/dist/{chunk-ZLQVRPDS.mjs → chunk-DMLQZG75.mjs} +1 -1
- package/dist/chunk-DMLQZG75.mjs.map +1 -0
- package/dist/chunk-F555TVE4.mjs +33 -0
- package/dist/chunk-F555TVE4.mjs.map +1 -0
- package/dist/{chunk-C6IANC2R.mjs → chunk-FBD24VEH.mjs} +7 -43
- package/dist/chunk-FBD24VEH.mjs.map +1 -0
- package/dist/chunk-FD6FGKYY.mjs +1 -0
- package/dist/chunk-FDOMAPJY.mjs +59 -0
- package/dist/chunk-FDOMAPJY.mjs.map +1 -0
- package/dist/{chunk-E3624YDU.mjs → chunk-GMI4KO4X.mjs} +8 -6
- package/dist/{chunk-E3624YDU.mjs.map → chunk-GMI4KO4X.mjs.map} +1 -1
- package/dist/chunk-IUSKVYUI.mjs +13 -0
- package/dist/chunk-IUSKVYUI.mjs.map +1 -0
- package/dist/chunk-JD7BAH7U.mjs +1 -0
- package/dist/{chunk-EDBI5PCJ.mjs → chunk-JRT5BJF3.mjs} +2 -2
- package/dist/{chunk-N4VN2B5S.mjs → chunk-LHERIF3L.mjs} +2 -2
- package/dist/{chunk-DXEQPN43.mjs → chunk-LHKZJ2ND.mjs} +3 -3
- package/dist/chunk-NB2FKV2V.mjs +1 -0
- package/dist/chunk-NBK4KBLX.mjs +54 -0
- package/dist/chunk-NBK4KBLX.mjs.map +1 -0
- package/dist/chunk-NG26QEGF.mjs +46 -0
- package/dist/chunk-NG26QEGF.mjs.map +1 -0
- package/dist/chunk-NROJOTQP.mjs +163 -0
- package/dist/chunk-NROJOTQP.mjs.map +1 -0
- package/dist/{chunk-MGWRDFBE.mjs → chunk-OVYFRPSN.mjs} +2 -2
- package/dist/{chunk-MQYWH4E6.mjs → chunk-QU6NONOD.mjs} +2 -2
- package/dist/chunk-R4MR43UQ.mjs +101 -0
- package/dist/chunk-R4MR43UQ.mjs.map +1 -0
- package/dist/chunk-SPCZTZCY.mjs +1 -0
- package/dist/chunk-SPCZTZCY.mjs.map +1 -0
- package/dist/chunk-TXI72QHK.mjs +80 -0
- package/dist/chunk-TXI72QHK.mjs.map +1 -0
- package/dist/chunk-UJBV5GAG.mjs +767 -0
- package/dist/chunk-UJBV5GAG.mjs.map +1 -0
- package/dist/{chunk-OKCYPO4I.mjs → chunk-WMJVBMUX.mjs} +3 -3
- package/dist/{chunk-EUX2P2E7.mjs → chunk-WVLHXIFP.mjs} +11 -9
- package/dist/chunk-WVLHXIFP.mjs.map +1 -0
- package/dist/{chunk-5FHSUKQL.mjs → chunk-YYN33GSG.mjs} +5 -2
- package/dist/chunk-YYN33GSG.mjs.map +1 -0
- package/dist/chunk-ZVF5Q6IH.mjs +29 -0
- package/dist/chunk-ZVF5Q6IH.mjs.map +1 -0
- package/dist/components/CopilotListeners.d.ts +3 -0
- package/dist/components/CopilotListeners.js +234 -0
- package/dist/components/CopilotListeners.js.map +1 -0
- package/dist/components/CopilotListeners.mjs +14 -0
- package/dist/components/CopilotListeners.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +14 -48
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.d.ts +9 -2
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.js +528 -370
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +15 -10
- package/dist/components/copilot-provider/index.d.ts +2 -1
- package/dist/components/copilot-provider/index.js +528 -370
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +16 -10
- package/dist/components/dev-console/console-trigger.js +10 -8
- package/dist/components/dev-console/console-trigger.js.map +1 -1
- package/dist/components/dev-console/console-trigger.mjs +4 -4
- package/dist/components/dev-console/developer-console-modal.js +10 -8
- package/dist/components/dev-console/developer-console-modal.js.map +1 -1
- package/dist/components/dev-console/developer-console-modal.mjs +3 -3
- package/dist/components/error-boundary/error-boundary.d.ts +7 -7
- package/dist/components/error-boundary/error-boundary.js +3 -3
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/error-boundary/error-utils.d.ts +1 -1
- package/dist/components/error-boundary/error-utils.js +3 -3
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +528 -370
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +17 -10
- package/dist/components/toast/exclamation-mark-icon.d.ts +2 -2
- package/dist/components/toast/toast-provider.d.ts +3 -3
- package/dist/components/usage-banner.d.ts +2 -2
- package/dist/context/coagent-state-renders-context.d.ts +24 -0
- package/dist/context/coagent-state-renders-context.js +91 -0
- package/dist/context/coagent-state-renders-context.js.map +1 -0
- package/dist/context/coagent-state-renders-context.mjs +12 -0
- package/dist/context/coagent-state-renders-context.mjs.map +1 -0
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +10 -8
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/copilot-messages-context.d.ts +18 -11
- package/dist/context/copilot-messages-context.js.map +1 -1
- package/dist/context/copilot-messages-context.mjs +1 -1
- package/dist/context/index.d.ts +6 -2
- package/dist/context/index.js +110 -10
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +20 -4
- package/dist/context/threads-context.d.ts +16 -0
- package/dist/context/threads-context.js +59 -0
- package/dist/context/threads-context.js.map +1 -0
- package/dist/context/threads-context.mjs +12 -0
- package/dist/context/threads-context.mjs.map +1 -0
- package/dist/{copilot-context-cf9de848.d.ts → copilot-context-1cd70a3f.d.ts} +36 -32
- package/dist/hooks/index.d.ts +9 -6
- package/dist/hooks/index.js +1445 -1839
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +47 -56
- package/dist/hooks/use-coagent-state-render-bridge.d.ts +100 -0
- package/dist/hooks/use-coagent-state-render-bridge.js +211 -0
- package/dist/hooks/use-coagent-state-render-bridge.js.map +1 -0
- package/dist/hooks/use-coagent-state-render-bridge.mjs +15 -0
- package/dist/hooks/use-coagent-state-render-bridge.mjs.map +1 -0
- package/dist/hooks/use-coagent-state-render.js +31 -20
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -2
- package/dist/hooks/use-coagent.d.ts +2 -14
- package/dist/hooks/use-coagent.js +109 -1906
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +1 -30
- package/dist/hooks/use-configure-chat-suggestions.d.ts +36 -0
- package/dist/hooks/use-configure-chat-suggestions.js +210 -0
- package/dist/hooks/use-configure-chat-suggestions.js.map +1 -0
- package/dist/hooks/use-configure-chat-suggestions.mjs +13 -0
- package/dist/hooks/use-configure-chat-suggestions.mjs.map +1 -0
- package/dist/hooks/use-copilot-action.d.ts +8 -45
- package/dist/hooks/use-copilot-action.js +207 -349
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -5
- package/dist/hooks/use-copilot-additional-instructions.js +10 -8
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +224 -248
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +6 -6
- package/dist/hooks/use-copilot-chat-headless_c.d.ts +2 -10
- package/dist/hooks/use-copilot-chat-headless_c.js +973 -1369
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -1
- package/dist/hooks/use-copilot-chat-headless_c.mjs +12 -22
- package/dist/hooks/use-copilot-chat.d.ts +2 -10
- package/dist/hooks/use-copilot-chat.js +967 -1388
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +12 -22
- package/dist/hooks/use-copilot-chat_internal.d.ts +38 -14
- package/dist/hooks/use-copilot-chat_internal.js +965 -1362
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +13 -23
- package/dist/hooks/use-copilot-readable.d.ts +1 -1
- package/dist/hooks/use-copilot-readable.js +6 -157
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +1 -2
- package/dist/hooks/use-default-tool.js +204 -349
- package/dist/hooks/use-default-tool.js.map +1 -1
- package/dist/hooks/use-default-tool.mjs +5 -6
- package/dist/hooks/use-flat-category-store.js +4 -1
- package/dist/hooks/use-flat-category-store.js.map +1 -1
- package/dist/hooks/use-flat-category-store.mjs +1 -1
- package/dist/hooks/use-frontend-tool.d.ts +3 -3
- package/dist/hooks/use-frontend-tool.js +30 -370
- package/dist/hooks/use-frontend-tool.js.map +1 -1
- package/dist/hooks/use-frontend-tool.mjs +1 -6
- package/dist/hooks/use-human-in-the-loop.d.ts +4 -3
- package/dist/hooks/use-human-in-the-loop.js +61 -393
- package/dist/hooks/use-human-in-the-loop.js.map +1 -1
- package/dist/hooks/use-human-in-the-loop.mjs +1 -6
- package/dist/hooks/use-langgraph-interrupt-render.d.ts +3 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +92 -36
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +6 -4
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +24 -1642
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +2 -23
- package/dist/hooks/use-lazy-tool-renderer.d.ts +6 -0
- package/dist/hooks/use-lazy-tool-renderer.js +53 -0
- package/dist/hooks/use-lazy-tool-renderer.js.map +1 -0
- package/dist/hooks/use-lazy-tool-renderer.mjs +8 -0
- package/dist/hooks/use-lazy-tool-renderer.mjs.map +1 -0
- package/dist/hooks/use-make-copilot-document-readable.js +11 -9
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/hooks/use-render-tool-call.d.ts +7 -6
- package/dist/hooks/use-render-tool-call.js +36 -386
- package/dist/hooks/use-render-tool-call.js.map +1 -1
- package/dist/hooks/use-render-tool-call.mjs +1 -6
- package/dist/index.d.ts +11 -6
- package/dist/index.js +1841 -2056
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +78 -59
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js +1 -0
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +18 -11
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +18 -11
- package/dist/setupTests.d.ts +2 -2
- package/dist/types/frontend-action.d.ts +5 -5
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/index.mjs +2 -1
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/types/interrupt-action.js.map +1 -1
- package/dist/types/interrupt-action.mjs +1 -0
- package/dist/utils/index.d.ts +0 -12
- package/dist/utils/index.js +6 -325
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +1 -21
- package/dist/utils/utils.js.map +1 -1
- package/dist/v2/index.d.ts +2 -0
- package/dist/v2/index.js +27 -0
- package/dist/v2/index.js.map +1 -0
- package/dist/v2/index.mjs +4 -0
- package/dist/v2/index.mjs.map +1 -0
- package/package.json +20 -9
- package/src/components/CopilotListeners.tsx +82 -0
- package/src/components/copilot-provider/copilot-messages.tsx +46 -47
- package/src/components/copilot-provider/copilotkit-props.tsx +8 -1
- package/src/components/copilot-provider/copilotkit.tsx +177 -144
- package/src/components/error-boundary/error-utils.tsx +3 -3
- package/src/context/coagent-state-renders-context.tsx +76 -0
- package/src/context/copilot-context.tsx +21 -21
- package/src/context/copilot-messages-context.tsx +3 -3
- package/src/context/index.ts +8 -0
- package/src/context/threads-context.tsx +41 -0
- package/src/hooks/index.ts +7 -3
- package/src/hooks/use-coagent-state-render-bridge.tsx +293 -0
- package/src/hooks/use-coagent-state-render.ts +4 -7
- package/src/hooks/use-coagent.ts +129 -249
- package/src/hooks/use-configure-chat-suggestions.tsx +85 -0
- package/src/hooks/use-copilot-action.ts +88 -199
- package/src/hooks/use-copilot-chat-headless_c.ts +2 -1
- package/src/hooks/use-copilot-chat.ts +4 -1
- package/src/hooks/use-copilot-chat_internal.ts +349 -258
- package/src/hooks/use-copilot-readable.ts +6 -26
- package/src/hooks/use-flat-category-store.ts +4 -3
- package/src/hooks/use-frontend-tool.ts +67 -8
- package/src/hooks/use-human-in-the-loop.ts +111 -13
- package/src/hooks/use-langgraph-interrupt-render.ts +90 -40
- package/src/hooks/use-langgraph-interrupt.ts +18 -47
- package/src/hooks/use-lazy-tool-renderer.tsx +30 -0
- package/src/hooks/use-make-copilot-document-readable.ts +1 -1
- package/src/hooks/use-render-tool-call.ts +73 -13
- package/src/types/index.ts +1 -0
- package/src/types/interrupt-action.ts +8 -4
- package/src/utils/index.ts +0 -3
- package/src/utils/utils.ts +7 -0
- package/src/v2/index.ts +2 -0
- package/src/v2/styles.css +1 -0
- package/tsup.config.ts +1 -1
- package/dist/chunk-5FHSUKQL.mjs.map +0 -1
- package/dist/chunk-6GPVUMBU.mjs +0 -13
- package/dist/chunk-6GPVUMBU.mjs.map +0 -1
- package/dist/chunk-AKR2SSUJ.mjs +0 -22
- package/dist/chunk-AKR2SSUJ.mjs.map +0 -1
- package/dist/chunk-BXXJQ2BL.mjs +0 -239
- package/dist/chunk-BXXJQ2BL.mjs.map +0 -1
- package/dist/chunk-C6IANC2R.mjs.map +0 -1
- package/dist/chunk-DZTU6PGS.mjs +0 -1
- package/dist/chunk-EUX2P2E7.mjs.map +0 -1
- package/dist/chunk-EVVO67QO.mjs +0 -25
- package/dist/chunk-EVVO67QO.mjs.map +0 -1
- package/dist/chunk-GGLAHG3I.mjs +0 -804
- package/dist/chunk-GGLAHG3I.mjs.map +0 -1
- package/dist/chunk-GT5WI3AF.mjs.map +0 -1
- package/dist/chunk-HDOG2RTM.mjs +0 -37
- package/dist/chunk-HDOG2RTM.mjs.map +0 -1
- package/dist/chunk-MIXSWZSB.mjs +0 -71
- package/dist/chunk-MIXSWZSB.mjs.map +0 -1
- package/dist/chunk-N4WEHORG.mjs.map +0 -1
- package/dist/chunk-NSBAWITG.mjs +0 -332
- package/dist/chunk-NSBAWITG.mjs.map +0 -1
- package/dist/chunk-OT5NHMEC.mjs +0 -723
- package/dist/chunk-OT5NHMEC.mjs.map +0 -1
- package/dist/chunk-T3376SZS.mjs +0 -142
- package/dist/chunk-T3376SZS.mjs.map +0 -1
- package/dist/chunk-YPBKY4KY.mjs +0 -1
- package/dist/chunk-YPSGKPDA.mjs +0 -1
- package/dist/chunk-ZLQVRPDS.mjs.map +0 -1
- package/dist/chunk-ZVOLWJCY.mjs +0 -47
- package/dist/chunk-ZVOLWJCY.mjs.map +0 -1
- package/dist/hooks/use-chat.d.ts +0 -145
- package/dist/hooks/use-chat.js +0 -1129
- package/dist/hooks/use-chat.js.map +0 -1
- package/dist/hooks/use-chat.mjs +0 -14
- package/dist/index-1f5b66ac.d.ts +0 -36
- package/dist/utils/extract.d.ts +0 -43
- package/dist/utils/extract.js +0 -208
- package/dist/utils/extract.js.map +0 -1
- package/dist/utils/extract.mjs +0 -25
- package/dist/utils/suggestions.d.ts +0 -11
- package/dist/utils/suggestions.js +0 -343
- package/dist/utils/suggestions.js.map +0 -1
- package/dist/utils/suggestions.mjs +0 -25
- package/src/hooks/use-chat.ts +0 -1142
- package/src/utils/extract.ts +0 -215
- package/src/utils/suggestions.ts +0 -208
- /package/dist/{chunk-DZTU6PGS.mjs.map → chunk-36KQV2NA.mjs.map} +0 -0
- /package/dist/{chunk-U7QULEVO.mjs.map → chunk-3GURHDG7.mjs.map} +0 -0
- /package/dist/{chunk-YPBKY4KY.mjs.map → chunk-A6NKSGH3.mjs.map} +0 -0
- /package/dist/{chunk-YPSGKPDA.mjs.map → chunk-CYDWEPFL.mjs.map} +0 -0
- /package/dist/{hooks/use-chat.mjs.map → chunk-FD6FGKYY.mjs.map} +0 -0
- /package/dist/{utils/extract.mjs.map → chunk-JD7BAH7U.mjs.map} +0 -0
- /package/dist/{chunk-EDBI5PCJ.mjs.map → chunk-JRT5BJF3.mjs.map} +0 -0
- /package/dist/{chunk-N4VN2B5S.mjs.map → chunk-LHERIF3L.mjs.map} +0 -0
- /package/dist/{chunk-DXEQPN43.mjs.map → chunk-LHKZJ2ND.mjs.map} +0 -0
- /package/dist/{utils/suggestions.mjs.map → chunk-NB2FKV2V.mjs.map} +0 -0
- /package/dist/{chunk-MGWRDFBE.mjs.map → chunk-OVYFRPSN.mjs.map} +0 -0
- /package/dist/{chunk-MQYWH4E6.mjs.map → chunk-QU6NONOD.mjs.map} +0 -0
- /package/dist/{chunk-OKCYPO4I.mjs.map → chunk-WMJVBMUX.mjs.map} +0 -0
package/src/utils/extract.ts
DELETED
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Action,
|
|
3
|
-
COPILOT_CLOUD_PUBLIC_API_KEY_HEADER,
|
|
4
|
-
MappedParameterTypes,
|
|
5
|
-
Parameter,
|
|
6
|
-
actionParametersToJsonSchema,
|
|
7
|
-
} from "@copilotkit/shared";
|
|
8
|
-
import {
|
|
9
|
-
ActionExecutionMessage,
|
|
10
|
-
Message,
|
|
11
|
-
Role,
|
|
12
|
-
TextMessage,
|
|
13
|
-
convertGqlOutputToMessages,
|
|
14
|
-
CopilotRequestType,
|
|
15
|
-
ForwardedParametersInput,
|
|
16
|
-
} from "@copilotkit/runtime-client-gql";
|
|
17
|
-
import { CopilotContextParams, CopilotMessagesContextParams } from "../context";
|
|
18
|
-
import { defaultCopilotContextCategories } from "../components";
|
|
19
|
-
import { CopilotRuntimeClient } from "@copilotkit/runtime-client-gql";
|
|
20
|
-
import {
|
|
21
|
-
convertMessagesToGqlInput,
|
|
22
|
-
filterAgentStateMessages,
|
|
23
|
-
} from "@copilotkit/runtime-client-gql";
|
|
24
|
-
|
|
25
|
-
interface InitialState<T extends Parameter[] | [] = []> {
|
|
26
|
-
status: "initial";
|
|
27
|
-
args: Partial<MappedParameterTypes<T>>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
interface InProgressState<T extends Parameter[] | [] = []> {
|
|
31
|
-
status: "inProgress";
|
|
32
|
-
args: Partial<MappedParameterTypes<T>>;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
interface CompleteState<T extends Parameter[] | [] = []> {
|
|
36
|
-
status: "complete";
|
|
37
|
-
args: MappedParameterTypes<T>;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type StreamHandlerArgs<T extends Parameter[] | [] = []> =
|
|
41
|
-
| InitialState<T>
|
|
42
|
-
| InProgressState<T>
|
|
43
|
-
| CompleteState<T>;
|
|
44
|
-
|
|
45
|
-
interface ExtractOptions<T extends Parameter[]> {
|
|
46
|
-
context: CopilotContextParams & CopilotMessagesContextParams;
|
|
47
|
-
instructions: string;
|
|
48
|
-
parameters: T;
|
|
49
|
-
include?: IncludeOptions;
|
|
50
|
-
data?: any;
|
|
51
|
-
abortSignal?: AbortSignal;
|
|
52
|
-
stream?: (args: StreamHandlerArgs<T>) => void;
|
|
53
|
-
requestType?: CopilotRequestType;
|
|
54
|
-
forwardedParameters?: ForwardedParametersInput;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
interface IncludeOptions {
|
|
58
|
-
readable?: boolean;
|
|
59
|
-
messages?: boolean;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export async function extract<const T extends Parameter[]>({
|
|
63
|
-
context,
|
|
64
|
-
instructions,
|
|
65
|
-
parameters,
|
|
66
|
-
include,
|
|
67
|
-
data,
|
|
68
|
-
abortSignal,
|
|
69
|
-
stream,
|
|
70
|
-
requestType = CopilotRequestType.Task,
|
|
71
|
-
forwardedParameters,
|
|
72
|
-
}: ExtractOptions<T>): Promise<MappedParameterTypes<T>> {
|
|
73
|
-
const { messages } = context;
|
|
74
|
-
|
|
75
|
-
const action: Action<any> = {
|
|
76
|
-
name: "extract",
|
|
77
|
-
description: instructions,
|
|
78
|
-
parameters,
|
|
79
|
-
handler: (args: any) => {},
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const includeReadable = include?.readable ?? false;
|
|
83
|
-
const includeMessages = include?.messages ?? false;
|
|
84
|
-
|
|
85
|
-
let contextString = "";
|
|
86
|
-
|
|
87
|
-
if (data) {
|
|
88
|
-
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
if (includeReadable) {
|
|
92
|
-
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const systemMessage: Message = new TextMessage({
|
|
96
|
-
content: makeSystemMessage(contextString, instructions),
|
|
97
|
-
role: Role.System,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const instructionsMessage: Message = new TextMessage({
|
|
101
|
-
content: makeInstructionsMessage(instructions),
|
|
102
|
-
role: Role.User,
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
const response = context.runtimeClient.asStream(
|
|
106
|
-
context.runtimeClient.generateCopilotResponse({
|
|
107
|
-
data: {
|
|
108
|
-
frontend: {
|
|
109
|
-
actions: [
|
|
110
|
-
{
|
|
111
|
-
name: action.name,
|
|
112
|
-
description: action.description || "",
|
|
113
|
-
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters || [])),
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
url: window.location.href,
|
|
117
|
-
},
|
|
118
|
-
|
|
119
|
-
messages: convertMessagesToGqlInput(
|
|
120
|
-
includeMessages
|
|
121
|
-
? [systemMessage, instructionsMessage, ...filterAgentStateMessages(messages)]
|
|
122
|
-
: [systemMessage, instructionsMessage],
|
|
123
|
-
),
|
|
124
|
-
metadata: {
|
|
125
|
-
requestType: requestType,
|
|
126
|
-
},
|
|
127
|
-
forwardedParameters: {
|
|
128
|
-
...(forwardedParameters ?? {}),
|
|
129
|
-
toolChoice: "function",
|
|
130
|
-
toolChoiceFunctionName: action.name,
|
|
131
|
-
},
|
|
132
|
-
},
|
|
133
|
-
properties: context.copilotApiConfig.properties,
|
|
134
|
-
signal: abortSignal,
|
|
135
|
-
}),
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const reader = response.getReader();
|
|
139
|
-
|
|
140
|
-
let isInitial = true;
|
|
141
|
-
|
|
142
|
-
let actionExecutionMessage: ActionExecutionMessage | undefined = undefined;
|
|
143
|
-
|
|
144
|
-
while (true) {
|
|
145
|
-
const { done, value } = await reader.read();
|
|
146
|
-
|
|
147
|
-
if (done) {
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (abortSignal?.aborted) {
|
|
152
|
-
throw new Error("Aborted");
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
actionExecutionMessage = convertGqlOutputToMessages(
|
|
156
|
-
value.generateCopilotResponse.messages,
|
|
157
|
-
).find((msg) => msg.isActionExecutionMessage()) as ActionExecutionMessage | undefined;
|
|
158
|
-
|
|
159
|
-
if (!actionExecutionMessage) {
|
|
160
|
-
continue;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
stream?.({
|
|
164
|
-
status: isInitial ? "initial" : "inProgress",
|
|
165
|
-
args: actionExecutionMessage.arguments as Partial<MappedParameterTypes<T>>,
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
isInitial = false;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (!actionExecutionMessage) {
|
|
172
|
-
throw new Error("extract() failed: No function call occurred");
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
stream?.({
|
|
176
|
-
status: "complete",
|
|
177
|
-
args: actionExecutionMessage.arguments as MappedParameterTypes<T>,
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
return actionExecutionMessage.arguments as MappedParameterTypes<T>;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// We need to put this in a user message since some LLMs need
|
|
184
|
-
// at least one user message to function
|
|
185
|
-
function makeInstructionsMessage(instructions: string): string {
|
|
186
|
-
return `
|
|
187
|
-
The user has given you the following task to complete:
|
|
188
|
-
|
|
189
|
-
\`\`\`
|
|
190
|
-
${instructions}
|
|
191
|
-
\`\`\`
|
|
192
|
-
|
|
193
|
-
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
194
|
-
`;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
function makeSystemMessage(contextString: string, instructions: string): string {
|
|
198
|
-
return `
|
|
199
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
200
|
-
|
|
201
|
-
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.
|
|
202
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
203
|
-
|
|
204
|
-
The user has provided you with the following context:
|
|
205
|
-
\`\`\`
|
|
206
|
-
${contextString}
|
|
207
|
-
\`\`\`
|
|
208
|
-
|
|
209
|
-
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
210
|
-
|
|
211
|
-
Please assist them as best you can.
|
|
212
|
-
|
|
213
|
-
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
214
|
-
`;
|
|
215
|
-
}
|
package/src/utils/suggestions.ts
DELETED
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Suggestions utility functions for CopilotKit
|
|
3
|
-
*
|
|
4
|
-
* This module handles the generation of chat suggestions with optimized error handling
|
|
5
|
-
* and streaming validation to prevent infinite retry loops and console spam.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { extract } from "./extract";
|
|
9
|
-
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
10
|
-
import { CopilotRequestType } from "@copilotkit/runtime-client-gql";
|
|
11
|
-
import { CopilotContextParams, CopilotMessagesContextParams } from "../context";
|
|
12
|
-
import { CopilotChatSuggestionConfiguration } from "../types";
|
|
13
|
-
|
|
14
|
-
export interface SuggestionItem {
|
|
15
|
-
title: string;
|
|
16
|
-
message: string;
|
|
17
|
-
partial?: boolean;
|
|
18
|
-
className?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const reloadSuggestions = async (
|
|
22
|
-
context: CopilotContextParams & CopilotMessagesContextParams,
|
|
23
|
-
chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration },
|
|
24
|
-
setCurrentSuggestions: (suggestions: SuggestionItem[]) => void,
|
|
25
|
-
abortControllerRef: React.MutableRefObject<AbortController | null>,
|
|
26
|
-
): Promise<void> => {
|
|
27
|
-
const abortController = abortControllerRef.current;
|
|
28
|
-
|
|
29
|
-
// Early abort check
|
|
30
|
-
if (abortController?.signal.aborted) {
|
|
31
|
-
return;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Abort-aware suggestion setter with safety checks to prevent race conditions
|
|
35
|
-
const setSuggestionsIfNotAborted = (suggestions: SuggestionItem[]) => {
|
|
36
|
-
if (!abortController?.signal.aborted && abortControllerRef.current === abortController) {
|
|
37
|
-
setCurrentSuggestions(suggestions);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
const tools = JSON.stringify(
|
|
43
|
-
Object.values(context.actions).map((action) => ({
|
|
44
|
-
name: action.name,
|
|
45
|
-
description: action.description,
|
|
46
|
-
jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),
|
|
47
|
-
})),
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const allSuggestions: SuggestionItem[] = [];
|
|
51
|
-
let hasSuccessfulSuggestions = false;
|
|
52
|
-
let hasErrors = false; // Track if any errors occurred
|
|
53
|
-
let lastError: Error | null = null; // Track the last error for better error reporting
|
|
54
|
-
|
|
55
|
-
// Get enabled configurations
|
|
56
|
-
const enabledConfigs = Object.values(chatSuggestionConfiguration).filter(
|
|
57
|
-
(config) => config.instructions && config.instructions.trim().length > 0,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
if (enabledConfigs.length === 0) {
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Clear existing suggestions
|
|
65
|
-
setSuggestionsIfNotAborted([]);
|
|
66
|
-
|
|
67
|
-
// Generate suggestions for each configuration
|
|
68
|
-
for (const config of enabledConfigs) {
|
|
69
|
-
// Check if aborted before each configuration
|
|
70
|
-
if (abortController?.signal.aborted) {
|
|
71
|
-
setSuggestionsIfNotAborted([]);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const result = await extract({
|
|
77
|
-
context,
|
|
78
|
-
instructions:
|
|
79
|
-
"Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
80
|
-
data: `${config.instructions}\n\nAvailable tools: ${tools}\n\n`,
|
|
81
|
-
requestType: CopilotRequestType.Task,
|
|
82
|
-
parameters: [
|
|
83
|
-
{
|
|
84
|
-
name: "suggestions",
|
|
85
|
-
type: "object[]",
|
|
86
|
-
attributes: [
|
|
87
|
-
{
|
|
88
|
-
name: "title",
|
|
89
|
-
description:
|
|
90
|
-
"The title of the suggestion. This is shown as a button and should be short.",
|
|
91
|
-
type: "string",
|
|
92
|
-
},
|
|
93
|
-
{
|
|
94
|
-
name: "message",
|
|
95
|
-
description:
|
|
96
|
-
"The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
|
|
97
|
-
type: "string",
|
|
98
|
-
},
|
|
99
|
-
],
|
|
100
|
-
},
|
|
101
|
-
],
|
|
102
|
-
include: {
|
|
103
|
-
messages: true,
|
|
104
|
-
readable: true,
|
|
105
|
-
},
|
|
106
|
-
abortSignal: abortController?.signal,
|
|
107
|
-
stream: ({ status, args }: { status: string; args: any }) => {
|
|
108
|
-
// Check abort status in stream callback
|
|
109
|
-
if (abortController?.signal.aborted) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const suggestions = args.suggestions || [];
|
|
114
|
-
const newSuggestions: SuggestionItem[] = [];
|
|
115
|
-
|
|
116
|
-
for (let i = 0; i < suggestions.length; i++) {
|
|
117
|
-
// Respect max suggestions limit
|
|
118
|
-
if (config.maxSuggestions !== undefined && i >= config.maxSuggestions) {
|
|
119
|
-
break;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const suggestion = suggestions[i];
|
|
123
|
-
|
|
124
|
-
// Skip completely empty or invalid objects during streaming
|
|
125
|
-
if (!suggestion || typeof suggestion !== "object") {
|
|
126
|
-
continue;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const { title, message } = suggestion;
|
|
130
|
-
|
|
131
|
-
// During streaming, be permissive but require at least a meaningful title
|
|
132
|
-
const hasValidTitle = title && typeof title === "string" && title.trim().length > 0;
|
|
133
|
-
const hasValidMessage =
|
|
134
|
-
message && typeof message === "string" && message.trim().length > 0;
|
|
135
|
-
|
|
136
|
-
// During streaming, we need at least a title to show something useful
|
|
137
|
-
if (!hasValidTitle) {
|
|
138
|
-
continue;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
// Mark as partial if this is the last suggestion and streaming isn't complete
|
|
142
|
-
const partial = i === suggestions.length - 1 && status !== "complete";
|
|
143
|
-
|
|
144
|
-
newSuggestions.push({
|
|
145
|
-
title: title.trim(),
|
|
146
|
-
message: hasValidMessage ? message.trim() : "", // Use title as fallback
|
|
147
|
-
partial,
|
|
148
|
-
className: config.className,
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// Update suggestions with current batch
|
|
153
|
-
setSuggestionsIfNotAborted([...allSuggestions, ...newSuggestions]);
|
|
154
|
-
},
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
// Process final results with strict validation
|
|
158
|
-
if (result?.suggestions && Array.isArray(result.suggestions)) {
|
|
159
|
-
const validSuggestions = result.suggestions
|
|
160
|
-
.filter(
|
|
161
|
-
(suggestion: any) =>
|
|
162
|
-
suggestion &&
|
|
163
|
-
typeof suggestion.title === "string" &&
|
|
164
|
-
suggestion.title.trim().length > 0,
|
|
165
|
-
)
|
|
166
|
-
.map((suggestion: any) => ({
|
|
167
|
-
title: suggestion.title.trim(),
|
|
168
|
-
message:
|
|
169
|
-
suggestion.message &&
|
|
170
|
-
typeof suggestion.message === "string" &&
|
|
171
|
-
suggestion.message.trim()
|
|
172
|
-
? suggestion.message.trim()
|
|
173
|
-
: suggestion.title.trim(),
|
|
174
|
-
}));
|
|
175
|
-
|
|
176
|
-
if (validSuggestions.length > 0) {
|
|
177
|
-
allSuggestions.push(...validSuggestions);
|
|
178
|
-
hasSuccessfulSuggestions = true;
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
} catch (error) {
|
|
182
|
-
// Simple error handling - just continue with next config, don't log here
|
|
183
|
-
hasErrors = true;
|
|
184
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
// Display any successful suggestions we got
|
|
189
|
-
if (hasSuccessfulSuggestions && allSuggestions.length > 0) {
|
|
190
|
-
// Remove duplicates based on message content
|
|
191
|
-
const uniqueSuggestions = allSuggestions.filter(
|
|
192
|
-
(suggestion, index, self) =>
|
|
193
|
-
index === self.findIndex((s) => s.message === suggestion.message),
|
|
194
|
-
);
|
|
195
|
-
|
|
196
|
-
setSuggestionsIfNotAborted(uniqueSuggestions);
|
|
197
|
-
} else if (hasErrors) {
|
|
198
|
-
// If we had errors but no successful suggestions, throw an error with details
|
|
199
|
-
const errorMessage = lastError
|
|
200
|
-
? lastError.message
|
|
201
|
-
: "Failed to generate suggestions due to API errors";
|
|
202
|
-
throw new Error(errorMessage);
|
|
203
|
-
}
|
|
204
|
-
} catch (error) {
|
|
205
|
-
// Top-level error handler - re-throw to allow caller to handle
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|