@copilotkit/react-core 1.10.0-next.7 → 1.10.0-next.8
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 +8 -0
- package/dist/{chunk-57MBVQPX.mjs → chunk-3RHHNUVV.mjs} +2 -2
- package/dist/{chunk-AC2GVFW6.mjs → chunk-6EKLRL7B.mjs} +2 -2
- package/dist/{chunk-EQQSE6KM.mjs → chunk-CLMDRYEN.mjs} +2 -2
- package/dist/{chunk-CZWJ4VJG.mjs → chunk-FTP6FDYS.mjs} +5 -5
- package/dist/{chunk-SMLWBM4N.mjs → chunk-GEKWHETN.mjs} +4 -4
- package/dist/{chunk-XGRBVNW2.mjs → chunk-GRCHDHC4.mjs} +11 -13
- package/dist/chunk-GRCHDHC4.mjs.map +1 -0
- package/dist/{chunk-OL3VRQKU.mjs → chunk-IN7GE4NO.mjs} +2 -2
- package/dist/{chunk-KTD5U4PK.mjs → chunk-K4HXT453.mjs} +3 -3
- package/dist/{chunk-X7ETNW3P.mjs → chunk-KH27ZS4Y.mjs} +7 -7
- package/dist/{chunk-4NR26FFD.mjs → chunk-MUDXTKXE.mjs} +43 -9
- package/dist/chunk-MUDXTKXE.mjs.map +1 -0
- package/dist/{chunk-5RPZ4T2V.mjs → chunk-MWHILKQH.mjs} +2 -2
- package/dist/{chunk-PH6RVMFU.mjs → chunk-OPRDTF4S.mjs} +4 -4
- package/dist/{chunk-TUPJR242.mjs → chunk-PHIMGB3K.mjs} +13 -15
- package/dist/chunk-PHIMGB3K.mjs.map +1 -0
- package/dist/{chunk-47GMU44Z.mjs → chunk-TEMLWRRT.mjs} +1 -4
- package/dist/{chunk-47GMU44Z.mjs.map → chunk-TEMLWRRT.mjs.map} +1 -1
- package/dist/{chunk-32JPCD6C.mjs → chunk-TTI4Z6GK.mjs} +16 -17
- package/dist/chunk-TTI4Z6GK.mjs.map +1 -0
- package/dist/{chunk-A3QJUCBZ.mjs → chunk-VH45SC6Z.mjs} +4 -4
- package/dist/{chunk-BJ7N5YF5.mjs → chunk-VSH4JSN3.mjs} +3 -3
- package/dist/{chunk-DCTJZ742.mjs → chunk-ZLQVRPDS.mjs} +5 -2
- package/dist/chunk-ZLQVRPDS.mjs.map +1 -0
- package/dist/{chunk-U6JSCZCE.mjs → chunk-ZTZJIDRJ.mjs} +4 -4
- package/dist/components/copilot-provider/copilot-messages.d.ts +17 -1
- package/dist/components/copilot-provider/copilot-messages.js +35 -7
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +9 -5
- package/dist/components/copilot-provider/copilotkit-props.d.ts +1 -2
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
- package/dist/components/copilot-provider/copilotkit.js +30 -9
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +8 -8
- package/dist/components/copilot-provider/index.d.ts +1 -2
- package/dist/components/copilot-provider/index.js +30 -9
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +8 -8
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/index.d.ts +1 -2
- package/dist/components/index.js +30 -9
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +8 -8
- package/dist/context/copilot-context.d.ts +1 -2
- package/dist/context/copilot-context.js +0 -3
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/copilot-messages-context.d.ts +11 -15
- package/dist/context/copilot-messages-context.js +4 -1
- package/dist/context/copilot-messages-context.js.map +1 -1
- package/dist/context/copilot-messages-context.mjs +1 -1
- package/dist/context/index.d.ts +2 -2
- package/dist/context/index.js +4 -4
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +5 -5
- package/dist/{copilot-context-78fc727c.d.ts → copilot-context-256f9020.d.ts} +1 -21
- package/dist/hooks/index.d.ts +3 -3
- package/dist/hooks/index.js +133 -123
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +32 -32
- package/dist/hooks/use-chat.d.ts +1 -2
- package/dist/hooks/use-chat.js +0 -3
- 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 +0 -3
- 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 -4
- package/dist/hooks/use-coagent.js +85 -75
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +14 -14
- package/dist/hooks/use-copilot-action.js +0 -3
- 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 +0 -3
- 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 +0 -3
- 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-light.d.ts +3 -3
- package/dist/hooks/use-copilot-chat-light.js +5 -7
- package/dist/hooks/use-copilot-chat-light.js.map +1 -1
- package/dist/hooks/use-copilot-chat-light.mjs +14 -14
- package/dist/hooks/use-copilot-chat.d.ts +2 -2
- package/dist/hooks/use-copilot-chat.js +5 -7
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +14 -14
- package/dist/hooks/use-copilot-chat_internal.d.ts +3 -3
- package/dist/hooks/use-copilot-chat_internal.js +5 -7
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -1
- package/dist/hooks/use-copilot-chat_internal.mjs +13 -13
- package/dist/hooks/use-copilot-readable.js +0 -3
- 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 +0 -3
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +3 -3
- package/dist/hooks/use-langgraph-interrupt.d.ts +3 -4
- package/dist/hooks/use-langgraph-interrupt.js +5 -7
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +14 -14
- package/dist/hooks/use-make-copilot-document-readable.js +0 -3
- 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-08c43df1.d.ts +36 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +38 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -37
- package/dist/lib/copilot-task.d.ts +1 -2
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +10 -10
- package/dist/lib/index.d.ts +1 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +10 -10
- package/dist/types/interrupt-action.d.ts +2 -3
- package/dist/utils/extract.d.ts +2 -2
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +8 -8
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +8 -8
- package/dist/utils/suggestions.d.ts +2 -2
- package/dist/utils/suggestions.js.map +1 -1
- package/dist/utils/suggestions.mjs +8 -8
- package/package.json +3 -3
- package/src/components/copilot-provider/copilot-messages.tsx +57 -1
- package/src/components/copilot-provider/copilotkit.tsx +4 -5
- package/src/context/copilot-context.tsx +0 -5
- package/src/context/copilot-messages-context.tsx +7 -1
- package/src/hooks/__tests__/use-coagent-config.test.ts +7 -0
- package/src/hooks/use-coagent.ts +11 -8
- package/src/hooks/use-copilot-chat_internal.ts +2 -3
- package/dist/chunk-32JPCD6C.mjs.map +0 -1
- package/dist/chunk-4NR26FFD.mjs.map +0 -1
- package/dist/chunk-DCTJZ742.mjs.map +0 -1
- package/dist/chunk-TUPJR242.mjs.map +0 -1
- package/dist/chunk-XGRBVNW2.mjs.map +0 -1
- /package/dist/{chunk-57MBVQPX.mjs.map → chunk-3RHHNUVV.mjs.map} +0 -0
- /package/dist/{chunk-AC2GVFW6.mjs.map → chunk-6EKLRL7B.mjs.map} +0 -0
- /package/dist/{chunk-EQQSE6KM.mjs.map → chunk-CLMDRYEN.mjs.map} +0 -0
- /package/dist/{chunk-CZWJ4VJG.mjs.map → chunk-FTP6FDYS.mjs.map} +0 -0
- /package/dist/{chunk-SMLWBM4N.mjs.map → chunk-GEKWHETN.mjs.map} +0 -0
- /package/dist/{chunk-OL3VRQKU.mjs.map → chunk-IN7GE4NO.mjs.map} +0 -0
- /package/dist/{chunk-KTD5U4PK.mjs.map → chunk-K4HXT453.mjs.map} +0 -0
- /package/dist/{chunk-X7ETNW3P.mjs.map → chunk-KH27ZS4Y.mjs.map} +0 -0
- /package/dist/{chunk-5RPZ4T2V.mjs.map → chunk-MWHILKQH.mjs.map} +0 -0
- /package/dist/{chunk-PH6RVMFU.mjs.map → chunk-OPRDTF4S.mjs.map} +0 -0
- /package/dist/{chunk-A3QJUCBZ.mjs.map → chunk-VH45SC6Z.mjs.map} +0 -0
- /package/dist/{chunk-BJ7N5YF5.mjs.map → chunk-VSH4JSN3.mjs.map} +0 -0
- /package/dist/{chunk-U6JSCZCE.mjs.map → chunk-ZTZJIDRJ.mjs.map} +0 -0
|
@@ -85,7 +85,7 @@ __export(use_coagent_exports, {
|
|
|
85
85
|
useCoAgent: () => useCoAgent
|
|
86
86
|
});
|
|
87
87
|
module.exports = __toCommonJS(use_coagent_exports);
|
|
88
|
-
var
|
|
88
|
+
var import_react11 = require("react");
|
|
89
89
|
|
|
90
90
|
// src/context/copilot-context.tsx
|
|
91
91
|
var import_react = __toESM(require("react"));
|
|
@@ -162,11 +162,8 @@ var emptyCopilotContext = {
|
|
|
162
162
|
setLangGraphInterruptAction: () => null,
|
|
163
163
|
removeLangGraphInterruptAction: () => null,
|
|
164
164
|
onError: void 0,
|
|
165
|
-
suggestions: [],
|
|
166
165
|
bannerError: null,
|
|
167
166
|
setBannerError: () => {
|
|
168
|
-
},
|
|
169
|
-
setSuggestions: () => {
|
|
170
167
|
}
|
|
171
168
|
};
|
|
172
169
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
@@ -185,7 +182,10 @@ function returnAndThrowInDebug(_value) {
|
|
|
185
182
|
var import_react2 = __toESM(require("react"));
|
|
186
183
|
var emptyCopilotContext2 = {
|
|
187
184
|
messages: [],
|
|
188
|
-
setMessages: () => []
|
|
185
|
+
setMessages: () => [],
|
|
186
|
+
// suggestions state
|
|
187
|
+
suggestions: [],
|
|
188
|
+
setSuggestions: () => []
|
|
189
189
|
};
|
|
190
190
|
var CopilotMessagesContext = import_react2.default.createContext(emptyCopilotContext2);
|
|
191
191
|
function useCopilotMessagesContext() {
|
|
@@ -199,7 +199,7 @@ function useCopilotMessagesContext() {
|
|
|
199
199
|
}
|
|
200
200
|
|
|
201
201
|
// src/hooks/use-copilot-chat_internal.ts
|
|
202
|
-
var
|
|
202
|
+
var import_react10 = require("react");
|
|
203
203
|
|
|
204
204
|
// src/hooks/use-chat.ts
|
|
205
205
|
var import_react6 = require("react");
|
|
@@ -1158,14 +1158,27 @@ function getPairedFeAction(actions, message) {
|
|
|
1158
1158
|
}
|
|
1159
1159
|
|
|
1160
1160
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1161
|
-
var
|
|
1161
|
+
var import_react8 = require("react");
|
|
1162
1162
|
var import_react_dom2 = require("react-dom");
|
|
1163
|
-
var
|
|
1163
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1164
1164
|
|
|
1165
|
-
// src/
|
|
1166
|
-
var
|
|
1165
|
+
// src/components/copilot-provider/copilot-messages.tsx
|
|
1166
|
+
var import_react7 = require("react");
|
|
1167
1167
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1168
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1169
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1170
|
+
var MessagesTapContext = (0, import_react7.createContext)(null);
|
|
1171
|
+
function useMessagesTap() {
|
|
1172
|
+
const tap = (0, import_react7.useContext)(MessagesTapContext);
|
|
1173
|
+
if (!tap)
|
|
1174
|
+
throw new Error("useMessagesTap must be used inside <MessagesTapProvider>");
|
|
1175
|
+
return tap;
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
// src/utils/extract.ts
|
|
1179
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1168
1180
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1181
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1169
1182
|
function extract(_0) {
|
|
1170
1183
|
return __async(this, arguments, function* ({
|
|
1171
1184
|
context,
|
|
@@ -1175,7 +1188,7 @@ function extract(_0) {
|
|
|
1175
1188
|
data,
|
|
1176
1189
|
abortSignal,
|
|
1177
1190
|
stream,
|
|
1178
|
-
requestType =
|
|
1191
|
+
requestType = import_runtime_client_gql5.CopilotRequestType.Task,
|
|
1179
1192
|
forwardedParameters
|
|
1180
1193
|
}) {
|
|
1181
1194
|
var _a, _b;
|
|
@@ -1196,13 +1209,13 @@ function extract(_0) {
|
|
|
1196
1209
|
if (includeReadable) {
|
|
1197
1210
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1198
1211
|
}
|
|
1199
|
-
const systemMessage = new
|
|
1212
|
+
const systemMessage = new import_runtime_client_gql5.TextMessage({
|
|
1200
1213
|
content: makeSystemMessage(contextString, instructions),
|
|
1201
|
-
role:
|
|
1214
|
+
role: import_runtime_client_gql5.Role.System
|
|
1202
1215
|
});
|
|
1203
|
-
const instructionsMessage = new
|
|
1216
|
+
const instructionsMessage = new import_runtime_client_gql5.TextMessage({
|
|
1204
1217
|
content: makeInstructionsMessage(instructions),
|
|
1205
|
-
role:
|
|
1218
|
+
role: import_runtime_client_gql5.Role.User
|
|
1206
1219
|
});
|
|
1207
1220
|
const response = context.runtimeClient.asStream(
|
|
1208
1221
|
context.runtimeClient.generateCopilotResponse({
|
|
@@ -1212,13 +1225,13 @@ function extract(_0) {
|
|
|
1212
1225
|
{
|
|
1213
1226
|
name: action.name,
|
|
1214
1227
|
description: action.description || "",
|
|
1215
|
-
jsonSchema: JSON.stringify((0,
|
|
1228
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters || []))
|
|
1216
1229
|
}
|
|
1217
1230
|
],
|
|
1218
1231
|
url: window.location.href
|
|
1219
1232
|
},
|
|
1220
|
-
messages: (0,
|
|
1221
|
-
includeMessages ? [systemMessage, instructionsMessage, ...(0,
|
|
1233
|
+
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)(
|
|
1234
|
+
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql6.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1222
1235
|
),
|
|
1223
1236
|
metadata: {
|
|
1224
1237
|
requestType
|
|
@@ -1243,7 +1256,7 @@ function extract(_0) {
|
|
|
1243
1256
|
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1244
1257
|
throw new Error("Aborted");
|
|
1245
1258
|
}
|
|
1246
|
-
actionExecutionMessage = (0,
|
|
1259
|
+
actionExecutionMessage = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
|
|
1247
1260
|
value.generateCopilotResponse.messages
|
|
1248
1261
|
).find((msg) => msg.isActionExecutionMessage());
|
|
1249
1262
|
if (!actionExecutionMessage) {
|
|
@@ -1297,8 +1310,8 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1297
1310
|
}
|
|
1298
1311
|
|
|
1299
1312
|
// src/utils/suggestions.ts
|
|
1300
|
-
var
|
|
1301
|
-
var
|
|
1313
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1314
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1302
1315
|
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1303
1316
|
const abortController = abortControllerRef.current;
|
|
1304
1317
|
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
@@ -1314,7 +1327,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1314
1327
|
Object.values(context.actions).map((action) => ({
|
|
1315
1328
|
name: action.name,
|
|
1316
1329
|
description: action.description,
|
|
1317
|
-
jsonSchema: JSON.stringify((0,
|
|
1330
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters))
|
|
1318
1331
|
}))
|
|
1319
1332
|
);
|
|
1320
1333
|
const allSuggestions = [];
|
|
@@ -1342,7 +1355,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1342
1355
|
Available tools: ${tools}
|
|
1343
1356
|
|
|
1344
1357
|
`,
|
|
1345
|
-
requestType:
|
|
1358
|
+
requestType: import_runtime_client_gql7.CopilotRequestType.Task,
|
|
1346
1359
|
parameters: [
|
|
1347
1360
|
{
|
|
1348
1361
|
name: "suggestions",
|
|
@@ -1430,21 +1443,21 @@ Available tools: ${tools}
|
|
|
1430
1443
|
});
|
|
1431
1444
|
|
|
1432
1445
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1433
|
-
var
|
|
1446
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1434
1447
|
var defaultCopilotContextCategories = ["global"];
|
|
1435
1448
|
|
|
1436
1449
|
// src/hooks/use-copilot-chat_internal.ts
|
|
1437
|
-
var
|
|
1450
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
1438
1451
|
|
|
1439
1452
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1440
|
-
var
|
|
1453
|
+
var import_react9 = __toESM(require("react"));
|
|
1441
1454
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1442
1455
|
return render({ event, result, resolve });
|
|
1443
1456
|
};
|
|
1444
1457
|
function useLangGraphInterruptRender() {
|
|
1445
1458
|
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1446
|
-
const responseRef =
|
|
1447
|
-
const resolveInterrupt = (0,
|
|
1459
|
+
const responseRef = import_react9.default.useRef();
|
|
1460
|
+
const resolveInterrupt = (0, import_react9.useCallback)(
|
|
1448
1461
|
(response) => {
|
|
1449
1462
|
responseRef.current = response;
|
|
1450
1463
|
setTimeout(() => {
|
|
@@ -1467,7 +1480,7 @@ function useLangGraphInterruptRender() {
|
|
|
1467
1480
|
resolve: resolveInterrupt
|
|
1468
1481
|
});
|
|
1469
1482
|
}
|
|
1470
|
-
return
|
|
1483
|
+
return import_react9.default.createElement(InterruptRenderer, {
|
|
1471
1484
|
event,
|
|
1472
1485
|
result,
|
|
1473
1486
|
render,
|
|
@@ -1505,15 +1518,13 @@ function useCopilotChat(options = {}) {
|
|
|
1505
1518
|
langGraphInterruptAction,
|
|
1506
1519
|
setLangGraphInterruptAction,
|
|
1507
1520
|
chatSuggestionConfiguration,
|
|
1508
|
-
suggestions,
|
|
1509
|
-
setSuggestions,
|
|
1510
1521
|
runtimeClient
|
|
1511
1522
|
} = useCopilotContext();
|
|
1512
|
-
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1513
|
-
const [mcpServers, setLocalMcpServers] = (0,
|
|
1514
|
-
const suggestionsAbortControllerRef = (0,
|
|
1515
|
-
const isLoadingSuggestionsRef = (0,
|
|
1516
|
-
const abortSuggestions = (0,
|
|
1523
|
+
const { messages, setMessages, suggestions, setSuggestions } = useCopilotMessagesContext();
|
|
1524
|
+
const [mcpServers, setLocalMcpServers] = (0, import_react10.useState)([]);
|
|
1525
|
+
const suggestionsAbortControllerRef = (0, import_react10.useRef)(null);
|
|
1526
|
+
const isLoadingSuggestionsRef = (0, import_react10.useRef)(false);
|
|
1527
|
+
const abortSuggestions = (0, import_react10.useCallback)(
|
|
1517
1528
|
(clear = true) => {
|
|
1518
1529
|
var _a2;
|
|
1519
1530
|
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort("suggestions aborted by user");
|
|
@@ -1524,7 +1535,7 @@ function useCopilotChat(options = {}) {
|
|
|
1524
1535
|
},
|
|
1525
1536
|
[setSuggestions]
|
|
1526
1537
|
);
|
|
1527
|
-
const stableContext = (0,
|
|
1538
|
+
const stableContext = (0, import_react10.useMemo)(() => {
|
|
1528
1539
|
return {
|
|
1529
1540
|
actions,
|
|
1530
1541
|
copilotApiConfig,
|
|
@@ -1540,7 +1551,7 @@ function useCopilotChat(options = {}) {
|
|
|
1540
1551
|
messages.length,
|
|
1541
1552
|
Object.keys(chatSuggestionConfiguration).length
|
|
1542
1553
|
]);
|
|
1543
|
-
const generateSuggestionsFunc = (0,
|
|
1554
|
+
const generateSuggestionsFunc = (0, import_react10.useCallback)(() => __async(this, null, function* () {
|
|
1544
1555
|
if (globalSuggestionPromise) {
|
|
1545
1556
|
return globalSuggestionPromise;
|
|
1546
1557
|
}
|
|
@@ -1565,10 +1576,10 @@ function useCopilotChat(options = {}) {
|
|
|
1565
1576
|
}))();
|
|
1566
1577
|
return globalSuggestionPromise;
|
|
1567
1578
|
}), [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);
|
|
1568
|
-
const resetSuggestions = (0,
|
|
1579
|
+
const resetSuggestions = (0, import_react10.useCallback)(() => {
|
|
1569
1580
|
setSuggestions([]);
|
|
1570
1581
|
}, [setSuggestions]);
|
|
1571
|
-
(0,
|
|
1582
|
+
(0, import_react10.useEffect)(() => {
|
|
1572
1583
|
if (mcpServers.length > 0) {
|
|
1573
1584
|
const serversCopy = [...mcpServers];
|
|
1574
1585
|
copilotApiConfig.mcpServers = serversCopy;
|
|
@@ -1578,7 +1589,7 @@ function useCopilotChat(options = {}) {
|
|
|
1578
1589
|
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
1579
1590
|
}
|
|
1580
1591
|
}, [mcpServers, copilotApiConfig]);
|
|
1581
|
-
const setMcpServers = (0,
|
|
1592
|
+
const setMcpServers = (0, import_react10.useCallback)((servers) => {
|
|
1582
1593
|
setLocalMcpServers(servers);
|
|
1583
1594
|
}, []);
|
|
1584
1595
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1599,15 +1610,15 @@ function useCopilotChat(options = {}) {
|
|
|
1599
1610
|
}),
|
|
1600
1611
|
[coAgentStateRenders]
|
|
1601
1612
|
);
|
|
1602
|
-
const makeSystemMessageCallback = (0,
|
|
1613
|
+
const makeSystemMessageCallback = (0, import_react10.useCallback)(() => {
|
|
1603
1614
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1604
1615
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
1605
|
-
return new
|
|
1616
|
+
return new import_runtime_client_gql8.TextMessage({
|
|
1606
1617
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1607
|
-
role:
|
|
1618
|
+
role: import_runtime_client_gql8.Role.System
|
|
1608
1619
|
});
|
|
1609
1620
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1610
|
-
const deleteMessage = (0,
|
|
1621
|
+
const deleteMessage = (0, import_react10.useCallback)(
|
|
1611
1622
|
(messageId) => {
|
|
1612
1623
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1613
1624
|
},
|
|
@@ -1616,7 +1627,7 @@ function useCopilotChat(options = {}) {
|
|
|
1616
1627
|
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1617
1628
|
actions: Object.values(actions),
|
|
1618
1629
|
copilotConfig: copilotApiConfig,
|
|
1619
|
-
initialMessages: (0,
|
|
1630
|
+
initialMessages: (0, import_runtime_client_gql8.aguiToGQL)(options.initialMessages || []),
|
|
1620
1631
|
onFunctionCall: getFunctionCallHandler(),
|
|
1621
1632
|
onCoAgentStateRender,
|
|
1622
1633
|
messages,
|
|
@@ -1644,7 +1655,7 @@ function useCopilotChat(options = {}) {
|
|
|
1644
1655
|
const latestAppendFunc = useAsyncCallback(
|
|
1645
1656
|
(message, options2) => __async(this, null, function* () {
|
|
1646
1657
|
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1647
|
-
return yield latestAppend.current((0,
|
|
1658
|
+
return yield latestAppend.current((0, import_runtime_client_gql8.aguiToGQL)([message])[0], options2);
|
|
1648
1659
|
}),
|
|
1649
1660
|
[latestAppend]
|
|
1650
1661
|
);
|
|
@@ -1656,20 +1667,20 @@ function useCopilotChat(options = {}) {
|
|
|
1656
1667
|
[latestReload]
|
|
1657
1668
|
);
|
|
1658
1669
|
const latestStop = useUpdatedRef(stop);
|
|
1659
|
-
const latestStopFunc = (0,
|
|
1670
|
+
const latestStopFunc = (0, import_react10.useCallback)(() => {
|
|
1660
1671
|
return latestStop.current();
|
|
1661
1672
|
}, [latestStop]);
|
|
1662
1673
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1663
|
-
const latestDeleteFunc = (0,
|
|
1674
|
+
const latestDeleteFunc = (0, import_react10.useCallback)(
|
|
1664
1675
|
(messageId) => {
|
|
1665
1676
|
return latestDelete.current(messageId);
|
|
1666
1677
|
},
|
|
1667
1678
|
[latestDelete]
|
|
1668
1679
|
);
|
|
1669
1680
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1670
|
-
const latestSetMessagesFunc = (0,
|
|
1681
|
+
const latestSetMessagesFunc = (0, import_react10.useCallback)(
|
|
1671
1682
|
(messages2) => {
|
|
1672
|
-
return latestSetMessages.current((0,
|
|
1683
|
+
return latestSetMessages.current((0, import_runtime_client_gql8.aguiToGQL)(messages2));
|
|
1673
1684
|
},
|
|
1674
1685
|
[latestSetMessages]
|
|
1675
1686
|
);
|
|
@@ -1677,7 +1688,7 @@ function useCopilotChat(options = {}) {
|
|
|
1677
1688
|
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1678
1689
|
return yield latestRunChatCompletion.current();
|
|
1679
1690
|
}), [latestRunChatCompletion]);
|
|
1680
|
-
const reset = (0,
|
|
1691
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
1681
1692
|
latestStopFunc();
|
|
1682
1693
|
setMessages([]);
|
|
1683
1694
|
setRunId(null);
|
|
@@ -1700,12 +1711,12 @@ function useCopilotChat(options = {}) {
|
|
|
1700
1711
|
resetSuggestions
|
|
1701
1712
|
]);
|
|
1702
1713
|
const latestReset = useUpdatedRef(reset);
|
|
1703
|
-
const latestResetFunc = (0,
|
|
1714
|
+
const latestResetFunc = (0, import_react10.useCallback)(() => {
|
|
1704
1715
|
return latestReset.current();
|
|
1705
1716
|
}, [latestReset]);
|
|
1706
1717
|
const interrupt = useLangGraphInterruptRender();
|
|
1707
1718
|
return {
|
|
1708
|
-
visibleMessages: (0,
|
|
1719
|
+
visibleMessages: (0, import_runtime_client_gql8.gqlToAGUI)(messages, actions, coAgentStateRenders),
|
|
1709
1720
|
appendMessage: latestAppendFunc,
|
|
1710
1721
|
setMessages: latestSetMessagesFunc,
|
|
1711
1722
|
reloadMessages: latestReloadFunc,
|
|
@@ -1725,8 +1736,8 @@ function useCopilotChat(options = {}) {
|
|
|
1725
1736
|
};
|
|
1726
1737
|
}
|
|
1727
1738
|
function useUpdatedRef(value) {
|
|
1728
|
-
const ref = (0,
|
|
1729
|
-
(0,
|
|
1739
|
+
const ref = (0, import_react10.useRef)(value);
|
|
1740
|
+
(0, import_react10.useEffect)(() => {
|
|
1730
1741
|
ref.current = value;
|
|
1731
1742
|
}, [value]);
|
|
1732
1743
|
return ref;
|
|
@@ -1759,27 +1770,26 @@ ${additionalInstructions}` : "");
|
|
|
1759
1770
|
}
|
|
1760
1771
|
|
|
1761
1772
|
// src/hooks/use-coagent.ts
|
|
1762
|
-
var
|
|
1773
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1763
1774
|
function useCoAgent(options) {
|
|
1764
|
-
const
|
|
1765
|
-
const { availableAgents } =
|
|
1775
|
+
const context = useCopilotContext();
|
|
1776
|
+
const { availableAgents } = context;
|
|
1766
1777
|
const { setBannerError } = useToast();
|
|
1767
|
-
const lastLoadedThreadId = (0,
|
|
1768
|
-
const lastLoadedState = (0,
|
|
1778
|
+
const lastLoadedThreadId = (0, import_react11.useRef)();
|
|
1779
|
+
const lastLoadedState = (0, import_react11.useRef)();
|
|
1769
1780
|
const { name } = options;
|
|
1770
|
-
(0,
|
|
1781
|
+
(0, import_react11.useEffect)(() => {
|
|
1771
1782
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
1772
1783
|
const message = `(useCoAgent): Agent "${name}" not found. Make sure the agent exists and is properly configured.`;
|
|
1773
1784
|
console.warn(message);
|
|
1774
|
-
const agentError = new
|
|
1785
|
+
const agentError = new import_shared9.CopilotKitAgentDiscoveryError({
|
|
1775
1786
|
agentName: name,
|
|
1776
1787
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
1777
1788
|
});
|
|
1778
1789
|
setBannerError(agentError);
|
|
1779
1790
|
}
|
|
1780
1791
|
}, [availableAgents]);
|
|
1781
|
-
const
|
|
1782
|
-
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1792
|
+
const { getMessagesFromTap } = useMessagesTap();
|
|
1783
1793
|
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
1784
1794
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1785
1795
|
const headers = __spreadValues({}, copilotApiConfig.headers || {});
|
|
@@ -1790,7 +1800,7 @@ function useCoAgent(options) {
|
|
|
1790
1800
|
credentials: copilotApiConfig.credentials,
|
|
1791
1801
|
showDevConsole: context.showDevConsole
|
|
1792
1802
|
});
|
|
1793
|
-
const setState = (0,
|
|
1803
|
+
const setState = (0, import_react11.useCallback)(
|
|
1794
1804
|
(newState) => {
|
|
1795
1805
|
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
1796
1806
|
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
@@ -1802,7 +1812,7 @@ function useCoAgent(options) {
|
|
|
1802
1812
|
},
|
|
1803
1813
|
[coagentStates, name]
|
|
1804
1814
|
);
|
|
1805
|
-
(0,
|
|
1815
|
+
(0, import_react11.useEffect)(() => {
|
|
1806
1816
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
1807
1817
|
var _a, _b, _c, _d;
|
|
1808
1818
|
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
@@ -1820,13 +1830,13 @@ function useCoAgent(options) {
|
|
|
1820
1830
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
1821
1831
|
lastLoadedState.current = newState;
|
|
1822
1832
|
lastLoadedThreadId.current = threadId;
|
|
1823
|
-
const fetchedState = (0,
|
|
1833
|
+
const fetchedState = (0, import_shared9.parseJson)(newState, {});
|
|
1824
1834
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
1825
1835
|
}
|
|
1826
1836
|
});
|
|
1827
1837
|
void fetchAgentState();
|
|
1828
1838
|
}, [threadId]);
|
|
1829
|
-
(0,
|
|
1839
|
+
(0, import_react11.useEffect)(() => {
|
|
1830
1840
|
if (isExternalStateManagement(options)) {
|
|
1831
1841
|
setState(options.state);
|
|
1832
1842
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -1837,7 +1847,7 @@ function useCoAgent(options) {
|
|
|
1837
1847
|
// reset initialstate on reset
|
|
1838
1848
|
coagentStates[name] === void 0
|
|
1839
1849
|
]);
|
|
1840
|
-
(0,
|
|
1850
|
+
(0, import_react11.useEffect)(() => {
|
|
1841
1851
|
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
1842
1852
|
if (newConfig === void 0)
|
|
1843
1853
|
return;
|
|
@@ -1865,11 +1875,11 @@ function useCoAgent(options) {
|
|
|
1865
1875
|
}, [JSON.stringify(options.config), JSON.stringify(options.configurable)]);
|
|
1866
1876
|
const runAgentCallback = useAsyncCallback(
|
|
1867
1877
|
(hint) => __async(this, null, function* () {
|
|
1868
|
-
yield runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
1878
|
+
yield runAgent(name, context, getMessagesFromTap(), appendMessage, runChatCompletion, hint);
|
|
1869
1879
|
}),
|
|
1870
1880
|
[name, context, appendMessage, runChatCompletion]
|
|
1871
1881
|
);
|
|
1872
|
-
return (0,
|
|
1882
|
+
return (0, import_react11.useMemo)(() => {
|
|
1873
1883
|
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
1874
1884
|
return {
|
|
1875
1885
|
name,
|
|
@@ -1909,7 +1919,7 @@ function stopAgent(name, context) {
|
|
|
1909
1919
|
console.warn(`No agent session found for ${name}`);
|
|
1910
1920
|
}
|
|
1911
1921
|
}
|
|
1912
|
-
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
1922
|
+
function runAgent(name, context, messages, appendMessage, runChatCompletion, hint) {
|
|
1913
1923
|
return __async(this, null, function* () {
|
|
1914
1924
|
var _a, _b;
|
|
1915
1925
|
const { agentSession, setAgentSession } = context;
|
|
@@ -1919,8 +1929,8 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
1919
1929
|
});
|
|
1920
1930
|
}
|
|
1921
1931
|
let previousState = null;
|
|
1922
|
-
for (let i =
|
|
1923
|
-
const message =
|
|
1932
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
1933
|
+
const message = messages[i];
|
|
1924
1934
|
if (message.isAgentStateMessage() && message.agentName === name) {
|
|
1925
1935
|
previousState = message.state;
|
|
1926
1936
|
}
|