@copilotkit/runtime 1.8.15-next.1 → 1.9.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 (38) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/dist/{chunk-76QVO5FK.mjs → chunk-FK4NZL4G.mjs} +2 -2
  3. package/dist/{chunk-XRKKSNLV.mjs → chunk-GI32PQX6.mjs} +2 -2
  4. package/dist/chunk-M3JAEGRU.mjs +141 -0
  5. package/dist/chunk-M3JAEGRU.mjs.map +1 -0
  6. package/dist/{chunk-2DM4G7DN.mjs → chunk-U74GJORZ.mjs} +2 -2
  7. package/dist/{chunk-WPALAYGE.mjs → chunk-YCN5NOAP.mjs} +4 -2
  8. package/dist/chunk-YCN5NOAP.mjs.map +1 -0
  9. package/dist/index.d.ts +3 -0
  10. package/dist/index.js +140 -6
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +10 -5
  13. package/dist/index.mjs.map +1 -1
  14. package/dist/lib/index.d.ts +154 -2
  15. package/dist/lib/index.js +140 -6
  16. package/dist/lib/index.js.map +1 -1
  17. package/dist/lib/index.mjs +10 -5
  18. package/dist/lib/integrations/index.js +2 -1
  19. package/dist/lib/integrations/index.js.map +1 -1
  20. package/dist/lib/integrations/index.mjs +4 -4
  21. package/dist/lib/integrations/nest/index.js +2 -1
  22. package/dist/lib/integrations/nest/index.js.map +1 -1
  23. package/dist/lib/integrations/nest/index.mjs +2 -2
  24. package/dist/lib/integrations/node-express/index.js +2 -1
  25. package/dist/lib/integrations/node-express/index.js.map +1 -1
  26. package/dist/lib/integrations/node-express/index.mjs +2 -2
  27. package/dist/lib/integrations/node-http/index.js +2 -1
  28. package/dist/lib/integrations/node-http/index.js.map +1 -1
  29. package/dist/lib/integrations/node-http/index.mjs +1 -1
  30. package/package.json +5 -4
  31. package/src/lib/index.ts +1 -0
  32. package/src/lib/runtime/langgraph/langgraph-agent.ts +190 -0
  33. package/dist/chunk-Q6JA6YY3.mjs +0 -1
  34. package/dist/chunk-Q6JA6YY3.mjs.map +0 -1
  35. package/dist/chunk-WPALAYGE.mjs.map +0 -1
  36. /package/dist/{chunk-76QVO5FK.mjs.map → chunk-FK4NZL4G.mjs.map} +0 -0
  37. /package/dist/{chunk-XRKKSNLV.mjs.map → chunk-GI32PQX6.mjs.map} +0 -0
  38. /package/dist/{chunk-2DM4G7DN.mjs.map → chunk-U74GJORZ.mjs.map} +0 -0
