@copilotkit/react-core 1.9.2-next.10 → 1.9.2-next.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 (168) hide show
  1. package/CHANGELOG.md +0 -64
  2. package/dist/{chunk-3YHYWAHK.mjs → chunk-2FW7HH6W.mjs} +3 -3
  3. package/dist/{chunk-EXU7GWLC.mjs → chunk-4I7PLQF7.mjs} +5 -5
  4. package/dist/{chunk-XFOTNHYA.mjs → chunk-6KGEF242.mjs} +2 -3
  5. package/dist/chunk-6KGEF242.mjs.map +1 -0
  6. package/dist/{chunk-JPMIAGI6.mjs → chunk-C6F6EQNA.mjs} +2 -2
  7. package/dist/{chunk-3OQM3NEK.mjs → chunk-CCESTGAM.mjs} +2 -2
  8. package/dist/{chunk-ADIITPD2.mjs → chunk-CMKIDDQL.mjs} +8 -11
  9. package/dist/{chunk-ADIITPD2.mjs.map → chunk-CMKIDDQL.mjs.map} +1 -1
  10. package/dist/{chunk-FXK6RQIN.mjs → chunk-FRZZPPIV.mjs} +2 -2
  11. package/dist/chunk-HD2GE3DK.mjs +359 -0
  12. package/dist/chunk-HD2GE3DK.mjs.map +1 -0
  13. package/dist/{chunk-WOGURSAL.mjs → chunk-L6QAOAE4.mjs} +12 -15
  14. package/dist/chunk-L6QAOAE4.mjs.map +1 -0
  15. package/dist/{chunk-EF5BNM34.mjs → chunk-LDACFA2B.mjs} +3 -3
  16. package/dist/{chunk-UBNRUXEK.mjs → chunk-LZDDYZEY.mjs} +2 -2
  17. package/dist/{chunk-G7LYGERN.mjs → chunk-MGIXEJWG.mjs} +16 -83
  18. package/dist/chunk-MGIXEJWG.mjs.map +1 -0
  19. package/dist/{chunk-JDEWNLNP.mjs → chunk-NNSXCFQO.mjs} +7 -41
  20. package/dist/chunk-NNSXCFQO.mjs.map +1 -0
  21. package/dist/{chunk-OF4SZTLL.mjs → chunk-OUSWPVDT.mjs} +4 -4
  22. package/dist/{chunk-CMQV4XNY.mjs → chunk-Q5D5XQFA.mjs} +2 -2
  23. package/dist/{chunk-SJJNFYGQ.mjs → chunk-QQZLIEXK.mjs} +3 -3
  24. package/dist/{chunk-55QZ2SVJ.mjs → chunk-RUY6MLHA.mjs} +6 -36
  25. package/dist/chunk-RUY6MLHA.mjs.map +1 -0
  26. package/dist/{chunk-NQVCZQ5T.mjs → chunk-T42PN5VN.mjs} +4 -4
  27. package/dist/{chunk-ERXWDCY6.mjs → chunk-UHQMV2CE.mjs} +2 -2
  28. package/dist/chunk-VRXANACV.mjs +277 -0
  29. package/dist/chunk-VRXANACV.mjs.map +1 -0
  30. package/dist/components/copilot-provider/copilot-messages.js +4 -39
  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 +2 -21
  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 +240 -330
  37. package/dist/components/copilot-provider/copilotkit.js.map +1 -1
  38. package/dist/components/copilot-provider/copilotkit.mjs +10 -10
  39. package/dist/components/copilot-provider/index.d.ts +1 -1
  40. package/dist/components/copilot-provider/index.js +240 -330
  41. package/dist/components/copilot-provider/index.js.map +1 -1
  42. package/dist/components/copilot-provider/index.mjs +10 -10
  43. package/dist/components/error-boundary/error-boundary.js +146 -135
  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 +240 -330
  50. package/dist/components/index.js.map +1 -1
  51. package/dist/components/index.mjs +10 -10
  52. package/dist/components/toast/toast-provider.js +85 -118
  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 +146 -135
  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 +1 -2
  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 +1 -2
  64. package/dist/context/index.js.map +1 -1
  65. package/dist/context/index.mjs +1 -1
  66. package/dist/{copilot-context-3da805ab.d.ts → copilot-context-f9b2b4c3.d.ts} +1 -5
  67. package/dist/hooks/index.d.ts +1 -1
  68. package/dist/hooks/index.js +12 -108
  69. package/dist/hooks/index.js.map +1 -1
  70. package/dist/hooks/index.mjs +32 -32
  71. package/dist/hooks/use-chat.d.ts +1 -1
  72. package/dist/hooks/use-chat.js +12 -105
  73. package/dist/hooks/use-chat.js.map +1 -1
  74. package/dist/hooks/use-chat.mjs +6 -6
  75. package/dist/hooks/use-coagent-state-render.js +1 -2
  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 +12 -108
  80. package/dist/hooks/use-coagent.js.map +1 -1
  81. package/dist/hooks/use-coagent.mjs +14 -14
  82. package/dist/hooks/use-copilot-action.js +1 -2
  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 +1 -2
  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 +1 -2
  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 +12 -105
  93. package/dist/hooks/use-copilot-chat.js.map +1 -1
  94. package/dist/hooks/use-copilot-chat.mjs +13 -13
  95. package/dist/hooks/use-copilot-readable.js +1 -2
  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 +0 -2
  99. package/dist/hooks/use-copilot-runtime-client.js +2 -52
  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 +1 -2
  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 +12 -105
  107. package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
  108. package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
  109. package/dist/hooks/use-make-copilot-document-readable.js +1 -2
  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 +249 -404
  114. package/dist/index.js.map +1 -1
  115. package/dist/index.mjs +33 -33
  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 +11 -11
  119. package/dist/lib/index.d.ts +1 -1
  120. package/dist/lib/index.js.map +1 -1
  121. package/dist/lib/index.mjs +11 -11
  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 +10 -10
  126. package/dist/utils/index.d.ts +1 -1
  127. package/dist/utils/index.js.map +1 -1
  128. package/dist/utils/index.mjs +10 -10
  129. package/dist/utils/utils.test.d.ts +2 -0
  130. package/dist/utils/utils.test.js +9 -0
  131. package/dist/utils/utils.test.js.map +1 -0
  132. package/dist/utils/utils.test.mjs +7 -0
  133. package/dist/utils/utils.test.mjs.map +1 -0
  134. package/jest.config.js +3 -7
  135. package/package.json +3 -4
  136. package/src/components/copilot-provider/copilot-messages.tsx +5 -46
  137. package/src/components/copilot-provider/copilotkit-props.tsx +0 -21
  138. package/src/components/copilot-provider/copilotkit.tsx +1 -5
  139. package/src/components/toast/toast-provider.tsx +24 -49
  140. package/src/components/usage-banner.tsx +147 -144
  141. package/src/context/copilot-context.tsx +1 -7
  142. package/src/hooks/use-chat.ts +6 -106
  143. package/src/hooks/use-coagent.ts +0 -5
  144. package/src/hooks/use-copilot-runtime-client.ts +39 -41
  145. package/tsconfig.json +8 -1
  146. package/tsup.config.ts +6 -6
  147. package/dist/chunk-55QZ2SVJ.mjs.map +0 -1
  148. package/dist/chunk-57K2ZJ5F.mjs +0 -348
  149. package/dist/chunk-57K2ZJ5F.mjs.map +0 -1
  150. package/dist/chunk-G7LYGERN.mjs.map +0 -1
  151. package/dist/chunk-JDEWNLNP.mjs.map +0 -1
  152. package/dist/chunk-WOGURSAL.mjs.map +0 -1
  153. package/dist/chunk-XFOTNHYA.mjs.map +0 -1
  154. package/dist/chunk-YAF2LATQ.mjs +0 -310
  155. package/dist/chunk-YAF2LATQ.mjs.map +0 -1
  156. package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +0 -75
  157. /package/dist/{chunk-3YHYWAHK.mjs.map → chunk-2FW7HH6W.mjs.map} +0 -0
  158. /package/dist/{chunk-EXU7GWLC.mjs.map → chunk-4I7PLQF7.mjs.map} +0 -0
  159. /package/dist/{chunk-JPMIAGI6.mjs.map → chunk-C6F6EQNA.mjs.map} +0 -0
  160. /package/dist/{chunk-3OQM3NEK.mjs.map → chunk-CCESTGAM.mjs.map} +0 -0
  161. /package/dist/{chunk-FXK6RQIN.mjs.map → chunk-FRZZPPIV.mjs.map} +0 -0
  162. /package/dist/{chunk-EF5BNM34.mjs.map → chunk-LDACFA2B.mjs.map} +0 -0
  163. /package/dist/{chunk-UBNRUXEK.mjs.map → chunk-LZDDYZEY.mjs.map} +0 -0
  164. /package/dist/{chunk-OF4SZTLL.mjs.map → chunk-OUSWPVDT.mjs.map} +0 -0
  165. /package/dist/{chunk-CMQV4XNY.mjs.map → chunk-Q5D5XQFA.mjs.map} +0 -0
  166. /package/dist/{chunk-SJJNFYGQ.mjs.map → chunk-QQZLIEXK.mjs.map} +0 -0
  167. /package/dist/{chunk-NQVCZQ5T.mjs.map → chunk-T42PN5VN.mjs.map} +0 -0
  168. /package/dist/{chunk-ERXWDCY6.mjs.map → chunk-UHQMV2CE.mjs.map} +0 -0
