@copilotkit/runtime 1.2.0 → 1.2.2-feat-runtime-remote-actions.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 (75) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/__snapshots__/schema/schema.graphql +41 -0
  3. package/dist/{chunk-HCUZC4GO.mjs → chunk-2N45GS3P.mjs} +2 -2
  4. package/dist/{chunk-URMISMK2.mjs → chunk-73NMP3DI.mjs} +2 -2
  5. package/dist/{chunk-736EEICU.mjs → chunk-BJ2LVHWA.mjs} +3 -3
  6. package/dist/{chunk-ZHFBLKC3.mjs → chunk-T6O5FSTK.mjs} +2 -2
  7. package/dist/{chunk-GEIBJJQ4.mjs → chunk-TBZGOJJX.mjs} +14 -2
  8. package/dist/chunk-TBZGOJJX.mjs.map +1 -0
  9. package/dist/{chunk-3MYGPMKL.mjs → chunk-X5QBBMCJ.mjs} +2 -2
  10. package/dist/{chunk-3TQLJ3YL.mjs → chunk-XROLDARH.mjs} +786 -158
  11. package/dist/chunk-XROLDARH.mjs.map +1 -0
  12. package/dist/chunk-ZNZGATLW.mjs +260 -0
  13. package/dist/chunk-ZNZGATLW.mjs.map +1 -0
  14. package/dist/{shared-c5362338.d.ts → copilot-runtime-d427e991.d.ts} +65 -38
  15. package/dist/graphql/types/converted/index.d.ts +1 -1
  16. package/dist/graphql/types/converted/index.js +13 -0
  17. package/dist/graphql/types/converted/index.js.map +1 -1
  18. package/dist/graphql/types/converted/index.mjs +3 -1
  19. package/dist/{index-aa091e3c.d.ts → index-0476e4f7.d.ts} +24 -2
  20. package/dist/{index-13aa818e.d.ts → index-079752b9.d.ts} +1 -1
  21. package/dist/index.d.ts +7 -7
  22. package/dist/index.js +982 -245
  23. package/dist/index.js.map +1 -1
  24. package/dist/index.mjs +8 -8
  25. package/dist/{langserve-a54438c6.d.ts → langserve-d6073a3b.d.ts} +24 -11
  26. package/dist/lib/index.d.ts +7 -7
  27. package/dist/lib/index.js +982 -245
  28. package/dist/lib/index.js.map +1 -1
  29. package/dist/lib/index.mjs +8 -8
  30. package/dist/lib/integrations/index.d.ts +6 -6
  31. package/dist/lib/integrations/index.js +437 -182
  32. package/dist/lib/integrations/index.js.map +1 -1
  33. package/dist/lib/integrations/index.mjs +6 -6
  34. package/dist/lib/integrations/nest/index.d.ts +5 -5
  35. package/dist/lib/integrations/nest/index.js +437 -182
  36. package/dist/lib/integrations/nest/index.js.map +1 -1
  37. package/dist/lib/integrations/nest/index.mjs +4 -4
  38. package/dist/lib/integrations/node-express/index.d.ts +5 -5
  39. package/dist/lib/integrations/node-express/index.js +437 -182
  40. package/dist/lib/integrations/node-express/index.js.map +1 -1
  41. package/dist/lib/integrations/node-express/index.mjs +4 -4
  42. package/dist/lib/integrations/node-http/index.d.ts +5 -5
  43. package/dist/lib/integrations/node-http/index.js +437 -182
  44. package/dist/lib/integrations/node-http/index.js.map +1 -1
  45. package/dist/lib/integrations/node-http/index.mjs +3 -3
  46. package/dist/service-adapters/index.d.ts +3 -3
  47. package/dist/service-adapters/index.js.map +1 -1
  48. package/dist/service-adapters/index.mjs +3 -3
  49. package/package.json +7 -5
  50. package/src/agents/langgraph/event-source.ts +222 -0
  51. package/src/agents/langgraph/events.ts +309 -0
  52. package/src/graphql/inputs/agent-session.input.ts +13 -0
  53. package/src/graphql/inputs/agent-state.input.ts +10 -0
  54. package/src/graphql/inputs/generate-copilot-response.input.ts +11 -0
  55. package/src/graphql/inputs/message.input.ts +30 -0
  56. package/src/graphql/resolvers/copilot.resolver.ts +56 -12
  57. package/src/graphql/types/converted/index.ts +15 -0
  58. package/src/graphql/types/copilot-response.type.ts +29 -0
  59. package/src/graphql/types/enums.ts +1 -0
  60. package/src/lib/index.ts +1 -1
  61. package/src/lib/integrations/shared.ts +1 -1
  62. package/src/lib/runtime/copilot-runtime.ts +360 -0
  63. package/src/lib/runtime/remote-actions.ts +241 -0
  64. package/src/service-adapters/conversion.ts +16 -0
  65. package/src/service-adapters/events.ts +101 -19
  66. package/dist/chunk-3TQLJ3YL.mjs.map +0 -1
  67. package/dist/chunk-GEIBJJQ4.mjs.map +0 -1
  68. package/dist/chunk-MHLJQ2RF.mjs +0 -158
  69. package/dist/chunk-MHLJQ2RF.mjs.map +0 -1
  70. package/src/lib/copilot-runtime.ts +0 -231
  71. /package/dist/{chunk-HCUZC4GO.mjs.map → chunk-2N45GS3P.mjs.map} +0 -0
  72. /package/dist/{chunk-URMISMK2.mjs.map → chunk-73NMP3DI.mjs.map} +0 -0
  73. /package/dist/{chunk-736EEICU.mjs.map → chunk-BJ2LVHWA.mjs.map} +0 -0
  74. /package/dist/{chunk-ZHFBLKC3.mjs.map → chunk-T6O5FSTK.mjs.map} +0 -0
  75. /package/dist/{chunk-3MYGPMKL.mjs.map → chunk-X5QBBMCJ.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  streamLangChainResponse
3
- } from "./chunk-URMISMK2.mjs";
3
+ } from "./chunk-73NMP3DI.mjs";
4
4
  import {
5
5
  GuardrailsValidationFailureResponse,
6
6
  MessageStreamInterruptedResponse,
@@ -10,9 +10,10 @@ import {
10
10
  } from "./chunk-U3V2BCGI.mjs";
11
11
  import {
12
12
  ActionExecutionMessage,
13
+ AgentStateMessage,
13
14
  ResultMessage,
14
15
  TextMessage
15
- } from "./chunk-GEIBJJQ4.mjs";
16
+ } from "./chunk-TBZGOJJX.mjs";
16
17
  import {
17
18
  BaseMessage
18
19
  } from "./chunk-RMZWGQ46.mjs";
