@copilotkit/react-core 1.5.1-next.2 → 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 +9 -0
- package/dist/{chunk-LNI2Z45S.mjs → chunk-2KCEHGSI.mjs} +50 -100
- package/dist/chunk-2KCEHGSI.mjs.map +1 -0
- package/dist/{chunk-2KT73RVG.mjs → chunk-6OR25P32.mjs} +19 -75
- package/dist/chunk-6OR25P32.mjs.map +1 -0
- package/dist/{chunk-3GQPEN4M.mjs → chunk-DDVXFNYA.mjs} +32 -66
- package/dist/chunk-DDVXFNYA.mjs.map +1 -0
- package/dist/{chunk-XOQMISG3.mjs → chunk-FXHKK52V.mjs} +13 -14
- package/dist/chunk-FXHKK52V.mjs.map +1 -0
- package/dist/{chunk-HIUT2NLX.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-X36DNILG.mjs → chunk-H7LSKIDK.mjs} +23 -71
- 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-L34MHAXR.mjs +1 -0
- package/dist/{chunk-WXREY7UP.mjs → chunk-LODRWFMB.mjs} +4 -16
- package/dist/chunk-LODRWFMB.mjs.map +1 -0
- package/dist/{chunk-EWKJMQOF.mjs → chunk-MWZO6TUR.mjs} +13 -29
- package/dist/chunk-MWZO6TUR.mjs.map +1 -0
- package/dist/{chunk-6BQVZFNO.mjs → chunk-ODN4H66E.mjs} +2 -6
- package/dist/chunk-ODN4H66E.mjs.map +1 -0
- package/dist/{chunk-FQ53HQYZ.mjs → chunk-QDGDXRRJ.mjs} +2 -2
- package/dist/{chunk-22XKTBPF.mjs → chunk-XINZBP3J.mjs} +3 -15
- package/dist/chunk-XINZBP3J.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.d.ts +0 -9
- package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -21
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +0 -9
- package/dist/components/copilot-provider/copilotkit.js +95 -224
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +8 -9
- package/dist/components/copilot-provider/index.d.ts +0 -9
- package/dist/components/copilot-provider/index.js +95 -224
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +8 -9
- package/dist/components/index.d.ts +0 -9
- package/dist/components/index.js +95 -224
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +8 -9
- package/dist/components/toast/toast-provider.d.ts +1 -2
- package/dist/components/toast/toast-provider.js +63 -77
- 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 -37
- package/dist/context/copilot-context.js +3 -15
- 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 -15
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +4 -4
- package/dist/hooks/index.d.ts +1 -3
- package/dist/hooks/index.js +297 -703
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +23 -35
- package/dist/hooks/use-chat.d.ts +3 -35
- package/dist/hooks/use-chat.js +205 -453
- 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 +8 -43
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -4
- package/dist/hooks/use-coagent.d.ts +1 -14
- package/dist/hooks/use-coagent.js +265 -603
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +12 -20
- package/dist/hooks/use-copilot-action.d.ts +2 -12
- package/dist/hooks/use-copilot-action.js +19 -169
- 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 +240 -545
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +11 -13
- package/dist/hooks/use-copilot-readable.js +3 -15
- 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 +3 -15
- 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 -4
- package/dist/index.js +398 -812
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -43
- 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 +9 -11
- 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 +9 -11
- 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 +8 -9
- 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/dist/chunk-22XKTBPF.mjs.map +0 -1
- package/dist/chunk-2KT73RVG.mjs.map +0 -1
- package/dist/chunk-3GQPEN4M.mjs.map +0 -1
- package/dist/chunk-6BQVZFNO.mjs.map +0 -1
- package/dist/chunk-EWKJMQOF.mjs.map +0 -1
- package/dist/chunk-LHKIIAUQ.mjs +0 -59
- package/dist/chunk-LHKIIAUQ.mjs.map +0 -1
- package/dist/chunk-LNI2Z45S.mjs.map +0 -1
- package/dist/chunk-NR2BTA6Z.mjs +0 -1
- package/dist/chunk-VGOFRULA.mjs +0 -401
- package/dist/chunk-VGOFRULA.mjs.map +0 -1
- package/dist/chunk-VNTDIJSG.mjs +0 -37
- package/dist/chunk-VNTDIJSG.mjs.map +0 -1
- package/dist/chunk-WXREY7UP.mjs.map +0 -1
- package/dist/chunk-X36DNILG.mjs.map +0 -1
- package/dist/chunk-XERJQUHA.mjs +0 -31
- package/dist/chunk-XERJQUHA.mjs.map +0 -1
- package/dist/chunk-XOQMISG3.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/hooks/use-copilot-authenticated-action.d.ts +0 -8
- package/dist/hooks/use-copilot-authenticated-action.js +0 -418
- package/dist/hooks/use-copilot-authenticated-action.js.map +0 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +0 -12
- package/dist/hooks/use-copilot-authenticated-action.mjs.map +0 -1
- /package/dist/{chunk-HIUT2NLX.mjs.map → chunk-H4VZMKR6.mjs.map} +0 -0
- /package/dist/{chunk-NR2BTA6Z.mjs.map → chunk-L34MHAXR.mjs.map} +0 -0
- /package/dist/{chunk-FQ53HQYZ.mjs.map → chunk-QDGDXRRJ.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_react8 = require("react");
|
|
89
89
|
|
|
90
90
|
// src/context/copilot-context.tsx
|
|
91
91
|
var import_react = __toESM(require("react"));
|
|
@@ -136,26 +136,14 @@ var emptyCopilotContext = {
|
|
|
136
136
|
coagentStates: {},
|
|
137
137
|
setCoagentStates: () => {
|
|
138
138
|
},
|
|
139
|
-
coagentStatesRef: { current: {} },
|
|
140
|
-
setCoagentStatesWithRef: () => {
|
|
141
|
-
},
|
|
142
139
|
agentSession: null,
|
|
143
140
|
setAgentSession: () => {
|
|
144
|
-
}
|
|
145
|
-
forwardedParameters: {},
|
|
146
|
-
agentLock: null,
|
|
147
|
-
threadId: null,
|
|
148
|
-
setThreadId: () => {
|
|
149
|
-
},
|
|
150
|
-
runId: null,
|
|
151
|
-
setRunId: () => {
|
|
152
|
-
},
|
|
153
|
-
chatAbortControllerRef: { current: null },
|
|
154
|
-
availableAgents: []
|
|
141
|
+
}
|
|
155
142
|
};
|
|
156
143
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
157
|
-
function returnAndThrowInDebug(
|
|
144
|
+
function returnAndThrowInDebug(value) {
|
|
158
145
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
146
|
+
return value;
|
|
159
147
|
}
|
|
160
148
|
|
|
161
149
|
// src/hooks/use-tree.ts
|
|
@@ -388,9 +376,6 @@ function CopilotMessages(_a) {
|
|
|
388
376
|
}
|
|
389
377
|
|
|
390
378
|
// src/components/toast/toast-provider.tsx
|
|
391
|
-
var import_react7 = require("react");
|
|
392
|
-
|
|
393
|
-
// src/components/error-boundary/error-utils.tsx
|
|
394
379
|
var import_react6 = require("react");
|
|
395
380
|
|
|
396
381
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
@@ -420,82 +405,11 @@ var ExclamationMarkIcon = ({
|
|
|
420
405
|
}
|
|
421
406
|
);
|
|
422
407
|
|
|
423
|
-
// src/components/error-boundary/error-utils.tsx
|
|
424
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
425
|
-
function ErrorToast({ errors }) {
|
|
426
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
427
|
-
var _a, _b, _c;
|
|
428
|
-
const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
|
|
429
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
430
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
431
|
-
"div",
|
|
432
|
-
{
|
|
433
|
-
style: {
|
|
434
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
435
|
-
marginBottom: 14
|
|
436
|
-
},
|
|
437
|
-
children: [
|
|
438
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
439
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
440
|
-
"div",
|
|
441
|
-
{
|
|
442
|
-
style: {
|
|
443
|
-
fontWeight: "600",
|
|
444
|
-
marginBottom: 4
|
|
445
|
-
},
|
|
446
|
-
children: [
|
|
447
|
-
"Copilot Cloud Error:",
|
|
448
|
-
" ",
|
|
449
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
450
|
-
]
|
|
451
|
-
}
|
|
452
|
-
),
|
|
453
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
454
|
-
]
|
|
455
|
-
},
|
|
456
|
-
idx
|
|
457
|
-
);
|
|
458
|
-
});
|
|
459
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
460
|
-
"div",
|
|
461
|
-
{
|
|
462
|
-
style: {
|
|
463
|
-
fontSize: "13px",
|
|
464
|
-
maxWidth: "600px"
|
|
465
|
-
},
|
|
466
|
-
children: [
|
|
467
|
-
errorsToRender,
|
|
468
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
469
|
-
]
|
|
470
|
-
}
|
|
471
|
-
);
|
|
472
|
-
}
|
|
473
|
-
function useErrorToast() {
|
|
474
|
-
const { addToast } = useToast();
|
|
475
|
-
return (0, import_react6.useCallback)(
|
|
476
|
-
(error) => {
|
|
477
|
-
const errorId = error.map((err) => {
|
|
478
|
-
var _a, _b;
|
|
479
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
480
|
-
const stack = err.stack || "";
|
|
481
|
-
return btoa(message + stack).slice(0, 32);
|
|
482
|
-
}).join("|");
|
|
483
|
-
addToast({
|
|
484
|
-
type: "error",
|
|
485
|
-
id: errorId,
|
|
486
|
-
// Toast libraries typically dedupe by id
|
|
487
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
488
|
-
});
|
|
489
|
-
},
|
|
490
|
-
[addToast]
|
|
491
|
-
);
|
|
492
|
-
}
|
|
493
|
-
|
|
494
408
|
// src/components/toast/toast-provider.tsx
|
|
495
|
-
var
|
|
496
|
-
var ToastContext = (0,
|
|
409
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
410
|
+
var ToastContext = (0, import_react6.createContext)(void 0);
|
|
497
411
|
function useToast() {
|
|
498
|
-
const context = (0,
|
|
412
|
+
const context = (0, import_react6.useContext)(ToastContext);
|
|
499
413
|
if (!context) {
|
|
500
414
|
throw new Error("useToast must be used within a ToastProvider");
|
|
501
415
|
}
|
|
@@ -505,28 +419,68 @@ function ToastProvider({
|
|
|
505
419
|
enabled,
|
|
506
420
|
children
|
|
507
421
|
}) {
|
|
508
|
-
const [toasts, setToasts] = (0,
|
|
509
|
-
const addToast = (0,
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
setToasts((currentToasts) => {
|
|
513
|
-
if (currentToasts.find((toast2) => toast2.id === id))
|
|
514
|
-
return currentToasts;
|
|
515
|
-
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
516
|
-
});
|
|
422
|
+
const [toasts, setToasts] = (0, import_react6.useState)([]);
|
|
423
|
+
const addToast = (0, import_react6.useCallback)((toast) => {
|
|
424
|
+
const id = Math.random().toString(36).substring(2, 9);
|
|
425
|
+
setToasts((currentToasts) => [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })]);
|
|
517
426
|
if (toast.duration) {
|
|
518
427
|
setTimeout(() => {
|
|
519
428
|
removeToast(id);
|
|
520
429
|
}, toast.duration);
|
|
521
430
|
}
|
|
522
431
|
}, []);
|
|
523
|
-
const addGraphQLErrorsToast = (0,
|
|
432
|
+
const addGraphQLErrorsToast = (0, import_react6.useCallback)((errors) => {
|
|
433
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
434
|
+
var _a;
|
|
435
|
+
const message = error.message;
|
|
436
|
+
const code = (_a = error.extensions) == null ? void 0 : _a.code;
|
|
437
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
438
|
+
"div",
|
|
439
|
+
{
|
|
440
|
+
style: {
|
|
441
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
442
|
+
marginBottom: 14
|
|
443
|
+
},
|
|
444
|
+
children: [
|
|
445
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
446
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
447
|
+
"div",
|
|
448
|
+
{
|
|
449
|
+
style: {
|
|
450
|
+
fontWeight: "600",
|
|
451
|
+
marginBottom: 4
|
|
452
|
+
},
|
|
453
|
+
children: [
|
|
454
|
+
"Copilot Cloud Error:",
|
|
455
|
+
" ",
|
|
456
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
457
|
+
]
|
|
458
|
+
}
|
|
459
|
+
),
|
|
460
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
461
|
+
]
|
|
462
|
+
},
|
|
463
|
+
idx
|
|
464
|
+
);
|
|
465
|
+
});
|
|
524
466
|
addToast({
|
|
525
467
|
type: "error",
|
|
526
|
-
message: /* @__PURE__ */ (0,
|
|
468
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
469
|
+
"div",
|
|
470
|
+
{
|
|
471
|
+
style: {
|
|
472
|
+
fontSize: "13px",
|
|
473
|
+
maxWidth: "600px"
|
|
474
|
+
},
|
|
475
|
+
children: [
|
|
476
|
+
errorsToRender,
|
|
477
|
+
/* @__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." })
|
|
478
|
+
]
|
|
479
|
+
}
|
|
480
|
+
)
|
|
527
481
|
});
|
|
528
482
|
}, []);
|
|
529
|
-
const removeToast = (0,
|
|
483
|
+
const removeToast = (0, import_react6.useCallback)((id) => {
|
|
530
484
|
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
531
485
|
}, []);
|
|
532
486
|
const value = {
|
|
@@ -536,8 +490,8 @@ function ToastProvider({
|
|
|
536
490
|
removeToast,
|
|
537
491
|
enabled
|
|
538
492
|
};
|
|
539
|
-
return /* @__PURE__ */ (0,
|
|
540
|
-
/* @__PURE__ */ (0,
|
|
493
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
|
|
494
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
541
495
|
"div",
|
|
542
496
|
{
|
|
543
497
|
style: {
|
|
@@ -551,7 +505,7 @@ function ToastProvider({
|
|
|
551
505
|
gap: "0.5rem"
|
|
552
506
|
},
|
|
553
507
|
children: [
|
|
554
|
-
toasts.length > 1 && /* @__PURE__ */ (0,
|
|
508
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
555
509
|
"button",
|
|
556
510
|
{
|
|
557
511
|
onClick: () => setToasts([]),
|
|
@@ -566,7 +520,7 @@ function ToastProvider({
|
|
|
566
520
|
children: "Close All"
|
|
567
521
|
}
|
|
568
522
|
) }),
|
|
569
|
-
toasts.map((toast) => /* @__PURE__ */ (0,
|
|
523
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
570
524
|
Toast,
|
|
571
525
|
{
|
|
572
526
|
message: toast.message,
|
|
@@ -592,21 +546,21 @@ function Toast({
|
|
|
592
546
|
warning: "#eab308",
|
|
593
547
|
error: "#ef4444"
|
|
594
548
|
};
|
|
595
|
-
return /* @__PURE__ */ (0,
|
|
549
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
596
550
|
"div",
|
|
597
551
|
{
|
|
598
552
|
style: {
|
|
599
553
|
backgroundColor: bgColors[type],
|
|
600
554
|
color: "white",
|
|
601
|
-
padding: "0.5rem
|
|
555
|
+
padding: "0.5rem 1rem",
|
|
602
556
|
borderRadius: "0.25rem",
|
|
603
557
|
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
604
558
|
position: "relative",
|
|
605
559
|
minWidth: "200px"
|
|
606
560
|
},
|
|
607
561
|
children: [
|
|
608
|
-
/* @__PURE__ */ (0,
|
|
609
|
-
/* @__PURE__ */ (0,
|
|
562
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
|
|
563
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
610
564
|
"button",
|
|
611
565
|
{
|
|
612
566
|
onClick: onClose,
|
|
@@ -631,17 +585,14 @@ function Toast({
|
|
|
631
585
|
|
|
632
586
|
// src/hooks/use-copilot-runtime-client.ts
|
|
633
587
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
634
|
-
var
|
|
588
|
+
var import_react7 = require("react");
|
|
635
589
|
var useCopilotRuntimeClient = (options) => {
|
|
636
590
|
const { addGraphQLErrorsToast } = useToast();
|
|
637
|
-
const
|
|
638
|
-
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
591
|
+
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
639
592
|
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
640
593
|
handleGQLErrors: (error) => {
|
|
641
594
|
if (error.graphQLErrors.length) {
|
|
642
595
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
643
|
-
} else {
|
|
644
|
-
addErrorToast([error]);
|
|
645
596
|
}
|
|
646
597
|
}
|
|
647
598
|
}));
|
|
@@ -663,41 +614,13 @@ function getHostname() {
|
|
|
663
614
|
return "";
|
|
664
615
|
}
|
|
665
616
|
|
|
666
|
-
// src/components/error-boundary/error-boundary.tsx
|
|
667
|
-
var import_react9 = __toESM(require("react"));
|
|
668
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
669
|
-
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
670
|
-
constructor(props) {
|
|
671
|
-
super(props);
|
|
672
|
-
this.state = { hasError: false };
|
|
673
|
-
}
|
|
674
|
-
static getDerivedStateFromError(error) {
|
|
675
|
-
return { hasError: true, error };
|
|
676
|
-
}
|
|
677
|
-
componentDidCatch(error, errorInfo) {
|
|
678
|
-
console.error("CopilotKit Error:", error, errorInfo);
|
|
679
|
-
}
|
|
680
|
-
render() {
|
|
681
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
|
|
682
|
-
}
|
|
683
|
-
};
|
|
684
|
-
function ErrorToast2({ error, children }) {
|
|
685
|
-
const addErrorToast = useErrorToast();
|
|
686
|
-
(0, import_react9.useEffect)(() => {
|
|
687
|
-
if (error) {
|
|
688
|
-
addErrorToast([error]);
|
|
689
|
-
}
|
|
690
|
-
}, [error, addErrorToast]);
|
|
691
|
-
return children;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
617
|
// src/components/copilot-provider/copilotkit.tsx
|
|
695
|
-
var
|
|
618
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
696
619
|
function CopilotKit(_a) {
|
|
697
620
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
698
621
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
699
622
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
700
|
-
return /* @__PURE__ */ (0,
|
|
623
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
|
|
701
624
|
}
|
|
702
625
|
function CopilotKitInternal(_a) {
|
|
703
626
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
@@ -707,50 +630,49 @@ function CopilotKitInternal(_a) {
|
|
|
707
630
|
);
|
|
708
631
|
}
|
|
709
632
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
710
|
-
const [actions, setActions] = (0,
|
|
711
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
712
|
-
const chatComponentsCache = (0,
|
|
633
|
+
const [actions, setActions] = (0, import_react8.useState)({});
|
|
634
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
|
|
635
|
+
const chatComponentsCache = (0, import_react8.useRef)({
|
|
713
636
|
actions: {},
|
|
714
637
|
coAgentStateRenders: {}
|
|
715
638
|
});
|
|
716
639
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
717
|
-
const [isLoading, setIsLoading] = (0,
|
|
718
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
719
|
-
const [authStates, setAuthStates] = (0, import_react10.useState)({});
|
|
640
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
641
|
+
const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
|
|
720
642
|
const {
|
|
721
643
|
addElement: addDocument,
|
|
722
644
|
removeElement: removeDocument,
|
|
723
645
|
allElements: allDocuments
|
|
724
646
|
} = use_flat_category_store_default();
|
|
725
|
-
const setAction = (0,
|
|
647
|
+
const setAction = (0, import_react8.useCallback)((id, action) => {
|
|
726
648
|
setActions((prevPoints) => {
|
|
727
649
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
728
650
|
[id]: action
|
|
729
651
|
});
|
|
730
652
|
});
|
|
731
653
|
}, []);
|
|
732
|
-
const removeAction = (0,
|
|
654
|
+
const removeAction = (0, import_react8.useCallback)((id) => {
|
|
733
655
|
setActions((prevPoints) => {
|
|
734
656
|
const newPoints = __spreadValues({}, prevPoints);
|
|
735
657
|
delete newPoints[id];
|
|
736
658
|
return newPoints;
|
|
737
659
|
});
|
|
738
660
|
}, []);
|
|
739
|
-
const setCoAgentStateRender = (0,
|
|
661
|
+
const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
|
|
740
662
|
setCoAgentStateRenders((prevPoints) => {
|
|
741
663
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
742
664
|
[id]: stateRender
|
|
743
665
|
});
|
|
744
666
|
});
|
|
745
667
|
}, []);
|
|
746
|
-
const removeCoAgentStateRender = (0,
|
|
668
|
+
const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
|
|
747
669
|
setCoAgentStateRenders((prevPoints) => {
|
|
748
670
|
const newPoints = __spreadValues({}, prevPoints);
|
|
749
671
|
delete newPoints[id];
|
|
750
672
|
return newPoints;
|
|
751
673
|
});
|
|
752
674
|
}, []);
|
|
753
|
-
const getContextString = (0,
|
|
675
|
+
const getContextString = (0, import_react8.useCallback)(
|
|
754
676
|
(documents, categories) => {
|
|
755
677
|
const documentsString = documents.map((document) => {
|
|
756
678
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -763,37 +685,37 @@ ${nonDocumentStrings}`;
|
|
|
763
685
|
},
|
|
764
686
|
[printTree]
|
|
765
687
|
);
|
|
766
|
-
const addContext = (0,
|
|
688
|
+
const addContext = (0, import_react8.useCallback)(
|
|
767
689
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
768
690
|
return addElement(context, categories, parentId);
|
|
769
691
|
},
|
|
770
692
|
[addElement]
|
|
771
693
|
);
|
|
772
|
-
const removeContext = (0,
|
|
694
|
+
const removeContext = (0, import_react8.useCallback)(
|
|
773
695
|
(id) => {
|
|
774
696
|
removeElement(id);
|
|
775
697
|
},
|
|
776
698
|
[removeElement]
|
|
777
699
|
);
|
|
778
|
-
const getFunctionCallHandler = (0,
|
|
700
|
+
const getFunctionCallHandler = (0, import_react8.useCallback)(
|
|
779
701
|
(customEntryPoints) => {
|
|
780
702
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
781
703
|
},
|
|
782
704
|
[actions]
|
|
783
705
|
);
|
|
784
|
-
const getDocumentsContext = (0,
|
|
706
|
+
const getDocumentsContext = (0, import_react8.useCallback)(
|
|
785
707
|
(categories) => {
|
|
786
708
|
return allDocuments(categories);
|
|
787
709
|
},
|
|
788
710
|
[allDocuments]
|
|
789
711
|
);
|
|
790
|
-
const addDocumentContext = (0,
|
|
712
|
+
const addDocumentContext = (0, import_react8.useCallback)(
|
|
791
713
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
792
714
|
return addDocument(documentPointer, categories);
|
|
793
715
|
},
|
|
794
716
|
[addDocument]
|
|
795
717
|
);
|
|
796
|
-
const removeDocumentContext = (0,
|
|
718
|
+
const removeDocumentContext = (0, import_react8.useCallback)(
|
|
797
719
|
(documentId) => {
|
|
798
720
|
removeDocument(documentId);
|
|
799
721
|
},
|
|
@@ -806,7 +728,7 @@ ${nonDocumentStrings}`;
|
|
|
806
728
|
);
|
|
807
729
|
}
|
|
808
730
|
}
|
|
809
|
-
const copilotApiConfig = (0,
|
|
731
|
+
const copilotApiConfig = (0, import_react8.useMemo)(() => {
|
|
810
732
|
var _a2, _b2;
|
|
811
733
|
let cloud = void 0;
|
|
812
734
|
if (props.publicApiKey) {
|
|
@@ -841,27 +763,14 @@ ${nonDocumentStrings}`;
|
|
|
841
763
|
props.credentials,
|
|
842
764
|
props.cloudRestrictToTopic
|
|
843
765
|
]);
|
|
844
|
-
const headers = (
|
|
845
|
-
const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
|
|
846
|
-
if (state.status === "authenticated" && state.authHeaders) {
|
|
847
|
-
return __spreadValues(__spreadValues({}, acc), Object.entries(state.authHeaders).reduce(
|
|
848
|
-
(headers2, [key, value]) => __spreadProps(__spreadValues({}, headers2), {
|
|
849
|
-
[key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
|
|
850
|
-
}),
|
|
851
|
-
{}
|
|
852
|
-
));
|
|
853
|
-
}
|
|
854
|
-
return acc;
|
|
855
|
-
}, {});
|
|
856
|
-
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
857
|
-
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
766
|
+
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
858
767
|
const runtimeClient = useCopilotRuntimeClient({
|
|
859
768
|
url: copilotApiConfig.chatApiEndpoint,
|
|
860
769
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
861
770
|
headers,
|
|
862
771
|
credentials: copilotApiConfig.credentials
|
|
863
772
|
});
|
|
864
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
773
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
|
|
865
774
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
866
775
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
867
776
|
};
|
|
@@ -871,41 +780,16 @@ ${nonDocumentStrings}`;
|
|
|
871
780
|
return rest;
|
|
872
781
|
});
|
|
873
782
|
};
|
|
874
|
-
const [
|
|
875
|
-
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
876
|
-
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
877
|
-
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
878
|
-
(value) => {
|
|
879
|
-
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
880
|
-
coagentStatesRef.current = newValue;
|
|
881
|
-
setCoagentStates((prev) => {
|
|
882
|
-
return newValue;
|
|
883
|
-
});
|
|
884
|
-
},
|
|
885
|
-
[]
|
|
886
|
-
);
|
|
887
|
-
(0, import_react10.useEffect)(() => {
|
|
888
|
-
const fetchData = () => __async(this, null, function* () {
|
|
889
|
-
var _a2;
|
|
890
|
-
const result = yield runtimeClient.availableAgents();
|
|
891
|
-
if ((_a2 = result.data) == null ? void 0 : _a2.availableAgents) {
|
|
892
|
-
setAvailableAgents(result.data.availableAgents.agents);
|
|
893
|
-
}
|
|
894
|
-
});
|
|
895
|
-
void fetchData();
|
|
896
|
-
}, []);
|
|
783
|
+
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
897
784
|
let initialAgentSession = null;
|
|
898
785
|
if (props.agent) {
|
|
899
786
|
initialAgentSession = {
|
|
900
787
|
agentName: props.agent
|
|
901
788
|
};
|
|
902
789
|
}
|
|
903
|
-
const [agentSession, setAgentSession] = (0,
|
|
904
|
-
const [threadId, setThreadId] = (0, import_react10.useState)(null);
|
|
905
|
-
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
906
|
-
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
790
|
+
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
907
791
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
908
|
-
return /* @__PURE__ */ (0,
|
|
792
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
909
793
|
CopilotContext.Provider,
|
|
910
794
|
{
|
|
911
795
|
value: {
|
|
@@ -934,24 +818,11 @@ ${nonDocumentStrings}`;
|
|
|
934
818
|
showDevConsole,
|
|
935
819
|
coagentStates,
|
|
936
820
|
setCoagentStates,
|
|
937
|
-
coagentStatesRef,
|
|
938
|
-
setCoagentStatesWithRef,
|
|
939
821
|
agentSession,
|
|
940
822
|
setAgentSession,
|
|
941
|
-
runtimeClient
|
|
942
|
-
forwardedParameters: props.forwardedParameters || {},
|
|
943
|
-
agentLock: props.agent || null,
|
|
944
|
-
threadId,
|
|
945
|
-
setThreadId,
|
|
946
|
-
runId,
|
|
947
|
-
setRunId,
|
|
948
|
-
chatAbortControllerRef,
|
|
949
|
-
availableAgents,
|
|
950
|
-
authConfig: props.authConfig,
|
|
951
|
-
authStates,
|
|
952
|
-
setAuthStates
|
|
823
|
+
runtimeClient
|
|
953
824
|
},
|
|
954
|
-
children: /* @__PURE__ */ (0,
|
|
825
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
955
826
|
}
|
|
956
827
|
);
|
|
957
828
|
}
|