package/dist/index.mjs CHANGED
@@ -1,15 +1,18 @@
1
- import "./chunk-Q6JA6YY3.mjs";
1
+ import {
2
+ CustomEventNames,
3
+ LangGraphAgent
4
+ } from "./chunk-M3JAEGRU.mjs";
2
5
  import {
3
6
  config,
4
7
  copilotRuntimeNextJSAppRouterEndpoint,
5
8
  copilotRuntimeNextJSPagesRouterEndpoint
6
- } from "./chunk-2DM4G7DN.mjs";
9
+ } from "./chunk-U74GJORZ.mjs";
7
10
  import {
8
11
  copilotRuntimeNestEndpoint
9
- } from "./chunk-76QVO5FK.mjs";
12
+ } from "./chunk-FK4NZL4G.mjs";
10
13
  import {
11
14
  copilotRuntimeNodeExpressEndpoint
12
- } from "./chunk-XRKKSNLV.mjs";
15
+ } from "./chunk-GI32PQX6.mjs";
13
16
  import {
14
17
  CopilotRuntime,
15
18
  addCustomHeaderPlugin,
@@ -25,7 +28,7 @@ import {
25
28
  getCommonConfig,
26
29
  langGraphPlatformEndpoint,
27
30
  resolveEndpointType
28
- } from "./chunk-WPALAYGE.mjs";
31
+ } from "./chunk-YCN5NOAP.mjs";
29
32
  import {
30
33
  AnthropicAdapter,
31
34
  BedrockAdapter,
@@ -55,6 +58,7 @@ export {
55
58
  AnthropicAdapter,
56
59
  BedrockAdapter,
57
60
  CopilotRuntime,
61
+ CustomEventNames,
58
62
  EmptyAdapter,
59
63
  ExperimentalEmptyAdapter,
60
64
  ExperimentalOllamaAdapter,
@@ -62,6 +66,7 @@ export {
62
66
  GroqAdapter,
63
67
  GuardrailsValidationFailureResponse,
64
68
  LangChainAdapter,
69
+ LangGraphAgent,
65
70
  MessageStreamInterruptedResponse,
66
71
  OpenAIAdapter,
67
72
  OpenAIAssistantAdapter,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import \"reflect-metadata\";\nexport * from \"./lib\";\nexport * from \"./utils\";\nexport * from \"./service-adapters\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import \"reflect-metadata\";\nexport * from \"./lib\";\nexport * from \"./utils\";\nexport * from \"./service-adapters\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO;","names":[]}
@@ -4,11 +4,14 @@ export { CopilotRuntimeServerInstance, config, copilotRuntimeNextJSAppRouterEndp
4
4
  export { copilotRuntimeNodeHttpEndpoint } from './integrations/node-http/index.js';
5
5
  export { copilotRuntimeNodeExpressEndpoint } from './integrations/node-express/index.js';
6
6
  export { copilotRuntimeNestEndpoint } from './integrations/nest/index.js';
7
+ import * as rxjs from 'rxjs';
8
+ import { TextMessageStartEvent, TextMessageContentEvent, TextMessageEndEvent, ToolCallStartEvent, ToolCallArgsEvent, ToolCallEndEvent, RunAgentInput, EventType } from '@ag-ui/client';
9
+ import { LangGraphAgent as LangGraphAgent$1, LangGraphAgentConfig, ProcessedEvents } from '@ag-ui/langgraph';
10
+ import { Message } from '@langchain/langgraph-sdk/dist/types.messages';
7
11
  import 'openai';
8
12
  import '../langserve-4a5c9217.js';
9
13
  import '../index-d4614f9b.js';
10
14
  import '../graphql/types/base/index.js';
11
- import 'rxjs';
12
15
  import '@copilotkit/shared';
13
16
  import '@langchain/core/messages';
14
17
  import '@langchain/core/tools';
@@ -18,4 +21,153 @@ import 'graphql';
18
21
  import 'pino';
19
22
  import 'graphql-yoga';
20
23
  import './cloud/index.js';
21
- import '@ag-ui/client';
24
+
25
+ interface PredictStateTool {
26
+ tool: string;
27
+ state_key: string;
28
+ tool_argument: string;
29
+ }
30
+ type State = Record<string, any>;
31
+ type TextMessageEvents = TextMessageStartEvent | TextMessageContentEvent | TextMessageEndEvent;
32
+ type ToolCallEvents = ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent;
33
+ declare enum CustomEventNames {
34
+ CopilotKitManuallyEmitMessage = "copilotkit_manually_emit_message",
35
+ CopilotKitManuallyEmitToolCall = "copilotkit_manually_emit_tool_call",
36
+ CopilotKitManuallyEmitIntermediateState = "copilotkit_manually_emit_intermediate_state",
37
+ CopilotKitExit = "copilotkit_exit"
38
+ }
39
+ declare class LangGraphAgent extends LangGraphAgent$1 {
40
+ constructor(config: LangGraphAgentConfig);
41
+ dispatchEvent(event: ProcessedEvents): boolean;
42
+ run(input: RunAgentInput): rxjs.Observable<{
43
+ type: EventType.TEXT_MESSAGE_START;
44
+ role: "assistant";
45
+ messageId: string;
46
+ timestamp?: number | undefined;
47
+ rawEvent?: any;
48
+ } | {
49
+ type: EventType.TEXT_MESSAGE_CONTENT;
50
+ messageId: string;
51
+ delta: string;
52
+ timestamp?: number | undefined;
53
+ rawEvent?: any;
54
+ } | {
55
+ type: EventType.TEXT_MESSAGE_END;
56
+ messageId: string;
57
+ timestamp?: number | undefined;
58
+ rawEvent?: any;
59
+ } | {
60
+ type: EventType.TOOL_CALL_START;
61
+ toolCallId: string;
62
+ toolCallName: string;
63
+ timestamp?: number | undefined;
64
+ rawEvent?: any;
65
+ parentMessageId?: string | undefined;
66
+ } | {
67
+ type: EventType.TOOL_CALL_ARGS;
68
+ toolCallId: string;
69
+ delta: string;
70
+ timestamp?: number | undefined;
71
+ rawEvent?: any;
72
+ } | {
73
+ type: EventType.TOOL_CALL_END;
74
+ toolCallId: string;
75
+ timestamp?: number | undefined;
76
+ rawEvent?: any;
77
+ } | {
78
+ type: EventType.STATE_SNAPSHOT;
79
+ timestamp?: number | undefined;
80
+ rawEvent?: any;
81
+ snapshot?: any;
82
+ } | {
83
+ type: EventType.STATE_DELTA;
84
+ delta: any[];
85
+ timestamp?: number | undefined;
86
+ rawEvent?: any;
87
+ } | {
88
+ type: EventType.MESSAGES_SNAPSHOT;
89
+ messages: ({
90
+ id: string;
91
+ role: "developer";
92
+ content: string;
93
+ name?: string | undefined;
94
+ } | {
95
+ id: string;
96
+ role: "system";
97
+ content: string;
98
+ name?: string | undefined;
99
+ } | {
100
+ id: string;
101
+ role: "assistant";
102
+ name?: string | undefined;
103
+ content?: string | undefined;
104
+ toolCalls?: {
105
+ function: {
106
+ name: string;
107
+ arguments: string;
108
+ };
109
+ type: "function";
110
+ id: string;
111
+ }[] | undefined;
112
+ } | {
113
+ id: string;
114
+ role: "user";
115
+ content: string;
116
+ name?: string | undefined;
117
+ } | {
118
+ id: string;
119
+ role: "tool";
120
+ content: string;
121
+ toolCallId: string;
122
+ })[];
123
+ timestamp?: number | undefined;
124
+ rawEvent?: any;
125
+ } | {
126
+ type: EventType.RAW;
127
+ timestamp?: number | undefined;
128
+ rawEvent?: any;
129
+ event?: any;
130
+ source?: string | undefined;
131
+ } | {
132
+ name: string;
133
+ type: EventType.CUSTOM;
134
+ value?: any;
135
+ timestamp?: number | undefined;
136
+ rawEvent?: any;
137
+ } | {
138
+ type: EventType.RUN_STARTED;
139
+ threadId: string;
140
+ runId: string;
141
+ timestamp?: number | undefined;
142
+ rawEvent?: any;
143
+ } | {
144
+ type: EventType.RUN_FINISHED;
145
+ threadId: string;
146
+ runId: string;
147
+ timestamp?: number | undefined;
148
+ rawEvent?: any;
149
+ } | {
150
+ message: string;
151
+ type: EventType.RUN_ERROR;
152
+ code?: string | undefined;
153
+ timestamp?: number | undefined;
154
+ rawEvent?: any;
155
+ } | {
156
+ type: EventType.STEP_STARTED;
157
+ stepName: string;
158
+ timestamp?: number | undefined;
159
+ rawEvent?: any;
160
+ } | {
161
+ type: EventType.STEP_FINISHED;
162
+ stepName: string;
163
+ timestamp?: number | undefined;
164
+ rawEvent?: any;
165
+ } | {
166
+ type: EventType;
167
+ name: string;
168
+ value: any;
169
+ }>;
170
+ langGraphDefaultMergeState(state: State, messages: Message[], tools: any): State;
171
+ }
172
+
173
+ export { CustomEventNames, LangGraphAgent, PredictStateTool, State, TextMessageEvents, ToolCallEvents };
package/dist/lib/index.js CHANGED
@@ -44,7 +44,7 @@ var require_package = __commonJS({
44
44
  publishConfig: {
45
45
  access: "public"
46
46
  },
47
- version: "1.8.15-next.1",
47
+ version: "1.9.0",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -85,6 +85,7 @@ var require_package = __commonJS({
85
85
  "@ag-ui/client": "0.0.28",
86
86
  "@ag-ui/core": "0.0.28",
87
87
  "@ag-ui/encoder": "0.0.28",
88
+ "@ag-ui/langgraph": "0.0.3",
88
89
  "@ag-ui/proto": "0.0.28",
89
90
  "@anthropic-ai/sdk": "^0.27.3",
90
91
  "@copilotkit/shared": "workspace:*",
@@ -138,9 +139,11 @@ var require_package = __commonJS({
138
139
  var lib_exports = {};
139
140
  __export(lib_exports, {
140
141
  CopilotRuntime: () => CopilotRuntime,
142
+ CustomEventNames: () => CustomEventNames2,
141
143
  GoogleGenerativeAIAdapter: () => GoogleGenerativeAIAdapter,
142
144
  GroqAdapter: () => GroqAdapter,
143
145
  LangChainAdapter: () => LangChainAdapter,
146
+ LangGraphAgent: () => LangGraphAgent,
144
147
  OpenAIAdapter: () => OpenAIAdapter,
145
148
  OpenAIAssistantAdapter: () => OpenAIAssistantAdapter,
146
149
  UnifyAdapter: () => UnifyAdapter,
@@ -2770,11 +2773,11 @@ var MetaEventNames;
2770
2773
  MetaEventNames2["CopilotKitLangGraphInterruptEvent"] = "CopilotKitLangGraphInterruptEvent";
2771
2774
  })(MetaEventNames || (MetaEventNames = {}));
2772
2775
  var CustomEventNames;
2773
- (function(CustomEventNames2) {
2774
- CustomEventNames2["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
2775
- CustomEventNames2["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
2776
- CustomEventNames2["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
2777
- CustomEventNames2["CopilotKitExit"] = "copilotkit_exit";
2776
+ (function(CustomEventNames3) {
2777
+ CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
2778
+ CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
2779
+ CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
2780
+ CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
2778
2781
  })(CustomEventNames || (CustomEventNames = {}));
2779
2782
 
2780
2783
  // src/agents/langgraph/event-source.ts
@@ -6666,12 +6669,143 @@ function copilotRuntimeNestEndpoint(options) {
6666
6669
  return copilotRuntimeNodeHttpEndpoint(options);
6667
6670
  }
6668
6671
  __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
6672
+
6673
+ // src/lib/runtime/langgraph/langgraph-agent.ts
6674
+ var import_client = require("@ag-ui/client");
6675
+ var import_rxjs5 = require("rxjs");
6676
+ var import_langgraph = require("@ag-ui/langgraph");
6677
+ var CustomEventNames2;
6678
+ (function(CustomEventNames3) {
6679
+ CustomEventNames3["CopilotKitManuallyEmitMessage"] = "copilotkit_manually_emit_message";
6680
+ CustomEventNames3["CopilotKitManuallyEmitToolCall"] = "copilotkit_manually_emit_tool_call";
6681
+ CustomEventNames3["CopilotKitManuallyEmitIntermediateState"] = "copilotkit_manually_emit_intermediate_state";
6682
+ CustomEventNames3["CopilotKitExit"] = "copilotkit_exit";
6683
+ })(CustomEventNames2 || (CustomEventNames2 = {}));
6684
+ var LangGraphAgent = class extends import_langgraph.LangGraphAgent {
6685
+ constructor(config2) {
6686
+ super(config2);
6687
+ }
6688
+ dispatchEvent(event) {
6689
+ if (event.type === import_client.EventType.CUSTOM) {
6690
+ const customEvent = event;
6691
+ if (customEvent.name === "copilotkit_manually_emit_message") {
6692
+ this.subscriber.next({
6693
+ type: import_client.EventType.TEXT_MESSAGE_START,
6694
+ role: "assistant",
6695
+ messageId: customEvent.value.message_id,
6696
+ rawEvent: event
6697
+ });
6698
+ this.subscriber.next({
6699
+ type: import_client.EventType.TEXT_MESSAGE_CONTENT,
6700
+ messageId: customEvent.value.message_id,
6701
+ delta: customEvent.value.message,
6702
+ rawEvent: event
6703
+ });
6704
+ this.subscriber.next({
6705
+ type: import_client.EventType.TEXT_MESSAGE_END,
6706
+ messageId: customEvent.value.message_id,
6707
+ rawEvent: event
6708
+ });
6709
+ return true;
6710
+ }
6711
+ if (customEvent.name === "copilotkit_manually_emit_tool_call") {
6712
+ this.subscriber.next({
6713
+ type: import_client.EventType.TOOL_CALL_START,
6714
+ toolCallId: customEvent.value.id,
6715
+ toolCallName: customEvent.value.name,
6716
+ parentMessageId: customEvent.value.id,
6717
+ rawEvent: event
6718
+ });
6719
+ this.subscriber.next({
6720
+ type: import_client.EventType.TOOL_CALL_ARGS,
6721
+ toolCallId: customEvent.value.id,
6722
+ delta: customEvent.value.args,
6723
+ rawEvent: event
6724
+ });
6725
+ this.subscriber.next({
6726
+ type: import_client.EventType.TOOL_CALL_END,
6727
+ toolCallId: customEvent.value.id,
6728
+ rawEvent: event
6729
+ });
6730
+ return true;
6731
+ }
6732
+ if (customEvent.name === "copilotkit_manually_emit_intermediate_state") {
6733
+ this.activeRun.manuallyEmittedState = customEvent.value;
6734
+ this.dispatchEvent({
6735
+ type: import_client.EventType.STATE_SNAPSHOT,
6736
+ snapshot: this.getStateSnapshot(this.activeRun.manuallyEmittedState),
6737
+ rawEvent: event
6738
+ });
6739
+ return true;
6740
+ }
6741
+ if (customEvent.name === "copilotkit_exit") {
6742
+ this.subscriber.next({
6743
+ type: import_client.EventType.CUSTOM,
6744
+ name: "Exit",
6745
+ value: true
6746
+ });
6747
+ return true;
6748
+ }
6749
+ }
6750
+ const rawEvent = event.rawEvent;
6751
+ if (!rawEvent) {
6752
+ this.subscriber.next(event);
6753
+ return true;
6754
+ }
6755
+ const isMessageEvent = event.type === import_client.EventType.TEXT_MESSAGE_START || event.type === import_client.EventType.TEXT_MESSAGE_CONTENT || event.type === import_client.EventType.TEXT_MESSAGE_END;
6756
+ const isToolEvent = event.type === import_client.EventType.TOOL_CALL_START || event.type === import_client.EventType.TOOL_CALL_ARGS || event.type === import_client.EventType.TOOL_CALL_END;
6757
+ if ("copilotkit:emit-tool-calls" in (rawEvent.metadata || {})) {
6758
+ if (rawEvent.metadata["copilotkit:emit-tool-calls"] === false && isToolEvent) {
6759
+ return false;
6760
+ }
6761
+ }
6762
+ if ("copilotkit:emit-messages" in (rawEvent.metadata || {})) {
6763
+ if (rawEvent.metadata["copilotkit:emit-messages"] === false && isMessageEvent) {
6764
+ return false;
6765
+ }
6766
+ }
6767
+ this.subscriber.next(event);
6768
+ return true;
6769
+ }
6770
+ // @ts-ignore
6771
+ run(input) {
6772
+ return super.run(input).pipe((0, import_rxjs5.map)((processedEvent) => {
6773
+ var _a, _b, _c, _d, _e;
6774
+ if (processedEvent.type === import_client.EventType.RAW) {
6775
+ const event = processedEvent.event ?? processedEvent.rawEvent;
6776
+ const eventType = event.event;
6777
+ const toolCallData = (_c = (_b = (_a = event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.tool_call_chunks) == null ? void 0 : _c[0];
6778
+ const toolCallUsedToPredictState = (_e = (_d = event.metadata) == null ? void 0 : _d["copilotkit:emit-intermediate-state"]) == null ? void 0 : _e.some((predictStateTool) => predictStateTool.tool === (toolCallData == null ? void 0 : toolCallData.name));
6779
+ if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {
6780
+ return {
6781
+ type: import_client.EventType.CUSTOM,
6782
+ name: "PredictState",
6783
+ value: event.metadata["copilotkit:emit-intermediate-state"]
6784
+ };
6785
+ }
6786
+ }
6787
+ return processedEvent;
6788
+ }));
6789
+ }
6790
+ langGraphDefaultMergeState(state, messages, tools) {
6791
+ const { tools: returnedTools, ...rest } = super.langGraphDefaultMergeState(state, messages, tools);
6792
+ return {
6793
+ ...rest,
6794
+ copilotkit: {
6795
+ actions: returnedTools
6796
+ }
6797
+ };
6798
+ }
6799
+ };
6800
+ __name(LangGraphAgent, "LangGraphAgent");
6669
6801
  // Annotate the CommonJS export names for ESM import in node:
6670
6802
  0 && (module.exports = {
6671
6803
  CopilotRuntime,
6804
+ CustomEventNames,
6672
6805
  GoogleGenerativeAIAdapter,
6673
6806
  GroqAdapter,
6674
6807
  LangChainAdapter,
6808
+ LangGraphAgent,
6675
6809
  OpenAIAdapter,
6676
6810
  OpenAIAssistantAdapter,
6677
6811
  UnifyAdapter,