@copilotkit/react-core 1.4.8-no-pino-redact.1 → 1.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/CHANGELOG.md +8 -3
  2. package/dist/{chunk-XBVKTDXP.mjs → chunk-6EMLM6WX.mjs} +17 -14
  3. package/dist/chunk-6EMLM6WX.mjs.map +1 -0
  4. package/dist/{chunk-ODN4H66E.mjs → chunk-7LRDVJH5.mjs} +6 -2
  5. package/dist/chunk-7LRDVJH5.mjs.map +1 -0
  6. package/dist/{chunk-O22KGHOQ.mjs → chunk-FSC4A3JN.mjs} +17 -13
  7. package/dist/chunk-FSC4A3JN.mjs.map +1 -0
  8. package/dist/{chunk-OT67R4NB.mjs → chunk-IFTHM7LF.mjs} +2 -2
  9. package/dist/{chunk-DHGXL5PC.mjs → chunk-IVYL7JRC.mjs} +7 -4
  10. package/dist/chunk-IVYL7JRC.mjs.map +1 -0
  11. package/dist/chunk-NTLCOVE5.mjs +321 -0
  12. package/dist/chunk-NTLCOVE5.mjs.map +1 -0
  13. package/dist/chunk-QCUP6HLK.mjs +37 -0
  14. package/dist/chunk-QCUP6HLK.mjs.map +1 -0
  15. package/dist/{chunk-2KCEHGSI.mjs → chunk-SFPANIOY.mjs} +99 -49
  16. package/dist/chunk-SFPANIOY.mjs.map +1 -0
  17. package/dist/{chunk-JHEAUB3Z.mjs → chunk-X6ZF5WAX.mjs} +1 -1
  18. package/dist/{chunk-JHEAUB3Z.mjs.map → chunk-X6ZF5WAX.mjs.map} +1 -1
  19. package/dist/{chunk-Y7MI4PBB.mjs → chunk-YUY5ZAST.mjs} +6 -3
  20. package/dist/chunk-YUY5ZAST.mjs.map +1 -0
  21. package/dist/components/copilot-provider/copilotkit.js +156 -91
  22. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  23. package/dist/components/copilot-provider/copilotkit.mjs +4 -3
  24. package/dist/components/copilot-provider/index.js +156 -91
  25. package/dist/components/copilot-provider/index.js.map +1 -1
  26. package/dist/components/copilot-provider/index.mjs +4 -3
  27. package/dist/components/error-boundary/error-boundary.d.ts +22 -0
  28. package/dist/components/error-boundary/error-boundary.js +183 -0
  29. package/dist/components/error-boundary/error-boundary.js.map +1 -0
  30. package/dist/components/error-boundary/error-boundary.mjs +12 -0
  31. package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
  32. package/dist/components/error-boundary/error-utils.d.ts +11 -0
  33. package/dist/components/error-boundary/error-utils.js +177 -0
  34. package/dist/components/error-boundary/error-utils.js.map +1 -0
  35. package/dist/components/error-boundary/error-utils.mjs +13 -0
  36. package/dist/components/error-boundary/error-utils.mjs.map +1 -0
  37. package/dist/components/index.js +156 -91
  38. package/dist/components/index.js.map +1 -1
  39. package/dist/components/index.mjs +4 -3
  40. package/dist/components/toast/toast-provider.d.ts +2 -1
  41. package/dist/components/toast/toast-provider.js +76 -62
  42. package/dist/components/toast/toast-provider.js.map +1 -1
  43. package/dist/components/toast/toast-provider.mjs +1 -1
  44. package/dist/hooks/index.js +398 -253
  45. package/dist/hooks/index.js.map +1 -1
  46. package/dist/hooks/index.mjs +9 -8
  47. package/dist/hooks/use-chat.js +343 -199
  48. package/dist/hooks/use-chat.js.map +1 -1
  49. package/dist/hooks/use-chat.mjs +3 -3
  50. package/dist/hooks/use-coagent-state-render.d.ts +2 -2
  51. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  52. package/dist/hooks/use-coagent-state-render.mjs +1 -1
  53. package/dist/hooks/use-coagent.js +378 -233
  54. package/dist/hooks/use-coagent.js.map +1 -1
  55. package/dist/hooks/use-coagent.mjs +7 -6
  56. package/dist/hooks/use-copilot-action.js +132 -7
  57. package/dist/hooks/use-copilot-action.js.map +1 -1
  58. package/dist/hooks/use-copilot-action.mjs +3 -1
  59. package/dist/hooks/use-copilot-chat.js +367 -223
  60. package/dist/hooks/use-copilot-chat.js.map +1 -1
  61. package/dist/hooks/use-copilot-chat.mjs +6 -5
  62. package/dist/hooks/use-copilot-runtime-client.js +110 -4
  63. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  64. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  65. package/dist/index.js +439 -335
  66. package/dist/index.js.map +1 -1
  67. package/dist/index.mjs +10 -9
  68. package/dist/lib/copilot-task.js.map +1 -1
  69. package/dist/lib/copilot-task.mjs +5 -4
  70. package/dist/lib/index.js.map +1 -1
  71. package/dist/lib/index.mjs +5 -4
  72. package/dist/utils/extract.js.map +1 -1
  73. package/dist/utils/extract.mjs +4 -3
  74. package/dist/utils/index.js.map +1 -1
  75. package/dist/utils/index.mjs +4 -3
  76. package/package.json +3 -3
  77. package/src/components/copilot-provider/copilotkit.tsx +4 -1
  78. package/src/components/error-boundary/error-boundary.tsx +42 -0
  79. package/src/components/error-boundary/error-utils.tsx +95 -0
  80. package/src/components/toast/toast-provider.tsx +10 -49
  81. package/src/hooks/use-chat.ts +286 -259
  82. package/src/hooks/use-coagent-state-render.ts +2 -2
  83. package/src/hooks/use-coagent.ts +14 -11
  84. package/src/hooks/use-copilot-action.ts +3 -2
  85. package/src/hooks/use-copilot-chat.ts +9 -8
  86. package/src/hooks/use-copilot-runtime-client.ts +4 -0
  87. package/dist/chunk-2KCEHGSI.mjs.map +0 -1
  88. package/dist/chunk-DHGXL5PC.mjs.map +0 -1
  89. package/dist/chunk-EUIBVFV6.mjs +0 -294
  90. package/dist/chunk-EUIBVFV6.mjs.map +0 -1
  91. package/dist/chunk-O22KGHOQ.mjs.map +0 -1
  92. package/dist/chunk-ODN4H66E.mjs.map +0 -1
  93. package/dist/chunk-XBVKTDXP.mjs.map +0 -1
  94. package/dist/chunk-Y7MI4PBB.mjs.map +0 -1
  95. /package/dist/{chunk-OT67R4NB.mjs.map → chunk-IFTHM7LF.mjs.map} +0 -0
