@copilotkit/react-core 1.9.3 → 1.10.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/chunk-2IDV5OHF.mjs +11 -0
- package/dist/chunk-2IDV5OHF.mjs.map +1 -0
- package/dist/{chunk-36MGCCPZ.mjs → chunk-4CFY3CON.mjs} +2 -2
- package/dist/{chunk-SP4LFJSS.mjs → chunk-4XVBXDCX.mjs} +2 -2
- package/dist/chunk-4XVBXDCX.mjs.map +1 -0
- package/dist/{chunk-BVK7PLK6.mjs → chunk-DF4YG4PF.mjs} +2 -2
- package/dist/{chunk-CUAFWKTQ.mjs → chunk-JZQOCH4A.mjs} +2 -2
- package/dist/{chunk-MEAIJ7V2.mjs → chunk-KV25ZRMH.mjs} +3 -3
- package/dist/{chunk-5BSUSFHM.mjs → chunk-LNAQ7JG3.mjs} +2 -2
- package/dist/{chunk-FN3UA2ZE.mjs → chunk-NXCJELW7.mjs} +3 -3
- package/dist/{chunk-GIMSRCVW.mjs → chunk-OMVNJ7S3.mjs} +149 -10
- package/dist/chunk-OMVNJ7S3.mjs.map +1 -0
- package/dist/{chunk-BSAVFYRQ.mjs → chunk-PYULBXCD.mjs} +2 -2
- package/dist/{chunk-VDADWRS3.mjs → chunk-Q6FZZJ5A.mjs} +2 -2
- package/dist/{chunk-KIXKBJUV.mjs → chunk-RGKZCCPA.mjs} +2 -2
- package/dist/{chunk-H56XI6TM.mjs → chunk-VM7CVIET.mjs} +3 -3
- package/dist/chunk-VM7CVIET.mjs.map +1 -0
- package/dist/{chunk-UBPKEQ7Z.mjs → chunk-VOMGRGWT.mjs} +94 -22
- package/dist/chunk-VOMGRGWT.mjs.map +1 -0
- package/dist/{chunk-NJA5ZLAZ.mjs → chunk-WUORFPJ7.mjs} +2 -2
- package/dist/chunk-WUORFPJ7.mjs.map +1 -0
- package/dist/{chunk-DKZTPL66.mjs → chunk-XGRBCWK6.mjs} +5 -2
- package/dist/chunk-XGRBCWK6.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +4 -1
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.js +8 -2
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +4 -3
- package/dist/components/copilot-provider/index.d.ts +2 -1
- package/dist/components/copilot-provider/index.js +8 -2
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +4 -3
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +8 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -3
- package/dist/context/copilot-context.d.ts +2 -1
- package/dist/context/copilot-context.js +4 -1
- 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 +4 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-3ab4fdf5.d.ts → copilot-context-bd88d30d.d.ts} +21 -1
- package/dist/hooks/index.d.ts +5 -5
- package/dist/hooks/index.js +492 -153
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +17 -16
- package/dist/hooks/use-chat.d.ts +6 -1
- package/dist/hooks/use-chat.js +4 -1
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +4 -1
- 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 +4 -4
- package/dist/hooks/use-coagent.js +426 -44
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +8 -6
- package/dist/hooks/use-copilot-action.d.ts +1 -1
- package/dist/hooks/use-copilot-action.js +4 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +4 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +4 -1
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +43 -6
- package/dist/hooks/use-copilot-chat.js +442 -64
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +7 -5
- package/dist/hooks/use-copilot-readable.js +4 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +4 -1
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +4 -3
- package/dist/hooks/use-langgraph-interrupt.js +451 -71
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +8 -6
- package/dist/hooks/use-make-copilot-document-readable.js +4 -1
- 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 -1
- package/dist/index.js +421 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -18
- package/dist/lib/copilot-task.d.ts +2 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +5 -4
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -4
- package/dist/types/interrupt-action.d.ts +3 -2
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +4 -3
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +144 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -4
- package/dist/utils/suggestions-constants.d.ts +9 -0
- package/dist/utils/suggestions-constants.js +35 -0
- package/dist/utils/suggestions-constants.js.map +1 -0
- package/dist/utils/suggestions-constants.mjs +8 -0
- package/dist/utils/suggestions-constants.mjs.map +1 -0
- package/dist/utils/suggestions.d.ts +11 -0
- package/dist/utils/suggestions.js +343 -0
- package/dist/utils/suggestions.js.map +1 -0
- package/dist/utils/suggestions.mjs +22 -0
- package/dist/utils/suggestions.mjs.map +1 -0
- package/package.json +3 -3
- package/src/components/copilot-provider/copilotkit.tsx +4 -0
- package/src/context/copilot-context.tsx +6 -0
- package/src/hooks/use-chat.ts +4 -0
- package/src/hooks/use-coagent.ts +2 -2
- package/src/hooks/use-copilot-action.ts +1 -1
- package/src/hooks/use-copilot-chat.ts +197 -21
- package/src/utils/index.ts +3 -0
- package/src/utils/suggestions-constants.ts +8 -0
- package/src/utils/suggestions.ts +208 -0
- package/dist/chunk-DKZTPL66.mjs.map +0 -1
- package/dist/chunk-GIMSRCVW.mjs.map +0 -1
- package/dist/chunk-H56XI6TM.mjs.map +0 -1
- package/dist/chunk-NJA5ZLAZ.mjs.map +0 -1
- package/dist/chunk-SP4LFJSS.mjs.map +0 -1
- package/dist/chunk-UBPKEQ7Z.mjs.map +0 -1
- /package/dist/{chunk-36MGCCPZ.mjs.map → chunk-4CFY3CON.mjs.map} +0 -0
- /package/dist/{chunk-BVK7PLK6.mjs.map → chunk-DF4YG4PF.mjs.map} +0 -0
- /package/dist/{chunk-CUAFWKTQ.mjs.map → chunk-JZQOCH4A.mjs.map} +0 -0
- /package/dist/{chunk-MEAIJ7V2.mjs.map → chunk-KV25ZRMH.mjs.map} +0 -0
- /package/dist/{chunk-5BSUSFHM.mjs.map → chunk-LNAQ7JG3.mjs.map} +0 -0
- /package/dist/{chunk-FN3UA2ZE.mjs.map → chunk-NXCJELW7.mjs.map} +0 -0
- /package/dist/{chunk-BSAVFYRQ.mjs.map → chunk-PYULBXCD.mjs.map} +0 -0
- /package/dist/{chunk-VDADWRS3.mjs.map → chunk-Q6FZZJ5A.mjs.map} +0 -0
- /package/dist/{chunk-KIXKBJUV.mjs.map → chunk-RGKZCCPA.mjs.map} +0 -0
|
@@ -82,7 +82,7 @@ __export(use_langgraph_interrupt_exports, {
|
|
|
82
82
|
useLangGraphInterrupt: () => useLangGraphInterrupt
|
|
83
83
|
});
|
|
84
84
|
module.exports = __toCommonJS(use_langgraph_interrupt_exports);
|
|
85
|
-
var
|
|
85
|
+
var import_react10 = require("react");
|
|
86
86
|
|
|
87
87
|
// src/context/copilot-context.tsx
|
|
88
88
|
var import_react = __toESM(require("react"));
|
|
@@ -158,7 +158,10 @@ var emptyCopilotContext = {
|
|
|
158
158
|
langGraphInterruptAction: null,
|
|
159
159
|
setLangGraphInterruptAction: () => null,
|
|
160
160
|
removeLangGraphInterruptAction: () => null,
|
|
161
|
-
onError: void 0
|
|
161
|
+
onError: void 0,
|
|
162
|
+
suggestions: [],
|
|
163
|
+
setSuggestions: () => {
|
|
164
|
+
}
|
|
162
165
|
};
|
|
163
166
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
164
167
|
function useCopilotContext() {
|
|
@@ -173,11 +176,27 @@ function returnAndThrowInDebug(_value) {
|
|
|
173
176
|
}
|
|
174
177
|
|
|
175
178
|
// src/hooks/use-copilot-chat.ts
|
|
176
|
-
var
|
|
177
|
-
|
|
179
|
+
var import_react9 = require("react");
|
|
180
|
+
|
|
181
|
+
// src/context/copilot-messages-context.tsx
|
|
182
|
+
var import_react2 = __toESM(require("react"));
|
|
183
|
+
var emptyCopilotContext2 = {
|
|
184
|
+
messages: [],
|
|
185
|
+
setMessages: () => []
|
|
186
|
+
};
|
|
187
|
+
var CopilotMessagesContext = import_react2.default.createContext(emptyCopilotContext2);
|
|
188
|
+
function useCopilotMessagesContext() {
|
|
189
|
+
const context = import_react2.default.useContext(CopilotMessagesContext);
|
|
190
|
+
if (context === emptyCopilotContext2) {
|
|
191
|
+
throw new Error(
|
|
192
|
+
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
return context;
|
|
196
|
+
}
|
|
178
197
|
|
|
179
198
|
// src/hooks/use-chat.ts
|
|
180
|
-
var
|
|
199
|
+
var import_react6 = require("react");
|
|
181
200
|
var import_react_dom = require("react-dom");
|
|
182
201
|
var import_shared4 = require("@copilotkit/shared");
|
|
183
202
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
@@ -211,12 +230,12 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
211
230
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
212
231
|
|
|
213
232
|
// src/components/toast/toast-provider.tsx
|
|
214
|
-
var
|
|
233
|
+
var import_react3 = require("react");
|
|
215
234
|
var import_shared2 = require("@copilotkit/shared");
|
|
216
235
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
217
|
-
var ToastContext = (0,
|
|
236
|
+
var ToastContext = (0, import_react3.createContext)(void 0);
|
|
218
237
|
function useToast() {
|
|
219
|
-
const context = (0,
|
|
238
|
+
const context = (0, import_react3.useContext)(ToastContext);
|
|
220
239
|
if (!context) {
|
|
221
240
|
throw new Error("useToast must be used within a ToastProvider");
|
|
222
241
|
}
|
|
@@ -224,7 +243,7 @@ function useToast() {
|
|
|
224
243
|
}
|
|
225
244
|
|
|
226
245
|
// src/hooks/use-copilot-runtime-client.ts
|
|
227
|
-
var
|
|
246
|
+
var import_react4 = require("react");
|
|
228
247
|
var import_shared3 = require("@copilotkit/shared");
|
|
229
248
|
|
|
230
249
|
// src/utils/dev-console.ts
|
|
@@ -236,7 +255,7 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
236
255
|
var useCopilotRuntimeClient = (options) => {
|
|
237
256
|
const { setBannerError } = useToast();
|
|
238
257
|
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
239
|
-
const lastStructuredErrorRef = (0,
|
|
258
|
+
const lastStructuredErrorRef = (0, import_react4.useRef)(null);
|
|
240
259
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
241
260
|
if (!onError || !runtimeOptions.publicApiKey)
|
|
242
261
|
return;
|
|
@@ -264,7 +283,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
264
283
|
console.error("Error in onError handler:", error2);
|
|
265
284
|
}
|
|
266
285
|
});
|
|
267
|
-
const runtimeClient = (0,
|
|
286
|
+
const runtimeClient = (0, import_react4.useMemo)(() => {
|
|
268
287
|
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
269
288
|
handleGQLErrors: (error) => {
|
|
270
289
|
var _a2;
|
|
@@ -353,7 +372,7 @@ function createStructuredError(gqlError) {
|
|
|
353
372
|
}
|
|
354
373
|
|
|
355
374
|
// src/components/error-boundary/error-utils.tsx
|
|
356
|
-
var
|
|
375
|
+
var import_react5 = require("react");
|
|
357
376
|
|
|
358
377
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
359
378
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -436,7 +455,7 @@ function ErrorToast({ errors }) {
|
|
|
436
455
|
}
|
|
437
456
|
function useErrorToast() {
|
|
438
457
|
const { addToast } = useToast();
|
|
439
|
-
return (0,
|
|
458
|
+
return (0, import_react5.useCallback)(
|
|
440
459
|
(error) => {
|
|
441
460
|
const errorId = error.map((err) => {
|
|
442
461
|
var _a, _b;
|
|
@@ -456,7 +475,7 @@ function useErrorToast() {
|
|
|
456
475
|
}
|
|
457
476
|
function useAsyncCallback(callback, deps) {
|
|
458
477
|
const addErrorToast = useErrorToast();
|
|
459
|
-
return (0,
|
|
478
|
+
return (0, import_react5.useCallback)((...args) => __async(this, null, function* () {
|
|
460
479
|
try {
|
|
461
480
|
return yield callback(...args);
|
|
462
481
|
} catch (error) {
|
|
@@ -495,7 +514,7 @@ function useChat(options) {
|
|
|
495
514
|
langGraphInterruptAction,
|
|
496
515
|
setLangGraphInterruptAction
|
|
497
516
|
} = options;
|
|
498
|
-
const runChatCompletionRef = (0,
|
|
517
|
+
const runChatCompletionRef = (0, import_react6.useRef)();
|
|
499
518
|
const addErrorToast = useErrorToast();
|
|
500
519
|
const { setBannerError } = useToast();
|
|
501
520
|
const { onError } = useCopilotContext();
|
|
@@ -526,11 +545,11 @@ function useChat(options) {
|
|
|
526
545
|
console.error("Error in use-chat onError handler:", traceError);
|
|
527
546
|
}
|
|
528
547
|
});
|
|
529
|
-
const agentSessionRef = (0,
|
|
548
|
+
const agentSessionRef = (0, import_react6.useRef)(agentSession);
|
|
530
549
|
agentSessionRef.current = agentSession;
|
|
531
|
-
const runIdRef = (0,
|
|
550
|
+
const runIdRef = (0, import_react6.useRef)(runId);
|
|
532
551
|
runIdRef.current = runId;
|
|
533
|
-
const extensionsRef = (0,
|
|
552
|
+
const extensionsRef = (0, import_react6.useRef)(extensions);
|
|
534
553
|
extensionsRef.current = extensions;
|
|
535
554
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
536
555
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
@@ -542,7 +561,7 @@ function useChat(options) {
|
|
|
542
561
|
credentials: copilotConfig.credentials,
|
|
543
562
|
showDevConsole
|
|
544
563
|
});
|
|
545
|
-
const pendingAppendsRef = (0,
|
|
564
|
+
const pendingAppendsRef = (0, import_react6.useRef)([]);
|
|
546
565
|
const runChatCompletion = useAsyncCallback(
|
|
547
566
|
(previousMessages) => __async(this, null, function* () {
|
|
548
567
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
@@ -936,7 +955,7 @@ function useChat(options) {
|
|
|
936
955
|
}),
|
|
937
956
|
[messages]
|
|
938
957
|
);
|
|
939
|
-
(0,
|
|
958
|
+
(0, import_react6.useEffect)(() => {
|
|
940
959
|
if (!isLoading && pendingAppendsRef.current.length > 0) {
|
|
941
960
|
const pending = pendingAppendsRef.current.splice(0);
|
|
942
961
|
const followUp = pending.some((p) => p.followUp);
|
|
@@ -947,7 +966,7 @@ function useChat(options) {
|
|
|
947
966
|
}
|
|
948
967
|
}
|
|
949
968
|
}, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);
|
|
950
|
-
const composeAndFlushMetaEventsInput = (0,
|
|
969
|
+
const composeAndFlushMetaEventsInput = (0, import_react6.useCallback)(
|
|
951
970
|
(metaEvents) => {
|
|
952
971
|
return metaEvents.reduce((acc, event) => {
|
|
953
972
|
if (!event)
|
|
@@ -1127,36 +1146,326 @@ function getPairedFeAction(actions, message) {
|
|
|
1127
1146
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1128
1147
|
var import_react7 = require("react");
|
|
1129
1148
|
var import_react_dom2 = require("react-dom");
|
|
1149
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1150
|
+
|
|
1151
|
+
// src/utils/extract.ts
|
|
1130
1152
|
var import_shared5 = require("@copilotkit/shared");
|
|
1153
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1154
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1155
|
+
function extract(_0) {
|
|
1156
|
+
return __async(this, arguments, function* ({
|
|
1157
|
+
context,
|
|
1158
|
+
instructions,
|
|
1159
|
+
parameters,
|
|
1160
|
+
include,
|
|
1161
|
+
data,
|
|
1162
|
+
abortSignal,
|
|
1163
|
+
stream,
|
|
1164
|
+
requestType = import_runtime_client_gql4.CopilotRequestType.Task,
|
|
1165
|
+
forwardedParameters
|
|
1166
|
+
}) {
|
|
1167
|
+
var _a, _b;
|
|
1168
|
+
const { messages } = context;
|
|
1169
|
+
const action = {
|
|
1170
|
+
name: "extract",
|
|
1171
|
+
description: instructions,
|
|
1172
|
+
parameters,
|
|
1173
|
+
handler: (args) => {
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
|
|
1177
|
+
const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
|
|
1178
|
+
let contextString = "";
|
|
1179
|
+
if (data) {
|
|
1180
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
1181
|
+
}
|
|
1182
|
+
if (includeReadable) {
|
|
1183
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1184
|
+
}
|
|
1185
|
+
const systemMessage = new import_runtime_client_gql4.TextMessage({
|
|
1186
|
+
content: makeSystemMessage(contextString, instructions),
|
|
1187
|
+
role: import_runtime_client_gql4.Role.System
|
|
1188
|
+
});
|
|
1189
|
+
const instructionsMessage = new import_runtime_client_gql4.TextMessage({
|
|
1190
|
+
content: makeInstructionsMessage(instructions),
|
|
1191
|
+
role: import_runtime_client_gql4.Role.User
|
|
1192
|
+
});
|
|
1193
|
+
const response = context.runtimeClient.asStream(
|
|
1194
|
+
context.runtimeClient.generateCopilotResponse({
|
|
1195
|
+
data: {
|
|
1196
|
+
frontend: {
|
|
1197
|
+
actions: [
|
|
1198
|
+
{
|
|
1199
|
+
name: action.name,
|
|
1200
|
+
description: action.description || "",
|
|
1201
|
+
jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || []))
|
|
1202
|
+
}
|
|
1203
|
+
],
|
|
1204
|
+
url: window.location.href
|
|
1205
|
+
},
|
|
1206
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(
|
|
1207
|
+
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql5.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1208
|
+
),
|
|
1209
|
+
metadata: {
|
|
1210
|
+
requestType
|
|
1211
|
+
},
|
|
1212
|
+
forwardedParameters: __spreadProps(__spreadValues({}, forwardedParameters != null ? forwardedParameters : {}), {
|
|
1213
|
+
toolChoice: "function",
|
|
1214
|
+
toolChoiceFunctionName: action.name
|
|
1215
|
+
})
|
|
1216
|
+
},
|
|
1217
|
+
properties: context.copilotApiConfig.properties,
|
|
1218
|
+
signal: abortSignal
|
|
1219
|
+
})
|
|
1220
|
+
);
|
|
1221
|
+
const reader = response.getReader();
|
|
1222
|
+
let isInitial = true;
|
|
1223
|
+
let actionExecutionMessage = void 0;
|
|
1224
|
+
while (true) {
|
|
1225
|
+
const { done, value } = yield reader.read();
|
|
1226
|
+
if (done) {
|
|
1227
|
+
break;
|
|
1228
|
+
}
|
|
1229
|
+
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1230
|
+
throw new Error("Aborted");
|
|
1231
|
+
}
|
|
1232
|
+
actionExecutionMessage = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1233
|
+
value.generateCopilotResponse.messages
|
|
1234
|
+
).find((msg) => msg.isActionExecutionMessage());
|
|
1235
|
+
if (!actionExecutionMessage) {
|
|
1236
|
+
continue;
|
|
1237
|
+
}
|
|
1238
|
+
stream == null ? void 0 : stream({
|
|
1239
|
+
status: isInitial ? "initial" : "inProgress",
|
|
1240
|
+
args: actionExecutionMessage.arguments
|
|
1241
|
+
});
|
|
1242
|
+
isInitial = false;
|
|
1243
|
+
}
|
|
1244
|
+
if (!actionExecutionMessage) {
|
|
1245
|
+
throw new Error("extract() failed: No function call occurred");
|
|
1246
|
+
}
|
|
1247
|
+
stream == null ? void 0 : stream({
|
|
1248
|
+
status: "complete",
|
|
1249
|
+
args: actionExecutionMessage.arguments
|
|
1250
|
+
});
|
|
1251
|
+
return actionExecutionMessage.arguments;
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
function makeInstructionsMessage(instructions) {
|
|
1255
|
+
return `
|
|
1256
|
+
The user has given you the following task to complete:
|
|
1131
1257
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
function
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1258
|
+
\`\`\`
|
|
1259
|
+
${instructions}
|
|
1260
|
+
\`\`\`
|
|
1261
|
+
|
|
1262
|
+
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
1263
|
+
`;
|
|
1264
|
+
}
|
|
1265
|
+
function makeSystemMessage(contextString, instructions) {
|
|
1266
|
+
return `
|
|
1267
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1268
|
+
|
|
1269
|
+
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.
|
|
1270
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1271
|
+
|
|
1272
|
+
The user has provided you with the following context:
|
|
1273
|
+
\`\`\`
|
|
1274
|
+
${contextString}
|
|
1275
|
+
\`\`\`
|
|
1276
|
+
|
|
1277
|
+
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
1278
|
+
|
|
1279
|
+
Please assist them as best you can.
|
|
1280
|
+
|
|
1281
|
+
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
1282
|
+
`;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1285
|
+
// src/utils/suggestions.ts
|
|
1286
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1287
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1288
|
+
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1289
|
+
const abortController = abortControllerRef.current;
|
|
1290
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
const setSuggestionsIfNotAborted = (suggestions) => {
|
|
1294
|
+
if (!(abortController == null ? void 0 : abortController.signal.aborted) && abortControllerRef.current === abortController) {
|
|
1295
|
+
setCurrentSuggestions(suggestions);
|
|
1296
|
+
}
|
|
1297
|
+
};
|
|
1298
|
+
try {
|
|
1299
|
+
const tools = JSON.stringify(
|
|
1300
|
+
Object.values(context.actions).map((action) => ({
|
|
1301
|
+
name: action.name,
|
|
1302
|
+
description: action.description,
|
|
1303
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters))
|
|
1304
|
+
}))
|
|
1305
|
+
);
|
|
1306
|
+
const allSuggestions = [];
|
|
1307
|
+
let hasSuccessfulSuggestions = false;
|
|
1308
|
+
let hasErrors = false;
|
|
1309
|
+
let lastError = null;
|
|
1310
|
+
const enabledConfigs = Object.values(chatSuggestionConfiguration).filter(
|
|
1311
|
+
(config) => config.instructions && config.instructions.trim().length > 0
|
|
1144
1312
|
);
|
|
1313
|
+
if (enabledConfigs.length === 0) {
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
setSuggestionsIfNotAborted([]);
|
|
1317
|
+
for (const config of enabledConfigs) {
|
|
1318
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1319
|
+
setSuggestionsIfNotAborted([]);
|
|
1320
|
+
return;
|
|
1321
|
+
}
|
|
1322
|
+
try {
|
|
1323
|
+
const result = yield extract({
|
|
1324
|
+
context,
|
|
1325
|
+
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
1326
|
+
data: `${config.instructions}
|
|
1327
|
+
|
|
1328
|
+
Available tools: ${tools}
|
|
1329
|
+
|
|
1330
|
+
`,
|
|
1331
|
+
requestType: import_runtime_client_gql6.CopilotRequestType.Task,
|
|
1332
|
+
parameters: [
|
|
1333
|
+
{
|
|
1334
|
+
name: "suggestions",
|
|
1335
|
+
type: "object[]",
|
|
1336
|
+
attributes: [
|
|
1337
|
+
{
|
|
1338
|
+
name: "title",
|
|
1339
|
+
description: "The title of the suggestion. This is shown as a button and should be short.",
|
|
1340
|
+
type: "string"
|
|
1341
|
+
},
|
|
1342
|
+
{
|
|
1343
|
+
name: "message",
|
|
1344
|
+
description: "The message to send when the suggestion is clicked. This should be a clear, complete sentence and will be sent as an instruction to the AI.",
|
|
1345
|
+
type: "string"
|
|
1346
|
+
}
|
|
1347
|
+
]
|
|
1348
|
+
}
|
|
1349
|
+
],
|
|
1350
|
+
include: {
|
|
1351
|
+
messages: true,
|
|
1352
|
+
readable: true
|
|
1353
|
+
},
|
|
1354
|
+
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
1355
|
+
stream: ({ status, args }) => {
|
|
1356
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1357
|
+
return;
|
|
1358
|
+
}
|
|
1359
|
+
const suggestions = args.suggestions || [];
|
|
1360
|
+
const newSuggestions = [];
|
|
1361
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
1362
|
+
if (config.maxSuggestions !== void 0 && i >= config.maxSuggestions) {
|
|
1363
|
+
break;
|
|
1364
|
+
}
|
|
1365
|
+
const suggestion = suggestions[i];
|
|
1366
|
+
if (!suggestion || typeof suggestion !== "object") {
|
|
1367
|
+
continue;
|
|
1368
|
+
}
|
|
1369
|
+
const { title, message } = suggestion;
|
|
1370
|
+
const hasValidTitle = title && typeof title === "string" && title.trim().length > 0;
|
|
1371
|
+
const hasValidMessage = message && typeof message === "string" && message.trim().length > 0;
|
|
1372
|
+
if (!hasValidTitle) {
|
|
1373
|
+
continue;
|
|
1374
|
+
}
|
|
1375
|
+
const partial = i === suggestions.length - 1 && status !== "complete";
|
|
1376
|
+
newSuggestions.push({
|
|
1377
|
+
title: title.trim(),
|
|
1378
|
+
message: hasValidMessage ? message.trim() : "",
|
|
1379
|
+
// Use title as fallback
|
|
1380
|
+
partial,
|
|
1381
|
+
className: config.className
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
setSuggestionsIfNotAborted([...allSuggestions, ...newSuggestions]);
|
|
1385
|
+
}
|
|
1386
|
+
});
|
|
1387
|
+
if ((result == null ? void 0 : result.suggestions) && Array.isArray(result.suggestions)) {
|
|
1388
|
+
const validSuggestions = result.suggestions.filter(
|
|
1389
|
+
(suggestion) => suggestion && typeof suggestion.title === "string" && suggestion.title.trim().length > 0
|
|
1390
|
+
).map((suggestion) => ({
|
|
1391
|
+
title: suggestion.title.trim(),
|
|
1392
|
+
message: suggestion.message && typeof suggestion.message === "string" && suggestion.message.trim() ? suggestion.message.trim() : suggestion.title.trim()
|
|
1393
|
+
}));
|
|
1394
|
+
if (validSuggestions.length > 0) {
|
|
1395
|
+
allSuggestions.push(...validSuggestions);
|
|
1396
|
+
hasSuccessfulSuggestions = true;
|
|
1397
|
+
}
|
|
1398
|
+
}
|
|
1399
|
+
} catch (error) {
|
|
1400
|
+
hasErrors = true;
|
|
1401
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
if (hasSuccessfulSuggestions && allSuggestions.length > 0) {
|
|
1405
|
+
const uniqueSuggestions = allSuggestions.filter(
|
|
1406
|
+
(suggestion, index, self) => index === self.findIndex((s) => s.message === suggestion.message)
|
|
1407
|
+
);
|
|
1408
|
+
setSuggestionsIfNotAborted(uniqueSuggestions);
|
|
1409
|
+
} else if (hasErrors) {
|
|
1410
|
+
const errorMessage = lastError ? lastError.message : "Failed to generate suggestions due to API errors";
|
|
1411
|
+
throw new Error(errorMessage);
|
|
1412
|
+
}
|
|
1413
|
+
} catch (error) {
|
|
1414
|
+
throw error;
|
|
1145
1415
|
}
|
|
1146
|
-
|
|
1147
|
-
}
|
|
1416
|
+
});
|
|
1148
1417
|
|
|
1149
1418
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1150
1419
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1151
1420
|
var defaultCopilotContextCategories = ["global"];
|
|
1152
1421
|
|
|
1153
1422
|
// src/hooks/use-copilot-chat.ts
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1423
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1424
|
+
|
|
1425
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1426
|
+
var import_react8 = __toESM(require("react"));
|
|
1427
|
+
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1428
|
+
return render({ event, result, resolve });
|
|
1429
|
+
};
|
|
1430
|
+
function useLangGraphInterruptRender() {
|
|
1431
|
+
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1432
|
+
const responseRef = import_react8.default.useRef();
|
|
1433
|
+
const resolveInterrupt = (0, import_react8.useCallback)(
|
|
1434
|
+
(response) => {
|
|
1435
|
+
responseRef.current = response;
|
|
1436
|
+
setTimeout(() => {
|
|
1437
|
+
setLangGraphInterruptAction({ event: { response } });
|
|
1438
|
+
}, 0);
|
|
1439
|
+
},
|
|
1440
|
+
[setLangGraphInterruptAction]
|
|
1441
|
+
);
|
|
1442
|
+
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
1443
|
+
return null;
|
|
1444
|
+
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
1445
|
+
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
1446
|
+
if (!conditionsMet) {
|
|
1447
|
+
return null;
|
|
1448
|
+
}
|
|
1449
|
+
let result = null;
|
|
1450
|
+
if (handler) {
|
|
1451
|
+
result = handler({
|
|
1452
|
+
event,
|
|
1453
|
+
resolve: resolveInterrupt
|
|
1454
|
+
});
|
|
1455
|
+
}
|
|
1456
|
+
return import_react8.default.createElement(InterruptRenderer, {
|
|
1457
|
+
event,
|
|
1458
|
+
result,
|
|
1459
|
+
render,
|
|
1460
|
+
resolve: resolveInterrupt
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
// src/hooks/use-copilot-chat.ts
|
|
1465
|
+
var globalSuggestionPromise = null;
|
|
1466
|
+
function useCopilotChat(options = {}) {
|
|
1467
|
+
var _a;
|
|
1468
|
+
const makeSystemMessage2 = (_a = options.makeSystemMessage) != null ? _a : defaultSystemMessage;
|
|
1160
1469
|
const {
|
|
1161
1470
|
getContextString,
|
|
1162
1471
|
getFunctionCallHandler,
|
|
@@ -1180,11 +1489,72 @@ function useCopilotChat(_a = {}) {
|
|
|
1180
1489
|
extensions,
|
|
1181
1490
|
setExtensions,
|
|
1182
1491
|
langGraphInterruptAction,
|
|
1183
|
-
setLangGraphInterruptAction
|
|
1492
|
+
setLangGraphInterruptAction,
|
|
1493
|
+
chatSuggestionConfiguration,
|
|
1494
|
+
suggestions,
|
|
1495
|
+
setSuggestions,
|
|
1496
|
+
runtimeClient
|
|
1184
1497
|
} = useCopilotContext();
|
|
1185
1498
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1186
|
-
const [mcpServers, setLocalMcpServers] = (0,
|
|
1187
|
-
(0,
|
|
1499
|
+
const [mcpServers, setLocalMcpServers] = (0, import_react9.useState)([]);
|
|
1500
|
+
const suggestionsAbortControllerRef = (0, import_react9.useRef)(null);
|
|
1501
|
+
const isLoadingSuggestionsRef = (0, import_react9.useRef)(false);
|
|
1502
|
+
const abortSuggestions = (0, import_react9.useCallback)(
|
|
1503
|
+
(clear = true) => {
|
|
1504
|
+
var _a2;
|
|
1505
|
+
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort("suggestions aborted by user");
|
|
1506
|
+
suggestionsAbortControllerRef.current = null;
|
|
1507
|
+
if (clear) {
|
|
1508
|
+
setSuggestions([]);
|
|
1509
|
+
}
|
|
1510
|
+
},
|
|
1511
|
+
[setSuggestions]
|
|
1512
|
+
);
|
|
1513
|
+
const stableContext = (0, import_react9.useMemo)(() => {
|
|
1514
|
+
return {
|
|
1515
|
+
actions,
|
|
1516
|
+
copilotApiConfig,
|
|
1517
|
+
chatSuggestionConfiguration,
|
|
1518
|
+
messages,
|
|
1519
|
+
setMessages,
|
|
1520
|
+
getContextString,
|
|
1521
|
+
runtimeClient
|
|
1522
|
+
};
|
|
1523
|
+
}, [
|
|
1524
|
+
JSON.stringify(Object.keys(actions)),
|
|
1525
|
+
copilotApiConfig.chatApiEndpoint,
|
|
1526
|
+
messages.length,
|
|
1527
|
+
Object.keys(chatSuggestionConfiguration).length
|
|
1528
|
+
]);
|
|
1529
|
+
const generateSuggestionsFunc = (0, import_react9.useCallback)(() => __async(this, null, function* () {
|
|
1530
|
+
if (globalSuggestionPromise) {
|
|
1531
|
+
return globalSuggestionPromise;
|
|
1532
|
+
}
|
|
1533
|
+
globalSuggestionPromise = (() => __async(this, null, function* () {
|
|
1534
|
+
try {
|
|
1535
|
+
abortSuggestions();
|
|
1536
|
+
isLoadingSuggestionsRef.current = true;
|
|
1537
|
+
suggestionsAbortControllerRef.current = new AbortController();
|
|
1538
|
+
setSuggestions([]);
|
|
1539
|
+
yield reloadSuggestions(
|
|
1540
|
+
stableContext,
|
|
1541
|
+
chatSuggestionConfiguration,
|
|
1542
|
+
setSuggestions,
|
|
1543
|
+
suggestionsAbortControllerRef
|
|
1544
|
+
);
|
|
1545
|
+
} catch (error) {
|
|
1546
|
+
throw error;
|
|
1547
|
+
} finally {
|
|
1548
|
+
isLoadingSuggestionsRef.current = false;
|
|
1549
|
+
globalSuggestionPromise = null;
|
|
1550
|
+
}
|
|
1551
|
+
}))();
|
|
1552
|
+
return globalSuggestionPromise;
|
|
1553
|
+
}), [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);
|
|
1554
|
+
const resetSuggestions = (0, import_react9.useCallback)(() => {
|
|
1555
|
+
setSuggestions([]);
|
|
1556
|
+
}, [setSuggestions]);
|
|
1557
|
+
(0, import_react9.useEffect)(() => {
|
|
1188
1558
|
if (mcpServers.length > 0) {
|
|
1189
1559
|
const serversCopy = [...mcpServers];
|
|
1190
1560
|
copilotApiConfig.mcpServers = serversCopy;
|
|
@@ -1194,7 +1564,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1194
1564
|
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
1195
1565
|
}
|
|
1196
1566
|
}, [mcpServers, copilotApiConfig]);
|
|
1197
|
-
const setMcpServers = (0,
|
|
1567
|
+
const setMcpServers = (0, import_react9.useCallback)((servers) => {
|
|
1198
1568
|
setLocalMcpServers(servers);
|
|
1199
1569
|
}, []);
|
|
1200
1570
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1215,15 +1585,15 @@ function useCopilotChat(_a = {}) {
|
|
|
1215
1585
|
}),
|
|
1216
1586
|
[coAgentStateRenders]
|
|
1217
1587
|
);
|
|
1218
|
-
const makeSystemMessageCallback = (0,
|
|
1219
|
-
const systemMessageMaker =
|
|
1588
|
+
const makeSystemMessageCallback = (0, import_react9.useCallback)(() => {
|
|
1589
|
+
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1220
1590
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
1221
|
-
return new
|
|
1591
|
+
return new import_runtime_client_gql7.TextMessage({
|
|
1222
1592
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1223
|
-
role:
|
|
1593
|
+
role: import_runtime_client_gql7.Role.System
|
|
1224
1594
|
});
|
|
1225
|
-
}, [getContextString,
|
|
1226
|
-
const deleteMessage = (0,
|
|
1595
|
+
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1596
|
+
const deleteMessage = (0, import_react9.useCallback)(
|
|
1227
1597
|
(messageId) => {
|
|
1228
1598
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1229
1599
|
},
|
|
@@ -1232,7 +1602,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1232
1602
|
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1233
1603
|
actions: Object.values(actions),
|
|
1234
1604
|
copilotConfig: copilotApiConfig,
|
|
1235
|
-
initialMessages: options.initialMessages || [],
|
|
1605
|
+
initialMessages: (0, import_runtime_client_gql7.aguiToGQL)(options.initialMessages || []),
|
|
1236
1606
|
onFunctionCall: getFunctionCallHandler(),
|
|
1237
1607
|
onCoAgentStateRender,
|
|
1238
1608
|
messages,
|
|
@@ -1259,7 +1629,8 @@ function useCopilotChat(_a = {}) {
|
|
|
1259
1629
|
const latestAppend = useUpdatedRef(append);
|
|
1260
1630
|
const latestAppendFunc = useAsyncCallback(
|
|
1261
1631
|
(message, options2) => __async(this, null, function* () {
|
|
1262
|
-
|
|
1632
|
+
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1633
|
+
return yield latestAppend.current((0, import_runtime_client_gql7.aguiToGQL)([message])[0], options2);
|
|
1263
1634
|
}),
|
|
1264
1635
|
[latestAppend]
|
|
1265
1636
|
);
|
|
@@ -1271,20 +1642,20 @@ function useCopilotChat(_a = {}) {
|
|
|
1271
1642
|
[latestReload]
|
|
1272
1643
|
);
|
|
1273
1644
|
const latestStop = useUpdatedRef(stop);
|
|
1274
|
-
const latestStopFunc = (0,
|
|
1645
|
+
const latestStopFunc = (0, import_react9.useCallback)(() => {
|
|
1275
1646
|
return latestStop.current();
|
|
1276
1647
|
}, [latestStop]);
|
|
1277
1648
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1278
|
-
const latestDeleteFunc = (0,
|
|
1649
|
+
const latestDeleteFunc = (0, import_react9.useCallback)(
|
|
1279
1650
|
(messageId) => {
|
|
1280
1651
|
return latestDelete.current(messageId);
|
|
1281
1652
|
},
|
|
1282
1653
|
[latestDelete]
|
|
1283
1654
|
);
|
|
1284
1655
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1285
|
-
const latestSetMessagesFunc = (0,
|
|
1656
|
+
const latestSetMessagesFunc = (0, import_react9.useCallback)(
|
|
1286
1657
|
(messages2) => {
|
|
1287
|
-
return latestSetMessages.current(messages2);
|
|
1658
|
+
return latestSetMessages.current((0, import_runtime_client_gql7.aguiToGQL)(messages2));
|
|
1288
1659
|
},
|
|
1289
1660
|
[latestSetMessages]
|
|
1290
1661
|
);
|
|
@@ -1292,7 +1663,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1292
1663
|
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1293
1664
|
return yield latestRunChatCompletion.current();
|
|
1294
1665
|
}), [latestRunChatCompletion]);
|
|
1295
|
-
const reset = (0,
|
|
1666
|
+
const reset = (0, import_react9.useCallback)(() => {
|
|
1296
1667
|
latestStopFunc();
|
|
1297
1668
|
setMessages([]);
|
|
1298
1669
|
setRunId(null);
|
|
@@ -1304,20 +1675,23 @@ function useCopilotChat(_a = {}) {
|
|
|
1304
1675
|
};
|
|
1305
1676
|
}
|
|
1306
1677
|
setAgentSession(initialAgentSession);
|
|
1678
|
+
resetSuggestions();
|
|
1307
1679
|
}, [
|
|
1308
1680
|
latestStopFunc,
|
|
1309
1681
|
setMessages,
|
|
1310
1682
|
setThreadId,
|
|
1311
1683
|
setCoagentStatesWithRef,
|
|
1312
1684
|
setAgentSession,
|
|
1313
|
-
agentLock
|
|
1685
|
+
agentLock,
|
|
1686
|
+
resetSuggestions
|
|
1314
1687
|
]);
|
|
1315
1688
|
const latestReset = useUpdatedRef(reset);
|
|
1316
|
-
const latestResetFunc = (0,
|
|
1689
|
+
const latestResetFunc = (0, import_react9.useCallback)(() => {
|
|
1317
1690
|
return latestReset.current();
|
|
1318
1691
|
}, [latestReset]);
|
|
1692
|
+
const interrupt = useLangGraphInterruptRender();
|
|
1319
1693
|
return {
|
|
1320
|
-
visibleMessages: messages,
|
|
1694
|
+
visibleMessages: (0, import_runtime_client_gql7.gqlToAGUI)(messages, actions, coAgentStateRenders),
|
|
1321
1695
|
appendMessage: latestAppendFunc,
|
|
1322
1696
|
setMessages: latestSetMessagesFunc,
|
|
1323
1697
|
reloadMessages: latestReloadFunc,
|
|
@@ -1327,12 +1701,18 @@ function useCopilotChat(_a = {}) {
|
|
|
1327
1701
|
runChatCompletion: latestRunChatCompletionFunc,
|
|
1328
1702
|
isLoading,
|
|
1329
1703
|
mcpServers,
|
|
1330
|
-
setMcpServers
|
|
1704
|
+
setMcpServers,
|
|
1705
|
+
suggestions,
|
|
1706
|
+
setSuggestions,
|
|
1707
|
+
generateSuggestions: generateSuggestionsFunc,
|
|
1708
|
+
resetSuggestions,
|
|
1709
|
+
isLoadingSuggestions: isLoadingSuggestionsRef.current,
|
|
1710
|
+
interrupt
|
|
1331
1711
|
};
|
|
1332
1712
|
}
|
|
1333
1713
|
function useUpdatedRef(value) {
|
|
1334
|
-
const ref = (0,
|
|
1335
|
-
(0,
|
|
1714
|
+
const ref = (0, import_react9.useRef)(value);
|
|
1715
|
+
(0, import_react9.useEffect)(() => {
|
|
1336
1716
|
ref.current = value;
|
|
1337
1717
|
}, [value]);
|
|
1338
1718
|
return ref;
|
|
@@ -1365,28 +1745,28 @@ ${additionalInstructions}` : "");
|
|
|
1365
1745
|
}
|
|
1366
1746
|
|
|
1367
1747
|
// src/hooks/use-langgraph-interrupt.ts
|
|
1368
|
-
var
|
|
1748
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1369
1749
|
function useLangGraphInterrupt(action, dependencies) {
|
|
1370
1750
|
var _a;
|
|
1371
|
-
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0,
|
|
1751
|
+
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react10.useContext)(CopilotContext);
|
|
1372
1752
|
const { runChatCompletion } = useCopilotChat();
|
|
1373
1753
|
const { addToast } = useToast();
|
|
1374
|
-
const actionId = (0,
|
|
1375
|
-
const hasAction = (0,
|
|
1754
|
+
const actionId = (0, import_shared8.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
1755
|
+
const hasAction = (0, import_react10.useMemo)(
|
|
1376
1756
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
1377
1757
|
[langGraphInterruptAction]
|
|
1378
1758
|
);
|
|
1379
|
-
const isCurrentAction = (0,
|
|
1759
|
+
const isCurrentAction = (0, import_react10.useMemo)(
|
|
1380
1760
|
() => (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) && (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) === actionId,
|
|
1381
1761
|
[langGraphInterruptAction]
|
|
1382
1762
|
);
|
|
1383
|
-
(0,
|
|
1763
|
+
(0, import_react10.useEffect)(() => {
|
|
1384
1764
|
var _a2;
|
|
1385
1765
|
if (hasAction && isCurrentAction && ((_a2 = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a2.response)) {
|
|
1386
1766
|
runChatCompletion();
|
|
1387
1767
|
}
|
|
1388
1768
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
1389
|
-
(0,
|
|
1769
|
+
(0, import_react10.useEffect)(() => {
|
|
1390
1770
|
if (!action)
|
|
1391
1771
|
return;
|
|
1392
1772
|
if (hasAction && !isCurrentAction && !action.enabled) {
|