@@ -5,8 +5,6 @@ import {
5
5
  CoAgentStateRenderHandler,
6
6
  randomId,
7
7
  parseJson,
8
- CopilotKitError,
9
- CopilotKitErrorCode,
10
8
  } from "@copilotkit/shared";
11
9
  import {
12
10
  Message,
@@ -41,7 +39,6 @@ import { AgentSession } from "../context/copilot-context";
41
39
  import { useCopilotRuntimeClient } from "./use-copilot-runtime-client";
42
40
  import { useCopilotContext } from "../context/copilot-context";
43
41
  import { useAsyncCallback, useErrorToast } from "../components/error-boundary/error-utils";
44
- import { useToast } from "../components/toast/toast-provider";
45
42
  import {
46
43
  LangGraphInterruptAction,
47
44
  LangGraphInterruptActionSetter,
@@ -221,41 +218,6 @@ export function useChat(options: UseChatOptions): UseChatHelpers {
221
218
  } = options;
222
219
  const runChatCompletionRef = useRef<(previousMessages: Message[]) => Promise<Message[]>>();
223
220
  const addErrorToast = useErrorToast();
224
- const { setBannerError } = useToast();
225
-
226
- // Get onTrace from context since it's not part of copilotConfig
227
- const { onTrace } = useCopilotContext();
228
-
229
- // Add tracing functionality to use-chat
230
- const traceUIError = async (error: CopilotKitError, originalError?: any) => {
231
- // Just check if onTrace and publicApiKey are defined
232
- if (!onTrace || !copilotConfig?.publicApiKey) return;
233
-
234
- try {
235
- const traceEvent = {
236
- type: "error" as const,
237
- timestamp: Date.now(),
238
- context: {
239
- source: "ui" as const,
240
- request: {
241
- operation: "useChatCompletion",
242
- url: copilotConfig.chatApiEndpoint,
243
- startTime: Date.now(),
244
- },
245
- technical: {
246
- environment: "browser",
247
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : undefined,
248
- stackTrace: originalError instanceof Error ? originalError.stack : undefined,
249
- },
250
- },
251
- error,
252
- };
253
-
254
- await onTrace(traceEvent);
255
- } catch (traceError) {
256
- console.error("Error in use-chat onTrace handler:", traceError);
257
- }
258
- };
259
221
  // We need to keep a ref of coagent states and session because of renderAndWait - making sure
260
222
  // the latest state is sent to the API
261
223
  // This is a workaround and needs to be addressed in the future
@@ -491,91 +453,29 @@ export function useChat(options: UseChatOptions): UseChatHelpers {
491
453
  filterAdjacentAgentStateMessages(rawMessagesResponse),
492
454
  );
493
455
 
494
- newMessages = [];
456
+ if (messages.length === 0) {
457
+ continue;
458
+ }
495
459
 
496
- // Handle error statuses BEFORE checking if there are messages
497
- // (errors can come in chunks with no messages)
460
+ newMessages = [];
498
461
 
499
462
  // request failed, display error message and quit
500
463
  if (
501
464
  value.generateCopilotResponse.status?.__typename === "FailedResponseStatus" &&
502
465
  value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED"
503
466
  ) {
504
- const guardrailsReason =
505
- value.generateCopilotResponse.status.details?.guardrailsReason || "";
506
-
507
467
  newMessages = [
508
468
  new TextMessage({
509
469
  role: MessageRole.Assistant,
510
- content: guardrailsReason,
470
+ content: value.generateCopilotResponse.status.details?.guardrailsReason || "",
511
471
  }),
512
472
  ];
513
-
514
- // Trace guardrails validation failure
515
- const guardrailsError = new CopilotKitError({
516
- message: `Guardrails validation failed: ${guardrailsReason}`,
517
- code: CopilotKitErrorCode.MISUSE,
518
- });
519
- await traceUIError(guardrailsError, {
520
- statusReason: value.generateCopilotResponse.status.reason,
521
- statusDetails: value.generateCopilotResponse.status.details,
522
- });
523
-
524
473
  setMessages([...previousMessages, ...newMessages]);
525
474
  break;
526
475
  }
527
476
 
528
- // Handle UNKNOWN_ERROR failures (like authentication errors) by routing to banner error system
529
- if (
530
- value.generateCopilotResponse.status?.__typename === "FailedResponseStatus" &&
531
- value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR"
532
- ) {
533
- const errorMessage =
534
- value.generateCopilotResponse.status.details?.description ||
535
- "An unknown error occurred";
536
-
537
- // Try to extract original error information from the response details
538
- const statusDetails = value.generateCopilotResponse.status.details;
539
- const originalError = statusDetails?.originalError || statusDetails?.error;
540
-
541
- // Extract structured error information if available (prioritize top-level over extensions)
542
- const originalCode = originalError?.code || originalError?.extensions?.code;
543
- const originalSeverity = originalError?.severity || originalError?.extensions?.severity;
544
- const originalVisibility =
545
- originalError?.visibility || originalError?.extensions?.visibility;
546
-
547
- // Use the original error code if available, otherwise default to NETWORK_ERROR
548
- let errorCode = CopilotKitErrorCode.NETWORK_ERROR;
549
- if (originalCode && Object.values(CopilotKitErrorCode).includes(originalCode)) {
550
- errorCode = originalCode;
551
- }
552
-
553
- // Create a structured CopilotKitError preserving original error information
554
- const structuredError = new CopilotKitError({
555
- message: errorMessage,
556
- code: errorCode,
557
- severity: originalSeverity,
558
- visibility: originalVisibility,
559
- });
560
-
561
- // Display the error in the banner
562
- setBannerError(structuredError);
563
-
564
- // Trace the error for debugging/observability
565
- await traceUIError(structuredError, {
566
- statusReason: value.generateCopilotResponse.status.reason,
567
- statusDetails: value.generateCopilotResponse.status.details,
568
- originalErrorCode: originalCode,
569
- preservedStructure: !!originalCode,
570
- });
571
-
572
- // Stop processing and break from the loop
573
- setIsLoading(false);
574
- break;
575
- }
576
-
577
477
  // add messages to the chat
578
- else if (messages.length > 0) {
478
+ else {
579
479
  newMessages = [...messages];
580
480
 
581
481
  for (const message of messages) {
@@ -278,11 +278,6 @@ export function useCoAgent<T = any>(options: UseCoagentOptions<T>): UseCoagentRe
278
278
  agentName: name,
279
279
  });
280
280
 
281
- // Runtime client handles errors automatically via handleGQLErrors
282
- if (result.error) {
283
- return; // Don't process data on error
284
- }
285
-
286
281
  const newState = result.data?.loadAgentState?.state;
287
282
  if (newState === lastLoadedState.current) return;
288
283
 
@@ -13,53 +13,20 @@ import {
13
13
  CopilotKitError,
14
14
  CopilotKitErrorCode,
15
15
  ERROR_CONFIG,
16
- CopilotTraceHandler,
17
- CopilotTraceEvent,
18
16
  } from "@copilotkit/shared";
19
17
  import { shouldShowDevConsole } from "../utils/dev-console";
20
18
 
21
19
  export interface CopilotRuntimeClientHookOptions extends CopilotRuntimeClientOptions {
22
20
  showDevConsole?: boolean;
23
- onTrace?: CopilotTraceHandler;
24
21
  }
25
22
 
26
23
  export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions) => {
27
24
  const { setBannerError } = useToast();
28
- const { showDevConsole, onTrace, ...runtimeOptions } = options;
25
+ const { showDevConsole, ...runtimeOptions } = options;
29
26
 
30
27
  // Deduplication state for structured errors
31
28
  const lastStructuredErrorRef = useRef<{ message: string; timestamp: number } | null>(null);
32
29
 
33
- // Helper function to trace UI errors
34
- const traceUIError = async (error: CopilotKitError, originalError?: any) => {
35
- // Just check if onTrace and publicApiKey are defined
36
- if (!onTrace || !runtimeOptions.publicApiKey) return;
37
-
38
- try {
39
- const traceEvent: CopilotTraceEvent = {
40
- type: "error",
41
- timestamp: Date.now(),
42
- context: {
43
- source: "ui",
44
- request: {
45
- operation: "runtimeClient",
46
- url: runtimeOptions.url,
47
- startTime: Date.now(),
48
- },
49
- technical: {
50
- environment: "browser",
51
- userAgent: typeof navigator !== "undefined" ? navigator.userAgent : undefined,
52
- stackTrace: originalError instanceof Error ? originalError.stack : undefined,
53
- },
54
- },
55
- error,
56
- };
57
- await onTrace(traceEvent);
58
- } catch (traceError) {
59
- console.error("Error in onTrace handler:", traceError);
60
- }
61
- };
62
-
63
30
  const runtimeClient = useMemo(() => {
64
31
  return new CopilotRuntimeClient({
65
32
  ...runtimeOptions,
@@ -79,6 +46,7 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
79
46
  return;
80
47
  }
81
48
 
49
+ // Respect showDevConsole setting for ALL errors
82
50
  if (!isDev) {
83
51
  console.error("CopilotKit Error (hidden in production):", gqlError.message);
84
52
  return;
@@ -100,8 +68,6 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
100
68
  const ckError = createStructuredError(gqlError);
101
69
  if (ckError) {
102
70
  setBannerError(ckError);
103
- // Trace the error
104
- traceUIError(ckError, gqlError);
105
71
  } else {
106
72
  // Fallback for unstructured errors
107
73
  const fallbackError = new CopilotKitError({
@@ -109,8 +75,6 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
109
75
  code: CopilotKitErrorCode.UNKNOWN,
110
76
  });
111
77
  setBannerError(fallbackError);
112
- // Trace the fallback error
113
- traceUIError(fallbackError, gqlError);
114
78
  }
115
79
  };
116
80
 
@@ -127,8 +91,6 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
127
91
  code: CopilotKitErrorCode.UNKNOWN,
128
92
  });
129
93
  setBannerError(fallbackError);
130
- // Trace the non-GraphQL error
131
- traceUIError(fallbackError, error);
132
94
  }
133
95
  }
134
96
  },
@@ -142,11 +104,47 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
142
104
  setBannerError(warningError);
143
105
  },
