@copilotkit/react-core 1.9.2-next.0 → 1.9.2-next.10

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 (168) hide show
  1. package/CHANGELOG.md +78 -0
  2. package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
  3. package/dist/{chunk-2FW7HH6W.mjs → chunk-3YHYWAHK.mjs} +3 -3
  4. package/dist/{chunk-RUY6MLHA.mjs → chunk-55QZ2SVJ.mjs} +36 -6
  5. package/dist/chunk-55QZ2SVJ.mjs.map +1 -0
  6. package/dist/chunk-57K2ZJ5F.mjs +348 -0
  7. package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
  8. package/dist/{chunk-XY5BN4HZ.mjs → chunk-ADIITPD2.mjs} +9 -6
  9. package/dist/{chunk-XY5BN4HZ.mjs.map → chunk-ADIITPD2.mjs.map} +1 -1
  10. package/dist/{chunk-Q5D5XQFA.mjs → chunk-CMQV4XNY.mjs} +2 -2
  11. package/dist/{chunk-LDACFA2B.mjs → chunk-EF5BNM34.mjs} +3 -3
  12. package/dist/{chunk-UHQMV2CE.mjs → chunk-ERXWDCY6.mjs} +2 -2
  13. package/dist/{chunk-UIT6QMUJ.mjs → chunk-EXU7GWLC.mjs} +5 -5
  14. package/dist/{chunk-YDENFEKA.mjs → chunk-FXK6RQIN.mjs} +2 -2
  15. package/dist/{chunk-HJP2RX5R.mjs → chunk-G7LYGERN.mjs} +81 -14
  16. package/dist/chunk-G7LYGERN.mjs.map +1 -0
  17. package/dist/{chunk-NNSXCFQO.mjs → chunk-JDEWNLNP.mjs} +41 -7
  18. package/dist/chunk-JDEWNLNP.mjs.map +1 -0
  19. package/dist/{chunk-C6F6EQNA.mjs → chunk-JPMIAGI6.mjs} +2 -2
  20. package/dist/{chunk-T42PN5VN.mjs → chunk-NQVCZQ5T.mjs} +4 -4
  21. package/dist/{chunk-YZDRMIOM.mjs → chunk-OF4SZTLL.mjs} +4 -4
  22. package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
  23. package/dist/{chunk-LZDDYZEY.mjs → chunk-UBNRUXEK.mjs} +2 -2
  24. package/dist/{chunk-SGLWMQ2J.mjs → chunk-WOGURSAL.mjs} +12 -9
  25. package/dist/chunk-WOGURSAL.mjs.map +1 -0
  26. package/dist/{chunk-6KGEF242.mjs → chunk-XFOTNHYA.mjs} +3 -2
  27. package/dist/chunk-XFOTNHYA.mjs.map +1 -0
  28. package/dist/chunk-YAF2LATQ.mjs +310 -0
  29. package/dist/chunk-YAF2LATQ.mjs.map +1 -0
  30. package/dist/components/copilot-provider/copilot-messages.js +39 -4
  31. package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
  32. package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
  33. package/dist/components/copilot-provider/copilotkit-props.d.ts +21 -2
  34. package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
  35. package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
  36. package/dist/components/copilot-provider/copilotkit.js +330 -240
  37. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  38. package/dist/components/copilot-provider/copilotkit.mjs +8 -8
  39. package/dist/components/copilot-provider/index.d.ts +1 -1
  40. package/dist/components/copilot-provider/index.js +330 -240
  41. package/dist/components/copilot-provider/index.js.map +1 -1
  42. package/dist/components/copilot-provider/index.mjs +8 -8
  43. package/dist/components/error-boundary/error-boundary.js +135 -146
  44. package/dist/components/error-boundary/error-boundary.js.map +1 -1
  45. package/dist/components/error-boundary/error-boundary.mjs +4 -4
  46. package/dist/components/error-boundary/error-utils.js.map +1 -1
  47. package/dist/components/error-boundary/error-utils.mjs +2 -2
  48. package/dist/components/index.d.ts +1 -1
  49. package/dist/components/index.js +330 -240
  50. package/dist/components/index.js.map +1 -1
  51. package/dist/components/index.mjs +8 -8
  52. package/dist/components/toast/toast-provider.js +118 -85
  53. package/dist/components/toast/toast-provider.js.map +1 -1
  54. package/dist/components/toast/toast-provider.mjs +1 -1
  55. package/dist/components/usage-banner.js +135 -146
  56. package/dist/components/usage-banner.js.map +1 -1
  57. package/dist/components/usage-banner.mjs +1 -1
  58. package/dist/context/copilot-context.d.ts +1 -1
  59. package/dist/context/copilot-context.js +2 -1
  60. package/dist/context/copilot-context.js.map +1 -1
  61. package/dist/context/copilot-context.mjs +1 -1
  62. package/dist/context/index.d.ts +1 -1
  63. package/dist/context/index.js +2 -1
  64. package/dist/context/index.js.map +1 -1
  65. package/dist/context/index.mjs +1 -1
  66. package/dist/{copilot-context-f9b2b4c3.d.ts → copilot-context-3da805ab.d.ts} +5 -1
  67. package/dist/hooks/index.d.ts +1 -1
  68. package/dist/hooks/index.js +108 -12
  69. package/dist/hooks/index.js.map +1 -1
  70. package/dist/hooks/index.mjs +19 -19
  71. package/dist/hooks/use-chat.d.ts +1 -1
  72. package/dist/hooks/use-chat.js +105 -12
  73. package/dist/hooks/use-chat.js.map +1 -1
  74. package/dist/hooks/use-chat.mjs +5 -5
  75. package/dist/hooks/use-coagent-state-render.js +2 -1
  76. package/dist/hooks/use-coagent-state-render.js.map +1 -1
  77. package/dist/hooks/use-coagent-state-render.mjs +3 -3
  78. package/dist/hooks/use-coagent.d.ts +1 -1
  79. package/dist/hooks/use-coagent.js +108 -12
  80. package/dist/hooks/use-coagent.js.map +1 -1
  81. package/dist/hooks/use-coagent.mjs +11 -11
  82. package/dist/hooks/use-copilot-action.js +2 -1
  83. package/dist/hooks/use-copilot-action.js.map +1 -1
  84. package/dist/hooks/use-copilot-action.mjs +4 -4
  85. package/dist/hooks/use-copilot-additional-instructions.js +2 -1
  86. package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
  87. package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
  88. package/dist/hooks/use-copilot-authenticated-action.js +2 -1
  89. package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
  90. package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
  91. package/dist/hooks/use-copilot-chat.d.ts +1 -1
  92. package/dist/hooks/use-copilot-chat.js +105 -12
  93. package/dist/hooks/use-copilot-chat.js.map +1 -1
  94. package/dist/hooks/use-copilot-chat.mjs +10 -10
  95. package/dist/hooks/use-copilot-readable.js +2 -1
  96. package/dist/hooks/use-copilot-readable.js.map +1 -1
  97. package/dist/hooks/use-copilot-readable.mjs +2 -2
  98. package/dist/hooks/use-copilot-runtime-client.d.ts +2 -0
  99. package/dist/hooks/use-copilot-runtime-client.js +52 -2
  100. package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
  101. package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
  102. package/dist/hooks/use-langgraph-interrupt-render.js +2 -1
  103. package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
  104. package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
  105. package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
  106. package/dist/hooks/use-langgraph-interrupt.js +105 -12
  107. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  108. package/dist/hooks/use-langgraph-interrupt.mjs +11 -11
  109. package/dist/hooks/use-make-copilot-document-readable.js +2 -1
  110. package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
  111. package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
  112. package/dist/index.d.ts +1 -1
  113. package/dist/index.js +404 -249
  114. package/dist/index.js.map +1 -1
  115. package/dist/index.mjs +20 -20
  116. package/dist/lib/copilot-task.d.ts +1 -1
  117. package/dist/lib/copilot-task.js.map +1 -1
  118. package/dist/lib/copilot-task.mjs +9 -9
  119. package/dist/lib/index.d.ts +1 -1
  120. package/dist/lib/index.js.map +1 -1
  121. package/dist/lib/index.mjs +9 -9
  122. package/dist/types/interrupt-action.d.ts +1 -1
  123. package/dist/utils/extract.d.ts +1 -1
  124. package/dist/utils/extract.js.map +1 -1
  125. package/dist/utils/extract.mjs +8 -8
  126. package/dist/utils/index.d.ts +1 -1
  127. package/dist/utils/index.js.map +1 -1
  128. package/dist/utils/index.mjs +8 -8
  129. package/jest.config.js +7 -3
  130. package/package.json +4 -3
  131. package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +75 -0
  132. package/src/components/copilot-provider/copilot-messages.tsx +46 -5
  133. package/src/components/copilot-provider/copilotkit-props.tsx +21 -0
  134. package/src/components/copilot-provider/copilotkit.tsx +5 -1
  135. package/src/components/toast/toast-provider.tsx +49 -24
  136. package/src/components/usage-banner.tsx +144 -147
  137. package/src/context/copilot-context.tsx +7 -1
  138. package/src/hooks/use-chat.ts +106 -6
  139. package/src/hooks/use-coagent.ts +5 -0
  140. package/src/hooks/use-copilot-runtime-client.ts +41 -39
  141. package/tsconfig.json +1 -8
  142. package/tsup.config.ts +6 -6
  143. package/dist/chunk-6KGEF242.mjs.map +0 -1
  144. package/dist/chunk-HD2GE3DK.mjs +0 -359
  145. package/dist/chunk-HD2GE3DK.mjs.map +0 -1
  146. package/dist/chunk-HJP2RX5R.mjs.map +0 -1
  147. package/dist/chunk-NNSXCFQO.mjs.map +0 -1
  148. package/dist/chunk-RUY6MLHA.mjs.map +0 -1
  149. package/dist/chunk-SGLWMQ2J.mjs.map +0 -1
  150. package/dist/chunk-VRXANACV.mjs +0 -277
  151. package/dist/chunk-VRXANACV.mjs.map +0 -1
  152. package/dist/utils/utils.test.d.ts +0 -2
  153. package/dist/utils/utils.test.js +0 -9
  154. package/dist/utils/utils.test.js.map +0 -1
  155. package/dist/utils/utils.test.mjs +0 -7
  156. package/dist/utils/utils.test.mjs.map +0 -1
  157. /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
  158. /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
  159. /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-CMQV4XNY.mjs.map} +0 -0
  160. /package/dist/{chunk-LDACFA2B.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
  161. /package/dist/{chunk-UHQMV2CE.mjs.map → chunk-ERXWDCY6.mjs.map} +0 -0
  162. /package/dist/{chunk-UIT6QMUJ.mjs.map → chunk-EXU7GWLC.mjs.map} +0 -0
  163. /package/dist/{chunk-YDENFEKA.mjs.map → chunk-FXK6RQIN.mjs.map} +0 -0
  164. /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-JPMIAGI6.mjs.map} +0 -0
  165. /package/dist/{chunk-T42PN5VN.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
  166. /package/dist/{chunk-YZDRMIOM.mjs.map → chunk-OF4SZTLL.mjs.map} +0 -0
  167. /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
  168. /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-UBNRUXEK.mjs.map} +0 -0
