@copilotkit/react-core 1.10.0-next.7 → 1.10.0-next.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -0
- package/dist/{chunk-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
package/dist/hooks/index.js
CHANGED
|
@@ -99,7 +99,7 @@ __export(hooks_exports, {
|
|
|
99
99
|
module.exports = __toCommonJS(hooks_exports);
|
|
100
100
|
|
|
101
101
|
// src/hooks/use-copilot-chat.ts
|
|
102
|
-
var
|
|
102
|
+
var import_react11 = require("react");
|
|
103
103
|
|
|
104
104
|
// src/context/copilot-context.tsx
|
|
105
105
|
var import_react = __toESM(require("react"));
|
|
@@ -176,11 +176,8 @@ var emptyCopilotContext = {
|
|
|
176
176
|
setLangGraphInterruptAction: () => null,
|
|
177
177
|
removeLangGraphInterruptAction: () => null,
|
|
178
178
|
onError: void 0,
|
|
179
|
-
suggestions: [],
|
|
180
179
|
bannerError: null,
|
|
181
180
|
setBannerError: () => {
|
|
182
|
-
},
|
|
183
|
-
setSuggestions: () => {
|
|
184
181
|
}
|
|
185
182
|
};
|
|
186
183
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
@@ -196,13 +193,16 @@ function returnAndThrowInDebug(_value) {
|
|
|
196
193
|
}
|
|
197
194
|
|
|
198
195
|
// src/hooks/use-copilot-chat_internal.ts
|
|
199
|
-
var
|
|
196
|
+
var import_react10 = require("react");
|
|
200
197
|
|
|
201
198
|
// src/context/copilot-messages-context.tsx
|
|
202
199
|
var import_react2 = __toESM(require("react"));
|
|
203
200
|
var emptyCopilotContext2 = {
|
|
204
201
|
messages: [],
|
|
205
|
-
setMessages: () => []
|
|
202
|
+
setMessages: () => [],
|
|
203
|
+
// suggestions state
|
|
204
|
+
suggestions: [],
|
|
205
|
+
setSuggestions: () => []
|
|
206
206
|
};
|
|
207
207
|
var CopilotMessagesContext = import_react2.default.createContext(emptyCopilotContext2);
|
|
208
208
|
function useCopilotMessagesContext() {
|
|
@@ -1172,14 +1172,27 @@ function getPairedFeAction(actions, message) {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
|
|
1174
1174
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1175
|
-
var
|
|
1175
|
+
var import_react8 = require("react");
|
|
1176
1176
|
var import_react_dom2 = require("react-dom");
|
|
1177
|
-
var
|
|
1177
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1178
1178
|
|
|
1179
|
-
// src/
|
|
1180
|
-
var
|
|
1179
|
+
// src/components/copilot-provider/copilot-messages.tsx
|
|
1180
|
+
var import_react7 = require("react");
|
|
1181
1181
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1182
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1183
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1184
|
+
var MessagesTapContext = (0, import_react7.createContext)(null);
|
|
1185
|
+
function useMessagesTap() {
|
|
1186
|
+
const tap = (0, import_react7.useContext)(MessagesTapContext);
|
|
1187
|
+
if (!tap)
|
|
1188
|
+
throw new Error("useMessagesTap must be used inside <MessagesTapProvider>");
|
|
1189
|
+
return tap;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
// src/utils/extract.ts
|
|
1193
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1182
1194
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1195
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1183
1196
|
function extract(_0) {
|
|
1184
1197
|
return __async(this, arguments, function* ({
|
|
1185
1198
|
context,
|
|
@@ -1189,7 +1202,7 @@ function extract(_0) {
|
|
|
1189
1202
|
data,
|
|
1190
1203
|
abortSignal,
|
|
1191
1204
|
stream,
|
|
1192
|
-
requestType =
|
|
1205
|
+
requestType = import_runtime_client_gql5.CopilotRequestType.Task,
|
|
1193
1206
|
forwardedParameters
|
|
1194
1207
|
}) {
|
|
1195
1208
|
var _a, _b;
|
|
@@ -1210,13 +1223,13 @@ function extract(_0) {
|
|
|
1210
1223
|
if (includeReadable) {
|
|
1211
1224
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1212
1225
|
}
|
|
1213
|
-
const systemMessage = new
|
|
1226
|
+
const systemMessage = new import_runtime_client_gql5.TextMessage({
|
|
1214
1227
|
content: makeSystemMessage(contextString, instructions),
|
|
1215
|
-
role:
|
|
1228
|
+
role: import_runtime_client_gql5.Role.System
|
|
1216
1229
|
});
|
|
1217
|
-
const instructionsMessage = new
|
|
1230
|
+
const instructionsMessage = new import_runtime_client_gql5.TextMessage({
|
|
1218
1231
|
content: makeInstructionsMessage(instructions),
|
|
1219
|
-
role:
|
|
1232
|
+
role: import_runtime_client_gql5.Role.User
|
|
1220
1233
|
});
|
|
1221
1234
|
const response = context.runtimeClient.asStream(
|
|
1222
1235
|
context.runtimeClient.generateCopilotResponse({
|
|
@@ -1226,13 +1239,13 @@ function extract(_0) {
|
|
|
1226
1239
|
{
|
|
1227
1240
|
name: action.name,
|
|
1228
1241
|
description: action.description || "",
|
|
1229
|
-
jsonSchema: JSON.stringify((0,
|
|
1242
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters || []))
|
|
1230
1243
|
}
|
|
1231
1244
|
],
|
|
1232
1245
|
url: window.location.href
|
|
1233
1246
|
},
|
|
1234
|
-
messages: (0,
|
|
1235
|
-
includeMessages ? [systemMessage, instructionsMessage, ...(0,
|
|
1247
|
+
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)(
|
|
1248
|
+
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql6.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1236
1249
|
),
|
|
1237
1250
|
metadata: {
|
|
1238
1251
|
requestType
|
|
@@ -1257,7 +1270,7 @@ function extract(_0) {
|
|
|
1257
1270
|
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1258
1271
|
throw new Error("Aborted");
|
|
1259
1272
|
}
|
|
1260
|
-
actionExecutionMessage = (0,
|
|
1273
|
+
actionExecutionMessage = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
|
|
1261
1274
|
value.generateCopilotResponse.messages
|
|
1262
1275
|
).find((msg) => msg.isActionExecutionMessage());
|
|
1263
1276
|
if (!actionExecutionMessage) {
|
|
@@ -1311,8 +1324,8 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1311
1324
|
}
|
|
1312
1325
|
|
|
1313
1326
|
// src/utils/suggestions.ts
|
|
1314
|
-
var
|
|
1315
|
-
var
|
|
1327
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1328
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1316
1329
|
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1317
1330
|
const abortController = abortControllerRef.current;
|
|
1318
1331
|
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
@@ -1328,7 +1341,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1328
1341
|
Object.values(context.actions).map((action) => ({
|
|
1329
1342
|
name: action.name,
|
|
1330
1343
|
description: action.description,
|
|
1331
|
-
jsonSchema: JSON.stringify((0,
|
|
1344
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters))
|
|
1332
1345
|
}))
|
|
1333
1346
|
);
|
|
1334
1347
|
const allSuggestions = [];
|
|
@@ -1356,7 +1369,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1356
1369
|
Available tools: ${tools}
|
|
1357
1370
|
|
|
1358
1371
|
`,
|
|
1359
|
-
requestType:
|
|
1372
|
+
requestType: import_runtime_client_gql7.CopilotRequestType.Task,
|
|
1360
1373
|
parameters: [
|
|
1361
1374
|
{
|
|
1362
1375
|
name: "suggestions",
|
|
@@ -1444,21 +1457,21 @@ Available tools: ${tools}
|
|
|
1444
1457
|
});
|
|
1445
1458
|
|
|
1446
1459
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1447
|
-
var
|
|
1460
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1448
1461
|
var defaultCopilotContextCategories = ["global"];
|
|
1449
1462
|
|
|
1450
1463
|
// src/hooks/use-copilot-chat_internal.ts
|
|
1451
|
-
var
|
|
1464
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
1452
1465
|
|
|
1453
1466
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1454
|
-
var
|
|
1467
|
+
var import_react9 = __toESM(require("react"));
|
|
1455
1468
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1456
1469
|
return render({ event, result, resolve });
|
|
1457
1470
|
};
|
|
1458
1471
|
function useLangGraphInterruptRender() {
|
|
1459
1472
|
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1460
|
-
const responseRef =
|
|
1461
|
-
const resolveInterrupt = (0,
|
|
1473
|
+
const responseRef = import_react9.default.useRef();
|
|
1474
|
+
const resolveInterrupt = (0, import_react9.useCallback)(
|
|
1462
1475
|
(response) => {
|
|
1463
1476
|
responseRef.current = response;
|
|
1464
1477
|
setTimeout(() => {
|
|
@@ -1481,7 +1494,7 @@ function useLangGraphInterruptRender() {
|
|
|
1481
1494
|
resolve: resolveInterrupt
|
|
1482
1495
|
});
|
|
1483
1496
|
}
|
|
1484
|
-
return
|
|
1497
|
+
return import_react9.default.createElement(InterruptRenderer, {
|
|
1485
1498
|
event,
|
|
1486
1499
|
result,
|
|
1487
1500
|
render,
|
|
@@ -1519,15 +1532,13 @@ function useCopilotChat(options = {}) {
|
|
|
1519
1532
|
langGraphInterruptAction,
|
|
1520
1533
|
setLangGraphInterruptAction,
|
|
1521
1534
|
chatSuggestionConfiguration,
|
|
1522
|
-
suggestions,
|
|
1523
|
-
setSuggestions,
|
|
1524
1535
|
runtimeClient
|
|
1525
1536
|
} = useCopilotContext();
|
|
1526
|
-
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1527
|
-
const [mcpServers, setLocalMcpServers] = (0,
|
|
1528
|
-
const suggestionsAbortControllerRef = (0,
|
|
1529
|
-
const isLoadingSuggestionsRef = (0,
|
|
1530
|
-
const abortSuggestions = (0,
|
|
1537
|
+
const { messages, setMessages, suggestions, setSuggestions } = useCopilotMessagesContext();
|
|
1538
|
+
const [mcpServers, setLocalMcpServers] = (0, import_react10.useState)([]);
|
|
1539
|
+
const suggestionsAbortControllerRef = (0, import_react10.useRef)(null);
|
|
1540
|
+
const isLoadingSuggestionsRef = (0, import_react10.useRef)(false);
|
|
1541
|
+
const abortSuggestions = (0, import_react10.useCallback)(
|
|
1531
1542
|
(clear = true) => {
|
|
1532
1543
|
var _a2;
|
|
1533
1544
|
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort("suggestions aborted by user");
|
|
@@ -1538,7 +1549,7 @@ function useCopilotChat(options = {}) {
|
|
|
1538
1549
|
},
|
|
1539
1550
|
[setSuggestions]
|
|
1540
1551
|
);
|
|
1541
|
-
const stableContext = (0,
|
|
1552
|
+
const stableContext = (0, import_react10.useMemo)(() => {
|
|
1542
1553
|
return {
|
|
1543
1554
|
actions,
|
|
1544
1555
|
copilotApiConfig,
|
|
@@ -1554,7 +1565,7 @@ function useCopilotChat(options = {}) {
|
|
|
1554
1565
|
messages.length,
|
|
1555
1566
|
Object.keys(chatSuggestionConfiguration).length
|
|
1556
1567
|
]);
|
|
1557
|
-
const generateSuggestionsFunc = (0,
|
|
1568
|
+
const generateSuggestionsFunc = (0, import_react10.useCallback)(() => __async(this, null, function* () {
|
|
1558
1569
|
if (globalSuggestionPromise) {
|
|
1559
1570
|
return globalSuggestionPromise;
|
|
1560
1571
|
}
|
|
@@ -1579,10 +1590,10 @@ function useCopilotChat(options = {}) {
|
|
|
1579
1590
|
}))();
|
|
1580
1591
|
return globalSuggestionPromise;
|
|
1581
1592
|
}), [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);
|
|
1582
|
-
const resetSuggestions = (0,
|
|
1593
|
+
const resetSuggestions = (0, import_react10.useCallback)(() => {
|
|
1583
1594
|
setSuggestions([]);
|
|
1584
1595
|
}, [setSuggestions]);
|
|
1585
|
-
(0,
|
|
1596
|
+
(0, import_react10.useEffect)(() => {
|
|
1586
1597
|
if (mcpServers.length > 0) {
|
|
1587
1598
|
const serversCopy = [...mcpServers];
|
|
1588
1599
|
copilotApiConfig.mcpServers = serversCopy;
|
|
@@ -1592,7 +1603,7 @@ function useCopilotChat(options = {}) {
|
|
|
1592
1603
|
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
1593
1604
|
}
|
|
1594
1605
|
}, [mcpServers, copilotApiConfig]);
|
|
1595
|
-
const setMcpServers = (0,
|
|
1606
|
+
const setMcpServers = (0, import_react10.useCallback)((servers) => {
|
|
1596
1607
|
setLocalMcpServers(servers);
|
|
1597
1608
|
}, []);
|
|
1598
1609
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1613,15 +1624,15 @@ function useCopilotChat(options = {}) {
|
|
|
1613
1624
|
}),
|
|
1614
1625
|
[coAgentStateRenders]
|
|
1615
1626
|
);
|
|
1616
|
-
const makeSystemMessageCallback = (0,
|
|
1627
|
+
const makeSystemMessageCallback = (0, import_react10.useCallback)(() => {
|
|
1617
1628
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1618
1629
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
1619
|
-
return new
|
|
1630
|
+
return new import_runtime_client_gql8.TextMessage({
|
|
1620
1631
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1621
|
-
role:
|
|
1632
|
+
role: import_runtime_client_gql8.Role.System
|
|
1622
1633
|
});
|
|
1623
1634
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1624
|
-
const deleteMessage = (0,
|
|
1635
|
+
const deleteMessage = (0, import_react10.useCallback)(
|
|
1625
1636
|
(messageId) => {
|
|
1626
1637
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1627
1638
|
},
|
|
@@ -1630,7 +1641,7 @@ function useCopilotChat(options = {}) {
|
|
|
1630
1641
|
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1631
1642
|
actions: Object.values(actions),
|
|
1632
1643
|
copilotConfig: copilotApiConfig,
|
|
1633
|
-
initialMessages: (0,
|
|
1644
|
+
initialMessages: (0, import_runtime_client_gql8.aguiToGQL)(options.initialMessages || []),
|
|
1634
1645
|
onFunctionCall: getFunctionCallHandler(),
|
|
1635
1646
|
onCoAgentStateRender,
|
|
1636
1647
|
messages,
|
|
@@ -1658,7 +1669,7 @@ function useCopilotChat(options = {}) {
|
|
|
1658
1669
|
const latestAppendFunc = useAsyncCallback(
|
|
1659
1670
|
(message, options2) => __async(this, null, function* () {
|
|
1660
1671
|
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1661
|
-
return yield latestAppend.current((0,
|
|
1672
|
+
return yield latestAppend.current((0, import_runtime_client_gql8.aguiToGQL)([message])[0], options2);
|
|
1662
1673
|
}),
|
|
1663
1674
|
[latestAppend]
|
|
1664
1675
|
);
|
|
@@ -1670,20 +1681,20 @@ function useCopilotChat(options = {}) {
|
|
|
1670
1681
|
[latestReload]
|
|
1671
1682
|
);
|
|
1672
1683
|
const latestStop = useUpdatedRef(stop);
|
|
1673
|
-
const latestStopFunc = (0,
|
|
1684
|
+
const latestStopFunc = (0, import_react10.useCallback)(() => {
|
|
1674
1685
|
return latestStop.current();
|
|
1675
1686
|
}, [latestStop]);
|
|
1676
1687
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1677
|
-
const latestDeleteFunc = (0,
|
|
1688
|
+
const latestDeleteFunc = (0, import_react10.useCallback)(
|
|
1678
1689
|
(messageId) => {
|
|
1679
1690
|
return latestDelete.current(messageId);
|
|
1680
1691
|
},
|
|
1681
1692
|
[latestDelete]
|
|
1682
1693
|
);
|
|
1683
1694
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1684
|
-
const latestSetMessagesFunc = (0,
|
|
1695
|
+
const latestSetMessagesFunc = (0, import_react10.useCallback)(
|
|
1685
1696
|
(messages2) => {
|
|
1686
|
-
return latestSetMessages.current((0,
|
|
1697
|
+
return latestSetMessages.current((0, import_runtime_client_gql8.aguiToGQL)(messages2));
|
|
1687
1698
|
},
|
|
1688
1699
|
[latestSetMessages]
|
|
1689
1700
|
);
|
|
@@ -1691,7 +1702,7 @@ function useCopilotChat(options = {}) {
|
|
|
1691
1702
|
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1692
1703
|
return yield latestRunChatCompletion.current();
|
|
1693
1704
|
}), [latestRunChatCompletion]);
|
|
1694
|
-
const reset = (0,
|
|
1705
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
1695
1706
|
latestStopFunc();
|
|
1696
1707
|
setMessages([]);
|
|
1697
1708
|
setRunId(null);
|
|
@@ -1714,12 +1725,12 @@ function useCopilotChat(options = {}) {
|
|
|
1714
1725
|
resetSuggestions
|
|
1715
1726
|
]);
|
|
1716
1727
|
const latestReset = useUpdatedRef(reset);
|
|
1717
|
-
const latestResetFunc = (0,
|
|
1728
|
+
const latestResetFunc = (0, import_react10.useCallback)(() => {
|
|
1718
1729
|
return latestReset.current();
|
|
1719
1730
|
}, [latestReset]);
|
|
1720
1731
|
const interrupt = useLangGraphInterruptRender();
|
|
1721
1732
|
return {
|
|
1722
|
-
visibleMessages: (0,
|
|
1733
|
+
visibleMessages: (0, import_runtime_client_gql8.gqlToAGUI)(messages, actions, coAgentStateRenders),
|
|
1723
1734
|
appendMessage: latestAppendFunc,
|
|
1724
1735
|
setMessages: latestSetMessagesFunc,
|
|
1725
1736
|
reloadMessages: latestReloadFunc,
|
|
@@ -1739,8 +1750,8 @@ function useCopilotChat(options = {}) {
|
|
|
1739
1750
|
};
|
|
1740
1751
|
}
|
|
1741
1752
|
function useUpdatedRef(value) {
|
|
1742
|
-
const ref = (0,
|
|
1743
|
-
(0,
|
|
1753
|
+
const ref = (0, import_react10.useRef)(value);
|
|
1754
|
+
(0, import_react10.useEffect)(() => {
|
|
1744
1755
|
ref.current = value;
|
|
1745
1756
|
}, [value]);
|
|
1746
1757
|
return ref;
|
|
@@ -1773,7 +1784,7 @@ ${additionalInstructions}` : "");
|
|
|
1773
1784
|
}
|
|
1774
1785
|
|
|
1775
1786
|
// src/hooks/use-copilot-chat.ts
|
|
1776
|
-
var
|
|
1787
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1777
1788
|
var createNonFunctionalReturn = () => ({
|
|
1778
1789
|
visibleMessages: [],
|
|
1779
1790
|
appendMessage: () => __async(void 0, null, function* () {
|
|
@@ -1809,17 +1820,17 @@ function useCopilotChat2(options = {}) {
|
|
|
1809
1820
|
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
1810
1821
|
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
1811
1822
|
const internalResult = useCopilotChat(options);
|
|
1812
|
-
(0,
|
|
1823
|
+
(0, import_react11.useEffect)(() => {
|
|
1813
1824
|
if (!hasPublicApiKey) {
|
|
1814
1825
|
setBannerError(
|
|
1815
|
-
new
|
|
1826
|
+
new import_shared9.CopilotKitError({
|
|
1816
1827
|
message: "As of v1.10.0, useCopilotChat requires a publicApiKey to function.",
|
|
1817
|
-
code:
|
|
1818
|
-
severity:
|
|
1819
|
-
visibility:
|
|
1828
|
+
code: import_shared9.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
1829
|
+
severity: import_shared9.Severity.CRITICAL,
|
|
1830
|
+
visibility: import_shared9.ErrorVisibility.BANNER
|
|
1820
1831
|
})
|
|
1821
1832
|
);
|
|
1822
|
-
|
|
1833
|
+
import_shared9.styledConsole.logCopilotKitPlatformMessage();
|
|
1823
1834
|
} else {
|
|
1824
1835
|
setBannerError(null);
|
|
1825
1836
|
}
|
|
@@ -1841,13 +1852,13 @@ function useCopilotChatLight(options = {}) {
|
|
|
1841
1852
|
}
|
|
1842
1853
|
|
|
1843
1854
|
// src/hooks/use-copilot-action.ts
|
|
1844
|
-
var
|
|
1845
|
-
var
|
|
1855
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1856
|
+
var import_react12 = require("react");
|
|
1846
1857
|
function useCopilotAction(action, dependencies) {
|
|
1847
1858
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1848
|
-
const idRef = (0,
|
|
1849
|
-
const renderAndWaitRef = (0,
|
|
1850
|
-
const activatingMessageIdRef = (0,
|
|
1859
|
+
const idRef = (0, import_react12.useRef)((0, import_shared10.randomId)());
|
|
1860
|
+
const renderAndWaitRef = (0, import_react12.useRef)(null);
|
|
1861
|
+
const activatingMessageIdRef = (0, import_react12.useRef)(null);
|
|
1851
1862
|
const { addToast } = useToast();
|
|
1852
1863
|
action = __spreadValues({}, action);
|
|
1853
1864
|
if (
|
|
@@ -1909,7 +1920,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1909
1920
|
return renderAndWait(waitProps);
|
|
1910
1921
|
}
|
|
1911
1922
|
}
|
|
1912
|
-
return (0,
|
|
1923
|
+
return (0, import_react12.createElement)(import_react12.Fragment);
|
|
1913
1924
|
};
|
|
1914
1925
|
}
|
|
1915
1926
|
if (dependencies === void 0) {
|
|
@@ -1924,7 +1935,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1924
1935
|
}
|
|
1925
1936
|
}
|
|
1926
1937
|
}
|
|
1927
|
-
(0,
|
|
1938
|
+
(0, import_react12.useEffect)(() => {
|
|
1928
1939
|
const hasDuplicate = Object.values(actions).some(
|
|
1929
1940
|
(otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current]
|
|
1930
1941
|
);
|
|
@@ -1936,7 +1947,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1936
1947
|
});
|
|
1937
1948
|
}
|
|
1938
1949
|
}, [actions]);
|
|
1939
|
-
(0,
|
|
1950
|
+
(0, import_react12.useEffect)(() => {
|
|
1940
1951
|
setAction(idRef.current, action);
|
|
1941
1952
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1942
1953
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1965,8 +1976,8 @@ function isFrontendAction(action) {
|
|
|
1965
1976
|
}
|
|
1966
1977
|
|
|
1967
1978
|
// src/hooks/use-coagent-state-render.ts
|
|
1968
|
-
var
|
|
1969
|
-
var
|
|
1979
|
+
var import_react13 = require("react");
|
|
1980
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1970
1981
|
function useCoAgentStateRender(action, dependencies) {
|
|
1971
1982
|
const {
|
|
1972
1983
|
setCoAgentStateRender,
|
|
@@ -1974,13 +1985,13 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1974
1985
|
coAgentStateRenders,
|
|
1975
1986
|
chatComponentsCache,
|
|
1976
1987
|
availableAgents
|
|
1977
|
-
} = (0,
|
|
1978
|
-
const idRef = (0,
|
|
1988
|
+
} = (0, import_react13.useContext)(CopilotContext);
|
|
1989
|
+
const idRef = (0, import_react13.useRef)((0, import_shared11.randomId)());
|
|
1979
1990
|
const { setBannerError, addToast } = useToast();
|
|
1980
|
-
(0,
|
|
1991
|
+
(0, import_react13.useEffect)(() => {
|
|
1981
1992
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
1982
1993
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
1983
|
-
const agentError = new
|
|
1994
|
+
const agentError = new import_shared11.CopilotKitAgentDiscoveryError({
|
|
1984
1995
|
agentName: action.name,
|
|
1985
1996
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
1986
1997
|
});
|
|
@@ -1998,7 +2009,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1998
2009
|
}
|
|
1999
2010
|
}
|
|
2000
2011
|
}
|
|
2001
|
-
(0,
|
|
2012
|
+
(0, import_react13.useEffect)(() => {
|
|
2002
2013
|
const currentId = idRef.current;
|
|
2003
2014
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
2004
2015
|
if (id === currentId)
|
|
@@ -2022,7 +2033,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
2022
2033
|
});
|
|
2023
2034
|
}
|
|
2024
2035
|
}, [coAgentStateRenders]);
|
|
2025
|
-
(0,
|
|
2036
|
+
(0, import_react13.useEffect)(() => {
|
|
2026
2037
|
setCoAgentStateRender(idRef.current, action);
|
|
2027
2038
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
2028
2039
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -2042,11 +2053,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
2042
2053
|
}
|
|
2043
2054
|
|
|
2044
2055
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
2045
|
-
var
|
|
2056
|
+
var import_react14 = require("react");
|
|
2046
2057
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
2047
2058
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
2048
|
-
const idRef = (0,
|
|
2049
|
-
(0,
|
|
2059
|
+
const idRef = (0, import_react14.useRef)();
|
|
2060
|
+
(0, import_react14.useEffect)(() => {
|
|
2050
2061
|
const id = addDocumentContext(document, categories);
|
|
2051
2062
|
idRef.current = id;
|
|
2052
2063
|
return () => {
|
|
@@ -2057,7 +2068,7 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
2057
2068
|
}
|
|
2058
2069
|
|
|
2059
2070
|
// src/hooks/use-copilot-readable.ts
|
|
2060
|
-
var
|
|
2071
|
+
var import_react15 = require("react");
|
|
2061
2072
|
function convertToJSON(description, value) {
|
|
2062
2073
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
2063
2074
|
}
|
|
@@ -2070,10 +2081,10 @@ function useCopilotReadable({
|
|
|
2070
2081
|
available = "enabled"
|
|
2071
2082
|
}, dependencies) {
|
|
2072
2083
|
const { addContext, removeContext } = useCopilotContext();
|
|
2073
|
-
const idRef = (0,
|
|
2084
|
+
const idRef = (0, import_react15.useRef)();
|
|
2074
2085
|
convert = convert || convertToJSON;
|
|
2075
2086
|
const information = convert(description, value);
|
|
2076
|
-
(0,
|
|
2087
|
+
(0, import_react15.useEffect)(() => {
|
|
2077
2088
|
if (available === "disabled")
|
|
2078
2089
|
return;
|
|
2079
2090
|
const id = addContext(information, parentId, categories);
|
|
@@ -2086,28 +2097,27 @@ function useCopilotReadable({
|
|
|
2086
2097
|
}
|
|
2087
2098
|
|
|
2088
2099
|
// src/hooks/use-coagent.ts
|
|
2089
|
-
var
|
|
2090
|
-
var
|
|
2100
|
+
var import_react16 = require("react");
|
|
2101
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2091
2102
|
function useCoAgent(options) {
|
|
2092
|
-
const
|
|
2093
|
-
const { availableAgents } =
|
|
2103
|
+
const context = useCopilotContext();
|
|
2104
|
+
const { availableAgents } = context;
|
|
2094
2105
|
const { setBannerError } = useToast();
|
|
2095
|
-
const lastLoadedThreadId = (0,
|
|
2096
|
-
const lastLoadedState = (0,
|
|
2106
|
+
const lastLoadedThreadId = (0, import_react16.useRef)();
|
|
2107
|
+
const lastLoadedState = (0, import_react16.useRef)();
|
|
2097
2108
|
const { name } = options;
|
|
2098
|
-
(0,
|
|
2109
|
+
(0, import_react16.useEffect)(() => {
|
|
2099
2110
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
2100
2111
|
const message = `(useCoAgent): Agent "${name}" not found. Make sure the agent exists and is properly configured.`;
|
|
2101
2112
|
console.warn(message);
|
|
2102
|
-
const agentError = new
|
|
2113
|
+
const agentError = new import_shared12.CopilotKitAgentDiscoveryError({
|
|
2103
2114
|
agentName: name,
|
|
2104
2115
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
2105
2116
|
});
|
|
2106
2117
|
setBannerError(agentError);
|
|
2107
2118
|
}
|
|
2108
2119
|
}, [availableAgents]);
|
|
2109
|
-
const
|
|
2110
|
-
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2120
|
+
const { getMessagesFromTap } = useMessagesTap();
|
|
2111
2121
|
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
2112
2122
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
2113
2123
|
const headers = __spreadValues({}, copilotApiConfig.headers || {});
|
|
@@ -2118,7 +2128,7 @@ function useCoAgent(options) {
|
|
|
2118
2128
|
credentials: copilotApiConfig.credentials,
|
|
2119
2129
|
showDevConsole: context.showDevConsole
|
|
2120
2130
|
});
|
|
2121
|
-
const setState = (0,
|
|
2131
|
+
const setState = (0, import_react16.useCallback)(
|
|
2122
2132
|
(newState) => {
|
|
2123
2133
|
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
2124
2134
|
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
@@ -2130,7 +2140,7 @@ function useCoAgent(options) {
|
|
|
2130
2140
|
},
|
|
2131
2141
|
[coagentStates, name]
|
|
2132
2142
|
);
|
|
2133
|
-
(0,
|
|
2143
|
+
(0, import_react16.useEffect)(() => {
|
|
2134
2144
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
2135
2145
|
var _a, _b, _c, _d;
|
|
2136
2146
|
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
@@ -2148,13 +2158,13 @@ function useCoAgent(options) {
|
|
|
2148
2158
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
2149
2159
|
lastLoadedState.current = newState;
|
|
2150
2160
|
lastLoadedThreadId.current = threadId;
|
|
2151
|
-
const fetchedState = (0,
|
|
2161
|
+
const fetchedState = (0, import_shared12.parseJson)(newState, {});
|
|
2152
2162
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
2153
2163
|
}
|
|
2154
2164
|
});
|
|
2155
2165
|
void fetchAgentState();
|
|
2156
2166
|
}, [threadId]);
|
|
2157
|
-
(0,
|
|
2167
|
+
(0, import_react16.useEffect)(() => {
|
|
2158
2168
|
if (isExternalStateManagement(options)) {
|
|
2159
2169
|
setState(options.state);
|
|
2160
2170
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -2165,7 +2175,7 @@ function useCoAgent(options) {
|
|
|
2165
2175
|
// reset initialstate on reset
|
|
2166
2176
|
coagentStates[name] === void 0
|
|
2167
2177
|
]);
|
|
2168
|
-
(0,
|
|
2178
|
+
(0, import_react16.useEffect)(() => {
|
|
2169
2179
|
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
2170
2180
|
if (newConfig === void 0)
|
|
2171
2181
|
return;
|
|
@@ -2193,11 +2203,11 @@ function useCoAgent(options) {
|
|
|
2193
2203
|
}, [JSON.stringify(options.config), JSON.stringify(options.configurable)]);
|
|
2194
2204
|
const runAgentCallback = useAsyncCallback(
|
|
2195
2205
|
(hint) => __async(this, null, function* () {
|
|
2196
|
-
yield runAgent(name, context, appendMessage, runChatCompletion, hint);
|
|
2206
|
+
yield runAgent(name, context, getMessagesFromTap(), appendMessage, runChatCompletion, hint);
|
|
2197
2207
|
}),
|
|
2198
2208
|
[name, context, appendMessage, runChatCompletion]
|
|
2199
2209
|
);
|
|
2200
|
-
return (0,
|
|
2210
|
+
return (0, import_react16.useMemo)(() => {
|
|
2201
2211
|
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
2202
2212
|
return {
|
|
2203
2213
|
name,
|
|
@@ -2237,7 +2247,7 @@ function stopAgent(name, context) {
|
|
|
2237
2247
|
console.warn(`No agent session found for ${name}`);
|
|
2238
2248
|
}
|
|
2239
2249
|
}
|
|
2240
|
-
function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
2250
|
+
function runAgent(name, context, messages, appendMessage, runChatCompletion, hint) {
|
|
2241
2251
|
return __async(this, null, function* () {
|
|
2242
2252
|
var _a, _b;
|
|
2243
2253
|
const { agentSession, setAgentSession } = context;
|
|
@@ -2247,8 +2257,8 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
2247
2257
|
});
|
|
2248
2258
|
}
|
|
2249
2259
|
let previousState = null;
|
|
2250
|
-
for (let i =
|
|
2251
|
-
const message =
|
|
2260
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2261
|
+
const message = messages[i];
|
|
2252
2262
|
if (message.isAgentStateMessage() && message.agentName === name) {
|
|
2253
2263
|
previousState = message.state;
|
|
2254
2264
|
}
|
|
@@ -2294,28 +2304,28 @@ var getCoagentState = ({
|
|
|
2294
2304
|
};
|
|
2295
2305
|
|
|
2296
2306
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
2297
|
-
var
|
|
2298
|
-
var
|
|
2307
|
+
var import_react17 = require("react");
|
|
2308
|
+
var import_react18 = __toESM(require("react"));
|
|
2299
2309
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
2300
2310
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
2301
|
-
const pendingActionRef = (0,
|
|
2302
|
-
const executeAction2 = (0,
|
|
2311
|
+
const pendingActionRef = (0, import_react17.useRef)(null);
|
|
2312
|
+
const executeAction2 = (0, import_react17.useCallback)(
|
|
2303
2313
|
(props) => {
|
|
2304
2314
|
if (typeof action.render === "function") {
|
|
2305
2315
|
return action.render(props);
|
|
2306
2316
|
}
|
|
2307
|
-
return action.render ||
|
|
2317
|
+
return action.render || import_react18.default.createElement(import_react17.Fragment);
|
|
2308
2318
|
},
|
|
2309
2319
|
[action]
|
|
2310
2320
|
);
|
|
2311
|
-
const wrappedRender = (0,
|
|
2321
|
+
const wrappedRender = (0, import_react17.useCallback)(
|
|
2312
2322
|
(props) => {
|
|
2313
2323
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
2314
2324
|
(state) => state.status === "authenticated"
|
|
2315
2325
|
);
|
|
2316
2326
|
if (!isAuthenticated) {
|
|
2317
2327
|
pendingActionRef.current = props;
|
|
2318
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
2328
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react18.default.createElement(authConfig_c.SignInComponent, {
|
|
2319
2329
|
onSignInComplete: (authState) => {
|
|
2320
2330
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
2321
2331
|
if (pendingActionRef.current) {
|
|
@@ -2323,7 +2333,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2323
2333
|
pendingActionRef.current = null;
|
|
2324
2334
|
}
|
|
2325
2335
|
}
|
|
2326
|
-
}) :
|
|
2336
|
+
}) : import_react18.default.createElement(import_react17.Fragment);
|
|
2327
2337
|
}
|
|
2328
2338
|
return executeAction2(props);
|
|
2329
2339
|
},
|
|
@@ -2338,29 +2348,29 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2338
2348
|
}
|
|
2339
2349
|
|
|
2340
2350
|
// src/hooks/use-langgraph-interrupt.ts
|
|
2341
|
-
var
|
|
2342
|
-
var
|
|
2351
|
+
var import_react19 = require("react");
|
|
2352
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2343
2353
|
function useLangGraphInterrupt(action, dependencies) {
|
|
2344
2354
|
var _a;
|
|
2345
|
-
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0,
|
|
2355
|
+
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react19.useContext)(CopilotContext);
|
|
2346
2356
|
const { runChatCompletion } = useCopilotChat();
|
|
2347
2357
|
const { addToast } = useToast();
|
|
2348
|
-
const actionId = (0,
|
|
2349
|
-
const hasAction = (0,
|
|
2358
|
+
const actionId = (0, import_shared13.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
2359
|
+
const hasAction = (0, import_react19.useMemo)(
|
|
2350
2360
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
2351
2361
|
[langGraphInterruptAction]
|
|
2352
2362
|
);
|
|
2353
|
-
const isCurrentAction = (0,
|
|
2363
|
+
const isCurrentAction = (0, import_react19.useMemo)(
|
|
2354
2364
|
() => (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) && (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) === actionId,
|
|
2355
2365
|
[langGraphInterruptAction]
|
|
2356
2366
|
);
|
|
2357
|
-
(0,
|
|
2367
|
+
(0, import_react19.useEffect)(() => {
|
|
2358
2368
|
var _a2;
|
|
2359
2369
|
if (hasAction && isCurrentAction && ((_a2 = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a2.response)) {
|
|
2360
2370
|
runChatCompletion();
|
|
2361
2371
|
}
|
|
2362
2372
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
2363
|
-
(0,
|
|
2373
|
+
(0, import_react19.useEffect)(() => {
|
|
2364
2374
|
if (!action)
|
|
2365
2375
|
return;
|
|
2366
2376
|
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
@@ -2385,10 +2395,10 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
2385
2395
|
}
|
|
2386
2396
|
|
|
2387
2397
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
2388
|
-
var
|
|
2398
|
+
var import_react20 = require("react");
|
|
2389
2399
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
2390
2400
|
const { setAdditionalInstructions } = useCopilotContext();
|
|
2391
|
-
(0,
|
|
2401
|
+
(0, import_react20.useEffect)(() => {
|
|
2392
2402
|
if (available === "disabled")
|
|
2393
2403
|
return;
|
|
2394
2404
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|