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