@@ -35,7 +36,7 @@ var require_package = __commonJS({
35
36
  publishConfig: {
36
37
  access: "public"
37
38
  },
38
- version: "1.2.0",
39
+ version: "1.2.2-feat-runtime-remote-actions.0",
39
40
  sideEffects: false,
40
41
  main: "./dist/index.js",
41
42
  module: "./dist/index.mjs",
@@ -50,7 +51,9 @@ var require_package = __commonJS({
50
51
  test: "jest --passWithNoTests",
51
52
  "check-types": "tsc --noEmit",
52
53
  clean: "rm -rf .turbo && rm -rf node_modules && rm -rf dist && rm -rf .next && rm -rf __snapshots__",
53
- "generate-graphql-schema": "rm -rf __snapshots__ && ts-node ./scripts/generate-gql-schema.ts"
54
+ "generate-graphql-schema": "rm -rf __snapshots__ && ts-node ./scripts/generate-gql-schema.ts",
55
+ "link:global": "pnpm link --global",
56
+ "unlink:global": "pnpm unlink --global"
54
57
  },
55
58
  devDependencies: {
56
59
  "@swc/core": "1.5.28",
@@ -114,10 +117,10 @@ import { buildSchemaSync } from "type-graphql";
114
117
 
115
118
  // src/graphql/resolvers/copilot.resolver.ts
116
119
  import { Arg, Ctx, Mutation, Query, Resolver } from "type-graphql";
117
- import { ReplaySubject as ReplaySubject2, Subject, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
120
+ import { ReplaySubject as ReplaySubject3, Subject, finalize, firstValueFrom as firstValueFrom2, shareReplay, skipWhile, take, takeWhile, tap } from "rxjs";
118
121
 
119
122
  // src/graphql/inputs/generate-copilot-response.input.ts
120
- import { Field as Field7, InputType as InputType7 } from "type-graphql";
123
+ import { Field as Field9, InputType as InputType9 } from "type-graphql";
121
124
 
122
125
  // src/graphql/inputs/message.input.ts
123
126
  import { Field, InputType } from "type-graphql";
@@ -134,6 +137,7 @@ var ActionExecutionScope;
134
137
  (function(ActionExecutionScope2) {
135
138
  ActionExecutionScope2["server"] = "server";
136
139
  ActionExecutionScope2["client"] = "client";
140
+ ActionExecutionScope2["passThrough"] = "passThrough";
137
141
  })(ActionExecutionScope || (ActionExecutionScope = {}));
138
142
  var CopilotRequestType;
139
143
  (function(CopilotRequestType2) {
@@ -177,6 +181,7 @@ var MessageInput = class extends BaseMessage {
177
181
  textMessage;
178
182
  actionExecutionMessage;
179
183
  resultMessage;
184
+ agentStateMessage;
180
185
  };
181
186
  __name(MessageInput, "MessageInput");
182
187
  _ts_decorate([
@@ -197,6 +202,12 @@ _ts_decorate([
197
202
  }),
198
203
  _ts_metadata("design:type", typeof ResultMessageInput === "undefined" ? Object : ResultMessageInput)
199
204
  ], MessageInput.prototype, "resultMessage", void 0);
205
+ _ts_decorate([
206
+ Field(() => AgentStateMessageInput, {
207
+ nullable: true
208
+ }),
209
+ _ts_metadata("design:type", typeof AgentStateMessageInput === "undefined" ? Object : AgentStateMessageInput)
210
+ ], MessageInput.prototype, "agentStateMessage", void 0);
200
211
  MessageInput = _ts_decorate([
201
212
  InputType()
202
213
  ], MessageInput);
@@ -258,6 +269,52 @@ _ts_decorate([
258
269
  ResultMessageInput = _ts_decorate([
259
270
  InputType()
260
271
  ], ResultMessageInput);
272
+ var AgentStateMessageInput = class {
273
+ threadId;
274
+ agentName;
275
+ role;
276
+ state;
277
+ running;
278
+ nodeName;
279
+ runId;
280
+ active;
281
+ };
282
+ __name(AgentStateMessageInput, "AgentStateMessageInput");
283
+ _ts_decorate([
284
+ Field(() => String),
285
+ _ts_metadata("design:type", String)
286
+ ], AgentStateMessageInput.prototype, "threadId", void 0);
287
+ _ts_decorate([
288
+ Field(() => String),
289
+ _ts_metadata("design:type", String)
290
+ ], AgentStateMessageInput.prototype, "agentName", void 0);
291
+ _ts_decorate([
292
+ Field(() => MessageRole),
293
+ _ts_metadata("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
294
+ ], AgentStateMessageInput.prototype, "role", void 0);
295
+ _ts_decorate([
296
+ Field(() => String),
297
+ _ts_metadata("design:type", String)
298
+ ], AgentStateMessageInput.prototype, "state", void 0);
299
+ _ts_decorate([
300
+ Field(() => Boolean),
301
+ _ts_metadata("design:type", Boolean)
302
+ ], AgentStateMessageInput.prototype, "running", void 0);
303
+ _ts_decorate([
304
+ Field(() => String),
305
+ _ts_metadata("design:type", String)
306
+ ], AgentStateMessageInput.prototype, "nodeName", void 0);
307
+ _ts_decorate([
308
+ Field(() => String),
309
+ _ts_metadata("design:type", String)
310
+ ], AgentStateMessageInput.prototype, "runId", void 0);
311
+ _ts_decorate([
312
+ Field(() => Boolean),
313
+ _ts_metadata("design:type", Boolean)
314
+ ], AgentStateMessageInput.prototype, "active", void 0);
315
+ AgentStateMessageInput = _ts_decorate([
316
+ InputType()
317
+ ], AgentStateMessageInput);
261
318
 
262
319
  // src/graphql/inputs/frontend.input.ts
263
320
  import { Field as Field3, InputType as InputType3 } from "type-graphql";
@@ -499,7 +556,8 @@ ForwardedParametersInput = _ts_decorate6([
499
556
  InputType6()
500
557
  ], ForwardedParametersInput);
501
558
 
502
- // src/graphql/inputs/generate-copilot-response.input.ts
559
+ // src/graphql/inputs/agent-session.input.ts
560
+ import { Field as Field7, InputType as InputType7 } from "type-graphql";
503
561
  function _ts_decorate7(decorators, target, key, desc) {
504
562
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
505
563
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -516,18 +574,96 @@ function _ts_metadata7(k, v) {
516
574
  return Reflect.metadata(k, v);
517
575
  }
518
576
  __name(_ts_metadata7, "_ts_metadata");
577
+ var AgentSessionInput = class {
578
+ agentName;
579
+ threadId;
580
+ nodeName;
581
+ };
582
+ __name(AgentSessionInput, "AgentSessionInput");
583
+ _ts_decorate7([
584
+ Field7(() => String),
585
+ _ts_metadata7("design:type", String)
586
+ ], AgentSessionInput.prototype, "agentName", void 0);
587
+ _ts_decorate7([
588
+ Field7(() => String, {
589
+ nullable: true
590
+ }),
591
+ _ts_metadata7("design:type", String)
592
+ ], AgentSessionInput.prototype, "threadId", void 0);
593
+ _ts_decorate7([
594
+ Field7(() => String, {
595
+ nullable: true
596
+ }),
597
+ _ts_metadata7("design:type", String)
598
+ ], AgentSessionInput.prototype, "nodeName", void 0);
599
+ AgentSessionInput = _ts_decorate7([
600
+ InputType7()
601
+ ], AgentSessionInput);
602
+
603
+ // src/graphql/inputs/agent-state.input.ts
604
+ import { Field as Field8, InputType as InputType8 } from "type-graphql";
605
+ function _ts_decorate8(decorators, target, key, desc) {
606
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
607
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
608
+ r = Reflect.decorate(decorators, target, key, desc);
609
+ else
610
+ for (var i = decorators.length - 1; i >= 0; i--)
611
+ if (d = decorators[i])
612
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
613
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
614
+ }
615
+ __name(_ts_decorate8, "_ts_decorate");
616
+ function _ts_metadata8(k, v) {
617
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
618
+ return Reflect.metadata(k, v);
619
+ }
620
+ __name(_ts_metadata8, "_ts_metadata");
621
+ var AgentStateInput = class {
622
+ agentName;
623
+ state;
624
+ };
625
+ __name(AgentStateInput, "AgentStateInput");
626
+ _ts_decorate8([
627
+ Field8(() => String),
628
+ _ts_metadata8("design:type", String)
629
+ ], AgentStateInput.prototype, "agentName", void 0);
630
+ _ts_decorate8([
631
+ Field8(() => String),
632
+ _ts_metadata8("design:type", String)
633
+ ], AgentStateInput.prototype, "state", void 0);
634
+ AgentStateInput = _ts_decorate8([
635
+ InputType8()
636
+ ], AgentStateInput);
637
+
638
+ // src/graphql/inputs/generate-copilot-response.input.ts
639
+ function _ts_decorate9(decorators, target, key, desc) {
640
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
641
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
642
+ r = Reflect.decorate(decorators, target, key, desc);
643
+ else
644
+ for (var i = decorators.length - 1; i >= 0; i--)
645
+ if (d = decorators[i])
646
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
647
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
648
+ }
649
+ __name(_ts_decorate9, "_ts_decorate");
650
+ function _ts_metadata9(k, v) {
651
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
652
+ return Reflect.metadata(k, v);
653
+ }
654
+ __name(_ts_metadata9, "_ts_metadata");
519
655
  var GenerateCopilotResponseMetadataInput = class {
520
656
  requestType;
521
657
  };
522
658
  __name(GenerateCopilotResponseMetadataInput, "GenerateCopilotResponseMetadataInput");
523
- _ts_decorate7([
524
- Field7(() => CopilotRequestType, {
659
+ _ts_decorate9([
660
+ Field9(() => CopilotRequestType, {
525
661
  nullable: true
526
662
  }),
527
- _ts_metadata7("design:type", typeof CopilotRequestType === "undefined" ? Object : CopilotRequestType)
663
+ _ts_metadata9("design:type", typeof CopilotRequestType === "undefined" ? Object : CopilotRequestType)
528
664
  ], GenerateCopilotResponseMetadataInput.prototype, "requestType", void 0);
529
- GenerateCopilotResponseMetadataInput = _ts_decorate7([
530
- InputType7()
665
+ GenerateCopilotResponseMetadataInput = _ts_decorate9([
666
+ InputType9()
531
667
  ], GenerateCopilotResponseMetadataInput);
532
668
  var GenerateCopilotResponseInput = class {
533
669
  metadata;
@@ -537,58 +673,81 @@ var GenerateCopilotResponseInput = class {
537
673
  frontend;
538
674
  cloud;
539
675
  forwardedParameters;
676
+ agentSession;
677
+ agentState;
678
+ agentStates;
540
679
  };
541
680
  __name(GenerateCopilotResponseInput, "GenerateCopilotResponseInput");
542
- _ts_decorate7([
543
- Field7(() => GenerateCopilotResponseMetadataInput, {
681
+ _ts_decorate9([
682
+ Field9(() => GenerateCopilotResponseMetadataInput, {
544
683
  nullable: false
545
684
  }),
546
- _ts_metadata7("design:type", typeof GenerateCopilotResponseMetadataInput === "undefined" ? Object : GenerateCopilotResponseMetadataInput)
685
+ _ts_metadata9("design:type", typeof GenerateCopilotResponseMetadataInput === "undefined" ? Object : GenerateCopilotResponseMetadataInput)
547
686
  ], GenerateCopilotResponseInput.prototype, "metadata", void 0);
548
- _ts_decorate7([
549
- Field7(() => String, {
687
+ _ts_decorate9([
688
+ Field9(() => String, {
550
689
  nullable: true
551
690
  }),
552
- _ts_metadata7("design:type", String)
691
+ _ts_metadata9("design:type", String)
553
692
  ], GenerateCopilotResponseInput.prototype, "threadId", void 0);
554
- _ts_decorate7([
555
- Field7(() => String, {
693
+ _ts_decorate9([
694
+ Field9(() => String, {
556
695
  nullable: true
557
696
  }),
558
- _ts_metadata7("design:type", String)
697
+ _ts_metadata9("design:type", String)
559
698
  ], GenerateCopilotResponseInput.prototype, "runId", void 0);
560
- _ts_decorate7([
561
- Field7(() => [
699
+ _ts_decorate9([
700
+ Field9(() => [
562
701
  MessageInput
563
702
  ]),
564
- _ts_metadata7("design:type", Array)
703
+ _ts_metadata9("design:type", Array)
565
704
  ], GenerateCopilotResponseInput.prototype, "messages", void 0);
566
- _ts_decorate7([
567
- Field7(() => FrontendInput),
568
- _ts_metadata7("design:type", typeof FrontendInput === "undefined" ? Object : FrontendInput)
705
+ _ts_decorate9([
706
+ Field9(() => FrontendInput),
707
+ _ts_metadata9("design:type", typeof FrontendInput === "undefined" ? Object : FrontendInput)
569
708
  ], GenerateCopilotResponseInput.prototype, "frontend", void 0);
570
- _ts_decorate7([
571
- Field7(() => CloudInput, {
709
+ _ts_decorate9([
710
+ Field9(() => CloudInput, {
572
711
  nullable: true
573
712
  }),
574
- _ts_metadata7("design:type", typeof CloudInput === "undefined" ? Object : CloudInput)
713
+ _ts_metadata9("design:type", typeof CloudInput === "undefined" ? Object : CloudInput)
575
714
  ], GenerateCopilotResponseInput.prototype, "cloud", void 0);
576
- _ts_decorate7([
577
- Field7(() => ForwardedParametersInput, {
715
+ _ts_decorate9([
716
+ Field9(() => ForwardedParametersInput, {
578
717
  nullable: true
579
718
  }),
580
- _ts_metadata7("design:type", typeof ForwardedParametersInput === "undefined" ? Object : ForwardedParametersInput)
719
+ _ts_metadata9("design:type", typeof ForwardedParametersInput === "undefined" ? Object : ForwardedParametersInput)
581
720
  ], GenerateCopilotResponseInput.prototype, "forwardedParameters", void 0);
582
- GenerateCopilotResponseInput = _ts_decorate7([
583
- InputType7()
721
+ _ts_decorate9([
722
+ Field9(() => AgentSessionInput, {
723
+ nullable: true
724
+ }),
725
+ _ts_metadata9("design:type", typeof AgentSessionInput === "undefined" ? Object : AgentSessionInput)
726
+ ], GenerateCopilotResponseInput.prototype, "agentSession", void 0);
727
+ _ts_decorate9([
728
+ Field9(() => AgentStateInput, {
729
+ nullable: true
730
+ }),
731
+ _ts_metadata9("design:type", typeof AgentStateInput === "undefined" ? Object : AgentStateInput)
732
+ ], GenerateCopilotResponseInput.prototype, "agentState", void 0);
733
+ _ts_decorate9([
734
+ Field9(() => [
735
+ AgentStateInput
736
+ ], {
737
+ nullable: true
738
+ }),
739
+ _ts_metadata9("design:type", Array)
740
+ ], GenerateCopilotResponseInput.prototype, "agentStates", void 0);
741
+ GenerateCopilotResponseInput = _ts_decorate9([
742
+ InputType9()
584
743
  ], GenerateCopilotResponseInput);
585
744
 
586
745
  // src/graphql/types/copilot-response.type.ts
587
- import { Field as Field9, InterfaceType, ObjectType as ObjectType2 } from "type-graphql";
746
+ import { Field as Field11, InterfaceType, ObjectType as ObjectType2 } from "type-graphql";
588
747
 
589
748
  // src/graphql/types/message-status.type.ts
590
- import { Field as Field8, ObjectType, createUnionType, registerEnumType as registerEnumType2 } from "type-graphql";
591
- function _ts_decorate8(decorators, target, key, desc) {
749
+ import { Field as Field10, ObjectType, createUnionType, registerEnumType as registerEnumType2 } from "type-graphql";
750
+ function _ts_decorate10(decorators, target, key, desc) {
592
751
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
593
752
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
594
753
  r = Reflect.decorate(decorators, target, key, desc);
@@ -598,12 +757,12 @@ function _ts_decorate8(decorators, target, key, desc) {
598
757
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
599
758
  return c > 3 && r && Object.defineProperty(target, key, r), r;
600
759
  }
601
- __name(_ts_decorate8, "_ts_decorate");
602
- function _ts_metadata8(k, v) {
760
+ __name(_ts_decorate10, "_ts_decorate");
761
+ function _ts_metadata10(k, v) {
603
762
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
604
763
  return Reflect.metadata(k, v);
605
764
  }
606
- __name(_ts_metadata8, "_ts_metadata");
765
+ __name(_ts_metadata10, "_ts_metadata");
607
766
  var MessageStatusCode;
608
767
  (function(MessageStatusCode2) {
609
768
  MessageStatusCode2["Pending"] = "pending";
@@ -616,25 +775,25 @@ registerEnumType2(MessageStatusCode, {
616
775
  var BaseMessageStatus = /* @__PURE__ */ __name(class BaseMessageStatus2 {
617
776
  code;
618
777
  }, "BaseMessageStatus");
619
- _ts_decorate8([
620
- Field8(() => MessageStatusCode),
621
- _ts_metadata8("design:type", String)
778
+ _ts_decorate10([
779
+ Field10(() => MessageStatusCode),
780
+ _ts_metadata10("design:type", String)
622
781
  ], BaseMessageStatus.prototype, "code", void 0);
623
- BaseMessageStatus = _ts_decorate8([
782
+ BaseMessageStatus = _ts_decorate10([
624
783
  ObjectType()
625
784
  ], BaseMessageStatus);
626
785
  var PendingMessageStatus = class extends BaseMessageStatus {
627
786
  code = "pending";
628
787
  };
629
788
  __name(PendingMessageStatus, "PendingMessageStatus");
630
- PendingMessageStatus = _ts_decorate8([
789
+ PendingMessageStatus = _ts_decorate10([
631
790
  ObjectType()
632
791
  ], PendingMessageStatus);
633
792
  var SuccessMessageStatus = class extends BaseMessageStatus {
634
793
  code = "success";
635
794
  };
636
795
  __name(SuccessMessageStatus, "SuccessMessageStatus");
637
- SuccessMessageStatus = _ts_decorate8([
796
+ SuccessMessageStatus = _ts_decorate10([
638
797
  ObjectType()
639
798
  ], SuccessMessageStatus);
640
799
  var FailedMessageStatus = class extends BaseMessageStatus {
@@ -642,11 +801,11 @@ var FailedMessageStatus = class extends BaseMessageStatus {
642
801
  reason;
643
802
  };
644
803
  __name(FailedMessageStatus, "FailedMessageStatus");
645
- _ts_decorate8([
646
- Field8(() => String),
647
- _ts_metadata8("design:type", String)
804
+ _ts_decorate10([
805
+ Field10(() => String),
806
+ _ts_metadata10("design:type", String)
648
807
  ], FailedMessageStatus.prototype, "reason", void 0);
649
- FailedMessageStatus = _ts_decorate8([
808
+ FailedMessageStatus = _ts_decorate10([
650
809
  ObjectType()
651
810
  ], FailedMessageStatus);
652
811
  var MessageStatusUnion = createUnionType({
@@ -659,7 +818,7 @@ var MessageStatusUnion = createUnionType({
659
818
  });
660
819
 
661
820
  // src/graphql/types/copilot-response.type.ts
662
- function _ts_decorate9(decorators, target, key, desc) {
821
+ function _ts_decorate11(decorators, target, key, desc) {
663
822
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
664
823
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
665
824
  r = Reflect.decorate(decorators, target, key, desc);
@@ -669,30 +828,30 @@ function _ts_decorate9(decorators, target, key, desc) {
669
828
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
670
829
  return c > 3 && r && Object.defineProperty(target, key, r), r;
671
830
  }
672
- __name(_ts_decorate9, "_ts_decorate");
673
- function _ts_metadata9(k, v) {
831
+ __name(_ts_decorate11, "_ts_decorate");
832
+ function _ts_metadata11(k, v) {
674
833
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
675
834
  return Reflect.metadata(k, v);
676
835
  }
677
- __name(_ts_metadata9, "_ts_metadata");
836
+ __name(_ts_metadata11, "_ts_metadata");
678
837
  var BaseMessageOutput = /* @__PURE__ */ __name(class BaseMessageOutput2 {
679
838
  id;
680
839
  createdAt;
681
840
  status;
682
841
  }, "BaseMessageOutput");
683
- _ts_decorate9([
684
- Field9(() => String),
685
- _ts_metadata9("design:type", String)
842
+ _ts_decorate11([
843
+ Field11(() => String),
844
+ _ts_metadata11("design:type", String)
686
845
  ], BaseMessageOutput.prototype, "id", void 0);
687
- _ts_decorate9([
688
- Field9(() => Date),
689
- _ts_metadata9("design:type", typeof Date === "undefined" ? Object : Date)
846
+ _ts_decorate11([
847
+ Field11(() => Date),
848
+ _ts_metadata11("design:type", typeof Date === "undefined" ? Object : Date)
690
849
  ], BaseMessageOutput.prototype, "createdAt", void 0);
691
- _ts_decorate9([
692
- Field9(() => MessageStatusUnion),
693
- _ts_metadata9("design:type", Object)
850
+ _ts_decorate11([
851
+ Field11(() => MessageStatusUnion),
852
+ _ts_metadata11("design:type", Object)
694
853
  ], BaseMessageOutput.prototype, "status", void 0);
695
- BaseMessageOutput = _ts_decorate9([
854
+ BaseMessageOutput = _ts_decorate11([
696
855
  InterfaceType({
697
856
  resolveType(value) {
698
857
  if (value.hasOwnProperty("content")) {
@@ -701,6 +860,8 @@ BaseMessageOutput = _ts_decorate9([
701
860
  return ActionExecutionMessageOutput;
702
861
  } else if (value.hasOwnProperty("result")) {
703
862
  return ResultMessageOutput;
863
+ } else if (value.hasOwnProperty("state")) {
864
+ return AgentStateMessageOutput;
704
865
  }
705
866
  return void 0;
706
867
  }
@@ -711,17 +872,17 @@ var TextMessageOutput = class {
711
872
  content;
712
873
  };
713
874
  __name(TextMessageOutput, "TextMessageOutput");
714
- _ts_decorate9([
715
- Field9(() => MessageRole),
716
- _ts_metadata9("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
875
+ _ts_decorate11([
876
+ Field11(() => MessageRole),
877
+ _ts_metadata11("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
717
878
  ], TextMessageOutput.prototype, "role", void 0);
718
- _ts_decorate9([
719
- Field9(() => [
879
+ _ts_decorate11([
880
+ Field11(() => [
720
881
  String
721
882
  ]),
722
- _ts_metadata9("design:type", Array)
883
+ _ts_metadata11("design:type", Array)
723
884
  ], TextMessageOutput.prototype, "content", void 0);
724
- TextMessageOutput = _ts_decorate9([
885
+ TextMessageOutput = _ts_decorate11([
725
886
  ObjectType2({
726
887
  implements: BaseMessageOutput
727
888
  })
@@ -732,21 +893,21 @@ var ActionExecutionMessageOutput = class {
732
893
  arguments;
733
894
  };
734
895
  __name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
735
- _ts_decorate9([
736
- Field9(() => String),
737
- _ts_metadata9("design:type", String)
896
+ _ts_decorate11([
897
+ Field11(() => String),
898
+ _ts_metadata11("design:type", String)
738
899
  ], ActionExecutionMessageOutput.prototype, "name", void 0);
739
- _ts_decorate9([
740
- Field9(() => ActionExecutionScope),
741
- _ts_metadata9("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
900
+ _ts_decorate11([
901
+ Field11(() => ActionExecutionScope),
902
+ _ts_metadata11("design:type", typeof ActionExecutionScope === "undefined" ? Object : ActionExecutionScope)
742
903
  ], ActionExecutionMessageOutput.prototype, "scope", void 0);
743
- _ts_decorate9([
744
- Field9(() => [
904
+ _ts_decorate11([
905
+ Field11(() => [
745
906
  String
746
907
  ]),
747
- _ts_metadata9("design:type", Array)
908
+ _ts_metadata11("design:type", Array)
748
909
  ], ActionExecutionMessageOutput.prototype, "arguments", void 0);
749
- ActionExecutionMessageOutput = _ts_decorate9([
910
+ ActionExecutionMessageOutput = _ts_decorate11([
750
911
  ObjectType2({
751
912
  implements: BaseMessageOutput
752
913
  })
@@ -757,23 +918,71 @@ var ResultMessageOutput = class {
757
918
  result;
758
919
  };
759
920
  __name(ResultMessageOutput, "ResultMessageOutput");
760
- _ts_decorate9([
761
- Field9(() => String),
762
- _ts_metadata9("design:type", String)
921
+ _ts_decorate11([
922
+ Field11(() => String),
923
+ _ts_metadata11("design:type", String)
763
924
  ], ResultMessageOutput.prototype, "actionExecutionId", void 0);
764
- _ts_decorate9([
765
- Field9(() => String),
766
- _ts_metadata9("design:type", String)
925
+ _ts_decorate11([
926
+ Field11(() => String),
927
+ _ts_metadata11("design:type", String)
767
928
  ], ResultMessageOutput.prototype, "actionName", void 0);
768
- _ts_decorate9([
769
- Field9(() => String),
770
- _ts_metadata9("design:type", String)
929
+ _ts_decorate11([
930
+ Field11(() => String),
931
+ _ts_metadata11("design:type", String)
771
932
  ], ResultMessageOutput.prototype, "result", void 0);
772
- ResultMessageOutput = _ts_decorate9([
933
+ ResultMessageOutput = _ts_decorate11([
773
934
  ObjectType2({
774
935
  implements: BaseMessageOutput
775
936
  })
776
937
  ], ResultMessageOutput);
938
+ var AgentStateMessageOutput = class {
939
+ threadId;
940
+ agentName;
941
+ nodeName;
942
+ runId;
943
+ active;
944
+ role;
945
+ state;
946
+ running;
947
+ };
948
+ __name(AgentStateMessageOutput, "AgentStateMessageOutput");
949
+ _ts_decorate11([
950
+ Field11(() => String),
951
+ _ts_metadata11("design:type", String)
952
+ ], AgentStateMessageOutput.prototype, "threadId", void 0);
953
+ _ts_decorate11([
954
+ Field11(() => String),
955
+ _ts_metadata11("design:type", String)
956
+ ], AgentStateMessageOutput.prototype, "agentName", void 0);
957
+ _ts_decorate11([
958
+ Field11(() => String),
959
+ _ts_metadata11("design:type", String)
960
+ ], AgentStateMessageOutput.prototype, "nodeName", void 0);
961
+ _ts_decorate11([
962
+ Field11(() => String),
963
+ _ts_metadata11("design:type", String)
964
+ ], AgentStateMessageOutput.prototype, "runId", void 0);
965
+ _ts_decorate11([
966
+ Field11(() => Boolean),
967
+ _ts_metadata11("design:type", Boolean)
968
+ ], AgentStateMessageOutput.prototype, "active", void 0);
969
+ _ts_decorate11([
970
+ Field11(() => MessageRole),
971
+ _ts_metadata11("design:type", typeof MessageRole === "undefined" ? Object : MessageRole)
972
+ ], AgentStateMessageOutput.prototype, "role", void 0);
973
+ _ts_decorate11([
974
+ Field11(() => String),
975
+ _ts_metadata11("design:type", String)
976
+ ], AgentStateMessageOutput.prototype, "state", void 0);
977
+ _ts_decorate11([
978
+ Field11(() => Boolean),
979
+ _ts_metadata11("design:type", Boolean)
980
+ ], AgentStateMessageOutput.prototype, "running", void 0);
981
+ AgentStateMessageOutput = _ts_decorate11([
982
+ ObjectType2({
983
+ implements: BaseMessageOutput
984
+ })
985
+ ], AgentStateMessageOutput);
777
986
  var CopilotResponse = class {
778
987
  threadId;
779
988
  status;
@@ -781,27 +990,27 @@ var CopilotResponse = class {
781
990
  messages;
782
991
  };
783
992
  __name(CopilotResponse, "CopilotResponse");
784
- _ts_decorate9([
785
- Field9(() => String),
786
- _ts_metadata9("design:type", String)
993
+ _ts_decorate11([
994
+ Field11(() => String),
995
+ _ts_metadata11("design:type", String)
787
996
  ], CopilotResponse.prototype, "threadId", void 0);
788
- _ts_decorate9([
789
- Field9(() => ResponseStatusUnion),
790
- _ts_metadata9("design:type", Object)
997
+ _ts_decorate11([
998
+ Field11(() => ResponseStatusUnion),
999
+ _ts_metadata11("design:type", Object)
791
1000
  ], CopilotResponse.prototype, "status", void 0);
792
- _ts_decorate9([
793
- Field9({
1001
+ _ts_decorate11([
1002
+ Field11({
794
1003
  nullable: true
795
1004
  }),
796
- _ts_metadata9("design:type", String)
1005
+ _ts_metadata11("design:type", String)
797
1006
  ], CopilotResponse.prototype, "runId", void 0);
798
- _ts_decorate9([
799
- Field9(() => [
1007
+ _ts_decorate11([
1008
+ Field11(() => [
800
1009
  BaseMessageOutput
801
1010
  ]),
802
- _ts_metadata9("design:type", Array)
1011
+ _ts_metadata11("design:type", Array)
803
1012
  ], CopilotResponse.prototype, "messages", void 0);
804
- CopilotResponse = _ts_decorate9([
1013
+ CopilotResponse = _ts_decorate11([
805
1014
  ObjectType2()
806
1015
  ], CopilotResponse);
807
1016
 
@@ -809,7 +1018,366 @@ CopilotResponse = _ts_decorate9([
809
1018
  import { Repeater } from "graphql-yoga";
810
1019
 
811
1020
  // src/service-adapters/events.ts
812
- import { of, concat, map, scan, concatMap, ReplaySubject, firstValueFrom } from "rxjs";
1021
+ import { of, concat, map, scan as scan2, concatMap, ReplaySubject as ReplaySubject2, firstValueFrom, from } from "rxjs";
1022
+
1023
+ // src/lib/telemetry-client.ts
1024
+ import { TelemetryClient } from "@copilotkit/shared";
1025
+ var packageJson = require_package();
1026
+ var telemetryClient = new TelemetryClient({
1027
+ packageName: packageJson.name,
1028
+ packageVersion: packageJson.version
1029
+ });
1030
+ var telemetry_client_default = telemetryClient;
1031
+
1032
+ // src/agents/langgraph/event-source.ts
1033
+ import { ReplaySubject, scan, mergeMap } from "rxjs";
1034
+
1035
+ // src/agents/langgraph/events.ts
1036
+ var LangGraphEventTypes;
1037
+ (function(LangGraphEventTypes2) {
1038
+ LangGraphEventTypes2["OnChainStart"] = "on_chain_start";
1039
+ LangGraphEventTypes2["OnChainStream"] = "on_chain_stream";
1040
+ LangGraphEventTypes2["OnChainEnd"] = "on_chain_end";
1041
+ LangGraphEventTypes2["OnChatModelStart"] = "on_chat_model_start";
1042
+ LangGraphEventTypes2["OnChatModelStream"] = "on_chat_model_stream";
1043
+ LangGraphEventTypes2["OnChatModelEnd"] = "on_chat_model_end";
1044
+ LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
1045
+ LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
1046
+ LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
1047
+ })(LangGraphEventTypes || (LangGraphEventTypes = {}));
1048
+
1049
+ // src/agents/langgraph/event-source.ts
1050
+ var RemoteLangGraphEventSource = class {
1051
+ eventStream$ = new ReplaySubject();
1052
+ async streamResponse(response) {
1053
+ const reader = response.body.getReader();
1054
+ const decoder = new TextDecoder();
1055
+ let buffer = [];
1056
+ const eventStream$ = this.eventStream$;
1057
+ function flushBuffer() {
1058
+ const currentBuffer = buffer.join("");
1059
+ if (currentBuffer.trim().length === 0) {
1060
+ return;
1061
+ }
1062
+ const parts = currentBuffer.split("\n");
1063
+ if (parts.length === 0) {
1064
+ return;
1065
+ }
1066
+ const lastPartIsComplete = currentBuffer.endsWith("\n");
1067
+ buffer = [];
1068
+ if (!lastPartIsComplete) {
1069
+ buffer.push(parts.pop());
1070
+ }
1071
+ parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
1072
+ eventStream$.next(JSON.parse(part));
1073
+ });
1074
+ }
1075
+ __name(flushBuffer, "flushBuffer");
1076
+ while (true) {
1077
+ const { done, value } = await reader.read();
1078
+ if (!done) {
1079
+ buffer.push(decoder.decode(value, {
1080
+ stream: true
1081
+ }));
1082
+ }
1083
+ flushBuffer();
1084
+ if (done) {
1085
+ break;
1086
+ }
1087
+ }
1088
+ eventStream$.complete();
1089
+ }
1090
+ processLangGraphEvents() {
1091
+ return this.eventStream$.pipe(scan((acc, event) => {
1092
+ var _a, _b, _c, _d, _e, _f, _g, _h;
1093
+ if (event.event === LangGraphEventTypes.OnChatModelStream) {
1094
+ if ((_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) {
1095
+ acc.prevToolCallId = acc.toolCallId;
1096
+ acc.toolCallId = (_d = event.data.chunk.kwargs) == null ? void 0 : _d.id;
1097
+ if ((_e = event.data.chunk.kwargs.tool_call_chunks[0]) == null ? void 0 : _e.name) {
1098
+ acc.toolCallName = event.data.chunk.kwargs.tool_call_chunks[0].name;
1099
+ }
1100
+ }
1101
+ acc.prevMessageId = acc.messageId;
1102
+ acc.messageId = (_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.id;
1103
+ } else {
1104
+ acc.prevToolCallId = acc.toolCallId;
1105
+ acc.toolCallId = null;
1106
+ acc.prevMessageId = acc.messageId;
1107
+ acc.messageId = null;
1108
+ acc.toolCallName = null;
1109
+ }
1110
+ acc.event = event;
1111
+ return acc;
1112
+ }, {
1113
+ event: null,
1114
+ toolCallId: null,
1115
+ prevToolCallId: null,
1116
+ messageId: null,
1117
+ toolCallName: null,
1118
+ prevMessageId: null
1119
+ }), mergeMap((eventWithState) => {
1120
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1121
+ const events = [];
1122
+ let shouldEmitMessages = false;
1123
+ let shouldEmitToolCalls = false;
1124
+ if (eventWithState.event.event == LangGraphEventTypes.OnChatModelStream) {
1125
+ if ((_a = eventWithState.event.tags) == null ? void 0 : _a.includes("copilotkit:emit-tool-calls")) {
1126
+ shouldEmitToolCalls = true;
1127
+ }
1128
+ if ((_b = eventWithState.event.tags) == null ? void 0 : _b.includes("copilotkit:emit-messages")) {
1129
+ shouldEmitMessages = true;
1130
+ }
1131
+ }
1132
+ if (eventWithState.prevToolCallId !== null && eventWithState.prevToolCallId !== eventWithState.toolCallId && shouldEmitToolCalls) {
1133
+ events.push({
1134
+ type: RuntimeEventTypes.ActionExecutionEnd
1135
+ });
1136
+ }
1137
+ if (eventWithState.prevMessageId !== null && eventWithState.prevMessageId !== eventWithState.messageId && shouldEmitMessages) {
1138
+ events.push({
1139
+ type: RuntimeEventTypes.TextMessageEnd
1140
+ });
1141
+ }
1142
+ switch (eventWithState.event.event) {
1143
+ case LangGraphEventTypes.OnCopilotKitStateSync:
1144
+ events.push({
1145
+ type: RuntimeEventTypes.AgentStateMessage,
1146
+ threadId: eventWithState.event.thread_id,
1147
+ role: eventWithState.event.role,
1148
+ agentName: eventWithState.event.agent_name,
1149
+ nodeName: eventWithState.event.node_name,
1150
+ runId: eventWithState.event.run_id,
1151
+ active: eventWithState.event.active,
1152
+ state: JSON.stringify(eventWithState.event.state),
1153
+ running: eventWithState.event.running
1154
+ });
1155
+ break;
1156
+ case LangGraphEventTypes.OnToolEnd:
1157
+ break;
1158
+ case LangGraphEventTypes.OnChatModelStream:
1159
+ if (eventWithState.toolCallId !== null && eventWithState.prevToolCallId !== eventWithState.toolCallId) {
1160
+ if (shouldEmitToolCalls) {
1161
+ events.push({
1162
+ type: RuntimeEventTypes.ActionExecutionStart,
1163
+ actionExecutionId: eventWithState.toolCallId,
1164
+ actionName: eventWithState.toolCallName,
1165
+ scope: "client"
1166
+ });
1167
+ }
1168
+ } else if (eventWithState.messageId !== null && eventWithState.prevMessageId !== eventWithState.messageId) {
1169
+ if (shouldEmitMessages) {
1170
+ events.push({
1171
+ type: RuntimeEventTypes.TextMessageStart,
1172
+ messageId: eventWithState.messageId
1173
+ });
1174
+ }
1175
+ }
1176
+ const args = (_g = (_f = (_e = (_d = (_c = eventWithState.event.data) == null ? void 0 : _c.chunk) == null ? void 0 : _d.kwargs) == null ? void 0 : _e.tool_call_chunks) == null ? void 0 : _f[0]) == null ? void 0 : _g.args;
1177
+ const content = (_j = (_i = (_h = eventWithState.event.data) == null ? void 0 : _h.chunk) == null ? void 0 : _i.kwargs) == null ? void 0 : _j.content;
1178
+ if (args) {
1179
+ if (shouldEmitToolCalls) {
1180
+ events.push({
1181
+ type: RuntimeEventTypes.ActionExecutionArgs,
1182
+ args
1183
+ });
1184
+ }
1185
+ } else if (eventWithState.messageId !== null && content) {
1186
+ if (shouldEmitMessages) {
1187
+ events.push({
1188
+ type: RuntimeEventTypes.TextMessageContent,
1189
+ content
1190
+ });
1191
+ }
1192
+ }
1193
+ break;
1194
+ }
1195
+ return events;
1196
+ }));
1197
+ }
1198
+ };
1199
+ __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
1200
+
1201
+ // src/lib/runtime/remote-actions.ts
1202
+ function isLangGraphAgentAction(action) {
1203
+ if (!action) {
1204
+ return false;
1205
+ }
1206
+ return typeof action.langGraphAgentHandler === "function";
1207
+ }
1208
+ __name(isLangGraphAgentAction, "isLangGraphAgentAction");
1209
+ function createHeaders(onBeforeRequest, graphqlContext) {
1210
+ const headers = {
1211
+ "Content-Type": "application/json"
1212
+ };
1213
+ if (onBeforeRequest) {
1214
+ const { headers: additionalHeaders } = onBeforeRequest({
1215
+ ctx: graphqlContext
1216
+ });
1217
+ if (additionalHeaders) {
1218
+ Object.assign(headers, additionalHeaders);
1219
+ }
1220
+ }
1221
+ return headers;
1222
+ }
1223
+ __name(createHeaders, "createHeaders");
1224
+ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2 }) {
1225
+ logger2.debug({
1226
+ url
1227
+ }, "Fetching actions from url");
1228
+ const headers = createHeaders(onBeforeRequest, graphqlContext);
1229
+ const response = await fetch(`${url}/info`, {
1230
+ method: "POST",
1231
+ headers,
1232
+ body: JSON.stringify({
1233
+ properties: graphqlContext.properties
1234
+ })
1235
+ });
1236
+ if (!response.ok) {
1237
+ logger2.error({
1238
+ url,
1239
+ status: response.status,
1240
+ body: await response.text()
1241
+ }, "Failed to fetch actions from url");
1242
+ return [];
1243
+ }
1244
+ const json = await response.json();
1245
+ logger2.debug({
1246
+ json
1247
+ }, "Fetched actions from url");
1248
+ return json;
1249
+ }
1250
+ __name(fetchRemoteInfo, "fetchRemoteInfo");
1251
+ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
1252
+ const actions = json["actions"].map((action) => ({
1253
+ name: action.name,
1254
+ description: action.description,
1255
+ parameters: action.parameters,
1256
+ handler: async (args) => {
1257
+ logger2.debug({
1258
+ actionName: action.name,
1259
+ args
1260
+ }, "Executing remote action");
1261
+ const headers = createHeaders(onBeforeRequest, graphqlContext);
1262
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
1263
+ const response = await fetch(`${url}/actions/execute`, {
1264
+ method: "POST",
1265
+ headers,
1266
+ body: JSON.stringify({
1267
+ name: action.name,
1268
+ arguments: args,
1269
+ properties: graphqlContext.properties
1270
+ })
1271
+ });
1272
+ if (!response.ok) {
1273
+ logger2.error({
1274
+ url,
1275
+ status: response.status,
1276
+ body: await response.text()
1277
+ }, "Failed to execute remote action");
1278
+ return "Failed to execute remote action";
1279
+ }
1280
+ const requestResult = await response.json();
1281
+ const result = requestResult["result"];
1282
+ logger2.debug({
1283
+ actionName: action.name,
1284
+ result
1285
+ }, "Executed remote action");
1286
+ return result;
1287
+ }
1288
+ }));
1289
+ const agents = json["agents"].map((agent) => ({
1290
+ name: agent.name,
1291
+ description: agent.description,
1292
+ parameters: [],
1293
+ handler: async (_args) => {
1294
+ },
1295
+ langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
1296
+ var _a;
1297
+ logger2.debug({
1298
+ actionName: agent.name
1299
+ }, "Executing remote agent");
1300
+ const headers = createHeaders(onBeforeRequest, graphqlContext);
1301
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
1302
+ let state = {};
1303
+ if (agentStates) {
1304
+ const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
1305
+ if (jsonState) {
1306
+ state = JSON.parse(jsonState);
1307
+ }
1308
+ }
1309
+ const response = await fetch(`${url}/agents/execute`, {
1310
+ method: "POST",
1311
+ headers,
1312
+ body: JSON.stringify({
1313
+ name,
1314
+ threadId,
1315
+ nodeName,
1316
+ messages,
1317
+ state,
1318
+ properties: graphqlContext.properties,
1319
+ actions: actionInputsWithoutAgents.map((action) => ({
1320
+ name: action.name,
1321
+ description: action.description,
1322
+ parameters: JSON.parse(action.jsonSchema)
1323
+ }))
1324
+ })
1325
+ });
1326
+ if (!response.ok) {
1327
+ logger2.error({
1328
+ url,
1329
+ status: response.status,
1330
+ body: await response.text()
1331
+ }, "Failed to execute remote agent");
1332
+ throw new Error("Failed to execute remote agent");
1333
+ }
1334
+ const eventSource = new RemoteLangGraphEventSource();
1335
+ eventSource.streamResponse(response);
1336
+ return eventSource.processLangGraphEvents();
1337
+ }
1338
+ }));
1339
+ return [
1340
+ ...actions,
1341
+ ...agents
1342
+ ];
1343
+ }
1344
+ __name(constructRemoteActions, "constructRemoteActions");
1345
+ async function setupRemoteActions({ remoteActionDefinitions, graphqlContext, messages, agentStates }) {
1346
+ const logger2 = graphqlContext.logger.child({
1347
+ component: "remote-actions.fetchRemoteActions"
1348
+ });
1349
+ logger2.debug({
1350
+ remoteActionDefinitions
1351
+ }, "Fetching remote actions");
1352
+ const filtered = remoteActionDefinitions.filter((value, index, self) => index === self.findIndex((t) => t.url === value.url));
1353
+ const result = await Promise.all(filtered.map(async (actionDefinition) => {
1354
+ const json = await fetchRemoteInfo({
1355
+ url: actionDefinition.url,
1356
+ onBeforeRequest: actionDefinition.onBeforeRequest,
1357
+ graphqlContext,
1358
+ logger: logger2.child({
1359
+ component: "remote-actions.fetchActionsFromUrl",
1360
+ actionDefinition
1361
+ })
1362
+ });
1363
+ return constructRemoteActions({
1364
+ json,
1365
+ messages,
1366
+ url: actionDefinition.url,
1367
+ onBeforeRequest: actionDefinition.onBeforeRequest,
1368
+ graphqlContext,
1369
+ logger: logger2.child({
1370
+ component: "remote-actions.constructActions",
1371
+ actionDefinition
1372
+ }),
1373
+ agentStates
1374
+ });
1375
+ }));
1376
+ return result.flat();
1377
+ }
1378
+ __name(setupRemoteActions, "setupRemoteActions");
1379
+
1380
+ // src/service-adapters/events.ts
813
1381
  var RuntimeEventTypes;
814
1382
  (function(RuntimeEventTypes2) {
815
1383
  RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
@@ -819,8 +1387,9 @@ var RuntimeEventTypes;
819
1387
  RuntimeEventTypes2["ActionExecutionArgs"] = "ActionExecutionArgs";
820
1388
  RuntimeEventTypes2["ActionExecutionEnd"] = "ActionExecutionEnd";
821
1389
  RuntimeEventTypes2["ActionExecutionResult"] = "ActionExecutionResult";
1390
+ RuntimeEventTypes2["AgentStateMessage"] = "AgentStateMessage";
822
1391
  })(RuntimeEventTypes || (RuntimeEventTypes = {}));
823
- var RuntimeEventSubject = class extends ReplaySubject {
1392
+ var RuntimeEventSubject = class extends ReplaySubject2 {
824
1393
  constructor() {
825
1394
  super();
826
1395
  }
@@ -877,6 +1446,19 @@ var RuntimeEventSubject = class extends ReplaySubject {
877
1446
  result
878
1447
  });
879
1448
  }
1449
+ sendAgentStateMessage(threadId, agentName, nodeName, runId, active, role, state, running) {
1450
+ this.next({
1451
+ type: "AgentStateMessage",
1452
+ threadId,
1453
+ agentName,
1454
+ nodeName,
1455
+ runId,
1456
+ active,
1457
+ role,
1458
+ state,
1459
+ running
1460
+ });
1461
+ }
880
1462
  };
881
1463
  __name(RuntimeEventSubject, "RuntimeEventSubject");
882
1464
  var RuntimeEventSource = class {
@@ -885,7 +1467,7 @@ var RuntimeEventSource = class {
885
1467
  async stream(callback) {
886
1468
  this.callback = callback;
887
1469
  }
888
- process({ serversideActions, guardrailsResult$ }) {
1470
+ processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
889
1471
  this.callback(this.eventStream$).catch((error) => {
890
1472
  console.error("Error in event source callback", error);
891
1473
  });
@@ -893,18 +1475,23 @@ var RuntimeEventSource = class {
893
1475
  // mark tools for server side execution
894
1476
  map((event) => {
895
1477
  if (event.type === "ActionExecutionStart") {
896
- event.scope = serversideActions.find((action) => action.name === event.actionName) ? "server" : "client";
1478
+ if (event.scope !== "passThrough") {
1479
+ event.scope = serverSideActions.find((action) => action.name === event.actionName) ? "server" : "client";
1480
+ }
897
1481
  }
898
1482
  return event;
899
1483
  }),
900
1484
  // track state
901
- scan((acc, event) => {
1485
+ scan2((acc, event) => {
1486
+ acc = {
1487
+ ...acc
1488
+ };
902
1489
  if (event.type === "ActionExecutionStart") {
903
1490
  acc.callActionServerSide = event.scope === "server";
904
1491
  acc.args = "";
905
1492
  acc.actionExecutionId = event.actionExecutionId;
906
1493
  if (acc.callActionServerSide) {
907
- acc.action = serversideActions.find((action) => action.name === event.actionName);
1494
+ acc.action = serverSideActions.find((action) => action.name === event.actionName);
908
1495
  }
909
1496
  } else if (event.type === "ActionExecutionArgs") {
910
1497
  acc.args += event.args;
@@ -921,9 +1508,10 @@ var RuntimeEventSource = class {
921
1508
  concatMap((eventWithState) => {
922
1509
  if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
923
1510
  const toolCallEventStream$ = new RuntimeEventSubject();
924
- executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId).catch((error) => {
1511
+ executeAction(toolCallEventStream$, guardrailsResult$ ? guardrailsResult$ : null, eventWithState.action, eventWithState.args, eventWithState.actionExecutionId, actionInputsWithoutAgents).catch((error) => {
925
1512
  console.error(error);
926
1513
  });
1514
+ telemetry_client_default.capture("oss.runtime.server_action_executed", {});
927
1515
  return concat(of(eventWithState.event), toolCallEventStream$);
928
1516
  } else {
929
1517
  return of(eventWithState.event);
@@ -933,7 +1521,8 @@ var RuntimeEventSource = class {
933
1521
  }
934
1522
  };
935
1523
  __name(RuntimeEventSource, "RuntimeEventSource");
936
- async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId) {
1524
+ async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
1525
+ var _a;
937
1526
  if (guardrailsResult$) {
938
1527
  const { status } = await firstValueFrom(guardrailsResult$);
939
1528
  if (status === "denied") {
@@ -945,15 +1534,28 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
945
1534
  if (actionArguments) {
946
1535
  args = JSON.parse(actionArguments);
947
1536
  }
948
- const result = await action.handler(args);
949
- await streamLangChainResponse({
950
- result,
951
- eventStream$,
952
- actionExecution: {
1537
+ if (isLangGraphAgentAction(action)) {
1538
+ eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
1539
+ const stream = await action.langGraphAgentHandler({
953
1540
  name: action.name,
954
- id: actionExecutionId
955
- }
956
- });
1541
+ actionInputsWithoutAgents
1542
+ });
1543
+ from(stream).subscribe({
1544
+ next: (event) => eventStream$.next(event),
1545
+ error: (err) => console.error("Error in stream", err),
1546
+ complete: () => eventStream$.complete()
1547
+ });
1548
+ } else {
1549
+ const result = await ((_a = action.handler) == null ? void 0 : _a.call(action, args));
1550
+ await streamLangChainResponse({
1551
+ result,
1552
+ eventStream$,
1553
+ actionExecution: {
1554
+ name: action.name,
1555
+ id: actionExecutionId
1556
+ }
1557
+ });
1558
+ }
957
1559
  }
958
1560
  __name(executeAction, "executeAction");
959
1561
 
@@ -961,19 +1563,8 @@ __name(executeAction, "executeAction");
961
1563
  import { GraphQLJSONObject } from "graphql-scalars";
962
1564
  import { plainToInstance } from "class-transformer";
963
1565
  import { GraphQLError } from "graphql";
964
-
965
- // src/lib/telemetry-client.ts
966
- import { TelemetryClient } from "@copilotkit/shared";
967
- var packageJson = require_package();
968
- var telemetryClient = new TelemetryClient({
969
- packageName: packageJson.name,
970
- packageVersion: packageJson.version
971
- });
972
- var telemetry_client_default = telemetryClient;
973
-
974
- // src/graphql/resolvers/copilot.resolver.ts
975
1566
  import { randomId } from "@copilotkit/shared";
976
- function _ts_decorate10(decorators, target, key, desc) {
1567
+ function _ts_decorate12(decorators, target, key, desc) {
977
1568
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
978
1569
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
979
1570
  r = Reflect.decorate(decorators, target, key, desc);
@@ -983,12 +1574,12 @@ function _ts_decorate10(decorators, target, key, desc) {
983
1574
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
984
1575
  return c > 3 && r && Object.defineProperty(target, key, r), r;
985
1576
  }
986
- __name(_ts_decorate10, "_ts_decorate");
987
- function _ts_metadata10(k, v) {
1577
+ __name(_ts_decorate12, "_ts_decorate");
1578
+ function _ts_metadata12(k, v) {
988
1579
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
989
1580
  return Reflect.metadata(k, v);
990
1581
  }
991
- __name(_ts_metadata10, "_ts_metadata");
1582
+ __name(_ts_metadata12, "_ts_metadata");
992
1583
  function _ts_param(paramIndex, decorator) {
993
1584
  return function(target, key) {
994
1585
  decorator(target, key, paramIndex);
@@ -997,7 +1588,6 @@ function _ts_param(paramIndex, decorator) {
997
1588
  __name(_ts_param, "_ts_param");
998
1589
  var invokeGuardrails = /* @__PURE__ */ __name(async ({ baseUrl, copilotCloudPublicApiKey, data, onResult, onError }) => {
999
1590
  var _a;
1000
- console.log("invokeGuardrails.baseUrl", baseUrl);
1001
1591
  if (data.messages.length && ((_a = data.messages[data.messages.length - 1].textMessage) == null ? void 0 : _a.role) === MessageRole.user) {
1002
1592
  const messages = data.messages.filter((m) => m.textMessage !== void 0 && (m.textMessage.role === MessageRole.user || m.textMessage.role === MessageRole.assistant)).map((m) => ({
1003
1593
  role: m.textMessage.role,
@@ -1043,8 +1633,6 @@ var CopilotResolver = class {
1043
1633
  logger2.debug({
1044
1634
  data
1045
1635
  }, "Generating Copilot response");
1046
- const copilotRuntime = ctx._copilotkit.runtime;
1047
- const serviceAdapter = ctx._copilotkit.serviceAdapter;
1048
1636
  if (properties) {
1049
1637
  logger2.debug("Properties provided, merging with context properties");
1050
1638
  ctx.properties = {
@@ -1052,6 +1640,8 @@ var CopilotResolver = class {
1052
1640
  ...properties
1053
1641
  };
1054
1642
  }
1643
+ const copilotRuntime = ctx._copilotkit.runtime;
1644
+ const serviceAdapter = ctx._copilotkit.serviceAdapter;
1055
1645
  let copilotCloudPublicApiKey = null;
1056
1646
  let copilotCloudBaseUrl;
1057
1647
  if (data.cloud) {
@@ -1079,9 +1669,9 @@ var CopilotResolver = class {
1079
1669
  });
1080
1670
  }
1081
1671
  logger2.debug("Setting up subjects");
1082
- const responseStatus$ = new ReplaySubject2();
1083
- const interruptStreaming$ = new ReplaySubject2();
1084
- const guardrailsResult$ = new ReplaySubject2();
1672
+ const responseStatus$ = new ReplaySubject3();
1673
+ const interruptStreaming$ = new ReplaySubject3();
1674
+ const guardrailsResult$ = new ReplaySubject3();
1085
1675
  let outputMessages = [];
1086
1676
  let resolveOutputMessagesPromise;
1087
1677
  let rejectOutputMessagesPromise;
@@ -1090,16 +1680,18 @@ var CopilotResolver = class {
1090
1680
  rejectOutputMessagesPromise = reject;
1091
1681
  });
1092
1682
  logger2.debug("Processing");
1093
- const { eventSource, threadId = randomId(), runId, actions } = await copilotRuntime.process({
1683
+ const { eventSource, threadId = randomId(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
1094
1684
  serviceAdapter,
1095
1685
  messages: data.messages,
1096
1686
  actions: data.frontend.actions,
1097
1687
  threadId: data.threadId,
1098
1688
  runId: data.runId,
1099
1689
  publicApiKey: void 0,
1100
- properties: ctx.properties || {},
1101
1690
  outputMessagesPromise,
1691
+ graphqlContext: ctx,
1102
1692
  forwardedParameters: data.forwardedParameters,
1693
+ agentSession: data.agentSession,
1694
+ agentStates: data.agentStates,
1103
1695
  url: data.frontend.url
1104
1696
  });
1105
1697
  logger2.debug("Event source created, creating response");
@@ -1157,9 +1749,13 @@ var CopilotResolver = class {
1157
1749
  });
1158
1750
  }
1159
1751
  let eventStreamSubscription;
1160
- const eventStream = eventSource.process({
1161
- serversideActions: actions,
1162
- guardrailsResult$: ((_b2 = data.cloud) == null ? void 0 : _b2.guardrails) ? guardrailsResult$ : null
1752
+ const eventStream = eventSource.processRuntimeEvents({
1753
+ serverSideActions,
1754
+ guardrailsResult$: ((_b2 = data.cloud) == null ? void 0 : _b2.guardrails) ? guardrailsResult$ : null,
1755
+ actionInputsWithoutAgents: actionInputsWithoutAgents.filter(
1756
+ // TODO-AGENTS: do not exclude ALL server side actions
1757
+ (action) => !serverSideActions.find((serverSideAction) => serverSideAction.name == action.name)
1758
+ )
1163
1759
  }).pipe(
1164
1760
  // shareReplay() ensures that later subscribers will see the whole stream instead of
1165
1761
  // just the events that were emitted after the subscriber was added.
@@ -1307,6 +1903,36 @@ var CopilotResolver = class {
1307
1903
  result: event.result
1308
1904
  }));
1309
1905
  break;
1906
+ case RuntimeEventTypes.AgentStateMessage:
1907
+ logger2.debug({
1908
+ event
1909
+ }, "Agent message event received");
1910
+ pushMessage({
1911
+ id: randomId(),
1912
+ status: new SuccessMessageStatus(),
1913
+ threadId: event.threadId,
1914
+ agentName: event.agentName,
1915
+ nodeName: event.nodeName,
1916
+ runId: event.runId,
1917
+ active: event.active,
1918
+ state: event.state,
1919
+ running: event.running,
1920
+ role: MessageRole.assistant,
1921
+ createdAt: /* @__PURE__ */ new Date()
1922
+ });
1923
+ outputMessages.push(plainToInstance(AgentStateMessage, {
1924
+ id: randomId(),
1925
+ threadId: event.threadId,
1926
+ agentName: event.agentName,
1927
+ nodeName: event.nodeName,
1928
+ runId: event.runId,
1929
+ active: event.active,
1930
+ state: event.state,
1931
+ running: event.running,
1932
+ role: MessageRole.assistant,
1933
+ createdAt: /* @__PURE__ */ new Date()
1934
+ }));
1935
+ break;
1310
1936
  }
1311
1937
  },
1312
1938
  error: (err) => {
@@ -1339,28 +1965,28 @@ var CopilotResolver = class {
1339
1965
  }
1340
1966
  };
1341
1967
  __name(CopilotResolver, "CopilotResolver");
1342
- _ts_decorate10([
1968
+ _ts_decorate12([
1343
1969
  Query(() => String),
1344
- _ts_metadata10("design:type", Function),
1345
- _ts_metadata10("design:paramtypes", []),
1346
- _ts_metadata10("design:returntype", Promise)
1970
+ _ts_metadata12("design:type", Function),
1971
+ _ts_metadata12("design:paramtypes", []),
1972
+ _ts_metadata12("design:returntype", Promise)
1347
1973
  ], CopilotResolver.prototype, "hello", null);
1348
- _ts_decorate10([
1974
+ _ts_decorate12([
1349
1975
  Mutation(() => CopilotResponse),
1350
1976
  _ts_param(0, Ctx()),
1351
1977
  _ts_param(1, Arg("data")),
1352
1978
  _ts_param(2, Arg("properties", () => GraphQLJSONObject, {
1353
1979
  nullable: true
1354
1980
  })),
1355
- _ts_metadata10("design:type", Function),
1356
- _ts_metadata10("design:paramtypes", [
1981
+ _ts_metadata12("design:type", Function),
1982
+ _ts_metadata12("design:paramtypes", [
1357
1983
  typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
1358
1984
  typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
1359
1985
  typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
1360
1986
  ]),
1361
- _ts_metadata10("design:returntype", Promise)
1987
+ _ts_metadata12("design:returntype", Promise)
1362
1988
  ], CopilotResolver.prototype, "generateCopilotResponse", null);
1363
- CopilotResolver = _ts_decorate10([
1989
+ CopilotResolver = _ts_decorate12([
1364
1990
  Resolver(() => CopilotResponse)
1365
1991
  ], CopilotResolver);
1366
1992
 
@@ -1494,11 +2120,13 @@ function copilotRuntimeNodeHttpEndpoint(options) {
1494
2120
  __name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
1495
2121
 
1496
2122
  export {
1497
- RuntimeEventSource,
1498
2123
  telemetry_client_default,
2124
+ isLangGraphAgentAction,
2125
+ setupRemoteActions,
2126
+ RuntimeEventSource,
1499
2127
  createContext,
1500
2128
  buildSchema,
1501
2129
  getCommonConfig,
1502
2130
  copilotRuntimeNodeHttpEndpoint
1503
2131
  };
1504
- //# sourceMappingURL=chunk-3TQLJ3YL.mjs.map
2132
+ //# sourceMappingURL=chunk-XROLDARH.mjs.map