@copilotkit/runtime 1.8.15-next.1 → 1.9.0-next.2

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 +11 -0
  2. package/dist/{chunk-WPALAYGE.mjs → chunk-6A27R7IP.mjs} +4 -2
  3. package/dist/chunk-6A27R7IP.mjs.map +1 -0
  4. package/dist/{chunk-2DM4G7DN.mjs → chunk-G4NOAQUA.mjs} +2 -2
  5. package/dist/{chunk-XRKKSNLV.mjs → chunk-S5TNKSNR.mjs} +2 -2
  6. package/dist/chunk-XB3TW5NJ.mjs +141 -0
  7. package/dist/chunk-XB3TW5NJ.mjs.map +1 -0
  8. package/dist/{chunk-76QVO5FK.mjs → chunk-XPTVSVNM.mjs} +2 -2
  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 +3 -2
  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-2DM4G7DN.mjs.map → chunk-G4NOAQUA.mjs.map} +0 -0
  37. /package/dist/{chunk-XRKKSNLV.mjs.map → chunk-S5TNKSNR.mjs.map} +0 -0
  38. /package/dist/{chunk-76QVO5FK.mjs.map → chunk-XPTVSVNM.mjs.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint
3
- } from "../../../chunk-WPALAYGE.mjs";
3
+ } from "../../../chunk-6A27R7IP.mjs";
4
4
  import "../../../chunk-IIXJVVTV.mjs";
5
5
  import "../../../chunk-5BIEM2UU.mjs";
6
6
  import "../../../chunk-SHBDMA63.mjs";
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.8.15-next.1",
12
+ "version": "1.9.0-next.2",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -40,6 +40,7 @@
40
40
  "@ag-ui/client": "0.0.28",
41
41
  "@ag-ui/core": "0.0.28",
42
42
  "@ag-ui/encoder": "0.0.28",
43
+ "@ag-ui/langgraph": "0.0.3",
43
44
  "@ag-ui/proto": "0.0.28",
44
45
  "@anthropic-ai/sdk": "^0.27.3",
45
46
  "@graphql-yoga/plugin-defer-stream": "^3.3.1",
@@ -65,7 +66,7 @@
65
66
  "rxjs": "^7.8.1",
66
67
  "type-graphql": "2.0.0-rc.1",
67
68
  "zod": "^3.23.3",
68
- "@copilotkit/shared": "1.8.15-next.1"
69
+ "@copilotkit/shared": "1.9.0-next.2"
69
70
  },
