@copilotkit/runtime 1.5.1-next.1 → 1.5.1-next.3
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 +17 -0
- package/__snapshots__/schema/schema.graphql +9 -8
- package/dist/{chunk-RFF5IIZJ.mjs → chunk-B74M7FXG.mjs} +2 -3
- package/dist/chunk-B74M7FXG.mjs.map +1 -0
- package/dist/{chunk-L4VT7Z25.mjs → chunk-M4QD67S3.mjs} +2 -2
- package/dist/{chunk-CLGKEUOA.mjs → chunk-OKQVDDJ2.mjs} +63 -298
- package/dist/chunk-OKQVDDJ2.mjs.map +1 -0
- package/dist/{chunk-G2PTXSIW.mjs → chunk-U3AYI5XZ.mjs} +2 -2
- package/dist/{chunk-Z3MD5FQ4.mjs → chunk-U75F2RAQ.mjs} +2 -2
- package/dist/{chunk-6N4ZHRRC.mjs → chunk-ZSWCEADS.mjs} +331 -465
- package/dist/chunk-ZSWCEADS.mjs.map +1 -0
- package/dist/{copilot-runtime-6285d897.d.ts → copilot-runtime-12e7ac40.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +1 -2
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-15d41154.d.ts → groq-adapter-24abe931.d.ts} +1 -1
- package/dist/{index-ff3fbc33.d.ts → index-10b1c870.d.ts} +8 -7
- package/dist/index.d.ts +5 -5
- package/dist/index.js +480 -852
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -15
- package/dist/index.mjs.map +1 -1
- package/dist/{langserve-48e976ac.d.ts → langserve-f021ab9c.d.ts} +14 -54
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +459 -754
- 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 +30 -78
- 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 +30 -78
- 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 +30 -78
- 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 +30 -78
- 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 +5 -36
- package/dist/service-adapters/index.js +61 -298
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +1 -5
- package/package.json +4 -4
- package/src/graphql/resolvers/copilot.resolver.ts +16 -0
- package/src/graphql/types/agents-response.type.ts +22 -0
- package/src/lib/runtime/copilot-runtime.ts +50 -0
- package/dist/chunk-6N4ZHRRC.mjs.map +0 -1
- package/dist/chunk-CLGKEUOA.mjs.map +0 -1
- package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
- /package/dist/{chunk-L4VT7Z25.mjs.map → chunk-M4QD67S3.mjs.map} +0 -0
- /package/dist/{chunk-G2PTXSIW.mjs.map → chunk-U3AYI5XZ.mjs.map} +0 -0
- /package/dist/{chunk-Z3MD5FQ4.mjs.map → chunk-U75F2RAQ.mjs.map} +0 -0
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RemoteChain,
|
|
3
|
-
streamLangChainResponse
|
|
4
|
-
} from "./chunk-CLGKEUOA.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-OKQVDDJ2.mjs";
|
|
12
12
|
import {
|
|
13
13
|
ActionExecutionMessage,
|
|
14
14
|
AgentStateMessage,
|
|
15
15
|
ResultMessage,
|
|
16
16
|
TextMessage
|
|
17
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-B74M7FXG.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.
|
|
40
|
+
version: "1.4.1-pre.6",
|
|
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,
|
|
125
|
+
import { ReplaySubject as ReplaySubject3, Subject, 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,6 +139,12 @@ 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 = {}));
|
|
142
148
|
var CopilotRequestType;
|
|
143
149
|
(function(CopilotRequestType2) {
|
|
144
150
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -157,6 +163,10 @@ registerEnumType(MessageRole, {
|
|
|
157
163
|
name: "MessageRole",
|
|
158
164
|
description: "The role of the message"
|
|
159
165
|
});
|
|
166
|
+
registerEnumType(ActionExecutionScope, {
|
|
167
|
+
name: "ActionExecutionScope",
|
|
168
|
+
description: "The scope of the action"
|
|
169
|
+
});
|
|
160
170
|
registerEnumType(CopilotRequestType, {
|
|
161
171
|
name: "CopilotRequestType",
|
|
162
172
|
description: "The type of Copilot request"
|
|
@@ -219,7 +229,6 @@ MessageInput = _ts_decorate([
|
|
|
219
229
|
], MessageInput);
|
|
220
230
|
var TextMessageInput = class {
|
|
221
231
|
content;
|
|
222
|
-
parentMessageId;
|
|
223
232
|
role;
|
|
224
233
|
};
|
|
225
234
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -227,12 +236,6 @@ _ts_decorate([
|
|
|
227
236
|
Field(() => String),
|
|
228
237
|
_ts_metadata("design:type", String)
|
|
229
238
|
], 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);
|
|
236
239
|
_ts_decorate([
|
|
237
240
|
Field(() => MessageRole),
|
|
238
241
|
_ts_metadata("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -243,7 +246,6 @@ TextMessageInput = _ts_decorate([
|
|
|
243
246
|
var ActionExecutionMessageInput = class {
|
|
244
247
|
name;
|
|
245
248
|
arguments;
|
|
246
|
-
parentMessageId;
|
|
247
249
|
scope;
|
|
248
250
|
};
|
|
249
251
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -256,17 +258,8 @@ _ts_decorate([
|
|
|
256
258
|
_ts_metadata("design:type", String)
|
|
257
259
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
258
260
|
_ts_decorate([
|
|
259
|
-
Field(() =>
|
|
260
|
-
|
|
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)
|
|
261
|
+
Field(() => ActionExecutionScope),
|
|
262
|
+
_ts_metadata("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
270
263
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
271
264
|
ActionExecutionMessageInput = _ts_decorate([
|
|
272
265
|
InputType()
|
|
@@ -274,7 +267,6 @@ ActionExecutionMessageInput = _ts_decorate([
|
|
|
274
267
|
var ResultMessageInput = class {
|
|
275
268
|
actionExecutionId;
|
|
276
269
|
actionName;
|
|
277
|
-
parentMessageId;
|
|
278
270
|
result;
|
|
279
271
|
};
|
|
280
272
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -286,12 +278,6 @@ _ts_decorate([
|
|
|
286
278
|
Field(() => String),
|
|
287
279
|
_ts_metadata("design:type", String)
|
|
288
280
|
], 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);
|
|
295
281
|
_ts_decorate([
|
|
296
282
|
Field(() => String),
|
|
297
283
|
_ts_metadata("design:type", String)
|
|
@@ -555,7 +541,6 @@ var ForwardedParametersInput = class {
|
|
|
555
541
|
stop;
|
|
556
542
|
toolChoice;
|
|
557
543
|
toolChoiceFunctionName;
|
|
558
|
-
temperature;
|
|
559
544
|
};
|
|
560
545
|
__name(ForwardedParametersInput, "ForwardedParametersInput");
|
|
561
546
|
_ts_decorate6([
|
|
@@ -590,12 +575,6 @@ _ts_decorate6([
|
|
|
590
575
|
}),
|
|
591
576
|
_ts_metadata6("design:type", String)
|
|
592
577
|
], ForwardedParametersInput.prototype, "toolChoiceFunctionName", void 0);
|
|
593
|
-
_ts_decorate6([
|
|
594
|
-
Field6(() => Number, {
|
|
595
|
-
nullable: true
|
|
596
|
-
}),
|
|
597
|
-
_ts_metadata6("design:type", Number)
|
|
598
|
-
], ForwardedParametersInput.prototype, "temperature", void 0);
|
|
599
578
|
ForwardedParametersInput = _ts_decorate6([
|
|
600
579
|
InputType6()
|
|
601
580
|
], ForwardedParametersInput);
|
|
@@ -914,7 +893,6 @@ BaseMessageOutput = _ts_decorate11([
|
|
|
914
893
|
var TextMessageOutput = class {
|
|
915
894
|
role;
|
|
916
895
|
content;
|
|
917
|
-
parentMessageId;
|
|
918
896
|
};
|
|
919
897
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
920
898
|
_ts_decorate11([
|
|
@@ -927,12 +905,6 @@ _ts_decorate11([
|
|
|
927
905
|
]),
|
|
928
906
|
_ts_metadata11("design:type", Array)
|
|
929
907
|
], TextMessageOutput.prototype, "content", void 0);
|
|
930
|
-
_ts_decorate11([
|
|
931
|
-
Field11(() => String, {
|
|
932
|
-
nullable: true
|
|
933
|
-
}),
|
|
934
|
-
_ts_metadata11("design:type", String)
|
|
935
|
-
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
936
908
|
TextMessageOutput = _ts_decorate11([
|
|
937
909
|
ObjectType2({
|
|
938
910
|
implements: BaseMessageOutput
|
|
@@ -942,7 +914,6 @@ var ActionExecutionMessageOutput = class {
|
|
|
942
914
|
name;
|
|
943
915
|
scope;
|
|
944
916
|
arguments;
|
|
945
|
-
parentMessageId;
|
|
946
917
|
};
|
|
947
918
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
948
919
|
_ts_decorate11([
|
|
@@ -950,11 +921,8 @@ _ts_decorate11([
|
|
|
950
921
|
_ts_metadata11("design:type", String)
|
|
951
922
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
952
923
|
_ts_decorate11([
|
|
953
|
-
Field11(() =>
|
|
954
|
-
|
|
955
|
-
deprecationReason: "This field will be removed in a future version"
|
|
956
|
-
}),
|
|
957
|
-
_ts_metadata11("design:type", String)
|
|
924
|
+
Field11(() => ActionExecutionScope),
|
|
925
|
+
_ts_metadata11("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
|
|
958
926
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
959
927
|
_ts_decorate11([
|
|
960
928
|
Field11(() => [
|
|
@@ -962,12 +930,6 @@ _ts_decorate11([
|
|
|
962
930
|
]),
|
|
963
931
|
_ts_metadata11("design:type", Array)
|
|
964
932
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
965
|
-
_ts_decorate11([
|
|
966
|
-
Field11(() => String, {
|
|
967
|
-
nullable: true
|
|
968
|
-
}),
|
|
969
|
-
_ts_metadata11("design:type", String)
|
|
970
|
-
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
971
933
|
ActionExecutionMessageOutput = _ts_decorate11([
|
|
972
934
|
ObjectType2({
|
|
973
935
|
implements: BaseMessageOutput
|
|
@@ -1079,8 +1041,8 @@ CopilotResponse = _ts_decorate11([
|
|
|
1079
1041
|
import { Repeater } from "graphql-yoga";
|
|
1080
1042
|
|
|
1081
1043
|
// src/service-adapters/events.ts
|
|
1082
|
-
import { randomId as
|
|
1083
|
-
import { of, concat, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
|
|
1044
|
+
import { randomId as randomId3 } from "@copilotkit/shared";
|
|
1045
|
+
import { of, concat, map, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
|
|
1084
1046
|
|
|
1085
1047
|
// src/lib/telemetry-client.ts
|
|
1086
1048
|
import { TelemetryClient } from "@copilotkit/shared";
|
|
@@ -1128,167 +1090,163 @@ var RemoteLangGraphEventSource = class {
|
|
|
1128
1090
|
}
|
|
1129
1091
|
return shouldEmitToolCalls === toolCallName;
|
|
1130
1092
|
}
|
|
1131
|
-
getCurrentContent(event) {
|
|
1132
|
-
var _a, _b, _c, _d, _e;
|
|
1133
|
-
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);
|
|
1134
|
-
if (!content) {
|
|
1135
|
-
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1136
|
-
for (const chunk of toolCallChunks) {
|
|
1137
|
-
if (chunk.args) {
|
|
1138
|
-
return chunk.args;
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
if (typeof content === "string") {
|
|
1143
|
-
return content;
|
|
1144
|
-
} else if (Array.isArray(content) && content.length > 0) {
|
|
1145
|
-
return content[0].text;
|
|
1146
|
-
}
|
|
1147
|
-
return null;
|
|
1148
|
-
}
|
|
1149
|
-
getCurrentMessageId(event) {
|
|
1150
|
-
var _a, _b, _c, _d, _e;
|
|
1151
|
-
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);
|
|
1152
|
-
}
|
|
1153
|
-
getCurrentToolCallChunks(event) {
|
|
1154
|
-
var _a, _b, _c, _d, _e;
|
|
1155
|
-
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);
|
|
1156
|
-
}
|
|
1157
|
-
getResponseMetadata(event) {
|
|
1158
|
-
var _a, _b, _c, _d, _e;
|
|
1159
|
-
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);
|
|
1160
|
-
}
|
|
1161
1093
|
processLangGraphEvents() {
|
|
1162
1094
|
let lastEventWithState = null;
|
|
1163
1095
|
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;
|
|
1164
1097
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1165
|
-
const
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1098
|
+
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);
|
|
1099
|
+
if (typeof content === "string") {
|
|
1100
|
+
acc.content = content;
|
|
1101
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1102
|
+
acc.content = content[0].text;
|
|
1103
|
+
} else {
|
|
1104
|
+
acc.content = null;
|
|
1105
|
+
}
|
|
1106
|
+
const toolCallChunks = (
|
|
1107
|
+
// @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
|
|
1108
|
+
((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) ?? ((_j = (_i = event.data) == null ? void 0 : _i.chunk) == null ? void 0 : _j.tool_call_chunks)
|
|
1109
|
+
);
|
|
1110
|
+
const toolCallMessageId = ((_m = (_l = (_k = event.data) == null ? void 0 : _k.chunk) == null ? void 0 : _l.kwargs) == null ? void 0 : _m.id) ?? ((_o = (_n = event.data) == null ? void 0 : _n.chunk) == null ? void 0 : _o.id);
|
|
1111
|
+
if (toolCallChunks && toolCallChunks.length > 0) {
|
|
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;
|
|
1179
1135
|
}
|
|
1180
1136
|
acc.event = event;
|
|
1181
1137
|
lastEventWithState = acc;
|
|
1182
1138
|
return acc;
|
|
1183
1139
|
}, {
|
|
1184
1140
|
event: null,
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
}), mergeMap((acc) => {
|
|
1141
|
+
toolCallId: null,
|
|
1142
|
+
toolCallMessageId: null,
|
|
1143
|
+
prevToolCallMessageId: null,
|
|
1144
|
+
messageId: null,
|
|
1145
|
+
toolCallName: null,
|
|
1146
|
+
prevMessageId: null,
|
|
1147
|
+
content: null
|
|
1148
|
+
}), mergeMap((eventWithState) => {
|
|
1149
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
1195
1150
|
const events = [];
|
|
1196
1151
|
let shouldEmitMessages = true;
|
|
1197
|
-
let shouldEmitToolCalls =
|
|
1198
|
-
if (
|
|
1199
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1200
|
-
shouldEmitToolCalls =
|
|
1152
|
+
let shouldEmitToolCalls = false;
|
|
1153
|
+
if (eventWithState.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1154
|
+
if ("copilotkit:emit-tool-calls" in (eventWithState.event.metadata || {})) {
|
|
1155
|
+
shouldEmitToolCalls = eventWithState.event.metadata["copilotkit:emit-tool-calls"];
|
|
1201
1156
|
}
|
|
1202
|
-
if ("copilotkit:emit-messages" in (
|
|
1203
|
-
shouldEmitMessages =
|
|
1157
|
+
if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
|
|
1158
|
+
shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
|
|
1204
1159
|
}
|
|
1205
1160
|
}
|
|
1206
|
-
|
|
1207
|
-
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1161
|
+
if (eventWithState.prevToolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId && this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1208
1162
|
events.push({
|
|
1209
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1210
|
-
actionExecutionId: acc.lastToolCallId
|
|
1163
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1211
1164
|
});
|
|
1212
1165
|
}
|
|
1213
|
-
if (
|
|
1166
|
+
if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
|
|
1214
1167
|
events.push({
|
|
1215
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1216
|
-
messageId: acc.lastMessageId
|
|
1168
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1217
1169
|
});
|
|
1218
1170
|
}
|
|
1219
|
-
switch (
|
|
1171
|
+
switch (eventWithState.event.event) {
|
|
1220
1172
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1221
|
-
if (
|
|
1173
|
+
if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1222
1174
|
events.push({
|
|
1223
1175
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1224
|
-
messageId:
|
|
1176
|
+
messageId: eventWithState.event.data.message_id
|
|
1225
1177
|
});
|
|
1226
1178
|
events.push({
|
|
1227
1179
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1228
|
-
|
|
1229
|
-
content: acc.event.data.message
|
|
1180
|
+
content: eventWithState.event.data.message
|
|
1230
1181
|
});
|
|
1231
1182
|
events.push({
|
|
1232
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1233
|
-
messageId: acc.event.data.message_id
|
|
1183
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1234
1184
|
});
|
|
1235
|
-
} else if (
|
|
1185
|
+
} else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1236
1186
|
events.push({
|
|
1237
1187
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1238
|
-
actionExecutionId:
|
|
1239
|
-
actionName:
|
|
1240
|
-
parentMessageId: acc.event.data.id
|
|
1188
|
+
actionExecutionId: eventWithState.event.data.id,
|
|
1189
|
+
actionName: eventWithState.event.data.name
|
|
1241
1190
|
});
|
|
1242
1191
|
events.push({
|
|
1243
1192
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1244
|
-
|
|
1245
|
-
args: JSON.stringify(acc.event.data.args)
|
|
1193
|
+
args: JSON.stringify(eventWithState.event.data.args)
|
|
1246
1194
|
});
|
|
1247
1195
|
events.push({
|
|
1248
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1249
|
-
actionExecutionId: acc.event.data.id
|
|
1196
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1250
1197
|
});
|
|
1251
1198
|
}
|
|
1252
1199
|
break;
|
|
1253
1200
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1254
1201
|
events.push({
|
|
1255
1202
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1256
|
-
threadId:
|
|
1257
|
-
role:
|
|
1258
|
-
agentName:
|
|
1259
|
-
nodeName:
|
|
1260
|
-
runId:
|
|
1261
|
-
active:
|
|
1262
|
-
state: JSON.stringify(
|
|
1263
|
-
running:
|
|
1203
|
+
threadId: eventWithState.event.thread_id,
|
|
1204
|
+
role: eventWithState.event.role,
|
|
1205
|
+
agentName: eventWithState.event.agent_name,
|
|
1206
|
+
nodeName: eventWithState.event.node_name,
|
|
1207
|
+
runId: eventWithState.event.run_id,
|
|
1208
|
+
active: eventWithState.event.active,
|
|
1209
|
+
state: JSON.stringify(eventWithState.event.state),
|
|
1210
|
+
running: eventWithState.event.running
|
|
1264
1211
|
});
|
|
1265
1212
|
break;
|
|
1213
|
+
case LangGraphEventTypes.OnToolEnd:
|
|
1214
|
+
break;
|
|
1266
1215
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1267
|
-
if (
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1216
|
+
if (eventWithState.toolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId) {
|
|
1217
|
+
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1218
|
+
events.push({
|
|
1219
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1220
|
+
actionExecutionId: eventWithState.toolCallMessageId,
|
|
1221
|
+
actionName: eventWithState.toolCallName,
|
|
1222
|
+
scope: "client"
|
|
1223
|
+
});
|
|
1224
|
+
}
|
|
1225
|
+
} else if (eventWithState.messageId !== null && eventWithState.prevMessageId !== eventWithState.messageId) {
|
|
1226
|
+
if (shouldEmitMessages) {
|
|
1227
|
+
events.push({
|
|
1228
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1229
|
+
messageId: eventWithState.messageId
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1279
1232
|
}
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1233
|
+
const args = ((_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args) ?? // @ts-expect-error -- sdf
|
|
1234
|
+
((_i = (_h = (_g = (_f = eventWithState.event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.tool_call_chunks) == null ? void 0 : _h[0]) == null ? void 0 : _i.args);
|
|
1235
|
+
const content = eventWithState.content;
|
|
1236
|
+
if (args) {
|
|
1237
|
+
if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
|
|
1238
|
+
events.push({
|
|
1239
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1240
|
+
args
|
|
1241
|
+
});
|
|
1242
|
+
}
|
|
1243
|
+
} else if (eventWithState.messageId !== null && content) {
|
|
1244
|
+
if (shouldEmitMessages) {
|
|
1245
|
+
events.push({
|
|
1246
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1247
|
+
content
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1292
1250
|
}
|
|
1293
1251
|
break;
|
|
1294
1252
|
}
|
|
@@ -1296,16 +1254,14 @@ var RemoteLangGraphEventSource = class {
|
|
|
1296
1254
|
}), catchError((error) => {
|
|
1297
1255
|
console.error(error);
|
|
1298
1256
|
const events = [];
|
|
1299
|
-
if (
|
|
1257
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
|
|
1300
1258
|
events.push({
|
|
1301
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1302
|
-
messageId: lastEventWithState.lastMessageId
|
|
1259
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1303
1260
|
});
|
|
1304
1261
|
}
|
|
1305
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1262
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
|
|
1306
1263
|
events.push({
|
|
1307
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1308
|
-
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1264
|
+
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1309
1265
|
});
|
|
1310
1266
|
}
|
|
1311
1267
|
const messageId = randomId();
|
|
@@ -1315,12 +1271,10 @@ var RemoteLangGraphEventSource = class {
|
|
|
1315
1271
|
});
|
|
1316
1272
|
events.push({
|
|
1317
1273
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1318
|
-
messageId,
|
|
1319
1274
|
content: "\u274C An error occurred. Please try again."
|
|
1320
1275
|
});
|
|
1321
1276
|
events.push({
|
|
1322
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1323
|
-
messageId
|
|
1277
|
+
type: RuntimeEventTypes.TextMessageEnd
|
|
1324
1278
|
});
|
|
1325
1279
|
return events;
|
|
1326
1280
|
}));
|
|
@@ -1359,6 +1313,8 @@ async function streamEvents(controller, args) {
|
|
|
1359
1313
|
if (initialThreadId && initialThreadId.startsWith("ck-")) {
|
|
1360
1314
|
initialThreadId = initialThreadId.substring(3);
|
|
1361
1315
|
}
|
|
1316
|
+
const assistants = await client.assistants.search();
|
|
1317
|
+
const retrievedAssistant = assistants.find((a) => a.name === name);
|
|
1362
1318
|
const threadId = initialThreadId ?? randomUUID();
|
|
1363
1319
|
if (initialThreadId === threadId) {
|
|
1364
1320
|
await client.threads.get(threadId);
|
|
@@ -1378,7 +1334,7 @@ async function streamEvents(controller, args) {
|
|
|
1378
1334
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1379
1335
|
let formattedMessages = [];
|
|
1380
1336
|
try {
|
|
1381
|
-
formattedMessages =
|
|
1337
|
+
formattedMessages = formatMessages(messages);
|
|
1382
1338
|
} catch (e) {
|
|
1383
1339
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1384
1340
|
}
|
|
@@ -1389,16 +1345,8 @@ async function streamEvents(controller, args) {
|
|
|
1389
1345
|
asNode: nodeName
|
|
1390
1346
|
});
|
|
1391
1347
|
}
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
};
|
|
1395
|
-
const assistants = await client.assistants.search();
|
|
1396
|
-
const retrievedAssistant = assistants.find((a) => a.name === name || a.assistant_id === initialAssistantId);
|
|
1397
|
-
if (!retrievedAssistant) {
|
|
1398
|
-
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1399
|
-
...streamInfo,
|
|
1400
|
-
error: `Found no assistants for given information, while ${assistants.length} assistants exists`
|
|
1401
|
-
});
|
|
1348
|
+
const assistantId = initialAssistantId ?? (retrievedAssistant == null ? void 0 : retrievedAssistant.assistant_id);
|
|
1349
|
+
if (!assistantId) {
|
|
1402
1350
|
console.error(`
|
|
1403
1351
|
No agent found for the agent name specified in CopilotKit provider
|
|
1404
1352
|
Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
|
|
@@ -1408,7 +1356,6 @@ async function streamEvents(controller, args) {
|
|
|
1408
1356
|
`);
|
|
1409
1357
|
throw new Error("No agent id found");
|
|
1410
1358
|
}
|
|
1411
|
-
const assistantId = retrievedAssistant.assistant_id;
|
|
1412
1359
|
const graphInfo = await client.assistants.getGraph(assistantId);
|
|
1413
1360
|
const streamInput = mode === "start" ? state : null;
|
|
1414
1361
|
let streamingStateExtractor = new StreamingStateExtractor([]);
|
|
@@ -1427,6 +1374,9 @@ async function streamEvents(controller, args) {
|
|
|
1427
1374
|
let latestStateValues = {};
|
|
1428
1375
|
let updatedState = state;
|
|
1429
1376
|
let manuallyEmittedState = null;
|
|
1377
|
+
let streamInfo = {
|
|
1378
|
+
hashedLgcKey: createHash("sha256").update(langsmithApiKey).digest("hex")
|
|
1379
|
+
};
|
|
1430
1380
|
try {
|
|
1431
1381
|
telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
|
|
1432
1382
|
hashedLgcKey: streamInfo.hashedLgcKey
|
|
@@ -1439,6 +1389,7 @@ async function streamEvents(controller, args) {
|
|
|
1439
1389
|
].includes(chunk.event))
|
|
1440
1390
|
continue;
|
|
1441
1391
|
if (chunk.event === "error") {
|
|
1392
|
+
logger2.error(chunk, `Error event thrown: ${chunk.data.message}`);
|
|
1442
1393
|
throw new Error(`Error event thrown: ${chunk.data.message}`);
|
|
1443
1394
|
}
|
|
1444
1395
|
if (chunk.event === "values") {
|
|
@@ -1531,34 +1482,21 @@ async function streamEvents(controller, args) {
|
|
|
1531
1482
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1532
1483
|
state: state.values,
|
|
1533
1484
|
running: !shouldExit,
|
|
1534
|
-
active: false
|
|
1535
|
-
includeMessages: true
|
|
1485
|
+
active: false
|
|
1536
1486
|
}));
|
|
1537
1487
|
return Promise.resolve();
|
|
1538
1488
|
} catch (e) {
|
|
1539
|
-
logger2.error(e);
|
|
1540
|
-
telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
|
|
1541
|
-
...streamInfo,
|
|
1542
|
-
error: e.message
|
|
1543
|
-
});
|
|
1544
1489
|
return Promise.resolve();
|
|
1545
1490
|
}
|
|
1546
1491
|
}
|
|
1547
1492
|
__name(streamEvents, "streamEvents");
|
|
1548
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
}, {});
|
|
1556
|
-
} else {
|
|
1557
|
-
state = {
|
|
1558
|
-
...state,
|
|
1559
|
-
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
1560
|
-
};
|
|
1561
|
-
}
|
|
1493
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1494
|
+
const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
|
|
1495
|
+
if (key !== "messages") {
|
|
1496
|
+
acc[key] = state[key];
|
|
1497
|
+
}
|
|
1498
|
+
return acc;
|
|
1499
|
+
}, {});
|
|
1562
1500
|
return JSON.stringify({
|
|
1563
1501
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1564
1502
|
thread_id: threadId,
|
|
@@ -1566,7 +1504,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1566
1504
|
agent_name: agentName,
|
|
1567
1505
|
node_name: nodeName,
|
|
1568
1506
|
active,
|
|
1569
|
-
state,
|
|
1507
|
+
state: stateWithoutMessages,
|
|
1570
1508
|
running,
|
|
1571
1509
|
role: "assistant"
|
|
1572
1510
|
}) + "\n";
|
|
@@ -1642,157 +1580,134 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1642
1580
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1643
1581
|
messages = messages.slice(1);
|
|
1644
1582
|
}
|
|
1645
|
-
const
|
|
1646
|
-
const existingMessageIds = new Set(
|
|
1647
|
-
const
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
copilotkit: {
|
|
1652
|
-
actions
|
|
1653
|
-
}
|
|
1654
|
-
};
|
|
1655
|
-
}
|
|
1656
|
-
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1657
|
-
function langchainMessagesToCopilotKit(messages) {
|
|
1658
|
-
const result = [];
|
|
1659
|
-
const tool_call_names = {};
|
|
1660
|
-
for (const message of messages) {
|
|
1661
|
-
if (message.type === "ai") {
|
|
1662
|
-
for (const tool_call of message.tool_calls) {
|
|
1663
|
-
tool_call_names[tool_call.id] = tool_call.name;
|
|
1664
|
-
}
|
|
1583
|
+
const mergedMessages = state.messages || [];
|
|
1584
|
+
const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
|
|
1585
|
+
const existingToolCallResults = /* @__PURE__ */ new Set();
|
|
1586
|
+
for (const message of mergedMessages) {
|
|
1587
|
+
if ("tool_call_id" in message) {
|
|
1588
|
+
existingToolCallResults.add(message.tool_call_id);
|
|
1665
1589
|
}
|
|
1666
1590
|
}
|
|
1667
1591
|
for (const message of messages) {
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
content = content[0];
|
|
1592
|
+
if ("tool_calls" in message && message.tool_calls.length > 0 && message.tool_calls[0].name === agentName) {
|
|
1593
|
+
continue;
|
|
1671
1594
|
}
|
|
1672
|
-
if (
|
|
1673
|
-
|
|
1595
|
+
if ("name" in message && message.name === agentName) {
|
|
1596
|
+
continue;
|
|
1674
1597
|
}
|
|
1675
|
-
if (message.
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
} else
|
|
1682
|
-
|
|
1683
|
-
role
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
for (const tool_call of message.tool_calls) {
|
|
1690
|
-
result.push({
|
|
1691
|
-
id: tool_call.id,
|
|
1692
|
-
name: tool_call.name,
|
|
1693
|
-
arguments: tool_call.args,
|
|
1694
|
-
parentMessageId: message.id
|
|
1695
|
-
});
|
|
1598
|
+
if (!existingMessageIds.has(message.id)) {
|
|
1599
|
+
if ("tool_call_id" in message && existingToolCallResults.has(message.tool_call_id)) {
|
|
1600
|
+
console.warn("Warning: Duplicate tool call result, skipping:", message.tool_call_id);
|
|
1601
|
+
continue;
|
|
1602
|
+
}
|
|
1603
|
+
mergedMessages.push(message);
|
|
1604
|
+
} else {
|
|
1605
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
1606
|
+
if (mergedMessages[i].id === message.id && message.role === "assistant") {
|
|
1607
|
+
if (("tool_calls" in mergedMessages[i] || "additional_kwargs" in mergedMessages[i]) && mergedMessages[i].content) {
|
|
1608
|
+
message.tool_calls = mergedMessages[i]["tool_calls"];
|
|
1609
|
+
message.additional_kwargs = mergedMessages[i].additional_kwargs;
|
|
1610
|
+
}
|
|
1611
|
+
mergedMessages[i] = message;
|
|
1696
1612
|
}
|
|
1697
|
-
} else {
|
|
1698
|
-
result.push({
|
|
1699
|
-
role: "assistant",
|
|
1700
|
-
content,
|
|
1701
|
-
id: message.id,
|
|
1702
|
-
parentMessageId: message.id
|
|
1703
|
-
});
|
|
1704
1613
|
}
|
|
1705
|
-
} else if (message.type === "tool") {
|
|
1706
|
-
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
1707
|
-
result.push({
|
|
1708
|
-
actionExecutionId: message.tool_call_id,
|
|
1709
|
-
actionName,
|
|
1710
|
-
result: content,
|
|
1711
|
-
id: message.id
|
|
1712
|
-
});
|
|
1713
1614
|
}
|
|
1714
1615
|
}
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1616
|
+
for (let i = 0; i < mergedMessages.length - 1; i++) {
|
|
1617
|
+
const currentMessage = mergedMessages[i];
|
|
1618
|
+
const nextMessage = mergedMessages[i + 1];
|
|
1619
|
+
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0 && "tool_call_id" in nextMessage) {
|
|
1620
|
+
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
1719
1621
|
}
|
|
1720
1622
|
}
|
|
1721
|
-
const
|
|
1722
|
-
for (
|
|
1723
|
-
|
|
1724
|
-
|
|
1623
|
+
const correctedMessages = [];
|
|
1624
|
+
for (let i = 0; i < mergedMessages.length; i++) {
|
|
1625
|
+
const currentMessage = mergedMessages[i];
|
|
1626
|
+
const nextMessage = mergedMessages[i + 1] || null;
|
|
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;
|
|
1725
1646
|
}
|
|
1726
|
-
if ("
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1647
|
+
if ("tool_call_id" in currentMessage) {
|
|
1648
|
+
if (!prevMessage || !("tool_calls" in prevMessage)) {
|
|
1649
|
+
console.warn("No previous tool call, skipping tool call result:", currentMessage.id);
|
|
1650
|
+
continue;
|
|
1730
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;
|
|
1655
|
+
}
|
|
1656
|
+
correctedMessages.push(currentMessage);
|
|
1657
|
+
continue;
|
|
1731
1658
|
}
|
|
1659
|
+
correctedMessages.push(currentMessage);
|
|
1732
1660
|
}
|
|
1733
|
-
return
|
|
1661
|
+
return {
|
|
1662
|
+
...state,
|
|
1663
|
+
messages: correctedMessages,
|
|
1664
|
+
copilotkit: {
|
|
1665
|
+
actions
|
|
1666
|
+
}
|
|
1667
|
+
};
|
|
1734
1668
|
}
|
|
1735
|
-
__name(
|
|
1736
|
-
function
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
} else if (message.role === "system") {
|
|
1747
|
-
result.push({
|
|
1748
|
-
...message,
|
|
1749
|
-
role: MessageRole.system
|
|
1750
|
-
});
|
|
1751
|
-
} else if (message.role === "assistant") {
|
|
1752
|
-
result.push({
|
|
1753
|
-
...message,
|
|
1754
|
-
role: MessageRole.assistant
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
continue;
|
|
1669
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1670
|
+
function formatMessages(messages) {
|
|
1671
|
+
return messages.map((message) => {
|
|
1672
|
+
if (message.isTextMessage() && message.role === "assistant") {
|
|
1673
|
+
return message;
|
|
1674
|
+
}
|
|
1675
|
+
if (message.isTextMessage() && message.role === "system") {
|
|
1676
|
+
return message;
|
|
1677
|
+
}
|
|
1678
|
+
if (message.isTextMessage() && message.role === "user") {
|
|
1679
|
+
return message;
|
|
1758
1680
|
}
|
|
1759
1681
|
if (message.isActionExecutionMessage()) {
|
|
1760
|
-
const
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
name: m.name,
|
|
1768
|
-
args: m.arguments,
|
|
1769
|
-
id: m.id
|
|
1770
|
-
}));
|
|
1771
|
-
result.push({
|
|
1772
|
-
id: messageId,
|
|
1773
|
-
type: "ActionExecutionMessage",
|
|
1682
|
+
const toolCall = {
|
|
1683
|
+
name: message.name,
|
|
1684
|
+
args: message.arguments,
|
|
1685
|
+
id: message.id
|
|
1686
|
+
};
|
|
1687
|
+
return {
|
|
1688
|
+
type: message.type,
|
|
1774
1689
|
content: "",
|
|
1775
|
-
tool_calls
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1690
|
+
tool_calls: [
|
|
1691
|
+
toolCall
|
|
1692
|
+
],
|
|
1693
|
+
role: MessageRole.assistant,
|
|
1694
|
+
id: message.id
|
|
1695
|
+
};
|
|
1779
1696
|
}
|
|
1780
1697
|
if (message.isResultMessage()) {
|
|
1781
|
-
|
|
1698
|
+
return {
|
|
1782
1699
|
type: message.type,
|
|
1783
1700
|
content: message.result,
|
|
1784
1701
|
id: message.id,
|
|
1785
1702
|
tool_call_id: message.actionExecutionId,
|
|
1786
1703
|
name: message.actionName,
|
|
1787
1704
|
role: MessageRole.tool
|
|
1788
|
-
}
|
|
1789
|
-
continue;
|
|
1705
|
+
};
|
|
1790
1706
|
}
|
|
1791
1707
|
throw new Error(`Unknown message type ${message.type}`);
|
|
1792
|
-
}
|
|
1793
|
-
return result;
|
|
1708
|
+
});
|
|
1794
1709
|
}
|
|
1795
|
-
__name(
|
|
1710
|
+
__name(formatMessages, "formatMessages");
|
|
1796
1711
|
|
|
1797
1712
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1798
1713
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -1802,7 +1717,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1802
1717
|
parameters: [],
|
|
1803
1718
|
handler: async (_args) => {
|
|
1804
1719
|
},
|
|
1805
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
1720
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1806
1721
|
var _a;
|
|
1807
1722
|
logger2.debug({
|
|
1808
1723
|
actionName: agent.name
|
|
@@ -1828,10 +1743,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1828
1743
|
agent,
|
|
1829
1744
|
threadId,
|
|
1830
1745
|
nodeName,
|
|
1831
|
-
messages
|
|
1832
|
-
...messages,
|
|
1833
|
-
...additionalMessages
|
|
1834
|
-
],
|
|
1746
|
+
messages,
|
|
1835
1747
|
state,
|
|
1836
1748
|
properties: graphqlContext.properties,
|
|
1837
1749
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1859,7 +1771,6 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1859
1771
|
}
|
|
1860
1772
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1861
1773
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1862
|
-
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
1863
1774
|
const actions = json["actions"].map((action) => ({
|
|
1864
1775
|
name: action.name,
|
|
1865
1776
|
description: action.description,
|
|
@@ -1873,7 +1784,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1873
1784
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1874
1785
|
agentExecution: false,
|
|
1875
1786
|
type: "self-hosted",
|
|
1876
|
-
agentsAmount:
|
|
1787
|
+
agentsAmount: json["agents"].length
|
|
1877
1788
|
});
|
|
1878
1789
|
try {
|
|
1879
1790
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -1908,13 +1819,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1908
1819
|
}
|
|
1909
1820
|
}
|
|
1910
1821
|
}));
|
|
1911
|
-
const agents =
|
|
1822
|
+
const agents = json["agents"].map((agent) => ({
|
|
1912
1823
|
name: agent.name,
|
|
1913
1824
|
description: agent.description,
|
|
1914
1825
|
parameters: [],
|
|
1915
1826
|
handler: async (_args) => {
|
|
1916
1827
|
},
|
|
1917
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName
|
|
1828
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1918
1829
|
var _a;
|
|
1919
1830
|
logger2.debug({
|
|
1920
1831
|
actionName: agent.name
|
|
@@ -1939,10 +1850,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1939
1850
|
name,
|
|
1940
1851
|
threadId,
|
|
1941
1852
|
nodeName,
|
|
1942
|
-
messages
|
|
1943
|
-
...messages,
|
|
1944
|
-
...additionalMessages
|
|
1945
|
-
],
|
|
1853
|
+
messages,
|
|
1946
1854
|
state,
|
|
1947
1855
|
properties: graphqlContext.properties,
|
|
1948
1856
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1964,7 +1872,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1964
1872
|
streamResponse(response.body, eventSource.eventStream$);
|
|
1965
1873
|
return eventSource.processLangGraphEvents();
|
|
1966
1874
|
}
|
|
1967
|
-
}))
|
|
1875
|
+
}));
|
|
1968
1876
|
return [
|
|
1969
1877
|
...actions,
|
|
1970
1878
|
...agents
|
|
@@ -2142,7 +2050,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2142
2050
|
import { createHash as createHash3 } from "crypto";
|
|
2143
2051
|
|
|
2144
2052
|
// src/lib/runtime/copilot-runtime.ts
|
|
2145
|
-
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
2053
|
+
import { actionParametersToJsonSchema, randomId as randomId2 } from "@copilotkit/shared";
|
|
2146
2054
|
|
|
2147
2055
|
// src/service-adapters/conversion.ts
|
|
2148
2056
|
import { plainToInstance } from "class-transformer";
|
|
@@ -2154,8 +2062,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2154
2062
|
id: message.id,
|
|
2155
2063
|
createdAt: message.createdAt,
|
|
2156
2064
|
role: message.textMessage.role,
|
|
2157
|
-
content: message.textMessage.content
|
|
2158
|
-
parentMessageId: message.textMessage.parentMessageId
|
|
2065
|
+
content: message.textMessage.content
|
|
2159
2066
|
}));
|
|
2160
2067
|
} else if (message.actionExecutionMessage) {
|
|
2161
2068
|
messages.push(plainToInstance(ActionExecutionMessage, {
|
|
@@ -2163,7 +2070,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2163
2070
|
createdAt: message.createdAt,
|
|
2164
2071
|
name: message.actionExecutionMessage.name,
|
|
2165
2072
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2166
|
-
|
|
2073
|
+
scope: message.actionExecutionMessage.scope
|
|
2167
2074
|
}));
|
|
2168
2075
|
} else if (message.resultMessage) {
|
|
2169
2076
|
messages.push(plainToInstance(ResultMessage, {
|
|
@@ -2274,7 +2181,13 @@ var CopilotRuntime = class {
|
|
|
2274
2181
|
} catch (error) {
|
|
2275
2182
|
console.error("Error getting response:", error);
|
|
2276
2183
|
eventSource.sendErrorMessageToChat();
|
|
2277
|
-
|
|
2184
|
+
return {
|
|
2185
|
+
threadId: threadId || randomId2(),
|
|
2186
|
+
runId: runId || randomId2(),
|
|
2187
|
+
eventSource,
|
|
2188
|
+
serverSideActions: [],
|
|
2189
|
+
actionInputsWithoutAgents: []
|
|
2190
|
+
};
|
|
2278
2191
|
}
|
|
2279
2192
|
}
|
|
2280
2193
|
async processAgentRequest(request) {
|
|
@@ -2460,7 +2373,6 @@ __name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
|
2460
2373
|
var telemetry_client_default = telemetryClient;
|
|
2461
2374
|
|
|
2462
2375
|
// src/service-adapters/events.ts
|
|
2463
|
-
import { plainToInstance as plainToInstance2 } from "class-transformer";
|
|
2464
2376
|
var RuntimeEventTypes;
|
|
2465
2377
|
(function(RuntimeEventTypes2) {
|
|
2466
2378
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2476,74 +2388,52 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2476
2388
|
constructor() {
|
|
2477
2389
|
super();
|
|
2478
2390
|
}
|
|
2479
|
-
sendTextMessageStart(
|
|
2391
|
+
sendTextMessageStart(messageId) {
|
|
2480
2392
|
this.next({
|
|
2481
2393
|
type: "TextMessageStart",
|
|
2482
|
-
messageId
|
|
2483
|
-
parentMessageId
|
|
2394
|
+
messageId
|
|
2484
2395
|
});
|
|
2485
2396
|
}
|
|
2486
|
-
sendTextMessageContent(
|
|
2397
|
+
sendTextMessageContent(content) {
|
|
2487
2398
|
this.next({
|
|
2488
2399
|
type: "TextMessageContent",
|
|
2489
|
-
content
|
|
2490
|
-
messageId
|
|
2400
|
+
content
|
|
2491
2401
|
});
|
|
2492
2402
|
}
|
|
2493
|
-
sendTextMessageEnd(
|
|
2403
|
+
sendTextMessageEnd() {
|
|
2494
2404
|
this.next({
|
|
2495
|
-
type: "TextMessageEnd"
|
|
2496
|
-
messageId
|
|
2405
|
+
type: "TextMessageEnd"
|
|
2497
2406
|
});
|
|
2498
2407
|
}
|
|
2499
2408
|
sendTextMessage(messageId, content) {
|
|
2500
|
-
this.sendTextMessageStart(
|
|
2501
|
-
|
|
2502
|
-
|
|
2503
|
-
this.sendTextMessageContent({
|
|
2504
|
-
messageId,
|
|
2505
|
-
content
|
|
2506
|
-
});
|
|
2507
|
-
this.sendTextMessageEnd({
|
|
2508
|
-
messageId
|
|
2509
|
-
});
|
|
2409
|
+
this.sendTextMessageStart(messageId);
|
|
2410
|
+
this.sendTextMessageContent(content);
|
|
2411
|
+
this.sendTextMessageEnd();
|
|
2510
2412
|
}
|
|
2511
|
-
sendActionExecutionStart(
|
|
2413
|
+
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2512
2414
|
this.next({
|
|
2513
2415
|
type: "ActionExecutionStart",
|
|
2514
2416
|
actionExecutionId,
|
|
2515
|
-
actionName
|
|
2516
|
-
parentMessageId
|
|
2417
|
+
actionName
|
|
2517
2418
|
});
|
|
2518
2419
|
}
|
|
2519
|
-
sendActionExecutionArgs(
|
|
2420
|
+
sendActionExecutionArgs(args) {
|
|
2520
2421
|
this.next({
|
|
2521
2422
|
type: "ActionExecutionArgs",
|
|
2522
|
-
args
|
|
2523
|
-
actionExecutionId
|
|
2423
|
+
args
|
|
2524
2424
|
});
|
|
2525
2425
|
}
|
|
2526
|
-
sendActionExecutionEnd(
|
|
2426
|
+
sendActionExecutionEnd() {
|
|
2527
2427
|
this.next({
|
|
2528
|
-
type: "ActionExecutionEnd"
|
|
2529
|
-
actionExecutionId
|
|
2428
|
+
type: "ActionExecutionEnd"
|
|
2530
2429
|
});
|
|
2531
2430
|
}
|
|
2532
|
-
sendActionExecution(
|
|
2533
|
-
this.sendActionExecutionStart(
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
parentMessageId
|
|
2537
|
-
});
|
|
2538
|
-
this.sendActionExecutionArgs({
|
|
2539
|
-
actionExecutionId,
|
|
2540
|
-
args
|
|
2541
|
-
});
|
|
2542
|
-
this.sendActionExecutionEnd({
|
|
2543
|
-
actionExecutionId
|
|
2544
|
-
});
|
|
2431
|
+
sendActionExecution(actionExecutionId, toolName, args) {
|
|
2432
|
+
this.sendActionExecutionStart(actionExecutionId, toolName);
|
|
2433
|
+
this.sendActionExecutionArgs(args);
|
|
2434
|
+
this.sendActionExecutionEnd();
|
|
2545
2435
|
}
|
|
2546
|
-
sendActionExecutionResult(
|
|
2436
|
+
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2547
2437
|
this.next({
|
|
2548
2438
|
type: "ActionExecutionResult",
|
|
2549
2439
|
actionName,
|
|
@@ -2551,7 +2441,7 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2551
2441
|
result
|
|
2552
2442
|
});
|
|
2553
2443
|
}
|
|
2554
|
-
sendAgentStateMessage(
|
|
2444
|
+
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2555
2445
|
this.next({
|
|
2556
2446
|
type: "AgentStateMessage",
|
|
2557
2447
|
threadId,
|
|
@@ -2572,14 +2462,14 @@ var RuntimeEventSource = class {
|
|
|
2572
2462
|
async stream(callback) {
|
|
2573
2463
|
this.callback = callback;
|
|
2574
2464
|
}
|
|
2575
|
-
sendErrorMessageToChat(
|
|
2576
|
-
const errorMessage =
|
|
2465
|
+
sendErrorMessageToChat() {
|
|
2466
|
+
const errorMessage = "\u274C An error occurred. Please try again.";
|
|
2577
2467
|
if (!this.callback) {
|
|
2578
2468
|
this.stream(async (eventStream$) => {
|
|
2579
|
-
eventStream$.sendTextMessage(
|
|
2469
|
+
eventStream$.sendTextMessage(randomId3(), errorMessage);
|
|
2580
2470
|
});
|
|
2581
2471
|
} else {
|
|
2582
|
-
this.eventStream$.sendTextMessage(
|
|
2472
|
+
this.eventStream$.sendTextMessage(randomId3(), errorMessage);
|
|
2583
2473
|
}
|
|
2584
2474
|
}
|
|
2585
2475
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
@@ -2588,19 +2478,27 @@ var RuntimeEventSource = class {
|
|
|
2588
2478
|
this.sendErrorMessageToChat();
|
|
2589
2479
|
});
|
|
2590
2480
|
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
|
+
}),
|
|
2591
2490
|
// track state
|
|
2592
2491
|
scan2((acc, event) => {
|
|
2593
2492
|
acc = {
|
|
2594
2493
|
...acc
|
|
2595
2494
|
};
|
|
2596
2495
|
if (event.type === "ActionExecutionStart") {
|
|
2597
|
-
acc.callActionServerSide =
|
|
2496
|
+
acc.callActionServerSide = event.scope === "server";
|
|
2598
2497
|
acc.args = "";
|
|
2599
2498
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2600
2499
|
if (acc.callActionServerSide) {
|
|
2601
2500
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2602
2501
|
}
|
|
2603
|
-
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2604
2502
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2605
2503
|
acc.args += event.args;
|
|
2606
2504
|
}
|
|
@@ -2611,13 +2509,12 @@ var RuntimeEventSource = class {
|
|
|
2611
2509
|
callActionServerSide: false,
|
|
2612
2510
|
args: "",
|
|
2613
2511
|
actionExecutionId: null,
|
|
2614
|
-
action: null
|
|
2615
|
-
actionExecutionParentMessageId: null
|
|
2512
|
+
action: null
|
|
2616
2513
|
}),
|
|
2617
2514
|
concatMap((eventWithState) => {
|
|
2618
2515
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2619
2516
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2620
|
-
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.
|
|
2517
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2621
2518
|
console.error(error);
|
|
2622
2519
|
});
|
|
2623
2520
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2630,7 +2527,7 @@ var RuntimeEventSource = class {
|
|
|
2630
2527
|
}
|
|
2631
2528
|
};
|
|
2632
2529
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2633
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments,
|
|
2530
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2634
2531
|
var _a;
|
|
2635
2532
|
if (guardrailsResult$) {
|
|
2636
2533
|
const { status } = await firstValueFrom(guardrailsResult$);
|
|
@@ -2650,33 +2547,10 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2650
2547
|
}
|
|
2651
2548
|
}
|
|
2652
2549
|
if (isLangGraphAgentAction(action)) {
|
|
2653
|
-
|
|
2654
|
-
const agentExecution = plainToInstance2(ActionExecutionMessage, {
|
|
2655
|
-
id: actionExecutionId,
|
|
2656
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2657
|
-
name: action.name,
|
|
2658
|
-
arguments: JSON.parse(actionArguments),
|
|
2659
|
-
parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
|
|
2660
|
-
});
|
|
2661
|
-
const agentExecutionResult = plainToInstance2(ResultMessage, {
|
|
2662
|
-
id: "result-" + actionExecutionId,
|
|
2663
|
-
createdAt: /* @__PURE__ */ new Date(),
|
|
2664
|
-
actionExecutionId,
|
|
2665
|
-
actionName: action.name,
|
|
2666
|
-
result
|
|
2667
|
-
});
|
|
2668
|
-
eventStream$.sendActionExecutionResult({
|
|
2669
|
-
actionExecutionId,
|
|
2670
|
-
actionName: action.name,
|
|
2671
|
-
result
|
|
2672
|
-
});
|
|
2550
|
+
eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
|
|
2673
2551
|
const stream = await action.langGraphAgentHandler({
|
|
2674
2552
|
name: action.name,
|
|
2675
|
-
actionInputsWithoutAgents
|
|
2676
|
-
additionalMessages: [
|
|
2677
|
-
agentExecution,
|
|
2678
|
-
agentExecutionResult
|
|
2679
|
-
]
|
|
2553
|
+
actionInputsWithoutAgents
|
|
2680
2554
|
});
|
|
2681
2555
|
from2(stream).subscribe({
|
|
2682
2556
|
next: (event) => eventStream$.next(event),
|
|
@@ -2699,9 +2573,9 @@ __name(executeAction, "executeAction");
|
|
|
2699
2573
|
|
|
2700
2574
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2701
2575
|
import { GraphQLJSONObject } from "graphql-scalars";
|
|
2702
|
-
import { plainToInstance as
|
|
2576
|
+
import { plainToInstance as plainToInstance2 } from "class-transformer";
|
|
2703
2577
|
import { GraphQLError } from "graphql";
|
|
2704
|
-
import { randomId as
|
|
2578
|
+
import { randomId as randomId4 } from "@copilotkit/shared";
|
|
2705
2579
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
2706
2580
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2707
2581
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -2818,7 +2692,7 @@ var CopilotResolver = class {
|
|
|
2818
2692
|
rejectOutputMessagesPromise = reject;
|
|
2819
2693
|
});
|
|
2820
2694
|
logger2.debug("Processing");
|
|
2821
|
-
const { eventSource, threadId =
|
|
2695
|
+
const { eventSource, threadId = randomId4(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
2822
2696
|
serviceAdapter,
|
|
2823
2697
|
messages: data.messages,
|
|
2824
2698
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -2862,8 +2736,8 @@ var CopilotResolver = class {
|
|
|
2862
2736
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
2863
2737
|
});
|
|
2864
2738
|
outputMessages = [
|
|
2865
|
-
|
|
2866
|
-
id:
|
|
2739
|
+
plainToInstance2(TextMessage, {
|
|
2740
|
+
id: randomId4(),
|
|
2867
2741
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2868
2742
|
content: result.reason,
|
|
2869
2743
|
role: MessageRole.assistant
|
|
@@ -2911,15 +2785,12 @@ var CopilotResolver = class {
|
|
|
2911
2785
|
// skip until this message start event
|
|
2912
2786
|
skipWhile((e) => e !== event),
|
|
2913
2787
|
// take until the message end event
|
|
2914
|
-
takeWhile((e) =>
|
|
2915
|
-
// filter out any other message events or message ids
|
|
2916
|
-
filter((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
2788
|
+
takeWhile((e) => e.type != RuntimeEventTypes.TextMessageEnd)
|
|
2917
2789
|
);
|
|
2918
2790
|
const streamingTextStatus = new Subject();
|
|
2919
2791
|
const messageId = event.messageId;
|
|
2920
2792
|
pushMessage({
|
|
2921
2793
|
id: messageId,
|
|
2922
|
-
parentMessageId: event.parentMessageId,
|
|
2923
2794
|
status: firstValueFrom2(streamingTextStatus),
|
|
2924
2795
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2925
2796
|
role: MessageRole.assistant,
|
|
@@ -2932,7 +2803,7 @@ var CopilotResolver = class {
|
|
|
2932
2803
|
reason,
|
|
2933
2804
|
messageId: messageId2
|
|
2934
2805
|
}, "Text streaming interrupted");
|
|
2935
|
-
streamingTextStatus.next(
|
|
2806
|
+
streamingTextStatus.next(plainToInstance2(FailedMessageStatus, {
|
|
2936
2807
|
reason
|
|
2937
2808
|
}));
|
|
2938
2809
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -2965,7 +2836,7 @@ var CopilotResolver = class {
|
|
|
2965
2836
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
2966
2837
|
stopStreamingText();
|
|
2967
2838
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2968
|
-
outputMessages.push(
|
|
2839
|
+
outputMessages.push(plainToInstance2(TextMessage, {
|
|
2969
2840
|
id: messageId,
|
|
2970
2841
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2971
2842
|
content: textChunks.join(""),
|
|
@@ -2978,20 +2849,14 @@ var CopilotResolver = class {
|
|
|
2978
2849
|
break;
|
|
2979
2850
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
2980
2851
|
logger2.debug("Action execution start event received");
|
|
2981
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
2982
|
-
skipWhile((e) => e !== event),
|
|
2983
|
-
// take until the action execution end event
|
|
2984
|
-
takeWhile((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
2985
|
-
// filter out any other action execution events or action execution ids
|
|
2986
|
-
filter((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
2987
|
-
);
|
|
2852
|
+
const actionExecutionArgumentStream = eventStream.pipe(skipWhile((e) => e !== event), takeWhile((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
|
|
2988
2853
|
const streamingArgumentsStatus = new Subject();
|
|
2989
2854
|
pushMessage({
|
|
2990
2855
|
id: event.actionExecutionId,
|
|
2991
|
-
parentMessageId: event.parentMessageId,
|
|
2992
2856
|
status: firstValueFrom2(streamingArgumentsStatus),
|
|
2993
2857
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2994
2858
|
name: event.actionName,
|
|
2859
|
+
scope: event.scope,
|
|
2995
2860
|
arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
2996
2861
|
logger2.debug("Action execution argument stream created");
|
|
2997
2862
|
const argumentChunks = [];
|
|
@@ -3007,7 +2872,7 @@ var CopilotResolver = class {
|
|
|
3007
2872
|
logger2.error({
|
|
3008
2873
|
err
|
|
3009
2874
|
}, "Error in action execution argument stream");
|
|
3010
|
-
streamingArgumentsStatus.next(
|
|
2875
|
+
streamingArgumentsStatus.next(plainToInstance2(FailedMessageStatus, {
|
|
3011
2876
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
3012
2877
|
}));
|
|
3013
2878
|
stopStreamingArguments();
|
|
@@ -3018,10 +2883,11 @@ var CopilotResolver = class {
|
|
|
3018
2883
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
3019
2884
|
stopStreamingArguments();
|
|
3020
2885
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
3021
|
-
outputMessages.push(
|
|
2886
|
+
outputMessages.push(plainToInstance2(ActionExecutionMessage, {
|
|
3022
2887
|
id: event.actionExecutionId,
|
|
3023
2888
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3024
2889
|
name: event.actionName,
|
|
2890
|
+
scope: event.scope,
|
|
3025
2891
|
arguments: argumentChunks.join("")
|
|
3026
2892
|
}));
|
|
3027
2893
|
}
|
|
@@ -3034,15 +2900,15 @@ var CopilotResolver = class {
|
|
|
3034
2900
|
result: event.result
|
|
3035
2901
|
}, "Action execution result event received");
|
|
3036
2902
|
pushMessage({
|
|
3037
|
-
id:
|
|
2903
|
+
id: randomId4(),
|
|
3038
2904
|
status: new SuccessMessageStatus(),
|
|
3039
2905
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3040
2906
|
actionExecutionId: event.actionExecutionId,
|
|
3041
2907
|
actionName: event.actionName,
|
|
3042
2908
|
result: event.result
|
|
3043
2909
|
});
|
|
3044
|
-
outputMessages.push(
|
|
3045
|
-
id:
|
|
2910
|
+
outputMessages.push(plainToInstance2(ResultMessage, {
|
|
2911
|
+
id: randomId4(),
|
|
3046
2912
|
createdAt: /* @__PURE__ */ new Date(),
|
|
3047
2913
|
actionExecutionId: event.actionExecutionId,
|
|
3048
2914
|
actionName: event.actionName,
|
|
@@ -3054,7 +2920,7 @@ var CopilotResolver = class {
|
|
|
3054
2920
|
event
|
|
3055
2921
|
}, "Agent message event received");
|
|
3056
2922
|
pushMessage({
|
|
3057
|
-
id:
|
|
2923
|
+
id: randomId4(),
|
|
3058
2924
|
status: new SuccessMessageStatus(),
|
|
3059
2925
|
threadId: event.threadId,
|
|
3060
2926
|
agentName: event.agentName,
|
|
@@ -3066,8 +2932,8 @@ var CopilotResolver = class {
|
|
|
3066
2932
|
role: MessageRole.assistant,
|
|
3067
2933
|
createdAt: /* @__PURE__ */ new Date()
|
|
3068
2934
|
});
|
|
3069
|
-
outputMessages.push(
|
|
3070
|
-
id:
|
|
2935
|
+
outputMessages.push(plainToInstance2(AgentStateMessage, {
|
|
2936
|
+
id: randomId4(),
|
|
3071
2937
|
threadId: event.threadId,
|
|
3072
2938
|
agentName: event.agentName,
|
|
3073
2939
|
nodeName: event.nodeName,
|
|
@@ -3278,4 +3144,4 @@ export {
|
|
|
3278
3144
|
getCommonConfig,
|
|
3279
3145
|
copilotRuntimeNodeHttpEndpoint
|
|
3280
3146
|
};
|
|
3281
|
-
//# sourceMappingURL=chunk-
|
|
3147
|
+
//# sourceMappingURL=chunk-ZSWCEADS.mjs.map
|