@copilotkit/react-core 1.4.1-pre.2 → 1.4.1-pre.6
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 +45 -3
- package/dist/chunk-2KCEHGSI.mjs +192 -0
- package/dist/chunk-2KCEHGSI.mjs.map +1 -0
- package/dist/{chunk-MX2OYLRS.mjs → chunk-DT52QX4H.mjs} +4 -4
- package/dist/{chunk-TRXKPXDE.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-G2K6T2QU.mjs → chunk-JDQCJCAQ.mjs} +38 -11
- package/dist/chunk-JDQCJCAQ.mjs.map +1 -0
- package/dist/chunk-L34MHAXR.mjs +1 -0
- package/dist/{chunk-7DFHFZJT.mjs → chunk-LMFSB5D5.mjs} +2 -2
- package/dist/chunk-LMFSB5D5.mjs.map +1 -0
- 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-7LKXEJXM.mjs → chunk-MWZO6TUR.mjs} +3 -2
- package/dist/chunk-MWZO6TUR.mjs.map +1 -0
- 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-K4HZL7SA.mjs → chunk-V22C3DOQ.mjs} +3 -3
- package/dist/{chunk-27IPQFJP.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/chunk-XINZBP3J.mjs.map +1 -0
- 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 +118 -62
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +17 -12
- package/dist/hooks/use-chat.js +78 -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.d.ts +1 -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 +96 -43
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +9 -7
- package/dist/hooks/use-copilot-action.d.ts +1 -1
- package/dist/hooks/use-copilot-action.js +2 -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 +98 -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 +513 -240
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -19
- package/dist/lib/copilot-task.d.ts +2 -5
- 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/types/frontend-action.d.ts +8 -1
- package/dist/types/frontend-action.js.map +1 -1
- 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 +36 -12
- package/src/hooks/use-coagent-state-render.ts +1 -1
- package/src/hooks/use-copilot-action.ts +2 -1
- package/src/hooks/use-copilot-runtime-client.ts +24 -0
- package/src/lib/copilot-task.ts +1 -5
- package/src/types/frontend-action.ts +8 -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-27IPQFJP.mjs.map +0 -1
- package/dist/chunk-2MPUQRAY.mjs.map +0 -1
- package/dist/chunk-6YEMNWKE.mjs.map +0 -1
- package/dist/chunk-7DFHFZJT.mjs.map +0 -1
- package/dist/chunk-7LKXEJXM.mjs.map +0 -1
- package/dist/chunk-BWYAGPEF.mjs +0 -1
- package/dist/chunk-G2K6T2QU.mjs.map +0 -1
- package/dist/chunk-JD7BAH7U.mjs +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-MX2OYLRS.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-ANOG3W5S.mjs.map → chunk-QDGDXRRJ.mjs.map} +0 -0
- /package/dist/{chunk-K4HZL7SA.mjs.map → chunk-V22C3DOQ.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
package/dist/index.js
CHANGED
|
@@ -87,6 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
CopilotTask: () => CopilotTask,
|
|
88
88
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
89
89
|
extract: () => extract,
|
|
90
|
+
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
90
91
|
useCoAgent: () => useCoAgent,
|
|
91
92
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
92
93
|
useCopilotAction: () => useCopilotAction,
|
|
@@ -94,12 +95,13 @@ __export(src_exports, {
|
|
|
94
95
|
useCopilotContext: () => useCopilotContext,
|
|
95
96
|
useCopilotMessagesContext: () => useCopilotMessagesContext,
|
|
96
97
|
useCopilotReadable: () => useCopilotReadable,
|
|
98
|
+
useCopilotRuntimeClient: () => useCopilotRuntimeClient,
|
|
97
99
|
useMakeCopilotDocumentReadable: () => useMakeCopilotDocumentReadable
|
|
98
100
|
});
|
|
99
101
|
module.exports = __toCommonJS(src_exports);
|
|
100
102
|
|
|
101
103
|
// src/components/copilot-provider/copilotkit.tsx
|
|
102
|
-
var
|
|
104
|
+
var import_react8 = require("react");
|
|
103
105
|
|
|
104
106
|
// src/context/copilot-context.tsx
|
|
105
107
|
var import_react = __toESM(require("react"));
|
|
@@ -129,6 +131,7 @@ var emptyCopilotContext = {
|
|
|
129
131
|
addDocumentContext: () => returnAndThrowInDebug(""),
|
|
130
132
|
removeDocumentContext: () => {
|
|
131
133
|
},
|
|
134
|
+
runtimeClient: {},
|
|
132
135
|
copilotApiConfig: new class {
|
|
133
136
|
get chatApiEndpoint() {
|
|
134
137
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
@@ -299,7 +302,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
299
302
|
|
|
300
303
|
// src/components/copilot-provider/copilotkit.tsx
|
|
301
304
|
var import_react_dom = require("react-dom");
|
|
302
|
-
var
|
|
305
|
+
var import_shared4 = require("@copilotkit/shared");
|
|
303
306
|
|
|
304
307
|
// src/hooks/use-flat-category-store.ts
|
|
305
308
|
var import_react3 = require("react");
|
|
@@ -404,59 +407,437 @@ function CopilotMessages(_a) {
|
|
|
404
407
|
);
|
|
405
408
|
}
|
|
406
409
|
|
|
407
|
-
// src/components/
|
|
410
|
+
// src/components/toast/toast-provider.tsx
|
|
411
|
+
var import_react6 = require("react");
|
|
412
|
+
|
|
413
|
+
// src/components/toast/exclamation-mark-icon.tsx
|
|
408
414
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
415
|
+
var ExclamationMarkIcon = ({
|
|
416
|
+
className,
|
|
417
|
+
style
|
|
418
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
419
|
+
"svg",
|
|
420
|
+
{
|
|
421
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
422
|
+
width: "24",
|
|
423
|
+
height: "24",
|
|
424
|
+
viewBox: "0 0 24 24",
|
|
425
|
+
fill: "none",
|
|
426
|
+
stroke: "currentColor",
|
|
427
|
+
strokeWidth: "2",
|
|
428
|
+
strokeLinecap: "round",
|
|
429
|
+
strokeLinejoin: "round",
|
|
430
|
+
className: `lucide lucide-circle-alert ${className ? className : ""}`,
|
|
431
|
+
style,
|
|
432
|
+
children: [
|
|
433
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
|
|
434
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12", y1: "8", y2: "12" }),
|
|
435
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "12", x2: "12.01", y1: "16", y2: "16" })
|
|
436
|
+
]
|
|
437
|
+
}
|
|
438
|
+
);
|
|
439
|
+
|
|
440
|
+
// src/components/toast/toast-provider.tsx
|
|
441
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
442
|
+
var ToastContext = (0, import_react6.createContext)(void 0);
|
|
443
|
+
function useToast() {
|
|
444
|
+
const context = (0, import_react6.useContext)(ToastContext);
|
|
445
|
+
if (!context) {
|
|
446
|
+
throw new Error("useToast must be used within a ToastProvider");
|
|
447
|
+
}
|
|
448
|
+
return context;
|
|
449
|
+
}
|
|
450
|
+
function ToastProvider({
|
|
451
|
+
enabled,
|
|
452
|
+
children
|
|
453
|
+
}) {
|
|
454
|
+
const [toasts, setToasts] = (0, import_react6.useState)([]);
|
|
455
|
+
const addToast = (0, import_react6.useCallback)((toast) => {
|
|
456
|
+
const id = Math.random().toString(36).substring(2, 9);
|
|
457
|
+
setToasts((currentToasts) => [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })]);
|
|
458
|
+
if (toast.duration) {
|
|
459
|
+
setTimeout(() => {
|
|
460
|
+
removeToast(id);
|
|
461
|
+
}, toast.duration);
|
|
462
|
+
}
|
|
463
|
+
}, []);
|
|
464
|
+
const addGraphQLErrorsToast = (0, import_react6.useCallback)((errors) => {
|
|
465
|
+
const errorsToRender = errors.map((error, idx) => {
|
|
466
|
+
var _a;
|
|
467
|
+
const message = error.message;
|
|
468
|
+
const code = (_a = error.extensions) == null ? void 0 : _a.code;
|
|
469
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
470
|
+
"div",
|
|
471
|
+
{
|
|
472
|
+
style: {
|
|
473
|
+
marginTop: idx === 0 ? 0 : 10,
|
|
474
|
+
marginBottom: 14
|
|
475
|
+
},
|
|
476
|
+
children: [
|
|
477
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
478
|
+
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
479
|
+
"div",
|
|
480
|
+
{
|
|
481
|
+
style: {
|
|
482
|
+
fontWeight: "600",
|
|
483
|
+
marginBottom: 4
|
|
484
|
+
},
|
|
485
|
+
children: [
|
|
486
|
+
"Copilot Cloud Error:",
|
|
487
|
+
" ",
|
|
488
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
489
|
+
]
|
|
490
|
+
}
|
|
491
|
+
),
|
|
492
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
493
|
+
]
|
|
494
|
+
},
|
|
495
|
+
idx
|
|
496
|
+
);
|
|
497
|
+
});
|
|
498
|
+
addToast({
|
|
499
|
+
type: "error",
|
|
500
|
+
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
501
|
+
"div",
|
|
502
|
+
{
|
|
503
|
+
style: {
|
|
504
|
+
fontSize: "13px",
|
|
505
|
+
maxWidth: "600px"
|
|
506
|
+
},
|
|
507
|
+
children: [
|
|
508
|
+
errorsToRender,
|
|
509
|
+
/* @__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." })
|
|
510
|
+
]
|
|
511
|
+
}
|
|
512
|
+
)
|
|
513
|
+
});
|
|
514
|
+
}, []);
|
|
515
|
+
const removeToast = (0, import_react6.useCallback)((id) => {
|
|
516
|
+
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
517
|
+
}, []);
|
|
518
|
+
const value = {
|
|
519
|
+
toasts,
|
|
520
|
+
addToast,
|
|
521
|
+
addGraphQLErrorsToast,
|
|
522
|
+
removeToast,
|
|
523
|
+
enabled
|
|
524
|
+
};
|
|
525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
|
|
526
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
527
|
+
"div",
|
|
528
|
+
{
|
|
529
|
+
style: {
|
|
530
|
+
position: "fixed",
|
|
531
|
+
bottom: "1rem",
|
|
532
|
+
left: "50%",
|
|
533
|
+
transform: "translateX(-50%)",
|
|
534
|
+
zIndex: 50,
|
|
535
|
+
display: "flex",
|
|
536
|
+
flexDirection: "column",
|
|
537
|
+
gap: "0.5rem"
|
|
538
|
+
},
|
|
539
|
+
children: [
|
|
540
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
541
|
+
"button",
|
|
542
|
+
{
|
|
543
|
+
onClick: () => setToasts([]),
|
|
544
|
+
style: {
|
|
545
|
+
padding: "4px 8px",
|
|
546
|
+
fontSize: "12px",
|
|
547
|
+
cursor: "pointer",
|
|
548
|
+
background: "white",
|
|
549
|
+
border: "1px solid rgba(0,0,0,0.2)",
|
|
550
|
+
borderRadius: "4px"
|
|
551
|
+
},
|
|
552
|
+
children: "Close All"
|
|
553
|
+
}
|
|
554
|
+
) }),
|
|
555
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
556
|
+
Toast,
|
|
557
|
+
{
|
|
558
|
+
message: toast.message,
|
|
559
|
+
type: toast.type,
|
|
560
|
+
onClose: () => removeToast(toast.id)
|
|
561
|
+
},
|
|
562
|
+
toast.id
|
|
563
|
+
))
|
|
564
|
+
]
|
|
565
|
+
}
|
|
566
|
+
),
|
|
567
|
+
children
|
|
568
|
+
] });
|
|
569
|
+
}
|
|
570
|
+
function Toast({
|
|
571
|
+
message,
|
|
572
|
+
type = "info",
|
|
573
|
+
onClose
|
|
574
|
+
}) {
|
|
575
|
+
const bgColors = {
|
|
576
|
+
info: "#3b82f6",
|
|
577
|
+
success: "#22c55e",
|
|
578
|
+
warning: "#eab308",
|
|
579
|
+
error: "#ef4444"
|
|
580
|
+
};
|
|
581
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
582
|
+
"div",
|
|
583
|
+
{
|
|
584
|
+
style: {
|
|
585
|
+
backgroundColor: bgColors[type],
|
|
586
|
+
color: "white",
|
|
587
|
+
padding: "0.5rem 1rem",
|
|
588
|
+
borderRadius: "0.25rem",
|
|
589
|
+
boxShadow: "0 2px 4px rgba(0,0,0,0.1)",
|
|
590
|
+
position: "relative",
|
|
591
|
+
minWidth: "200px"
|
|
592
|
+
},
|
|
593
|
+
children: [
|
|
594
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
|
|
595
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
596
|
+
"button",
|
|
597
|
+
{
|
|
598
|
+
onClick: onClose,
|
|
599
|
+
style: {
|
|
600
|
+
position: "absolute",
|
|
601
|
+
top: "0",
|
|
602
|
+
right: "0",
|
|
603
|
+
background: "none",
|
|
604
|
+
border: "none",
|
|
605
|
+
color: "white",
|
|
606
|
+
cursor: "pointer",
|
|
607
|
+
padding: "0.5rem",
|
|
608
|
+
fontSize: "1rem"
|
|
609
|
+
},
|
|
610
|
+
children: "\u2715"
|
|
611
|
+
}
|
|
612
|
+
)
|
|
613
|
+
]
|
|
614
|
+
}
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
// src/hooks/use-copilot-runtime-client.ts
|
|
619
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
620
|
+
var import_react7 = require("react");
|
|
621
|
+
var useCopilotRuntimeClient = (options) => {
|
|
622
|
+
const { addGraphQLErrorsToast } = useToast();
|
|
623
|
+
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
624
|
+
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
625
|
+
handleGQLErrors: (error) => {
|
|
626
|
+
if (error.graphQLErrors.length) {
|
|
627
|
+
addGraphQLErrorsToast(error.graphQLErrors);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}));
|
|
631
|
+
}, [options, addGraphQLErrorsToast]);
|
|
632
|
+
return runtimeClient;
|
|
633
|
+
};
|
|
634
|
+
|
|
635
|
+
// src/utils/extract.ts
|
|
636
|
+
var import_shared3 = require("@copilotkit/shared");
|
|
637
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
638
|
+
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
639
|
+
function extract(_0) {
|
|
640
|
+
return __async(this, arguments, function* ({
|
|
641
|
+
context,
|
|
642
|
+
instructions,
|
|
643
|
+
parameters,
|
|
644
|
+
include,
|
|
645
|
+
data,
|
|
646
|
+
abortSignal,
|
|
647
|
+
stream,
|
|
648
|
+
requestType = import_runtime_client_gql2.CopilotRequestType.Task
|
|
649
|
+
}) {
|
|
650
|
+
var _a, _b;
|
|
651
|
+
const { messages } = context;
|
|
652
|
+
const action = {
|
|
653
|
+
name: "extract",
|
|
654
|
+
description: instructions,
|
|
655
|
+
parameters,
|
|
656
|
+
handler: (args) => {
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
|
|
660
|
+
const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
|
|
661
|
+
let contextString = "";
|
|
662
|
+
if (data) {
|
|
663
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
664
|
+
}
|
|
665
|
+
if (includeReadable) {
|
|
666
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
667
|
+
}
|
|
668
|
+
const systemMessage = new import_runtime_client_gql2.TextMessage({
|
|
669
|
+
content: makeSystemMessage(contextString, instructions),
|
|
670
|
+
role: import_runtime_client_gql2.Role.System
|
|
671
|
+
});
|
|
672
|
+
const instructionsMessage = new import_runtime_client_gql2.TextMessage({
|
|
673
|
+
content: makeInstructionsMessage(instructions),
|
|
674
|
+
role: import_runtime_client_gql2.Role.User
|
|
675
|
+
});
|
|
676
|
+
const response = context.runtimeClient.asStream(
|
|
677
|
+
context.runtimeClient.generateCopilotResponse({
|
|
678
|
+
data: {
|
|
679
|
+
frontend: {
|
|
680
|
+
actions: [
|
|
681
|
+
{
|
|
682
|
+
name: action.name,
|
|
683
|
+
description: action.description || "",
|
|
684
|
+
jsonSchema: JSON.stringify((0, import_shared3.actionParametersToJsonSchema)(action.parameters || []))
|
|
685
|
+
}
|
|
686
|
+
],
|
|
687
|
+
url: window.location.href
|
|
688
|
+
},
|
|
689
|
+
messages: (0, import_runtime_client_gql3.convertMessagesToGqlInput)(
|
|
690
|
+
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql3.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
691
|
+
),
|
|
692
|
+
metadata: {
|
|
693
|
+
requestType
|
|
694
|
+
},
|
|
695
|
+
forwardedParameters: {
|
|
696
|
+
toolChoice: "function",
|
|
697
|
+
toolChoiceFunctionName: action.name
|
|
698
|
+
}
|
|
699
|
+
},
|
|
700
|
+
properties: context.copilotApiConfig.properties,
|
|
701
|
+
signal: abortSignal
|
|
702
|
+
})
|
|
703
|
+
);
|
|
704
|
+
const reader = response.getReader();
|
|
705
|
+
let isInitial = true;
|
|
706
|
+
let actionExecutionMessage = void 0;
|
|
707
|
+
while (true) {
|
|
708
|
+
const { done, value } = yield reader.read();
|
|
709
|
+
if (done) {
|
|
710
|
+
break;
|
|
711
|
+
}
|
|
712
|
+
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
713
|
+
throw new Error("Aborted");
|
|
714
|
+
}
|
|
715
|
+
actionExecutionMessage = (0, import_runtime_client_gql2.convertGqlOutputToMessages)(
|
|
716
|
+
value.generateCopilotResponse.messages
|
|
717
|
+
).find((msg) => msg.isActionExecutionMessage());
|
|
718
|
+
if (!actionExecutionMessage) {
|
|
719
|
+
continue;
|
|
720
|
+
}
|
|
721
|
+
stream == null ? void 0 : stream({
|
|
722
|
+
status: isInitial ? "initial" : "inProgress",
|
|
723
|
+
args: actionExecutionMessage.arguments
|
|
724
|
+
});
|
|
725
|
+
isInitial = false;
|
|
726
|
+
}
|
|
727
|
+
if (!actionExecutionMessage) {
|
|
728
|
+
throw new Error("extract() failed: No function call occurred");
|
|
729
|
+
}
|
|
730
|
+
stream == null ? void 0 : stream({
|
|
731
|
+
status: "complete",
|
|
732
|
+
args: actionExecutionMessage.arguments
|
|
733
|
+
});
|
|
734
|
+
return actionExecutionMessage.arguments;
|
|
735
|
+
});
|
|
736
|
+
}
|
|
737
|
+
function makeInstructionsMessage(instructions) {
|
|
738
|
+
return `
|
|
739
|
+
The user has given you the following task to complete:
|
|
740
|
+
|
|
741
|
+
\`\`\`
|
|
742
|
+
${instructions}
|
|
743
|
+
\`\`\`
|
|
744
|
+
|
|
745
|
+
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
746
|
+
`;
|
|
747
|
+
}
|
|
748
|
+
function makeSystemMessage(contextString, instructions) {
|
|
749
|
+
return `
|
|
750
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
751
|
+
|
|
752
|
+
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
753
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
754
|
+
|
|
755
|
+
The user has provided you with the following context:
|
|
756
|
+
\`\`\`
|
|
757
|
+
${contextString}
|
|
758
|
+
\`\`\`
|
|
759
|
+
|
|
760
|
+
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
761
|
+
|
|
762
|
+
Please assist them as best you can.
|
|
763
|
+
|
|
764
|
+
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
765
|
+
`;
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// src/utils/dev-console.ts
|
|
769
|
+
function shouldShowDevConsole(showDevConsole) {
|
|
770
|
+
if (typeof showDevConsole === "boolean") {
|
|
771
|
+
return showDevConsole;
|
|
772
|
+
}
|
|
773
|
+
return getHostname() === "localhost" || getHostname() === "127.0.0.1" || getHostname() === "0.0.0.0" || getHostname() === "::1";
|
|
774
|
+
}
|
|
775
|
+
function getHostname() {
|
|
776
|
+
if (typeof window !== "undefined" && window.location) {
|
|
777
|
+
return window.location.hostname;
|
|
778
|
+
}
|
|
779
|
+
return "";
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
// src/components/copilot-provider/copilotkit.tsx
|
|
783
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
409
784
|
function CopilotKit(_a) {
|
|
785
|
+
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
786
|
+
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
787
|
+
const enabled = shouldShowDevConsole(showDevConsole);
|
|
788
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
|
|
789
|
+
}
|
|
790
|
+
function CopilotKitInternal(_a) {
|
|
410
791
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
411
792
|
if (!props.runtimeUrl && !props.publicApiKey) {
|
|
412
793
|
throw new Error(
|
|
413
794
|
"Please provide either a runtimeUrl or a publicApiKey to the CopilotKit component."
|
|
414
795
|
);
|
|
415
796
|
}
|
|
416
|
-
const chatApiEndpoint = props.runtimeUrl ||
|
|
417
|
-
const [actions, setActions] = (0,
|
|
418
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
419
|
-
const chatComponentsCache = (0,
|
|
797
|
+
const chatApiEndpoint = props.runtimeUrl || import_shared4.COPILOT_CLOUD_CHAT_URL;
|
|
798
|
+
const [actions, setActions] = (0, import_react8.useState)({});
|
|
799
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
|
|
800
|
+
const chatComponentsCache = (0, import_react8.useRef)({
|
|
420
801
|
actions: {},
|
|
421
802
|
coAgentStateRenders: {}
|
|
422
803
|
});
|
|
423
804
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
424
|
-
const [isLoading, setIsLoading] = (0,
|
|
425
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
805
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
806
|
+
const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
|
|
426
807
|
const {
|
|
427
808
|
addElement: addDocument,
|
|
428
809
|
removeElement: removeDocument,
|
|
429
810
|
allElements: allDocuments
|
|
430
811
|
} = use_flat_category_store_default();
|
|
431
|
-
const setAction = (0,
|
|
812
|
+
const setAction = (0, import_react8.useCallback)((id, action) => {
|
|
432
813
|
setActions((prevPoints) => {
|
|
433
814
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
434
815
|
[id]: action
|
|
435
816
|
});
|
|
436
817
|
});
|
|
437
818
|
}, []);
|
|
438
|
-
const removeAction = (0,
|
|
819
|
+
const removeAction = (0, import_react8.useCallback)((id) => {
|
|
439
820
|
setActions((prevPoints) => {
|
|
440
821
|
const newPoints = __spreadValues({}, prevPoints);
|
|
441
822
|
delete newPoints[id];
|
|
442
823
|
return newPoints;
|
|
443
824
|
});
|
|
444
825
|
}, []);
|
|
445
|
-
const setCoAgentStateRender = (0,
|
|
826
|
+
const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
|
|
446
827
|
setCoAgentStateRenders((prevPoints) => {
|
|
447
828
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
448
829
|
[id]: stateRender
|
|
449
830
|
});
|
|
450
831
|
});
|
|
451
832
|
}, []);
|
|
452
|
-
const removeCoAgentStateRender = (0,
|
|
833
|
+
const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
|
|
453
834
|
setCoAgentStateRenders((prevPoints) => {
|
|
454
835
|
const newPoints = __spreadValues({}, prevPoints);
|
|
455
836
|
delete newPoints[id];
|
|
456
837
|
return newPoints;
|
|
457
838
|
});
|
|
458
839
|
}, []);
|
|
459
|
-
const getContextString = (0,
|
|
840
|
+
const getContextString = (0, import_react8.useCallback)(
|
|
460
841
|
(documents, categories) => {
|
|
461
842
|
const documentsString = documents.map((document) => {
|
|
462
843
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -469,37 +850,37 @@ ${nonDocumentStrings}`;
|
|
|
469
850
|
},
|
|
470
851
|
[printTree]
|
|
471
852
|
);
|
|
472
|
-
const addContext = (0,
|
|
853
|
+
const addContext = (0, import_react8.useCallback)(
|
|
473
854
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
474
855
|
return addElement(context, categories, parentId);
|
|
475
856
|
},
|
|
476
857
|
[addElement]
|
|
477
858
|
);
|
|
478
|
-
const removeContext = (0,
|
|
859
|
+
const removeContext = (0, import_react8.useCallback)(
|
|
479
860
|
(id) => {
|
|
480
861
|
removeElement(id);
|
|
481
862
|
},
|
|
482
863
|
[removeElement]
|
|
483
864
|
);
|
|
484
|
-
const getFunctionCallHandler = (0,
|
|
865
|
+
const getFunctionCallHandler = (0, import_react8.useCallback)(
|
|
485
866
|
(customEntryPoints) => {
|
|
486
867
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
487
868
|
},
|
|
488
869
|
[actions]
|
|
489
870
|
);
|
|
490
|
-
const getDocumentsContext = (0,
|
|
871
|
+
const getDocumentsContext = (0, import_react8.useCallback)(
|
|
491
872
|
(categories) => {
|
|
492
873
|
return allDocuments(categories);
|
|
493
874
|
},
|
|
494
875
|
[allDocuments]
|
|
495
876
|
);
|
|
496
|
-
const addDocumentContext = (0,
|
|
877
|
+
const addDocumentContext = (0, import_react8.useCallback)(
|
|
497
878
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
498
879
|
return addDocument(documentPointer, categories);
|
|
499
880
|
},
|
|
500
881
|
[addDocument]
|
|
501
882
|
);
|
|
502
|
-
const removeDocumentContext = (0,
|
|
883
|
+
const removeDocumentContext = (0, import_react8.useCallback)(
|
|
503
884
|
(documentId) => {
|
|
504
885
|
removeDocument(documentId);
|
|
505
886
|
},
|
|
@@ -512,7 +893,7 @@ ${nonDocumentStrings}`;
|
|
|
512
893
|
);
|
|
513
894
|
}
|
|
514
895
|
}
|
|
515
|
-
const copilotApiConfig = (0,
|
|
896
|
+
const copilotApiConfig = (0, import_react8.useMemo)(() => {
|
|
516
897
|
var _a2, _b2;
|
|
517
898
|
let cloud = void 0;
|
|
518
899
|
if (props.publicApiKey) {
|
|
@@ -547,7 +928,14 @@ ${nonDocumentStrings}`;
|
|
|
547
928
|
props.credentials,
|
|
548
929
|
props.cloudRestrictToTopic
|
|
549
930
|
]);
|
|
550
|
-
const
|
|
931
|
+
const headers = __spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {});
|
|
932
|
+
const runtimeClient = useCopilotRuntimeClient({
|
|
933
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
934
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
935
|
+
headers,
|
|
936
|
+
credentials: copilotApiConfig.credentials
|
|
937
|
+
});
|
|
938
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
|
|
551
939
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
552
940
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
553
941
|
};
|
|
@@ -557,15 +945,16 @@ ${nonDocumentStrings}`;
|
|
|
557
945
|
return rest;
|
|
558
946
|
});
|
|
559
947
|
};
|
|
560
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
948
|
+
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
561
949
|
let initialAgentSession = null;
|
|
562
950
|
if (props.agent) {
|
|
563
951
|
initialAgentSession = {
|
|
564
952
|
agentName: props.agent
|
|
565
953
|
};
|
|
566
954
|
}
|
|
567
|
-
const [agentSession, setAgentSession] = (0,
|
|
568
|
-
|
|
955
|
+
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
956
|
+
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
957
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
569
958
|
CopilotContext.Provider,
|
|
570
959
|
{
|
|
571
960
|
value: {
|
|
@@ -591,13 +980,14 @@ ${nonDocumentStrings}`;
|
|
|
591
980
|
removeChatSuggestionConfiguration,
|
|
592
981
|
chatInstructions,
|
|
593
982
|
setChatInstructions,
|
|
594
|
-
showDevConsole
|
|
983
|
+
showDevConsole,
|
|
595
984
|
coagentStates,
|
|
596
985
|
setCoagentStates,
|
|
597
986
|
agentSession,
|
|
598
|
-
setAgentSession
|
|
987
|
+
setAgentSession,
|
|
988
|
+
runtimeClient
|
|
599
989
|
},
|
|
600
|
-
children: /* @__PURE__ */ (0,
|
|
990
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
601
991
|
}
|
|
602
992
|
);
|
|
603
993
|
}
|
|
@@ -629,13 +1019,13 @@ function entryPointsToFunctionCallHandler(actions) {
|
|
|
629
1019
|
}
|
|
630
1020
|
|
|
631
1021
|
// src/hooks/use-copilot-chat.ts
|
|
632
|
-
var
|
|
633
|
-
var
|
|
1022
|
+
var import_react10 = require("react");
|
|
1023
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
634
1024
|
|
|
635
1025
|
// src/hooks/use-chat.ts
|
|
636
|
-
var
|
|
637
|
-
var
|
|
638
|
-
var
|
|
1026
|
+
var import_react9 = require("react");
|
|
1027
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1028
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
639
1029
|
function useChat(options) {
|
|
640
1030
|
const {
|
|
641
1031
|
messages,
|
|
@@ -653,17 +1043,18 @@ function useChat(options) {
|
|
|
653
1043
|
agentSession,
|
|
654
1044
|
setAgentSession
|
|
655
1045
|
} = options;
|
|
656
|
-
const abortControllerRef = (0,
|
|
657
|
-
const threadIdRef = (0,
|
|
658
|
-
const runIdRef = (0,
|
|
659
|
-
const
|
|
660
|
-
const
|
|
1046
|
+
const abortControllerRef = (0, import_react9.useRef)();
|
|
1047
|
+
const threadIdRef = (0, import_react9.useRef)(null);
|
|
1048
|
+
const runIdRef = (0, import_react9.useRef)(null);
|
|
1049
|
+
const { addGraphQLErrorsToast } = useToast();
|
|
1050
|
+
const runChatCompletionRef = (0, import_react9.useRef)();
|
|
1051
|
+
const coagentStatesRef = (0, import_react9.useRef)(coagentStates);
|
|
661
1052
|
coagentStatesRef.current = coagentStates;
|
|
662
|
-
const agentSessionRef = (0,
|
|
1053
|
+
const agentSessionRef = (0, import_react9.useRef)(agentSession);
|
|
663
1054
|
agentSessionRef.current = agentSession;
|
|
664
1055
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
665
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [
|
|
666
|
-
const runtimeClient =
|
|
1056
|
+
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared5.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1057
|
+
const runtimeClient = useCopilotRuntimeClient({
|
|
667
1058
|
url: copilotConfig.chatApiEndpoint,
|
|
668
1059
|
publicApiKey: copilotConfig.publicApiKey,
|
|
669
1060
|
headers,
|
|
@@ -673,9 +1064,9 @@ function useChat(options) {
|
|
|
673
1064
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
674
1065
|
setIsLoading(true);
|
|
675
1066
|
let newMessages = [
|
|
676
|
-
new
|
|
1067
|
+
new import_runtime_client_gql4.TextMessage({
|
|
677
1068
|
content: "",
|
|
678
|
-
role:
|
|
1069
|
+
role: import_runtime_client_gql4.Role.Assistant
|
|
679
1070
|
})
|
|
680
1071
|
];
|
|
681
1072
|
const abortController = new AbortController();
|
|
@@ -683,20 +1074,33 @@ function useChat(options) {
|
|
|
683
1074
|
setMessages([...previousMessages, ...newMessages]);
|
|
684
1075
|
const systemMessage = makeSystemMessageCallback();
|
|
685
1076
|
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
686
|
-
const stream =
|
|
1077
|
+
const stream = runtimeClient.asStream(
|
|
687
1078
|
runtimeClient.generateCopilotResponse({
|
|
688
1079
|
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
689
1080
|
frontend: {
|
|
690
|
-
actions: actions.filter(
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
1081
|
+
actions: actions.filter(
|
|
1082
|
+
(action) => action.available !== import_runtime_client_gql4.ActionInputAvailability.Disabled || !action.disabled
|
|
1083
|
+
).map((action) => {
|
|
1084
|
+
let available = import_runtime_client_gql4.ActionInputAvailability.Enabled;
|
|
1085
|
+
if (action.disabled) {
|
|
1086
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
1087
|
+
} else if (action.available === "disabled") {
|
|
1088
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
1089
|
+
} else if (action.available === "remote") {
|
|
1090
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Remote;
|
|
1091
|
+
}
|
|
1092
|
+
return {
|
|
1093
|
+
name: action.name,
|
|
1094
|
+
description: action.description || "",
|
|
1095
|
+
jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || [])),
|
|
1096
|
+
available
|
|
1097
|
+
};
|
|
1098
|
+
}),
|
|
695
1099
|
url: window.location.href
|
|
696
1100
|
},
|
|
697
1101
|
threadId: threadIdRef.current,
|
|
698
1102
|
runId: runIdRef.current,
|
|
699
|
-
messages: (0,
|
|
1103
|
+
messages: (0, import_runtime_client_gql4.convertMessagesToGqlInput)((0, import_runtime_client_gql4.filterAgentStateMessages)(messagesWithContext))
|
|
700
1104
|
}, copilotConfig.cloud ? {
|
|
701
1105
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
702
1106
|
guardrails: {
|
|
@@ -708,7 +1112,7 @@ function useChat(options) {
|
|
|
708
1112
|
} : {})
|
|
709
1113
|
} : {}), {
|
|
710
1114
|
metadata: {
|
|
711
|
-
requestType:
|
|
1115
|
+
requestType: import_runtime_client_gql4.CopilotRequestType.Chat
|
|
712
1116
|
}
|
|
713
1117
|
}), agentSessionRef.current ? {
|
|
714
1118
|
agentSession: agentSessionRef.current
|
|
@@ -729,7 +1133,14 @@ function useChat(options) {
|
|
|
729
1133
|
let followUp = void 0;
|
|
730
1134
|
try {
|
|
731
1135
|
while (true) {
|
|
732
|
-
|
|
1136
|
+
let done, value;
|
|
1137
|
+
try {
|
|
1138
|
+
const readResult = yield reader.read();
|
|
1139
|
+
done = readResult.done;
|
|
1140
|
+
value = readResult.value;
|
|
1141
|
+
} catch (readError) {
|
|
1142
|
+
break;
|
|
1143
|
+
}
|
|
733
1144
|
if (done) {
|
|
734
1145
|
break;
|
|
735
1146
|
}
|
|
@@ -738,8 +1149,8 @@ function useChat(options) {
|
|
|
738
1149
|
}
|
|
739
1150
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
740
1151
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
741
|
-
const messages2 = (0,
|
|
742
|
-
(0,
|
|
1152
|
+
const messages2 = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1153
|
+
(0, import_runtime_client_gql4.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
743
1154
|
);
|
|
744
1155
|
if (messages2.length === 0) {
|
|
745
1156
|
continue;
|
|
@@ -747,15 +1158,15 @@ function useChat(options) {
|
|
|
747
1158
|
newMessages = [];
|
|
748
1159
|
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
749
1160
|
newMessages = [
|
|
750
|
-
new
|
|
751
|
-
role:
|
|
1161
|
+
new import_runtime_client_gql4.TextMessage({
|
|
1162
|
+
role: import_runtime_client_gql4.MessageRole.Assistant,
|
|
752
1163
|
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
753
1164
|
})
|
|
754
1165
|
];
|
|
755
1166
|
} else {
|
|
756
1167
|
for (const message of messages2) {
|
|
757
1168
|
newMessages.push(message);
|
|
758
|
-
if (message.isActionExecutionMessage() && message.status.code !==
|
|
1169
|
+
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql4.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
759
1170
|
if (!(message.id in actionResults)) {
|
|
760
1171
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
761
1172
|
break;
|
|
@@ -778,8 +1189,8 @@ function useChat(options) {
|
|
|
778
1189
|
}
|
|
779
1190
|
}
|
|
780
1191
|
newMessages.push(
|
|
781
|
-
new
|
|
782
|
-
result:
|
|
1192
|
+
new import_runtime_client_gql4.ResultMessage({
|
|
1193
|
+
result: import_runtime_client_gql4.ResultMessage.encodeResult(actionResults[message.id]),
|
|
783
1194
|
actionExecutionId: message.id,
|
|
784
1195
|
actionName: message.name
|
|
785
1196
|
})
|
|
@@ -898,21 +1309,21 @@ function useCopilotChat(_a = {}) {
|
|
|
898
1309
|
} = useCopilotContext();
|
|
899
1310
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
900
1311
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
901
|
-
const deleteMessage = (0,
|
|
1312
|
+
const deleteMessage = (0, import_react10.useCallback)(
|
|
902
1313
|
(messageId) => {
|
|
903
1314
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
904
1315
|
},
|
|
905
1316
|
[setMessages]
|
|
906
1317
|
);
|
|
907
|
-
const makeSystemMessageCallback = (0,
|
|
1318
|
+
const makeSystemMessageCallback = (0, import_react10.useCallback)(() => {
|
|
908
1319
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
909
1320
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
910
|
-
return new
|
|
1321
|
+
return new import_runtime_client_gql5.TextMessage({
|
|
911
1322
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
912
|
-
role:
|
|
1323
|
+
role: import_runtime_client_gql5.Role.System
|
|
913
1324
|
});
|
|
914
1325
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
915
|
-
const onCoAgentStateRender = (0,
|
|
1326
|
+
const onCoAgentStateRender = (0, import_react10.useCallback)(
|
|
916
1327
|
(args) => __async(this, null, function* () {
|
|
917
1328
|
var _a2;
|
|
918
1329
|
const { name, nodeName, state } = args;
|
|
@@ -947,29 +1358,29 @@ function useCopilotChat(_a = {}) {
|
|
|
947
1358
|
setAgentSession
|
|
948
1359
|
}));
|
|
949
1360
|
const latestAppend = useUpdatedRef(append);
|
|
950
|
-
const latestAppendFunc = (0,
|
|
1361
|
+
const latestAppendFunc = (0, import_react10.useCallback)(
|
|
951
1362
|
(message) => {
|
|
952
1363
|
return latestAppend.current(message);
|
|
953
1364
|
},
|
|
954
1365
|
[latestAppend]
|
|
955
1366
|
);
|
|
956
1367
|
const latestReload = useUpdatedRef(reload);
|
|
957
|
-
const latestReloadFunc = (0,
|
|
1368
|
+
const latestReloadFunc = (0, import_react10.useCallback)(() => {
|
|
958
1369
|
return latestReload.current();
|
|
959
1370
|
}, [latestReload]);
|
|
960
1371
|
const latestStop = useUpdatedRef(stop);
|
|
961
|
-
const latestStopFunc = (0,
|
|
1372
|
+
const latestStopFunc = (0, import_react10.useCallback)(() => {
|
|
962
1373
|
return latestStop.current();
|
|
963
1374
|
}, [latestStop]);
|
|
964
1375
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
965
|
-
const latestDeleteFunc = (0,
|
|
1376
|
+
const latestDeleteFunc = (0, import_react10.useCallback)(
|
|
966
1377
|
(messageId) => {
|
|
967
1378
|
return latestDelete.current(messageId);
|
|
968
1379
|
},
|
|
969
1380
|
[latestDelete]
|
|
970
1381
|
);
|
|
971
1382
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
972
|
-
const latestSetMessagesFunc = (0,
|
|
1383
|
+
const latestSetMessagesFunc = (0, import_react10.useCallback)(
|
|
973
1384
|
(messages2) => {
|
|
974
1385
|
return latestSetMessages.current(messages2);
|
|
975
1386
|
},
|
|
@@ -986,8 +1397,8 @@ function useCopilotChat(_a = {}) {
|
|
|
986
1397
|
};
|
|
987
1398
|
}
|
|
988
1399
|
function useUpdatedRef(value) {
|
|
989
|
-
const ref = (0,
|
|
990
|
-
(0,
|
|
1400
|
+
const ref = (0, import_react10.useRef)(value);
|
|
1401
|
+
(0, import_react10.useEffect)(() => {
|
|
991
1402
|
ref.current = value;
|
|
992
1403
|
}, [value]);
|
|
993
1404
|
return ref;
|
|
@@ -1017,12 +1428,12 @@ ${additionalInstructions}` : "");
|
|
|
1017
1428
|
}
|
|
1018
1429
|
|
|
1019
1430
|
// src/hooks/use-copilot-action.ts
|
|
1020
|
-
var
|
|
1021
|
-
var
|
|
1431
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1432
|
+
var import_react11 = require("react");
|
|
1022
1433
|
function useCopilotAction(action, dependencies) {
|
|
1023
1434
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1024
|
-
const idRef = (0,
|
|
1025
|
-
const renderAndWaitRef = (0,
|
|
1435
|
+
const idRef = (0, import_react11.useRef)((0, import_shared6.randomId)());
|
|
1436
|
+
const renderAndWaitRef = (0, import_react11.useRef)(null);
|
|
1026
1437
|
action = __spreadValues({}, action);
|
|
1027
1438
|
if (action.renderAndWait || action.renderAndWaitForResponse) {
|
|
1028
1439
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
@@ -1057,7 +1468,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1057
1468
|
return renderAndWait(waitProps);
|
|
1058
1469
|
}
|
|
1059
1470
|
}
|
|
1060
|
-
return (0,
|
|
1471
|
+
return (0, import_react11.createElement)(import_react11.Fragment);
|
|
1061
1472
|
};
|
|
1062
1473
|
}
|
|
1063
1474
|
if (dependencies === void 0) {
|
|
@@ -1070,7 +1481,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1070
1481
|
}
|
|
1071
1482
|
}
|
|
1072
1483
|
}
|
|
1073
|
-
(0,
|
|
1484
|
+
(0, import_react11.useEffect)(() => {
|
|
1074
1485
|
setAction(idRef.current, action);
|
|
1075
1486
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1076
1487
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1084,6 +1495,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1084
1495
|
action.description,
|
|
1085
1496
|
action.name,
|
|
1086
1497
|
action.disabled,
|
|
1498
|
+
action.available,
|
|
1087
1499
|
// This should be faster than deep equality checking
|
|
1088
1500
|
// In addition, all major JS engines guarantee the order of object keys
|
|
1089
1501
|
JSON.stringify(action.parameters),
|
|
@@ -1095,16 +1507,16 @@ function useCopilotAction(action, dependencies) {
|
|
|
1095
1507
|
}
|
|
1096
1508
|
|
|
1097
1509
|
// src/hooks/use-coagent-state-render.ts
|
|
1098
|
-
var
|
|
1099
|
-
var
|
|
1510
|
+
var import_react12 = require("react");
|
|
1511
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1100
1512
|
function useCoAgentStateRender(action, dependencies) {
|
|
1101
1513
|
const {
|
|
1102
1514
|
setCoAgentStateRender,
|
|
1103
1515
|
removeCoAgentStateRender,
|
|
1104
1516
|
coAgentStateRenders,
|
|
1105
1517
|
chatComponentsCache
|
|
1106
|
-
} = (0,
|
|
1107
|
-
const idRef = (0,
|
|
1518
|
+
} = (0, import_react12.useContext)(CopilotContext);
|
|
1519
|
+
const idRef = (0, import_react12.useRef)((0, import_shared7.randomId)());
|
|
1108
1520
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1109
1521
|
if (dependencies === void 0) {
|
|
1110
1522
|
if (coAgentStateRenders[idRef.current]) {
|
|
@@ -1116,7 +1528,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1116
1528
|
}
|
|
1117
1529
|
}
|
|
1118
1530
|
}
|
|
1119
|
-
(0,
|
|
1531
|
+
(0, import_react12.useEffect)(() => {
|
|
1120
1532
|
setCoAgentStateRender(idRef.current, action);
|
|
1121
1533
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1122
1534
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -1136,11 +1548,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1136
1548
|
}
|
|
1137
1549
|
|
|
1138
1550
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1139
|
-
var
|
|
1551
|
+
var import_react13 = require("react");
|
|
1140
1552
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1141
1553
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1142
|
-
const idRef = (0,
|
|
1143
|
-
(0,
|
|
1554
|
+
const idRef = (0, import_react13.useRef)();
|
|
1555
|
+
(0, import_react13.useEffect)(() => {
|
|
1144
1556
|
const id = addDocumentContext(document, categories);
|
|
1145
1557
|
idRef.current = id;
|
|
1146
1558
|
return () => {
|
|
@@ -1151,16 +1563,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1151
1563
|
}
|
|
1152
1564
|
|
|
1153
1565
|
// src/hooks/use-copilot-readable.ts
|
|
1154
|
-
var
|
|
1566
|
+
var import_react14 = require("react");
|
|
1155
1567
|
function convertToJSON(description, value) {
|
|
1156
1568
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1157
1569
|
}
|
|
1158
1570
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
1159
1571
|
const { addContext, removeContext } = useCopilotContext();
|
|
1160
|
-
const idRef = (0,
|
|
1572
|
+
const idRef = (0, import_react14.useRef)();
|
|
1161
1573
|
convert = convert || convertToJSON;
|
|
1162
1574
|
const information = convert(description, value);
|
|
1163
|
-
(0,
|
|
1575
|
+
(0, import_react14.useEffect)(() => {
|
|
1164
1576
|
const id = addContext(information, parentId, categories);
|
|
1165
1577
|
idRef.current = id;
|
|
1166
1578
|
return () => {
|
|
@@ -1171,7 +1583,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1171
1583
|
}
|
|
1172
1584
|
|
|
1173
1585
|
// src/hooks/use-coagent.ts
|
|
1174
|
-
var
|
|
1586
|
+
var import_react15 = require("react");
|
|
1175
1587
|
function useCoAgent(options) {
|
|
1176
1588
|
const isExternalStateManagement = (options2) => {
|
|
1177
1589
|
return "state" in options2 && "setState" in options2;
|
|
@@ -1213,7 +1625,7 @@ function useCoAgent(options) {
|
|
|
1213
1625
|
};
|
|
1214
1626
|
const coagentState = getCoagentState(coagentStates, name);
|
|
1215
1627
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
1216
|
-
(0,
|
|
1628
|
+
(0, import_react15.useEffect)(() => {
|
|
1217
1629
|
if (isExternalStateManagement(options)) {
|
|
1218
1630
|
setState(options.state);
|
|
1219
1631
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -1278,8 +1690,8 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
1278
1690
|
}
|
|
1279
1691
|
|
|
1280
1692
|
// src/lib/copilot-task.ts
|
|
1281
|
-
var
|
|
1282
|
-
var
|
|
1693
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1694
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1283
1695
|
var CopilotTask = class {
|
|
1284
1696
|
constructor(config) {
|
|
1285
1697
|
this.instructions = config.instructions;
|
|
@@ -1306,12 +1718,12 @@ var CopilotTask = class {
|
|
|
1306
1718
|
if (this.includeCopilotReadable) {
|
|
1307
1719
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1308
1720
|
}
|
|
1309
|
-
const systemMessage = new
|
|
1721
|
+
const systemMessage = new import_runtime_client_gql6.TextMessage({
|
|
1310
1722
|
content: taskSystemMessage(contextString, this.instructions),
|
|
1311
|
-
role:
|
|
1723
|
+
role: import_runtime_client_gql6.Role.System
|
|
1312
1724
|
});
|
|
1313
1725
|
const messages = [systemMessage];
|
|
1314
|
-
const runtimeClient = new
|
|
1726
|
+
const runtimeClient = new import_runtime_client_gql6.CopilotRuntimeClient({
|
|
1315
1727
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
1316
1728
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
1317
1729
|
headers: context.copilotApiConfig.headers,
|
|
@@ -1323,13 +1735,13 @@ var CopilotTask = class {
|
|
|
1323
1735
|
actions: Object.values(actions).map((action) => ({
|
|
1324
1736
|
name: action.name,
|
|
1325
1737
|
description: action.description || "",
|
|
1326
|
-
jsonSchema: JSON.stringify((0,
|
|
1738
|
+
jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || []))
|
|
1327
1739
|
})),
|
|
1328
1740
|
url: window.location.href
|
|
1329
1741
|
},
|
|
1330
|
-
messages: (0,
|
|
1742
|
+
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)((0, import_runtime_client_gql6.filterAgentStateMessages)(messages)),
|
|
1331
1743
|
metadata: {
|
|
1332
|
-
requestType:
|
|
1744
|
+
requestType: import_runtime_client_gql6.CopilotRequestType.Task
|
|
1333
1745
|
},
|
|
1334
1746
|
forwardedParameters: {
|
|
1335
1747
|
toolChoice: "required"
|
|
@@ -1338,7 +1750,7 @@ var CopilotTask = class {
|
|
|
1338
1750
|
properties: context.copilotApiConfig.properties
|
|
1339
1751
|
}).toPromise();
|
|
1340
1752
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
1341
|
-
const functionCalls = (0,
|
|
1753
|
+
const functionCalls = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
|
|
1342
1754
|
((_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) || []
|
|
1343
1755
|
).filter((m) => m.isActionExecutionMessage());
|
|
1344
1756
|
for (const functionCall of functionCalls) {
|
|
@@ -1376,147 +1788,6 @@ ${instructions}
|
|
|
1376
1788
|
\`\`\`
|
|
1377
1789
|
`;
|
|
1378
1790
|
}
|
|
1379
|
-
|
|
1380
|
-
// src/utils/extract.ts
|
|
1381
|
-
var import_shared8 = require("@copilotkit/shared");
|
|
1382
|
-
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1383
|
-
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1384
|
-
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1385
|
-
function extract(_0) {
|
|
1386
|
-
return __async(this, arguments, function* ({
|
|
1387
|
-
context,
|
|
1388
|
-
instructions,
|
|
1389
|
-
parameters,
|
|
1390
|
-
include,
|
|
1391
|
-
data,
|
|
1392
|
-
abortSignal,
|
|
1393
|
-
stream,
|
|
1394
|
-
requestType = import_runtime_client_gql4.CopilotRequestType.Task
|
|
1395
|
-
}) {
|
|
1396
|
-
var _a, _b;
|
|
1397
|
-
const { messages } = context;
|
|
1398
|
-
const action = {
|
|
1399
|
-
name: "extract",
|
|
1400
|
-
description: instructions,
|
|
1401
|
-
parameters,
|
|
1402
|
-
handler: (args) => {
|
|
1403
|
-
}
|
|
1404
|
-
};
|
|
1405
|
-
const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
|
|
1406
|
-
const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
|
|
1407
|
-
let contextString = "";
|
|
1408
|
-
if (data) {
|
|
1409
|
-
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
1410
|
-
}
|
|
1411
|
-
if (includeReadable) {
|
|
1412
|
-
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1413
|
-
}
|
|
1414
|
-
const systemMessage = new import_runtime_client_gql4.TextMessage({
|
|
1415
|
-
content: makeSystemMessage(contextString, instructions),
|
|
1416
|
-
role: import_runtime_client_gql4.Role.System
|
|
1417
|
-
});
|
|
1418
|
-
const instructionsMessage = new import_runtime_client_gql4.TextMessage({
|
|
1419
|
-
content: makeInstructionsMessage(instructions),
|
|
1420
|
-
role: import_runtime_client_gql4.Role.User
|
|
1421
|
-
});
|
|
1422
|
-
const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [import_shared8.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
|
|
1423
|
-
const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
1424
|
-
url: context.copilotApiConfig.chatApiEndpoint,
|
|
1425
|
-
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
1426
|
-
headers,
|
|
1427
|
-
credentials: context.copilotApiConfig.credentials
|
|
1428
|
-
});
|
|
1429
|
-
const response = import_runtime_client_gql5.CopilotRuntimeClient.asStream(
|
|
1430
|
-
runtimeClient.generateCopilotResponse({
|
|
1431
|
-
data: {
|
|
1432
|
-
frontend: {
|
|
1433
|
-
actions: [
|
|
1434
|
-
{
|
|
1435
|
-
name: action.name,
|
|
1436
|
-
description: action.description || "",
|
|
1437
|
-
jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || []))
|
|
1438
|
-
}
|
|
1439
|
-
],
|
|
1440
|
-
url: window.location.href
|
|
1441
|
-
},
|
|
1442
|
-
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)(
|
|
1443
|
-
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql6.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1444
|
-
),
|
|
1445
|
-
metadata: {
|
|
1446
|
-
requestType
|
|
1447
|
-
},
|
|
1448
|
-
forwardedParameters: {
|
|
1449
|
-
toolChoice: "function",
|
|
1450
|
-
toolChoiceFunctionName: action.name
|
|
1451
|
-
}
|
|
1452
|
-
},
|
|
1453
|
-
properties: context.copilotApiConfig.properties,
|
|
1454
|
-
signal: abortSignal
|
|
1455
|
-
})
|
|
1456
|
-
);
|
|
1457
|
-
const reader = response.getReader();
|
|
1458
|
-
let isInitial = true;
|
|
1459
|
-
let actionExecutionMessage = void 0;
|
|
1460
|
-
while (true) {
|
|
1461
|
-
const { done, value } = yield reader.read();
|
|
1462
|
-
if (done) {
|
|
1463
|
-
break;
|
|
1464
|
-
}
|
|
1465
|
-
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1466
|
-
throw new Error("Aborted");
|
|
1467
|
-
}
|
|
1468
|
-
actionExecutionMessage = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1469
|
-
value.generateCopilotResponse.messages
|
|
1470
|
-
).find((msg) => msg.isActionExecutionMessage());
|
|
1471
|
-
if (!actionExecutionMessage) {
|
|
1472
|
-
continue;
|
|
1473
|
-
}
|
|
1474
|
-
stream == null ? void 0 : stream({
|
|
1475
|
-
status: isInitial ? "initial" : "inProgress",
|
|
1476
|
-
args: actionExecutionMessage.arguments
|
|
1477
|
-
});
|
|
1478
|
-
isInitial = false;
|
|
1479
|
-
}
|
|
1480
|
-
if (!actionExecutionMessage) {
|
|
1481
|
-
throw new Error("extract() failed: No function call occurred");
|
|
1482
|
-
}
|
|
1483
|
-
stream == null ? void 0 : stream({
|
|
1484
|
-
status: "complete",
|
|
1485
|
-
args: actionExecutionMessage.arguments
|
|
1486
|
-
});
|
|
1487
|
-
return actionExecutionMessage.arguments;
|
|
1488
|
-
});
|
|
1489
|
-
}
|
|
1490
|
-
function makeInstructionsMessage(instructions) {
|
|
1491
|
-
return `
|
|
1492
|
-
The user has given you the following task to complete:
|
|
1493
|
-
|
|
1494
|
-
\`\`\`
|
|
1495
|
-
${instructions}
|
|
1496
|
-
\`\`\`
|
|
1497
|
-
|
|
1498
|
-
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
1499
|
-
`;
|
|
1500
|
-
}
|
|
1501
|
-
function makeSystemMessage(contextString, instructions) {
|
|
1502
|
-
return `
|
|
1503
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1504
|
-
|
|
1505
|
-
Help the user achieve their goals, and you do so in a way that is as efficient as possible, without unnecessary fluff, but also without sacrificing professionalism.
|
|
1506
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1507
|
-
|
|
1508
|
-
The user has provided you with the following context:
|
|
1509
|
-
\`\`\`
|
|
1510
|
-
${contextString}
|
|
1511
|
-
\`\`\`
|
|
1512
|
-
|
|
1513
|
-
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
1514
|
-
|
|
1515
|
-
Please assist them as best you can.
|
|
1516
|
-
|
|
1517
|
-
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
1518
|
-
`;
|
|
1519
|
-
}
|
|
1520
1791
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1521
1792
|
0 && (module.exports = {
|
|
1522
1793
|
CopilotContext,
|
|
@@ -1525,6 +1796,7 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1525
1796
|
CopilotTask,
|
|
1526
1797
|
defaultCopilotContextCategories,
|
|
1527
1798
|
extract,
|
|
1799
|
+
shouldShowDevConsole,
|
|
1528
1800
|
useCoAgent,
|
|
1529
1801
|
useCoAgentStateRender,
|
|
1530
1802
|
useCopilotAction,
|
|
@@ -1532,6 +1804,7 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1532
1804
|
useCopilotContext,
|
|
1533
1805
|
useCopilotMessagesContext,
|
|
1534
1806
|
useCopilotReadable,
|
|
1807
|
+
useCopilotRuntimeClient,
|
|
1535
1808
|
useMakeCopilotDocumentReadable
|
|
1536
1809
|
});
|
|
1537
1810
|
//# sourceMappingURL=index.js.map
|