@copilotkit/react-core 1.5.1-next.1 → 1.5.1-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/dist/{chunk-SFPANIOY.mjs → chunk-2KCEHGSI.mjs} +49 -99
- package/dist/chunk-2KCEHGSI.mjs.map +1 -0
- package/dist/{chunk-YL6V3QTN.mjs → chunk-6OR25P32.mjs} +15 -42
- package/dist/chunk-6OR25P32.mjs.map +1 -0
- package/dist/{chunk-VQDGBYWQ.mjs → chunk-DDVXFNYA.mjs} +31 -55
- package/dist/chunk-DDVXFNYA.mjs.map +1 -0
- package/dist/{chunk-NYBGR2NK.mjs → chunk-FXHKK52V.mjs} +13 -14
- package/dist/chunk-FXHKK52V.mjs.map +1 -0
- package/dist/{chunk-VPTC36RZ.mjs → chunk-H4VZMKR6.mjs} +2 -2
- package/dist/{chunk-OAF4ASJH.mjs → chunk-H7LSKIDK.mjs} +23 -70
- package/dist/chunk-H7LSKIDK.mjs.map +1 -0
- package/dist/chunk-JDQCJCAQ.mjs +295 -0
- package/dist/chunk-JDQCJCAQ.mjs.map +1 -0
- package/dist/{chunk-STZUYPHJ.mjs → chunk-LODRWFMB.mjs} +2 -14
- package/dist/chunk-LODRWFMB.mjs.map +1 -0
- package/dist/{chunk-MKEQ2MJG.mjs → chunk-MWZO6TUR.mjs} +13 -29
- package/dist/chunk-MWZO6TUR.mjs.map +1 -0
- package/dist/{chunk-7LRDVJH5.mjs → chunk-ODN4H66E.mjs} +2 -6
- package/dist/chunk-ODN4H66E.mjs.map +1 -0
- package/dist/{chunk-6KHA5W5R.mjs → chunk-QDGDXRRJ.mjs} +2 -2
- package/dist/{chunk-ODAH4HNG.mjs → chunk-XINZBP3J.mjs} +2 -2
- package/dist/{chunk-ODAH4HNG.mjs.map → chunk-XINZBP3J.mjs.map} +1 -1
- package/dist/components/copilot-provider/copilot-messages.d.ts +0 -1
- package/dist/components/copilot-provider/copilotkit-props.d.ts +0 -5
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +0 -1
- package/dist/components/copilot-provider/copilotkit.js +91 -191
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +7 -8
- package/dist/components/copilot-provider/index.d.ts +0 -1
- package/dist/components/copilot-provider/index.js +91 -191
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +7 -8
- package/dist/components/index.d.ts +0 -1
- package/dist/components/index.js +91 -191
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +7 -8
- package/dist/components/toast/toast-provider.d.ts +1 -2
- package/dist/components/toast/toast-provider.js +62 -76
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/context/copilot-context.d.ts +3 -15
- package/dist/context/copilot-context.js +1 -13
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +1 -13
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +4 -4
- package/dist/hooks/index.d.ts +1 -2
- package/dist/hooks/index.js +293 -624
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +22 -30
- package/dist/hooks/use-chat.d.ts +3 -31
- package/dist/hooks/use-chat.js +205 -443
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +3 -4
- package/dist/hooks/use-coagent-state-render.d.ts +2 -2
- package/dist/hooks/use-coagent-state-render.js +1 -13
- 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.d.ts +1 -14
- package/dist/hooks/use-coagent.js +262 -580
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +11 -19
- package/dist/hooks/use-copilot-action.d.ts +2 -12
- package/dist/hooks/use-copilot-action.js +17 -167
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -4
- package/dist/hooks/use-copilot-chat.d.ts +0 -2
- package/dist/hooks/use-copilot-chat.js +238 -532
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +10 -12
- package/dist/hooks/use-copilot-readable.js +1 -13
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.js +4 -110
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +1 -13
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +391 -703
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -38
- package/dist/lib/copilot-task.d.ts +1 -6
- package/dist/lib/copilot-task.js +17 -55
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +8 -10
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +17 -55
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +8 -10
- package/dist/types/frontend-action.d.ts +2 -21
- package/dist/types/frontend-action.js +0 -34
- package/dist/types/frontend-action.js.map +1 -1
- package/dist/types/frontend-action.mjs +0 -7
- package/dist/types/index.d.ts +1 -2
- package/dist/types/index.js.map +1 -1
- package/dist/utils/extract.d.ts +2 -3
- package/dist/utils/extract.js +3 -21
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +7 -8
- package/dist/utils/index.js +3 -21
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +9 -10
- package/package.json +5 -5
- package/src/components/copilot-provider/copilotkit-props.tsx +10 -0
- package/src/components/copilot-provider/copilotkit.tsx +44 -7
- package/src/components/toast/toast-provider.tsx +1 -1
- package/src/context/copilot-context.tsx +28 -2
- package/src/hooks/index.ts +1 -0
- package/src/hooks/use-chat.ts +15 -5
- package/src/hooks/use-coagent-state-render.ts +11 -0
- package/src/hooks/use-coagent.ts +11 -1
- package/src/hooks/use-copilot-authenticated-action.ts +60 -0
- package/src/hooks/use-copilot-chat.ts +1 -0
- package/dist/chunk-7LRDVJH5.mjs.map +0 -1
- package/dist/chunk-M3SYKJ3W.mjs +0 -393
- package/dist/chunk-M3SYKJ3W.mjs.map +0 -1
- package/dist/chunk-MKEQ2MJG.mjs.map +0 -1
- package/dist/chunk-NYBGR2NK.mjs.map +0 -1
- package/dist/chunk-OAF4ASJH.mjs.map +0 -1
- package/dist/chunk-QCUP6HLK.mjs +0 -37
- package/dist/chunk-QCUP6HLK.mjs.map +0 -1
- package/dist/chunk-SFPANIOY.mjs.map +0 -1
- package/dist/chunk-STZUYPHJ.mjs.map +0 -1
- package/dist/chunk-VQDGBYWQ.mjs.map +0 -1
- package/dist/chunk-XERJQUHA.mjs +0 -31
- package/dist/chunk-XERJQUHA.mjs.map +0 -1
- package/dist/chunk-YL6V3QTN.mjs.map +0 -1
- package/dist/components/error-boundary/error-boundary.d.ts +0 -22
- package/dist/components/error-boundary/error-boundary.js +0 -183
- package/dist/components/error-boundary/error-boundary.js.map +0 -1
- package/dist/components/error-boundary/error-boundary.mjs +0 -12
- package/dist/components/error-boundary/error-boundary.mjs.map +0 -1
- package/dist/components/error-boundary/error-utils.d.ts +0 -11
- package/dist/components/error-boundary/error-utils.js +0 -177
- package/dist/components/error-boundary/error-utils.js.map +0 -1
- package/dist/components/error-boundary/error-utils.mjs +0 -13
- package/dist/components/error-boundary/error-utils.mjs.map +0 -1
- /package/dist/{chunk-VPTC36RZ.mjs.map → chunk-H4VZMKR6.mjs.map} +0 -0
- /package/dist/{chunk-6KHA5W5R.mjs.map → chunk-QDGDXRRJ.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -87,10 +87,7 @@ __export(src_exports, {
|
|
|
87
87
|
CopilotTask: () => CopilotTask,
|
|
88
88
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
89
89
|
extract: () => extract,
|
|
90
|
-
runAgent: () => runAgent,
|
|
91
90
|
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
92
|
-
startAgent: () => startAgent,
|
|
93
|
-
stopAgent: () => stopAgent,
|
|
94
91
|
useCoAgent: () => useCoAgent,
|
|
95
92
|
useCoAgentStateRender: () => useCoAgentStateRender,
|
|
96
93
|
useCopilotAction: () => useCopilotAction,
|
|
@@ -104,7 +101,7 @@ __export(src_exports, {
|
|
|
104
101
|
module.exports = __toCommonJS(src_exports);
|
|
105
102
|
|
|
106
103
|
// src/components/copilot-provider/copilotkit.tsx
|
|
107
|
-
var
|
|
104
|
+
var import_react8 = require("react");
|
|
108
105
|
|
|
109
106
|
// src/context/copilot-context.tsx
|
|
110
107
|
var import_react = __toESM(require("react"));
|
|
@@ -155,21 +152,9 @@ var emptyCopilotContext = {
|
|
|
155
152
|
coagentStates: {},
|
|
156
153
|
setCoagentStates: () => {
|
|
157
154
|
},
|
|
158
|
-
coagentStatesRef: { current: {} },
|
|
159
|
-
setCoagentStatesWithRef: () => {
|
|
160
|
-
},
|
|
161
155
|
agentSession: null,
|
|
162
156
|
setAgentSession: () => {
|
|
163
|
-
}
|
|
164
|
-
forwardedParameters: {},
|
|
165
|
-
agentLock: null,
|
|
166
|
-
threadId: null,
|
|
167
|
-
setThreadId: () => {
|
|
168
|
-
},
|
|
169
|
-
runId: null,
|
|
170
|
-
setRunId: () => {
|
|
171
|
-
},
|
|
172
|
-
chatAbortControllerRef: { current: null }
|
|
157
|
+
}
|
|
173
158
|
};
|
|
174
159
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
175
160
|
function useCopilotContext() {
|
|
@@ -423,9 +408,6 @@ function CopilotMessages(_a) {
|
|
|
423
408
|
}
|
|
424
409
|
|
|
425
410
|
// src/components/toast/toast-provider.tsx
|
|
426
|
-
var import_react7 = require("react");
|
|
427
|
-
|
|
428
|
-
// src/components/error-boundary/error-utils.tsx
|
|
429
411
|
var import_react6 = require("react");
|
|
430
412
|
|
|
431
413
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
@@ -455,94 +437,11 @@ var ExclamationMarkIcon = ({
|
|
|
455
437
|
}
|
|
456
438
|
);
|
|
457
439
|
|
|
458
|
-
// src/components/error-boundary/error-utils.tsx
|
|
459
|
-
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
460
|
-
function ErrorToast({ errors }) {
|
|
461
|
-
const errorsToRender = errors.map((error, idx) => {
|
|
462
|
-
var _a, _b, _c;
|
|
463
|
-
const message = "extensions" in error ? (_b = (_a = error.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message : error.message;
|
|
464
|
-
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
465
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
466
|
-
"div",
|
|
467
|
-
{
|
|
468
|
-
style: {
|
|
469
|
-
marginTop: idx === 0 ? 0 : 10,
|
|
470
|
-
marginBottom: 14
|
|
471
|
-
},
|
|
472
|
-
children: [
|
|
473
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ExclamationMarkIcon, { style: { marginBottom: 4 } }),
|
|
474
|
-
code && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
475
|
-
"div",
|
|
476
|
-
{
|
|
477
|
-
style: {
|
|
478
|
-
fontWeight: "600",
|
|
479
|
-
marginBottom: 4
|
|
480
|
-
},
|
|
481
|
-
children: [
|
|
482
|
-
"Copilot Cloud Error:",
|
|
483
|
-
" ",
|
|
484
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontFamily: "monospace", fontWeight: "normal" }, children: code })
|
|
485
|
-
]
|
|
486
|
-
}
|
|
487
|
-
),
|
|
488
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message })
|
|
489
|
-
]
|
|
490
|
-
},
|
|
491
|
-
idx
|
|
492
|
-
);
|
|
493
|
-
});
|
|
494
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
495
|
-
"div",
|
|
496
|
-
{
|
|
497
|
-
style: {
|
|
498
|
-
fontSize: "13px",
|
|
499
|
-
maxWidth: "600px"
|
|
500
|
-
},
|
|
501
|
-
children: [
|
|
502
|
-
errorsToRender,
|
|
503
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "11px", opacity: 0.75 }, children: "NOTE: This error only displays during local development." })
|
|
504
|
-
]
|
|
505
|
-
}
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
function useErrorToast() {
|
|
509
|
-
const { addToast } = useToast();
|
|
510
|
-
return (0, import_react6.useCallback)(
|
|
511
|
-
(error) => {
|
|
512
|
-
const errorId = error.map((err) => {
|
|
513
|
-
var _a, _b;
|
|
514
|
-
const message = "extensions" in err ? ((_b = (_a = err.extensions) == null ? void 0 : _a.originalError) == null ? void 0 : _b.message) || err.message : err.message;
|
|
515
|
-
const stack = err.stack || "";
|
|
516
|
-
return btoa(message + stack).slice(0, 32);
|
|
517
|
-
}).join("|");
|
|
518
|
-
addToast({
|
|
519
|
-
type: "error",
|
|
520
|
-
id: errorId,
|
|
521
|
-
// Toast libraries typically dedupe by id
|
|
522
|
-
message: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ErrorToast, { errors: error })
|
|
523
|
-
});
|
|
524
|
-
},
|
|
525
|
-
[addToast]
|
|
526
|
-
);
|
|
527
|
-
}
|
|
528
|
-
function useAsyncCallback(callback, deps) {
|
|
529
|
-
const addErrorToast = useErrorToast();
|
|
530
|
-
return (0, import_react6.useCallback)((...args) => __async(this, null, function* () {
|
|
531
|
-
try {
|
|
532
|
-
return yield callback(...args);
|
|
533
|
-
} catch (error) {
|
|
534
|
-
console.error("Error in async callback:", error);
|
|
535
|
-
addErrorToast([error]);
|
|
536
|
-
throw error;
|
|
537
|
-
}
|
|
538
|
-
}), deps);
|
|
539
|
-
}
|
|
540
|
-
|
|
541
440
|
// src/components/toast/toast-provider.tsx
|
|
542
|
-
var
|
|
543
|
-
var ToastContext = (0,
|
|
441
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
442
|
+
var ToastContext = (0, import_react6.createContext)(void 0);
|
|
544
443
|
function useToast() {
|
|
545
|
-
const context = (0,
|
|
444
|
+
const context = (0, import_react6.useContext)(ToastContext);
|
|
546
445
|
if (!context) {
|
|
547
446
|
throw new Error("useToast must be used within a ToastProvider");
|
|
548
447
|
}
|
|
@@ -552,28 +451,68 @@ function ToastProvider({
|
|
|
552
451
|
enabled,
|
|
553
452
|
children
|
|
554
453
|
}) {
|
|
555
|
-
const [toasts, setToasts] = (0,
|
|
556
|
-
const addToast = (0,
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
setToasts((currentToasts) => {
|
|
560
|
-
if (currentToasts.find((toast2) => toast2.id === id))
|
|
561
|
-
return currentToasts;
|
|
562
|
-
return [...currentToasts, __spreadProps(__spreadValues({}, toast), { id })];
|
|
563
|
-
});
|
|
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 })]);
|
|
564
458
|
if (toast.duration) {
|
|
565
459
|
setTimeout(() => {
|
|
566
460
|
removeToast(id);
|
|
567
461
|
}, toast.duration);
|
|
568
462
|
}
|
|
569
463
|
}, []);
|
|
570
|
-
const addGraphQLErrorsToast = (0,
|
|
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
|
+
});
|
|
571
498
|
addToast({
|
|
572
499
|
type: "error",
|
|
573
|
-
message: /* @__PURE__ */ (0,
|
|
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
|
+
)
|
|
574
513
|
});
|
|
575
514
|
}, []);
|
|
576
|
-
const removeToast = (0,
|
|
515
|
+
const removeToast = (0, import_react6.useCallback)((id) => {
|
|
577
516
|
setToasts((currentToasts) => currentToasts.filter((toast) => toast.id !== id));
|
|
578
517
|
}, []);
|
|
579
518
|
const value = {
|
|
@@ -583,8 +522,8 @@ function ToastProvider({
|
|
|
583
522
|
removeToast,
|
|
584
523
|
enabled
|
|
585
524
|
};
|
|
586
|
-
return /* @__PURE__ */ (0,
|
|
587
|
-
/* @__PURE__ */ (0,
|
|
525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ToastContext.Provider, { value, children: [
|
|
526
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
588
527
|
"div",
|
|
589
528
|
{
|
|
590
529
|
style: {
|
|
@@ -598,7 +537,7 @@ function ToastProvider({
|
|
|
598
537
|
gap: "0.5rem"
|
|
599
538
|
},
|
|
600
539
|
children: [
|
|
601
|
-
toasts.length > 1 && /* @__PURE__ */ (0,
|
|
540
|
+
toasts.length > 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { textAlign: "right" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
602
541
|
"button",
|
|
603
542
|
{
|
|
604
543
|
onClick: () => setToasts([]),
|
|
@@ -613,7 +552,7 @@ function ToastProvider({
|
|
|
613
552
|
children: "Close All"
|
|
614
553
|
}
|
|
615
554
|
) }),
|
|
616
|
-
toasts.map((toast) => /* @__PURE__ */ (0,
|
|
555
|
+
toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
617
556
|
Toast,
|
|
618
557
|
{
|
|
619
558
|
message: toast.message,
|
|
@@ -639,7 +578,7 @@ function Toast({
|
|
|
639
578
|
warning: "#eab308",
|
|
640
579
|
error: "#ef4444"
|
|
641
580
|
};
|
|
642
|
-
return /* @__PURE__ */ (0,
|
|
581
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
643
582
|
"div",
|
|
644
583
|
{
|
|
645
584
|
style: {
|
|
@@ -652,8 +591,8 @@ function Toast({
|
|
|
652
591
|
minWidth: "200px"
|
|
653
592
|
},
|
|
654
593
|
children: [
|
|
655
|
-
/* @__PURE__ */ (0,
|
|
656
|
-
/* @__PURE__ */ (0,
|
|
594
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { children: message }),
|
|
595
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
657
596
|
"button",
|
|
658
597
|
{
|
|
659
598
|
onClick: onClose,
|
|
@@ -678,17 +617,14 @@ function Toast({
|
|
|
678
617
|
|
|
679
618
|
// src/hooks/use-copilot-runtime-client.ts
|
|
680
619
|
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
681
|
-
var
|
|
620
|
+
var import_react7 = require("react");
|
|
682
621
|
var useCopilotRuntimeClient = (options) => {
|
|
683
622
|
const { addGraphQLErrorsToast } = useToast();
|
|
684
|
-
const
|
|
685
|
-
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
623
|
+
const runtimeClient = (0, import_react7.useMemo)(() => {
|
|
686
624
|
return new import_runtime_client_gql.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
687
625
|
handleGQLErrors: (error) => {
|
|
688
626
|
if (error.graphQLErrors.length) {
|
|
689
627
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
690
|
-
} else {
|
|
691
|
-
addErrorToast([error]);
|
|
692
628
|
}
|
|
693
629
|
}
|
|
694
630
|
}));
|
|
@@ -709,8 +645,7 @@ function extract(_0) {
|
|
|
709
645
|
data,
|
|
710
646
|
abortSignal,
|
|
711
647
|
stream,
|
|
712
|
-
requestType = import_runtime_client_gql2.CopilotRequestType.Task
|
|
713
|
-
forwardedParameters
|
|
648
|
+
requestType = import_runtime_client_gql2.CopilotRequestType.Task
|
|
714
649
|
}) {
|
|
715
650
|
var _a, _b;
|
|
716
651
|
const { messages } = context;
|
|
@@ -757,10 +692,10 @@ function extract(_0) {
|
|
|
757
692
|
metadata: {
|
|
758
693
|
requestType
|
|
759
694
|
},
|
|
760
|
-
forwardedParameters:
|
|
695
|
+
forwardedParameters: {
|
|
761
696
|
toolChoice: "function",
|
|
762
697
|
toolChoiceFunctionName: action.name
|
|
763
|
-
}
|
|
698
|
+
}
|
|
764
699
|
},
|
|
765
700
|
properties: context.copilotApiConfig.properties,
|
|
766
701
|
signal: abortSignal
|
|
@@ -844,41 +779,13 @@ function getHostname() {
|
|
|
844
779
|
return "";
|
|
845
780
|
}
|
|
846
781
|
|
|
847
|
-
// src/components/error-boundary/error-boundary.tsx
|
|
848
|
-
var import_react9 = __toESM(require("react"));
|
|
849
|
-
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
850
|
-
var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
851
|
-
constructor(props) {
|
|
852
|
-
super(props);
|
|
853
|
-
this.state = { hasError: false };
|
|
854
|
-
}
|
|
855
|
-
static getDerivedStateFromError(error) {
|
|
856
|
-
return { hasError: true, error };
|
|
857
|
-
}
|
|
858
|
-
componentDidCatch(error, errorInfo) {
|
|
859
|
-
console.error("CopilotKit Error:", error, errorInfo);
|
|
860
|
-
}
|
|
861
|
-
render() {
|
|
862
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ErrorToast2, { error: this.state.error, children: this.props.children });
|
|
863
|
-
}
|
|
864
|
-
};
|
|
865
|
-
function ErrorToast2({ error, children }) {
|
|
866
|
-
const addErrorToast = useErrorToast();
|
|
867
|
-
(0, import_react9.useEffect)(() => {
|
|
868
|
-
if (error) {
|
|
869
|
-
addErrorToast([error]);
|
|
870
|
-
}
|
|
871
|
-
}, [error, addErrorToast]);
|
|
872
|
-
return children;
|
|
873
|
-
}
|
|
874
|
-
|
|
875
782
|
// src/components/copilot-provider/copilotkit.tsx
|
|
876
|
-
var
|
|
783
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
877
784
|
function CopilotKit(_a) {
|
|
878
785
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
879
786
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
880
787
|
const enabled = shouldShowDevConsole(showDevConsole);
|
|
881
|
-
return /* @__PURE__ */ (0,
|
|
788
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ToastProvider, { enabled, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotKitInternal, __spreadProps(__spreadValues({}, props), { children })) });
|
|
882
789
|
}
|
|
883
790
|
function CopilotKitInternal(_a) {
|
|
884
791
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
@@ -888,49 +795,49 @@ function CopilotKitInternal(_a) {
|
|
|
888
795
|
);
|
|
889
796
|
}
|
|
890
797
|
const chatApiEndpoint = props.runtimeUrl || import_shared4.COPILOT_CLOUD_CHAT_URL;
|
|
891
|
-
const [actions, setActions] = (0,
|
|
892
|
-
const [coAgentStateRenders, setCoAgentStateRenders] = (0,
|
|
893
|
-
const chatComponentsCache = (0,
|
|
798
|
+
const [actions, setActions] = (0, import_react8.useState)({});
|
|
799
|
+
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react8.useState)({});
|
|
800
|
+
const chatComponentsCache = (0, import_react8.useRef)({
|
|
894
801
|
actions: {},
|
|
895
802
|
coAgentStateRenders: {}
|
|
896
803
|
});
|
|
897
804
|
const { addElement, removeElement, printTree } = use_tree_default();
|
|
898
|
-
const [isLoading, setIsLoading] = (0,
|
|
899
|
-
const [chatInstructions, setChatInstructions] = (0,
|
|
805
|
+
const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
|
|
806
|
+
const [chatInstructions, setChatInstructions] = (0, import_react8.useState)("");
|
|
900
807
|
const {
|
|
901
808
|
addElement: addDocument,
|
|
902
809
|
removeElement: removeDocument,
|
|
903
810
|
allElements: allDocuments
|
|
904
811
|
} = use_flat_category_store_default();
|
|
905
|
-
const setAction = (0,
|
|
812
|
+
const setAction = (0, import_react8.useCallback)((id, action) => {
|
|
906
813
|
setActions((prevPoints) => {
|
|
907
814
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
908
815
|
[id]: action
|
|
909
816
|
});
|
|
910
817
|
});
|
|
911
818
|
}, []);
|
|
912
|
-
const removeAction = (0,
|
|
819
|
+
const removeAction = (0, import_react8.useCallback)((id) => {
|
|
913
820
|
setActions((prevPoints) => {
|
|
914
821
|
const newPoints = __spreadValues({}, prevPoints);
|
|
915
822
|
delete newPoints[id];
|
|
916
823
|
return newPoints;
|
|
917
824
|
});
|
|
918
825
|
}, []);
|
|
919
|
-
const setCoAgentStateRender = (0,
|
|
826
|
+
const setCoAgentStateRender = (0, import_react8.useCallback)((id, stateRender) => {
|
|
920
827
|
setCoAgentStateRenders((prevPoints) => {
|
|
921
828
|
return __spreadProps(__spreadValues({}, prevPoints), {
|
|
922
829
|
[id]: stateRender
|
|
923
830
|
});
|
|
924
831
|
});
|
|
925
832
|
}, []);
|
|
926
|
-
const removeCoAgentStateRender = (0,
|
|
833
|
+
const removeCoAgentStateRender = (0, import_react8.useCallback)((id) => {
|
|
927
834
|
setCoAgentStateRenders((prevPoints) => {
|
|
928
835
|
const newPoints = __spreadValues({}, prevPoints);
|
|
929
836
|
delete newPoints[id];
|
|
930
837
|
return newPoints;
|
|
931
838
|
});
|
|
932
839
|
}, []);
|
|
933
|
-
const getContextString = (0,
|
|
840
|
+
const getContextString = (0, import_react8.useCallback)(
|
|
934
841
|
(documents, categories) => {
|
|
935
842
|
const documentsString = documents.map((document) => {
|
|
936
843
|
return `${document.name} (${document.sourceApplication}):
|
|
@@ -943,37 +850,37 @@ ${nonDocumentStrings}`;
|
|
|
943
850
|
},
|
|
944
851
|
[printTree]
|
|
945
852
|
);
|
|
946
|
-
const addContext = (0,
|
|
853
|
+
const addContext = (0, import_react8.useCallback)(
|
|
947
854
|
(context, parentId, categories = defaultCopilotContextCategories) => {
|
|
948
855
|
return addElement(context, categories, parentId);
|
|
949
856
|
},
|
|
950
857
|
[addElement]
|
|
951
858
|
);
|
|
952
|
-
const removeContext = (0,
|
|
859
|
+
const removeContext = (0, import_react8.useCallback)(
|
|
953
860
|
(id) => {
|
|
954
861
|
removeElement(id);
|
|
955
862
|
},
|
|
956
863
|
[removeElement]
|
|
957
864
|
);
|
|
958
|
-
const getFunctionCallHandler = (0,
|
|
865
|
+
const getFunctionCallHandler = (0, import_react8.useCallback)(
|
|
959
866
|
(customEntryPoints) => {
|
|
960
867
|
return entryPointsToFunctionCallHandler(Object.values(customEntryPoints || actions));
|
|
961
868
|
},
|
|
962
869
|
[actions]
|
|
963
870
|
);
|
|
964
|
-
const getDocumentsContext = (0,
|
|
871
|
+
const getDocumentsContext = (0, import_react8.useCallback)(
|
|
965
872
|
(categories) => {
|
|
966
873
|
return allDocuments(categories);
|
|
967
874
|
},
|
|
968
875
|
[allDocuments]
|
|
969
876
|
);
|
|
970
|
-
const addDocumentContext = (0,
|
|
877
|
+
const addDocumentContext = (0, import_react8.useCallback)(
|
|
971
878
|
(documentPointer, categories = defaultCopilotContextCategories) => {
|
|
972
879
|
return addDocument(documentPointer, categories);
|
|
973
880
|
},
|
|
974
881
|
[addDocument]
|
|
975
882
|
);
|
|
976
|
-
const removeDocumentContext = (0,
|
|
883
|
+
const removeDocumentContext = (0, import_react8.useCallback)(
|
|
977
884
|
(documentId) => {
|
|
978
885
|
removeDocument(documentId);
|
|
979
886
|
},
|
|
@@ -986,7 +893,7 @@ ${nonDocumentStrings}`;
|
|
|
986
893
|
);
|
|
987
894
|
}
|
|
988
895
|
}
|
|
989
|
-
const copilotApiConfig = (0,
|
|
896
|
+
const copilotApiConfig = (0, import_react8.useMemo)(() => {
|
|
990
897
|
var _a2, _b2;
|
|
991
898
|
let cloud = void 0;
|
|
992
899
|
if (props.publicApiKey) {
|
|
@@ -1028,7 +935,7 @@ ${nonDocumentStrings}`;
|
|
|
1028
935
|
headers,
|
|
1029
936
|
credentials: copilotApiConfig.credentials
|
|
1030
937
|
});
|
|
1031
|
-
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0,
|
|
938
|
+
const [chatSuggestionConfiguration, setChatSuggestionConfiguration] = (0, import_react8.useState)({});
|
|
1032
939
|
const addChatSuggestionConfiguration = (id, suggestion) => {
|
|
1033
940
|
setChatSuggestionConfiguration((prev) => __spreadProps(__spreadValues({}, prev), { [id]: suggestion }));
|
|
1034
941
|
};
|
|
@@ -1038,30 +945,16 @@ ${nonDocumentStrings}`;
|
|
|
1038
945
|
return rest;
|
|
1039
946
|
});
|
|
1040
947
|
};
|
|
1041
|
-
const [coagentStates, setCoagentStates] = (0,
|
|
1042
|
-
const coagentStatesRef = (0, import_react10.useRef)({});
|
|
1043
|
-
const setCoagentStatesWithRef = (0, import_react10.useCallback)(
|
|
1044
|
-
(value) => {
|
|
1045
|
-
const newValue = typeof value === "function" ? value(coagentStatesRef.current) : value;
|
|
1046
|
-
coagentStatesRef.current = newValue;
|
|
1047
|
-
setCoagentStates((prev) => {
|
|
1048
|
-
return newValue;
|
|
1049
|
-
});
|
|
1050
|
-
},
|
|
1051
|
-
[]
|
|
1052
|
-
);
|
|
948
|
+
const [coagentStates, setCoagentStates] = (0, import_react8.useState)({});
|
|
1053
949
|
let initialAgentSession = null;
|
|
1054
950
|
if (props.agent) {
|
|
1055
951
|
initialAgentSession = {
|
|
1056
952
|
agentName: props.agent
|
|
1057
953
|
};
|
|
1058
954
|
}
|
|
1059
|
-
const [agentSession, setAgentSession] = (0,
|
|
1060
|
-
const [threadId, setThreadId] = (0, import_react10.useState)(null);
|
|
1061
|
-
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
1062
|
-
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
955
|
+
const [agentSession, setAgentSession] = (0, import_react8.useState)(initialAgentSession);
|
|
1063
956
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
1064
|
-
return /* @__PURE__ */ (0,
|
|
957
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
1065
958
|
CopilotContext.Provider,
|
|
1066
959
|
{
|
|
1067
960
|
value: {
|
|
@@ -1090,20 +983,11 @@ ${nonDocumentStrings}`;
|
|
|
1090
983
|
showDevConsole,
|
|
1091
984
|
coagentStates,
|
|
1092
985
|
setCoagentStates,
|
|
1093
|
-
coagentStatesRef,
|
|
1094
|
-
setCoagentStatesWithRef,
|
|
1095
986
|
agentSession,
|
|
1096
987
|
setAgentSession,
|
|
1097
|
-
runtimeClient
|
|
1098
|
-
forwardedParameters: props.forwardedParameters || {},
|
|
1099
|
-
agentLock: props.agent || null,
|
|
1100
|
-
threadId,
|
|
1101
|
-
setThreadId,
|
|
1102
|
-
runId,
|
|
1103
|
-
setRunId,
|
|
1104
|
-
chatAbortControllerRef
|
|
988
|
+
runtimeClient
|
|
1105
989
|
},
|
|
1106
|
-
children: /* @__PURE__ */ (0,
|
|
990
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CopilotMessages, { children })
|
|
1107
991
|
}
|
|
1108
992
|
);
|
|
1109
993
|
}
|
|
@@ -1135,40 +1019,13 @@ function entryPointsToFunctionCallHandler(actions) {
|
|
|
1135
1019
|
}
|
|
1136
1020
|
|
|
1137
1021
|
// src/hooks/use-copilot-chat.ts
|
|
1138
|
-
var
|
|
1139
|
-
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1140
|
-
|
|
1141
|
-
// src/hooks/use-chat.ts
|
|
1142
|
-
var import_react11 = require("react");
|
|
1143
|
-
var import_shared6 = require("@copilotkit/shared");
|
|
1022
|
+
var import_react10 = require("react");
|
|
1144
1023
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1145
1024
|
|
|
1146
|
-
// src/types/frontend-action.ts
|
|
1147
|
-
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1148
|
-
var import_shared5 = require("@copilotkit/shared");
|
|
1149
|
-
function processActionsForRuntimeRequest(actions) {
|
|
1150
|
-
const filteredActions = actions.filter(
|
|
1151
|
-
(action) => action.available !== import_runtime_client_gql4.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
|
|
1152
|
-
).map((action) => {
|
|
1153
|
-
let available = import_runtime_client_gql4.ActionInputAvailability.Enabled;
|
|
1154
|
-
if (action.disabled) {
|
|
1155
|
-
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
1156
|
-
} else if (action.available === "disabled") {
|
|
1157
|
-
available = import_runtime_client_gql4.ActionInputAvailability.Disabled;
|
|
1158
|
-
} else if (action.available === "remote") {
|
|
1159
|
-
available = import_runtime_client_gql4.ActionInputAvailability.Remote;
|
|
1160
|
-
}
|
|
1161
|
-
return {
|
|
1162
|
-
name: action.name,
|
|
1163
|
-
description: action.description || "",
|
|
1164
|
-
jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || [])),
|
|
1165
|
-
available
|
|
1166
|
-
};
|
|
1167
|
-
});
|
|
1168
|
-
return filteredActions;
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
1025
|
// src/hooks/use-chat.ts
|
|
1026
|
+
var import_react9 = require("react");
|
|
1027
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1028
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1172
1029
|
function useChat(options) {
|
|
1173
1030
|
const {
|
|
1174
1031
|
messages,
|
|
@@ -1181,309 +1038,232 @@ function useChat(options) {
|
|
|
1181
1038
|
actions,
|
|
1182
1039
|
onFunctionCall,
|
|
1183
1040
|
onCoAgentStateRender,
|
|
1184
|
-
|
|
1185
|
-
|
|
1041
|
+
setCoagentStates,
|
|
1042
|
+
coagentStates,
|
|
1186
1043
|
agentSession,
|
|
1187
|
-
setAgentSession
|
|
1188
|
-
threadId,
|
|
1189
|
-
setThreadId,
|
|
1190
|
-
runId,
|
|
1191
|
-
setRunId,
|
|
1192
|
-
chatAbortControllerRef
|
|
1044
|
+
setAgentSession
|
|
1193
1045
|
} = options;
|
|
1046
|
+
const abortControllerRef = (0, import_react9.useRef)();
|
|
1047
|
+
const threadIdRef = (0, import_react9.useRef)(null);
|
|
1048
|
+
const runIdRef = (0, import_react9.useRef)(null);
|
|
1194
1049
|
const { addGraphQLErrorsToast } = useToast();
|
|
1195
|
-
const runChatCompletionRef = (0,
|
|
1196
|
-
const
|
|
1050
|
+
const runChatCompletionRef = (0, import_react9.useRef)();
|
|
1051
|
+
const coagentStatesRef = (0, import_react9.useRef)(coagentStates);
|
|
1052
|
+
coagentStatesRef.current = coagentStates;
|
|
1053
|
+
const agentSessionRef = (0, import_react9.useRef)(agentSession);
|
|
1197
1054
|
agentSessionRef.current = agentSession;
|
|
1198
|
-
const threadIdRef = (0, import_react11.useRef)(threadId);
|
|
1199
|
-
threadIdRef.current = threadId;
|
|
1200
|
-
const runIdRef = (0, import_react11.useRef)(runId);
|
|
1201
|
-
runIdRef.current = runId;
|
|
1202
1055
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
1203
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [
|
|
1056
|
+
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared5.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1204
1057
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1205
1058
|
url: copilotConfig.chatApiEndpoint,
|
|
1206
1059
|
publicApiKey: copilotConfig.publicApiKey,
|
|
1207
1060
|
headers,
|
|
1208
1061
|
credentials: copilotConfig.credentials
|
|
1209
1062
|
});
|
|
1210
|
-
const runChatCompletion =
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1063
|
+
const runChatCompletion = (previousMessages) => __async(this, null, function* () {
|
|
1064
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1065
|
+
setIsLoading(true);
|
|
1066
|
+
let newMessages = [
|
|
1067
|
+
new import_runtime_client_gql4.TextMessage({
|
|
1068
|
+
content: "",
|
|
1069
|
+
role: import_runtime_client_gql4.Role.Assistant
|
|
1070
|
+
})
|
|
1071
|
+
];
|
|
1072
|
+
const abortController = new AbortController();
|
|
1073
|
+
abortControllerRef.current = abortController;
|
|
1074
|
+
setMessages([...previousMessages, ...newMessages]);
|
|
1075
|
+
const systemMessage = makeSystemMessageCallback();
|
|
1076
|
+
const messagesWithContext = [systemMessage, ...initialMessages || [], ...previousMessages];
|
|
1077
|
+
const stream = runtimeClient.asStream(
|
|
1078
|
+
runtimeClient.generateCopilotResponse({
|
|
1079
|
+
data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({
|
|
1080
|
+
frontend: {
|
|
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
|
+
}),
|
|
1099
|
+
url: window.location.href
|
|
1100
|
+
},
|
|
1101
|
+
threadId: threadIdRef.current,
|
|
1102
|
+
runId: runIdRef.current,
|
|
1103
|
+
messages: (0, import_runtime_client_gql4.convertMessagesToGqlInput)((0, import_runtime_client_gql4.filterAgentStateMessages)(messagesWithContext))
|
|
1104
|
+
}, copilotConfig.cloud ? {
|
|
1105
|
+
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
1106
|
+
guardrails: {
|
|
1107
|
+
inputValidationRules: {
|
|
1108
|
+
allowList: copilotConfig.cloud.guardrails.input.restrictToTopic.validTopics,
|
|
1109
|
+
denyList: copilotConfig.cloud.guardrails.input.restrictToTopic.invalidTopics
|
|
1242
1110
|
}
|
|
1243
|
-
} : {})
|
|
1244
|
-
} : {}), {
|
|
1245
|
-
metadata: {
|
|
1246
|
-
requestType: import_runtime_client_gql5.CopilotRequestType.Chat
|
|
1247
|
-
}
|
|
1248
|
-
}), agentSessionRef.current ? {
|
|
1249
|
-
agentSession: agentSessionRef.current
|
|
1250
|
-
} : {}), {
|
|
1251
|
-
agentStates: Object.values(coagentStatesRef.current).map((state) => ({
|
|
1252
|
-
agentName: state.name,
|
|
1253
|
-
state: JSON.stringify(state.state)
|
|
1254
|
-
})),
|
|
1255
|
-
forwardedParameters: options.forwardedParameters || {}
|
|
1256
|
-
}),
|
|
1257
|
-
properties: copilotConfig.properties,
|
|
1258
|
-
signal: (_d = chatAbortControllerRef.current) == null ? void 0 : _d.signal
|
|
1259
|
-
})
|
|
1260
|
-
);
|
|
1261
|
-
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
1262
|
-
const reader = stream.getReader();
|
|
1263
|
-
let executedCoAgentStateRenders = [];
|
|
1264
|
-
let followUp = void 0;
|
|
1265
|
-
let messages2 = [];
|
|
1266
|
-
let syncedMessages = [];
|
|
1267
|
-
try {
|
|
1268
|
-
while (true) {
|
|
1269
|
-
let done, value;
|
|
1270
|
-
try {
|
|
1271
|
-
const readResult = yield reader.read();
|
|
1272
|
-
done = readResult.done;
|
|
1273
|
-
value = readResult.value;
|
|
1274
|
-
} catch (readError) {
|
|
1275
|
-
break;
|
|
1276
|
-
}
|
|
1277
|
-
if (done) {
|
|
1278
|
-
if (chatAbortControllerRef.current.signal.aborted) {
|
|
1279
|
-
return [];
|
|
1280
1111
|
}
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
}
|
|
1286
|
-
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
1287
|
-
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
1288
|
-
setThreadId(threadIdRef.current);
|
|
1289
|
-
setRunId(runIdRef.current);
|
|
1290
|
-
messages2 = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
|
|
1291
|
-
(0, import_runtime_client_gql5.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
1292
|
-
);
|
|
1293
|
-
if (messages2.length === 0) {
|
|
1294
|
-
continue;
|
|
1112
|
+
} : {})
|
|
1113
|
+
} : {}), {
|
|
1114
|
+
metadata: {
|
|
1115
|
+
requestType: import_runtime_client_gql4.CopilotRequestType.Chat
|
|
1295
1116
|
}
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1117
|
+
}), agentSessionRef.current ? {
|
|
1118
|
+
agentSession: agentSessionRef.current
|
|
1119
|
+
} : {}), {
|
|
1120
|
+
agentStates: Object.values(coagentStatesRef.current).map((state) => ({
|
|
1121
|
+
agentName: state.name,
|
|
1122
|
+
state: JSON.stringify(state.state)
|
|
1123
|
+
}))
|
|
1124
|
+
}),
|
|
1125
|
+
properties: copilotConfig.properties,
|
|
1126
|
+
signal: (_d = abortControllerRef.current) == null ? void 0 : _d.signal
|
|
1127
|
+
})
|
|
1128
|
+
);
|
|
1129
|
+
const guardrailsEnabled = ((_g = (_f = (_e = copilotConfig.cloud) == null ? void 0 : _e.guardrails) == null ? void 0 : _f.input) == null ? void 0 : _g.restrictToTopic.enabled) || false;
|
|
1130
|
+
const reader = stream.getReader();
|
|
1131
|
+
let actionResults = {};
|
|
1132
|
+
let executedCoAgentStateRenders = [];
|
|
1133
|
+
let followUp = void 0;
|
|
1134
|
+
try {
|
|
1135
|
+
while (true) {
|
|
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
|
+
}
|
|
1144
|
+
if (done) {
|
|
1145
|
+
break;
|
|
1146
|
+
}
|
|
1147
|
+
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
1148
|
+
continue;
|
|
1149
|
+
}
|
|
1150
|
+
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
1151
|
+
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
1152
|
+
const messages2 = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1153
|
+
(0, import_runtime_client_gql4.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
1154
|
+
);
|
|
1155
|
+
if (messages2.length === 0) {
|
|
1156
|
+
continue;
|
|
1157
|
+
}
|
|
1158
|
+
newMessages = [];
|
|
1159
|
+
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
1160
|
+
newMessages = [
|
|
1161
|
+
new import_runtime_client_gql4.TextMessage({
|
|
1162
|
+
role: import_runtime_client_gql4.MessageRole.Assistant,
|
|
1163
|
+
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
1164
|
+
})
|
|
1165
|
+
];
|
|
1166
|
+
} else {
|
|
1167
|
+
for (const message of messages2) {
|
|
1168
|
+
newMessages.push(message);
|
|
1169
|
+
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql4.MessageStatusCode.Pending && message.scope === "client" && onFunctionCall) {
|
|
1170
|
+
if (!(message.id in actionResults)) {
|
|
1310
1171
|
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
1311
1172
|
break;
|
|
1312
1173
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
}
|
|
1321
|
-
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
1322
|
-
if (lastAgentStateMessage) {
|
|
1323
|
-
if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
|
|
1324
|
-
syncedMessages = (0, import_runtime_client_gql5.loadMessagesFromJsonRepresentation)(
|
|
1325
|
-
lastAgentStateMessage.state.messages
|
|
1326
|
-
);
|
|
1327
|
-
}
|
|
1328
|
-
setCoagentStatesWithRef((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1329
|
-
[lastAgentStateMessage.agentName]: {
|
|
1330
|
-
name: lastAgentStateMessage.agentName,
|
|
1331
|
-
state: lastAgentStateMessage.state,
|
|
1332
|
-
running: lastAgentStateMessage.running,
|
|
1333
|
-
active: lastAgentStateMessage.active,
|
|
1334
|
-
threadId: lastAgentStateMessage.threadId,
|
|
1335
|
-
nodeName: lastAgentStateMessage.nodeName,
|
|
1336
|
-
runId: lastAgentStateMessage.runId
|
|
1337
|
-
}
|
|
1338
|
-
}));
|
|
1339
|
-
if (lastAgentStateMessage.running) {
|
|
1340
|
-
setAgentSession({
|
|
1341
|
-
threadId: lastAgentStateMessage.threadId,
|
|
1342
|
-
agentName: lastAgentStateMessage.agentName,
|
|
1343
|
-
nodeName: lastAgentStateMessage.nodeName
|
|
1344
|
-
});
|
|
1345
|
-
} else {
|
|
1346
|
-
setAgentSession(null);
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
if (newMessages.length > 0) {
|
|
1351
|
-
setMessages([...previousMessages, ...newMessages]);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
const finalMessages = constructFinalMessages(syncedMessages, previousMessages, newMessages);
|
|
1355
|
-
let didExecuteAction = false;
|
|
1356
|
-
if (onFunctionCall) {
|
|
1357
|
-
const lastMessages = [];
|
|
1358
|
-
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
1359
|
-
const message = finalMessages[i];
|
|
1360
|
-
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql5.MessageStatusCode.Pending) {
|
|
1361
|
-
lastMessages.unshift(message);
|
|
1362
|
-
} else {
|
|
1363
|
-
break;
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
for (const message of lastMessages) {
|
|
1367
|
-
setMessages(finalMessages);
|
|
1368
|
-
const action = actions.find((action2) => action2.name === message.name);
|
|
1369
|
-
if (action) {
|
|
1370
|
-
followUp = action.followUp;
|
|
1371
|
-
let result;
|
|
1372
|
-
try {
|
|
1373
|
-
result = yield Promise.race([
|
|
1374
|
-
onFunctionCall({
|
|
1174
|
+
try {
|
|
1175
|
+
setMessages([...previousMessages, ...newMessages]);
|
|
1176
|
+
const action = actions.find((action2) => action2.name === message.name);
|
|
1177
|
+
if (action) {
|
|
1178
|
+
followUp = action.followUp;
|
|
1179
|
+
}
|
|
1180
|
+
const result = yield onFunctionCall({
|
|
1375
1181
|
messages: previousMessages,
|
|
1376
1182
|
name: message.name,
|
|
1377
1183
|
args: message.arguments
|
|
1378
|
-
})
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
() => resolve("Operation was aborted by the user")
|
|
1385
|
-
);
|
|
1386
|
-
}
|
|
1387
|
-
),
|
|
1388
|
-
// if the user stopped generation, we also abort consecutive actions
|
|
1389
|
-
new Promise((resolve) => {
|
|
1390
|
-
var _a2;
|
|
1391
|
-
if ((_a2 = chatAbortControllerRef.current) == null ? void 0 : _a2.signal.aborted) {
|
|
1392
|
-
resolve("Operation was aborted by the user");
|
|
1393
|
-
}
|
|
1394
|
-
})
|
|
1395
|
-
]);
|
|
1396
|
-
} catch (e) {
|
|
1397
|
-
result = `Failed to execute action ${message.name}`;
|
|
1398
|
-
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
1184
|
+
});
|
|
1185
|
+
actionResults[message.id] = result;
|
|
1186
|
+
} catch (e) {
|
|
1187
|
+
actionResults[message.id] = `Failed to execute action ${message.name}`;
|
|
1188
|
+
console.error(`Failed to execute action ${message.name}: ${e}`);
|
|
1189
|
+
}
|
|
1399
1190
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
messageIndex + 1,
|
|
1404
|
-
0,
|
|
1405
|
-
new import_runtime_client_gql5.ResultMessage({
|
|
1406
|
-
id: "result-" + message.id,
|
|
1407
|
-
result: import_runtime_client_gql5.ResultMessage.encodeResult(result),
|
|
1191
|
+
newMessages.push(
|
|
1192
|
+
new import_runtime_client_gql4.ResultMessage({
|
|
1193
|
+
result: import_runtime_client_gql4.ResultMessage.encodeResult(actionResults[message.id]),
|
|
1408
1194
|
actionExecutionId: message.id,
|
|
1409
1195
|
actionName: message.name
|
|
1410
1196
|
})
|
|
1411
1197
|
);
|
|
1412
1198
|
}
|
|
1199
|
+
if (message.isAgentStateMessage() && !message.active && !executedCoAgentStateRenders.includes(message.id) && onCoAgentStateRender) {
|
|
1200
|
+
if (guardrailsEnabled && value.generateCopilotResponse.status === void 0) {
|
|
1201
|
+
break;
|
|
1202
|
+
}
|
|
1203
|
+
yield onCoAgentStateRender({
|
|
1204
|
+
name: message.agentName,
|
|
1205
|
+
nodeName: message.nodeName,
|
|
1206
|
+
state: message.state
|
|
1207
|
+
});
|
|
1208
|
+
executedCoAgentStateRenders.push(message.id);
|
|
1209
|
+
}
|
|
1413
1210
|
}
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
if (
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1211
|
+
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
1212
|
+
if (lastAgentStateMessage) {
|
|
1213
|
+
setCoagentStates((prevAgentStates) => __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1214
|
+
[lastAgentStateMessage.agentName]: {
|
|
1215
|
+
name: lastAgentStateMessage.agentName,
|
|
1216
|
+
state: lastAgentStateMessage.state,
|
|
1217
|
+
running: lastAgentStateMessage.running,
|
|
1218
|
+
active: lastAgentStateMessage.active,
|
|
1219
|
+
threadId: lastAgentStateMessage.threadId,
|
|
1220
|
+
nodeName: lastAgentStateMessage.nodeName,
|
|
1221
|
+
runId: lastAgentStateMessage.runId
|
|
1222
|
+
}
|
|
1223
|
+
}));
|
|
1224
|
+
if (lastAgentStateMessage.running) {
|
|
1225
|
+
setAgentSession({
|
|
1226
|
+
threadId: lastAgentStateMessage.threadId,
|
|
1227
|
+
agentName: lastAgentStateMessage.agentName,
|
|
1228
|
+
nodeName: lastAgentStateMessage.nodeName
|
|
1229
|
+
});
|
|
1230
|
+
} else {
|
|
1231
|
+
setAgentSession(null);
|
|
1431
1232
|
}
|
|
1432
|
-
return true;
|
|
1433
|
-
});
|
|
1434
|
-
const repairedMessageIds = repairedMessages.map((message) => message.id);
|
|
1435
|
-
setMessages(repairedMessages);
|
|
1436
|
-
if ((_l = agentSessionRef.current) == null ? void 0 : _l.nodeName) {
|
|
1437
|
-
setAgentSession({
|
|
1438
|
-
threadId: agentSessionRef.current.threadId,
|
|
1439
|
-
agentName: agentSessionRef.current.agentName,
|
|
1440
|
-
nodeName: "__end__"
|
|
1441
|
-
});
|
|
1442
1233
|
}
|
|
1443
|
-
return newMessages.filter((message) => repairedMessageIds.includes(message.id));
|
|
1444
|
-
} else {
|
|
1445
|
-
return newMessages.slice();
|
|
1446
1234
|
}
|
|
1447
|
-
|
|
1448
|
-
|
|
1235
|
+
if (newMessages.length > 0) {
|
|
1236
|
+
setMessages([...previousMessages, ...newMessages]);
|
|
1237
|
+
}
|
|
1449
1238
|
}
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
onFunctionCall,
|
|
1461
|
-
onCoAgentStateRender,
|
|
1462
|
-
setCoagentStatesWithRef,
|
|
1463
|
-
coagentStatesRef,
|
|
1464
|
-
agentSession,
|
|
1465
|
-
setAgentSession
|
|
1466
|
-
]
|
|
1467
|
-
);
|
|
1468
|
-
runChatCompletionRef.current = runChatCompletion;
|
|
1469
|
-
const runChatCompletionAndHandleFunctionCall = useAsyncCallback(
|
|
1470
|
-
(messages2) => __async(this, null, function* () {
|
|
1471
|
-
yield runChatCompletionRef.current(messages2);
|
|
1472
|
-
}),
|
|
1473
|
-
[messages]
|
|
1474
|
-
);
|
|
1475
|
-
const append = useAsyncCallback(
|
|
1476
|
-
(message) => __async(this, null, function* () {
|
|
1477
|
-
if (isLoading) {
|
|
1478
|
-
return;
|
|
1239
|
+
if (
|
|
1240
|
+
// if followUp is not explicitly false
|
|
1241
|
+
followUp !== false && // if we have client side results
|
|
1242
|
+
(Object.values(actionResults).length || // or the last message we received is a result
|
|
1243
|
+
newMessages.length && newMessages[newMessages.length - 1].isResultMessage())
|
|
1244
|
+
) {
|
|
1245
|
+
yield new Promise((resolve) => setTimeout(resolve, 10));
|
|
1246
|
+
return yield runChatCompletionRef.current([...previousMessages, ...newMessages]);
|
|
1247
|
+
} else {
|
|
1248
|
+
return newMessages.slice();
|
|
1479
1249
|
}
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
)
|
|
1486
|
-
|
|
1250
|
+
} finally {
|
|
1251
|
+
setIsLoading(false);
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
runChatCompletionRef.current = runChatCompletion;
|
|
1255
|
+
const runChatCompletionAndHandleFunctionCall = (messages2) => __async(this, null, function* () {
|
|
1256
|
+
yield runChatCompletionRef.current(messages2);
|
|
1257
|
+
});
|
|
1258
|
+
const append = (message) => __async(this, null, function* () {
|
|
1259
|
+
if (isLoading) {
|
|
1260
|
+
return;
|
|
1261
|
+
}
|
|
1262
|
+
const newMessages = [...messages, message];
|
|
1263
|
+
setMessages(newMessages);
|
|
1264
|
+
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
1265
|
+
});
|
|
1266
|
+
const reload = () => __async(this, null, function* () {
|
|
1487
1267
|
if (isLoading || messages.length === 0) {
|
|
1488
1268
|
return;
|
|
1489
1269
|
}
|
|
@@ -1494,35 +1274,17 @@ function useChat(options) {
|
|
|
1494
1274
|
}
|
|
1495
1275
|
setMessages(newMessages);
|
|
1496
1276
|
return runChatCompletionAndHandleFunctionCall(newMessages);
|
|
1497
|
-
})
|
|
1277
|
+
});
|
|
1498
1278
|
const stop = () => {
|
|
1499
1279
|
var _a;
|
|
1500
|
-
(_a =
|
|
1280
|
+
(_a = abortControllerRef.current) == null ? void 0 : _a.abort();
|
|
1501
1281
|
};
|
|
1502
1282
|
return {
|
|
1503
1283
|
append,
|
|
1504
1284
|
reload,
|
|
1505
|
-
stop
|
|
1506
|
-
runChatCompletion: () => runChatCompletionRef.current(messages)
|
|
1285
|
+
stop
|
|
1507
1286
|
};
|
|
1508
1287
|
}
|
|
1509
|
-
function constructFinalMessages(syncedMessages, previousMessages, newMessages) {
|
|
1510
|
-
const finalMessages = syncedMessages.length > 0 ? [...syncedMessages] : [...previousMessages, ...newMessages];
|
|
1511
|
-
if (syncedMessages.length > 0) {
|
|
1512
|
-
const messagesWithAgentState = [...previousMessages, ...newMessages];
|
|
1513
|
-
let previousMessageId = void 0;
|
|
1514
|
-
for (const message of messagesWithAgentState) {
|
|
1515
|
-
if (message.isAgentStateMessage()) {
|
|
1516
|
-
const index = finalMessages.findIndex((msg) => msg.id === previousMessageId);
|
|
1517
|
-
if (index !== -1) {
|
|
1518
|
-
finalMessages.splice(index + 1, 0, message);
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
previousMessageId = message.id;
|
|
1522
|
-
}
|
|
1523
|
-
}
|
|
1524
|
-
return finalMessages;
|
|
1525
|
-
}
|
|
1526
1288
|
|
|
1527
1289
|
// src/hooks/use-copilot-chat.ts
|
|
1528
1290
|
function useCopilotChat(_a = {}) {
|
|
@@ -1539,36 +1301,29 @@ function useCopilotChat(_a = {}) {
|
|
|
1539
1301
|
setIsLoading,
|
|
1540
1302
|
chatInstructions,
|
|
1541
1303
|
actions,
|
|
1542
|
-
|
|
1543
|
-
|
|
1304
|
+
coagentStates,
|
|
1305
|
+
setCoagentStates,
|
|
1544
1306
|
coAgentStateRenders,
|
|
1545
1307
|
agentSession,
|
|
1546
|
-
setAgentSession
|
|
1547
|
-
forwardedParameters,
|
|
1548
|
-
agentLock,
|
|
1549
|
-
threadId,
|
|
1550
|
-
setThreadId,
|
|
1551
|
-
runId,
|
|
1552
|
-
setRunId,
|
|
1553
|
-
chatAbortControllerRef
|
|
1308
|
+
setAgentSession
|
|
1554
1309
|
} = useCopilotContext();
|
|
1555
1310
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1556
1311
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
1557
|
-
const deleteMessage = (0,
|
|
1312
|
+
const deleteMessage = (0, import_react10.useCallback)(
|
|
1558
1313
|
(messageId) => {
|
|
1559
1314
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1560
1315
|
},
|
|
1561
1316
|
[setMessages]
|
|
1562
1317
|
);
|
|
1563
|
-
const makeSystemMessageCallback = (0,
|
|
1318
|
+
const makeSystemMessageCallback = (0, import_react10.useCallback)(() => {
|
|
1564
1319
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1565
1320
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
1566
|
-
return new
|
|
1321
|
+
return new import_runtime_client_gql5.TextMessage({
|
|
1567
1322
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1568
|
-
role:
|
|
1323
|
+
role: import_runtime_client_gql5.Role.System
|
|
1569
1324
|
});
|
|
1570
1325
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1571
|
-
const onCoAgentStateRender =
|
|
1326
|
+
const onCoAgentStateRender = (0, import_react10.useCallback)(
|
|
1572
1327
|
(args) => __async(this, null, function* () {
|
|
1573
1328
|
var _a2;
|
|
1574
1329
|
const { name, nodeName, state } = args;
|
|
@@ -1586,7 +1341,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1586
1341
|
}),
|
|
1587
1342
|
[coAgentStateRenders]
|
|
1588
1343
|
);
|
|
1589
|
-
const { append, reload, stop
|
|
1344
|
+
const { append, reload, stop } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1590
1345
|
actions: Object.values(actions),
|
|
1591
1346
|
copilotConfig: copilotApiConfig,
|
|
1592
1347
|
initialMessages: options.initialMessages || [],
|
|
@@ -1597,90 +1352,53 @@ function useCopilotChat(_a = {}) {
|
|
|
1597
1352
|
makeSystemMessageCallback,
|
|
1598
1353
|
isLoading,
|
|
1599
1354
|
setIsLoading,
|
|
1600
|
-
|
|
1601
|
-
|
|
1355
|
+
coagentStates,
|
|
1356
|
+
setCoagentStates,
|
|
1602
1357
|
agentSession,
|
|
1603
|
-
setAgentSession
|
|
1604
|
-
forwardedParameters,
|
|
1605
|
-
threadId,
|
|
1606
|
-
setThreadId,
|
|
1607
|
-
runId,
|
|
1608
|
-
setRunId,
|
|
1609
|
-
chatAbortControllerRef
|
|
1358
|
+
setAgentSession
|
|
1610
1359
|
}));
|
|
1611
1360
|
const latestAppend = useUpdatedRef(append);
|
|
1612
|
-
const latestAppendFunc =
|
|
1613
|
-
(message) =>
|
|
1614
|
-
return
|
|
1615
|
-
}
|
|
1361
|
+
const latestAppendFunc = (0, import_react10.useCallback)(
|
|
1362
|
+
(message) => {
|
|
1363
|
+
return latestAppend.current(message);
|
|
1364
|
+
},
|
|
1616
1365
|
[latestAppend]
|
|
1617
1366
|
);
|
|
1618
1367
|
const latestReload = useUpdatedRef(reload);
|
|
1619
|
-
const latestReloadFunc =
|
|
1620
|
-
return
|
|
1621
|
-
}
|
|
1368
|
+
const latestReloadFunc = (0, import_react10.useCallback)(() => {
|
|
1369
|
+
return latestReload.current();
|
|
1370
|
+
}, [latestReload]);
|
|
1622
1371
|
const latestStop = useUpdatedRef(stop);
|
|
1623
|
-
const latestStopFunc = (0,
|
|
1372
|
+
const latestStopFunc = (0, import_react10.useCallback)(() => {
|
|
1624
1373
|
return latestStop.current();
|
|
1625
1374
|
}, [latestStop]);
|
|
1626
1375
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1627
|
-
const latestDeleteFunc = (0,
|
|
1376
|
+
const latestDeleteFunc = (0, import_react10.useCallback)(
|
|
1628
1377
|
(messageId) => {
|
|
1629
1378
|
return latestDelete.current(messageId);
|
|
1630
1379
|
},
|
|
1631
1380
|
[latestDelete]
|
|
1632
1381
|
);
|
|
1633
1382
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1634
|
-
const latestSetMessagesFunc = (0,
|
|
1383
|
+
const latestSetMessagesFunc = (0, import_react10.useCallback)(
|
|
1635
1384
|
(messages2) => {
|
|
1636
1385
|
return latestSetMessages.current(messages2);
|
|
1637
1386
|
},
|
|
1638
1387
|
[latestSetMessages]
|
|
1639
1388
|
);
|
|
1640
|
-
const latestRunChatCompletion = useUpdatedRef(runChatCompletion);
|
|
1641
|
-
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1642
|
-
return yield latestRunChatCompletion.current();
|
|
1643
|
-
}), [latestRunChatCompletion]);
|
|
1644
|
-
const reset = (0, import_react12.useCallback)(() => {
|
|
1645
|
-
latestStopFunc();
|
|
1646
|
-
setMessages([]);
|
|
1647
|
-
setThreadId(null);
|
|
1648
|
-
setRunId(null);
|
|
1649
|
-
setCoagentStatesWithRef({});
|
|
1650
|
-
let initialAgentSession = null;
|
|
1651
|
-
if (agentLock) {
|
|
1652
|
-
initialAgentSession = {
|
|
1653
|
-
agentName: agentLock
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
setAgentSession(initialAgentSession);
|
|
1657
|
-
}, [
|
|
1658
|
-
latestStopFunc,
|
|
1659
|
-
setMessages,
|
|
1660
|
-
setThreadId,
|
|
1661
|
-
setCoagentStatesWithRef,
|
|
1662
|
-
setAgentSession,
|
|
1663
|
-
agentLock
|
|
1664
|
-
]);
|
|
1665
|
-
const latestReset = useUpdatedRef(reset);
|
|
1666
|
-
const latestResetFunc = (0, import_react12.useCallback)(() => {
|
|
1667
|
-
return latestReset.current();
|
|
1668
|
-
}, [latestReset]);
|
|
1669
1389
|
return {
|
|
1670
1390
|
visibleMessages: messages,
|
|
1671
1391
|
appendMessage: latestAppendFunc,
|
|
1672
1392
|
setMessages: latestSetMessagesFunc,
|
|
1673
1393
|
reloadMessages: latestReloadFunc,
|
|
1674
1394
|
stopGeneration: latestStopFunc,
|
|
1675
|
-
reset: latestResetFunc,
|
|
1676
1395
|
deleteMessage: latestDeleteFunc,
|
|
1677
|
-
runChatCompletion: latestRunChatCompletionFunc,
|
|
1678
1396
|
isLoading
|
|
1679
1397
|
};
|
|
1680
1398
|
}
|
|
1681
1399
|
function useUpdatedRef(value) {
|
|
1682
|
-
const ref = (0,
|
|
1683
|
-
(0,
|
|
1400
|
+
const ref = (0, import_react10.useRef)(value);
|
|
1401
|
+
(0, import_react10.useEffect)(() => {
|
|
1684
1402
|
ref.current = value;
|
|
1685
1403
|
}, [value]);
|
|
1686
1404
|
return ref;
|
|
@@ -1710,22 +1428,18 @@ ${additionalInstructions}` : "");
|
|
|
1710
1428
|
}
|
|
1711
1429
|
|
|
1712
1430
|
// src/hooks/use-copilot-action.ts
|
|
1713
|
-
var
|
|
1714
|
-
var
|
|
1431
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1432
|
+
var import_react11 = require("react");
|
|
1715
1433
|
function useCopilotAction(action, dependencies) {
|
|
1716
1434
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1717
|
-
const idRef = (0,
|
|
1718
|
-
const renderAndWaitRef = (0,
|
|
1435
|
+
const idRef = (0, import_react11.useRef)((0, import_shared6.randomId)());
|
|
1436
|
+
const renderAndWaitRef = (0, import_react11.useRef)(null);
|
|
1719
1437
|
action = __spreadValues({}, action);
|
|
1720
|
-
if (
|
|
1721
|
-
// renderAndWaitForResponse is not available for catch all actions
|
|
1722
|
-
isFrontendAction(action) && // check if renderAndWaitForResponse is set
|
|
1723
|
-
(action.renderAndWait || action.renderAndWaitForResponse)
|
|
1724
|
-
) {
|
|
1438
|
+
if (action.renderAndWait || action.renderAndWaitForResponse) {
|
|
1725
1439
|
const renderAndWait = action.renderAndWait || action.renderAndWaitForResponse;
|
|
1726
1440
|
action.renderAndWait = void 0;
|
|
1727
1441
|
action.renderAndWaitForResponse = void 0;
|
|
1728
|
-
action.handler =
|
|
1442
|
+
action.handler = () => __async(this, null, function* () {
|
|
1729
1443
|
let resolve;
|
|
1730
1444
|
let reject;
|
|
1731
1445
|
const promise = new Promise((resolvePromise, rejectPromise) => {
|
|
@@ -1734,18 +1448,14 @@ function useCopilotAction(action, dependencies) {
|
|
|
1734
1448
|
});
|
|
1735
1449
|
renderAndWaitRef.current = { promise, resolve, reject };
|
|
1736
1450
|
return yield promise;
|
|
1737
|
-
})
|
|
1451
|
+
});
|
|
1738
1452
|
action.render = (props) => {
|
|
1739
|
-
let status = props.status;
|
|
1740
|
-
if (props.status === "executing" && !renderAndWaitRef.current) {
|
|
1741
|
-
status = "inProgress";
|
|
1742
|
-
}
|
|
1743
1453
|
const waitProps = {
|
|
1744
|
-
status,
|
|
1454
|
+
status: props.status,
|
|
1745
1455
|
args: props.args,
|
|
1746
1456
|
result: props.result,
|
|
1747
|
-
handler: status === "executing" ? renderAndWaitRef.current.resolve : void 0,
|
|
1748
|
-
respond: status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
1457
|
+
handler: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0,
|
|
1458
|
+
respond: props.status === "executing" ? renderAndWaitRef.current.resolve : void 0
|
|
1749
1459
|
};
|
|
1750
1460
|
const isNoArgsRenderWait = (_fn) => {
|
|
1751
1461
|
var _a;
|
|
@@ -1758,14 +1468,12 @@ function useCopilotAction(action, dependencies) {
|
|
|
1758
1468
|
return renderAndWait(waitProps);
|
|
1759
1469
|
}
|
|
1760
1470
|
}
|
|
1761
|
-
return (0,
|
|
1471
|
+
return (0, import_react11.createElement)(import_react11.Fragment);
|
|
1762
1472
|
};
|
|
1763
1473
|
}
|
|
1764
1474
|
if (dependencies === void 0) {
|
|
1765
1475
|
if (actions[idRef.current]) {
|
|
1766
|
-
|
|
1767
|
-
actions[idRef.current].handler = action.handler;
|
|
1768
|
-
}
|
|
1476
|
+
actions[idRef.current].handler = action.handler;
|
|
1769
1477
|
if (typeof action.render === "function") {
|
|
1770
1478
|
if (chatComponentsCache.current !== null) {
|
|
1771
1479
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1773,7 +1481,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1773
1481
|
}
|
|
1774
1482
|
}
|
|
1775
1483
|
}
|
|
1776
|
-
(0,
|
|
1484
|
+
(0, import_react11.useEffect)(() => {
|
|
1777
1485
|
setAction(idRef.current, action);
|
|
1778
1486
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1779
1487
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1784,34 +1492,31 @@ function useCopilotAction(action, dependencies) {
|
|
|
1784
1492
|
}, [
|
|
1785
1493
|
setAction,
|
|
1786
1494
|
removeAction,
|
|
1787
|
-
|
|
1495
|
+
action.description,
|
|
1788
1496
|
action.name,
|
|
1789
|
-
|
|
1790
|
-
|
|
1497
|
+
action.disabled,
|
|
1498
|
+
action.available,
|
|
1791
1499
|
// This should be faster than deep equality checking
|
|
1792
1500
|
// In addition, all major JS engines guarantee the order of object keys
|
|
1793
|
-
JSON.stringify(
|
|
1501
|
+
JSON.stringify(action.parameters),
|
|
1794
1502
|
// include render only if it's a string
|
|
1795
1503
|
typeof action.render === "string" ? action.render : void 0,
|
|
1796
1504
|
// dependencies set by the developer
|
|
1797
1505
|
...dependencies || []
|
|
1798
1506
|
]);
|
|
1799
1507
|
}
|
|
1800
|
-
function isFrontendAction(action) {
|
|
1801
|
-
return action.name !== "*";
|
|
1802
|
-
}
|
|
1803
1508
|
|
|
1804
1509
|
// src/hooks/use-coagent-state-render.ts
|
|
1805
|
-
var
|
|
1806
|
-
var
|
|
1510
|
+
var import_react12 = require("react");
|
|
1511
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1807
1512
|
function useCoAgentStateRender(action, dependencies) {
|
|
1808
1513
|
const {
|
|
1809
1514
|
setCoAgentStateRender,
|
|
1810
1515
|
removeCoAgentStateRender,
|
|
1811
1516
|
coAgentStateRenders,
|
|
1812
1517
|
chatComponentsCache
|
|
1813
|
-
} = (0,
|
|
1814
|
-
const idRef = (0,
|
|
1518
|
+
} = (0, import_react12.useContext)(CopilotContext);
|
|
1519
|
+
const idRef = (0, import_react12.useRef)((0, import_shared7.randomId)());
|
|
1815
1520
|
const key = `${action.name}-${action.nodeName || "global"}`;
|
|
1816
1521
|
if (dependencies === void 0) {
|
|
1817
1522
|
if (coAgentStateRenders[idRef.current]) {
|
|
@@ -1823,7 +1528,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1823
1528
|
}
|
|
1824
1529
|
}
|
|
1825
1530
|
}
|
|
1826
|
-
(0,
|
|
1531
|
+
(0, import_react12.useEffect)(() => {
|
|
1827
1532
|
setCoAgentStateRender(idRef.current, action);
|
|
1828
1533
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1829
1534
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -1843,11 +1548,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1843
1548
|
}
|
|
1844
1549
|
|
|
1845
1550
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1846
|
-
var
|
|
1551
|
+
var import_react13 = require("react");
|
|
1847
1552
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1848
1553
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1849
|
-
const idRef = (0,
|
|
1850
|
-
(0,
|
|
1554
|
+
const idRef = (0, import_react13.useRef)();
|
|
1555
|
+
(0, import_react13.useEffect)(() => {
|
|
1851
1556
|
const id = addDocumentContext(document, categories);
|
|
1852
1557
|
idRef.current = id;
|
|
1853
1558
|
return () => {
|
|
@@ -1858,16 +1563,16 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1858
1563
|
}
|
|
1859
1564
|
|
|
1860
1565
|
// src/hooks/use-copilot-readable.ts
|
|
1861
|
-
var
|
|
1566
|
+
var import_react14 = require("react");
|
|
1862
1567
|
function convertToJSON(description, value) {
|
|
1863
1568
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1864
1569
|
}
|
|
1865
1570
|
function useCopilotReadable({ description, value, parentId, categories, convert }, dependencies) {
|
|
1866
1571
|
const { addContext, removeContext } = useCopilotContext();
|
|
1867
|
-
const idRef = (0,
|
|
1572
|
+
const idRef = (0, import_react14.useRef)();
|
|
1868
1573
|
convert = convert || convertToJSON;
|
|
1869
1574
|
const information = convert(description, value);
|
|
1870
|
-
(0,
|
|
1575
|
+
(0, import_react14.useEffect)(() => {
|
|
1871
1576
|
const id = addContext(information, parentId, categories);
|
|
1872
1577
|
idRef.current = id;
|
|
1873
1578
|
return () => {
|
|
@@ -1878,7 +1583,7 @@ function useCopilotReadable({ description, value, parentId, categories, convert
|
|
|
1878
1583
|
}
|
|
1879
1584
|
|
|
1880
1585
|
// src/hooks/use-coagent.ts
|
|
1881
|
-
var
|
|
1586
|
+
var import_react15 = require("react");
|
|
1882
1587
|
function useCoAgent(options) {
|
|
1883
1588
|
const isExternalStateManagement = (options2) => {
|
|
1884
1589
|
return "state" in options2 && "setState" in options2;
|
|
@@ -1890,8 +1595,8 @@ function useCoAgent(options) {
|
|
|
1890
1595
|
const generalContext = useCopilotContext();
|
|
1891
1596
|
const messagesContext = useCopilotMessagesContext();
|
|
1892
1597
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1893
|
-
const { coagentStates,
|
|
1894
|
-
const { appendMessage
|
|
1598
|
+
const { coagentStates, setCoagentStates } = context;
|
|
1599
|
+
const { appendMessage } = useCopilotChat();
|
|
1895
1600
|
const getCoagentState = (coagentStates2, name2) => {
|
|
1896
1601
|
if (coagentStates2[name2]) {
|
|
1897
1602
|
return coagentStates2[name2];
|
|
@@ -1908,43 +1613,40 @@ function useCoAgent(options) {
|
|
|
1908
1613
|
}
|
|
1909
1614
|
};
|
|
1910
1615
|
const setState = (newState) => {
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1616
|
+
setCoagentStates((prevAgentStates) => {
|
|
1617
|
+
let coagentState2 = getCoagentState(prevAgentStates, name);
|
|
1618
|
+
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
1619
|
+
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1620
|
+
[name]: __spreadProps(__spreadValues({}, coagentState2), {
|
|
1621
|
+
state: updatedState
|
|
1622
|
+
})
|
|
1623
|
+
});
|
|
1624
|
+
});
|
|
1918
1625
|
};
|
|
1919
1626
|
const coagentState = getCoagentState(coagentStates, name);
|
|
1920
1627
|
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
1921
|
-
(0,
|
|
1628
|
+
(0, import_react15.useEffect)(() => {
|
|
1922
1629
|
if (isExternalStateManagement(options)) {
|
|
1923
1630
|
setState(options.state);
|
|
1924
1631
|
} else if (coagentStates[name] === void 0) {
|
|
1925
1632
|
setState(options.initialState === void 0 ? {} : options.initialState);
|
|
1926
1633
|
}
|
|
1927
|
-
}, [
|
|
1928
|
-
isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0,
|
|
1929
|
-
// reset initialstate on reset
|
|
1930
|
-
coagentStates[name] === void 0
|
|
1931
|
-
]);
|
|
1932
|
-
const runAgentCallback = useAsyncCallback(
|
|
1933
|
-
(hint) => __async(this, null, function* () {
|
|
1934
|
-
yield runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
1935
|
-
}),
|
|
1936
|
-
[name, context, appendMessage, runChatCompletion]
|
|
1937
|
-
);
|
|
1634
|
+
}, [isExternalStateManagement(options) ? JSON.stringify(options.state) : void 0]);
|
|
1938
1635
|
return {
|
|
1939
1636
|
name,
|
|
1940
1637
|
nodeName: coagentState.nodeName,
|
|
1941
|
-
|
|
1638
|
+
state,
|
|
1639
|
+
setState,
|
|
1942
1640
|
running: coagentState.running,
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
stop: () =>
|
|
1947
|
-
|
|
1641
|
+
start: () => {
|
|
1642
|
+
startAgent(name, context);
|
|
1643
|
+
},
|
|
1644
|
+
stop: () => {
|
|
1645
|
+
stopAgent(name, context);
|
|
1646
|
+
},
|
|
1647
|
+
run: (hint) => {
|
|
1648
|
+
return runAgent(name, context, appendMessage, hint);
|
|
1649
|
+
}
|
|
1948
1650
|
};
|
|
1949
1651
|
}
|
|
1950
1652
|
function startAgent(name, context) {
|
|
@@ -1957,22 +1659,11 @@ function stopAgent(name, context) {
|
|
|
1957
1659
|
const { agentSession, setAgentSession } = context;
|
|
1958
1660
|
if (agentSession && agentSession.agentName === name) {
|
|
1959
1661
|
setAgentSession(null);
|
|
1960
|
-
context.setCoagentStates((prevAgentStates) => {
|
|
1961
|
-
return __spreadProps(__spreadValues({}, prevAgentStates), {
|
|
1962
|
-
[name]: __spreadProps(__spreadValues({}, prevAgentStates[name]), {
|
|
1963
|
-
running: false,
|
|
1964
|
-
active: false,
|
|
1965
|
-
threadId: void 0,
|
|
1966
|
-
nodeName: void 0,
|
|
1967
|
-
runId: void 0
|
|
1968
|
-
})
|
|
1969
|
-
});
|
|
1970
|
-
});
|
|
1971
1662
|
} else {
|
|
1972
1663
|
console.warn(`No agent session found for ${name}`);
|
|
1973
1664
|
}
|
|
1974
1665
|
}
|
|
1975
|
-
function runAgent(name, context, appendMessage,
|
|
1666
|
+
function runAgent(name, context, appendMessage, hint) {
|
|
1976
1667
|
return __async(this, null, function* () {
|
|
1977
1668
|
var _a, _b;
|
|
1978
1669
|
const { agentSession, setAgentSession } = context;
|
|
@@ -1988,29 +1679,25 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
1988
1679
|
previousState = message.state;
|
|
1989
1680
|
}
|
|
1990
1681
|
}
|
|
1991
|
-
let state = ((_b = (_a = context.
|
|
1682
|
+
let state = ((_b = (_a = context.coagentStates) == null ? void 0 : _a[name]) == null ? void 0 : _b.state) || {};
|
|
1992
1683
|
if (hint) {
|
|
1993
1684
|
const hintMessage = hint({ previousState, currentState: state });
|
|
1994
1685
|
if (hintMessage) {
|
|
1995
1686
|
yield appendMessage(hintMessage);
|
|
1996
|
-
} else {
|
|
1997
|
-
yield runChatCompletion();
|
|
1998
1687
|
}
|
|
1999
|
-
} else {
|
|
2000
|
-
yield runChatCompletion();
|
|
2001
1688
|
}
|
|
2002
1689
|
});
|
|
2003
1690
|
}
|
|
2004
1691
|
|
|
2005
1692
|
// src/lib/copilot-task.ts
|
|
2006
|
-
var
|
|
1693
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1694
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
2007
1695
|
var CopilotTask = class {
|
|
2008
1696
|
constructor(config) {
|
|
2009
1697
|
this.instructions = config.instructions;
|
|
2010
1698
|
this.actions = config.actions || [];
|
|
2011
1699
|
this.includeCopilotReadable = config.includeCopilotReadable !== false;
|
|
2012
1700
|
this.includeCopilotActions = config.includeCopilotActions !== false;
|
|
2013
|
-
this.forwardedParameters = config.forwardedParameters;
|
|
2014
1701
|
}
|
|
2015
1702
|
/**
|
|
2016
1703
|
* Run the task.
|
|
@@ -2019,7 +1706,7 @@ var CopilotTask = class {
|
|
|
2019
1706
|
*/
|
|
2020
1707
|
run(context, data) {
|
|
2021
1708
|
return __async(this, null, function* () {
|
|
2022
|
-
var _a, _b
|
|
1709
|
+
var _a, _b;
|
|
2023
1710
|
const actions = this.includeCopilotActions ? Object.assign({}, context.actions) : {};
|
|
2024
1711
|
for (const fn of this.actions) {
|
|
2025
1712
|
actions[fn.name] = fn;
|
|
@@ -2031,12 +1718,12 @@ var CopilotTask = class {
|
|
|
2031
1718
|
if (this.includeCopilotReadable) {
|
|
2032
1719
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
2033
1720
|
}
|
|
2034
|
-
const systemMessage = new
|
|
1721
|
+
const systemMessage = new import_runtime_client_gql6.TextMessage({
|
|
2035
1722
|
content: taskSystemMessage(contextString, this.instructions),
|
|
2036
|
-
role:
|
|
1723
|
+
role: import_runtime_client_gql6.Role.System
|
|
2037
1724
|
});
|
|
2038
1725
|
const messages = [systemMessage];
|
|
2039
|
-
const runtimeClient = new
|
|
1726
|
+
const runtimeClient = new import_runtime_client_gql6.CopilotRuntimeClient({
|
|
2040
1727
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
2041
1728
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
2042
1729
|
headers: context.copilotApiConfig.headers,
|
|
@@ -2045,22 +1732,26 @@ var CopilotTask = class {
|
|
|
2045
1732
|
const response = yield runtimeClient.generateCopilotResponse({
|
|
2046
1733
|
data: {
|
|
2047
1734
|
frontend: {
|
|
2048
|
-
actions:
|
|
1735
|
+
actions: Object.values(actions).map((action) => ({
|
|
1736
|
+
name: action.name,
|
|
1737
|
+
description: action.description || "",
|
|
1738
|
+
jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters || []))
|
|
1739
|
+
})),
|
|
2049
1740
|
url: window.location.href
|
|
2050
1741
|
},
|
|
2051
|
-
messages: (0,
|
|
1742
|
+
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)((0, import_runtime_client_gql6.filterAgentStateMessages)(messages)),
|
|
2052
1743
|
metadata: {
|
|
2053
|
-
requestType:
|
|
1744
|
+
requestType: import_runtime_client_gql6.CopilotRequestType.Task
|
|
2054
1745
|
},
|
|
2055
|
-
forwardedParameters:
|
|
1746
|
+
forwardedParameters: {
|
|
2056
1747
|
toolChoice: "required"
|
|
2057
|
-
}
|
|
1748
|
+
}
|
|
2058
1749
|
},
|
|
2059
1750
|
properties: context.copilotApiConfig.properties
|
|
2060
1751
|
}).toPromise();
|
|
2061
1752
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
2062
|
-
const functionCalls = (0,
|
|
2063
|
-
((
|
|
1753
|
+
const functionCalls = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
|
|
1754
|
+
((_b = (_a = response.data) == null ? void 0 : _a.generateCopilotResponse) == null ? void 0 : _b.messages) || []
|
|
2064
1755
|
).filter((m) => m.isActionExecutionMessage());
|
|
2065
1756
|
for (const functionCall of functionCalls) {
|
|
2066
1757
|
yield functionCallHandler({
|
|
@@ -2105,10 +1796,7 @@ ${instructions}
|
|
|
2105
1796
|
CopilotTask,
|
|
2106
1797
|
defaultCopilotContextCategories,
|
|
2107
1798
|
extract,
|
|
2108
|
-
runAgent,
|
|
2109
1799
|
shouldShowDevConsole,
|
|
2110
|
-
startAgent,
|
|
2111
|
-
stopAgent,
|
|
2112
1800
|
useCoAgent,
|
|
2113
1801
|
useCoAgentStateRender,
|
|
2114
1802
|
useCopilotAction,
|