@copilotkit/runtime 1.4.8 → 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.
Files changed (73) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/__snapshots__/schema/schema.graphql +7 -9
  3. package/dist/{chunk-W7GP2EOT.mjs → chunk-4AYRDPWK.mjs} +239 -65
  4. package/dist/chunk-4AYRDPWK.mjs.map +1 -0
  5. package/dist/{chunk-LSLFIYKP.mjs → chunk-7BOO3OFP.mjs} +2 -2
  6. package/dist/{chunk-GGNRDS7N.mjs → chunk-GSTWFOZF.mjs} +2 -2
  7. package/dist/{chunk-TA5I5LYF.mjs → chunk-OMAAKIJQ.mjs} +2 -2
  8. package/dist/{chunk-R6AUAQK6.mjs → chunk-PXS4SBRF.mjs} +423 -299
  9. package/dist/chunk-PXS4SBRF.mjs.map +1 -0
  10. package/dist/{chunk-B74M7FXG.mjs → chunk-RFF5IIZJ.mjs} +3 -2
  11. package/dist/chunk-RFF5IIZJ.mjs.map +1 -0
  12. package/dist/{copilot-runtime-48d7c2fc.d.ts → copilot-runtime-2e46a7b6.d.ts} +2 -2
  13. package/dist/graphql/types/converted/index.d.ts +1 -1
  14. package/dist/graphql/types/converted/index.js +2 -1
  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-ac43305a.d.ts → groq-adapter-7bf6824b.d.ts} +1 -1
  18. package/dist/{index-10b1c870.d.ts → index-ff3fbc33.d.ts} +7 -8
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +747 -448
  21. package/dist/index.js.map +1 -1
  22. package/dist/index.mjs +6 -6
  23. package/dist/{langserve-b74e8606.d.ts → langserve-f318db89.d.ts} +51 -12
  24. package/dist/lib/index.d.ts +4 -4
  25. package/dist/lib/index.js +714 -439
  26. package/dist/lib/index.js.map +1 -1
  27. package/dist/lib/index.mjs +6 -6
  28. package/dist/lib/integrations/index.d.ts +4 -4
  29. package/dist/lib/integrations/index.js +71 -30
  30. package/dist/lib/integrations/index.js.map +1 -1
  31. package/dist/lib/integrations/index.mjs +6 -6
  32. package/dist/lib/integrations/nest/index.d.ts +3 -3
  33. package/dist/lib/integrations/nest/index.js +71 -30
  34. package/dist/lib/integrations/nest/index.js.map +1 -1
  35. package/dist/lib/integrations/nest/index.mjs +4 -4
  36. package/dist/lib/integrations/node-express/index.d.ts +3 -3
  37. package/dist/lib/integrations/node-express/index.js +71 -30
  38. package/dist/lib/integrations/node-express/index.js.map +1 -1
  39. package/dist/lib/integrations/node-express/index.mjs +4 -4
  40. package/dist/lib/integrations/node-http/index.d.ts +3 -3
  41. package/dist/lib/integrations/node-http/index.js +71 -30
  42. package/dist/lib/integrations/node-http/index.js.map +1 -1
  43. package/dist/lib/integrations/node-http/index.mjs +3 -3
  44. package/dist/service-adapters/index.d.ts +4 -4
  45. package/dist/service-adapters/index.js +238 -64
  46. package/dist/service-adapters/index.js.map +1 -1
  47. package/dist/service-adapters/index.mjs +1 -1
  48. package/package.json +2 -2
  49. package/src/agents/langgraph/event-source.ts +140 -148
  50. package/src/agents/langgraph/events.ts +1 -1
  51. package/src/graphql/inputs/message.input.ts +15 -3
  52. package/src/graphql/resolvers/copilot.resolver.ts +32 -6
  53. package/src/graphql/types/converted/index.ts +4 -3
  54. package/src/graphql/types/copilot-response.type.ts +12 -3
  55. package/src/graphql/types/enums.ts +0 -11
  56. package/src/lib/runtime/remote-action-constructors.ts +4 -2
  57. package/src/lib/runtime/remote-actions.ts +1 -0
  58. package/src/lib/runtime/remote-lg-action.ts +159 -140
  59. package/src/service-adapters/anthropic/anthropic-adapter.ts +16 -6
  60. package/src/service-adapters/conversion.ts +2 -1
  61. package/src/service-adapters/events.ts +116 -52
  62. package/src/service-adapters/experimental/ollama/ollama-adapter.ts +7 -3
  63. package/src/service-adapters/groq/groq-adapter.ts +23 -8
  64. package/src/service-adapters/langchain/utils.ts +55 -32
  65. package/src/service-adapters/openai/openai-adapter.ts +22 -9
  66. package/src/service-adapters/openai/openai-assistant-adapter.ts +22 -8
  67. package/src/service-adapters/unify/unify-adapter.ts +28 -11
  68. package/dist/chunk-B74M7FXG.mjs.map +0 -1
  69. package/dist/chunk-R6AUAQK6.mjs.map +0 -1
  70. package/dist/chunk-W7GP2EOT.mjs.map +0 -1
  71. /package/dist/{chunk-LSLFIYKP.mjs.map → chunk-7BOO3OFP.mjs.map} +0 -0
  72. /package/dist/{chunk-GGNRDS7N.mjs.map → chunk-GSTWFOZF.mjs.map} +0 -0
  73. /package/dist/{chunk-TA5I5LYF.mjs.map → chunk-OMAAKIJQ.mjs.map} +0 -0
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.4.8",
47
+ version: "1.5.0-coagents-v0-3.0",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -432,6 +432,8 @@ var OpenAIAdapter = class {
432
432
  eventSource.stream(async (eventStream$) => {
433
433
  var _a, _b;
434
434
  let mode = null;
435
+ let currentMessageId;
436
+ let currentToolCallId;
435
437
  for await (const chunk of stream) {
436
438
  if (chunk.choices.length === 0) {
437
439
  continue;
@@ -440,30 +442,52 @@ var OpenAIAdapter = class {
440
442
  const content = chunk.choices[0].delta.content;
441
443
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
442
444
  mode = null;
443
- eventStream$.sendTextMessageEnd();
445
+ eventStream$.sendTextMessageEnd({
446
+ messageId: currentMessageId
447
+ });
444
448
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
445
449
  mode = null;
446
- eventStream$.sendActionExecutionEnd();
450
+ eventStream$.sendActionExecutionEnd({
451
+ actionExecutionId: currentToolCallId
452
+ });
447
453
  }
448
454
  if (mode === null) {
449
455
  if (toolCall == null ? void 0 : toolCall.id) {
450
456
  mode = "function";
451
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
457
+ currentToolCallId = toolCall.id;
458
+ eventStream$.sendActionExecutionStart({
459
+ actionExecutionId: currentToolCallId,
460
+ parentMessageId: chunk.id,
461
+ actionName: toolCall.function.name
462
+ });
452
463
  } else if (content) {
453
464
  mode = "message";
454
- eventStream$.sendTextMessageStart(chunk.id);
465
+ currentMessageId = chunk.id;
466
+ eventStream$.sendTextMessageStart({
467
+ messageId: currentMessageId
468
+ });
455
469
  }
456
470
  }
457
471
  if (mode === "message" && content) {
458
- eventStream$.sendTextMessageContent(content);
472
+ eventStream$.sendTextMessageContent({
473
+ messageId: currentMessageId,
474
+ content
475
+ });
459
476
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
460
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
477
+ eventStream$.sendActionExecutionArgs({
478
+ actionExecutionId: currentToolCallId,
479
+ args: toolCall.function.arguments
480
+ });
461
481
  }
462
482
  }
463
483
  if (mode === "message") {
464
- eventStream$.sendTextMessageEnd();
484
+ eventStream$.sendTextMessageEnd({
485
+ messageId: currentMessageId
486
+ });
465
487
  } else if (mode === "function") {
466
- eventStream$.sendActionExecutionEnd();
488
+ eventStream$.sendActionExecutionEnd({
489
+ actionExecutionId: currentToolCallId
490
+ });
467
491
  }
468
492
  eventStream$.complete();
469
493
  });
@@ -531,17 +555,25 @@ function isBaseMessageChunk(message) {
531
555
  __name(isBaseMessageChunk, "isBaseMessageChunk");
532
556
  function maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution) {
533
557
  if (actionExecution) {
534
- eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, "Sending a message");
558
+ eventStream$.sendActionExecutionResult({
559
+ actionExecutionId: actionExecution.id,
560
+ actionName: actionExecution.name,
561
+ result: "Sending a message"
562
+ });
535
563
  }
536
564
  }
537
565
  __name(maybeSendActionExecutionResultIsMessage, "maybeSendActionExecutionResultIsMessage");
538
566
  async function streamLangChainResponse({ result, eventStream$, actionExecution }) {
539
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
567
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
540
568
  if (typeof result === "string") {
541
569
  if (!actionExecution) {
542
570
  eventStream$.sendTextMessage((0, import_shared2.randomId)(), result);
543
571
  } else {
544
- eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, result);
572
+ eventStream$.sendActionExecutionResult({
573
+ actionExecutionId: actionExecution.id,
574
+ actionName: actionExecution.name,
575
+ result
576
+ });
545
577
  }
546
578
  } else if (isAIMessage(result)) {
547
579
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
@@ -549,7 +581,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
549
581
  eventStream$.sendTextMessage((0, import_shared2.randomId)(), result.content);
550
582
  }
551
583
  for (const toolCall of result.tool_calls) {
552
- eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
584
+ eventStream$.sendActionExecution({
585
+ actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
586
+ actionName: toolCall.name,
587
+ args: JSON.stringify(toolCall.args)
588
+ });
553
589
  }
554
590
  } else if (isBaseMessageChunk(result)) {
555
591
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
@@ -558,13 +594,18 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
558
594
  }
559
595
  if ((_b = result.lc_kwargs) == null ? void 0 : _b.tool_calls) {
560
596
  for (const toolCall of (_c = result.lc_kwargs) == null ? void 0 : _c.tool_calls) {
561
- eventStream$.sendActionExecution(toolCall.id || (0, import_shared2.randomId)(), toolCall.name, JSON.stringify(toolCall.args));
597
+ eventStream$.sendActionExecution({
598
+ actionExecutionId: toolCall.id || (0, import_shared2.randomId)(),
599
+ actionName: toolCall.name,
600
+ args: JSON.stringify(toolCall.args)
601
+ });
562
602
  }
563
603
  }
