@copilotkit/runtime 1.4.8-no-pino-redact.1 → 1.5.0-coagents-v0-3.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 +20 -5
- package/__snapshots__/schema/schema.graphql +7 -9
- package/dist/{chunk-OKQVDDJ2.mjs → chunk-4AYRDPWK.mjs} +285 -63
- package/dist/chunk-4AYRDPWK.mjs.map +1 -0
- package/dist/{chunk-APVJZO3R.mjs → chunk-7BOO3OFP.mjs} +2 -2
- package/dist/{chunk-OSWF5QDO.mjs → chunk-GSTWFOZF.mjs} +2 -2
- package/dist/{chunk-M74ZTUCC.mjs → chunk-OMAAKIJQ.mjs} +2 -2
- package/dist/{chunk-36AYTJIE.mjs → chunk-PXS4SBRF.mjs} +447 -321
- package/dist/chunk-PXS4SBRF.mjs.map +1 -0
- package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
- package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
- package/dist/{copilot-runtime-12e7ac40.d.ts → copilot-runtime-2e46a7b6.d.ts} +2 -2
- package/dist/graphql/types/converted/index.d.ts +1 -1
- package/dist/graphql/types/converted/index.js +2 -1
- package/dist/graphql/types/converted/index.js.map +1 -1
- package/dist/graphql/types/converted/index.mjs +1 -1
- package/dist/{groq-adapter-24abe931.d.ts → groq-adapter-7bf6824b.d.ts} +1 -1
- package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
- package/dist/index.d.ts +5 -5
- package/dist/index.js +824 -473
- 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-f318db89.d.ts} +53 -14
- package/dist/lib/index.d.ts +4 -4
- package/dist/lib/index.js +729 -452
- 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 +79 -31
- 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 +79 -31
- 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 +79 -31
- 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 +79 -31
- package/dist/lib/integrations/node-http/index.js.map +1 -1
- package/dist/lib/integrations/node-http/index.mjs +3 -3
- package/dist/service-adapters/index.d.ts +36 -5
- package/dist/service-adapters/index.js +285 -61
- package/dist/service-adapters/index.js.map +1 -1
- package/dist/service-adapters/index.mjs +5 -1
- package/package.json +2 -2
- package/src/agents/langgraph/event-source.ts +140 -148
- package/src/agents/langgraph/events.ts +1 -1
- package/src/graphql/inputs/message.input.ts +15 -3
- package/src/graphql/resolvers/copilot.resolver.ts +32 -6
- package/src/graphql/types/converted/index.ts +4 -3
- package/src/graphql/types/copilot-response.type.ts +12 -3
- package/src/graphql/types/enums.ts +0 -11
- package/src/lib/logger.ts +4 -0
- 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 +159 -140
- package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
- package/src/service-adapters/conversion.ts +2 -1
- package/src/service-adapters/events.ts +118 -54
- package/src/service-adapters/experimental/empty/empty-adapter.ts +33 -0
- package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
- package/src/service-adapters/groq/groq-adapter.ts +23 -8
- package/src/service-adapters/index.ts +7 -1
- package/src/service-adapters/langchain/utils.ts +55 -32
- package/src/service-adapters/openai/openai-adapter.ts +22 -9
- package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
- package/src/service-adapters/unify/unify-adapter.ts +28 -11
- package/dist/chunk-36AYTJIE.mjs.map +0 -1
- package/dist/chunk-B74M7FXG.mjs.map +0 -1
- package/dist/chunk-OKQVDDJ2.mjs.map +0 -1
- /package/dist/{chunk-APVJZO3R.mjs.map → chunk-7BOO3OFP.mjs.map} +0 -0
- /package/dist/{chunk-OSWF5QDO.mjs.map → chunk-GSTWFOZF.mjs.map} +0 -0
- /package/dist/{chunk-M74ZTUCC.mjs.map → chunk-OMAAKIJQ.mjs.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RemoteChain,
|
|
3
3
|
streamLangChainResponse
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-4AYRDPWK.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.
|
|
40
|
+
version: "1.5.0-coagents-v0-3.0",
|
|
41
41
|
sideEffects: false,
|
|
42
42
|
main: "./dist/index.js",
|
|
43
43
|
module: "./dist/index.mjs",
|
|
@@ -122,7 +122,7 @@ import { buildSchemaSync } from "type-graphql";
|
|
|
122
122
|
|
|
123
123
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
124
124
|
import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
|
|
125
|
-
import { ReplaySubject as ReplaySubject3, Subject, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
|
|
125
|
+
import { ReplaySubject as ReplaySubject3, Subject, filter, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
|
|
126
126
|
|
|
127
127
|
// src/graphql/inputs/generate-copilot-response.input.ts
|
|
128
128
|
import { Field as Field9, InputType as InputType9 } from "type-graphql";
|
|
@@ -139,12 +139,6 @@ var MessageRole;
|
|
|
139
139
|
MessageRole2["system"] = "system";
|
|
140
140
|
MessageRole2["tool"] = "tool";
|
|
141
141
|
})(MessageRole || (MessageRole = {}));
|
|
142
|
-
var ActionExecutionScope;
|
|
143
|
-
(function(ActionExecutionScope2) {
|
|
144
|
-
ActionExecutionScope2["server"] = "server";
|
|
145
|
-
ActionExecutionScope2["client"] = "client";
|
|
146
|
-
ActionExecutionScope2["passThrough"] = "passThrough";
|
|
147
|
-
})(ActionExecutionScope || (ActionExecutionScope = {}));
|
|
148
142
|
var CopilotRequestType;
|
|
149
143
|
(function(CopilotRequestType2) {
|
|
150
144
|
CopilotRequestType2["Chat"] = "Chat";
|
|
@@ -163,10 +157,6 @@ registerEnumType(MessageRole, {
|
|
|
163
157
|
name: "MessageRole",
|
|
164
158
|
description: "The role of the message"
|
|
165
159
|
});
|
|
166
|
-
registerEnumType(ActionExecutionScope, {
|
|
167
|
-
name: "ActionExecutionScope",
|
|
168
|
-
description: "The scope of the action"
|
|
169
|
-
});
|
|
170
160
|
registerEnumType(CopilotRequestType, {
|
|
171
161
|
name: "CopilotRequestType",
|
|
172
162
|
description: "The type of Copilot request"
|
|
@@ -229,6 +219,7 @@ MessageInput = _ts_decorate([
|
|
|
229
219
|
], MessageInput);
|
|
230
220
|
var TextMessageInput = class {
|
|
231
221
|
content;
|
|
222
|
+
parentMessageId;
|
|
232
223
|
role;
|
|
233
224
|
};
|
|
234
225
|
__name(TextMessageInput, "TextMessageInput");
|
|
@@ -236,6 +227,12 @@ _ts_decorate([
|
|
|
236
227
|
Field(() => String),
|
|
237
228
|
_ts_metadata("design:type", String)
|
|
238
229
|
], TextMessageInput.prototype, "content", void 0);
|
|
230
|
+
_ts_decorate([
|
|
231
|
+
Field(() => String, {
|
|
232
|
+
nullable: true
|
|
233
|
+
}),
|
|
234
|
+
_ts_metadata("design:type", String)
|
|
235
|
+
], TextMessageInput.prototype, "parentMessageId", void 0);
|
|
239
236
|
_ts_decorate([
|
|
240
237
|
Field(() => MessageRole),
|
|
241
238
|
_ts_metadata("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
|
|
@@ -246,6 +243,7 @@ TextMessageInput = _ts_decorate([
|
|
|
246
243
|
var ActionExecutionMessageInput = class {
|
|
247
244
|
name;
|
|
248
245
|
arguments;
|
|
246
|
+
parentMessageId;
|
|
249
247
|
scope;
|
|
250
248
|
};
|
|
251
249
|
__name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
|
|
@@ -258,8 +256,17 @@ _ts_decorate([
|
|
|
258
256
|
_ts_metadata("design:type", String)
|
|
259
257
|
], ActionExecutionMessageInput.prototype, "arguments", void 0);
|
|
260
258
|
_ts_decorate([
|
|
261
|
-
Field(() =>
|
|
262
|
-
|
|
259
|
+
Field(() => String, {
|
|
260
|
+
nullable: true
|
|
261
|
+
}),
|
|
262
|
+
_ts_metadata("design:type", String)
|
|
263
|
+
], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
|
|
264
|
+
_ts_decorate([
|
|
265
|
+
Field(() => String, {
|
|
266
|
+
nullable: true,
|
|
267
|
+
deprecationReason: "This field will be removed in a future version"
|
|
268
|
+
}),
|
|
269
|
+
_ts_metadata("design:type", typeof String === "undefined" ? Object : String)
|
|
263
270
|
], ActionExecutionMessageInput.prototype, "scope", void 0);
|
|
264
271
|
ActionExecutionMessageInput = _ts_decorate([
|
|
265
272
|
InputType()
|
|
@@ -267,6 +274,7 @@ ActionExecutionMessageInput = _ts_decorate([
|
|
|
267
274
|
var ResultMessageInput = class {
|
|
268
275
|
actionExecutionId;
|
|
269
276
|
actionName;
|
|
277
|
+
parentMessageId;
|
|
270
278
|
result;
|
|
271
279
|
};
|
|
272
280
|
__name(ResultMessageInput, "ResultMessageInput");
|
|
@@ -278,6 +286,12 @@ _ts_decorate([
|
|
|
278
286
|
Field(() => String),
|
|
279
287
|
_ts_metadata("design:type", String)
|
|
280
288
|
], ResultMessageInput.prototype, "actionName", void 0);
|
|
289
|
+
_ts_decorate([
|
|
290
|
+
Field(() => String, {
|
|
291
|
+
nullable: true
|
|
292
|
+
}),
|
|
293
|
+
_ts_metadata("design:type", String)
|
|
294
|
+
], ResultMessageInput.prototype, "parentMessageId", void 0);
|
|
281
295
|
_ts_decorate([
|
|
282
296
|
Field(() => String),
|
|
283
297
|
_ts_metadata("design:type", String)
|
|
@@ -893,6 +907,7 @@ BaseMessageOutput = _ts_decorate11([
|
|
|
893
907
|
var TextMessageOutput = class {
|
|
894
908
|
role;
|
|
895
909
|
content;
|
|
910
|
+
parentMessageId;
|
|
896
911
|
};
|
|
897
912
|
__name(TextMessageOutput, "TextMessageOutput");
|
|
898
913
|
_ts_decorate11([
|
|
@@ -905,6 +920,12 @@ _ts_decorate11([
|
|
|
905
920
|
]),
|
|
906
921
|
_ts_metadata11("design:type", Array)
|
|
907
922
|
], TextMessageOutput.prototype, "content", void 0);
|
|
923
|
+
_ts_decorate11([
|
|
924
|
+
Field11(() => String, {
|
|
925
|
+
nullable: true
|
|
926
|
+
}),
|
|
927
|
+
_ts_metadata11("design:type", String)
|
|
928
|
+
], TextMessageOutput.prototype, "parentMessageId", void 0);
|
|
908
929
|
TextMessageOutput = _ts_decorate11([
|
|
909
930
|
ObjectType2({
|
|
910
931
|
implements: BaseMessageOutput
|
|
@@ -914,6 +935,7 @@ var ActionExecutionMessageOutput = class {
|
|
|
914
935
|
name;
|
|
915
936
|
scope;
|
|
916
937
|
arguments;
|
|
938
|
+
parentMessageId;
|
|
917
939
|
};
|
|
918
940
|
__name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
|
|
919
941
|
_ts_decorate11([
|
|
@@ -921,8 +943,11 @@ _ts_decorate11([
|
|
|
921
943
|
_ts_metadata11("design:type", String)
|
|
922
944
|
], ActionExecutionMessageOutput.prototype, "name", void 0);
|
|
923
945
|
_ts_decorate11([
|
|
924
|
-
Field11(() =>
|
|
925
|
-
|
|
946
|
+
Field11(() => String, {
|
|
947
|
+
nullable: true,
|
|
948
|
+
deprecationReason: "This field will be removed in a future version"
|
|
949
|
+
}),
|
|
950
|
+
_ts_metadata11("design:type", String)
|
|
926
951
|
], ActionExecutionMessageOutput.prototype, "scope", void 0);
|
|
927
952
|
_ts_decorate11([
|
|
928
953
|
Field11(() => [
|
|
@@ -930,6 +955,12 @@ _ts_decorate11([
|
|
|
930
955
|
]),
|
|
931
956
|
_ts_metadata11("design:type", Array)
|
|
932
957
|
], ActionExecutionMessageOutput.prototype, "arguments", void 0);
|
|
958
|
+
_ts_decorate11([
|
|
959
|
+
Field11(() => String, {
|
|
960
|
+
nullable: true
|
|
961
|
+
}),
|
|
962
|
+
_ts_metadata11("design:type", String)
|
|
963
|
+
], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
|
|
933
964
|
ActionExecutionMessageOutput = _ts_decorate11([
|
|
934
965
|
ObjectType2({
|
|
935
966
|
implements: BaseMessageOutput
|
|
@@ -1041,8 +1072,8 @@ CopilotResponse = _ts_decorate11([
|
|
|
1041
1072
|
import { Repeater } from "graphql-yoga";
|
|
1042
1073
|
|
|
1043
1074
|
// src/service-adapters/events.ts
|
|
1044
|
-
import { randomId as
|
|
1045
|
-
import { of, concat,
|
|
1075
|
+
import { randomId as randomId2 } from "@copilotkit/shared";
|
|
1076
|
+
import { of, concat, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
|
|
1046
1077
|
|
|
1047
1078
|
// src/lib/telemetry-client.ts
|
|
1048
1079
|
import { TelemetryClient } from "@copilotkit/shared";
|
|
@@ -1090,163 +1121,167 @@ var RemoteLangGraphEventSource = class {
|
|
|
1090
1121
|
}
|
|
1091
1122
|
return shouldEmitToolCalls === toolCallName;
|
|
1092
1123
|
}
|
|
1124
|
+
getCurrentContent(event) {
|
|
1125
|
+
var _a, _b, _c, _d, _e;
|
|
1126
|
+
const content = ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.content) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.content);
|
|
1127
|
+
if (!content) {
|
|
1128
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1129
|
+
for (const chunk of toolCallChunks) {
|
|
1130
|
+
if (chunk.args) {
|
|
1131
|
+
return chunk.args;
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
if (typeof content === "string") {
|
|
1136
|
+
return content;
|
|
1137
|
+
} else if (Array.isArray(content) && content.length > 0) {
|
|
1138
|
+
return content[0].text;
|
|
1139
|
+
}
|
|
1140
|
+
return null;
|
|
1141
|
+
}
|
|
1142
|
+
getCurrentMessageId(event) {
|
|
1143
|
+
var _a, _b, _c, _d, _e;
|
|
1144
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.id) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.id);
|
|
1145
|
+
}
|
|
1146
|
+
getCurrentToolCallChunks(event) {
|
|
1147
|
+
var _a, _b, _c, _d, _e;
|
|
1148
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.tool_call_chunks);
|
|
1149
|
+
}
|
|
1150
|
+
getResponseMetadata(event) {
|
|
1151
|
+
var _a, _b, _c, _d, _e;
|
|
1152
|
+
return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.response_metadata) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.response_metadata);
|
|
1153
|
+
}
|
|
1093
1154
|
processLangGraphEvents() {
|
|
1094
1155
|
let lastEventWithState = null;
|
|
1095
1156
|
return this.eventStream$.pipe(scan((acc, event) => {
|
|
1096
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
1097
1157
|
if (event.event === LangGraphEventTypes.OnChatModelStream) {
|
|
1098
|
-
const
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1113
|
-
acc.toolCallMessageId = toolCallMessageId;
|
|
1114
|
-
if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
|
|
1115
|
-
acc.toolCallName = toolCallChunks[0].name;
|
|
1116
|
-
}
|
|
1117
|
-
if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
|
|
1118
|
-
acc.toolCallId = toolCallChunks[0].id;
|
|
1119
|
-
}
|
|
1120
|
-
acc.prevMessageId = acc.messageId;
|
|
1121
|
-
acc.messageId = toolCallMessageId;
|
|
1122
|
-
} else if (acc.content && acc.content != "") {
|
|
1123
|
-
acc.prevMessageId = acc.messageId;
|
|
1124
|
-
acc.messageId = toolCallMessageId;
|
|
1125
|
-
} else {
|
|
1126
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1127
|
-
acc.prevMessageId = acc.messageId;
|
|
1128
|
-
}
|
|
1129
|
-
} else {
|
|
1130
|
-
acc.prevToolCallMessageId = acc.toolCallMessageId;
|
|
1131
|
-
acc.toolCallMessageId = null;
|
|
1132
|
-
acc.prevMessageId = acc.messageId;
|
|
1133
|
-
acc.messageId = null;
|
|
1134
|
-
acc.toolCallName = null;
|
|
1158
|
+
const prevMessageId = acc.lastMessageId;
|
|
1159
|
+
acc.currentContent = this.getCurrentContent(event);
|
|
1160
|
+
acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
|
|
1161
|
+
const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
|
|
1162
|
+
const responseMetadata = this.getResponseMetadata(event);
|
|
1163
|
+
acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
|
|
1164
|
+
acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
|
|
1165
|
+
acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
|
|
1166
|
+
acc.isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
|
|
1167
|
+
acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
|
|
1168
|
+
({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
|
|
1169
|
+
name: acc.lastToolCallName,
|
|
1170
|
+
id: acc.lastToolCallId
|
|
1171
|
+
});
|
|
1135
1172
|
}
|
|
1136
1173
|
acc.event = event;
|
|
1137
1174
|
lastEventWithState = acc;
|
|
1138
1175
|
return acc;
|
|
1139
1176
|
}, {
|
|
1140
1177
|
event: null,
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1178
|
+
isMessageStart: false,
|
|
1179
|
+
isMessageEnd: false,
|
|
1180
|
+
isToolCallStart: false,
|
|
1181
|
+
isToolCallEnd: false,
|
|
1182
|
+
isToolCall: false,
|
|
1183
|
+
lastMessageId: null,
|
|
1184
|
+
lastToolCallId: null,
|
|
1185
|
+
lastToolCallName: null,
|
|
1186
|
+
currentContent: null
|
|
1187
|
+
}), mergeMap((acc) => {
|
|
1150
1188
|
const events = [];
|
|
1151
1189
|
let shouldEmitMessages = true;
|
|
1152
|
-
let shouldEmitToolCalls =
|
|
1153
|
-
if (
|
|
1154
|
-
if ("copilotkit:emit-tool-calls" in (
|
|
1155
|
-
shouldEmitToolCalls =
|
|
1190
|
+
let shouldEmitToolCalls = true;
|
|
1191
|
+
if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
|
|
1192
|
+
if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
|
|
1193
|
+
shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
|
|
1156
1194
|
}
|
|
1157
|
-
if ("copilotkit:emit-messages" in (
|
|
1158
|
-
shouldEmitMessages =
|
|
1195
|
+
if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
|
|
1196
|
+
shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
|
|
1159
1197
|
}
|
|
1160
1198
|
}
|
|
1161
|
-
|
|
1199
|
+
const responseMetadata = this.getResponseMetadata(acc.event);
|
|
1200
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1162
1201
|
events.push({
|
|
1163
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1202
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1203
|
+
actionExecutionId: acc.lastToolCallId
|
|
1164
1204
|
});
|
|
1165
1205
|
}
|
|
1166
|
-
if (
|
|
1206
|
+
if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
|
|
1167
1207
|
events.push({
|
|
1168
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1208
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1209
|
+
messageId: acc.lastMessageId
|
|
1169
1210
|
});
|
|
1170
1211
|
}
|
|
1171
|
-
switch (
|
|
1212
|
+
switch (acc.event.event) {
|
|
1172
1213
|
case LangGraphEventTypes.OnCustomEvent:
|
|
1173
|
-
if (
|
|
1214
|
+
if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
|
|
1174
1215
|
events.push({
|
|
1175
1216
|
type: RuntimeEventTypes.TextMessageStart,
|
|
1176
|
-
messageId:
|
|
1217
|
+
messageId: acc.event.data.message_id
|
|
1177
1218
|
});
|
|
1178
1219
|
events.push({
|
|
1179
1220
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1180
|
-
|
|
1221
|
+
messageId: acc.event.data.message_id,
|
|
1222
|
+
content: acc.event.data.message
|
|
1181
1223
|
});
|
|
1182
1224
|
events.push({
|
|
1183
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1225
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1226
|
+
messageId: acc.event.data.message_id
|
|
1184
1227
|
});
|
|
1185
|
-
} else if (
|
|
1228
|
+
} else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
|
|
1186
1229
|
events.push({
|
|
1187
1230
|
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1188
|
-
actionExecutionId:
|
|
1189
|
-
actionName:
|
|
1231
|
+
actionExecutionId: acc.event.data.id,
|
|
1232
|
+
actionName: acc.event.data.name,
|
|
1233
|
+
parentMessageId: acc.event.data.id
|
|
1190
1234
|
});
|
|
1191
1235
|
events.push({
|
|
1192
1236
|
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1193
|
-
|
|
1237
|
+
actionExecutionId: acc.event.data.id,
|
|
1238
|
+
args: JSON.stringify(acc.event.data.args)
|
|
1194
1239
|
});
|
|
1195
1240
|
events.push({
|
|
1196
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1241
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1242
|
+
actionExecutionId: acc.event.data.id
|
|
1197
1243
|
});
|
|
1198
1244
|
}
|
|
1199
1245
|
break;
|
|
1200
1246
|
case LangGraphEventTypes.OnCopilotKitStateSync:
|
|
1201
1247
|
events.push({
|
|
1202
1248
|
type: RuntimeEventTypes.AgentStateMessage,
|
|
1203
|
-
threadId:
|
|
1204
|
-
role:
|
|
1205
|
-
agentName:
|
|
1206
|
-
nodeName:
|
|
1207
|
-
runId:
|
|
1208
|
-
active:
|
|
1209
|
-
state: JSON.stringify(
|
|
1210
|
-
running:
|
|
1249
|
+
threadId: acc.event.thread_id,
|
|
1250
|
+
role: acc.event.role,
|
|
1251
|
+
agentName: acc.event.agent_name,
|
|
1252
|
+
nodeName: acc.event.node_name,
|
|
1253
|
+
runId: acc.event.run_id,
|
|
1254
|
+
active: acc.event.active,
|
|
1255
|
+
state: JSON.stringify(acc.event.state),
|
|
1256
|
+
running: acc.event.running
|
|
1211
1257
|
});
|
|
1212
1258
|
break;
|
|
1213
|
-
case LangGraphEventTypes.OnToolEnd:
|
|
1214
|
-
break;
|
|
1215
1259
|
case LangGraphEventTypes.OnChatModelStream:
|
|
1216
|
-
if (
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
type: RuntimeEventTypes.TextMessageStart,
|
|
1229
|
-
messageId: eventWithState.messageId
|
|
1230
|
-
});
|
|
1231
|
-
}
|
|
1260
|
+
if (acc.isToolCallStart && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1261
|
+
events.push({
|
|
1262
|
+
type: RuntimeEventTypes.ActionExecutionStart,
|
|
1263
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1264
|
+
actionName: acc.lastToolCallName,
|
|
1265
|
+
parentMessageId: acc.lastMessageId
|
|
1266
|
+
});
|
|
1267
|
+
} else if (acc.isMessageStart && shouldEmitMessages) {
|
|
1268
|
+
events.push({
|
|
1269
|
+
type: RuntimeEventTypes.TextMessageStart,
|
|
1270
|
+
messageId: acc.lastMessageId
|
|
1271
|
+
});
|
|
1232
1272
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
events.push({
|
|
1246
|
-
type: RuntimeEventTypes.TextMessageContent,
|
|
1247
|
-
content
|
|
1248
|
-
});
|
|
1249
|
-
}
|
|
1273
|
+
if (acc.isToolCall && acc.currentContent && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
|
|
1274
|
+
events.push({
|
|
1275
|
+
type: RuntimeEventTypes.ActionExecutionArgs,
|
|
1276
|
+
actionExecutionId: acc.lastToolCallId,
|
|
1277
|
+
args: acc.currentContent
|
|
1278
|
+
});
|
|
1279
|
+
} else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
|
|
1280
|
+
events.push({
|
|
1281
|
+
type: RuntimeEventTypes.TextMessageContent,
|
|
1282
|
+
messageId: acc.lastMessageId,
|
|
1283
|
+
content: acc.currentContent
|
|
1284
|
+
});
|
|
1250
1285
|
}
|
|
1251
1286
|
break;
|
|
1252
1287
|
}
|
|
@@ -1254,14 +1289,16 @@ var RemoteLangGraphEventSource = class {
|
|
|
1254
1289
|
}), catchError((error) => {
|
|
1255
1290
|
console.error(error);
|
|
1256
1291
|
const events = [];
|
|
1257
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1292
|
+
if ((lastEventWithState == null ? void 0 : lastEventWithState.lastMessageId) && !lastEventWithState.isToolCall) {
|
|
1258
1293
|
events.push({
|
|
1259
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1294
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1295
|
+
messageId: lastEventWithState.lastMessageId
|
|
1260
1296
|
});
|
|
1261
1297
|
}
|
|
1262
|
-
if (lastEventWithState == null ? void 0 : lastEventWithState.
|
|
1298
|
+
if (lastEventWithState == null ? void 0 : lastEventWithState.lastToolCallId) {
|
|
1263
1299
|
events.push({
|
|
1264
|
-
type: RuntimeEventTypes.ActionExecutionEnd
|
|
1300
|
+
type: RuntimeEventTypes.ActionExecutionEnd,
|
|
1301
|
+
actionExecutionId: lastEventWithState.lastToolCallId
|
|
1265
1302
|
});
|
|
1266
1303
|
}
|
|
1267
1304
|
const messageId = randomId();
|
|
@@ -1271,10 +1308,12 @@ var RemoteLangGraphEventSource = class {
|
|
|
1271
1308
|
});
|
|
1272
1309
|
events.push({
|
|
1273
1310
|
type: RuntimeEventTypes.TextMessageContent,
|
|
1311
|
+
messageId,
|
|
1274
1312
|
content: "\u274C An error occurred. Please try again."
|
|
1275
1313
|
});
|
|
1276
1314
|
events.push({
|
|
1277
|
-
type: RuntimeEventTypes.TextMessageEnd
|
|
1315
|
+
type: RuntimeEventTypes.TextMessageEnd,
|
|
1316
|
+
messageId
|
|
1278
1317
|
});
|
|
1279
1318
|
return events;
|
|
1280
1319
|
}));
|
|
@@ -1332,7 +1371,7 @@ async function streamEvents(controller, args) {
|
|
|
1332
1371
|
const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
|
|
1333
1372
|
let formattedMessages = [];
|
|
1334
1373
|
try {
|
|
1335
|
-
formattedMessages =
|
|
1374
|
+
formattedMessages = copilotkitMessagesToLangChain(messages);
|
|
1336
1375
|
} catch (e) {
|
|
1337
1376
|
logger2.error(e, `Error event thrown: ${e.message}`);
|
|
1338
1377
|
}
|
|
@@ -1485,7 +1524,8 @@ async function streamEvents(controller, args) {
|
|
|
1485
1524
|
nodeName: isEndNode ? "__end__" : nodeName,
|
|
1486
1525
|
state: state.values,
|
|
1487
1526
|
running: !shouldExit,
|
|
1488
|
-
active: false
|
|
1527
|
+
active: false,
|
|
1528
|
+
includeMessages: true
|
|
1489
1529
|
}));
|
|
1490
1530
|
return Promise.resolve();
|
|
1491
1531
|
} catch (e) {
|
|
@@ -1498,13 +1538,20 @@ async function streamEvents(controller, args) {
|
|
|
1498
1538
|
}
|
|
1499
1539
|
}
|
|
1500
1540
|
__name(streamEvents, "streamEvents");
|
|
1501
|
-
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1541
|
+
function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
|
|
1542
|
+
if (!includeMessages) {
|
|
1543
|
+
state = Object.keys(state).reduce((acc, key) => {
|
|
1544
|
+
if (key !== "messages") {
|
|
1545
|
+
acc[key] = state[key];
|
|
1546
|
+
}
|
|
1547
|
+
return acc;
|
|
1548
|
+
}, {});
|
|
1549
|
+
} else {
|
|
1550
|
+
state = {
|
|
1551
|
+
...state,
|
|
1552
|
+
messages: langchainMessagesToCopilotKit(state.messages || [])
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1508
1555
|
return JSON.stringify({
|
|
1509
1556
|
event: LangGraphEventTypes.OnCopilotKitStateSync,
|
|
1510
1557
|
thread_id: threadId,
|
|
@@ -1512,7 +1559,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
|
|
|
1512
1559
|
agent_name: agentName,
|
|
1513
1560
|
node_name: nodeName,
|
|
1514
1561
|
active,
|
|
1515
|
-
state
|
|
1562
|
+
state,
|
|
1516
1563
|
running,
|
|
1517
1564
|
role: "assistant"
|
|
1518
1565
|
}) + "\n";
|
|
@@ -1588,134 +1635,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
|
|
|
1588
1635
|
if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
|
|
1589
1636
|
messages = messages.slice(1);
|
|
1590
1637
|
}
|
|
1591
|
-
const
|
|
1592
|
-
const existingMessageIds = new Set(
|
|
1593
|
-
const
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1638
|
+
const existingMessages = state.messages || [];
|
|
1639
|
+
const existingMessageIds = new Set(existingMessages.map((message) => message.id));
|
|
1640
|
+
const newMessages = messages.filter((message) => !existingMessageIds.has(message.id));
|
|
1641
|
+
return {
|
|
1642
|
+
...state,
|
|
1643
|
+
messages: newMessages,
|
|
1644
|
+
copilotkit: {
|
|
1645
|
+
actions
|
|
1646
|
+
}
|
|
1647
|
+
};
|
|
1648
|
+
}
|
|
1649
|
+
__name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
|
|
1650
|
+
function langchainMessagesToCopilotKit(messages) {
|
|
1651
|
+
const result = [];
|
|
1652
|
+
const tool_call_names = {};
|
|
1653
|
+
for (const message of messages) {
|
|
1654
|
+
if (message.type === "ai") {
|
|
1655
|
+
for (const tool_call of message.tool_calls) {
|
|
1656
|
+
tool_call_names[tool_call.id] = tool_call.name;
|
|
1657
|
+
}
|
|
1597
1658
|
}
|
|
1598
1659
|
}
|
|
1599
1660
|
for (const message of messages) {
|
|
1600
|
-
|
|
1601
|
-
|
|
1661
|
+
let content = message.content;
|
|
1662
|
+
if (content instanceof Array) {
|
|
1663
|
+
content = content[0];
|
|
1602
1664
|
}
|
|
1603
|
-
if (
|
|
1604
|
-
|
|
1665
|
+
if (content instanceof Object) {
|
|
1666
|
+
content = content.text;
|
|
1605
1667
|
}
|
|
1606
|
-
if (
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
} else {
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1668
|
+
if (message.type === "human") {
|
|
1669
|
+
result.push({
|
|
1670
|
+
role: "user",
|
|
1671
|
+
content,
|
|
1672
|
+
id: message.id
|
|
1673
|
+
});
|
|
1674
|
+
} else if (message.type === "system") {
|
|
1675
|
+
result.push({
|
|
1676
|
+
role: "system",
|
|
1677
|
+
content,
|
|
1678
|
+
id: message.id
|
|
1679
|
+
});
|
|
1680
|
+
} else if (message.type === "ai") {
|
|
1681
|
+
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
1682
|
+
for (const tool_call of message.tool_calls) {
|
|
1683
|
+
result.push({
|
|
1684
|
+
id: tool_call.id,
|
|
1685
|
+
name: tool_call.name,
|
|
1686
|
+
arguments: tool_call.args,
|
|
1687
|
+
parentMessageId: message.id
|
|
1688
|
+
});
|
|
1620
1689
|
}
|
|
1690
|
+
} else {
|
|
1691
|
+
result.push({
|
|
1692
|
+
role: "assistant",
|
|
1693
|
+
content,
|
|
1694
|
+
id: message.id,
|
|
1695
|
+
parentMessageId: message.id
|
|
1696
|
+
});
|
|
1621
1697
|
}
|
|
1698
|
+
} else if (message.type === "tool") {
|
|
1699
|
+
const actionName = tool_call_names[message.tool_call_id] || message.name || "";
|
|
1700
|
+
result.push({
|
|
1701
|
+
actionExecutionId: message.tool_call_id,
|
|
1702
|
+
actionName,
|
|
1703
|
+
result: content,
|
|
1704
|
+
id: message.id
|
|
1705
|
+
});
|
|
1622
1706
|
}
|
|
1623
1707
|
}
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
|
|
1708
|
+
const resultsDict = {};
|
|
1709
|
+
for (const msg of result) {
|
|
1710
|
+
if (msg.actionExecutionId) {
|
|
1711
|
+
resultsDict[msg.actionExecutionId] = msg;
|
|
1629
1712
|
}
|
|
1630
1713
|
}
|
|
1631
|
-
const
|
|
1632
|
-
for (
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
const prevMessage = mergedMessages[i - 1] || null;
|
|
1636
|
-
if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
|
|
1637
|
-
if (!nextMessage) {
|
|
1638
|
-
console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1639
|
-
continue;
|
|
1640
|
-
}
|
|
1641
|
-
if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
|
|
1642
|
-
const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
|
|
1643
|
-
if (toolMessage) {
|
|
1644
|
-
console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
|
|
1645
|
-
correctedMessages.push(currentMessage, toolMessage);
|
|
1646
|
-
continue;
|
|
1647
|
-
} else {
|
|
1648
|
-
console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
|
|
1649
|
-
continue;
|
|
1650
|
-
}
|
|
1651
|
-
}
|
|
1652
|
-
correctedMessages.push(currentMessage);
|
|
1653
|
-
continue;
|
|
1714
|
+
const reorderedResult = [];
|
|
1715
|
+
for (const msg of result) {
|
|
1716
|
+
if (!("actionExecutionId" in msg)) {
|
|
1717
|
+
reorderedResult.push(msg);
|
|
1654
1718
|
}
|
|
1655
|
-
if ("
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1719
|
+
if ("arguments" in msg) {
|
|
1720
|
+
const msgId = msg.id;
|
|
1721
|
+
if (msgId in resultsDict) {
|
|
1722
|
+
reorderedResult.push(resultsDict[msgId]);
|
|
1659
1723
|
}
|
|
1660
|
-
if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
|
|
1661
|
-
console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
|
|
1662
|
-
continue;
|
|
1663
|
-
}
|
|
1664
|
-
correctedMessages.push(currentMessage);
|
|
1665
|
-
continue;
|
|
1666
1724
|
}
|
|
1667
|
-
correctedMessages.push(currentMessage);
|
|
1668
1725
|
}
|
|
1669
|
-
return
|
|
1670
|
-
...state,
|
|
1671
|
-
messages: correctedMessages,
|
|
1672
|
-
copilotkit: {
|
|
1673
|
-
actions
|
|
1674
|
-
}
|
|
1675
|
-
};
|
|
1726
|
+
return reorderedResult;
|
|
1676
1727
|
}
|
|
1677
|
-
__name(
|
|
1678
|
-
function
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1728
|
+
__name(langchainMessagesToCopilotKit, "langchainMessagesToCopilotKit");
|
|
1729
|
+
function copilotkitMessagesToLangChain(messages) {
|
|
1730
|
+
const result = [];
|
|
1731
|
+
const processedActionExecutions = /* @__PURE__ */ new Set();
|
|
1732
|
+
for (const message of messages) {
|
|
1733
|
+
if (message.isTextMessage()) {
|
|
1734
|
+
if (message.role === "user") {
|
|
1735
|
+
result.push({
|
|
1736
|
+
...message,
|
|
1737
|
+
role: MessageRole.user
|
|
1738
|
+
});
|
|
1739
|
+
} else if (message.role === "system") {
|
|
1740
|
+
result.push({
|
|
1741
|
+
...message,
|
|
1742
|
+
role: MessageRole.system
|
|
1743
|
+
});
|
|
1744
|
+
} else if (message.role === "assistant") {
|
|
1745
|
+
result.push({
|
|
1746
|
+
...message,
|
|
1747
|
+
role: MessageRole.assistant
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
continue;
|
|
1688
1751
|
}
|
|
1689
1752
|
if (message.isActionExecutionMessage()) {
|
|
1690
|
-
const
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1753
|
+
const messageId = message.parentMessageId ?? message.id;
|
|
1754
|
+
if (processedActionExecutions.has(messageId)) {
|
|
1755
|
+
continue;
|
|
1756
|
+
}
|
|
1757
|
+
processedActionExecutions.add(messageId);
|
|
1758
|
+
const relatedActionExecutions = messages.filter((m) => m.isActionExecutionMessage() && (m.parentMessageId && m.parentMessageId === messageId || m.id === messageId));
|
|
1759
|
+
const tool_calls = relatedActionExecutions.map((m) => ({
|
|
1760
|
+
name: m.name,
|
|
1761
|
+
args: m.arguments,
|
|
1762
|
+
id: m.id
|
|
1763
|
+
}));
|
|
1764
|
+
result.push({
|
|
1765
|
+
id: messageId,
|
|
1766
|
+
type: "ActionExecutionMessage",
|
|
1697
1767
|
content: "",
|
|
1698
|
-
tool_calls
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
id: message.id
|
|
1703
|
-
};
|
|
1768
|
+
tool_calls,
|
|
1769
|
+
role: MessageRole.assistant
|
|
1770
|
+
});
|
|
1771
|
+
continue;
|
|
1704
1772
|
}
|
|
1705
1773
|
if (message.isResultMessage()) {
|
|
1706
|
-
|
|
1774
|
+
result.push({
|
|
1707
1775
|
type: message.type,
|
|
1708
1776
|
content: message.result,
|
|
1709
1777
|
id: message.id,
|
|
1710
1778
|
tool_call_id: message.actionExecutionId,
|
|
1711
1779
|
name: message.actionName,
|
|
1712
1780
|
role: MessageRole.tool
|
|
1713
|
-
};
|
|
1781
|
+
});
|
|
1782
|
+
continue;
|
|
1714
1783
|
}
|
|
1715
1784
|
throw new Error(`Unknown message type ${message.type}`);
|
|
1716
|
-
}
|
|
1785
|
+
}
|
|
1786
|
+
return result;
|
|
1717
1787
|
}
|
|
1718
|
-
__name(
|
|
1788
|
+
__name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
|
|
1719
1789
|
|
|
1720
1790
|
// src/lib/runtime/remote-action-constructors.ts
|
|
1721
1791
|
function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
@@ -1725,7 +1795,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1725
1795
|
parameters: [],
|
|
1726
1796
|
handler: async (_args) => {
|
|
1727
1797
|
},
|
|
1728
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1798
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1729
1799
|
var _a;
|
|
1730
1800
|
logger2.debug({
|
|
1731
1801
|
actionName: agent.name
|
|
@@ -1751,7 +1821,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1751
1821
|
agent,
|
|
1752
1822
|
threadId,
|
|
1753
1823
|
nodeName,
|
|
1754
|
-
messages
|
|
1824
|
+
messages: [
|
|
1825
|
+
...messages,
|
|
1826
|
+
...additionalMessages
|
|
1827
|
+
],
|
|
1755
1828
|
state,
|
|
1756
1829
|
properties: graphqlContext.properties,
|
|
1757
1830
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1779,6 +1852,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
|
|
|
1779
1852
|
}
|
|
1780
1853
|
__name(constructLGCRemoteAction, "constructLGCRemoteAction");
|
|
1781
1854
|
function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
|
|
1855
|
+
const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
|
|
1782
1856
|
const actions = json["actions"].map((action) => ({
|
|
1783
1857
|
name: action.name,
|
|
1784
1858
|
description: action.description,
|
|
@@ -1792,7 +1866,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1792
1866
|
telemetry_client_default.capture("oss.runtime.remote_action_executed", {
|
|
1793
1867
|
agentExecution: false,
|
|
1794
1868
|
type: "self-hosted",
|
|
1795
|
-
agentsAmount:
|
|
1869
|
+
agentsAmount: totalAgents
|
|
1796
1870
|
});
|
|
1797
1871
|
try {
|
|
1798
1872
|
const response = await fetch(`${url}/actions/execute`, {
|
|
@@ -1827,13 +1901,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1827
1901
|
}
|
|
1828
1902
|
}
|
|
1829
1903
|
}));
|
|
1830
|
-
const agents = json["agents"].map((agent) => ({
|
|
1904
|
+
const agents = totalAgents ? json["agents"].map((agent) => ({
|
|
1831
1905
|
name: agent.name,
|
|
1832
1906
|
description: agent.description,
|
|
1833
1907
|
parameters: [],
|
|
1834
1908
|
handler: async (_args) => {
|
|
1835
1909
|
},
|
|
1836
|
-
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
|
|
1910
|
+
langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
|
|
1837
1911
|
var _a;
|
|
1838
1912
|
logger2.debug({
|
|
1839
1913
|
actionName: agent.name
|
|
@@ -1858,7 +1932,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1858
1932
|
name,
|
|
1859
1933
|
threadId,
|
|
1860
1934
|
nodeName,
|
|
1861
|
-
messages
|
|
1935
|
+
messages: [
|
|
1936
|
+
...messages,
|
|
1937
|
+
...additionalMessages
|
|
1938
|
+
],
|
|
1862
1939
|
state,
|
|
1863
1940
|
properties: graphqlContext.properties,
|
|
1864
1941
|
actions: actionInputsWithoutAgents.map((action) => ({
|
|
@@ -1880,7 +1957,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
|
|
|
1880
1957
|
streamResponse(response.body, eventSource.eventStream$);
|
|
1881
1958
|
return eventSource.processLangGraphEvents();
|
|
1882
1959
|
}
|
|
1883
|
-
}));
|
|
1960
|
+
})) : [];
|
|
1884
1961
|
return [
|
|
1885
1962
|
...actions,
|
|
1886
1963
|
...agents
|
|
@@ -2058,7 +2135,7 @@ __name(setupRemoteActions, "setupRemoteActions");
|
|
|
2058
2135
|
import { createHash as createHash3 } from "crypto";
|
|
2059
2136
|
|
|
2060
2137
|
// src/lib/runtime/copilot-runtime.ts
|
|
2061
|
-
import { actionParametersToJsonSchema
|
|
2138
|
+
import { actionParametersToJsonSchema } from "@copilotkit/shared";
|
|
2062
2139
|
|
|
2063
2140
|
// src/service-adapters/conversion.ts
|
|
2064
2141
|
import { plainToInstance } from "class-transformer";
|
|
@@ -2070,7 +2147,8 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2070
2147
|
id: message.id,
|
|
2071
2148
|
createdAt: message.createdAt,
|
|
2072
2149
|
role: message.textMessage.role,
|
|
2073
|
-
content: message.textMessage.content
|
|
2150
|
+
content: message.textMessage.content,
|
|
2151
|
+
parentMessageId: message.textMessage.parentMessageId
|
|
2074
2152
|
}));
|
|
2075
2153
|
} else if (message.actionExecutionMessage) {
|
|
2076
2154
|
messages.push(plainToInstance(ActionExecutionMessage, {
|
|
@@ -2078,7 +2156,7 @@ function convertGqlInputToMessages(inputMessages) {
|
|
|
2078
2156
|
createdAt: message.createdAt,
|
|
2079
2157
|
name: message.actionExecutionMessage.name,
|
|
2080
2158
|
arguments: JSON.parse(message.actionExecutionMessage.arguments),
|
|
2081
|
-
|
|
2159
|
+
parentMessageId: message.actionExecutionMessage.parentMessageId
|
|
2082
2160
|
}));
|
|
2083
2161
|
} else if (message.resultMessage) {
|
|
2084
2162
|
messages.push(plainToInstance(ResultMessage, {
|
|
@@ -2189,13 +2267,7 @@ var CopilotRuntime = class {
|
|
|
2189
2267
|
} catch (error) {
|
|
2190
2268
|
console.error("Error getting response:", error);
|
|
2191
2269
|
eventSource.sendErrorMessageToChat();
|
|
2192
|
-
|
|
2193
|
-
threadId: threadId || randomId2(),
|
|
2194
|
-
runId: runId || randomId2(),
|
|
2195
|
-
eventSource,
|
|
2196
|
-
serverSideActions: [],
|
|
2197
|
-
actionInputsWithoutAgents: []
|
|
2198
|
-
};
|
|
2270
|
+
throw error;
|
|
2199
2271
|
}
|
|
2200
2272
|
}
|
|
2201
2273
|
async processAgentRequest(request) {
|
|
@@ -2381,6 +2453,7 @@ __name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
|
|
|
2381
2453
|
var telemetry_client_default = telemetryClient;
|
|
2382
2454
|
|
|
2383
2455
|
// src/service-adapters/events.ts
|
|
2456
|
+
import { plainToInstance as plainToInstance2 } from "class-transformer";
|
|
2384
2457
|
var RuntimeEventTypes;
|
|
2385
2458
|
(function(RuntimeEventTypes2) {
|
|
2386
2459
|
RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
|
|
@@ -2396,52 +2469,74 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2396
2469
|
constructor() {
|
|
2397
2470
|
super();
|
|
2398
2471
|
}
|
|
2399
|
-
sendTextMessageStart(messageId) {
|
|
2472
|
+
sendTextMessageStart({ messageId, parentMessageId }) {
|
|
2400
2473
|
this.next({
|
|
2401
2474
|
type: "TextMessageStart",
|
|
2402
|
-
messageId
|
|
2475
|
+
messageId,
|
|
2476
|
+
parentMessageId
|
|
2403
2477
|
});
|
|
2404
2478
|
}
|
|
2405
|
-
sendTextMessageContent(content) {
|
|
2479
|
+
sendTextMessageContent({ messageId, content }) {
|
|
2406
2480
|
this.next({
|
|
2407
2481
|
type: "TextMessageContent",
|
|
2408
|
-
content
|
|
2482
|
+
content,
|
|
2483
|
+
messageId
|
|
2409
2484
|
});
|
|
2410
2485
|
}
|
|
2411
|
-
sendTextMessageEnd() {
|
|
2486
|
+
sendTextMessageEnd({ messageId }) {
|
|
2412
2487
|
this.next({
|
|
2413
|
-
type: "TextMessageEnd"
|
|
2488
|
+
type: "TextMessageEnd",
|
|
2489
|
+
messageId
|
|
2414
2490
|
});
|
|
2415
2491
|
}
|
|
2416
2492
|
sendTextMessage(messageId, content) {
|
|
2417
|
-
this.sendTextMessageStart(
|
|
2418
|
-
|
|
2419
|
-
|
|
2493
|
+
this.sendTextMessageStart({
|
|
2494
|
+
messageId
|
|
2495
|
+
});
|
|
2496
|
+
this.sendTextMessageContent({
|
|
2497
|
+
messageId,
|
|
2498
|
+
content
|
|
2499
|
+
});
|
|
2500
|
+
this.sendTextMessageEnd({
|
|
2501
|
+
messageId
|
|
2502
|
+
});
|
|
2420
2503
|
}
|
|
2421
|
-
sendActionExecutionStart(actionExecutionId, actionName) {
|
|
2504
|
+
sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
|
|
2422
2505
|
this.next({
|
|
2423
2506
|
type: "ActionExecutionStart",
|
|
2424
2507
|
actionExecutionId,
|
|
2425
|
-
actionName
|
|
2508
|
+
actionName,
|
|
2509
|
+
parentMessageId
|
|
2426
2510
|
});
|
|
2427
2511
|
}
|
|
2428
|
-
sendActionExecutionArgs(args) {
|
|
2512
|
+
sendActionExecutionArgs({ actionExecutionId, args }) {
|
|
2429
2513
|
this.next({
|
|
2430
2514
|
type: "ActionExecutionArgs",
|
|
2431
|
-
args
|
|
2515
|
+
args,
|
|
2516
|
+
actionExecutionId
|
|
2432
2517
|
});
|
|
2433
2518
|
}
|
|
2434
|
-
sendActionExecutionEnd() {
|
|
2519
|
+
sendActionExecutionEnd({ actionExecutionId }) {
|
|
2435
2520
|
this.next({
|
|
2436
|
-
type: "ActionExecutionEnd"
|
|
2521
|
+
type: "ActionExecutionEnd",
|
|
2522
|
+
actionExecutionId
|
|
2437
2523
|
});
|
|
2438
2524
|
}
|
|
2439
|
-
sendActionExecution(actionExecutionId,
|
|
2440
|
-
this.sendActionExecutionStart(
|
|
2441
|
-
|
|
2442
|
-
|
|
2525
|
+
sendActionExecution({ actionExecutionId, actionName, args, parentMessageId }) {
|
|
2526
|
+
this.sendActionExecutionStart({
|
|
2527
|
+
actionExecutionId,
|
|
2528
|
+
actionName,
|
|
2529
|
+
parentMessageId
|
|
2530
|
+
});
|
|
2531
|
+
this.sendActionExecutionArgs({
|
|
2532
|
+
actionExecutionId,
|
|
2533
|
+
args
|
|
2534
|
+
});
|
|
2535
|
+
this.sendActionExecutionEnd({
|
|
2536
|
+
actionExecutionId
|
|
2537
|
+
});
|
|
2443
2538
|
}
|
|
2444
|
-
sendActionExecutionResult(actionExecutionId, actionName, result) {
|
|
2539
|
+
sendActionExecutionResult({ actionExecutionId, actionName, result }) {
|
|
2445
2540
|
this.next({
|
|
2446
2541
|
type: "ActionExecutionResult",
|
|
2447
2542
|
actionName,
|
|
@@ -2449,7 +2544,7 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
|
|
|
2449
2544
|
result
|
|
2450
2545
|
});
|
|
2451
2546
|
}
|
|
2452
|
-
sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
|
|
2547
|
+
sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
|
|
2453
2548
|
this.next({
|
|
2454
2549
|
type: "AgentStateMessage",
|
|
2455
2550
|
threadId,
|
|
@@ -2470,14 +2565,14 @@ var RuntimeEventSource = class {
|
|
|
2470
2565
|
async stream(callback) {
|
|
2471
2566
|
this.callback = callback;
|
|
2472
2567
|
}
|
|
2473
|
-
sendErrorMessageToChat() {
|
|
2474
|
-
const errorMessage =
|
|
2568
|
+
sendErrorMessageToChat(message = "An error occurred. Please try again.") {
|
|
2569
|
+
const errorMessage = `\u274C ${message}`;
|
|
2475
2570
|
if (!this.callback) {
|
|
2476
2571
|
this.stream(async (eventStream$) => {
|
|
2477
|
-
eventStream$.sendTextMessage(
|
|
2572
|
+
eventStream$.sendTextMessage(randomId2(), errorMessage);
|
|
2478
2573
|
});
|
|
2479
2574
|
} else {
|
|
2480
|
-
this.eventStream$.sendTextMessage(
|
|
2575
|
+
this.eventStream$.sendTextMessage(randomId2(), errorMessage);
|
|
2481
2576
|
}
|
|
2482
2577
|
}
|
|
2483
2578
|
processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
|
|
@@ -2486,27 +2581,19 @@ var RuntimeEventSource = class {
|
|
|
2486
2581
|
this.sendErrorMessageToChat();
|
|
2487
2582
|
});
|
|
2488
2583
|
return this.eventStream$.pipe(
|
|
2489
|
-
// mark tools for server side execution
|
|
2490
|
-
map((event) => {
|
|
2491
|
-
if (event.type === "ActionExecutionStart") {
|
|
2492
|
-
if (event.scope !== "passThrough") {
|
|
2493
|
-
event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
|
|
2494
|
-
}
|
|
2495
|
-
}
|
|
2496
|
-
return event;
|
|
2497
|
-
}),
|
|
2498
2584
|
// track state
|
|
2499
2585
|
scan2((acc, event) => {
|
|
2500
2586
|
acc = {
|
|
2501
2587
|
...acc
|
|
2502
2588
|
};
|
|
2503
2589
|
if (event.type === "ActionExecutionStart") {
|
|
2504
|
-
acc.callActionServerSide =
|
|
2590
|
+
acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
|
|
2505
2591
|
acc.args = "";
|
|
2506
2592
|
acc.actionExecutionId = event.actionExecutionId;
|
|
2507
2593
|
if (acc.callActionServerSide) {
|
|
2508
2594
|
acc.action = serverSideActions.find((action) => action.name === event.actionName);
|
|
2509
2595
|
}
|
|
2596
|
+
acc.actionExecutionParentMessageId = event.parentMessageId;
|
|
2510
2597
|
} else if (event.type === "ActionExecutionArgs") {
|
|
2511
2598
|
acc.args += event.args;
|
|
2512
2599
|
}
|
|
@@ -2517,12 +2604,13 @@ var RuntimeEventSource = class {
|
|
|
2517
2604
|
callActionServerSide: false,
|
|
2518
2605
|
args: "",
|
|
2519
2606
|
actionExecutionId: null,
|
|
2520
|
-
action: null
|
|
2607
|
+
action: null,
|
|
2608
|
+
actionExecutionParentMessageId: null
|
|
2521
2609
|
}),
|
|
2522
2610
|
concatMap((eventWithState) => {
|
|
2523
2611
|
if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
|
|
2524
2612
|
const toolCallEventStream$ = new RuntimeEventSubject();
|
|
2525
|
-
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2613
|
+
executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionParentMessageId, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
|
|
2526
2614
|
console.error(error);
|
|
2527
2615
|
});
|
|
2528
2616
|
telemetry_client_default.capture("oss.runtime.server_action_executed", {});
|
|
@@ -2535,7 +2623,7 @@ var RuntimeEventSource = class {
|
|
|
2535
2623
|
}
|
|
2536
2624
|
};
|
|
2537
2625
|
__name(RuntimeEventSource, "RuntimeEventSource");
|
|
2538
|
-
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
|
|
2626
|
+
async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
|
|
2539
2627
|
var _a;
|
|
2540
2628
|
if (guardrailsResult$) {
|
|
2541
2629
|
const { status } = await firstValueFrom(guardrailsResult$);
|
|
@@ -2555,10 +2643,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
|
|
|
2555
2643
|
}
|
|
2556
2644
|
}
|
|
2557
2645
|
if (isLangGraphAgentAction(action)) {
|
|
2558
|
-
|
|
2646
|
+
const result = `${action.name} agent started`;
|
|
2647
|
+
const agentExecution = plainToInstance2(ActionExecutionMessage, {
|
|
2648
|
+
id: actionExecutionId,
|
|
2649
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2650
|
+
name: action.name,
|
|
2651
|
+
arguments: JSON.parse(actionArguments),
|
|
2652
|
+
parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
|
|
2653
|
+
});
|
|
2654
|
+
const agentExecutionResult = plainToInstance2(ResultMessage, {
|
|
2655
|
+
id: "result-" + actionExecutionId,
|
|
2656
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
2657
|
+
actionExecutionId,
|
|
2658
|
+
actionName: action.name,
|
|
2659
|
+
result
|
|
2660
|
+
});
|
|
2661
|
+
eventStream$.sendActionExecutionResult({
|
|
2662
|
+
actionExecutionId,
|
|
2663
|
+
actionName: action.name,
|
|
2664
|
+
result
|
|
2665
|
+
});
|
|
2559
2666
|
const stream = await action.langGraphAgentHandler({
|
|
2560
2667
|
name: action.name,
|
|
2561
|
-
actionInputsWithoutAgents
|
|
2668
|
+
actionInputsWithoutAgents,
|
|
2669
|
+
additionalMessages: [
|
|
2670
|
+
agentExecution,
|
|
2671
|
+
agentExecutionResult
|
|
2672
|
+
]
|
|
2562
2673
|
});
|
|
2563
2674
|
from2(stream).subscribe({
|
|
2564
2675
|
next: (event) => eventStream$.next(event),
|
|
@@ -2581,9 +2692,9 @@ __name(executeAction, "executeAction");
|
|
|
2581
2692
|
|
|
2582
2693
|
// src/graphql/resolvers/copilot.resolver.ts
|
|
2583
2694
|
import { GraphQLJSONObject } from "graphql-scalars";
|
|
2584
|
-
import { plainToInstance as
|
|
2695
|
+
import { plainToInstance as plainToInstance3 } from "class-transformer";
|
|
2585
2696
|
import { GraphQLError } from "graphql";
|
|
2586
|
-
import { randomId as
|
|
2697
|
+
import { randomId as randomId3 } from "@copilotkit/shared";
|
|
2587
2698
|
function _ts_decorate12(decorators, target, key, desc) {
|
|
2588
2699
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
2589
2700
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
|
|
@@ -2700,7 +2811,7 @@ var CopilotResolver = class {
|
|
|
2700
2811
|
rejectOutputMessagesPromise = reject;
|
|
2701
2812
|
});
|
|
2702
2813
|
logger2.debug("Processing");
|
|
2703
|
-
const { eventSource, threadId =
|
|
2814
|
+
const { eventSource, threadId = randomId3(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
|
|
2704
2815
|
serviceAdapter,
|
|
2705
2816
|
messages: data.messages,
|
|
2706
2817
|
actions: data.frontend.actions.filter((action) => action.available !== ActionInputAvailability.disabled),
|
|
@@ -2744,8 +2855,8 @@ var CopilotResolver = class {
|
|
|
2744
2855
|
reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
|
|
2745
2856
|
});
|
|
2746
2857
|
outputMessages = [
|
|
2747
|
-
|
|
2748
|
-
id:
|
|
2858
|
+
plainToInstance3(TextMessage, {
|
|
2859
|
+
id: randomId3(),
|
|
2749
2860
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2750
2861
|
content: result.reason,
|
|
2751
2862
|
role: MessageRole.assistant
|
|
@@ -2793,12 +2904,15 @@ var CopilotResolver = class {
|
|
|
2793
2904
|
// skip until this message start event
|
|
2794
2905
|
skipWhile((e) => e !== event),
|
|
2795
2906
|
// take until the message end event
|
|
2796
|
-
takeWhile((e) => e.type
|
|
2907
|
+
takeWhile((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
|
|
2908
|
+
// filter out any other message events or message ids
|
|
2909
|
+
filter((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
|
|
2797
2910
|
);
|
|
2798
2911
|
const streamingTextStatus = new Subject();
|
|
2799
2912
|
const messageId = event.messageId;
|
|
2800
2913
|
pushMessage({
|
|
2801
2914
|
id: messageId,
|
|
2915
|
+
parentMessageId: event.parentMessageId,
|
|
2802
2916
|
status: firstValueFrom2(streamingTextStatus),
|
|
2803
2917
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2804
2918
|
role: MessageRole.assistant,
|
|
@@ -2811,7 +2925,7 @@ var CopilotResolver = class {
|
|
|
2811
2925
|
reason,
|
|
2812
2926
|
messageId: messageId2
|
|
2813
2927
|
}, "Text streaming interrupted");
|
|
2814
|
-
streamingTextStatus.next(
|
|
2928
|
+
streamingTextStatus.next(plainToInstance3(FailedMessageStatus, {
|
|
2815
2929
|
reason
|
|
2816
2930
|
}));
|
|
2817
2931
|
responseStatus$.next(new MessageStreamInterruptedResponse({
|
|
@@ -2844,7 +2958,7 @@ var CopilotResolver = class {
|
|
|
2844
2958
|
streamingTextStatus.next(new SuccessMessageStatus());
|
|
2845
2959
|
stopStreamingText();
|
|
2846
2960
|
textSubscription == null ? void 0 : textSubscription.unsubscribe();
|
|
2847
|
-
outputMessages.push(
|
|
2961
|
+
outputMessages.push(plainToInstance3(TextMessage, {
|
|
2848
2962
|
id: messageId,
|
|
2849
2963
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2850
2964
|
content: textChunks.join(""),
|
|
@@ -2857,14 +2971,20 @@ var CopilotResolver = class {
|
|
|
2857
2971
|
break;
|
|
2858
2972
|
case RuntimeEventTypes.ActionExecutionStart:
|
|
2859
2973
|
logger2.debug("Action execution start event received");
|
|
2860
|
-
const actionExecutionArgumentStream = eventStream.pipe(
|
|
2974
|
+
const actionExecutionArgumentStream = eventStream.pipe(
|
|
2975
|
+
skipWhile((e) => e !== event),
|
|
2976
|
+
// take until the action execution end event
|
|
2977
|
+
takeWhile((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
|
|
2978
|
+
// filter out any other action execution events or action execution ids
|
|
2979
|
+
filter((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
|
|
2980
|
+
);
|
|
2861
2981
|
const streamingArgumentsStatus = new Subject();
|
|
2862
2982
|
pushMessage({
|
|
2863
2983
|
id: event.actionExecutionId,
|
|
2984
|
+
parentMessageId: event.parentMessageId,
|
|
2864
2985
|
status: firstValueFrom2(streamingArgumentsStatus),
|
|
2865
2986
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2866
2987
|
name: event.actionName,
|
|
2867
|
-
scope: event.scope,
|
|
2868
2988
|
arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
|
|
2869
2989
|
logger2.debug("Action execution argument stream created");
|
|
2870
2990
|
const argumentChunks = [];
|
|
@@ -2880,7 +3000,7 @@ var CopilotResolver = class {
|
|
|
2880
3000
|
logger2.error({
|
|
2881
3001
|
err
|
|
2882
3002
|
}, "Error in action execution argument stream");
|
|
2883
|
-
streamingArgumentsStatus.next(
|
|
3003
|
+
streamingArgumentsStatus.next(plainToInstance3(FailedMessageStatus, {
|
|
2884
3004
|
reason: "An unknown error has occurred in the action execution argument stream"
|
|
2885
3005
|
}));
|
|
2886
3006
|
stopStreamingArguments();
|
|
@@ -2891,11 +3011,10 @@ var CopilotResolver = class {
|
|
|
2891
3011
|
streamingArgumentsStatus.next(new SuccessMessageStatus());
|
|
2892
3012
|
stopStreamingArguments();
|
|
2893
3013
|
actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
|
|
2894
|
-
outputMessages.push(
|
|
3014
|
+
outputMessages.push(plainToInstance3(ActionExecutionMessage, {
|
|
2895
3015
|
id: event.actionExecutionId,
|
|
2896
3016
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2897
3017
|
name: event.actionName,
|
|
2898
|
-
scope: event.scope,
|
|
2899
3018
|
arguments: argumentChunks.join("")
|
|
2900
3019
|
}));
|
|
2901
3020
|
}
|
|
@@ -2908,15 +3027,15 @@ var CopilotResolver = class {
|
|
|
2908
3027
|
result: event.result
|
|
2909
3028
|
}, "Action execution result event received");
|
|
2910
3029
|
pushMessage({
|
|
2911
|
-
id:
|
|
3030
|
+
id: "result-" + event.actionExecutionId,
|
|
2912
3031
|
status: new SuccessMessageStatus(),
|
|
2913
3032
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2914
3033
|
actionExecutionId: event.actionExecutionId,
|
|
2915
3034
|
actionName: event.actionName,
|
|
2916
3035
|
result: event.result
|
|
2917
3036
|
});
|
|
2918
|
-
outputMessages.push(
|
|
2919
|
-
id:
|
|
3037
|
+
outputMessages.push(plainToInstance3(ResultMessage, {
|
|
3038
|
+
id: "result-" + event.actionExecutionId,
|
|
2920
3039
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2921
3040
|
actionExecutionId: event.actionExecutionId,
|
|
2922
3041
|
actionName: event.actionName,
|
|
@@ -2928,7 +3047,7 @@ var CopilotResolver = class {
|
|
|
2928
3047
|
event
|
|
2929
3048
|
}, "Agent message event received");
|
|
2930
3049
|
pushMessage({
|
|
2931
|
-
id:
|
|
3050
|
+
id: randomId3(),
|
|
2932
3051
|
status: new SuccessMessageStatus(),
|
|
2933
3052
|
threadId: event.threadId,
|
|
2934
3053
|
agentName: event.agentName,
|
|
@@ -2940,8 +3059,8 @@ var CopilotResolver = class {
|
|
|
2940
3059
|
role: MessageRole.assistant,
|
|
2941
3060
|
createdAt: /* @__PURE__ */ new Date()
|
|
2942
3061
|
});
|
|
2943
|
-
outputMessages.push(
|
|
2944
|
-
id:
|
|
3062
|
+
outputMessages.push(plainToInstance3(AgentStateMessage, {
|
|
3063
|
+
id: randomId3(),
|
|
2945
3064
|
threadId: event.threadId,
|
|
2946
3065
|
agentName: event.agentName,
|
|
2947
3066
|
nodeName: event.nodeName,
|
|
@@ -3022,7 +3141,14 @@ function createLogger(options) {
|
|
|
3022
3141
|
colorize: true
|
|
3023
3142
|
});
|
|
3024
3143
|
const logger2 = createPinoLogger({
|
|
3025
|
-
level: process.env.LOG_LEVEL || level || "error"
|
|
3144
|
+
level: process.env.LOG_LEVEL || level || "error",
|
|
3145
|
+
redact: {
|
|
3146
|
+
paths: [
|
|
3147
|
+
"pid",
|
|
3148
|
+
"hostname"
|
|
3149
|
+
],
|
|
3150
|
+
remove: true
|
|
3151
|
+
}
|
|
3026
3152
|
}, stream);
|
|
3027
3153
|
if (component) {
|
|
3028
3154
|
return logger2.child({
|
|
@@ -3145,4 +3271,4 @@ export {
|
|
|
3145
3271
|
getCommonConfig,
|
|
3146
3272
|
copilotRuntimeNodeHttpEndpoint
|
|
3147
3273
|
};
|
|
3148
|
-
//# sourceMappingURL=chunk-
|
|
3274
|
+
//# sourceMappingURL=chunk-PXS4SBRF.mjs.map
|