@copilotkit/react-core 1.9.2-next.1 → 1.9.2-next.11
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.
- package/CHANGELOG.md +78 -0
- package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
- package/dist/{chunk-2FW7HH6W.mjs → chunk-3YHYWAHK.mjs} +3 -3
- package/dist/{chunk-RUY6MLHA.mjs → chunk-55QZ2SVJ.mjs} +36 -6
- package/dist/chunk-55QZ2SVJ.mjs.map +1 -0
- package/dist/chunk-57K2ZJ5F.mjs +348 -0
- package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
- package/dist/{chunk-UIT6QMUJ.mjs → chunk-7BYXCFPB.mjs} +5 -5
- package/dist/{chunk-HJP2RX5R.mjs → chunk-AFDL5JI3.mjs} +82 -15
- package/dist/chunk-AFDL5JI3.mjs.map +1 -0
- package/dist/{chunk-SGLWMQ2J.mjs → chunk-BEDNUHSA.mjs} +15 -12
- package/dist/chunk-BEDNUHSA.mjs.map +1 -0
- package/dist/{chunk-Q5D5XQFA.mjs → chunk-CMQV4XNY.mjs} +2 -2
- package/dist/{chunk-LDACFA2B.mjs → chunk-EF5BNM34.mjs} +3 -3
- package/dist/{chunk-UHQMV2CE.mjs → chunk-ERXWDCY6.mjs} +2 -2
- package/dist/{chunk-NNSXCFQO.mjs → chunk-JDEWNLNP.mjs} +41 -7
- package/dist/chunk-JDEWNLNP.mjs.map +1 -0
- package/dist/{chunk-C6F6EQNA.mjs → chunk-JPMIAGI6.mjs} +2 -2
- package/dist/{chunk-T42PN5VN.mjs → chunk-NQVCZQ5T.mjs} +4 -4
- package/dist/{chunk-YZDRMIOM.mjs → chunk-OIPDW3UR.mjs} +4 -4
- package/dist/{chunk-XY5BN4HZ.mjs → chunk-RYREGU4E.mjs} +11 -8
- package/dist/{chunk-XY5BN4HZ.mjs.map → chunk-RYREGU4E.mjs.map} +1 -1
- package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
- package/dist/{chunk-YDENFEKA.mjs → chunk-U4LIYN3I.mjs} +2 -2
- package/dist/{chunk-LZDDYZEY.mjs → chunk-UBNRUXEK.mjs} +2 -2
- package/dist/{chunk-6KGEF242.mjs → chunk-XFOTNHYA.mjs} +3 -2
- package/dist/chunk-XFOTNHYA.mjs.map +1 -0
- package/dist/chunk-YAF2LATQ.mjs +310 -0
- package/dist/chunk-YAF2LATQ.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +39 -4
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +3 -3
- package/dist/components/copilot-provider/copilotkit-props.d.ts +21 -2
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -1
- package/dist/components/copilot-provider/copilotkit.js +330 -240
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +10 -10
- package/dist/components/copilot-provider/index.d.ts +1 -1
- package/dist/components/copilot-provider/index.js +330 -240
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -10
- package/dist/components/error-boundary/error-boundary.js +135 -146
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -4
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -2
- package/dist/components/index.d.ts +1 -1
- package/dist/components/index.js +330 -240
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -10
- package/dist/components/toast/toast-provider.js +118 -85
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.js +135 -146
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +1 -1
- package/dist/context/copilot-context.d.ts +1 -1
- package/dist/context/copilot-context.js +2 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +2 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-f9b2b4c3.d.ts → copilot-context-3da805ab.d.ts} +5 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +108 -12
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +32 -32
- package/dist/hooks/use-chat.d.ts +1 -1
- package/dist/hooks/use-chat.js +105 -12
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +6 -6
- package/dist/hooks/use-coagent-state-render.js +2 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -3
- package/dist/hooks/use-coagent.d.ts +1 -1
- package/dist/hooks/use-coagent.js +108 -12
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +2 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -4
- package/dist/hooks/use-copilot-additional-instructions.js +2 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +2 -1
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
- package/dist/hooks/use-copilot-chat.d.ts +1 -1
- package/dist/hooks/use-copilot-chat.js +105 -12
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +13 -13
- package/dist/hooks/use-copilot-readable.js +2 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.d.ts +2 -0
- package/dist/hooks/use-copilot-runtime-client.js +52 -2
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +2 -1
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +1 -1
- package/dist/hooks/use-langgraph-interrupt.js +105 -12
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
- package/dist/hooks/use-make-copilot-document-readable.js +2 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +404 -249
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +33 -33
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +11 -11
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +11 -11
- package/dist/types/interrupt-action.d.ts +1 -1
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +10 -10
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -10
- package/jest.config.js +7 -3
- package/package.json +4 -3
- package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +75 -0
- package/src/components/copilot-provider/copilot-messages.tsx +46 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +21 -0
- package/src/components/copilot-provider/copilotkit.tsx +5 -1
- package/src/components/toast/toast-provider.tsx +49 -24
- package/src/components/usage-banner.tsx +144 -147
- package/src/context/copilot-context.tsx +7 -1
- package/src/hooks/use-chat.ts +106 -6
- package/src/hooks/use-coagent.ts +5 -0
- package/src/hooks/use-copilot-runtime-client.ts +41 -39
- package/tsconfig.json +1 -8
- package/tsup.config.ts +6 -6
- package/dist/chunk-6KGEF242.mjs.map +0 -1
- package/dist/chunk-HD2GE3DK.mjs +0 -359
- package/dist/chunk-HD2GE3DK.mjs.map +0 -1
- package/dist/chunk-HJP2RX5R.mjs.map +0 -1
- package/dist/chunk-NNSXCFQO.mjs.map +0 -1
- package/dist/chunk-RUY6MLHA.mjs.map +0 -1
- package/dist/chunk-SGLWMQ2J.mjs.map +0 -1
- package/dist/chunk-VRXANACV.mjs +0 -277
- package/dist/chunk-VRXANACV.mjs.map +0 -1
- package/dist/utils/utils.test.d.ts +0 -2
- package/dist/utils/utils.test.js +0 -9
- package/dist/utils/utils.test.js.map +0 -1
- package/dist/utils/utils.test.mjs +0 -7
- package/dist/utils/utils.test.mjs.map +0 -1
- /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
- /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
- /package/dist/{chunk-UIT6QMUJ.mjs.map → chunk-7BYXCFPB.mjs.map} +0 -0
- /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-CMQV4XNY.mjs.map} +0 -0
- /package/dist/{chunk-LDACFA2B.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
- /package/dist/{chunk-UHQMV2CE.mjs.map → chunk-ERXWDCY6.mjs.map} +0 -0
- /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-JPMIAGI6.mjs.map} +0 -0
- /package/dist/{chunk-T42PN5VN.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
- /package/dist/{chunk-YZDRMIOM.mjs.map → chunk-OIPDW3UR.mjs.map} +0 -0
- /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-YDENFEKA.mjs.map → chunk-U4LIYN3I.mjs.map} +0 -0
- /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-UBNRUXEK.mjs.map} +0 -0
package/src/hooks/use-chat.ts
CHANGED
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
CoAgentStateRenderHandler,
|
|
6
6
|
randomId,
|
|
7
7
|
parseJson,
|
|
8
|
+
CopilotKitError,
|
|
9
|
+
CopilotKitErrorCode,
|
|
8
10
|
} from "@copilotkit/shared";
|
|
9
11
|
import {
|
|
10
12
|
Message,
|
|
@@ -39,6 +41,7 @@ import { AgentSession } from "../context/copilot-context";
|
|
|
39
41
|
import { useCopilotRuntimeClient } from "./use-copilot-runtime-client";
|
|
40
42
|
import { useCopilotContext } from "../context/copilot-context";
|
|
41
43
|
import { useAsyncCallback, useErrorToast } from "../components/error-boundary/error-utils";
|
|
44
|
+
import { useToast } from "../components/toast/toast-provider";
|
|
42
45
|
import {
|
|
43
46
|
LangGraphInterruptAction,
|
|
44
47
|
LangGraphInterruptActionSetter,
|
|
@@ -218,6 +221,41 @@ export function useChat(options: UseChatOptions): UseChatHelpers {
|
|
|
218
221
|
} = options;
|
|
219
222
|
const runChatCompletionRef = useRef<(previousMessages: Message[]) => Promise<Message[]>>();
|
|
220
223
|
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
|
+
};
|
|
221
259
|
// We need to keep a ref of coagent states and session because of renderAndWait - making sure
|
|
222
260
|
// the latest state is sent to the API
|
|
223
261
|
// This is a workaround and needs to be addressed in the future
|
|
@@ -453,29 +491,91 @@ export function useChat(options: UseChatOptions): UseChatHelpers {
|
|
|
453
491
|
filterAdjacentAgentStateMessages(rawMessagesResponse),
|
|
454
492
|
);
|
|
455
493
|
|
|
456
|
-
if (messages.length === 0) {
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
494
|
newMessages = [];
|
|
461
495
|
|
|
496
|
+
// Handle error statuses BEFORE checking if there are messages
|
|
497
|
+
// (errors can come in chunks with no messages)
|
|
498
|
+
|
|
462
499
|
// request failed, display error message and quit
|
|
463
500
|
if (
|
|
464
501
|
value.generateCopilotResponse.status?.__typename === "FailedResponseStatus" &&
|
|
465
502
|
value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED"
|
|
466
503
|
) {
|
|
504
|
+
const guardrailsReason =
|
|
505
|
+
value.generateCopilotResponse.status.details?.guardrailsReason || "";
|
|
506
|
+
|
|
467
507
|
newMessages = [
|
|
468
508
|
new TextMessage({
|
|
469
509
|
role: MessageRole.Assistant,
|
|
470
|
-
content:
|
|
510
|
+
content: guardrailsReason,
|
|
471
511
|
}),
|
|
472
512
|
];
|
|
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
|
+
|
|
473
524
|
setMessages([...previousMessages, ...newMessages]);
|
|
474
525
|
break;
|
|
475
526
|
}
|
|
476
527
|
|
|
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
|
+
|
|
477
577
|
// add messages to the chat
|
|
478
|
-
else {
|
|
578
|
+
else if (messages.length > 0) {
|
|
479
579
|
newMessages = [...messages];
|
|
480
580
|
|
|
481
581
|
for (const message of messages) {
|
package/src/hooks/use-coagent.ts
CHANGED
|
@@ -278,6 +278,11 @@ 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
|
+
|
|
281
286
|
const newState = result.data?.loadAgentState?.state;
|
|
282
287
|
if (newState === lastLoadedState.current) return;
|
|
283
288
|
|
|
@@ -13,20 +13,53 @@ import {
|
|
|
13
13
|
CopilotKitError,
|
|
14
14
|
CopilotKitErrorCode,
|
|
15
15
|
ERROR_CONFIG,
|
|
16
|
+
CopilotTraceHandler,
|
|
17
|
+
CopilotTraceEvent,
|
|
16
18
|
} from "@copilotkit/shared";
|
|
17
19
|
import { shouldShowDevConsole } from "../utils/dev-console";
|
|
18
20
|
|
|
19
21
|
export interface CopilotRuntimeClientHookOptions extends CopilotRuntimeClientOptions {
|
|
20
22
|
showDevConsole?: boolean;
|
|
23
|
+
onTrace?: CopilotTraceHandler;
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions) => {
|
|
24
27
|
const { setBannerError } = useToast();
|
|
25
|
-
const { showDevConsole, ...runtimeOptions } = options;
|
|
28
|
+
const { showDevConsole, onTrace, ...runtimeOptions } = options;
|
|
26
29
|
|
|
27
30
|
// Deduplication state for structured errors
|
|
28
31
|
const lastStructuredErrorRef = useRef<{ message: string; timestamp: number } | null>(null);
|
|
29
32
|
|
|
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
|
+
|
|
30
63
|
const runtimeClient = useMemo(() => {
|
|
31
64
|
return new CopilotRuntimeClient({
|
|
32
65
|
...runtimeOptions,
|
|
@@ -46,7 +79,6 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
|
|
|
46
79
|
return;
|
|
47
80
|
}
|
|
48
81
|
|
|
49
|
-
// Respect showDevConsole setting for ALL errors
|
|
50
82
|
if (!isDev) {
|
|
51
83
|
console.error("CopilotKit Error (hidden in production):", gqlError.message);
|
|
52
84
|
return;
|
|
@@ -68,6 +100,8 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
|
|
|
68
100
|
const ckError = createStructuredError(gqlError);
|
|
69
101
|
if (ckError) {
|
|
70
102
|
setBannerError(ckError);
|
|
103
|
+
// Trace the error
|
|
104
|
+
traceUIError(ckError, gqlError);
|
|
71
105
|
} else {
|
|
72
106
|
// Fallback for unstructured errors
|
|
73
107
|
const fallbackError = new CopilotKitError({
|
|
@@ -75,6 +109,8 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
|
|
|
75
109
|
code: CopilotKitErrorCode.UNKNOWN,
|
|
76
110
|
});
|
|
77
111
|
setBannerError(fallbackError);
|
|
112
|
+
// Trace the fallback error
|
|
113
|
+
traceUIError(fallbackError, gqlError);
|
|
78
114
|
}
|
|
79
115
|
};
|
|
80
116
|
|
|
@@ -91,6 +127,8 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
|
|
|
91
127
|
code: CopilotKitErrorCode.UNKNOWN,
|
|
92
128
|
});
|
|
93
129
|
setBannerError(fallbackError);
|
|
130
|
+
// Trace the non-GraphQL error
|
|
131
|
+
traceUIError(fallbackError, error);
|
|
94
132
|
}
|
|
95
133
|
}
|
|
96
134
|
},
|
|
@@ -104,47 +142,11 @@ export const useCopilotRuntimeClient = (options: CopilotRuntimeClientHookOptions
|
|
|
104
142
|
setBannerError(warningError);
|
|
105
143
|
},
|
|
106
144
|
});
|
|
107
|
-
}, [runtimeOptions, setBannerError, showDevConsole]);
|
|
145
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onTrace]);
|
|
108
146
|
|
|
109
147
|
return runtimeClient;
|
|
110
148
|
};
|
|
111
149
|
|
|
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
|
-
|
|
148
150
|
// Create appropriate structured error from GraphQL error
|
|
149
151
|
function createStructuredError(gqlError: GraphQLError): CopilotKitError | null {
|
|
150
152
|
const extensions = gqlError.extensions;
|
package/tsconfig.json
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"extends": "../../utilities/tsconfig/react-library.json",
|
|
3
3
|
"include": ["."],
|
|
4
|
-
"exclude": [
|
|
5
|
-
"dist",
|
|
6
|
-
"build",
|
|
7
|
-
"node_modules",
|
|
8
|
-
"**/*.test.ts",
|
|
9
|
-
"**/*.test.tsx",
|
|
10
|
-
"**/__tests__/*"
|
|
11
|
-
]
|
|
4
|
+
"exclude": ["dist", "build", "node_modules", "**/*.test.ts", "**/*.test.tsx", "**/__tests__/*"]
|
|
12
5
|
}
|
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: [
|
|
4
|
+
entry: [
|
|
5
|
+
"src/**/*.{ts,tsx}",
|
|
6
|
+
"!src/**/*.test.{ts,tsx}",
|
|
7
|
+
"!src/**/__tests__/**/*",
|
|
8
|
+
"!src/**/*.spec.{ts,tsx}",
|
|
9
|
+
],
|
|
5
10
|
format: ["esm", "cjs"],
|
|
6
11
|
dts: true,
|
|
7
12
|
minify: false,
|
|
8
13
|
external: ["react"],
|
|
9
14
|
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/context/copilot-context.tsx"],"sourcesContent":["import { CopilotCloudConfig, FunctionCallHandler } from \"@copilotkit/shared\";\nimport {\n ActionRenderProps,\n CatchAllActionRenderProps,\n FrontendAction,\n} from \"../types/frontend-action\";\nimport React from \"react\";\nimport { TreeNodeId, Tree } from \"../hooks/use-tree\";\nimport { DocumentPointer } from \"../types\";\nimport { CopilotChatSuggestionConfiguration } from \"../types/chat-suggestion-configuration\";\nimport { CoAgentStateRender, CoAgentStateRenderProps } from \"../types/coagent-action\";\nimport { CoagentState } from \"../types/coagent-state\";\nimport {\n CopilotRuntimeClient,\n ExtensionsInput,\n ForwardedParametersInput,\n} from \"@copilotkit/runtime-client-gql\";\nimport { Agent } from \"@copilotkit/runtime-client-gql\";\nimport {\n LangGraphInterruptAction,\n LangGraphInterruptActionSetter,\n} from \"../types/interrupt-action\";\n\n/**\n * Interface for the configuration of the Copilot API.\n */\nexport interface CopilotApiConfig {\n /**\n * The public API key for Copilot Cloud.\n */\n publicApiKey?: string;\n\n /**\n * The configuration for Copilot Cloud.\n */\n cloud?: CopilotCloudConfig;\n\n /**\n * The endpoint for the chat API.\n */\n chatApiEndpoint: string;\n\n /**\n * The endpoint for the Copilot transcribe audio service.\n */\n transcribeAudioUrl?: string;\n\n /**\n * The endpoint for the Copilot text to speech service.\n */\n textToSpeechUrl?: string;\n\n /**\n * additional headers to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'Authorization': 'Bearer your_token_here'\n * }\n * ```\n */\n headers: Record<string, string>;\n\n /**\n * Custom properties to be sent with the request\n * @default {}\n * @example\n * ```\n * {\n * 'user_id': 'user_id'\n * }\n * ```\n */\n properties?: Record<string, any>;\n\n /**\n * Indicates whether the user agent should send or receive cookies from the other domain\n * in the case of cross-origin requests.\n */\n credentials?: RequestCredentials;\n\n /**\n * Optional configuration for connecting to Model Context Protocol (MCP) servers.\n * This is typically derived from the CopilotKitProps and used internally.\n * @experimental\n */\n mcpServers?: Array<{ endpoint: string; apiKey?: string }>;\n}\n\nexport type InChatRenderFunction<TProps = ActionRenderProps<any> | CatchAllActionRenderProps<any>> =\n (props: TProps) => string | JSX.Element;\nexport type CoagentInChatRenderFunction = (\n props: CoAgentStateRenderProps<any>,\n) => string | JSX.Element | undefined | null;\n\nexport interface ChatComponentsCache {\n actions: Record<string, InChatRenderFunction | string>;\n coAgentStateRenders: Record<string, CoagentInChatRenderFunction | string>;\n}\n\nexport interface AgentSession {\n agentName: string;\n threadId?: string;\n nodeName?: string;\n}\n\nexport interface AuthState {\n status: \"authenticated\" | \"unauthenticated\";\n authHeaders: Record<string, string>;\n userId?: string;\n metadata?: Record<string, any>;\n}\n\nexport type ActionName = string;\nexport type ContextTree = Tree;\n\nexport interface CopilotContextParams {\n // function-calling\n actions: Record<string, FrontendAction<any>>;\n setAction: (id: string, action: FrontendAction<any>) => void;\n removeAction: (id: string) => void;\n\n // coagent actions\n coAgentStateRenders: Record<string, CoAgentStateRender<any>>;\n setCoAgentStateRender: (id: string, stateRender: CoAgentStateRender<any>) => void;\n removeCoAgentStateRender: (id: string) => void;\n\n chatComponentsCache: React.RefObject<ChatComponentsCache>;\n\n getFunctionCallHandler: (\n customEntryPoints?: Record<string, FrontendAction<any>>,\n ) => FunctionCallHandler;\n\n // text context\n addContext: (context: string, parentId?: string, categories?: string[]) => TreeNodeId;\n removeContext: (id: TreeNodeId) => void;\n getAllContext: () => Tree;\n getContextString: (documents: DocumentPointer[], categories: string[]) => string;\n\n // document context\n addDocumentContext: (documentPointer: DocumentPointer, categories?: string[]) => TreeNodeId;\n removeDocumentContext: (documentId: string) => void;\n getDocumentsContext: (categories: string[]) => DocumentPointer[];\n\n isLoading: boolean;\n setIsLoading: React.Dispatch<React.SetStateAction<boolean>>;\n\n chatSuggestionConfiguration: { [key: string]: CopilotChatSuggestionConfiguration };\n addChatSuggestionConfiguration: (\n id: string,\n suggestion: CopilotChatSuggestionConfiguration,\n ) => void;\n removeChatSuggestionConfiguration: (id: string) => void;\n\n chatInstructions: string;\n setChatInstructions: React.Dispatch<React.SetStateAction<string>>;\n\n additionalInstructions?: string[];\n setAdditionalInstructions: React.Dispatch<React.SetStateAction<string[]>>;\n\n // api endpoints\n copilotApiConfig: CopilotApiConfig;\n\n showDevConsole: boolean;\n\n // agents\n coagentStates: Record<string, CoagentState>;\n setCoagentStates: React.Dispatch<React.SetStateAction<Record<string, CoagentState>>>;\n coagentStatesRef: React.RefObject<Record<string, CoagentState>>;\n setCoagentStatesWithRef: (\n value:\n | Record<string, CoagentState>\n | ((prev: Record<string, CoagentState>) => Record<string, CoagentState>),\n ) => void;\n\n agentSession: AgentSession | null;\n setAgentSession: React.Dispatch<React.SetStateAction<AgentSession | null>>;\n\n agentLock: string | null;\n\n threadId: string;\n setThreadId: React.Dispatch<React.SetStateAction<string>>;\n\n runId: string | null;\n setRunId: React.Dispatch<React.SetStateAction<string | null>>;\n\n // The chat abort controller can be used to stop generation globally,\n // i.e. when using `stop()` from `useChat`\n chatAbortControllerRef: React.MutableRefObject<AbortController | null>;\n\n // runtime\n runtimeClient: CopilotRuntimeClient;\n\n /**\n * The forwarded parameters to use for the task.\n */\n forwardedParameters?: Pick<ForwardedParametersInput, \"temperature\">;\n availableAgents: Agent[];\n\n /**\n * The auth states for the CopilotKit.\n */\n authStates_c?: Record<ActionName, AuthState>;\n setAuthStates_c?: React.Dispatch<React.SetStateAction<Record<ActionName, AuthState>>>;\n\n /**\n * The auth config for the CopilotKit.\n */\n authConfig_c?: {\n SignInComponent: React.ComponentType<{\n onSignInComplete: (authState: AuthState) => void;\n }>;\n };\n\n extensions: ExtensionsInput;\n setExtensions: React.Dispatch<React.SetStateAction<ExtensionsInput>>;\n langGraphInterruptAction: LangGraphInterruptAction | null;\n setLangGraphInterruptAction: LangGraphInterruptActionSetter;\n removeLangGraphInterruptAction: () => void;\n}\n\nconst emptyCopilotContext: CopilotContextParams = {\n actions: {},\n setAction: () => {},\n removeAction: () => {},\n\n coAgentStateRenders: {},\n setCoAgentStateRender: () => {},\n removeCoAgentStateRender: () => {},\n\n chatComponentsCache: { current: { actions: {}, coAgentStateRenders: {} } },\n getContextString: (documents: DocumentPointer[], categories: string[]) =>\n returnAndThrowInDebug(\"\"),\n addContext: () => \"\",\n removeContext: () => {},\n getAllContext: () => [],\n\n getFunctionCallHandler: () => returnAndThrowInDebug(async () => {}),\n\n isLoading: false,\n setIsLoading: () => returnAndThrowInDebug(false),\n\n chatInstructions: \"\",\n setChatInstructions: () => returnAndThrowInDebug(\"\"),\n\n additionalInstructions: [],\n setAdditionalInstructions: () => returnAndThrowInDebug([]),\n\n getDocumentsContext: (categories: string[]) => returnAndThrowInDebug([]),\n addDocumentContext: () => returnAndThrowInDebug(\"\"),\n removeDocumentContext: () => {},\n runtimeClient: {} as any,\n\n copilotApiConfig: new (class implements CopilotApiConfig {\n get chatApiEndpoint(): string {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n\n get headers(): Record<string, string> {\n return {};\n }\n get body(): Record<string, any> {\n return {};\n }\n })(),\n\n chatSuggestionConfiguration: {},\n addChatSuggestionConfiguration: () => {},\n removeChatSuggestionConfiguration: () => {},\n showDevConsole: false,\n coagentStates: {},\n setCoagentStates: () => {},\n coagentStatesRef: { current: {} },\n setCoagentStatesWithRef: () => {},\n agentSession: null,\n setAgentSession: () => {},\n forwardedParameters: {},\n agentLock: null,\n threadId: \"\",\n setThreadId: () => {},\n runId: null,\n setRunId: () => {},\n chatAbortControllerRef: { current: null },\n availableAgents: [],\n extensions: {},\n setExtensions: () => {},\n langGraphInterruptAction: null,\n setLangGraphInterruptAction: () => null,\n removeLangGraphInterruptAction: () => null,\n};\n\nexport const CopilotContext = React.createContext<CopilotContextParams>(emptyCopilotContext);\n\nexport function useCopilotContext(): CopilotContextParams {\n const context = React.useContext(CopilotContext);\n if (context === emptyCopilotContext) {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n }\n return context;\n}\n\nfunction returnAndThrowInDebug<T>(_value: T): T {\n throw new Error(\"Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!\");\n}\n"],"mappings":";;;;;AAMA,OAAO,WAAW;AAwNlB,IAAM,sBAA4C;AAAA,EAChD,SAAS,CAAC;AAAA,EACV,WAAW,MAAM;AAAA,EAAC;AAAA,EAClB,cAAc,MAAM;AAAA,EAAC;AAAA,EAErB,qBAAqB,CAAC;AAAA,EACtB,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,0BAA0B,MAAM;AAAA,EAAC;AAAA,EAEjC,qBAAqB,EAAE,SAAS,EAAE,SAAS,CAAC,GAAG,qBAAqB,CAAC,EAAE,EAAE;AAAA,EACzE,kBAAkB,CAAC,WAA8B,eAC/C,sBAAsB,EAAE;AAAA,EAC1B,YAAY,MAAM;AAAA,EAClB,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,eAAe,MAAM,CAAC;AAAA,EAEtB,wBAAwB,MAAM,sBAAsB,MAAY;AAAA,EAAC,EAAC;AAAA,EAElE,WAAW;AAAA,EACX,cAAc,MAAM,sBAAsB,KAAK;AAAA,EAE/C,kBAAkB;AAAA,EAClB,qBAAqB,MAAM,sBAAsB,EAAE;AAAA,EAEnD,wBAAwB,CAAC;AAAA,EACzB,2BAA2B,MAAM,sBAAsB,CAAC,CAAC;AAAA,EAEzD,qBAAqB,CAAC,eAAyB,sBAAsB,CAAC,CAAC;AAAA,EACvE,oBAAoB,MAAM,sBAAsB,EAAE;AAAA,EAClD,uBAAuB,MAAM;AAAA,EAAC;AAAA,EAC9B,eAAe,CAAC;AAAA,EAEhB,kBAAkB,IAAK,MAAkC;AAAA,IACvD,IAAI,kBAA0B;AAC5B,YAAM,IAAI,MAAM,uEAAuE;AAAA,IACzF;AAAA,IAEA,IAAI,UAAkC;AACpC,aAAO,CAAC;AAAA,IACV;AAAA,IACA,IAAI,OAA4B;AAC9B,aAAO,CAAC;AAAA,IACV;AAAA,EACF,EAAG;AAAA,EAEH,6BAA6B,CAAC;AAAA,EAC9B,gCAAgC,MAAM;AAAA,EAAC;AAAA,EACvC,mCAAmC,MAAM;AAAA,EAAC;AAAA,EAC1C,gBAAgB;AAAA,EAChB,eAAe,CAAC;AAAA,EAChB,kBAAkB,MAAM;AAAA,EAAC;AAAA,EACzB,kBAAkB,EAAE,SAAS,CAAC,EAAE;AAAA,EAChC,yBAAyB,MAAM;AAAA,EAAC;AAAA,EAChC,cAAc;AAAA,EACd,iBAAiB,MAAM;AAAA,EAAC;AAAA,EACxB,qBAAqB,CAAC;AAAA,EACtB,WAAW;AAAA,EACX,UAAU;AAAA,EACV,aAAa,MAAM;AAAA,EAAC;AAAA,EACpB,OAAO;AAAA,EACP,UAAU,MAAM;AAAA,EAAC;AAAA,EACjB,wBAAwB,EAAE,SAAS,KAAK;AAAA,EACxC,iBAAiB,CAAC;AAAA,EAClB,YAAY,CAAC;AAAA,EACb,eAAe,MAAM;AAAA,EAAC;AAAA,EACtB,0BAA0B;AAAA,EAC1B,6BAA6B,MAAM;AAAA,EACnC,gCAAgC,MAAM;AACxC;AAEO,IAAM,iBAAiB,MAAM,cAAoC,mBAAmB;AAEpF,SAAS,oBAA0C;AACxD,QAAM,UAAU,MAAM,WAAW,cAAc;AAC/C,MAAI,YAAY,qBAAqB;AACnC,UAAM,IAAI,MAAM,uEAAuE;AAAA,EACzF;AACA,SAAO;AACT;AAEA,SAAS,sBAAyB,QAAc;AAC9C,QAAM,IAAI,MAAM,uEAAuE;AACzF;","names":[]}
|