564
604
  } else if (result && "getReader" in result) {
565
605
  maybeSendActionExecutionResultIsMessage(eventStream$, actionExecution);
566
606
  let reader = result.getReader();
567
607
  let mode = null;
608
+ let currentMessageId;
568
609
  const toolCallDetails = {
569
610
  name: null,
570
611
  id: null,
@@ -578,9 +619,12 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
578
619
  let toolCallId = void 0;
579
620
  let toolCallArgs = void 0;
580
621
  let hasToolCall = false;
581
- let content = value == null ? void 0 : value.content;
622
+ let content = "";
623
+ if (value && value.content) {
624
+ content = Array.isArray(value.content) ? ((_d = value.content[0]) == null ? void 0 : _d.text) ?? "" : value.content;
625
+ }
582
626
  if (isAIMessageChunk(value)) {
583
- let chunk = (_d = value.tool_call_chunks) == null ? void 0 : _d[0];
627
+ let chunk = (_e = value.tool_call_chunks) == null ? void 0 : _e[0];
584
628
  toolCallArgs = chunk == null ? void 0 : chunk.args;
585
629
  hasToolCall = chunk != void 0;
586
630
  if (chunk == null ? void 0 : chunk.name)
@@ -595,18 +639,22 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
595
639
  toolCallName = toolCallDetails.name;
596
640
  toolCallId = toolCallDetails.id;
597
641
  } else if (isBaseMessageChunk(value)) {
598
- let chunk = (_f = (_e = value.additional_kwargs) == null ? void 0 : _e.tool_calls) == null ? void 0 : _f[0];
599
- toolCallName = (_g = chunk == null ? void 0 : chunk.function) == null ? void 0 : _g.name;
642
+ let chunk = (_g = (_f = value.additional_kwargs) == null ? void 0 : _f.tool_calls) == null ? void 0 : _g[0];
643
+ toolCallName = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.name;
600
644
  toolCallId = chunk == null ? void 0 : chunk.id;
601
- toolCallArgs = (_h = chunk == null ? void 0 : chunk.function) == null ? void 0 : _h.arguments;
645
+ toolCallArgs = (_i = chunk == null ? void 0 : chunk.function) == null ? void 0 : _i.arguments;
602
646
  hasToolCall = (chunk == null ? void 0 : chunk.function) != void 0;
603
647
  }
604
648
  if (mode === "message" && (toolCallId || done)) {
605
649
  mode = null;
606
- eventStream$.sendTextMessageEnd();
650
+ eventStream$.sendTextMessageEnd({
651
+ messageId: currentMessageId
652
+ });
607
653
  } else if (mode === "function" && (!hasToolCall || done)) {
608
654
  mode = null;
609
- eventStream$.sendActionExecutionEnd();
655
+ eventStream$.sendActionExecutionEnd({
656
+ actionExecutionId: toolCallId
657
+ });
610
658
  }
611
659
  if (done) {
612
660
  break;
@@ -614,21 +662,40 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
614
662
  if (mode === null) {
615
663
  if (hasToolCall && toolCallId && toolCallName) {
616
664
  mode = "function";
617
- eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
665
+ eventStream$.sendActionExecutionStart({
666
+ actionExecutionId: toolCallId,
667
+ actionName: toolCallName,
668
+ parentMessageId: (_j = value.lc_kwargs) == null ? void 0 : _j.id
669
+ });
618
670
  } else if (content) {
619
671
  mode = "message";
620
- eventStream$.sendTextMessageStart((0, import_shared2.randomId)());
672
+ currentMessageId = ((_k = value.lc_kwargs) == null ? void 0 : _k.id) || (0, import_shared2.randomId)();
673
+ eventStream$.sendTextMessageStart({
674
+ messageId: currentMessageId
675
+ });
621
676
  }
622
677
  }
623
678
  if (mode === "message" && content) {
624
- eventStream$.sendTextMessageContent(Array.isArray(content) ? ((_i = content[0]) == null ? void 0 : _i.text) ?? "" : content);
679
+ eventStream$.sendTextMessageContent({
680
+ messageId: currentMessageId,
681
+ content
682
+ });
625
683
  } else if (mode === "function" && toolCallArgs) {
626
684
  if (toolCallDetails.index !== toolCallDetails.prevIndex) {
627
- eventStream$.sendActionExecutionEnd();
628
- eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
685
+ eventStream$.sendActionExecutionEnd({
686
+ actionExecutionId: toolCallId
687
+ });
688
+ eventStream$.sendActionExecutionStart({
689
+ actionExecutionId: toolCallId,
690
+ actionName: toolCallName,
691
+ parentMessageId: (_l = value.lc_kwargs) == null ? void 0 : _l.id
692
+ });
629
693
  toolCallDetails.prevIndex = toolCallDetails.index;
630
694
  }
631
- eventStream$.sendActionExecutionArgs(toolCallArgs);
695
+ eventStream$.sendActionExecutionArgs({
696
+ actionExecutionId: toolCallId,
697
+ args: toolCallArgs
698
+ });
632
699
  }
633
700
  } catch (error) {
634
701
  console.error("Error reading from stream", error);
@@ -636,7 +703,11 @@ async function streamLangChainResponse({ result, eventStream$, actionExecution }
636
703
  }
637
704
  }
638
705
  } else if (actionExecution) {
639
- eventStream$.sendActionExecutionResult(actionExecution.id, actionExecution.name, encodeResult(result));
706
+ eventStream$.sendActionExecutionResult({
707
+ actionExecutionId: actionExecution.id,
708
+ actionName: actionExecution.name,
709
+ result: encodeResult(result)
710
+ });
640
711
  } else {
641
712
  throw new Error("Invalid return type from LangChain function.");
642
713
  }
@@ -816,21 +887,33 @@ var OpenAIAssistantAdapter = class {
816
887
  eventSource.stream(async (eventStream$) => {
817
888
  var _a, _b, _c, _d, _e, _f;
818
889
  let inFunctionCall = false;
890
+ let currentMessageId;
891
+ let currentToolCallId;
819
892
  for await (const chunk of stream) {
820
893
  switch (chunk.event) {
821
894
  case "thread.message.created":
822
895
  if (inFunctionCall) {
823
- eventStream$.sendActionExecutionEnd();
896
+ eventStream$.sendActionExecutionEnd({
897
+ actionExecutionId: currentToolCallId
898
+ });
824
899
  }
825
- eventStream$.sendTextMessageStart(chunk.data.id);
900
+ currentMessageId = chunk.data.id;
901
+ eventStream$.sendTextMessageStart({
902
+ messageId: currentMessageId
903
+ });
826
904
  break;
827
905
  case "thread.message.delta":
828
906
  if (((_a = chunk.data.delta.content) == null ? void 0 : _a[0].type) === "text") {
829
- eventStream$.sendTextMessageContent((_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value);
907
+ eventStream$.sendTextMessageContent({
908
+ messageId: currentMessageId,
909
+ content: (_b = chunk.data.delta.content) == null ? void 0 : _b[0].text.value
910
+ });
830
911
  }
831
912
  break;
832
913
  case "thread.message.completed":
833
- eventStream$.sendTextMessageEnd();
914
+ eventStream$.sendTextMessageEnd({
915
+ messageId: currentMessageId
916
+ });
834
917
  break;
835
918
  case "thread.run.step.delta":
836
919
  let toolCallId;
@@ -843,18 +926,30 @@ var OpenAIAssistantAdapter = class {
843
926
  }
844
927
  if (toolCallName && toolCallId) {
845
928
  if (inFunctionCall) {
846
- eventStream$.sendActionExecutionEnd();
929
+ eventStream$.sendActionExecutionEnd({
930
+ actionExecutionId: currentToolCallId
931
+ });
847
932
  }
848
933
  inFunctionCall = true;
849
- eventStream$.sendActionExecutionStart(toolCallId, toolCallName);
934
+ currentToolCallId = toolCallId;
935
+ eventStream$.sendActionExecutionStart({
936
+ actionExecutionId: currentToolCallId,
937
+ parentMessageId: chunk.data.id,
938
+ actionName: toolCallName
939
+ });
850
940
  } else if (toolCallArgs) {
851
- eventStream$.sendActionExecutionArgs(toolCallArgs);
941
+ eventStream$.sendActionExecutionArgs({
942
+ actionExecutionId: currentToolCallId,
943
+ args: toolCallArgs
944
+ });
852
945
  }
853
946
  break;
854
947
  }
855
948
  }
856
949
  if (inFunctionCall) {
857
- eventStream$.sendActionExecutionEnd();
950
+ eventStream$.sendActionExecutionEnd({
951
+ actionExecutionId: currentToolCallId
952
+ });
858
953
  }
859
954
  eventStream$.complete();
860
955
  });
@@ -907,46 +1002,77 @@ var UnifyAdapter = class {
907
1002
  }
908
1003
  });
909
1004
  let model = null;
1005
+ let currentMessageId;
1006
+ let currentToolCallId;
910
1007
  request.eventSource.stream(async (eventStream$) => {
911
1008
  var _a, _b;
912
1009
  let mode = null;
913
1010
  for await (const chunk of stream) {
914
1011
  if (this.start) {
915
1012
  model = chunk.model;
916
- eventStream$.sendTextMessageStart((0, import_shared4.randomId)());
917
- eventStream$.sendTextMessageContent(`Model used: ${model}
918
- `);
919
- eventStream$.sendTextMessageEnd();
1013
+ currentMessageId = (0, import_shared4.randomId)();
1014
+ eventStream$.sendTextMessageStart({
1015
+ messageId: currentMessageId
1016
+ });
1017
+ eventStream$.sendTextMessageContent({
1018
+ messageId: currentMessageId,
1019
+ content: `Model used: ${model}
1020
+ `
1021
+ });
1022
+ eventStream$.sendTextMessageEnd({
1023
+ messageId: currentMessageId
1024
+ });
920
1025
  this.start = false;
921
1026
  }
922
1027
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
923
1028
  const content = chunk.choices[0].delta.content;
924
1029
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
925
1030
  mode = null;
926
- eventStream$.sendTextMessageEnd();
1031
+ eventStream$.sendTextMessageEnd({
1032
+ messageId: currentMessageId
1033
+ });
927
1034
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
928
1035
  mode = null;
929
- eventStream$.sendActionExecutionEnd();
1036
+ eventStream$.sendActionExecutionEnd({
1037
+ actionExecutionId: currentToolCallId
1038
+ });
930
1039
  }
931
1040
  if (mode === null) {
932
1041
  if (toolCall == null ? void 0 : toolCall.id) {
933
1042
  mode = "function";
934
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
1043
+ currentToolCallId = toolCall.id;
1044
+ eventStream$.sendActionExecutionStart({
1045
+ actionExecutionId: currentToolCallId,
1046
+ actionName: toolCall.function.name
1047
+ });
935
1048
  } else if (content) {
936
1049
  mode = "message";
937
- eventStream$.sendTextMessageStart(chunk.id);
1050
+ currentMessageId = chunk.id;
1051
+ eventStream$.sendTextMessageStart({
1052
+ messageId: currentMessageId
1053
+ });
938
1054
  }
939
1055
  }
940
1056
  if (mode === "message" && content) {
941
- eventStream$.sendTextMessageContent(content);
1057
+ eventStream$.sendTextMessageContent({
1058
+ messageId: currentMessageId,
1059
+ content
1060
+ });
942
1061
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
943
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
1062
+ eventStream$.sendActionExecutionArgs({
1063
+ actionExecutionId: currentToolCallId,
1064
+ args: toolCall.function.arguments
1065
+ });
944
1066
  }
945
1067
  }
946
1068
  if (mode === "message") {
947
- eventStream$.sendTextMessageEnd();
1069
+ eventStream$.sendTextMessageEnd({
1070
+ messageId: currentMessageId
1071
+ });
948
1072
  } else if (mode === "function") {
949
- eventStream$.sendActionExecutionEnd();
1073
+ eventStream$.sendActionExecutionEnd({
1074
+ actionExecutionId: currentToolCallId
1075
+ });
950
1076
  }
951
1077
  eventStream$.complete();
952
1078
  });
