@copilotkit/react-core 1.5.15 → 1.5.16-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.
Files changed (75) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/{chunk-HZCROITJ.mjs → chunk-22ENANUU.mjs} +21 -15
  3. package/dist/chunk-22ENANUU.mjs.map +1 -0
  4. package/dist/{chunk-WU53OU3E.mjs → chunk-2VIL3F36.mjs} +2 -2
  5. package/dist/chunk-2VIL3F36.mjs.map +1 -0
  6. package/dist/{chunk-UMQQA6HK.mjs → chunk-5K2FUI34.mjs} +2 -2
  7. package/dist/{chunk-E64HFWRV.mjs → chunk-6ZFOXYPW.mjs} +2 -2
  8. package/dist/{chunk-AL3MOOKF.mjs → chunk-CUSSPNG5.mjs} +2 -2
  9. package/dist/{chunk-CQWEXISS.mjs → chunk-F7CT7ISL.mjs} +2 -2
  10. package/dist/{chunk-VQFN2PUH.mjs → chunk-I26H7OZO.mjs} +3 -3
  11. package/dist/{chunk-YG5MITQX.mjs → chunk-J3VBYQS4.mjs} +3 -3
  12. package/dist/{chunk-GANI4ZZM.mjs → chunk-MIUILUVX.mjs} +2 -2
  13. package/dist/{chunk-NXHL6AOE.mjs → chunk-MOWA6EG3.mjs} +4 -4
  14. package/dist/{chunk-MUO7UFSI.mjs → chunk-QAOIQER4.mjs} +4 -4
  15. package/dist/chunk-QAOIQER4.mjs.map +1 -0
  16. package/dist/{chunk-KBCZA4FC.mjs → chunk-V3UIPF2O.mjs} +4 -4
  17. package/dist/components/copilot-provider/copilotkit.js +20 -14
  18. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  19. package/dist/components/copilot-provider/copilotkit.mjs +4 -4
  20. package/dist/components/copilot-provider/index.js +20 -14
  21. package/dist/components/copilot-provider/index.js.map +1 -1
  22. package/dist/components/copilot-provider/index.mjs +4 -4
  23. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  24. package/dist/components/error-boundary/error-boundary.mjs +2 -2
  25. package/dist/components/error-boundary/error-utils.js.map +1 -1
  26. package/dist/components/error-boundary/error-utils.mjs +1 -1
  27. package/dist/components/index.js +20 -14
  28. package/dist/components/index.js.map +1 -1
  29. package/dist/components/index.mjs +4 -4
  30. package/dist/components/toast/toast-provider.js +20 -14
  31. package/dist/components/toast/toast-provider.js.map +1 -1
  32. package/dist/components/toast/toast-provider.mjs +1 -1
  33. package/dist/hooks/index.js.map +1 -1
  34. package/dist/hooks/index.mjs +11 -11
  35. package/dist/hooks/use-chat.js.map +1 -1
  36. package/dist/hooks/use-chat.mjs +3 -3
  37. package/dist/hooks/use-coagent-state-render.d.ts +1 -6
  38. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  39. package/dist/hooks/use-coagent-state-render.mjs +2 -2
  40. package/dist/hooks/use-coagent.d.ts +2 -2
  41. package/dist/hooks/use-coagent.js.map +1 -1
  42. package/dist/hooks/use-coagent.mjs +7 -7
  43. package/dist/hooks/use-copilot-action.js.map +1 -1
  44. package/dist/hooks/use-copilot-action.mjs +2 -2
  45. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  46. package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
  47. package/dist/hooks/use-copilot-chat.js.map +1 -1
  48. package/dist/hooks/use-copilot-chat.mjs +6 -6
  49. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  50. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  51. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  52. package/dist/hooks/use-langgraph-interrupt.mjs +7 -7
  53. package/dist/index.js +20 -14
  54. package/dist/index.js.map +1 -1
  55. package/dist/index.mjs +12 -12
  56. package/dist/lib/copilot-task.mjs +5 -5
  57. package/dist/lib/index.mjs +5 -5
  58. package/dist/utils/extract.mjs +4 -4
  59. package/dist/utils/index.mjs +4 -4
  60. package/package.json +3 -3
  61. package/src/components/toast/toast-provider.tsx +20 -17
  62. package/src/hooks/use-coagent-state-render.ts +1 -6
  63. package/src/hooks/use-coagent.ts +2 -2
  64. package/dist/chunk-HZCROITJ.mjs.map +0 -1
  65. package/dist/chunk-MUO7UFSI.mjs.map +0 -1
  66. package/dist/chunk-WU53OU3E.mjs.map +0 -1
  67. /package/dist/{chunk-UMQQA6HK.mjs.map → chunk-5K2FUI34.mjs.map} +0 -0
  68. /package/dist/{chunk-E64HFWRV.mjs.map → chunk-6ZFOXYPW.mjs.map} +0 -0
  69. /package/dist/{chunk-AL3MOOKF.mjs.map → chunk-CUSSPNG5.mjs.map} +0 -0
  70. /package/dist/{chunk-CQWEXISS.mjs.map → chunk-F7CT7ISL.mjs.map} +0 -0
  71. /package/dist/{chunk-VQFN2PUH.mjs.map → chunk-I26H7OZO.mjs.map} +0 -0
  72. /package/dist/{chunk-YG5MITQX.mjs.map → chunk-J3VBYQS4.mjs.map} +0 -0
  73. /package/dist/{chunk-GANI4ZZM.mjs.map → chunk-MIUILUVX.mjs.map} +0 -0
  74. /package/dist/{chunk-NXHL6AOE.mjs.map → chunk-MOWA6EG3.mjs.map} +0 -0
  75. /package/dist/{chunk-KBCZA4FC.mjs.map → chunk-V3UIPF2O.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # ui
2
2
 
3
+ ## 1.5.16-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [48b7c7b]
8
+ - @copilotkit/runtime-client-gql@1.5.16-next.1
9
+ - @copilotkit/shared@1.5.16-next.1
10
+
11
+ ## 1.5.16-next.0
12
+
13
+ ### Patch Changes
14
+
15
+ - 07be5ca: - fix: disable error toasts if dev console is disabled
16
+ - @copilotkit/runtime-client-gql@1.5.16-next.0
17
+ - @copilotkit/shared@1.5.16-next.0
18
+
3
19
  ## 1.5.15
4
20
 
5
21
  ### Patch Changes
@@ -26,20 +26,26 @@ function ToastProvider({
26
26
  children
27
27
  }) {
28
28
  const [toasts, setToasts] = useState([]);
29
- const addToast = useCallback((toast) => {
30
- var _a;
31
- const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
32
- setToasts((currentToasts) => {
33
- if (currentToasts.find((toast2) => toast2.id === id))
34
- return currentToasts;
35
- return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
36
- });
37
- if (toast.duration) {
38
- setTimeout(() => {
39
- removeToast(id);
40
- }, toast.duration);
41
- }
42
- }, []);
29
+ const addToast = useCallback(
30
+ (toast) => {
31
+ var _a;
32
+ if (!enabled) {
33
+ return;
34
+ }
35
+ const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
36
+ setToasts((currentToasts) => {
37
+ if (currentToasts.find((toast2) => toast2.id === id))
38
+ return currentToasts;
39
+ return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
40
+ });
41
+ if (toast.duration) {
42
+ setTimeout(() => {
43
+ removeToast(id);
44
+ }, toast.duration);
45
+ }
46
+ },
47
+ [enabled]
48
+ );
43
49
  const addGraphQLErrorsToast = useCallback((errors) => {
44
50
  addToast({
45
51
  type: "error",
@@ -241,4 +247,4 @@ export {
241
247
  useToast,
242
248
  ToastProvider
243
249
  };
244
- //# sourceMappingURL=chunk-HZCROITJ.mjs.map
250
+ //# sourceMappingURL=chunk-22ENANUU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/error-boundary/error-utils.tsx","../src/components/toast/toast-provider.tsx"],"sourcesContent":["import React, { useCallback } from \"react\";\nimport { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport { useToast } from \"../toast/toast-provider\";\nimport { ExclamationMarkIcon } from \"../toast/exclamation-mark-icon\";\nimport ReactMarkdown from \"react-markdown\";\n\ninterface OriginalError {\n message?: string;\n stack?: string;\n}\n\nexport function ErrorToast({ errors }: { errors: (Error | GraphQLError)[] }) {\n const errorsToRender = errors.map((error, idx) => {\n const originalError =\n \"extensions\" in error ? (error.extensions?.originalError as undefined | OriginalError) : {};\n const message = originalError?.message ?? error.message;\n const code = \"extensions\" in error ? (error.extensions?.code as string) : null;\n\n return (\n <div\n key={idx}\n style={{\n marginTop: idx === 0 ? 0 : 10,\n marginBottom: 14,\n }}\n >\n <ExclamationMarkIcon style={{ marginBottom: 4 }} />\n\n {code && (\n <div\n style={{\n fontWeight: \"600\",\n marginBottom: 4,\n }}\n >\n Copilot Cloud Error:{\" \"}\n <span style={{ fontFamily: \"monospace\", fontWeight: \"normal\" }}>{code}</span>\n </div>\n )}\n <ReactMarkdown>{message}</ReactMarkdown>\n </div>\n );\n });\n return (\n <div\n style={{\n fontSize: \"13px\",\n maxWidth: \"600px\",\n }}\n >\n {errorsToRender}\n <div style={{ fontSize: \"11px\", opacity: 0.75 }}>\n NOTE: This error only displays during local development.\n </div>\n </div>\n );\n}\n\nexport function useErrorToast() {\n const { addToast } = useToast();\n\n return useCallback(\n (error: (Error | GraphQLError)[]) => {\n const errorId = error\n .map((err) => {\n const message =\n \"extensions\" in err\n ? (err.extensions?.originalError as any)?.message || err.message\n : err.message;\n const stack = err.stack || \"\";\n return btoa(message + stack).slice(0, 32); // Create hash from message + stack\n })\n .join(\"|\");\n\n addToast({\n type: \"error\",\n id: errorId, // Toast libraries typically dedupe by id\n message: <ErrorToast errors={error} />,\n });\n },\n [addToast],\n );\n}\n\nexport function useAsyncCallback<T extends (...args: any[]) => Promise<any>>(\n callback: T,\n deps: Parameters<typeof useCallback>[1],\n) {\n const addErrorToast = useErrorToast();\n return useCallback(async (...args: Parameters<T>) => {\n try {\n return await callback(...args);\n } catch (error) {\n console.error(\"Error in async callback:\", error);\n // @ts-ignore\n addErrorToast([error]);\n throw error;\n }\n }, deps);\n}\n","import { GraphQLError } from \"@copilotkit/runtime-client-gql\";\nimport React, { createContext, useContext, useState, useCallback } from \"react\";\nimport { ErrorToast } from \"../error-boundary/error-utils\";\nimport { PartialBy } from \"@copilotkit/shared\";\n\ninterface Toast {\n id: string;\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n duration?: number;\n}\n\ninterface ToastContextValue {\n toasts: Toast[];\n addToast: (toast: PartialBy<Toast, \"id\">) => void;\n addGraphQLErrorsToast: (errors: GraphQLError[]) => void;\n removeToast: (id: string) => void;\n enabled: boolean;\n}\n\nconst ToastContext = createContext<ToastContextValue | undefined>(undefined);\n\nexport function useToast() {\n const context = useContext(ToastContext);\n if (!context) {\n throw new Error(\"useToast must be used within a ToastProvider\");\n }\n return context;\n}\n\nexport function ToastProvider({\n enabled,\n children,\n}: {\n enabled: boolean;\n children: React.ReactNode;\n}) {\n const [toasts, setToasts] = useState<Toast[]>([]);\n const addToast = useCallback(\n (toast: PartialBy<Toast, \"id\">) => {\n // We do not display these errors unless we are in dev mode.\n if (!enabled) {\n return;\n }\n\n const id = toast.id ?? Math.random().toString(36).substring(2, 9);\n\n setToasts((currentToasts) => {\n if (currentToasts.find((toast) => toast.id === id)) return currentToasts;\n return [...currentToasts, { ...toast, id }];\n });\n\n if (toast.duration) {\n setTimeout(() => {\n removeToast(id);\n }, toast.duration);\n }\n },\n [enabled],\n );\n\n const addGraphQLErrorsToast = useCallback((errors: GraphQLError[]) => {\n addToast({\n type: \"error\",\n message: <ErrorToast errors={errors} />,\n });\n }, []);\n\n const removeToast = useCallback((id: string) => {\n setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));\n }, []);\n\n const value = {\n toasts,\n addToast,\n addGraphQLErrorsToast,\n removeToast,\n enabled,\n };\n\n return (\n <ToastContext.Provider value={value}>\n <div\n style={{\n position: \"fixed\",\n bottom: \"1rem\",\n left: \"50%\",\n transform: \"translateX(-50%)\",\n zIndex: 50,\n display: \"flex\",\n flexDirection: \"column\",\n gap: \"0.5rem\",\n }}\n >\n {toasts.length > 1 && (\n <div style={{ textAlign: \"right\" }}>\n <button\n onClick={() => setToasts([])}\n style={{\n padding: \"4px 8px\",\n fontSize: \"12px\",\n cursor: \"pointer\",\n background: \"white\",\n border: \"1px solid rgba(0,0,0,0.2)\",\n borderRadius: \"4px\",\n }}\n >\n Close All\n </button>\n </div>\n )}\n {toasts.map((toast) => (\n <Toast\n key={toast.id}\n message={toast.message}\n type={toast.type}\n onClose={() => removeToast(toast.id)}\n />\n ))}\n </div>\n {children}\n </ToastContext.Provider>\n );\n}\n\nfunction Toast({\n message,\n type = \"info\",\n onClose,\n}: {\n message: string | React.ReactNode;\n type: \"info\" | \"success\" | \"warning\" | \"error\";\n onClose: () => void;\n}) {\n const bgColors = {\n info: \"#3b82f6\",\n success: \"#22c55e\",\n warning: \"#eab308\",\n error: \"#ef4444\",\n };\n\n return (\n <div\n style={{\n backgroundColor: bgColors[type],\n color: \"white\",\n padding: \"0.5rem 1.5rem\",\n borderRadius: \"0.25rem\",\n boxShadow: \"0 2px 4px rgba(0,0,0,0.1)\",\n position: \"relative\",\n minWidth: \"200px\",\n }}\n >\n <div>{message}</div>\n <button\n onClick={onClose}\n style={{\n position: \"absolute\",\n top: \"0\",\n right: \"0\",\n background: \"none\",\n border: \"none\",\n color: \"white\",\n cursor: \"pointer\",\n padding: \"0.5rem\",\n fontSize: \"1rem\",\n }}\n >\n ✕\n </button>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAgB,eAAAA,oBAAmB;;;ACCnC,SAAgB,eAAe,YAAY,UAAU,mBAAmB;AA+DzD,cAkBT,YAlBS;AA5Cf,IAAM,eAAe,cAA6C,MAAS;AAEpE,SAAS,WAAW;AACzB,QAAM,UAAU,WAAW,YAAY;AACvC,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AACA,SAAO;AACT;AAEO,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AACF,GAGG;AACD,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAkB,CAAC,CAAC;AAChD,QAAM,WAAW;AAAA,IACf,CAAC,UAAkC;AAvCvC;AAyCM,UAAI,CAAC,SAAS;AACZ;AAAA,MACF;AAEA,YAAM,MAAK,WAAM,OAAN,YAAY,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,U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QACN,IAAI;AAAA;AAAA,QACJ,SAAS,gBAAAF,KAAC,cAAW,QAAQ,OAAO;AAAA,MACtC,CAAC;AAAA,IACH;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AACF;AAEO,SAAS,iBACd,UACA,MACA;AACA,QAAM,gBAAgB,cAAc;AACpC,SAAOE,aAAY,IAAU,SAAwB;AACnD,QAAI;AACF,aAAO,MAAM,SAAS,GAAG,IAAI;AAAA,IAC/B,SAAS,OAAP;AACA,cAAQ,MAAM,4BAA4B,KAAK;AAE/C,oBAAc,CAAC,KAAK,CAAC;AACrB,YAAM;AAAA,IACR;AAAA,EACF,IAAG,IAAI;AACT;","names":["useCallback","toast","jsx","jsxs","useCallback"]}
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-ZM56S3LJ.mjs";
4
4
  import {
5
5
  useToast
6
- } from "./chunk-HZCROITJ.mjs";
6
+ } from "./chunk-22ENANUU.mjs";
7
7
 
8
8
  // src/hooks/use-coagent-state-render.ts
9
9
  import { useRef, useContext, useEffect } from "react";
@@ -58,4 +58,4 @@ function useCoAgentStateRender(action, dependencies) {
58
58
  export {
59
59
  useCoAgentStateRender
60
60
  };
61
- //# sourceMappingURL=chunk-WU53OU3E.mjs.map
61
+ //# sourceMappingURL=chunk-2VIL3F36.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-coagent-state-render.ts"],"sourcesContent":["/**\n * The useCoAgentStateRender hook allows you to render UI components or text based on a Agentic Copilot's state.\n * This is particularly useful for showing intermediate state or progress during Agentic Copilot operations.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCoAgentStateRender } from \"@copilotkit/react-core\";\n *\n * type YourAgentState = {\n * agent_state_property: string;\n * }\n *\n * useCoAgentStateRender<YourAgentState>({\n * name: \"basic_agent\",\n * nodeName: \"optionally_specify_a_specific_node\",\n * render: ({ status, state, nodeName }) => {\n * return (\n * <YourComponent\n * agentStateProperty={state.agent_state_property}\n * status={status}\n * nodeName={nodeName}\n * />\n * );\n * },\n * });\n * ```\n *\n * This allows for you to render UI components or text based on what is happening within the agent.\n *\n * ### Example\n * A great example of this is in our Perplexity Clone where we render the progress of an agent's internet search as it is happening.\n * You can play around with it below or learn how to build it with its [demo](/coagents/videos/perplexity-clone).\n *\n * <Callout type=\"info\">\n * This example is hosted on Vercel and may take a few seconds to load.\n * </Callout>\n *\n * <iframe src=\"https://examples-coagents-ai-researcher-ui.vercel.app/\" className=\"w-full rounded-lg border h-[700px] my-4\" />\n */\n\nimport { useRef, useContext, useEffect } from \"react\";\nimport { CopilotContext } from \"../context/copilot-context\";\nimport { randomId } from \"@copilotkit/shared\";\nimport { CoAgentStateRender } from \"../types/coagent-action\";\nimport { useToast } from \"../components/toast/toast-provider\";\n\n/**\n * This hook is used to render agent state with custom UI components or text. This is particularly\n * useful for showing intermediate state or progress during Agentic Copilot operations.\n * To get started using rendering intermediate state through this hook, checkout the documentation.\n *\n * https://docs.copilotkit.ai/coagents/shared-state/predictive-state-updates\n */\n\n// We implement useCoAgentStateRender dependency handling so that\n// the developer has the option to not provide any dependencies.\n// see useCopilotAction for more details about this approach.\nexport function useCoAgentStateRender<T = any>(\n action: CoAgentStateRender<T>,\n dependencies?: any[],\n): void {\n const {\n setCoAgentStateRender,\n removeCoAgentStateRender,\n coAgentStateRenders,\n chatComponentsCache,\n availableAgents,\n } = useContext(CopilotContext);\n const idRef = useRef<string>(randomId());\n const { addToast } = useToast();\n\n useEffect(() => {\n if (availableAgents?.length && !availableAgents.some((a) => a.name === action.name)) {\n const message = `(useCoAgentStateRender): Agent \"${action.name}\" not found. Make sure the agent exists and is properly configured.`;\n console.warn(message);\n addToast({ type: \"warning\", message });\n }\n }, [availableAgents]);\n\n const key = `${action.name}-${action.nodeName || \"global\"}`;\n\n if (dependencies === undefined) {\n if (coAgentStateRenders[idRef.current]) {\n coAgentStateRenders[idRef.current].handler = action.handler as any;\n if (typeof action.render === \"function\") {\n if (chatComponentsCache.current !== null) {\n chatComponentsCache.current.coAgentStateRenders[key] = action.render;\n }\n }\n }\n }\n\n useEffect(() => {\n setCoAgentStateRender(idRef.current, action as any);\n if (chatComponentsCache.current !== null && action.render !== undefined) {\n chatComponentsCache.current.coAgentStateRenders[key] = action.render;\n }\n return () => {\n removeCoAgentStateRender(idRef.current);\n };\n }, [\n setCoAgentStateRender,\n removeCoAgentStateRender,\n action.name,\n // include render only if it's a string\n typeof action.render === \"string\" ? action.render : undefined,\n // dependencies set by the developer\n ...(dependencies || []),\n ]);\n}\n"],"mappings":";;;;;;;;AA2CA,SAAS,QAAQ,YAAY,iBAAiB;AAE9C,SAAS,gBAAgB;AAelB,SAAS,sBACd,QACA,cACM;AACN,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,WAAW,cAAc;AAC7B,QAAM,QAAQ,OAAe,SAAS,CAAC;AACvC,QAAM,EAAE,SAAS,IAAI,SAAS;AAE9B,YAAU,MAAM;AACd,SAAI,mDAAiB,WAAU,CAAC,gBAAgB,KAAK,CAAC,MAAM,EAAE,SAAS,OAAO,IAAI,GAAG;AACnF,YAAM,UAAU,mCAAmC,OAAO;AAC1D,cAAQ,KAAK,OAAO;AACpB,eAAS,EAAE,MAAM,WAAW,QAAQ,CAAC;AAAA,IACvC;AAAA,EACF,GAAG,CAAC,eAAe,CAAC;AAEpB,QAAM,MAAM,GAAG,OAAO,QAAQ,OAAO,YAAY;AAEjD,MAAI,iBAAiB,QAAW;AAC9B,QAAI,oBAAoB,MAAM,OAAO,GAAG;AACtC,0BAAoB,MAAM,OAAO,EAAE,UAAU,OAAO;AACpD,UAAI,OAAO,OAAO,WAAW,YAAY;AACvC,YAAI,oBAAoB,YAAY,MAAM;AACxC,8BAAoB,QAAQ,oBAAoB,GAAG,IAAI,OAAO;AAAA,QAChE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,YAAU,MAAM;AACd,0BAAsB,MAAM,SAAS,MAAa;AAClD,QAAI,oBAAoB,YAAY,QAAQ,OAAO,WAAW,QAAW;AACvE,0BAAoB,QAAQ,oBAAoB,GAAG,IAAI,OAAO;AAAA,IAChE;AACA,WAAO,MAAM;AACX,+BAAyB,MAAM,OAAO;AAAA,IACxC;AAAA,EACF,GAAG;AAAA,IACD;AAAA,IACA;AAAA,IACA,OAAO;AAAA;AAAA,IAEP,OAAO,OAAO,WAAW,WAAW,OAAO,SAAS;AAAA;AAAA,IAEpD,GAAI,gBAAgB,CAAC;AAAA,EACvB,CAAC;AACH;","names":[]}
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-D34OH4VN.mjs";
8
8
  import {
9
9
  useErrorToast
10
- } from "./chunk-HZCROITJ.mjs";
10
+ } from "./chunk-22ENANUU.mjs";
11
11
 
12
12
  // src/components/error-boundary/error-boundary.tsx
13
13
  import React, { useEffect } from "react";
@@ -77,4 +77,4 @@ export {
77
77
  CopilotErrorBoundary,
78
78
  ErrorToast
79
79
  };
80
- //# sourceMappingURL=chunk-UMQQA6HK.mjs.map
80
+ //# sourceMappingURL=chunk-5K2FUI34.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-NXHL6AOE.mjs";
3
+ } from "./chunk-MOWA6EG3.mjs";
4
4
  import {
5
5
  processActionsForRuntimeRequest
6
6
  } from "./chunk-XERJQUHA.mjs";
@@ -117,4 +117,4 @@ ${instructions}
117
117
  export {
118
118
  CopilotTask
119
119
  };
120
- //# sourceMappingURL=chunk-E64HFWRV.mjs.map
120
+ //# sourceMappingURL=chunk-6ZFOXYPW.mjs.map
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-ZM56S3LJ.mjs";
4
4
  import {
5
5
  useAsyncCallback
6
- } from "./chunk-HZCROITJ.mjs";
6
+ } from "./chunk-22ENANUU.mjs";
7
7
  import {
8
8
  __async,
9
9
  __spreadValues
@@ -104,4 +104,4 @@ function isFrontendAction(action) {
104
104
  export {
105
105
  useCopilotAction
106
106
  };
107
- //# sourceMappingURL=chunk-AL3MOOKF.mjs.map
107
+ //# sourceMappingURL=chunk-CUSSPNG5.mjs.map
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  useErrorToast,
3
3
  useToast
4
- } from "./chunk-HZCROITJ.mjs";
4
+ } from "./chunk-22ENANUU.mjs";
5
5
  import {
6
6
  __spreadProps,
7
7
  __spreadValues
@@ -32,4 +32,4 @@ var useCopilotRuntimeClient = (options) => {
32
32
  export {
33
33
  useCopilotRuntimeClient
34
34
  };
35
- //# sourceMappingURL=chunk-CQWEXISS.mjs.map
35
+ //# sourceMappingURL=chunk-F7CT7ISL.mjs.map
@@ -3,11 +3,11 @@ import {
3
3
  } from "./chunk-XERJQUHA.mjs";
4
4
  import {
5
5
  useCopilotRuntimeClient
6
- } from "./chunk-CQWEXISS.mjs";
6
+ } from "./chunk-F7CT7ISL.mjs";
7
7
  import {
8
8
  useAsyncCallback,
9
9
  useErrorToast
10
- } from "./chunk-HZCROITJ.mjs";
10
+ } from "./chunk-22ENANUU.mjs";
11
11
  import {
12
12
  __async,
13
13
  __spreadProps,
@@ -472,4 +472,4 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
472
472
  export {
473
473
  useChat
474
474
  };
475
- //# sourceMappingURL=chunk-VQFN2PUH.mjs.map
475
+ //# sourceMappingURL=chunk-I26H7OZO.mjs.map
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  useCopilotChat
3
- } from "./chunk-KBCZA4FC.mjs";
3
+ } from "./chunk-V3UIPF2O.mjs";
4
4
  import {
5
5
  CopilotContext
6
6
  } from "./chunk-ZM56S3LJ.mjs";
7
7
  import {
8
8
  useToast
9
- } from "./chunk-HZCROITJ.mjs";
9
+ } from "./chunk-22ENANUU.mjs";
10
10
  import {
11
11
  __spreadProps,
12
12
  __spreadValues
@@ -63,4 +63,4 @@ function useLangGraphInterrupt(action, dependencies) {
63
63
  export {
64
64
  useLangGraphInterrupt
65
65
  };
66
- //# sourceMappingURL=chunk-YG5MITQX.mjs.map
66
+ //# sourceMappingURL=chunk-J3VBYQS4.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotAction
3
- } from "./chunk-AL3MOOKF.mjs";
3
+ } from "./chunk-CUSSPNG5.mjs";
4
4
  import {
5
5
  useCopilotContext
6
6
  } from "./chunk-ZM56S3LJ.mjs";
@@ -56,4 +56,4 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
56
56
  export {
57
57
  useCopilotAuthenticatedAction_c
58
58
  };
59
- //# sourceMappingURL=chunk-GANI4ZZM.mjs.map
59
+ //# sourceMappingURL=chunk-MIUILUVX.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  CopilotErrorBoundary
3
- } from "./chunk-UMQQA6HK.mjs";
3
+ } from "./chunk-5K2FUI34.mjs";
4
4
  import {
5
5
  CopilotMessages
6
6
  } from "./chunk-5M47BILE.mjs";