@@ -1,56 +1,56 @@
1
1
  import "../chunk-CQPYJIBH.mjs";
2
2
  import {
3
3
  useLangGraphInterruptRender
4
- } from "../chunk-Q5D5XQFA.mjs";
4
+ } from "../chunk-CMQV4XNY.mjs";
5
5
  import {
6
6
  useLangGraphInterrupt
7
- } from "../chunk-YZDRMIOM.mjs";
7
+ } from "../chunk-OF4SZTLL.mjs";
8
8
  import {
9
9
  useMakeCopilotDocumentReadable
10
- } from "../chunk-UHQMV2CE.mjs";
10
+ } from "../chunk-ERXWDCY6.mjs";
11
11
  import {
12
12
  useCoAgentStateRender
13
- } from "../chunk-2FW7HH6W.mjs";
13
+ } from "../chunk-3YHYWAHK.mjs";
14
14
  import {
15
15
  runAgent,
16
16
  startAgent,
17
17
  stopAgent,
18
18
  useCoAgent
19
- } from "../chunk-XY5BN4HZ.mjs";
19
+ } from "../chunk-ADIITPD2.mjs";
20
20
  import {
21
21
  useCopilotAdditionalInstructions
22
- } from "../chunk-C6F6EQNA.mjs";
22
+ } from "../chunk-JPMIAGI6.mjs";
23
23
  import {
24
24
  useCopilotAuthenticatedAction_c
25
- } from "../chunk-LDACFA2B.mjs";
25
+ } from "../chunk-EF5BNM34.mjs";
26
26
  import {
27
27
  useCopilotAction
28
- } from "../chunk-T42PN5VN.mjs";
28
+ } from "../chunk-NQVCZQ5T.mjs";
29
29
  import {
30
30
  useCopilotChat
31
- } from "../chunk-UIT6QMUJ.mjs";
31
+ } from "../chunk-EXU7GWLC.mjs";
32
32
  import {
33
33
  useCopilotReadable
34
- } from "../chunk-LZDDYZEY.mjs";
35
- import "../chunk-SGLWMQ2J.mjs";
36
- import "../chunk-QQZLIEXK.mjs";
37
- import "../chunk-NNSXCFQO.mjs";
34
+ } from "../chunk-UBNRUXEK.mjs";
35
+ import "../chunk-WOGURSAL.mjs";
36
+ import "../chunk-SJJNFYGQ.mjs";
37
+ import "../chunk-JDEWNLNP.mjs";
38
38
  import "../chunk-5FHSUKQL.mjs";