144
106
  });
145
- }, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
107
+ }, [runtimeOptions, setBannerError, showDevConsole]);
146
108
 
147
109
  return runtimeClient;
148
110
  };
149
111
 
112
+ // Helper to determine if error should show as banner based on structured error system
113
+ function shouldShowAsBanner(gqlError: GraphQLError): boolean {
114
+ const extensions = gqlError.extensions;
115
+ if (!extensions) return false;
116
+
117
+ // Primary: Check error code and use structured config
118
+ const code = extensions.code as CopilotKitErrorCode;
119
+ if (code && ERROR_CONFIG[code]?.visibility === ErrorVisibility.BANNER) {
120
+ return true;
121
+ }
122
+
123
+ // Fallback: Check for API key errors which should always be banners
124
+ const errorMessage = gqlError.message.toLowerCase();
125
+ if (
126
+ errorMessage.includes("api key") ||
127
+ errorMessage.includes("401") ||
128
+ errorMessage.includes("unauthorized") ||
129
+ errorMessage.includes("authentication") ||
130
+ errorMessage.includes("incorrect api key")
131
+ ) {
132
+ return true;
133
+ }
134
+
135
+ // Legacy: Check by stack trace for discovery errors (for backward compatibility)
136
+ const originalError = extensions.originalError as any;
137
+ if (originalError?.stack) {
138
+ return (
139
+ originalError.stack.includes("CopilotApiDiscoveryError") ||
140
+ originalError.stack.includes("CopilotKitRemoteEndpointDiscoveryError") ||
141
+ originalError.stack.includes("CopilotKitAgentDiscoveryError")
142
+ );
143
+ }
144
+
145
+ return false;
146
+ }
147
+
150
148
  // Create appropriate structured error from GraphQL error
