@copilotkit/react-core 1.5.12-next.5 → 1.5.12-next.7
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 +20 -0
- package/dist/{chunk-KOSLAM4Z.mjs → chunk-6BQUI465.mjs} +27 -6
- package/dist/chunk-6BQUI465.mjs.map +1 -0
- package/dist/{chunk-22XKTBPF.mjs → chunk-CBWNO2FP.mjs} +3 -3
- package/dist/{chunk-6BQVZFNO.mjs → chunk-CQWEXISS.mjs} +2 -2
- package/dist/{chunk-EWKJMQOF.mjs → chunk-EXX267DG.mjs} +3 -3
- package/dist/{chunk-LNI2Z45S.mjs → chunk-HZCROITJ.mjs} +5 -3
- package/dist/chunk-HZCROITJ.mjs.map +1 -0
- package/dist/chunk-IFBUUIU7.mjs +53 -0
- package/dist/chunk-IFBUUIU7.mjs.map +1 -0
- package/dist/{chunk-HIUT2NLX.mjs → chunk-J6UBNKIR.mjs} +2 -2
- package/dist/{chunk-6DQD4B23.mjs → chunk-KGCYVAIN.mjs} +16 -10
- package/dist/chunk-KGCYVAIN.mjs.map +1 -0
- package/dist/{chunk-LHKIIAUQ.mjs → chunk-MF4F77OY.mjs} +3 -3
- package/dist/{chunk-LZWH4OG5.mjs → chunk-MYCYEMIM.mjs} +31 -13
- package/dist/chunk-MYCYEMIM.mjs.map +1 -0
- package/dist/{chunk-FQ53HQYZ.mjs → chunk-N37EFAUX.mjs} +2 -2
- package/dist/{chunk-M2NT7NOO.mjs → chunk-VEGDEDID.mjs} +2 -2
- package/dist/{chunk-VNTDIJSG.mjs → chunk-X47CUJJT.mjs} +2 -2
- package/dist/{chunk-RD5XFSI4.mjs → chunk-X62FIPVR.mjs} +11 -8
- package/dist/chunk-X62FIPVR.mjs.map +1 -0
- package/dist/{chunk-WXREY7UP.mjs → chunk-YVQNSJ4Z.mjs} +6 -3
- package/dist/chunk-YVQNSJ4Z.mjs.map +1 -0
- package/dist/components/copilot-provider/copilot-messages.js +125 -2
- package/dist/components/copilot-provider/copilot-messages.js.map +1 -1
- package/dist/components/copilot-provider/copilot-messages.mjs +2 -1
- package/dist/components/copilot-provider/copilotkit-props.d.ts +4 -0
- package/dist/components/copilot-provider/copilotkit-props.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.js +58 -9
- package/dist/components/copilot-provider/copilotkit.js.map +1 -1
- package/dist/components/copilot-provider/copilotkit.mjs +7 -7
- package/dist/components/copilot-provider/index.js +58 -9
- package/dist/components/copilot-provider/index.js.map +1 -1
- package/dist/components/copilot-provider/index.mjs +7 -7
- package/dist/components/error-boundary/error-boundary.js +4 -2
- package/dist/components/error-boundary/error-boundary.js.map +1 -1
- package/dist/components/error-boundary/error-boundary.mjs +2 -2
- package/dist/components/error-boundary/error-utils.js +14 -2
- package/dist/components/error-boundary/error-utils.js.map +1 -1
- package/dist/components/error-boundary/error-utils.mjs +1 -1
- package/dist/components/index.js +58 -9
- package/dist/components/index.js.map +1 -1
- package/dist/components/index.mjs +7 -7
- package/dist/components/toast/toast-provider.js +14 -2
- package/dist/components/toast/toast-provider.js.map +1 -1
- package/dist/components/toast/toast-provider.mjs +1 -1
- package/dist/context/copilot-context.d.ts +5 -3
- package/dist/context/copilot-context.js +5 -2
- package/dist/context/copilot-context.js.map +1 -1
- package/dist/context/copilot-context.mjs +1 -1
- package/dist/context/index.js +5 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/index.mjs +1 -1
- package/dist/hooks/index.js +46 -15
- package/dist/hooks/index.js.map +1 -1
- package/dist/hooks/index.mjs +25 -25
- package/dist/hooks/use-chat.d.ts +11 -3
- package/dist/hooks/use-chat.js +25 -8
- package/dist/hooks/use-chat.js.map +1 -1
- package/dist/hooks/use-chat.mjs +3 -3
- package/dist/hooks/use-coagent-state-render.js +5 -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.js +46 -15
- package/dist/hooks/use-coagent.js.map +1 -1
- package/dist/hooks/use-coagent.mjs +11 -11
- package/dist/hooks/use-copilot-action.js +9 -4
- package/dist/hooks/use-copilot-action.js.map +1 -1
- package/dist/hooks/use-copilot-action.mjs +3 -3
- package/dist/hooks/use-copilot-authenticated-action.js +9 -4
- package/dist/hooks/use-copilot-authenticated-action.js.map +1 -1
- package/dist/hooks/use-copilot-authenticated-action.mjs +4 -4
- package/dist/hooks/use-copilot-chat.js +26 -13
- package/dist/hooks/use-copilot-chat.js.map +1 -1
- package/dist/hooks/use-copilot-chat.mjs +10 -10
- package/dist/hooks/use-copilot-readable.js +5 -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 +14 -2
- package/dist/hooks/use-copilot-runtime-client.js.map +1 -1
- package/dist/hooks/use-copilot-runtime-client.mjs +2 -2
- package/dist/hooks/use-make-copilot-document-readable.js +5 -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.js +126 -58
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +26 -26
- package/dist/lib/copilot-task.js.map +1 -1
- package/dist/lib/copilot-task.mjs +8 -8
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +8 -8
- package/dist/utils/extract.js.map +1 -1
- package/dist/utils/extract.mjs +7 -7
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/index.mjs +7 -7
- package/package.json +5 -4
- package/src/components/copilot-provider/copilot-messages.tsx +24 -2
- package/src/components/copilot-provider/copilotkit-props.tsx +5 -0
- package/src/components/copilot-provider/copilotkit.tsx +30 -4
- package/src/components/error-boundary/error-utils.tsx +11 -6
- package/src/context/copilot-context.tsx +13 -4
- package/src/hooks/use-chat.ts +27 -7
- package/src/hooks/use-coagent.ts +30 -4
- package/src/hooks/use-copilot-chat.ts +5 -2
- package/dist/chunk-6DQD4B23.mjs.map +0 -1
- package/dist/chunk-KOSLAM4Z.mjs.map +0 -1
- package/dist/chunk-LNI2Z45S.mjs.map +0 -1
- package/dist/chunk-LZWH4OG5.mjs.map +0 -1
- package/dist/chunk-RD5XFSI4.mjs.map +0 -1
- package/dist/chunk-WXREY7UP.mjs.map +0 -1
- package/dist/chunk-XXR4QFAQ.mjs +0 -29
- package/dist/chunk-XXR4QFAQ.mjs.map +0 -1
- /package/dist/{chunk-22XKTBPF.mjs.map → chunk-CBWNO2FP.mjs.map} +0 -0
- /package/dist/{chunk-6BQVZFNO.mjs.map → chunk-CQWEXISS.mjs.map} +0 -0
- /package/dist/{chunk-EWKJMQOF.mjs.map → chunk-EXX267DG.mjs.map} +0 -0
- /package/dist/{chunk-HIUT2NLX.mjs.map → chunk-J6UBNKIR.mjs.map} +0 -0
- /package/dist/{chunk-LHKIIAUQ.mjs.map → chunk-MF4F77OY.mjs.map} +0 -0
- /package/dist/{chunk-FQ53HQYZ.mjs.map → chunk-N37EFAUX.mjs.map} +0 -0
- /package/dist/{chunk-M2NT7NOO.mjs.map → chunk-VEGDEDID.mjs.map} +0 -0
- /package/dist/{chunk-VNTDIJSG.mjs.map → chunk-X47CUJJT.mjs.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -164,14 +164,17 @@ var emptyCopilotContext = {
|
|
|
164
164
|
},
|
|
165
165
|
forwardedParameters: {},
|
|
166
166
|
agentLock: null,
|
|
167
|
-
threadId:
|
|
167
|
+
threadId: "",
|
|
168
168
|
setThreadId: () => {
|
|
169
169
|
},
|
|
170
170
|
runId: null,
|
|
171
171
|
setRunId: () => {
|
|
172
172
|
},
|
|
173
173
|
chatAbortControllerRef: { current: null },
|
|
174
|
-
availableAgents: []
|
|
174
|
+
availableAgents: [],
|
|
175
|
+
extensions: {},
|
|
176
|
+
setExtensions: () => {
|
|
177
|
+
}
|
|
175
178
|
};
|
|
176
179
|
var CopilotContext = import_react.default.createContext(emptyCopilotContext);
|
|
177
180
|
function useCopilotContext() {
|
|
@@ -407,10 +410,30 @@ function useCopilotMessagesContext() {
|
|
|
407
410
|
}
|
|
408
411
|
|
|
409
412
|
// src/components/copilot-provider/copilot-messages.tsx
|
|
413
|
+
var import_runtime_client_gql = require("@copilotkit/runtime-client-gql");
|
|
410
414
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
411
415
|
function CopilotMessages(_a) {
|
|
412
416
|
var _b = _a, { children } = _b, props = __objRest(_b, ["children"]);
|
|
413
417
|
const [messages, setMessages] = (0, import_react5.useState)([]);
|
|
418
|
+
const { threadId, agentSession, runtimeClient } = useCopilotContext();
|
|
419
|
+
(0, import_react5.useEffect)(() => {
|
|
420
|
+
if (agentSession == null ? void 0 : agentSession.agentName) {
|
|
421
|
+
const fetchAgentState = () => __async(this, null, function* () {
|
|
422
|
+
var _a2, _b2, _c, _d;
|
|
423
|
+
const result = yield runtimeClient.loadAgentState({
|
|
424
|
+
threadId,
|
|
425
|
+
agentName: agentSession.agentName
|
|
426
|
+
});
|
|
427
|
+
if ((_b2 = (_a2 = result.data) == null ? void 0 : _a2.loadAgentState) == null ? void 0 : _b2.threadExists) {
|
|
428
|
+
const messages2 = (0, import_runtime_client_gql.loadMessagesFromJsonRepresentation)(
|
|
429
|
+
JSON.parse(((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.messages) || "[]")
|
|
430
|
+
);
|
|
431
|
+
setMessages(messages2);
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
void fetchAgentState();
|
|
435
|
+
}
|
|
436
|
+
}, [threadId, (agentSession == null ? void 0 : agentSession.agentName) !== void 0]);
|
|
414
437
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
415
438
|
CopilotMessagesContext.Provider,
|
|
416
439
|
{
|
|
@@ -457,11 +480,13 @@ var ExclamationMarkIcon = ({
|
|
|
457
480
|
);
|
|
458
481
|
|
|
459
482
|
// src/components/error-boundary/error-utils.tsx
|
|
483
|
+
var import_react_markdown = __toESM(require("react-markdown"));
|
|
460
484
|
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
461
485
|
function ErrorToast({ errors }) {
|
|
462
486
|
const errorsToRender = errors.map((error, idx) => {
|
|
463
487
|
var _a, _b, _c;
|
|
464
|
-
const
|
|
488
|
+
const originalError = "extensions" in error ? (_a = error.extensions) == null ? void 0 : _a.originalError : {};
|
|
489
|
+
const message = (_b = originalError == null ? void 0 : originalError.message) != null ? _b : error.message;
|
|
465
490
|
const code = "extensions" in error ? (_c = error.extensions) == null ? void 0 : _c.code : null;
|
|
466
491
|
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
467
492
|
"div",
|
|
@@ -486,7 +511,7 @@ function ErrorToast({ errors }) {
|
|
|
486
511
|
]
|
|
487
512
|
}
|
|
488
513
|
),
|
|
489
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
514
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_markdown.default, { children: message })
|
|
490
515
|
]
|
|
491
516
|
},
|
|
492
517
|
idx
|
|
@@ -678,13 +703,13 @@ function Toast({
|
|
|
678
703
|
}
|
|
679
704
|
|
|
680
705
|
// src/hooks/use-copilot-runtime-client.ts
|
|
681
|
-
var
|
|
706
|
+
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
682
707
|
var import_react8 = require("react");
|
|
683
708
|
var useCopilotRuntimeClient = (options) => {
|
|
684
709
|
const { addGraphQLErrorsToast } = useToast();
|
|
685
710
|
const addErrorToast = useErrorToast();
|
|
686
711
|
const runtimeClient = (0, import_react8.useMemo)(() => {
|
|
687
|
-
return new
|
|
712
|
+
return new import_runtime_client_gql2.CopilotRuntimeClient(__spreadProps(__spreadValues({}, options), {
|
|
688
713
|
handleGQLErrors: (error) => {
|
|
689
714
|
if (error.graphQLErrors.length) {
|
|
690
715
|
addGraphQLErrorsToast(error.graphQLErrors);
|
|
@@ -699,8 +724,8 @@ var useCopilotRuntimeClient = (options) => {
|
|
|
699
724
|
|
|
700
725
|
// src/utils/extract.ts
|
|
701
726
|
var import_shared3 = require("@copilotkit/shared");
|
|
702
|
-
var import_runtime_client_gql2 = require("@copilotkit/runtime-client-gql");
|
|
703
727
|
var import_runtime_client_gql3 = require("@copilotkit/runtime-client-gql");
|
|
728
|
+
var import_runtime_client_gql4 = require("@copilotkit/runtime-client-gql");
|
|
704
729
|
function extract(_0) {
|
|
705
730
|
return __async(this, arguments, function* ({
|
|
706
731
|
context,
|
|
@@ -710,7 +735,7 @@ function extract(_0) {
|
|
|
710
735
|
data,
|
|
711
736
|
abortSignal,
|
|
712
737
|
stream,
|
|
713
|
-
requestType =
|
|
738
|
+
requestType = import_runtime_client_gql3.CopilotRequestType.Task,
|
|
714
739
|
forwardedParameters
|
|
715
740
|
}) {
|
|
716
741
|
var _a, _b;
|
|
@@ -731,13 +756,13 @@ function extract(_0) {
|
|
|
731
756
|
if (includeReadable) {
|
|
732
757
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
733
758
|
}
|
|
734
|
-
const systemMessage = new
|
|
759
|
+
const systemMessage = new import_runtime_client_gql3.TextMessage({
|
|
735
760
|
content: makeSystemMessage(contextString, instructions),
|
|
736
|
-
role:
|
|
761
|
+
role: import_runtime_client_gql3.Role.System
|
|
737
762
|
});
|
|
738
|
-
const instructionsMessage = new
|
|
763
|
+
const instructionsMessage = new import_runtime_client_gql3.TextMessage({
|
|
739
764
|
content: makeInstructionsMessage(instructions),
|
|
740
|
-
role:
|
|
765
|
+
role: import_runtime_client_gql3.Role.User
|
|
741
766
|
});
|
|
742
767
|
const response = context.runtimeClient.asStream(
|
|
743
768
|
context.runtimeClient.generateCopilotResponse({
|
|
@@ -752,8 +777,8 @@ function extract(_0) {
|
|
|
752
777
|
],
|
|
753
778
|
url: window.location.href
|
|
754
779
|
},
|
|
755
|
-
messages: (0,
|
|
756
|
-
includeMessages ? [systemMessage, instructionsMessage, ...(0,
|
|
780
|
+
messages: (0, import_runtime_client_gql4.convertMessagesToGqlInput)(
|
|
781
|
+
includeMessages ? [systemMessage, instructionsMessage, ...(0, import_runtime_client_gql4.filterAgentStateMessages)(messages)] : [systemMessage, instructionsMessage]
|
|
757
782
|
),
|
|
758
783
|
metadata: {
|
|
759
784
|
requestType
|
|
@@ -778,7 +803,7 @@ function extract(_0) {
|
|
|
778
803
|
if (abortSignal == null ? void 0 : abortSignal.aborted) {
|
|
779
804
|
throw new Error("Aborted");
|
|
780
805
|
}
|
|
781
|
-
actionExecutionMessage = (0,
|
|
806
|
+
actionExecutionMessage = (0, import_runtime_client_gql3.convertGqlOutputToMessages)(
|
|
782
807
|
value.generateCopilotResponse.messages
|
|
783
808
|
).find((msg) => msg.isActionExecutionMessage());
|
|
784
809
|
if (!actionExecutionMessage) {
|
|
@@ -899,6 +924,7 @@ function CopilotKitInternal(_a) {
|
|
|
899
924
|
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
900
925
|
const [chatInstructions, setChatInstructions] = (0, import_react10.useState)("");
|
|
901
926
|
const [authStates, setAuthStates] = (0, import_react10.useState)({});
|
|
927
|
+
const [extensions, setExtensions] = (0, import_react10.useState)({});
|
|
902
928
|
const {
|
|
903
929
|
addElement: addDocument,
|
|
904
930
|
removeElement: removeDocument,
|
|
@@ -1083,7 +1109,21 @@ ${nonDocumentStrings}`;
|
|
|
1083
1109
|
};
|
|
1084
1110
|
}
|
|
1085
1111
|
const [agentSession, setAgentSession] = (0, import_react10.useState)(initialAgentSession);
|
|
1086
|
-
const [
|
|
1112
|
+
const [internalThreadId, setInternalThreadId] = (0, import_react10.useState)(props.threadId || (0, import_shared4.randomUUID)());
|
|
1113
|
+
const setThreadId = (0, import_react10.useCallback)(
|
|
1114
|
+
(value) => {
|
|
1115
|
+
if (props.threadId) {
|
|
1116
|
+
throw new Error("Cannot call setThreadId() when threadId is provided via props.");
|
|
1117
|
+
}
|
|
1118
|
+
setInternalThreadId(value);
|
|
1119
|
+
},
|
|
1120
|
+
[props.threadId]
|
|
1121
|
+
);
|
|
1122
|
+
(0, import_react10.useEffect)(() => {
|
|
1123
|
+
if (props.threadId !== void 0) {
|
|
1124
|
+
setInternalThreadId(props.threadId);
|
|
1125
|
+
}
|
|
1126
|
+
}, [props.threadId]);
|
|
1087
1127
|
const [runId, setRunId] = (0, import_react10.useState)(null);
|
|
1088
1128
|
const chatAbortControllerRef = (0, import_react10.useRef)(null);
|
|
1089
1129
|
const showDevConsole = props.showDevConsole === void 0 ? "auto" : props.showDevConsole;
|
|
@@ -1123,7 +1163,7 @@ ${nonDocumentStrings}`;
|
|
|
1123
1163
|
runtimeClient,
|
|
1124
1164
|
forwardedParameters: props.forwardedParameters || {},
|
|
1125
1165
|
agentLock: props.agent || null,
|
|
1126
|
-
threadId,
|
|
1166
|
+
threadId: internalThreadId,
|
|
1127
1167
|
setThreadId,
|
|
1128
1168
|
runId,
|
|
1129
1169
|
setRunId,
|
|
@@ -1131,7 +1171,9 @@ ${nonDocumentStrings}`;
|
|
|
1131
1171
|
availableAgents,
|
|
1132
1172
|
authConfig: props.authConfig,
|
|
1133
1173
|
authStates,
|
|
1134
|
-
setAuthStates
|
|
1174
|
+
setAuthStates,
|
|
1175
|
+
extensions,
|
|
1176
|
+
setExtensions
|
|
1135
1177
|
},
|
|
1136
1178
|
children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CopilotMessages, { children })
|
|
1137
1179
|
}
|
|
@@ -1166,27 +1208,27 @@ function entryPointsToFunctionCallHandler(actions) {
|
|
|
1166
1208
|
|
|
1167
1209
|
// src/hooks/use-copilot-chat.ts
|
|
1168
1210
|
var import_react12 = require("react");
|
|
1169
|
-
var
|
|
1211
|
+
var import_runtime_client_gql7 = require("@copilotkit/runtime-client-gql");
|
|
1170
1212
|
|
|
1171
1213
|
// src/hooks/use-chat.ts
|
|
1172
1214
|
var import_react11 = require("react");
|
|
1173
1215
|
var import_shared6 = require("@copilotkit/shared");
|
|
1174
|
-
var
|
|
1216
|
+
var import_runtime_client_gql6 = require("@copilotkit/runtime-client-gql");
|
|
1175
1217
|
|
|
1176
1218
|
// src/types/frontend-action.ts
|
|
1177
|
-
var
|
|
1219
|
+
var import_runtime_client_gql5 = require("@copilotkit/runtime-client-gql");
|
|
1178
1220
|
var import_shared5 = require("@copilotkit/shared");
|
|
1179
1221
|
function processActionsForRuntimeRequest(actions) {
|
|
1180
1222
|
const filteredActions = actions.filter(
|
|
1181
|
-
(action) => action.available !==
|
|
1223
|
+
(action) => action.available !== import_runtime_client_gql5.ActionInputAvailability.Disabled && action.disabled !== true && action.name !== "*"
|
|
1182
1224
|
).map((action) => {
|
|
1183
|
-
let available =
|
|
1225
|
+
let available = import_runtime_client_gql5.ActionInputAvailability.Enabled;
|
|
1184
1226
|
if (action.disabled) {
|
|
1185
|
-
available =
|
|
1227
|
+
available = import_runtime_client_gql5.ActionInputAvailability.Disabled;
|
|
1186
1228
|
} else if (action.available === "disabled") {
|
|
1187
|
-
available =
|
|
1229
|
+
available = import_runtime_client_gql5.ActionInputAvailability.Disabled;
|
|
1188
1230
|
} else if (action.available === "remote") {
|
|
1189
|
-
available =
|
|
1231
|
+
available = import_runtime_client_gql5.ActionInputAvailability.Remote;
|
|
1190
1232
|
}
|
|
1191
1233
|
return {
|
|
1192
1234
|
name: action.name,
|
|
@@ -1220,16 +1262,18 @@ function useChat(options) {
|
|
|
1220
1262
|
runId,
|
|
1221
1263
|
setRunId,
|
|
1222
1264
|
chatAbortControllerRef,
|
|
1223
|
-
agentLock
|
|
1265
|
+
agentLock,
|
|
1266
|
+
extensions,
|
|
1267
|
+
setExtensions
|
|
1224
1268
|
} = options;
|
|
1225
1269
|
const runChatCompletionRef = (0, import_react11.useRef)();
|
|
1226
1270
|
const addErrorToast = useErrorToast();
|
|
1227
1271
|
const agentSessionRef = (0, import_react11.useRef)(agentSession);
|
|
1228
1272
|
agentSessionRef.current = agentSession;
|
|
1229
|
-
const threadIdRef = (0, import_react11.useRef)(threadId);
|
|
1230
|
-
threadIdRef.current = threadId;
|
|
1231
1273
|
const runIdRef = (0, import_react11.useRef)(runId);
|
|
1232
1274
|
runIdRef.current = runId;
|
|
1275
|
+
const extensionsRef = (0, import_react11.useRef)(extensions);
|
|
1276
|
+
extensionsRef.current = extensions;
|
|
1233
1277
|
const publicApiKey = copilotConfig.publicApiKey;
|
|
1234
1278
|
const headers = __spreadValues(__spreadValues({}, copilotConfig.headers || {}), publicApiKey ? { [import_shared6.COPILOT_CLOUD_PUBLIC_API_KEY_HEADER]: publicApiKey } : {});
|
|
1235
1279
|
const runtimeClient = useCopilotRuntimeClient({
|
|
@@ -1243,9 +1287,9 @@ function useChat(options) {
|
|
|
1243
1287
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
1244
1288
|
setIsLoading(true);
|
|
1245
1289
|
let newMessages = [
|
|
1246
|
-
new
|
|
1290
|
+
new import_runtime_client_gql6.TextMessage({
|
|
1247
1291
|
content: "",
|
|
1248
|
-
role:
|
|
1292
|
+
role: import_runtime_client_gql6.Role.Assistant
|
|
1249
1293
|
})
|
|
1250
1294
|
];
|
|
1251
1295
|
chatAbortControllerRef.current = new AbortController();
|
|
@@ -1260,9 +1304,10 @@ function useChat(options) {
|
|
|
1260
1304
|
actions: processActionsForRuntimeRequest(actions),
|
|
1261
1305
|
url: window.location.href
|
|
1262
1306
|
},
|
|
1263
|
-
threadId
|
|
1307
|
+
threadId,
|
|
1264
1308
|
runId: runIdRef.current,
|
|
1265
|
-
|
|
1309
|
+
extensions: extensionsRef.current,
|
|
1310
|
+
messages: (0, import_runtime_client_gql6.convertMessagesToGqlInput)((0, import_runtime_client_gql6.filterAgentStateMessages)(messagesWithContext))
|
|
1266
1311
|
}, copilotConfig.cloud ? {
|
|
1267
1312
|
cloud: __spreadValues({}, ((_c = (_b = (_a = copilotConfig.cloud.guardrails) == null ? void 0 : _a.input) == null ? void 0 : _b.restrictToTopic) == null ? void 0 : _c.enabled) ? {
|
|
1268
1313
|
guardrails: {
|
|
@@ -1274,7 +1319,7 @@ function useChat(options) {
|
|
|
1274
1319
|
} : {})
|
|
1275
1320
|
} : {}), {
|
|
1276
1321
|
metadata: {
|
|
1277
|
-
requestType:
|
|
1322
|
+
requestType: import_runtime_client_gql6.CopilotRequestType.Chat
|
|
1278
1323
|
}
|
|
1279
1324
|
}), agentSessionRef.current ? {
|
|
1280
1325
|
agentSession: agentSessionRef.current
|
|
@@ -1314,12 +1359,14 @@ function useChat(options) {
|
|
|
1314
1359
|
if (!(value == null ? void 0 : value.generateCopilotResponse)) {
|
|
1315
1360
|
continue;
|
|
1316
1361
|
}
|
|
1317
|
-
threadIdRef.current = value.generateCopilotResponse.threadId || null;
|
|
1318
1362
|
runIdRef.current = value.generateCopilotResponse.runId || null;
|
|
1319
|
-
|
|
1363
|
+
extensionsRef.current = import_runtime_client_gql6.CopilotRuntimeClient.removeGraphQLTypename(
|
|
1364
|
+
value.generateCopilotResponse.extensions || {}
|
|
1365
|
+
);
|
|
1320
1366
|
setRunId(runIdRef.current);
|
|
1321
|
-
|
|
1322
|
-
|
|
1367
|
+
setExtensions(extensionsRef.current);
|
|
1368
|
+
messages2 = (0, import_runtime_client_gql6.convertGqlOutputToMessages)(
|
|
1369
|
+
(0, import_runtime_client_gql6.filterAdjacentAgentStateMessages)(value.generateCopilotResponse.messages)
|
|
1323
1370
|
);
|
|
1324
1371
|
if (messages2.length === 0) {
|
|
1325
1372
|
continue;
|
|
@@ -1327,8 +1374,8 @@ function useChat(options) {
|
|
|
1327
1374
|
newMessages = [];
|
|
1328
1375
|
if (((_h = value.generateCopilotResponse.status) == null ? void 0 : _h.__typename) === "FailedResponseStatus" && value.generateCopilotResponse.status.reason === "GUARDRAILS_VALIDATION_FAILED") {
|
|
1329
1376
|
newMessages = [
|
|
1330
|
-
new
|
|
1331
|
-
role:
|
|
1377
|
+
new import_runtime_client_gql6.TextMessage({
|
|
1378
|
+
role: import_runtime_client_gql6.MessageRole.Assistant,
|
|
1332
1379
|
content: ((_i = value.generateCopilotResponse.status.details) == null ? void 0 : _i.guardrailsReason) || ""
|
|
1333
1380
|
})
|
|
1334
1381
|
];
|
|
@@ -1352,7 +1399,7 @@ function useChat(options) {
|
|
|
1352
1399
|
const lastAgentStateMessage = [...messages2].reverse().find((message) => message.isAgentStateMessage());
|
|
1353
1400
|
if (lastAgentStateMessage) {
|
|
1354
1401
|
if (lastAgentStateMessage.state.messages && lastAgentStateMessage.state.messages.length > 0) {
|
|
1355
|
-
syncedMessages = (0,
|
|
1402
|
+
syncedMessages = (0, import_runtime_client_gql6.loadMessagesFromJsonRepresentation)(
|
|
1356
1403
|
lastAgentStateMessage.state.messages
|
|
1357
1404
|
);
|
|
1358
1405
|
}
|
|
@@ -1396,7 +1443,7 @@ function useChat(options) {
|
|
|
1396
1443
|
const lastMessages = [];
|
|
1397
1444
|
for (let i = finalMessages.length - 1; i >= 0; i--) {
|
|
1398
1445
|
const message = finalMessages[i];
|
|
1399
|
-
if (message.isActionExecutionMessage() && message.status.code !==
|
|
1446
|
+
if (message.isActionExecutionMessage() && message.status.code !== import_runtime_client_gql6.MessageStatusCode.Pending) {
|
|
1400
1447
|
lastMessages.unshift(message);
|
|
1401
1448
|
} else {
|
|
1402
1449
|
break;
|
|
@@ -1444,9 +1491,9 @@ function useChat(options) {
|
|
|
1444
1491
|
finalMessages.splice(
|
|
1445
1492
|
messageIndex + 1,
|
|
1446
1493
|
0,
|
|
1447
|
-
new
|
|
1494
|
+
new import_runtime_client_gql6.ResultMessage({
|
|
1448
1495
|
id: "result-" + message.id,
|
|
1449
|
-
result:
|
|
1496
|
+
result: import_runtime_client_gql6.ResultMessage.encodeResult(
|
|
1450
1497
|
error ? {
|
|
1451
1498
|
content: result,
|
|
1452
1499
|
error: JSON.parse(
|
|
@@ -1603,7 +1650,9 @@ function useCopilotChat(_a = {}) {
|
|
|
1603
1650
|
setThreadId,
|
|
1604
1651
|
runId,
|
|
1605
1652
|
setRunId,
|
|
1606
|
-
chatAbortControllerRef
|
|
1653
|
+
chatAbortControllerRef,
|
|
1654
|
+
extensions,
|
|
1655
|
+
setExtensions
|
|
1607
1656
|
} = useCopilotContext();
|
|
1608
1657
|
const { messages, setMessages } = useCopilotMessagesContext();
|
|
1609
1658
|
const latestGetContextString = useUpdatedRef(getContextString);
|
|
@@ -1616,9 +1665,9 @@ function useCopilotChat(_a = {}) {
|
|
|
1616
1665
|
const makeSystemMessageCallback = (0, import_react12.useCallback)(() => {
|
|
1617
1666
|
const systemMessageMaker = makeSystemMessage2 || defaultSystemMessage;
|
|
1618
1667
|
const contextString = latestGetContextString.current([], defaultCopilotContextCategories);
|
|
1619
|
-
return new
|
|
1668
|
+
return new import_runtime_client_gql7.TextMessage({
|
|
1620
1669
|
content: systemMessageMaker(contextString, chatInstructions),
|
|
1621
|
-
role:
|
|
1670
|
+
role: import_runtime_client_gql7.Role.System
|
|
1622
1671
|
});
|
|
1623
1672
|
}, [getContextString, makeSystemMessage2, chatInstructions]);
|
|
1624
1673
|
const onCoAgentStateRender = useAsyncCallback(
|
|
@@ -1660,7 +1709,9 @@ function useCopilotChat(_a = {}) {
|
|
|
1660
1709
|
runId,
|
|
1661
1710
|
setRunId,
|
|
1662
1711
|
chatAbortControllerRef,
|
|
1663
|
-
agentLock
|
|
1712
|
+
agentLock,
|
|
1713
|
+
extensions,
|
|
1714
|
+
setExtensions
|
|
1664
1715
|
}));
|
|
1665
1716
|
const latestAppend = useUpdatedRef(append);
|
|
1666
1717
|
const latestAppendFunc = useAsyncCallback(
|
|
@@ -1698,7 +1749,6 @@ function useCopilotChat(_a = {}) {
|
|
|
1698
1749
|
const reset = (0, import_react12.useCallback)(() => {
|
|
1699
1750
|
latestStopFunc();
|
|
1700
1751
|
setMessages([]);
|
|
1701
|
-
setThreadId(null);
|
|
1702
1752
|
setRunId(null);
|
|
1703
1753
|
setCoagentStatesWithRef({});
|
|
1704
1754
|
let initialAgentSession = null;
|
|
@@ -1965,7 +2015,7 @@ function useCoAgent(options) {
|
|
|
1965
2015
|
};
|
|
1966
2016
|
const messagesContext = useCopilotMessagesContext();
|
|
1967
2017
|
const context = __spreadValues(__spreadValues({}, generalContext), messagesContext);
|
|
1968
|
-
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef } = context;
|
|
2018
|
+
const { coagentStates, coagentStatesRef, setCoagentStatesWithRef, threadId, copilotApiConfig } = context;
|
|
1969
2019
|
const { appendMessage, runChatCompletion } = useCopilotChat();
|
|
1970
2020
|
const getCoagentState = (coagentStates2, name2) => {
|
|
1971
2021
|
if (coagentStates2[name2]) {
|
|
@@ -1982,6 +2032,11 @@ function useCoAgent(options) {
|
|
|
1982
2032
|
};
|
|
1983
2033
|
}
|
|
1984
2034
|
};
|
|
2035
|
+
const runtimeClient = useCopilotRuntimeClient({
|
|
2036
|
+
url: copilotApiConfig.chatApiEndpoint,
|
|
2037
|
+
publicApiKey: copilotApiConfig.publicApiKey,
|
|
2038
|
+
credentials: copilotApiConfig.credentials
|
|
2039
|
+
});
|
|
1985
2040
|
const setState = (newState) => {
|
|
1986
2041
|
let coagentState2 = getCoagentState(coagentStatesRef.current || {}, name);
|
|
1987
2042
|
const updatedState = typeof newState === "function" ? newState(coagentState2.state) : newState;
|
|
@@ -1991,8 +2046,21 @@ function useCoAgent(options) {
|
|
|
1991
2046
|
})
|
|
1992
2047
|
}));
|
|
1993
2048
|
};
|
|
2049
|
+
(0, import_react17.useEffect)(() => {
|
|
2050
|
+
const fetchAgentState = () => __async(this, null, function* () {
|
|
2051
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
2052
|
+
const result = yield runtimeClient.loadAgentState({
|
|
2053
|
+
threadId,
|
|
2054
|
+
agentName: name
|
|
2055
|
+
});
|
|
2056
|
+
if (((_b = (_a = result.data) == null ? void 0 : _a.loadAgentState) == null ? void 0 : _b.threadExists) && ((_d = (_c = result.data) == null ? void 0 : _c.loadAgentState) == null ? void 0 : _d.state) && ((_f = (_e = result.data) == null ? void 0 : _e.loadAgentState) == null ? void 0 : _f.state) != "{}") {
|
|
2057
|
+
const fetchedState = JSON.parse((_h = (_g = result.data) == null ? void 0 : _g.loadAgentState) == null ? void 0 : _h.state);
|
|
2058
|
+
isExternalStateManagement(options) ? options.setState(fetchedState) : setState(fetchedState);
|
|
2059
|
+
}
|
|
2060
|
+
});
|
|
2061
|
+
void fetchAgentState();
|
|
2062
|
+
}, [threadId]);
|
|
1994
2063
|
const coagentState = getCoagentState(coagentStates, name);
|
|
1995
|
-
const state = isExternalStateManagement(options) ? options.state : coagentState.state;
|
|
1996
2064
|
(0, import_react17.useEffect)(() => {
|
|
1997
2065
|
if (isExternalStateManagement(options)) {
|
|
1998
2066
|
setState(options.state);
|
|
@@ -2122,7 +2190,7 @@ function useCopilotAuthenticatedAction(action, dependencies) {
|
|
|
2122
2190
|
}
|
|
2123
2191
|
|
|
2124
2192
|
// src/lib/copilot-task.ts
|
|
2125
|
-
var
|
|
2193
|
+
var import_runtime_client_gql8 = require("@copilotkit/runtime-client-gql");
|
|
2126
2194
|
var CopilotTask = class {
|
|
2127
2195
|
constructor(config) {
|
|
2128
2196
|
this.instructions = config.instructions;
|
|
@@ -2150,12 +2218,12 @@ var CopilotTask = class {
|
|
|
2150
2218
|
if (this.includeCopilotReadable) {
|
|
2151
2219
|
contextString += context.getContextString([], defaultCopilotContextCategories);
|
|
2152
2220
|
}
|
|
2153
|
-
const systemMessage = new
|
|
2221
|
+
const systemMessage = new import_runtime_client_gql8.TextMessage({
|
|
2154
2222
|
content: taskSystemMessage(contextString, this.instructions),
|
|
2155
|
-
role:
|
|
2223
|
+
role: import_runtime_client_gql8.Role.System
|
|
2156
2224
|
});
|
|
2157
2225
|
const messages = [systemMessage];
|
|
2158
|
-
const runtimeClient = new
|
|
2226
|
+
const runtimeClient = new import_runtime_client_gql8.CopilotRuntimeClient({
|
|
2159
2227
|
url: context.copilotApiConfig.chatApiEndpoint,
|
|
2160
2228
|
publicApiKey: context.copilotApiConfig.publicApiKey,
|
|
2161
2229
|
headers: context.copilotApiConfig.headers,
|
|
@@ -2167,9 +2235,9 @@ var CopilotTask = class {
|
|
|
2167
2235
|
actions: processActionsForRuntimeRequest(Object.values(actions)),
|
|
2168
2236
|
url: window.location.href
|
|
2169
2237
|
},
|
|
2170
|
-
messages: (0,
|
|
2238
|
+
messages: (0, import_runtime_client_gql8.convertMessagesToGqlInput)((0, import_runtime_client_gql8.filterAgentStateMessages)(messages)),
|
|
2171
2239
|
metadata: {
|
|
2172
|
-
requestType:
|
|
2240
|
+
requestType: import_runtime_client_gql8.CopilotRequestType.Task
|
|
2173
2241
|
},
|
|
2174
2242
|
forwardedParameters: __spreadProps(__spreadValues({}, (_a = this.forwardedParameters) != null ? _a : {}), {
|
|
2175
2243
|
toolChoice: "required"
|
|
@@ -2178,7 +2246,7 @@ var CopilotTask = class {
|
|
|
2178
2246
|
properties: context.copilotApiConfig.properties
|
|
2179
2247
|
}).toPromise();
|
|
2180
2248
|
const functionCallHandler = context.getFunctionCallHandler(actions);
|
|
2181
|
-
const functionCalls = (0,
|
|
2249
|
+
const functionCalls = (0, import_runtime_client_gql8.convertGqlOutputToMessages)(
|
|
2182
2250
|
((_c = (_b = response.data) == null ? void 0 : _b.generateCopilotResponse) == null ? void 0 : _c.messages) || []
|
|
2183
2251
|
).filter((m) => m.isActionExecutionMessage());
|
|
2184
2252
|
for (const functionCall of functionCalls) {
|