@copilotkit/runtime 1.1.2 → 1.1.3-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 (85) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +32 -37
  3. package/__snapshots__/schema/schema.graphql +42 -0
  4. package/dist/chunk-4WFNRUBE.mjs +260 -0
  5. package/dist/chunk-4WFNRUBE.mjs.map +1 -0
  6. package/dist/{chunk-MKV3LEJ6.mjs → chunk-6X5MPWIC.mjs} +795 -159
  7. package/dist/chunk-6X5MPWIC.mjs.map +1 -0
  8. package/dist/{chunk-URMISMK2.mjs → chunk-73NMP3DI.mjs} +2 -2
  9. package/dist/{chunk-CUVWSISN.mjs → chunk-BJ2LVHWA.mjs} +22 -4
  10. package/dist/chunk-BJ2LVHWA.mjs.map +1 -0
  11. package/dist/{chunk-74B76SMO.mjs → chunk-HYNSUFUM.mjs} +2 -2
  12. package/dist/{chunk-6PAC74F2.mjs → chunk-JV3CSVW6.mjs} +2 -2
  13. package/dist/{chunk-NPCP4YZB.mjs → chunk-OYUVLDJF.mjs} +2 -2
  14. package/dist/{chunk-GEIBJJQ4.mjs → chunk-TBZGOJJX.mjs} +14 -2
  15. package/dist/chunk-TBZGOJJX.mjs.map +1 -0
  16. package/dist/{shared-ec6c7db5.d.ts → copilot-runtime-d427e991.d.ts} +68 -37
  17. package/dist/graphql/types/converted/index.d.ts +1 -1
  18. package/dist/graphql/types/converted/index.js +13 -0
  19. package/dist/graphql/types/converted/index.js.map +1 -1
  20. package/dist/graphql/types/converted/index.mjs +3 -1
  21. package/dist/{index-aa091e3c.d.ts → index-0476e4f7.d.ts} +24 -2
  22. package/dist/{groq-adapter-675b30c6.d.ts → index-079752b9.d.ts} +31 -1
  23. package/dist/index.d.ts +9 -9
  24. package/dist/index.js +1012 -246
  25. package/dist/index.js.map +1 -1
  26. package/dist/index.mjs +8 -8
  27. package/dist/{langserve-a54438c6.d.ts → langserve-d6073a3b.d.ts} +24 -11
  28. package/dist/lib/index.d.ts +8 -8
  29. package/dist/lib/index.js +1012 -246
  30. package/dist/lib/index.js.map +1 -1
  31. package/dist/lib/index.mjs +8 -8
  32. package/dist/lib/integrations/index.d.ts +26 -7
  33. package/dist/lib/integrations/index.js +446 -183
  34. package/dist/lib/integrations/index.js.map +1 -1
  35. package/dist/lib/integrations/index.mjs +6 -6
  36. package/dist/lib/integrations/nest/index.d.ts +5 -5
  37. package/dist/lib/integrations/nest/index.js +446 -183
  38. package/dist/lib/integrations/nest/index.js.map +1 -1
  39. package/dist/lib/integrations/nest/index.mjs +4 -4
  40. package/dist/lib/integrations/node-express/index.d.ts +5 -5
  41. package/dist/lib/integrations/node-express/index.js +446 -183
  42. package/dist/lib/integrations/node-express/index.js.map +1 -1
  43. package/dist/lib/integrations/node-express/index.mjs +4 -4
  44. package/dist/lib/integrations/node-http/index.d.ts +5 -5
  45. package/dist/lib/integrations/node-http/index.js +446 -183
  46. package/dist/lib/integrations/node-http/index.js.map +1 -1
  47. package/dist/lib/integrations/node-http/index.mjs +3 -3
  48. package/dist/service-adapters/index.d.ts +3 -3
  49. package/dist/service-adapters/index.js +19 -1
  50. package/dist/service-adapters/index.js.map +1 -1
  51. package/dist/service-adapters/index.mjs +3 -3
  52. package/dist/utils/index.d.ts +49 -1
  53. package/package.json +7 -5
  54. package/src/agents/langgraph/event-source.ts +222 -0
  55. package/src/agents/langgraph/events.ts +309 -0
  56. package/src/graphql/inputs/agent-session.input.ts +13 -0
  57. package/src/graphql/inputs/agent-state.input.ts +10 -0
  58. package/src/graphql/inputs/frontend.input.ts +3 -0
  59. package/src/graphql/inputs/generate-copilot-response.input.ts +11 -0
  60. package/src/graphql/inputs/message.input.ts +30 -0
  61. package/src/graphql/resolvers/copilot.resolver.ts +57 -12
  62. package/src/graphql/types/converted/index.ts +15 -0
  63. package/src/graphql/types/copilot-response.type.ts +29 -0
  64. package/src/graphql/types/enums.ts +1 -0
  65. package/src/lib/index.ts +1 -1
  66. package/src/lib/integrations/shared.ts +1 -1
  67. package/src/lib/runtime/copilot-runtime.ts +360 -0
  68. package/src/lib/runtime/remote-actions.ts +241 -0
  69. package/src/service-adapters/conversion.ts +16 -0
  70. package/src/service-adapters/events.ts +101 -19
  71. package/src/service-adapters/groq/groq-adapter.ts +13 -0
  72. package/src/service-adapters/openai/openai-adapter.ts +13 -0
  73. package/src/service-adapters/openai/openai-assistant-adapter.ts +14 -0
  74. package/dist/chunk-CUVWSISN.mjs.map +0 -1
  75. package/dist/chunk-GEIBJJQ4.mjs.map +0 -1
  76. package/dist/chunk-MKV3LEJ6.mjs.map +0 -1
  77. package/dist/chunk-RDEOIOQR.mjs +0 -155
  78. package/dist/chunk-RDEOIOQR.mjs.map +0 -1
  79. package/dist/failed-response-status-reasons-0ab19e06.d.ts +0 -49
  80. package/dist/pages-router-df82c666.d.ts +0 -21
  81. package/src/lib/copilot-runtime.ts +0 -225
  82. /package/dist/{chunk-URMISMK2.mjs.map → chunk-73NMP3DI.mjs.map} +0 -0
  83. /package/dist/{chunk-74B76SMO.mjs.map → chunk-HYNSUFUM.mjs.map} +0 -0
  84. /package/dist/{chunk-6PAC74F2.mjs.map → chunk-JV3CSVW6.mjs.map} +0 -0
  85. /package/dist/{chunk-NPCP4YZB.mjs.map → chunk-OYUVLDJF.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.1.2",
39
+ version: "1.1.3-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";
@@ -322,6 +379,7 @@ __name(_ts_metadata3, "_ts_metadata");
322
379
  var FrontendInput = class {
323
380
  toDeprecate_fullContext;
324
381
  actions;
382
+ url;
325
383
  };
326
384
  __name(FrontendInput, "FrontendInput");
327
385
  _ts_decorate3([
@@ -336,6 +394,12 @@ _ts_decorate3([
336
394
  ]),
337
395
  _ts_metadata3("design:type", Array)
338
396
  ], FrontendInput.prototype, "actions", void 0);
397
+ _ts_decorate3([
398
+ Field3(() => String, {
399
+ nullable: true
400
+ }),
401
+ _ts_metadata3("design:type", String)
402
+ ], FrontendInput.prototype, "url", void 0);
339
403
  FrontendInput = _ts_decorate3([
340
404
  InputType3()
341
405
  ], FrontendInput);
@@ -492,7 +556,8 @@ ForwardedParametersInput = _ts_decorate6([
492
556
  InputType6()
493
557
  ], ForwardedParametersInput);
494
558
 
495
- // 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";
496
561
  function _ts_decorate7(decorators, target, key, desc) {
497
562
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
498
563
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -509,18 +574,96 @@ function _ts_metadata7(k, v) {
509
574
  return Reflect.metadata(k, v);
510
575
  }
511
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");
512
655
  var GenerateCopilotResponseMetadataInput = class {
513
656
  requestType;
514
657
  };
515
658
  __name(GenerateCopilotResponseMetadataInput, "GenerateCopilotResponseMetadataInput");
516
- _ts_decorate7([
517
- Field7(() => CopilotRequestType, {
659
+ _ts_decorate9([
660
+ Field9(() => CopilotRequestType, {
518
661
  nullable: true
519
662
  }),
520
- _ts_metadata7("design:type", typeof CopilotRequestType === "undefined" ? Object : CopilotRequestType)
663
+ _ts_metadata9("design:type", typeof CopilotRequestType === "undefined" ? Object : CopilotRequestType)
521
664
  ], GenerateCopilotResponseMetadataInput.prototype, "requestType", void 0);
522
- GenerateCopilotResponseMetadataInput = _ts_decorate7([
523
- InputType7()
665
+ GenerateCopilotResponseMetadataInput = _ts_decorate9([
666
+ InputType9()
524
667
  ], GenerateCopilotResponseMetadataInput);
525
668
  var GenerateCopilotResponseInput = class {
526
669
  metadata;
@@ -530,58 +673,81 @@ var GenerateCopilotResponseInput = class {
530
673
  frontend;
531
674
  cloud;
532
675
  forwardedParameters;
676
+ agentSession;
677
+ agentState;
678
+ agentStates;
533
679
  };
534
680
  __name(GenerateCopilotResponseInput, "GenerateCopilotResponseInput");
535
- _ts_decorate7([
536
- Field7(() => GenerateCopilotResponseMetadataInput, {
681
+ _ts_decorate9([
682
+ Field9(() => GenerateCopilotResponseMetadataInput, {
537
683
  nullable: false
538
684
  }),
539
- _ts_metadata7("design:type", typeof GenerateCopilotResponseMetadataInput === "undefined" ? Object : GenerateCopilotResponseMetadataInput)
685
+ _ts_metadata9("design:type", typeof GenerateCopilotResponseMetadataInput === "undefined" ? Object : GenerateCopilotResponseMetadataInput)
540
686
  ], GenerateCopilotResponseInput.prototype, "metadata", void 0);
541
- _ts_decorate7([
542
- Field7(() => String, {
687
+ _ts_decorate9([
688
+ Field9(() => String, {
543
689
  nullable: true
544
690
  }),
545
- _ts_metadata7("design:type", String)
691
+ _ts_metadata9("design:type", String)
546
692
  ], GenerateCopilotResponseInput.prototype, "threadId", void 0);
547
- _ts_decorate7([
548
- Field7(() => String, {
693
+ _ts_decorate9([
694
+ Field9(() => String, {
549
695
  nullable: true
550
696
  }),
551
- _ts_metadata7("design:type", String)
697
+ _ts_metadata9("design:type", String)
552
698
  ], GenerateCopilotResponseInput.prototype, "runId", void 0);
553
- _ts_decorate7([
554
- Field7(() => [
699
+ _ts_decorate9([
700
+ Field9(() => [
555
701
  MessageInput
556
702
  ]),
557
- _ts_metadata7("design:type", Array)
703
+ _ts_metadata9("design:type", Array)
558
704
  ], GenerateCopilotResponseInput.prototype, "messages", void 0);
559
- _ts_decorate7([
560
- Field7(() => FrontendInput),
561
- _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)
562
708
  ], GenerateCopilotResponseInput.prototype, "frontend", void 0);
563
- _ts_decorate7([
564
- Field7(() => CloudInput, {
709
+ _ts_decorate9([
710
+ Field9(() => CloudInput, {
565
711
  nullable: true
566
712
  }),
567
- _ts_metadata7("design:type", typeof CloudInput === "undefined" ? Object : CloudInput)
713
+ _ts_metadata9("design:type", typeof CloudInput === "undefined" ? Object : CloudInput)
568
714
  ], GenerateCopilotResponseInput.prototype, "cloud", void 0);
569
- _ts_decorate7([
570
- Field7(() => ForwardedParametersInput, {
715
+ _ts_decorate9([
716
+ Field9(() => ForwardedParametersInput, {
571
717
  nullable: true
572
718
  }),
573
- _ts_metadata7("design:type", typeof ForwardedParametersInput === "undefined" ? Object : ForwardedParametersInput)
719
+ _ts_metadata9("design:type", typeof ForwardedParametersInput === "undefined" ? Object : ForwardedParametersInput)
574
720
  ], GenerateCopilotResponseInput.prototype, "forwardedParameters", void 0);
575
- GenerateCopilotResponseInput = _ts_decorate7([
576
- 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()
577
743
  ], GenerateCopilotResponseInput);
578
744
 
579
745
  // src/graphql/types/copilot-response.type.ts
580
- import { Field as Field9, InterfaceType, ObjectType as ObjectType2 } from "type-graphql";
746
+ import { Field as Field11, InterfaceType, ObjectType as ObjectType2 } from "type-graphql";
581
747
 
582
748
  // src/graphql/types/message-status.type.ts
583
- import { Field as Field8, ObjectType, createUnionType, registerEnumType as registerEnumType2 } from "type-graphql";
584
- 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) {
585
751
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
586
752
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
587
753
  r = Reflect.decorate(decorators, target, key, desc);
@@ -591,12 +757,12 @@ function _ts_decorate8(decorators, target, key, desc) {
591
757
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
592
758
  return c > 3 && r && Object.defineProperty(target, key, r), r;
593
759
  }
594
- __name(_ts_decorate8, "_ts_decorate");
595
- function _ts_metadata8(k, v) {
760
+ __name(_ts_decorate10, "_ts_decorate");
761
+ function _ts_metadata10(k, v) {
596
762
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
597
763
  return Reflect.metadata(k, v);
598
764
  }
599
- __name(_ts_metadata8, "_ts_metadata");
765
+ __name(_ts_metadata10, "_ts_metadata");
600
766
  var MessageStatusCode;
601
767
  (function(MessageStatusCode2) {
602
768
  MessageStatusCode2["Pending"] = "pending";
@@ -609,25 +775,25 @@ registerEnumType2(MessageStatusCode, {
609
775
  var BaseMessageStatus = /* @__PURE__ */ __name(class BaseMessageStatus2 {
610
776
  code;
611
777
  }, "BaseMessageStatus");
612
- _ts_decorate8([
613
- Field8(() => MessageStatusCode),
614
- _ts_metadata8("design:type", String)
778
+ _ts_decorate10([
779
+ Field10(() => MessageStatusCode),
780
+ _ts_metadata10("design:type", String)
615
781
  ], BaseMessageStatus.prototype, "code", void 0);
616
- BaseMessageStatus = _ts_decorate8([
782
+ BaseMessageStatus = _ts_decorate10([
617
783
  ObjectType()
618
784
  ], BaseMessageStatus);
619
785
  var PendingMessageStatus = class extends BaseMessageStatus {
620
786
  code = "pending";
621
787
  };
622
788
  __name(PendingMessageStatus, "PendingMessageStatus");
623
- PendingMessageStatus = _ts_decorate8([
789
+ PendingMessageStatus = _ts_decorate10([
624
790
  ObjectType()
625
791
  ], PendingMessageStatus);
626
792
  var SuccessMessageStatus = class extends BaseMessageStatus {
627
793
  code = "success";
628
794
  };
629
795
  __name(SuccessMessageStatus, "SuccessMessageStatus");
630
- SuccessMessageStatus = _ts_decorate8([
796
+ SuccessMessageStatus = _ts_decorate10([
631
797
  ObjectType()
632
798
  ], SuccessMessageStatus);
633
799
  var FailedMessageStatus = class extends BaseMessageStatus {
@@ -635,11 +801,11 @@ var FailedMessageStatus = class extends BaseMessageStatus {
635
801
  reason;
636
802
  };
637
803
  __name(FailedMessageStatus, "FailedMessageStatus");
638
- _ts_decorate8([
639
- Field8(() => String),
640
- _ts_metadata8("design:type", String)
804
+ _ts_decorate10([
805
+ Field10(() => String),
806
+ _ts_metadata10("design:type", String)
641
807
  ], FailedMessageStatus.prototype, "reason", void 0);
642
- FailedMessageStatus = _ts_decorate8([
808
+ FailedMessageStatus = _ts_decorate10([
643
809
  ObjectType()
644
810
  ], FailedMessageStatus);
645
811
  var MessageStatusUnion = createUnionType({
@@ -652,7 +818,7 @@ var MessageStatusUnion = createUnionType({
652
818
  });
653
819
 
654
820
  // src/graphql/types/copilot-response.type.ts
655
- function _ts_decorate9(decorators, target, key, desc) {
821
+ function _ts_decorate11(decorators, target, key, desc) {
656
822
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
657
823
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
658
824
  r = Reflect.decorate(decorators, target, key, desc);
@@ -662,30 +828,30 @@ function _ts_decorate9(decorators, target, key, desc) {
662
828
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
663
829
  return c > 3 && r && Object.defineProperty(target, key, r), r;
664
830
  }
665
- __name(_ts_decorate9, "_ts_decorate");
666
- function _ts_metadata9(k, v) {
831
+ __name(_ts_decorate11, "_ts_decorate");
832
+ function _ts_metadata11(k, v) {
667
833
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
668
834
  return Reflect.metadata(k, v);
669
835
  }
670
- __name(_ts_metadata9, "_ts_metadata");
836
+ __name(_ts_metadata11, "_ts_metadata");
671
837
  var BaseMessageOutput = /* @__PURE__ */ __name(class BaseMessageOutput2 {
672
838
  id;
673
839
  createdAt;
674
840
  status;
675
841
  }, "BaseMessageOutput");
676
- _ts_decorate9([
677
- Field9(() => String),
678
- _ts_metadata9("design:type", String)
842
+ _ts_decorate11([
843
+ Field11(() => String),
844
+ _ts_metadata11("design:type", String)
679
845
  ], BaseMessageOutput.prototype, "id", void 0);
680
- _ts_decorate9([
681
- Field9(() => Date),
682
- _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)
683
849
  ], BaseMessageOutput.prototype, "createdAt", void 0);
684
- _ts_decorate9([
685
- Field9(() => MessageStatusUnion),
686
- _ts_metadata9("design:type", Object)
850
+ _ts_decorate11([
851
+ Field11(() => MessageStatusUnion),
852
+ _ts_metadata11("design:type", Object)
687
853
  ], BaseMessageOutput.prototype, "status", void 0);
688
- BaseMessageOutput = _ts_decorate9([
854
+ BaseMessageOutput = _ts_decorate11([
689
855
  InterfaceType({
690
856
  resolveType(value) {
691
857
  if (value.hasOwnProperty("content")) {
@@ -694,6 +860,8 @@ BaseMessageOutput = _ts_decorate9([
694
860
  return ActionExecutionMessageOutput;
695
861
  } else if (value.hasOwnProperty("result")) {
696
862
  return ResultMessageOutput;
863
+ } else if (value.hasOwnProperty("state")) {
864
+ return AgentStateMessageOutput;
697
865
  }
698
866
  return void 0;
699
867
  }
@@ -704,17 +872,17 @@ var TextMessageOutput = class {
704
872
  content;
705
873
  };
706
874
  __name(TextMessageOutput, "TextMessageOutput");
707
- _ts_decorate9([
708
- Field9(() => MessageRole),
709
- _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)
710
878
  ], TextMessageOutput.prototype, "role", void 0);
711
- _ts_decorate9([
712
- Field9(() => [
879
+ _ts_decorate11([
880
+ Field11(() => [
713
881
  String
714
882
  ]),
715
- _ts_metadata9("design:type", Array)
883
+ _ts_metadata11("design:type", Array)
716
884
  ], TextMessageOutput.prototype, "content", void 0);
717
- TextMessageOutput = _ts_decorate9([
885
+ TextMessageOutput = _ts_decorate11([
718
886
  ObjectType2({
719
887
  implements: BaseMessageOutput
720
888
  })
@@ -725,21 +893,21 @@ var ActionExecutionMessageOutput = class {
725
893
  arguments;
726
894
  };
727
895
  __name(ActionExecutionMessageOutput, "ActionExecutionMessageOutput");
728
- _ts_decorate9([
729
- Field9(() => String),
730
- _ts_metadata9("design:type", String)
896
+ _ts_decorate11([
897
+ Field11(() => String),
898
+ _ts_metadata11("design:type", String)
731
899
  ], ActionExecutionMessageOutput.prototype, "name", void 0);
732
- _ts_decorate9([
733
- Field9(() => ActionExecutionScope),
734
- _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)
735
903
  ], ActionExecutionMessageOutput.prototype, "scope", void 0);
736
- _ts_decorate9([
737
- Field9(() => [
904
+ _ts_decorate11([
905
+ Field11(() => [
738
906
  String
739
907
  ]),
740
- _ts_metadata9("design:type", Array)
908
+ _ts_metadata11("design:type", Array)
741
909
  ], ActionExecutionMessageOutput.prototype, "arguments", void 0);
742
- ActionExecutionMessageOutput = _ts_decorate9([
910
+ ActionExecutionMessageOutput = _ts_decorate11([
743
911
  ObjectType2({
744
912
  implements: BaseMessageOutput
745
913
  })
@@ -750,23 +918,71 @@ var ResultMessageOutput = class {
750
918
  result;
751
919
  };
752
920
  __name(ResultMessageOutput, "ResultMessageOutput");
753
- _ts_decorate9([
754
- Field9(() => String),
755
- _ts_metadata9("design:type", String)
921
+ _ts_decorate11([
922
+ Field11(() => String),
923
+ _ts_metadata11("design:type", String)
756
924
  ], ResultMessageOutput.prototype, "actionExecutionId", void 0);
757
- _ts_decorate9([
758
- Field9(() => String),
759
- _ts_metadata9("design:type", String)
925
+ _ts_decorate11([
926
+ Field11(() => String),
927
+ _ts_metadata11("design:type", String)
760
928
  ], ResultMessageOutput.prototype, "actionName", void 0);
761
- _ts_decorate9([
762
- Field9(() => String),
763
- _ts_metadata9("design:type", String)
929
+ _ts_decorate11([
930
+ Field11(() => String),
931
+ _ts_metadata11("design:type", String)
764
932
  ], ResultMessageOutput.prototype, "result", void 0);
765
- ResultMessageOutput = _ts_decorate9([
933
+ ResultMessageOutput = _ts_decorate11([
766
934
  ObjectType2({
767
935
  implements: BaseMessageOutput
768
936
  })
769
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);
770
986
  var CopilotResponse = class {
771
987
  threadId;
772
988
  status;
@@ -774,27 +990,27 @@ var CopilotResponse = class {
774
990
  messages;
775
991
  };
776
992
  __name(CopilotResponse, "CopilotResponse");
777
- _ts_decorate9([
778
- Field9(() => String),
779
- _ts_metadata9("design:type", String)
993
+ _ts_decorate11([
994
+ Field11(() => String),
995
+ _ts_metadata11("design:type", String)
780
996
  ], CopilotResponse.prototype, "threadId", void 0);
781
- _ts_decorate9([
782
- Field9(() => ResponseStatusUnion),
783
- _ts_metadata9("design:type", Object)
997
+ _ts_decorate11([
998
+ Field11(() => ResponseStatusUnion),
999
+ _ts_metadata11("design:type", Object)
784
1000
  ], CopilotResponse.prototype, "status", void 0);
785
- _ts_decorate9([
786
- Field9({
1001
+ _ts_decorate11([
1002
+ Field11({
787
1003
  nullable: true
788
1004
  }),
789
- _ts_metadata9("design:type", String)
1005
+ _ts_metadata11("design:type", String)
790
1006
  ], CopilotResponse.prototype, "runId", void 0);
791
- _ts_decorate9([
792
- Field9(() => [
1007
+ _ts_decorate11([
1008
+ Field11(() => [
793
1009
  BaseMessageOutput
794
1010
  ]),
795
- _ts_metadata9("design:type", Array)
1011
+ _ts_metadata11("design:type", Array)
796
1012
  ], CopilotResponse.prototype, "messages", void 0);
797
- CopilotResponse = _ts_decorate9([
1013
+ CopilotResponse = _ts_decorate11([
798
1014
  ObjectType2()
799
1015
  ], CopilotResponse);
800
1016
 
@@ -802,7 +1018,366 @@ CopilotResponse = _ts_decorate9([
802
1018
  import { Repeater } from "graphql-yoga";
803
1019
 
804
1020
  // src/service-adapters/events.ts
805
- 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
806
1381
  var RuntimeEventTypes;
807
1382
  (function(RuntimeEventTypes2) {
808
1383
  RuntimeEventTypes2["TextMessageStart"] = "TextMessageStart";
@@ -812,8 +1387,9 @@ var RuntimeEventTypes;
812
1387
  RuntimeEventTypes2["ActionExecutionArgs"] = "ActionExecutionArgs";
813
1388
  RuntimeEventTypes2["ActionExecutionEnd"] = "ActionExecutionEnd";
814
1389
  RuntimeEventTypes2["ActionExecutionResult"] = "ActionExecutionResult";
1390
+ RuntimeEventTypes2["AgentStateMessage"] = "AgentStateMessage";
815
1391
  })(RuntimeEventTypes || (RuntimeEventTypes = {}));
816
- var RuntimeEventSubject = class extends ReplaySubject {
1392
+ var RuntimeEventSubject = class extends ReplaySubject2 {
817
1393
  constructor() {
818
1394
  super();
819
1395
  }
@@ -870,6 +1446,19 @@ var RuntimeEventSubject = class extends ReplaySubject {
870
1446
  result
871
1447
  });
872
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
+ }
873
1462
  };
874
1463
  __name(RuntimeEventSubject, "RuntimeEventSubject");
875
1464
  var RuntimeEventSource = class {
@@ -878,7 +1467,7 @@ var RuntimeEventSource = class {
878
1467
  async stream(callback) {
879
1468
  this.callback = callback;
880
1469
  }
881
- process({ serversideActions, guardrailsResult$ }) {
1470
+ processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
882
1471
  this.callback(this.eventStream$).catch((error) => {
883
1472
  console.error("Error in event source callback", error);
884
1473
  });
@@ -886,18 +1475,23 @@ var RuntimeEventSource = class {
886
1475
  // mark tools for server side execution
887
1476
  map((event) => {
888
1477
  if (event.type === "ActionExecutionStart") {
889
- 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
+ }
890
1481
  }
891
1482
  return event;
892
1483
  }),
893
1484
  // track state
894
- scan((acc, event) => {
1485
+ scan2((acc, event) => {
1486
+ acc = {
1487
+ ...acc
1488
+ };
895
1489
  if (event.type === "ActionExecutionStart") {
896
1490
  acc.callActionServerSide = event.scope === "server";
897
1491
  acc.args = "";
898
1492
  acc.actionExecutionId = event.actionExecutionId;
899
1493
  if (acc.callActionServerSide) {
900
- acc.action = serversideActions.find((action) => action.name === event.actionName);
1494
+ acc.action = serverSideActions.find((action) => action.name === event.actionName);
901
1495
  }
902
1496
  } else if (event.type === "ActionExecutionArgs") {
903
1497
  acc.args += event.args;
@@ -914,9 +1508,10 @@ var RuntimeEventSource = class {
914
1508
  concatMap((eventWithState) => {
915
1509
  if (eventWithState.event.type === "ActionExecutionEnd" && eventWithState.callActionServerSide) {
916
1510
  const toolCallEventStream$ = new RuntimeEventSubject();
917
- 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) => {
918
1512
  console.error(error);
919
1513
  });
1514
+ telemetry_client_default.capture("oss.runtime.server_action_executed", {});
920
1515
  return concat(of(eventWithState.event), toolCallEventStream$);
921
1516
  } else {
922
1517
  return of(eventWithState.event);
@@ -926,7 +1521,8 @@ var RuntimeEventSource = class {
926
1521
  }
927
1522
  };
928
1523
  __name(RuntimeEventSource, "RuntimeEventSource");
929
- async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId) {
1524
+ async function executeAction(eventStream$, guardrailsResult$, action, actionArguments, actionExecutionId, actionInputsWithoutAgents) {
1525
+ var _a;
930
1526
  if (guardrailsResult$) {
931
1527
  const { status } = await firstValueFrom(guardrailsResult$);
932
1528
  if (status === "denied") {
@@ -938,15 +1534,28 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
938
1534
  if (actionArguments) {
939
1535
  args = JSON.parse(actionArguments);
940
1536
  }
941
- const result = await action.handler(args);
942
- await streamLangChainResponse({
943
- result,
944
- eventStream$,
945
- actionExecution: {
1537
+ if (isLangGraphAgentAction(action)) {
1538
+ eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
1539
+ const stream = await action.langGraphAgentHandler({
946
1540
  name: action.name,
947
- id: actionExecutionId
948
- }
949
- });
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
+ }
950
1559
  }
951
1560
  __name(executeAction, "executeAction");
952
1561
 
@@ -954,19 +1563,8 @@ __name(executeAction, "executeAction");
954
1563
  import { GraphQLJSONObject } from "graphql-scalars";
955
1564
  import { plainToInstance } from "class-transformer";
956
1565
  import { GraphQLError } from "graphql";
957
-
958
- // src/lib/telemetry-client.ts
959
- import { TelemetryClient } from "@copilotkit/shared";
960
- var packageJson = require_package();
961
- var telemetryClient = new TelemetryClient({
962
- packageName: packageJson.name,
963
- packageVersion: packageJson.version
964
- });
965
- var telemetry_client_default = telemetryClient;
966
-
967
- // src/graphql/resolvers/copilot.resolver.ts
968
1566
  import { randomId } from "@copilotkit/shared";
969
- function _ts_decorate10(decorators, target, key, desc) {
1567
+ function _ts_decorate12(decorators, target, key, desc) {
970
1568
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
971
1569
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
972
1570
  r = Reflect.decorate(decorators, target, key, desc);
@@ -976,12 +1574,12 @@ function _ts_decorate10(decorators, target, key, desc) {
976
1574
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
977
1575
  return c > 3 && r && Object.defineProperty(target, key, r), r;
978
1576
  }
979
- __name(_ts_decorate10, "_ts_decorate");
980
- function _ts_metadata10(k, v) {
1577
+ __name(_ts_decorate12, "_ts_decorate");
1578
+ function _ts_metadata12(k, v) {
981
1579
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function")
982
1580
  return Reflect.metadata(k, v);
983
1581
  }
984
- __name(_ts_metadata10, "_ts_metadata");
1582
+ __name(_ts_metadata12, "_ts_metadata");
985
1583
  function _ts_param(paramIndex, decorator) {
986
1584
  return function(target, key) {
987
1585
  decorator(target, key, paramIndex);
@@ -990,7 +1588,6 @@ function _ts_param(paramIndex, decorator) {
990
1588
  __name(_ts_param, "_ts_param");
991
1589
  var invokeGuardrails = /* @__PURE__ */ __name(async ({ baseUrl, copilotCloudPublicApiKey, data, onResult, onError }) => {
992
1590
  var _a;
993
- console.log("invokeGuardrails.baseUrl", baseUrl);
994
1591
  if (data.messages.length && ((_a = data.messages[data.messages.length - 1].textMessage) == null ? void 0 : _a.role) === MessageRole.user) {
995
1592
  const messages = data.messages.filter((m) => m.textMessage !== void 0 && (m.textMessage.role === MessageRole.user || m.textMessage.role === MessageRole.assistant)).map((m) => ({
996
1593
  role: m.textMessage.role,
@@ -1036,8 +1633,6 @@ var CopilotResolver = class {
1036
1633
  logger2.debug({
1037
1634
  data
1038
1635
  }, "Generating Copilot response");
1039
- const copilotRuntime = ctx._copilotkit.runtime;
1040
- const serviceAdapter = ctx._copilotkit.serviceAdapter;
1041
1636
  if (properties) {
1042
1637
  logger2.debug("Properties provided, merging with context properties");
1043
1638
  ctx.properties = {
@@ -1045,6 +1640,8 @@ var CopilotResolver = class {
1045
1640
  ...properties
1046
1641
  };
1047
1642
  }
1643
+ const copilotRuntime = ctx._copilotkit.runtime;
1644
+ const serviceAdapter = ctx._copilotkit.serviceAdapter;
1048
1645
  let copilotCloudPublicApiKey = null;
1049
1646
  let copilotCloudBaseUrl;
1050
1647
  if (data.cloud) {
@@ -1072,9 +1669,9 @@ var CopilotResolver = class {
1072
1669
  });
1073
1670
  }
1074
1671
  logger2.debug("Setting up subjects");
1075
- const responseStatus$ = new ReplaySubject2();
1076
- const interruptStreaming$ = new ReplaySubject2();
1077
- const guardrailsResult$ = new ReplaySubject2();
1672
+ const responseStatus$ = new ReplaySubject3();
1673
+ const interruptStreaming$ = new ReplaySubject3();
1674
+ const guardrailsResult$ = new ReplaySubject3();
1078
1675
  let outputMessages = [];
1079
1676
  let resolveOutputMessagesPromise;
1080
1677
  let rejectOutputMessagesPromise;
@@ -1083,16 +1680,19 @@ var CopilotResolver = class {
1083
1680
  rejectOutputMessagesPromise = reject;
1084
1681
  });
1085
1682
  logger2.debug("Processing");
1086
- const { eventSource, threadId = randomId(), runId, actions } = await copilotRuntime.process({
1683
+ const { eventSource, threadId = randomId(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
1087
1684
  serviceAdapter,
1088
1685
  messages: data.messages,
1089
1686
  actions: data.frontend.actions,
1090
1687
  threadId: data.threadId,
1091
1688
  runId: data.runId,
1092
1689
  publicApiKey: void 0,
1093
- properties: ctx.properties || {},
1094
1690
  outputMessagesPromise,
1095
- forwardedParameters: data.forwardedParameters
1691
+ graphqlContext: ctx,
1692
+ forwardedParameters: data.forwardedParameters,
1693
+ agentSession: data.agentSession,
1694
+ agentStates: data.agentStates,
1695
+ url: data.frontend.url
1096
1696
  });
1097
1697
  logger2.debug("Event source created, creating response");
1098
1698
  const response = {
@@ -1149,9 +1749,13 @@ var CopilotResolver = class {
1149
1749
  });
1150
1750
  }
1151
1751
  let eventStreamSubscription;
1152
- const eventStream = eventSource.process({
1153
- serversideActions: actions,
1154
- 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
+ )
1155
1759
  }).pipe(
1156
1760
  // shareReplay() ensures that later subscribers will see the whole stream instead of
1157
1761
  // just the events that were emitted after the subscriber was added.
@@ -1299,6 +1903,36 @@ var CopilotResolver = class {
1299
1903
  result: event.result
1300
1904
  }));
1301
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;
1302
1936
  }
1303
1937
  },
1304
1938
  error: (err) => {
@@ -1331,28 +1965,28 @@ var CopilotResolver = class {
1331
1965
  }
1332
1966
  };
1333
1967
  __name(CopilotResolver, "CopilotResolver");
1334
- _ts_decorate10([
1968
+ _ts_decorate12([
1335
1969
  Query(() => String),
1336
- _ts_metadata10("design:type", Function),
1337
- _ts_metadata10("design:paramtypes", []),
1338
- _ts_metadata10("design:returntype", Promise)
1970
+ _ts_metadata12("design:type", Function),
1971
+ _ts_metadata12("design:paramtypes", []),
1972
+ _ts_metadata12("design:returntype", Promise)
1339
1973
  ], CopilotResolver.prototype, "hello", null);
1340
- _ts_decorate10([
1974
+ _ts_decorate12([
1341
1975
  Mutation(() => CopilotResponse),
1342
1976
  _ts_param(0, Ctx()),
1343
1977
  _ts_param(1, Arg("data")),
1344
1978
  _ts_param(2, Arg("properties", () => GraphQLJSONObject, {
1345
1979
  nullable: true
1346
1980
  })),
1347
- _ts_metadata10("design:type", Function),
1348
- _ts_metadata10("design:paramtypes", [
1981
+ _ts_metadata12("design:type", Function),
1982
+ _ts_metadata12("design:paramtypes", [
1349
1983
  typeof GraphQLContext === "undefined" ? Object : GraphQLContext,
1350
1984
  typeof GenerateCopilotResponseInput === "undefined" ? Object : GenerateCopilotResponseInput,
1351
1985
  typeof CopilotRequestContextProperties === "undefined" ? Object : CopilotRequestContextProperties
1352
1986
  ]),
1353
- _ts_metadata10("design:returntype", Promise)
1987
+ _ts_metadata12("design:returntype", Promise)
1354
1988
  ], CopilotResolver.prototype, "generateCopilotResponse", null);
1355
- CopilotResolver = _ts_decorate10([
1989
+ CopilotResolver = _ts_decorate12([
1356
1990
  Resolver(() => CopilotResponse)
1357
1991
  ], CopilotResolver);
1358
1992
 
@@ -1486,11 +2120,13 @@ function copilotRuntimeNodeHttpEndpoint(options) {
1486
2120
  __name(copilotRuntimeNodeHttpEndpoint, "copilotRuntimeNodeHttpEndpoint");
1487
2121
 
1488
2122
  export {
1489
- RuntimeEventSource,
1490
2123
  telemetry_client_default,
2124
+ isLangGraphAgentAction,
2125
+ setupRemoteActions,
2126
+ RuntimeEventSource,
1491
2127
  createContext,
1492
2128
  buildSchema,
1493
2129
  getCommonConfig,
1494
2130
  copilotRuntimeNodeHttpEndpoint
1495
2131
  };
1496
- //# sourceMappingURL=chunk-MKV3LEJ6.mjs.map
2132
+ //# sourceMappingURL=chunk-6X5MPWIC.mjs.map