@copilotkit/react-core 1.4.8-next.2 → 1.4.8
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 +8 -13
- package/dist/{chunk-DIX6ISOB.mjs → chunk-6EMLM6WX.mjs} +20 -19
- package/dist/chunk-6EMLM6WX.mjs.map +1 -0
- package/dist/{chunk-ODN4H66E.mjs → chunk-7LRDVJH5.mjs} +6 -2
- package/dist/chunk-7LRDVJH5.mjs.map +1 -0
- package/dist/{chunk-XXCJFOLY.mjs → chunk-AG7FH7OD.mjs} +2 -2
- package/dist/{chunk-XYFTGCMS.mjs → chunk-FSC4A3JN.mjs} +18 -14
- package/dist/chunk-FSC4A3JN.mjs.map +1 -0
- package/dist/{chunk-E3HHCHMQ.mjs → chunk-IFTHM7LF.mjs} +7 -10
- package/dist/chunk-IFTHM7LF.mjs.map +1 -0
- package/dist/{chunk-V6CEKRZA.mjs → chunk-IVYL7JRC.mjs} +12 -11
- package/dist/chunk-IVYL7JRC.mjs.map +1 -0
- package/dist/chunk-NTLCOVE5.mjs +321 -0
- package/dist/chunk-NTLCOVE5.mjs.map +1 -0
- package/dist/chunk-QCUP6HLK.mjs +37 -0
- package/dist/chunk-QCUP6HLK.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-CBMCK7UC.mjs → chunk-UOVONDR6.mjs} +2 -2
- package/dist/{chunk-XSORW54K.mjs → chunk-X6ZF5WAX.mjs} +2 -2
- package/dist/{chunk-4P56GAFP.mjs → chunk-XQFVXX6R.mjs} +2 -3
- package/dist/chunk-XQFVXX6R.mjs.map +1 -0
- package/dist/{chunk-ETCKRNXQ.mjs → chunk-YUY5ZAST.mjs} +7 -4
- package/dist/chunk-YUY5ZAST.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.d.ts +0 -1
- package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -5
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +0 -1
- package/dist/components/copilot-provider/copilotkit.js +158 -95
- 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.d.ts +0 -1
- package/dist/components/copilot-provider/index.js +158 -95
- 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.d.ts +0 -1
- package/dist/components/index.js +158 -95
- 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 +1 -5
- package/dist/context/copilot-context.js +1 -2
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +1 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.js +401 -260
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +19 -18
- package/dist/hooks/use-chat.d.ts +1 -2
- package/dist/hooks/use-chat.js +343 -200
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +3 -3
- package/dist/hooks/use-coagent-state-render.js +1 -2
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.js +381 -240
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +9 -8
- package/dist/hooks/use-copilot-action.js +133 -9
- 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.js +370 -230
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +8 -7
- package/dist/hooks/use-copilot-readable.js +1 -2
- 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 +1 -2
- 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 +450 -353
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -19
- package/dist/lib/copilot-task.d.ts +1 -6
- package/dist/lib/copilot-task.js +4 -22
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +6 -5
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +4 -22
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +6 -5
- package/dist/utils/extract.d.ts +2 -3
- package/dist/utils/extract.js +3 -21
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +5 -4
- package/dist/utils/index.js +3 -21
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +5 -4
- package/package.json +3 -3
- package/src/components/copilot-provider/copilotkit-props.tsx +0 -6
- package/src/components/copilot-provider/copilotkit.tsx +4 -2
- 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 +1 -8
- package/src/hooks/use-chat.ts +286 -266
- package/src/hooks/use-coagent.ts +14 -11
- package/src/hooks/use-copilot-action.ts +3 -2
- package/src/hooks/use-copilot-chat.ts +9 -10
- package/src/hooks/use-copilot-runtime-client.ts +4 -0
- package/src/lib/copilot-task.ts +2 -10
- package/src/utils/extract.ts +0 -4
- package/dist/chunk-2KCEHGSI.mjs.map +0 -1
- package/dist/chunk-4P56GAFP.mjs.map +0 -1
- package/dist/chunk-DIX6ISOB.mjs.map +0 -1
- package/dist/chunk-E3HHCHMQ.mjs.map +0 -1
- package/dist/chunk-ETCKRNXQ.mjs.map +0 -1
- package/dist/chunk-ODN4H66E.mjs.map +0 -1
- package/dist/chunk-PG5XEJVS.mjs +0 -295
- package/dist/chunk-PG5XEJVS.mjs.map +0 -1
- package/dist/chunk-V6CEKRZA.mjs.map +0 -1
- package/dist/chunk-XYFTGCMS.mjs.map +0 -1
- /package/dist/{chunk-XXCJFOLY.mjs.map → chunk-AG7FH7OD.mjs.map} +0 -0
- /package/dist/{chunk-CBMCK7UC.mjs.map → chunk-UOVONDR6.mjs.map} +0 -0
- /package/dist/{chunk-XSORW54K.mjs.map → chunk-X6ZF5WAX.mjs.map} +0 -0
|
@@ -86,7 +86,7 @@ __export(copilot_provider_exports, {
|
|
|
86
86
|
module.exports = __toCommonJS(copilot_provider_exports);
|
|
87
87
|
|
|
88
88
|
// src/components/copilot-provider/copilotkit.tsx
|
|
89
|
-
var
|
|
89
|
+
var import_react10 = require("react");
|
|
90
90
|
|
|
91
91
|
// src/context/copilot-context.tsx
|
|
92
92
|
var import_react = __toESM(require("react"));
|
|
@@ -142,8 +142,7 @@ var emptyCopilotContext = {
|
|
|
142
142
|
},
|
|
143
143
|
agentSession: null,
|
|
144
144
|
setAgentSession: () => {
|
|
145
|
-
}
|
|
146
|
-
forwardedParameters: {}
|
|
145
|
+
}
|
|
147
146
|
};
|
|
148
147
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
149
148
|
function returnAndThrowInDebug(value) {
|
|
@@ -381,6 +380,9 @@ function CopilotMessages(_a) {
|
|
|
381
380
|
}
|
|
382
381
|
|
|
383
382
|
// src/components/toast/toast-provider.tsx
|
|
383
|
+
var import_react7 = require("react");
|
|
384
|
+
|
|
385
|
+
// src/components/error-boundary/error-utils.tsx
|
|
384
386
|
var import_react6 = require("react");
|
|
385
387
|
|
|
386
388
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
@@ -410,11 +412,82 @@ var ExclamationMarkIcon = ({
|
|
|
410
412
|
}
|
|
411
413
|
);
|
|
412
414
|
|
|
413
|
-
// src/components/
|
|
415
|
+
// src/components/error-boundary/error-utils.tsx
|
|
414
416
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
415
|
-
|
|
417
|
+
function ErrorToast({ errors }) {
|
|
418
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
419
|
+
var _a, _b, _c;
|
|
420
|
+
const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
|
|
421
|
+
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
422
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
423
|
+
"div",
|
|
424
|
+
{
|
|
425
|
+
style: {
|
|
426
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
427
|
+
marginBottom: 14
|
|
428
|
+
},
|
|
429
|
+
children: [
|
|
430
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
431
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
432
|
+
"div",
|
|
433
|
+
{
|
|
434
|
+
style: {
|
|
435
|
+
fontWeight: "600",
|
|
436
|
+
marginBottom: 4
|
|
437
|
+
},
|
|
438
|
+
children: [
|
|
439
|
+
"Copilot Cloud Error:",
|
|
440
|
+
" ",
|
|
441
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
442
|
+
]
|
|
443
|
+
}
|
|
444
|
+
),
|
|
445
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
446
|
+
]
|
|
447
|
+
},
|
|
448
|
+
idx
|
|
449
|
+
);
|
|
450
|
+
});
|
|
451
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
452
|
+
"div",
|
|
453
|
+
{
|
|
454
|
+
style: {
|
|
455
|
+
fontSize: "13px",
|
|
456
|
+
maxWidth: "600px"
|
|
457
|
+
},
|
|
458
|
+
children: [
|
|
459
|
+
errorsToRender,
|
|
460
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
461
|
+
]
|
|
462
|
+
}
|
|
463
|
+
);
|
|
464
|
+
}
|
|
465
|
+
function useErrorToast() {
|
|
466
|
+
const { addToast } = useToast();
|
|
467
|
+
return (0, import_react6.useCallback)(
|
|
468
|
+
(error) => {
|
|
469
|
+
const errorId = error.map((err) => {
|
|
470
|
+
var _a, _b;
|
|
471
|
+
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
472
|
+
const stack = err.stack || "";
|
|
473
|
+
return btoa(message + stack).slice(0, 32);
|
|
474
|
+
}).join("|");
|
|
475
|
+
addToast({
|
|
476
|
+
type: "error",
|
|
477
|
+
id: errorId,
|
|
478
|
+
// Toast libraries typically dedupe by id
|
|
479
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
480
|
+
});
|
|
481
|
+
},
|
|
482
|
+
[addToast]
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// src/components/toast/toast-provider.tsx
|
|
487
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
488
|
+
var ToastContext = (0, import_react7.createContext)(void 0);
|
|
416
489
|
function useToast() {
|
|
417
|
-
const context = (0,
|
|
490
|
+
const context = (0, import_react7.useContext)(ToastContext);
|
|
418
491
|
if (!context) {
|
|
419
492
|
throw new Error("useToast must be used within a ToastProvider");
|
|
420
493
|
}
|
|
@@ -424,68 +497,28 @@ function ToastProvider({
|
|
|
424
497
|
enabled,
|
|
425
498
|
children
|
|
426
499
|
}) {
|
|
427
|
-
const [toasts, setToasts] = (0,
|
|
428
|
-
const addToast = (0,
|
|
429
|
-
|
|
430
|
-
|
|
500
|
+
const [toasts, setToasts] = (0, import_react7.useState)([]);
|
|
501
|
+
const addToast = (0, import_react7.useCallback)((toast) => {
|
|
502
|
+
var _a;
|
|
503
|
+
const id = (_a = toast.id) != null ? _a : Math.random().toString(36).substring(2, 9);
|
|
504
|
+
setToasts((currentToasts) => {
|
|
505
|
+
if (currentToasts.find((toast2) => toast2.id === id))
|
|
506
|
+
return currentToasts;
|
|
507
|
+
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
508
|
+
});
|
|
431
509
|
if (toast.duration) {
|
|
432
510
|
setTimeout(() => {
|
|
433
511
|
removeToast(id);
|
|
434
512
|
}, toast.duration);
|
|
435
513
|
}
|
|
436
514
|
}, []);
|
|
437
|
-
const addGraphQLErrorsToast = (0,
|
|
438
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
439
|
-
var _a;
|
|
440
|
-
const message = error.message;
|
|
441
|
-
const code = (_a = error.extensions) == null ? void 0 : _a.code;
|
|
442
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
443
|
-
"div",
|
|
444
|
-
{
|
|
445
|
-
style: {
|
|
446
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
447
|
-
marginBottom: 14
|
|
448
|
-
},
|
|
449
|
-
children: [
|
|
450
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
451
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
452
|
-
"div",
|
|
453
|
-
{
|
|
454
|
-
style: {
|
|
455
|
-
fontWeight: "600",
|
|
456
|
-
marginBottom: 4
|
|
457
|
-
},
|
|
458
|
-
children: [
|
|
459
|
-
"Copilot Cloud Error:",
|
|
460
|
-
" ",
|
|
461
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
462
|
-
]
|
|
463
|
-
}
|
|
464
|
-
),
|
|
465
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
466
|
-
]
|
|
467
|
-
},
|
|
468
|
-
idx
|
|
469
|
-
);
|
|
470
|
-
});
|
|
515
|
+
const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
|
|
471
516
|
addToast({
|
|
472
517
|
type: "error",
|
|
473
|
-
message: /* @__PURE__ */ (0,
|
|
474
|
-
"div",
|
|
475
|
-
{
|
|
476
|
-
style: {
|
|
477
|
-
fontSize: "13px",
|
|
478
|
-
maxWidth: "600px"
|
|
479
|
-
},
|
|
480
|
-
children: [
|
|
481
|
-
errorsToRender,
|
|
482
|
-
/* @__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." })
|
|
483
|
-
]
|
|
484
|
-
}
|
|
485
|
-
)
|
|
518
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
|
|
486
519
|
});
|
|
487
520
|
}, []);
|
|
488
|
-
const removeToast = (0,
|
|
521
|
+
const removeToast = (0, import_react7.useCallback)((id) => {
|
|
489
522
|
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
490
523
|
}, []);
|
|
491
524
|
const value = {
|
|
@@ -495,8 +528,8 @@ function ToastProvider({
|
|
|
495
528
|
removeToast,
|
|
496
529
|
enabled
|
|
497
530
|
};
|
|
498
|
-
return /* @__PURE__ */ (0,
|
|
499
|
-
/* @__PURE__ */ (0,
|
|
531
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ToastContext.Provider, { value, children: [
|
|
532
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
500
533
|
"div",
|
|
501
534
|
{
|
|
502
535
|
style: {
|
|
@@ -510,7 +543,7 @@ function ToastProvider({
|
|
|
510
543
|
gap: "0.5rem"
|
|
511
544
|
},
|
|
512
545
|
children: [
|
|
513
|
-
toasts.length > 1 && /* @__PURE__ */ (0,
|
|
546
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
514
547
|
"button",
|
|
515
548
|
{
|
|
516
549
|
onClick: () => setToasts([]),
|
|
@@ -525,7 +558,7 @@ function ToastProvider({
|
|
|
525
558
|
children: "Close All"
|
|
526
559
|
}
|
|
527
560
|
) }),
|
|
528
|
-
toasts.map((toast) => /* @__PURE__ */ (0,
|
|
561
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
529
562
|
Toast,
|
|
530
563
|
{
|
|
531
564
|
message: toast.message,
|
|
@@ -551,7 +584,7 @@ function Toast({
|
|
|
551
584
|
warning: "#eab308",
|
|
552
585
|
error: "#ef4444"
|
|
553
586
|
};
|
|
554
|
-
return /* @__PURE__ */ (0,
|
|
587
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
555
588
|
"div",
|
|
556
589
|
{
|
|
557
590
|
style: {
|
|
@@ -564,8 +597,8 @@ function Toast({
|
|
|
564
597
|
minWidth: "200px"
|
|
565
598
|
},
|
|
566
599
|
children: [
|
|
567
|
-
/* @__PURE__ */ (0,
|
|
568
|
-
/* @__PURE__ */ (0,
|
|
600
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
|
|
601
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
569
602
|
"button",
|
|
570
603
|
{
|
|
571
604
|
onClick: onClose,
|
|
@@ -590,14 +623,17 @@ function Toast({
|
|
|
590
623
|
|
|
591
624
|
// src/hooks/use-copilot-runtime-client.ts
|
|
592
625
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
593
|
-
var
|
|
626
|
+
var import_react8 = require("react");
|
|
594
627
|
var useCopilotRuntimeClient = (options) => {
|
|
595
628
|
const { addGraphQLErrorsToast } = useToast();
|
|
596
|
-
const
|
|
629
|
+
const addErrorToast = useErrorToast();
|
|
630
|
+
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
597
631
|
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
598
632
|
handleGQLErrors: (error) => {
|
|
599
633
|
if (error.graphQLErrors.length) {
|
|
600
634
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
635
|
+
} else {
|
|
636
|
+
addErrorToast([error]);
|
|
601
637
|
}
|
|
602
638
|
}
|
|
603
639
|
}));
|
|
@@ -619,13 +655,41 @@ function getHostname() {
|
|
|
619
655
|
return "";
|
|
620
656
|
}
|
|
621
657
|
|
|
658
|
+
// src/components/error-boundary/error-boundary.tsx
|
|
659
|
+
var import_react9 = __toESM(require("react"));
|
|
660
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
661
|
+
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
662
|
+
constructor(props) {
|
|
663
|
+
super(props);
|
|
664
|
+
this.state = { hasError: false };
|
|
665
|
+
}
|
|
666
|
+
static getDerivedStateFromError(error) {
|
|
667
|
+
return { hasError: true, error };
|
|
668
|
+
}
|
|
669
|
+
componentDidCatch(error, errorInfo) {
|
|
670
|
+
console.error("CopilotKit Error:", error, errorInfo);
|
|
671
|
+
}
|
|
672
|
+
render() {
|
|
673
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
|
|
674
|
+
}
|
|
675
|
+
};
|
|
676
|
+
function ErrorToast2({ error, children }) {
|
|
677
|
+
const addErrorToast = useErrorToast();
|
|
678
|
+
(0, import_react9.useEffect)(() => {
|
|
679
|
+
if (error) {
|
|
680
|
+
addErrorToast([error]);
|
|
681
|
+
}
|
|
682
|
+
}, [error, addErrorToast]);
|
|
683
|
+
return children;
|
|
684
|
+
}
|
|
685
|
+
|
|
622
686
|
// src/components/copilot-provider/copilotkit.tsx
|
|
623
|
-
var
|
|
687
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
624
688
|
function CopilotKit(_a) {
|
|
625
689
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
626
690
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
627
691
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
628
|
-
return /* @__PURE__ */ (0,
|
|
692
|
+
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 })) }) });
|
|
629
693
|
}
|
|
630
694
|
function CopilotKitInternal(_a) {
|
|
631
695
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
@@ -635,49 +699,49 @@ function CopilotKitInternal(_a) {
|
|
|
635
699
|
);
|
|
636
700
|
}
|
|
637
701
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
638
|
-
const [actions, setActions] = (0,
|
|
639
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
640
|
-
const chatComponentsCache = (0,
|
|
702
|
+
const [actions, setActions] = (0, import_react10.useState)({});
|
|
703
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
|
|
704
|
+
const chatComponentsCache = (0, import_react10.useRef)({
|
|
641
705
|
actions: {},
|
|
642
706
|
coAgentStateRenders: {}
|
|
643
707
|
});
|
|
644
708
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
645
|
-
const [isLoading, setIsLoading] = (0,
|
|
646
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
709
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
710
|
+
const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
|
|
647
711
|
const {
|
|
648
712
|
addElement: addDocument,
|
|
649
713
|
removeElement: removeDocument,
|
|
650
714
|
allElements: allDocuments
|
|
651
715
|
} = use_flat_category_store_default();
|
|
652
|
-
const setAction = (0,
|
|
716
|
+
const setAction = (0, import_react10.useCallback)((id, action) => {
|
|
653
717
|
setActions((prevPoints) => {
|
|
654
718
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
655
719
|
[id]: action
|
|
656
720
|
});
|
|
657
721
|
});
|
|
658
722
|
}, []);
|
|
659
|
-
const removeAction = (0,
|
|
723
|
+
const removeAction = (0, import_react10.useCallback)((id) => {
|
|
660
724
|
setActions((prevPoints) => {
|
|
661
725
|
const newPoints = __spreadValues({}, prevPoints);
|
|
662
726
|
delete newPoints[id];
|
|
663
727
|
return newPoints;
|
|
664
728
|
});
|
|
665
729
|
}, []);
|
|
666
|
-
const setCoAgentStateRender = (0,
|
|
730
|
+
const setCoAgentStateRender = (0, import_react10.useCallback)((id, stateRender) => {
|
|
667
731
|
setCoAgentStateRenders((prevPoints) => {
|
|
668
732
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
669
733
|
[id]: stateRender
|
|
670
734
|
});
|
|
671
735
|
});
|
|
672
736
|
}, []);
|
|
673
|
-
const removeCoAgentStateRender = (0,
|
|
737
|
+
const removeCoAgentStateRender = (0, import_react10.useCallback)((id) => {
|
|
674
738
|
setCoAgentStateRenders((prevPoints) => {
|
|
675
739
|
const newPoints = __spreadValues({}, prevPoints);
|
|
676
740
|
delete newPoints[id];
|
|
677
741
|
return newPoints;
|
|
678
742
|
});
|
|
679
743
|
}, []);
|
|
680
|
-
const getContextString = (0,
|
|
744
|
+
const getContextString = (0, import_react10.useCallback)(
|
|
681
745
|
(documents, categories) => {
|
|
682
746
|
const documentsString = documents.map((document) => {
|
|
683
747
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -690,37 +754,37 @@ ${nonDocumentStrings}`;
|
|
|
690
754
|
},
|
|
691
755
|
[printTree]
|
|
692
756
|
);
|
|
693
|
-
const addContext = (0,
|
|
757
|
+
const addContext = (0, import_react10.useCallback)(
|
|
694
758
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
695
759
|
return addElement(context, categories, parentId);
|
|
696
760
|
},
|
|
697
761
|
[addElement]
|
|
698
762
|
);
|
|
699
|
-
const removeContext = (0,
|
|
763
|
+
const removeContext = (0, import_react10.useCallback)(
|
|
700
764
|
(id) => {
|
|
701
765
|
removeElement(id);
|
|
702
766
|
},
|
|
703
767
|
[removeElement]
|
|
704
768
|
);
|
|
705
|
-
const getFunctionCallHandler = (0,
|
|
769
|
+
const getFunctionCallHandler = (0, import_react10.useCallback)(
|
|
706
770
|
(customEntryPoints) => {
|
|
707
771
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
708
772
|
},
|
|
709
773
|
[actions]
|
|
710
774
|
);
|
|
711
|
-
const getDocumentsContext = (0,
|
|
775
|
+
const getDocumentsContext = (0, import_react10.useCallback)(
|
|
712
776
|
(categories) => {
|
|
713
777
|
return allDocuments(categories);
|
|
714
778
|
},
|
|
715
779
|
[allDocuments]
|
|
716
780
|
);
|
|
717
|
-
const addDocumentContext = (0,
|
|
781
|
+
const addDocumentContext = (0, import_react10.useCallback)(
|
|
718
782
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
719
783
|
return addDocument(documentPointer, categories);
|
|
720
784
|
},
|
|
721
785
|
[addDocument]
|
|
722
786
|
);
|
|
723
|
-
const removeDocumentContext = (0,
|
|
787
|
+
const removeDocumentContext = (0, import_react10.useCallback)(
|
|
724
788
|
(documentId) => {
|
|
725
789
|
removeDocument(documentId);
|
|
726
790
|
},
|
|
@@ -733,7 +797,7 @@ ${nonDocumentStrings}`;
|
|
|
733
797
|
);
|
|
734
798
|
}
|
|
735
799
|
}
|
|
736
|
-
const copilotApiConfig = (0,
|
|
800
|
+
const copilotApiConfig = (0, import_react10.useMemo)(() => {
|
|
737
801
|
var _a2, _b2;
|
|
738
802
|
let cloud = void 0;
|
|
739
803
|
if (props.publicApiKey) {
|
|
@@ -775,7 +839,7 @@ ${nonDocumentStrings}`;
|
|
|
775
839
|
headers,
|
|
776
840
|
credentials: copilotApiConfig.credentials
|
|
777
841
|
});
|
|
778
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
842
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
779
843
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
780
844
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
781
845
|
};
|
|
@@ -785,9 +849,9 @@ ${nonDocumentStrings}`;
|
|
|
785
849
|
return rest;
|
|
786
850
|
});
|
|
787
851
|
};
|
|
788
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
789
|
-
const coagentStatesRef = (0,
|
|
790
|
-
const setCoagentStatesWithRef = (0,
|
|
852
|
+
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
853
|
+
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
854
|
+
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
791
855
|
(value) => {
|
|
792
856
|
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
793
857
|
coagentStatesRef.current = newValue;
|
|
@@ -803,9 +867,9 @@ ${nonDocumentStrings}`;
|
|
|
803
867
|
agentName: props.agent
|
|
804
868
|
};
|
|
805
869
|
}
|
|
806
|
-
const [agentSession, setAgentSession] = (0,
|
|
870
|
+
const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
|
|
807
871
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
808
|
-
return /* @__PURE__ */ (0,
|
|
872
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
809
873
|
CopilotContext.Provider,
|
|
810
874
|
{
|
|
811
875
|
value: {
|
|
@@ -838,10 +902,9 @@ ${nonDocumentStrings}`;
|
|
|
838
902
|
setCoagentStatesWithRef,
|
|
839
903
|
agentSession,
|
|
840
904
|
setAgentSession,
|
|
841
|
-
runtimeClient
|
|
842
|
-
forwardedParameters: props.forwardedParameters || {}
|
|
905
|
+
runtimeClient
|
|
843
906
|
},
|
|
844
|
-
children: /* @__PURE__ */ (0,
|
|
907
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
|
|
845
908
|
}
|
|
846
909
|
);
|
|
847
910
|
}
|