@copilotkit/runtime 1.5.0-tyler-reset-chat.0 → 1.5.0
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 +141 -3
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-K67A6XOJ.mjs → chunk-25G6SHWM.mjs} +458 -331
- package/dist/chunk-25G6SHWM.mjs.map +1 -0
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-ZBG4KJW5.mjs → chunk-AFKLCW76.mjs} +2 -2
- package/dist/{chunk-AGSBOD2T.mjs → chunk-D6J2N5ZQ.mjs} +2 -2
- package/dist/{chunk-QNQ6UT3D.mjs → chunk-PIUHAIBR.mjs} +2 -2
- package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-2e46a7b6.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +2 -1
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-7bf6824b.d.ts} +1 -1
- package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.js +832 -480
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +15 -11
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-f021ab9c.d.ts → langserve-f318db89.d.ts} +53 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +737 -459
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/index.mjs +7 -7
- package/dist/lib/integrations/index.d.ts +4 -4
- package/dist/lib/integrations/index.js +71 -30
- package/dist/lib/integrations/index.js.map +1 -1
- package/dist/lib/integrations/index.mjs +6 -6
- package/dist/lib/integrations/nest/index.d.ts +3 -3
- package/dist/lib/integrations/nest/index.js +71 -30
- package/dist/lib/integrations/nest/index.js.map +1 -1
- package/dist/lib/integrations/nest/index.mjs +4 -4
- package/dist/lib/integrations/node-express/index.d.ts +3 -3
- package/dist/lib/integrations/node-express/index.js +71 -30
- package/dist/lib/integrations/node-express/index.js.map +1 -1
- package/dist/lib/integrations/node-express/index.mjs +4 -4
- package/dist/lib/integrations/node-http/index.d.ts +3 -3
- package/dist/lib/integrations/node-http/index.js +71 -30
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +36 -5
- package/dist/service-adapters/index.js +285 -61
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +4 -4
- package/src/agents/langgraph/event-source.ts +140 -148
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/message.input.ts +15 -3
- package/src/graphql/resolvers/copilot.resolver.ts +32 -6
- package/src/graphql/types/converted/index.ts +4 -3
- package/src/graphql/types/copilot-response.type.ts +12 -3
- package/src/graphql/types/enums.ts +0 -11
- package/src/lib/runtime/copilot-runtime.ts +1 -7
- package/src/lib/runtime/remote-action-constructors.ts +64 -58
- package/src/lib/runtime/remote-actions.ts +1 -0
- package/src/lib/runtime/remote-lg-action.ts +184 -154
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
- package/src/service-adapters/conversion.ts +2 -1
- package/src/service-adapters/events.ts +118 -54
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/groq/groq-adapter.ts +23 -8
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +55 -32
- package/src/service-adapters/openai/openai-adapter.ts +22 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-K67A6XOJ.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-ZBG4KJW5.mjs.map → chunk-AFKLCW76.mjs.map} +0 -0
- /package/dist/{chunk-AGSBOD2T.mjs.map → chunk-D6J2N5ZQ.mjs.map} +0 -0
- /package/dist/{chunk-QNQ6UT3D.mjs.map → chunk-PIUHAIBR.mjs.map} +0 -0
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RemoteChain,
|
|
3
|
-
streamLangChainResponse
|
|
4
|
-
} from "./chunk-OKQVDDJ2.mjs";
|
|
5
1
|
import {
|
|
6
2
|
GuardrailsValidationFailureResponse,
|
|
7
3
|
MessageStreamInterruptedResponse,
|
|
@@ -9,12 +5,16 @@ import {
|
|
|
9
5
|
SuccessResponseStatus,
|
|
10
6
|
UnknownErrorResponse
|
|
11
7
|
} from "./chunk-U3V2BCGI.mjs";
|
|
8
|
+
import {
|
|
9
|
+
RemoteChain,
|
|
10
|
+
streamLangChainResponse
|
|
11
|
+
} from "./chunk-4AYRDPWK.mjs";
|
|
12
12
|
import {
|
|
13
13
|
ActionExecutionMessage,
|
|
14
14
|
AgentStateMessage,
|
|
15
15
|
ResultMessage,
|
|
16
16
|
TextMessage
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-RFF5IIZJ.mjs";
|
|
18
18
|
import {
|
|
19
19
|
BaseMessageInput
|
|
20
20
|
} from "./chunk-D2WLFQS6.mjs";
|
|
@@ -37,7 +37,7 @@ var require_package = __commonJS({
|
|
|
37
37
|
publishConfig: {
|
|
38
38
|
access: "public"
|
|
39
39
|
},
|
|
40
|
-
version: "1.5.0
|
|
40
|
+
version: "1.5.0",
|
|
41
41
|
sideEffects: false,
|
|
42
42
|
main: "./dist/index.js",
|
|
43
43
|
module: "./dist/index.mjs",
|
|
@@ -122,7 +122,7 @@ import { buildSchemaSync } from "type-graphql";
|
|
|
122
122
|
|
|
123
123
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
124
124
|
import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
|
|
125
|
-
import { ReplaySubject as ReplaySubject3, Subject, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
|
|
125
|
+
import { ReplaySubject as ReplaySubject3, Subject, filter, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
|
|
126
126
|
|
|
127
127
|
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
128
128
|
import { Field as Field9, InputType as InputType9 } from "type-graphql";
|
|
@@ -139,12 +139,6 @@ var MessageRole;
|
|
|
139
139
|
MessageRole2["system"] = "system";
|
|
140
140
|
MessageRole2["tool"] = "tool";
|
|
141
141
|
})(MessageRole || (MessageRole = {}));
|
|
142
|
-
var ActionExecutionScope;
|
|
143
|
-
(function(ActionExecutionScope2) {
|
|
144
|
-
ActionExecutionScope2["server"] = "server";
|
|
145
|
-
ActionExecutionScope2["client"] = "client";
|
|
146
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
147
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
148
142
|
var CopilotRequestType;
|
|
149
143
|
(function(CopilotRequestType2) {
|
|
150
144
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -163,10 +157,6 @@ registerEnumType(MessageRole, {
|
|
|
163
157
|
name: "MessageRole",
|
|
164
158
|
description: "The role of the message"
|
|
165
159
|
});
|
|
166
|
-
registerEnumType(ActionExecutionScope, {
|
|
167
|
-
name: "ActionExecutionScope",
|
|
168
|
-
description: "The scope of the action"
|
|
169
|
-
});
|
|
170
160
|
registerEnumType(CopilotRequestType, {
|
|
171
161
|
name: "CopilotRequestType",
|
|
172
162
|
description: "The type of Copilot request"
|
|
@@ -229,6 +219,7 @@ MessageInput = _ts_decorate([
|
|
|
229
219
|
], MessageInput);
|
|
230
220
|
var TextMessageInput = class {
|
|
231
221
|
content;
|
|
222
|
+
parentMessageId;
|
|
232
223
|
role;
|
|
233
224
|
};
|
|
234
225
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -236,6 +227,12 @@ _ts_decorate([
|
|
|
236
227
|
Field(() => String),
|
|
237
228
|
_ts_metadata("design:type", String)
|
|
238
229
|
], TextMessageInput.prototype, "content", void 0);
|
|
230
|
+
_ts_decorate([
|
|
231
|
+
Field(() => String, {
|
|
232
|
+
nullable: true
|
|
233
|
+
}),
|
|
234
|
+
_ts_metadata("design:type", String)
|
|
235
|
+
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
239
236
|
_ts_decorate([
|
|
240
237
|
Field(() => MessageRole),
|
|
241
238
|
_ts_metadata("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -246,6 +243,7 @@ TextMessageInput = _ts_decorate([
|
|
|
246
243
|
var ActionExecutionMessageInput = class {
|
|
247
244
|
name;
|
|
248
245
|
arguments;
|
|
246
|
+
parentMessageId;
|
|
249
247
|
scope;
|
|
250
248
|
};
|
|
251
249
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -258,8 +256,17 @@ _ts_decorate([
|
|
|
258
256
|
_ts_metadata("design:type", String)
|
|
259
257
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
260
258
|
_ts_decorate([
|
|
261
|
-
Field(() =>
|
|
262
|
-
|
|
259
|
+
Field(() => String, {
|
|
260
|
+
nullable: true
|
|
261
|
+
}),
|
|
262
|
+
_ts_metadata("design:type", String)
|
|
263
|
+
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
264
|
+
_ts_decorate([
|
|
265
|
+
Field(() => String, {
|
|
266
|
+
nullable: true,
|
|
267
|
+
deprecationReason: "This field will be removed in a future version"
|
|
268
|
+
}),
|
|
269
|
+
_ts_metadata("design:type", typeof String === "undefined" ? Object : String)
|
|
263
270
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
264
271
|
ActionExecutionMessageInput = _ts_decorate([
|
|
265
272
|
InputType()
|
|
@@ -267,6 +274,7 @@ ActionExecutionMessageInput = _ts_decorate([
|
|
|
267
274
|
var ResultMessageInput = class {
|
|
268
275
|
actionExecutionId;
|
|
269
276
|
actionName;
|
|
277
|
+
parentMessageId;
|
|
270
278
|
result;
|
|
271
279
|
};
|
|
272
280
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -278,6 +286,12 @@ _ts_decorate([
|
|
|
278
286
|
Field(() => String),
|
|
279
287
|
_ts_metadata("design:type", String)
|
|
280
288
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
289
|
+
_ts_decorate([
|
|
290
|
+
Field(() => String, {
|
|
291
|
+
nullable: true
|
|
292
|
+
}),
|
|
293
|
+
_ts_metadata("design:type", String)
|
|
294
|
+
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
281
295
|
_ts_decorate([
|
|
282
296
|
Field(() => String),
|
|
283
297
|
_ts_metadata("design:type", String)
|
|
@@ -893,6 +907,7 @@ BaseMessageOutput = _ts_decorate11([
|
|
|
893
907
|
var TextMessageOutput = class {
|
|
894
908
|
role;
|
|
895
909
|
content;
|
|
910
|
+
parentMessageId;
|
|
896
911
|
};
|
|
897
912
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
898
913
|
_ts_decorate11([
|
|
@@ -905,6 +920,12 @@ _ts_decorate11([
|
|
|
905
920
|
]),
|
|
906
921
|
_ts_metadata11("design:type", Array)
|
|
907
922
|
], TextMessageOutput.prototype, "content", void 0);
|
|
923
|
+
_ts_decorate11([
|
|
924
|
+
Field11(() => String, {
|
|
925
|
+
nullable: true
|
|
926
|
+
}),
|
|
927
|
+
_ts_metadata11("design:type", String)
|
|
928
|
+
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
908
929
|
TextMessageOutput = _ts_decorate11([
|
|
909
930
|
ObjectType2({
|
|
910
931
|
implements: BaseMessageOutput
|
|
@@ -914,6 +935,7 @@ var ActionExecutionMessageOutput = class {
|
|
|
914
935
|
name;
|
|
915
936
|
scope;
|
|
916
937
|
arguments;
|
|
938
|
+
parentMessageId;
|
|
917
939
|
};
|
|
918
940
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
919
941
|
_ts_decorate11([
|
|
@@ -921,8 +943,11 @@ _ts_decorate11([
|
|
|
921
943
|
_ts_metadata11("design:type", String)
|
|
922
944
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
923
945
|
_ts_decorate11([
|
|
924
|
-
Field11(() =>
|
|
925
|
-
|
|
946
|
+
Field11(() => String, {
|
|
947
|
+
nullable: true,
|
|
948
|
+
deprecationReason: "This field will be removed in a future version"
|
|
949
|
+
}),
|
|
950
|
+
_ts_metadata11("design:type", String)
|
|
926
951
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
927
952
|
_ts_decorate11([
|
|
928
953
|
Field11(() => [
|
|
@@ -930,6 +955,12 @@ _ts_decorate11([
|
|
|
930
955
|
]),
|
|
931
956
|
_ts_metadata11("design:type", Array)
|
|
932
957
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
958
|
+
_ts_decorate11([
|
|
959
|
+
Field11(() => String, {
|
|
960
|
+
nullable: true
|
|
961
|
+
}),
|
|
962
|
+
_ts_metadata11("design:type", String)
|
|
963
|
+
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
933
964
|
ActionExecutionMessageOutput = _ts_decorate11([
|
|
934
965
|
ObjectType2({
|
|
935
966
|
implements: BaseMessageOutput
|
|
@@ -1041,8 +1072,8 @@ CopilotResponse = _ts_decorate11([
|
|
|
1041
1072
|
import { Repeater } from "graphql-yoga";
|
|
1042
1073
|
|
|
1043
1074
|
// src/service-adapters/events.ts
|
|
1044
|
-
import { randomId as
|
|
1045
|
-
import { of, concat,
|
|
1075
|
+
import { randomId as randomId2 } from "@copilotkit/shared";
|
|
1076
|
+
import { of, concat, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
|
|
1046
1077
|
|
|
1047
1078
|
// src/lib/telemetry-client.ts
|
|
1048
1079
|
import { TelemetryClient } from "@copilotkit/shared";
|
|
@@ -1090,163 +1121,167 @@ var RemoteLangGraphEventSource = class {
|
|
|
1090
1121
|
}
|
|
1091
1122
|
return shouldEmitToolCalls === toolCallName;
|
|
1092
1123
|
}
|
|
1124
|
+
getCurrentContent(event) {
|
|
1125
|
+
var _a, _b, _c, _d, _e;
|
|
1126
|
+
const content = ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.content) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.content);
|
|
1127
|
+
if (!content) {
|
|
1128
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1129
|
+
for (const chunk of toolCallChunks) {
|
|
1130
|
+
if (chunk.args) {
|
|
1131
|
+
return chunk.args;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
if (typeof content === "string") {
|
|
1136
|
+
return content;
|
|
1137
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1138
|
+
return content[0].text;
|
|
1139
|
+
}
|
|
1140
|
+
return null;
|
|
1141
|
+
}
|
|
1142
|
+
getCurrentMessageId(event) {
|
|
1143
|
+
var _a, _b, _c, _d, _e;
|
|
1144
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.id) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.id);
|
|
1145
|
+
}
|
|
1146
|
+
getCurrentToolCallChunks(event) {
|
|
1147
|
+
var _a, _b, _c, _d, _e;
|
|
1148
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.tool_call_chunks);
|
|
1149
|
+
}
|
|
1150
|
+
getResponseMetadata(event) {
|
|
1151
|
+
var _a, _b, _c, _d, _e;
|
|
1152
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.response_metadata) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.response_metadata);
|
|
1153
|
+
}
|
|
1093
1154
|
processLangGraphEvents() {
|
|
1094
1155
|
let lastEventWithState = null;
|
|
1095
1156
|
return this.eventStream$.pipe(scan((acc, event) => {
|
|
1096
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1097
1157
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1113
|
-
acc.toolCallMessageId = toolCallMessageId;
|
|
1114
|
-
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1115
|
-
acc.toolCallName = toolCallChunks[0].name;
|
|
1116
|
-
}
|
|
1117
|
-
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1118
|
-
acc.toolCallId = toolCallChunks[0].id;
|
|
1119
|
-
}
|
|
1120
|
-
acc.prevMessageId = acc.messageId;
|
|
1121
|
-
acc.messageId = toolCallMessageId;
|
|
1122
|
-
} else if (acc.content && acc.content != "") {
|
|
1123
|
-
acc.prevMessageId = acc.messageId;
|
|
1124
|
-
acc.messageId = toolCallMessageId;
|
|
1125
|
-
} else {
|
|
1126
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1127
|
-
acc.prevMessageId = acc.messageId;
|
|
1128
|
-
}
|
|
1129
|
-
} else {
|
|
1130
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1131
|
-
acc.toolCallMessageId = null;
|
|
1132
|
-
acc.prevMessageId = acc.messageId;
|
|
1133
|
-
acc.messageId = null;
|
|
1134
|
-
acc.toolCallName = null;
|
|
1158
|
+
const prevMessageId = acc.lastMessageId;
|
|
1159
|
+
acc.currentContent = this.getCurrentContent(event);
|
|
1160
|
+
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
1161
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1162
|
+
const responseMetadata = this.getResponseMetadata(event);
|
|
1163
|
+
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1164
|
+
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1165
|
+
acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
|
|
1166
|
+
acc.isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1167
|
+
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1168
|
+
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
1169
|
+
name: acc.lastToolCallName,
|
|
1170
|
+
id: acc.lastToolCallId
|
|
1171
|
+
});
|
|
1135
1172
|
}
|
|
1136
1173
|
acc.event = event;
|
|
1137
1174
|
lastEventWithState = acc;
|
|
1138
1175
|
return acc;
|
|
1139
1176
|
}, {
|
|
1140
1177
|
event: null,
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1178
|
+
isMessageStart: false,
|
|
1179
|
+
isMessageEnd: false,
|
|
1180
|
+
isToolCallStart: false,
|
|
1181
|
+
isToolCallEnd: false,
|
|
1182
|
+
isToolCall: false,
|
|
1183
|
+
lastMessageId: null,
|
|
1184
|
+
lastToolCallId: null,
|
|
1185
|
+
lastToolCallName: null,
|
|
1186
|
+
currentContent: null
|
|
1187
|
+
}), mergeMap((acc) => {
|
|
1150
1188
|
const events = [];
|
|
1151
1189
|
let shouldEmitMessages = true;
|
|
1152
|
-
let shouldEmitToolCalls =
|
|
1153
|
-
if (
|
|
1154
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1155
|
-
shouldEmitToolCalls =
|
|
1190
|
+
let shouldEmitToolCalls = true;
|
|
1191
|
+
if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1192
|
+
if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
|
|
1193
|
+
shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
|
|
1156
1194
|
}
|
|
1157
|
-
if ("copilotkit:emit-messages" in (
|
|
1158
|
-
shouldEmitMessages =
|
|
1195
|
+
if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
|
|
1196
|
+
shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
|
|
1159
1197
|
}
|
|
1160
1198
|
}
|
|
1161
|
-
|
|
1199
|
+
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1200
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1162
1201
|
events.push({
|
|
1163
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1202
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1203
|
+
actionExecutionId: acc.lastToolCallId
|
|
1164
1204
|
});
|
|
1165
1205
|
}
|
|
1166
|
-
if (
|
|
1206
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1167
1207
|
events.push({
|
|
1168
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1208
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1209
|
+
messageId: acc.lastMessageId
|
|
1169
1210
|
});
|
|
1170
1211
|
}
|
|
1171
|
-
switch (
|
|
1212
|
+
switch (acc.event.event) {
|
|
1172
1213
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1173
|
-
if (
|
|
1214
|
+
if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1174
1215
|
events.push({
|
|
1175
1216
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1176
|
-
messageId:
|
|
1217
|
+
messageId: acc.event.data.message_id
|
|
1177
1218
|
});
|
|
1178
1219
|
events.push({
|
|
1179
1220
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1180
|
-
|
|
1221
|
+
messageId: acc.event.data.message_id,
|
|
1222
|
+
content: acc.event.data.message
|
|
1181
1223
|
});
|
|
1182
1224
|
events.push({
|
|
1183
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1225
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1226
|
+
messageId: acc.event.data.message_id
|
|
1184
1227
|
});
|
|
1185
|
-
} else if (
|
|
1228
|
+
} else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1186
1229
|
events.push({
|
|
1187
1230
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1188
|
-
actionExecutionId:
|
|
1189
|
-
actionName:
|
|
1231
|
+
actionExecutionId: acc.event.data.id,
|
|
1232
|
+
actionName: acc.event.data.name,
|
|
1233
|
+
parentMessageId: acc.event.data.id
|
|
1190
1234
|
});
|
|
1191
1235
|
events.push({
|
|
1192
1236
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1193
|
-
|
|
1237
|
+
actionExecutionId: acc.event.data.id,
|
|
1238
|
+
args: JSON.stringify(acc.event.data.args)
|
|
1194
1239
|
});
|
|
1195
1240
|
events.push({
|
|
1196
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1241
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1242
|
+
actionExecutionId: acc.event.data.id
|
|
1197
1243
|
});
|
|
1198
1244
|
}
|
|
1199
1245
|
break;
|
|
1200
1246
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1201
1247
|
events.push({
|
|
1202
1248
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1203
|
-
threadId:
|
|
1204
|
-
role:
|
|
1205
|
-
agentName:
|
|
1206
|
-
nodeName:
|
|
1207
|
-
runId:
|
|
1208
|
-
active:
|
|
1209
|
-
state: JSON.stringify(
|
|
1210
|
-
running:
|
|
1249
|
+
threadId: acc.event.thread_id,
|
|
1250
|
+
role: acc.event.role,
|
|
1251
|
+
agentName: acc.event.agent_name,
|
|
1252
|
+
nodeName: acc.event.node_name,
|
|
1253
|
+
runId: acc.event.run_id,
|
|
1254
|
+
active: acc.event.active,
|
|
1255
|
+
state: JSON.stringify(acc.event.state),
|
|
1256
|
+
running: acc.event.running
|
|
1211
1257
|
});
|
|
1212
1258
|
break;
|
|
1213
|
-
case LangGraphEventTypes.OnToolEnd:
|
|
1214
|
-
break;
|
|
1215
1259
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1216
|
-
if (
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
type: RuntimeEventTypes.TextMessageStart,
|
|
1229
|
-
messageId: eventWithState.messageId
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1260
|
+
if (acc.isToolCallStart && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1261
|
+
events.push({
|
|
1262
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1263
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1264
|
+
actionName: acc.lastToolCallName,
|
|
1265
|
+
parentMessageId: acc.lastMessageId
|
|
1266
|
+
});
|
|
1267
|
+
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1268
|
+
events.push({
|
|
1269
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1270
|
+
messageId: acc.lastMessageId
|
|
1271
|
+
});
|
|
1232
1272
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
events.push({
|
|
1246
|
-
type: RuntimeEventTypes.TextMessageContent,
|
|
1247
|
-
content
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1273
|
+
if (acc.isToolCall && acc.currentContent && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1274
|
+
events.push({
|
|
1275
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1276
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1277
|
+
args: acc.currentContent
|
|
1278
|
+
});
|
|
1279
|
+
} else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
|
|
1280
|
+
events.push({
|
|
1281
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1282
|
+
messageId: acc.lastMessageId,
|
|
1283
|
+
content: acc.currentContent
|
|
1284
|
+
});
|
|
1250
1285
|
}
|
|
1251
1286
|
break;
|
|
1252
1287
|
}
|
|
@@ -1254,14 +1289,16 @@ var RemoteLangGraphEventSource = class {
|
|
|
1254
1289
|
}), catchError((error) => {
|
|
1255
1290
|
console.error(error);
|
|
1256
1291
|
const events = [];
|
|
1257
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1292
|
+
if ((lastEventWithState == null ? void 0 : lastEventWithState.lastMessageId) && !lastEventWithState.isToolCall) {
|
|
1258
1293
|
events.push({
|
|
1259
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1294
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1295
|
+
messageId: lastEventWithState.lastMessageId
|
|
1260
1296
|
});
|
|
1261
1297
|
}
|
|
1262
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1298
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.lastToolCallId) {
|
|
1263
1299
|
events.push({
|
|
1264
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1300
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1301
|
+
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1265
1302
|
});
|
|
1266
1303
|
}
|
|
1267
1304
|
const messageId = randomId();
|
|
@@ -1271,10 +1308,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1271
1308
|
});
|
|
1272
1309
|
events.push({
|
|
1273
1310
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1311
|
+
messageId,
|
|
1274
1312
|
content: "\u274C An error occurred. Please try again."
|
|
1275
1313
|
});
|
|
1276
1314
|
events.push({
|
|
1277
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1315
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1316
|
+
messageId
|
|
1278
1317
|
});
|
|
1279
1318
|
return events;
|
|
1280
1319
|
}));
|
|
@@ -1313,8 +1352,6 @@ async function streamEvents(controller, args) {
|
|
|
1313
1352
|
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1314
1353
|
initialThreadId = initialThreadId.substring(3);
|
|
1315
1354
|
}
|
|
1316
|
-
const assistants = await client.assistants.search();
|
|
1317
|
-
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1318
1355
|
const threadId = initialThreadId ?? randomUUID();
|
|
1319
1356
|
if (initialThreadId === threadId) {
|
|
1320
1357
|
await client.threads.get(threadId);
|
|
@@ -1334,7 +1371,7 @@ async function streamEvents(controller, args) {
|
|
|
1334
1371
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1335
1372
|
let formattedMessages = [];
|
|
1336
1373
|
try {
|
|
1337
|
-
formattedMessages =
|
|
1374
|
+
formattedMessages = copilotkitMessagesToLangChain(messages);
|
|
1338
1375
|
} catch (e) {
|
|
1339
1376
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1340
1377
|
}
|
|
@@ -1345,8 +1382,16 @@ async function streamEvents(controller, args) {
|
|
|
1345
1382
|
asNode: nodeName
|
|
1346
1383
|
});
|
|
1347
1384
|
}
|
|
1348
|
-
|
|
1349
|
-
|
|
1385
|
+
let streamInfo = {
|
|
1386
|
+
hashedLgcKey: createHash("sha256").update(langsmithApiKey).digest("hex")
|
|
1387
|
+
};
|
|
1388
|
+
const assistants = await client.assistants.search();
|
|
1389
|
+
const retrievedAssistant = assistants.find((a) => a.name === name || a.assistant_id === initialAssistantId);
|
|
1390
|
+
if (!retrievedAssistant) {
|
|
1391
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1392
|
+
...streamInfo,
|
|
1393
|
+
error: `Found no assistants for given information, while ${assistants.length} assistants exists`
|
|
1394
|
+
});
|
|
1350
1395
|
console.error(`
|
|
1351
1396
|
No agent found for the agent name specified in CopilotKit provider
|
|
1352
1397
|
Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
|
|
@@ -1356,6 +1401,7 @@ async function streamEvents(controller, args) {
|
|
|
1356
1401
|
`);
|
|
1357
1402
|
throw new Error("No agent id found");
|
|
1358
1403
|
}
|
|
1404
|
+
const assistantId = retrievedAssistant.assistant_id;
|
|
1359
1405
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1360
1406
|
const streamInput = mode === "start" ? state : null;
|
|
1361
1407
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
@@ -1374,9 +1420,6 @@ async function streamEvents(controller, args) {
|
|
|
1374
1420
|
let latestStateValues = {};
|
|
1375
1421
|
let updatedState = state;
|
|
1376
1422
|
let manuallyEmittedState = null;
|
|
1377
|
-
let streamInfo = {
|
|
1378
|
-
hashedLgcKey: createHash("sha256").update(langsmithApiKey).digest("hex")
|
|
1379
|
-
};
|
|
1380
1423
|
try {
|
|
1381
1424
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1382
1425
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
@@ -1389,7 +1432,6 @@ async function streamEvents(controller, args) {
|
|
|
1389
1432
|
].includes(chunk.event))
|
|
1390
1433
|
continue;
|
|
1391
1434
|
if (chunk.event === "error") {
|
|
1392
|
-
logger2.error(chunk, `Error event thrown: ${chunk.data.message}`);
|
|
1393
1435
|
throw new Error(`Error event thrown: ${chunk.data.message}`);
|
|
1394
1436
|
}
|
|
1395
1437
|
if (chunk.event === "values") {
|
|
@@ -1482,21 +1524,34 @@ async function streamEvents(controller, args) {
|
|
|
1482
1524
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1483
1525
|
state: state.values,
|
|
1484
1526
|
running: !shouldExit,
|
|
1485
|
-
active: false
|
|
1527
|
+
active: false,
|
|
1528
|
+
includeMessages: true
|
|
1486
1529
|
}));
|
|
1487
1530
|
return Promise.resolve();
|
|
1488
1531
|
} catch (e) {
|
|
1532
|
+
logger2.error(e);
|
|
1533
|
+
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1534
|
+
...streamInfo,
|
|
1535
|
+
error: e.message
|
|
1536
|
+
});
|
|
1489
1537
|
return Promise.resolve();
|
|
1490
1538
|
}
|
|
1491
1539
|
}
|
|
1492
1540
|
__name(streamEvents, "streamEvents");
|
|
1493
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1541
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
|
|
1542
|
+
if (!includeMessages) {
|
|
1543
|
+
state = Object.keys(state).reduce((acc, key) => {
|
|
1544
|
+
if (key !== "messages") {
|
|
1545
|
+
acc[key] = state[key];
|
|
1546
|
+
}
|
|
1547
|
+
return acc;
|
|
1548
|
+
}, {});
|
|
1549
|
+
} else {
|
|
1550
|
+
state = {
|
|
1551
|
+
...state,
|
|
1552
|
+
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1500
1555
|
return JSON.stringify({
|
|
1501
1556
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1502
1557
|
thread_id: threadId,
|
|
@@ -1504,7 +1559,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1504
1559
|
agent_name: agentName,
|
|
1505
1560
|
node_name: nodeName,
|
|
1506
1561
|
active,
|
|
1507
|
-
state
|
|
1562
|
+
state,
|
|
1508
1563
|
running,
|
|
1509
1564
|
role: "assistant"
|
|
1510
1565
|
}) + "\n";
|
|
@@ -1580,134 +1635,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1580
1635
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1581
1636
|
messages = messages.slice(1);
|
|
1582
1637
|
}
|
|
1583
|
-
const
|
|
1584
|
-
const existingMessageIds = new Set(
|
|
1585
|
-
const
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1638
|
+
const existingMessages = state.messages || [];
|
|
1639
|
+
const existingMessageIds = new Set(existingMessages.map((message) => message.id));
|
|
1640
|
+
const newMessages = messages.filter((message) => !existingMessageIds.has(message.id));
|
|
1641
|
+
return {
|
|
1642
|
+
...state,
|
|
1643
|
+
messages: newMessages,
|
|
1644
|
+
copilotkit: {
|
|
1645
|
+
actions
|
|
1646
|
+
}
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1650
|
+
function langchainMessagesToCopilotKit(messages) {
|
|
1651
|
+
const result = [];
|
|
1652
|
+
const tool_call_names = {};
|
|
1653
|
+
for (const message of messages) {
|
|
1654
|
+
if (message.type === "ai") {
|
|
1655
|
+
for (const tool_call of message.tool_calls) {
|
|
1656
|
+
tool_call_names[tool_call.id] = tool_call.name;
|
|
1657
|
+
}
|
|
1589
1658
|
}
|
|
1590
1659
|
}
|
|
1591
1660
|
for (const message of messages) {
|
|
1592
|
-
|
|
1593
|
-
|
|
1661
|
+
let content = message.content;
|
|
1662
|
+
if (content instanceof Array) {
|
|
1663
|
+
content = content[0];
|
|
1594
1664
|
}
|
|
1595
|
-
if (
|
|
1596
|
-
|
|
1665
|
+
if (content instanceof Object) {
|
|
1666
|
+
content = content.text;
|
|
1597
1667
|
}
|
|
1598
|
-
if (
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
} else {
|
|
1605
|
-
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1668
|
+
if (message.type === "human") {
|
|
1669
|
+
result.push({
|
|
1670
|
+
role: "user",
|
|
1671
|
+
content,
|
|
1672
|
+
id: message.id
|
|
1673
|
+
});
|
|
1674
|
+
} else if (message.type === "system") {
|
|
1675
|
+
result.push({
|
|
1676
|
+
role: "system",
|
|
1677
|
+
content,
|
|
1678
|
+
id: message.id
|
|
1679
|
+
});
|
|
1680
|
+
} else if (message.type === "ai") {
|
|
1681
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
1682
|
+
for (const tool_call of message.tool_calls) {
|
|
1683
|
+
result.push({
|
|
1684
|
+
id: tool_call.id,
|
|
1685
|
+
name: tool_call.name,
|
|
1686
|
+
arguments: tool_call.args,
|
|
1687
|
+
parentMessageId: message.id
|
|
1688
|
+
});
|
|
1612
1689
|
}
|
|
1690
|
+
} else {
|
|
1691
|
+
result.push({
|
|
1692
|
+
role: "assistant",
|
|
1693
|
+
content,
|
|
1694
|
+
id: message.id,
|
|
1695
|
+
parentMessageId: message.id
|
|
1696
|
+
});
|
|
1613
1697
|
}
|
|
1698
|
+
} else if (message.type === "tool") {
|
|
1699
|
+
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
1700
|
+
result.push({
|
|
1701
|
+
actionExecutionId: message.tool_call_id,
|
|
1702
|
+
actionName,
|
|
1703
|
+
result: content,
|
|
1704
|
+
id: message.id
|
|
1705
|
+
});
|
|
1614
1706
|
}
|
|
1615
1707
|
}
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
1708
|
+
const resultsDict = {};
|
|
1709
|
+
for (const msg of result) {
|
|
1710
|
+
if (msg.actionExecutionId) {
|
|
1711
|
+
resultsDict[msg.actionExecutionId] = msg;
|
|
1621
1712
|
}
|
|
1622
1713
|
}
|
|
1623
|
-
const
|
|
1624
|
-
for (
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
const prevMessage = mergedMessages[i - 1] || null;
|
|
1628
|
-
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
1629
|
-
if (!nextMessage) {
|
|
1630
|
-
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1631
|
-
continue;
|
|
1632
|
-
}
|
|
1633
|
-
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
1634
|
-
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
1635
|
-
if (toolMessage) {
|
|
1636
|
-
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
1637
|
-
correctedMessages.push(currentMessage, toolMessage);
|
|
1638
|
-
continue;
|
|
1639
|
-
} else {
|
|
1640
|
-
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1641
|
-
continue;
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
correctedMessages.push(currentMessage);
|
|
1645
|
-
continue;
|
|
1714
|
+
const reorderedResult = [];
|
|
1715
|
+
for (const msg of result) {
|
|
1716
|
+
if (!("actionExecutionId" in msg)) {
|
|
1717
|
+
reorderedResult.push(msg);
|
|
1646
1718
|
}
|
|
1647
|
-
if ("
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
}
|
|
1652
|
-
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
1653
|
-
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
1654
|
-
continue;
|
|
1719
|
+
if ("arguments" in msg) {
|
|
1720
|
+
const msgId = msg.id;
|
|
1721
|
+
if (msgId in resultsDict) {
|
|
1722
|
+
reorderedResult.push(resultsDict[msgId]);
|
|
1655
1723
|
}
|
|
1656
|
-
correctedMessages.push(currentMessage);
|
|
1657
|
-
continue;
|
|
1658
1724
|
}
|
|
1659
|
-
correctedMessages.push(currentMessage);
|
|
1660
1725
|
}
|
|
1661
|
-
return
|
|
1662
|
-
...state,
|
|
1663
|
-
messages: correctedMessages,
|
|
1664
|
-
copilotkit: {
|
|
1665
|
-
actions
|
|
1666
|
-
}
|
|
1667
|
-
};
|
|
1726
|
+
return reorderedResult;
|
|
1668
1727
|
}
|
|
1669
|
-
__name(
|
|
1670
|
-
function
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1728
|
+
__name(langchainMessagesToCopilotKit, "langchainMessagesToCopilotKit");
|
|
1729
|
+
function copilotkitMessagesToLangChain(messages) {
|
|
1730
|
+
const result = [];
|
|
1731
|
+
const processedActionExecutions = /* @__PURE__ */ new Set();
|
|
1732
|
+
for (const message of messages) {
|
|
1733
|
+
if (message.isTextMessage()) {
|
|
1734
|
+
if (message.role === "user") {
|
|
1735
|
+
result.push({
|
|
1736
|
+
...message,
|
|
1737
|
+
role: MessageRole.user
|
|
1738
|
+
});
|
|
1739
|
+
} else if (message.role === "system") {
|
|
1740
|
+
result.push({
|
|
1741
|
+
...message,
|
|
1742
|
+
role: MessageRole.system
|
|
1743
|
+
});
|
|
1744
|
+
} else if (message.role === "assistant") {
|
|
1745
|
+
result.push({
|
|
1746
|
+
...message,
|
|
1747
|
+
role: MessageRole.assistant
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
continue;
|
|
1680
1751
|
}
|
|
1681
1752
|
if (message.isActionExecutionMessage()) {
|
|
1682
|
-
const
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1753
|
+
const messageId = message.parentMessageId ?? message.id;
|
|
1754
|
+
if (processedActionExecutions.has(messageId)) {
|
|
1755
|
+
continue;
|
|
1756
|
+
}
|
|
1757
|
+
processedActionExecutions.add(messageId);
|
|
1758
|
+
const relatedActionExecutions = messages.filter((m) => m.isActionExecutionMessage() && (m.parentMessageId && m.parentMessageId === messageId || m.id === messageId));
|
|
1759
|
+
const tool_calls = relatedActionExecutions.map((m) => ({
|
|
1760
|
+
name: m.name,
|
|
1761
|
+
args: m.arguments,
|
|
1762
|
+
id: m.id
|
|
1763
|
+
}));
|
|
1764
|
+
result.push({
|
|
1765
|
+
id: messageId,
|
|
1766
|
+
type: "ActionExecutionMessage",
|
|
1689
1767
|
content: "",
|
|
1690
|
-
tool_calls
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
id: message.id
|
|
1695
|
-
};
|
|
1768
|
+
tool_calls,
|
|
1769
|
+
role: MessageRole.assistant
|
|
1770
|
+
});
|
|
1771
|
+
continue;
|
|
1696
1772
|
}
|
|
1697
1773
|
if (message.isResultMessage()) {
|
|
1698
|
-
|
|
1774
|
+
result.push({
|
|
1699
1775
|
type: message.type,
|
|
1700
1776
|
content: message.result,
|
|
1701
1777
|
id: message.id,
|
|
1702
1778
|
tool_call_id: message.actionExecutionId,
|
|
1703
1779
|
name: message.actionName,
|
|
1704
1780
|
role: MessageRole.tool
|
|
1705
|
-
};
|
|
1781
|
+
});
|
|
1782
|
+
continue;
|
|
1706
1783
|
}
|
|
1707
1784
|
throw new Error(`Unknown message type ${message.type}`);
|
|
1708
|
-
}
|
|
1785
|
+
}
|
|
1786
|
+
return result;
|
|
1709
1787
|
}
|
|
1710
|
-
__name(
|
|
1788
|
+
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
1711
1789
|
|
|
1712
1790
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1713
1791
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -1717,7 +1795,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1717
1795
|
parameters: [],
|
|
1718
1796
|
handler: async (_args) => {
|
|
1719
1797
|
},
|
|
1720
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1798
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1721
1799
|
var _a;
|
|
1722
1800
|
logger2.debug({
|
|
1723
1801
|
actionName: agent.name
|
|
@@ -1743,7 +1821,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1743
1821
|
agent,
|
|
1744
1822
|
threadId,
|
|
1745
1823
|
nodeName,
|
|
1746
|
-
messages
|
|
1824
|
+
messages: [
|
|
1825
|
+
...messages,
|
|
1826
|
+
...additionalMessages
|
|
1827
|
+
],
|
|
1747
1828
|
state,
|
|
1748
1829
|
properties: graphqlContext.properties,
|
|
1749
1830
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1771,6 +1852,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1771
1852
|
}
|
|
1772
1853
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1773
1854
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1855
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
1774
1856
|
const actions = json["actions"].map((action) => ({
|
|
1775
1857
|
name: action.name,
|
|
1776
1858
|
description: action.description,
|
|
@@ -1784,7 +1866,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1784
1866
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1785
1867
|
agentExecution: false,
|
|
1786
1868
|
type: "self-hosted",
|
|
1787
|
-
agentsAmount:
|
|
1869
|
+
agentsAmount: totalAgents
|
|
1788
1870
|
});
|
|
1789
1871
|
try {
|
|
1790
1872
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -1819,13 +1901,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1819
1901
|
}
|
|
1820
1902
|
}
|
|
1821
1903
|
}));
|
|
1822
|
-
const agents = json["agents"].map((agent) => ({
|
|
1904
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
1823
1905
|
name: agent.name,
|
|
1824
1906
|
description: agent.description,
|
|
1825
1907
|
parameters: [],
|
|
1826
1908
|
handler: async (_args) => {
|
|
1827
1909
|
},
|
|
1828
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1910
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1829
1911
|
var _a;
|
|
1830
1912
|
logger2.debug({
|
|
1831
1913
|
actionName: agent.name
|
|
@@ -1850,7 +1932,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1850
1932
|
name,
|
|
1851
1933
|
threadId,
|
|
1852
1934
|
nodeName,
|
|
1853
|
-
messages
|
|
1935
|
+
messages: [
|
|
1936
|
+
...messages,
|
|
1937
|
+
...additionalMessages
|
|
1938
|
+
],
|
|
1854
1939
|
state,
|
|
1855
1940
|
properties: graphqlContext.properties,
|
|
1856
1941
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1872,7 +1957,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1872
1957
|
streamResponse(response.body, eventSource.eventStream$);
|
|
1873
1958
|
return eventSource.processLangGraphEvents();
|
|
1874
1959
|
}
|
|
1875
|
-
}));
|
|
1960
|
+
})) : [];
|
|
1876
1961
|
return [
|
|
1877
1962
|
...actions,
|
|
1878
1963
|
...agents
|
|
@@ -2050,7 +2135,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2050
2135
|
import { createHash as createHash3 } from "crypto";
|
|
2051
2136
|
|
|
2052
2137
|
// src/lib/runtime/copilot-runtime.ts
|
|
2053
|
-
import { actionParametersToJsonSchema
|
|
2138
|
+
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
2054
2139
|
|
|
2055
2140
|
// src/service-adapters/conversion.ts
|
|
2056
2141
|
import { plainToInstance } from "class-transformer";
|
|
@@ -2062,7 +2147,8 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2062
2147
|
id: message.id,
|
|
2063
2148
|
createdAt: message.createdAt,
|
|
2064
2149
|
role: message.textMessage.role,
|
|
2065
|
-
content: message.textMessage.content
|
|
2150
|
+
content: message.textMessage.content,
|
|
2151
|
+
parentMessageId: message.textMessage.parentMessageId
|
|
2066
2152
|
}));
|
|
2067
2153
|
} else if (message.actionExecutionMessage) {
|
|
2068
2154
|
messages.push(plainToInstance(ActionExecutionMessage, {
|
|
@@ -2070,7 +2156,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2070
2156
|
createdAt: message.createdAt,
|
|
2071
2157
|
name: message.actionExecutionMessage.name,
|
|
2072
2158
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2073
|
-
|
|
2159
|
+
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
2074
2160
|
}));
|
|
2075
2161
|
} else if (message.resultMessage) {
|
|
2076
2162
|
messages.push(plainToInstance(ResultMessage, {
|
|
@@ -2181,13 +2267,7 @@ var CopilotRuntime = class {
|
|
|
2181
2267
|
} catch (error) {
|
|
2182
2268
|
console.error("Error getting response:", error);
|
|
2183
2269
|
eventSource.sendErrorMessageToChat();
|
|
2184
|
-
|
|
2185
|
-
threadId: threadId || randomId2(),
|
|
2186
|
-
runId: runId || randomId2(),
|
|
2187
|
-
eventSource,
|
|
2188
|
-
serverSideActions: [],
|
|
2189
|
-
actionInputsWithoutAgents: []
|
|
2190
|
-
};
|
|
2270
|
+
throw error;
|
|
2191
2271
|
}
|
|
2192
2272
|
}
|
|
2193
2273
|
async processAgentRequest(request) {
|
|
@@ -2373,6 +2453,7 @@ __name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
|
2373
2453
|
var telemetry_client_default = telemetryClient;
|
|
2374
2454
|
|
|
2375
2455
|
// src/service-adapters/events.ts
|
|
2456
|
+
import { plainToInstance as plainToInstance2 } from "class-transformer";
|
|
2376
2457
|
var RuntimeEventTypes;
|
|
2377
2458
|
(function(RuntimeEventTypes2) {
|
|
2378
2459
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2388,52 +2469,74 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2388
2469
|
constructor() {
|
|
2389
2470
|
super();
|
|
2390
2471
|
}
|
|
2391
|
-
sendTextMessageStart(messageId) {
|
|
2472
|
+
sendTextMessageStart({ messageId, parentMessageId }) {
|
|
2392
2473
|
this.next({
|
|
2393
2474
|
type: "TextMessageStart",
|
|
2394
|
-
messageId
|
|
2475
|
+
messageId,
|
|
2476
|
+
parentMessageId
|
|
2395
2477
|
});
|
|
2396
2478
|
}
|
|
2397
|
-
sendTextMessageContent(content) {
|
|
2479
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2398
2480
|
this.next({
|
|
2399
2481
|
type: "TextMessageContent",
|
|
2400
|
-
content
|
|
2482
|
+
content,
|
|
2483
|
+
messageId
|
|
2401
2484
|
});
|
|
2402
2485
|
}
|
|
2403
|
-
sendTextMessageEnd() {
|
|
2486
|
+
sendTextMessageEnd({ messageId }) {
|
|
2404
2487
|
this.next({
|
|
2405
|
-
type: "TextMessageEnd"
|
|
2488
|
+
type: "TextMessageEnd",
|
|
2489
|
+
messageId
|
|
2406
2490
|
});
|
|
2407
2491
|
}
|
|
2408
2492
|
sendTextMessage(messageId, content) {
|
|
2409
|
-
this.sendTextMessageStart(
|
|
2410
|
-
|
|
2411
|
-
|
|
2493
|
+
this.sendTextMessageStart({
|
|
2494
|
+
messageId
|
|
2495
|
+
});
|
|
2496
|
+
this.sendTextMessageContent({
|
|
2497
|
+
messageId,
|
|
2498
|
+
content
|
|
2499
|
+
});
|
|
2500
|
+
this.sendTextMessageEnd({
|
|
2501
|
+
messageId
|
|
2502
|
+
});
|
|
2412
2503
|
}
|
|
2413
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2504
|
+
sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
|
|
2414
2505
|
this.next({
|
|
2415
2506
|
type: "ActionExecutionStart",
|
|
2416
2507
|
actionExecutionId,
|
|
2417
|
-
actionName
|
|
2508
|
+
actionName,
|
|
2509
|
+
parentMessageId
|
|
2418
2510
|
});
|
|
2419
2511
|
}
|
|
2420
|
-
sendActionExecutionArgs(args) {
|
|
2512
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2421
2513
|
this.next({
|
|
2422
2514
|
type: "ActionExecutionArgs",
|
|
2423
|
-
args
|
|
2515
|
+
args,
|
|
2516
|
+
actionExecutionId
|
|
2424
2517
|
});
|
|
2425
2518
|
}
|
|
2426
|
-
sendActionExecutionEnd() {
|
|
2519
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2427
2520
|
this.next({
|
|
2428
|
-
type: "ActionExecutionEnd"
|
|
2521
|
+
type: "ActionExecutionEnd",
|
|
2522
|
+
actionExecutionId
|
|
2429
2523
|
});
|
|
2430
2524
|
}
|
|
2431
|
-
sendActionExecution(actionExecutionId,
|
|
2432
|
-
this.sendActionExecutionStart(
|
|
2433
|
-
|
|
2434
|
-
|
|
2525
|
+
sendActionExecution({ actionExecutionId, actionName, args, parentMessageId }) {
|
|
2526
|
+
this.sendActionExecutionStart({
|
|
2527
|
+
actionExecutionId,
|
|
2528
|
+
actionName,
|
|
2529
|
+
parentMessageId
|
|
2530
|
+
});
|
|
2531
|
+
this.sendActionExecutionArgs({
|
|
2532
|
+
actionExecutionId,
|
|
2533
|
+
args
|
|
2534
|
+
});
|
|
2535
|
+
this.sendActionExecutionEnd({
|
|
2536
|
+
actionExecutionId
|
|
2537
|
+
});
|
|
2435
2538
|
}
|
|
2436
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2539
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2437
2540
|
this.next({
|
|
2438
2541
|
type: "ActionExecutionResult",
|
|
2439
2542
|
actionName,
|
|
@@ -2441,7 +2544,7 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2441
2544
|
result
|
|
2442
2545
|
});
|
|
2443
2546
|
}
|
|
2444
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2547
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2445
2548
|
this.next({
|
|
2446
2549
|
type: "AgentStateMessage",
|
|
2447
2550
|
threadId,
|
|
@@ -2462,14 +2565,14 @@ var RuntimeEventSource = class {
|
|
|
2462
2565
|
async stream(callback) {
|
|
2463
2566
|
this.callback = callback;
|
|
2464
2567
|
}
|
|
2465
|
-
sendErrorMessageToChat() {
|
|
2466
|
-
const errorMessage =
|
|
2568
|
+
sendErrorMessageToChat(message = "An error occurred. Please try again.") {
|
|
2569
|
+
const errorMessage = `\u274C ${message}`;
|
|
2467
2570
|
if (!this.callback) {
|
|
2468
2571
|
this.stream(async (eventStream$) => {
|
|
2469
|
-
eventStream$.sendTextMessage(
|
|
2572
|
+
eventStream$.sendTextMessage(randomId2(), errorMessage);
|
|
2470
2573
|
});
|
|
2471
2574
|
} else {
|
|
2472
|
-
this.eventStream$.sendTextMessage(
|
|
2575
|
+
this.eventStream$.sendTextMessage(randomId2(), errorMessage);
|
|
2473
2576
|
}
|
|
2474
2577
|
}
|
|
2475
2578
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
@@ -2478,27 +2581,19 @@ var RuntimeEventSource = class {
|
|
|
2478
2581
|
this.sendErrorMessageToChat();
|
|
2479
2582
|
});
|
|
2480
2583
|
return this.eventStream$.pipe(
|
|
2481
|
-
// mark tools for server side execution
|
|
2482
|
-
map((event) => {
|
|
2483
|
-
if (event.type === "ActionExecutionStart") {
|
|
2484
|
-
if (event.scope !== "passThrough") {
|
|
2485
|
-
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2486
|
-
}
|
|
2487
|
-
}
|
|
2488
|
-
return event;
|
|
2489
|
-
}),
|
|
2490
2584
|
// track state
|
|
2491
2585
|
scan2((acc, event) => {
|
|
2492
2586
|
acc = {
|
|
2493
2587
|
...acc
|
|
2494
2588
|
};
|
|
2495
2589
|
if (event.type === "ActionExecutionStart") {
|
|
2496
|
-
acc.callActionServerSide =
|
|
2590
|
+
acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
|
|
2497
2591
|
acc.args = "";
|
|
2498
2592
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2499
2593
|
if (acc.callActionServerSide) {
|
|
2500
2594
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2501
2595
|
}
|
|
2596
|
+
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2502
2597
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2503
2598
|
acc.args += event.args;
|
|
2504
2599
|
}
|
|
@@ -2509,12 +2604,13 @@ var RuntimeEventSource = class {
|
|
|
2509
2604
|
callActionServerSide: false,
|
|
2510
2605
|
args: "",
|
|
2511
2606
|
actionExecutionId: null,
|
|
2512
|
-
action: null
|
|
2607
|
+
action: null,
|
|
2608
|
+
actionExecutionParentMessageId: null
|
|
2513
2609
|
}),
|
|
2514
2610
|
concatMap((eventWithState) => {
|
|
2515
2611
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2516
2612
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2517
|
-
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2613
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionParentMessageId, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2518
2614
|
console.error(error);
|
|
2519
2615
|
});
|
|
2520
2616
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2527,7 +2623,7 @@ var RuntimeEventSource = class {
|
|
|
2527
2623
|
}
|
|
2528
2624
|
};
|
|
2529
2625
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2530
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2626
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
|
|
2531
2627
|
var _a;
|
|
2532
2628
|
if (guardrailsResult$) {
|
|
2533
2629
|
const { status } = await firstValueFrom(guardrailsResult$);
|
|
@@ -2547,10 +2643,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2547
2643
|
}
|
|
2548
2644
|
}
|
|
2549
2645
|
if (isLangGraphAgentAction(action)) {
|
|
2550
|
-
|
|
2646
|
+
const result = `${action.name} agent started`;
|
|
2647
|
+
const agentExecution = plainToInstance2(ActionExecutionMessage, {
|
|
2648
|
+
id: actionExecutionId,
|
|
2649
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2650
|
+
name: action.name,
|
|
2651
|
+
arguments: JSON.parse(actionArguments),
|
|
2652
|
+
parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
|
|
2653
|
+
});
|
|
2654
|
+
const agentExecutionResult = plainToInstance2(ResultMessage, {
|
|
2655
|
+
id: "result-" + actionExecutionId,
|
|
2656
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2657
|
+
actionExecutionId,
|
|
2658
|
+
actionName: action.name,
|
|
2659
|
+
result
|
|
2660
|
+
});
|
|
2661
|
+
eventStream$.sendActionExecutionResult({
|
|
2662
|
+
actionExecutionId,
|
|
2663
|
+
actionName: action.name,
|
|
2664
|
+
result
|
|
2665
|
+
});
|
|
2551
2666
|
const stream = await action.langGraphAgentHandler({
|
|
2552
2667
|
name: action.name,
|
|
2553
|
-
actionInputsWithoutAgents
|
|
2668
|
+
actionInputsWithoutAgents,
|
|
2669
|
+
additionalMessages: [
|
|
2670
|
+
agentExecution,
|
|
2671
|
+
agentExecutionResult
|
|
2672
|
+
]
|
|
2554
2673
|
});
|
|
2555
2674
|
from2(stream).subscribe({
|
|
2556
2675
|
next: (event) => eventStream$.next(event),
|
|
@@ -2573,9 +2692,9 @@ __name(executeAction, "executeAction");
|
|
|
2573
2692
|
|
|
2574
2693
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2575
2694
|
import { GraphQLJSONObject } from "graphql-scalars";
|
|
2576
|
-
import { plainToInstance as
|
|
2695
|
+
import { plainToInstance as plainToInstance3 } from "class-transformer";
|
|
2577
2696
|
import { GraphQLError } from "graphql";
|
|
2578
|
-
import { randomId as
|
|
2697
|
+
import { randomId as randomId3 } from "@copilotkit/shared";
|
|
2579
2698
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
2580
2699
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2581
2700
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -2692,7 +2811,7 @@ var CopilotResolver = class {
|
|
|
2692
2811
|
rejectOutputMessagesPromise = reject;
|
|
2693
2812
|
});
|
|
2694
2813
|
logger2.debug("Processing");
|
|
2695
|
-
const { eventSource, threadId =
|
|
2814
|
+
const { eventSource, threadId = randomId3(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
2696
2815
|
serviceAdapter,
|
|
2697
2816
|
messages: data.messages,
|
|
2698
2817
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -2736,8 +2855,8 @@ var CopilotResolver = class {
|
|
|
2736
2855
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
2737
2856
|
});
|
|
2738
2857
|
outputMessages = [
|
|
2739
|
-
|
|
2740
|
-
id:
|
|
2858
|
+
plainToInstance3(TextMessage, {
|
|
2859
|
+
id: randomId3(),
|
|
2741
2860
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2742
2861
|
content: result.reason,
|
|
2743
2862
|
role: MessageRole.assistant
|
|
@@ -2785,12 +2904,15 @@ var CopilotResolver = class {
|
|
|
2785
2904
|
// skip until this message start event
|
|
2786
2905
|
skipWhile((e) => e !== event),
|
|
2787
2906
|
// take until the message end event
|
|
2788
|
-
takeWhile((e) => e.type
|
|
2907
|
+
takeWhile((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
|
|
2908
|
+
// filter out any other message events or message ids
|
|
2909
|
+
filter((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
2789
2910
|
);
|
|
2790
2911
|
const streamingTextStatus = new Subject();
|
|
2791
2912
|
const messageId = event.messageId;
|
|
2792
2913
|
pushMessage({
|
|
2793
2914
|
id: messageId,
|
|
2915
|
+
parentMessageId: event.parentMessageId,
|
|
2794
2916
|
status: firstValueFrom2(streamingTextStatus),
|
|
2795
2917
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2796
2918
|
role: MessageRole.assistant,
|
|
@@ -2803,7 +2925,7 @@ var CopilotResolver = class {
|
|
|
2803
2925
|
reason,
|
|
2804
2926
|
messageId: messageId2
|
|
2805
2927
|
}, "Text streaming interrupted");
|
|
2806
|
-
streamingTextStatus.next(
|
|
2928
|
+
streamingTextStatus.next(plainToInstance3(FailedMessageStatus, {
|
|
2807
2929
|
reason
|
|
2808
2930
|
}));
|
|
2809
2931
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -2836,7 +2958,7 @@ var CopilotResolver = class {
|
|
|
2836
2958
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
2837
2959
|
stopStreamingText();
|
|
2838
2960
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2839
|
-
outputMessages.push(
|
|
2961
|
+
outputMessages.push(plainToInstance3(TextMessage, {
|
|
2840
2962
|
id: messageId,
|
|
2841
2963
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2842
2964
|
content: textChunks.join(""),
|
|
@@ -2849,14 +2971,20 @@ var CopilotResolver = class {
|
|
|
2849
2971
|
break;
|
|
2850
2972
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
2851
2973
|
logger2.debug("Action execution start event received");
|
|
2852
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
2974
|
+
const actionExecutionArgumentStream = eventStream.pipe(
|
|
2975
|
+
skipWhile((e) => e !== event),
|
|
2976
|
+
// take until the action execution end event
|
|
2977
|
+
takeWhile((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
2978
|
+
// filter out any other action execution events or action execution ids
|
|
2979
|
+
filter((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
2980
|
+
);
|
|
2853
2981
|
const streamingArgumentsStatus = new Subject();
|
|
2854
2982
|
pushMessage({
|
|
2855
2983
|
id: event.actionExecutionId,
|
|
2984
|
+
parentMessageId: event.parentMessageId,
|
|
2856
2985
|
status: firstValueFrom2(streamingArgumentsStatus),
|
|
2857
2986
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2858
2987
|
name: event.actionName,
|
|
2859
|
-
scope: event.scope,
|
|
2860
2988
|
arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
2861
2989
|
logger2.debug("Action execution argument stream created");
|
|
2862
2990
|
const argumentChunks = [];
|
|
@@ -2872,7 +3000,7 @@ var CopilotResolver = class {
|
|
|
2872
3000
|
logger2.error({
|
|
2873
3001
|
err
|
|
2874
3002
|
}, "Error in action execution argument stream");
|
|
2875
|
-
streamingArgumentsStatus.next(
|
|
3003
|
+
streamingArgumentsStatus.next(plainToInstance3(FailedMessageStatus, {
|
|
2876
3004
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
2877
3005
|
}));
|
|
2878
3006
|
stopStreamingArguments();
|
|
@@ -2883,11 +3011,10 @@ var CopilotResolver = class {
|
|
|
2883
3011
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2884
3012
|
stopStreamingArguments();
|
|
2885
3013
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
2886
|
-
outputMessages.push(
|
|
3014
|
+
outputMessages.push(plainToInstance3(ActionExecutionMessage, {
|
|
2887
3015
|
id: event.actionExecutionId,
|
|
2888
3016
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2889
3017
|
name: event.actionName,
|
|
2890
|
-
scope: event.scope,
|
|
2891
3018
|
arguments: argumentChunks.join("")
|
|
2892
3019
|
}));
|
|
2893
3020
|
}
|
|
@@ -2900,15 +3027,15 @@ var CopilotResolver = class {
|
|
|
2900
3027
|
result: event.result
|
|
2901
3028
|
}, "Action execution result event received");
|
|
2902
3029
|
pushMessage({
|
|
2903
|
-
id:
|
|
3030
|
+
id: "result-" + event.actionExecutionId,
|
|
2904
3031
|
status: new SuccessMessageStatus(),
|
|
2905
3032
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2906
3033
|
actionExecutionId: event.actionExecutionId,
|
|
2907
3034
|
actionName: event.actionName,
|
|
2908
3035
|
result: event.result
|
|
2909
3036
|
});
|
|
2910
|
-
outputMessages.push(
|
|
2911
|
-
id:
|
|
3037
|
+
outputMessages.push(plainToInstance3(ResultMessage, {
|
|
3038
|
+
id: "result-" + event.actionExecutionId,
|
|
2912
3039
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2913
3040
|
actionExecutionId: event.actionExecutionId,
|
|
2914
3041
|
actionName: event.actionName,
|
|
@@ -2920,7 +3047,7 @@ var CopilotResolver = class {
|
|
|
2920
3047
|
event
|
|
2921
3048
|
}, "Agent message event received");
|
|
2922
3049
|
pushMessage({
|
|
2923
|
-
id:
|
|
3050
|
+
id: randomId3(),
|
|
2924
3051
|
status: new SuccessMessageStatus(),
|
|
2925
3052
|
threadId: event.threadId,
|
|
2926
3053
|
agentName: event.agentName,
|
|
@@ -2932,8 +3059,8 @@ var CopilotResolver = class {
|
|
|
2932
3059
|
role: MessageRole.assistant,
|
|
2933
3060
|
createdAt: /* @__PURE__ */ new Date()
|
|
2934
3061
|
});
|
|
2935
|
-
outputMessages.push(
|
|
2936
|
-
id:
|
|
3062
|
+
outputMessages.push(plainToInstance3(AgentStateMessage, {
|
|
3063
|
+
id: randomId3(),
|
|
2937
3064
|
threadId: event.threadId,
|
|
2938
3065
|
agentName: event.agentName,
|
|
2939
3066
|
nodeName: event.nodeName,
|
|
@@ -3144,4 +3271,4 @@ export {
|
|
|
3144
3271
|
getCommonConfig,
|
|
3145
3272
|
copilotRuntimeNodeHttpEndpoint
|
|
3146
3273
|
};
|
|
3147
|
-
//# sourceMappingURL=chunk-
|
|
3274
|
+
//# sourceMappingURL=chunk-25G6SHWM.mjs.map
|