@@ -18,10 +18,10 @@ import {
18
18
  } from "./chunk-ZM56S3LJ.mjs";
19
19
  import {
20
20
  useCopilotRuntimeClient
21
- } from "./chunk-CQWEXISS.mjs";
21
+ } from "./chunk-F7CT7ISL.mjs";
22
22
  import {
23
23
  ToastProvider
24
- } from "./chunk-HZCROITJ.mjs";
24
+ } from "./chunk-22ENANUU.mjs";
25
25
  import {
26
26
  __async,
27
27
  __objRest,
@@ -527,4 +527,4 @@ export {
527
527
  CopilotKitInternal,
528
528
  defaultCopilotContextCategories
529
529
  };
530
- //# sourceMappingURL=chunk-NXHL6AOE.mjs.map
530
+ //# sourceMappingURL=chunk-MOWA6EG3.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  useCopilotChat
3
- } from "./chunk-KBCZA4FC.mjs";
3
+ } from "./chunk-V3UIPF2O.mjs";
4
4
  import {
5
5
  useCopilotContext
6
6
  } from "./chunk-ZM56S3LJ.mjs";
@@ -9,11 +9,11 @@ import {
9
9
  } from "./chunk-DCTJZ742.mjs";
10
10
  import {
11
11
  useCopilotRuntimeClient
12
- } from "./chunk-CQWEXISS.mjs";
12
+ } from "./chunk-F7CT7ISL.mjs";
13
13
  import {
14
14
  useAsyncCallback,
15
15
  useToast
16
- } from "./chunk-HZCROITJ.mjs";
16
+ } from "./chunk-22ENANUU.mjs";
17
17
  import {
18
18
  __async,
19
19
  __spreadProps,
@@ -187,4 +187,4 @@ export {
187
187
  stopAgent,
188
188
  runAgent
189
189
  };
190
- //# sourceMappingURL=chunk-MUO7UFSI.mjs.map
190
+ //# sourceMappingURL=chunk-QAOIQER4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/hooks/use-coagent.ts"],"sourcesContent":["/**\n * <Callout type=\"info\">\n * Usage of this hook assumes some additional setup in your application, for more information\n * on that see the CoAgents <span className=\"text-blue-500\">[getting started guide](/coagents/quickstart/langgraph)</span>.\n * </Callout>\n * <Frame className=\"my-12\">\n * <img\n * src=\"/images/coagents/SharedStateCoAgents.gif\"\n * alt=\"CoAgents demonstration\"\n * className=\"w-auto\"\n * />\n * </Frame>\n *\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of an agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences agentic copilots, or CoAgents for short.\n *\n * ## Usage\n *\n * ### Simple Usage\n *\n * ```tsx\n * import { useCoAgent } from \"@copilotkit/react-core\";\n *\n * type AgentState = {\n * count: number;\n * }\n *\n * const agent = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * ```\n *\n * `useCoAgent` returns an object with the following properties:\n *\n * ```tsx\n * const {\n * name, // The name of the agent currently being used.\n * nodeName, // The name of the current LangGraph node.\n * state, // The current state of the agent.\n * setState, // A function to update the state of the agent.\n * running, // A boolean indicating if the agent is currently running.\n * start, // A function to start the agent.\n * stop, // A function to stop the agent.\n * run, // A function to re-run the agent. Takes a HintFunction to inform the agent why it is being re-run.\n * } = agent;\n * ```\n *\n * Finally we can leverage these properties to create reactive experiences with the agent!\n *\n * ```tsx\n * const { state, setState } = useCoAgent<AgentState>({\n * name: \"my-agent\",\n * initialState: {\n * count: 0,\n * },\n * });\n *\n * return (\n * <div>\n * <p>Count: {state.count}</p>\n * <button onClick={() => setState({ count: state.count + 1 })}>Increment</button>\n * </div>\n * );\n * ```\n *\n * This reactivity is bidirectional, meaning that changes to the state from the agent will be reflected in the UI and vice versa.\n *\n * ## Parameters\n * <PropertyReference name=\"options\" type=\"UseCoagentOptions<T>\" required>\n * The options to use when creating the coagent.\n * <PropertyReference name=\"name\" type=\"string\" required>\n * The name of the agent to use.\n * </PropertyReference>\n * <PropertyReference name=\"initialState\" type=\"T | any\">\n * The initial state of the agent.\n * </PropertyReference>\n * <PropertyReference name=\"state\" type=\"T | any\">\n * State to manage externally if you are using this hook with external state management.\n * </PropertyReference>\n * <PropertyReference name=\"setState\" type=\"(newState: T | ((prevState: T | undefined) => T)) => void\">\n * A function to update the state of the agent if you are using this hook with external state management.\n * </PropertyReference>\n * </PropertyReference>\n */\n\nimport { useEffect, useRef } from \"react\";\nimport {\n CopilotContextParams,\n CopilotMessagesContextParams,\n useCopilotContext,\n useCopilotMessagesContext,\n} from \"../context\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport { useCopilotChat } from \"./use-copilot-chat\";\nimport { Message } from \"@copilotkit/runtime-client-gql\";\nimport { useAsyncCallback } from \"../components/error-boundary/error-utils\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport { useCopilotRuntimeClient } from \"./use-copilot-runtime-client\";\n\ninterface WithInternalStateManagementAndInitial<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The initial state of the agent.\n */\n initialState: T;\n}\n\ninterface WithInternalStateManagement {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * Optional initialState with default type any\n */\n initialState?: any;\n}\n\ninterface WithExternalStateManagement<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n}\n\ntype UseCoagentOptions<T> =\n | WithInternalStateManagementAndInitial<T>\n | WithInternalStateManagement\n | WithExternalStateManagement<T>;\n\nexport interface UseCoagentReturnType<T> {\n /**\n * The name of the agent being used.\n */\n name: string;\n /**\n * The name of the current LangGraph node.\n */\n nodeName?: string;\n /**\n * The ID of the thread the agent is running in.\n */\n threadId?: string;\n /**\n * A boolean indicating if the agent is currently running.\n */\n running: boolean;\n /**\n * The current state of the agent.\n */\n state: T;\n /**\n * A function to update the state of the agent.\n */\n setState: (newState: T | ((prevState: T | undefined) => T)) => void;\n /**\n * A function to start the agent.\n */\n start: () => void;\n /**\n * A function to stop the agent.\n */\n stop: () => void;\n /**\n * A function to re-run the agent. The hint function can be used to provide a hint to the agent\n * about why it is being re-run again.\n */\n run: (hint?: HintFunction) => Promise<void>;\n}\n\nexport interface HintFunctionParams {\n /**\n * The previous state of the agent.\n */\n previousState: any;\n /**\n * The current state of the agent.\n */\n currentState: any;\n}\n\nexport type HintFunction = (params: HintFunctionParams) => Message | undefined;\n\n/**\n * This hook is used to integrate an agent into your application. With its use, you can\n * render and update the state of the agent, allowing for a dynamic and interactive experience.\n * We call these shared state experiences \"agentic copilots\". To get started using agentic copilots, which\n * we refer to as CoAgents, checkout the documentation at https://docs.copilotkit.ai/coagents/quickstart/langgraph.\n */\nexport function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentReturnType<T> {\n const generalContext = useCopilotContext();\n const { availableAgents } = generalContext;\n const { addToast } = useToast();\n const lastLoadedThreadId = useRef<string>();\n const lastLoadedState = useRef<any>();\n\n const isExternalStateManagement = (\n options: UseCoagentOptions<T>,\n ): options is WithExternalStateManagement<T> => {\n return \"state\" in options && \"setState\" in options;\n };\n\n const { name } = options;\n useEffect(() => {\n if (availableAgents?.length && !availableAgents.some((a) => a.name === name)) {\n const message = `(useCoAgent): Agent \"${name}\" not found. Make sure the agent exists and is properly configured.`;\n console.warn(message);\n addToast({ type: \"warning\", message });\n }\n }, [availableAgents]);\n\n const isInternalStateManagementWithInitial = (\n options: UseCoagentOptions<T>,\n ): options is WithInternalStateManagementAndInitial<T> => {\n return \"initialState\" in options;\n };\n\n const messagesContext = useCopilotMessagesContext();\n const context = { ...generalContext, ...messagesContext };\n const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } =\n context;\n const { appendMessage, runChatCompletion } = useCopilotChat();\n\n const getCoagentState = (coagentStates: Record<string, CoagentState>, name: string) => {\n if (coagentStates[name]) {\n return coagentStates[name];\n } else {\n return {\n name,\n state: isInternalStateManagementWithInitial(options) ? options.initialState : {},\n running: false,\n active: false,\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n };\n }\n };\n\n const runtimeClient = useCopilotRuntimeClient({\n url: copilotApiConfig.chatApiEndpoint,\n publicApiKey: copilotApiConfig.publicApiKey,\n credentials: copilotApiConfig.credentials,\n });\n\n // if we manage state internally, we need to provide a function to set the state\n const setState = (newState: T | ((prevState: T | undefined) => T)) => {\n let coagentState: CoagentState = getCoagentState(coagentStatesRef.current || {}, name);\n const updatedState =\n typeof newState === \"function\" ? (newState as Function)(coagentState.state) : newState;\n\n setCoagentStatesWithRef({\n ...coagentStatesRef.current,\n [name]: {\n ...coagentState,\n state: updatedState,\n },\n });\n };\n\n useEffect(() => {\n const fetchAgentState = async () => {\n if (!threadId || threadId === lastLoadedThreadId.current) return;\n\n const result = await runtimeClient.loadAgentState({\n threadId,\n agentName: name,\n });\n\n const newState = result.data?.loadAgentState?.state;\n if (newState === lastLoadedState.current) return;\n\n if (result.data?.loadAgentState?.threadExists && newState && newState != \"{}\") {\n lastLoadedState.current = newState;\n lastLoadedThreadId.current = threadId;\n const fetchedState = JSON.parse(newState);\n isExternalStateManagement(options)\n ? options.setState(fetchedState)\n : setState(fetchedState);\n }\n };\n void fetchAgentState();\n }, [threadId]);\n\n const coagentState = getCoagentState(coagentStates, name);\n\n // Sync internal state with external state if state management is external\n useEffect(() => {\n if (isExternalStateManagement(options)) {\n setState(options.state);\n } else if (coagentStates[name] === undefined) {\n setState(options.initialState === undefined ? {} : options.initialState);\n }\n }, [\n isExternalStateManagement(options) ? JSON.stringify(options.state) : undefined,\n // reset initialstate on reset\n coagentStates[name] === undefined,\n ]);\n\n const runAgentCallback = useAsyncCallback(\n async (hint?: HintFunction) => {\n await runAgent(name, context, appendMessage, runChatCompletion, hint);\n },\n [name, context, appendMessage, runChatCompletion],\n );\n\n // Return the state and setState function\n return {\n name,\n nodeName: coagentState.nodeName,\n threadId: coagentState.threadId,\n running: coagentState.running,\n state: coagentState.state,\n setState: isExternalStateManagement(options) ? options.setState : setState,\n start: () => startAgent(name, context),\n stop: () => stopAgent(name, context),\n run: runAgentCallback,\n };\n}\n\nexport function startAgent(name: string, context: CopilotContextParams) {\n const { setAgentSession } = context;\n setAgentSession({\n agentName: name,\n });\n}\n\nexport function stopAgent(name: string, context: CopilotContextParams) {\n const { agentSession, setAgentSession } = context;\n if (agentSession && agentSession.agentName === name) {\n setAgentSession(null);\n context.setCoagentStates((prevAgentStates) => {\n return {\n ...prevAgentStates,\n [name]: {\n ...prevAgentStates[name],\n running: false,\n active: false,\n threadId: undefined,\n nodeName: undefined,\n runId: undefined,\n },\n };\n });\n } else {\n console.warn(`No agent session found for ${name}`);\n }\n}\n\nexport async function runAgent(\n name: string,\n context: CopilotContextParams & CopilotMessagesContextParams,\n appendMessage: (message: Message) => Promise<void>,\n runChatCompletion: () => Promise<Message[]>,\n hint?: HintFunction,\n) {\n const { agentSession, setAgentSession } = context;\n if (!agentSession || agentSession.agentName !== name) {\n setAgentSession({\n agentName: name,\n });\n }\n\n let previousState: any = null;\n for (let i = context.messages.length - 1; i >= 0; i--) {\n const message = context.messages[i];\n if (message.isAgentStateMessage() && message.agentName === name) {\n previousState = message.state;\n }\n }\n\n let state = context.coagentStatesRef.current?.[name]?.state || {};\n\n if (hint) {\n const hintMessage = hint({ previousState, currentState: state });\n if (hintMessage) {\n await appendMessage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,QAAI,CAAC,gBAAgB,aAAa,cAAc,MAAM;AACpD,sBAAgB;AAAA,QACd,WAAW;AAAA,MACb,CAAC;AAAA,IACH;AAEA,QAAI,gBAAqB;AACzB,aAAS,IAAI,QAAQ,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK;AACrD,YAAM,UAAU,QAAQ,SAAS,CAAC;AAClC,UAAI,QAAQ,oBAAoB,KAAK,QAAQ,cAAc,MAAM;AAC/D,wBAAgB,QAAQ;AAAA,MAC1B;AAAA,IACF;AAEA,QAAI,UAAQ,mBAAQ,iBAAiB,YAAzB,mBAAmC,UAAnC,mBAA0C,UAAS,CAAC;AAEhE,QAAI,MAAM;AACR,YAAM,cAAc,KAAK,EAAE,eAAe,cAAc,MAAM,CAAC;AAC/D,UAAI,aAAa;AACf,cAAM,cAAc,WAAW;AAAA,MACjC,OAAO;AACL,cAAM,kBAAkB;AAAA,MAC1B;AAAA,IACF,OAAO;AACL,YAAM,kBAAkB;AAAA,IAC1B;AAAA,EACF;AAAA;","names":["options","coagentStates","name","coagentState"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  defaultCopilotContextCategories
3
- } from "./chunk-NXHL6AOE.mjs";
3
+ } from "./chunk-MOWA6EG3.mjs";
4
4
  import {
5
5
  useCopilotContext
6
6
  } from "./chunk-ZM56S3LJ.mjs";