39
39
  import "../chunk-RKTVJRK7.mjs";
40
40
  import "../chunk-PMAFHQ7P.mjs";
41
- import "../chunk-HD2GE3DK.mjs";
41
+ import "../chunk-57K2ZJ5F.mjs";
42
42
  import "../chunk-YPSGKPDA.mjs";
43
43
  import "../chunk-DCTJZ742.mjs";
44
- import "../chunk-HJP2RX5R.mjs";
44
+ import "../chunk-G7LYGERN.mjs";
45
45
  import "../chunk-4CEQJ2X6.mjs";
46
- import "../chunk-CCESTGAM.mjs";
46
+ import "../chunk-3OQM3NEK.mjs";
47
47
  import "../chunk-O7ARI5CV.mjs";
48
48
  import {
49
49
  useCopilotRuntimeClient
50
- } from "../chunk-RUY6MLHA.mjs";
50
+ } from "../chunk-55QZ2SVJ.mjs";
51
51
  import "../chunk-GFJW4RIM.mjs";
52
- import "../chunk-VRXANACV.mjs";
53
- import "../chunk-6KGEF242.mjs";
52
+ import "../chunk-YAF2LATQ.mjs";
53
+ import "../chunk-XFOTNHYA.mjs";
54
54
  import "../chunk-SKC7AJIV.mjs";