@@ -1012,35 +1138,59 @@ var GroqAdapter = class {
1012
1138
  eventSource.stream(async (eventStream$) => {
1013
1139
  var _a, _b;
1014
1140
  let mode = null;
1141
+ let currentMessageId;
1142
+ let currentToolCallId;
1015
1143
  for await (const chunk of stream) {
1016
1144
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
1017
1145
  const content = chunk.choices[0].delta.content;
1018
1146
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
1019
1147
  mode = null;
1020
- eventStream$.sendTextMessageEnd();
1148
+ eventStream$.sendTextMessageEnd({
1149
+ messageId: currentMessageId
1150
+ });
1021
1151
  } else if (mode === "function" && (toolCall === void 0 || (toolCall == null ? void 0 : toolCall.id))) {
1022
1152
  mode = null;
1023
- eventStream$.sendActionExecutionEnd();
1153
+ eventStream$.sendActionExecutionEnd({
1154
+ actionExecutionId: currentToolCallId
1155
+ });
1024
1156
  }
1025
1157
  if (mode === null) {
1026
1158
  if (toolCall == null ? void 0 : toolCall.id) {
1027
1159
  mode = "function";
1028
- eventStream$.sendActionExecutionStart(toolCall.id, toolCall.function.name);
1160
+ currentToolCallId = toolCall.id;
1161
+ eventStream$.sendActionExecutionStart({
1162
+ actionExecutionId: currentToolCallId,
1163
+ actionName: toolCall.function.name,
1164
+ parentMessageId: chunk.id
1165
+ });
1029
1166
  } else if (content) {
1030
1167
  mode = "message";
1031
- eventStream$.sendTextMessageStart(chunk.id);
1168
+ currentMessageId = chunk.id;
1169
+ eventStream$.sendTextMessageStart({
1170
+ messageId: currentMessageId
1171
+ });
1032
1172
  }
1033
1173
  }
1034
1174
  if (mode === "message" && content) {
1035
- eventStream$.sendTextMessageContent(content);
1175
+ eventStream$.sendTextMessageContent({
1176
+ messageId: currentMessageId,
1177
+ content
1178
+ });
1036
1179
  } else if (mode === "function" && ((_b = toolCall == null ? void 0 : toolCall.function) == null ? void 0 : _b.arguments)) {
1037
- eventStream$.sendActionExecutionArgs(toolCall.function.arguments);
1180
+ eventStream$.sendActionExecutionArgs({
1181
+ actionExecutionId: currentToolCallId,
1182
+ args: toolCall.function.arguments
1183
+ });
1038
1184
  }
1039
1185
  }
1040
1186
  if (mode === "message") {
1041
- eventStream$.sendTextMessageEnd();
1187
+ eventStream$.sendTextMessageEnd({
1188
+ messageId: currentMessageId
1189
+ });
1042
1190
  } else if (mode === "function") {
1043
- eventStream$.sendActionExecutionEnd();
1191
+ eventStream$.sendActionExecutionEnd({
1192
+ actionExecutionId: currentToolCallId
1193
+ });
1044
1194
  }
1045
1195
  eventStream$.complete();
1046
1196
  });
@@ -1248,7 +1398,11 @@ var AnthropicAdapter = class {
1248
1398
  mode = "message";
1249
1399
  } else if (chunk.content_block.type === "tool_use") {
1250
1400
  currentToolCallId = chunk.content_block.id;
1251
- eventStream$.sendActionExecutionStart(currentToolCallId, chunk.content_block.name);
1401
+ eventStream$.sendActionExecutionStart({
1402
+ actionExecutionId: currentToolCallId,
1403
+ actionName: chunk.content_block.name,
1404
+ parentMessageId: currentMessageId
1405
+ });
1252
1406
  mode = "function";
1253
1407
  }
1254
1408
  } else if (chunk.type === "content_block_delta") {
@@ -1256,21 +1410,33 @@ var AnthropicAdapter = class {
1256
1410
  const text = filterThinkingTextBuffer.onTextChunk(chunk.delta.text);
1257
1411
  if (text.length > 0) {
1258
1412
  if (!didOutputText) {
1259
- eventStream$.sendTextMessageStart(currentMessageId);
1413
+ eventStream$.sendTextMessageStart({
1414
+ messageId: currentMessageId
1415
+ });
1260
1416
  didOutputText = true;
1261
1417
  }
1262
- eventStream$.sendTextMessageContent(text);
1418
+ eventStream$.sendTextMessageContent({
1419
+ messageId: currentMessageId,
1420
+ content: text
1421
+ });
1263
1422
  }
1264
1423
  } else if (chunk.delta.type === "input_json_delta") {
1265
- eventStream$.sendActionExecutionArgs(chunk.delta.partial_json);
1424
+ eventStream$.sendActionExecutionArgs({
1425
+ actionExecutionId: currentToolCallId,
1426
+ args: chunk.delta.partial_json
1427
+ });
1266
1428
  }
1267
1429
  } else if (chunk.type === "content_block_stop") {
1268
1430
  if (mode === "message") {
1269
1431
  if (didOutputText) {
1270
- eventStream$.sendTextMessageEnd();
1432
+ eventStream$.sendTextMessageEnd({
1433
+ messageId: currentMessageId
1434
+ });
1271
1435
  }
1272
1436
  } else if (mode === "function") {
1273
- eventStream$.sendActionExecutionEnd();
1437
+ eventStream$.sendActionExecutionEnd({
1438
+ actionExecutionId: currentToolCallId
1439
+ });
1274
1440
  }
1275
1441
  }
1276
1442
  }
