@copilotkit/runtime 1.5.1-next.2 → 1.5.1-next.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/__snapshots__/schema/schema.graphql +9 -19
  3. package/dist/{chunk-RFF5IIZJ.mjs → chunk-B74M7FXG.mjs} +2 -3
  4. package/dist/chunk-B74M7FXG.mjs.map +1 -0
  5. package/dist/{chunk-2FY7EQEE.mjs → chunk-M4QD67S3.mjs} +2 -2
  6. package/dist/{chunk-CLGKEUOA.mjs → chunk-OKQVDDJ2.mjs} +63 -298
  7. package/dist/chunk-OKQVDDJ2.mjs.map +1 -0
  8. package/dist/{chunk-2ZPE55QG.mjs → chunk-U3AYI5XZ.mjs} +2 -2
  9. package/dist/{chunk-W6E7AVR7.mjs → chunk-U75F2RAQ.mjs} +2 -2
  10. package/dist/{chunk-2V7BHSFE.mjs → chunk-ZSWCEADS.mjs} +331 -579
  11. package/dist/chunk-ZSWCEADS.mjs.map +1 -0
  12. package/dist/{copilot-runtime-36700e00.d.ts → copilot-runtime-12e7ac40.d.ts} +2 -9
  13. package/dist/graphql/types/converted/index.d.ts +1 -1
  14. package/dist/graphql/types/converted/index.js +1 -2
  15. package/dist/graphql/types/converted/index.js.map +1 -1
  16. package/dist/graphql/types/converted/index.mjs +1 -1
  17. package/dist/{groq-adapter-696b5d29.d.ts → groq-adapter-24abe931.d.ts} +1 -1
  18. package/dist/{index-cc2b17be.d.ts → index-10b1c870.d.ts} +9 -8
  19. package/dist/index.d.ts +5 -5
  20. package/dist/index.js +498 -984
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +11 -15
  23. package/dist/index.mjs.map +1 -1
  24. package/dist/{langserve-9125a12e.d.ts → langserve-f021ab9c.d.ts} +14 -54
  25. package/dist/lib/index.d.ts +4 -4
  26. package/dist/lib/index.js +477 -886
  27. package/dist/lib/index.js.map +1 -1
  28. package/dist/lib/index.mjs +7 -7
  29. package/dist/lib/integrations/index.d.ts +4 -4
  30. package/dist/lib/integrations/index.js +48 -171
  31. package/dist/lib/integrations/index.js.map +1 -1
  32. package/dist/lib/integrations/index.mjs +6 -6
  33. package/dist/lib/integrations/nest/index.d.ts +3 -3
  34. package/dist/lib/integrations/nest/index.js +48 -171
  35. package/dist/lib/integrations/nest/index.js.map +1 -1
  36. package/dist/lib/integrations/nest/index.mjs +4 -4
  37. package/dist/lib/integrations/node-express/index.d.ts +3 -3
  38. package/dist/lib/integrations/node-express/index.js +48 -171
  39. package/dist/lib/integrations/node-express/index.js.map +1 -1
  40. package/dist/lib/integrations/node-express/index.mjs +4 -4
  41. package/dist/lib/integrations/node-http/index.d.ts +3 -3
  42. package/dist/lib/integrations/node-http/index.js +48 -171
  43. package/dist/lib/integrations/node-http/index.js.map +1 -1
  44. package/dist/lib/integrations/node-http/index.mjs +3 -3
  45. package/dist/service-adapters/index.d.ts +5 -36
  46. package/dist/service-adapters/index.js +61 -298
  47. package/dist/service-adapters/index.js.map +1 -1
  48. package/dist/service-adapters/index.mjs +1 -5
  49. package/package.json +2 -2
  50. package/dist/chunk-2V7BHSFE.mjs.map +0 -1
  51. package/dist/chunk-CLGKEUOA.mjs.map +0 -1
  52. package/dist/chunk-RFF5IIZJ.mjs.map +0 -1
  53. /package/dist/{chunk-2FY7EQEE.mjs.map → chunk-M4QD67S3.mjs.map} +0 -0
  54. /package/dist/{chunk-2ZPE55QG.mjs.map → chunk-U3AYI5XZ.mjs.map} +0 -0
  55. /package/dist/{chunk-W6E7AVR7.mjs.map → chunk-U75F2RAQ.mjs.map} +0 -0
@@ -1,7 +1,3 @@
1
- import {
2
- RemoteChain,
3
- streamLangChainResponse
4
- } from "./chunk-CLGKEUOA.mjs";
5
1
  import {
6
2
  GuardrailsValidationFailureResponse,
7
3
  MessageStreamInterruptedResponse,
@@ -9,12 +5,16 @@ import {
9
5
  SuccessResponseStatus,
10
6
  UnknownErrorResponse
11
7
  } from "./chunk-U3V2BCGI.mjs";
8
+ import {
9
+ RemoteChain,
10
+ streamLangChainResponse
11
+ } from "./chunk-OKQVDDJ2.mjs";
12
12
  import {
13
13
  ActionExecutionMessage,
14
14
  AgentStateMessage,
15
15
  ResultMessage,
16
16
  TextMessage
17
- } from "./chunk-RFF5IIZJ.mjs";
17
+ } from "./chunk-B74M7FXG.mjs";
18
18
  import {
19
19
  BaseMessageInput
20
20
  } from "./chunk-D2WLFQS6.mjs";
