@copilotkit/react-core 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.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 +22 -3
- package/dist/{chunk-JHEAUB3Z.mjs → chunk-35EN6BG4.mjs} +2 -2
- package/dist/{chunk-JHEAUB3Z.mjs.map → chunk-35EN6BG4.mjs.map} +1 -1
- package/dist/{chunk-O22KGHOQ.mjs → chunk-42N5VKIX.mjs} +38 -16
- package/dist/chunk-42N5VKIX.mjs.map +1 -0
- package/dist/{chunk-AG7FH7OD.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-Y7MI4PBB.mjs → chunk-ALR5W5JK.mjs} +22 -10
- package/dist/chunk-ALR5W5JK.mjs.map +1 -0
- package/dist/{chunk-XBVKTDXP.mjs → chunk-BT6WK2JZ.mjs} +57 -17
- package/dist/chunk-BT6WK2JZ.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-OT67R4NB.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-XQFVXX6R.mjs → chunk-TQN3EZWQ.mjs} +10 -2
- package/dist/chunk-TQN3EZWQ.mjs.map +1 -0
- package/dist/{chunk-UOVONDR6.mjs → chunk-V3PFWGIY.mjs} +2 -2
- package/dist/{chunk-DHGXL5PC.mjs → chunk-VMP6JWBB.mjs} +18 -6
- 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 +175 -93
- 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 +175 -93
- 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 +175 -93
- 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 +8 -2
- package/dist/context/copilot-context.js +9 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +9 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +584 -270
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +19 -11
- package/dist/hooks/use-chat.d.ts +20 -0
- package/dist/hooks/use-chat.js +438 -200
- 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 +9 -1
- 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 +14 -1
- package/dist/hooks/use-coagent.js +547 -242
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +15 -7
- package/dist/hooks/use-copilot-action.d.ts +12 -2
- package/dist/hooks/use-copilot-action.js +156 -14
- 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 +514 -231
- 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 +9 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.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 +9 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +642 -363
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -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 +3 -3
- package/src/components/copilot-provider/copilotkit.tsx +14 -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 +30 -2
- package/src/hooks/index.ts +1 -1
- package/src/hooks/use-chat.ts +391 -256
- package/src/hooks/use-coagent-state-render.ts +2 -2
- package/src/hooks/use-coagent.ts +35 -15
- package/src/hooks/use-copilot-action.ts +41 -12
- package/src/hooks/use-copilot-chat.ts +52 -11
- 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-2KCEHGSI.mjs.map +0 -1
- package/dist/chunk-DHGXL5PC.mjs.map +0 -1
- package/dist/chunk-EUIBVFV6.mjs +0 -294
- package/dist/chunk-EUIBVFV6.mjs.map +0 -1
- package/dist/chunk-O22KGHOQ.mjs.map +0 -1
- package/dist/chunk-ODN4H66E.mjs.map +0 -1
- package/dist/chunk-OT67R4NB.mjs.map +0 -1
- package/dist/chunk-XBVKTDXP.mjs.map +0 -1
- package/dist/chunk-XQFVXX6R.mjs.map +0 -1
- package/dist/chunk-Y7MI4PBB.mjs.map +0 -1
- /package/dist/{chunk-AG7FH7OD.mjs.map → chunk-5FYKUKG3.mjs.map} +0 -0
- /package/dist/{chunk-UOVONDR6.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"));
|
|
@@ -141,7 +141,15 @@ var emptyCopilotContext = {
|
|
|
141
141
|
},
|
|
142
142
|
agentSession: null,
|
|
143
143
|
setAgentSession: () => {
|
|
144
|
-
}
|
|
144
|
+
},
|
|
145
|
+
agentLock: null,
|
|
146
|
+
threadId: null,
|
|
147
|
+
setThreadId: () => {
|
|
148
|
+
},
|
|
149
|
+
runId: null,
|
|
150
|
+
setRunId: () => {
|
|
151
|
+
},
|
|
152
|
+
chatAbortControllerRef: { current: null }
|
|
145
153
|
};
|
|
146
154
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
147
155
|
function returnAndThrowInDebug(value) {
|
|
@@ -379,6 +387,9 @@ function CopilotMessages(_a) {
|
|
|
379
387
|
}
|
|
380
388
|
|
|
381
389
|
// src/components/toast/toast-provider.tsx
|
|
390
|
+
var import_react7 = require("react");
|
|
391
|
+
|
|
392
|
+
// src/components/error-boundary/error-utils.tsx
|
|
382
393
|
var import_react6 = require("react");
|
|
383
394
|
|
|
384
395
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
@@ -408,11 +419,82 @@ var ExclamationMarkIcon = ({
|
|
|
408
419
|
}
|
|
409
420
|
);
|
|
410
421
|
|
|
411
|
-
// src/components/
|
|
422
|
+
// src/components/error-boundary/error-utils.tsx
|
|
412
423
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
413
|
-
|
|
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);
|
|
414
496
|
function useToast() {
|
|
415
|
-
const context = (0,
|
|
497
|
+
const context = (0, import_react7.useContext)(ToastContext);
|
|
416
498
|
if (!context) {
|
|
417
499
|
throw new Error("useToast must be used within a ToastProvider");
|
|
418
500
|
}
|
|
@@ -422,68 +504,28 @@ function ToastProvider({
|
|
|
422
504
|
enabled,
|
|
423
505
|
children
|
|
424
506
|
}) {
|
|
425
|
-
const [toasts, setToasts] = (0,
|
|
426
|
-
const addToast = (0,
|
|
427
|
-
|
|
428
|
-
|
|
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
|
+
});
|
|
429
516
|
if (toast.duration) {
|
|
430
517
|
setTimeout(() => {
|
|
431
518
|
removeToast(id);
|
|
432
519
|
}, toast.duration);
|
|
433
520
|
}
|
|
434
521
|
}, []);
|
|
435
|
-
const addGraphQLErrorsToast = (0,
|
|
436
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
437
|
-
var _a;
|
|
438
|
-
const message = error.message;
|
|
439
|
-
const code = (_a = error.extensions) == null ? void 0 : _a.code;
|
|
440
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
441
|
-
"div",
|
|
442
|
-
{
|
|
443
|
-
style: {
|
|
444
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
445
|
-
marginBottom: 14
|
|
446
|
-
},
|
|
447
|
-
children: [
|
|
448
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
449
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
450
|
-
"div",
|
|
451
|
-
{
|
|
452
|
-
style: {
|
|
453
|
-
fontWeight: "600",
|
|
454
|
-
marginBottom: 4
|
|
455
|
-
},
|
|
456
|
-
children: [
|
|
457
|
-
"Copilot Cloud Error:",
|
|
458
|
-
" ",
|
|
459
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
460
|
-
]
|
|
461
|
-
}
|
|
462
|
-
),
|
|
463
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
464
|
-
]
|
|
465
|
-
},
|
|
466
|
-
idx
|
|
467
|
-
);
|
|
468
|
-
});
|
|
522
|
+
const addGraphQLErrorsToast = (0, import_react7.useCallback)((errors) => {
|
|
469
523
|
addToast({
|
|
470
524
|
type: "error",
|
|
471
|
-
message: /* @__PURE__ */ (0,
|
|
472
|
-
"div",
|
|
473
|
-
{
|
|
474
|
-
style: {
|
|
475
|
-
fontSize: "13px",
|
|
476
|
-
maxWidth: "600px"
|
|
477
|
-
},
|
|
478
|
-
children: [
|
|
479
|
-
errorsToRender,
|
|
480
|
-
/* @__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." })
|
|
481
|
-
]
|
|
482
|
-
}
|
|
483
|
-
)
|
|
525
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ErrorToast, { errors })
|
|
484
526
|
});
|
|
485
527
|
}, []);
|
|
486
|
-
const removeToast = (0,
|
|
528
|
+
const removeToast = (0, import_react7.useCallback)((id) => {
|
|
487
529
|
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
488
530
|
}, []);
|
|
489
531
|
const value = {
|
|
@@ -493,8 +535,8 @@ function ToastProvider({
|
|
|
493
535
|
removeToast,
|
|
494
536
|
enabled
|
|
495
537
|
};
|
|
496
|
-
return /* @__PURE__ */ (0,
|
|
497
|
-
/* @__PURE__ */ (0,
|
|
538
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ToastContext.Provider, { value, children: [
|
|
539
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
498
540
|
"div",
|
|
499
541
|
{
|
|
500
542
|
style: {
|
|
@@ -508,7 +550,7 @@ function ToastProvider({
|
|
|
508
550
|
gap: "0.5rem"
|
|
509
551
|
},
|
|
510
552
|
children: [
|
|
511
|
-
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)(
|
|
512
554
|
"button",
|
|
513
555
|
{
|
|
514
556
|
onClick: () => setToasts([]),
|
|
@@ -523,7 +565,7 @@ function ToastProvider({
|
|
|
523
565
|
children: "Close All"
|
|
524
566
|
}
|
|
525
567
|
) }),
|
|
526
|
-
toasts.map((toast) => /* @__PURE__ */ (0,
|
|
568
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
527
569
|
Toast,
|
|
528
570
|
{
|
|
529
571
|
message: toast.message,
|
|
@@ -549,7 +591,7 @@ function Toast({
|
|
|
549
591
|
warning: "#eab308",
|
|
550
592
|
error: "#ef4444"
|
|
551
593
|
};
|
|
552
|
-
return /* @__PURE__ */ (0,
|
|
594
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
|
553
595
|
"div",
|
|
554
596
|
{
|
|
555
597
|
style: {
|
|
@@ -562,8 +604,8 @@ function Toast({
|
|
|
562
604
|
minWidth: "200px"
|
|
563
605
|
},
|
|
564
606
|
children: [
|
|
565
|
-
/* @__PURE__ */ (0,
|
|
566
|
-
/* @__PURE__ */ (0,
|
|
607
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { children: message }),
|
|
608
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
567
609
|
"button",
|
|
568
610
|
{
|
|
569
611
|
onClick: onClose,
|
|
@@ -588,14 +630,17 @@ function Toast({
|
|
|
588
630
|
|
|
589
631
|
// src/hooks/use-copilot-runtime-client.ts
|
|
590
632
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
591
|
-
var
|
|
633
|
+
var import_react8 = require("react");
|
|
592
634
|
var useCopilotRuntimeClient = (options) => {
|
|
593
635
|
const { addGraphQLErrorsToast } = useToast();
|
|
594
|
-
const
|
|
636
|
+
const addErrorToast = useErrorToast();
|
|
637
|
+
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
595
638
|
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
596
639
|
handleGQLErrors: (error) => {
|
|
597
640
|
if (error.graphQLErrors.length) {
|
|
598
641
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
642
|
+
} else {
|
|
643
|
+
addErrorToast([error]);
|
|
599
644
|
}
|
|
600
645
|
}
|
|
601
646
|
}));
|
|
@@ -617,13 +662,41 @@ function getHostname() {
|
|
|
617
662
|
return "";
|
|
618
663
|
}
|
|
619
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
|
+
|
|
620
693
|
// src/components/copilot-provider/copilotkit.tsx
|
|
621
|
-
var
|
|
694
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
622
695
|
function CopilotKit(_a) {
|
|
623
696
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
624
697
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
625
698
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
626
|
-
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 })) }) });
|
|
627
700
|
}
|
|
628
701
|
function CopilotKitInternal(_a) {
|
|
629
702
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
@@ -633,49 +706,49 @@ function CopilotKitInternal(_a) {
|
|
|
633
706
|
);
|
|
634
707
|
}
|
|
635
708
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
636
|
-
const [actions, setActions] = (0,
|
|
637
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
638
|
-
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)({
|
|
639
712
|
actions: {},
|
|
640
713
|
coAgentStateRenders: {}
|
|
641
714
|
});
|
|
642
715
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
643
|
-
const [isLoading, setIsLoading] = (0,
|
|
644
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
716
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
717
|
+
const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
|
|
645
718
|
const {
|
|
646
719
|
addElement: addDocument,
|
|
647
720
|
removeElement: removeDocument,
|
|
648
721
|
allElements: allDocuments
|
|
649
722
|
} = use_flat_category_store_default();
|
|
650
|
-
const setAction = (0,
|
|
723
|
+
const setAction = (0, import_react10.useCallback)((id, action) => {
|
|
651
724
|
setActions((prevPoints) => {
|
|
652
725
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
653
726
|
[id]: action
|
|
654
727
|
});
|
|
655
728
|
});
|
|
656
729
|
}, []);
|
|
657
|
-
const removeAction = (0,
|
|
730
|
+
const removeAction = (0, import_react10.useCallback)((id) => {
|
|
658
731
|
setActions((prevPoints) => {
|
|
659
732
|
const newPoints = __spreadValues({}, prevPoints);
|
|
660
733
|
delete newPoints[id];
|
|
661
734
|
return newPoints;
|
|
662
735
|
});
|
|
663
736
|
}, []);
|
|
664
|
-
const setCoAgentStateRender = (0,
|
|
737
|
+
const setCoAgentStateRender = (0, import_react10.useCallback)((id, stateRender) => {
|
|
665
738
|
setCoAgentStateRenders((prevPoints) => {
|
|
666
739
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
667
740
|
[id]: stateRender
|
|
668
741
|
});
|
|
669
742
|
});
|
|
670
743
|
}, []);
|
|
671
|
-
const removeCoAgentStateRender = (0,
|
|
744
|
+
const removeCoAgentStateRender = (0, import_react10.useCallback)((id) => {
|
|
672
745
|
setCoAgentStateRenders((prevPoints) => {
|
|
673
746
|
const newPoints = __spreadValues({}, prevPoints);
|
|
674
747
|
delete newPoints[id];
|
|
675
748
|
return newPoints;
|
|
676
749
|
});
|
|
677
750
|
}, []);
|
|
678
|
-
const getContextString = (0,
|
|
751
|
+
const getContextString = (0, import_react10.useCallback)(
|
|
679
752
|
(documents, categories) => {
|
|
680
753
|
const documentsString = documents.map((document) => {
|
|
681
754
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -688,37 +761,37 @@ ${nonDocumentStrings}`;
|
|
|
688
761
|
},
|
|
689
762
|
[printTree]
|
|
690
763
|
);
|
|
691
|
-
const addContext = (0,
|
|
764
|
+
const addContext = (0, import_react10.useCallback)(
|
|
692
765
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
693
766
|
return addElement(context, categories, parentId);
|
|
694
767
|
},
|
|
695
768
|
[addElement]
|
|
696
769
|
);
|
|
697
|
-
const removeContext = (0,
|
|
770
|
+
const removeContext = (0, import_react10.useCallback)(
|
|
698
771
|
(id) => {
|
|
699
772
|
removeElement(id);
|
|
700
773
|
},
|
|
701
774
|
[removeElement]
|
|
702
775
|
);
|
|
703
|
-
const getFunctionCallHandler = (0,
|
|
776
|
+
const getFunctionCallHandler = (0, import_react10.useCallback)(
|
|
704
777
|
(customEntryPoints) => {
|
|
705
778
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
706
779
|
},
|
|
707
780
|
[actions]
|
|
708
781
|
);
|
|
709
|
-
const getDocumentsContext = (0,
|
|
782
|
+
const getDocumentsContext = (0, import_react10.useCallback)(
|
|
710
783
|
(categories) => {
|
|
711
784
|
return allDocuments(categories);
|
|
712
785
|
},
|
|
713
786
|
[allDocuments]
|
|
714
787
|
);
|
|
715
|
-
const addDocumentContext = (0,
|
|
788
|
+
const addDocumentContext = (0, import_react10.useCallback)(
|
|
716
789
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
717
790
|
return addDocument(documentPointer, categories);
|
|
718
791
|
},
|
|
719
792
|
[addDocument]
|
|
720
793
|
);
|
|
721
|
-
const removeDocumentContext = (0,
|
|
794
|
+
const removeDocumentContext = (0, import_react10.useCallback)(
|
|
722
795
|
(documentId) => {
|
|
723
796
|
removeDocument(documentId);
|
|
724
797
|
},
|
|
@@ -731,7 +804,7 @@ ${nonDocumentStrings}`;
|
|
|
731
804
|
);
|
|
732
805
|
}
|
|
733
806
|
}
|
|
734
|
-
const copilotApiConfig = (0,
|
|
807
|
+
const copilotApiConfig = (0, import_react10.useMemo)(() => {
|
|
735
808
|
var _a2, _b2;
|
|
736
809
|
let cloud = void 0;
|
|
737
810
|
if (props.publicApiKey) {
|
|
@@ -773,7 +846,7 @@ ${nonDocumentStrings}`;
|
|
|
773
846
|
headers,
|
|
774
847
|
credentials: copilotApiConfig.credentials
|
|
775
848
|
});
|
|
776
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
849
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react10.useState)({});
|
|
777
850
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
778
851
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
779
852
|
};
|
|
@@ -783,9 +856,9 @@ ${nonDocumentStrings}`;
|
|
|
783
856
|
return rest;
|
|
784
857
|
});
|
|
785
858
|
};
|
|
786
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
787
|
-
const coagentStatesRef = (0,
|
|
788
|
-
const setCoagentStatesWithRef = (0,
|
|
859
|
+
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
860
|
+
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
861
|
+
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
789
862
|
(value) => {
|
|
790
863
|
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
791
864
|
coagentStatesRef.current = newValue;
|
|
@@ -801,9 +874,12 @@ ${nonDocumentStrings}`;
|
|
|
801
874
|
agentName: props.agent
|
|
802
875
|
};
|
|
803
876
|
}
|
|
804
|
-
const [agentSession, setAgentSession] = (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);
|
|
805
881
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
806
|
-
return /* @__PURE__ */ (0,
|
|
882
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
|
|
807
883
|
CopilotContext.Provider,
|
|
808
884
|
{
|
|
809
885
|
value: {
|
|
@@ -836,9 +912,15 @@ ${nonDocumentStrings}`;
|
|
|
836
912
|
setCoagentStatesWithRef,
|
|
837
913
|
agentSession,
|
|
838
914
|
setAgentSession,
|
|
839
|
-
runtimeClient
|
|
915
|
+
runtimeClient,
|
|
916
|
+
agentLock: props.agent || null,
|
|
917
|
+
threadId,
|
|
918
|
+
setThreadId,
|
|
919
|
+
runId,
|
|
920
|
+
setRunId,
|
|
921
|
+
chatAbortControllerRef
|
|
840
922
|
},
|
|
841
|
-
children: /* @__PURE__ */ (0,
|
|
923
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
|
|
842
924
|
}
|
|
843
925
|
);
|
|
844
926
|
}
|