@copilotkit/react-core 1.10.0-next.1 → 1.10.0-next.10
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 +87 -0
- package/dist/{chunk-KV25ZRMH.mjs → chunk-2TSNHEIS.mjs} +6 -6
- package/dist/chunk-2TSNHEIS.mjs.map +1 -0
- package/dist/{chunk-DF4YG4PF.mjs → chunk-3RHHNUVV.mjs} +2 -2
- package/dist/{chunk-LNAQ7JG3.mjs → chunk-6EKLRL7B.mjs} +2 -2
- package/dist/{chunk-JZQOCH4A.mjs → chunk-ADZDXHVC.mjs} +4 -4
- package/dist/{chunk-4CFY3CON.mjs → chunk-CLMDRYEN.mjs} +2 -2
- package/dist/{chunk-VM7CVIET.mjs → chunk-COEUPDRL.mjs} +20 -21
- package/dist/chunk-COEUPDRL.mjs.map +1 -0
- package/dist/{chunk-RGKZCCPA.mjs → chunk-DLEXVOQE.mjs} +5 -5
- package/dist/{chunk-YAF2LATQ.mjs → chunk-EFL5OBKN.mjs} +1 -1
- package/dist/chunk-EFL5OBKN.mjs.map +1 -0
- package/dist/{chunk-JWAXDYOW.mjs → chunk-FAUNHSQU.mjs} +3 -3
- package/dist/chunk-ICIK2BSB.mjs +17 -0
- package/dist/chunk-ICIK2BSB.mjs.map +1 -0
- package/dist/chunk-IHAZJF3V.mjs +34 -0
- package/dist/chunk-IHAZJF3V.mjs.map +1 -0
- package/dist/{chunk-Q6FZZJ5A.mjs → chunk-IN7GE4NO.mjs} +2 -2
- package/dist/{chunk-4XVBXDCX.mjs → chunk-JBLMXZ3O.mjs} +8 -8
- package/dist/{chunk-NXCJELW7.mjs → chunk-JJDXTTEN.mjs} +3 -3
- package/dist/chunk-KDAZGZ24.mjs +1 -0
- package/dist/{chunk-VOMGRGWT.mjs → chunk-L6HQIJ74.mjs} +33 -17
- package/dist/chunk-L6HQIJ74.mjs.map +1 -0
- package/dist/{chunk-OMVNJ7S3.mjs → chunk-LVWV62JZ.mjs} +37 -24
- package/dist/chunk-LVWV62JZ.mjs.map +1 -0
- package/dist/{chunk-3OQM3NEK.mjs → chunk-N4WEHORG.mjs} +2 -2
- package/dist/chunk-OKRZF3DD.mjs +225 -0
- package/dist/chunk-OKRZF3DD.mjs.map +1 -0
- package/dist/{chunk-SGF6C7I6.mjs → chunk-Q42NJFXR.mjs} +11 -16
- package/dist/chunk-Q42NJFXR.mjs.map +1 -0
- package/dist/chunk-QGE7U4NV.mjs +85 -0
- package/dist/chunk-QGE7U4NV.mjs.map +1 -0
- package/dist/{chunk-XGRBCWK6.mjs → chunk-TEMLWRRT.mjs} +3 -3
- package/dist/chunk-TEMLWRRT.mjs.map +1 -0
- package/dist/{chunk-PYULBXCD.mjs → chunk-TWYUYC4F.mjs} +44 -10
- package/dist/chunk-TWYUYC4F.mjs.map +1 -0
- package/dist/{chunk-WUORFPJ7.mjs → chunk-X2DNXTME.mjs} +6 -6
- package/dist/{chunk-DCTJZ742.mjs → chunk-ZLQVRPDS.mjs} +5 -2
- package/dist/chunk-ZLQVRPDS.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.d.ts +17 -1
- package/dist/components/copilot-provider/copilot-messages.js +46 -7
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +11 -7
- package/dist/components/copilot-provider/copilotkit-props.d.ts +5 -3
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.d.ts +1 -2
- package/dist/components/copilot-provider/copilotkit.js +337 -555
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +10 -10
- package/dist/components/copilot-provider/index.d.ts +1 -2
- package/dist/components/copilot-provider/index.js +337 -555
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +10 -10
- package/dist/components/error-boundary/error-boundary.js +176 -323
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +4 -4
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +2 -2
- package/dist/components/index.d.ts +1 -2
- package/dist/components/index.js +337 -555
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +10 -10
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/components/usage-banner.d.ts +10 -4
- package/dist/components/usage-banner.js +176 -302
- package/dist/components/usage-banner.js.map +1 -1
- package/dist/components/usage-banner.mjs +3 -1
- package/dist/context/copilot-context.d.ts +1 -2
- package/dist/context/copilot-context.js +2 -2
- 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 +6 -3
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +5 -5
- package/dist/{copilot-context-bd88d30d.d.ts → copilot-context-256f9020.d.ts} +4 -22
- package/dist/hooks/index.d.ts +7 -5
- package/dist/hooks/index.js +250 -122
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +42 -34
- package/dist/hooks/use-chat.d.ts +1 -2
- package/dist/hooks/use-chat.js +11 -3
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +6 -6
- package/dist/hooks/use-coagent-state-render.js +2 -2
- package/dist/hooks/use-coagent-state-render.js.map +1 -1
- package/dist/hooks/use-coagent-state-render.mjs +3 -3
- package/dist/hooks/use-coagent.d.ts +3 -4
- package/dist/hooks/use-coagent.js +114 -81
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +16 -16
- package/dist/hooks/use-copilot-action.js +2 -2
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +4 -4
- package/dist/hooks/use-copilot-additional-instructions.js +2 -2
- 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 +2 -2
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +5 -5
- package/dist/hooks/use-copilot-chat-headless_c.d.ts +33 -0
- package/dist/hooks/use-copilot-chat-headless_c.js +1837 -0
- package/dist/hooks/use-copilot-chat-headless_c.js.map +1 -0
- package/dist/hooks/use-copilot-chat-headless_c.mjs +31 -0
- package/dist/hooks/use-copilot-chat-headless_c.mjs.map +1 -0
- package/dist/hooks/use-copilot-chat.d.ts +52 -82
- package/dist/hooks/use-copilot-chat.js +60 -13
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +16 -17
- package/dist/hooks/use-copilot-chat_internal.d.ts +177 -0
- package/dist/hooks/use-copilot-chat_internal.js +1770 -0
- package/dist/hooks/use-copilot-chat_internal.js.map +1 -0
- package/dist/hooks/use-copilot-chat_internal.mjs +29 -0
- package/dist/hooks/use-copilot-chat_internal.mjs.map +1 -0
- package/dist/hooks/use-copilot-readable.js +2 -2
- package/dist/hooks/use-copilot-readable.js.map +1 -1
- package/dist/hooks/use-copilot-readable.mjs +2 -2
- package/dist/hooks/use-copilot-runtime-client.js +9 -1
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +3 -3
- package/dist/hooks/use-langgraph-interrupt-render.js +2 -2
- 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 +32 -11
- package/dist/hooks/use-langgraph-interrupt.js.map +1 -1
- package/dist/hooks/use-langgraph-interrupt.mjs +16 -16
- package/dist/hooks/use-make-copilot-document-readable.js +2 -2
- 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 +5 -3
- package/dist/index.js +460 -471
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -39
- package/dist/lib/copilot-task.d.ts +1 -2
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +12 -12
- package/dist/lib/index.d.ts +1 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +12 -12
- package/dist/types/interrupt-action.d.ts +2 -3
- package/dist/utils/dev-console.d.ts +1 -1
- package/dist/utils/dev-console.js +9 -1
- package/dist/utils/dev-console.js.map +1 -1
- package/dist/utils/dev-console.mjs +1 -1
- package/dist/utils/extract.d.ts +2 -2
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +10 -10
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/index.js +9 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +11 -11
- package/dist/utils/suggestions.d.ts +2 -2
- package/dist/utils/suggestions.js.map +1 -1
- package/dist/utils/suggestions.mjs +10 -10
- package/package.json +3 -3
- package/src/components/copilot-provider/copilot-messages.tsx +57 -1
- package/src/components/copilot-provider/copilotkit-props.tsx +4 -1
- package/src/components/copilot-provider/copilotkit.tsx +20 -10
- package/src/components/error-boundary/error-boundary.tsx +5 -15
- package/src/components/toast/toast-provider.tsx +1 -3
- package/src/components/usage-banner.tsx +193 -316
- package/src/context/copilot-context.tsx +12 -6
- package/src/context/copilot-messages-context.tsx +7 -1
- package/src/hooks/__tests__/use-coagent-config.test.ts +8 -1
- package/src/hooks/index.ts +7 -2
- package/src/hooks/use-coagent.ts +17 -19
- package/src/hooks/use-copilot-chat-headless_c.ts +187 -0
- package/src/hooks/use-copilot-chat.ts +64 -495
- package/src/hooks/use-copilot-chat_internal.ts +543 -0
- package/src/hooks/use-langgraph-interrupt.ts +1 -1
- package/src/utils/dev-console.ts +18 -2
- package/dist/chunk-57K2ZJ5F.mjs +0 -348
- package/dist/chunk-57K2ZJ5F.mjs.map +0 -1
- package/dist/chunk-CQPYJIBH.mjs +0 -1
- package/dist/chunk-DCTJZ742.mjs.map +0 -1
- package/dist/chunk-GFJW4RIM.mjs +0 -9
- package/dist/chunk-GFJW4RIM.mjs.map +0 -1
- package/dist/chunk-KV25ZRMH.mjs.map +0 -1
- package/dist/chunk-OMVNJ7S3.mjs.map +0 -1
- package/dist/chunk-PYULBXCD.mjs.map +0 -1
- package/dist/chunk-SGF6C7I6.mjs.map +0 -1
- package/dist/chunk-VM7CVIET.mjs.map +0 -1
- package/dist/chunk-VOMGRGWT.mjs.map +0 -1
- package/dist/chunk-XGRBCWK6.mjs.map +0 -1
- package/dist/chunk-YAF2LATQ.mjs.map +0 -1
- /package/dist/{chunk-DF4YG4PF.mjs.map → chunk-3RHHNUVV.mjs.map} +0 -0
- /package/dist/{chunk-LNAQ7JG3.mjs.map → chunk-6EKLRL7B.mjs.map} +0 -0
- /package/dist/{chunk-JZQOCH4A.mjs.map → chunk-ADZDXHVC.mjs.map} +0 -0
- /package/dist/{chunk-4CFY3CON.mjs.map → chunk-CLMDRYEN.mjs.map} +0 -0
- /package/dist/{chunk-RGKZCCPA.mjs.map → chunk-DLEXVOQE.mjs.map} +0 -0
- /package/dist/{chunk-JWAXDYOW.mjs.map → chunk-FAUNHSQU.mjs.map} +0 -0
- /package/dist/{chunk-Q6FZZJ5A.mjs.map → chunk-IN7GE4NO.mjs.map} +0 -0
- /package/dist/{chunk-4XVBXDCX.mjs.map → chunk-JBLMXZ3O.mjs.map} +0 -0
- /package/dist/{chunk-NXCJELW7.mjs.map → chunk-JJDXTTEN.mjs.map} +0 -0
- /package/dist/{chunk-CQPYJIBH.mjs.map → chunk-KDAZGZ24.mjs.map} +0 -0
- /package/dist/{chunk-3OQM3NEK.mjs.map → chunk-N4WEHORG.mjs.map} +0 -0
- /package/dist/{chunk-WUORFPJ7.mjs.map → chunk-X2DNXTME.mjs.map} +0 -0
package/dist/hooks/index.js
CHANGED
|
@@ -87,7 +87,9 @@ __export(hooks_exports, {
|
|
|
87
87
|
useCopilotAction: () => useCopilotAction,
|
|
88
88
|
useCopilotAdditionalInstructions: () => useCopilotAdditionalInstructions,
|
|
89
89
|
useCopilotAuthenticatedAction_c: () => useCopilotAuthenticatedAction_c,
|
|
90
|
-
useCopilotChat: () =>
|
|
90
|
+
useCopilotChat: () => useCopilotChat2,
|
|
91
|
+
useCopilotChatHeadless_c: () => useCopilotChatHeadless_c,
|
|
92
|
+
useCopilotChatInternal: () => useCopilotChat,
|
|
91
93
|
useCopilotReadable: () => useCopilotReadable,
|
|
92
94
|
useCopilotRuntimeClient: () => useCopilotRuntimeClient,
|
|
93
95
|
useLangGraphInterrupt: () => useLangGraphInterrupt,
|
|
@@ -96,8 +98,8 @@ __export(hooks_exports, {
|
|
|
96
98
|
});
|
|
97
99
|
module.exports = __toCommonJS(hooks_exports);
|
|
98
100
|
|
|
99
|
-
// src/hooks/use-copilot-
|
|
100
|
-
var
|
|
101
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
102
|
+
var import_react10 = require("react");
|
|
101
103
|
|
|
102
104
|
// src/context/copilot-context.tsx
|
|
103
105
|
var import_react = __toESM(require("react"));
|
|
@@ -174,8 +176,8 @@ var emptyCopilotContext = {
|
|
|
174
176
|
setLangGraphInterruptAction: () => null,
|
|
175
177
|
removeLangGraphInterruptAction: () => null,
|
|
176
178
|
onError: void 0,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
+
bannerError: null,
|
|
180
|
+
setBannerError: () => {
|
|
179
181
|
}
|
|
180
182
|
};
|
|
181
183
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
@@ -194,7 +196,10 @@ function returnAndThrowInDebug(_value) {
|
|
|
194
196
|
var import_react2 = __toESM(require("react"));
|
|
195
197
|
var emptyCopilotContext2 = {
|
|
196
198
|
messages: [],
|
|
197
|
-
setMessages: () => []
|
|
199
|
+
setMessages: () => [],
|
|
200
|
+
// suggestions state
|
|
201
|
+
suggestions: [],
|
|
202
|
+
setSuggestions: () => []
|
|
198
203
|
};
|
|
199
204
|
var CopilotMessagesContext = import_react2.default.createContext(emptyCopilotContext2);
|
|
200
205
|
function useCopilotMessagesContext() {
|
|
@@ -259,8 +264,16 @@ var import_react4 = require("react");
|
|
|
259
264
|
var import_shared3 = require("@copilotkit/shared");
|
|
260
265
|
|
|
261
266
|
// src/utils/dev-console.ts
|
|
267
|
+
function isLocalhost() {
|
|
268
|
+
if (typeof window === "undefined")
|
|
269
|
+
return false;
|
|
270
|
+
return window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname === "0.0.0.0";
|
|
271
|
+
}
|
|
262
272
|
function shouldShowDevConsole(showDevConsole) {
|
|
263
|
-
|
|
273
|
+
if (showDevConsole !== void 0) {
|
|
274
|
+
return showDevConsole;
|
|
275
|
+
}
|
|
276
|
+
return isLocalhost();
|
|
264
277
|
}
|
|
265
278
|
|
|
266
279
|
// src/hooks/use-copilot-runtime-client.ts
|
|
@@ -1156,14 +1169,27 @@ function getPairedFeAction(actions, message) {
|
|
|
1156
1169
|
}
|
|
1157
1170
|
|
|
1158
1171
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1159
|
-
var
|
|
1172
|
+
var import_react8 = require("react");
|
|
1160
1173
|
var import_react_dom2 = require("react-dom");
|
|
1161
|
-
var
|
|
1174
|
+
var import_shared8 = require("@copilotkit/shared");
|
|
1162
1175
|
|
|
1163
|
-
// src/
|
|
1164
|
-
var
|
|
1176
|
+
// src/components/copilot-provider/copilot-messages.tsx
|
|
1177
|
+
var import_react7 = require("react");
|
|
1165
1178
|
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
1179
|
+
var import_shared5 = require("@copilotkit/shared");
|
|
1180
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
1181
|
+
var MessagesTapContext = (0, import_react7.createContext)(null);
|
|
1182
|
+
function useMessagesTap() {
|
|
1183
|
+
const tap = (0, import_react7.useContext)(MessagesTapContext);
|
|
1184
|
+
if (!tap)
|
|
1185
|
+
throw new Error("useMessagesTap must be used inside <MessagesTapProvider>");
|
|
1186
|
+
return tap;
|
|
1187
|
+
}
|
|
1188
|
+
|
|
1189
|
+
// src/utils/extract.ts
|
|
1190
|
+
var import_shared6 = require("@copilotkit/shared");
|
|
1166
1191
|
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1192
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1167
1193
|
function extract(_0) {
|
|
1168
1194
|
return __async(this, arguments, function* ({
|
|
1169
1195
|
context,
|
|
@@ -1173,7 +1199,7 @@ function extract(_0) {
|
|
|
1173
1199
|
data,
|
|
1174
1200
|
abortSignal,
|
|
1175
1201
|
stream,
|
|
1176
|
-
requestType =
|
|
1202
|
+
requestType = import_runtime_client_gql5.CopilotRequestType.Task,
|
|
1177
1203
|
forwardedParameters
|
|
1178
1204
|
}) {
|
|
1179
1205
|
var _a, _b;
|
|
@@ -1194,13 +1220,13 @@ function extract(_0) {
|
|
|
1194
1220
|
if (includeReadable) {
|
|
1195
1221
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
1196
1222
|
}
|
|
1197
|
-
const systemMessage = new
|
|
1223
|
+
const systemMessage = new import_runtime_client_gql5.TextMessage({
|
|
1198
1224
|
content: makeSystemMessage(contextString, instructions),
|
|
1199
|
-
role:
|
|
1225
|
+
role: import_runtime_client_gql5.Role.System
|
|
1200
1226
|
});
|
|
1201
|
-
const instructionsMessage = new
|
|
1227
|
+
const instructionsMessage = new import_runtime_client_gql5.TextMessage({
|
|
1202
1228
|
content: makeInstructionsMessage(instructions),
|
|
1203
|
-
role:
|
|
1229
|
+
role: import_runtime_client_gql5.Role.User
|
|
1204
1230
|
});
|
|
1205
1231
|
const response = context.runtimeClient.asStream(
|
|
1206
1232
|
context.runtimeClient.generateCopilotResponse({
|
|
@@ -1210,13 +1236,13 @@ function extract(_0) {
|
|
|
1210
1236
|
{
|
|
1211
1237
|
name: action.name,
|
|
1212
1238
|
description: action.description || "",
|
|
1213
|
-
jsonSchema: JSON.stringify((0,
|
|
1239
|
+
jsonSchema: JSON.stringify((0, import_shared6.actionParametersToJsonSchema)(action.parameters || []))
|
|
1214
1240
|
}
|
|
1215
1241
|
],
|
|
1216
1242
|
url: window.location.href
|
|
1217
1243
|
},
|
|
1218
|
-
messages: (0,
|
|
1219
|
-
includeMessages ? [systemMessage, instructionsMessage, ...(0,
|
|
1244
|
+
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)(
|
|
1245
|
+
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql6.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
1220
1246
|
),
|
|
1221
1247
|
metadata: {
|
|
1222
1248
|
requestType
|
|
@@ -1241,7 +1267,7 @@ function extract(_0) {
|
|
|
1241
1267
|
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
1242
1268
|
throw new Error("Aborted");
|
|
1243
1269
|
}
|
|
1244
|
-
actionExecutionMessage = (0,
|
|
1270
|
+
actionExecutionMessage = (0, import_runtime_client_gql5.convertGqlOutputToMessages)(
|
|
1245
1271
|
value.generateCopilotResponse.messages
|
|
1246
1272
|
).find((msg) => msg.isActionExecutionMessage());
|
|
1247
1273
|
if (!actionExecutionMessage) {
|
|
@@ -1295,8 +1321,8 @@ This is not a conversation, so please do not ask questions. Just call the functi
|
|
|
1295
1321
|
}
|
|
1296
1322
|
|
|
1297
1323
|
// src/utils/suggestions.ts
|
|
1298
|
-
var
|
|
1299
|
-
var
|
|
1324
|
+
var import_shared7 = require("@copilotkit/shared");
|
|
1325
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1300
1326
|
var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggestions, abortControllerRef) => __async(void 0, null, function* () {
|
|
1301
1327
|
const abortController = abortControllerRef.current;
|
|
1302
1328
|
if (abortController == null ? void 0 : abortController.signal.aborted) {
|
|
@@ -1312,7 +1338,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1312
1338
|
Object.values(context.actions).map((action) => ({
|
|
1313
1339
|
name: action.name,
|
|
1314
1340
|
description: action.description,
|
|
1315
|
-
jsonSchema: JSON.stringify((0,
|
|
1341
|
+
jsonSchema: JSON.stringify((0, import_shared7.actionParametersToJsonSchema)(action.parameters))
|
|
1316
1342
|
}))
|
|
1317
1343
|
);
|
|
1318
1344
|
const allSuggestions = [];
|
|
@@ -1340,7 +1366,7 @@ var reloadSuggestions = (context, chatSuggestionConfiguration, setCurrentSuggest
|
|
|
1340
1366
|
Available tools: ${tools}
|
|
1341
1367
|
|
|
1342
1368
|
`,
|
|
1343
|
-
requestType:
|
|
1369
|
+
requestType: import_runtime_client_gql7.CopilotRequestType.Task,
|
|
1344
1370
|
parameters: [
|
|
1345
1371
|
{
|
|
1346
1372
|
name: "suggestions",
|
|
@@ -1428,21 +1454,21 @@ Available tools: ${tools}
|
|
|
1428
1454
|
});
|
|
1429
1455
|
|
|
1430
1456
|
// src/components/copilot-provider/copilotkit.tsx
|
|
1431
|
-
var
|
|
1457
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
1432
1458
|
var defaultCopilotContextCategories = ["global"];
|
|
1433
1459
|
|
|
1434
|
-
// src/hooks/use-copilot-
|
|
1435
|
-
var
|
|
1460
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
1461
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
1436
1462
|
|
|
1437
1463
|
// src/hooks/use-langgraph-interrupt-render.ts
|
|
1438
|
-
var
|
|
1464
|
+
var import_react9 = __toESM(require("react"));
|
|
1439
1465
|
var InterruptRenderer = ({ event, result, render, resolve }) => {
|
|
1440
1466
|
return render({ event, result, resolve });
|
|
1441
1467
|
};
|
|
1442
1468
|
function useLangGraphInterruptRender() {
|
|
1443
1469
|
const { langGraphInterruptAction, setLangGraphInterruptAction, agentSession } = useCopilotContext();
|
|
1444
|
-
const responseRef =
|
|
1445
|
-
const resolveInterrupt = (0,
|
|
1470
|
+
const responseRef = import_react9.default.useRef();
|
|
1471
|
+
const resolveInterrupt = (0, import_react9.useCallback)(
|
|
1446
1472
|
(response) => {
|
|
1447
1473
|
responseRef.current = response;
|
|
1448
1474
|
setTimeout(() => {
|
|
@@ -1465,7 +1491,7 @@ function useLangGraphInterruptRender() {
|
|
|
1465
1491
|
resolve: resolveInterrupt
|
|
1466
1492
|
});
|
|
1467
1493
|
}
|
|
1468
|
-
return
|
|
1494
|
+
return import_react9.default.createElement(InterruptRenderer, {
|
|
1469
1495
|
event,
|
|
1470
1496
|
result,
|
|
1471
1497
|
render,
|
|
@@ -1473,7 +1499,7 @@ function useLangGraphInterruptRender() {
|
|
|
1473
1499
|
});
|
|
1474
1500
|
}
|
|
1475
1501
|
|
|
1476
|
-
// src/hooks/use-copilot-
|
|
1502
|
+
// src/hooks/use-copilot-chat_internal.ts
|
|
1477
1503
|
var globalSuggestionPromise = null;
|
|
1478
1504
|
function useCopilotChat(options = {}) {
|
|
1479
1505
|
var _a;
|
|
@@ -1503,15 +1529,13 @@ function useCopilotChat(options = {}) {
|
|
|
1503
1529
|
langGraphInterruptAction,
|
|
1504
1530
|
setLangGraphInterruptAction,
|
|
1505
1531
|
chatSuggestionConfiguration,
|
|
1506
|
-
suggestions,
|
|
1507
|
-
setSuggestions,
|
|
1508
1532
|
runtimeClient
|
|
1509
1533
|
} = useCopilotContext();
|
|
1510
|
-
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1511
|
-
const [mcpServers, setLocalMcpServers] = (0,
|
|
1512
|
-
const suggestionsAbortControllerRef = (0,
|
|
1513
|
-
const isLoadingSuggestionsRef = (0,
|
|
1514
|
-
const abortSuggestions = (0,
|
|
1534
|
+
const { messages, setMessages, suggestions, setSuggestions } = useCopilotMessagesContext();
|
|
1535
|
+
const [mcpServers, setLocalMcpServers] = (0, import_react10.useState)([]);
|
|
1536
|
+
const suggestionsAbortControllerRef = (0, import_react10.useRef)(null);
|
|
1537
|
+
const isLoadingSuggestionsRef = (0, import_react10.useRef)(false);
|
|
1538
|
+
const abortSuggestions = (0, import_react10.useCallback)(
|
|
1515
1539
|
(clear = true) => {
|
|
1516
1540
|
var _a2;
|
|
1517
1541
|
(_a2 = suggestionsAbortControllerRef.current) == null ? void 0 : _a2.abort("suggestions aborted by user");
|
|
@@ -1522,7 +1546,7 @@ function useCopilotChat(options = {}) {
|
|
|
1522
1546
|
},
|
|
1523
1547
|
[setSuggestions]
|
|
1524
1548
|
);
|
|
1525
|
-
const stableContext = (0,
|
|
1549
|
+
const stableContext = (0, import_react10.useMemo)(() => {
|
|
1526
1550
|
return {
|
|
1527
1551
|
actions,
|
|
1528
1552
|
copilotApiConfig,
|
|
@@ -1538,7 +1562,7 @@ function useCopilotChat(options = {}) {
|
|
|
1538
1562
|
messages.length,
|
|
1539
1563
|
Object.keys(chatSuggestionConfiguration).length
|
|
1540
1564
|
]);
|
|
1541
|
-
const generateSuggestionsFunc = (0,
|
|
1565
|
+
const generateSuggestionsFunc = (0, import_react10.useCallback)(() => __async(this, null, function* () {
|
|
1542
1566
|
if (globalSuggestionPromise) {
|
|
1543
1567
|
return globalSuggestionPromise;
|
|
1544
1568
|
}
|
|
@@ -1563,10 +1587,10 @@ function useCopilotChat(options = {}) {
|
|
|
1563
1587
|
}))();
|
|
1564
1588
|
return globalSuggestionPromise;
|
|
1565
1589
|
}), [stableContext, chatSuggestionConfiguration, setSuggestions, abortSuggestions]);
|
|
1566
|
-
const resetSuggestions = (0,
|
|
1590
|
+
const resetSuggestions = (0, import_react10.useCallback)(() => {
|
|
1567
1591
|
setSuggestions([]);
|
|
1568
1592
|
}, [setSuggestions]);
|
|
1569
|
-
(0,
|
|
1593
|
+
(0, import_react10.useEffect)(() => {
|
|
1570
1594
|
if (mcpServers.length > 0) {
|
|
1571
1595
|
const serversCopy = [...mcpServers];
|
|
1572
1596
|
copilotApiConfig.mcpServers = serversCopy;
|
|
@@ -1576,7 +1600,7 @@ function useCopilotChat(options = {}) {
|
|
|
1576
1600
|
copilotApiConfig.properties.mcpServers = serversCopy;
|
|
1577
1601
|
}
|
|
1578
1602
|
}, [mcpServers, copilotApiConfig]);
|
|
1579
|
-
const setMcpServers = (0,
|
|
1603
|
+
const setMcpServers = (0, import_react10.useCallback)((servers) => {
|
|
1580
1604
|
setLocalMcpServers(servers);
|
|
1581
1605
|
}, []);
|
|
1582
1606
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1597,15 +1621,15 @@ function useCopilotChat(options = {}) {
|
|
|
1597
1621
|
}),
|
|
1598
1622
|
[coAgentStateRenders]
|
|
1599
1623
|
);
|
|
1600
|
-
const makeSystemMessageCallback = (0,
|
|
1624
|
+
const makeSystemMessageCallback = (0, import_react10.useCallback)(() => {
|
|
1601
1625
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1602
1626
|
const contextString = getContextString([], defaultCopilotContextCategories);
|
|
1603
|
-
return new
|
|
1627
|
+
return new import_runtime_client_gql8.TextMessage({
|
|
1604
1628
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1605
|
-
role:
|
|
1629
|
+
role: import_runtime_client_gql8.Role.System
|
|
1606
1630
|
});
|
|
1607
1631
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1608
|
-
const deleteMessage = (0,
|
|
1632
|
+
const deleteMessage = (0, import_react10.useCallback)(
|
|
1609
1633
|
(messageId) => {
|
|
1610
1634
|
setMessages((prev) => prev.filter((message) => message.id !== messageId));
|
|
1611
1635
|
},
|
|
@@ -1614,7 +1638,7 @@ function useCopilotChat(options = {}) {
|
|
|
1614
1638
|
const { append, reload, stop, runChatCompletion } = useChat(__spreadProps(__spreadValues({}, options), {
|
|
1615
1639
|
actions: Object.values(actions),
|
|
1616
1640
|
copilotConfig: copilotApiConfig,
|
|
1617
|
-
initialMessages: (0,
|
|
1641
|
+
initialMessages: (0, import_runtime_client_gql8.aguiToGQL)(options.initialMessages || []),
|
|
1618
1642
|
onFunctionCall: getFunctionCallHandler(),
|
|
1619
1643
|
onCoAgentStateRender,
|
|
1620
1644
|
messages,
|
|
@@ -1642,7 +1666,14 @@ function useCopilotChat(options = {}) {
|
|
|
1642
1666
|
const latestAppendFunc = useAsyncCallback(
|
|
1643
1667
|
(message, options2) => __async(this, null, function* () {
|
|
1644
1668
|
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1645
|
-
return yield latestAppend.current(
|
|
1669
|
+
return yield latestAppend.current(message, options2);
|
|
1670
|
+
}),
|
|
1671
|
+
[latestAppend]
|
|
1672
|
+
);
|
|
1673
|
+
const latestSendMessageFunc = useAsyncCallback(
|
|
1674
|
+
(message, options2) => __async(this, null, function* () {
|
|
1675
|
+
abortSuggestions(options2 == null ? void 0 : options2.clearSuggestions);
|
|
1676
|
+
return yield latestAppend.current((0, import_runtime_client_gql8.aguiToGQL)([message])[0], options2);
|
|
1646
1677
|
}),
|
|
1647
1678
|
[latestAppend]
|
|
1648
1679
|
);
|
|
@@ -1654,20 +1685,23 @@ function useCopilotChat(options = {}) {
|
|
|
1654
1685
|
[latestReload]
|
|
1655
1686
|
);
|
|
1656
1687
|
const latestStop = useUpdatedRef(stop);
|
|
1657
|
-
const latestStopFunc = (0,
|
|
1688
|
+
const latestStopFunc = (0, import_react10.useCallback)(() => {
|
|
1658
1689
|
return latestStop.current();
|
|
1659
1690
|
}, [latestStop]);
|
|
1660
1691
|
const latestDelete = useUpdatedRef(deleteMessage);
|
|
1661
|
-
const latestDeleteFunc = (0,
|
|
1692
|
+
const latestDeleteFunc = (0, import_react10.useCallback)(
|
|
1662
1693
|
(messageId) => {
|
|
1663
1694
|
return latestDelete.current(messageId);
|
|
1664
1695
|
},
|
|
1665
1696
|
[latestDelete]
|
|
1666
1697
|
);
|
|
1667
1698
|
const latestSetMessages = useUpdatedRef(setMessages);
|
|
1668
|
-
const latestSetMessagesFunc = (0,
|
|
1699
|
+
const latestSetMessagesFunc = (0, import_react10.useCallback)(
|
|
1669
1700
|
(messages2) => {
|
|
1670
|
-
|
|
1701
|
+
if (messages2.every((message) => message instanceof import_runtime_client_gql8.Message)) {
|
|
1702
|
+
return latestSetMessages.current(messages2);
|
|
1703
|
+
}
|
|
1704
|
+
return latestSetMessages.current((0, import_runtime_client_gql8.aguiToGQL)(messages2));
|
|
1671
1705
|
},
|
|
1672
1706
|
[latestSetMessages]
|
|
1673
1707
|
);
|
|
@@ -1675,7 +1709,7 @@ function useCopilotChat(options = {}) {
|
|
|
1675
1709
|
const latestRunChatCompletionFunc = useAsyncCallback(() => __async(this, null, function* () {
|
|
1676
1710
|
return yield latestRunChatCompletion.current();
|
|
1677
1711
|
}), [latestRunChatCompletion]);
|
|
1678
|
-
const reset = (0,
|
|
1712
|
+
const reset = (0, import_react10.useCallback)(() => {
|
|
1679
1713
|
latestStopFunc();
|
|
1680
1714
|
setMessages([]);
|
|
1681
1715
|
setRunId(null);
|
|
@@ -1698,12 +1732,14 @@ function useCopilotChat(options = {}) {
|
|
|
1698
1732
|
resetSuggestions
|
|
1699
1733
|
]);
|
|
1700
1734
|
const latestReset = useUpdatedRef(reset);
|
|
1701
|
-
const latestResetFunc = (0,
|
|
1735
|
+
const latestResetFunc = (0, import_react10.useCallback)(() => {
|
|
1702
1736
|
return latestReset.current();
|
|
1703
1737
|
}, [latestReset]);
|
|
1704
1738
|
const interrupt = useLangGraphInterruptRender();
|
|
1705
1739
|
return {
|
|
1706
|
-
visibleMessages:
|
|
1740
|
+
visibleMessages: messages,
|
|
1741
|
+
messages: (0, import_runtime_client_gql8.gqlToAGUI)(messages, actions, coAgentStateRenders),
|
|
1742
|
+
sendMessage: latestSendMessageFunc,
|
|
1707
1743
|
appendMessage: latestAppendFunc,
|
|
1708
1744
|
setMessages: latestSetMessagesFunc,
|
|
1709
1745
|
reloadMessages: latestReloadFunc,
|
|
@@ -1723,8 +1759,8 @@ function useCopilotChat(options = {}) {
|
|
|
1723
1759
|
};
|
|
1724
1760
|
}
|
|
1725
1761
|
function useUpdatedRef(value) {
|
|
1726
|
-
const ref = (0,
|
|
1727
|
-
(0,
|
|
1762
|
+
const ref = (0, import_react10.useRef)(value);
|
|
1763
|
+
(0, import_react10.useEffect)(() => {
|
|
1728
1764
|
ref.current = value;
|
|
1729
1765
|
}, [value]);
|
|
1730
1766
|
return ref;
|
|
@@ -1756,14 +1792,105 @@ In case of a function error:
|
|
|
1756
1792
|
${additionalInstructions}` : "");
|
|
1757
1793
|
}
|
|
1758
1794
|
|
|
1795
|
+
// src/hooks/use-copilot-chat.ts
|
|
1796
|
+
function useCopilotChat2(options = {}) {
|
|
1797
|
+
const {
|
|
1798
|
+
visibleMessages,
|
|
1799
|
+
appendMessage,
|
|
1800
|
+
reloadMessages,
|
|
1801
|
+
stopGeneration,
|
|
1802
|
+
reset,
|
|
1803
|
+
isLoading,
|
|
1804
|
+
runChatCompletion,
|
|
1805
|
+
mcpServers,
|
|
1806
|
+
setMcpServers
|
|
1807
|
+
} = useCopilotChat(options);
|
|
1808
|
+
return {
|
|
1809
|
+
visibleMessages,
|
|
1810
|
+
appendMessage,
|
|
1811
|
+
reloadMessages,
|
|
1812
|
+
stopGeneration,
|
|
1813
|
+
reset,
|
|
1814
|
+
isLoading,
|
|
1815
|
+
runChatCompletion,
|
|
1816
|
+
mcpServers,
|
|
1817
|
+
setMcpServers
|
|
1818
|
+
};
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
// src/hooks/use-copilot-chat-headless_c.ts
|
|
1822
|
+
var import_react11 = require("react");
|
|
1823
|
+
var import_shared9 = require("@copilotkit/shared");
|
|
1824
|
+
var createNonFunctionalReturn = () => ({
|
|
1825
|
+
visibleMessages: [],
|
|
1826
|
+
messages: [],
|
|
1827
|
+
sendMessage: () => __async(void 0, null, function* () {
|
|
1828
|
+
}),
|
|
1829
|
+
appendMessage: () => __async(void 0, null, function* () {
|
|
1830
|
+
}),
|
|
1831
|
+
setMessages: () => {
|
|
1832
|
+
},
|
|
1833
|
+
deleteMessage: () => {
|
|
1834
|
+
},
|
|
1835
|
+
reloadMessages: () => __async(void 0, null, function* () {
|
|
1836
|
+
}),
|
|
1837
|
+
stopGeneration: () => {
|
|
1838
|
+
},
|
|
1839
|
+
reset: () => {
|
|
1840
|
+
},
|
|
1841
|
+
isLoading: false,
|
|
1842
|
+
runChatCompletion: () => __async(void 0, null, function* () {
|
|
1843
|
+
return [];
|
|
1844
|
+
}),
|
|
1845
|
+
mcpServers: [],
|
|
1846
|
+
setMcpServers: () => {
|
|
1847
|
+
},
|
|
1848
|
+
suggestions: [],
|
|
1849
|
+
setSuggestions: () => {
|
|
1850
|
+
},
|
|
1851
|
+
generateSuggestions: () => __async(void 0, null, function* () {
|
|
1852
|
+
}),
|
|
1853
|
+
resetSuggestions: () => {
|
|
1854
|
+
},
|
|
1855
|
+
isLoadingSuggestions: false,
|
|
1856
|
+
interrupt: null
|
|
1857
|
+
});
|
|
1858
|
+
function useCopilotChatHeadless_c(options = {}) {
|
|
1859
|
+
const { copilotApiConfig, setBannerError } = useCopilotContext();
|
|
1860
|
+
const hasPublicApiKey = Boolean(copilotApiConfig.publicApiKey);
|
|
1861
|
+
const internalResult = useCopilotChat(options);
|
|
1862
|
+
(0, import_react11.useEffect)(() => {
|
|
1863
|
+
if (!hasPublicApiKey) {
|
|
1864
|
+
setBannerError(
|
|
1865
|
+
new import_shared9.CopilotKitError({
|
|
1866
|
+
message: (
|
|
1867
|
+
// add link to documentation here
|
|
1868
|
+
"You're using useCopilotChatHeadless_c, a subscription-only feature, which offers extensive headless chat capabilities. To continue, you'll need to provide a free subscription key."
|
|
1869
|
+
),
|
|
1870
|
+
code: import_shared9.CopilotKitErrorCode.MISSING_PUBLIC_API_KEY_ERROR,
|
|
1871
|
+
severity: import_shared9.Severity.WARNING,
|
|
1872
|
+
visibility: import_shared9.ErrorVisibility.BANNER
|
|
1873
|
+
})
|
|
1874
|
+
);
|
|
1875
|
+
import_shared9.styledConsole.logCopilotKitPlatformMessage();
|
|
1876
|
+
} else {
|
|
1877
|
+
setBannerError(null);
|
|
1878
|
+
}
|
|
1879
|
+
}, [hasPublicApiKey]);
|
|
1880
|
+
if (hasPublicApiKey) {
|
|
1881
|
+
return internalResult;
|
|
1882
|
+
}
|
|
1883
|
+
return createNonFunctionalReturn();
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1759
1886
|
// src/hooks/use-copilot-action.ts
|
|
1760
|
-
var
|
|
1761
|
-
var
|
|
1887
|
+
var import_shared10 = require("@copilotkit/shared");
|
|
1888
|
+
var import_react12 = require("react");
|
|
1762
1889
|
function useCopilotAction(action, dependencies) {
|
|
1763
1890
|
const { setAction, removeAction, actions, chatComponentsCache } = useCopilotContext();
|
|
1764
|
-
const idRef = (0,
|
|
1765
|
-
const renderAndWaitRef = (0,
|
|
1766
|
-
const activatingMessageIdRef = (0,
|
|
1891
|
+
const idRef = (0, import_react12.useRef)((0, import_shared10.randomId)());
|
|
1892
|
+
const renderAndWaitRef = (0, import_react12.useRef)(null);
|
|
1893
|
+
const activatingMessageIdRef = (0, import_react12.useRef)(null);
|
|
1767
1894
|
const { addToast } = useToast();
|
|
1768
1895
|
action = __spreadValues({}, action);
|
|
1769
1896
|
if (
|
|
@@ -1825,7 +1952,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1825
1952
|
return renderAndWait(waitProps);
|
|
1826
1953
|
}
|
|
1827
1954
|
}
|
|
1828
|
-
return (0,
|
|
1955
|
+
return (0, import_react12.createElement)(import_react12.Fragment);
|
|
1829
1956
|
};
|
|
1830
1957
|
}
|
|
1831
1958
|
if (dependencies === void 0) {
|
|
@@ -1840,7 +1967,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1840
1967
|
}
|
|
1841
1968
|
}
|
|
1842
1969
|
}
|
|
1843
|
-
(0,
|
|
1970
|
+
(0, import_react12.useEffect)(() => {
|
|
1844
1971
|
const hasDuplicate = Object.values(actions).some(
|
|
1845
1972
|
(otherAction) => otherAction.name === action.name && otherAction !== actions[idRef.current]
|
|
1846
1973
|
);
|
|
@@ -1852,7 +1979,7 @@ function useCopilotAction(action, dependencies) {
|
|
|
1852
1979
|
});
|
|
1853
1980
|
}
|
|
1854
1981
|
}, [actions]);
|
|
1855
|
-
(0,
|
|
1982
|
+
(0, import_react12.useEffect)(() => {
|
|
1856
1983
|
setAction(idRef.current, action);
|
|
1857
1984
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1858
1985
|
chatComponentsCache.current.actions[action.name] = action.render;
|
|
@@ -1881,8 +2008,8 @@ function isFrontendAction(action) {
|
|
|
1881
2008
|
}
|
|
1882
2009
|
|
|
1883
2010
|
// src/hooks/use-coagent-state-render.ts
|
|
1884
|
-
var
|
|
1885
|
-
var
|
|
2011
|
+
var import_react13 = require("react");
|
|
2012
|
+
var import_shared11 = require("@copilotkit/shared");
|
|
1886
2013
|
function useCoAgentStateRender(action, dependencies) {
|
|
1887
2014
|
const {
|
|
1888
2015
|
setCoAgentStateRender,
|
|
@@ -1890,13 +2017,13 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1890
2017
|
coAgentStateRenders,
|
|
1891
2018
|
chatComponentsCache,
|
|
1892
2019
|
availableAgents
|
|
1893
|
-
} = (0,
|
|
1894
|
-
const idRef = (0,
|
|
2020
|
+
} = (0, import_react13.useContext)(CopilotContext);
|
|
2021
|
+
const idRef = (0, import_react13.useRef)((0, import_shared11.randomId)());
|
|
1895
2022
|
const { setBannerError, addToast } = useToast();
|
|
1896
|
-
(0,
|
|
2023
|
+
(0, import_react13.useEffect)(() => {
|
|
1897
2024
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === action.name)) {
|
|
1898
2025
|
const message = `(useCoAgentStateRender): Agent "${action.name}" not found. Make sure the agent exists and is properly configured.`;
|
|
1899
|
-
const agentError = new
|
|
2026
|
+
const agentError = new import_shared11.CopilotKitAgentDiscoveryError({
|
|
1900
2027
|
agentName: action.name,
|
|
1901
2028
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
1902
2029
|
});
|
|
@@ -1914,7 +2041,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1914
2041
|
}
|
|
1915
2042
|
}
|
|
1916
2043
|
}
|
|
1917
|
-
(0,
|
|
2044
|
+
(0, import_react13.useEffect)(() => {
|
|
1918
2045
|
const currentId = idRef.current;
|
|
1919
2046
|
const hasDuplicate = Object.entries(coAgentStateRenders).some(([id, otherAction]) => {
|
|
1920
2047
|
if (id === currentId)
|
|
@@ -1938,7 +2065,7 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1938
2065
|
});
|
|
1939
2066
|
}
|
|
1940
2067
|
}, [coAgentStateRenders]);
|
|
1941
|
-
(0,
|
|
2068
|
+
(0, import_react13.useEffect)(() => {
|
|
1942
2069
|
setCoAgentStateRender(idRef.current, action);
|
|
1943
2070
|
if (chatComponentsCache.current !== null && action.render !== void 0) {
|
|
1944
2071
|
chatComponentsCache.current.coAgentStateRenders[key] = action.render;
|
|
@@ -1958,11 +2085,11 @@ function useCoAgentStateRender(action, dependencies) {
|
|
|
1958
2085
|
}
|
|
1959
2086
|
|
|
1960
2087
|
// src/hooks/use-make-copilot-document-readable.ts
|
|
1961
|
-
var
|
|
2088
|
+
var import_react14 = require("react");
|
|
1962
2089
|
function useMakeCopilotDocumentReadable(document, categories, dependencies = []) {
|
|
1963
2090
|
const { addDocumentContext, removeDocumentContext } = useCopilotContext();
|
|
1964
|
-
const idRef = (0,
|
|
1965
|
-
(0,
|
|
2091
|
+
const idRef = (0, import_react14.useRef)();
|
|
2092
|
+
(0, import_react14.useEffect)(() => {
|
|
1966
2093
|
const id = addDocumentContext(document, categories);
|
|
1967
2094
|
idRef.current = id;
|
|
1968
2095
|
return () => {
|
|
@@ -1973,7 +2100,7 @@ function useMakeCopilotDocumentReadable(document, categories, dependencies = [])
|
|
|
1973
2100
|
}
|
|
1974
2101
|
|
|
1975
2102
|
// src/hooks/use-copilot-readable.ts
|
|
1976
|
-
var
|
|
2103
|
+
var import_react15 = require("react");
|
|
1977
2104
|
function convertToJSON(description, value) {
|
|
1978
2105
|
return `${description}: ${typeof value === "string" ? value : JSON.stringify(value)}`;
|
|
1979
2106
|
}
|
|
@@ -1986,10 +2113,10 @@ function useCopilotReadable({
|
|
|
1986
2113
|
available = "enabled"
|
|
1987
2114
|
}, dependencies) {
|
|
1988
2115
|
const { addContext, removeContext } = useCopilotContext();
|
|
1989
|
-
const idRef = (0,
|
|
2116
|
+
const idRef = (0, import_react15.useRef)();
|
|
1990
2117
|
convert = convert || convertToJSON;
|
|
1991
2118
|
const information = convert(description, value);
|
|
1992
|
-
(0,
|
|
2119
|
+
(0, import_react15.useEffect)(() => {
|
|
1993
2120
|
if (available === "disabled")
|
|
1994
2121
|
return;
|
|
1995
2122
|
const id = addContext(information, parentId, categories);
|
|
@@ -2002,30 +2129,29 @@ function useCopilotReadable({
|
|
|
2002
2129
|
}
|
|
2003
2130
|
|
|
2004
2131
|
// src/hooks/use-coagent.ts
|
|
2005
|
-
var
|
|
2006
|
-
var
|
|
2132
|
+
var import_react16 = require("react");
|
|
2133
|
+
var import_shared12 = require("@copilotkit/shared");
|
|
2007
2134
|
function useCoAgent(options) {
|
|
2008
|
-
const
|
|
2009
|
-
const { availableAgents } =
|
|
2135
|
+
const context = useCopilotContext();
|
|
2136
|
+
const { availableAgents } = context;
|
|
2010
2137
|
const { setBannerError } = useToast();
|
|
2011
|
-
const lastLoadedThreadId = (0,
|
|
2012
|
-
const lastLoadedState = (0,
|
|
2138
|
+
const lastLoadedThreadId = (0, import_react16.useRef)();
|
|
2139
|
+
const lastLoadedState = (0, import_react16.useRef)();
|
|
2013
2140
|
const { name } = options;
|
|
2014
|
-
(0,
|
|
2141
|
+
(0, import_react16.useEffect)(() => {
|
|
2015
2142
|
if ((availableAgents == null ? void 0 : availableAgents.length) && !availableAgents.some((a) => a.name === name)) {
|
|
2016
2143
|
const message = `(useCoAgent): Agent "${name}" not found. Make sure the agent exists and is properly configured.`;
|
|
2017
2144
|
console.warn(message);
|
|
2018
|
-
const agentError = new
|
|
2145
|
+
const agentError = new import_shared12.CopilotKitAgentDiscoveryError({
|
|
2019
2146
|
agentName: name,
|
|
2020
2147
|
availableAgents: availableAgents.map((a) => ({ name: a.name, id: a.id }))
|
|
2021
2148
|
});
|
|
2022
2149
|
setBannerError(agentError);
|
|
2023
2150
|
}
|
|
2024
2151
|
}, [availableAgents]);
|
|
2025
|
-
const
|
|
2026
|
-
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
2152
|
+
const { getMessagesFromTap } = useMessagesTap();
|
|
2027
2153
|
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
2028
|
-
const {
|
|
2154
|
+
const { sendMessage, runChatCompletion } = useCopilotChat();
|
|
2029
2155
|
const headers = __spreadValues({}, copilotApiConfig.headers || {});
|
|
2030
2156
|
const runtimeClient = useCopilotRuntimeClient({
|
|
2031
2157
|
url: copilotApiConfig.chatApiEndpoint,
|
|
@@ -2034,7 +2160,7 @@ function useCoAgent(options) {
|
|
|
2034
2160
|
credentials: copilotApiConfig.credentials,
|
|
2035
2161
|
showDevConsole: context.showDevConsole
|
|
2036
2162
|
});
|
|
2037
|
-
const setState = (0,
|
|
2163
|
+
const setState = (0, import_react16.useCallback)(
|
|
2038
2164
|
(newState) => {
|
|
2039
2165
|
let coagentState = getCoagentState({ coagentStates, name, options });
|
|
2040
2166
|
const updatedState = typeof newState === "function" ? newState(coagentState.state) : newState;
|
|
@@ -2046,7 +2172,7 @@ function useCoAgent(options) {
|
|
|
2046
2172
|
},
|
|
2047
2173
|
[coagentStates, name]
|
|
2048
2174
|
);
|
|
2049
|
-
(0,
|
|
2175
|
+
(0, import_react16.useEffect)(() => {
|
|
2050
2176
|
const fetchAgentState = () => __async(this, null, function* () {
|
|
2051
2177
|
var _a, _b, _c, _d;
|
|
2052
2178
|
if (!threadId || threadId === lastLoadedThreadId.current)
|
|
@@ -2064,13 +2190,13 @@ function useCoAgent(options) {
|
|
|
2064
2190
|
if (((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.threadExists) && newState && newState != "{}") {
|
|
2065
2191
|
lastLoadedState.current = newState;
|
|
2066
2192
|
lastLoadedThreadId.current = threadId;
|
|
2067
|
-
const fetchedState = (0,
|
|
2193
|
+
const fetchedState = (0, import_shared12.parseJson)(newState, {});
|
|
2068
2194
|
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
2069
2195
|
}
|
|
2070
2196
|
});
|
|
2071
2197
|
void fetchAgentState();
|
|
2072
2198
|
}, [threadId]);
|
|
2073
|
-
(0,
|
|
2199
|
+
(0, import_react16.useEffect)(() => {
|
|
2074
2200
|
if (isExternalStateManagement(options)) {
|
|
2075
2201
|
setState(options.state);
|
|
2076
2202
|
} else if (coagentStates[name] === void 0) {
|
|
@@ -2081,7 +2207,7 @@ function useCoAgent(options) {
|
|
|
2081
2207
|
// reset initialstate on reset
|
|
2082
2208
|
coagentStates[name] === void 0
|
|
2083
2209
|
]);
|
|
2084
|
-
(0,
|
|
2210
|
+
(0, import_react16.useEffect)(() => {
|
|
2085
2211
|
const newConfig = options.config ? options.config : options.configurable ? { configurable: options.configurable } : void 0;
|
|
2086
2212
|
if (newConfig === void 0)
|
|
2087
2213
|
return;
|
|
@@ -2109,11 +2235,11 @@ function useCoAgent(options) {
|
|
|
2109
2235
|
}, [JSON.stringify(options.config), JSON.stringify(options.configurable)]);
|
|
2110
2236
|
const runAgentCallback = useAsyncCallback(
|
|
2111
2237
|
(hint) => __async(this, null, function* () {
|
|
2112
|
-
yield runAgent(name, context,
|
|
2238
|
+
yield runAgent(name, context, getMessagesFromTap(), sendMessage, runChatCompletion, hint);
|
|
2113
2239
|
}),
|
|
2114
|
-
[name, context,
|
|
2240
|
+
[name, context, sendMessage, runChatCompletion]
|
|
2115
2241
|
);
|
|
2116
|
-
return (0,
|
|
2242
|
+
return (0, import_react16.useMemo)(() => {
|
|
2117
2243
|
const coagentState = getCoagentState({ coagentStates, name, options });
|
|
2118
2244
|
return {
|
|
2119
2245
|
name,
|
|
@@ -2153,7 +2279,7 @@ function stopAgent(name, context) {
|
|
|
2153
2279
|
console.warn(`No agent session found for ${name}`);
|
|
2154
2280
|
}
|
|
2155
2281
|
}
|
|
2156
|
-
function runAgent(name, context,
|
|
2282
|
+
function runAgent(name, context, messages, sendMessage, runChatCompletion, hint) {
|
|
2157
2283
|
return __async(this, null, function* () {
|
|
2158
2284
|
var _a, _b;
|
|
2159
2285
|
const { agentSession, setAgentSession } = context;
|
|
@@ -2163,8 +2289,8 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
2163
2289
|
});
|
|
2164
2290
|
}
|
|
2165
2291
|
let previousState = null;
|
|
2166
|
-
for (let i =
|
|
2167
|
-
const message =
|
|
2292
|
+
for (let i = messages.length - 1; i >= 0; i--) {
|
|
2293
|
+
const message = messages[i];
|
|
2168
2294
|
if (message.isAgentStateMessage() && message.agentName === name) {
|
|
2169
2295
|
previousState = message.state;
|
|
2170
2296
|
}
|
|
@@ -2173,7 +2299,7 @@ function runAgent(name, context, appendMessage, runChatCompletion, hint) {
|
|
|
2173
2299
|
if (hint) {
|
|
2174
2300
|
const hintMessage = hint({ previousState, currentState: state });
|
|
2175
2301
|
if (hintMessage) {
|
|
2176
|
-
yield
|
|
2302
|
+
yield sendMessage(hintMessage);
|
|
2177
2303
|
} else {
|
|
2178
2304
|
yield runChatCompletion();
|
|
2179
2305
|
}
|
|
@@ -2210,28 +2336,28 @@ var getCoagentState = ({
|
|
|
2210
2336
|
};
|
|
2211
2337
|
|
|
2212
2338
|
// src/hooks/use-copilot-authenticated-action.ts
|
|
2213
|
-
var
|
|
2214
|
-
var
|
|
2339
|
+
var import_react17 = require("react");
|
|
2340
|
+
var import_react18 = __toESM(require("react"));
|
|
2215
2341
|
function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
2216
2342
|
const { authConfig_c, authStates_c, setAuthStates_c } = useCopilotContext();
|
|
2217
|
-
const pendingActionRef = (0,
|
|
2218
|
-
const executeAction2 = (0,
|
|
2343
|
+
const pendingActionRef = (0, import_react17.useRef)(null);
|
|
2344
|
+
const executeAction2 = (0, import_react17.useCallback)(
|
|
2219
2345
|
(props) => {
|
|
2220
2346
|
if (typeof action.render === "function") {
|
|
2221
2347
|
return action.render(props);
|
|
2222
2348
|
}
|
|
2223
|
-
return action.render ||
|
|
2349
|
+
return action.render || import_react18.default.createElement(import_react17.Fragment);
|
|
2224
2350
|
},
|
|
2225
2351
|
[action]
|
|
2226
2352
|
);
|
|
2227
|
-
const wrappedRender = (0,
|
|
2353
|
+
const wrappedRender = (0, import_react17.useCallback)(
|
|
2228
2354
|
(props) => {
|
|
2229
2355
|
const isAuthenticated = Object.values(authStates_c || {}).some(
|
|
2230
2356
|
(state) => state.status === "authenticated"
|
|
2231
2357
|
);
|
|
2232
2358
|
if (!isAuthenticated) {
|
|
2233
2359
|
pendingActionRef.current = props;
|
|
2234
|
-
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ?
|
|
2360
|
+
return (authConfig_c == null ? void 0 : authConfig_c.SignInComponent) ? import_react18.default.createElement(authConfig_c.SignInComponent, {
|
|
2235
2361
|
onSignInComplete: (authState) => {
|
|
2236
2362
|
setAuthStates_c == null ? void 0 : setAuthStates_c((prev) => __spreadProps(__spreadValues({}, prev), { [action.name]: authState }));
|
|
2237
2363
|
if (pendingActionRef.current) {
|
|
@@ -2239,7 +2365,7 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2239
2365
|
pendingActionRef.current = null;
|
|
2240
2366
|
}
|
|
2241
2367
|
}
|
|
2242
|
-
}) :
|
|
2368
|
+
}) : import_react18.default.createElement(import_react17.Fragment);
|
|
2243
2369
|
}
|
|
2244
2370
|
return executeAction2(props);
|
|
2245
2371
|
},
|
|
@@ -2254,29 +2380,29 @@ function useCopilotAuthenticatedAction_c(action, dependencies) {
|
|
|
2254
2380
|
}
|
|
2255
2381
|
|
|
2256
2382
|
// src/hooks/use-langgraph-interrupt.ts
|
|
2257
|
-
var
|
|
2258
|
-
var
|
|
2383
|
+
var import_react19 = require("react");
|
|
2384
|
+
var import_shared13 = require("@copilotkit/shared");
|
|
2259
2385
|
function useLangGraphInterrupt(action, dependencies) {
|
|
2260
2386
|
var _a;
|
|
2261
|
-
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0,
|
|
2387
|
+
const { setLangGraphInterruptAction, removeLangGraphInterruptAction, langGraphInterruptAction } = (0, import_react19.useContext)(CopilotContext);
|
|
2262
2388
|
const { runChatCompletion } = useCopilotChat();
|
|
2263
2389
|
const { addToast } = useToast();
|
|
2264
|
-
const actionId = (0,
|
|
2265
|
-
const hasAction = (0,
|
|
2390
|
+
const actionId = (0, import_shared13.dataToUUID)(JSON.stringify(action), "lgAction");
|
|
2391
|
+
const hasAction = (0, import_react19.useMemo)(
|
|
2266
2392
|
() => Boolean(langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id),
|
|
2267
2393
|
[langGraphInterruptAction]
|
|
2268
2394
|
);
|
|
2269
|
-
const isCurrentAction = (0,
|
|
2395
|
+
const isCurrentAction = (0, import_react19.useMemo)(
|
|
2270
2396
|
() => (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) && (langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.id) === actionId,
|
|
2271
2397
|
[langGraphInterruptAction]
|
|
2272
2398
|
);
|
|
2273
|
-
(0,
|
|
2399
|
+
(0, import_react19.useEffect)(() => {
|
|
2274
2400
|
var _a2;
|
|
2275
2401
|
if (hasAction && isCurrentAction && ((_a2 = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a2.response)) {
|
|
2276
2402
|
runChatCompletion();
|
|
2277
2403
|
}
|
|
2278
2404
|
}, [(_a = langGraphInterruptAction == null ? void 0 : langGraphInterruptAction.event) == null ? void 0 : _a.response, runChatCompletion, hasAction, isCurrentAction]);
|
|
2279
|
-
(0,
|
|
2405
|
+
(0, import_react19.useEffect)(() => {
|
|
2280
2406
|
if (!action)
|
|
2281
2407
|
return;
|
|
2282
2408
|
if (hasAction && !isCurrentAction && !action.enabled) {
|
|
@@ -2301,10 +2427,10 @@ function useLangGraphInterrupt(action, dependencies) {
|
|
|
2301
2427
|
}
|
|
2302
2428
|
|
|
2303
2429
|
// src/hooks/use-copilot-additional-instructions.ts
|
|
2304
|
-
var
|
|
2430
|
+
var import_react20 = require("react");
|
|
2305
2431
|
function useCopilotAdditionalInstructions({ instructions, available = "enabled" }, dependencies) {
|
|
2306
2432
|
const { setAdditionalInstructions } = useCopilotContext();
|
|
2307
|
-
(0,
|
|
2433
|
+
(0, import_react20.useEffect)(() => {
|
|
2308
2434
|
if (available === "disabled")
|
|
2309
2435
|
return;
|
|
2310
2436
|
setAdditionalInstructions((prevInstructions) => [...prevInstructions || [], instructions]);
|
|
@@ -2326,6 +2452,8 @@ function useCopilotAdditionalInstructions({ instructions, available = "enabled"
|
|
|
2326
2452
|
useCopilotAdditionalInstructions,
|
|
2327
2453
|
useCopilotAuthenticatedAction_c,
|
|
2328
2454
|
useCopilotChat,
|
|
2455
|
+
useCopilotChatHeadless_c,
|
|
2456
|
+
useCopilotChatInternal,
|
|
2329
2457
|
useCopilotReadable,
|
|
2330
2458
|
useCopilotRuntimeClient,
|
|
2331
2459
|
useLangGraphInterrupt,
|