@copilotkit/react-core 1.4.1-pre.5 → 1.4.1
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 +63 -0
- package/dist/chunk-2KCEHGSI.mjs +192 -0
- package/dist/chunk-2KCEHGSI.mjs.map +1 -0
- package/dist/{chunk-IIGBMHZI.mjs → chunk-DT52QX4H.mjs} +4 -4
- package/dist/{chunk-TRXKPXDE.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-OQ326E7V.mjs → chunk-JDQCJCAQ.mjs} +18 -5
- package/dist/chunk-JDQCJCAQ.mjs.map +1 -0
- package/dist/chunk-L34MHAXR.mjs +1 -0
- package/dist/{chunk-HVWV4SDG.mjs → chunk-LMFSB5D5.mjs} +2 -2
- package/dist/{chunk-2MPUQRAY.mjs → chunk-LODRWFMB.mjs} +2 -1
- package/dist/chunk-LODRWFMB.mjs.map +1 -0
- package/dist/chunk-MLAS4QUR.mjs +18 -0
- package/dist/chunk-MLAS4QUR.mjs.map +1 -0
- package/dist/{chunk-K76NL2VN.mjs → chunk-MWZO6TUR.mjs} +2 -2
- package/dist/chunk-O7ARI5CV.mjs +31 -0
- package/dist/chunk-O7ARI5CV.mjs.map +1 -0
- package/dist/chunk-ODN4H66E.mjs +31 -0
- package/dist/chunk-ODN4H66E.mjs.map +1 -0
- package/dist/{chunk-6YEMNWKE.mjs → chunk-P6VS7ST4.mjs} +177 -5
- package/dist/chunk-P6VS7ST4.mjs.map +1 -0
- package/dist/{chunk-ANOG3W5S.mjs → chunk-QDGDXRRJ.mjs} +2 -2
- package/dist/{chunk-VE63DJCR.mjs → chunk-V22C3DOQ.mjs} +3 -3
- package/dist/{chunk-MTVKTUZD.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.js +283 -26
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +8 -2
- package/dist/components/copilot-provider/index.js +281 -26
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +6 -3
- package/dist/components/index.js +281 -26
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +6 -4
- package/dist/components/toast/exclamation-mark-icon.d.ts +9 -0
- package/dist/components/toast/exclamation-mark-icon.js +55 -0
- package/dist/components/toast/exclamation-mark-icon.js.map +1 -0
- package/dist/components/toast/exclamation-mark-icon.mjs +8 -0
- package/dist/components/toast/toast-provider.d.ts +29 -0
- package/dist/components/toast/toast-provider.js +255 -0
- package/dist/components/toast/toast-provider.js.map +1 -0
- package/dist/components/toast/toast-provider.mjs +11 -0
- package/dist/context/copilot-context.d.ts +2 -0
- package/dist/context/copilot-context.js +1 -0
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +1 -0
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +104 -62
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +17 -12
- package/dist/hooks/use-chat.js +65 -26
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -1
- package/dist/hooks/use-coagent-state-render.js +1 -0
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.js +83 -43
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +9 -7
- package/dist/hooks/use-copilot-action.js +1 -0
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-chat.js +85 -45
- 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 +1 -0
- 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.d.ts +5 -0
- package/dist/hooks/use-copilot-runtime-client.js +76 -0
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -0
- package/dist/hooks/use-copilot-runtime-client.mjs +10 -0
- package/dist/hooks/use-make-copilot-document-readable.js +1 -0
- 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 -0
- package/dist/index.js +500 -241
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -19
- package/dist/lib/copilot-task.d.ts +1 -0
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +7 -5
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -5
- package/dist/utils/dev-console.d.ts +3 -0
- package/dist/utils/dev-console.js +42 -0
- package/dist/utils/dev-console.js.map +1 -0
- package/dist/utils/dev-console.mjs +8 -0
- package/dist/utils/dev-console.mjs.map +1 -0
- package/dist/utils/extract.js +4 -26
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +6 -5
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +22 -28
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -7
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit.tsx +32 -1
- package/src/components/toast/exclamation-mark-icon.tsx +27 -0
- package/src/components/toast/toast-provider.tsx +209 -0
- package/src/context/copilot-context.tsx +5 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-chat.ts +14 -6
- package/src/hooks/use-copilot-runtime-client.ts +24 -0
- package/src/utils/dev-console.ts +18 -0
- package/src/utils/extract.ts +2 -16
- package/src/utils/index.ts +1 -0
- package/dist/chunk-2MPUQRAY.mjs.map +0 -1
- package/dist/chunk-6YEMNWKE.mjs.map +0 -1
- package/dist/chunk-BWYAGPEF.mjs +0 -1
- package/dist/chunk-JD7BAH7U.mjs +0 -1
- package/dist/chunk-OQ326E7V.mjs.map +0 -1
- package/dist/chunk-SPCZTZCY.mjs +0 -1
- package/dist/chunk-YJLRG5U3.mjs +0 -1
- package/dist/chunk-ZM6HV22S.mjs +0 -164
- package/dist/chunk-ZM6HV22S.mjs.map +0 -1
- /package/dist/{chunk-IIGBMHZI.mjs.map → chunk-DT52QX4H.mjs.map} +0 -0
- /package/dist/{chunk-TRXKPXDE.mjs.map → chunk-H4VZMKR6.mjs.map} +0 -0
- /package/dist/{chunk-BWYAGPEF.mjs.map → chunk-L34MHAXR.mjs.map} +0 -0
- /package/dist/{chunk-HVWV4SDG.mjs.map → chunk-LMFSB5D5.mjs.map} +0 -0
- /package/dist/{chunk-K76NL2VN.mjs.map → chunk-MWZO6TUR.mjs.map} +0 -0
- /package/dist/{chunk-ANOG3W5S.mjs.map → chunk-QDGDXRRJ.mjs.map} +0 -0
- /package/dist/{chunk-VE63DJCR.mjs.map → chunk-V22C3DOQ.mjs.map} +0 -0
- /package/dist/{chunk-MTVKTUZD.mjs.map → chunk-XINZBP3J.mjs.map} +0 -0
- /package/dist/{chunk-JD7BAH7U.mjs.map → components/toast/exclamation-mark-icon.mjs.map} +0 -0
- /package/dist/{chunk-SPCZTZCY.mjs.map → components/toast/toast-provider.mjs.map} +0 -0
- /package/dist/{chunk-YJLRG5U3.mjs.map → hooks/use-copilot-runtime-client.mjs.map} +0 -0
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import "../../chunk-SPCZTZCY.mjs";
|
|
2
1
|
import {
|
|
3
2
|
CopilotKit,
|
|
4
3
|
defaultCopilotContextCategories
|
|
5
|
-
} from "../../chunk-
|
|
4
|
+
} from "../../chunk-P6VS7ST4.mjs";
|
|
5
|
+
import "../../chunk-MLAS4QUR.mjs";
|
|
6
6
|
import "../../chunk-XXR4QFAQ.mjs";
|
|
7
7
|
import "../../chunk-5FHSUKQL.mjs";
|
|
8
8
|
import "../../chunk-6U3UH3KO.mjs";
|
|
9
9
|
import "../../chunk-DCTJZ742.mjs";
|
|
10
|
-
import "../../chunk-
|
|
10
|
+
import "../../chunk-ODN4H66E.mjs";
|
|
11
|
+
import "../../chunk-2KCEHGSI.mjs";
|
|
12
|
+
import "../../chunk-O7ARI5CV.mjs";
|
|
13
|
+
import "../../chunk-LODRWFMB.mjs";
|
|
11
14
|
import "../../chunk-SKC7AJIV.mjs";
|
|
12
15
|
export {
|
|
13
16
|
CopilotKit,
|
package/dist/components/index.js
CHANGED
|
@@ -86,7 +86,7 @@ __export(components_exports, {
|
|
|
86
86
|
module.exports = __toCommonJS(components_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"));
|
|
@@ -116,6 +116,7 @@ var emptyCopilotContext = {
|
|
|
116
116
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
117
117
|
removeDocumentContext: () => {
|
|
118
118
|
},
|
|
119
|
+
runtimeClient: {},
|
|
119
120
|
copilotApiConfig: new class {
|
|
120
121
|
get chatApiEndpoint() {
|
|
121
122
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
@@ -375,9 +376,254 @@ function CopilotMessages(_a) {
|
|
|
375
376
|
);
|
|
376
377
|
}
|
|
377
378
|
|
|
378
|
-
// src/components/
|
|
379
|
+
// src/components/toast/toast-provider.tsx
|
|
380
|
+
var import_react6 = require("react");
|
|
381
|
+
|
|
382
|
+
// src/components/toast/exclamation-mark-icon.tsx
|
|
379
383
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
384
|
+
var ExclamationMarkIcon = ({
|
|
385
|
+
className,
|
|
386
|
+
style
|
|
387
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
388
|
+
"svg",
|
|
389
|
+
{
|
|
390
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
391
|
+
width: "24",
|
|
392
|
+
height: "24",
|
|
393
|
+
viewBox: "0 0 24 24",
|
|
394
|
+
fill: "none",
|
|
395
|
+
stroke: "currentColor",
|
|
396
|
+
strokeWidth: "2",
|
|
397
|
+
strokeLinecap: "round",
|
|
398
|
+
strokeLinejoin: "round",
|
|
399
|
+
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
400
|
+
style,
|
|
401
|
+
children: [
|
|
402
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
403
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
404
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
405
|
+
]
|
|
406
|
+
}
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
// src/components/toast/toast-provider.tsx
|
|
410
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
411
|
+
var ToastContext = (0, import_react6.createContext)(void 0);
|
|
412
|
+
function useToast() {
|
|
413
|
+
const context = (0, import_react6.useContext)(ToastContext);
|
|
414
|
+
if (!context) {
|
|
415
|
+
throw new Error("useToast must be used within a ToastProvider");
|
|
416
|
+
}
|
|
417
|
+
return context;
|
|
418
|
+
}
|
|
419
|
+
function ToastProvider({
|
|
420
|
+
enabled,
|
|
421
|
+
children
|
|
422
|
+
}) {
|
|
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 })]);
|
|
427
|
+
if (toast.duration) {
|
|
428
|
+
setTimeout(() => {
|
|
429
|
+
removeToast(id);
|
|
430
|
+
}, toast.duration);
|
|
431
|
+
}
|
|
432
|
+
}, []);
|
|
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
|
+
});
|
|
467
|
+
addToast({
|
|
468
|
+
type: "error",
|
|
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
|
+
)
|
|
482
|
+
});
|
|
483
|
+
}, []);
|
|
484
|
+
const removeToast = (0, import_react6.useCallback)((id) => {
|
|
485
|
+
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
486
|
+
}, []);
|
|
487
|
+
const value = {
|
|
488
|
+
toasts,
|
|
489
|
+
addToast,
|
|
490
|
+
addGraphQLErrorsToast,
|
|
491
|
+
removeToast,
|
|
492
|
+
enabled
|
|
493
|
+
};
|
|
494
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
|
|
495
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
496
|
+
"div",
|
|
497
|
+
{
|
|
498
|
+
style: {
|
|
499
|
+
position: "fixed",
|
|
500
|
+
bottom: "1rem",
|
|
501
|
+
left: "50%",
|
|
502
|
+
transform: "translateX(-50%)",
|
|
503
|
+
zIndex: 50,
|
|
504
|
+
display: "flex",
|
|
505
|
+
flexDirection: "column",
|
|
506
|
+
gap: "0.5rem"
|
|
507
|
+
},
|
|
508
|
+
children: [
|
|
509
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
510
|
+
"button",
|
|
511
|
+
{
|
|
512
|
+
onClick: () => setToasts([]),
|
|
513
|
+
style: {
|
|
514
|
+
padding: "4px 8px",
|
|
515
|
+
fontSize: "12px",
|
|
516
|
+
cursor: "pointer",
|
|
517
|
+
background: "white",
|
|
518
|
+
border: "1px solid rgba(0,0,0,0.2)",
|
|
519
|
+
borderRadius: "4px"
|
|
520
|
+
},
|
|
521
|
+
children: "Close All"
|
|
522
|
+
}
|
|
523
|
+
) }),
|
|
524
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
525
|
+
Toast,
|
|
526
|
+
{
|
|
527
|
+
message: toast.message,
|
|
528
|
+
type: toast.type,
|
|
529
|
+
onClose: () => removeToast(toast.id)
|
|
530
|
+
},
|
|
531
|
+
toast.id
|
|
532
|
+
))
|
|
533
|
+
]
|
|
534
|
+
}
|
|
535
|
+
),
|
|
536
|
+
children
|
|
537
|
+
] });
|
|
538
|
+
}
|
|
539
|
+
function Toast({
|
|
540
|
+
message,
|
|
541
|
+
type = "info",
|
|
542
|
+
onClose
|
|
543
|
+
}) {
|
|
544
|
+
const bgColors = {
|
|
545
|
+
info: "#3b82f6",
|
|
546
|
+
success: "#22c55e",
|
|
547
|
+
warning: "#eab308",
|
|
548
|
+
error: "#ef4444"
|
|
549
|
+
};
|
|
550
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
551
|
+
"div",
|
|
552
|
+
{
|
|
553
|
+
style: {
|
|
554
|
+
backgroundColor: bgColors[type],
|
|
555
|
+
color: "white",
|
|
556
|
+
padding: "0.5rem 1rem",
|
|
557
|
+
borderRadius: "0.25rem",
|
|
558
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
559
|
+
position: "relative",
|
|
560
|
+
minWidth: "200px"
|
|
561
|
+
},
|
|
562
|
+
children: [
|
|
563
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
|
|
564
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
565
|
+
"button",
|
|
566
|
+
{
|
|
567
|
+
onClick: onClose,
|
|
568
|
+
style: {
|
|
569
|
+
position: "absolute",
|
|
570
|
+
top: "0",
|
|
571
|
+
right: "0",
|
|
572
|
+
background: "none",
|
|
573
|
+
border: "none",
|
|
574
|
+
color: "white",
|
|
575
|
+
cursor: "pointer",
|
|
576
|
+
padding: "0.5rem",
|
|
577
|
+
fontSize: "1rem"
|
|
578
|
+
},
|
|
579
|
+
children: "\u2715"
|
|
580
|
+
}
|
|
581
|
+
)
|
|
582
|
+
]
|
|
583
|
+
}
|
|
584
|
+
);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// src/hooks/use-copilot-runtime-client.ts
|
|
588
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
589
|
+
var import_react7 = require("react");
|
|
590
|
+
var useCopilotRuntimeClient = (options) => {
|
|
591
|
+
const { addGraphQLErrorsToast } = useToast();
|
|
592
|
+
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
593
|
+
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
594
|
+
handleGQLErrors: (error) => {
|
|
595
|
+
if (error.graphQLErrors.length) {
|
|
596
|
+
addGraphQLErrorsToast(error.graphQLErrors);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
}));
|
|
600
|
+
}, [options, addGraphQLErrorsToast]);
|
|
601
|
+
return runtimeClient;
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
// src/utils/dev-console.ts
|
|
605
|
+
function shouldShowDevConsole(showDevConsole) {
|
|
606
|
+
if (typeof showDevConsole === "boolean") {
|
|
607
|
+
return showDevConsole;
|
|
608
|
+
}
|
|
609
|
+
return getHostname() === "localhost" || getHostname() === "127.0.0.1" || getHostname() === "0.0.0.0" || getHostname() === "::1";
|
|
610
|
+
}
|
|
611
|
+
function getHostname() {
|
|
612
|
+
if (typeof window !== "undefined" && window.location) {
|
|
613
|
+
return window.location.hostname;
|
|
614
|
+
}
|
|
615
|
+
return "";
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
619
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
380
620
|
function CopilotKit(_a) {
|
|
621
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
622
|
+
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
623
|
+
const enabled = shouldShowDevConsole(showDevConsole);
|
|
624
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
|
|
625
|
+
}
|
|
626
|
+
function CopilotKitInternal(_a) {
|
|
381
627
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
382
628
|
if (!props.runtimeUrl && !props.publicApiKey) {
|
|
383
629
|
throw new Error(
|
|
@@ -385,49 +631,49 @@ function CopilotKit(_a) {
|
|
|
385
631
|
);
|
|
386
632
|
}
|
|
387
633
|
const chatApiEndpoint = props.runtimeUrl || import_shared3.COPILOT_CLOUD_CHAT_URL;
|
|
388
|
-
const [actions, setActions] = (0,
|
|
389
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
390
|
-
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)({
|
|
391
637
|
actions: {},
|
|
392
638
|
coAgentStateRenders: {}
|
|
393
639
|
});
|
|
394
640
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
395
|
-
const [isLoading, setIsLoading] = (0,
|
|
396
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
641
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
642
|
+
const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
|
|
397
643
|
const {
|
|
398
644
|
addElement: addDocument,
|
|
399
645
|
removeElement: removeDocument,
|
|
400
646
|
allElements: allDocuments
|
|
401
647
|
} = use_flat_category_store_default();
|
|
402
|
-
const setAction = (0,
|
|
648
|
+
const setAction = (0, import_react8.useCallback)((id, action) => {
|
|
403
649
|
setActions((prevPoints) => {
|
|
404
650
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
405
651
|
[id]: action
|
|
406
652
|
});
|
|
407
653
|
});
|
|
408
654
|
}, []);
|
|
409
|
-
const removeAction = (0,
|
|
655
|
+
const removeAction = (0, import_react8.useCallback)((id) => {
|
|
410
656
|
setActions((prevPoints) => {
|
|
411
657
|
const newPoints = __spreadValues({}, prevPoints);
|
|
412
658
|
delete newPoints[id];
|
|
413
659
|
return newPoints;
|
|
414
660
|
});
|
|
415
661
|
}, []);
|
|
416
|
-
const setCoAgentStateRender = (0,
|
|
662
|
+
const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
|
|
417
663
|
setCoAgentStateRenders((prevPoints) => {
|
|
418
664
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
419
665
|
[id]: stateRender
|
|
420
666
|
});
|
|
421
667
|
});
|
|
422
668
|
}, []);
|
|
423
|
-
const removeCoAgentStateRender = (0,
|
|
669
|
+
const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
|
|
424
670
|
setCoAgentStateRenders((prevPoints) => {
|
|
425
671
|
const newPoints = __spreadValues({}, prevPoints);
|
|
426
672
|
delete newPoints[id];
|
|
427
673
|
return newPoints;
|
|
428
674
|
});
|
|
429
675
|
}, []);
|
|
430
|
-
const getContextString = (0,
|
|
676
|
+
const getContextString = (0, import_react8.useCallback)(
|
|
431
677
|
(documents, categories) => {
|
|
432
678
|
const documentsString = documents.map((document) => {
|
|
433
679
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -440,37 +686,37 @@ ${nonDocumentStrings}`;
|
|
|
440
686
|
},
|
|
441
687
|
[printTree]
|
|
442
688
|
);
|
|
443
|
-
const addContext = (0,
|
|
689
|
+
const addContext = (0, import_react8.useCallback)(
|
|
444
690
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
445
691
|
return addElement(context, categories, parentId);
|
|
446
692
|
},
|
|
447
693
|
[addElement]
|
|
448
694
|
);
|
|
449
|
-
const removeContext = (0,
|
|
695
|
+
const removeContext = (0, import_react8.useCallback)(
|
|
450
696
|
(id) => {
|
|
451
697
|
removeElement(id);
|
|
452
698
|
},
|
|
453
699
|
[removeElement]
|
|
454
700
|
);
|
|
455
|
-
const getFunctionCallHandler = (0,
|
|
701
|
+
const getFunctionCallHandler = (0, import_react8.useCallback)(
|
|
456
702
|
(customEntryPoints) => {
|
|
457
703
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
458
704
|
},
|
|
459
705
|
[actions]
|
|
460
706
|
);
|
|
461
|
-
const getDocumentsContext = (0,
|
|
707
|
+
const getDocumentsContext = (0, import_react8.useCallback)(
|
|
462
708
|
(categories) => {
|
|
463
709
|
return allDocuments(categories);
|
|
464
710
|
},
|
|
465
711
|
[allDocuments]
|
|
466
712
|
);
|
|
467
|
-
const addDocumentContext = (0,
|
|
713
|
+
const addDocumentContext = (0, import_react8.useCallback)(
|
|
468
714
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
469
715
|
return addDocument(documentPointer, categories);
|
|
470
716
|
},
|
|
471
717
|
[addDocument]
|
|
472
718
|
);
|
|
473
|
-
const removeDocumentContext = (0,
|
|
719
|
+
const removeDocumentContext = (0, import_react8.useCallback)(
|
|
474
720
|
(documentId) => {
|
|
475
721
|
removeDocument(documentId);
|
|
476
722
|
},
|
|
@@ -483,7 +729,7 @@ ${nonDocumentStrings}`;
|
|
|
483
729
|
);
|
|
484
730
|
}
|
|
485
731
|
}
|
|
486
|
-
const copilotApiConfig = (0,
|
|
732
|
+
const copilotApiConfig = (0, import_react8.useMemo)(() => {
|
|
487
733
|
var _a2, _b2;
|
|
488
734
|
let cloud = void 0;
|
|
489
735
|
if (props.publicApiKey) {
|
|
@@ -518,7 +764,14 @@ ${nonDocumentStrings}`;
|
|
|
518
764
|
props.credentials,
|
|
519
765
|
props.cloudRestrictToTopic
|
|
520
766
|
]);
|
|
521
|
-
const
|
|
767
|
+
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared3.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
768
|
+
const runtimeClient = useCopilotRuntimeClient({
|
|
769
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
770
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
771
|
+
headers,
|
|
772
|
+
credentials: copilotApiConfig.credentials
|
|
773
|
+
});
|
|
774
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
|
|
522
775
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
523
776
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
524
777
|
};
|
|
@@ -528,15 +781,16 @@ ${nonDocumentStrings}`;
|
|
|
528
781
|
return rest;
|
|
529
782
|
});
|
|
530
783
|
};
|
|
531
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
784
|
+
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
532
785
|
let initialAgentSession = null;
|
|
533
786
|
if (props.agent) {
|
|
534
787
|
initialAgentSession = {
|
|
535
788
|
agentName: props.agent
|
|
536
789
|
};
|
|
537
790
|
}
|
|
538
|
-
const [agentSession, setAgentSession] = (0,
|
|
539
|
-
|
|
791
|
+
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
792
|
+
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
793
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
540
794
|
CopilotContext.Provider,
|
|
541
795
|
{
|
|
542
796
|
value: {
|
|
@@ -562,13 +816,14 @@ ${nonDocumentStrings}`;
|
|
|
562
816
|
removeChatSuggestionConfiguration,
|
|
563
817
|
chatInstructions,
|
|
564
818
|
setChatInstructions,
|
|
565
|
-
showDevConsole
|
|
819
|
+
showDevConsole,
|
|
566
820
|
coagentStates,
|
|
567
821
|
setCoagentStates,
|
|
568
822
|
agentSession,
|
|
569
|
-
setAgentSession
|
|
823
|
+
setAgentSession,
|
|
824
|
+
runtimeClient
|
|
570
825
|
},
|
|
571
|
-
children: /* @__PURE__ */ (0,
|
|
826
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
572
827
|
}
|
|
573
828
|
);
|
|
574
829
|
}
|