55
55
  export {
56
56
  runAgent,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { FunctionCallHandler, CoAgentStateRenderHandler } from '@copilotkit/shared';
3
3
  import { Message, TextMessage, ForwardedParametersInput, ExtensionsInput } from '@copilotkit/runtime-client-gql';
4
- import { c as CopilotApiConfig, A as AgentSession, L as LangGraphInterruptAction, d as LangGraphInterruptActionSetter } from '../copilot-context-f9b2b4c3.js';
4
+ import { c as CopilotApiConfig, A as AgentSession, L as LangGraphInterruptAction, d as LangGraphInterruptActionSetter } from '../copilot-context-3da805ab.js';
5
5
  import { FrontendAction } from '../types/frontend-action.js';
6
6
  import { CoagentState } from '../types/coagent-state.js';
7
7
  import './use-tree.js';
@@ -139,8 +139,35 @@ function shouldShowDevConsole(showDevConsole) {
139
139
  // src/hooks/use-copilot-runtime-client.ts
140
140
  var useCopilotRuntimeClient = (options) => {
141
141
  const { setBannerError } = useToast();
142
- const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
142
+ const _a = options, { showDevConsole, onTrace } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onTrace"]);
143
143
  const lastStructuredErrorRef = (0, import_react2.useRef)(null);
144
+ const traceUIError = (error, originalError) => __async(void 0, null, function* () {
145
+ if (!onTrace || !runtimeOptions.publicApiKey)
146
+ return;
147
+ try {
148
+ const traceEvent = {
149
+ type: "error",
150
+ timestamp: Date.now(),
151
+ context: {
152
+ source: "ui",
153
+ request: {
154
+ operation: "runtimeClient",
155
+ url: runtimeOptions.url,
156
+ startTime: Date.now()
157
+ },
158
+ technical: {
159
+ environment: "browser",
160
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
161
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
162
+ }
163
+ },
164
+ error
165
+ };
166
+ yield onTrace(traceEvent);
167
+ } catch (traceError) {
168
+ console.error("Error in onTrace handler:", traceError);
169
+ }
170
+ });
144
171
  const runtimeClient = (0, import_react2.useMemo)(() => {
145
172
  return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
146
173
  handleGQLErrors: (error) => {
@@ -168,12 +195,14 @@ var useCopilotRuntimeClient = (options) => {
168
195
  const ckError = createStructuredError(gqlError);
169
196
  if (ckError) {
170
197
  setBannerError(ckError);
198
+ traceUIError(ckError, gqlError);
171
199
  } else {
172
200
  const fallbackError = new import_shared3.CopilotKitError({
173
201
  message: gqlError.message,
174
202
  code: import_shared3.CopilotKitErrorCode.UNKNOWN
175
203
  });
176
204
  setBannerError(fallbackError);
205
+ traceUIError(fallbackError, gqlError);
177
206
  }
178
207
  };
179
208
  graphQLErrors.forEach(routeError);
@@ -187,6 +216,7 @@ var useCopilotRuntimeClient = (options) => {
187
216
  code: import_shared3.CopilotKitErrorCode.UNKNOWN
188
217
  });
189
218
  setBannerError(fallbackError);
219
+ traceUIError(fallbackError, error);
190
220
  }
191
221
  }
192
222
  },
@@ -199,7 +229,7 @@ var useCopilotRuntimeClient = (options) => {
199
229
  setBannerError(warningError);
200
230
  }
201
231
  }));
