@copilotkit/react-core 1.9.2-next.7 → 1.9.2-next.9
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 +16 -0
- package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
- package/dist/{chunk-T4ZKC4X4.mjs → chunk-3YHYWAHK.mjs} +2 -2
- package/dist/{chunk-ISYBUDL4.mjs → chunk-55QZ2SVJ.mjs} +4 -5
- 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-ZHEEHGLS.mjs → chunk-ADIITPD2.mjs} +8 -5
- package/dist/{chunk-ZHEEHGLS.mjs.map → chunk-ADIITPD2.mjs.map} +1 -1
- package/dist/{chunk-S4BOATBG.mjs → chunk-EF5BNM34.mjs} +2 -2
- package/dist/{chunk-I4JPQECN.mjs → chunk-EXU7GWLC.mjs} +4 -4
- package/dist/{chunk-7G6RR4HE.mjs → chunk-FXK6RQIN.mjs} +2 -2
- package/dist/{chunk-JXF732XG.mjs → chunk-G7LYGERN.mjs} +80 -13
- package/dist/chunk-G7LYGERN.mjs.map +1 -0
- package/dist/{chunk-VJCHRQ7Q.mjs → chunk-JDEWNLNP.mjs} +37 -4
- package/dist/chunk-JDEWNLNP.mjs.map +1 -0
- package/dist/{chunk-JHIZ5HAI.mjs → chunk-NQVCZQ5T.mjs} +3 -3
- package/dist/{chunk-VF6UPRKM.mjs → chunk-OF4SZTLL.mjs} +3 -3
- package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
- package/dist/{chunk-RN3ZRHI7.mjs → chunk-WOGURSAL.mjs} +5 -5
- package/dist/chunk-YAF2LATQ.mjs +310 -0
- package/dist/chunk-YAF2LATQ.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +35 -2
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit.js +289 -234
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +7 -7
- package/dist/components/copilot-provider/index.js +289 -234
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +7 -7
- 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.js +289 -234
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +7 -7
- 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/hooks/index.js +75 -10
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +14 -14
- package/dist/hooks/use-chat.js +72 -10
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -4
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.js +75 -10
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +10 -10
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +3 -3
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
- package/dist/hooks/use-copilot-chat.js +72 -10
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +9 -9
- package/dist/hooks/use-copilot-runtime-client.js +1 -1
- 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.js +72 -10
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +10 -10
- package/dist/index.js +363 -243
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -15
- package/dist/lib/copilot-task.mjs +8 -8
- package/dist/lib/index.mjs +8 -8
- package/dist/utils/extract.mjs +7 -7
- package/dist/utils/index.mjs +7 -7
- package/jest.config.js +7 -3
- package/package.json +4 -3
- package/src/components/copilot-provider/__tests__/copilotkit-trace.test.tsx +1 -0
- package/src/components/copilot-provider/copilot-messages.tsx +42 -3
- package/src/components/toast/toast-provider.tsx +49 -24
- package/src/components/usage-banner.tsx +144 -147
- package/src/hooks/use-chat.ts +106 -6
- package/src/hooks/use-coagent.ts +5 -0
- package/src/hooks/use-copilot-runtime-client.ts +2 -39
- package/tsconfig.json +1 -8
- package/dist/chunk-HD2GE3DK.mjs +0 -359
- package/dist/chunk-HD2GE3DK.mjs.map +0 -1
- package/dist/chunk-ISYBUDL4.mjs.map +0 -1
- package/dist/chunk-JXF732XG.mjs.map +0 -1
- package/dist/chunk-VJCHRQ7Q.mjs.map +0 -1
- package/dist/chunk-VRXANACV.mjs +0 -277
- package/dist/chunk-VRXANACV.mjs.map +0 -1
- /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
- /package/dist/{chunk-T4ZKC4X4.mjs.map → chunk-3YHYWAHK.mjs.map} +0 -0
- /package/dist/{chunk-S4BOATBG.mjs.map → chunk-EF5BNM34.mjs.map} +0 -0
- /package/dist/{chunk-I4JPQECN.mjs.map → chunk-EXU7GWLC.mjs.map} +0 -0
- /package/dist/{chunk-7G6RR4HE.mjs.map → chunk-FXK6RQIN.mjs.map} +0 -0
- /package/dist/{chunk-JHIZ5HAI.mjs.map → chunk-NQVCZQ5T.mjs.map} +0 -0
- /package/dist/{chunk-VF6UPRKM.mjs.map → chunk-OF4SZTLL.mjs.map} +0 -0
- /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-RN3ZRHI7.mjs.map → chunk-WOGURSAL.mjs.map} +0 -0
|
@@ -251,7 +251,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
251
251
|
startTime: Date.now()
|
|
252
252
|
},
|
|
253
253
|
technical: {
|
|
254
|
-
environment:
|
|
254
|
+
environment: "browser",
|
|
255
255
|
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
256
256
|
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
257
257
|
}
|
|
@@ -496,6 +496,35 @@ function useChat(options) {
|
|
|
496
496
|
} = options;
|
|
497
497
|
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
498
498
|
const addErrorToast = useErrorToast();
|
|
499
|
+
const { setBannerError } = useToast();
|
|
500
|
+
const { onTrace } = useCopilotContext();
|
|
501
|
+
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
502
|
+
if (!onTrace || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
503
|
+
return;
|
|
504
|
+
try {
|
|
505
|
+
const traceEvent = {
|
|
506
|
+
type: "error",
|
|
507
|
+
timestamp: Date.now(),
|
|
508
|
+
context: {
|
|
509
|
+
source: "ui",
|
|
510
|
+
request: {
|
|
511
|
+
operation: "useChatCompletion",
|
|
512
|
+
url: copilotConfig.chatApiEndpoint,
|
|
513
|
+
startTime: Date.now()
|
|
514
|
+
},
|
|
515
|
+
technical: {
|
|
516
|
+
environment: "browser",
|
|
517
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
518
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
519
|
+
}
|
|
520
|
+
},
|
|
521
|
+
error
|
|
522
|
+
};
|
|
523
|
+
yield onTrace(traceEvent);
|
|
524
|
+
} catch (traceError) {
|
|
525
|
+
console.error("Error in use-chat onTrace handler:", traceError);
|
|
526
|
+
}
|
|
527
|
+
});
|
|
499
528
|
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
500
529
|
agentSessionRef.current = agentSession;
|
|
501
530
|
const runIdRef = (0, import_react5.useRef)(runId);
|
|
@@ -515,7 +544,7 @@ function useChat(options) {
|
|
|
515
544
|
const pendingAppendsRef = (0, import_react5.useRef)([]);
|
|
516
545
|
const runChatCompletion = useAsyncCallback(
|
|
517
546
|
(previousMessages) => __async(this, null, function* () {
|
|
518
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
547
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
519
548
|
setIsLoading(true);
|
|
520
549
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
521
550
|
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) {
|
|
@@ -647,20 +676,53 @@ function useChat(options) {
|
|
|
647
676
|
messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
648
677
|
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
649
678
|
);
|
|
650
|
-
if (messages2.length === 0) {
|
|
651
|
-
continue;
|
|
652
|
-
}
|
|
653
679
|
newMessages = [];
|
|
654
680
|
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
681
|
+
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
655
682
|
newMessages = [
|
|
656
683
|
new import_runtime_client_gql3.TextMessage({
|
|
657
684
|
role: import_runtime_client_gql3.MessageRole.Assistant,
|
|
658
|
-
content:
|
|
685
|
+
content: guardrailsReason
|
|
659
686
|
})
|
|
660
687
|
];
|
|
688
|
+
const guardrailsError = new import_shared4.CopilotKitError({
|
|
689
|
+
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
690
|
+
code: import_shared4.CopilotKitErrorCode.MISUSE
|
|
691
|
+
});
|
|
692
|
+
yield traceUIError(guardrailsError, {
|
|
693
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
694
|
+
statusDetails: value.generateCopilotResponse.status.details
|
|
695
|
+
});
|
|
661
696
|
setMessages([...previousMessages, ...newMessages]);
|
|
662
697
|
break;
|
|
663
|
-
}
|
|
698
|
+
}
|
|
699
|
+
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
700
|
+
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
701
|
+
const statusDetails = value.generateCopilotResponse.status.details;
|
|
702
|
+
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
703
|
+
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
704
|
+
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
705
|
+
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
706
|
+
let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
|
|
707
|
+
if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
|
|
708
|
+
errorCode = originalCode;
|
|
709
|
+
}
|
|
710
|
+
const structuredError = new import_shared4.CopilotKitError({
|
|
711
|
+
message: errorMessage,
|
|
712
|
+
code: errorCode,
|
|
713
|
+
severity: originalSeverity,
|
|
714
|
+
visibility: originalVisibility
|
|
715
|
+
});
|
|
716
|
+
setBannerError(structuredError);
|
|
717
|
+
yield traceUIError(structuredError, {
|
|
718
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
719
|
+
statusDetails: value.generateCopilotResponse.status.details,
|
|
720
|
+
originalErrorCode: originalCode,
|
|
721
|
+
preservedStructure: !!originalCode
|
|
722
|
+
});
|
|
723
|
+
setIsLoading(false);
|
|
724
|
+
break;
|
|
725
|
+
} else if (messages2.length > 0) {
|
|
664
726
|
newMessages = [...messages2];
|
|
665
727
|
for (const message of messages2) {
|
|
666
728
|
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
@@ -791,11 +853,11 @@ function useChat(options) {
|
|
|
791
853
|
followUp !== false && // and we executed an action
|
|
792
854
|
(didExecuteAction || // the last message is a server side result
|
|
793
855
|
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
794
|
-
!((
|
|
856
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)
|
|
795
857
|
) {
|
|
796
858
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
797
859
|
return yield runChatCompletionRef.current(finalMessages);
|
|
798
|
-
} else if ((
|
|
860
|
+
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
799
861
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
800
862
|
if (message.isActionExecutionMessage()) {
|
|
801
863
|
return finalMessages.find(
|
|
@@ -806,7 +868,7 @@ function useChat(options) {
|
|
|
806
868
|
});
|
|
807
869
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
808
870
|
setMessages(repairedMessages);
|
|
809
|
-
if ((
|
|
871
|
+
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
810
872
|
setAgentSession({
|
|
811
873
|
threadId: agentSessionRef.current.threadId,
|
|
812
874
|
agentName: agentSessionRef.current.agentName,
|