@@ -9,10 +9,10 @@ import {
9
9
  } from "./chunk-DCTJZ742.mjs";
10
10
  import {
11
11
  useChat
12
- } from "./chunk-VQFN2PUH.mjs";
12
+ } from "./chunk-I26H7OZO.mjs";
13
13
  import {
14
14
  useAsyncCallback
15
- } from "./chunk-HZCROITJ.mjs";
15
+ } from "./chunk-22ENANUU.mjs";
16
16
  import {
17
17
  __async,
18
18
  __objRest,
@@ -222,4 +222,4 @@ export {
222
222
  useCopilotChat,
223
223
  defaultSystemMessage
224
224
  };
225
- //# sourceMappingURL=chunk-KBCZA4FC.mjs.map
225
+ //# sourceMappingURL=chunk-V3UIPF2O.mjs.map
@@ -552,20 +552,26 @@ function ToastProvider({
552
552
  children
553
553
  }) {
554
554
  const [toasts, setToasts] = (0, import_react7.useState)([]);
555
- const addToast = (0, import_react7.useCallback)((toast) => {
556
- var _a;
557
- const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
558
- setToasts((currentToasts) => {
559
- if (currentToasts.find((toast2) => toast2.id === id))
560
- return currentToasts;
561
- return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
562
- });
563
- if (toast.duration) {
564
- setTimeout(() => {
565
- removeToast(id);
566
- }, toast.duration);
567
- }
568
- }, []);
555
+ const addToast = (0, import_react7.useCallback)(
556
+ (toast) => {
557
+ var _a;
558
+ if (!enabled) {
559
+ return;
560
+ }
561
+ const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
562
+ setToasts((currentToasts) => {
563
+ if (currentToasts.find((toast2) => toast2.id === id))
564
+ return currentToasts;
565
+ return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
566
+ });
567
+ if (toast.duration) {
568
+ setTimeout(() => {
569
+ removeToast(id);
570
+ }, toast.duration);
571
+ }
572
+ },
573
+ [enabled]
574
+ );
569
575
  const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
570
576
  addToast({
571
577
  type: "error",