151
149
  function createStructuredError(gqlError: GraphQLError): CopilotKitError | null {
152
150
  const extensions = gqlError.extensions;
package/tsconfig.json CHANGED
@@ -1,5 +1,12 @@
1
1
  {
2
2
  "extends": "../../utilities/tsconfig/react-library.json",
3
3
  "include": ["."],
4
- "exclude": ["dist", "build", "node_modules", "**/*.test.ts", "**/*.test.tsx", "**/__tests__/*"]
4
+ "exclude": [
5
+ "dist",
6
+ "build",
7
+ "node_modules",
8
+ "**/*.test.ts",
9
+ "**/*.test.tsx",
10
+ "**/__tests__/*"
11
+ ]
5
12
  }
package/tsup.config.ts CHANGED
@@ -1,16 +1,16 @@
1
1
  import { defineConfig, Options } from "tsup";
2
2
 
3
3
  export default defineConfig((options: Options) => ({
4
- entry: [
5
- "src/**/*.{ts,tsx}",
6
- "!src/**/*.test.{ts,tsx}",
7
- "!src/**/__tests__/**/*",
8
- "!src/**/*.spec.{ts,tsx}",
9
- ],
4
+ entry: ["src/**/*.{ts,tsx}"],
10
5
  format: ["esm", "cjs"],
11
6
  dts: true,
12
7
  minify: false,
13
8
  external: ["react"],
14
9
  sourcemap: true,
10
+ exclude: [
11
+ "**/*.test.ts", // Exclude TypeScript test files
12
+ "**/*.test.tsx", // Exclude TypeScript React test files
13
+ "**/__tests__/*", // Exclude any files inside a __tests__ directory
14
+ ],
15
15
  ...options,
16
16
  }));
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/hooks/use-copilot-runtime-client.ts"],"sourcesContent":["import {\n CopilotRuntimeClient,\n CopilotRuntimeClientOptions,\n GraphQLError,\n} from \"@copilotkit/runtime-client-gql\";\nimport { useToast } from \"../components/toast/toast-provider\";\nimport { useMemo, useRef } from \"react\";\nimport {\n ErrorVisibility,\n CopilotKitApiDiscoveryError,\n CopilotKitRemoteEndpointDiscoveryError,\n CopilotKitAgentDiscoveryError,\n CopilotKitError,\n CopilotKitErrorCode,\n ERROR_CONFIG,\n CopilotTraceHandler,\n CopilotTraceEvent,\n} from \"@copilotkit/shared\";\nimport { shouldShowDevConsole } from \"../utils/dev-console\";\n\nexport interface CopilotRuntimeClientHookOptions extends CopilotRuntimeClientOptions {\n showDevConsole?: boolean;\n onTrace?: CopilotTraceHandler;\n}\n\nexport const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions) => {\n const { setBannerError } = useToast();\n const { showDevConsole, onTrace, ...runtimeOptions } = options;\n\n // Deduplication state for structured errors\n const lastStructuredErrorRef = useRef<{ message: string; timestamp: number } | null>(null);\n\n // Helper function to trace UI errors\n const traceUIError = async (error: CopilotKitError, originalError?: any) => {\n // Just check if onTrace and publicApiKey are defined\n if (!onTrace || !runtimeOptions.publicApiKey) return;\n\n try {\n const traceEvent: CopilotTraceEvent = {\n type: \"error\",\n timestamp: Date.now(),\n context: {\n source: \"ui\",\n request: {\n operation: \"runtimeClient\",\n url: runtimeOptions.url,\n startTime: Date.now(),\n },\n technical: {\n environment: \"browser\",\n userAgent: typeof navigator !== \"undefined\" ? navigator.userAgent : undefined,\n stackTrace: originalError instanceof Error ? originalError.stack : undefined,\n },\n },\n error,\n };\n await onTrace(traceEvent);\n } catch (traceError) {\n console.error(\"Error in onTrace handler:\", traceError);\n }\n };\n\n const runtimeClient = useMemo(() => {\n return new CopilotRuntimeClient({\n ...runtimeOptions,\n handleGQLErrors: (error) => {\n if ((error as any).graphQLErrors?.length) {\n const graphQLErrors = (error as any).graphQLErrors as GraphQLError[];\n\n // Route all errors to banners for consistent UI\n const routeError = (gqlError: GraphQLError) => {\n const extensions = gqlError.extensions;\n const visibility = extensions?.visibility as ErrorVisibility;\n const isDev = shouldShowDevConsole(showDevConsole ?? false);\n\n // Silent errors - just log\n if (visibility === ErrorVisibility.SILENT) {\n console.error(\"CopilotKit Silent Error:\", gqlError.message);\n return;\n }\n\n if (!isDev) {\n console.error(\"CopilotKit Error (hidden in production):\", gqlError.message);\n return;\n }\n\n // All errors (including DEV_ONLY) show as banners for consistency\n // Deduplicate to prevent spam\n const now = Date.now();\n const errorMessage = gqlError.message;\n if (\n lastStructuredErrorRef.current &&\n lastStructuredErrorRef.current.message === errorMessage &&\n now - lastStructuredErrorRef.current.timestamp < 150\n ) {\n return; // Skip duplicate\n }\n lastStructuredErrorRef.current = { message: errorMessage, timestamp: now };\n\n const ckError = createStructuredError(gqlError);\n if (ckError) {\n setBannerError(ckError);\n // Trace the error\n traceUIError(ckError, gqlError);\n } else {\n // Fallback for unstructured errors\n const fallbackError = new CopilotKitError({\n message: gqlError.message,\n code: CopilotKitErrorCode.UNKNOWN,\n });\n setBannerError(fallbackError);\n // Trace the fallback error\n traceUIError(fallbackError, gqlError);\n }\n };\n\n // Process all errors as banners\n graphQLErrors.forEach(routeError);\n } else {\n const isDev = shouldShowDevConsole(showDevConsole ?? false);\n if (!isDev) {\n console.error(\"CopilotKit Error (hidden in production):\", error);\n } else {\n // Route non-GraphQL errors to banner as well\n const fallbackError = new CopilotKitError({\n message: error?.message || String(error),\n code: CopilotKitErrorCode.UNKNOWN,\n });\n setBannerError(fallbackError);\n // Trace the non-GraphQL error\n traceUIError(fallbackError, error);\n }\n }\n },\n handleGQLWarning: (message: string) => {\n console.warn(message);\n // Show warnings as banners too for consistency\n const warningError = new CopilotKitError({\n message,\n code: CopilotKitErrorCode.UNKNOWN,\n });\n setBannerError(warningError);\n },\n });\n }, [runtimeOptions, setBannerError, showDevConsole, onTrace]);\n\n return runtimeClient;\n};\n\n// Create appropriate structured error from GraphQL error\nfunction createStructuredError(gqlError: GraphQLError): CopilotKitError | null {\n const extensions = gqlError.extensions;\n const originalError = extensions?.originalError as any;\n const message = originalError?.message || gqlError.message;\n const code = extensions?.code as CopilotKitErrorCode;\n\n if (code) {\n return new CopilotKitError({ message, code });\n }\n\n // Legacy error detection by stack trace\n if (originalError?.stack?.includes(\"CopilotApiDiscoveryError\")) {\n return new CopilotKitApiDiscoveryError({ message });\n }\n if (originalError?.stack?.includes(\"CopilotKitRemoteEndpointDiscoveryError\")) {\n return new CopilotKitRemoteEndpointDiscoveryError({ message });\n }\n if (originalError?.stack?.includes(\"CopilotKitAgentDiscoveryError\")) {\n return new CopilotKitAgentDiscoveryError({\n agentName: \"\",\n availableAgents: [],\n });\n }\n\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,OAGK;AAEP,SAAS,SAAS,cAAc;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAQA,IAAM,0BAA0B,CAAC,YAA6C;AACnF,QAAM,EAAE,eAAe,IAAI,SAAS;AACpC,QAAuD,cAA/C,kBAAgB,QA3B1B,IA2ByD,IAAnB,2BAAmB,IAAnB,CAA5B,kBAAgB;AAGxB,QAAM,yBAAyB,OAAsD,IAAI;AAGzF,QAAM,eAAe,CAAO,OAAwB,kBAAwB;AAE1E,QAAI,CAAC,WAAW,CAAC,eAAe;AAAc;AAE9C,QAAI;AACF,YAAM,aAAgC;AAAA,QACpC,MAAM;AAAA,QACN,WAAW,KAAK,IAAI;AAAA,QACpB,SAAS;AAAA,UACP,QAAQ;AAAA,UACR,SAAS;AAAA,YACP,WAAW;AAAA,YACX,KAAK,eAAe;AAAA,YACpB,W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