@copilotkit/react-core 1.5.0-tyler-reset-chat.0 → 1.5.0
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 +158 -4
- package/README.md +2 -0
- package/dist/{chunk-3AYELZJS.mjs → chunk-35EN6BG4.mjs} +2 -2
- package/dist/{chunk-3AYELZJS.mjs.map → chunk-35EN6BG4.mjs.map} +1 -1
- package/dist/{chunk-SEPYQHH7.mjs → chunk-42N5VKIX.mjs} +34 -28
- package/dist/chunk-42N5VKIX.mjs.map +1 -0
- package/dist/{chunk-USL3EHJB.mjs → chunk-5FYKUKG3.mjs} +2 -2
- package/dist/{chunk-ODN4H66E.mjs → chunk-7LRDVJH5.mjs} +6 -2
- package/dist/chunk-7LRDVJH5.mjs.map +1 -0
- package/dist/{chunk-CZMEZR6F.mjs → chunk-BT6WK2JZ.mjs} +34 -19
- package/dist/chunk-BT6WK2JZ.mjs.map +1 -0
- package/dist/{chunk-3R4J2TPH.mjs → chunk-EUU6NNYU.mjs} +29 -13
- package/dist/chunk-EUU6NNYU.mjs.map +1 -0
- package/dist/chunk-QCUP6HLK.mjs +37 -0
- package/dist/chunk-QCUP6HLK.mjs.map +1 -0
- package/dist/chunk-QTDCEDOC.mjs +392 -0
- package/dist/chunk-QTDCEDOC.mjs.map +1 -0
- package/dist/{chunk-JR55I3FL.mjs → chunk-QX6V774L.mjs} +6 -8
- package/dist/chunk-QX6V774L.mjs.map +1 -0
- package/dist/{chunk-2KCEHGSI.mjs → chunk-SFPANIOY.mjs} +99 -49
- package/dist/chunk-SFPANIOY.mjs.map +1 -0
- package/dist/{chunk-2JP64U3A.mjs → chunk-TQN3EZWQ.mjs} +4 -1
- package/dist/chunk-TQN3EZWQ.mjs.map +1 -0
- package/dist/{chunk-XUPO37VH.mjs → chunk-V3PFWGIY.mjs} +2 -2
- package/dist/{chunk-6QKA3SNN.mjs → chunk-VMP6JWBB.mjs} +21 -5
- package/dist/chunk-VMP6JWBB.mjs.map +1 -0
- package/dist/chunk-XERJQUHA.mjs +31 -0
- package/dist/chunk-XERJQUHA.mjs.map +1 -0
- package/dist/components/copilot-provider/copilotkit.js +173 -92
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +5 -4
- package/dist/components/copilot-provider/index.js +173 -92
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +5 -4
- package/dist/components/error-boundary/error-boundary.d.ts +22 -0
- package/dist/components/error-boundary/error-boundary.js +183 -0
- package/dist/components/error-boundary/error-boundary.js.map +1 -0
- package/dist/components/error-boundary/error-boundary.mjs +12 -0
- package/dist/components/error-boundary/error-boundary.mjs.map +1 -0
- package/dist/components/error-boundary/error-utils.d.ts +11 -0
- package/dist/components/error-boundary/error-utils.js +177 -0
- package/dist/components/error-boundary/error-utils.js.map +1 -0
- package/dist/components/error-boundary/error-utils.mjs +13 -0
- package/dist/components/error-boundary/error-utils.mjs.map +1 -0
- package/dist/components/index.js +173 -92
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +5 -4
- package/dist/components/toast/toast-provider.d.ts +2 -1
- package/dist/components/toast/toast-provider.js +76 -62
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/context/copilot-context.d.ts +4 -2
- package/dist/context/copilot-context.js +3 -0
- 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 +3 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.js +554 -308
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +13 -11
- package/dist/hooks/use-chat.d.ts +6 -2
- package/dist/hooks/use-chat.js +434 -219
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -3
- package/dist/hooks/use-coagent-state-render.d.ts +2 -2
- package/dist/hooks/use-coagent-state-render.js +3 -0
- 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.d.ts +1 -1
- package/dist/hooks/use-coagent.js +510 -277
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +9 -7
- package/dist/hooks/use-copilot-action.d.ts +12 -2
- package/dist/hooks/use-copilot-action.js +157 -16
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -2
- package/dist/hooks/use-copilot-chat.d.ts +1 -0
- package/dist/hooks/use-copilot-chat.js +483 -253
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +8 -6
- package/dist/hooks/use-copilot-readable.js +3 -0
- 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.js +110 -4
- 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-make-copilot-document-readable.js +3 -0
- 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 +616 -401
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -12
- package/dist/lib/copilot-task.d.ts +1 -1
- package/dist/lib/copilot-task.js +33 -13
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +7 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +33 -13
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -5
- package/dist/types/frontend-action.d.ts +21 -2
- package/dist/types/frontend-action.js +34 -0
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +7 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.js.map +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +5 -4
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +5 -4
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +22 -1
- package/src/components/error-boundary/error-boundary.tsx +42 -0
- package/src/components/error-boundary/error-utils.tsx +95 -0
- package/src/components/toast/toast-provider.tsx +10 -49
- package/src/context/copilot-context.tsx +17 -2
- package/src/hooks/use-chat.ts +375 -279
- package/src/hooks/use-coagent-state-render.ts +2 -2
- package/src/hooks/use-coagent.ts +34 -28
- package/src/hooks/use-copilot-action.ts +50 -15
- package/src/hooks/use-copilot-chat.ts +28 -14
- package/src/hooks/use-copilot-runtime-client.ts +4 -0
- package/src/lib/copilot-task.ts +2 -8
- package/src/types/frontend-action.ts +55 -2
- package/src/types/index.ts +5 -1
- package/dist/chunk-2JP64U3A.mjs.map +0 -1
- package/dist/chunk-2KCEHGSI.mjs.map +0 -1
- package/dist/chunk-3R4J2TPH.mjs.map +0 -1
- package/dist/chunk-6EN7J4V2.mjs +0 -317
- package/dist/chunk-6EN7J4V2.mjs.map +0 -1
- package/dist/chunk-6QKA3SNN.mjs.map +0 -1
- package/dist/chunk-CZMEZR6F.mjs.map +0 -1
- package/dist/chunk-JR55I3FL.mjs.map +0 -1
- package/dist/chunk-ODN4H66E.mjs.map +0 -1
- package/dist/chunk-SEPYQHH7.mjs.map +0 -1
- /package/dist/{chunk-USL3EHJB.mjs.map → chunk-5FYKUKG3.mjs.map} +0 -0
- /package/dist/{chunk-XUPO37VH.mjs.map → chunk-V3PFWGIY.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -104,7 +104,7 @@ __export(src_exports, {
|
|
|
104
104
|
module.exports = __toCommonJS(src_exports);
|
|
105
105
|
|
|
106
106
|
// src/components/copilot-provider/copilotkit.tsx
|
|
107
|
-
var
|
|
107
|
+
var import_react10 = require("react");
|
|
108
108
|
|
|
109
109
|
// src/context/copilot-context.tsx
|
|
110
110
|
var import_react = __toESM(require("react"));
|
|
@@ -155,6 +155,9 @@ var emptyCopilotContext = {
|
|
|
155
155
|
coagentStates: {},
|
|
156
156
|
setCoagentStates: () => {
|
|
157
157
|
},
|
|
158
|
+
coagentStatesRef: { current: {} },
|
|
159
|
+
setCoagentStatesWithRef: () => {
|
|
160
|
+
},
|
|
158
161
|
agentSession: null,
|
|
159
162
|
setAgentSession: () => {
|
|
160
163
|
},
|
|
@@ -419,6 +422,9 @@ function CopilotMessages(_a) {
|
|
|
419
422
|
}
|
|
420
423
|
|
|
421
424
|
// src/components/toast/toast-provider.tsx
|
|
425
|
+
var import_react7 = require("react");
|
|
426
|
+
|
|
427
|
+
// src/components/error-boundary/error-utils.tsx
|
|
422
428
|
var import_react6 = require("react");
|
|
423
429
|
|
|
424
430
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
@@ -448,11 +454,94 @@ var ExclamationMarkIcon = ({
|
|
|
448
454
|
}
|
|
449
455
|
);
|
|
450
456
|
|
|
451
|
-
// src/components/
|
|
457
|
+
// src/components/error-boundary/error-utils.tsx
|
|
452
458
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
453
|
-
|
|
459
|
+
function ErrorToast({ errors }) {
|
|
460
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
461
|
+
var _a, _b, _c;
|
|
462
|
+
const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
|
|
463
|
+
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
464
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
465
|
+
"div",
|
|
466
|
+
{
|
|
467
|
+
style: {
|
|
468
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
469
|
+
marginBottom: 14
|
|
470
|
+
},
|
|
471
|
+
children: [
|
|
472
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
473
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
474
|
+
"div",
|
|
475
|
+
{
|
|
476
|
+
style: {
|
|
477
|
+
fontWeight: "600",
|
|
478
|
+
marginBottom: 4
|
|
479
|
+
},
|
|
480
|
+
children: [
|
|
481
|
+
"Copilot Cloud Error:",
|
|
482
|
+
" ",
|
|
483
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
484
|
+
]
|
|
485
|
+
}
|
|
486
|
+
),
|
|
487
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
488
|
+
]
|
|
489
|
+
},
|
|
490
|
+
idx
|
|
491
|
+
);
|
|
492
|
+
});
|
|
493
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
494
|
+
"div",
|
|
495
|
+
{
|
|
496
|
+
style: {
|
|
497
|
+
fontSize: "13px",
|
|
498
|
+
maxWidth: "600px"
|
|
499
|
+
},
|
|
500
|
+
children: [
|
|
501
|
+
errorsToRender,
|
|
502
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
503
|
+
]
|
|
504
|
+
}
|
|
505
|
+
);
|
|
506
|
+
}
|
|
507
|
+
function useErrorToast() {
|
|
508
|
+
const { addToast } = useToast();
|
|
509
|
+
return (0, import_react6.useCallback)(
|
|
510
|
+
(error) => {
|
|
511
|
+
const errorId = error.map((err) => {
|
|
512
|
+
var _a, _b;
|
|
513
|
+
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
514
|
+
const stack = err.stack || "";
|
|
515
|
+
return btoa(message + stack).slice(0, 32);
|
|
516
|
+
}).join("|");
|
|
517
|
+
addToast({
|
|
518
|
+
type: "error",
|
|
519
|
+
id: errorId,
|
|
520
|
+
// Toast libraries typically dedupe by id
|
|
521
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
522
|
+
});
|
|
523
|
+
},
|
|
524
|
+
[addToast]
|
|
525
|
+
);
|
|
526
|
+
}
|
|
527
|
+
function useAsyncCallback(callback, deps) {
|
|
528
|
+
const addErrorToast = useErrorToast();
|
|
529
|
+
return (0, import_react6.useCallback)((...args) => __async(this, null, function* () {
|
|
530
|
+
try {
|
|
531
|
+
return yield callback(...args);
|
|
532
|
+
} catch (error) {
|
|
533
|
+
console.error("Error in async callback:", error);
|
|
534
|
+
addErrorToast([error]);
|
|
535
|
+
throw error;
|
|
536
|
+
}
|
|
537
|
+
}), deps);
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/components/toast/toast-provider.tsx
|
|
541
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
542
|
+
var ToastContext = (0, import_react7.createContext)(void 0);
|
|
454
543
|
function useToast() {
|
|
455
|
-
const context = (0,
|
|
544
|
+
const context = (0, import_react7.useContext)(ToastContext);
|
|
456
545
|
if (!context) {
|
|
457
546
|
throw new Error("useToast must be used within a ToastProvider");
|
|
458
547
|
}
|
|
@@ -462,68 +551,28 @@ function ToastProvider({
|
|
|
462
551
|
enabled,
|
|
463
552
|
children
|
|
464
553
|
}) {
|
|
465
|
-
const [toasts, setToasts] = (0,
|
|
466
|
-
const addToast = (0,
|
|
467
|
-
|
|
468
|
-
|
|
554
|
+
const [toasts, setToasts] = (0, import_react7.useState)([]);
|
|
555
|
+
const addToast = (0, import_react7.useCallback)((toast) => {
|
|
556
|
+
var _a;
|
|
557
|
+
const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
|
|
558
|
+
setToasts((currentToasts) => {
|
|
559
|
+
if (currentToasts.find((toast2) => toast2.id === id))
|
|
560
|
+
return currentToasts;
|
|
561
|
+
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
562
|
+
});
|
|
469
563
|
if (toast.duration) {
|
|
470
564
|
setTimeout(() => {
|
|
471
565
|
removeToast(id);
|
|
472
566
|
}, toast.duration);
|
|
473
567
|
}
|
|
474
568
|
}, []);
|
|
475
|
-
const addGraphQLErrorsToast = (0,
|
|
476
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
477
|
-
var _a;
|
|
478
|
-
const message = error.message;
|
|
479
|
-
const code = (_a = error.extensions) == null ? void 0 : _a.code;
|
|
480
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
481
|
-
"div",
|
|
482
|
-
{
|
|
483
|
-
style: {
|
|
484
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
485
|
-
marginBottom: 14
|
|
486
|
-
},
|
|
487
|
-
children: [
|
|
488
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
489
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
490
|
-
"div",
|
|
491
|
-
{
|
|
492
|
-
style: {
|
|
493
|
-
fontWeight: "600",
|
|
494
|
-
marginBottom: 4
|
|
495
|
-
},
|
|
496
|
-
children: [
|
|
497
|
-
"Copilot Cloud Error:",
|
|
498
|
-
" ",
|
|
499
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
500
|
-
]
|
|
501
|
-
}
|
|
502
|
-
),
|
|
503
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
504
|
-
]
|
|
505
|
-
},
|
|
506
|
-
idx
|
|
507
|
-
);
|
|
508
|
-
});
|
|
569
|
+
const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
|
|
509
570
|
addToast({
|
|
510
571
|
type: "error",
|
|
511
|
-
message: /* @__PURE__ */ (0,
|
|
512
|
-
"div",
|
|
513
|
-
{
|
|
514
|
-
style: {
|
|
515
|
-
fontSize: "13px",
|
|
516
|
-
maxWidth: "600px"
|
|
517
|
-
},
|
|
518
|
-
children: [
|
|
519
|
-
errorsToRender,
|
|
520
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This is a Copilot Cloud error, and it only displays during local development." })
|
|
521
|
-
]
|
|
522
|
-
}
|
|
523
|
-
)
|
|
572
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
|
|
524
573
|
});
|
|
525
574
|
}, []);
|
|
526
|
-
const removeToast = (0,
|
|
575
|
+
const removeToast = (0, import_react7.useCallback)((id) => {
|
|
527
576
|
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
528
577
|
}, []);
|
|
529
578
|
const value = {
|
|
@@ -533,8 +582,8 @@ function ToastProvider({
|
|
|
533
582
|
removeToast,
|
|
534
583
|
enabled
|
|
535
584
|
};
|
|
536
|
-
return /* @__PURE__ */ (0,
|
|
537
|
-
/* @__PURE__ */ (0,
|
|
585
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ToastContext.Provider, { value, children: [
|
|
586
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
538
587
|
"div",
|
|
539
588
|
{
|
|
540
589
|
style: {
|
|
@@ -548,7 +597,7 @@ function ToastProvider({
|
|
|
548
597
|
gap: "0.5rem"
|
|
549
598
|
},
|
|
550
599
|
children: [
|
|
551
|
-
toasts.length > 1 && /* @__PURE__ */ (0,
|
|
600
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
552
601
|
"button",
|
|
553
602
|
{
|
|
554
603
|
onClick: () => setToasts([]),
|
|
@@ -563,7 +612,7 @@ function ToastProvider({
|
|
|
563
612
|
children: "Close All"
|
|
564
613
|
}
|
|
565
614
|
) }),
|
|
566
|
-
toasts.map((toast) => /* @__PURE__ */ (0,
|
|
615
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
567
616
|
Toast,
|
|
568
617
|
{
|
|
569
618
|
message: toast.message,
|
|
@@ -589,7 +638,7 @@ function Toast({
|
|
|
589
638
|
warning: "#eab308",
|
|
590
639
|
error: "#ef4444"
|
|
591
640
|
};
|
|
592
|
-
return /* @__PURE__ */ (0,
|
|
641
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
593
642
|
"div",
|
|
594
643
|
{
|
|
595
644
|
style: {
|
|
@@ -602,8 +651,8 @@ function Toast({
|
|
|
602
651
|
minWidth: "200px"
|
|
603
652
|
},
|
|
604
653
|
children: [
|
|
605
|
-
/* @__PURE__ */ (0,
|
|
606
|
-
/* @__PURE__ */ (0,
|
|
654
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
|
|
655
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
607
656
|
"button",
|
|
608
657
|
{
|
|
609
658
|
onClick: onClose,
|
|
@@ -628,14 +677,17 @@ function Toast({
|
|
|
628
677
|
|
|
629
678
|
// src/hooks/use-copilot-runtime-client.ts
|
|
630
679
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
631
|
-
var
|
|
680
|
+
var import_react8 = require("react");
|
|
632
681
|
var useCopilotRuntimeClient = (options) => {
|
|
633
682
|
const { addGraphQLErrorsToast } = useToast();
|
|
634
|
-
const
|
|
683
|
+
const addErrorToast = useErrorToast();
|
|
684
|
+
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
635
685
|
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
636
686
|
handleGQLErrors: (error) => {
|
|
637
687
|
if (error.graphQLErrors.length) {
|
|
638
688
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
689
|
+
} else {
|
|
690
|
+
addErrorToast([error]);
|
|
639
691
|
}
|
|
640
692
|
}
|
|
641
693
|
}));
|
|
@@ -790,13 +842,41 @@ function getHostname() {
|
|
|
790
842
|
return "";
|
|
791
843
|
}
|
|
792
844
|
|
|
845
|
+
// src/components/error-boundary/error-boundary.tsx
|
|
846
|
+
var import_react9 = __toESM(require("react"));
|
|
847
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
848
|
+
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
849
|
+
constructor(props) {
|
|
850
|
+
super(props);
|
|
851
|
+
this.state = { hasError: false };
|
|
852
|
+
}
|
|
853
|
+
static getDerivedStateFromError(error) {
|
|
854
|
+
return { hasError: true, error };
|
|
855
|
+
}
|
|
856
|
+
componentDidCatch(error, errorInfo) {
|
|
857
|
+
console.error("CopilotKit Error:", error, errorInfo);
|
|
858
|
+
}
|
|
859
|
+
render() {
|
|
860
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
|
|
861
|
+
}
|
|
862
|
+
};
|
|
863
|
+
function ErrorToast2({ error, children }) {
|
|
864
|
+
const addErrorToast = useErrorToast();
|
|
865
|
+
(0, import_react9.useEffect)(() => {
|
|
866
|
+
if (error) {
|
|
867
|
+
addErrorToast([error]);
|
|
868
|
+
}
|
|
869
|
+
}, [error, addErrorToast]);
|
|
870
|
+
return children;
|
|
871
|
+
}
|
|
872
|
+
|
|
793
873
|
// src/components/copilot-provider/copilotkit.tsx
|
|
794
|
-
var
|
|
874
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
795
875
|
function CopilotKit(_a) {
|
|
796
876
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
797
877
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
798
878
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
799
|
-
return /* @__PURE__ */ (0,
|
|
879
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotErrorBoundary, { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) }) });
|
|
800
880
|
}
|
|
801
881
|
function CopilotKitInternal(_a) {
|
|
802
882
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
@@ -806,49 +886,49 @@ function CopilotKitInternal(_a) {
|
|
|
806
886
|
);
|
|
807
887
|
}
|
|
808
888
|
const chatApiEndpoint = props.runtimeUrl || import_shared4.COPILOT_CLOUD_CHAT_URL;
|
|
809
|
-
const [actions, setActions] = (0,
|
|
810
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
811
|
-
const chatComponentsCache = (0,
|
|
889
|
+
const [actions, setActions] = (0, import_react10.useState)({});
|
|
890
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
|
|
891
|
+
const chatComponentsCache = (0, import_react10.useRef)({
|
|
812
892
|
actions: {},
|
|
813
893
|
coAgentStateRenders: {}
|
|
814
894
|
});
|
|
815
895
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
816
|
-
const [isLoading, setIsLoading] = (0,
|
|
817
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
896
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
897
|
+
const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
|
|
818
898
|
const {
|
|
819
899
|
addElement: addDocument,
|
|
820
900
|
removeElement: removeDocument,
|
|
821
901
|
allElements: allDocuments
|
|
822
902
|
} = use_flat_category_store_default();
|
|
823
|
-
const setAction = (0,
|
|
903
|
+
const setAction = (0, import_react10.useCallback)((id, action) => {
|
|
824
904
|
setActions((prevPoints) => {
|
|
825
905
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
826
906
|
[id]: action
|
|
827
907
|
});
|
|
828
908
|
});
|
|
829
909
|
}, []);
|
|
830
|
-
const removeAction = (0,
|
|
910
|
+
const removeAction = (0, import_react10.useCallback)((id) => {
|
|
831
911
|
setActions((prevPoints) => {
|
|
832
912
|
const newPoints = __spreadValues({}, prevPoints);
|
|
833
913
|
delete newPoints[id];
|
|
834
914
|
return newPoints;
|
|
835
915
|
});
|
|
836
916
|
}, []);
|
|
837
|
-
const setCoAgentStateRender = (0,
|
|
917
|
+
const setCoAgentStateRender = (0, import_react10.useCallback)((id, stateRender) => {
|
|
838
918
|
setCoAgentStateRenders((prevPoints) => {
|
|
839
919
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
840
920
|
[id]: stateRender
|
|
841
921
|
});
|
|
842
922
|
});
|
|
843
923
|
}, []);
|
|
844
|
-
const removeCoAgentStateRender = (0,
|
|
924
|
+
const removeCoAgentStateRender = (0, import_react10.useCallback)((id) => {
|
|
845
925
|
setCoAgentStateRenders((prevPoints) => {
|
|
846
926
|
const newPoints = __spreadValues({}, prevPoints);
|
|
847
927
|
delete newPoints[id];
|
|
848
928
|
return newPoints;
|
|
849
929
|
});
|
|
850
930
|
}, []);
|
|
851
|
-
const getContextString = (0,
|
|
931
|
+
const getContextString = (0, import_react10.useCallback)(
|
|
852
932
|
(documents, categories) => {
|
|
853
933
|
const documentsString = documents.map((document) => {
|
|
854
934
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -861,37 +941,37 @@ ${nonDocumentStrings}`;
|
|
|
861
941
|
},
|
|
862
942
|
[printTree]
|
|
863
943
|
);
|
|
864
|
-
const addContext = (0,
|
|
944
|
+
const addContext = (0, import_react10.useCallback)(
|
|
865
945
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
866
946
|
return addElement(context, categories, parentId);
|
|
867
947
|
},
|
|
868
948
|
[addElement]
|
|
869
949
|
);
|
|
870
|
-
const removeContext = (0,
|
|
950
|
+
const removeContext = (0, import_react10.useCallback)(
|
|
871
951
|
(id) => {
|
|
872
952
|
removeElement(id);
|
|
873
953
|
},
|
|
874
954
|
[removeElement]
|
|
875
955
|
);
|
|
876
|
-
const getFunctionCallHandler = (0,
|
|
956
|
+
const getFunctionCallHandler = (0, import_react10.useCallback)(
|
|
877
957
|
(customEntryPoints) => {
|
|
878
958
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
879
959
|
},
|
|
880
960
|
[actions]
|
|
881
961
|
);
|
|
882
|
-
const getDocumentsContext = (0,
|
|
962
|
+
const getDocumentsContext = (0, import_react10.useCallback)(
|
|
883
963
|
(categories) => {
|
|
884
964
|
return allDocuments(categories);
|
|
885
965
|
},
|
|
886
966
|
[allDocuments]
|
|
887
967
|
);
|
|
888
|
-
const addDocumentContext = (0,
|
|
968
|
+
const addDocumentContext = (0, import_react10.useCallback)(
|
|
889
969
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
890
970
|
return addDocument(documentPointer, categories);
|
|
891
971
|
},
|
|
892
972
|
[addDocument]
|
|
893
973
|
);
|
|
894
|
-
const removeDocumentContext = (0,
|
|
974
|
+
const removeDocumentContext = (0, import_react10.useCallback)(
|
|
895
975
|
(documentId) => {
|
|
896
976
|
removeDocument(documentId);
|
|
897
977
|
},
|
|
@@ -904,7 +984,7 @@ ${nonDocumentStrings}`;
|
|
|
904
984
|
);
|
|
905
985
|
}
|
|
906
986
|
}
|
|
907
|
-
const copilotApiConfig = (0,
|
|
987
|
+
const copilotApiConfig = (0, import_react10.useMemo)(() => {
|
|
908
988
|
var _a2, _b2;
|
|
909
989
|
let cloud = void 0;
|
|
910
990
|
if (props.publicApiKey) {
|
|
@@ -946,7 +1026,7 @@ ${nonDocumentStrings}`;
|
|
|
946
1026
|
headers,
|
|
947
1027
|
credentials: copilotApiConfig.credentials
|
|
948
1028
|
});
|
|
949
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
1029
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
950
1030
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
951
1031
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
952
1032
|
};
|
|
@@ -956,19 +1036,30 @@ ${nonDocumentStrings}`;
|
|
|
956
1036
|
return rest;
|
|
957
1037
|
});
|
|
958
1038
|
};
|
|
959
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
1039
|
+
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
1040
|
+
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
1041
|
+
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
1042
|
+
(value) => {
|
|
1043
|
+
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
1044
|
+
coagentStatesRef.current = newValue;
|
|
1045
|
+
setCoagentStates((prev) => {
|
|
1046
|
+
return newValue;
|
|
1047
|
+
});
|
|
1048
|
+
},
|
|
1049
|
+
[]
|
|
1050
|
+
);
|
|
960
1051
|
let initialAgentSession = null;
|
|
961
1052
|
if (props.agent) {
|
|
962
1053
|
initialAgentSession = {
|
|
963
1054
|
agentName: props.agent
|
|
964
1055
|
};
|
|
965
1056
|
}
|
|
966
|
-
const [agentSession, setAgentSession] = (0,
|
|
967
|
-
const [threadId, setThreadId] = (0,
|
|
968
|
-
const [runId, setRunId] = (0,
|
|
969
|
-
const chatAbortControllerRef = (0,
|
|
1057
|
+
const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
|
|
1058
|
+
const [threadId, setThreadId] = (0, import_react10.useState)(null);
|
|
1059
|
+
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
1060
|
+
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
970
1061
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
971
|
-
return /* @__PURE__ */ (0,
|
|
1062
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
972
1063
|
CopilotContext.Provider,
|
|
973
1064
|
{
|
|
974
1065
|
value: {
|
|
@@ -997,6 +1088,8 @@ ${nonDocumentStrings}`;
|
|
|
997
1088
|
showDevConsole,
|
|
998
1089
|
coagentStates,
|
|
999
1090
|
setCoagentStates,
|
|
1091
|
+
coagentStatesRef,
|
|
1092
|
+
setCoagentStatesWithRef,
|
|
1000
1093
|
agentSession,
|
|
1001
1094
|
setAgentSession,
|
|
1002
1095
|
runtimeClient,
|
|
@@ -1007,7 +1100,7 @@ ${nonDocumentStrings}`;
|
|
|
1007
1100
|
setRunId,
|
|
1008
1101
|
chatAbortControllerRef
|
|
1009
1102
|
},
|
|
1010
|
-
children: /* @__PURE__ */ (0,
|
|
1103
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
|
|
1011
1104
|
}
|
|
1012
1105
|
);
|
|
1013
1106
|
}
|
|
@@ -1039,13 +1132,40 @@ function entryPointsToFunctionCallHandler(actions) {
|
|
|
1039
1132
|
}
|
|
1040
1133
|
|
|
1041
1134
|
// src/hooks/use-copilot-chat.ts
|
|
1042
|
-
var
|
|
1043
|
-
var
|
|
1135
|
+
var import_react12 = require("react");
|
|
1136
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1044
1137
|
|
|
1045
1138
|
// src/hooks/use-chat.ts
|
|
1046
|
-
var
|
|
1047
|
-
var
|
|
1139
|
+
var import_react11 = require("react");
|
|
1140
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1141
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1142
|
+
|
|
1143
|
+
// src/types/frontend-action.ts
|
|
1048
1144
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1145
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1146
|
+
function processActionsForRuntimeRequest(actions) {
|
|
1147
|
+
const filteredActions = actions.filter(
|
|
1148
|
+
(action) => action.available !== import_runtime_client_gql4.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
|
|
1149
|
+
).map((action) => {
|
|
1150
|
+
let available = import_runtime_client_gql4.ActionInputAvailability.Enabled;
|
|
1151
|
+
if (action.disabled) {
|
|
1152
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
1153
|
+
} else if (action.available === "disabled") {
|
|
1154
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
1155
|
+
} else if (action.available === "remote") {
|
|
1156
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Remote;
|
|
1157
|
+
}
|
|
1158
|
+
return {
|
|
1159
|
+
name: action.name,
|
|
1160
|
+
description: action.description || "",
|
|
1161
|
+
jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || [])),
|
|
1162
|
+
available
|
|
1163
|
+
};
|
|
1164
|
+
});
|
|
1165
|
+
return filteredActions;
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// src/hooks/use-chat.ts
|
|
1049
1169
|
function useChat(options) {
|
|
1050
1170
|
const {
|
|
1051
1171
|
messages,
|
|
@@ -1058,8 +1178,8 @@ function useChat(options) {
|
|
|
1058
1178
|
actions,
|
|
1059
1179
|
onFunctionCall,
|
|
1060
1180
|
onCoAgentStateRender,
|
|
1061
|
-
|
|
1062
|
-
|
|
1181
|
+
setCoagentStatesWithRef,
|
|
1182
|
+
coagentStatesRef,
|
|
1063
1183
|
agentSession,
|
|
1064
1184
|
setAgentSession,
|
|
1065
1185
|
threadId,
|
|
@@ -1068,244 +1188,298 @@ function useChat(options) {
|
|
|
1068
1188
|
setRunId,
|
|
1069
1189
|
chatAbortControllerRef
|
|
1070
1190
|
} = options;
|
|
1071
|
-
const abortController = new AbortController();
|
|
1072
|
-
chatAbortControllerRef.current = abortController;
|
|
1073
1191
|
const { addGraphQLErrorsToast } = useToast();
|
|
1074
|
-
const runChatCompletionRef = (0,
|
|
1075
|
-
const
|
|
1076
|
-
coagentStatesRef.current = coagentStates;
|
|
1077
|
-
const agentSessionRef = (0, import_react9.useRef)(agentSession);
|
|
1192
|
+
const runChatCompletionRef = (0, import_react11.useRef)();
|
|
1193
|
+
const agentSessionRef = (0, import_react11.useRef)(agentSession);
|
|
1078
1194
|
agentSessionRef.current = agentSession;
|
|
1079
|
-
const threadIdRef = (0,
|
|
1195
|
+
const threadIdRef = (0, import_react11.useRef)(threadId);
|
|
1080
1196
|
threadIdRef.current = threadId;
|
|
1081
|
-
const runIdRef = (0,
|
|
1197
|
+
const runIdRef = (0, import_react11.useRef)(runId);
|
|
1082
1198
|
runIdRef.current = runId;
|
|
1083
1199
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
1084
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [
|
|
1200
|
+
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1085
1201
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1086
1202
|
url: copilotConfig.chatApiEndpoint,
|
|
1087
1203
|
publicApiKey: copilotConfig.publicApiKey,
|
|
1088
1204
|
headers,
|
|
1089
1205
|
credentials: copilotConfig.credentials
|
|
1090
1206
|
});
|
|
1091
|
-
const runChatCompletion = (
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
available
|
|
1124
|
-
};
|
|
1125
|
-
}),
|
|
1126
|
-
url: window.location.href
|
|
1127
|
-
},
|
|
1128
|
-
threadId: threadIdRef.current,
|
|
1129
|
-
runId: runIdRef.current,
|
|
1130
|
-
messages: (0, import_runtime_client_gql4.convertMessagesToGqlInput)((0, import_runtime_client_gql4.filterAgentStateMessages)(messagesWithContext))
|
|
1131
|
-
}, copilotConfig.cloud ? {
|
|
1132
|
-
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
1133
|
-
guardrails: {
|
|
1134
|
-
inputValidationRules: {
|
|
1135
|
-
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
1136
|
-
denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
|
|
1207
|
+
const runChatCompletion = useAsyncCallback(
|
|
1208
|
+
(previousMessages) => __async(this, null, function* () {
|
|
1209
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1210
|
+
setIsLoading(true);
|
|
1211
|
+
let newMessages = [
|
|
1212
|
+
new import_runtime_client_gql5.TextMessage({
|
|
1213
|
+
content: "",
|
|
1214
|
+
role: import_runtime_client_gql5.Role.Assistant
|
|
1215
|
+
})
|
|
1216
|
+
];
|
|
1217
|
+
chatAbortControllerRef.current = new AbortController();
|
|
1218
|
+
setMessages([...previousMessages, ...newMessages]);
|
|
1219
|
+
const systemMessage = makeSystemMessageCallback();
|
|
1220
|
+
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
1221
|
+
const isAgentRun = agentSessionRef.current !== null;
|
|
1222
|
+
const stream = runtimeClient.asStream(
|
|
1223
|
+
runtimeClient.generateCopilotResponse({
|
|
1224
|
+
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
1225
|
+
frontend: {
|
|
1226
|
+
actions: processActionsForRuntimeRequest(actions),
|
|
1227
|
+
url: window.location.href
|
|
1228
|
+
},
|
|
1229
|
+
threadId: threadIdRef.current,
|
|
1230
|
+
runId: runIdRef.current,
|
|
1231
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)((0, import_runtime_client_gql5.filterAgentStateMessages)(messagesWithContext))
|
|
1232
|
+
}, copilotConfig.cloud ? {
|
|
1233
|
+
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
1234
|
+
guardrails: {
|
|
1235
|
+
inputValidationRules: {
|
|
1236
|
+
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
1237
|
+
denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
|
|
1238
|
+
}
|
|
1137
1239
|
}
|
|
1240
|
+
} : {})
|
|
1241
|
+
} : {}), {
|
|
1242
|
+
metadata: {
|
|
1243
|
+
requestType: import_runtime_client_gql5.CopilotRequestType.Chat
|
|
1138
1244
|
}
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1245
|
+
}), agentSessionRef.current ? {
|
|
1246
|
+
agentSession: agentSessionRef.current
|
|
1247
|
+
} : {}), {
|
|
1248
|
+
agentStates: Object.values(coagentStatesRef.current).map((state) => ({
|
|
1249
|
+
agentName: state.name,
|
|
1250
|
+
state: JSON.stringify(state.state)
|
|
1251
|
+
}))
|
|
1252
|
+
}),
|
|
1253
|
+
properties: copilotConfig.properties,
|
|
1254
|
+
signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
|
|
1255
|
+
})
|
|
1256
|
+
);
|
|
1257
|
+
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
1258
|
+
const reader = stream.getReader();
|
|
1259
|
+
let executedCoAgentStateRenders = [];
|
|
1260
|
+
let followUp = void 0;
|
|
1261
|
+
let messages2 = [];
|
|
1262
|
+
let syncedMessages = [];
|
|
1263
|
+
try {
|
|
1264
|
+
while (true) {
|
|
1265
|
+
let done, value;
|
|
1266
|
+
try {
|
|
1267
|
+
const readResult = yield reader.read();
|
|
1268
|
+
done = readResult.done;
|
|
1269
|
+
value = readResult.value;
|
|
1270
|
+
} catch (readError) {
|
|
1271
|
+
break;
|
|
1143
1272
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
state: JSON.stringify(state.state)
|
|
1150
|
-
}))
|
|
1151
|
-
}),
|
|
1152
|
-
properties: copilotConfig.properties,
|
|
1153
|
-
signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
|
|
1154
|
-
})
|
|
1155
|
-
);
|
|
1156
|
-
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
1157
|
-
const reader = stream.getReader();
|
|
1158
|
-
let actionResults = {};
|
|
1159
|
-
let executedCoAgentStateRenders = [];
|
|
1160
|
-
let followUp = void 0;
|
|
1161
|
-
try {
|
|
1162
|
-
while (true) {
|
|
1163
|
-
let done, value;
|
|
1164
|
-
try {
|
|
1165
|
-
const readResult = yield reader.read();
|
|
1166
|
-
done = readResult.done;
|
|
1167
|
-
value = readResult.value;
|
|
1168
|
-
} catch (readError) {
|
|
1169
|
-
break;
|
|
1170
|
-
}
|
|
1171
|
-
if (done) {
|
|
1172
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1173
|
-
return newMessages.slice();
|
|
1273
|
+
if (done) {
|
|
1274
|
+
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1275
|
+
return [];
|
|
1276
|
+
}
|
|
1277
|
+
break;
|
|
1174
1278
|
}
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
if (!(message.id in actionResults)) {
|
|
1279
|
+
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
1280
|
+
continue;
|
|
1281
|
+
}
|
|
1282
|
+
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
1283
|
+
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
1284
|
+
setThreadId(threadIdRef.current);
|
|
1285
|
+
setRunId(runIdRef.current);
|
|
1286
|
+
messages2 = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
|
|
1287
|
+
(0, import_runtime_client_gql5.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
1288
|
+
);
|
|
1289
|
+
if (messages2.length === 0) {
|
|
1290
|
+
continue;
|
|
1291
|
+
}
|
|
1292
|
+
newMessages = [];
|
|
1293
|
+
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
1294
|
+
newMessages = [
|
|
1295
|
+
new import_runtime_client_gql5.TextMessage({
|
|
1296
|
+
role: import_runtime_client_gql5.MessageRole.Assistant,
|
|
1297
|
+
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
1298
|
+
})
|
|
1299
|
+
];
|
|
1300
|
+
setMessages([...previousMessages, ...newMessages]);
|
|
1301
|
+
break;
|
|
1302
|
+
} else {
|
|
1303
|
+
newMessages = [...messages2];
|
|
1304
|
+
for (const message of messages2) {
|
|
1305
|
+
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
1203
1306
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
1204
1307
|
break;
|
|
1205
1308
|
}
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
1309
|
+
yield onCoAgentStateRender({
|
|
1310
|
+
name: message.agentName,
|
|
1311
|
+
nodeName: message.nodeName,
|
|
1312
|
+
state: message.state
|
|
1313
|
+
});
|
|
1314
|
+
executedCoAgentStateRenders.push(message.id);
|
|
1315
|
+
}
|
|
1316
|
+
}
|
|
1317
|
+
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
1318
|
+
if (lastAgentStateMessage) {
|
|
1319
|
+
if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
|
|
1320
|
+
syncedMessages = (0, import_runtime_client_gql5.loadMessagesFromJsonRepresentation)(
|
|
1321
|
+
lastAgentStateMessage.state.messages
|
|
1322
|
+
);
|
|
1323
|
+
}
|
|
1324
|
+
setCoagentStatesWithRef((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1325
|
+
[lastAgentStateMessage.agentName]: {
|
|
1326
|
+
name: lastAgentStateMessage.agentName,
|
|
1327
|
+
state: lastAgentStateMessage.state,
|
|
1328
|
+
running: lastAgentStateMessage.running,
|
|
1329
|
+
active: lastAgentStateMessage.active,
|
|
1330
|
+
threadId: lastAgentStateMessage.threadId,
|
|
1331
|
+
nodeName: lastAgentStateMessage.nodeName,
|
|
1332
|
+
runId: lastAgentStateMessage.runId
|
|
1231
1333
|
}
|
|
1334
|
+
}));
|
|
1335
|
+
if (lastAgentStateMessage.running) {
|
|
1336
|
+
setAgentSession({
|
|
1337
|
+
threadId: lastAgentStateMessage.threadId,
|
|
1338
|
+
agentName: lastAgentStateMessage.agentName,
|
|
1339
|
+
nodeName: lastAgentStateMessage.nodeName
|
|
1340
|
+
});
|
|
1341
|
+
} else {
|
|
1342
|
+
setAgentSession(null);
|
|
1232
1343
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
if (newMessages.length > 0) {
|
|
1347
|
+
setMessages([...previousMessages, ...newMessages]);
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
const finalMessages = constructFinalMessages(syncedMessages, previousMessages, newMessages);
|
|
1351
|
+
let didExecuteAction = false;
|
|
1352
|
+
if (onFunctionCall) {
|
|
1353
|
+
const lastMessages = [];
|
|
1354
|
+
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
1355
|
+
const message = finalMessages[i];
|
|
1356
|
+
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql5.MessageStatusCode.Pending) {
|
|
1357
|
+
lastMessages.unshift(message);
|
|
1358
|
+
} else {
|
|
1359
|
+
break;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
for (const message of lastMessages) {
|
|
1363
|
+
setMessages(finalMessages);
|
|
1364
|
+
const action = actions.find((action2) => action2.name === message.name);
|
|
1365
|
+
if (action) {
|
|
1366
|
+
followUp = action.followUp;
|
|
1367
|
+
let result;
|
|
1368
|
+
try {
|
|
1369
|
+
result = yield Promise.race([
|
|
1370
|
+
onFunctionCall({
|
|
1371
|
+
messages: previousMessages,
|
|
1372
|
+
name: message.name,
|
|
1373
|
+
args: message.arguments
|
|
1374
|
+
}),
|
|
1375
|
+
new Promise(
|
|
1376
|
+
(resolve) => {
|
|
1377
|
+
var _a2;
|
|
1378
|
+
return (_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.addEventListener(
|
|
1379
|
+
"abort",
|
|
1380
|
+
() => resolve("Operation was aborted by the user")
|
|
1381
|
+
);
|
|
1382
|
+
}
|
|
1383
|
+
),
|
|
1384
|
+
// if the user stopped generation, we also abort consecutive actions
|
|
1385
|
+
new Promise((resolve) => {
|
|
1386
|
+
var _a2;
|
|
1387
|
+
if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
|
|
1388
|
+
resolve("Operation was aborted by the user");
|
|
1389
|
+
}
|
|
1390
|
+
})
|
|
1391
|
+
]);
|
|
1392
|
+
} catch (e) {
|
|
1393
|
+
result = `Failed to execute action ${message.name}`;
|
|
1394
|
+
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
1395
|
+
}
|
|
1396
|
+
didExecuteAction = true;
|
|
1397
|
+
const messageIndex = finalMessages.findIndex((msg) => msg.id === message.id);
|
|
1398
|
+
finalMessages.splice(
|
|
1399
|
+
messageIndex + 1,
|
|
1400
|
+
0,
|
|
1401
|
+
new import_runtime_client_gql5.ResultMessage({
|
|
1402
|
+
id: "result-" + message.id,
|
|
1403
|
+
result: import_runtime_client_gql5.ResultMessage.encodeResult(result),
|
|
1236
1404
|
actionExecutionId: message.id,
|
|
1237
1405
|
actionName: message.name
|
|
1238
1406
|
})
|
|
1239
1407
|
);
|
|
1240
1408
|
}
|
|
1241
|
-
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
1242
|
-
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
1243
|
-
break;
|
|
1244
|
-
}
|
|
1245
|
-
yield onCoAgentStateRender({
|
|
1246
|
-
name: message.agentName,
|
|
1247
|
-
nodeName: message.nodeName,
|
|
1248
|
-
state: message.state
|
|
1249
|
-
});
|
|
1250
|
-
executedCoAgentStateRenders.push(message.id);
|
|
1251
|
-
}
|
|
1252
1409
|
}
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
if (
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
nodeName: lastAgentStateMessage.nodeName
|
|
1271
|
-
});
|
|
1272
|
-
} else {
|
|
1273
|
-
setAgentSession(null);
|
|
1410
|
+
setMessages(finalMessages);
|
|
1411
|
+
}
|
|
1412
|
+
if (
|
|
1413
|
+
// if followUp is not explicitly false
|
|
1414
|
+
followUp !== false && // and we executed an action
|
|
1415
|
+
(didExecuteAction || // the last message is a server side result
|
|
1416
|
+
!isAgentRun && finalMessages.length && finalMessages[finalMessages.length - 1].isResultMessage()) && // the user did not stop generation
|
|
1417
|
+
!((_j = chatAbortControllerRef.current) == null ? void 0 : _j.signal.aborted)
|
|
1418
|
+
) {
|
|
1419
|
+
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
1420
|
+
return yield runChatCompletionRef.current(finalMessages);
|
|
1421
|
+
} else if ((_k = chatAbortControllerRef.current) == null ? void 0 : _k.signal.aborted) {
|
|
1422
|
+
const repairedMessages = finalMessages.filter((message, actionExecutionIndex) => {
|
|
1423
|
+
if (message.isActionExecutionMessage()) {
|
|
1424
|
+
return finalMessages.find(
|
|
1425
|
+
(msg, resultIndex) => msg.isResultMessage() && msg.actionExecutionId === message.id && resultIndex === actionExecutionIndex + 1
|
|
1426
|
+
);
|
|
1274
1427
|
}
|
|
1428
|
+
return true;
|
|
1429
|
+
});
|
|
1430
|
+
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
1431
|
+
setMessages(repairedMessages);
|
|
1432
|
+
if ((_l = agentSessionRef.current) == null ? void 0 : _l.nodeName) {
|
|
1433
|
+
setAgentSession({
|
|
1434
|
+
threadId: agentSessionRef.current.threadId,
|
|
1435
|
+
agentName: agentSessionRef.current.agentName,
|
|
1436
|
+
nodeName: "__end__"
|
|
1437
|
+
});
|
|
1275
1438
|
}
|
|
1439
|
+
return newMessages.filter((message) => repairedMessageIds.includes(message.id));
|
|
1440
|
+
} else {
|
|
1441
|
+
return newMessages.slice();
|
|
1276
1442
|
}
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1281
|
-
if (
|
|
1282
|
-
// if followUp is not explicitly false
|
|
1283
|
-
followUp !== false && // if we have client side results
|
|
1284
|
-
(Object.values(actionResults).length || // or the last message we received is a result
|
|
1285
|
-
newMessages.length && newMessages[newMessages.length - 1].isResultMessage())
|
|
1286
|
-
) {
|
|
1287
|
-
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
1288
|
-
return yield runChatCompletionRef.current([...previousMessages, ...newMessages]);
|
|
1289
|
-
} else {
|
|
1290
|
-
return newMessages.slice();
|
|
1443
|
+
} finally {
|
|
1444
|
+
setIsLoading(false);
|
|
1291
1445
|
}
|
|
1292
|
-
}
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1446
|
+
}),
|
|
1447
|
+
[
|
|
1448
|
+
messages,
|
|
1449
|
+
setMessages,
|
|
1450
|
+
makeSystemMessageCallback,
|
|
1451
|
+
copilotConfig,
|
|
1452
|
+
setIsLoading,
|
|
1453
|
+
initialMessages,
|
|
1454
|
+
isLoading,
|
|
1455
|
+
actions,
|
|
1456
|
+
onFunctionCall,
|
|
1457
|
+
onCoAgentStateRender,
|
|
1458
|
+
setCoagentStatesWithRef,
|
|
1459
|
+
coagentStatesRef,
|
|
1460
|
+
agentSession,
|
|
1461
|
+
setAgentSession
|
|
1462
|
+
]
|
|
1463
|
+
);
|
|
1296
1464
|
runChatCompletionRef.current = runChatCompletion;
|
|
1297
|
-
const runChatCompletionAndHandleFunctionCall = (
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1465
|
+
const runChatCompletionAndHandleFunctionCall = useAsyncCallback(
|
|
1466
|
+
(messages2) => __async(this, null, function* () {
|
|
1467
|
+
yield runChatCompletionRef.current(messages2);
|
|
1468
|
+
}),
|
|
1469
|
+
[messages]
|
|
1470
|
+
);
|
|
1471
|
+
const append = useAsyncCallback(
|
|
1472
|
+
(message) => __async(this, null, function* () {
|
|
1473
|
+
if (isLoading) {
|
|
1474
|
+
return;
|
|
1475
|
+
}
|
|
1476
|
+
const newMessages = [...messages, message];
|
|
1477
|
+
setMessages(newMessages);
|
|
1478
|
+
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
1479
|
+
}),
|
|
1480
|
+
[isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]
|
|
1481
|
+
);
|
|
1482
|
+
const reload = useAsyncCallback(() => __async(this, null, function* () {
|
|
1309
1483
|
if (isLoading || messages.length === 0) {
|
|
1310
1484
|
return;
|
|
1311
1485
|
}
|
|
@@ -1316,7 +1490,7 @@ function useChat(options) {
|
|
|
1316
1490
|
}
|
|
1317
1491
|
setMessages(newMessages);
|
|
1318
1492
|
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
1319
|
-
});
|
|
1493
|
+
}), [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);
|
|
1320
1494
|
const stop = () => {
|
|
1321
1495
|
var _a;
|
|
1322
1496
|
(_a = chatAbortControllerRef.current) == null ? void 0 : _a.abort("Stop was called");
|
|
@@ -1324,9 +1498,27 @@ function useChat(options) {
|
|
|
1324
1498
|
return {
|
|
1325
1499
|
append,
|
|
1326
1500
|
reload,
|
|
1327
|
-
stop
|
|
1501
|
+
stop,
|
|
1502
|
+
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
1328
1503
|
};
|
|
1329
1504
|
}
|
|
1505
|
+
function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
1506
|
+
const finalMessages = syncedMessages.length > 0 ? [...syncedMessages] : [...previousMessages, ...newMessages];
|
|
1507
|
+
if (syncedMessages.length > 0) {
|
|
1508
|
+
const messagesWithAgentState = [...previousMessages, ...newMessages];
|
|
1509
|
+
let previousMessageId = void 0;
|
|
1510
|
+
for (const message of messagesWithAgentState) {
|
|
1511
|
+
if (message.isAgentStateMessage()) {
|
|
1512
|
+
const index = finalMessages.findIndex((msg) => msg.id === previousMessageId);
|
|
1513
|
+
if (index !== -1) {
|
|
1514
|
+
finalMessages.splice(index + 1, 0, message);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
previousMessageId = message.id;
|
|
1518
|
+
}
|
|
1519
|
+
}
|
|
1520
|
+
return finalMessages;
|
|
1521
|
+
}
|
|
1330
1522
|
|
|
1331
1523
|
// src/hooks/use-copilot-chat.ts
|
|
1332
1524
|
function useCopilotChat(_a = {}) {
|
|
@@ -1343,8 +1535,8 @@ function useCopilotChat(_a = {}) {
|
|
|
1343
1535
|
setIsLoading,
|
|
1344
1536
|
chatInstructions,
|
|
1345
1537
|
actions,
|
|
1346
|
-
|
|
1347
|
-
|
|
1538
|
+
coagentStatesRef,
|
|
1539
|
+
setCoagentStatesWithRef,
|
|
1348
1540
|
coAgentStateRenders,
|
|
1349
1541
|
agentSession,
|
|
1350
1542
|
setAgentSession,
|
|
@@ -1357,21 +1549,21 @@ function useCopilotChat(_a = {}) {
|
|
|
1357
1549
|
} = useCopilotContext();
|
|
1358
1550
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1359
1551
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
1360
|
-
const deleteMessage = (0,
|
|
1552
|
+
const deleteMessage = (0, import_react12.useCallback)(
|
|
1361
1553
|
(messageId) => {
|
|
1362
1554
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1363
1555
|
},
|
|
1364
1556
|
[setMessages]
|
|
1365
1557
|
);
|
|
1366
|
-
const makeSystemMessageCallback = (0,
|
|
1558
|
+
const makeSystemMessageCallback = (0, import_react12.useCallback)(() => {
|
|
1367
1559
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1368
1560
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
1369
|
-
return new
|
|
1561
|
+
return new import_runtime_client_gql6.TextMessage({
|
|
1370
1562
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1371
|
-
role:
|
|
1563
|
+
role: import_runtime_client_gql6.Role.System
|
|
1372
1564
|
});
|
|
1373
1565
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1374
|
-
const onCoAgentStateRender = (
|
|
1566
|
+
const onCoAgentStateRender = useAsyncCallback(
|
|
1375
1567
|
(args) => __async(this, null, function* () {
|
|
1376
1568
|
var _a2;
|
|
1377
1569
|
const { name, nodeName, state } = args;
|
|
@@ -1389,7 +1581,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1389
1581
|
}),
|
|
1390
1582
|
[coAgentStateRenders]
|
|
1391
1583
|
);
|
|
1392
|
-
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1584
|
+
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1393
1585
|
actions: Object.values(actions),
|
|
1394
1586
|
copilotConfig: copilotApiConfig,
|
|
1395
1587
|
initialMessages: options.initialMessages || [],
|
|
@@ -1400,8 +1592,8 @@ function useCopilotChat(_a = {}) {
|
|
|
1400
1592
|
makeSystemMessageCallback,
|
|
1401
1593
|
isLoading,
|
|
1402
1594
|
setIsLoading,
|
|
1403
|
-
|
|
1404
|
-
|
|
1595
|
+
coagentStatesRef,
|
|
1596
|
+
setCoagentStatesWithRef,
|
|
1405
1597
|
agentSession,
|
|
1406
1598
|
setAgentSession,
|
|
1407
1599
|
threadId,
|
|
@@ -1411,40 +1603,44 @@ function useCopilotChat(_a = {}) {
|
|
|
1411
1603
|
chatAbortControllerRef
|
|
1412
1604
|
}));
|
|
1413
1605
|
const latestAppend = useUpdatedRef(append);
|
|
1414
|
-
const latestAppendFunc = (
|
|
1415
|
-
(message) => {
|
|
1416
|
-
return latestAppend.current(message);
|
|
1417
|
-
},
|
|
1606
|
+
const latestAppendFunc = useAsyncCallback(
|
|
1607
|
+
(message) => __async(this, null, function* () {
|
|
1608
|
+
return yield latestAppend.current(message);
|
|
1609
|
+
}),
|
|
1418
1610
|
[latestAppend]
|
|
1419
1611
|
);
|
|
1420
1612
|
const latestReload = useUpdatedRef(reload);
|
|
1421
|
-
const latestReloadFunc = (
|
|
1422
|
-
return latestReload.current();
|
|
1423
|
-
}, [latestReload]);
|
|
1613
|
+
const latestReloadFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1614
|
+
return yield latestReload.current();
|
|
1615
|
+
}), [latestReload]);
|
|
1424
1616
|
const latestStop = useUpdatedRef(stop);
|
|
1425
|
-
const latestStopFunc = (0,
|
|
1617
|
+
const latestStopFunc = (0, import_react12.useCallback)(() => {
|
|
1426
1618
|
return latestStop.current();
|
|
1427
1619
|
}, [latestStop]);
|
|
1428
1620
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1429
|
-
const latestDeleteFunc = (0,
|
|
1621
|
+
const latestDeleteFunc = (0, import_react12.useCallback)(
|
|
1430
1622
|
(messageId) => {
|
|
1431
1623
|
return latestDelete.current(messageId);
|
|
1432
1624
|
},
|
|
1433
1625
|
[latestDelete]
|
|
1434
1626
|
);
|
|
1435
1627
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1436
|
-
const latestSetMessagesFunc = (0,
|
|
1628
|
+
const latestSetMessagesFunc = (0, import_react12.useCallback)(
|
|
1437
1629
|
(messages2) => {
|
|
1438
1630
|
return latestSetMessages.current(messages2);
|
|
1439
1631
|
},
|
|
1440
1632
|
[latestSetMessages]
|
|
1441
1633
|
);
|
|
1442
|
-
const
|
|
1634
|
+
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
1635
|
+
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1636
|
+
return yield latestRunChatCompletion.current();
|
|
1637
|
+
}), [latestRunChatCompletion]);
|
|
1638
|
+
const reset = (0, import_react12.useCallback)(() => {
|
|
1443
1639
|
latestStopFunc();
|
|
1444
1640
|
setMessages([]);
|
|
1445
1641
|
setThreadId(null);
|
|
1446
1642
|
setRunId(null);
|
|
1447
|
-
|
|
1643
|
+
setCoagentStatesWithRef({});
|
|
1448
1644
|
let initialAgentSession = null;
|
|
1449
1645
|
if (agentLock) {
|
|
1450
1646
|
initialAgentSession = {
|
|
@@ -1452,9 +1648,16 @@ function useCopilotChat(_a = {}) {
|
|
|
1452
1648
|
};
|
|
1453
1649
|
}
|
|
1454
1650
|
setAgentSession(initialAgentSession);
|
|
1455
|
-
}, [
|
|
1651
|
+
}, [
|
|
1652
|
+
latestStopFunc,
|
|
1653
|
+
setMessages,
|
|
1654
|
+
setThreadId,
|
|
1655
|
+
setCoagentStatesWithRef,
|
|
1656
|
+
setAgentSession,
|
|
1657
|
+
agentLock
|
|
1658
|
+
]);
|
|
1456
1659
|
const latestReset = useUpdatedRef(reset);
|
|
1457
|
-
const latestResetFunc = (0,
|
|
1660
|
+
const latestResetFunc = (0, import_react12.useCallback)(() => {
|
|
1458
1661
|
return latestReset.current();
|
|
1459
1662
|
}, [latestReset]);
|
|
1460
1663
|
return {
|
|
@@ -1465,12 +1668,13 @@ function useCopilotChat(_a = {}) {
|
|
|
1465
1668
|
stopGeneration: latestStopFunc,
|
|
1466
1669
|
reset: latestResetFunc,
|
|
1467
1670
|
deleteMessage: latestDeleteFunc,
|
|
1671
|
+
runChatCompletion: latestRunChatCompletionFunc,
|
|
1468
1672
|
isLoading
|
|
1469
1673
|
};
|
|
1470
1674
|
}
|
|
1471
1675
|
function useUpdatedRef(value) {
|
|
1472
|
-
const ref = (0,
|
|
1473
|
-
(0,
|
|
1676
|
+
const ref = (0, import_react12.useRef)(value);
|
|
1677
|
+
(0, import_react12.useEffect)(() => {
|
|
1474
1678
|
ref.current = value;
|
|
1475
1679
|
}, [value]);
|
|
1476
1680
|
return ref;
|
|
@@ -1500,18 +1704,22 @@ ${additionalInstructions}` : "");
|
|
|
1500
1704
|
}
|
|
1501
1705
|
|
|
1502
1706
|
// src/hooks/use-copilot-action.ts
|
|
1503
|
-
var
|
|
1504
|
-
var
|
|
1707
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1708
|
+
var import_react13 = require("react");
|
|
1505
1709
|
function useCopilotAction(action, dependencies) {
|
|
1506
1710
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1507
|
-
const idRef = (0,
|
|
1508
|
-
const renderAndWaitRef = (0,
|
|
1711
|
+
const idRef = (0, import_react13.useRef)((0, import_shared7.randomId)());
|
|
1712
|
+
const renderAndWaitRef = (0, import_react13.useRef)(null);
|
|
1509
1713
|
action = __spreadValues({}, action);
|
|
1510
|
-
if (
|
|
1714
|
+
if (
|
|
1715
|
+
// renderAndWaitForResponse is not available for catch all actions
|
|
1716
|
+
isFrontendAction(action) && // check if renderAndWaitForResponse is set
|
|
1717
|
+
(action.renderAndWait || action.renderAndWaitForResponse)
|
|
1718
|
+
) {
|
|
1511
1719
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
1512
1720
|
action.renderAndWait = void 0;
|
|
1513
1721
|
action.renderAndWaitForResponse = void 0;
|
|
1514
|
-
action.handler = () => __async(this, null, function* () {
|
|
1722
|
+
action.handler = useAsyncCallback(() => __async(this, null, function* () {
|
|
1515
1723
|
let resolve;
|
|
1516
1724
|
let reject;
|
|
1517
1725
|
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
@@ -1520,14 +1728,18 @@ function useCopilotAction(action, dependencies) {
|
|
|
1520
1728
|
});
|
|
1521
1729
|
renderAndWaitRef.current = { promise, resolve, reject };
|
|
1522
1730
|
return yield promise;
|
|
1523
|
-
});
|
|
1731
|
+
}), []);
|
|
1524
1732
|
action.render = (props) => {
|
|
1733
|
+
let status = props.status;
|
|
1734
|
+
if (props.status === "executing" && !renderAndWaitRef.current) {
|
|
1735
|
+
status = "inProgress";
|
|
1736
|
+
}
|
|
1525
1737
|
const waitProps = {
|
|
1526
|
-
status
|
|
1738
|
+
status,
|
|
1527
1739
|
args: props.args,
|
|
1528
1740
|
result: props.result,
|
|
1529
|
-
handler:
|
|
1530
|
-
respond:
|
|
1741
|
+
handler: status === "executing" ? renderAndWaitRef.current.resolve : void 0,
|
|
1742
|
+
respond: status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
1531
1743
|
};
|
|
1532
1744
|
const isNoArgsRenderWait = (_fn) => {
|
|
1533
1745
|
var _a;
|
|
@@ -1540,12 +1752,14 @@ function useCopilotAction(action, dependencies) {
|
|
|
1540
1752
|
return renderAndWait(waitProps);
|
|
1541
1753
|
}
|
|
1542
1754
|
}
|
|
1543
|
-
return (0,
|
|
1755
|
+
return (0, import_react13.createElement)(import_react13.Fragment);
|
|
1544
1756
|
};
|
|
1545
1757
|
}
|
|
1546
1758
|
if (dependencies === void 0) {
|
|
1547
1759
|
if (actions[idRef.current]) {
|
|
1548
|
-
|
|
1760
|
+
if (isFrontendAction(action)) {
|
|
1761
|
+
actions[idRef.current].handler = action.handler;
|
|
1762
|
+
}
|
|
1549
1763
|
if (typeof action.render === "function") {
|
|
1550
1764
|
if (chatComponentsCache.current !== null) {
|
|
1551
1765
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1553,7 +1767,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1553
1767
|
}
|
|
1554
1768
|
}
|
|
1555
1769
|
}
|
|
1556
|
-
(0,
|
|
1770
|
+
(0, import_react13.useEffect)(() => {
|
|
1557
1771
|
setAction(idRef.current, action);
|
|
1558
1772
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1559
1773
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1564,31 +1778,34 @@ function useCopilotAction(action, dependencies) {
|
|
|
1564
1778
|
}, [
|
|
1565
1779
|
setAction,
|
|
1566
1780
|
removeAction,
|
|
1567
|
-
action.description,
|
|
1781
|
+
isFrontendAction(action) ? action.description : void 0,
|
|
1568
1782
|
action.name,
|
|
1569
|
-
action.disabled,
|
|
1570
|
-
action.available,
|
|
1783
|
+
isFrontendAction(action) ? action.disabled : void 0,
|
|
1784
|
+
isFrontendAction(action) ? action.available : void 0,
|
|
1571
1785
|
// This should be faster than deep equality checking
|
|
1572
1786
|
// In addition, all major JS engines guarantee the order of object keys
|
|
1573
|
-
JSON.stringify(action.parameters),
|
|
1787
|
+
JSON.stringify(isFrontendAction(action) ? action.parameters : []),
|
|
1574
1788
|
// include render only if it's a string
|
|
1575
1789
|
typeof action.render === "string" ? action.render : void 0,
|
|
1576
1790
|
// dependencies set by the developer
|
|
1577
1791
|
...dependencies || []
|
|
1578
1792
|
]);
|
|
1579
1793
|
}
|
|
1794
|
+
function isFrontendAction(action) {
|
|
1795
|
+
return action.name !== "*";
|
|
1796
|
+
}
|
|
1580
1797
|
|
|
1581
1798
|
// src/hooks/use-coagent-state-render.ts
|
|
1582
|
-
var
|
|
1583
|
-
var
|
|
1799
|
+
var import_react14 = require("react");
|
|
1800
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1584
1801
|
function useCoAgentStateRender(action, dependencies) {
|
|
1585
1802
|
const {
|
|
1586
1803
|
setCoAgentStateRender,
|
|
1587
1804
|
removeCoAgentStateRender,
|
|
1588
1805
|
coAgentStateRenders,
|
|
1589
1806
|
chatComponentsCache
|
|
1590
|
-
} = (0,
|
|
1591
|
-
const idRef = (0,
|
|
1807
|
+
} = (0, import_react14.useContext)(CopilotContext);
|
|
1808
|
+
const idRef = (0, import_react14.useRef)((0, import_shared8.randomId)());
|
|
1592
1809
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1593
1810
|
if (dependencies === void 0) {
|
|
1594
1811
|
if (coAgentStateRenders[idRef.current]) {
|
|
@@ -1600,7 +1817,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1600
1817
|
}
|
|
1601
1818
|
}
|
|
1602
1819
|
}
|
|
1603
|
-
(0,
|
|
1820
|
+
(0, import_react14.useEffect)(() => {
|
|
1604
1821
|
setCoAgentStateRender(idRef.current, action);
|
|
1605
1822
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1606
1823
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -1620,11 +1837,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1620
1837
|
}
|
|
1621
1838
|
|
|
1622
1839
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1623
|
-
var
|
|
1840
|
+
var import_react15 = require("react");
|
|
1624
1841
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1625
1842
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1626
|
-
const idRef = (0,
|
|
1627
|
-
(0,
|
|
1843
|
+
const idRef = (0, import_react15.useRef)();
|
|
1844
|
+
(0, import_react15.useEffect)(() => {
|
|
1628
1845
|
const id = addDocumentContext(document, categories);
|
|
1629
1846
|
idRef.current = id;
|
|
1630
1847
|
return () => {
|
|
@@ -1635,16 +1852,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1635
1852
|
}
|
|
1636
1853
|
|
|
1637
1854
|
// src/hooks/use-copilot-readable.ts
|
|
1638
|
-
var
|
|
1855
|
+
var import_react16 = require("react");
|
|
1639
1856
|
function convertToJSON(description, value) {
|
|
1640
1857
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1641
1858
|
}
|
|
1642
1859
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
1643
1860
|
const { addContext, removeContext } = useCopilotContext();
|
|
1644
|
-
const idRef = (0,
|
|
1861
|
+
const idRef = (0, import_react16.useRef)();
|
|
1645
1862
|
convert = convert || convertToJSON;
|
|
1646
1863
|
const information = convert(description, value);
|
|
1647
|
-
(0,
|
|
1864
|
+
(0, import_react16.useEffect)(() => {
|
|
1648
1865
|
const id = addContext(information, parentId, categories);
|
|
1649
1866
|
idRef.current = id;
|
|
1650
1867
|
return () => {
|
|
@@ -1655,7 +1872,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1655
1872
|
}
|
|
1656
1873
|
|
|
1657
1874
|
// src/hooks/use-coagent.ts
|
|
1658
|
-
var
|
|
1875
|
+
var import_react17 = require("react");
|
|
1659
1876
|
function useCoAgent(options) {
|
|
1660
1877
|
const isExternalStateManagement = (options2) => {
|
|
1661
1878
|
return "state" in options2 && "setState" in options2;
|
|
@@ -1667,8 +1884,8 @@ function useCoAgent(options) {
|
|
|
1667
1884
|
const generalContext = useCopilotContext();
|
|
1668
1885
|
const messagesContext = useCopilotMessagesContext();
|
|
1669
1886
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1670
|
-
const { coagentStates,
|
|
1671
|
-
const { appendMessage } = useCopilotChat();
|
|
1887
|
+
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
|
|
1888
|
+
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1672
1889
|
const getCoagentState = (coagentStates2, name2) => {
|
|
1673
1890
|
if (coagentStates2[name2]) {
|
|
1674
1891
|
return coagentStates2[name2];
|
|
@@ -1685,19 +1902,17 @@ function useCoAgent(options) {
|
|
|
1685
1902
|
}
|
|
1686
1903
|
};
|
|
1687
1904
|
const setState = (newState) => {
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
});
|
|
1696
|
-
});
|
|
1905
|
+
let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
|
|
1906
|
+
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
1907
|
+
setCoagentStatesWithRef(__spreadProps(__spreadValues({}, coagentStatesRef.current), {
|
|
1908
|
+
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
1909
|
+
state: updatedState
|
|
1910
|
+
})
|
|
1911
|
+
}));
|
|
1697
1912
|
};
|
|
1698
1913
|
const coagentState = getCoagentState(coagentStates, name);
|
|
1699
1914
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
1700
|
-
(0,
|
|
1915
|
+
(0, import_react17.useEffect)(() => {
|
|
1701
1916
|
if (isExternalStateManagement(options)) {
|
|
1702
1917
|
setState(options.state);
|
|
1703
1918
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -1706,23 +1921,24 @@ function useCoAgent(options) {
|
|
|
1706
1921
|
}, [
|
|
1707
1922
|
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
1708
1923
|
// reset initialstate on reset
|
|
1709
|
-
coagentStates === void 0
|
|
1924
|
+
coagentStates[name] === void 0
|
|
1710
1925
|
]);
|
|
1926
|
+
const runAgentCallback = useAsyncCallback(
|
|
1927
|
+
(hint) => __async(this, null, function* () {
|
|
1928
|
+
yield runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
1929
|
+
}),
|
|
1930
|
+
[name, context, appendMessage, runChatCompletion]
|
|
1931
|
+
);
|
|
1711
1932
|
return {
|
|
1712
1933
|
name,
|
|
1713
1934
|
nodeName: coagentState.nodeName,
|
|
1714
|
-
|
|
1715
|
-
setState,
|
|
1935
|
+
threadId: coagentState.threadId,
|
|
1716
1936
|
running: coagentState.running,
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
stop: () =>
|
|
1721
|
-
|
|
1722
|
-
},
|
|
1723
|
-
run: (hint) => {
|
|
1724
|
-
return runAgent(name, context, appendMessage, hint);
|
|
1725
|
-
}
|
|
1937
|
+
state: coagentState.state,
|
|
1938
|
+
setState: isExternalStateManagement(options) ? options.setState : setState,
|
|
1939
|
+
start: () => startAgent(name, context),
|
|
1940
|
+
stop: () => stopAgent(name, context),
|
|
1941
|
+
run: runAgentCallback
|
|
1726
1942
|
};
|
|
1727
1943
|
}
|
|
1728
1944
|
function startAgent(name, context) {
|
|
@@ -1750,7 +1966,7 @@ function stopAgent(name, context) {
|
|
|
1750
1966
|
console.warn(`No agent session found for ${name}`);
|
|
1751
1967
|
}
|
|
1752
1968
|
}
|
|
1753
|
-
function runAgent(name, context, appendMessage, hint) {
|
|
1969
|
+
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
1754
1970
|
return __async(this, null, function* () {
|
|
1755
1971
|
var _a, _b;
|
|
1756
1972
|
const { agentSession, setAgentSession } = context;
|
|
@@ -1766,19 +1982,22 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
1766
1982
|
previousState = message.state;
|
|
1767
1983
|
}
|
|
1768
1984
|
}
|
|
1769
|
-
let state = ((_b = (_a = context.
|
|
1985
|
+
let state = ((_b = (_a = context.coagentStatesRef.current) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
|
|
1770
1986
|
if (hint) {
|
|
1771
1987
|
const hintMessage = hint({ previousState, currentState: state });
|
|
1772
1988
|
if (hintMessage) {
|
|
1773
1989
|
yield appendMessage(hintMessage);
|
|
1990
|
+
} else {
|
|
1991
|
+
yield runChatCompletion();
|
|
1774
1992
|
}
|
|
1993
|
+
} else {
|
|
1994
|
+
yield runChatCompletion();
|
|
1775
1995
|
}
|
|
1776
1996
|
});
|
|
1777
1997
|
}
|
|
1778
1998
|
|
|
1779
1999
|
// src/lib/copilot-task.ts
|
|
1780
|
-
var
|
|
1781
|
-
var import_shared8 = require("@copilotkit/shared");
|
|
2000
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1782
2001
|
var CopilotTask = class {
|
|
1783
2002
|
constructor(config) {
|
|
1784
2003
|
this.instructions = config.instructions;
|
|
@@ -1805,12 +2024,12 @@ var CopilotTask = class {
|
|
|
1805
2024
|
if (this.includeCopilotReadable) {
|
|
1806
2025
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1807
2026
|
}
|
|
1808
|
-
const systemMessage = new
|
|
2027
|
+
const systemMessage = new import_runtime_client_gql7.TextMessage({
|
|
1809
2028
|
content: taskSystemMessage(contextString, this.instructions),
|
|
1810
|
-
role:
|
|
2029
|
+
role: import_runtime_client_gql7.Role.System
|
|
1811
2030
|
});
|
|
1812
2031
|
const messages = [systemMessage];
|
|
1813
|
-
const runtimeClient = new
|
|
2032
|
+
const runtimeClient = new import_runtime_client_gql7.CopilotRuntimeClient({
|
|
1814
2033
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
1815
2034
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
1816
2035
|
headers: context.copilotApiConfig.headers,
|
|
@@ -1819,16 +2038,12 @@ var CopilotTask = class {
|
|
|
1819
2038
|
const response = yield runtimeClient.generateCopilotResponse({
|
|
1820
2039
|
data: {
|
|
1821
2040
|
frontend: {
|
|
1822
|
-
actions: Object.values(actions)
|
|
1823
|
-
name: action.name,
|
|
1824
|
-
description: action.description || "",
|
|
1825
|
-
jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || []))
|
|
1826
|
-
})),
|
|
2041
|
+
actions: processActionsForRuntimeRequest(Object.values(actions)),
|
|
1827
2042
|
url: window.location.href
|
|
1828
2043
|
},
|
|
1829
|
-
messages: (0,
|
|
2044
|
+
messages: (0, import_runtime_client_gql7.convertMessagesToGqlInput)((0, import_runtime_client_gql7.filterAgentStateMessages)(messages)),
|
|
1830
2045
|
metadata: {
|
|
1831
|
-
requestType:
|
|
2046
|
+
requestType: import_runtime_client_gql7.CopilotRequestType.Task
|
|
1832
2047
|
},
|
|
1833
2048
|
forwardedParameters: {
|
|
1834
2049
|
toolChoice: "required"
|
|
@@ -1837,7 +2052,7 @@ var CopilotTask = class {
|
|
|
1837
2052
|
properties: context.copilotApiConfig.properties
|
|
1838
2053
|
}).toPromise();
|
|
1839
2054
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
1840
|
-
const functionCalls = (0,
|
|
2055
|
+
const functionCalls = (0, import_runtime_client_gql7.convertGqlOutputToMessages)(
|
|
1841
2056
|
((_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) || []
|
|
1842
2057
|
).filter((m) => m.isActionExecutionMessage());
|
|
1843
2058
|
for (const functionCall of functionCalls) {
|