@copilotkit/react-core 1.9.3-next.4 → 1.10.0-next.0
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 +38 -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-BVK7PLK6.mjs → chunk-DF4YG4PF.mjs} +2 -2
- package/dist/{chunk-ELU3VLPJ.mjs → chunk-G35QHAQ6.mjs} +8 -8
- package/dist/chunk-G35QHAQ6.mjs.map +1 -0
- package/dist/{chunk-DNHCRVE6.mjs → chunk-LIGLZ53V.mjs} +98 -26
- package/dist/chunk-LIGLZ53V.mjs.map +1 -0
- package/dist/{chunk-5BSUSFHM.mjs → chunk-LNAQ7JG3.mjs} +2 -2
- package/dist/{chunk-NJA5ZLAZ.mjs → chunk-LU5JPZ24.mjs} +2 -2
- package/dist/{chunk-GIMSRCVW.mjs → chunk-NAM55D5I.mjs} +153 -14
- package/dist/chunk-NAM55D5I.mjs.map +1 -0
- package/dist/{chunk-CUAFWKTQ.mjs → chunk-O5KV32S5.mjs} +4 -4
- package/dist/{chunk-FN3UA2ZE.mjs → chunk-PZXTDFMX.mjs} +3 -3
- package/dist/{chunk-VDADWRS3.mjs → chunk-Q6FZZJ5A.mjs} +2 -2
- package/dist/{chunk-KIXKBJUV.mjs → chunk-RGKZCCPA.mjs} +2 -2
- package/dist/{chunk-SGF6C7I6.mjs → chunk-SJJNFYGQ.mjs} +4 -4
- package/dist/{chunk-DKZTPL66.mjs → chunk-XGRBCWK6.mjs} +5 -2
- package/dist/chunk-XGRBCWK6.mjs.map +1 -0
- package/dist/{chunk-BSAVFYRQ.mjs → chunk-YBDRISKO.mjs} +5 -5
- package/dist/{chunk-QPX2JKOR.mjs → chunk-YSQ5I2AE.mjs} +6 -6
- package/dist/chunk-YSQ5I2AE.mjs.map +1 -0
- package/dist/{chunk-5B3NSTQK.mjs → chunk-YVBDAURK.mjs} +3 -3
- 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 +3 -3
- 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 +10 -9
- 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 +10 -9
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- 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 +10 -9
- 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 +4 -4
- 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 +493 -154
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +32 -31
- package/dist/hooks/use-chat.d.ts +6 -1
- package/dist/hooks/use-chat.js +5 -2
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +4 -4
- 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 +3 -3
- package/dist/hooks/use-coagent.js +427 -45
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +16 -14
- 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 +443 -65
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +15 -13
- 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 +452 -72
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +16 -14
- 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 +422 -201
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -36
- package/dist/lib/copilot-task.d.ts +2 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +12 -11
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +12 -11
- 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 +10 -9
- 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 +16 -10
- 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 +6 -2
- package/src/hooks/use-coagent.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-DNHCRVE6.mjs.map +0 -1
- package/dist/chunk-ELU3VLPJ.mjs.map +0 -1
- package/dist/chunk-GIMSRCVW.mjs.map +0 -1
- package/dist/chunk-QPX2JKOR.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-5BSUSFHM.mjs.map → chunk-LNAQ7JG3.mjs.map} +0 -0
- /package/dist/{chunk-NJA5ZLAZ.mjs.map → chunk-LU5JPZ24.mjs.map} +0 -0
- /package/dist/{chunk-CUAFWKTQ.mjs.map → chunk-O5KV32S5.mjs.map} +0 -0
- /package/dist/{chunk-FN3UA2ZE.mjs.map → chunk-PZXTDFMX.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
- /package/dist/{chunk-SGF6C7I6.mjs.map → chunk-SJJNFYGQ.mjs.map} +0 -0
- /package/dist/{chunk-BSAVFYRQ.mjs.map → chunk-YBDRISKO.mjs.map} +0 -0
- /package/dist/{chunk-5B3NSTQK.mjs.map → chunk-YVBDAURK.mjs.map} +0 -0
package/dist/hooks/index.js
CHANGED
|
@@ -97,7 +97,7 @@ __export(hooks_exports, {
|
|
|
97
97
|
module.exports = __toCommonJS(hooks_exports);
|
|
98
98
|
|
|
99
99
|
// src/hooks/use-copilot-chat.ts
|
|
100
|
-
var
|
|
100
|
+
var import_react9 = require("react");
|
|
101
101
|
|
|
102
102
|
// src/context/copilot-context.tsx
|
|
103
103
|
var import_react = __toESM(require("react"));
|
|
@@ -173,7 +173,10 @@ var emptyCopilotContext = {
|
|
|
173
173
|
langGraphInterruptAction: null,
|
|
174
174
|
setLangGraphInterruptAction: () => null,
|
|
175
175
|
removeLangGraphInterruptAction: () => null,
|
|
176
|
-
onError: void 0
|
|
176
|
+
onError: void 0,
|
|
177
|
+
suggestions: [],
|
|
178
|
+
setSuggestions: () => {
|
|
179
|
+
}
|
|
177
180
|
};
|
|
178
181
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
179
182
|
function useCopilotContext() {
|
|
@@ -187,11 +190,25 @@ function returnAndThrowInDebug(_value) {
|
|
|
187
190
|
throw new Error("Remember to wrap your app in a `<CopilotKit> {...} </CopilotKit>` !!!");
|
|
188
191
|
}
|
|
189
192
|
|
|
190
|
-
// src/
|
|
191
|
-
var
|
|
193
|
+
// src/context/copilot-messages-context.tsx
|
|
194
|
+
var import_react2 = __toESM(require("react"));
|
|
195
|
+
var emptyCopilotContext2 = {
|
|
196
|
+
messages: [],
|
|
197
|
+
setMessages: () => []
|
|
198
|
+
};
|
|
199
|
+
var CopilotMessagesContext = import_react2.default.createContext(emptyCopilotContext2);
|
|
200
|
+
function useCopilotMessagesContext() {
|
|
201
|
+
const context = import_react2.default.useContext(CopilotMessagesContext);
|
|
202
|
+
if (context === emptyCopilotContext2) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
"A messages consuming component was not wrapped with `<CopilotMessages> {...} </CopilotMessages>`"
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return context;
|
|
208
|
+
}
|
|
192
209
|
|
|
193
210
|
// src/hooks/use-chat.ts
|
|
194
|
-
var
|
|
211
|
+
var import_react6 = require("react");
|
|
195
212
|
var import_react_dom = require("react-dom");
|
|
196
213
|
var import_shared4 = require("@copilotkit/shared");
|
|
197
214
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
@@ -225,12 +242,12 @@ function processActionsForRuntimeRequest(actions) {
|
|
|
225
242
|
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
226
243
|
|
|
227
244
|
// src/components/toast/toast-provider.tsx
|
|
228
|
-
var
|
|
245
|
+
var import_react3 = require("react");
|
|
229
246
|
var import_shared2 = require("@copilotkit/shared");
|
|
230
247
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
231
|
-
var ToastContext = (0,
|
|
248
|
+
var ToastContext = (0, import_react3.createContext)(void 0);
|
|
232
249
|
function useToast() {
|
|
233
|
-
const context = (0,
|
|
250
|
+
const context = (0, import_react3.useContext)(ToastContext);
|
|
234
251
|
if (!context) {
|
|
235
252
|
throw new Error("useToast must be used within a ToastProvider");
|
|
236
253
|
}
|
|
@@ -238,7 +255,7 @@ function useToast() {
|
|
|
238
255
|
}
|
|
239
256
|
|
|
240
257
|
// src/hooks/use-copilot-runtime-client.ts
|
|
241
|
-
var
|
|
258
|
+
var import_react4 = require("react");
|
|
242
259
|
var import_shared3 = require("@copilotkit/shared");
|
|
243
260
|
|
|
244
261
|
// src/utils/dev-console.ts
|
|
@@ -250,7 +267,7 @@ function shouldShowDevConsole(showDevConsole) {
|
|
|
250
267
|
var useCopilotRuntimeClient = (options) => {
|
|
251
268
|
const { setBannerError } = useToast();
|
|
252
269
|
const _a = options, { showDevConsole, onError } = _a, runtimeOptions = __objRest(_a, ["showDevConsole", "onError"]);
|
|
253
|
-
const lastStructuredErrorRef = (0,
|
|
270
|
+
const lastStructuredErrorRef = (0, import_react4.useRef)(null);
|
|
254
271
|
const traceUIError = (error, originalError) => __async(void 0, null, function* () {
|
|
255
272
|
if (!onError || !runtimeOptions.publicApiKey)
|
|
256
273
|
return;
|
|
@@ -278,7 +295,7 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
278
295
|
console.error("Error in onError handler:", error2);
|
|
279
296
|
}
|
|
280
297
|
});
|
|
281
|
-
const runtimeClient = (0,
|
|
298
|
+
const runtimeClient = (0, import_react4.useMemo)(() => {
|
|
282
299
|
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, runtimeOptions), {
|
|
283
300
|
handleGQLErrors: (error) => {
|
|
284
301
|
var _a2;
|
|
@@ -367,7 +384,7 @@ function createStructuredError(gqlError) {
|
|
|
367
384
|
}
|
|
368
385
|
|
|
369
386
|
// src/components/error-boundary/error-utils.tsx
|
|
370
|
-
var
|
|
387
|
+
var import_react5 = require("react");
|
|
371
388
|
|
|
372
389
|
// src/components/toast/exclamation-mark-icon.tsx
|
|
373
390
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
@@ -450,7 +467,7 @@ function ErrorToast({ errors }) {
|
|
|
450
467
|
}
|
|
451
468
|
function useErrorToast() {
|
|
452
469
|
const { addToast } = useToast();
|
|
453
|
-
return (0,
|
|
470
|
+
return (0, import_react5.useCallback)(
|
|
454
471
|
(error) => {
|
|
455
472
|
const errorId = error.map((err) => {
|
|
456
473
|
var _a, _b;
|
|
@@ -470,7 +487,7 @@ function useErrorToast() {
|
|
|
470
487
|
}
|
|
471
488
|
function useAsyncCallback(callback, deps) {
|
|
472
489
|
const addErrorToast = useErrorToast();
|
|
473
|
-
return (0,
|
|
490
|
+
return (0, import_react5.useCallback)((...args) => __async(this, null, function* () {
|
|
474
491
|
try {
|
|
475
492
|
return yield callback(...args);
|
|
476
493
|
} catch (error) {
|
|
@@ -509,7 +526,7 @@ function useChat(options) {
|
|
|
509
526
|
langGraphInterruptAction,
|
|
510
527
|
setLangGraphInterruptAction
|
|
511
528
|
} = options;
|
|
512
|
-
const runChatCompletionRef = (0,
|
|
529
|
+
const runChatCompletionRef = (0, import_react6.useRef)();
|
|
513
530
|
const addErrorToast = useErrorToast();
|
|
514
531
|
const { setBannerError } = useToast();
|
|
515
532
|
const { onError } = useCopilotContext();
|
|
@@ -540,11 +557,11 @@ function useChat(options) {
|
|
|
540
557
|
console.error("Error in use-chat onError handler:", traceError);
|
|
541
558
|
}
|
|
542
559
|
});
|
|
543
|
-
const agentSessionRef = (0,
|
|
560
|
+
const agentSessionRef = (0, import_react6.useRef)(agentSession);
|
|
544
561
|
agentSessionRef.current = agentSession;
|
|
545
|
-
const runIdRef = (0,
|
|
562
|
+
const runIdRef = (0, import_react6.useRef)(runId);
|
|
546
563
|
runIdRef.current = runId;
|
|
547
|
-
const extensionsRef = (0,
|
|
564
|
+
const extensionsRef = (0, import_react6.useRef)(extensions);
|
|
548
565
|
extensionsRef.current = extensions;
|
|
549
566
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
550
567
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared4.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
@@ -556,7 +573,7 @@ function useChat(options) {
|
|
|
556
573
|
credentials: copilotConfig.credentials,
|
|
557
574
|
showDevConsole
|
|
558
575
|
});
|
|
559
|
-
const pendingAppendsRef = (0,
|
|
576
|
+
const pendingAppendsRef = (0, import_react6.useRef)([]);
|
|
560
577
|
const runChatCompletion = useAsyncCallback(
|
|
561
578
|
(previousMessages) => __async(this, null, function* () {
|
|
562
579
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
@@ -852,7 +869,7 @@ function useChat(options) {
|
|
|
852
869
|
const action = actions.find(
|
|
853
870
|
(action2) => action2.name === message.name
|
|
854
871
|
);
|
|
855
|
-
if (action && action.available === "
|
|
872
|
+
if (action && action.available === "frontend") {
|
|
856
873
|
continue;
|
|
857
874
|
}
|
|
858
875
|
const currentResultMessagePairedFeAction = message.isResultMessage() ? getPairedFeAction(actions, message) : null;
|
|
@@ -950,7 +967,7 @@ function useChat(options) {
|
|
|
950
967
|
}),
|
|
951
968
|
[messages]
|
|
952
969
|
);
|
|
953
|
-
(0,
|
|
970
|
+
(0, import_react6.useEffect)(() => {
|
|
954
971
|
if (!isLoading && pendingAppendsRef.current.length > 0) {
|
|
955
972
|
const pending = pendingAppendsRef.current.splice(0);
|
|
956
973
|
const followUp = pending.some((p) => p.followUp);
|
|
@@ -961,7 +978,7 @@ function useChat(options) {
|
|
|
961
978
|
}
|
|
962
979
|
}
|
|
963
980
|
}, [isLoading, messages, setMessages, runChatCompletionAndHandleFunctionCall]);
|
|
964
|
-
const composeAndFlushMetaEventsInput = (0,
|
|
981
|
+
const composeAndFlushMetaEventsInput = (0, import_react6.useCallback)(
|
|
965
982
|
(metaEvents) => {
|
|
966
983
|
return metaEvents.reduce((acc, event) => {
|
|
967
984
|
if (!event)
|
|
@@ -1141,36 +1158,326 @@ function getPairedFeAction(actions, message) {
|
|
|
1141
1158
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1142
1159
|
var import_react7 = require("react");
|
|
1143
1160
|
var import_react_dom2 = require("react-dom");
|
|
1161
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1162
|
+
|
|
1163
|
+
// src/utils/extract.ts
|
|
1144
1164
|
var import_shared5 = require("@copilotkit/shared");
|
|
1165
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1166
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1167
|
+
function extract(_0) {
|
|
1168
|
+
return __async(this, arguments, function* ({
|
|
1169
|
+
context,
|
|
1170
|
+
instructions,
|
|
1171
|
+
parameters,
|
|
1172
|
+
include,
|
|
1173
|
+
data,
|
|
1174
|
+
abortSignal,
|
|
1175
|
+
stream,
|
|
1176
|
+
requestType = import_runtime_client_gql4.CopilotRequestType.Task,
|
|
1177
|
+
forwardedParameters
|
|
1178
|
+
}) {
|
|
1179
|
+
var _a, _b;
|
|
1180
|
+
const { messages } = context;
|
|
1181
|
+
const action = {
|
|
1182
|
+
name: "extract",
|
|
1183
|
+
description: instructions,
|
|
1184
|
+
parameters,
|
|
1185
|
+
handler: (args) => {
|
|
1186
|
+
}
|
|
1187
|
+
};
|
|
1188
|
+
const includeReadable = (_a = include == null ? void 0 : include.readable) != null ? _a : false;
|
|
1189
|
+
const includeMessages = (_b = include == null ? void 0 : include.messages) != null ? _b : false;
|
|
1190
|
+
let contextString = "";
|
|
1191
|
+
if (data) {
|
|
1192
|
+
contextString = (typeof data === "string" ? data : JSON.stringify(data)) + "\n\n";
|
|
1193
|
+
}
|
|
1194
|
+
if (includeReadable) {
|
|
1195
|
+
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1196
|
+
}
|
|
1197
|
+
const systemMessage = new import_runtime_client_gql4.TextMessage({
|
|
1198
|
+
content: makeSystemMessage(contextString, instructions),
|
|
1199
|
+
role: import_runtime_client_gql4.Role.System
|
|
1200
|
+
});
|
|
1201
|
+
const instructionsMessage = new import_runtime_client_gql4.TextMessage({
|
|
1202
|
+
content: makeInstructionsMessage(instructions),
|
|
1203
|
+
role: import_runtime_client_gql4.Role.User
|
|
1204
|
+
});
|
|
1205
|
+
const response = context.runtimeClient.asStream(
|
|
1206
|
+
context.runtimeClient.generateCopilotResponse({
|
|
1207
|
+
data: {
|
|
1208
|
+
frontend: {
|
|
1209
|
+
actions: [
|
|
1210
|
+
{
|
|
1211
|
+
name: action.name,
|
|
1212
|
+
description: action.description || "",
|
|
1213
|
+
jsonSchema: JSON.stringify((0, import_shared5.actionParametersToJsonSchema)(action.parameters || []))
|
|
1214
|
+
}
|
|
1215
|
+
],
|
|
1216
|
+
url: window.location.href
|
|
1217
|
+
},
|
|
1218
|
+
messages: (0, import_runtime_client_gql5.convertMessagesToGqlInput)(
|
|
1219
|
+
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql5.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1220
|
+
),
|
|
1221
|
+
metadata: {
|
|
1222
|
+
requestType
|
|
1223
|
+
},
|
|
1224
|
+
forwardedParameters: __spreadProps(__spreadValues({}, forwardedParameters != null ? forwardedParameters : {}), {
|
|
1225
|
+
toolChoice: "function",
|
|
1226
|
+
toolChoiceFunctionName: action.name
|
|
1227
|
+
})
|
|
1228
|
+
},
|
|
1229
|
+
properties: context.copilotApiConfig.properties,
|
|
1230
|
+
signal: abortSignal
|
|
1231
|
+
})
|
|
1232
|
+
);
|
|
1233
|
+
const reader = response.getReader();
|
|
1234
|
+
let isInitial = true;
|
|
1235
|
+
let actionExecutionMessage = void 0;
|
|
1236
|
+
while (true) {
|
|
1237
|
+
const { done, value } = yield reader.read();
|
|
1238
|
+
if (done) {
|
|
1239
|
+
break;
|
|
1240
|
+
}
|
|
1241
|
+
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1242
|
+
throw new Error("Aborted");
|
|
1243
|
+
}
|
|
1244
|
+
actionExecutionMessage = (0, import_runtime_client_gql4.convertGqlOutputToMessages)(
|
|
1245
|
+
value.generateCopilotResponse.messages
|
|
1246
|
+
).find((msg) => msg.isActionExecutionMessage());
|
|
1247
|
+
if (!actionExecutionMessage) {
|
|
1248
|
+
continue;
|
|
1249
|
+
}
|
|
1250
|
+
stream == null ? void 0 : stream({
|
|
1251
|
+
status: isInitial ? "initial" : "inProgress",
|
|
1252
|
+
args: actionExecutionMessage.arguments
|
|
1253
|
+
});
|
|
1254
|
+
isInitial = false;
|
|
1255
|
+
}
|
|
1256
|
+
if (!actionExecutionMessage) {
|
|
1257
|
+
throw new Error("extract() failed: No function call occurred");
|
|
1258
|
+
}
|
|
1259
|
+
stream == null ? void 0 : stream({
|
|
1260
|
+
status: "complete",
|
|
1261
|
+
args: actionExecutionMessage.arguments
|
|
1262
|
+
});
|
|
1263
|
+
return actionExecutionMessage.arguments;
|
|
1264
|
+
});
|
|
1265
|
+
}
|
|
1266
|
+
function makeInstructionsMessage(instructions) {
|
|
1267
|
+
return `
|
|
1268
|
+
The user has given you the following task to complete:
|
|
1145
1269
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
function
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1270
|
+
\`\`\`
|
|
1271
|
+
${instructions}
|
|
1272
|
+
\`\`\`
|
|
1273
|
+
|
|
1274
|
+
Any additional messages provided are for providing context only and should not be used to ask questions or engage in conversation.
|
|
1275
|
+
`;
|
|
1276
|
+
}
|
|
1277
|
+
function makeSystemMessage(contextString, instructions) {
|
|
1278
|
+
return `
|
|
1279
|
+
Please act as an efficient, competent, conscientious, and industrious professional assistant.
|
|
1280
|
+
|
|
1281
|
+
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.
|
|
1282
|
+
Always be polite and respectful, and prefer brevity over verbosity.
|
|
1283
|
+
|
|
1284
|
+
The user has provided you with the following context:
|
|
1285
|
+
\`\`\`
|
|
1286
|
+
${contextString}
|
|
1287
|
+
\`\`\`
|
|
1288
|
+
|
|
1289
|
+
They have also provided you with a function called extract you MUST call to initiate actions on their behalf.
|
|
1290
|
+
|
|
1291
|
+
Please assist them as best you can.
|
|
1292
|
+
|
|
1293
|
+
This is not a conversation, so please do not ask questions. Just call the function without saying anything else.
|
|
1294
|
+
`;
|
|
1295
|
+
}
|
|
1296
|
+
|
|
1297
|
+
// src/utils/suggestions.ts
|
|
1298
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1299
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1300
|
+
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1301
|
+
const abortController = abortControllerRef.current;
|
|
1302
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1303
|
+
return;
|
|
1304
|
+
}
|
|
1305
|
+
const setSuggestionsIfNotAborted = (suggestions) => {
|
|
1306
|
+
if (!(abortController == null ? void 0 : abortController.signal.aborted) && abortControllerRef.current === abortController) {
|
|
1307
|
+
setCurrentSuggestions(suggestions);
|
|
1308
|
+
}
|
|
1309
|
+
};
|
|
1310
|
+
try {
|
|
1311
|
+
const tools = JSON.stringify(
|
|
1312
|
+
Object.values(context.actions).map((action) => ({
|
|
1313
|
+
name: action.name,
|
|
1314
|
+
description: action.description,
|
|
1315
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters))
|
|
1316
|
+
}))
|
|
1158
1317
|
);
|
|
1318
|
+
const allSuggestions = [];
|
|
1319
|
+
let hasSuccessfulSuggestions = false;
|
|
1320
|
+
let hasErrors = false;
|
|
1321
|
+
let lastError = null;
|
|
1322
|
+
const enabledConfigs = Object.values(chatSuggestionConfiguration).filter(
|
|
1323
|
+
(config) => config.instructions && config.instructions.trim().length > 0
|
|
1324
|
+
);
|
|
1325
|
+
if (enabledConfigs.length === 0) {
|
|
1326
|
+
return;
|
|
1327
|
+
}
|
|
1328
|
+
setSuggestionsIfNotAborted([]);
|
|
1329
|
+
for (const config of enabledConfigs) {
|
|
1330
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1331
|
+
setSuggestionsIfNotAborted([]);
|
|
1332
|
+
return;
|
|
1333
|
+
}
|
|
1334
|
+
try {
|
|
1335
|
+
const result = yield extract({
|
|
1336
|
+
context,
|
|
1337
|
+
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
1338
|
+
data: `${config.instructions}
|
|
1339
|
+
|
|
1340
|
+
Available tools: ${tools}
|
|
1341
|
+
|
|
1342
|
+
`,
|
|
1343
|
+
requestType: import_runtime_client_gql6.CopilotRequestType.Task,
|
|
1344
|
+
parameters: [
|
|
1345
|
+
{
|
|
1346
|
+
name: "suggestions",
|
|
1347
|
+
type: "object[]",
|
|
1348
|
+
attributes: [
|
|
1349
|
+
{
|
|
1350
|
+
name: "title",
|
|
1351
|
+
description: "The title of the suggestion. This is shown as a button and should be short.",
|
|
1352
|
+
type: "string"
|
|
1353
|
+
},
|
|
1354
|
+
{
|
|
1355
|
+
name: "message",
|
|
1356
|
+
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.",
|
|
1357
|
+
type: "string"
|
|
1358
|
+
}
|
|
1359
|
+
]
|
|
1360
|
+
}
|
|
1361
|
+
],
|
|
1362
|
+
include: {
|
|
1363
|
+
messages: true,
|
|
1364
|
+
readable: true
|
|
1365
|
+
},
|
|
1366
|
+
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
1367
|
+
stream: ({ status, args }) => {
|
|
1368
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1369
|
+
return;
|
|
1370
|
+
}
|
|
1371
|
+
const suggestions = args.suggestions || [];
|
|
1372
|
+
const newSuggestions = [];
|
|
1373
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
1374
|
+
if (config.maxSuggestions !== void 0 && i >= config.maxSuggestions) {
|
|
1375
|
+
break;
|
|
1376
|
+
}
|
|
1377
|
+
const suggestion = suggestions[i];
|
|
1378
|
+
if (!suggestion || typeof suggestion !== "object") {
|
|
1379
|
+
continue;
|
|
1380
|
+
}
|
|
1381
|
+
const { title, message } = suggestion;
|
|
1382
|
+
const hasValidTitle = title && typeof title === "string" && title.trim().length > 0;
|
|
1383
|
+
const hasValidMessage = message && typeof message === "string" && message.trim().length > 0;
|
|
1384
|
+
if (!hasValidTitle) {
|
|
1385
|
+
continue;
|
|
1386
|
+
}
|
|
1387
|
+
const partial = i === suggestions.length - 1 && status !== "complete";
|
|
1388
|
+
newSuggestions.push({
|
|
1389
|
+
title: title.trim(),
|
|
1390
|
+
message: hasValidMessage ? message.trim() : "",
|
|
1391
|
+
// Use title as fallback
|
|
1392
|
+
partial,
|
|
1393
|
+
className: config.className
|
|
1394
|
+
});
|
|
1395
|
+
}
|
|
1396
|
+
setSuggestionsIfNotAborted([...allSuggestions, ...newSuggestions]);
|
|
1397
|
+
}
|
|
1398
|
+
});
|
|
1399
|
+
if ((result == null ? void 0 : result.suggestions) && Array.isArray(result.suggestions)) {
|
|
1400
|
+
const validSuggestions = result.suggestions.filter(
|
|
1401
|
+
(suggestion) => suggestion && typeof suggestion.title === "string" && suggestion.title.trim().length > 0
|
|
1402
|
+
).map((suggestion) => ({
|
|
1403
|
+
title: suggestion.title.trim(),
|
|
1404
|
+
message: suggestion.message && typeof suggestion.message === "string" && suggestion.message.trim() ? suggestion.message.trim() : suggestion.title.trim()
|
|
1405
|
+
}));
|
|
1406
|
+
if (validSuggestions.length > 0) {
|
|
1407
|
+
allSuggestions.push(...validSuggestions);
|
|
1408
|
+
hasSuccessfulSuggestions = true;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
hasErrors = true;
|
|
1413
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
if (hasSuccessfulSuggestions && allSuggestions.length > 0) {
|
|
1417
|
+
const uniqueSuggestions = allSuggestions.filter(
|
|
1418
|
+
(suggestion, index, self) => index === self.findIndex((s) => s.message === suggestion.message)
|
|
1419
|
+
);
|
|
1420
|
+
setSuggestionsIfNotAborted(uniqueSuggestions);
|
|
1421
|
+
} else if (hasErrors) {
|
|
1422
|
+
const errorMessage = lastError ? lastError.message : "Failed to generate suggestions due to API errors";
|
|
1423
|
+
throw new Error(errorMessage);
|
|
1424
|
+
}
|
|
1425
|
+
} catch (error) {
|
|
1426
|
+
throw error;
|
|
1159
1427
|
}
|
|
1160
|
-
|
|
1161
|
-
}
|
|
1428
|
+
});
|
|
1162
1429
|
|
|
1163
1430
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1164
1431
|
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1165
1432
|
var defaultCopilotContextCategories = ["global"];
|
|
1166
1433
|
|
|
1167
1434
|
// src/hooks/use-copilot-chat.ts
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1435
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1436
|
+
|
|
1437
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1438
|
+
var import_react8 = __toESM(require("react"));
|
|
1439
|
+
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1440
|
+
return render({ event, result, resolve });
|
|
1441
|
+
};
|
|
1442
|
+
function useLangGraphInterruptRender() {
|
|
1443
|
+
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1444
|
+
const responseRef = import_react8.default.useRef();
|
|
1445
|
+
const resolveInterrupt = (0, import_react8.useCallback)(
|
|
1446
|
+
(response) => {
|
|
1447
|
+
responseRef.current = response;
|
|
1448
|
+
setTimeout(() => {
|
|
1449
|
+
setLangGraphInterruptAction({ event: { response } });
|
|
1450
|
+
}, 0);
|
|
1451
|
+
},
|
|
1452
|
+
[setLangGraphInterruptAction]
|
|
1453
|
+
);
|
|
1454
|
+
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
1455
|
+
return null;
|
|
1456
|
+
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
1457
|
+
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
1458
|
+
if (!conditionsMet) {
|
|
1459
|
+
return null;
|
|
1460
|
+
}
|
|
1461
|
+
let result = null;
|
|
1462
|
+
if (handler) {
|
|
1463
|
+
result = handler({
|
|
1464
|
+
event,
|
|
1465
|
+
resolve: resolveInterrupt
|
|
1466
|
+
});
|
|
1467
|
+
}
|
|
1468
|
+
return import_react8.default.createElement(InterruptRenderer, {
|
|
1469
|
+
event,
|
|
1470
|
+
result,
|
|
1471
|
+
render,
|
|
1472
|
+
resolve: resolveInterrupt
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
|
|
1476
|
+
// src/hooks/use-copilot-chat.ts
|
|
1477
|
+
var globalSuggestionPromise = null;
|
|
1478
|
+
function useCopilotChat(options = {}) {
|
|
1479
|
+
var _a;
|
|
1480
|
+
const makeSystemMessage2 = (_a = options.makeSystemMessage) != null ? _a : defaultSystemMessage;
|
|
1174
1481
|
const {
|
|
1175
1482
|
getContextString,
|
|
1176
1483
|
getFunctionCallHandler,
|
|
@@ -1194,11 +1501,72 @@ function useCopilotChat(_a = {}) {
|
|
|
1194
1501
|
extensions,
|
|
1195
1502
|
setExtensions,
|
|
1196
1503
|
langGraphInterruptAction,
|
|
1197
|
-
setLangGraphInterruptAction
|
|
1504
|
+
setLangGraphInterruptAction,
|
|
1505
|
+
chatSuggestionConfiguration,
|
|
1506
|
+
suggestions,
|
|
1507
|
+
setSuggestions,
|
|
1508
|
+
runtimeClient
|
|
1198
1509
|
} = useCopilotContext();
|
|
1199
1510
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1200
|
-
const [mcpServers, setLocalMcpServers] = (0,
|
|
1201
|
-
(0,
|
|
1511
|
+
const [mcpServers, setLocalMcpServers] = (0, import_react9.useState)([]);
|
|
1512
|
+
const suggestionsAbortControllerRef = (0, import_react9.useRef)(null);
|
|
1513
|
+
const isLoadingSuggestionsRef = (0, import_react9.useRef)(false);
|
|
1514
|
+
const abortSuggestions = (0, import_react9.useCallback)(
|
|
1515
|
+
(clear = true) => {
|
|
1516
|
+
var _a2;
|
|
1517
|
+
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort("suggestions aborted by user");
|
|
1518
|
+
suggestionsAbortControllerRef.current = null;
|
|
1519
|
+
if (clear) {
|
|
1520
|
+
setSuggestions([]);
|
|
1521
|
+
}
|
|
1522
|
+
},
|
|
1523
|
+
[setSuggestions]
|
|
1524
|
+
);
|
|
1525
|
+
const stableContext = (0, import_react9.useMemo)(() => {
|
|
1526
|
+
return {
|
|
1527
|
+
actions,
|
|
1528
|
+
copilotApiConfig,
|
|
1529
|
+
chatSuggestionConfiguration,
|
|
1530
|
+
messages,
|
|
1531
|
+
setMessages,
|
|
1532
|
+
getContextString,
|
|
1533
|
+
runtimeClient
|
|
1534
|
+
};
|
|
1535
|
+
}, [
|
|
1536
|
+
JSON.stringify(Object.keys(actions)),
|
|
1537
|
+
copilotApiConfig.chatApiEndpoint,
|
|
1538
|
+
messages.length,
|
|
1539
|
+
Object.keys(chatSuggestionConfiguration).length
|
|
1540
|
+
]);
|
|
1541
|
+
const generateSuggestionsFunc = (0, import_react9.useCallback)(() => __async(this, null, function* () {
|
|
1542
|
+
if (globalSuggestionPromise) {
|
|
1543
|
+
return globalSuggestionPromise;
|
|
1544
|
+
}
|
|
1545
|
+
globalSuggestionPromise = (() => __async(this, null, function* () {
|
|
1546
|
+
try {
|
|
1547
|
+
abortSuggestions();
|
|
1548
|
+
isLoadingSuggestionsRef.current = true;
|
|
1549
|
+
suggestionsAbortControllerRef.current = new AbortController();
|
|
1550
|
+
setSuggestions([]);
|
|
1551
|
+
yield reloadSuggestions(
|
|
1552
|
+
stableContext,
|
|
1553
|
+
chatSuggestionConfiguration,
|
|
1554
|
+
setSuggestions,
|
|
1555
|
+
suggestionsAbortControllerRef
|
|
1556
|
+
);
|
|
1557
|
+
} catch (error) {
|
|
1558
|
+
throw error;
|
|
1559
|
+
} finally {
|
|
1560
|
+
isLoadingSuggestionsRef.current = false;
|
|
1561
|
+
globalSuggestionPromise = null;
|
|
1562
|
+
}
|
|
1563
|
+
}))();
|
|
1564
|
+
return globalSuggestionPromise;
|
|
1565
|
+
}), [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);
|
|
1566
|
+
const resetSuggestions = (0, import_react9.useCallback)(() => {
|
|
1567
|
+
setSuggestions([]);
|
|
1568
|
+
}, [setSuggestions]);
|
|
1569
|
+
(0, import_react9.useEffect)(() => {
|
|
1202
1570
|
if (mcpServers.length > 0) {
|
|
1203
1571
|
const serversCopy = [...mcpServers];
|
|
1204
1572
|
copilotApiConfig.mcpServers = serversCopy;
|
|
@@ -1208,7 +1576,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1208
1576
|
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
1209
1577
|
}
|
|
1210
1578
|
}, [mcpServers, copilotApiConfig]);
|
|
1211
|
-
const setMcpServers = (0,
|
|
1579
|
+
const setMcpServers = (0, import_react9.useCallback)((servers) => {
|
|
1212
1580
|
setLocalMcpServers(servers);
|
|
1213
1581
|
}, []);
|
|
1214
1582
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1229,15 +1597,15 @@ function useCopilotChat(_a = {}) {
|
|
|
1229
1597
|
}),
|
|
1230
1598
|
[coAgentStateRenders]
|
|
1231
1599
|
);
|
|
1232
|
-
const makeSystemMessageCallback = (0,
|
|
1233
|
-
const systemMessageMaker =
|
|
1600
|
+
const makeSystemMessageCallback = (0, import_react9.useCallback)(() => {
|
|
1601
|
+
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1234
1602
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
1235
|
-
return new
|
|
1603
|
+
return new import_runtime_client_gql7.TextMessage({
|
|
1236
1604
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1237
|
-
role:
|
|
1605
|
+
role: import_runtime_client_gql7.Role.System
|
|
1238
1606
|
});
|
|
1239
|
-
}, [getContextString,
|
|
1240
|
-
const deleteMessage = (0,
|
|
1607
|
+
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1608
|
+
const deleteMessage = (0, import_react9.useCallback)(
|
|
1241
1609
|
(messageId) => {
|
|
1242
1610
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1243
1611
|
},
|
|
@@ -1246,7 +1614,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1246
1614
|
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1247
1615
|
actions: Object.values(actions),
|
|
1248
1616
|
copilotConfig: copilotApiConfig,
|
|
1249
|
-
initialMessages: options.initialMessages || [],
|
|
1617
|
+
initialMessages: (0, import_runtime_client_gql7.aguiToGQL)(options.initialMessages || []),
|
|
1250
1618
|
onFunctionCall: getFunctionCallHandler(),
|
|
1251
1619
|
onCoAgentStateRender,
|
|
1252
1620
|
messages,
|
|
@@ -1273,7 +1641,8 @@ function useCopilotChat(_a = {}) {
|
|
|
1273
1641
|
const latestAppend = useUpdatedRef(append);
|
|
1274
1642
|
const latestAppendFunc = useAsyncCallback(
|
|
1275
1643
|
(message, options2) => __async(this, null, function* () {
|
|
1276
|
-
|
|
1644
|
+
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1645
|
+
return yield latestAppend.current((0, import_runtime_client_gql7.aguiToGQL)([message])[0], options2);
|
|
1277
1646
|
}),
|
|
1278
1647
|
[latestAppend]
|
|
1279
1648
|
);
|
|
@@ -1285,20 +1654,20 @@ function useCopilotChat(_a = {}) {
|
|
|
1285
1654
|
[latestReload]
|
|
1286
1655
|
);
|
|
1287
1656
|
const latestStop = useUpdatedRef(stop);
|
|
1288
|
-
const latestStopFunc = (0,
|
|
1657
|
+
const latestStopFunc = (0, import_react9.useCallback)(() => {
|
|
1289
1658
|
return latestStop.current();
|
|
1290
1659
|
}, [latestStop]);
|
|
1291
1660
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1292
|
-
const latestDeleteFunc = (0,
|
|
1661
|
+
const latestDeleteFunc = (0, import_react9.useCallback)(
|
|
1293
1662
|
(messageId) => {
|
|
1294
1663
|
return latestDelete.current(messageId);
|
|
1295
1664
|
},
|
|
1296
1665
|
[latestDelete]
|
|
1297
1666
|
);
|
|
1298
1667
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1299
|
-
const latestSetMessagesFunc = (0,
|
|
1668
|
+
const latestSetMessagesFunc = (0, import_react9.useCallback)(
|
|
1300
1669
|
(messages2) => {
|
|
1301
|
-
return latestSetMessages.current(messages2);
|
|
1670
|
+
return latestSetMessages.current((0, import_runtime_client_gql7.aguiToGQL)(messages2));
|
|
1302
1671
|
},
|
|
1303
1672
|
[latestSetMessages]
|
|
1304
1673
|
);
|
|
@@ -1306,7 +1675,7 @@ function useCopilotChat(_a = {}) {
|
|
|
1306
1675
|
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1307
1676
|
return yield latestRunChatCompletion.current();
|
|
1308
1677
|
}), [latestRunChatCompletion]);
|
|
1309
|
-
const reset = (0,
|
|
1678
|
+
const reset = (0, import_react9.useCallback)(() => {
|
|
1310
1679
|
latestStopFunc();
|
|
1311
1680
|
setMessages([]);
|
|
1312
1681
|
setRunId(null);
|
|
@@ -1318,20 +1687,23 @@ function useCopilotChat(_a = {}) {
|
|
|
1318
1687
|
};
|
|
1319
1688
|
}
|
|
1320
1689
|
setAgentSession(initialAgentSession);
|
|
1690
|
+
resetSuggestions();
|
|
1321
1691
|
}, [
|
|
1322
1692
|
latestStopFunc,
|
|
1323
1693
|
setMessages,
|
|
1324
1694
|
setThreadId,
|
|
1325
1695
|
setCoagentStatesWithRef,
|
|
1326
1696
|
setAgentSession,
|
|
1327
|
-
agentLock
|
|
1697
|
+
agentLock,
|
|
1698
|
+
resetSuggestions
|
|
1328
1699
|
]);
|
|
1329
1700
|
const latestReset = useUpdatedRef(reset);
|
|
1330
|
-
const latestResetFunc = (0,
|
|
1701
|
+
const latestResetFunc = (0, import_react9.useCallback)(() => {
|
|
1331
1702
|
return latestReset.current();
|
|
1332
1703
|
}, [latestReset]);
|
|
1704
|
+
const interrupt = useLangGraphInterruptRender();
|
|
1333
1705
|
return {
|
|
1334
|
-
visibleMessages: messages,
|
|
1706
|
+
visibleMessages: (0, import_runtime_client_gql7.gqlToAGUI)(messages, actions, coAgentStateRenders),
|
|
1335
1707
|
appendMessage: latestAppendFunc,
|
|
1336
1708
|
setMessages: latestSetMessagesFunc,
|
|
1337
1709
|
reloadMessages: latestReloadFunc,
|
|
@@ -1341,12 +1713,18 @@ function useCopilotChat(_a = {}) {
|
|
|
1341
1713
|
runChatCompletion: latestRunChatCompletionFunc,
|
|
1342
1714
|
isLoading,
|
|
1343
1715
|
mcpServers,
|
|
1344
|
-
setMcpServers
|
|
1716
|
+
setMcpServers,
|
|
1717
|
+
suggestions,
|
|
1718
|
+
setSuggestions,
|
|
1719
|
+
generateSuggestions: generateSuggestionsFunc,
|
|
1720
|
+
resetSuggestions,
|
|
1721
|
+
isLoadingSuggestions: isLoadingSuggestionsRef.current,
|
|
1722
|
+
interrupt
|
|
1345
1723
|
};
|
|
1346
1724
|
}
|
|
1347
1725
|
function useUpdatedRef(value) {
|
|
1348
|
-
const ref = (0,
|
|
1349
|
-
(0,
|
|
1726
|
+
const ref = (0, import_react9.useRef)(value);
|
|
1727
|
+
(0, import_react9.useEffect)(() => {
|
|
1350
1728
|
ref.current = value;
|
|
1351
1729
|
}, [value]);
|
|
1352
1730
|
return ref;
|
|
@@ -1379,13 +1757,13 @@ ${additionalInstructions}` : "");
|
|
|
1379
1757
|
}
|
|
1380
1758
|
|
|
1381
1759
|
// src/hooks/use-copilot-action.ts
|
|
1382
|
-
var
|
|
1383
|
-
var
|
|
1760
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1761
|
+
var import_react10 = require("react");
|
|
1384
1762
|
function useCopilotAction(action, dependencies) {
|
|
1385
1763
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1386
|
-
const idRef = (0,
|
|
1387
|
-
const renderAndWaitRef = (0,
|
|
1388
|
-
const activatingMessageIdRef = (0,
|
|
1764
|
+
const idRef = (0, import_react10.useRef)((0, import_shared8.randomId)());
|
|
1765
|
+
const renderAndWaitRef = (0, import_react10.useRef)(null);
|
|
1766
|
+
const activatingMessageIdRef = (0, import_react10.useRef)(null);
|
|
1389
1767
|
const { addToast } = useToast();
|
|
1390
1768
|
action = __spreadValues({}, action);
|
|
1391
1769
|
if (
|
|
@@ -1447,7 +1825,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1447
1825
|
return renderAndWait(waitProps);
|
|
1448
1826
|
}
|
|
1449
1827
|
}
|
|
1450
|
-
return (0,
|
|
1828
|
+
return (0, import_react10.createElement)(import_react10.Fragment);
|
|
1451
1829
|
};
|
|
1452
1830
|
}
|
|
1453
1831
|
if (dependencies === void 0) {
|
|
@@ -1462,7 +1840,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1462
1840
|
}
|
|
1463
1841
|
}
|
|
1464
1842
|
}
|
|
1465
|
-
(0,
|
|
1843
|
+
(0, import_react10.useEffect)(() => {
|
|
1466
1844
|
const hasDuplicate = Object.values(actions).some(
|
|
1467
1845
|
(otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current]
|
|
1468
1846
|
);
|
|
@@ -1474,7 +1852,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1474
1852
|
});
|
|
1475
1853
|
}
|
|
1476
1854
|
}, [actions]);
|
|
1477
|
-
(0,
|
|
1855
|
+
(0, import_react10.useEffect)(() => {
|
|
1478
1856
|
setAction(idRef.current, action);
|
|
1479
1857
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1480
1858
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1503,8 +1881,8 @@ function isFrontendAction(action) {
|
|
|
1503
1881
|
}
|
|
1504
1882
|
|
|
1505
1883
|
// src/hooks/use-coagent-state-render.ts
|
|
1506
|
-
var
|
|
1507
|
-
var
|
|
1884
|
+
var import_react11 = require("react");
|
|
1885
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1508
1886
|
function useCoAgentStateRender(action, dependencies) {
|
|
1509
1887
|
const {
|
|
1510
1888
|
setCoAgentStateRender,
|
|
@@ -1512,13 +1890,13 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1512
1890
|
coAgentStateRenders,
|
|
1513
1891
|
chatComponentsCache,
|
|
1514
1892
|
availableAgents
|
|
1515
|
-
} = (0,
|
|
1516
|
-
const idRef = (0,
|
|
1893
|
+
} = (0, import_react11.useContext)(CopilotContext);
|
|
1894
|
+
const idRef = (0, import_react11.useRef)((0, import_shared9.randomId)());
|
|
1517
1895
|
const { setBannerError, addToast } = useToast();
|
|
1518
|
-
(0,
|
|
1896
|
+
(0, import_react11.useEffect)(() => {
|
|
1519
1897
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
1520
1898
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
1521
|
-
const agentError = new
|
|
1899
|
+
const agentError = new import_shared9.CopilotKitAgentDiscoveryError({
|
|
1522
1900
|
agentName: action.name,
|
|
1523
1901
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
1524
1902
|
});
|
|
@@ -1536,7 +1914,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1536
1914
|
}
|
|
1537
1915
|
}
|
|
1538
1916
|
}
|
|
1539
|
-
(0,
|
|
1917
|
+
(0, import_react11.useEffect)(() => {
|
|
1540
1918
|
const currentId = idRef.current;
|
|
1541
1919
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
1542
1920
|
if (id === currentId)
|
|
@@ -1560,7 +1938,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1560
1938
|
});
|
|
1561
1939
|
}
|
|
1562
1940
|
}, [coAgentStateRenders]);
|
|
1563
|
-
(0,
|
|
1941
|
+
(0, import_react11.useEffect)(() => {
|
|
1564
1942
|
setCoAgentStateRender(idRef.current, action);
|
|
1565
1943
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1566
1944
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -1580,11 +1958,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1580
1958
|
}
|
|
1581
1959
|
|
|
1582
1960
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1583
|
-
var
|
|
1961
|
+
var import_react12 = require("react");
|
|
1584
1962
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1585
1963
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1586
|
-
const idRef = (0,
|
|
1587
|
-
(0,
|
|
1964
|
+
const idRef = (0, import_react12.useRef)();
|
|
1965
|
+
(0, import_react12.useEffect)(() => {
|
|
1588
1966
|
const id = addDocumentContext(document, categories);
|
|
1589
1967
|
idRef.current = id;
|
|
1590
1968
|
return () => {
|
|
@@ -1595,7 +1973,7 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1595
1973
|
}
|
|
1596
1974
|
|
|
1597
1975
|
// src/hooks/use-copilot-readable.ts
|
|
1598
|
-
var
|
|
1976
|
+
var import_react13 = require("react");
|
|
1599
1977
|
function convertToJSON(description, value) {
|
|
1600
1978
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1601
1979
|
}
|
|
@@ -1608,10 +1986,10 @@ function useCopilotReadable({
|
|
|
1608
1986
|
available = "enabled"
|
|
1609
1987
|
}, dependencies) {
|
|
1610
1988
|
const { addContext, removeContext } = useCopilotContext();
|
|
1611
|
-
const idRef = (0,
|
|
1989
|
+
const idRef = (0, import_react13.useRef)();
|
|
1612
1990
|
convert = convert || convertToJSON;
|
|
1613
1991
|
const information = convert(description, value);
|
|
1614
|
-
(0,
|
|
1992
|
+
(0, import_react13.useEffect)(() => {
|
|
1615
1993
|
if (available === "disabled")
|
|
1616
1994
|
return;
|
|
1617
1995
|
const id = addContext(information, parentId, categories);
|
|
@@ -1624,20 +2002,20 @@ function useCopilotReadable({
|
|
|
1624
2002
|
}
|
|
1625
2003
|
|
|
1626
2004
|
// src/hooks/use-coagent.ts
|
|
1627
|
-
var
|
|
1628
|
-
var
|
|
2005
|
+
var import_react14 = require("react");
|
|
2006
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1629
2007
|
function useCoAgent(options) {
|
|
1630
2008
|
const generalContext = useCopilotContext();
|
|
1631
2009
|
const { availableAgents } = generalContext;
|
|
1632
2010
|
const { setBannerError } = useToast();
|
|
1633
|
-
const lastLoadedThreadId = (0,
|
|
1634
|
-
const lastLoadedState = (0,
|
|
2011
|
+
const lastLoadedThreadId = (0, import_react14.useRef)();
|
|
2012
|
+
const lastLoadedState = (0, import_react14.useRef)();
|
|
1635
2013
|
const { name } = options;
|
|
1636
|
-
(0,
|
|
2014
|
+
(0, import_react14.useEffect)(() => {
|
|
1637
2015
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
1638
2016
|
const message = `(useCoAgent): Agent "${name}" not found. Make sure the agent exists and is properly configured.`;
|
|
1639
2017
|
console.warn(message);
|
|
1640
|
-
const agentError = new
|
|
2018
|
+
const agentError = new import_shared10.CopilotKitAgentDiscoveryError({
|
|
1641
2019
|
agentName: name,
|
|
1642
2020
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
1643
2021
|
});
|
|
@@ -1656,7 +2034,7 @@ function useCoAgent(options) {
|
|
|
1656
2034
|
credentials: copilotApiConfig.credentials,
|
|
1657
2035
|
showDevConsole: context.showDevConsole
|
|
1658
2036
|
});
|
|
1659
|
-
const setState = (0,
|
|
2037
|
+
const setState = (0, import_react14.useCallback)(
|
|
1660
2038
|
(newState) => {
|
|
1661
2039
|
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
1662
2040
|
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
@@ -1668,7 +2046,7 @@ function useCoAgent(options) {
|
|
|
1668
2046
|
},
|
|
1669
2047
|
[coagentStates, name]
|
|
1670
2048
|
);
|
|
1671
|
-
(0,
|
|
2049
|
+
(0, import_react14.useEffect)(() => {
|
|
1672
2050
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
1673
2051
|
var _a, _b, _c, _d;
|
|
1674
2052
|
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
@@ -1686,13 +2064,13 @@ function useCoAgent(options) {
|
|
|
1686
2064
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
1687
2065
|
lastLoadedState.current = newState;
|
|
1688
2066
|
lastLoadedThreadId.current = threadId;
|
|
1689
|
-
const fetchedState = (0,
|
|
2067
|
+
const fetchedState = (0, import_shared10.parseJson)(newState, {});
|
|
1690
2068
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
1691
2069
|
}
|
|
1692
2070
|
});
|
|
1693
2071
|
void fetchAgentState();
|
|
1694
2072
|
}, [threadId]);
|
|
1695
|
-
(0,
|
|
2073
|
+
(0, import_react14.useEffect)(() => {
|
|
1696
2074
|
if (isExternalStateManagement(options)) {
|
|
1697
2075
|
setState(options.state);
|
|
1698
2076
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -1703,7 +2081,7 @@ function useCoAgent(options) {
|
|
|
1703
2081
|
// reset initialstate on reset
|
|
1704
2082
|
coagentStates[name] === void 0
|
|
1705
2083
|
]);
|
|
1706
|
-
(0,
|
|
2084
|
+
(0, import_react14.useEffect)(() => {
|
|
1707
2085
|
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
1708
2086
|
if (newConfig === void 0)
|
|
1709
2087
|
return;
|
|
@@ -1735,7 +2113,7 @@ function useCoAgent(options) {
|
|
|
1735
2113
|
}),
|
|
1736
2114
|
[name, context, appendMessage, runChatCompletion]
|
|
1737
2115
|
);
|
|
1738
|
-
return (0,
|
|
2116
|
+
return (0, import_react14.useMemo)(() => {
|
|
1739
2117
|
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
1740
2118
|
return {
|
|
1741
2119
|
name,
|
|
@@ -1832,28 +2210,28 @@ var getCoagentState = ({
|
|
|
1832
2210
|
};
|
|
1833
2211
|
|
|
1834
2212
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
1835
|
-
var
|
|
1836
|
-
var
|
|
2213
|
+
var import_react15 = require("react");
|
|
2214
|
+
var import_react16 = __toESM(require("react"));
|
|
1837
2215
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
1838
2216
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
1839
|
-
const pendingActionRef = (0,
|
|
1840
|
-
const executeAction2 = (0,
|
|
2217
|
+
const pendingActionRef = (0, import_react15.useRef)(null);
|
|
2218
|
+
const executeAction2 = (0, import_react15.useCallback)(
|
|
1841
2219
|
(props) => {
|
|
1842
2220
|
if (typeof action.render === "function") {
|
|
1843
2221
|
return action.render(props);
|
|
1844
2222
|
}
|
|
1845
|
-
return action.render ||
|
|
2223
|
+
return action.render || import_react16.default.createElement(import_react15.Fragment);
|
|
1846
2224
|
},
|
|
1847
2225
|
[action]
|
|
1848
2226
|
);
|
|
1849
|
-
const wrappedRender = (0,
|
|
2227
|
+
const wrappedRender = (0, import_react15.useCallback)(
|
|
1850
2228
|
(props) => {
|
|
1851
2229
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
1852
2230
|
(state) => state.status === "authenticated"
|
|
1853
2231
|
);
|
|
1854
2232
|
if (!isAuthenticated) {
|
|
1855
2233
|
pendingActionRef.current = props;
|
|
1856
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
2234
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react16.default.createElement(authConfig_c.SignInComponent, {
|
|
1857
2235
|
onSignInComplete: (authState) => {
|
|
1858
2236
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
1859
2237
|
if (pendingActionRef.current) {
|
|
@@ -1861,7 +2239,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
1861
2239
|
pendingActionRef.current = null;
|
|
1862
2240
|
}
|
|
1863
2241
|
}
|
|
1864
|
-
}) :
|
|
2242
|
+
}) : import_react16.default.createElement(import_react15.Fragment);
|
|
1865
2243
|
}
|
|
1866
2244
|
return executeAction2(props);
|
|
1867
2245
|
},
|
|
@@ -1876,29 +2254,29 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
1876
2254
|
}
|
|
1877
2255
|
|
|
1878
2256
|
// src/hooks/use-langgraph-interrupt.ts
|
|
1879
|
-
var
|
|
1880
|
-
var
|
|
2257
|
+
var import_react17 = require("react");
|
|
2258
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1881
2259
|
function useLangGraphInterrupt(action, dependencies) {
|
|
1882
2260
|
var _a;
|
|
1883
|
-
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0,
|
|
2261
|
+
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react17.useContext)(CopilotContext);
|
|
1884
2262
|
const { runChatCompletion } = useCopilotChat();
|
|
1885
2263
|
const { addToast } = useToast();
|
|
1886
|
-
const actionId = (0,
|
|
1887
|
-
const hasAction = (0,
|
|
2264
|
+
const actionId = (0, import_shared11.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
2265
|
+
const hasAction = (0, import_react17.useMemo)(
|
|
1888
2266
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
1889
2267
|
[langGraphInterruptAction]
|
|
1890
2268
|
);
|
|
1891
|
-
const isCurrentAction = (0,
|
|
2269
|
+
const isCurrentAction = (0, import_react17.useMemo)(
|
|
1892
2270
|
() => (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) && (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) === actionId,
|
|
1893
2271
|
[langGraphInterruptAction]
|
|
1894
2272
|
);
|
|
1895
|
-
(0,
|
|
2273
|
+
(0, import_react17.useEffect)(() => {
|
|
1896
2274
|
var _a2;
|
|
1897
2275
|
if (hasAction && isCurrentAction && ((_a2 = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a2.response)) {
|
|
1898
2276
|
runChatCompletion();
|
|
1899
2277
|
}
|
|
1900
2278
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
1901
|
-
(0,
|
|
2279
|
+
(0, import_react17.useEffect)(() => {
|
|
1902
2280
|
if (!action)
|
|
1903
2281
|
return;
|
|
1904
2282
|
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
@@ -1922,45 +2300,6 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
1922
2300
|
]);
|
|
1923
2301
|
}
|
|
1924
2302
|
|
|
1925
|
-
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1926
|
-
var import_react17 = __toESM(require("react"));
|
|
1927
|
-
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1928
|
-
return render({ event, result, resolve });
|
|
1929
|
-
};
|
|
1930
|
-
function useLangGraphInterruptRender() {
|
|
1931
|
-
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1932
|
-
const responseRef = import_react17.default.useRef();
|
|
1933
|
-
const resolveInterrupt = (0, import_react17.useCallback)(
|
|
1934
|
-
(response) => {
|
|
1935
|
-
responseRef.current = response;
|
|
1936
|
-
setTimeout(() => {
|
|
1937
|
-
setLangGraphInterruptAction({ event: { response } });
|
|
1938
|
-
}, 0);
|
|
1939
|
-
},
|
|
1940
|
-
[setLangGraphInterruptAction]
|
|
1941
|
-
);
|
|
1942
|
-
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
1943
|
-
return null;
|
|
1944
|
-
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
1945
|
-
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
1946
|
-
if (!conditionsMet) {
|
|
1947
|
-
return null;
|
|
1948
|
-
}
|
|
1949
|
-
let result = null;
|
|
1950
|
-
if (handler) {
|
|
1951
|
-
result = handler({
|
|
1952
|
-
event,
|
|
1953
|
-
resolve: resolveInterrupt
|
|
1954
|
-
});
|
|
1955
|
-
}
|
|
1956
|
-
return import_react17.default.createElement(InterruptRenderer, {
|
|
1957
|
-
event,
|
|
1958
|
-
result,
|
|
1959
|
-
render,
|
|
1960
|
-
resolve: resolveInterrupt
|
|
1961
|
-
});
|
|
1962
|
-
}
|
|
1963
|
-
|
|
1964
2303
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
1965
2304
|
var import_react18 = require("react");
|
|
1966
2305
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|