202
- }, [runtimeOptions, setBannerError, showDevConsole]);
232
+ }, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
203
233
  return runtimeClient;
204
234
  };
205
235
  function createStructuredError(gqlError) {
@@ -299,7 +329,8 @@ var emptyCopilotContext = {
299
329
  },
300
330
  langGraphInterruptAction: null,
301
331
  setLangGraphInterruptAction: () => null,
302
- removeLangGraphInterruptAction: () => null
332
+ removeLangGraphInterruptAction: () => null,
333
+ onTrace: void 0
303
334
  };
304
335
  var CopilotContext = import_react3.default.createContext(emptyCopilotContext);
305
336
  function useCopilotContext() {
@@ -458,6 +489,35 @@ function useChat(options) {
458
489
  } = options;
459
490
  const runChatCompletionRef = (0, import_react5.useRef)();
460
491
  const addErrorToast = useErrorToast();
492
+ const { setBannerError } = useToast();
493
+ const { onTrace } = useCopilotContext();
494
+ const traceUIError = (error, originalError) => __async(this, null, function* () {
495
+ if (!onTrace || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
496
+ return;
497
+ try {
498
+ const traceEvent = {
499
+ type: "error",
500
+ timestamp: Date.now(),
501
+ context: {
502
+ source: "ui",
503
+ request: {
504
+ operation: "useChatCompletion",
505
+ url: copilotConfig.chatApiEndpoint,
506
+ startTime: Date.now()
507
+ },
508
+ technical: {
509
+ environment: "browser",
510
+ userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
511
+ stackTrace: originalError instanceof Error ? originalError.stack : void 0
512
+ }
513
+ },
514
+ error
515
+ };
516
+ yield onTrace(traceEvent);
517
+ } catch (traceError) {
518
+ console.error("Error in use-chat onTrace handler:", traceError);
519
+ }
520
+ });
461
521
  const agentSessionRef = (0, import_react5.useRef)(agentSession);
462
522
  agentSessionRef.current = agentSession;
463
523
  const runIdRef = (0, import_react5.useRef)(runId);
@@ -477,7 +537,7 @@ function useChat(options) {
477
537
  const pendingAppendsRef = (0, import_react5.useRef)([]);
478
538
  const runChatCompletion = useAsyncCallback(
479
539
  (previousMessages) => __async(this, null, function* () {
480
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
540
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
481
541
  setIsLoading(true);
482
542
  const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
483
543
  if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql3.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
@@ -609,20 +669,53 @@ function useChat(options) {
609
669
  messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
610
670
  (0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
611
671
  );
612
- if (messages2.length === 0) {
613
- continue;
614
- }
615
672
  newMessages = [];
616
673
  if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
674
+ const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
617
675
  newMessages = [
618
676
  new import_runtime_client_gql3.TextMessage({
619
677
  role: import_runtime_client_gql3.MessageRole.Assistant,
620
- content: ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || ""
678
+ content: guardrailsReason
621
679
  })
622
680
  ];
681
+ const guardrailsError = new import_shared4.CopilotKitError({
682
+ message: `Guardrails validation failed: ${guardrailsReason}`,
683
+ code: import_shared4.CopilotKitErrorCode.MISUSE
684
+ });
685
+ yield traceUIError(guardrailsError, {
686
+ statusReason: value.generateCopilotResponse.status.reason,
687
+ statusDetails: value.generateCopilotResponse.status.details
688
+ });
623
689
  setMessages([...previousMessages, ...newMessages]);
624
690
  break;
625
- } else {
691
+ }
692
+ if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
693
+ const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
694
+ const statusDetails = value.generateCopilotResponse.status.details;
695
+ const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
696
+ const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
697
+ const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
698
+ const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
699
+ let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
700
+ if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
701
+ errorCode = originalCode;
702
+ }
703
+ const structuredError = new import_shared4.CopilotKitError({
704
+ message: errorMessage,
705
+ code: errorCode,
706
+ severity: originalSeverity,
707
+ visibility: originalVisibility
708
+ });
709
+ setBannerError(structuredError);
710
+ yield traceUIError(structuredError, {
711
+ statusReason: value.generateCopilotResponse.status.reason,
712
+ statusDetails: value.generateCopilotResponse.status.details,
713
+ originalErrorCode: originalCode,
714
+ preservedStructure: !!originalCode
715
+ });
716
+ setIsLoading(false);
717
+ break;
718
+ } else if (messages2.length > 0) {
626
719
  newMessages = [...messages2];
627
720
  for (const message of messages2) {
628
721
  if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
@@ -753,11 +846,11 @@ function useChat(options) {
753
846
  followUp !== false && // and we executed an action
754
847
  (didExecuteAction || // the last message is a server side result
755
848
  !isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
756
- !((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
849
+ !((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
757
850
  ) {
758
851
  yield new Promise((resolve) => setTimeout(resolve, 10));
759
852
  return yield runChatCompletionRef.current(finalMessages);
760
- } else if ((_n = chatAbortControllerRef.current) == null ? void 0 : _n.signal.aborted) {
853
+ } else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
761
854
  const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
762
855
  if (message.isActionExecutionMessage()) {
763
856
  return finalMessages.find(
@@ -768,7 +861,7 @@ function useChat(options) {
768
861
  });
769
862
  const repairedMessageIds = repairedMessages.map((message) => message.id);
770
863
  setMessages(repairedMessages);
771
- if ((_o = agentSessionRef.current) == null ? void 0 : _o.nodeName) {
864
+ if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
772
865
  setAgentSession({
773
866
  threadId: agentSessionRef.current.threadId,
774
867
  agentName: agentSessionRef.current.agentName,