@copilotkit/react-core 1.9.3 → 1.10.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +36 -0
- package/dist/chunk-2IDV5OHF.mjs +11 -0
- package/dist/chunk-2IDV5OHF.mjs.map +1 -0
- package/dist/{chunk-36MGCCPZ.mjs → chunk-4CFY3CON.mjs} +2 -2
- package/dist/{chunk-SP4LFJSS.mjs → chunk-4XVBXDCX.mjs} +2 -2
- package/dist/chunk-4XVBXDCX.mjs.map +1 -0
- package/dist/{chunk-BVK7PLK6.mjs → chunk-DF4YG4PF.mjs} +2 -2
- package/dist/{chunk-CUAFWKTQ.mjs → chunk-JZQOCH4A.mjs} +2 -2
- package/dist/{chunk-MEAIJ7V2.mjs → chunk-KV25ZRMH.mjs} +3 -3
- package/dist/{chunk-5BSUSFHM.mjs → chunk-LNAQ7JG3.mjs} +2 -2
- package/dist/{chunk-FN3UA2ZE.mjs → chunk-NXCJELW7.mjs} +3 -3
- package/dist/{chunk-GIMSRCVW.mjs → chunk-OMVNJ7S3.mjs} +149 -10
- package/dist/chunk-OMVNJ7S3.mjs.map +1 -0
- package/dist/{chunk-BSAVFYRQ.mjs → chunk-PYULBXCD.mjs} +2 -2
- package/dist/{chunk-VDADWRS3.mjs → chunk-Q6FZZJ5A.mjs} +2 -2
- package/dist/{chunk-KIXKBJUV.mjs → chunk-RGKZCCPA.mjs} +2 -2
- package/dist/{chunk-H56XI6TM.mjs → chunk-VM7CVIET.mjs} +3 -3
- package/dist/chunk-VM7CVIET.mjs.map +1 -0
- package/dist/{chunk-UBPKEQ7Z.mjs → chunk-VOMGRGWT.mjs} +94 -22
- package/dist/chunk-VOMGRGWT.mjs.map +1 -0
- package/dist/{chunk-NJA5ZLAZ.mjs → chunk-WUORFPJ7.mjs} +2 -2
- package/dist/chunk-WUORFPJ7.mjs.map +1 -0
- package/dist/{chunk-DKZTPL66.mjs → chunk-XGRBCWK6.mjs} +5 -2
- package/dist/chunk-XGRBCWK6.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +4 -1
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -2
- package/dist/components/copilot-provider/copilotkit-props.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +2 -1
- package/dist/components/copilot-provider/copilotkit.js +8 -2
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +4 -3
- package/dist/components/copilot-provider/index.d.ts +2 -1
- package/dist/components/copilot-provider/index.js +8 -2
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +4 -3
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.js +8 -2
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +4 -3
- package/dist/context/copilot-context.d.ts +2 -1
- package/dist/context/copilot-context.js +4 -1
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.js +4 -1
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/{copilot-context-3ab4fdf5.d.ts → copilot-context-bd88d30d.d.ts} +21 -1
- package/dist/hooks/index.d.ts +5 -5
- package/dist/hooks/index.js +492 -153
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +17 -16
- package/dist/hooks/use-chat.d.ts +6 -1
- package/dist/hooks/use-chat.js +4 -1
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +2 -2
- package/dist/hooks/use-coagent-state-render.js +4 -1
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +2 -2
- package/dist/hooks/use-coagent.d.ts +4 -4
- package/dist/hooks/use-coagent.js +426 -44
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +8 -6
- package/dist/hooks/use-copilot-action.d.ts +1 -1
- package/dist/hooks/use-copilot-action.js +4 -1
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +2 -2
- package/dist/hooks/use-copilot-additional-instructions.js +4 -1
- package/dist/hooks/use-copilot-additional-instructions.js.map +1 -1
- package/dist/hooks/use-copilot-additional-instructions.mjs +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js +4 -1
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +3 -3
- package/dist/hooks/use-copilot-chat.d.ts +43 -6
- package/dist/hooks/use-copilot-chat.js +442 -64
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +7 -5
- package/dist/hooks/use-copilot-readable.js +4 -1
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt-render.js +4 -1
- package/dist/hooks/use-langgraph-interrupt-render.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt-render.mjs +2 -2
- package/dist/hooks/use-langgraph-interrupt.d.ts +4 -3
- package/dist/hooks/use-langgraph-interrupt.js +451 -71
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +8 -6
- package/dist/hooks/use-make-copilot-document-readable.js +4 -1
- package/dist/hooks/use-make-copilot-document-readable.js.map +1 -1
- package/dist/hooks/use-make-copilot-document-readable.mjs +2 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +421 -200
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -18
- package/dist/lib/copilot-task.d.ts +2 -1
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +5 -4
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +5 -4
- package/dist/types/interrupt-action.d.ts +3 -2
- package/dist/utils/extract.d.ts +1 -1
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +4 -3
- package/dist/utils/index.d.ts +4 -3
- package/dist/utils/index.js +144 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +10 -4
- package/dist/utils/suggestions-constants.d.ts +9 -0
- package/dist/utils/suggestions-constants.js +35 -0
- package/dist/utils/suggestions-constants.js.map +1 -0
- package/dist/utils/suggestions-constants.mjs +8 -0
- package/dist/utils/suggestions-constants.mjs.map +1 -0
- package/dist/utils/suggestions.d.ts +11 -0
- package/dist/utils/suggestions.js +343 -0
- package/dist/utils/suggestions.js.map +1 -0
- package/dist/utils/suggestions.mjs +22 -0
- package/dist/utils/suggestions.mjs.map +1 -0
- package/package.json +3 -3
- package/src/components/copilot-provider/copilotkit.tsx +4 -0
- package/src/context/copilot-context.tsx +6 -0
- package/src/hooks/use-chat.ts +4 -0
- package/src/hooks/use-coagent.ts +2 -2
- package/src/hooks/use-copilot-action.ts +1 -1
- package/src/hooks/use-copilot-chat.ts +197 -21
- package/src/utils/index.ts +3 -0
- package/src/utils/suggestions-constants.ts +8 -0
- package/src/utils/suggestions.ts +208 -0
- package/dist/chunk-DKZTPL66.mjs.map +0 -1
- package/dist/chunk-GIMSRCVW.mjs.map +0 -1
- package/dist/chunk-H56XI6TM.mjs.map +0 -1
- package/dist/chunk-NJA5ZLAZ.mjs.map +0 -1
- package/dist/chunk-SP4LFJSS.mjs.map +0 -1
- package/dist/chunk-UBPKEQ7Z.mjs.map +0 -1
- /package/dist/{chunk-36MGCCPZ.mjs.map → chunk-4CFY3CON.mjs.map} +0 -0
- /package/dist/{chunk-BVK7PLK6.mjs.map → chunk-DF4YG4PF.mjs.map} +0 -0
- /package/dist/{chunk-CUAFWKTQ.mjs.map → chunk-JZQOCH4A.mjs.map} +0 -0
- /package/dist/{chunk-MEAIJ7V2.mjs.map → chunk-KV25ZRMH.mjs.map} +0 -0
- /package/dist/{chunk-5BSUSFHM.mjs.map → chunk-LNAQ7JG3.mjs.map} +0 -0
- /package/dist/{chunk-FN3UA2ZE.mjs.map → chunk-NXCJELW7.mjs.map} +0 -0
- /package/dist/{chunk-BSAVFYRQ.mjs.map → chunk-PYULBXCD.mjs.map} +0 -0
- /package/dist/{chunk-VDADWRS3.mjs.map → chunk-Q6FZZJ5A.mjs.map} +0 -0
- /package/dist/{chunk-KIXKBJUV.mjs.map → chunk-RGKZCCPA.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -85,8 +85,10 @@ __export(src_exports, {
|
|
|
85
85
|
CopilotKit: () => CopilotKit,
|
|
86
86
|
CopilotMessagesContext: () => CopilotMessagesContext,
|
|
87
87
|
CopilotTask: () => CopilotTask,
|
|
88
|
+
SUGGESTION_RETRY_CONFIG: () => SUGGESTION_RETRY_CONFIG,
|
|
88
89
|
defaultCopilotContextCategories: () => defaultCopilotContextCategories,
|
|
89
90
|
extract: () => extract,
|
|
91
|
+
reloadSuggestions: () => reloadSuggestions,
|
|
90
92
|
runAgent: () => runAgent,
|
|
91
93
|
shouldShowDevConsole: () => shouldShowDevConsole,
|
|
92
94
|
startAgent: () => startAgent,
|
|
@@ -184,7 +186,10 @@ var emptyCopilotContext = {
|
|
|
184
186
|
langGraphInterruptAction: null,
|
|
185
187
|
setLangGraphInterruptAction: () => null,
|
|
186
188
|
removeLangGraphInterruptAction: () => null,
|
|
187
|
-
onError: void 0
|
|
189
|
+
onError: void 0,
|
|
190
|
+
suggestions: [],
|
|
191
|
+
setSuggestions: () => {
|
|
192
|
+
}
|
|
188
193
|
};
|
|
189
194
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
190
195
|
function useCopilotContext() {
|
|
@@ -334,7 +339,7 @@ function setsHaveIntersection(setA, setB) {
|
|
|
334
339
|
|
|
335
340
|
// src/components/copilot-provider/copilotkit.tsx
|
|
336
341
|
var import_react_dom = require("react-dom");
|
|
337
|
-
var
|
|
342
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
338
343
|
|
|
339
344
|
// src/hooks/use-flat-category-store.ts
|
|
340
345
|
var import_react3 = require("react");
|
|
@@ -1144,12 +1149,152 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1144
1149
|
`;
|
|
1145
1150
|
}
|
|
1146
1151
|
|
|
1152
|
+
// src/utils/suggestions.ts
|
|
1153
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1154
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1155
|
+
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1156
|
+
const abortController = abortControllerRef.current;
|
|
1157
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
const setSuggestionsIfNotAborted = (suggestions) => {
|
|
1161
|
+
if (!(abortController == null ? void 0 : abortController.signal.aborted) && abortControllerRef.current === abortController) {
|
|
1162
|
+
setCurrentSuggestions(suggestions);
|
|
1163
|
+
}
|
|
1164
|
+
};
|
|
1165
|
+
try {
|
|
1166
|
+
const tools = JSON.stringify(
|
|
1167
|
+
Object.values(context.actions).map((action) => ({
|
|
1168
|
+
name: action.name,
|
|
1169
|
+
description: action.description,
|
|
1170
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters))
|
|
1171
|
+
}))
|
|
1172
|
+
);
|
|
1173
|
+
const allSuggestions = [];
|
|
1174
|
+
let hasSuccessfulSuggestions = false;
|
|
1175
|
+
let hasErrors = false;
|
|
1176
|
+
let lastError = null;
|
|
1177
|
+
const enabledConfigs = Object.values(chatSuggestionConfiguration).filter(
|
|
1178
|
+
(config) => config.instructions && config.instructions.trim().length > 0
|
|
1179
|
+
);
|
|
1180
|
+
if (enabledConfigs.length === 0) {
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
setSuggestionsIfNotAborted([]);
|
|
1184
|
+
for (const config of enabledConfigs) {
|
|
1185
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1186
|
+
setSuggestionsIfNotAborted([]);
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
try {
|
|
1190
|
+
const result = yield extract({
|
|
1191
|
+
context,
|
|
1192
|
+
instructions: "Suggest what the user could say next. Provide clear, highly relevant suggestions. Do not literally suggest function calls. ",
|
|
1193
|
+
data: `${config.instructions}
|
|
1194
|
+
|
|
1195
|
+
Available tools: ${tools}
|
|
1196
|
+
|
|
1197
|
+
`,
|
|
1198
|
+
requestType: import_runtime_client_gql5.CopilotRequestType.Task,
|
|
1199
|
+
parameters: [
|
|
1200
|
+
{
|
|
1201
|
+
name: "suggestions",
|
|
1202
|
+
type: "object[]",
|
|
1203
|
+
attributes: [
|
|
1204
|
+
{
|
|
1205
|
+
name: "title",
|
|
1206
|
+
description: "The title of the suggestion. This is shown as a button and should be short.",
|
|
1207
|
+
type: "string"
|
|
1208
|
+
},
|
|
1209
|
+
{
|
|
1210
|
+
name: "message",
|
|
1211
|
+
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.",
|
|
1212
|
+
type: "string"
|
|
1213
|
+
}
|
|
1214
|
+
]
|
|
1215
|
+
}
|
|
1216
|
+
],
|
|
1217
|
+
include: {
|
|
1218
|
+
messages: true,
|
|
1219
|
+
readable: true
|
|
1220
|
+
},
|
|
1221
|
+
abortSignal: abortController == null ? void 0 : abortController.signal,
|
|
1222
|
+
stream: ({ status, args }) => {
|
|
1223
|
+
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
const suggestions = args.suggestions || [];
|
|
1227
|
+
const newSuggestions = [];
|
|
1228
|
+
for (let i = 0; i < suggestions.length; i++) {
|
|
1229
|
+
if (config.maxSuggestions !== void 0 && i >= config.maxSuggestions) {
|
|
1230
|
+
break;
|
|
1231
|
+
}
|
|
1232
|
+
const suggestion = suggestions[i];
|
|
1233
|
+
if (!suggestion || typeof suggestion !== "object") {
|
|
1234
|
+
continue;
|
|
1235
|
+
}
|
|
1236
|
+
const { title, message } = suggestion;
|
|
1237
|
+
const hasValidTitle = title && typeof title === "string" && title.trim().length > 0;
|
|
1238
|
+
const hasValidMessage = message && typeof message === "string" && message.trim().length > 0;
|
|
1239
|
+
if (!hasValidTitle) {
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
const partial = i === suggestions.length - 1 && status !== "complete";
|
|
1243
|
+
newSuggestions.push({
|
|
1244
|
+
title: title.trim(),
|
|
1245
|
+
message: hasValidMessage ? message.trim() : "",
|
|
1246
|
+
// Use title as fallback
|
|
1247
|
+
partial,
|
|
1248
|
+
className: config.className
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
setSuggestionsIfNotAborted([...allSuggestions, ...newSuggestions]);
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
if ((result == null ? void 0 : result.suggestions) && Array.isArray(result.suggestions)) {
|
|
1255
|
+
const validSuggestions = result.suggestions.filter(
|
|
1256
|
+
(suggestion) => suggestion && typeof suggestion.title === "string" && suggestion.title.trim().length > 0
|
|
1257
|
+
).map((suggestion) => ({
|
|
1258
|
+
title: suggestion.title.trim(),
|
|
1259
|
+
message: suggestion.message && typeof suggestion.message === "string" && suggestion.message.trim() ? suggestion.message.trim() : suggestion.title.trim()
|
|
1260
|
+
}));
|
|
1261
|
+
if (validSuggestions.length > 0) {
|
|
1262
|
+
allSuggestions.push(...validSuggestions);
|
|
1263
|
+
hasSuccessfulSuggestions = true;
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
} catch (error) {
|
|
1267
|
+
hasErrors = true;
|
|
1268
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
if (hasSuccessfulSuggestions && allSuggestions.length > 0) {
|
|
1272
|
+
const uniqueSuggestions = allSuggestions.filter(
|
|
1273
|
+
(suggestion, index, self) => index === self.findIndex((s) => s.message === suggestion.message)
|
|
1274
|
+
);
|
|
1275
|
+
setSuggestionsIfNotAborted(uniqueSuggestions);
|
|
1276
|
+
} else if (hasErrors) {
|
|
1277
|
+
const errorMessage = lastError ? lastError.message : "Failed to generate suggestions due to API errors";
|
|
1278
|
+
throw new Error(errorMessage);
|
|
1279
|
+
}
|
|
1280
|
+
} catch (error) {
|
|
1281
|
+
throw error;
|
|
1282
|
+
}
|
|
1283
|
+
});
|
|
1284
|
+
|
|
1285
|
+
// src/utils/suggestions-constants.ts
|
|
1286
|
+
var SUGGESTION_RETRY_CONFIG = {
|
|
1287
|
+
MAX_RETRIES: 3,
|
|
1288
|
+
COOLDOWN_MS: 5e3
|
|
1289
|
+
// 5 seconds
|
|
1290
|
+
};
|
|
1291
|
+
|
|
1147
1292
|
// src/components/error-boundary/error-boundary.tsx
|
|
1148
1293
|
var import_react9 = __toESM(require("react"));
|
|
1149
|
-
var
|
|
1294
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1150
1295
|
|
|
1151
1296
|
// src/lib/status-checker.ts
|
|
1152
|
-
var
|
|
1297
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1153
1298
|
var STATUS_CHECK_INTERVAL = 1e3 * 60 * 5;
|
|
1154
1299
|
var StatusChecker = class {
|
|
1155
1300
|
constructor() {
|
|
@@ -1167,10 +1312,10 @@ var StatusChecker = class {
|
|
|
1167
1312
|
clearInterval(this.intervalId);
|
|
1168
1313
|
const checkStatus = () => __async(this, null, function* () {
|
|
1169
1314
|
try {
|
|
1170
|
-
const response = yield fetch(`${
|
|
1315
|
+
const response = yield fetch(`${import_shared8.COPILOT_CLOUD_API_URL}/ciu`, {
|
|
1171
1316
|
method: "GET",
|
|
1172
1317
|
headers: {
|
|
1173
|
-
[
|
|
1318
|
+
[import_shared8.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey
|
|
1174
1319
|
}
|
|
1175
1320
|
}).then((response2) => response2.json());
|
|
1176
1321
|
this.lastResponse = response;
|
|
@@ -1203,10 +1348,10 @@ var StatusChecker = class {
|
|
|
1203
1348
|
};
|
|
1204
1349
|
|
|
1205
1350
|
// src/components/usage-banner.tsx
|
|
1206
|
-
var
|
|
1351
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1207
1352
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
1208
1353
|
var defaultIcons = {
|
|
1209
|
-
[
|
|
1354
|
+
[import_shared9.Severity.CRITICAL]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1210
1355
|
"svg",
|
|
1211
1356
|
{
|
|
1212
1357
|
viewBox: "0 0 24 24",
|
|
@@ -1224,7 +1369,7 @@ var defaultIcons = {
|
|
|
1224
1369
|
]
|
|
1225
1370
|
}
|
|
1226
1371
|
),
|
|
1227
|
-
[
|
|
1372
|
+
[import_shared9.Severity.WARNING]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1228
1373
|
"svg",
|
|
1229
1374
|
{
|
|
1230
1375
|
viewBox: "0 0 24 24",
|
|
@@ -1242,7 +1387,7 @@ var defaultIcons = {
|
|
|
1242
1387
|
]
|
|
1243
1388
|
}
|
|
1244
1389
|
),
|
|
1245
|
-
[
|
|
1390
|
+
[import_shared9.Severity.INFO]: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1246
1391
|
"svg",
|
|
1247
1392
|
{
|
|
1248
1393
|
viewBox: "0 0 24 24",
|
|
@@ -1262,7 +1407,7 @@ var defaultIcons = {
|
|
|
1262
1407
|
)
|
|
1263
1408
|
};
|
|
1264
1409
|
function UsageBanner({
|
|
1265
|
-
severity =
|
|
1410
|
+
severity = import_shared9.Severity.CRITICAL,
|
|
1266
1411
|
message = "",
|
|
1267
1412
|
icon,
|
|
1268
1413
|
onClose,
|
|
@@ -1297,7 +1442,7 @@ function UsageBanner({
|
|
|
1297
1442
|
const cleanMessage = parseMessage(message);
|
|
1298
1443
|
const Icon = icon || defaultIcons[severity];
|
|
1299
1444
|
const themeConfigs = {
|
|
1300
|
-
[
|
|
1445
|
+
[import_shared9.Severity.INFO]: {
|
|
1301
1446
|
bg: "rgba(239, 246, 255, 0.95)",
|
|
1302
1447
|
border: "#93c5fd",
|
|
1303
1448
|
text: "#1e40af",
|
|
@@ -1305,7 +1450,7 @@ function UsageBanner({
|
|
|
1305
1450
|
primaryBtn: "#3b82f6",
|
|
1306
1451
|
primaryBtnHover: "#2563eb"
|
|
1307
1452
|
},
|
|
1308
|
-
[
|
|
1453
|
+
[import_shared9.Severity.WARNING]: {
|
|
1309
1454
|
bg: "rgba(255, 251, 235, 0.95)",
|
|
1310
1455
|
border: "#fbbf24",
|
|
1311
1456
|
text: "#92400e",
|
|
@@ -1313,7 +1458,7 @@ function UsageBanner({
|
|
|
1313
1458
|
primaryBtn: "#f59e0b",
|
|
1314
1459
|
primaryBtnHover: "#d97706"
|
|
1315
1460
|
},
|
|
1316
|
-
[
|
|
1461
|
+
[import_shared9.Severity.CRITICAL]: {
|
|
1317
1462
|
bg: "rgba(254, 242, 242, 0.95)",
|
|
1318
1463
|
border: "#f87171",
|
|
1319
1464
|
text: "#991b1b",
|
|
@@ -1322,7 +1467,7 @@ function UsageBanner({
|
|
|
1322
1467
|
primaryBtnHover: "#dc2626"
|
|
1323
1468
|
}
|
|
1324
1469
|
};
|
|
1325
|
-
const themeConfig = themeConfigs[severity] || themeConfigs[
|
|
1470
|
+
const themeConfig = themeConfigs[severity] || themeConfigs[import_shared9.Severity.CRITICAL];
|
|
1326
1471
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
1327
1472
|
"div",
|
|
1328
1473
|
{
|
|
@@ -1491,7 +1636,7 @@ function UsageBanner({
|
|
|
1491
1636
|
);
|
|
1492
1637
|
}
|
|
1493
1638
|
function renderCopilotKitUsage(error, onClose) {
|
|
1494
|
-
if (error.visibility !==
|
|
1639
|
+
if (error.visibility !== import_shared9.ErrorVisibility.BANNER) {
|
|
1495
1640
|
return null;
|
|
1496
1641
|
}
|
|
1497
1642
|
const extractUrlFromMessage = (message) => {
|
|
@@ -1501,23 +1646,23 @@ function renderCopilotKitUsage(error, onClose) {
|
|
|
1501
1646
|
};
|
|
1502
1647
|
const getErrorActions = (error2) => {
|
|
1503
1648
|
switch (error2.name) {
|
|
1504
|
-
case
|
|
1649
|
+
case import_shared9.ERROR_NAMES.MISSING_PUBLIC_API_KEY_ERROR:
|
|
1505
1650
|
return {
|
|
1506
1651
|
primary: {
|
|
1507
1652
|
label: "Sign In",
|
|
1508
1653
|
onClick: () => window.location.href = "https://cloud.copilotkit.ai"
|
|
1509
1654
|
}
|
|
1510
1655
|
};
|
|
1511
|
-
case
|
|
1656
|
+
case import_shared9.ERROR_NAMES.UPGRADE_REQUIRED_ERROR:
|
|
1512
1657
|
return {
|
|
1513
1658
|
primary: {
|
|
1514
1659
|
label: "Upgrade",
|
|
1515
1660
|
onClick: () => window.location.href = "https://copilotkit.ai/"
|
|
1516
1661
|
}
|
|
1517
1662
|
};
|
|
1518
|
-
case
|
|
1519
|
-
case
|
|
1520
|
-
case
|
|
1663
|
+
case import_shared9.ERROR_NAMES.COPILOT_API_DISCOVERY_ERROR:
|
|
1664
|
+
case import_shared9.ERROR_NAMES.COPILOT_REMOTE_ENDPOINT_DISCOVERY_ERROR:
|
|
1665
|
+
case import_shared9.ERROR_NAMES.COPILOT_KIT_AGENT_DISCOVERY_ERROR:
|
|
1521
1666
|
return {
|
|
1522
1667
|
primary: {
|
|
1523
1668
|
label: "View Docs",
|
|
@@ -1537,7 +1682,7 @@ function renderCopilotKitUsage(error, onClose) {
|
|
|
1537
1682
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
1538
1683
|
UsageBanner,
|
|
1539
1684
|
{
|
|
1540
|
-
severity: error.severity ||
|
|
1685
|
+
severity: error.severity || import_shared9.Severity.CRITICAL,
|
|
1541
1686
|
message: error.message,
|
|
1542
1687
|
onClose,
|
|
1543
1688
|
actions: getErrorActions(error)
|
|
@@ -1695,8 +1840,8 @@ var CopilotErrorBoundary = class extends import_react9.default.Component {
|
|
|
1695
1840
|
render() {
|
|
1696
1841
|
var _a, _b;
|
|
1697
1842
|
if (this.state.hasError) {
|
|
1698
|
-
if (this.state.error instanceof
|
|
1699
|
-
if (this.state.error.visibility ===
|
|
1843
|
+
if (this.state.error instanceof import_shared10.CopilotKitError) {
|
|
1844
|
+
if (this.state.error.visibility === import_shared10.ErrorVisibility.BANNER) {
|
|
1700
1845
|
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ErrorToast2, { error: this.state.error, children: renderCopilotKitUsage(
|
|
1701
1846
|
this.state.error,
|
|
1702
1847
|
() => this.setState({ hasError: false, error: void 0 })
|
|
@@ -1743,7 +1888,7 @@ function CopilotKitInternal(cpkProps) {
|
|
|
1743
1888
|
var _b, _c;
|
|
1744
1889
|
const _a = cpkProps, { children } = _a, props = __objRest(_a, ["children"]);
|
|
1745
1890
|
validateProps(cpkProps);
|
|
1746
|
-
const chatApiEndpoint = props.runtimeUrl ||
|
|
1891
|
+
const chatApiEndpoint = props.runtimeUrl || import_shared11.COPILOT_CLOUD_CHAT_URL;
|
|
1747
1892
|
const [actions, setActions] = (0, import_react10.useState)({});
|
|
1748
1893
|
const [coAgentStateRenders, setCoAgentStateRenders] = (0, import_react10.useState)({});
|
|
1749
1894
|
const chatComponentsCache = (0, import_react10.useRef)({
|
|
@@ -1891,7 +2036,7 @@ ${nonDocumentStrings}`;
|
|
|
1891
2036
|
}
|
|
1892
2037
|
return acc;
|
|
1893
2038
|
}, {});
|
|
1894
|
-
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [
|
|
2039
|
+
return __spreadValues(__spreadValues(__spreadValues({}, copilotApiConfig.headers || {}), copilotApiConfig.publicApiKey ? { [import_shared11.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: copilotApiConfig.publicApiKey } : {}), authHeaders);
|
|
1895
2040
|
}, [copilotApiConfig.headers, copilotApiConfig.publicApiKey, authStates]);
|
|
1896
2041
|
const runtimeClient = useCopilotRuntimeClient({
|
|
1897
2042
|
url: copilotApiConfig.chatApiEndpoint,
|
|
@@ -1960,7 +2105,7 @@ ${nonDocumentStrings}`;
|
|
|
1960
2105
|
setAgentSession(null);
|
|
1961
2106
|
}
|
|
1962
2107
|
}, [props.agent]);
|
|
1963
|
-
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0,
|
|
2108
|
+
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared11.randomUUID)());
|
|
1964
2109
|
const setThreadId = (0, import_react10.useCallback)(
|
|
1965
2110
|
(value) => {
|
|
1966
2111
|
if (props.threadId) {
|
|
@@ -1996,6 +2141,7 @@ ${nonDocumentStrings}`;
|
|
|
1996
2141
|
setLangGraphInterruptAction(null);
|
|
1997
2142
|
}, []);
|
|
1998
2143
|
const memoizedChildren = (0, import_react10.useMemo)(() => children, [children]);
|
|
2144
|
+
const [suggestions, setSuggestions] = (0, import_react10.useState)([]);
|
|
1999
2145
|
const agentLock = (0, import_react10.useMemo)(() => {
|
|
2000
2146
|
var _a2;
|
|
2001
2147
|
return (_a2 = props.agent) != null ? _a2 : null;
|
|
@@ -2084,7 +2230,9 @@ ${nonDocumentStrings}`;
|
|
|
2084
2230
|
langGraphInterruptAction,
|
|
2085
2231
|
setLangGraphInterruptAction,
|
|
2086
2232
|
removeLangGraphInterruptAction,
|
|
2087
|
-
onError: props.onError
|
|
2233
|
+
onError: props.onError,
|
|
2234
|
+
suggestions,
|
|
2235
|
+
setSuggestions
|
|
2088
2236
|
},
|
|
2089
2237
|
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(CopilotMessages, { children: memoizedChildren })
|
|
2090
2238
|
}
|
|
@@ -2122,44 +2270,43 @@ function formatFeatureName(featureName) {
|
|
|
2122
2270
|
function validateProps(props) {
|
|
2123
2271
|
const cloudFeatures = Object.keys(props).filter((key) => key.endsWith("_c"));
|
|
2124
2272
|
if (!props.runtimeUrl && !props.publicApiKey) {
|
|
2125
|
-
throw new
|
|
2273
|
+
throw new import_shared11.ConfigurationError("Missing required prop: 'runtimeUrl' or 'publicApiKey'");
|
|
2126
2274
|
}
|
|
2127
2275
|
if (cloudFeatures.length > 0 && !props.publicApiKey) {
|
|
2128
|
-
throw new
|
|
2276
|
+
throw new import_shared11.MissingPublicApiKeyError(
|
|
2129
2277
|
`Missing required prop: 'publicApiKey' to use cloud features: ${cloudFeatures.map(formatFeatureName).join(", ")}`
|
|
2130
2278
|
);
|
|
2131
2279
|
}
|
|
2132
2280
|
}
|
|
2133
2281
|
|
|
2134
2282
|
// src/hooks/use-copilot-chat.ts
|
|
2135
|
-
var
|
|
2136
|
-
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
2283
|
+
var import_react13 = require("react");
|
|
2137
2284
|
|
|
2138
2285
|
// src/hooks/use-chat.ts
|
|
2139
2286
|
var import_react11 = require("react");
|
|
2140
2287
|
var import_react_dom2 = require("react-dom");
|
|
2141
|
-
var
|
|
2142
|
-
var
|
|
2288
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2289
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
2143
2290
|
|
|
2144
2291
|
// src/types/frontend-action.ts
|
|
2145
|
-
var
|
|
2146
|
-
var
|
|
2292
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
2293
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2147
2294
|
function processActionsForRuntimeRequest(actions) {
|
|
2148
2295
|
const filteredActions = actions.filter(
|
|
2149
|
-
(action) => action.available !==
|
|
2296
|
+
(action) => action.available !== import_runtime_client_gql6.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*" && action.available != "frontend" && !action.pairedAction
|
|
2150
2297
|
).map((action) => {
|
|
2151
|
-
let available =
|
|
2298
|
+
let available = import_runtime_client_gql6.ActionInputAvailability.Enabled;
|
|
2152
2299
|
if (action.disabled) {
|
|
2153
|
-
available =
|
|
2300
|
+
available = import_runtime_client_gql6.ActionInputAvailability.Disabled;
|
|
2154
2301
|
} else if (action.available === "disabled") {
|
|
2155
|
-
available =
|
|
2302
|
+
available = import_runtime_client_gql6.ActionInputAvailability.Disabled;
|
|
2156
2303
|
} else if (action.available === "remote") {
|
|
2157
|
-
available =
|
|
2304
|
+
available = import_runtime_client_gql6.ActionInputAvailability.Remote;
|
|
2158
2305
|
}
|
|
2159
2306
|
return {
|
|
2160
2307
|
name: action.name,
|
|
2161
2308
|
description: action.description || "",
|
|
2162
|
-
jsonSchema: JSON.stringify((0,
|
|
2309
|
+
jsonSchema: JSON.stringify((0, import_shared12.actionParametersToJsonSchema)(action.parameters || [])),
|
|
2163
2310
|
available
|
|
2164
2311
|
};
|
|
2165
2312
|
});
|
|
@@ -2232,7 +2379,7 @@ function useChat(options) {
|
|
|
2232
2379
|
const extensionsRef = (0, import_react11.useRef)(extensions);
|
|
2233
2380
|
extensionsRef.current = extensions;
|
|
2234
2381
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
2235
|
-
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [
|
|
2382
|
+
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared13.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
2236
2383
|
const { showDevConsole } = useCopilotContext();
|
|
2237
2384
|
const runtimeClient = useCopilotRuntimeClient({
|
|
2238
2385
|
url: copilotConfig.chatApiEndpoint,
|
|
@@ -2247,7 +2394,7 @@ function useChat(options) {
|
|
|
2247
2394
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
2248
2395
|
setIsLoading(true);
|
|
2249
2396
|
const interruptEvent = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event;
|
|
2250
|
-
if ((interruptEvent == null ? void 0 : interruptEvent.name) ===
|
|
2397
|
+
if ((interruptEvent == null ? void 0 : interruptEvent.name) === import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent && (interruptEvent == null ? void 0 : interruptEvent.value) && !(interruptEvent == null ? void 0 : interruptEvent.response) && agentSessionRef.current) {
|
|
2251
2398
|
addErrorToast([
|
|
2252
2399
|
new Error(
|
|
2253
2400
|
"A message was sent while interrupt is active. This will cause failure on the agent side"
|
|
@@ -2255,9 +2402,9 @@ function useChat(options) {
|
|
|
2255
2402
|
]);
|
|
2256
2403
|
}
|
|
2257
2404
|
let newMessages = [
|
|
2258
|
-
new
|
|
2405
|
+
new import_runtime_client_gql7.TextMessage({
|
|
2259
2406
|
content: "",
|
|
2260
|
-
role:
|
|
2407
|
+
role: import_runtime_client_gql7.Role.Assistant
|
|
2261
2408
|
})
|
|
2262
2409
|
];
|
|
2263
2410
|
chatAbortControllerRef.current = new AbortController();
|
|
@@ -2287,7 +2434,7 @@ function useChat(options) {
|
|
|
2287
2434
|
runId: runIdRef.current,
|
|
2288
2435
|
extensions: extensionsRef.current,
|
|
2289
2436
|
metaEvents: composeAndFlushMetaEventsInput([langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event]),
|
|
2290
|
-
messages: (0,
|
|
2437
|
+
messages: (0, import_runtime_client_gql7.convertMessagesToGqlInput)((0, import_runtime_client_gql7.filterAgentStateMessages)(messagesWithContext))
|
|
2291
2438
|
}, copilotConfig.cloud ? {
|
|
2292
2439
|
cloud: __spreadValues({}, ((_d = (_c = (_b = copilotConfig.cloud.guardrails) == null ? void 0 : _b.input) == null ? void 0 : _c.restrictToTopic) == null ? void 0 : _d.enabled) ? {
|
|
2293
2440
|
guardrails: {
|
|
@@ -2299,7 +2446,7 @@ function useChat(options) {
|
|
|
2299
2446
|
} : {})
|
|
2300
2447
|
} : {}), {
|
|
2301
2448
|
metadata: {
|
|
2302
|
-
requestType:
|
|
2449
|
+
requestType: import_runtime_client_gql7.CopilotRequestType.Chat
|
|
2303
2450
|
}
|
|
2304
2451
|
}), agentSessionRef.current ? {
|
|
2305
2452
|
agentSession: agentSessionRef.current
|
|
@@ -2347,7 +2494,7 @@ function useChat(options) {
|
|
|
2347
2494
|
continue;
|
|
2348
2495
|
}
|
|
2349
2496
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
2350
|
-
extensionsRef.current =
|
|
2497
|
+
extensionsRef.current = import_runtime_client_gql7.CopilotRuntimeClient.removeGraphQLTypename(
|
|
2351
2498
|
value.generateCopilotResponse.extensions || {}
|
|
2352
2499
|
);
|
|
2353
2500
|
setRunId(runIdRef.current);
|
|
@@ -2355,39 +2502,39 @@ function useChat(options) {
|
|
|
2355
2502
|
let rawMessagesResponse = value.generateCopilotResponse.messages;
|
|
2356
2503
|
const metaEvents = (_j = (_i = value.generateCopilotResponse) == null ? void 0 : _i.metaEvents) != null ? _j : [];
|
|
2357
2504
|
(metaEvents != null ? metaEvents : []).forEach((ev) => {
|
|
2358
|
-
if (ev.name ===
|
|
2359
|
-
let eventValue = (0,
|
|
2360
|
-
eventValue = (0,
|
|
2505
|
+
if (ev.name === import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent) {
|
|
2506
|
+
let eventValue = (0, import_runtime_client_gql7.langGraphInterruptEvent)(ev).value;
|
|
2507
|
+
eventValue = (0, import_shared13.parseJson)(eventValue, eventValue);
|
|
2361
2508
|
setLangGraphInterruptAction({
|
|
2362
|
-
event: __spreadProps(__spreadValues({}, (0,
|
|
2509
|
+
event: __spreadProps(__spreadValues({}, (0, import_runtime_client_gql7.langGraphInterruptEvent)(ev)), {
|
|
2363
2510
|
value: eventValue
|
|
2364
2511
|
})
|
|
2365
2512
|
});
|
|
2366
2513
|
}
|
|
2367
|
-
if (ev.name ===
|
|
2514
|
+
if (ev.name === import_runtime_client_gql7.MetaEventName.CopilotKitLangGraphInterruptEvent) {
|
|
2368
2515
|
const data = ev.data;
|
|
2369
2516
|
rawMessagesResponse = [...rawMessagesResponse, ...data.messages];
|
|
2370
|
-
interruptMessages = (0,
|
|
2517
|
+
interruptMessages = (0, import_runtime_client_gql7.convertGqlOutputToMessages)(
|
|
2371
2518
|
// @ts-ignore
|
|
2372
|
-
(0,
|
|
2519
|
+
(0, import_runtime_client_gql7.filterAdjacentAgentStateMessages)(data.messages)
|
|
2373
2520
|
);
|
|
2374
2521
|
}
|
|
2375
2522
|
});
|
|
2376
|
-
messages2 = (0,
|
|
2377
|
-
(0,
|
|
2523
|
+
messages2 = (0, import_runtime_client_gql7.convertGqlOutputToMessages)(
|
|
2524
|
+
(0, import_runtime_client_gql7.filterAdjacentAgentStateMessages)(rawMessagesResponse)
|
|
2378
2525
|
);
|
|
2379
2526
|
newMessages = [];
|
|
2380
2527
|
if (((_k = value.generateCopilotResponse.status) == null ? void 0 : _k.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
2381
2528
|
const guardrailsReason = ((_l = value.generateCopilotResponse.status.details) == null ? void 0 : _l.guardrailsReason) || "";
|
|
2382
2529
|
newMessages = [
|
|
2383
|
-
new
|
|
2384
|
-
role:
|
|
2530
|
+
new import_runtime_client_gql7.TextMessage({
|
|
2531
|
+
role: import_runtime_client_gql7.MessageRole.Assistant,
|
|
2385
2532
|
content: guardrailsReason
|
|
2386
2533
|
})
|
|
2387
2534
|
];
|
|
2388
|
-
const guardrailsError = new
|
|
2535
|
+
const guardrailsError = new import_shared13.CopilotKitError({
|
|
2389
2536
|
message: `Guardrails validation failed: ${guardrailsReason}`,
|
|
2390
|
-
code:
|
|
2537
|
+
code: import_shared13.CopilotKitErrorCode.MISUSE
|
|
2391
2538
|
});
|
|
2392
2539
|
yield traceUIError(guardrailsError, {
|
|
2393
2540
|
statusReason: value.generateCopilotResponse.status.reason,
|
|
@@ -2403,11 +2550,11 @@ function useChat(options) {
|
|
|
2403
2550
|
const originalCode = (originalError == null ? void 0 : originalError.code) || ((_o = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _o.code);
|
|
2404
2551
|
const originalSeverity = (originalError == null ? void 0 : originalError.severity) || ((_p = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _p.severity);
|
|
2405
2552
|
const originalVisibility = (originalError == null ? void 0 : originalError.visibility) || ((_q = originalError == null ? void 0 : originalError.extensions) == null ? void 0 : _q.visibility);
|
|
2406
|
-
let errorCode =
|
|
2407
|
-
if (originalCode && Object.values(
|
|
2553
|
+
let errorCode = import_shared13.CopilotKitErrorCode.NETWORK_ERROR;
|
|
2554
|
+
if (originalCode && Object.values(import_shared13.CopilotKitErrorCode).includes(originalCode)) {
|
|
2408
2555
|
errorCode = originalCode;
|
|
2409
2556
|
}
|
|
2410
|
-
const structuredError = new
|
|
2557
|
+
const structuredError = new import_shared13.CopilotKitError({
|
|
2411
2558
|
message: errorMessage,
|
|
2412
2559
|
code: errorCode,
|
|
2413
2560
|
severity: originalSeverity,
|
|
@@ -2440,7 +2587,7 @@ function useChat(options) {
|
|
|
2440
2587
|
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
2441
2588
|
if (lastAgentStateMessage) {
|
|
2442
2589
|
if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
|
|
2443
|
-
syncedMessages = (0,
|
|
2590
|
+
syncedMessages = (0, import_runtime_client_gql7.loadMessagesFromJsonRepresentation)(
|
|
2444
2591
|
lastAgentStateMessage.state.messages
|
|
2445
2592
|
);
|
|
2446
2593
|
}
|
|
@@ -2469,7 +2616,7 @@ function useChat(options) {
|
|
|
2469
2616
|
} else {
|
|
2470
2617
|
if (agentLock) {
|
|
2471
2618
|
setAgentSession({
|
|
2472
|
-
threadId: (0,
|
|
2619
|
+
threadId: (0, import_shared13.randomId)(),
|
|
2473
2620
|
agentName: agentLock,
|
|
2474
2621
|
nodeName: void 0
|
|
2475
2622
|
});
|
|
@@ -2526,7 +2673,7 @@ function useChat(options) {
|
|
|
2526
2673
|
const lastMessages = [];
|
|
2527
2674
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
2528
2675
|
const message = finalMessages[i];
|
|
2529
|
-
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !==
|
|
2676
|
+
if ((message.isActionExecutionMessage() || message.isResultMessage()) && message.status.code !== import_runtime_client_gql7.MessageStatusCode.Pending) {
|
|
2530
2677
|
lastMessages.unshift(message);
|
|
2531
2678
|
} else if (!message.isAgentStateMessage()) {
|
|
2532
2679
|
break;
|
|
@@ -2554,9 +2701,9 @@ function useChat(options) {
|
|
|
2554
2701
|
);
|
|
2555
2702
|
const pairedFeAction = getPairedFeAction(actions, resultMessage);
|
|
2556
2703
|
if (pairedFeAction) {
|
|
2557
|
-
const newExecutionMessage = new
|
|
2704
|
+
const newExecutionMessage = new import_runtime_client_gql7.ActionExecutionMessage({
|
|
2558
2705
|
name: pairedFeAction.name,
|
|
2559
|
-
arguments: (0,
|
|
2706
|
+
arguments: (0, import_shared13.parseJson)(resultMessage.result, resultMessage.result),
|
|
2560
2707
|
status: message.status,
|
|
2561
2708
|
createdAt: message.createdAt,
|
|
2562
2709
|
parentMessageId: message.parentMessageId
|
|
@@ -2565,9 +2712,9 @@ function useChat(options) {
|
|
|
2565
2712
|
}
|
|
2566
2713
|
}
|
|
2567
2714
|
} else if (message.isResultMessage() && currentResultMessagePairedFeAction) {
|
|
2568
|
-
const newExecutionMessage = new
|
|
2715
|
+
const newExecutionMessage = new import_runtime_client_gql7.ActionExecutionMessage({
|
|
2569
2716
|
name: currentResultMessagePairedFeAction.name,
|
|
2570
|
-
arguments: (0,
|
|
2717
|
+
arguments: (0, import_shared13.parseJson)(message.result, message.result),
|
|
2571
2718
|
status: message.status,
|
|
2572
2719
|
createdAt: message.createdAt
|
|
2573
2720
|
});
|
|
@@ -2652,7 +2799,7 @@ function useChat(options) {
|
|
|
2652
2799
|
if (!event)
|
|
2653
2800
|
return acc;
|
|
2654
2801
|
switch (event.name) {
|
|
2655
|
-
case
|
|
2802
|
+
case import_runtime_client_gql7.MetaEventName.LangGraphInterruptEvent:
|
|
2656
2803
|
if (event.response) {
|
|
2657
2804
|
setLangGraphInterruptAction(null);
|
|
2658
2805
|
const value = event.value;
|
|
@@ -2700,7 +2847,7 @@ function useChat(options) {
|
|
|
2700
2847
|
return;
|
|
2701
2848
|
}
|
|
2702
2849
|
const reloadMessageRole = messages[reloadMessageIndex].role;
|
|
2703
|
-
if (reloadMessageRole !==
|
|
2850
|
+
if (reloadMessageRole !== import_runtime_client_gql7.MessageRole.Assistant) {
|
|
2704
2851
|
console.warn(`Regenerate cannot be performed on ${reloadMessageRole} role`);
|
|
2705
2852
|
return;
|
|
2706
2853
|
}
|
|
@@ -2709,7 +2856,7 @@ function useChat(options) {
|
|
|
2709
2856
|
const lastUserMessageBeforeRegenerate = messages.slice(0, reloadMessageIndex).reverse().find(
|
|
2710
2857
|
(msg) => (
|
|
2711
2858
|
// @ts-expect-error -- message has role
|
|
2712
|
-
msg.role ===
|
|
2859
|
+
msg.role === import_runtime_client_gql7.MessageRole.User
|
|
2713
2860
|
)
|
|
2714
2861
|
);
|
|
2715
2862
|
const indexOfLastUserMessageBeforeRegenerate = messages.findIndex(
|
|
@@ -2798,9 +2945,9 @@ function executeAction(_0) {
|
|
|
2798
2945
|
} catch (e) {
|
|
2799
2946
|
onError(e);
|
|
2800
2947
|
}
|
|
2801
|
-
return new
|
|
2948
|
+
return new import_runtime_client_gql7.ResultMessage({
|
|
2802
2949
|
id: "result-" + message.id,
|
|
2803
|
-
result:
|
|
2950
|
+
result: import_runtime_client_gql7.ResultMessage.encodeResult(
|
|
2804
2951
|
error ? {
|
|
2805
2952
|
content: result,
|
|
2806
2953
|
error: JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error)))
|
|
@@ -2824,12 +2971,52 @@ function getPairedFeAction(actions, message) {
|
|
|
2824
2971
|
}
|
|
2825
2972
|
|
|
2826
2973
|
// src/hooks/use-copilot-chat.ts
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2974
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
2975
|
+
|
|
2976
|
+
// src/hooks/use-langgraph-interrupt-render.ts
|
|
2977
|
+
var import_react12 = __toESM(require("react"));
|
|
2978
|
+
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
2979
|
+
return render({ event, result, resolve });
|
|
2980
|
+
};
|
|
2981
|
+
function useLangGraphInterruptRender() {
|
|
2982
|
+
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
2983
|
+
const responseRef = import_react12.default.useRef();
|
|
2984
|
+
const resolveInterrupt = (0, import_react12.useCallback)(
|
|
2985
|
+
(response) => {
|
|
2986
|
+
responseRef.current = response;
|
|
2987
|
+
setTimeout(() => {
|
|
2988
|
+
setLangGraphInterruptAction({ event: { response } });
|
|
2989
|
+
}, 0);
|
|
2990
|
+
},
|
|
2991
|
+
[setLangGraphInterruptAction]
|
|
2992
|
+
);
|
|
2993
|
+
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
2994
|
+
return null;
|
|
2995
|
+
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
2996
|
+
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
2997
|
+
if (!conditionsMet) {
|
|
2998
|
+
return null;
|
|
2999
|
+
}
|
|
3000
|
+
let result = null;
|
|
3001
|
+
if (handler) {
|
|
3002
|
+
result = handler({
|
|
3003
|
+
event,
|
|
3004
|
+
resolve: resolveInterrupt
|
|
3005
|
+
});
|
|
3006
|
+
}
|
|
3007
|
+
return import_react12.default.createElement(InterruptRenderer, {
|
|
3008
|
+
event,
|
|
3009
|
+
result,
|
|
3010
|
+
render,
|
|
3011
|
+
resolve: resolveInterrupt
|
|
3012
|
+
});
|
|
3013
|
+
}
|
|
3014
|
+
|
|
3015
|
+
// src/hooks/use-copilot-chat.ts
|
|
3016
|
+
var globalSuggestionPromise = null;
|
|
3017
|
+
function useCopilotChat(options = {}) {
|
|
3018
|
+
var _a;
|
|
3019
|
+
const makeSystemMessage2 = (_a = options.makeSystemMessage) != null ? _a : defaultSystemMessage;
|
|
2833
3020
|
const {
|
|
2834
3021
|
getContextString,
|
|
2835
3022
|
getFunctionCallHandler,
|
|
@@ -2853,11 +3040,72 @@ function useCopilotChat(_a = {}) {
|
|
|
2853
3040
|
extensions,
|
|
2854
3041
|
setExtensions,
|
|
2855
3042
|
langGraphInterruptAction,
|
|
2856
|
-
setLangGraphInterruptAction
|
|
3043
|
+
setLangGraphInterruptAction,
|
|
3044
|
+
chatSuggestionConfiguration,
|
|
3045
|
+
suggestions,
|
|
3046
|
+
setSuggestions,
|
|
3047
|
+
runtimeClient
|
|
2857
3048
|
} = useCopilotContext();
|
|
2858
3049
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
2859
|
-
const [mcpServers, setLocalMcpServers] = (0,
|
|
2860
|
-
(0,
|
|
3050
|
+
const [mcpServers, setLocalMcpServers] = (0, import_react13.useState)([]);
|
|
3051
|
+
const suggestionsAbortControllerRef = (0, import_react13.useRef)(null);
|
|
3052
|
+
const isLoadingSuggestionsRef = (0, import_react13.useRef)(false);
|
|
3053
|
+
const abortSuggestions = (0, import_react13.useCallback)(
|
|
3054
|
+
(clear = true) => {
|
|
3055
|
+
var _a2;
|
|
3056
|
+
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort("suggestions aborted by user");
|
|
3057
|
+
suggestionsAbortControllerRef.current = null;
|
|
3058
|
+
if (clear) {
|
|
3059
|
+
setSuggestions([]);
|
|
3060
|
+
}
|
|
3061
|
+
},
|
|
3062
|
+
[setSuggestions]
|
|
3063
|
+
);
|
|
3064
|
+
const stableContext = (0, import_react13.useMemo)(() => {
|
|
3065
|
+
return {
|
|
3066
|
+
actions,
|
|
3067
|
+
copilotApiConfig,
|
|
3068
|
+
chatSuggestionConfiguration,
|
|
3069
|
+
messages,
|
|
3070
|
+
setMessages,
|
|
3071
|
+
getContextString,
|
|
3072
|
+
runtimeClient
|
|
3073
|
+
};
|
|
3074
|
+
}, [
|
|
3075
|
+
JSON.stringify(Object.keys(actions)),
|
|
3076
|
+
copilotApiConfig.chatApiEndpoint,
|
|
3077
|
+
messages.length,
|
|
3078
|
+
Object.keys(chatSuggestionConfiguration).length
|
|
3079
|
+
]);
|
|
3080
|
+
const generateSuggestionsFunc = (0, import_react13.useCallback)(() => __async(this, null, function* () {
|
|
3081
|
+
if (globalSuggestionPromise) {
|
|
3082
|
+
return globalSuggestionPromise;
|
|
3083
|
+
}
|
|
3084
|
+
globalSuggestionPromise = (() => __async(this, null, function* () {
|
|
3085
|
+
try {
|
|
3086
|
+
abortSuggestions();
|
|
3087
|
+
isLoadingSuggestionsRef.current = true;
|
|
3088
|
+
suggestionsAbortControllerRef.current = new AbortController();
|
|
3089
|
+
setSuggestions([]);
|
|
3090
|
+
yield reloadSuggestions(
|
|
3091
|
+
stableContext,
|
|
3092
|
+
chatSuggestionConfiguration,
|
|
3093
|
+
setSuggestions,
|
|
3094
|
+
suggestionsAbortControllerRef
|
|
3095
|
+
);
|
|
3096
|
+
} catch (error) {
|
|
3097
|
+
throw error;
|
|
3098
|
+
} finally {
|
|
3099
|
+
isLoadingSuggestionsRef.current = false;
|
|
3100
|
+
globalSuggestionPromise = null;
|
|
3101
|
+
}
|
|
3102
|
+
}))();
|
|
3103
|
+
return globalSuggestionPromise;
|
|
3104
|
+
}), [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);
|
|
3105
|
+
const resetSuggestions = (0, import_react13.useCallback)(() => {
|
|
3106
|
+
setSuggestions([]);
|
|
3107
|
+
}, [setSuggestions]);
|
|
3108
|
+
(0, import_react13.useEffect)(() => {
|
|
2861
3109
|
if (mcpServers.length > 0) {
|
|
2862
3110
|
const serversCopy = [...mcpServers];
|
|
2863
3111
|
copilotApiConfig.mcpServers = serversCopy;
|
|
@@ -2867,7 +3115,7 @@ function useCopilotChat(_a = {}) {
|
|
|
2867
3115
|
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
2868
3116
|
}
|
|
2869
3117
|
}, [mcpServers, copilotApiConfig]);
|
|
2870
|
-
const setMcpServers = (0,
|
|
3118
|
+
const setMcpServers = (0, import_react13.useCallback)((servers) => {
|
|
2871
3119
|
setLocalMcpServers(servers);
|
|
2872
3120
|
}, []);
|
|
2873
3121
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -2888,15 +3136,15 @@ function useCopilotChat(_a = {}) {
|
|
|
2888
3136
|
}),
|
|
2889
3137
|
[coAgentStateRenders]
|
|
2890
3138
|
);
|
|
2891
|
-
const makeSystemMessageCallback = (0,
|
|
3139
|
+
const makeSystemMessageCallback = (0, import_react13.useCallback)(() => {
|
|
2892
3140
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
2893
3141
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
2894
|
-
return new
|
|
3142
|
+
return new import_runtime_client_gql8.TextMessage({
|
|
2895
3143
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
2896
|
-
role:
|
|
3144
|
+
role: import_runtime_client_gql8.Role.System
|
|
2897
3145
|
});
|
|
2898
3146
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
2899
|
-
const deleteMessage = (0,
|
|
3147
|
+
const deleteMessage = (0, import_react13.useCallback)(
|
|
2900
3148
|
(messageId) => {
|
|
2901
3149
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
2902
3150
|
},
|
|
@@ -2905,7 +3153,7 @@ function useCopilotChat(_a = {}) {
|
|
|
2905
3153
|
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
2906
3154
|
actions: Object.values(actions),
|
|
2907
3155
|
copilotConfig: copilotApiConfig,
|
|
2908
|
-
initialMessages: options.initialMessages || [],
|
|
3156
|
+
initialMessages: (0, import_runtime_client_gql8.aguiToGQL)(options.initialMessages || []),
|
|
2909
3157
|
onFunctionCall: getFunctionCallHandler(),
|
|
2910
3158
|
onCoAgentStateRender,
|
|
2911
3159
|
messages,
|
|
@@ -2932,7 +3180,8 @@ function useCopilotChat(_a = {}) {
|
|
|
2932
3180
|
const latestAppend = useUpdatedRef(append);
|
|
2933
3181
|
const latestAppendFunc = useAsyncCallback(
|
|
2934
3182
|
(message, options2) => __async(this, null, function* () {
|
|
2935
|
-
|
|
3183
|
+
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
3184
|
+
return yield latestAppend.current((0, import_runtime_client_gql8.aguiToGQL)([message])[0], options2);
|
|
2936
3185
|
}),
|
|
2937
3186
|
[latestAppend]
|
|
2938
3187
|
);
|
|
@@ -2944,20 +3193,20 @@ function useCopilotChat(_a = {}) {
|
|
|
2944
3193
|
[latestReload]
|
|
2945
3194
|
);
|
|
2946
3195
|
const latestStop = useUpdatedRef(stop);
|
|
2947
|
-
const latestStopFunc = (0,
|
|
3196
|
+
const latestStopFunc = (0, import_react13.useCallback)(() => {
|
|
2948
3197
|
return latestStop.current();
|
|
2949
3198
|
}, [latestStop]);
|
|
2950
3199
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
2951
|
-
const latestDeleteFunc = (0,
|
|
3200
|
+
const latestDeleteFunc = (0, import_react13.useCallback)(
|
|
2952
3201
|
(messageId) => {
|
|
2953
3202
|
return latestDelete.current(messageId);
|
|
2954
3203
|
},
|
|
2955
3204
|
[latestDelete]
|
|
2956
3205
|
);
|
|
2957
3206
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
2958
|
-
const latestSetMessagesFunc = (0,
|
|
3207
|
+
const latestSetMessagesFunc = (0, import_react13.useCallback)(
|
|
2959
3208
|
(messages2) => {
|
|
2960
|
-
return latestSetMessages.current(messages2);
|
|
3209
|
+
return latestSetMessages.current((0, import_runtime_client_gql8.aguiToGQL)(messages2));
|
|
2961
3210
|
},
|
|
2962
3211
|
[latestSetMessages]
|
|
2963
3212
|
);
|
|
@@ -2965,7 +3214,7 @@ function useCopilotChat(_a = {}) {
|
|
|
2965
3214
|
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
2966
3215
|
return yield latestRunChatCompletion.current();
|
|
2967
3216
|
}), [latestRunChatCompletion]);
|
|
2968
|
-
const reset = (0,
|
|
3217
|
+
const reset = (0, import_react13.useCallback)(() => {
|
|
2969
3218
|
latestStopFunc();
|
|
2970
3219
|
setMessages([]);
|
|
2971
3220
|
setRunId(null);
|
|
@@ -2977,20 +3226,23 @@ function useCopilotChat(_a = {}) {
|
|
|
2977
3226
|
};
|
|
2978
3227
|
}
|
|
2979
3228
|
setAgentSession(initialAgentSession);
|
|
3229
|
+
resetSuggestions();
|
|
2980
3230
|
}, [
|
|
2981
3231
|
latestStopFunc,
|
|
2982
3232
|
setMessages,
|
|
2983
3233
|
setThreadId,
|
|
2984
3234
|
setCoagentStatesWithRef,
|
|
2985
3235
|
setAgentSession,
|
|
2986
|
-
agentLock
|
|
3236
|
+
agentLock,
|
|
3237
|
+
resetSuggestions
|
|
2987
3238
|
]);
|
|
2988
3239
|
const latestReset = useUpdatedRef(reset);
|
|
2989
|
-
const latestResetFunc = (0,
|
|
3240
|
+
const latestResetFunc = (0, import_react13.useCallback)(() => {
|
|
2990
3241
|
return latestReset.current();
|
|
2991
3242
|
}, [latestReset]);
|
|
3243
|
+
const interrupt = useLangGraphInterruptRender();
|
|
2992
3244
|
return {
|
|
2993
|
-
visibleMessages: messages,
|
|
3245
|
+
visibleMessages: (0, import_runtime_client_gql8.gqlToAGUI)(messages, actions, coAgentStateRenders),
|
|
2994
3246
|
appendMessage: latestAppendFunc,
|
|
2995
3247
|
setMessages: latestSetMessagesFunc,
|
|
2996
3248
|
reloadMessages: latestReloadFunc,
|
|
@@ -3000,12 +3252,18 @@ function useCopilotChat(_a = {}) {
|
|
|
3000
3252
|
runChatCompletion: latestRunChatCompletionFunc,
|
|
3001
3253
|
isLoading,
|
|
3002
3254
|
mcpServers,
|
|
3003
|
-
setMcpServers
|
|
3255
|
+
setMcpServers,
|
|
3256
|
+
suggestions,
|
|
3257
|
+
setSuggestions,
|
|
3258
|
+
generateSuggestions: generateSuggestionsFunc,
|
|
3259
|
+
resetSuggestions,
|
|
3260
|
+
isLoadingSuggestions: isLoadingSuggestionsRef.current,
|
|
3261
|
+
interrupt
|
|
3004
3262
|
};
|
|
3005
3263
|
}
|
|
3006
3264
|
function useUpdatedRef(value) {
|
|
3007
|
-
const ref = (0,
|
|
3008
|
-
(0,
|
|
3265
|
+
const ref = (0, import_react13.useRef)(value);
|
|
3266
|
+
(0, import_react13.useEffect)(() => {
|
|
3009
3267
|
ref.current = value;
|
|
3010
3268
|
}, [value]);
|
|
3011
3269
|
return ref;
|
|
@@ -3038,13 +3296,13 @@ ${additionalInstructions}` : "");
|
|
|
3038
3296
|
}
|
|
3039
3297
|
|
|
3040
3298
|
// src/hooks/use-copilot-action.ts
|
|
3041
|
-
var
|
|
3042
|
-
var
|
|
3299
|
+
var import_shared14 = require("@copilotkit/shared");
|
|
3300
|
+
var import_react14 = require("react");
|
|
3043
3301
|
function useCopilotAction(action, dependencies) {
|
|
3044
3302
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
3045
|
-
const idRef = (0,
|
|
3046
|
-
const renderAndWaitRef = (0,
|
|
3047
|
-
const activatingMessageIdRef = (0,
|
|
3303
|
+
const idRef = (0, import_react14.useRef)((0, import_shared14.randomId)());
|
|
3304
|
+
const renderAndWaitRef = (0, import_react14.useRef)(null);
|
|
3305
|
+
const activatingMessageIdRef = (0, import_react14.useRef)(null);
|
|
3048
3306
|
const { addToast } = useToast();
|
|
3049
3307
|
action = __spreadValues({}, action);
|
|
3050
3308
|
if (
|
|
@@ -3106,7 +3364,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
3106
3364
|
return renderAndWait(waitProps);
|
|
3107
3365
|
}
|
|
3108
3366
|
}
|
|
3109
|
-
return (0,
|
|
3367
|
+
return (0, import_react14.createElement)(import_react14.Fragment);
|
|
3110
3368
|
};
|
|
3111
3369
|
}
|
|
3112
3370
|
if (dependencies === void 0) {
|
|
@@ -3121,7 +3379,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
3121
3379
|
}
|
|
3122
3380
|
}
|
|
3123
3381
|
}
|
|
3124
|
-
(0,
|
|
3382
|
+
(0, import_react14.useEffect)(() => {
|
|
3125
3383
|
const hasDuplicate = Object.values(actions).some(
|
|
3126
3384
|
(otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current]
|
|
3127
3385
|
);
|
|
@@ -3133,7 +3391,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
3133
3391
|
});
|
|
3134
3392
|
}
|
|
3135
3393
|
}, [actions]);
|
|
3136
|
-
(0,
|
|
3394
|
+
(0, import_react14.useEffect)(() => {
|
|
3137
3395
|
setAction(idRef.current, action);
|
|
3138
3396
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
3139
3397
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -3162,8 +3420,8 @@ function isFrontendAction(action) {
|
|
|
3162
3420
|
}
|
|
3163
3421
|
|
|
3164
3422
|
// src/hooks/use-coagent-state-render.ts
|
|
3165
|
-
var
|
|
3166
|
-
var
|
|
3423
|
+
var import_react15 = require("react");
|
|
3424
|
+
var import_shared15 = require("@copilotkit/shared");
|
|
3167
3425
|
function useCoAgentStateRender(action, dependencies) {
|
|
3168
3426
|
const {
|
|
3169
3427
|
setCoAgentStateRender,
|
|
@@ -3171,13 +3429,13 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
3171
3429
|
coAgentStateRenders,
|
|
3172
3430
|
chatComponentsCache,
|
|
3173
3431
|
availableAgents
|
|
3174
|
-
} = (0,
|
|
3175
|
-
const idRef = (0,
|
|
3432
|
+
} = (0, import_react15.useContext)(CopilotContext);
|
|
3433
|
+
const idRef = (0, import_react15.useRef)((0, import_shared15.randomId)());
|
|
3176
3434
|
const { setBannerError, addToast } = useToast();
|
|
3177
|
-
(0,
|
|
3435
|
+
(0, import_react15.useEffect)(() => {
|
|
3178
3436
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
3179
3437
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
3180
|
-
const agentError = new
|
|
3438
|
+
const agentError = new import_shared15.CopilotKitAgentDiscoveryError({
|
|
3181
3439
|
agentName: action.name,
|
|
3182
3440
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
3183
3441
|
});
|
|
@@ -3195,7 +3453,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
3195
3453
|
}
|
|
3196
3454
|
}
|
|
3197
3455
|
}
|
|
3198
|
-
(0,
|
|
3456
|
+
(0, import_react15.useEffect)(() => {
|
|
3199
3457
|
const currentId = idRef.current;
|
|
3200
3458
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
3201
3459
|
if (id === currentId)
|
|
@@ -3219,7 +3477,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
3219
3477
|
});
|
|
3220
3478
|
}
|
|
3221
3479
|
}, [coAgentStateRenders]);
|
|
3222
|
-
(0,
|
|
3480
|
+
(0, import_react15.useEffect)(() => {
|
|
3223
3481
|
setCoAgentStateRender(idRef.current, action);
|
|
3224
3482
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
3225
3483
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -3239,11 +3497,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
3239
3497
|
}
|
|
3240
3498
|
|
|
3241
3499
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
3242
|
-
var
|
|
3500
|
+
var import_react16 = require("react");
|
|
3243
3501
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
3244
3502
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
3245
|
-
const idRef = (0,
|
|
3246
|
-
(0,
|
|
3503
|
+
const idRef = (0, import_react16.useRef)();
|
|
3504
|
+
(0, import_react16.useEffect)(() => {
|
|
3247
3505
|
const id = addDocumentContext(document, categories);
|
|
3248
3506
|
idRef.current = id;
|
|
3249
3507
|
return () => {
|
|
@@ -3254,7 +3512,7 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
3254
3512
|
}
|
|
3255
3513
|
|
|
3256
3514
|
// src/hooks/use-copilot-readable.ts
|
|
3257
|
-
var
|
|
3515
|
+
var import_react17 = require("react");
|
|
3258
3516
|
function convertToJSON(description, value) {
|
|
3259
3517
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
3260
3518
|
}
|
|
@@ -3267,10 +3525,10 @@ function useCopilotReadable({
|
|
|
3267
3525
|
available = "enabled"
|
|
3268
3526
|
}, dependencies) {
|
|
3269
3527
|
const { addContext, removeContext } = useCopilotContext();
|
|
3270
|
-
const idRef = (0,
|
|
3528
|
+
const idRef = (0, import_react17.useRef)();
|
|
3271
3529
|
convert = convert || convertToJSON;
|
|
3272
3530
|
const information = convert(description, value);
|
|
3273
|
-
(0,
|
|
3531
|
+
(0, import_react17.useEffect)(() => {
|
|
3274
3532
|
if (available === "disabled")
|
|
3275
3533
|
return;
|
|
3276
3534
|
const id = addContext(information, parentId, categories);
|
|
@@ -3283,20 +3541,20 @@ function useCopilotReadable({
|
|
|
3283
3541
|
}
|
|
3284
3542
|
|
|
3285
3543
|
// src/hooks/use-coagent.ts
|
|
3286
|
-
var
|
|
3287
|
-
var
|
|
3544
|
+
var import_react18 = require("react");
|
|
3545
|
+
var import_shared16 = require("@copilotkit/shared");
|
|
3288
3546
|
function useCoAgent(options) {
|
|
3289
3547
|
const generalContext = useCopilotContext();
|
|
3290
3548
|
const { availableAgents } = generalContext;
|
|
3291
3549
|
const { setBannerError } = useToast();
|
|
3292
|
-
const lastLoadedThreadId = (0,
|
|
3293
|
-
const lastLoadedState = (0,
|
|
3550
|
+
const lastLoadedThreadId = (0, import_react18.useRef)();
|
|
3551
|
+
const lastLoadedState = (0, import_react18.useRef)();
|
|
3294
3552
|
const { name } = options;
|
|
3295
|
-
(0,
|
|
3553
|
+
(0, import_react18.useEffect)(() => {
|
|
3296
3554
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
3297
3555
|
const message = `(useCoAgent): Agent "${name}" not found. Make sure the agent exists and is properly configured.`;
|
|
3298
3556
|
console.warn(message);
|
|
3299
|
-
const agentError = new
|
|
3557
|
+
const agentError = new import_shared16.CopilotKitAgentDiscoveryError({
|
|
3300
3558
|
agentName: name,
|
|
3301
3559
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
3302
3560
|
});
|
|
@@ -3315,7 +3573,7 @@ function useCoAgent(options) {
|
|
|
3315
3573
|
credentials: copilotApiConfig.credentials,
|
|
3316
3574
|
showDevConsole: context.showDevConsole
|
|
3317
3575
|
});
|
|
3318
|
-
const setState = (0,
|
|
3576
|
+
const setState = (0, import_react18.useCallback)(
|
|
3319
3577
|
(newState) => {
|
|
3320
3578
|
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
3321
3579
|
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
@@ -3327,7 +3585,7 @@ function useCoAgent(options) {
|
|
|
3327
3585
|
},
|
|
3328
3586
|
[coagentStates, name]
|
|
3329
3587
|
);
|
|
3330
|
-
(0,
|
|
3588
|
+
(0, import_react18.useEffect)(() => {
|
|
3331
3589
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
3332
3590
|
var _a, _b, _c, _d;
|
|
3333
3591
|
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
@@ -3345,13 +3603,13 @@ function useCoAgent(options) {
|
|
|
3345
3603
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
3346
3604
|
lastLoadedState.current = newState;
|
|
3347
3605
|
lastLoadedThreadId.current = threadId;
|
|
3348
|
-
const fetchedState = (0,
|
|
3606
|
+
const fetchedState = (0, import_shared16.parseJson)(newState, {});
|
|
3349
3607
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
3350
3608
|
}
|
|
3351
3609
|
});
|
|
3352
3610
|
void fetchAgentState();
|
|
3353
3611
|
}, [threadId]);
|
|
3354
|
-
(0,
|
|
3612
|
+
(0, import_react18.useEffect)(() => {
|
|
3355
3613
|
if (isExternalStateManagement(options)) {
|
|
3356
3614
|
setState(options.state);
|
|
3357
3615
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -3362,7 +3620,7 @@ function useCoAgent(options) {
|
|
|
3362
3620
|
// reset initialstate on reset
|
|
3363
3621
|
coagentStates[name] === void 0
|
|
3364
3622
|
]);
|
|
3365
|
-
(0,
|
|
3623
|
+
(0, import_react18.useEffect)(() => {
|
|
3366
3624
|
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
3367
3625
|
if (newConfig === void 0)
|
|
3368
3626
|
return;
|
|
@@ -3394,7 +3652,7 @@ function useCoAgent(options) {
|
|
|
3394
3652
|
}),
|
|
3395
3653
|
[name, context, appendMessage, runChatCompletion]
|
|
3396
3654
|
);
|
|
3397
|
-
return (0,
|
|
3655
|
+
return (0, import_react18.useMemo)(() => {
|
|
3398
3656
|
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
3399
3657
|
return {
|
|
3400
3658
|
name,
|
|
@@ -3491,28 +3749,28 @@ var getCoagentState = ({
|
|
|
3491
3749
|
};
|
|
3492
3750
|
|
|
3493
3751
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
3494
|
-
var
|
|
3495
|
-
var
|
|
3752
|
+
var import_react19 = require("react");
|
|
3753
|
+
var import_react20 = __toESM(require("react"));
|
|
3496
3754
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
3497
3755
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
3498
|
-
const pendingActionRef = (0,
|
|
3499
|
-
const executeAction2 = (0,
|
|
3756
|
+
const pendingActionRef = (0, import_react19.useRef)(null);
|
|
3757
|
+
const executeAction2 = (0, import_react19.useCallback)(
|
|
3500
3758
|
(props) => {
|
|
3501
3759
|
if (typeof action.render === "function") {
|
|
3502
3760
|
return action.render(props);
|
|
3503
3761
|
}
|
|
3504
|
-
return action.render ||
|
|
3762
|
+
return action.render || import_react20.default.createElement(import_react19.Fragment);
|
|
3505
3763
|
},
|
|
3506
3764
|
[action]
|
|
3507
3765
|
);
|
|
3508
|
-
const wrappedRender = (0,
|
|
3766
|
+
const wrappedRender = (0, import_react19.useCallback)(
|
|
3509
3767
|
(props) => {
|
|
3510
3768
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
3511
3769
|
(state) => state.status === "authenticated"
|
|
3512
3770
|
);
|
|
3513
3771
|
if (!isAuthenticated) {
|
|
3514
3772
|
pendingActionRef.current = props;
|
|
3515
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
3773
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react20.default.createElement(authConfig_c.SignInComponent, {
|
|
3516
3774
|
onSignInComplete: (authState) => {
|
|
3517
3775
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
3518
3776
|
if (pendingActionRef.current) {
|
|
@@ -3520,7 +3778,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
3520
3778
|
pendingActionRef.current = null;
|
|
3521
3779
|
}
|
|
3522
3780
|
}
|
|
3523
|
-
}) :
|
|
3781
|
+
}) : import_react20.default.createElement(import_react19.Fragment);
|
|
3524
3782
|
}
|
|
3525
3783
|
return executeAction2(props);
|
|
3526
3784
|
},
|
|
@@ -3535,29 +3793,29 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
3535
3793
|
}
|
|
3536
3794
|
|
|
3537
3795
|
// src/hooks/use-langgraph-interrupt.ts
|
|
3538
|
-
var
|
|
3539
|
-
var
|
|
3796
|
+
var import_react21 = require("react");
|
|
3797
|
+
var import_shared17 = require("@copilotkit/shared");
|
|
3540
3798
|
function useLangGraphInterrupt(action, dependencies) {
|
|
3541
3799
|
var _a;
|
|
3542
|
-
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0,
|
|
3800
|
+
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react21.useContext)(CopilotContext);
|
|
3543
3801
|
const { runChatCompletion } = useCopilotChat();
|
|
3544
3802
|
const { addToast } = useToast();
|
|
3545
|
-
const actionId = (0,
|
|
3546
|
-
const hasAction = (0,
|
|
3803
|
+
const actionId = (0, import_shared17.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
3804
|
+
const hasAction = (0, import_react21.useMemo)(
|
|
3547
3805
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
3548
3806
|
[langGraphInterruptAction]
|
|
3549
3807
|
);
|
|
3550
|
-
const isCurrentAction = (0,
|
|
3808
|
+
const isCurrentAction = (0, import_react21.useMemo)(
|
|
3551
3809
|
() => (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) && (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) === actionId,
|
|
3552
3810
|
[langGraphInterruptAction]
|
|
3553
3811
|
);
|
|
3554
|
-
(0,
|
|
3812
|
+
(0, import_react21.useEffect)(() => {
|
|
3555
3813
|
var _a2;
|
|
3556
3814
|
if (hasAction && isCurrentAction && ((_a2 = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a2.response)) {
|
|
3557
3815
|
runChatCompletion();
|
|
3558
3816
|
}
|
|
3559
3817
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
3560
|
-
(0,
|
|
3818
|
+
(0, import_react21.useEffect)(() => {
|
|
3561
3819
|
if (!action)
|
|
3562
3820
|
return;
|
|
3563
3821
|
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
@@ -3581,45 +3839,6 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
3581
3839
|
]);
|
|
3582
3840
|
}
|
|
3583
3841
|
|
|
3584
|
-
// src/hooks/use-langgraph-interrupt-render.ts
|
|
3585
|
-
var import_react21 = __toESM(require("react"));
|
|
3586
|
-
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
3587
|
-
return render({ event, result, resolve });
|
|
3588
|
-
};
|
|
3589
|
-
function useLangGraphInterruptRender() {
|
|
3590
|
-
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
3591
|
-
const responseRef = import_react21.default.useRef();
|
|
3592
|
-
const resolveInterrupt = (0, import_react21.useCallback)(
|
|
3593
|
-
(response) => {
|
|
3594
|
-
responseRef.current = response;
|
|
3595
|
-
setTimeout(() => {
|
|
3596
|
-
setLangGraphInterruptAction({ event: { response } });
|
|
3597
|
-
}, 0);
|
|
3598
|
-
},
|
|
3599
|
-
[setLangGraphInterruptAction]
|
|
3600
|
-
);
|
|
3601
|
-
if (!langGraphInterruptAction || !langGraphInterruptAction.event || !langGraphInterruptAction.render)
|
|
3602
|
-
return null;
|
|
3603
|
-
const { render, handler, event, enabled } = langGraphInterruptAction;
|
|
3604
|
-
const conditionsMet = !agentSession || !enabled ? true : enabled({ eventValue: event.value, agentMetadata: agentSession });
|
|
3605
|
-
if (!conditionsMet) {
|
|
3606
|
-
return null;
|
|
3607
|
-
}
|
|
3608
|
-
let result = null;
|
|
3609
|
-
if (handler) {
|
|
3610
|
-
result = handler({
|
|
3611
|
-
event,
|
|
3612
|
-
resolve: resolveInterrupt
|
|
3613
|
-
});
|
|
3614
|
-
}
|
|
3615
|
-
return import_react21.default.createElement(InterruptRenderer, {
|
|
3616
|
-
event,
|
|
3617
|
-
result,
|
|
3618
|
-
render,
|
|
3619
|
-
resolve: resolveInterrupt
|
|
3620
|
-
});
|
|
3621
|
-
}
|
|
3622
|
-
|
|
3623
3842
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
3624
3843
|
var import_react22 = require("react");
|
|
3625
3844
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
@@ -3637,7 +3856,7 @@ function useCopilotAdditionalInstructions({ instructions, available = "enabled"
|
|
|
3637
3856
|
}
|
|
3638
3857
|
|
|
3639
3858
|
// src/lib/copilot-task.ts
|
|
3640
|
-
var
|
|
3859
|
+
var import_runtime_client_gql9 = require("@copilotkit/runtime-client-gql");
|
|
3641
3860
|
var CopilotTask = class {
|
|
3642
3861
|
constructor(config) {
|
|
3643
3862
|
this.instructions = config.instructions;
|
|
@@ -3665,12 +3884,12 @@ var CopilotTask = class {
|
|
|
3665
3884
|
if (this.includeCopilotReadable) {
|
|
3666
3885
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
3667
3886
|
}
|
|
3668
|
-
const systemMessage = new
|
|
3887
|
+
const systemMessage = new import_runtime_client_gql9.TextMessage({
|
|
3669
3888
|
content: taskSystemMessage(contextString, this.instructions),
|
|
3670
|
-
role:
|
|
3889
|
+
role: import_runtime_client_gql9.Role.System
|
|
3671
3890
|
});
|
|
3672
3891
|
const messages = [systemMessage];
|
|
3673
|
-
const runtimeClient = new
|
|
3892
|
+
const runtimeClient = new import_runtime_client_gql9.CopilotRuntimeClient({
|
|
3674
3893
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
3675
3894
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
3676
3895
|
headers: context.copilotApiConfig.headers,
|
|
@@ -3682,9 +3901,9 @@ var CopilotTask = class {
|
|
|
3682
3901
|
actions: processActionsForRuntimeRequest(Object.values(actions)),
|
|
3683
3902
|
url: window.location.href
|
|
3684
3903
|
},
|
|
3685
|
-
messages: (0,
|
|
3904
|
+
messages: (0, import_runtime_client_gql9.convertMessagesToGqlInput)((0, import_runtime_client_gql9.filterAgentStateMessages)(messages)),
|
|
3686
3905
|
metadata: {
|
|
3687
|
-
requestType:
|
|
3906
|
+
requestType: import_runtime_client_gql9.CopilotRequestType.Task
|
|
3688
3907
|
},
|
|
3689
3908
|
forwardedParameters: __spreadValues({
|
|
3690
3909
|
// if forwardedParameters is provided, use it
|
|
@@ -3694,7 +3913,7 @@ var CopilotTask = class {
|
|
|
3694
3913
|
properties: context.copilotApiConfig.properties
|
|
3695
3914
|
}).toPromise();
|
|
3696
3915
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
3697
|
-
const functionCalls = (0,
|
|
3916
|
+
const functionCalls = (0, import_runtime_client_gql9.convertGqlOutputToMessages)(
|
|
3698
3917
|
((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
|
|
3699
3918
|
).filter((m) => m.isActionExecutionMessage());
|
|
3700
3919
|
for (const functionCall of functionCalls) {
|
|
@@ -3738,8 +3957,10 @@ ${instructions}
|
|
|
3738
3957
|
CopilotKit,
|
|
3739
3958
|
CopilotMessagesContext,
|
|
3740
3959
|
CopilotTask,
|
|
3960
|
+
SUGGESTION_RETRY_CONFIG,
|
|
3741
3961
|
defaultCopilotContextCategories,
|
|
3742
3962
|
extract,
|
|
3963
|
+
reloadSuggestions,
|
|
3743
3964
|
runAgent,
|
|
3744
3965
|
shouldShowDevConsole,
|
|
3745
3966
|
startAgent,
|