@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
|
@@ -85,7 +85,7 @@ __export(copilotkit_exports, {
|
|
|
85
85
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories
|
|
86
86
|
});
|
|
87
87
|
module.exports = __toCommonJS(copilotkit_exports);
|
|
88
|
-
var
|
|
88
|
+
var import_react10 = require("react");
|
|
89
89
|
|
|
90
90
|
// src/context/copilot-context.tsx
|
|
91
91
|
var import_react = __toESM(require("react"));
|
|
@@ -136,6 +136,9 @@ var emptyCopilotContext = {
|
|
|
136
136
|
coagentStates: {},
|
|
137
137
|
setCoagentStates: () => {
|
|
138
138
|
},
|
|
139
|
+
coagentStatesRef: { current: {} },
|
|
140
|
+
setCoagentStatesWithRef: () => {
|
|
141
|
+
},
|
|
139
142
|
agentSession: null,
|
|
140
143
|
setAgentSession: () => {
|
|
141
144
|
},
|
|
@@ -384,6 +387,9 @@ function CopilotMessages(_a) {
|
|
|
384
387
|
}
|
|
385
388
|
|
|
386
389
|
// src/components/toast/toast-provider.tsx
|
|
390
|
+
var import_react7 = require("react");
|
|
391
|
+
|
|
392
|
+
// src/components/error-boundary/error-utils.tsx
|
|
387
393
|
var import_react6 = require("react");
|
|
388
394
|
|
|
389
395
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
@@ -413,11 +419,82 @@ var ExclamationMarkIcon = ({
|
|
|
413
419
|
}
|
|
414
420
|
);
|
|
415
421
|
|
|
416
|
-
// src/components/
|
|
422
|
+
// src/components/error-boundary/error-utils.tsx
|
|
417
423
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
418
|
-
|
|
424
|
+
function ErrorToast({ errors }) {
|
|
425
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
426
|
+
var _a, _b, _c;
|
|
427
|
+
const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
|
|
428
|
+
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
429
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
430
|
+
"div",
|
|
431
|
+
{
|
|
432
|
+
style: {
|
|
433
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
434
|
+
marginBottom: 14
|
|
435
|
+
},
|
|
436
|
+
children: [
|
|
437
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
438
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
439
|
+
"div",
|
|
440
|
+
{
|
|
441
|
+
style: {
|
|
442
|
+
fontWeight: "600",
|
|
443
|
+
marginBottom: 4
|
|
444
|
+
},
|
|
445
|
+
children: [
|
|
446
|
+
"Copilot Cloud Error:",
|
|
447
|
+
" ",
|
|
448
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
449
|
+
]
|
|
450
|
+
}
|
|
451
|
+
),
|
|
452
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
453
|
+
]
|
|
454
|
+
},
|
|
455
|
+
idx
|
|
456
|
+
);
|
|
457
|
+
});
|
|
458
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
459
|
+
"div",
|
|
460
|
+
{
|
|
461
|
+
style: {
|
|
462
|
+
fontSize: "13px",
|
|
463
|
+
maxWidth: "600px"
|
|
464
|
+
},
|
|
465
|
+
children: [
|
|
466
|
+
errorsToRender,
|
|
467
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
468
|
+
]
|
|
469
|
+
}
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
function useErrorToast() {
|
|
473
|
+
const { addToast } = useToast();
|
|
474
|
+
return (0, import_react6.useCallback)(
|
|
475
|
+
(error) => {
|
|
476
|
+
const errorId = error.map((err) => {
|
|
477
|
+
var _a, _b;
|
|
478
|
+
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
479
|
+
const stack = err.stack || "";
|
|
480
|
+
return btoa(message + stack).slice(0, 32);
|
|
481
|
+
}).join("|");
|
|
482
|
+
addToast({
|
|
483
|
+
type: "error",
|
|
484
|
+
id: errorId,
|
|
485
|
+
// Toast libraries typically dedupe by id
|
|
486
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
[addToast]
|
|
490
|
+
);
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
// src/components/toast/toast-provider.tsx
|
|
494
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
495
|
+
var ToastContext = (0, import_react7.createContext)(void 0);
|
|
419
496
|
function useToast() {
|
|
420
|
-
const context = (0,
|
|
497
|
+
const context = (0, import_react7.useContext)(ToastContext);
|
|
421
498
|
if (!context) {
|
|
422
499
|
throw new Error("useToast must be used within a ToastProvider");
|
|
423
500
|
}
|
|
@@ -427,68 +504,28 @@ function ToastProvider({
|
|
|
427
504
|
enabled,
|
|
428
505
|
children
|
|
429
506
|
}) {
|
|
430
|
-
const [toasts, setToasts] = (0,
|
|
431
|
-
const addToast = (0,
|
|
432
|
-
|
|
433
|
-
|
|
507
|
+
const [toasts, setToasts] = (0, import_react7.useState)([]);
|
|
508
|
+
const addToast = (0, import_react7.useCallback)((toast) => {
|
|
509
|
+
var _a;
|
|
510
|
+
const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
|
|
511
|
+
setToasts((currentToasts) => {
|
|
512
|
+
if (currentToasts.find((toast2) => toast2.id === id))
|
|
513
|
+
return currentToasts;
|
|
514
|
+
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
515
|
+
});
|
|
434
516
|
if (toast.duration) {
|
|
435
517
|
setTimeout(() => {
|
|
436
518
|
removeToast(id);
|
|
437
519
|
}, toast.duration);
|
|
438
520
|
}
|
|
439
521
|
}, []);
|
|
440
|
-
const addGraphQLErrorsToast = (0,
|
|
441
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
442
|
-
var _a;
|
|
443
|
-
const message = error.message;
|
|
444
|
-
const code = (_a = error.extensions) == null ? void 0 : _a.code;
|
|
445
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
446
|
-
"div",
|
|
447
|
-
{
|
|
448
|
-
style: {
|
|
449
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
450
|
-
marginBottom: 14
|
|
451
|
-
},
|
|
452
|
-
children: [
|
|
453
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
454
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
455
|
-
"div",
|
|
456
|
-
{
|
|
457
|
-
style: {
|
|
458
|
-
fontWeight: "600",
|
|
459
|
-
marginBottom: 4
|
|
460
|
-
},
|
|
461
|
-
children: [
|
|
462
|
-
"Copilot Cloud Error:",
|
|
463
|
-
" ",
|
|
464
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
465
|
-
]
|
|
466
|
-
}
|
|
467
|
-
),
|
|
468
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
469
|
-
]
|
|
470
|
-
},
|
|
471
|
-
idx
|
|
472
|
-
);
|
|
473
|
-
});
|
|
522
|
+
const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
|
|
474
523
|
addToast({
|
|
475
524
|
type: "error",
|
|
476
|
-
message: /* @__PURE__ */ (0,
|
|
477
|
-
"div",
|
|
478
|
-
{
|
|
479
|
-
style: {
|
|
480
|
-
fontSize: "13px",
|
|
481
|
-
maxWidth: "600px"
|
|
482
|
-
},
|
|
483
|
-
children: [
|
|
484
|
-
errorsToRender,
|
|
485
|
-
/* @__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." })
|
|
486
|
-
]
|
|
487
|
-
}
|
|
488
|
-
)
|
|
525
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
|
|
489
526
|
});
|
|
490
527
|
}, []);
|
|
491
|
-
const removeToast = (0,
|
|
528
|
+
const removeToast = (0, import_react7.useCallback)((id) => {
|
|
492
529
|
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
493
530
|
}, []);
|
|
494
531
|
const value = {
|
|
@@ -498,8 +535,8 @@ function ToastProvider({
|
|
|
498
535
|
removeToast,
|
|
499
536
|
enabled
|
|
500
537
|
};
|
|
501
|
-
return /* @__PURE__ */ (0,
|
|
502
|
-
/* @__PURE__ */ (0,
|
|
538
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ToastContext.Provider, { value, children: [
|
|
539
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
503
540
|
"div",
|
|
504
541
|
{
|
|
505
542
|
style: {
|
|
@@ -513,7 +550,7 @@ function ToastProvider({
|
|
|
513
550
|
gap: "0.5rem"
|
|
514
551
|
},
|
|
515
552
|
children: [
|
|
516
|
-
toasts.length > 1 && /* @__PURE__ */ (0,
|
|
553
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
517
554
|
"button",
|
|
518
555
|
{
|
|
519
556
|
onClick: () => setToasts([]),
|
|
@@ -528,7 +565,7 @@ function ToastProvider({
|
|
|
528
565
|
children: "Close All"
|
|
529
566
|
}
|
|
530
567
|
) }),
|
|
531
|
-
toasts.map((toast) => /* @__PURE__ */ (0,
|
|
568
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
532
569
|
Toast,
|
|
533
570
|
{
|
|
534
571
|
message: toast.message,
|
|
@@ -554,7 +591,7 @@ function Toast({
|
|
|
554
591
|
warning: "#eab308",
|
|
555
592
|
error: "#ef4444"
|
|
556
593
|
};
|
|
557
|
-
return /* @__PURE__ */ (0,
|
|
594
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
558
595
|
"div",
|
|
559
596
|
{
|
|
560
597
|
style: {
|
|
@@ -567,8 +604,8 @@ function Toast({
|
|
|
567
604
|
minWidth: "200px"
|
|
568
605
|
},
|
|
569
606
|
children: [
|
|
570
|
-
/* @__PURE__ */ (0,
|
|
571
|
-
/* @__PURE__ */ (0,
|
|
607
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
|
|
608
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
572
609
|
"button",
|
|
573
610
|
{
|
|
574
611
|
onClick: onClose,
|
|
@@ -593,14 +630,17 @@ function Toast({
|
|
|
593
630
|
|
|
594
631
|
// src/hooks/use-copilot-runtime-client.ts
|
|
595
632
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
596
|
-
var
|
|
633
|
+
var import_react8 = require("react");
|
|
597
634
|
var useCopilotRuntimeClient = (options) => {
|
|
598
635
|
const { addGraphQLErrorsToast } = useToast();
|
|
599
|
-
const
|
|
636
|
+
const addErrorToast = useErrorToast();
|
|
637
|
+
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
600
638
|
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
601
639
|
handleGQLErrors: (error) => {
|
|
602
640
|
if (error.graphQLErrors.length) {
|
|
603
641
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
642
|
+
} else {
|
|
643
|
+
addErrorToast([error]);
|
|
604
644
|
}
|
|
605
645
|
}
|
|
606
646
|
}));
|
|
@@ -622,13 +662,41 @@ function getHostname() {
|
|
|
622
662
|
return "";
|
|
623
663
|
}
|
|
624
664
|
|
|
665
|
+
// src/components/error-boundary/error-boundary.tsx
|
|
666
|
+
var import_react9 = __toESM(require("react"));
|
|
667
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
668
|
+
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
669
|
+
constructor(props) {
|
|
670
|
+
super(props);
|
|
671
|
+
this.state = { hasError: false };
|
|
672
|
+
}
|
|
673
|
+
static getDerivedStateFromError(error) {
|
|
674
|
+
return { hasError: true, error };
|
|
675
|
+
}
|
|
676
|
+
componentDidCatch(error, errorInfo) {
|
|
677
|
+
console.error("CopilotKit Error:", error, errorInfo);
|
|
678
|
+
}
|
|
679
|
+
render() {
|
|
680
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
|
|
681
|
+
}
|
|
682
|
+
};
|
|
683
|
+
function ErrorToast2({ error, children }) {
|
|
684
|
+
const addErrorToast = useErrorToast();
|
|
685
|
+
(0, import_react9.useEffect)(() => {
|
|
686
|
+
if (error) {
|
|
687
|
+
addErrorToast([error]);
|
|
688
|
+
}
|
|
689
|
+
}, [error, addErrorToast]);
|
|
690
|
+
return children;
|
|
691
|
+
}
|
|
692
|
+
|
|
625
693
|
// src/components/copilot-provider/copilotkit.tsx
|
|
626
|
-
var
|
|
694
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
627
695
|
function CopilotKit(_a) {
|
|
628
696
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
629
697
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
630
698
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
631
|
-
return /* @__PURE__ */ (0,
|
|
699
|
+
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 })) }) });
|
|
632
700
|
}
|
|
633
701
|
function CopilotKitInternal(_a) {
|
|
634
702
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
@@ -638,49 +706,49 @@ function CopilotKitInternal(_a) {
|
|
|
638
706
|
);
|
|
639
707
|
}
|
|
640
708
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
641
|
-
const [actions, setActions] = (0,
|
|
642
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
643
|
-
const chatComponentsCache = (0,
|
|
709
|
+
const [actions, setActions] = (0, import_react10.useState)({});
|
|
710
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
|
|
711
|
+
const chatComponentsCache = (0, import_react10.useRef)({
|
|
644
712
|
actions: {},
|
|
645
713
|
coAgentStateRenders: {}
|
|
646
714
|
});
|
|
647
715
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
648
|
-
const [isLoading, setIsLoading] = (0,
|
|
649
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
716
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
717
|
+
const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
|
|
650
718
|
const {
|
|
651
719
|
addElement: addDocument,
|
|
652
720
|
removeElement: removeDocument,
|
|
653
721
|
allElements: allDocuments
|
|
654
722
|
} = use_flat_category_store_default();
|
|
655
|
-
const setAction = (0,
|
|
723
|
+
const setAction = (0, import_react10.useCallback)((id, action) => {
|
|
656
724
|
setActions((prevPoints) => {
|
|
657
725
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
658
726
|
[id]: action
|
|
659
727
|
});
|
|
660
728
|
});
|
|
661
729
|
}, []);
|
|
662
|
-
const removeAction = (0,
|
|
730
|
+
const removeAction = (0, import_react10.useCallback)((id) => {
|
|
663
731
|
setActions((prevPoints) => {
|
|
664
732
|
const newPoints = __spreadValues({}, prevPoints);
|
|
665
733
|
delete newPoints[id];
|
|
666
734
|
return newPoints;
|
|
667
735
|
});
|
|
668
736
|
}, []);
|
|
669
|
-
const setCoAgentStateRender = (0,
|
|
737
|
+
const setCoAgentStateRender = (0, import_react10.useCallback)((id, stateRender) => {
|
|
670
738
|
setCoAgentStateRenders((prevPoints) => {
|
|
671
739
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
672
740
|
[id]: stateRender
|
|
673
741
|
});
|
|
674
742
|
});
|
|
675
743
|
}, []);
|
|
676
|
-
const removeCoAgentStateRender = (0,
|
|
744
|
+
const removeCoAgentStateRender = (0, import_react10.useCallback)((id) => {
|
|
677
745
|
setCoAgentStateRenders((prevPoints) => {
|
|
678
746
|
const newPoints = __spreadValues({}, prevPoints);
|
|
679
747
|
delete newPoints[id];
|
|
680
748
|
return newPoints;
|
|
681
749
|
});
|
|
682
750
|
}, []);
|
|
683
|
-
const getContextString = (0,
|
|
751
|
+
const getContextString = (0, import_react10.useCallback)(
|
|
684
752
|
(documents, categories) => {
|
|
685
753
|
const documentsString = documents.map((document) => {
|
|
686
754
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -693,37 +761,37 @@ ${nonDocumentStrings}`;
|
|
|
693
761
|
},
|
|
694
762
|
[printTree]
|
|
695
763
|
);
|
|
696
|
-
const addContext = (0,
|
|
764
|
+
const addContext = (0, import_react10.useCallback)(
|
|
697
765
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
698
766
|
return addElement(context, categories, parentId);
|
|
699
767
|
},
|
|
700
768
|
[addElement]
|
|
701
769
|
);
|
|
702
|
-
const removeContext = (0,
|
|
770
|
+
const removeContext = (0, import_react10.useCallback)(
|
|
703
771
|
(id) => {
|
|
704
772
|
removeElement(id);
|
|
705
773
|
},
|
|
706
774
|
[removeElement]
|
|
707
775
|
);
|
|
708
|
-
const getFunctionCallHandler = (0,
|
|
776
|
+
const getFunctionCallHandler = (0, import_react10.useCallback)(
|
|
709
777
|
(customEntryPoints) => {
|
|
710
778
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
711
779
|
},
|
|
712
780
|
[actions]
|
|
713
781
|
);
|
|
714
|
-
const getDocumentsContext = (0,
|
|
782
|
+
const getDocumentsContext = (0, import_react10.useCallback)(
|
|
715
783
|
(categories) => {
|
|
716
784
|
return allDocuments(categories);
|
|
717
785
|
},
|
|
718
786
|
[allDocuments]
|
|
719
787
|
);
|
|
720
|
-
const addDocumentContext = (0,
|
|
788
|
+
const addDocumentContext = (0, import_react10.useCallback)(
|
|
721
789
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
722
790
|
return addDocument(documentPointer, categories);
|
|
723
791
|
},
|
|
724
792
|
[addDocument]
|
|
725
793
|
);
|
|
726
|
-
const removeDocumentContext = (0,
|
|
794
|
+
const removeDocumentContext = (0, import_react10.useCallback)(
|
|
727
795
|
(documentId) => {
|
|
728
796
|
removeDocument(documentId);
|
|
729
797
|
},
|
|
@@ -736,7 +804,7 @@ ${nonDocumentStrings}`;
|
|
|
736
804
|
);
|
|
737
805
|
}
|
|
738
806
|
}
|
|
739
|
-
const copilotApiConfig = (0,
|
|
807
|
+
const copilotApiConfig = (0, import_react10.useMemo)(() => {
|
|
740
808
|
var _a2, _b2;
|
|
741
809
|
let cloud = void 0;
|
|
742
810
|
if (props.publicApiKey) {
|
|
@@ -778,7 +846,7 @@ ${nonDocumentStrings}`;
|
|
|
778
846
|
headers,
|
|
779
847
|
credentials: copilotApiConfig.credentials
|
|
780
848
|
});
|
|
781
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
849
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
782
850
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
783
851
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
784
852
|
};
|
|
@@ -788,19 +856,30 @@ ${nonDocumentStrings}`;
|
|
|
788
856
|
return rest;
|
|
789
857
|
});
|
|
790
858
|
};
|
|
791
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
859
|
+
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
860
|
+
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
861
|
+
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
862
|
+
(value) => {
|
|
863
|
+
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
864
|
+
coagentStatesRef.current = newValue;
|
|
865
|
+
setCoagentStates((prev) => {
|
|
866
|
+
return newValue;
|
|
867
|
+
});
|
|
868
|
+
},
|
|
869
|
+
[]
|
|
870
|
+
);
|
|
792
871
|
let initialAgentSession = null;
|
|
793
872
|
if (props.agent) {
|
|
794
873
|
initialAgentSession = {
|
|
795
874
|
agentName: props.agent
|
|
796
875
|
};
|
|
797
876
|
}
|
|
798
|
-
const [agentSession, setAgentSession] = (0,
|
|
799
|
-
const [threadId, setThreadId] = (0,
|
|
800
|
-
const [runId, setRunId] = (0,
|
|
801
|
-
const chatAbortControllerRef = (0,
|
|
877
|
+
const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
|
|
878
|
+
const [threadId, setThreadId] = (0, import_react10.useState)(null);
|
|
879
|
+
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
880
|
+
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
802
881
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
803
|
-
return /* @__PURE__ */ (0,
|
|
882
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
804
883
|
CopilotContext.Provider,
|
|
805
884
|
{
|
|
806
885
|
value: {
|
|
@@ -829,6 +908,8 @@ ${nonDocumentStrings}`;
|
|
|
829
908
|
showDevConsole,
|
|
830
909
|
coagentStates,
|
|
831
910
|
setCoagentStates,
|
|
911
|
+
coagentStatesRef,
|
|
912
|
+
setCoagentStatesWithRef,
|
|
832
913
|
agentSession,
|
|
833
914
|
setAgentSession,
|
|
834
915
|
runtimeClient,
|
|
@@ -839,7 +920,7 @@ ${nonDocumentStrings}`;
|
|
|
839
920
|
setRunId,
|
|
840
921
|
chatAbortControllerRef
|
|
841
922
|
},
|
|
842
|
-
children: /* @__PURE__ */ (0,
|
|
923
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
|
|
843
924
|
}
|
|
844
925
|
);
|
|
845
926
|
}
|