@@ -0,0 +1,42 @@
1
+ import React, { useEffect } from "react";
2
+ import { useErrorToast } from "./error-utils";
3
+
4
+ interface Props {
5
+ children: React.ReactNode;
6
+ }
7
+
8
+ interface State {
9
+ hasError: boolean;
10
+ error?: Error;
11
+ }
12
+
13
+ export class CopilotErrorBoundary extends React.Component<Props, State> {
14
+ constructor(props: Props) {
15
+ super(props);
16
+ this.state = { hasError: false };
17
+ }
18
+
19
+ static getDerivedStateFromError(error: Error): State {
20
+ return { hasError: true, error };
21
+ }
22
+
23
+ componentDidCatch(error: Error, errorInfo: React.ErrorInfo) {
24
+ console.error("CopilotKit Error:", error, errorInfo);
25
+ }
26
+
27
+ render() {
28
+ return <ErrorToast error={this.state.error}>{this.props.children}</ErrorToast>;
29
+ }
30
+ }
31
+
32
+ export function ErrorToast({ error, children }: { error?: Error; children: React.ReactNode }) {
33
+ const addErrorToast = useErrorToast();
34
+
35
+ useEffect(() => {
36
+ if (error) {
37
+ addErrorToast([error]);
38
+ }
39
+ }, [error, addErrorToast]);
40
+
41
+ return children;
42
+ }
@@ -0,0 +1,95 @@
1
+ import React, { useCallback, useEffect } from "react";
2
+ import { GraphQLError } from "@copilotkit/runtime-client-gql";
3
+ import { useToast } from "../toast/toast-provider";
4
+ import { ExclamationMarkIcon } from "../toast/exclamation-mark-icon";
5
+
6
+ export function ErrorToast({ errors }: { errors: (Error | GraphQLError)[] }) {
7
+ const errorsToRender = errors.map((error, idx) => {
8
+ const message =
9
+ "extensions" in error
10
+ ? (error.extensions?.originalError as undefined | { message?: string })?.message
11
+ : error.message;
12
+ const code = "extensions" in error ? (error.extensions?.code as string) : null;
13
+
14
+ return (
15
+ <div
16
+ key={idx}
17
+ style={{
18
+ marginTop: idx === 0 ? 0 : 10,
19
+ marginBottom: 14,
20
+ }}
21
+ >
22
+ <ExclamationMarkIcon style={{ marginBottom: 4 }} />
23
+
24
+ {code && (
25
+ <div
26
+ style={{
27
+ fontWeight: "600",
28
+ marginBottom: 4,
29
+ }}
30
+ >
31
+ Copilot Cloud Error:{" "}
32
+ <span style={{ fontFamily: "monospace", fontWeight: "normal" }}>{code}</span>
33
+ </div>
34
+ )}
35
+ <div>{message}</div>
36
+ </div>
37
+ );
38
+ });
39
+ return (
40
+ <div
41
+ style={{
42
+ fontSize: "13px",
43
+ maxWidth: "600px",
44
+ }}
45
+ >
46
+ {errorsToRender}
47
+ <div style={{ fontSize: "11px", opacity: 0.75 }}>
48
+ NOTE: This error only displays during local development.
49
+ </div>
50
+ </div>
51
+ );
52
+ }
53
+
54
+ export function useErrorToast() {
55
+ const { addToast } = useToast();
56
+
57
+ return useCallback(
58
+ (error: (Error | GraphQLError)[]) => {
59
+ const errorId = error
60
+ .map((err) => {
61
+ const message =
62
+ "extensions" in err
63
+ ? (err.extensions?.originalError as any)?.message || err.message
64
+ : err.message;
65
+ const stack = err.stack || "";
66
+ return btoa(message + stack).slice(0, 32); // Create hash from message + stack
67
+ })
68
+ .join("|");
69
+
70
+ addToast({
71
+ type: "error",
72
+ id: errorId, // Toast libraries typically dedupe by id
73
+ message: <ErrorToast errors={error} />,
74
+ });
75
+ },
76
+ [addToast],
77
+ );
78
+ }
79
+
80
+ export function useAsyncCallback<T extends (...args: any[]) => Promise<any>>(
81
+ callback: T,
82
+ deps: Parameters<typeof useCallback>[1],
83
+ ) {
84
+ const addErrorToast = useErrorToast();
85
+ return useCallback(async (...args: Parameters<T>) => {
86
+ try {
87
+ return await callback(...args);
88
+ } catch (error) {
89
+ console.error("Error in async callback:", error);
90
+ // @ts-ignore
91
+ addErrorToast([error]);
92
+ throw error;
93
+ }
94
+ }, deps);
95
+ }
@@ -1,7 +1,7 @@
1
- import { useCopilotContext } from "../../context";
2
1
  import { GraphQLError } from "@copilotkit/runtime-client-gql";
