@copilotkit/react-core 1.5.1-next.1 → 1.5.1-next.3
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 +21 -0
- package/dist/{chunk-SFPANIOY.mjs → chunk-2KCEHGSI.mjs} +49 -99
- package/dist/chunk-2KCEHGSI.mjs.map +1 -0
- package/dist/{chunk-YL6V3QTN.mjs → chunk-6OR25P32.mjs} +15 -42
- package/dist/chunk-6OR25P32.mjs.map +1 -0
- package/dist/{chunk-VQDGBYWQ.mjs → chunk-DDVXFNYA.mjs} +31 -55
- package/dist/chunk-DDVXFNYA.mjs.map +1 -0
- package/dist/{chunk-NYBGR2NK.mjs → chunk-FXHKK52V.mjs} +13 -14
- package/dist/chunk-FXHKK52V.mjs.map +1 -0
- package/dist/{chunk-VPTC36RZ.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-OAF4ASJH.mjs → chunk-H7LSKIDK.mjs} +23 -70
- package/dist/chunk-H7LSKIDK.mjs.map +1 -0
- package/dist/chunk-JDQCJCAQ.mjs +295 -0
- package/dist/chunk-JDQCJCAQ.mjs.map +1 -0
- package/dist/{chunk-STZUYPHJ.mjs → chunk-LODRWFMB.mjs} +2 -14
- package/dist/chunk-LODRWFMB.mjs.map +1 -0
- package/dist/{chunk-MKEQ2MJG.mjs → chunk-MWZO6TUR.mjs} +13 -29
- package/dist/chunk-MWZO6TUR.mjs.map +1 -0
- package/dist/{chunk-7LRDVJH5.mjs → chunk-ODN4H66E.mjs} +2 -6
- package/dist/chunk-ODN4H66E.mjs.map +1 -0
- package/dist/{chunk-6KHA5W5R.mjs → chunk-QDGDXRRJ.mjs} +2 -2
- package/dist/{chunk-ODAH4HNG.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/{chunk-ODAH4HNG.mjs.map → chunk-XINZBP3J.mjs.map} +1 -1
- 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 +91 -191
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +7 -8
- package/dist/components/copilot-provider/index.d.ts +0 -1
- package/dist/components/copilot-provider/index.js +91 -191
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +7 -8
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +91 -191
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +7 -8
- package/dist/components/toast/toast-provider.d.ts +1 -2
- package/dist/components/toast/toast-provider.js +62 -76
- 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 +3 -15
- package/dist/context/copilot-context.js +1 -13
- 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 +1 -13
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +4 -4
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +293 -624
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +22 -30
- package/dist/hooks/use-chat.d.ts +3 -31
- package/dist/hooks/use-chat.js +205 -443
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +3 -4
- package/dist/hooks/use-coagent-state-render.d.ts +2 -2
- package/dist/hooks/use-coagent-state-render.js +1 -13
- 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 -14
- package/dist/hooks/use-coagent.js +262 -580
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +11 -19
- package/dist/hooks/use-copilot-action.d.ts +2 -12
- package/dist/hooks/use-copilot-action.js +17 -167
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -4
- package/dist/hooks/use-copilot-chat.d.ts +0 -2
- package/dist/hooks/use-copilot-chat.js +238 -532
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +10 -12
- package/dist/hooks/use-copilot-readable.js +1 -13
- 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 +4 -110
- 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 -13
- 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 +3 -3
- package/dist/index.js +391 -703
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -38
- package/dist/lib/copilot-task.d.ts +1 -6
- package/dist/lib/copilot-task.js +17 -55
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +8 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +17 -55
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +8 -10
- package/dist/types/frontend-action.d.ts +2 -21
- package/dist/types/frontend-action.js +0 -34
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +0 -7
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.js.map +1 -1
- 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 +7 -8
- package/dist/utils/index.js +3 -21
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +9 -10
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +10 -0
- package/src/components/copilot-provider/copilotkit.tsx +44 -7
- package/src/components/toast/toast-provider.tsx +1 -1
- package/src/context/copilot-context.tsx +28 -2
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-chat.ts +15 -5
- package/src/hooks/use-coagent-state-render.ts +11 -0
- package/src/hooks/use-coagent.ts +11 -1
- package/src/hooks/use-copilot-authenticated-action.ts +60 -0
- package/src/hooks/use-copilot-chat.ts +1 -0
- package/dist/chunk-7LRDVJH5.mjs.map +0 -1
- package/dist/chunk-M3SYKJ3W.mjs +0 -393
- package/dist/chunk-M3SYKJ3W.mjs.map +0 -1
- package/dist/chunk-MKEQ2MJG.mjs.map +0 -1
- package/dist/chunk-NYBGR2NK.mjs.map +0 -1
- package/dist/chunk-OAF4ASJH.mjs.map +0 -1
- package/dist/chunk-QCUP6HLK.mjs +0 -37
- package/dist/chunk-QCUP6HLK.mjs.map +0 -1
- package/dist/chunk-SFPANIOY.mjs.map +0 -1
- package/dist/chunk-STZUYPHJ.mjs.map +0 -1
- package/dist/chunk-VQDGBYWQ.mjs.map +0 -1
- package/dist/chunk-XERJQUHA.mjs +0 -31
- package/dist/chunk-XERJQUHA.mjs.map +0 -1
- package/dist/chunk-YL6V3QTN.mjs.map +0 -1
- package/dist/components/error-boundary/error-boundary.d.ts +0 -22
- package/dist/components/error-boundary/error-boundary.js +0 -183
- package/dist/components/error-boundary/error-boundary.js.map +0 -1
- package/dist/components/error-boundary/error-boundary.mjs +0 -12
- package/dist/components/error-boundary/error-boundary.mjs.map +0 -1
- package/dist/components/error-boundary/error-utils.d.ts +0 -11
- package/dist/components/error-boundary/error-utils.js +0 -177
- package/dist/components/error-boundary/error-utils.js.map +0 -1
- package/dist/components/error-boundary/error-utils.mjs +0 -13
- package/dist/components/error-boundary/error-utils.mjs.map +0 -1
- /package/dist/{chunk-VPTC36RZ.mjs.map → chunk-H4VZMKR6.mjs.map} +0 -0
- /package/dist/{chunk-6KHA5W5R.mjs.map → chunk-QDGDXRRJ.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_react8 = require("react");
|
|
90
90
|
|
|
91
91
|
// src/context/copilot-context.tsx
|
|
92
92
|
var import_react = __toESM(require("react"));
|
|
@@ -137,21 +137,9 @@ var emptyCopilotContext = {
|
|
|
137
137
|
coagentStates: {},
|
|
138
138
|
setCoagentStates: () => {
|
|
139
139
|
},
|
|
140
|
-
coagentStatesRef: { current: {} },
|
|
141
|
-
setCoagentStatesWithRef: () => {
|
|
142
|
-
},
|
|
143
140
|
agentSession: null,
|
|
144
141
|
setAgentSession: () => {
|
|
145
|
-
}
|
|
146
|
-
forwardedParameters: {},
|
|
147
|
-
agentLock: null,
|
|
148
|
-
threadId: null,
|
|
149
|
-
setThreadId: () => {
|
|
150
|
-
},
|
|
151
|
-
runId: null,
|
|
152
|
-
setRunId: () => {
|
|
153
|
-
},
|
|
154
|
-
chatAbortControllerRef: { current: null }
|
|
142
|
+
}
|
|
155
143
|
};
|
|
156
144
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
157
145
|
function returnAndThrowInDebug(value) {
|
|
@@ -389,9 +377,6 @@ function CopilotMessages(_a) {
|
|
|
389
377
|
}
|
|
390
378
|
|
|
391
379
|
// src/components/toast/toast-provider.tsx
|
|
392
|
-
var import_react7 = require("react");
|
|
393
|
-
|
|
394
|
-
// src/components/error-boundary/error-utils.tsx
|
|
395
380
|
var import_react6 = require("react");
|
|
396
381
|
|
|
397
382
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
@@ -421,82 +406,11 @@ var ExclamationMarkIcon = ({
|
|
|
421
406
|
}
|
|
422
407
|
);
|
|
423
408
|
|
|
424
|
-
// src/components/error-boundary/error-utils.tsx
|
|
425
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
426
|
-
function ErrorToast({ errors }) {
|
|
427
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
428
|
-
var _a, _b, _c;
|
|
429
|
-
const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
|
|
430
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
431
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
432
|
-
"div",
|
|
433
|
-
{
|
|
434
|
-
style: {
|
|
435
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
436
|
-
marginBottom: 14
|
|
437
|
-
},
|
|
438
|
-
children: [
|
|
439
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
440
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
441
|
-
"div",
|
|
442
|
-
{
|
|
443
|
-
style: {
|
|
444
|
-
fontWeight: "600",
|
|
445
|
-
marginBottom: 4
|
|
446
|
-
},
|
|
447
|
-
children: [
|
|
448
|
-
"Copilot Cloud Error:",
|
|
449
|
-
" ",
|
|
450
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
451
|
-
]
|
|
452
|
-
}
|
|
453
|
-
),
|
|
454
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
455
|
-
]
|
|
456
|
-
},
|
|
457
|
-
idx
|
|
458
|
-
);
|
|
459
|
-
});
|
|
460
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
461
|
-
"div",
|
|
462
|
-
{
|
|
463
|
-
style: {
|
|
464
|
-
fontSize: "13px",
|
|
465
|
-
maxWidth: "600px"
|
|
466
|
-
},
|
|
467
|
-
children: [
|
|
468
|
-
errorsToRender,
|
|
469
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
470
|
-
]
|
|
471
|
-
}
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
function useErrorToast() {
|
|
475
|
-
const { addToast } = useToast();
|
|
476
|
-
return (0, import_react6.useCallback)(
|
|
477
|
-
(error) => {
|
|
478
|
-
const errorId = error.map((err) => {
|
|
479
|
-
var _a, _b;
|
|
480
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
481
|
-
const stack = err.stack || "";
|
|
482
|
-
return btoa(message + stack).slice(0, 32);
|
|
483
|
-
}).join("|");
|
|
484
|
-
addToast({
|
|
485
|
-
type: "error",
|
|
486
|
-
id: errorId,
|
|
487
|
-
// Toast libraries typically dedupe by id
|
|
488
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
489
|
-
});
|
|
490
|
-
},
|
|
491
|
-
[addToast]
|
|
492
|
-
);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
409
|
// src/components/toast/toast-provider.tsx
|
|
496
|
-
var
|
|
497
|
-
var ToastContext = (0,
|
|
410
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
411
|
+
var ToastContext = (0, import_react6.createContext)(void 0);
|
|
498
412
|
function useToast() {
|
|
499
|
-
const context = (0,
|
|
413
|
+
const context = (0, import_react6.useContext)(ToastContext);
|
|
500
414
|
if (!context) {
|
|
501
415
|
throw new Error("useToast must be used within a ToastProvider");
|
|
502
416
|
}
|
|
@@ -506,28 +420,68 @@ function ToastProvider({
|
|
|
506
420
|
enabled,
|
|
507
421
|
children
|
|
508
422
|
}) {
|
|
509
|
-
const [toasts, setToasts] = (0,
|
|
510
|
-
const addToast = (0,
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
setToasts((currentToasts) => {
|
|
514
|
-
if (currentToasts.find((toast2) => toast2.id === id))
|
|
515
|
-
return currentToasts;
|
|
516
|
-
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
517
|
-
});
|
|
423
|
+
const [toasts, setToasts] = (0, import_react6.useState)([]);
|
|
424
|
+
const addToast = (0, import_react6.useCallback)((toast) => {
|
|
425
|
+
const id = Math.random().toString(36).substring(2, 9);
|
|
426
|
+
setToasts((currentToasts) => [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })]);
|
|
518
427
|
if (toast.duration) {
|
|
519
428
|
setTimeout(() => {
|
|
520
429
|
removeToast(id);
|
|
521
430
|
}, toast.duration);
|
|
522
431
|
}
|
|
523
432
|
}, []);
|
|
524
|
-
const addGraphQLErrorsToast = (0,
|
|
433
|
+
const addGraphQLErrorsToast = (0, import_react6.useCallback)((errors) => {
|
|
434
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
435
|
+
var _a;
|
|
436
|
+
const message = error.message;
|
|
437
|
+
const code = (_a = error.extensions) == null ? void 0 : _a.code;
|
|
438
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
439
|
+
"div",
|
|
440
|
+
{
|
|
441
|
+
style: {
|
|
442
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
443
|
+
marginBottom: 14
|
|
444
|
+
},
|
|
445
|
+
children: [
|
|
446
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
447
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
448
|
+
"div",
|
|
449
|
+
{
|
|
450
|
+
style: {
|
|
451
|
+
fontWeight: "600",
|
|
452
|
+
marginBottom: 4
|
|
453
|
+
},
|
|
454
|
+
children: [
|
|
455
|
+
"Copilot Cloud Error:",
|
|
456
|
+
" ",
|
|
457
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
458
|
+
]
|
|
459
|
+
}
|
|
460
|
+
),
|
|
461
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
462
|
+
]
|
|
463
|
+
},
|
|
464
|
+
idx
|
|
465
|
+
);
|
|
466
|
+
});
|
|
525
467
|
addToast({
|
|
526
468
|
type: "error",
|
|
527
|
-
message: /* @__PURE__ */ (0,
|
|
469
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
470
|
+
"div",
|
|
471
|
+
{
|
|
472
|
+
style: {
|
|
473
|
+
fontSize: "13px",
|
|
474
|
+
maxWidth: "600px"
|
|
475
|
+
},
|
|
476
|
+
children: [
|
|
477
|
+
errorsToRender,
|
|
478
|
+
/* @__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." })
|
|
479
|
+
]
|
|
480
|
+
}
|
|
481
|
+
)
|
|
528
482
|
});
|
|
529
483
|
}, []);
|
|
530
|
-
const removeToast = (0,
|
|
484
|
+
const removeToast = (0, import_react6.useCallback)((id) => {
|
|
531
485
|
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
532
486
|
}, []);
|
|
533
487
|
const value = {
|
|
@@ -537,8 +491,8 @@ function ToastProvider({
|
|
|
537
491
|
removeToast,
|
|
538
492
|
enabled
|
|
539
493
|
};
|
|
540
|
-
return /* @__PURE__ */ (0,
|
|
541
|
-
/* @__PURE__ */ (0,
|
|
494
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
|
|
495
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
542
496
|
"div",
|
|
543
497
|
{
|
|
544
498
|
style: {
|
|
@@ -552,7 +506,7 @@ function ToastProvider({
|
|
|
552
506
|
gap: "0.5rem"
|
|
553
507
|
},
|
|
554
508
|
children: [
|
|
555
|
-
toasts.length > 1 && /* @__PURE__ */ (0,
|
|
509
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
556
510
|
"button",
|
|
557
511
|
{
|
|
558
512
|
onClick: () => setToasts([]),
|
|
@@ -567,7 +521,7 @@ function ToastProvider({
|
|
|
567
521
|
children: "Close All"
|
|
568
522
|
}
|
|
569
523
|
) }),
|
|
570
|
-
toasts.map((toast) => /* @__PURE__ */ (0,
|
|
524
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
571
525
|
Toast,
|
|
572
526
|
{
|
|
573
527
|
message: toast.message,
|
|
@@ -593,7 +547,7 @@ function Toast({
|
|
|
593
547
|
warning: "#eab308",
|
|
594
548
|
error: "#ef4444"
|
|
595
549
|
};
|
|
596
|
-
return /* @__PURE__ */ (0,
|
|
550
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
597
551
|
"div",
|
|
598
552
|
{
|
|
599
553
|
style: {
|
|
@@ -606,8 +560,8 @@ function Toast({
|
|
|
606
560
|
minWidth: "200px"
|
|
607
561
|
},
|
|
608
562
|
children: [
|
|
609
|
-
/* @__PURE__ */ (0,
|
|
610
|
-
/* @__PURE__ */ (0,
|
|
563
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
|
|
564
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
611
565
|
"button",
|
|
612
566
|
{
|
|
613
567
|
onClick: onClose,
|
|
@@ -632,17 +586,14 @@ function Toast({
|
|
|
632
586
|
|
|
633
587
|
// src/hooks/use-copilot-runtime-client.ts
|
|
634
588
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
635
|
-
var
|
|
589
|
+
var import_react7 = require("react");
|
|
636
590
|
var useCopilotRuntimeClient = (options) => {
|
|
637
591
|
const { addGraphQLErrorsToast } = useToast();
|
|
638
|
-
const
|
|
639
|
-
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
592
|
+
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
640
593
|
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
641
594
|
handleGQLErrors: (error) => {
|
|
642
595
|
if (error.graphQLErrors.length) {
|
|
643
596
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
644
|
-
} else {
|
|
645
|
-
addErrorToast([error]);
|
|
646
597
|
}
|
|
647
598
|
}
|
|
648
599
|
}));
|
|
@@ -664,41 +615,13 @@ function getHostname() {
|
|
|
664
615
|
return "";
|
|
665
616
|
}
|
|
666
617
|
|
|
667
|
-
// src/components/error-boundary/error-boundary.tsx
|
|
668
|
-
var import_react9 = __toESM(require("react"));
|
|
669
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
670
|
-
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
671
|
-
constructor(props) {
|
|
672
|
-
super(props);
|
|
673
|
-
this.state = { hasError: false };
|
|
674
|
-
}
|
|
675
|
-
static getDerivedStateFromError(error) {
|
|
676
|
-
return { hasError: true, error };
|
|
677
|
-
}
|
|
678
|
-
componentDidCatch(error, errorInfo) {
|
|
679
|
-
console.error("CopilotKit Error:", error, errorInfo);
|
|
680
|
-
}
|
|
681
|
-
render() {
|
|
682
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
|
|
683
|
-
}
|
|
684
|
-
};
|
|
685
|
-
function ErrorToast2({ error, children }) {
|
|
686
|
-
const addErrorToast = useErrorToast();
|
|
687
|
-
(0, import_react9.useEffect)(() => {
|
|
688
|
-
if (error) {
|
|
689
|
-
addErrorToast([error]);
|
|
690
|
-
}
|
|
691
|
-
}, [error, addErrorToast]);
|
|
692
|
-
return children;
|
|
693
|
-
}
|
|
694
|
-
|
|
695
618
|
// src/components/copilot-provider/copilotkit.tsx
|
|
696
|
-
var
|
|
619
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
697
620
|
function CopilotKit(_a) {
|
|
698
621
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
699
622
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
700
623
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
701
|
-
return /* @__PURE__ */ (0,
|
|
624
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
|
|
702
625
|
}
|
|
703
626
|
function CopilotKitInternal(_a) {
|
|
704
627
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
@@ -708,49 +631,49 @@ function CopilotKitInternal(_a) {
|
|
|
708
631
|
);
|
|
709
632
|
}
|
|
710
633
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
711
|
-
const [actions, setActions] = (0,
|
|
712
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
713
|
-
const chatComponentsCache = (0,
|
|
634
|
+
const [actions, setActions] = (0, import_react8.useState)({});
|
|
635
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
|
|
636
|
+
const chatComponentsCache = (0, import_react8.useRef)({
|
|
714
637
|
actions: {},
|
|
715
638
|
coAgentStateRenders: {}
|
|
716
639
|
});
|
|
717
640
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
718
|
-
const [isLoading, setIsLoading] = (0,
|
|
719
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
641
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
642
|
+
const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
|
|
720
643
|
const {
|
|
721
644
|
addElement: addDocument,
|
|
722
645
|
removeElement: removeDocument,
|
|
723
646
|
allElements: allDocuments
|
|
724
647
|
} = use_flat_category_store_default();
|
|
725
|
-
const setAction = (0,
|
|
648
|
+
const setAction = (0, import_react8.useCallback)((id, action) => {
|
|
726
649
|
setActions((prevPoints) => {
|
|
727
650
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
728
651
|
[id]: action
|
|
729
652
|
});
|
|
730
653
|
});
|
|
731
654
|
}, []);
|
|
732
|
-
const removeAction = (0,
|
|
655
|
+
const removeAction = (0, import_react8.useCallback)((id) => {
|
|
733
656
|
setActions((prevPoints) => {
|
|
734
657
|
const newPoints = __spreadValues({}, prevPoints);
|
|
735
658
|
delete newPoints[id];
|
|
736
659
|
return newPoints;
|
|
737
660
|
});
|
|
738
661
|
}, []);
|
|
739
|
-
const setCoAgentStateRender = (0,
|
|
662
|
+
const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
|
|
740
663
|
setCoAgentStateRenders((prevPoints) => {
|
|
741
664
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
742
665
|
[id]: stateRender
|
|
743
666
|
});
|
|
744
667
|
});
|
|
745
668
|
}, []);
|
|
746
|
-
const removeCoAgentStateRender = (0,
|
|
669
|
+
const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
|
|
747
670
|
setCoAgentStateRenders((prevPoints) => {
|
|
748
671
|
const newPoints = __spreadValues({}, prevPoints);
|
|
749
672
|
delete newPoints[id];
|
|
750
673
|
return newPoints;
|
|
751
674
|
});
|
|
752
675
|
}, []);
|
|
753
|
-
const getContextString = (0,
|
|
676
|
+
const getContextString = (0, import_react8.useCallback)(
|
|
754
677
|
(documents, categories) => {
|
|
755
678
|
const documentsString = documents.map((document) => {
|
|
756
679
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -763,37 +686,37 @@ ${nonDocumentStrings}`;
|
|
|
763
686
|
},
|
|
764
687
|
[printTree]
|
|
765
688
|
);
|
|
766
|
-
const addContext = (0,
|
|
689
|
+
const addContext = (0, import_react8.useCallback)(
|
|
767
690
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
768
691
|
return addElement(context, categories, parentId);
|
|
769
692
|
},
|
|
770
693
|
[addElement]
|
|
771
694
|
);
|
|
772
|
-
const removeContext = (0,
|
|
695
|
+
const removeContext = (0, import_react8.useCallback)(
|
|
773
696
|
(id) => {
|
|
774
697
|
removeElement(id);
|
|
775
698
|
},
|
|
776
699
|
[removeElement]
|
|
777
700
|
);
|
|
778
|
-
const getFunctionCallHandler = (0,
|
|
701
|
+
const getFunctionCallHandler = (0, import_react8.useCallback)(
|
|
779
702
|
(customEntryPoints) => {
|
|
780
703
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
781
704
|
},
|
|
782
705
|
[actions]
|
|
783
706
|
);
|
|
784
|
-
const getDocumentsContext = (0,
|
|
707
|
+
const getDocumentsContext = (0, import_react8.useCallback)(
|
|
785
708
|
(categories) => {
|
|
786
709
|
return allDocuments(categories);
|
|
787
710
|
},
|
|
788
711
|
[allDocuments]
|
|
789
712
|
);
|
|
790
|
-
const addDocumentContext = (0,
|
|
713
|
+
const addDocumentContext = (0, import_react8.useCallback)(
|
|
791
714
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
792
715
|
return addDocument(documentPointer, categories);
|
|
793
716
|
},
|
|
794
717
|
[addDocument]
|
|
795
718
|
);
|
|
796
|
-
const removeDocumentContext = (0,
|
|
719
|
+
const removeDocumentContext = (0, import_react8.useCallback)(
|
|
797
720
|
(documentId) => {
|
|
798
721
|
removeDocument(documentId);
|
|
799
722
|
},
|
|
@@ -806,7 +729,7 @@ ${nonDocumentStrings}`;
|
|
|
806
729
|
);
|
|
807
730
|
}
|
|
808
731
|
}
|
|
809
|
-
const copilotApiConfig = (0,
|
|
732
|
+
const copilotApiConfig = (0, import_react8.useMemo)(() => {
|
|
810
733
|
var _a2, _b2;
|
|
811
734
|
let cloud = void 0;
|
|
812
735
|
if (props.publicApiKey) {
|
|
@@ -848,7 +771,7 @@ ${nonDocumentStrings}`;
|
|
|
848
771
|
headers,
|
|
849
772
|
credentials: copilotApiConfig.credentials
|
|
850
773
|
});
|
|
851
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
774
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
|
|
852
775
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
853
776
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
854
777
|
};
|
|
@@ -858,30 +781,16 @@ ${nonDocumentStrings}`;
|
|
|
858
781
|
return rest;
|
|
859
782
|
});
|
|
860
783
|
};
|
|
861
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
862
|
-
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
863
|
-
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
864
|
-
(value) => {
|
|
865
|
-
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
866
|
-
coagentStatesRef.current = newValue;
|
|
867
|
-
setCoagentStates((prev) => {
|
|
868
|
-
return newValue;
|
|
869
|
-
});
|
|
870
|
-
},
|
|
871
|
-
[]
|
|
872
|
-
);
|
|
784
|
+
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
873
785
|
let initialAgentSession = null;
|
|
874
786
|
if (props.agent) {
|
|
875
787
|
initialAgentSession = {
|
|
876
788
|
agentName: props.agent
|
|
877
789
|
};
|
|
878
790
|
}
|
|
879
|
-
const [agentSession, setAgentSession] = (0,
|
|
880
|
-
const [threadId, setThreadId] = (0, import_react10.useState)(null);
|
|
881
|
-
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
882
|
-
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
791
|
+
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
883
792
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
884
|
-
return /* @__PURE__ */ (0,
|
|
793
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
885
794
|
CopilotContext.Provider,
|
|
886
795
|
{
|
|
887
796
|
value: {
|
|
@@ -910,20 +819,11 @@ ${nonDocumentStrings}`;
|
|
|
910
819
|
showDevConsole,
|
|
911
820
|
coagentStates,
|
|
912
821
|
setCoagentStates,
|
|
913
|
-
coagentStatesRef,
|
|
914
|
-
setCoagentStatesWithRef,
|
|
915
822
|
agentSession,
|
|
916
823
|
setAgentSession,
|
|
917
|
-
runtimeClient
|
|
918
|
-
forwardedParameters: props.forwardedParameters || {},
|
|
919
|
-
agentLock: props.agent || null,
|
|
920
|
-
threadId,
|
|
921
|
-
setThreadId,
|
|
922
|
-
runId,
|
|
923
|
-
setRunId,
|
|
924
|
-
chatAbortControllerRef
|
|
824
|
+
runtimeClient
|
|
925
825
|
},
|
|
926
|
-
children: /* @__PURE__ */ (0,
|
|
826
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
927
827
|
}
|
|
928
828
|
);
|
|
929
829
|
}
|