@copilotkit/react-core 1.9.2-next.2 → 1.9.2-next.20
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 +154 -0
- package/dist/{chunk-UHQMV2CE.mjs → chunk-36MGCCPZ.mjs} +2 -2
- package/dist/{chunk-CCESTGAM.mjs → chunk-3OQM3NEK.mjs} +2 -2
- package/dist/{chunk-FRZZPPIV.mjs → chunk-3SLA7Q2N.mjs} +2 -2
- package/dist/chunk-57K2ZJ5F.mjs +348 -0
- package/dist/chunk-57K2ZJ5F.mjs.map +1 -0
- package/dist/{chunk-LZDDYZEY.mjs → chunk-5BSUSFHM.mjs} +2 -2
- package/dist/{chunk-C6F6EQNA.mjs → chunk-BVK7PLK6.mjs} +2 -2
- package/dist/{chunk-6KGEF242.mjs → chunk-DKZTPL66.mjs} +3 -2
- package/dist/chunk-DKZTPL66.mjs.map +1 -0
- package/dist/{chunk-LDACFA2B.mjs → chunk-FN3UA2ZE.mjs} +3 -3
- package/dist/{chunk-RUY6MLHA.mjs → chunk-JWAXDYOW.mjs} +36 -6
- package/dist/chunk-JWAXDYOW.mjs.map +1 -0
- package/dist/{chunk-4I7PLQF7.mjs → chunk-K42OD3J6.mjs} +5 -5
- package/dist/{chunk-2FW7HH6W.mjs → chunk-KIXKBJUV.mjs} +3 -3
- package/dist/{chunk-L6QAOAE4.mjs → chunk-KWQPQ4MM.mjs} +69 -25
- package/dist/chunk-KWQPQ4MM.mjs.map +1 -0
- package/dist/{chunk-MGIXEJWG.mjs → chunk-MTAJI7HV.mjs} +181 -68
- package/dist/chunk-MTAJI7HV.mjs.map +1 -0
- package/dist/{chunk-T42PN5VN.mjs → chunk-NJA5ZLAZ.mjs} +29 -10
- package/dist/chunk-NJA5ZLAZ.mjs.map +1 -0
- package/dist/{chunk-NNSXCFQO.mjs → chunk-R2LNRHJP.mjs} +41 -7
- package/dist/chunk-R2LNRHJP.mjs.map +1 -0
- package/dist/{chunk-QQZLIEXK.mjs → chunk-SJJNFYGQ.mjs} +3 -3
- package/dist/{chunk-OUSWPVDT.mjs → chunk-UGJGKBFB.mjs} +4 -4
- package/dist/{chunk-Q5D5XQFA.mjs → chunk-VDADWRS3.mjs} +2 -2
- package/dist/chunk-YAF2LATQ.mjs +310 -0
- package/dist/chunk-YAF2LATQ.mjs.map +1 -0
- package/dist/{chunk-CMKIDDQL.mjs → chunk-ZOMEQ3XC.mjs} +11 -8
- package/dist/{chunk-CMKIDDQL.mjs.map → chunk-ZOMEQ3XC.mjs.map} +1 -1
- 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 +27 -3
- 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 +384 -253
- 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 +384 -253
- 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 +384 -253
- 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-3ab4fdf5.d.ts} +6 -2
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +232 -71
- 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 +295 -156
- 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 +207 -65
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +27 -7
- 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 +27 -7
- 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 +204 -65
- 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 +204 -65
- 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 +581 -320
- 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-error.test.tsx +75 -0
- package/src/components/copilot-provider/copilot-messages.tsx +46 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +27 -1
- package/src/components/copilot-provider/copilotkit.tsx +64 -18
- package/src/components/toast/toast-provider.tsx +49 -24
- package/src/components/usage-banner.tsx +144 -147
- package/src/context/copilot-context.tsx +8 -2
- package/src/hooks/use-chat.ts +247 -61
- package/src/hooks/use-coagent.ts +5 -0
- package/src/hooks/use-copilot-action.ts +51 -9
- package/src/hooks/use-copilot-runtime-client.ts +41 -40
- package/tsconfig.json +4 -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-L6QAOAE4.mjs.map +0 -1
- package/dist/chunk-MGIXEJWG.mjs.map +0 -1
- package/dist/chunk-NNSXCFQO.mjs.map +0 -1
- package/dist/chunk-RUY6MLHA.mjs.map +0 -1
- package/dist/chunk-T42PN5VN.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-UHQMV2CE.mjs.map → chunk-36MGCCPZ.mjs.map} +0 -0
- /package/dist/{chunk-CCESTGAM.mjs.map → chunk-3OQM3NEK.mjs.map} +0 -0
- /package/dist/{chunk-FRZZPPIV.mjs.map → chunk-3SLA7Q2N.mjs.map} +0 -0
- /package/dist/{chunk-LZDDYZEY.mjs.map → chunk-5BSUSFHM.mjs.map} +0 -0
- /package/dist/{chunk-C6F6EQNA.mjs.map → chunk-BVK7PLK6.mjs.map} +0 -0
- /package/dist/{chunk-LDACFA2B.mjs.map → chunk-FN3UA2ZE.mjs.map} +0 -0
- /package/dist/{chunk-4I7PLQF7.mjs.map → chunk-K42OD3J6.mjs.map} +0 -0
- /package/dist/{chunk-2FW7HH6W.mjs.map → chunk-KIXKBJUV.mjs.map} +0 -0
- /package/dist/{chunk-QQZLIEXK.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-OUSWPVDT.mjs.map → chunk-UGJGKBFB.mjs.map} +0 -0
- /package/dist/{chunk-Q5D5XQFA.mjs.map → chunk-VDADWRS3.mjs.map} +0 -0
|
@@ -158,7 +158,8 @@ var emptyCopilotContext = {
|
|
|
158
158
|
},
|
|
159
159
|
langGraphInterruptAction: null,
|
|
160
160
|
setLangGraphInterruptAction: () => null,
|
|
161
|
-
removeLangGraphInterruptAction: () => null
|
|
161
|
+
removeLangGraphInterruptAction: () => null,
|
|
162
|
+
onError: void 0
|
|
162
163
|
};
|
|
163
164
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
164
165
|
function useCopilotContext() {
|
|
@@ -177,6 +178,7 @@ var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
|
177
178
|
|
|
178
179
|
// src/hooks/use-chat.ts
|
|
179
180
|
var import_react5 = require("react");
|
|
181
|
+
var import_react_dom = require("react-dom");
|
|
180
182
|
var import_shared4 = require("@copilotkit/shared");
|
|
181
183
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
182
184
|
|
|
@@ -233,8 +235,35 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
233
235
|
// src/hooks/use-copilot-runtime-client.ts
|
|
234
236
|
var useCopilotRuntimeClient = (options) => {
|
|
235
237
|
const { setBannerError } = useToast();
|
|
236
|
-
const _a = options, { showDevConsole } = _a, runtimeOptions = __objRest(_a, ["showDevConsole"]);
|
|
238
|
+
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
237
239
|
const lastStructuredErrorRef = (0, import_react3.useRef)(null);
|
|
240
|
+
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
241
|
+
if (!onError || !runtimeOptions.publicApiKey)
|
|
242
|
+
return;
|
|
243
|
+
try {
|
|
244
|
+
const errorEvent = {
|
|
245
|
+
type: "error",
|
|
246
|
+
timestamp: Date.now(),
|
|
247
|
+
context: {
|
|
248
|
+
source: "ui",
|
|
249
|
+
request: {
|
|
250
|
+
operation: "runtimeClient",
|
|
251
|
+
url: runtimeOptions.url,
|
|
252
|
+
startTime: Date.now()
|
|
253
|
+
},
|
|
254
|
+
technical: {
|
|
255
|
+
environment: "browser",
|
|
256
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
257
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
error
|
|
261
|
+
};
|
|
262
|
+
yield onError(errorEvent);
|
|
263
|
+
} catch (error2) {
|
|
264
|
+
console.error("Error in onError handler:", error2);
|
|
265
|
+
}
|
|
266
|
+
});
|
|
238
267
|
const runtimeClient = (0, import_react3.useMemo)(() => {
|
|
239
268
|
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
240
269
|
handleGQLErrors: (error) => {
|
|
@@ -262,12 +291,14 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
262
291
|
const ckError = createStructuredError(gqlError);
|
|
263
292
|
if (ckError) {
|
|
264
293
|
setBannerError(ckError);
|
|
294
|
+
traceUIError(ckError, gqlError);
|
|
265
295
|
} else {
|
|
266
296
|
const fallbackError = new import_shared3.CopilotKitError({
|
|
267
297
|
message: gqlError.message,
|
|
268
298
|
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
269
299
|
});
|
|
270
300
|
setBannerError(fallbackError);
|
|
301
|
+
traceUIError(fallbackError, gqlError);
|
|
271
302
|
}
|
|
272
303
|
};
|
|
273
304
|
graphQLErrors.forEach(routeError);
|
|
@@ -281,6 +312,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
281
312
|
code: import_shared3.CopilotKitErrorCode.UNKNOWN
|
|
282
313
|
});
|
|
283
314
|
setBannerError(fallbackError);
|
|
315
|
+
traceUIError(fallbackError, error);
|
|
284
316
|
}
|
|
285
317
|
}
|
|
286
318
|
},
|
|
@@ -293,7 +325,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
293
325
|
setBannerError(warningError);
|
|
294
326
|
}
|
|
295
327
|
}));
|
|
296
|
-
}, [runtimeOptions, setBannerError, showDevConsole]);
|
|
328
|
+
}, [runtimeOptions, setBannerError, showDevConsole, onError]);
|
|
297
329
|
return runtimeClient;
|
|
298
330
|
};
|
|
299
331
|
function createStructuredError(gqlError) {
|
|
@@ -465,6 +497,35 @@ function useChat(options) {
|
|
|
465
497
|
} = options;
|
|
466
498
|
const runChatCompletionRef = (0, import_react5.useRef)();
|
|
467
499
|
const addErrorToast = useErrorToast();
|
|
500
|
+
const { setBannerError } = useToast();
|
|
501
|
+
const { onError } = useCopilotContext();
|
|
502
|
+
const traceUIError = (error, originalError) => __async(this, null, function* () {
|
|
503
|
+
if (!onError || !(copilotConfig == null ? void 0 : copilotConfig.publicApiKey))
|
|
504
|
+
return;
|
|
505
|
+
try {
|
|
506
|
+
const traceEvent = {
|
|
507
|
+
type: "error",
|
|
508
|
+
timestamp: Date.now(),
|
|
509
|
+
context: {
|
|
510
|
+
source: "ui",
|
|
511
|
+
request: {
|
|
512
|
+
operation: "useChatCompletion",
|
|
513
|
+
url: copilotConfig.chatApiEndpoint,
|
|
514
|
+
startTime: Date.now()
|
|
515
|
+
},
|
|
516
|
+
technical: {
|
|
517
|
+
environment: "browser",
|
|
518
|
+
userAgent: typeof navigator !== "undefined" ? navigator.userAgent : void 0,
|
|
519
|
+
stackTrace: originalError instanceof Error ? originalError.stack : void 0
|
|
520
|
+
}
|
|
521
|
+
},
|
|
522
|
+
error
|
|
523
|
+
};
|
|
524
|
+
yield onError(traceEvent);
|
|
525
|
+
} catch (traceError) {
|
|
526
|
+
console.error("Error in use-chat onError handler:", traceError);
|
|
527
|
+
}
|
|
528
|
+
});
|
|
468
529
|
const agentSessionRef = (0, import_react5.useRef)(agentSession);
|
|
469
530
|
agentSessionRef.current = agentSession;
|
|
470
531
|
const runIdRef = (0, import_react5.useRef)(runId);
|
|
@@ -484,7 +545,7 @@ function useChat(options) {
|
|
|
484
545
|
const pendingAppendsRef = (0, import_react5.useRef)([]);
|
|
485
546
|
const runChatCompletion = useAsyncCallback(
|
|
486
547
|
(previousMessages) => __async(this, null, function* () {
|
|
487
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
|
|
548
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
488
549
|
setIsLoading(true);
|
|
489
550
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
490
551
|
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) {
|
|
@@ -616,20 +677,53 @@ function useChat(options) {
|
|
|
616
677
|
messages2 = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
617
678
|
(0, import_runtime_client_gql3.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
618
679
|
);
|
|
619
|
-
if (messages2.length === 0) {
|
|
620
|
-
continue;
|
|
621
|
-
}
|
|
622
680
|
newMessages = [];
|
|
623
681
|
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
682
|
+
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
624
683
|
newMessages = [
|
|
625
684
|
new import_runtime_client_gql3.TextMessage({
|
|
626
685
|
role: import_runtime_client_gql3.MessageRole.Assistant,
|
|
627
|
-
content:
|
|
686
|
+
content: guardrailsReason
|
|
628
687
|
})
|
|
629
688
|
];
|
|
689
|
+
const guardrailsError = new import_shared4.CopilotKitError({
|
|
690
|
+
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
691
|
+
code: import_shared4.CopilotKitErrorCode.MISUSE
|
|
692
|
+
});
|
|
693
|
+
yield traceUIError(guardrailsError, {
|
|
694
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
695
|
+
statusDetails: value.generateCopilotResponse.status.details
|
|
696
|
+
});
|
|
630
697
|
setMessages([...previousMessages, ...newMessages]);
|
|
631
698
|
break;
|
|
632
|
-
}
|
|
699
|
+
}
|
|
700
|
+
if (((_m = value.generateCopilotResponse.status) == null ? void 0 : _m.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "UNKNOWN_ERROR") {
|
|
701
|
+
const errorMessage = ((_n = value.generateCopilotResponse.status.details) == null ? void 0 : _n.description) || "An unknown error occurred";
|
|
702
|
+
const statusDetails = value.generateCopilotResponse.status.details;
|
|
703
|
+
const originalError = (statusDetails == null ? void 0 : statusDetails.originalError) || (statusDetails == null ? void 0 : statusDetails.error);
|
|
704
|
+
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
705
|
+
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
706
|
+
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
707
|
+
let errorCode = import_shared4.CopilotKitErrorCode.NETWORK_ERROR;
|
|
708
|
+
if (originalCode && Object.values(import_shared4.CopilotKitErrorCode).includes(originalCode)) {
|
|
709
|
+
errorCode = originalCode;
|
|
710
|
+
}
|
|
711
|
+
const structuredError = new import_shared4.CopilotKitError({
|
|
712
|
+
message: errorMessage,
|
|
713
|
+
code: errorCode,
|
|
714
|
+
severity: originalSeverity,
|
|
715
|
+
visibility: originalVisibility
|
|
716
|
+
});
|
|
717
|
+
setBannerError(structuredError);
|
|
718
|
+
yield traceUIError(structuredError, {
|
|
719
|
+
statusReason: value.generateCopilotResponse.status.reason,
|
|
720
|
+
statusDetails: value.generateCopilotResponse.status.details,
|
|
721
|
+
originalErrorCode: originalCode,
|
|
722
|
+
preservedStructure: !!originalCode
|
|
723
|
+
});
|
|
724
|
+
setIsLoading(false);
|
|
725
|
+
break;
|
|
726
|
+
} else if (messages2.length > 0) {
|
|
633
727
|
newMessages = [...messages2];
|
|
634
728
|
for (const message of messages2) {
|
|
635
729
|
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
@@ -691,6 +785,39 @@ function useChat(options) {
|
|
|
691
785
|
newMessages
|
|
692
786
|
);
|
|
693
787
|
let didExecuteAction = false;
|
|
788
|
+
const executeActionFromMessage = (currentAction, actionMessage) => __async(this, null, function* () {
|
|
789
|
+
var _a2;
|
|
790
|
+
const isInterruptAction = interruptMessages.find((m) => m.id === actionMessage.id);
|
|
791
|
+
followUp = (_a2 = currentAction == null ? void 0 : currentAction.followUp) != null ? _a2 : !isInterruptAction;
|
|
792
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
793
|
+
currentAction._setActivatingMessageId(actionMessage.id);
|
|
794
|
+
}
|
|
795
|
+
const resultMessage = yield executeAction({
|
|
796
|
+
onFunctionCall,
|
|
797
|
+
message: actionMessage,
|
|
798
|
+
chatAbortControllerRef,
|
|
799
|
+
onError: (error) => {
|
|
800
|
+
addErrorToast([error]);
|
|
801
|
+
console.error(`Failed to execute action ${actionMessage.name}: ${error}`);
|
|
802
|
+
},
|
|
803
|
+
setMessages,
|
|
804
|
+
getFinalMessages: () => finalMessages,
|
|
805
|
+
isRenderAndWait: (currentAction == null ? void 0 : currentAction._isRenderAndWait) || false
|
|
806
|
+
});
|
|
807
|
+
didExecuteAction = true;
|
|
808
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === actionMessage.id);
|
|
809
|
+
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
810
|
+
if (currentAction == null ? void 0 : currentAction._isRenderAndWait) {
|
|
811
|
+
const messagesForImmediateUpdate = [...finalMessages];
|
|
812
|
+
(0, import_react_dom.flushSync)(() => {
|
|
813
|
+
setMessages(messagesForImmediateUpdate);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
if (currentAction == null ? void 0 : currentAction._setActivatingMessageId) {
|
|
817
|
+
currentAction._setActivatingMessageId(null);
|
|
818
|
+
}
|
|
819
|
+
return resultMessage;
|
|
820
|
+
});
|
|
694
821
|
if (onFunctionCall) {
|
|
695
822
|
const lastMessages = [];
|
|
696
823
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
@@ -707,37 +834,28 @@ function useChat(options) {
|
|
|
707
834
|
(action2) => action2.name === message.name
|
|
708
835
|
);
|
|
709
836
|
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
710
|
-
const executeActionFromMessage = (action2, message2) => __async(this, null, function* () {
|
|
711
|
-
var _a2;
|
|
712
|
-
const isInterruptAction = interruptMessages.find((m) => m.id === message2.id);
|
|
713
|
-
followUp = (_a2 = action2 == null ? void 0 : action2.followUp) != null ? _a2 : !isInterruptAction;
|
|
714
|
-
const resultMessage = yield executeAction({
|
|
715
|
-
onFunctionCall,
|
|
716
|
-
previousMessages,
|
|
717
|
-
message: message2,
|
|
718
|
-
chatAbortControllerRef,
|
|
719
|
-
onError: (error) => {
|
|
720
|
-
addErrorToast([error]);
|
|
721
|
-
console.error(`Failed to execute action ${message2.name}: ${error}`);
|
|
722
|
-
}
|
|
723
|
-
});
|
|
724
|
-
didExecuteAction = true;
|
|
725
|
-
const messageIndex = finalMessages.findIndex((msg) => msg.id === message2.id);
|
|
726
|
-
finalMessages.splice(messageIndex + 1, 0, resultMessage);
|
|
727
|
-
return resultMessage;
|
|
728
|
-
});
|
|
729
837
|
if (action && message.isActionExecutionMessage()) {
|
|
730
|
-
const
|
|
731
|
-
const
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
838
|
+
const isRenderAndWaitAction = (action == null ? void 0 : action._isRenderAndWait) || false;
|
|
839
|
+
const alreadyProcessed = isRenderAndWaitAction && finalMessages.some(
|
|
840
|
+
(fm) => fm.isResultMessage() && fm.actionExecutionId === message.id
|
|
841
|
+
);
|
|
842
|
+
if (alreadyProcessed) {
|
|
843
|
+
} else {
|
|
844
|
+
const resultMessage = yield executeActionFromMessage(
|
|
845
|
+
action,
|
|
846
|
+
message
|
|
847
|
+
);
|
|
848
|
+
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
849
|
+
if (pairedFeAction) {
|
|
850
|
+
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
851
|
+
name: pairedFeAction.name,
|
|
852
|
+
arguments: (0, import_shared4.parseJson)(resultMessage.result, resultMessage.result),
|
|
853
|
+
status: message.status,
|
|
854
|
+
createdAt: message.createdAt,
|
|
855
|
+
parentMessageId: message.parentMessageId
|
|
856
|
+
});
|
|
857
|
+
yield executeActionFromMessage(pairedFeAction, newExecutionMessage);
|
|
858
|
+
}
|
|
741
859
|
}
|
|
742
860
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
743
861
|
const newExecutionMessage = new import_runtime_client_gql3.ActionExecutionMessage({
|
|
@@ -755,16 +873,12 @@ function useChat(options) {
|
|
|
755
873
|
}
|
|
756
874
|
setMessages(finalMessages);
|
|
757
875
|
}
|
|
758
|
-
if (
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
(didExecuteAction || // the last message is a server side result
|
|
762
|
-
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
763
|
-
!((_m = chatAbortControllerRef.current) == null ? void 0 : _m.signal.aborted)
|
|
764
|
-
) {
|
|
876
|
+
if (followUp !== false && (didExecuteAction || // the last message is a server side result
|
|
877
|
+
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
878
|
+
!((_r = chatAbortControllerRef.current) == null ? void 0 : _r.signal.aborted)) {
|
|
765
879
|
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
766
880
|
return yield runChatCompletionRef.current(finalMessages);
|
|
767
|
-
} else if ((
|
|
881
|
+
} else if ((_s = chatAbortControllerRef.current) == null ? void 0 : _s.signal.aborted) {
|
|
768
882
|
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
769
883
|
if (message.isActionExecutionMessage()) {
|
|
770
884
|
return finalMessages.find(
|
|
@@ -775,7 +889,7 @@ function useChat(options) {
|
|
|
775
889
|
});
|
|
776
890
|
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
777
891
|
setMessages(repairedMessages);
|
|
778
|
-
if ((
|
|
892
|
+
if ((_t = agentSessionRef.current) == null ? void 0 : _t.nodeName) {
|
|
779
893
|
setAgentSession({
|
|
780
894
|
threadId: agentSessionRef.current.threadId,
|
|
781
895
|
agentName: agentSessionRef.current.agentName,
|
|
@@ -869,21 +983,35 @@ function useChat(options) {
|
|
|
869
983
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
870
984
|
);
|
|
871
985
|
const reload = useAsyncCallback(
|
|
872
|
-
(
|
|
986
|
+
(reloadMessageId) => __async(this, null, function* () {
|
|
873
987
|
if (isLoading || messages.length === 0) {
|
|
874
988
|
return;
|
|
875
989
|
}
|
|
876
|
-
const
|
|
877
|
-
if (
|
|
878
|
-
console.warn(`Message with id ${
|
|
990
|
+
const reloadMessageIndex = messages.findIndex((msg) => msg.id === reloadMessageId);
|
|
991
|
+
if (reloadMessageIndex === -1) {
|
|
992
|
+
console.warn(`Message with id ${reloadMessageId} not found`);
|
|
879
993
|
return;
|
|
880
994
|
}
|
|
881
|
-
|
|
882
|
-
if (
|
|
883
|
-
|
|
995
|
+
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
996
|
+
if (reloadMessageRole !== import_runtime_client_gql3.MessageRole.Assistant) {
|
|
997
|
+
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
998
|
+
return;
|
|
884
999
|
}
|
|
885
|
-
|
|
886
|
-
|
|
1000
|
+
let historyCutoff = [];
|
|
1001
|
+
if (messages.length > 2) {
|
|
1002
|
+
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
1003
|
+
(msg) => (
|
|
1004
|
+
// @ts-expect-error -- message has role
|
|
1005
|
+
msg.role === import_runtime_client_gql3.MessageRole.User
|
|
1006
|
+
)
|
|
1007
|
+
);
|
|
1008
|
+
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
1009
|
+
(msg) => msg.id === lastUserMessageBeforeRegenerate.id
|
|
1010
|
+
);
|
|
1011
|
+
historyCutoff = messages.slice(0, indexOfLastUserMessageBeforeRegenerate + 1);
|
|
1012
|
+
}
|
|
1013
|
+
setMessages(historyCutoff);
|
|
1014
|
+
return runChatCompletionAndHandleFunctionCall(historyCutoff);
|
|
887
1015
|
}),
|
|
888
1016
|
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
889
1017
|
);
|
|
@@ -918,20 +1046,31 @@ function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
|
918
1046
|
function executeAction(_0) {
|
|
919
1047
|
return __async(this, arguments, function* ({
|
|
920
1048
|
onFunctionCall,
|
|
921
|
-
previousMessages,
|
|
922
1049
|
message,
|
|
923
1050
|
chatAbortControllerRef,
|
|
924
|
-
onError
|
|
1051
|
+
onError,
|
|
1052
|
+
setMessages,
|
|
1053
|
+
getFinalMessages,
|
|
1054
|
+
isRenderAndWait
|
|
925
1055
|
}) {
|
|
926
1056
|
let result;
|
|
927
1057
|
let error = null;
|
|
1058
|
+
const currentMessagesForHandler = getFinalMessages();
|
|
1059
|
+
const handlerReturnedPromise = onFunctionCall({
|
|
1060
|
+
messages: currentMessagesForHandler,
|
|
1061
|
+
name: message.name,
|
|
1062
|
+
args: message.arguments
|
|
1063
|
+
});
|
|
1064
|
+
if (isRenderAndWait) {
|
|
1065
|
+
const currentMessagesForRender = getFinalMessages();
|
|
1066
|
+
(0, import_react_dom.flushSync)(() => {
|
|
1067
|
+
setMessages([...currentMessagesForRender]);
|
|
1068
|
+
});
|
|
1069
|
+
}
|
|
928
1070
|
try {
|
|
929
1071
|
result = yield Promise.race([
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
name: message.name,
|
|
933
|
-
args: message.arguments
|
|
934
|
-
}),
|
|
1072
|
+
handlerReturnedPromise,
|
|
1073
|
+
// Await the promise returned by the handler
|
|
935
1074
|
new Promise(
|
|
936
1075
|
(resolve) => {
|
|
937
1076
|
var _a;
|
|
@@ -979,7 +1118,7 @@ function getPairedFeAction(actions, message) {
|
|
|
979
1118
|
|
|
980
1119
|
// src/components/copilot-provider/copilotkit.tsx
|
|
981
1120
|
var import_react7 = require("react");
|
|
982
|
-
var
|
|
1121
|
+
var import_react_dom2 = require("react-dom");
|
|
983
1122
|
var import_shared5 = require("@copilotkit/shared");
|
|
984
1123
|
|
|
985
1124
|
// src/context/copilot-messages-context.tsx
|