@@ -1336,11 +1502,19 @@ var ExperimentalOllamaAdapter = class {
1336
1502
  const contents = messages.filter((m) => m.isTextMessage()).map((m) => m.content);
1337
1503
  const _stream = await ollama.stream(contents);
1338
1504
  eventSource.stream(async (eventStream$) => {
1339
- eventStream$.sendTextMessageStart((0, import_shared7.randomId)());
1505
+ const currentMessageId = (0, import_shared7.randomId)();
1506
+ eventStream$.sendTextMessageStart({
1507
+ messageId: currentMessageId
1508
+ });
1340
1509
  for await (const chunkText of _stream) {
1341
- eventStream$.sendTextMessageContent(chunkText);
1510
+ eventStream$.sendTextMessageContent({
1511
+ messageId: currentMessageId,
1512
+ content: chunkText
1513
+ });
1342
1514
  }
1343
- eventStream$.sendTextMessageEnd();
1515
+ eventStream$.sendTextMessageEnd({
1516
+ messageId: currentMessageId
1517
+ });
1344
1518
  eventStream$.complete();
1345
1519
  });
1346
1520
  return {
@@ -1411,163 +1585,167 @@ var RemoteLangGraphEventSource = class {
1411
1585
  }
1412
1586
  return shouldEmitToolCalls === toolCallName;
1413
1587
  }
1588
+ getCurrentContent(event) {
1589
+ var _a, _b, _c, _d, _e;
1590
+ 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);
1591
+ if (!content) {
1592
+ const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
1593
+ for (const chunk of toolCallChunks) {
1594
+ if (chunk.args) {
1595
+ return chunk.args;
1596
+ }
1597
+ }
1598
+ }
1599
+ if (typeof content === "string") {
1600
+ return content;
1601
+ } else if (Array.isArray(content) && content.length > 0) {
1602
+ return content[0].text;
1603
+ }
1604
+ return null;
1605
+ }
1606
+ getCurrentMessageId(event) {
1607
+ var _a, _b, _c, _d, _e;
1608
+ 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);
1609
+ }
1610
+ getCurrentToolCallChunks(event) {
1611
+ var _a, _b, _c, _d, _e;
1612
+ 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);
1613
+ }
1614
+ getResponseMetadata(event) {
1615
+ var _a, _b, _c, _d, _e;
1616
+ 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);
1617
+ }
1414
1618
  processLangGraphEvents() {
1415
1619
  let lastEventWithState = null;
1416
1620
  return this.eventStream$.pipe((0, import_rxjs.scan)((acc, event) => {
1417
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1418
1621
  if (event.event === LangGraphEventTypes.OnChatModelStream) {
1419
- 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);
1420
- if (typeof content === "string") {
1421
- acc.content = content;
1422
- } else if (Array.isArray(content) && content.length > 0) {
1423
- acc.content = content[0].text;
1424
- } else {
1425
- acc.content = null;
1426
- }
1427
- const toolCallChunks = (
1428
- // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
1429
- ((_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)
1430
- );
1431
- 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);
1432
- if (toolCallChunks && toolCallChunks.length > 0) {
1433
- acc.prevToolCallMessageId = acc.toolCallMessageId;
1434
- acc.toolCallMessageId = toolCallMessageId;
1435
- if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
1436
- acc.toolCallName = toolCallChunks[0].name;
1437
- }
1438
- if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
1439
- acc.toolCallId = toolCallChunks[0].id;
1440
- }
1441
- acc.prevMessageId = acc.messageId;
1442
- acc.messageId = toolCallMessageId;
1443
- } else if (acc.content && acc.content != "") {
1444
- acc.prevMessageId = acc.messageId;
1445
- acc.messageId = toolCallMessageId;
1446
- } else {
1447
- acc.prevToolCallMessageId = acc.toolCallMessageId;
1448
- acc.prevMessageId = acc.messageId;
1449
- }
1450
- } else {
1451
- acc.prevToolCallMessageId = acc.toolCallMessageId;
1452
- acc.toolCallMessageId = null;
1453
- acc.prevMessageId = acc.messageId;
1454
- acc.messageId = null;
1455
- acc.toolCallName = null;
1622
+ const prevMessageId = acc.lastMessageId;
1623
+ acc.currentContent = this.getCurrentContent(event);
1624
+ acc.lastMessageId = this.getCurrentMessageId(event) ?? acc.lastMessageId;
1625
+ const toolCallChunks = this.getCurrentToolCallChunks(event) ?? [];
1626
+ const responseMetadata = this.getResponseMetadata(event);
1627
+ acc.isToolCallStart = toolCallChunks.some((chunk) => chunk.name && chunk.id);
1628
+ acc.isMessageStart = prevMessageId !== acc.lastMessageId && !acc.isToolCallStart;
1629
+ acc.isToolCall = toolCallChunks && toolCallChunks.length > 0;
1630
+ acc.isToolCallEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls";
1631
+ acc.isMessageEnd = (responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop";
1632
+ ({ name: acc.lastToolCallName, id: acc.lastToolCallId } = toolCallChunks.find((chunk) => chunk.name && chunk.id) ?? {
1633
+ name: acc.lastToolCallName,
1634
+ id: acc.lastToolCallId
1635
+ });
1456
1636
  }
1457
1637
  acc.event = event;
1458
1638
  lastEventWithState = acc;
1459
1639
  return acc;
1460
1640
  }, {
1461
1641
  event: null,
1462
- toolCallId: null,
1463
- toolCallMessageId: null,
1464
- prevToolCallMessageId: null,
1465
- messageId: null,
1466
- toolCallName: null,
1467
- prevMessageId: null,
1468
- content: null
1469
- }), (0, import_rxjs.mergeMap)((eventWithState) => {
1470
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1642
+ isMessageStart: false,
1643
+ isMessageEnd: false,
1644
+ isToolCallStart: false,
1645
+ isToolCallEnd: false,
1646
+ isToolCall: false,
1647
+ lastMessageId: null,
1648
+ lastToolCallId: null,
1649
+ lastToolCallName: null,
1650
+ currentContent: null
1651
+ }), (0, import_rxjs.mergeMap)((acc) => {
1471
1652
  const events = [];
1472
1653
  let shouldEmitMessages = true;
1473
- let shouldEmitToolCalls = false;
1474
- if (eventWithState.event.event == LangGraphEventTypes.OnChatModelStream) {
1475
- if ("copilotkit:emit-tool-calls" in (eventWithState.event.metadata || {})) {
1476
- shouldEmitToolCalls = eventWithState.event.metadata["copilotkit:emit-tool-calls"];
1654
+ let shouldEmitToolCalls = true;
1655
+ if (acc.event.event == LangGraphEventTypes.OnChatModelStream) {
1656
+ if ("copilotkit:emit-tool-calls" in (acc.event.metadata || {})) {
1657
+ shouldEmitToolCalls = acc.event.metadata["copilotkit:emit-tool-calls"];
1477
1658
  }
1478
- if ("copilotkit:emit-messages" in (eventWithState.event.metadata || {})) {
1479
- shouldEmitMessages = eventWithState.event.metadata["copilotkit:emit-messages"];
1659
+ if ("copilotkit:emit-messages" in (acc.event.metadata || {})) {
1660
+ shouldEmitMessages = acc.event.metadata["copilotkit:emit-messages"];
1480
1661
  }
1481
1662
  }
1482
- if (eventWithState.prevToolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId && this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
1663
+ const responseMetadata = this.getResponseMetadata(acc.event);
1664
+ if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "tool_calls" && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
1483
1665
  events.push({
1484
- type: RuntimeEventTypes.ActionExecutionEnd
1666
+ type: RuntimeEventTypes.ActionExecutionEnd,
1667
+ actionExecutionId: acc.lastToolCallId
1485
1668
  });
1486
1669
  }
1487
- if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
1670
+ if ((responseMetadata == null ? void 0 : responseMetadata.finish_reason) === "stop" && shouldEmitMessages) {
1488
1671
  events.push({
1489
- type: RuntimeEventTypes.TextMessageEnd
1672
+ type: RuntimeEventTypes.TextMessageEnd,
1673
+ messageId: acc.lastMessageId
1490
1674
  });
1491
1675
  }
1492
- switch (eventWithState.event.event) {
1676
+ switch (acc.event.event) {
1493
1677
  case LangGraphEventTypes.OnCustomEvent:
1494
- if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
1678
+ if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
1495
1679
  events.push({
1496
1680
  type: RuntimeEventTypes.TextMessageStart,
1497
- messageId: eventWithState.event.data.message_id
1681
+ messageId: acc.event.data.message_id
1498
1682
  });
1499
1683
  events.push({
1500
1684
  type: RuntimeEventTypes.TextMessageContent,
1501
- content: eventWithState.event.data.message
1685
+ messageId: acc.event.data.message_id,
1686
+ content: acc.event.data.message
1502
1687
  });
1503
1688
  events.push({
1504
- type: RuntimeEventTypes.TextMessageEnd
1689
+ type: RuntimeEventTypes.TextMessageEnd,
1690
+ messageId: acc.event.data.message_id
1505
1691
  });
1506
- } else if (eventWithState.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
1692
+ } else if (acc.event.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
1507
1693
  events.push({
1508
1694
  type: RuntimeEventTypes.ActionExecutionStart,
1509
- actionExecutionId: eventWithState.event.data.id,
1510
- actionName: eventWithState.event.data.name
1695
+ actionExecutionId: acc.event.data.id,
1696
+ actionName: acc.event.data.name,
1697
+ parentMessageId: acc.event.data.id
1511
1698
  });
1512
1699
  events.push({
1513
1700
  type: RuntimeEventTypes.ActionExecutionArgs,
1514
- args: JSON.stringify(eventWithState.event.data.args)
1701
+ actionExecutionId: acc.event.data.id,
1702
+ args: JSON.stringify(acc.event.data.args)
1515
1703
  });
1516
1704
  events.push({
1517
- type: RuntimeEventTypes.ActionExecutionEnd
1705
+ type: RuntimeEventTypes.ActionExecutionEnd,
1706
+ actionExecutionId: acc.event.data.id
1518
1707
  });
1519
1708
  }
1520
1709
  break;
1521
1710
  case LangGraphEventTypes.OnCopilotKitStateSync:
1522
1711
  events.push({
1523
1712
  type: RuntimeEventTypes.AgentStateMessage,
1524
- threadId: eventWithState.event.thread_id,
1525
- role: eventWithState.event.role,
1526
- agentName: eventWithState.event.agent_name,
1527
- nodeName: eventWithState.event.node_name,
1528
- runId: eventWithState.event.run_id,
1529
- active: eventWithState.event.active,
1530
- state: JSON.stringify(eventWithState.event.state),
1531
- running: eventWithState.event.running
1713
+ threadId: acc.event.thread_id,
1714
+ role: acc.event.role,
1715
+ agentName: acc.event.agent_name,
1716
+ nodeName: acc.event.node_name,
1717
+ runId: acc.event.run_id,
1718
+ active: acc.event.active,
1719
+ state: JSON.stringify(acc.event.state),
1720
+ running: acc.event.running
1532
1721
  });
1533
1722
  break;
1534
- case LangGraphEventTypes.OnToolEnd:
1535
- break;
1536
1723
  case LangGraphEventTypes.OnChatModelStream:
1537
- if (eventWithState.toolCallMessageId !== null && eventWithState.prevToolCallMessageId !== eventWithState.toolCallMessageId) {
1538
- if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
1539
- events.push({
1540
- type: RuntimeEventTypes.ActionExecutionStart,
1541
- actionExecutionId: eventWithState.toolCallMessageId,
1542
- actionName: eventWithState.toolCallName,
1543
- scope: "client"
1544
- });
1545
- }
1546
- } else if (eventWithState.messageId !== null && eventWithState.prevMessageId !== eventWithState.messageId) {
1547
- if (shouldEmitMessages) {
1548
- events.push({
1549
- type: RuntimeEventTypes.TextMessageStart,
1550
- messageId: eventWithState.messageId
1551
- });
1552
- }
1724
+ if (acc.isToolCallStart && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
1725
+ events.push({
1726
+ type: RuntimeEventTypes.ActionExecutionStart,
1727
+ actionExecutionId: acc.lastToolCallId,
1728
+ actionName: acc.lastToolCallName,
1729
+ parentMessageId: acc.lastMessageId
1730
+ });
1731
+ } else if (acc.isMessageStart && shouldEmitMessages) {
1732
+ events.push({
1733
+ type: RuntimeEventTypes.TextMessageStart,
1734
+ messageId: acc.lastMessageId
1735
+ });
1553
1736
  }
1554
- 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
1555
- ((_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);
1556
- const content = eventWithState.content;
1557
- if (args) {
1558
- if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
1559
- events.push({
1560
- type: RuntimeEventTypes.ActionExecutionArgs,
1561
- args
1562
- });
1563
- }
1564
- } else if (eventWithState.messageId !== null && content) {
1565
- if (shouldEmitMessages) {
1566
- events.push({
1567
- type: RuntimeEventTypes.TextMessageContent,
1568
- content
1569
- });
1570
- }
1737
+ if (acc.isToolCall && acc.currentContent && this.shouldEmitToolCall(shouldEmitToolCalls, acc.lastToolCallName)) {
1738
+ events.push({
1739
+ type: RuntimeEventTypes.ActionExecutionArgs,
1740
+ actionExecutionId: acc.lastToolCallId,
1741
+ args: acc.currentContent
1742
+ });
1743
+ } else if (!acc.isToolCall && acc.currentContent && shouldEmitMessages) {
1744
+ events.push({
1745
+ type: RuntimeEventTypes.TextMessageContent,
1746
+ messageId: acc.lastMessageId,
1747
+ content: acc.currentContent
1748
+ });
1571
1749
  }
1572
1750
  break;
1573
1751
  }
@@ -1575,14 +1753,16 @@ var RemoteLangGraphEventSource = class {
1575
1753
  }), (0, import_rxjs.catchError)((error) => {
1576
1754
  console.error(error);
1577
1755
  const events = [];
1578
- if (lastEventWithState == null ? void 0 : lastEventWithState.messageId) {
1756
+ if ((lastEventWithState == null ? void 0 : lastEventWithState.lastMessageId) && !lastEventWithState.isToolCall) {
1579
1757
  events.push({
1580
- type: RuntimeEventTypes.TextMessageEnd
1758
+ type: RuntimeEventTypes.TextMessageEnd,
1759
+ messageId: lastEventWithState.lastMessageId
1581
1760
  });
1582
1761
  }
1583
- if (lastEventWithState == null ? void 0 : lastEventWithState.toolCallMessageId) {
1762
+ if (lastEventWithState == null ? void 0 : lastEventWithState.lastToolCallId) {
1584
1763
  events.push({
1585
- type: RuntimeEventTypes.ActionExecutionEnd
1764
+ type: RuntimeEventTypes.ActionExecutionEnd,
1765
+ actionExecutionId: lastEventWithState.lastToolCallId
1586
1766
  });
1587
1767
  }
1588
1768
  const messageId = (0, import_shared9.randomId)();
@@ -1592,10 +1772,12 @@ var RemoteLangGraphEventSource = class {
1592
1772
  });
1593
1773
  events.push({
1594
1774
  type: RuntimeEventTypes.TextMessageContent,
1775
+ messageId,
1595
1776
  content: "\u274C An error occurred. Please try again."
1596
1777
  });
1597
1778
  events.push({
1598
- type: RuntimeEventTypes.TextMessageEnd
1779
+ type: RuntimeEventTypes.TextMessageEnd,
1780
+ messageId
1599
1781
  });
1600
1782
  return events;
1601
1783
  }));
@@ -1617,12 +1799,6 @@ var MessageRole;
1617
1799
  MessageRole2["system"] = "system";
1618
1800
  MessageRole2["tool"] = "tool";
1619
1801
  })(MessageRole || (MessageRole = {}));
1620
- var ActionExecutionScope;
1621
- (function(ActionExecutionScope2) {
1622
- ActionExecutionScope2["server"] = "server";
1623
- ActionExecutionScope2["client"] = "client";
1624
- ActionExecutionScope2["passThrough"] = "passThrough";
1625
- })(ActionExecutionScope || (ActionExecutionScope = {}));
1626
1802
  var CopilotRequestType;
1627
1803
  (function(CopilotRequestType2) {
1628
1804
  CopilotRequestType2["Chat"] = "Chat";
@@ -1641,10 +1817,6 @@ var ActionInputAvailability;
1641
1817
  name: "MessageRole",
1642
1818
  description: "The role of the message"
1643
1819
  });
1644
- (0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
1645
- name: "ActionExecutionScope",
1646
- description: "The scope of the action"
1647
- });
1648
1820
  (0, import_type_graphql.registerEnumType)(CopilotRequestType, {
1649
1821
  name: "CopilotRequestType",
1650
1822
  description: "The type of Copilot request"
@@ -1701,7 +1873,7 @@ async function streamEvents(controller, args) {
1701
1873
  const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
1702
1874
  let formattedMessages = [];
1703
1875
  try {
1704
- formattedMessages = formatMessages(messages);
1876
+ formattedMessages = copilotkitMessagesToLangChain(messages);
1705
1877
  } catch (e) {
1706
1878
  logger2.error(e, `Error event thrown: ${e.message}`);
1707
1879
  }
@@ -1854,7 +2026,8 @@ async function streamEvents(controller, args) {
1854
2026
  nodeName: isEndNode ? "__end__" : nodeName,
1855
2027
  state: state.values,
1856
2028
  running: !shouldExit,
1857
- active: false
2029
+ active: false,
2030
+ includeMessages: true
1858
2031
  }));
1859
2032
  return Promise.resolve();
1860
2033
  } catch (e) {
@@ -1867,13 +2040,20 @@ async function streamEvents(controller, args) {
1867
2040
  }
1868
2041
  }
1869
2042
  __name(streamEvents, "streamEvents");
1870
- function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
1871
- const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
1872
- if (key !== "messages") {
1873
- acc[key] = state[key];
1874
- }
1875
- return acc;
1876
- }, {});
2043
+ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active, includeMessages = false }) {
2044
+ if (!includeMessages) {
2045
+ state = Object.keys(state).reduce((acc, key) => {
2046
+ if (key !== "messages") {
2047
+ acc[key] = state[key];
2048
+ }
2049
+ return acc;
2050
+ }, {});
2051
+ } else {
2052
+ state = {
2053
+ ...state,
2054
+ messages: langchainMessagesToCopilotKit(state.messages || [])
2055
+ };
2056
+ }
1877
2057
  return JSON.stringify({
1878
2058
  event: LangGraphEventTypes.OnCopilotKitStateSync,
1879
2059
  thread_id: threadId,
@@ -1881,7 +2061,7 @@ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, runnin
1881
2061
  agent_name: agentName,
1882
2062
  node_name: nodeName,
1883
2063
  active,
1884
- state: stateWithoutMessages,
2064
+ state,
1885
2065
  running,
1886
2066
  role: "assistant"
1887
2067
  }) + "\n";
@@ -1957,134 +2137,157 @@ function langGraphDefaultMergeState(state, messages, actions, agentName) {
1957
2137
  if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
1958
2138
  messages = messages.slice(1);
1959
2139
  }
1960
- const mergedMessages = state.messages || [];
1961
- const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
1962
- const existingToolCallResults = /* @__PURE__ */ new Set();
1963
- for (const message of mergedMessages) {
1964
- if ("tool_call_id" in message) {
1965
- existingToolCallResults.add(message.tool_call_id);
2140
+ const existingMessages = state.messages || [];
2141
+ const existingMessageIds = new Set(existingMessages.map((message) => message.id));
2142
+ const newMessages = messages.filter((message) => !existingMessageIds.has(message.id));
2143
+ return {
2144
+ ...state,
2145
+ messages: newMessages,
2146
+ copilotkit: {
2147
+ actions
2148
+ }
2149
+ };
2150
+ }
2151
+ __name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
2152
+ function langchainMessagesToCopilotKit(messages) {
2153
+ const result = [];
2154
+ const tool_call_names = {};
2155
+ for (const message of messages) {
2156
+ if (message.type === "ai") {
2157
+ for (const tool_call of message.tool_calls) {
2158
+ tool_call_names[tool_call.id] = tool_call.name;
2159
+ }
1966
2160
  }
1967
2161
  }
1968
2162
  for (const message of messages) {
1969
- if ("tool_calls" in message && message.tool_calls.length > 0 && message.tool_calls[0].name === agentName) {
1970
- continue;
2163
+ let content = message.content;
2164
+ if (content instanceof Array) {
2165
+ content = content[0];
1971
2166
  }
1972
- if ("name" in message && message.name === agentName) {
1973
- continue;
2167
+ if (content instanceof Object) {
2168
+ content = content.text;
1974
2169
  }
1975
- if (!existingMessageIds.has(message.id)) {
1976
- if ("tool_call_id" in message && existingToolCallResults.has(message.tool_call_id)) {
1977
- console.warn("Warning: Duplicate tool call result, skipping:", message.tool_call_id);
1978
- continue;
1979
- }
1980
- mergedMessages.push(message);
1981
- } else {
1982
- for (let i = 0; i < mergedMessages.length; i++) {
1983
- if (mergedMessages[i].id === message.id && message.role === "assistant") {
1984
- if (("tool_calls" in mergedMessages[i] || "additional_kwargs" in mergedMessages[i]) && mergedMessages[i].content) {
1985
- message.tool_calls = mergedMessages[i]["tool_calls"];
1986
- message.additional_kwargs = mergedMessages[i].additional_kwargs;
1987
- }
1988
- mergedMessages[i] = message;
2170
+ if (message.type === "human") {
2171
+ result.push({
2172
+ role: "user",
2173
+ content,
2174
+ id: message.id
2175
+ });
2176
+ } else if (message.type === "system") {
2177
+ result.push({
2178
+ role: "system",
2179
+ content,
2180
+ id: message.id
2181
+ });
2182
+ } else if (message.type === "ai") {
2183
+ if (message.tool_calls && message.tool_calls.length > 0) {
2184
+ for (const tool_call of message.tool_calls) {
2185
+ result.push({
2186
+ id: tool_call.id,
2187
+ name: tool_call.name,
2188
+ arguments: tool_call.args,
2189
+ parentMessageId: message.id
2190
+ });
1989
2191
  }
2192
+ } else {
2193
+ result.push({
2194
+ role: "assistant",
2195
+ content,
2196
+ id: message.id,
2197
+ parentMessageId: message.id
2198
+ });
1990
2199
  }
2200
+ } else if (message.type === "tool") {
2201
+ const actionName = tool_call_names[message.tool_call_id] || message.name || "";
2202
+ result.push({
2203
+ actionExecutionId: message.tool_call_id,
2204
+ actionName,
2205
+ result: content,
2206
+ id: message.id
2207
+ });
1991
2208
  }
1992
2209
  }
1993
- for (let i = 0; i < mergedMessages.length - 1; i++) {
1994
- const currentMessage = mergedMessages[i];
1995
- const nextMessage = mergedMessages[i + 1];
1996
- if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0 && "tool_call_id" in nextMessage) {
1997
- nextMessage.tool_call_id = currentMessage.tool_calls[0].id;
2210
+ const resultsDict = {};
2211
+ for (const msg of result) {
2212
+ if (msg.actionExecutionId) {
2213
+ resultsDict[msg.actionExecutionId] = msg;
1998
2214
  }
1999
2215
  }
2000
- const correctedMessages = [];
2001
- for (let i = 0; i < mergedMessages.length; i++) {
2002
- const currentMessage = mergedMessages[i];
2003
- const nextMessage = mergedMessages[i + 1] || null;
2004
- const prevMessage = mergedMessages[i - 1] || null;
2005
- if ("tool_calls" in currentMessage && currentMessage.tool_calls.length > 0) {
2006
- if (!nextMessage) {
2007
- console.warn("No next message to auto-correct tool call, skipping:", currentMessage.tool_calls[0].id);
2008
- continue;
2009
- }
2010
- if (!("tool_call_id" in nextMessage) || nextMessage.tool_call_id !== currentMessage.tool_calls[0].id) {
2011
- const toolMessage = mergedMessages.find((m) => "tool_call_id" in m && m.tool_call_id === currentMessage.tool_calls[0].id);
2012
- if (toolMessage) {
2013
- console.warn("Auto-corrected tool call alignment issue:", currentMessage.tool_calls[0].id);
2014
- correctedMessages.push(currentMessage, toolMessage);
2015
- continue;
2016
- } else {
2017
- console.warn("No corresponding tool call result found for tool call, skipping:", currentMessage.tool_calls[0].id);
2018
- continue;
2019
- }
2020
- }
2021
- correctedMessages.push(currentMessage);
2022
- continue;
2216
+ const reorderedResult = [];
2217
+ for (const msg of result) {
2218
+ if (!("actionExecutionId" in msg)) {
2219
+ reorderedResult.push(msg);
2023
2220
  }
2024
- if ("tool_call_id" in currentMessage) {
2025
- if (!prevMessage || !("tool_calls" in prevMessage)) {
2026
- console.warn("No previous tool call, skipping tool call result:", currentMessage.id);
2027
- continue;
2028
- }
2029
- if (prevMessage.tool_calls && prevMessage.tool_calls[0].id !== currentMessage.tool_call_id) {
2030
- console.warn("Tool call id is incorrect, skipping tool call result:", currentMessage.id);
2031
- continue;
2221
+ if ("arguments" in msg) {
2222
+ const msgId = msg.id;
2223
+ if (msgId in resultsDict) {
2224
+ reorderedResult.push(resultsDict[msgId]);
2032
2225
  }
2033
- correctedMessages.push(currentMessage);
2034
- continue;
2035
2226
  }
2036
- correctedMessages.push(currentMessage);
2037
2227
  }
2038
- return {
2039
- ...state,
2040
- messages: correctedMessages,
2041
- copilotkit: {
2042
- actions
2043
- }
2044
- };
2228
+ return reorderedResult;
2045
2229
  }
2046
- __name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
2047
- function formatMessages(messages) {
2048
- return messages.map((message) => {
2049
- if (message.isTextMessage() && message.role === "assistant") {
2050
- return message;
2051
- }
2052
- if (message.isTextMessage() && message.role === "system") {
2053
- return message;
2054
- }
2055
- if (message.isTextMessage() && message.role === "user") {
2056
- return message;
2230
+ __name(langchainMessagesToCopilotKit, "langchainMessagesToCopilotKit");
2231
+ function copilotkitMessagesToLangChain(messages) {
2232
+ const result = [];
2233
+ const processedActionExecutions = /* @__PURE__ */ new Set();
2234
+ for (const message of messages) {
2235
+ if (message.isTextMessage()) {
2236
+ if (message.role === "user") {
2237
+ result.push({
2238
+ ...message,
2239
+ role: MessageRole.user
2240
+ });
2241
+ } else if (message.role === "system") {
2242
+ result.push({
2243
+ ...message,
2244
+ role: MessageRole.system
2245
+ });
2246
+ } else if (message.role === "assistant") {
2247
+ result.push({
2248
+ ...message,
2249
+ role: MessageRole.assistant
2250
+ });
2251
+ }
2252
+ continue;
2057
2253
  }
2058
2254
  if (message.isActionExecutionMessage()) {
2059
- const toolCall = {
2060
- name: message.name,
2061
- args: message.arguments,
2062
- id: message.id
2063
- };
2064
- return {
2065
- type: message.type,
2255
+ const messageId = message.parentMessageId ?? message.id;
2256
+ if (processedActionExecutions.has(messageId)) {
2257
+ continue;
2258
+ }
2259
+ processedActionExecutions.add(messageId);
2260
+ const relatedActionExecutions = messages.filter((m) => m.isActionExecutionMessage() && (m.parentMessageId && m.parentMessageId === messageId || m.id === messageId));
2261
+ const tool_calls = relatedActionExecutions.map((m) => ({
2262
+ name: m.name,
2263
+ args: m.arguments,
2264
+ id: m.id
2265
+ }));
2266
+ result.push({
2267
+ id: messageId,
2268
+ type: "ActionExecutionMessage",
2066
2269
  content: "",
2067
- tool_calls: [
2068
- toolCall
2069
- ],
2070
- role: MessageRole.assistant,
2071
- id: message.id
2072
- };
2270
+ tool_calls,
2271
+ role: MessageRole.assistant
2272
+ });
2273
+ continue;
2073
2274
  }
2074
2275
  if (message.isResultMessage()) {
2075
- return {
2276
+ result.push({
2076
2277
  type: message.type,
2077
2278
  content: message.result,
2078
2279
  id: message.id,
2079
2280
  tool_call_id: message.actionExecutionId,
2080
2281
  name: message.actionName,
2081
2282
  role: MessageRole.tool
2082
- };
2283
+ });
2284
+ continue;
2083
2285
  }
2084
2286
  throw new Error(`Unknown message type ${message.type}`);
2085
- });
2287
+ }
2288
+ return result;
2086
2289
  }
2087
- __name(formatMessages, "formatMessages");
2290
+ __name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
2088
2291
 
2089
2292
  // src/lib/runtime/remote-action-constructors.ts
2090
2293
  function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
@@ -2094,7 +2297,7 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
2094
2297
  parameters: [],
2095
2298
  handler: async (_args) => {
2096
2299
  },
2097
- langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
2300
+ langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
2098
2301
  var _a;
2099
2302
  logger2.debug({
2100
2303
  actionName: agent.name
@@ -2120,7 +2323,10 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
2120
2323
  agent,
2121
2324
  threadId,
2122
2325
  nodeName,
2123
- messages,
2326
+ messages: [
2327
+ ...messages,
2328
+ ...additionalMessages
2329
+ ],
2124
2330
  state,
2125
2331
  properties: graphqlContext.properties,
2126
2332
  actions: actionInputsWithoutAgents.map((action) => ({
@@ -2203,7 +2409,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2203
2409
  parameters: [],
2204
2410
  handler: async (_args) => {
2205
2411
  },
2206
- langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
2412
+ langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName, additionalMessages = [] }) => {
2207
2413
  var _a;
2208
2414
  logger2.debug({
2209
2415
  actionName: agent.name
@@ -2228,7 +2434,10 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2228
2434
  name,
2229
2435
  threadId,
2230
2436
  nodeName,
2231
- messages,
2437
+ messages: [
2438
+ ...messages,
2439
+ ...additionalMessages
2440
+ ],
2232
2441
  state,
2233
2442
  properties: graphqlContext.properties,
2234
2443
  actions: actionInputsWithoutAgents.map((action) => ({
@@ -2471,7 +2680,94 @@ function getRuntimeInstanceTelemetryInfo(runtime) {
2471
2680
  __name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
2472
2681
  var telemetry_client_default = telemetryClient;
2473
2682
 
2683
+ // src/graphql/types/base/index.ts
2684
+ var import_type_graphql2 = require("type-graphql");
2685
+ function _ts_decorate(decorators, target, key, desc) {
2686
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2687
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2688
+ r = Reflect.decorate(decorators, target, key, desc);
2689
+ else
2690
+ for (var i = decorators.length - 1; i >= 0; i--)
2691
+ if (d = decorators[i])
2692
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2693
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
2694
+ }
2695
+ __name(_ts_decorate, "_ts_decorate");
2696
+ function _ts_metadata(k, v) {
2697
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
2698
+ return Reflect.metadata(k, v);
2699
+ }
2700
+ __name(_ts_metadata, "_ts_metadata");
2701
+ var BaseMessageInput = class {
2702
+ id;
2703
+ createdAt;
2704
+ };
2705
+ __name(BaseMessageInput, "BaseMessageInput");
2706
+ _ts_decorate([
2707
+ (0, import_type_graphql2.Field)(() => String),
2708
+ _ts_metadata("design:type", String)
2709
+ ], BaseMessageInput.prototype, "id", void 0);
2710
+ _ts_decorate([
2711
+ (0, import_type_graphql2.Field)(() => Date),
2712
+ _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
2713
+ ], BaseMessageInput.prototype, "createdAt", void 0);
2714
+ BaseMessageInput = _ts_decorate([
2715
+ (0, import_type_graphql2.InputType)()
2716
+ ], BaseMessageInput);
2717
+
2718
+ // src/graphql/types/converted/index.ts
2719
+ var Message = class extends BaseMessageInput {
2720
+ type;
2721
+ isTextMessage() {
2722
+ return this.type === "TextMessage";
2723
+ }
2724
+ isActionExecutionMessage() {
2725
+ return this.type === "ActionExecutionMessage";
2726
+ }
2727
+ isResultMessage() {
2728
+ return this.type === "ResultMessage";
2729
+ }
2730
+ isAgentStateMessage() {
2731
+ return this.type === "AgentStateMessage";
2732
+ }
2733
+ };
2734
+ __name(Message, "Message");
2735
+ var TextMessage = class extends Message {
2736
+ type = "TextMessage";
2737
+ content;
2738
+ role;
2739
+ parentMessageId;
2740
+ };
2741
+ __name(TextMessage, "TextMessage");
2742
+ var ActionExecutionMessage = class extends Message {
2743
+ type = "ActionExecutionMessage";
2744
+ name;
2745
+ arguments;
2746
+ parentMessageId;
2747
+ };
2748
+ __name(ActionExecutionMessage, "ActionExecutionMessage");
2749
+ var ResultMessage = class extends Message {
2750
+ type = "ResultMessage";
2751
+ actionExecutionId;
2752
+ actionName;
2753
+ result;
2754
+ };
2755
+ __name(ResultMessage, "ResultMessage");
2756
+ var AgentStateMessage = class extends Message {
2757
+ type = "AgentStateMessage";
2758
+ threadId;
2759
+ agentName;
2760
+ nodeName;
2761
+ runId;
2762
+ active;
2763
+ role;
2764
+ state;
2765
+ running;
2766
+ };
2767
+ __name(AgentStateMessage, "AgentStateMessage");
2768
+
2474
2769
  // src/service-adapters/events.ts
2770
+ var import_class_transformer = require("class-transformer");
2475
2771
  var RuntimeEventTypes;
2476
2772
  (function(RuntimeEventTypes2) {
2477
2773
  RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
@@ -2487,52 +2783,74 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
2487
2783
  constructor() {
2488
2784
  super();
2489
2785
  }
2490
- sendTextMessageStart(messageId) {
2786
+ sendTextMessageStart({ messageId, parentMessageId }) {
2491
2787
  this.next({
2492
2788
  type: "TextMessageStart",
2493
- messageId
2789
+ messageId,
2790
+ parentMessageId
2494
2791
  });
2495
2792
  }
2496
- sendTextMessageContent(content) {
2793
+ sendTextMessageContent({ messageId, content }) {
2497
2794
  this.next({
2498
2795
  type: "TextMessageContent",
2499
- content
2796
+ content,
2797
+ messageId
2500
2798
  });
2501
2799
  }
2502
- sendTextMessageEnd() {
2800
+ sendTextMessageEnd({ messageId }) {
2503
2801
  this.next({
2504
- type: "TextMessageEnd"
2802
+ type: "TextMessageEnd",
2803
+ messageId
2505
2804
  });
2506
2805
  }
2507
2806
  sendTextMessage(messageId, content) {
2508
- this.sendTextMessageStart(messageId);
2509
- this.sendTextMessageContent(content);
2510
- this.sendTextMessageEnd();
2807
+ this.sendTextMessageStart({
2808
+ messageId
2809
+ });
2810
+ this.sendTextMessageContent({
2811
+ messageId,
2812
+ content
2813
+ });
2814
+ this.sendTextMessageEnd({
2815
+ messageId
2816
+ });
2511
2817
  }
2512
- sendActionExecutionStart(actionExecutionId, actionName) {
2818
+ sendActionExecutionStart({ actionExecutionId, actionName, parentMessageId }) {
2513
2819
  this.next({
2514
2820
  type: "ActionExecutionStart",
2515
2821
  actionExecutionId,
2516
- actionName
2822
+ actionName,
2823
+ parentMessageId
2517
2824
  });
2518
2825
  }
2519
- sendActionExecutionArgs(args) {
2826
+ sendActionExecutionArgs({ actionExecutionId, args }) {
2520
2827
  this.next({
2521
2828
  type: "ActionExecutionArgs",
2522
- args
2829
+ args,
2830
+ actionExecutionId
2523
2831
  });
2524
2832
  }
2525
- sendActionExecutionEnd() {
2833
+ sendActionExecutionEnd({ actionExecutionId }) {
2526
2834
  this.next({
2527
- type: "ActionExecutionEnd"
2835
+ type: "ActionExecutionEnd",
2836
+ actionExecutionId
2528
2837
  });
2529
2838
  }
2530
- sendActionExecution(actionExecutionId, toolName, args) {
2531
- this.sendActionExecutionStart(actionExecutionId, toolName);
2532
- this.sendActionExecutionArgs(args);
2533
- this.sendActionExecutionEnd();
2839
+ sendActionExecution({ actionExecutionId, actionName, args, parentMessageId }) {
2840
+ this.sendActionExecutionStart({
2841
+ actionExecutionId,
2842
+ actionName,
2843
+ parentMessageId
2844
+ });
2845
+ this.sendActionExecutionArgs({
2846
+ actionExecutionId,
2847
+ args
2848
+ });
2849
+ this.sendActionExecutionEnd({
2850
+ actionExecutionId
2851
+ });
2534
2852
  }
2535
- sendActionExecutionResult(actionExecutionId, actionName, result) {
2853
+ sendActionExecutionResult({ actionExecutionId, actionName, result }) {
2536
2854
  this.next({
2537
2855
  type: "ActionExecutionResult",
2538
2856
  actionName,
@@ -2540,7 +2858,7 @@ var RuntimeEventSubject = class extends import_rxjs2.ReplaySubject {
2540
2858
  result
2541
2859
  });
2542
2860
  }
2543
- sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
2861
+ sendAgentStateMessage({ threadId, agentName, nodeName, runId, active, role, state, running }) {
2544
2862
  this.next({
2545
2863
  type: "AgentStateMessage",
2546
2864
  threadId,
@@ -2577,27 +2895,19 @@ var RuntimeEventSource = class {
2577
2895
  this.sendErrorMessageToChat();
2578
2896
  });
2579
2897
  return this.eventStream$.pipe(
2580
- // mark tools for server side execution
2581
- (0, import_rxjs2.map)((event) => {
2582
- if (event.type === "ActionExecutionStart") {
2583
- if (event.scope !== "passThrough") {
2584
- event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
2585
- }
2586
- }
2587
- return event;
2588
- }),
2589
2898
  // track state
2590
2899
  (0, import_rxjs2.scan)((acc, event) => {
2591
2900
  acc = {
2592
2901
  ...acc
2593
2902
  };
2594
2903
  if (event.type === "ActionExecutionStart") {
2595
- acc.callActionServerSide = event.scope === "server";
2904
+ acc.callActionServerSide = serverSideActions.find((action) => action.name === event.actionName) !== void 0;
2596
2905
  acc.args = "";
2597
2906
  acc.actionExecutionId = event.actionExecutionId;
2598
2907
  if (acc.callActionServerSide) {
2599
2908
  acc.action = serverSideActions.find((action) => action.name === event.actionName);
2600
2909
  }
2910
+ acc.actionExecutionParentMessageId = event.parentMessageId;
2601
2911
  } else if (event.type === "ActionExecutionArgs") {
2602
2912
  acc.args += event.args;
2603
2913
  }
@@ -2608,12 +2918,13 @@ var RuntimeEventSource = class {
2608
2918
  callActionServerSide: false,
2609
2919
  args: "",
2610
2920
  actionExecutionId: null,
2611
- action: null
2921
+ action: null,
2922
+ actionExecutionParentMessageId: null
2612
2923
  }),
2613
2924
  (0, import_rxjs2.concatMap)((eventWithState) => {
2614
2925
  if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
2615
2926
  const toolCallEventStream$ = new RuntimeEventSubject();
2616
- executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
2927
+ executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionParentMessageId, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
2617
2928
  console.error(error);
2618
2929
  });
2619
2930
  telemetry_client_default.capture("oss.runtime.server_action_executed", {});
@@ -2626,7 +2937,7 @@ var RuntimeEventSource = class {
2626
2937
  }
2627
2938
  };
2628
2939
  __name(RuntimeEventSource, "RuntimeEventSource");
2629
- async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
2940
+ async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionParentMessageId, actionExecutionId, actionInputsWithoutAgents) {
2630
2941
  var _a;
2631
2942
  if (guardrailsResult$) {
2632
2943
  const { status } = await (0, import_rxjs2.firstValueFrom)(guardrailsResult$);
@@ -2646,10 +2957,33 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
2646
2957
  }
2647
2958
  }
2648
2959
  if (isLangGraphAgentAction(action)) {
2649
- eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
2960
+ const result = `${action.name} agent started`;
2961
+ const agentExecution = (0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
2962
+ id: actionExecutionId,
2963
+ createdAt: /* @__PURE__ */ new Date(),
2964
+ name: action.name,
2965
+ arguments: JSON.parse(actionArguments),
2966
+ parentMessageId: actionExecutionParentMessageId ?? actionExecutionId
2967
+ });
2968
+ const agentExecutionResult = (0, import_class_transformer.plainToInstance)(ResultMessage, {
2969
+ id: "result-" + actionExecutionId,
2970
+ createdAt: /* @__PURE__ */ new Date(),
2971
+ actionExecutionId,
2972
+ actionName: action.name,
2973
+ result
2974
+ });
2975
+ eventStream$.sendActionExecutionResult({
2976
+ actionExecutionId,
2977
+ actionName: action.name,
2978
+ result
2979
+ });
2650
2980
  const stream = await action.langGraphAgentHandler({
2651
2981
  name: action.name,
2652
- actionInputsWithoutAgents
2982
+ actionInputsWithoutAgents,
2983
+ additionalMessages: [
2984
+ agentExecution,
2985
+ agentExecutionResult
2986
+ ]
2653
2987
  });
2654
2988
  (0, import_rxjs2.from)(stream).subscribe({
2655
2989
  next: (event) => eventStream$.next(event),
@@ -2670,113 +3004,29 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
2670
3004
  }
2671
3005
  __name(executeAction, "executeAction");
2672
3006
 
2673
- // src/graphql/types/base/index.ts
2674
- var import_type_graphql2 = require("type-graphql");
2675
- function _ts_decorate(decorators, target, key, desc) {
2676
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2677
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
2678
- r = Reflect.decorate(decorators, target, key, desc);
2679
- else
2680
- for (var i = decorators.length - 1; i >= 0; i--)
2681
- if (d = decorators[i])
2682
- r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
2683
- return c > 3 && r && Object.defineProperty(target, key, r), r;
2684
- }
2685
- __name(_ts_decorate, "_ts_decorate");
2686
- function _ts_metadata(k, v) {
2687
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
2688
- return Reflect.metadata(k, v);
2689
- }
2690
- __name(_ts_metadata, "_ts_metadata");
2691
- var BaseMessageInput = class {
2692
- id;
2693
- createdAt;
2694
- };
2695
- __name(BaseMessageInput, "BaseMessageInput");
2696
- _ts_decorate([
2697
- (0, import_type_graphql2.Field)(() => String),
2698
- _ts_metadata("design:type", String)
2699
- ], BaseMessageInput.prototype, "id", void 0);
2700
- _ts_decorate([
2701
- (0, import_type_graphql2.Field)(() => Date),
2702
- _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
2703
- ], BaseMessageInput.prototype, "createdAt", void 0);
2704
- BaseMessageInput = _ts_decorate([
2705
- (0, import_type_graphql2.InputType)()
2706
- ], BaseMessageInput);
2707
-
2708
- // src/graphql/types/converted/index.ts
2709
- var Message = class extends BaseMessageInput {
2710
- type;
2711
- isTextMessage() {
2712
- return this.type === "TextMessage";
2713
- }
2714
- isActionExecutionMessage() {
2715
- return this.type === "ActionExecutionMessage";
2716
- }
2717
- isResultMessage() {
2718
- return this.type === "ResultMessage";
2719
- }
2720
- isAgentStateMessage() {
2721
- return this.type === "AgentStateMessage";
2722
- }
2723
- };
2724
- __name(Message, "Message");
2725
- var TextMessage = class extends Message {
2726
- type = "TextMessage";
2727
- content;
2728
- role;
2729
- };
2730
- __name(TextMessage, "TextMessage");
2731
- var ActionExecutionMessage = class extends Message {
2732
- type = "ActionExecutionMessage";
2733
- name;
2734
- arguments;
2735
- scope;
2736
- };
2737
- __name(ActionExecutionMessage, "ActionExecutionMessage");
2738
- var ResultMessage = class extends Message {
2739
- type = "ResultMessage";
2740
- actionExecutionId;
2741
- actionName;
2742
- result;
2743
- };
2744
- __name(ResultMessage, "ResultMessage");
2745
- var AgentStateMessage = class extends Message {
2746
- type = "AgentStateMessage";
2747
- threadId;
2748
- agentName;
2749
- nodeName;
2750
- runId;
2751
- active;
2752
- role;
2753
- state;
2754
- running;
2755
- };
2756
- __name(AgentStateMessage, "AgentStateMessage");
2757
-
2758
3007
  // src/service-adapters/conversion.ts
2759
- var import_class_transformer = require("class-transformer");
3008
+ var import_class_transformer2 = require("class-transformer");
2760
3009
  function convertGqlInputToMessages(inputMessages) {
2761
3010
  const messages = [];
2762
3011
  for (const message of inputMessages) {
2763
3012
  if (message.textMessage) {
2764
- messages.push((0, import_class_transformer.plainToInstance)(TextMessage, {
3013
+ messages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
2765
3014
  id: message.id,
2766
3015
  createdAt: message.createdAt,
2767
3016
  role: message.textMessage.role,
2768
- content: message.textMessage.content
3017
+ content: message.textMessage.content,
3018
+ parentMessageId: message.textMessage.parentMessageId
2769
3019
  }));
2770
3020
  } else if (message.actionExecutionMessage) {
2771
- messages.push((0, import_class_transformer.plainToInstance)(ActionExecutionMessage, {
3021
+ messages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
2772
3022
  id: message.id,
2773
3023
  createdAt: message.createdAt,
2774
3024
  name: message.actionExecutionMessage.name,
2775
3025
  arguments: JSON.parse(message.actionExecutionMessage.arguments),
2776
- scope: message.actionExecutionMessage.scope
3026
+ parentMessageId: message.actionExecutionMessage.parentMessageId
2777
3027
  }));
2778
3028
  } else if (message.resultMessage) {
2779
- messages.push((0, import_class_transformer.plainToInstance)(ResultMessage, {
3029
+ messages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
2780
3030
  id: message.id,
2781
3031
  createdAt: message.createdAt,
2782
3032
  actionExecutionId: message.resultMessage.actionExecutionId,
@@ -2784,7 +3034,7 @@ function convertGqlInputToMessages(inputMessages) {
2784
3034
  result: message.resultMessage.result
2785
3035
  }));
2786
3036
  } else if (message.agentStateMessage) {
2787
- messages.push((0, import_class_transformer.plainToInstance)(AgentStateMessage, {
3037
+ messages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
2788
3038
  id: message.id,
2789
3039
  threadId: message.agentStateMessage.threadId,
2790
3040
  createdAt: message.createdAt,
@@ -3087,6 +3337,7 @@ MessageInput = _ts_decorate2([
3087
3337
  ], MessageInput);
3088
3338
  var TextMessageInput = class {
3089
3339
  content;
3340
+ parentMessageId;
3090
3341
  role;
3091
3342
  };
3092
3343
  __name(TextMessageInput, "TextMessageInput");
@@ -3094,6 +3345,12 @@ _ts_decorate2([
3094
3345
  (0, import_type_graphql3.Field)(() => String),
3095
3346
  _ts_metadata2("design:type", String)
3096
3347
  ], TextMessageInput.prototype, "content", void 0);
3348
+ _ts_decorate2([
3349
+ (0, import_type_graphql3.Field)(() => String, {
3350
+ nullable: true
3351
+ }),
3352
+ _ts_metadata2("design:type", String)
3353
+ ], TextMessageInput.prototype, "parentMessageId", void 0);
3097
3354
  _ts_decorate2([
3098
3355
  (0, import_type_graphql3.Field)(() => MessageRole),
3099
3356
  _ts_metadata2("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
@@ -3104,6 +3361,7 @@ TextMessageInput = _ts_decorate2([
3104
3361
  var ActionExecutionMessageInput = class {
3105
3362
  name;
3106
3363
  arguments;
3364
+ parentMessageId;
3107
3365
  scope;
3108
3366
  };
3109
3367
  __name(ActionExecutionMessageInput, "ActionExecutionMessageInput");
@@ -3116,8 +3374,17 @@ _ts_decorate2([
3116
3374
  _ts_metadata2("design:type", String)
3117
3375
  ], ActionExecutionMessageInput.prototype, "arguments", void 0);
3118
3376
  _ts_decorate2([
3119
- (0, import_type_graphql3.Field)(() => ActionExecutionScope),
3120
- _ts_metadata2("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
3377
+ (0, import_type_graphql3.Field)(() => String, {
3378
+ nullable: true
3379
+ }),
3380
+ _ts_metadata2("design:type", String)
3381
+ ], ActionExecutionMessageInput.prototype, "parentMessageId", void 0);
3382
+ _ts_decorate2([
3383
+ (0, import_type_graphql3.Field)(() => String, {
3384
+ nullable: true,
3385
+ deprecationReason: "This field will be removed in a future version"
3386
+ }),
3387
+ _ts_metadata2("design:type", typeof String === "undefined" ? Object : String)
3121
3388
  ], ActionExecutionMessageInput.prototype, "scope", void 0);
3122
3389
  ActionExecutionMessageInput = _ts_decorate2([
3123
3390
  (0, import_type_graphql3.InputType)()
@@ -3125,6 +3392,7 @@ ActionExecutionMessageInput = _ts_decorate2([
3125
3392
  var ResultMessageInput = class {
3126
3393
  actionExecutionId;
3127
3394
  actionName;
3395
+ parentMessageId;
3128
3396
  result;
3129
3397
  };
3130
3398
  __name(ResultMessageInput, "ResultMessageInput");
@@ -3136,6 +3404,12 @@ _ts_decorate2([
3136
3404
  (0, import_type_graphql3.Field)(() => String),
3137
3405
  _ts_metadata2("design:type", String)
3138
3406
  ], ResultMessageInput.prototype, "actionName", void 0);
3407
+ _ts_decorate2([
3408
+ (0, import_type_graphql3.Field)(() => String, {
3409
+ nullable: true
3410
+ }),
3411
+ _ts_metadata2("design:type", String)
3412
+ ], ResultMessageInput.prototype, "parentMessageId", void 0);
3139
3413
  _ts_decorate2([
3140
3414
  (0, import_type_graphql3.Field)(() => String),
3141
3415
  _ts_metadata2("design:type", String)
@@ -3858,6 +4132,7 @@ BaseMessageOutput = _ts_decorate13([
3858
4132
  var TextMessageOutput = class {
3859
4133
  role;
3860
4134
  content;
4135
+ parentMessageId;
3861
4136
  };
3862
4137
  __name(TextMessageOutput, "TextMessageOutput");
3863
4138
  _ts_decorate13([
@@ -3870,6 +4145,12 @@ _ts_decorate13([
3870
4145
  ]),
3871
4146
  _ts_metadata13("design:type", Array)
3872
4147
  ], TextMessageOutput.prototype, "content", void 0);
4148
+ _ts_decorate13([
4149
+ (0, import_type_graphql14.Field)(() => String, {
4150
+ nullable: true
4151
+ }),
4152
+ _ts_metadata13("design:type", String)
4153
+ ], TextMessageOutput.prototype, "parentMessageId", void 0);
3873
4154
  TextMessageOutput = _ts_decorate13([
3874
4155
  (0, import_type_graphql14.ObjectType)({
3875
4156
  implements: BaseMessageOutput
@@ -3879,6 +4160,7 @@ var ActionExecutionMessageOutput = class {
3879
4160
  name;
3880
4161
  scope;
3881
4162
  arguments;
4163
+ parentMessageId;
3882
4164
  };
3883
4165
  __name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
3884
4166
  _ts_decorate13([
@@ -3886,8 +4168,11 @@ _ts_decorate13([
3886
4168
  _ts_metadata13("design:type", String)
3887
4169
  ], ActionExecutionMessageOutput.prototype, "name", void 0);
3888
4170
  _ts_decorate13([
3889
- (0, import_type_graphql14.Field)(() => ActionExecutionScope),
3890
- _ts_metadata13("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
4171
+ (0, import_type_graphql14.Field)(() => String, {
4172
+ nullable: true,
4173
+ deprecationReason: "This field will be removed in a future version"
4174
+ }),
4175
+ _ts_metadata13("design:type", String)
3891
4176
  ], ActionExecutionMessageOutput.prototype, "scope", void 0);
3892
4177
  _ts_decorate13([
3893
4178
  (0, import_type_graphql14.Field)(() => [
@@ -3895,6 +4180,12 @@ _ts_decorate13([
3895
4180
  ]),
3896
4181
  _ts_metadata13("design:type", Array)
3897
4182
  ], ActionExecutionMessageOutput.prototype, "arguments", void 0);
4183
+ _ts_decorate13([
4184
+ (0, import_type_graphql14.Field)(() => String, {
4185
+ nullable: true
4186
+ }),
4187
+ _ts_metadata13("design:type", String)
4188
+ ], ActionExecutionMessageOutput.prototype, "parentMessageId", void 0);
3898
4189
  ActionExecutionMessageOutput = _ts_decorate13([
3899
4190
  (0, import_type_graphql14.ObjectType)({
3900
4191
  implements: BaseMessageOutput
@@ -4005,7 +4296,7 @@ CopilotResponse = _ts_decorate13([
4005
4296
  // src/graphql/resolvers/copilot.resolver.ts
4006
4297
  var import_graphql_yoga = require("graphql-yoga");
4007
4298
  var import_graphql_scalars2 = require("graphql-scalars");
4008
- var import_class_transformer2 = require("class-transformer");
4299
+ var import_class_transformer3 = require("class-transformer");
4009
4300
  var import_graphql = require("graphql");
4010
4301
 
4011
4302
  // src/utils/failed-response-status-reasons.ts
@@ -4203,7 +4494,7 @@ var CopilotResolver = class {
4203
4494
  reason: `Interrupted due to Guardrails validation failure. Reason: ${result.reason}`
4204
4495
  });
4205
4496
  outputMessages = [
4206
- (0, import_class_transformer2.plainToInstance)(TextMessage, {
4497
+ (0, import_class_transformer3.plainToInstance)(TextMessage, {
4207
4498
  id: (0, import_shared13.randomId)(),
4208
4499
  createdAt: /* @__PURE__ */ new Date(),
4209
4500
  content: result.reason,
@@ -4252,12 +4543,15 @@ var CopilotResolver = class {
4252
4543
  // skip until this message start event
4253
4544
  (0, import_rxjs4.skipWhile)((e) => e !== event),
4254
4545
  // take until the message end event
4255
- (0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.TextMessageEnd)
4546
+ (0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.TextMessageEnd && e.messageId == event.messageId)),
4547
+ // filter out any other message events or message ids
4548
+ (0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.TextMessageContent && e.messageId == event.messageId)
4256
4549
  );
4257
4550
  const streamingTextStatus = new import_rxjs4.Subject();
4258
4551
  const messageId = event.messageId;
4259
4552
  pushMessage({
4260
4553
  id: messageId,
4554
+ parentMessageId: event.parentMessageId,
4261
4555
  status: (0, import_rxjs4.firstValueFrom)(streamingTextStatus),
4262
4556
  createdAt: /* @__PURE__ */ new Date(),
4263
4557
  role: MessageRole.assistant,
@@ -4270,7 +4564,7 @@ var CopilotResolver = class {
4270
4564
  reason,
4271
4565
  messageId: messageId2
4272
4566
  }, "Text streaming interrupted");
4273
- streamingTextStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
4567
+ streamingTextStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
4274
4568
  reason
4275
4569
  }));
4276
4570
  responseStatus$.next(new MessageStreamInterruptedResponse({
@@ -4303,7 +4597,7 @@ var CopilotResolver = class {
4303
4597
  streamingTextStatus.next(new SuccessMessageStatus());
4304
4598
  stopStreamingText();
4305
4599
  textSubscription == null ? void 0 : textSubscription.unsubscribe();
4306
- outputMessages.push((0, import_class_transformer2.plainToInstance)(TextMessage, {
4600
+ outputMessages.push((0, import_class_transformer3.plainToInstance)(TextMessage, {
4307
4601
  id: messageId,
4308
4602
  createdAt: /* @__PURE__ */ new Date(),
4309
4603
  content: textChunks.join(""),
@@ -4316,14 +4610,20 @@ var CopilotResolver = class {
4316
4610
  break;
4317
4611
  case RuntimeEventTypes.ActionExecutionStart:
4318
4612
  logger2.debug("Action execution start event received");
4319
- const actionExecutionArgumentStream = eventStream.pipe((0, import_rxjs4.skipWhile)((e) => e !== event), (0, import_rxjs4.takeWhile)((e) => e.type != RuntimeEventTypes.ActionExecutionEnd));
4613
+ const actionExecutionArgumentStream = eventStream.pipe(
4614
+ (0, import_rxjs4.skipWhile)((e) => e !== event),
4615
+ // take until the action execution end event
4616
+ (0, import_rxjs4.takeWhile)((e) => !(e.type === RuntimeEventTypes.ActionExecutionEnd && e.actionExecutionId == event.actionExecutionId)),
4617
+ // filter out any other action execution events or action execution ids
4618
+ (0, import_rxjs4.filter)((e) => e.type == RuntimeEventTypes.ActionExecutionArgs && e.actionExecutionId == event.actionExecutionId)
4619
+ );
4320
4620
  const streamingArgumentsStatus = new import_rxjs4.Subject();
4321
4621
  pushMessage({
4322
4622
  id: event.actionExecutionId,
4623
+ parentMessageId: event.parentMessageId,
4323
4624
  status: (0, import_rxjs4.firstValueFrom)(streamingArgumentsStatus),
4324
4625
  createdAt: /* @__PURE__ */ new Date(),
4325
4626
  name: event.actionName,
4326
- scope: event.scope,
4327
4627
  arguments: new import_graphql_yoga.Repeater(async (pushArgumentsChunk, stopStreamingArguments) => {
4328
4628
  logger2.debug("Action execution argument stream created");
4329
4629
  const argumentChunks = [];
@@ -4339,7 +4639,7 @@ var CopilotResolver = class {
4339
4639
  logger2.error({
4340
4640
  err
4341
4641
  }, "Error in action execution argument stream");
4342
- streamingArgumentsStatus.next((0, import_class_transformer2.plainToInstance)(FailedMessageStatus, {
4642
+ streamingArgumentsStatus.next((0, import_class_transformer3.plainToInstance)(FailedMessageStatus, {
4343
4643
  reason: "An unknown error has occurred in the action execution argument stream"
4344
4644
  }));
4345
4645
  stopStreamingArguments();
@@ -4350,11 +4650,10 @@ var CopilotResolver = class {
4350
4650
  streamingArgumentsStatus.next(new SuccessMessageStatus());
4351
4651
  stopStreamingArguments();
4352
4652
  actionExecutionArgumentSubscription == null ? void 0 : actionExecutionArgumentSubscription.unsubscribe();
4353
- outputMessages.push((0, import_class_transformer2.plainToInstance)(ActionExecutionMessage, {
4653
+ outputMessages.push((0, import_class_transformer3.plainToInstance)(ActionExecutionMessage, {
4354
4654
  id: event.actionExecutionId,
4355
4655
  createdAt: /* @__PURE__ */ new Date(),
4356
4656
  name: event.actionName,
4357
- scope: event.scope,
4358
4657
  arguments: argumentChunks.join("")
4359
4658
  }));
4360
4659
  }
@@ -4367,15 +4666,15 @@ var CopilotResolver = class {
4367
4666
  result: event.result
4368
4667
  }, "Action execution result event received");
4369
4668
  pushMessage({
4370
- id: (0, import_shared13.randomId)(),
4669
+ id: "result-" + event.actionExecutionId,
4371
4670
  status: new SuccessMessageStatus(),
4372
4671
  createdAt: /* @__PURE__ */ new Date(),
4373
4672
  actionExecutionId: event.actionExecutionId,
4374
4673
  actionName: event.actionName,
4375
4674
  result: event.result
4376
4675
  });
4377
- outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
4378
- id: (0, import_shared13.randomId)(),
4676
+ outputMessages.push((0, import_class_transformer3.plainToInstance)(ResultMessage, {
4677
+ id: "result-" + event.actionExecutionId,
4379
4678
  createdAt: /* @__PURE__ */ new Date(),
4380
4679
  actionExecutionId: event.actionExecutionId,
4381
4680
  actionName: event.actionName,
@@ -4399,7 +4698,7 @@ var CopilotResolver = class {
4399
4698
  role: MessageRole.assistant,
4400
4699
  createdAt: /* @__PURE__ */ new Date()
4401
4700
  });
4402
- outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
4701
+ outputMessages.push((0, import_class_transformer3.plainToInstance)(AgentStateMessage, {
4403
4702
  id: (0, import_shared13.randomId)(),
4404
4703
  threadId: event.threadId,
4405
4704
  agentName: event.agentName,