@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
|
@@ -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,26 +137,14 @@ 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 },
|
|
155
|
-
availableAgents: []
|
|
142
|
+
}
|
|
156
143
|
};
|
|
157
144
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
158
|
-
function returnAndThrowInDebug(
|
|
145
|
+
function returnAndThrowInDebug(value) {
|
|
159
146
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
147
|
+
return value;
|
|
160
148
|
}
|
|
161
149
|
|
|
162
150
|
// src/hooks/use-tree.ts
|
|
@@ -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,21 +547,21 @@ 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: {
|
|
600
554
|
backgroundColor: bgColors[type],
|
|
601
555
|
color: "white",
|
|
602
|
-
padding: "0.5rem
|
|
556
|
+
padding: "0.5rem 1rem",
|
|
603
557
|
borderRadius: "0.25rem",
|
|
604
558
|
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
605
559
|
position: "relative",
|
|
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,50 +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,
|
|
720
|
-
const [authStates, setAuthStates] = (0, import_react10.useState)({});
|
|
641
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
642
|
+
const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
|
|
721
643
|
const {
|
|
722
644
|
addElement: addDocument,
|
|
723
645
|
removeElement: removeDocument,
|
|
724
646
|
allElements: allDocuments
|
|
725
647
|
} = use_flat_category_store_default();
|
|
726
|
-
const setAction = (0,
|
|
648
|
+
const setAction = (0, import_react8.useCallback)((id, action) => {
|
|
727
649
|
setActions((prevPoints) => {
|
|
728
650
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
729
651
|
[id]: action
|
|
730
652
|
});
|
|
731
653
|
});
|
|
732
654
|
}, []);
|
|
733
|
-
const removeAction = (0,
|
|
655
|
+
const removeAction = (0, import_react8.useCallback)((id) => {
|
|
734
656
|
setActions((prevPoints) => {
|
|
735
657
|
const newPoints = __spreadValues({}, prevPoints);
|
|
736
658
|
delete newPoints[id];
|
|
737
659
|
return newPoints;
|
|
738
660
|
});
|
|
739
661
|
}, []);
|
|
740
|
-
const setCoAgentStateRender = (0,
|
|
662
|
+
const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
|
|
741
663
|
setCoAgentStateRenders((prevPoints) => {
|
|
742
664
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
743
665
|
[id]: stateRender
|
|
744
666
|
});
|
|
745
667
|
});
|
|
746
668
|
}, []);
|
|
747
|
-
const removeCoAgentStateRender = (0,
|
|
669
|
+
const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
|
|
748
670
|
setCoAgentStateRenders((prevPoints) => {
|
|
749
671
|
const newPoints = __spreadValues({}, prevPoints);
|
|
750
672
|
delete newPoints[id];
|
|
751
673
|
return newPoints;
|
|
752
674
|
});
|
|
753
675
|
}, []);
|
|
754
|
-
const getContextString = (0,
|
|
676
|
+
const getContextString = (0, import_react8.useCallback)(
|
|
755
677
|
(documents, categories) => {
|
|
756
678
|
const documentsString = documents.map((document) => {
|
|
757
679
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -764,37 +686,37 @@ ${nonDocumentStrings}`;
|
|
|
764
686
|
},
|
|
765
687
|
[printTree]
|
|
766
688
|
);
|
|
767
|
-
const addContext = (0,
|
|
689
|
+
const addContext = (0, import_react8.useCallback)(
|
|
768
690
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
769
691
|
return addElement(context, categories, parentId);
|
|
770
692
|
},
|
|
771
693
|
[addElement]
|
|
772
694
|
);
|
|
773
|
-
const removeContext = (0,
|
|
695
|
+
const removeContext = (0, import_react8.useCallback)(
|
|
774
696
|
(id) => {
|
|
775
697
|
removeElement(id);
|
|
776
698
|
},
|
|
777
699
|
[removeElement]
|
|
778
700
|
);
|
|
779
|
-
const getFunctionCallHandler = (0,
|
|
701
|
+
const getFunctionCallHandler = (0, import_react8.useCallback)(
|
|
780
702
|
(customEntryPoints) => {
|
|
781
703
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
782
704
|
},
|
|
783
705
|
[actions]
|
|
784
706
|
);
|
|
785
|
-
const getDocumentsContext = (0,
|
|
707
|
+
const getDocumentsContext = (0, import_react8.useCallback)(
|
|
786
708
|
(categories) => {
|
|
787
709
|
return allDocuments(categories);
|
|
788
710
|
},
|
|
789
711
|
[allDocuments]
|
|
790
712
|
);
|
|
791
|
-
const addDocumentContext = (0,
|
|
713
|
+
const addDocumentContext = (0, import_react8.useCallback)(
|
|
792
714
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
793
715
|
return addDocument(documentPointer, categories);
|
|
794
716
|
},
|
|
795
717
|
[addDocument]
|
|
796
718
|
);
|
|
797
|
-
const removeDocumentContext = (0,
|
|
719
|
+
const removeDocumentContext = (0, import_react8.useCallback)(
|
|
798
720
|
(documentId) => {
|
|
799
721
|
removeDocument(documentId);
|
|
800
722
|
},
|
|
@@ -807,7 +729,7 @@ ${nonDocumentStrings}`;
|
|
|
807
729
|
);
|
|
808
730
|
}
|
|
809
731
|
}
|
|
810
|
-
const copilotApiConfig = (0,
|
|
732
|
+
const copilotApiConfig = (0, import_react8.useMemo)(() => {
|
|
811
733
|
var _a2, _b2;
|
|
812
734
|
let cloud = void 0;
|
|
813
735
|
if (props.publicApiKey) {
|
|
@@ -842,27 +764,14 @@ ${nonDocumentStrings}`;
|
|
|
842
764
|
props.credentials,
|
|
843
765
|
props.cloudRestrictToTopic
|
|
844
766
|
]);
|
|
845
|
-
const headers = (
|
|
846
|
-
const authHeaders = Object.values(authStates || {}).reduce((acc, state) => {
|
|
847
|
-
if (state.status === "authenticated" && state.authHeaders) {
|
|
848
|
-
return __spreadValues(__spreadValues({}, acc), Object.entries(state.authHeaders).reduce(
|
|
849
|
-
(headers2, [key, value]) => __spreadProps(__spreadValues({}, headers2), {
|
|
850
|
-
[key.startsWith("X-Custom-") ? key : `X-Custom-${key}`]: value
|
|
851
|
-
}),
|
|
852
|
-
{}
|
|
853
|
-
));
|
|
854
|
-
}
|
|
855
|
-
return acc;
|
|
856
|
-
}, {});
|
|
857
|
-
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
858
|
-
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
767
|
+
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
859
768
|
const runtimeClient = useCopilotRuntimeClient({
|
|
860
769
|
url: copilotApiConfig.chatApiEndpoint,
|
|
861
770
|
publicApiKey: copilotApiConfig.publicApiKey,
|
|
862
771
|
headers,
|
|
863
772
|
credentials: copilotApiConfig.credentials
|
|
864
773
|
});
|
|
865
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
774
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
|
|
866
775
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
867
776
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
868
777
|
};
|
|
@@ -872,41 +781,16 @@ ${nonDocumentStrings}`;
|
|
|
872
781
|
return rest;
|
|
873
782
|
});
|
|
874
783
|
};
|
|
875
|
-
const [
|
|
876
|
-
const [coagentStates, setCoagentStates] = (0, import_react10.useState)({});
|
|
877
|
-
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
878
|
-
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
879
|
-
(value) => {
|
|
880
|
-
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
881
|
-
coagentStatesRef.current = newValue;
|
|
882
|
-
setCoagentStates((prev) => {
|
|
883
|
-
return newValue;
|
|
884
|
-
});
|
|
885
|
-
},
|
|
886
|
-
[]
|
|
887
|
-
);
|
|
888
|
-
(0, import_react10.useEffect)(() => {
|
|
889
|
-
const fetchData = () => __async(this, null, function* () {
|
|
890
|
-
var _a2;
|
|
891
|
-
const result = yield runtimeClient.availableAgents();
|
|
892
|
-
if ((_a2 = result.data) == null ? void 0 : _a2.availableAgents) {
|
|
893
|
-
setAvailableAgents(result.data.availableAgents.agents);
|
|
894
|
-
}
|
|
895
|
-
});
|
|
896
|
-
void fetchData();
|
|
897
|
-
}, []);
|
|
784
|
+
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
898
785
|
let initialAgentSession = null;
|
|
899
786
|
if (props.agent) {
|
|
900
787
|
initialAgentSession = {
|
|
901
788
|
agentName: props.agent
|
|
902
789
|
};
|
|
903
790
|
}
|
|
904
|
-
const [agentSession, setAgentSession] = (0,
|
|
905
|
-
const [threadId, setThreadId] = (0, import_react10.useState)(null);
|
|
906
|
-
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
907
|
-
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
791
|
+
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
908
792
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
909
|
-
return /* @__PURE__ */ (0,
|
|
793
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
910
794
|
CopilotContext.Provider,
|
|
911
795
|
{
|
|
912
796
|
value: {
|
|
@@ -935,24 +819,11 @@ ${nonDocumentStrings}`;
|
|
|
935
819
|
showDevConsole,
|
|
936
820
|
coagentStates,
|
|
937
821
|
setCoagentStates,
|
|
938
|
-
coagentStatesRef,
|
|
939
|
-
setCoagentStatesWithRef,
|
|
940
822
|
agentSession,
|
|
941
823
|
setAgentSession,
|
|
942
|
-
runtimeClient
|
|
943
|
-
forwardedParameters: props.forwardedParameters || {},
|
|
944
|
-
agentLock: props.agent || null,
|
|
945
|
-
threadId,
|
|
946
|
-
setThreadId,
|
|
947
|
-
runId,
|
|
948
|
-
setRunId,
|
|
949
|
-
chatAbortControllerRef,
|
|
950
|
-
availableAgents,
|
|
951
|
-
authConfig: props.authConfig,
|
|
952
|
-
authStates,
|
|
953
|
-
setAuthStates
|
|
824
|
+
runtimeClient
|
|
954
825
|
},
|
|
955
|
-
children: /* @__PURE__ */ (0,
|
|
826
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
956
827
|
}
|
|
957
828
|
);
|
|
958
829
|
}
|