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