@@ -37,7 +37,7 @@ var require_package = __commonJS({
37
37
  publishConfig: {
38
38
  access: "public"
39
39
  },
40
- version: "1.5.1-next.2",
40
+ version: "1.4.1-pre.6",
41
41
  sideEffects: false,
42
42
  main: "./dist/index.js",
43
43
  module: "./dist/index.mjs",
@@ -122,7 +122,7 @@ import { buildSchemaSync } from "type-graphql";
122
122
 
123
123
  // src/graphql/resolvers/copilot.resolver.ts
124
124
  import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
125
- import { ReplaySubject as ReplaySubject3, Subject, filter, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
125
+ import { ReplaySubject as ReplaySubject3, Subject, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
126
126
 
127
127
  // src/graphql/inputs/generate-copilot-response.input.ts
128
128
  import { Field as Field9, InputType as InputType9 } from "type-graphql";
@@ -139,6 +139,12 @@ var MessageRole;
139
139
  MessageRole2["system"] = "system";
140
140
  MessageRole2["tool"] = "tool";
141
141
  })(MessageRole || (MessageRole = {}));
142
+ var ActionExecutionScope;
143
+ (function(ActionExecutionScope2) {
144
+ ActionExecutionScope2["server"] = "server";
145
+ ActionExecutionScope2["client"] = "client";
146
+ ActionExecutionScope2["passThrough"] = "passThrough";
147
+ })(ActionExecutionScope || (ActionExecutionScope = {}));
142
148
  var CopilotRequestType;
143
149
  (function(CopilotRequestType2) {
144
150
  CopilotRequestType2["Chat"] = "Chat";
@@ -157,6 +163,10 @@ registerEnumType(MessageRole, {
157
163
  name: "MessageRole",
158
164
  description: "The role of the message"
159
165
  });
166
+ registerEnumType(ActionExecutionScope, {
167
+ name: "ActionExecutionScope",
168
+ description: "The scope of the action"
169
+ });
160
170
  registerEnumType(CopilotRequestType, {
161
171
  name: "CopilotRequestType",
162
172
  description: "The type of Copilot request"
@@ -219,7 +229,6 @@ MessageInput = _ts_decorate([
219
229
  ], MessageInput);
220
230
  var TextMessageInput = class {
221
231
  content;
222
- parentMessageId;
223
232
  role;
224
233
  };
225
234
  __name(TextMessageInput, "TextMessageInput");
@@ -227,12 +236,6 @@ _ts_decorate([
227
236
  Field(() => String),
228
237
  _ts_metadata("design:type", String)
229
238
  ], TextMessageInput.prototype, "content", void 0);
230
- _ts_decorate([
231
- Field(() => String, {
232
- nullable: true
233
- }),
234
- _ts_metadata("design:type", String)
235
- ], TextMessageInput.prototype, "parentMessageId", void 0);
236
239
  _ts_decorate([
237
240
  Field(() => MessageRole),
238
241
  _ts_metadata("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
@@ -243,7 +246,6 @@ TextMessageInput = _ts_decorate([
243
246
  var ActionExecutionMessageInput = class {
244
247
  name;
245
248
  arguments;
246
- parentMessageId;
247
249
  scope;
248
250
  };
249
251
  __name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
@@ -256,17 +258,8 @@ _ts_decorate([
256
258
  _ts_metadata("design:type", String)
257
259
  ], ActionExecutionMessageInput.prototype, "arguments", void 0);
258
260
  _ts_decorate([
259
- Field(() => 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)
261
+ Field(() => ActionExecutionScope),
262
+ _ts_metadata("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
270
263
  ], ActionExecutionMessageInput.prototype, "scope", void 0);
271
264
  ActionExecutionMessageInput = _ts_decorate([
272
265
  InputType()
@@ -274,7 +267,6 @@ ActionExecutionMessageInput = _ts_decorate([
274
267
  var ResultMessageInput = class {
275
268
  actionExecutionId;
276
269
  actionName;
277
- parentMessageId;
278
270
  result;
279
271
  };
280
272
  __name(ResultMessageInput, "ResultMessageInput");
@@ -286,12 +278,6 @@ _ts_decorate([
286
278
  Field(() => String),
287
279
  _ts_metadata("design:type", String)
288
280
  ], ResultMessageInput.prototype, "actionName", void 0);
289
- _ts_decorate([
290
- Field(() => String, {
291
- nullable: true
292
- }),
293
- _ts_metadata("design:type", String)
294
- ], ResultMessageInput.prototype, "parentMessageId", void 0);
295
281
  _ts_decorate([
296
282
  Field(() => String),
297
283
  _ts_metadata("design:type", String)
@@ -555,7 +541,6 @@ var ForwardedParametersInput = class {
555
541
  stop;
556
542
  toolChoice;
557
543
  toolChoiceFunctionName;
558
- temperature;
559
544
  };
560
545
  __name(ForwardedParametersInput, "ForwardedParametersInput");
561
546
  _ts_decorate6([
@@ -590,12 +575,6 @@ _ts_decorate6([
590
575
  }),
591
576
  _ts_metadata6("design:type", String)
592
577
  ], ForwardedParametersInput.prototype, "toolChoiceFunctionName", void 0);
593
- _ts_decorate6([
594
- Field6(() => Number, {
595
- nullable: true
596
- }),
597
- _ts_metadata6("design:type", Number)
598
- ], ForwardedParametersInput.prototype, "temperature", void 0);
599
578
  ForwardedParametersInput = _ts_decorate6([
600
579
  InputType6()
601
580
  ], ForwardedParametersInput);
@@ -914,7 +893,6 @@ BaseMessageOutput = _ts_decorate11([
914
893
  var TextMessageOutput = class {
915
894
  role;
916
895
  content;
917
- parentMessageId;
918
896
  };
919
897
  __name(TextMessageOutput, "TextMessageOutput");
920
898
  _ts_decorate11([
@@ -927,12 +905,6 @@ _ts_decorate11([
927
905
  ]),
928
906
  _ts_metadata11("design:type", Array)
929
907
  ], TextMessageOutput.prototype, "content", void 0);
930
- _ts_decorate11([
931
- Field11(() => String, {
932
- nullable: true
933
- }),
934
- _ts_metadata11("design:type", String)
935
- ], TextMessageOutput.prototype, "parentMessageId", void 0);
936
908
  TextMessageOutput = _ts_decorate11([
937
909
  ObjectType2({
938
910
  implements: BaseMessageOutput
@@ -942,7 +914,6 @@ var ActionExecutionMessageOutput = class {
942
914
  name;
943
915
  scope;
944
916
  arguments;
945
- parentMessageId;
946
917
  };
947
918
  __name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
948
919
  _ts_decorate11([
@@ -950,11 +921,8 @@ _ts_decorate11([
950
921
  _ts_metadata11("design:type", String)
951
922
  ], ActionExecutionMessageOutput.prototype, "name", void 0);
952
923
  _ts_decorate11([
953
- Field11(() => String, {
954
- nullable: true,
955
- deprecationReason: "This field will be removed in a future version"
956
- }),
957
- _ts_metadata11("design:type", String)
924
+ Field11(() => ActionExecutionScope),
925
+ _ts_metadata11("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
958
926
  ], ActionExecutionMessageOutput.prototype, "scope", void 0);
959
927
  _ts_decorate11([
960
928
  Field11(() => [
@@ -962,12 +930,6 @@ _ts_decorate11([
962
930
  ]),
963
931
  _ts_metadata11("design:type", Array)
964
932
  ], ActionExecutionMessageOutput.prototype, "arguments", void 0);
965
- _ts_decorate11([
966
- Field11(() => String, {
967
- nullable: true
968
- }),
969
- _ts_metadata11("design:type", String)
970
- ], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
971
933
  ActionExecutionMessageOutput = _ts_decorate11([
972
934
  ObjectType2({
973
935
  implements: BaseMessageOutput
@@ -1080,7 +1042,7 @@ import { Repeater } from "graphql-yoga";
1080
1042
 
1081
1043
  // src/service-adapters/events.ts
1082
1044
  import { randomId as randomId3 } from "@copilotkit/shared";
1083
- import { of, concat, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
1045
+ import { of, concat, map, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from as from2 } from "rxjs";
1084
1046
 
1085
1047
  // src/lib/telemetry-client.ts
1086
1048
  import { TelemetryClient } from "@copilotkit/shared";
@@ -1128,167 +1090,163 @@ var RemoteLangGraphEventSource = class {
1128
1090
  }
1129
1091
  return shouldEmitToolCalls === toolCallName;
1130
1092
  }
1131
- getCurrentContent(event) {
1132
- var _a, _b, _c, _d, _e;
1133
- const content = ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.content) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.content);
1134
- if (!content) {
1135
- const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
1136
- for (const chunk of toolCallChunks) {
1137
- if (chunk.args) {
1138
- return chunk.args;
1139
- }
1140
- }
1141
- }
1142
- if (typeof content === "string") {
1143
- return content;
1144
- } else if (Array.isArray(content) && content.length > 0) {
1145
- return content[0].text;
1146
- }
1147
- return null;
1148
- }
1149
- getCurrentMessageId(event) {
1150
- var _a, _b, _c, _d, _e;
1151
- return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.id) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.id);
1152
- }
1153
- getCurrentToolCallChunks(event) {
1154
- var _a, _b, _c, _d, _e;
1155
- return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.tool_call_chunks);
1156
- }
1157
- getResponseMetadata(event) {
1158
- var _a, _b, _c, _d, _e;
1159
- return ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.response_metadata) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.response_metadata);
1160
- }
1161
1093
  processLangGraphEvents() {
1162
1094
  let lastEventWithState = null;
1163
1095
  return this.eventStream$.pipe(scan((acc, event) => {
1096
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1164
1097
  if (event.event === LangGraphEventTypes.OnChatModelStream) {
1165
- const 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
- });
1098
+ const content = ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.content) ?? ((_e = (_d = event.data) == null ? void 0 : _d.chunk) == null ? void 0 : _e.content);
1099
+ if (typeof content === "string") {
1100
+ acc.content = content;
1101
+ } else if (Array.isArray(content) && content.length > 0) {
1102
+ acc.content = content[0].text;
1103
+ } else {
1104
+ acc.content = null;
1105
+ }
1106
+ const toolCallChunks = (
1107
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
1108
+ ((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) ?? ((_j = (_i = event.data) == null ? void 0 : _i.chunk) == null ? void 0 : _j.tool_call_chunks)
1109
+ );
1110
+ const toolCallMessageId = ((_m = (_l = (_k = event.data) == null ? void 0 : _k.chunk) == null ? void 0 : _l.kwargs) == null ? void 0 : _m.id) ?? ((_o = (_n = event.data) == null ? void 0 : _n.chunk) == null ? void 0 : _o.id);
1111
+ if (toolCallChunks && toolCallChunks.length > 0) {
1112
+ acc.prevToolCallMessageId = acc.toolCallMessageId;
1113
+ acc.toolCallMessageId = toolCallMessageId;
1114
+ if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
1115
+ acc.toolCallName = toolCallChunks[0].name;
1116
+ }
1117
+ if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
1118
+ acc.toolCallId = toolCallChunks[0].id;
1119
+ }
1120
+ acc.prevMessageId = acc.messageId;
1121
+ acc.messageId = toolCallMessageId;
1122
+ } else if (acc.content && acc.content != "") {
1123
+ acc.prevMessageId = acc.messageId;
1124
+ acc.messageId = toolCallMessageId;
1125
+ } else {
1126
+ acc.prevToolCallMessageId = acc.toolCallMessageId;
1127
+ acc.prevMessageId = acc.messageId;
1128
+ }
1129
+ } else {
1130
+ acc.prevToolCallMessageId = acc.toolCallMessageId;
1131
+ acc.toolCallMessageId = null;
1132
+ acc.prevMessageId = acc.messageId;
1133
+ acc.messageId = null;
1134
+ acc.toolCallName = null;
1179
1135
  }
1180
1136
  acc.event = event;
1181
1137
  lastEventWithState = acc;
1182
1138
  return acc;
1183
1139
  }, {
1184
1140
  event: null,
1185
- 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) => {
1141
+ toolCallId: null,
1142
+ toolCallMessageId: null,
1143
+ prevToolCallMessageId: null,
1144
+ messageId: null,
1145
+ toolCallName: null,
1146
+ prevMessageId: null,
1147
+ content: null
1148
+ }), mergeMap((eventWithState) => {
1149
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1195
1150
  const events = [];
1196
1151
  let shouldEmitMessages = true;
1197
- let shouldEmitToolCalls = 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"];
1152
+ let shouldEmitToolCalls = false;
1153
+ if (eventWithState.event.event == LangGraphEventTypes.OnChatModelStream) {
1154
+ if ("copilotkit:emit-tool-calls" in (eventWithState.event.metadata || {})) {
1155
+ shouldEmitToolCalls = eventWithState.event.metadata["copilotkit:emit-tool-calls"];
1201
1156
  }
1202
- if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
1203
- shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
1157
+ if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
1158
+ shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
1204
1159
  }
1205
1160
  }
1206
- const responseMetadata = this.getResponseMetadata(acc.event);
1207
- if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
1161
+ if (eventWithState.prevToolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId && this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
1208
1162
  events.push({
1209
- type: RuntimeEventTypes.ActionExecutionEnd,
1210
- actionExecutionId: acc.lastToolCallId
1163
+ type: RuntimeEventTypes.ActionExecutionEnd
1211
1164
  });
1212
1165
  }
1213
- if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
1166
+ if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
1214
1167
  events.push({
1215
- type: RuntimeEventTypes.TextMessageEnd,
1216
- messageId: acc.lastMessageId
1168
+ type: RuntimeEventTypes.TextMessageEnd
1217
1169
  });
1218
1170
  }
1219
- switch (acc.event.event) {
1171
+ switch (eventWithState.event.event) {
1220
1172
  case LangGraphEventTypes.OnCustomEvent:
1221
- if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
1173
+ if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
1222
1174
  events.push({
1223
1175
  type: RuntimeEventTypes.TextMessageStart,
1224
- messageId: acc.event.data.message_id
1176
+ messageId: eventWithState.event.data.message_id
1225
1177
  });
1226
1178
  events.push({
1227
1179
  type: RuntimeEventTypes.TextMessageContent,
1228
- messageId: acc.event.data.message_id,
1229
- content: acc.event.data.message
1180
+ content: eventWithState.event.data.message
1230
1181
  });
1231
1182
  events.push({
1232
- type: RuntimeEventTypes.TextMessageEnd,
1233
- messageId: acc.event.data.message_id
1183
+ type: RuntimeEventTypes.TextMessageEnd
1234
1184
  });
1235
- } else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
1185
+ } else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
1236
1186
  events.push({
1237
1187
  type: RuntimeEventTypes.ActionExecutionStart,
1238
- actionExecutionId: acc.event.data.id,
1239
- actionName: acc.event.data.name,
1240
- parentMessageId: acc.event.data.id
1188
+ actionExecutionId: eventWithState.event.data.id,
1189
+ actionName: eventWithState.event.data.name
1241
1190
  });
1242
1191
  events.push({
1243
1192
  type: RuntimeEventTypes.ActionExecutionArgs,
1244
- actionExecutionId: acc.event.data.id,
1245
- args: JSON.stringify(acc.event.data.args)
1193
+ args: JSON.stringify(eventWithState.event.data.args)
1246
1194
  });
1247
1195
  events.push({
1248
- type: RuntimeEventTypes.ActionExecutionEnd,
1249
- actionExecutionId: acc.event.data.id
1196
+ type: RuntimeEventTypes.ActionExecutionEnd
1250
1197
  });
1251
1198
  }
1252
1199
  break;
1253
1200
  case LangGraphEventTypes.OnCopilotKitStateSync:
1254
1201
  events.push({
1255
1202
  type: RuntimeEventTypes.AgentStateMessage,
1256
- threadId: 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
1203
+ threadId: eventWithState.event.thread_id,
1204
+ role: eventWithState.event.role,
1205
+ agentName: eventWithState.event.agent_name,
1206
+ nodeName: eventWithState.event.node_name,
1207
+ runId: eventWithState.event.run_id,
1208
+ active: eventWithState.event.active,
1209
+ state: JSON.stringify(eventWithState.event.state),
1210
+ running: eventWithState.event.running
1264
1211
  });
1265
1212
  break;
1213
+ case LangGraphEventTypes.OnToolEnd:
1214
+ break;
1266
1215
  case LangGraphEventTypes.OnChatModelStream:
1267
- if (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
- });
1216
+ if (eventWithState.toolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId) {
1217
+ if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
1218
+ events.push({
1219
+ type: RuntimeEventTypes.ActionExecutionStart,
1220
+ actionExecutionId: eventWithState.toolCallMessageId,
1221
+ actionName: eventWithState.toolCallName,
1222
+ scope: "client"
1223
+ });
1224
+ }
1225
+ } else if (eventWithState.messageId !== null && eventWithState.prevMessageId !== eventWithState.messageId) {
1226
+ if (shouldEmitMessages) {
1227
+ events.push({
1228
+ type: RuntimeEventTypes.TextMessageStart,
1229
+ messageId: eventWithState.messageId
1230
+ });
1231
+ }
1279
1232
  }
1280
- 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
- });
1233
+ const args = ((_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args) ?? // @ts-expect-error -- sdf
1234
+ ((_i = (_h = (_g = (_f = eventWithState.event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.tool_call_chunks) == null ? void 0 : _h[0]) == null ? void 0 : _i.args);
1235
+ const content = eventWithState.content;
1236
+ if (args) {
1237
+ if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
1238
+ events.push({
1239
+ type: RuntimeEventTypes.ActionExecutionArgs,
1240
+ args
1241
+ });
1242
+ }
1243
+ } else if (eventWithState.messageId !== null && content) {
1244
+ if (shouldEmitMessages) {
1245
+ events.push({
1246
+ type: RuntimeEventTypes.TextMessageContent,
1247
+ content
1248
+ });
1249
+ }
1292
1250
  }
1293
1251
  break;
1294
1252
  }
@@ -1296,16 +1254,14 @@ var RemoteLangGraphEventSource = class {
1296
1254
  }), catchError((error) => {
1297
1255
  console.error(error);
1298
1256
  const events = [];
1299
- if ((lastEventWithState == null ? void 0 : lastEventWithState.lastMessageId) && !lastEventWithState.isToolCall) {
1257
+ if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
1300
1258
  events.push({
1301
- type: RuntimeEventTypes.TextMessageEnd,
1302
- messageId: lastEventWithState.lastMessageId
1259
+ type: RuntimeEventTypes.TextMessageEnd
1303
1260
  });
1304
1261
  }
1305
- if (lastEventWithState == null ? void 0 : lastEventWithState.lastToolCallId) {
1262
+ if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
1306
1263
  events.push({
1307
- type: RuntimeEventTypes.ActionExecutionEnd,
1308
- actionExecutionId: lastEventWithState.lastToolCallId
1264
+ type: RuntimeEventTypes.ActionExecutionEnd
1309
1265
  });
1310
1266
  }
1311
1267
  const messageId = randomId();
@@ -1315,12 +1271,10 @@ var RemoteLangGraphEventSource = class {
1315
1271
  });
1316
1272
  events.push({
1317
1273
  type: RuntimeEventTypes.TextMessageContent,
1318
- messageId,
1319
1274
  content: "\u274C An error occurred. Please try again."
1320
1275
  });
1321
1276
  events.push({
1322
- type: RuntimeEventTypes.TextMessageEnd,
1323
- messageId
1277
+ type: RuntimeEventTypes.TextMessageEnd
1324
1278
  });
1325
1279
  return events;
1326
1280
  }));
@@ -1359,6 +1313,8 @@ async function streamEvents(controller, args) {
1359
1313
  if (initialThreadId && initialThreadId.startsWith("ck-")) {
1360
1314
  initialThreadId = initialThreadId.substring(3);
1361
1315
  }
1316
+ const assistants = await client.assistants.search();
1317
+ const retrievedAssistant = assistants.find((a) => a.name === name);
1362
1318
  const threadId = initialThreadId ?? randomUUID();
1363
1319
  if (initialThreadId === threadId) {
1364
1320
  await client.threads.get(threadId);
@@ -1378,7 +1334,7 @@ async function streamEvents(controller, args) {
1378
1334
  const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
1379
1335
  let formattedMessages = [];
1380
1336
  try {
1381
- formattedMessages = copilotkitMessagesToLangChain(messages);
1337
+ formattedMessages = formatMessages(messages);
1382
1338
  } catch (e) {
1383
1339
  logger2.error(e, `Error event thrown: ${e.message}`);
1384
1340
  }
@@ -1389,16 +1345,8 @@ async function streamEvents(controller, args) {
1389
1345
  asNode: nodeName
1390
1346
  });
1391
1347
  }
1392
- 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
- });
1348
+ const assistantId = initialAssistantId ?? (retrievedAssistant == null ? void 0 : retrievedAssistant.assistant_id);
1349
+ if (!assistantId) {
1402
1350
  console.error(`
1403
1351
  No agent found for the agent name specified in CopilotKit provider
1404
1352
  Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
@@ -1408,7 +1356,6 @@ async function streamEvents(controller, args) {
1408
1356
  `);
1409
1357
  throw new Error("No agent id found");
1410
1358
  }
1411
- const assistantId = retrievedAssistant.assistant_id;
1412
1359
  const graphInfo = await client.assistants.getGraph(assistantId);
1413
1360
  const streamInput = mode === "start" ? state : null;
1414
1361
  let streamingStateExtractor = new StreamingStateExtractor([]);
@@ -1427,6 +1374,9 @@ async function streamEvents(controller, args) {
1427
1374
  let latestStateValues = {};
1428
1375
  let updatedState = state;
1429
1376
  let manuallyEmittedState = null;
1377
+ let streamInfo = {
1378
+ hashedLgcKey: createHash("sha256").update(langsmithApiKey).digest("hex")
1379
+ };
1430
1380
  try {
1431
1381
  telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
1432
1382
  hashedLgcKey: streamInfo.hashedLgcKey
@@ -1439,6 +1389,7 @@ async function streamEvents(controller, args) {
1439
1389
  ].includes(chunk.event))
1440
1390
  continue;
1441
1391
  if (chunk.event === "error") {
1392
+ logger2.error(chunk, `Error event thrown: ${chunk.data.message}`);
1442
1393
  throw new Error(`Error event thrown: ${chunk.data.message}`);
1443
1394
  }
1444
1395
  if (chunk.event === "values") {
@@ -1531,34 +1482,21 @@ async function streamEvents(controller, args) {
1531
1482
  nodeName: isEndNode ? "__end__" : nodeName,
1532
1483
  state: state.values,
1533
1484
  running: !shouldExit,
1534
- active: false,
1535
- includeMessages: true
1485
+ active: false
1536
1486
  }));
1537
1487
  return Promise.resolve();
1538
1488
  } catch (e) {
1539
- logger2.error(e);
1540
- telemetry_client_default.capture("oss.runtime.agent_execution_stream_errored", {
1541
- ...streamInfo,
1542
- error: e.message
1543
- });
1544
1489
  return Promise.resolve();
1545
1490
  }
1546
1491
  }
1547
1492
  __name(streamEvents, "streamEvents");
1548
- function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, 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
- }
1493
+ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
1494
+ const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
1495
+ if (key !== "messages") {
1496
+ acc[key] = state[key];
1497
+ }
1498
+ return acc;
1499
+ }, {});
1562
1500
  return JSON.stringify({
1563
1501
  event: LangGraphEventTypes.OnCopilotKitStateSync,
1564
1502
  thread_id: threadId,
@@ -1566,7 +1504,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
1566
1504
  agent_name: agentName,
1567
1505
  node_name: nodeName,
1568
1506
  active,
1569
- state,
1507
+ state: stateWithoutMessages,
1570
1508
  running,
1571
1509
  role: "assistant"
1572
1510
  }) + "\n";
@@ -1642,157 +1580,134 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
1642
1580
  if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
1643
1581
  messages = messages.slice(1);
1644
1582
  }
1645
- const 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
- }
1583
+ const mergedMessages = state.messages || [];
1584
+ const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
1585
+ const existingToolCallResults = /* @__PURE__ */ new Set();
1586
+ for (const message of mergedMessages) {
1587
+ if ("tool_call_id" in message) {
1588
+ existingToolCallResults.add(message.tool_call_id);
1665
1589
  }
1666
1590
  }
1667
1591
  for (const message of messages) {
1668
- let content = message.content;
1669
- if (content instanceof Array) {
1670
- content = content[0];
1592
+ if ("tool_calls" in message && message.tool_calls.length > 0 && message.tool_calls[0].name === agentName) {
1593
+ continue;
1671
1594
  }
1672
- if (content instanceof Object) {
1673
- content = content.text;
1595
+ if ("name" in message && message.name === agentName) {
1596
+ continue;
1674
1597
  }
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
- });
1598
+ if (!existingMessageIds.has(message.id)) {
1599
+ if ("tool_call_id" in message && existingToolCallResults.has(message.tool_call_id)) {
1600
+ console.warn("Warning: Duplicate tool call result, skipping:", message.tool_call_id);
1601
+ continue;
1602
+ }
1603
+ mergedMessages.push(message);
1604
+ } else {
1605
+ for (let i = 0; i < mergedMessages.length; i++) {
1606
+ if (mergedMessages[i].id === message.id && message.role === "assistant") {
1607
+ if (("tool_calls" in mergedMessages[i] || "additional_kwargs" in mergedMessages[i]) && mergedMessages[i].content) {
1608
+ message.tool_calls = mergedMessages[i]["tool_calls"];
1609
+ message.additional_kwargs = mergedMessages[i].additional_kwargs;
1610
+ }
1611
+ mergedMessages[i] = message;
1696
1612
  }
1697
- } else {
1698
- result.push({
1699
- role: "assistant",
1700
- content,
1701
- id: message.id,
1702
- parentMessageId: message.id
1703
- });
1704
1613
  }
1705
- } else if (message.type === "tool") {
1706
- const actionName = tool_call_names[message.tool_call_id] || message.name || "";
1707
- result.push({
1708
- actionExecutionId: message.tool_call_id,
1709
- actionName,
1710
- result: content,
1711
- id: message.id
1712
- });
1713
1614
  }
1714
1615
  }
1715
- const resultsDict = {};
1716
- for (const msg of result) {
1717
- if (msg.actionExecutionId) {
1718
- resultsDict[msg.actionExecutionId] = msg;
1616
+ for (let i = 0; i < mergedMessages.length - 1; i++) {
1617
+ const currentMessage = mergedMessages[i];
1618
+ const nextMessage = mergedMessages[i + 1];
1619
+ if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0 && "tool_call_id" in nextMessage) {
1620
+ nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
1719
1621
  }
1720
1622
  }
1721
- const reorderedResult = [];
1722
- for (const msg of result) {
1723
- if (!("actionExecutionId" in msg)) {
1724
- reorderedResult.push(msg);
1623
+ const correctedMessages = [];
1624
+ for (let i = 0; i < mergedMessages.length; i++) {
1625
+ const currentMessage = mergedMessages[i];
1626
+ const nextMessage = mergedMessages[i + 1] || null;
1627
+ const prevMessage = mergedMessages[i - 1] || null;
1628
+ if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
1629
+ if (!nextMessage) {
1630
+ console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
1631
+ continue;
1632
+ }
1633
+ if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
1634
+ const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
1635
+ if (toolMessage) {
1636
+ console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
1637
+ correctedMessages.push(currentMessage, toolMessage);
1638
+ continue;
1639
+ } else {
1640
+ console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
1641
+ continue;
1642
+ }
1643
+ }
1644
+ correctedMessages.push(currentMessage);
1645
+ continue;
1725
1646
  }
1726
- if ("arguments" in msg) {
1727
- const msgId = msg.id;
1728
- if (msgId in resultsDict) {
1729
- reorderedResult.push(resultsDict[msgId]);
1647
+ if ("tool_call_id" in currentMessage) {
1648
+ if (!prevMessage || !("tool_calls" in prevMessage)) {
1649
+ console.warn("No previous tool call, skipping tool call result:", currentMessage.id);
1650
+ continue;
1730
1651
  }
1652
+ if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
1653
+ console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
1654
+ continue;
1655
+ }
1656
+ correctedMessages.push(currentMessage);
1657
+ continue;
1731
1658
  }
1659
+ correctedMessages.push(currentMessage);
1732
1660
  }
1733
- return reorderedResult;
1661
+ return {
1662
+ ...state,
1663
+ messages: correctedMessages,
1664
+ copilotkit: {
1665
+ actions
1666
+ }
1667
+ };
1734
1668
  }
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;
1669
+ __name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
1670
+ function formatMessages(messages) {
1671
+ return messages.map((message) => {
1672
+ if (message.isTextMessage() && message.role === "assistant") {
1673
+ return message;
1674
+ }
1675
+ if (message.isTextMessage() && message.role === "system") {
1676
+ return message;
1677
+ }
1678
+ if (message.isTextMessage() && message.role === "user") {
1679
+ return message;
1758
1680
  }
1759
1681
  if (message.isActionExecutionMessage()) {
1760
- const 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",
1682
+ const toolCall = {
1683
+ name: message.name,
1684
+ args: message.arguments,
1685
+ id: message.id
1686
+ };
1687
+ return {
1688
+ type: message.type,
1774
1689
  content: "",
1775
- tool_calls,
1776
- role: MessageRole.assistant
1777
- });
1778
- continue;
1690
+ tool_calls: [
1691
+ toolCall
1692
+ ],
1693
+ role: MessageRole.assistant,
1694
+ id: message.id
1695
+ };
1779
1696
  }
1780
1697
  if (message.isResultMessage()) {
1781
- result.push({
1698
+ return {
1782
1699
  type: message.type,
1783
1700
  content: message.result,
1784
1701
  id: message.id,
1785
1702
  tool_call_id: message.actionExecutionId,
1786
1703
  name: message.actionName,
1787
1704
  role: MessageRole.tool
1788
- });
1789
- continue;
1705
+ };
1790
1706
  }
1791
1707
  throw new Error(`Unknown message type ${message.type}`);
1792
- }
1793
- return result;
1708
+ });
1794
1709
  }
1795
- __name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
1710
+ __name(formatMessages, "formatMessages");
1796
1711
 
1797
1712
  // src/lib/runtime/remote-action-constructors.ts
1798
1713
  function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
@@ -1802,7 +1717,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
1802
1717
  parameters: [],
1803
1718
  handler: async (_args) => {
1804
1719
  },
1805
- langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
1720
+ langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
1806
1721
  var _a;
1807
1722
  logger2.debug({
1808
1723
  actionName: agent.name
@@ -1828,10 +1743,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
1828
1743
  agent,
1829
1744
  threadId,
1830
1745
  nodeName,
1831
- messages: [
1832
- ...messages,
1833
- ...additionalMessages
1834
- ],
1746
+ messages,
1835
1747
  state,
1836
1748
  properties: graphqlContext.properties,
1837
1749
  actions: actionInputsWithoutAgents.map((action) => ({
@@ -1859,7 +1771,6 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
1859
1771
  }
1860
1772
  __name(constructLGCRemoteAction, "constructLGCRemoteAction");
1861
1773
  function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
1862
- const totalAgents = Array.isArray(json["agents"]) ? json["agents"].length : 0;
1863
1774
  const actions = json["actions"].map((action) => ({
1864
1775
  name: action.name,
1865
1776
  description: action.description,
@@ -1873,7 +1784,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1873
1784
  telemetry_client_default.capture("oss.runtime.remote_action_executed", {
1874
1785
  agentExecution: false,
1875
1786
  type: "self-hosted",
1876
- agentsAmount: totalAgents
1787
+ agentsAmount: json["agents"].length
1877
1788
  });
1878
1789
  try {
1879
1790
  const response = await fetch(`${url}/actions/execute`, {
@@ -1908,13 +1819,13 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1908
1819
  }
1909
1820
  }
1910
1821
  }));
1911
- const agents = totalAgents ? json["agents"].map((agent) => ({
1822
+ const agents = json["agents"].map((agent) => ({
1912
1823
  name: agent.name,
1913
1824
  description: agent.description,
1914
1825
  parameters: [],
1915
1826
  handler: async (_args) => {
1916
1827
  },
1917
- langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
1828
+ langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
1918
1829
  var _a;
1919
1830
  logger2.debug({
1920
1831
  actionName: agent.name
@@ -1939,10 +1850,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1939
1850
  name,
1940
1851
  threadId,
1941
1852
  nodeName,
1942
- messages: [
1943
- ...messages,
1944
- ...additionalMessages
1945
- ],
1853
+ messages,
1946
1854
  state,
1947
1855
  properties: graphqlContext.properties,
1948
1856
  actions: actionInputsWithoutAgents.map((action) => ({
@@ -1964,7 +1872,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1964
1872
  streamResponse(response.body, eventSource.eventStream$);
1965
1873
  return eventSource.processLangGraphEvents();
1966
1874
  }
1967
- })) : [];
1875
+ }));
1968
1876
  return [
1969
1877
  ...actions,
1970
1878
  ...agents
@@ -2154,8 +2062,7 @@ function convertGqlInputToMessages(inputMessages) {
2154
2062
  id: message.id,
2155
2063
  createdAt: message.createdAt,
2156
2064
  role: message.textMessage.role,
2157
- content: message.textMessage.content,
2158
- parentMessageId: message.textMessage.parentMessageId
2065
+ content: message.textMessage.content
2159
2066
  }));
2160
2067
  } else if (message.actionExecutionMessage) {
2161
2068
  messages.push(plainToInstance(ActionExecutionMessage, {
@@ -2163,7 +2070,7 @@ function convertGqlInputToMessages(inputMessages) {
2163
2070
  createdAt: message.createdAt,
2164
2071
  name: message.actionExecutionMessage.name,
2165
2072
  arguments: JSON.parse(message.actionExecutionMessage.arguments),
2166
- parentMessageId: message.actionExecutionMessage.parentMessageId
2073
+ scope: message.actionExecutionMessage.scope
2167
2074
  }));
2168
2075
  } else if (message.resultMessage) {
2169
2076
  messages.push(plainToInstance(ResultMessage, {
@@ -2274,48 +2181,15 @@ var CopilotRuntime = class {
2274
2181
  } catch (error) {
2275
2182
  console.error("Error getting response:", error);
2276
2183
  eventSource.sendErrorMessageToChat();
2277
- throw error;
2184
+ return {
2185
+ threadId: threadId || randomId2(),
2186
+ runId: runId || randomId2(),
2187
+ eventSource,
2188
+ serverSideActions: [],
2189
+ actionInputsWithoutAgents: []
2190
+ };
2278
2191
  }
2279
2192
  }
2280
- async discoverAgentsFromEndpoints(graphqlContext) {
2281
- const headers = createHeaders(null, graphqlContext);
2282
- const agents = this.remoteEndpointDefinitions.reduce(async (acc, endpoint) => {
2283
- const agents2 = await acc;
2284
- if (endpoint.type === EndpointType.LangGraphPlatform) {
2285
- const response2 = await fetch(`${endpoint.deploymentUrl}/assistants/search`, {
2286
- method: "POST",
2287
- headers
2288
- });
2289
- const data2 = await response2.json();
2290
- const endpointAgents2 = (data2 ?? []).map((entry) => ({
2291
- name: entry.graph_id,
2292
- id: entry.assistant_id
2293
- }));
2294
- return [
2295
- ...agents2,
2296
- ...endpointAgents2
2297
- ];
2298
- }
2299
- const response = await fetch(`${endpoint.url}/info`, {
2300
- method: "POST",
2301
- headers,
2302
- body: JSON.stringify({
2303
- properties: graphqlContext.properties
2304
- })
2305
- });
2306
- const data = await response.json();
2307
- const endpointAgents = ((data == null ? void 0 : data.agents) ?? []).map((agent) => ({
2308
- name: agent.name,
2309
- description: agent.description,
2310
- id: randomId2()
2311
- }));
2312
- return [
2313
- ...agents2,
2314
- ...endpointAgents
2315
- ];
2316
- }, Promise.resolve([]));
2317
- return agents;
2318
- }
2319
2193
  async processAgentRequest(request) {
2320
2194
  var _a;
2321
2195
  const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
@@ -2499,7 +2373,6 @@ __name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
2499
2373
  var telemetry_client_default = telemetryClient;
2500
2374
 
2501
2375
  // src/service-adapters/events.ts
2502
- import { plainToInstance as plainToInstance2 } from "class-transformer";
2503
2376
  var RuntimeEventTypes;
2504
2377
  (function(RuntimeEventTypes2) {
2505
2378
  RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
@@ -2515,74 +2388,52 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
2515
2388
  constructor() {
2516
2389
  super();
2517
2390
  }
2518
- sendTextMessageStart({ messageId, parentMessageId }) {
2391
+ sendTextMessageStart(messageId) {
2519
2392
  this.next({
2520
2393
  type: "TextMessageStart",
2521
- messageId,
2522
- parentMessageId
2394
+ messageId
2523
2395
  });
2524
2396
  }
2525
- sendTextMessageContent({ messageId, content }) {
2397
+ sendTextMessageContent(content) {
2526
2398
  this.next({
2527
2399
  type: "TextMessageContent",
2528
- content,
2529
- messageId
2400
+ content
2530
2401
  });
2531
2402
  }
2532
- sendTextMessageEnd({ messageId }) {
2403
+ sendTextMessageEnd() {
2533
2404
  this.next({
2534
- type: "TextMessageEnd",
2535
- messageId
2405
+ type: "TextMessageEnd"
2536
2406
  });
2537
2407
  }
2538
2408
  sendTextMessage(messageId, content) {
2539
- this.sendTextMessageStart({
2540
- messageId
2541
- });
2542
- this.sendTextMessageContent({
2543
- messageId,
2544
- content
2545
- });
2546
- this.sendTextMessageEnd({
2547
- messageId
2548
- });
2409
+ this.sendTextMessageStart(messageId);
2410
+ this.sendTextMessageContent(content);
2411
+ this.sendTextMessageEnd();
2549
2412
  }
2550
- sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
2413
+ sendActionExecutionStart(actionExecutionId, actionName) {
2551
2414
  this.next({
2552
2415
  type: "ActionExecutionStart",
2553
2416
  actionExecutionId,
2554
- actionName,
2555
- parentMessageId
2417
+ actionName
2556
2418
  });
2557
2419
  }
2558
- sendActionExecutionArgs({ actionExecutionId, args }) {
2420
+ sendActionExecutionArgs(args) {
2559
2421
  this.next({
2560
2422
  type: "ActionExecutionArgs",
2561
- args,
2562
- actionExecutionId
2423
+ args
2563
2424
  });
2564
2425
  }
2565
- sendActionExecutionEnd({ actionExecutionId }) {
2426
+ sendActionExecutionEnd() {
2566
2427
  this.next({
2567
- type: "ActionExecutionEnd",
2568
- actionExecutionId
2428
+ type: "ActionExecutionEnd"
2569
2429
  });
2570
2430
  }
2571
- sendActionExecution({ actionExecutionId, actionName, args, parentMessageId }) {
2572
- this.sendActionExecutionStart({
2573
- actionExecutionId,
2574
- actionName,
2575
- parentMessageId
2576
- });
2577
- this.sendActionExecutionArgs({
2578
- actionExecutionId,
2579
- args
2580
- });
2581
- this.sendActionExecutionEnd({
2582
- actionExecutionId
2583
- });
2431
+ sendActionExecution(actionExecutionId, toolName, args) {
2432
+ this.sendActionExecutionStart(actionExecutionId, toolName);
2433
+ this.sendActionExecutionArgs(args);
2434
+ this.sendActionExecutionEnd();
2584
2435
  }
2585
- sendActionExecutionResult({ actionExecutionId, actionName, result }) {
2436
+ sendActionExecutionResult(actionExecutionId, actionName, result) {
2586
2437
  this.next({
2587
2438
  type: "ActionExecutionResult",
2588
2439
  actionName,
@@ -2590,7 +2441,7 @@ var RuntimeEventSubject = class extends ReplaySubject2 {
2590
2441
  result
2591
2442
  });
2592
2443
  }
2593
- sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
2444
+ sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
2594
2445
  this.next({
2595
2446
  type: "AgentStateMessage",
2596
2447
  threadId,
@@ -2611,8 +2462,8 @@ var RuntimeEventSource = class {
2611
2462
  async stream(callback) {
2612
2463
  this.callback = callback;
2613
2464
  }
2614
- sendErrorMessageToChat(message = "An error occurred. Please try again.") {
2615
- const errorMessage = `\u274C ${message}`;
2465
+ sendErrorMessageToChat() {
2466
+ const errorMessage = "\u274C An error occurred. Please try again.";
2616
2467
  if (!this.callback) {
2617
2468
  this.stream(async (eventStream$) => {
2618
2469
  eventStream$.sendTextMessage(randomId3(), errorMessage);
@@ -2627,19 +2478,27 @@ var RuntimeEventSource = class {
2627
2478
  this.sendErrorMessageToChat();
2628
2479
  });
2629
2480
  return this.eventStream$.pipe(
2481
+ // mark tools for server side execution
2482
+ map((event) => {
2483
+ if (event.type === "ActionExecutionStart") {
2484
+ if (event.scope !== "passThrough") {
2485
+ event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
2486
+ }
2487
+ }
2488
+ return event;
2489
+ }),
2630
2490
  // track state
2631
2491
  scan2((acc, event) => {
2632
2492
  acc = {
2633
2493
  ...acc
2634
2494
  };
2635
2495
  if (event.type === "ActionExecutionStart") {
2636
- acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
2496
+ acc.callActionServerSide = event.scope === "server";
2637
2497
  acc.args = "";
2638
2498
  acc.actionExecutionId = event.actionExecutionId;
2639
2499
  if (acc.callActionServerSide) {
2640
2500
  acc.action = serverSideActions.find((action) => action.name === event.actionName);
2641
2501
  }
2642
- acc.actionExecutionParentMessageId = event.parentMessageId;
2643
2502
  } else if (event.type === "ActionExecutionArgs") {
2644
2503
  acc.args += event.args;
2645
2504
  }
@@ -2650,13 +2509,12 @@ var RuntimeEventSource = class {
2650
2509
  callActionServerSide: false,
2651
2510
  args: "",
2652
2511
  actionExecutionId: null,
2653
- action: null,
2654
- actionExecutionParentMessageId: null
2512
+ action: null
2655
2513
  }),
2656
2514
  concatMap((eventWithState) => {
2657
2515
  if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
2658
2516
  const toolCallEventStream$ = new RuntimeEventSubject();
2659
- executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionParentMessageId, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
2517
+ executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
2660
2518
  console.error(error);
2661
2519
  });
2662
2520
  telemetry_client_default.capture("oss.runtime.server_action_executed", {});
@@ -2669,7 +2527,7 @@ var RuntimeEventSource = class {
2669
2527
  }
2670
2528
  };
2671
2529
  __name(RuntimeEventSource, "RuntimeEventSource");
2672
- async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
2530
+ async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
2673
2531
  var _a;
2674
2532
  if (guardrailsResult$) {
2675
2533
  const { status } = await firstValueFrom(guardrailsResult$);
@@ -2689,33 +2547,10 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
2689
2547
  }
2690
2548
  }
2691
2549
  if (isLangGraphAgentAction(action)) {
2692
- const result = `${action.name} agent started`;
2693
- const agentExecution = plainToInstance2(ActionExecutionMessage, {
2694
- id: actionExecutionId,
2695
- createdAt: /* @__PURE__ */ new Date(),
2696
- name: action.name,
2697
- arguments: JSON.parse(actionArguments),
2698
- parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
2699
- });
2700
- const agentExecutionResult = plainToInstance2(ResultMessage, {
2701
- id: "result-" + actionExecutionId,
2702
- createdAt: /* @__PURE__ */ new Date(),
2703
- actionExecutionId,
2704
- actionName: action.name,
2705
- result
2706
- });
2707
- eventStream$.sendActionExecutionResult({
2708
- actionExecutionId,
2709
- actionName: action.name,
2710
- result
2711
- });
2550
+ eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
2712
2551
  const stream = await action.langGraphAgentHandler({
2713
2552
  name: action.name,
2714
- actionInputsWithoutAgents,
2715
- additionalMessages: [
2716
- agentExecution,
2717
- agentExecutionResult
2718
- ]
2553
+ actionInputsWithoutAgents
2719
2554
  });
2720
2555
  from2(stream).subscribe({
2721
2556
  next: (event) => eventStream$.next(event),
@@ -2738,12 +2573,9 @@ __name(executeAction, "executeAction");
2738
2573
 
2739
2574
  // src/graphql/resolvers/copilot.resolver.ts
2740
2575
  import { GraphQLJSONObject } from "graphql-scalars";
2741
- import { plainToInstance as plainToInstance3 } from "class-transformer";
2576
+ import { plainToInstance as plainToInstance2 } from "class-transformer";
2742
2577
  import { GraphQLError } from "graphql";
2743
2578
  import { randomId as randomId4 } from "@copilotkit/shared";
2744
-
2745
- // src/graphql/types/agents-response.type.ts
2746
- import { Field as Field12, ObjectType as ObjectType3 } from "type-graphql";
2747
2579
  function _ts_decorate12(decorators, target, key, desc) {
2748
2580
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2749
2581
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -2760,58 +2592,6 @@ function _ts_metadata12(k, v) {
2760
2592
  return Reflect.metadata(k, v);
2761
2593
  }
2762
2594
  __name(_ts_metadata12, "_ts_metadata");
2763
- var Agent = class {
2764
- id;
2765
- name;
2766
- description;
2767
- };
2768
- __name(Agent, "Agent");
2769
- _ts_decorate12([
2770
- Field12(() => String),
2771
- _ts_metadata12("design:type", String)
2772
- ], Agent.prototype, "id", void 0);
2773
- _ts_decorate12([
2774
- Field12(() => String),
2775
- _ts_metadata12("design:type", String)
2776
- ], Agent.prototype, "name", void 0);
2777
- _ts_decorate12([
2778
- Field12(() => String),
2779
- _ts_metadata12("design:type", String)
2780
- ], Agent.prototype, "description", void 0);
2781
- Agent = _ts_decorate12([
2782
- ObjectType3()
2783
- ], Agent);
2784
- var AgentsResponse = class {
2785
- agents;
2786
- };
2787
- __name(AgentsResponse, "AgentsResponse");
2788
- _ts_decorate12([
2789
- Field12(() => [
2790
- Agent
2791
- ]),
2792
- _ts_metadata12("design:type", Array)
2793
- ], AgentsResponse.prototype, "agents", void 0);
2794
- AgentsResponse = _ts_decorate12([
2795
- ObjectType3()
2796
- ], AgentsResponse);
2797
-
2798
- // src/graphql/resolvers/copilot.resolver.ts
2799
- function _ts_decorate13(decorators, target, key, desc) {
2800
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2801
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2802
- r = Reflect.decorate(decorators, target, key, desc);
2803
- else
2804
- for (var i = decorators.length - 1; i >= 0; i--)
2805
- if (d = decorators[i])
2806
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2807
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2808
- }
2809
- __name(_ts_decorate13, "_ts_decorate");
2810
- function _ts_metadata13(k, v) {
2811
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
2812
- return Reflect.metadata(k, v);
2813
- }
2814
- __name(_ts_metadata13, "_ts_metadata");
2815
2595
  function _ts_param(paramIndex, decorator) {
2816
2596
  return function(target, key) {
2817
2597
  decorator(target, key, paramIndex);
@@ -2853,17 +2633,6 @@ var CopilotResolver = class {
2853
2633
  async hello() {
2854
2634
  return "Hello World";
2855
2635
  }
2856
- async availableAgents(ctx) {
2857
- let logger2 = ctx.logger.child({
2858
- component: "CopilotResolver.availableAgents"
2859
- });
2860
- logger2.debug("Processing");
2861
- const agents = await ctx._copilotkit.runtime.discoverAgentsFromEndpoints(ctx);
2862
- logger2.debug("Event source created, creating response");
2863
- return {
2864
- agents
2865
- };
2866
- }
2867
2636
  async generateCopilotResponse(ctx, data, properties) {
2868
2637
  var _a, _b, _c;
2869
2638
  telemetry_client_default.capture("oss.runtime.copilot_request_created", {
@@ -2967,7 +2736,7 @@ var CopilotResolver = class {
2967
2736
  reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
2968
2737
  });
2969
2738
  outputMessages = [
2970
- plainToInstance3(TextMessage, {
2739
+ plainToInstance2(TextMessage, {
2971
2740
  id: randomId4(),
2972
2741
  createdAt: /* @__PURE__ */ new Date(),
2973
2742
  content: result.reason,
@@ -3016,15 +2785,12 @@ var CopilotResolver = class {
3016
2785
  // skip until this message start event
3017
2786
  skipWhile((e) => e !== event),
3018
2787
  // take until the message end event
3019
- takeWhile((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
3020
- // filter out any other message events or message ids
3021
- filter((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
2788
+ takeWhile((e) => e.type != RuntimeEventTypes.TextMessageEnd)
3022
2789
  );
3023
2790
  const streamingTextStatus = new Subject();
3024
2791
  const messageId = event.messageId;
3025
2792
  pushMessage({
3026
2793
  id: messageId,
3027
- parentMessageId: event.parentMessageId,
3028
2794
  status: firstValueFrom2(streamingTextStatus),
3029
2795
  createdAt: /* @__PURE__ */ new Date(),
3030
2796
  role: MessageRole.assistant,
@@ -3037,7 +2803,7 @@ var CopilotResolver = class {
3037
2803
  reason,
3038
2804
  messageId: messageId2
3039
2805
  }, "Text streaming interrupted");
3040
- streamingTextStatus.next(plainToInstance3(FailedMessageStatus, {
2806
+ streamingTextStatus.next(plainToInstance2(FailedMessageStatus, {
3041
2807
  reason
3042
2808
  }));
3043
2809
  responseStatus$.next(new MessageStreamInterruptedResponse({
@@ -3070,7 +2836,7 @@ var CopilotResolver = class {
3070
2836
  streamingTextStatus.next(new SuccessMessageStatus());
3071
2837
  stopStreamingText();
3072
2838
  textSubscription == null ? void 0 : textSubscription.unsubscribe();
3073
- outputMessages.push(plainToInstance3(TextMessage, {
2839
+ outputMessages.push(plainToInstance2(TextMessage, {
3074
2840
  id: messageId,
3075
2841
  createdAt: /* @__PURE__ */ new Date(),
3076
2842
  content: textChunks.join(""),
@@ -3083,20 +2849,14 @@ var CopilotResolver = class {
3083
2849
  break;
3084
2850
  case RuntimeEventTypes.ActionExecutionStart:
3085
2851
  logger2.debug("Action execution start event received");
3086
- const actionExecutionArgumentStream = eventStream.pipe(
3087
- skipWhile((e) => e !== event),
3088
- // take until the action execution end event
3089
- takeWhile((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
3090
- // filter out any other action execution events or action execution ids
3091
- filter((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
3092
- );
2852
+ const actionExecutionArgumentStream = eventStream.pipe(skipWhile((e) => e !== event), takeWhile((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
3093
2853
  const streamingArgumentsStatus = new Subject();
3094
2854
  pushMessage({
3095
2855
  id: event.actionExecutionId,
3096
- parentMessageId: event.parentMessageId,
3097
2856
  status: firstValueFrom2(streamingArgumentsStatus),
3098
2857
  createdAt: /* @__PURE__ */ new Date(),
3099
2858
  name: event.actionName,
2859
+ scope: event.scope,
3100
2860
  arguments: new Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
3101
2861
  logger2.debug("Action execution argument stream created");
3102
2862
  const argumentChunks = [];
@@ -3112,7 +2872,7 @@ var CopilotResolver = class {
3112
2872
  logger2.error({
3113
2873
  err
3114
2874
  }, "Error in action execution argument stream");
3115
- streamingArgumentsStatus.next(plainToInstance3(FailedMessageStatus, {
2875
+ streamingArgumentsStatus.next(plainToInstance2(FailedMessageStatus, {
3116
2876
  reason: "An unknown error has occurred in the action execution argument stream"
3117
2877
  }));
3118
2878
  stopStreamingArguments();
@@ -3123,10 +2883,11 @@ var CopilotResolver = class {
3123
2883
  streamingArgumentsStatus.next(new SuccessMessageStatus());
3124
2884
  stopStreamingArguments();
3125
2885
  actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
3126
- outputMessages.push(plainToInstance3(ActionExecutionMessage, {
2886
+ outputMessages.push(plainToInstance2(ActionExecutionMessage, {
3127
2887
  id: event.actionExecutionId,
3128
2888
  createdAt: /* @__PURE__ */ new Date(),
3129
2889
  name: event.actionName,
2890
+ scope: event.scope,
3130
2891
  arguments: argumentChunks.join("")
3131
2892
  }));
3132
2893
  }
@@ -3139,15 +2900,15 @@ var CopilotResolver = class {
3139
2900
  result: event.result
3140
2901
  }, "Action execution result event received");
3141
2902
  pushMessage({
3142
- id: "result-" + event.actionExecutionId,
2903
+ id: randomId4(),
3143
2904
  status: new SuccessMessageStatus(),
3144
2905
  createdAt: /* @__PURE__ */ new Date(),
3145
2906
  actionExecutionId: event.actionExecutionId,
3146
2907
  actionName: event.actionName,
3147
2908
  result: event.result
3148
2909
  });
3149
- outputMessages.push(plainToInstance3(ResultMessage, {
3150
- id: "result-" + event.actionExecutionId,
2910
+ outputMessages.push(plainToInstance2(ResultMessage, {
2911
+ id: randomId4(),
3151
2912
  createdAt: /* @__PURE__ */ new Date(),
3152
2913
  actionExecutionId: event.actionExecutionId,
3153
2914
  actionName: event.actionName,
@@ -3171,7 +2932,7 @@ var CopilotResolver = class {
3171
2932
  role: MessageRole.assistant,
3172
2933
  createdAt: /* @__PURE__ */ new Date()
3173
2934
  });
3174
- outputMessages.push(plainToInstance3(AgentStateMessage, {
2935
+ outputMessages.push(plainToInstance2(AgentStateMessage, {
3175
2936
  id: randomId4(),
3176
2937
  threadId: event.threadId,
3177
2938
  agentName: event.agentName,
@@ -3216,37 +2977,28 @@ var CopilotResolver = class {
3216
2977
  }
3217
2978
  };
3218
2979
  __name(CopilotResolver, "CopilotResolver");
3219
- _ts_decorate13([
2980
+ _ts_decorate12([
3220
2981
  Query(() => String),
3221
- _ts_metadata13("design:type", Function),
3222
- _ts_metadata13("design:paramtypes", []),
3223
- _ts_metadata13("design:returntype", Promise)
2982
+ _ts_metadata12("design:type", Function),
2983
+ _ts_metadata12("design:paramtypes", []),
2984
+ _ts_metadata12("design:returntype", Promise)
3224
2985
  ], CopilotResolver.prototype, "hello", null);
3225
- _ts_decorate13([
3226
- Query(() => AgentsResponse),
3227
- _ts_param(0, Ctx()),
3228
- _ts_metadata13("design:type", Function),
3229
- _ts_metadata13("design:paramtypes", [
3230
- typeof GraphQLContext === "undefined" ? Object : GraphQLContext
3231
- ]),
3232
- _ts_metadata13("design:returntype", Promise)
3233
- ], CopilotResolver.prototype, "availableAgents", null);
3234
- _ts_decorate13([
2986
+ _ts_decorate12([
3235
2987
  Mutation(() => CopilotResponse),
3236
2988
  _ts_param(0, Ctx()),
3237
2989
  _ts_param(1, Arg("data")),
3238
2990
  _ts_param(2, Arg("properties", () => GraphQLJSONObject, {
3239
2991
  nullable: true
3240
2992
  })),
3241
- _ts_metadata13("design:type", Function),
3242
- _ts_metadata13("design:paramtypes", [
2993
+ _ts_metadata12("design:type", Function),
2994
+ _ts_metadata12("design:paramtypes", [
3243
2995
  typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
3244
2996
  typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
3245
2997
  typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
3246
2998
  ]),
3247
- _ts_metadata13("design:returntype", Promise)
2999
+ _ts_metadata12("design:returntype", Promise)
3248
3000
  ], CopilotResolver.prototype, "generateCopilotResponse", null);
3249
- CopilotResolver = _ts_decorate13([
3001
+ CopilotResolver = _ts_decorate12([
3250
3002
  Resolver(() => CopilotResponse)
3251
3003
  ], CopilotResolver);
3252
3004
 
@@ -3392,4 +3144,4 @@ export {
3392
3144
  getCommonConfig,
3393
3145
  copilotRuntimeNodeHttpEndpoint
3394
3146
  };
3395
- //# sourceMappingURL=chunk-2V7BHSFE.mjs.map
3147
+ //# sourceMappingURL=chunk-ZSWCEADS.mjs.map