3
2
  import React, { createContext, useContext, useState, useCallback } from "react";
4
- import { ExclamationMarkIcon } from "./exclamation-mark-icon";
3
+ import { ErrorToast } from "../error-boundary/error-utils";
4
+ import { PartialBy } from "@copilotkit/shared";
5
5
 
6
6
  interface Toast {
7
7
  id: string;
@@ -12,7 +12,7 @@ interface Toast {
12
12
 
13
13
  interface ToastContextValue {
14
14
  toasts: Toast[];
15
- addToast: (toast: Omit<Toast, "id">) => void;
15
+ addToast: (toast: PartialBy<Toast, "id">) => void;
16
16
  addGraphQLErrorsToast: (errors: GraphQLError[]) => void;
17
17
  removeToast: (id: string) => void;
18
18
  enabled: boolean;
@@ -36,10 +36,13 @@ export function ToastProvider({
36
36
  children: React.ReactNode;
37
37
  }) {
38
38
  const [toasts, setToasts] = useState<Toast[]>([]);
39
- const addToast = useCallback((toast: Omit<Toast, "id">) => {
40
- const id = Math.random().toString(36).substring(2, 9);
39
+ const addToast = useCallback((toast: PartialBy<Toast, "id">) => {
40
+ const id = toast.id ?? Math.random().toString(36).substring(2, 9);
41
41
 
42
- setToasts((currentToasts) => [...currentToasts, { ...toast, id }]);
42
+ setToasts((currentToasts) => {
43
+ if (currentToasts.find((toast) => toast.id === id)) return currentToasts;
44
+ return [...currentToasts, { ...toast, id }];
45
+ });
43
46
 
44
47
  if (toast.duration) {
45
48
  setTimeout(() => {
@@ -54,51 +57,9 @@ export function ToastProvider({
54
57
  // return;
55
58
  // }
56
59
 
57
- const errorsToRender = errors.map((error, idx) => {
58
- const message = error.message;
59
- const code = error.extensions?.code as string;
60
-
61
- return (
62
- <div
63
- key={idx}
64
- style={{
65
- marginTop: idx === 0 ? 0 : 10,
66
- marginBottom: 14,
67
- }}
68
- >
69
- <ExclamationMarkIcon style={{ marginBottom: 4 }} />
70
-
71
- {code && (
72
- <div
73
- style={{
74
- fontWeight: "600",
75
- marginBottom: 4,
76
- }}
77
- >
78
- Copilot Cloud Error:{" "}
79
- <span style={{ fontFamily: "monospace", fontWeight: "normal" }}>{code}</span>
80
- </div>
81
- )}
82
- <div>{message}</div>
83
- </div>
84
- );
85
- });
86
-
87
60
  addToast({
88
61
  type: "error",
89
- message: (
90
- <div
91
- style={{
92
- fontSize: "13px",
93
- maxWidth: "600px",
94
- }}
95
- >
96
- {errorsToRender}
97
- <div style={{ fontSize: "11px", opacity: 0.75 }}>
98
- NOTE: This is a Copilot Cloud error, and it only displays during local development.
99
- </div>
100
- </div>
101
- ),
62
+ message: <ErrorToast errors={errors} />,
102
63
  });
103
64
  }, []);
104
65