@copilotkit/react-core 1.4.1-pre.5 → 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 +15 -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
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,25 +1074,25 @@ 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
1081
|
actions: actions.filter(
|
|
691
|
-
(action) => action.available !==
|
|
1082
|
+
(action) => action.available !== import_runtime_client_gql4.ActionInputAvailability.Disabled || !action.disabled
|
|
692
1083
|
).map((action) => {
|
|
693
|
-
let available =
|
|
1084
|
+
let available = import_runtime_client_gql4.ActionInputAvailability.Enabled;
|
|
694
1085
|
if (action.disabled) {
|
|
695
|
-
available =
|
|
1086
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
696
1087
|
} else if (action.available === "disabled") {
|
|
697
|
-
available =
|
|
1088
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
698
1089
|
} else if (action.available === "remote") {
|
|
699
|
-
available =
|
|
1090
|
+
available = import_runtime_client_gql4.ActionInputAvailability.Remote;
|
|
700
1091
|
}
|
|
701
1092
|
return {
|
|
702
1093
|
name: action.name,
|
|
703
1094
|
description: action.description || "",
|
|
704
|
-
jsonSchema: JSON.stringify((0,
|
|
1095
|
+
jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || [])),
|
|
705
1096
|
available
|
|
706
1097
|
};
|
|
707
1098
|
}),
|
|
@@ -709,7 +1100,7 @@ function useChat(options) {
|
|
|
709
1100
|
},
|
|
710
1101
|
threadId: threadIdRef.current,
|
|
711
1102
|
runId: runIdRef.current,
|
|
712
|
-
messages: (0,
|
|
1103
|
+
messages: (0, import_runtime_client_gql4.convertMessagesToGqlInput)((0, import_runtime_client_gql4.filterAgentStateMessages)(messagesWithContext))
|
|
713
1104
|
}, copilotConfig.cloud ? {
|
|
714
1105
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
715
1106
|
guardrails: {
|
|
@@ -721,7 +1112,7 @@ function useChat(options) {
|
|
|
721
1112
|
} : {})
|
|
722
1113
|
} : {}), {
|
|
723
1114
|
metadata: {
|
|
724
|
-
requestType:
|
|
1115
|
+
requestType: import_runtime_client_gql4.CopilotRequestType.Chat
|
|
725
1116
|
}
|
|
726
1117
|
}), agentSessionRef.current ? {
|
|
727
1118
|
agentSession: agentSessionRef.current
|
|
@@ -742,7 +1133,14 @@ function useChat(options) {
|
|
|
742
1133
|
let followUp = void 0;
|
|
743
1134
|
try {
|
|
744
1135
|
while (true) {
|
|
745
|
-
|
|
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
|
+
}
|
|
746
1144
|
if (done) {
|
|
747
1145
|
break;
|
|
748
1146
|
}
|
|
@@ -751,8 +1149,8 @@ function useChat(options) {
|
|
|
751
1149
|
}
|
|
752
1150
|
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
753
1151
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
754
|
-
const messages2 = (0,
|
|
755
|
-
(0,
|
|
1152
|
+
const messages2 = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1153
|
+
(0, import_runtime_client_gql4.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
756
1154
|
);
|
|
757
1155
|
if (messages2.length === 0) {
|
|
758
1156
|
continue;
|
|
@@ -760,15 +1158,15 @@ function useChat(options) {
|
|
|
760
1158
|
newMessages = [];
|
|
761
1159
|
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
762
1160
|
newMessages = [
|
|
763
|
-
new
|
|
764
|
-
role:
|
|
1161
|
+
new import_runtime_client_gql4.TextMessage({
|
|
1162
|
+
role: import_runtime_client_gql4.MessageRole.Assistant,
|
|
765
1163
|
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
766
1164
|
})
|
|
767
1165
|
];
|
|
768
1166
|
} else {
|
|
769
1167
|
for (const message of messages2) {
|
|
770
1168
|
newMessages.push(message);
|
|
771
|
-
if (message.isActionExecutionMessage() && message.status.code !==
|
|
1169
|
+
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql4.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
772
1170
|
if (!(message.id in actionResults)) {
|
|
773
1171
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
774
1172
|
break;
|
|
@@ -791,8 +1189,8 @@ function useChat(options) {
|
|
|
791
1189
|
}
|
|
792
1190
|
}
|
|
793
1191
|
newMessages.push(
|
|
794
|
-
new
|
|
795
|
-
result:
|
|
1192
|
+
new import_runtime_client_gql4.ResultMessage({
|
|
1193
|
+
result: import_runtime_client_gql4.ResultMessage.encodeResult(actionResults[message.id]),
|
|
796
1194
|
actionExecutionId: message.id,
|
|
797
1195
|
actionName: message.name
|
|
798
1196
|
})
|
|
@@ -911,21 +1309,21 @@ function useCopilotChat(_a = {}) {
|
|
|
911
1309
|
} = useCopilotContext();
|
|
912
1310
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
913
1311
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
914
|
-
const deleteMessage = (0,
|
|
1312
|
+
const deleteMessage = (0, import_react10.useCallback)(
|
|
915
1313
|
(messageId) => {
|
|
916
1314
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
917
1315
|
},
|
|
918
1316
|
[setMessages]
|
|
919
1317
|
);
|
|
920
|
-
const makeSystemMessageCallback = (0,
|
|
1318
|
+
const makeSystemMessageCallback = (0, import_react10.useCallback)(() => {
|
|
921
1319
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
922
1320
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
923
|
-
return new
|
|
1321
|
+
return new import_runtime_client_gql5.TextMessage({
|
|
924
1322
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
925
|
-
role:
|
|
1323
|
+
role: import_runtime_client_gql5.Role.System
|
|
926
1324
|
});
|
|
927
1325
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
928
|
-
const onCoAgentStateRender = (0,
|
|
1326
|
+
const onCoAgentStateRender = (0, import_react10.useCallback)(
|
|
929
1327
|
(args) => __async(this, null, function* () {
|
|
930
1328
|
var _a2;
|
|
931
1329
|
const { name, nodeName, state } = args;
|
|
@@ -960,29 +1358,29 @@ function useCopilotChat(_a = {}) {
|
|
|
960
1358
|
setAgentSession
|
|
961
1359
|
}));
|
|
962
1360
|
const latestAppend = useUpdatedRef(append);
|
|
963
|
-
const latestAppendFunc = (0,
|
|
1361
|
+
const latestAppendFunc = (0, import_react10.useCallback)(
|
|
964
1362
|
(message) => {
|
|
965
1363
|
return latestAppend.current(message);
|
|
966
1364
|
},
|
|
967
1365
|
[latestAppend]
|
|
968
1366
|
);
|
|
969
1367
|
const latestReload = useUpdatedRef(reload);
|
|
970
|
-
const latestReloadFunc = (0,
|
|
1368
|
+
const latestReloadFunc = (0, import_react10.useCallback)(() => {
|
|
971
1369
|
return latestReload.current();
|
|
972
1370
|
}, [latestReload]);
|
|
973
1371
|
const latestStop = useUpdatedRef(stop);
|
|
974
|
-
const latestStopFunc = (0,
|
|
1372
|
+
const latestStopFunc = (0, import_react10.useCallback)(() => {
|
|
975
1373
|
return latestStop.current();
|
|
976
1374
|
}, [latestStop]);
|
|
977
1375
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
978
|
-
const latestDeleteFunc = (0,
|
|
1376
|
+
const latestDeleteFunc = (0, import_react10.useCallback)(
|
|
979
1377
|
(messageId) => {
|
|
980
1378
|
return latestDelete.current(messageId);
|
|
981
1379
|
},
|
|
982
1380
|
[latestDelete]
|
|
983
1381
|
);
|
|
984
1382
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
985
|
-
const latestSetMessagesFunc = (0,
|
|
1383
|
+
const latestSetMessagesFunc = (0, import_react10.useCallback)(
|
|
986
1384
|
(messages2) => {
|
|
987
1385
|
return latestSetMessages.current(messages2);
|
|
988
1386
|
},
|
|
@@ -999,8 +1397,8 @@ function useCopilotChat(_a = {}) {
|
|
|
999
1397
|
};
|
|
1000
1398
|
}
|
|
1001
1399
|
function useUpdatedRef(value) {
|
|
1002
|
-
const ref = (0,
|
|
1003
|
-
(0,
|
|
1400
|
+
const ref = (0, import_react10.useRef)(value);
|
|
1401
|
+
(0, import_react10.useEffect)(() => {
|
|
1004
1402
|
ref.current = value;
|
|
1005
1403
|
}, [value]);
|
|
1006
1404
|
return ref;
|
|
@@ -1030,12 +1428,12 @@ ${additionalInstructions}` : "");
|
|
|
1030
1428
|
}
|
|
1031
1429
|
|
|
1032
1430
|
// src/hooks/use-copilot-action.ts
|
|
1033
|
-
var
|
|
1034
|
-
var
|
|
1431
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1432
|
+
var import_react11 = require("react");
|
|
1035
1433
|
function useCopilotAction(action, dependencies) {
|
|
1036
1434
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1037
|
-
const idRef = (0,
|
|
1038
|
-
const renderAndWaitRef = (0,
|
|
1435
|
+
const idRef = (0, import_react11.useRef)((0, import_shared6.randomId)());
|
|
1436
|
+
const renderAndWaitRef = (0, import_react11.useRef)(null);
|
|
1039
1437
|
action = __spreadValues({}, action);
|
|
1040
1438
|
if (action.renderAndWait || action.renderAndWaitForResponse) {
|
|
1041
1439
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
@@ -1070,7 +1468,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1070
1468
|
return renderAndWait(waitProps);
|
|
1071
1469
|
}
|
|
1072
1470
|
}
|
|
1073
|
-
return (0,
|
|
1471
|
+
return (0, import_react11.createElement)(import_react11.Fragment);
|
|
1074
1472
|
};
|
|
1075
1473
|
}
|
|
1076
1474
|
if (dependencies === void 0) {
|
|
@@ -1083,7 +1481,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1083
1481
|
}
|
|
1084
1482
|
}
|
|
1085
1483
|
}
|
|
1086
|
-
(0,
|
|
1484
|
+
(0, import_react11.useEffect)(() => {
|
|
1087
1485
|
setAction(idRef.current, action);
|
|
1088
1486
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1089
1487
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1109,16 +1507,16 @@ function useCopilotAction(action, dependencies) {
|
|
|
1109
1507
|
}
|
|
1110
1508
|
|
|
1111
1509
|
// src/hooks/use-coagent-state-render.ts
|
|
1112
|
-
var
|
|
1113
|
-
var
|
|
1510
|
+
var import_react12 = require("react");
|
|
1511
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1114
1512
|
function useCoAgentStateRender(action, dependencies) {
|
|
1115
1513
|
const {
|
|
1116
1514
|
setCoAgentStateRender,
|
|
1117
1515
|
removeCoAgentStateRender,
|
|
1118
1516
|
coAgentStateRenders,
|
|
1119
1517
|
chatComponentsCache
|
|
1120
|
-
} = (0,
|
|
1121
|
-
const idRef = (0,
|
|
1518
|
+
} = (0, import_react12.useContext)(CopilotContext);
|
|
1519
|
+
const idRef = (0, import_react12.useRef)((0, import_shared7.randomId)());
|
|
1122
1520
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1123
1521
|
if (dependencies === void 0) {
|
|
1124
1522
|
if (coAgentStateRenders[idRef.current]) {
|
|
@@ -1130,7 +1528,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1130
1528
|
}
|
|
1131
1529
|
}
|
|
1132
1530
|
}
|
|
1133
|
-
(0,
|
|
1531
|
+
(0, import_react12.useEffect)(() => {
|
|
1134
1532
|
setCoAgentStateRender(idRef.current, action);
|
|
1135
1533
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1136
1534
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -1150,11 +1548,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1150
1548
|
}
|
|
1151
1549
|
|
|
1152
1550
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1153
|
-
var
|
|
1551
|
+
var import_react13 = require("react");
|
|
1154
1552
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1155
1553
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1156
|
-
const idRef = (0,
|
|
1157
|
-
(0,
|
|
1554
|
+
const idRef = (0, import_react13.useRef)();
|
|
1555
|
+
(0, import_react13.useEffect)(() => {
|
|
1158
1556
|
const id = addDocumentContext(document, categories);
|
|
1159
1557
|
idRef.current = id;
|
|
1160
1558
|
return () => {
|
|
@@ -1165,16 +1563,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1165
1563
|
}
|
|
1166
1564
|
|
|
1167
1565
|
// src/hooks/use-copilot-readable.ts
|
|
1168
|
-
var
|
|
1566
|
+
var import_react14 = require("react");
|
|
1169
1567
|
function convertToJSON(description, value) {
|
|
1170
1568
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1171
1569
|
}
|
|
1172
1570
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
1173
1571
|
const { addContext, removeContext } = useCopilotContext();
|
|
1174
|
-
const idRef = (0,
|
|
1572
|
+
const idRef = (0, import_react14.useRef)();
|
|
1175
1573
|
convert = convert || convertToJSON;
|
|
1176
1574
|
const information = convert(description, value);
|
|
1177
|
-
(0,
|
|
1575
|
+
(0, import_react14.useEffect)(() => {
|
|
1178
1576
|
const id = addContext(information, parentId, categories);
|
|
1179
1577
|
idRef.current = id;
|
|
1180
1578
|
return () => {
|
|
@@ -1185,7 +1583,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1185
1583
|
}
|
|
1186
1584
|
|
|
1187
1585
|
// src/hooks/use-coagent.ts
|
|
1188
|
-
var
|
|
1586
|
+
var import_react15 = require("react");
|
|
1189
1587
|
function useCoAgent(options) {
|
|
1190
1588
|
const isExternalStateManagement = (options2) => {
|
|
1191
1589
|
return "state" in options2 && "setState" in options2;
|
|
@@ -1227,7 +1625,7 @@ function useCoAgent(options) {
|
|
|
1227
1625
|
};
|
|
1228
1626
|
const coagentState = getCoagentState(coagentStates, name);
|
|
1229
1627
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
1230
|
-
(0,
|
|
1628
|
+
(0, import_react15.useEffect)(() => {
|
|
1231
1629
|
if (isExternalStateManagement(options)) {
|
|
1232
1630
|
setState(options.state);
|
|
1233
1631
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -1292,8 +1690,8 @@ function runAgent(name, context, appendMessage, hint) {
|
|
|
1292
1690
|
}
|
|
1293
1691
|
|
|
1294
1692
|
// src/lib/copilot-task.ts
|
|
1295
|
-
var
|
|
1296
|
-
var
|
|
1693
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1694
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1297
1695
|
var CopilotTask = class {
|
|
1298
1696
|
constructor(config) {
|
|
1299
1697
|
this.instructions = config.instructions;
|
|
@@ -1320,12 +1718,12 @@ var CopilotTask = class {
|
|
|
1320
1718
|
if (this.includeCopilotReadable) {
|
|
1321
1719
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1322
1720
|
}
|
|
1323
|
-
const systemMessage = new
|
|
1721
|
+
const systemMessage = new import_runtime_client_gql6.TextMessage({
|
|
1324
1722
|
content: taskSystemMessage(contextString, this.instructions),
|
|
1325
|
-
role:
|
|
1723
|
+
role: import_runtime_client_gql6.Role.System
|
|
1326
1724
|
});
|
|
1327
1725
|
const messages = [systemMessage];
|
|
1328
|
-
const runtimeClient = new
|
|
1726
|
+
const runtimeClient = new import_runtime_client_gql6.CopilotRuntimeClient({
|
|
1329
1727
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
1330
1728
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
1331
1729
|
headers: context.copilotApiConfig.headers,
|
|
@@ -1337,13 +1735,13 @@ var CopilotTask = class {
|
|
|
1337
1735
|
actions: Object.values(actions).map((action) => ({
|
|
1338
1736
|
name: action.name,
|
|
1339
1737
|
description: action.description || "",
|
|
1340
|
-
jsonSchema: JSON.stringify((0,
|
|
1738
|
+
jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || []))
|
|
1341
1739
|
})),
|
|
1342
1740
|
url: window.location.href
|
|
1343
1741
|
},
|
|
1344
|
-
messages: (0,
|
|
1742
|
+
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)((0, import_runtime_client_gql6.filterAgentStateMessages)(messages)),
|
|
1345
1743
|
metadata: {
|
|
1346
|
-
requestType:
|
|
1744
|
+
requestType: import_runtime_client_gql6.CopilotRequestType.Task
|
|
1347
1745
|
},
|
|
1348
1746
|
forwardedParameters: {
|
|
1349
1747
|
toolChoice: "required"
|
|
@@ -1352,7 +1750,7 @@ var CopilotTask = class {
|
|
|
1352
1750
|
properties: context.copilotApiConfig.properties
|
|
1353
1751
|
}).toPromise();
|
|
1354
1752
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
1355
|
-
const functionCalls = (0,
|
|
1753
|
+
const functionCalls = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
|
|
1356
1754
|
((_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) || []
|
|
1357
1755
|
).filter((m) => m.isActionExecutionMessage());
|
|
1358
1756
|
for (const functionCall of functionCalls) {
|
|
@@ -1390,147 +1788,6 @@ ${instructions}
|
|
|
1390
1788
|
\`\`\`
|
|
1391
1789
|
`;
|
|
1392
1790
|
}
|
|
1393
|
-
|
|
1394
|
-
// src/utils/extract.ts
|
|
1395
|
-
var import_shared8 = require("@copilotkit/shared");
|
|
1396
|
-
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1397
|
-
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1398
|
-
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1399
|
-
function extract(_0) {
|
|
1400
|
-
return __async(this, arguments, function* ({
|
|
1401
|
-
context,
|
|
1402
|
-
instructions,
|
|
1403
|
-
parameters,
|
|
1404
|
-
include,
|
|
1405
|
-
data,
|
|
1406
|
-
abortSignal,
|
|
1407
|
-
stream,
|
|
1408
|
-
requestType = import_runtime_client_gql4.CopilotRequestType.Task
|
|
1409
|
-
}) {
|
|
1410
|
-
var _a, _b;
|
|
1411
|
-
const { messages } = context;
|
|
1412
|
-
const action = {
|
|
1413
|
-
name: "extract",
|
|
1414
|
-
description: instructions,
|
|
1415
|
-
parameters,
|
|
1416
|
-
handler: (args) => {
|
|
1417
|
-
}
|
|
1418
|
-
};
|
|
1419
|
-
const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
|
|
1420
|
-
const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
|
|
1421
|
-
let contextString = "";
|
|
1422
|
-
if (data) {
|
|
1423
|
-
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
1424
|
-
}
|
|
1425
|
-
if (includeReadable) {
|
|
1426
|
-
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1427
|
-
}
|
|
1428
|
-
const systemMessage = new import_runtime_client_gql4.TextMessage({
|
|
1429
|
-
content: makeSystemMessage(contextString, instructions),
|
|
1430
|
-
role: import_runtime_client_gql4.Role.System
|
|
1431
|
-
});
|
|
1432
|
-
const instructionsMessage = new import_runtime_client_gql4.TextMessage({
|
|
1433
|
-
content: makeInstructionsMessage(instructions),
|
|
1434
|
-
role: import_runtime_client_gql4.Role.User
|
|
1435
|
-
});
|
|
1436
|
-
const headers = __spreadValues(__spreadValues({}, context.copilotApiConfig.headers || {}), context.copilotApiConfig.publicApiKey ? { [import_shared8.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: context.copilotApiConfig.publicApiKey } : {});
|
|
1437
|
-
const runtimeClient = new import_runtime_client_gql5.CopilotRuntimeClient({
|
|
1438
|
-
url: context.copilotApiConfig.chatApiEndpoint,
|
|
1439
|
-
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
1440
|
-
headers,
|
|
1441
|
-
credentials: context.copilotApiConfig.credentials
|
|
1442
|
-
});
|
|
1443
|
-
const response = import_runtime_client_gql5.CopilotRuntimeClient.asStream(
|
|
1444
|
-
runtimeClient.generateCopilotResponse({
|
|
1445
|
-
data: {
|
|
1446
|
-
frontend: {
|
|
1447
|
-
actions: [
|
|
1448
|
-
{
|
|
1449
|
-
name: action.name,
|
|
1450
|
-
description: action.description || "",
|
|
1451
|
-
jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || []))
|
|
1452
|
-
}
|
|
1453
|
-
],
|
|
1454
|
-
url: window.location.href
|
|
1455
|
-
},
|
|
1456
|
-
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)(
|
|
1457
|
-
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql6.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1458
|
-
),
|
|
1459
|
-
metadata: {
|
|
1460
|
-
requestType
|
|
1461
|
-
},
|
|
1462
|
-
forwardedParameters: {
|
|
1463
|
-
toolChoice: "function",
|
|
1464
|
-
toolChoiceFunctionName: action.name
|
|
1465
|
-
}
|
|
1466
|
-
},
|
|
1467
|
-
properties: context.copilotApiConfig.properties,
|
|
1468
|
-
signal: abortSignal
|
|
1469
|
-
})
|
|
1470
|
-
);
|
|
1471
|
-
const reader = response.getReader();
|
|
1472
|
-
let isInitial = true;
|
|
1473
|
-
let actionExecutionMessage = void 0;
|
|
1474
|
-
while (true) {
|
|
1475
|
-
const { done, value } = yield reader.read();
|
|
1476
|
-
if (done) {
|
|
1477
|
-
break;
|
|
1478
|
-
}
|
|
1479
|
-
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1480
|
-
throw new Error("Aborted");
|
|
1481
|
-
}
|
|
1482
|
-
actionExecutionMessage = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1483
|
-
value.generateCopilotResponse.messages
|
|
1484
|
-
).find((msg) => msg.isActionExecutionMessage());
|
|
1485
|
-
if (!actionExecutionMessage) {
|
|
1486
|
-
continue;
|
|
1487
|
-
}
|
|
1488
|
-
stream == null ? void 0 : stream({
|
|
1489
|
-
status: isInitial ? "initial" : "inProgress",
|
|
1490
|
-
args: actionExecutionMessage.arguments
|
|
1491
|
-
});
|
|
1492
|
-
isInitial = false;
|
|
1493
|
-
}
|
|
1494
|
-
if (!actionExecutionMessage) {
|
|
1495
|
-
throw new Error("extract() failed: No function call occurred");
|
|
1496
|
-
}
|
|
1497
|
-
stream == null ? void 0 : stream({
|
|
1498
|
-
status: "complete",
|
|
1499
|
-
args: actionExecutionMessage.arguments
|
|
1500
|
-
});
|
|
1501
|
-
return actionExecutionMessage.arguments;
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
function makeInstructionsMessage(instructions) {
|
|
1505
|
-
return `
|
|
1506
|
-
The user has given you the following task to complete:
|
|
1507
|
-
|
|
1508
|
-
\`\`\`
|
|
1509
|
-
${instructions}
|
|
1510
|
-
\`\`\`
|
|
1511
|
-
|
|
1512
|
-
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
1513
|
-
`;
|
|
1514
|
-
}
|
|
1515
|
-
function makeSystemMessage(contextString, instructions) {
|
|
1516
|
-
return `
|
|
1517
|
-
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1518
|
-
|
|
1519
|
-
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.
|
|
1520
|
-
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1521
|
-
|
|
1522
|
-
The user has provided you with the following context:
|
|
1523
|
-
\`\`\`
|
|
1524
|
-
${contextString}
|
|
1525
|
-
\`\`\`
|
|
1526
|
-
|
|
1527
|
-
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
1528
|
-
|
|
1529
|
-
Please assist them as best you can.
|
|
1530
|
-
|
|
1531
|
-
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
1532
|
-
`;
|
|
1533
|
-
}
|
|
1534
1791
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1535
1792
|
0 && (module.exports = {
|
|
1536
1793
|
CopilotContext,
|
|
@@ -1539,6 +1796,7 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1539
1796
|
CopilotTask,
|
|
1540
1797
|
defaultCopilotContextCategories,
|
|
1541
1798
|
extract,
|
|
1799
|
+
shouldShowDevConsole,
|
|
1542
1800
|
useCoAgent,
|
|
1543
1801
|
useCoAgentStateRender,
|
|
1544
1802
|
useCopilotAction,
|
|
@@ -1546,6 +1804,7 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1546
1804
|
useCopilotContext,
|
|
1547
1805
|
useCopilotMessagesContext,
|
|
1548
1806
|
useCopilotReadable,
|
|
1807
|
+
useCopilotRuntimeClient,
|
|
1549
1808
|
useMakeCopilotDocumentReadable
|
|
1550
1809
|
});
|
|
1551
1810
|
//# sourceMappingURL=index.js.map
|