@copilotkit/react-core 1.9.2-next.8 → 1.9.2

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 (171) hide show
  1. package/CHANGELOG.md +193 -0
  2. package/dist/{chunk-ERXWDCY6.mjs → chunk-36MGCCPZ.mjs} +2 -2
  3. package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
  4. package/dist/{chunk-7G6RR4HE.mjs → chunk-3Q4F7RF2.mjs} +2 -2
  5. package/dist/chunk-57K2ZJ5F.mjs +348 -0
  6. package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
  7. package/dist/{chunk-UBNRUXEK.mjs → chunk-5BSUSFHM.mjs} +2 -2
  8. package/dist/{chunk-RN3ZRHI7.mjs → chunk-AD7DWJNW.mjs} +66 -25
  9. package/dist/chunk-AD7DWJNW.mjs.map +1 -0
  10. package/dist/{chunk-JPMIAGI6.mjs → chunk-BVK7PLK6.mjs} +2 -2
  11. package/dist/{chunk-VJCHRQ7Q.mjs → chunk-DGON3GZX.mjs} +39 -6
  12. package/dist/chunk-DGON3GZX.mjs.map +1 -0
  13. package/dist/{chunk-XFOTNHYA.mjs → chunk-DKZTPL66.mjs} +2 -2
  14. package/dist/{chunk-XFOTNHYA.mjs.map → chunk-DKZTPL66.mjs.map} +1 -1
  15. package/dist/{chunk-S4BOATBG.mjs → chunk-FN3UA2ZE.mjs} +3 -3
  16. package/dist/{chunk-ISYBUDL4.mjs → chunk-JWAXDYOW.mjs} +11 -12
  17. package/dist/chunk-JWAXDYOW.mjs.map +1 -0
  18. package/dist/{chunk-T4ZKC4X4.mjs → chunk-KIXKBJUV.mjs} +3 -3
  19. package/dist/{chunk-I4JPQECN.mjs → chunk-LFAZTKBK.mjs} +5 -5
  20. package/dist/{chunk-JHIZ5HAI.mjs → chunk-NJA5ZLAZ.mjs} +29 -10
  21. package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
  22. package/dist/{chunk-ZHEEHGLS.mjs → chunk-QGT4JO7R.mjs} +35 -6
  23. package/dist/chunk-QGT4JO7R.mjs.map +1 -0
  24. package/dist/{chunk-JXF732XG.mjs → chunk-S5QUEHJC.mjs} +195 -77
  25. package/dist/chunk-S5QUEHJC.mjs.map +1 -0
  26. package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
  27. package/dist/{chunk-CMQV4XNY.mjs → chunk-VDADWRS3.mjs} +2 -2
  28. package/dist/chunk-YAF2LATQ.mjs +310 -0
  29. package/dist/chunk-YAF2LATQ.mjs.map +1 -0
  30. package/dist/{chunk-VF6UPRKM.mjs → chunk-ZGMZ5WJI.mjs} +4 -4
  31. package/dist/components/copilot-provider/copilot-messages.js +37 -4
  32. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  33. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  34. package/dist/components/copilot-provider/copilotkit-props.d.ts +14 -9
  35. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  36. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  37. package/dist/components/copilot-provider/copilotkit.js +354 -258
  38. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  39. package/dist/components/copilot-provider/copilotkit.mjs +10 -10
  40. package/dist/components/copilot-provider/index.d.ts +1 -1
  41. package/dist/components/copilot-provider/index.js +354 -258
  42. package/dist/components/copilot-provider/index.js.map +1 -1
  43. package/dist/components/copilot-provider/index.mjs +10 -10
  44. package/dist/components/error-boundary/error-boundary.js +135 -146
  45. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  46. package/dist/components/error-boundary/error-boundary.mjs +4 -4
  47. package/dist/components/error-boundary/error-utils.js.map +1 -1
  48. package/dist/components/error-boundary/error-utils.mjs +2 -2
  49. package/dist/components/index.d.ts +1 -1
  50. package/dist/components/index.js +354 -258
  51. package/dist/components/index.js.map +1 -1
  52. package/dist/components/index.mjs +10 -10
  53. package/dist/components/toast/toast-provider.js +118 -85
  54. package/dist/components/toast/toast-provider.js.map +1 -1
  55. package/dist/components/toast/toast-provider.mjs +1 -1
  56. package/dist/components/usage-banner.js +135 -146
  57. package/dist/components/usage-banner.js.map +1 -1
  58. package/dist/components/usage-banner.mjs +1 -1
  59. package/dist/context/copilot-context.d.ts +1 -1
  60. package/dist/context/copilot-context.js +1 -1
  61. package/dist/context/copilot-context.js.map +1 -1
  62. package/dist/context/copilot-context.mjs +1 -1
  63. package/dist/context/index.d.ts +1 -1
  64. package/dist/context/index.js +1 -1
  65. package/dist/context/index.js.map +1 -1
  66. package/dist/context/index.mjs +1 -1
  67. package/dist/{copilot-context-3da805ab.d.ts → copilot-context-3ab4fdf5.d.ts} +3 -3
  68. package/dist/hooks/index.d.ts +1 -1
  69. package/dist/hooks/index.js +249 -88
  70. package/dist/hooks/index.js.map +1 -1
  71. package/dist/hooks/index.mjs +32 -32
  72. package/dist/hooks/use-chat.d.ts +1 -1
  73. package/dist/hooks/use-chat.js +287 -174
  74. package/dist/hooks/use-chat.js.map +1 -1
  75. package/dist/hooks/use-chat.mjs +5 -5
  76. package/dist/hooks/use-coagent-state-render.js +1 -1
  77. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  78. package/dist/hooks/use-coagent-state-render.mjs +3 -3
  79. package/dist/hooks/use-coagent.d.ts +1 -1
  80. package/dist/hooks/use-coagent.js +224 -82
  81. package/dist/hooks/use-coagent.js.map +1 -1
  82. package/dist/hooks/use-coagent.mjs +14 -14
  83. package/dist/hooks/use-copilot-action.js +26 -7
  84. package/dist/hooks/use-copilot-action.js.map +1 -1
  85. package/dist/hooks/use-copilot-action.mjs +4 -4
  86. package/dist/hooks/use-copilot-additional-instructions.js +1 -1
  87. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  88. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  89. package/dist/hooks/use-copilot-authenticated-action.js +26 -7
  90. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  91. package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
  92. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  93. package/dist/hooks/use-copilot-chat.js +195 -82
  94. package/dist/hooks/use-copilot-chat.js.map +1 -1
  95. package/dist/hooks/use-copilot-chat.mjs +13 -13
  96. package/dist/hooks/use-copilot-readable.js +1 -1
  97. package/dist/hooks/use-copilot-readable.js.map +1 -1
  98. package/dist/hooks/use-copilot-readable.mjs +2 -2
  99. package/dist/hooks/use-copilot-runtime-client.d.ts +2 -2
  100. package/dist/hooks/use-copilot-runtime-client.js +8 -8
  101. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  102. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  103. package/dist/hooks/use-langgraph-interrupt-render.js +1 -1
  104. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  105. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  106. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  107. package/dist/hooks/use-langgraph-interrupt.js +195 -82
  108. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  109. package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
  110. package/dist/hooks/use-make-copilot-document-readable.js +1 -1
  111. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  112. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  113. package/dist/index.d.ts +1 -1
  114. package/dist/index.js +593 -336
  115. package/dist/index.js.map +1 -1
  116. package/dist/index.mjs +33 -33
  117. package/dist/lib/copilot-task.d.ts +1 -1
  118. package/dist/lib/copilot-task.js.map +1 -1
  119. package/dist/lib/copilot-task.mjs +11 -11
  120. package/dist/lib/index.d.ts +1 -1
  121. package/dist/lib/index.js.map +1 -1
  122. package/dist/lib/index.mjs +11 -11
  123. package/dist/setupTests.d.ts +2 -0
  124. package/dist/setupTests.js +26 -0
  125. package/dist/setupTests.js.map +1 -0
  126. package/dist/setupTests.mjs +24 -0
  127. package/dist/setupTests.mjs.map +1 -0
  128. package/dist/types/interrupt-action.d.ts +1 -1
  129. package/dist/utils/extract.d.ts +1 -1
  130. package/dist/utils/extract.js.map +1 -1
  131. package/dist/utils/extract.mjs +10 -10
  132. package/dist/utils/index.d.ts +1 -1
  133. package/dist/utils/index.js.map +1 -1
  134. package/dist/utils/index.mjs +10 -10
  135. package/jest.config.js +4 -0
  136. package/package.json +6 -3
  137. package/src/components/copilot-provider/__tests__/{copilotkit-trace.test.tsx → copilotkit-error.test.tsx} +17 -17
  138. package/src/components/copilot-provider/copilot-messages.tsx +43 -4
  139. package/src/components/copilot-provider/copilotkit-props.tsx +13 -8
  140. package/src/components/copilot-provider/copilotkit.tsx +61 -19
  141. package/src/components/toast/toast-provider.tsx +49 -24
  142. package/src/components/usage-banner.tsx +144 -147
  143. package/src/context/copilot-context.tsx +4 -4
  144. package/src/hooks/__tests__/use-coagent-config.test.ts +284 -0
  145. package/src/hooks/use-chat.ts +249 -61
  146. package/src/hooks/use-coagent.ts +41 -0
  147. package/src/hooks/use-copilot-action.ts +51 -9
  148. package/src/hooks/use-copilot-runtime-client.ts +12 -50
  149. package/src/setupTests.ts +26 -0
  150. package/tsconfig.json +5 -2
  151. package/dist/chunk-HD2GE3DK.mjs +0 -359
  152. package/dist/chunk-HD2GE3DK.mjs.map +0 -1
  153. package/dist/chunk-ISYBUDL4.mjs.map +0 -1
  154. package/dist/chunk-JHIZ5HAI.mjs.map +0 -1
  155. package/dist/chunk-JXF732XG.mjs.map +0 -1
  156. package/dist/chunk-RN3ZRHI7.mjs.map +0 -1
  157. package/dist/chunk-VJCHRQ7Q.mjs.map +0 -1
  158. package/dist/chunk-VRXANACV.mjs +0 -277
  159. package/dist/chunk-VRXANACV.mjs.map +0 -1
  160. package/dist/chunk-ZHEEHGLS.mjs.map +0 -1
  161. /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
  162. /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
  163. /package/dist/{chunk-7G6RR4HE.mjs.map → chunk-3Q4F7RF2.mjs.map} +0 -0
  164. /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
  165. /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
  166. /package/dist/{chunk-S4BOATBG.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
  167. /package/dist/{chunk-T4ZKC4X4.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
  168. /package/dist/{chunk-I4JPQECN.mjs.map → chunk-LFAZTKBK.mjs.map} +0 -0
  169. /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
  170. /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
  171. /package/dist/{chunk-VF6UPRKM.mjs.map → chunk-ZGMZ5WJI.mjs.map} +0 -0
@@ -1,4 +1,4 @@
1
- import { CopilotCloudConfig, FunctionCallHandler, CopilotTraceHandler } from "@copilotkit/shared";
1
+ import { CopilotCloudConfig, FunctionCallHandler, CopilotErrorHandler } from "@copilotkit/shared";
2
2
  import {
3
3
  ActionRenderProps,
4
4
  CatchAllActionRenderProps,
@@ -195,7 +195,7 @@ export interface CopilotContextParams {
195
195
  /**
196
196
  * The forwarded parameters to use for the task.
197
197
  */
198
- forwardedParameters?: Pick<ForwardedParametersInput, "temperature">;
198
+ forwardedParameters?: Partial<Pick<ForwardedParametersInput, "temperature">>;
199
199
  availableAgents: Agent[];
200
200
 
201
201
  /**
@@ -222,7 +222,7 @@ export interface CopilotContextParams {
222
222
  /**
223
223
  * Optional trace handler for comprehensive debugging and observability.
224
224
  */
225
- onTrace?: CopilotTraceHandler;
225
+ onError?: CopilotErrorHandler;
226
226
  }
227
227
 
228
228
  const emptyCopilotContext: CopilotContextParams = {
@@ -293,7 +293,7 @@ const emptyCopilotContext: CopilotContextParams = {
293
293
  langGraphInterruptAction: null,
294
294
  setLangGraphInterruptAction: () => null,
295
295
  removeLangGraphInterruptAction: () => null,
296
- onTrace: undefined,
296
+ onError: undefined,
297
297
  };
298
298
 
299
299
  export const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);
@@ -0,0 +1,284 @@
1
+ import { renderHook } from "@testing-library/react";
2
+ import { useCoAgent } from "../use-coagent";
3
+
4
+ // Mock the dependencies
5
+ const mockSetCoagentStatesWithRef = jest.fn();
6
+ const mockAppendMessage = jest.fn();
7
+ const mockRunChatCompletion = jest.fn();
8
+
9
+ jest.mock("../use-copilot-chat", () => ({
10
+ useCopilotChat: () => ({
11
+ appendMessage: mockAppendMessage,
12
+ runChatCompletion: mockRunChatCompletion,
13
+ }),
14
+ }));
15
+
16
+ jest.mock("../use-copilot-runtime-client", () => ({
17
+ useCopilotRuntimeClient: () => ({
18
+ loadAgentState: jest.fn().mockResolvedValue({
19
+ data: { loadAgentState: { state: "{}", threadExists: false } },
20
+ error: null,
21
+ }),
22
+ }),
23
+ }));
24
+
25
+ jest.mock("../../context", () => ({
26
+ useCopilotContext: () => ({
27
+ availableAgents: [],
28
+ coagentStates: {},
29
+ coagentStatesRef: { current: {} },
30
+ setCoagentStatesWithRef: mockSetCoagentStatesWithRef,
31
+ threadId: "test-thread",
32
+ copilotApiConfig: {
33
+ headers: {},
34
+ chatApiEndpoint: "test-endpoint",
35
+ publicApiKey: "test-key",
36
+ },
37
+ showDevConsole: false,
38
+ }),
39
+ useCopilotMessagesContext: () => ({
40
+ messages: [],
41
+ }),
42
+ }));
43
+
44
+ jest.mock("../../components/toast/toast-provider", () => ({
45
+ useToast: () => ({
46
+ setBannerError: jest.fn(),
47
+ }),
48
+ }));
49
+
50
+ jest.mock("../../components/error-boundary/error-utils", () => ({
51
+ useAsyncCallback: (fn: any) => fn,
52
+ }));
53
+
54
+ describe("useCoAgent config synchronization", () => {
55
+ beforeEach(() => {
56
+ jest.clearAllMocks();
57
+ mockSetCoagentStatesWithRef.mockImplementation((updater) => {
58
+ if (typeof updater === "function") {
59
+ updater({});
60
+ }
61
+ });
62
+ });
63
+
64
+ it("should call setCoagentStatesWithRef when config changes", () => {
65
+ const { rerender } = renderHook(
66
+ ({ config }) =>
67
+ useCoAgent({
68
+ name: "test-agent",
69
+ initialState: { count: 0 },
70
+ config,
71
+ }),
72
+ {
73
+ initialProps: { config: { configurable: { model: "gpt-4" } } },
74
+ },
75
+ );
76
+
77
+ // Clear the initial calls
78
+ mockSetCoagentStatesWithRef.mockClear();
79
+
80
+ // Change config
81
+ rerender({ config: { configurable: { model: "gpt-4o" } } });
82
+
83
+ // Should have called setCoagentStatesWithRef with new config
84
+ expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
85
+ });
86
+
87
+ it("should not call setCoagentStatesWithRef when config is unchanged", () => {
88
+ const config = { configurable: { model: "gpt-4" } };
89
+
90
+ const { rerender } = renderHook(
91
+ ({ config }) =>
92
+ useCoAgent({
93
+ name: "test-agent",
94
+ initialState: { count: 0 },
95
+ config,
96
+ }),
97
+ {
98
+ initialProps: { config },
99
+ },
100
+ );
101
+
102
+ // Clear the initial calls
103
+ mockSetCoagentStatesWithRef.mockClear();
104
+
105
+ // Re-render with same config
106
+ rerender({ config });
107
+
108
+ // Should not have called setCoagentStatesWithRef
109
+ expect(mockSetCoagentStatesWithRef).not.toHaveBeenCalled();
110
+ });
111
+
112
+ it("should handle backward compatibility with configurable prop", () => {
113
+ const { rerender } = renderHook(
114
+ ({ configurable }) =>
115
+ useCoAgent({
116
+ name: "test-agent",
117
+ initialState: { count: 0 },
118
+ configurable,
119
+ }),
120
+ {
121
+ initialProps: { configurable: { model: "gpt-4" } },
122
+ },
123
+ );
124
+
125
+ // Clear the initial calls
126
+ mockSetCoagentStatesWithRef.mockClear();
127
+
128
+ // Change configurable prop
129
+ rerender({ configurable: { model: "gpt-4o" } });
130
+
131
+ // Should have called setCoagentStatesWithRef
132
+ expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
133
+ });
134
+
135
+ it("should update config while preserving other state properties", () => {
136
+ let capturedUpdater: any = null;
137
+
138
+ mockSetCoagentStatesWithRef.mockImplementation((updater) => {
139
+ capturedUpdater = updater;
140
+ return updater;
141
+ });
142
+
143
+ const { rerender } = renderHook(
144
+ ({ config }) =>
145
+ useCoAgent({
146
+ name: "test-agent",
147
+ initialState: { count: 0 },
148
+ config,
149
+ }),
150
+ {
151
+ initialProps: { config: { configurable: { model: "gpt-4" } } },
152
+ },
153
+ );
154
+
155
+ // Clear the initial calls and reset captured updater
156
+ mockSetCoagentStatesWithRef.mockClear();
157
+ capturedUpdater = null;
158
+
159
+ // Change config
160
+ rerender({ config: { configurable: { model: "gpt-4o" } } });
161
+
162
+ // Should have called setCoagentStatesWithRef
163
+ expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
164
+ expect(capturedUpdater).toBeTruthy();
165
+
166
+ // Test the updater function behavior
167
+ const prevState = {
168
+ "test-agent": {
169
+ name: "test-agent",
170
+ state: { count: 5 },
171
+ config: { configurable: { model: "gpt-4" } },
172
+ running: true,
173
+ active: true,
174
+ threadId: "thread-123",
175
+ nodeName: "test-node",
176
+ runId: "run-456",
177
+ },
178
+ };
179
+
180
+ const newState = capturedUpdater(prevState);
181
+
182
+ // Verify the state is updated correctly
183
+ expect(newState).toEqual({
184
+ "test-agent": {
185
+ name: "test-agent",
186
+ state: { count: 5 }, // State preserved
187
+ config: { configurable: { model: "gpt-4o" } }, // Config updated
188
+ running: true, // Other properties preserved
189
+ active: true,
190
+ threadId: "thread-123",
191
+ nodeName: "test-node",
192
+ runId: "run-456",
193
+ },
194
+ });
195
+ });
196
+
197
+ it("should create new agent state when agent doesn't exist", () => {
198
+ let capturedUpdater: any = null;
199
+
200
+ mockSetCoagentStatesWithRef.mockImplementation((updater) => {
201
+ capturedUpdater = updater;
202
+ return updater;
203
+ });
204
+
205
+ const { rerender } = renderHook(
206
+ ({ config }) =>
207
+ useCoAgent({
208
+ name: "test-agent",
209
+ initialState: { count: 0 },
210
+ config,
211
+ }),
212
+ {
213
+ initialProps: { config: { configurable: { model: "gpt-4" } } },
214
+ },
215
+ );
216
+
217
+ // Clear the initial calls and reset captured updater
218
+ mockSetCoagentStatesWithRef.mockClear();
219
+ capturedUpdater = null;
220
+
221
+ // Change config
222
+ rerender({ config: { configurable: { model: "gpt-4o" } } });
223
+
224
+ // Should have called setCoagentStatesWithRef
225
+ expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
226
+ expect(capturedUpdater).toBeTruthy();
227
+
228
+ // Test the updater function behavior with empty previous state
229
+ const prevState = {}; // No existing agent state
230
+
231
+ const newState = capturedUpdater(prevState);
232
+
233
+ // Verify the state creates a new agent state with default values
234
+ expect(newState).toEqual({
235
+ "test-agent": {
236
+ name: "test-agent",
237
+ state: { count: 0 }, // Uses initialState
238
+ config: { configurable: { model: "gpt-4o" } }, // New config
239
+ running: false, // Default values
240
+ active: false,
241
+ threadId: undefined,
242
+ nodeName: undefined,
243
+ runId: undefined,
244
+ },
245
+ });
246
+ });
247
+
248
+ it("should handle deeply nested config changes", () => {
249
+ const { rerender } = renderHook(
250
+ ({ config }) =>
251
+ useCoAgent({
252
+ name: "test-agent",
253
+ initialState: { count: 0 },
254
+ config,
255
+ }),
256
+ {
257
+ initialProps: {
258
+ config: {
259
+ configurable: {
260
+ model: "gpt-4",
261
+ settings: { temperature: 0.5 },
262
+ },
263
+ },
264
+ },
265
+ },
266
+ );
267
+
268
+ // Clear the initial calls
269
+ mockSetCoagentStatesWithRef.mockClear();
270
+
271
+ // Change nested config
272
+ rerender({
273
+ config: {
274
+ configurable: {
275
+ model: "gpt-4",
276
+ settings: { temperature: 0.7 }, // Only nested property changed
277
+ },
278
+ },
279
+ });
280
+
281
+ // Should detect the nested change
282
+ expect(mockSetCoagentStatesWithRef).toHaveBeenCalledWith(expect.any(Function));
283
+ });
284
+ });