70
71
  "peerDependencies": {
71
72
  "@ag-ui/client": ">=0.0.28",
package/src/lib/index.ts CHANGED
@@ -8,3 +8,4 @@ export * from "./integrations";
8
8
  export * from "./logger";
9
9
  export * from "./runtime/copilot-runtime";
10
10
  export * from "./runtime/mcp-tools-utils";
11
+ export * from "./runtime/langgraph/langgraph-agent";
@@ -0,0 +1,190 @@
1
+ import {
2
+ RunAgentInput,
3
+ EventType,
4
+ CustomEvent,
5
+ TextMessageStartEvent,
6
+ TextMessageContentEvent,
7
+ TextMessageEndEvent,
8
+ ToolCallStartEvent,
9
+ ToolCallArgsEvent,
10
+ ToolCallEndEvent,
11
+ } from "@ag-ui/client";
12
+ import { map } from "rxjs";
13
+ import { LangGraphEventTypes } from "../../../agents/langgraph/events";
14
+ import { RawEvent } from "@ag-ui/core";
15
+ import {
16
+ LangGraphAgent as AGUILangGraphAgent,
17
+ type LangGraphAgentConfig,
18
+ ProcessedEvents,
19
+ } from "@ag-ui/langgraph";
20
+ import { Message as LangGraphMessage } from "@langchain/langgraph-sdk/dist/types.messages";
21
+
22
+ export interface PredictStateTool {
23
+ tool: string;
24
+ state_key: string;
25
+ tool_argument: string;
26
+ }
27
+ export type State = Record<string, any>;
28
+
29
+ export type TextMessageEvents =
30
+ | TextMessageStartEvent
31
+ | TextMessageContentEvent
32
+ | TextMessageEndEvent;
33
+
34
+ export type ToolCallEvents = ToolCallStartEvent | ToolCallArgsEvent | ToolCallEndEvent;
35
+
36
+ export enum CustomEventNames {
37
+ CopilotKitManuallyEmitMessage = "copilotkit_manually_emit_message",
38
+ CopilotKitManuallyEmitToolCall = "copilotkit_manually_emit_tool_call",
39
+ CopilotKitManuallyEmitIntermediateState = "copilotkit_manually_emit_intermediate_state",
40
+ CopilotKitExit = "copilotkit_exit",
41
+ }
42
+
43
+ export class LangGraphAgent extends AGUILangGraphAgent {
44
+ constructor(config: LangGraphAgentConfig) {
45
+ super(config);
46
+ }
47
+
48
+ dispatchEvent(event: ProcessedEvents) {
49
+ if (event.type === EventType.CUSTOM) {
50
+ // const event = processedEvent as unknown as CustomEvent;
51
+ const customEvent = event as unknown as CustomEvent;
52
+
53
+ if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitMessage) {
54
+ this.subscriber.next({
55
+ type: EventType.TEXT_MESSAGE_START,
56
+ role: "assistant",
57
+ messageId: customEvent.value.message_id,
58
+ rawEvent: event,
59
+ });
60
+ this.subscriber.next({
61
+ type: EventType.TEXT_MESSAGE_CONTENT,
62
+ messageId: customEvent.value.message_id,
63
+ delta: customEvent.value.message,
64
+ rawEvent: event,
65
+ });
66
+ this.subscriber.next({
67
+ type: EventType.TEXT_MESSAGE_END,
68
+ messageId: customEvent.value.message_id,
69
+ rawEvent: event,
70
+ });
71
+ return true;
72
+ }
73
+
74
+ if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitToolCall) {
75
+ this.subscriber.next({
76
+ type: EventType.TOOL_CALL_START,
77
+ toolCallId: customEvent.value.id,
78
+ toolCallName: customEvent.value.name,
79
+ parentMessageId: customEvent.value.id,
80
+ rawEvent: event,
81
+ });
82
+ this.subscriber.next({
83
+ type: EventType.TOOL_CALL_ARGS,
84
+ toolCallId: customEvent.value.id,
85
+ delta: customEvent.value.args,
86
+ rawEvent: event,
87
+ });
88
+ this.subscriber.next({
89
+ type: EventType.TOOL_CALL_END,
90
+ toolCallId: customEvent.value.id,
91
+ rawEvent: event,
92
+ });
93
+ return true;
94
+ }
95
+
96
+ if (customEvent.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState) {
97
+ this.activeRun.manuallyEmittedState = customEvent.value;
98
+ this.dispatchEvent({
99
+ type: EventType.STATE_SNAPSHOT,
100
+ snapshot: this.getStateSnapshot(this.activeRun.manuallyEmittedState),
101
+ rawEvent: event,
102
+ });
103
+ return true;
104
+ }
105
+
106
+ if (customEvent.name === CustomEventNames.CopilotKitExit) {
107
+ this.subscriber.next({
108
+ type: EventType.CUSTOM,
109
+ name: "Exit",
110
+ value: true,
111
+ });
112
+ return true;
113
+ }
114
+ }
115
+
116
+ // Intercept all text message and tool call events and check if should disable
117
+ const rawEvent = (event as ToolCallEvents | TextMessageEvents).rawEvent;
118
+ if (!rawEvent) {
119
+ this.subscriber.next(event);
120
+ return true;
121
+ }
122
+
123
+ const isMessageEvent =
124
+ event.type === EventType.TEXT_MESSAGE_START ||
125
+ event.type === EventType.TEXT_MESSAGE_CONTENT ||
126
+ event.type === EventType.TEXT_MESSAGE_END;
127
+ const isToolEvent =
128
+ event.type === EventType.TOOL_CALL_START ||
129
+ event.type === EventType.TOOL_CALL_ARGS ||
130
+ event.type === EventType.TOOL_CALL_END;
131
+ if ("copilotkit:emit-tool-calls" in (rawEvent.metadata || {})) {
132
+ if (rawEvent.metadata["copilotkit:emit-tool-calls"] === false && isToolEvent) {
133
+ return false;
134
+ }
135
+ }
136
+ if ("copilotkit:emit-messages" in (rawEvent.metadata || {})) {
137
+ if (rawEvent.metadata["copilotkit:emit-messages"] === false && isMessageEvent) {
138
+ return false;
139
+ }
140
+ }
141
+
142
+ this.subscriber.next(event);
143
+ return true;
144
+ }
145
+
146
+ // @ts-ignore
147
+ run(input: RunAgentInput) {
148
+ return super.run(input).pipe(
149
+ map((processedEvent) => {
150
+ // Turn raw event into emit state snapshot from tool call event
151
+ if (processedEvent.type === EventType.RAW) {
152
+ // Get the LangGraph event from the AGUI event.
153
+ const event = (processedEvent as RawEvent).event ?? (processedEvent as RawEvent).rawEvent;
154
+
155
+ const eventType = event.event;
156
+ const toolCallData = event.data?.chunk?.tool_call_chunks?.[0];
157
+ const toolCallUsedToPredictState = event.metadata?.[
158
+ "copilotkit:emit-intermediate-state"
159
+ ]?.some(
160
+ (predictStateTool: PredictStateTool) => predictStateTool.tool === toolCallData?.name,
161
+ );
162
+
163
+ if (eventType === LangGraphEventTypes.OnChatModelStream && toolCallUsedToPredictState) {
164
+ return {
165
+ type: EventType.CUSTOM,
166
+ name: "PredictState",
167
+ value: event.metadata["copilotkit:emit-intermediate-state"],
168
+ };
169
+ }
170
+ }
171
+
172
+ return processedEvent;
173
+ }),
174
+ );
175
+ }
176
+
177
+ langGraphDefaultMergeState(state: State, messages: LangGraphMessage[], tools: any): State {
178
+ const { tools: returnedTools, ...rest } = super.langGraphDefaultMergeState(
179
+ state,
180
+ messages,
181
+ tools,
182
+ );
183
+ return {
184
+ ...rest,
185
+ copilotkit: {
186
+ actions: returnedTools,
187
+ },
188
+ };
189
+ }
190
+ }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-Q6JA6YY3.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}