@copilotkit/runtime 1.3.16-mme-reset-chat.10 → 1.3.16-mme-reset-chat.11

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 (46) hide show
  1. package/CHANGELOG.md +21 -43
  2. package/dist/{chunk-2S6JGN2A.mjs → chunk-NJH4ZBXT.mjs} +2 -2
  3. package/dist/{chunk-TBNMKEWV.mjs → chunk-T2MGJXW2.mjs} +2 -2
  4. package/dist/{chunk-3XICZ4K2.mjs → chunk-XR3QOJ47.mjs} +2 -2
  5. package/dist/{chunk-ODOSADGH.mjs → chunk-YILXJQFD.mjs} +78 -57
  6. package/dist/chunk-YILXJQFD.mjs.map +1 -0
  7. package/dist/{copilot-runtime-b9715bd4.d.ts → copilot-runtime-335a610d.d.ts} +8 -8
  8. package/dist/{groq-adapter-dbfba3eb.d.ts → groq-adapter-2f8fd767.d.ts} +1 -1
  9. package/dist/index.d.ts +3 -3
  10. package/dist/index.js +80 -59
  11. package/dist/index.js.map +1 -1
  12. package/dist/index.mjs +6 -6
  13. package/dist/{langserve-f00629d2.d.ts → langserve-cc06e76e.d.ts} +1 -0
  14. package/dist/lib/index.d.ts +3 -3
  15. package/dist/lib/index.js +80 -59
  16. package/dist/lib/index.js.map +1 -1
  17. package/dist/lib/index.mjs +6 -6
  18. package/dist/lib/integrations/index.d.ts +3 -3
  19. package/dist/lib/integrations/index.js +12 -11
  20. package/dist/lib/integrations/index.js.map +1 -1
  21. package/dist/lib/integrations/index.mjs +4 -4
  22. package/dist/lib/integrations/nest/index.d.ts +2 -2
  23. package/dist/lib/integrations/nest/index.js +12 -11
  24. package/dist/lib/integrations/nest/index.js.map +1 -1
  25. package/dist/lib/integrations/nest/index.mjs +2 -2
  26. package/dist/lib/integrations/node-express/index.d.ts +2 -2
  27. package/dist/lib/integrations/node-express/index.js +12 -11
  28. package/dist/lib/integrations/node-express/index.js.map +1 -1
  29. package/dist/lib/integrations/node-express/index.mjs +2 -2
  30. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  31. package/dist/lib/integrations/node-http/index.js +12 -11
  32. package/dist/lib/integrations/node-http/index.js.map +1 -1
  33. package/dist/lib/integrations/node-http/index.mjs +1 -1
  34. package/dist/service-adapters/index.d.ts +3 -3
  35. package/package.json +4 -4
  36. package/src/agents/langgraph/event-source.ts +2 -2
  37. package/src/lib/runtime/copilot-runtime.ts +40 -33
  38. package/src/lib/runtime/remote-action-constructors.ts +7 -7
  39. package/src/lib/runtime/remote-actions.ts +9 -9
  40. package/src/lib/runtime/{remote-lg-cloud-action.ts → remote-lg-action.ts} +34 -31
  41. package/src/lib/telemetry-client.ts +3 -3
  42. package/src/service-adapters/events.ts +13 -1
  43. package/dist/chunk-ODOSADGH.mjs.map +0 -1
  44. /package/dist/{chunk-2S6JGN2A.mjs.map → chunk-NJH4ZBXT.mjs.map} +0 -0
  45. /package/dist/{chunk-TBNMKEWV.mjs.map → chunk-T2MGJXW2.mjs.map} +0 -0
  46. /package/dist/{chunk-3XICZ4K2.mjs.map → chunk-XR3QOJ47.mjs.map} +0 -0
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.3.16-mme-reset-chat.10",
12
+ "version": "1.3.16-mme-reset-chat.11",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -32,8 +32,8 @@
32
32
  "tsup": "^6.7.0",
33
33
  "typescript": "^5.2.3",
34
34
  "zod-to-json-schema": "^3.23.5",
35
- "eslint-config-custom": "1.3.16-mme-reset-chat.4",
36
- "tsconfig": "1.3.16-mme-reset-chat.4"
35
+ "eslint-config-custom": "1.3.16-mme-reset-chat.1",
36
+ "tsconfig": "1.3.16-mme-reset-chat.1"
37
37
  },
38
38
  "dependencies": {
39
39
  "@anthropic-ai/sdk": "^0.27.3",
@@ -58,7 +58,7 @@
58
58
  "rxjs": "^7.8.1",
59
59
  "type-graphql": "2.0.0-rc.1",
60
60
  "zod": "^3.23.3",
61
- "@copilotkit/shared": "1.3.16-mme-reset-chat.10"
61
+ "@copilotkit/shared": "1.3.16-mme-reset-chat.11"
62
62
  },
63
63
  "keywords": [
64
64
  "copilotkit",
@@ -37,7 +37,7 @@ export class RemoteLangGraphEventSource {
37
37
  scan(
38
38
  (acc, event) => {
39
39
  if (event.event === LangGraphEventTypes.OnChatModelStream) {
40
- // @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
40
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
41
41
  const content = event.data?.chunk?.kwargs?.content ?? event.data?.chunk?.content;
42
42
 
43
43
  if (typeof content === "string") {
@@ -49,7 +49,7 @@ export class RemoteLangGraphEventSource {
49
49
  }
50
50
 
51
51
  const toolCallChunks =
52
- // @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
52
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
53
53
  event.data?.chunk?.kwargs?.tool_call_chunks ?? event.data?.chunk?.tool_call_chunks;
54
54
 
55
55
  const toolCallMessageId =
@@ -12,7 +12,7 @@
12
12
  * ```
13
13
  */
14
14
 
15
- import { Action, actionParametersToJsonSchema, Parameter } from "@copilotkit/shared";
15
+ import { Action, actionParametersToJsonSchema, Parameter, randomId } from "@copilotkit/shared";
16
16
  import { CopilotServiceAdapter, RemoteChain, RemoteChainParameters } from "../../service-adapters";
17
17
  import { MessageInput } from "../../graphql/inputs/message.input";
18
18
  import { ActionInput } from "../../graphql/inputs/action.input";
@@ -27,7 +27,7 @@ import {
27
27
  setupRemoteActions,
28
28
  EndpointDefinition,
29
29
  CopilotKitEndpoint,
30
- LangGraphCloudEndpoint,
30
+ LangGraphPlatformEndpoint,
31
31
  } from "./remote-actions";
32
32
  import { GraphQLContext } from "../integrations/shared";
33
33
  import { AgentSessionInput } from "../../graphql/inputs/agent-session.input";
@@ -155,7 +155,7 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
155
155
  this.langserve.push(remoteChain.toAction());
156
156
  }
157
157
 
158
- this.remoteEndpointDefinitions = params?.remoteEndpoints || [];
158
+ this.remoteEndpointDefinitions = params?.remoteEndpoints ?? params?.remoteActions ?? [];
159
159
 
160
160
  this.onBeforeRequest = params?.middleware?.onBeforeRequest;
161
161
  this.onAfterRequest = params?.middleware?.onAfterRequest;
@@ -175,36 +175,36 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
175
175
  url,
176
176
  } = request;
177
177
 
178
- if (agentSession) {
179
- return this.processAgentRequest(request);
180
- }
178
+ const eventSource = new RuntimeEventSource();
181
179
 
182
- const messages = rawMessages.filter((message) => !message.agentStateMessage);
180
+ try {
181
+ if (agentSession) {
182
+ return await this.processAgentRequest(request);
183
+ }
183
184
 
184
- const inputMessages = convertGqlInputToMessages(messages);
185
- const serverSideActions = await this.getServerSideActions(request);
185
+ const messages = rawMessages.filter((message) => !message.agentStateMessage);
186
186
 
187
- const serverSideActionsInput: ActionInput[] = serverSideActions.map((action) => ({
188
- name: action.name,
189
- description: action.description,
190
- jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),
191
- }));
187
+ const inputMessages = convertGqlInputToMessages(messages);
188
+ const serverSideActions = await this.getServerSideActions(request);
192
189
 
193
- const actionInputs = flattenToolCallsNoDuplicates([
194
- ...serverSideActionsInput,
195
- ...clientSideActionsInput,
196
- ]);
190
+ const serverSideActionsInput: ActionInput[] = serverSideActions.map((action) => ({
191
+ name: action.name,
192
+ description: action.description,
193
+ jsonSchema: JSON.stringify(actionParametersToJsonSchema(action.parameters)),
194
+ }));
197
195
 
198
- await this.onBeforeRequest?.({
199
- threadId,
200
- runId,
201
- inputMessages,
202
- properties: graphqlContext.properties,
203
- url,
204
- });
196
+ const actionInputs = flattenToolCallsNoDuplicates([
197
+ ...serverSideActionsInput,
198
+ ...clientSideActionsInput,
199
+ ]);
205
200
 
206
- try {
207
- const eventSource = new RuntimeEventSource();
201
+ await this.onBeforeRequest?.({
202
+ threadId,
203
+ runId,
204
+ inputMessages,
205
+ properties: graphqlContext.properties,
206
+ url,
207
+ });
208
208
 
209
209
  const result = await serviceAdapter.process({
210
210
  messages: inputMessages,
@@ -244,7 +244,14 @@ export class CopilotRuntime<const T extends Parameter[] | [] = []> {
244
244
  };
245
245
  } catch (error) {
246
246
  console.error("Error getting response:", error);
247
- throw error;
247
+ eventSource.sendErrorMessageToChat();
248
+ return {
249
+ threadId: threadId || randomId(),
250
+ runId: runId || randomId(),
251
+ eventSource,
252
+ serverSideActions: [],
253
+ actionInputsWithoutAgents: [],
254
+ };
248
255
  }
249
256
  }
250
257
 
@@ -385,19 +392,19 @@ export function copilotKitEndpoint(config: Omit<CopilotKitEndpoint, "type">): Co
385
392
  };
386
393
  }
387
394
 
388
- export function langGraphCloudEndpoint(
389
- config: Omit<LangGraphCloudEndpoint, "type">,
390
- ): LangGraphCloudEndpoint {
395
+ export function langGraphPlatformEndpoint(
396
+ config: Omit<LangGraphPlatformEndpoint, "type">,
397
+ ): LangGraphPlatformEndpoint {
391
398
  return {
392
399
  ...config,
393
- type: EndpointType.LangGraphCloud,
400
+ type: EndpointType.LangGraphPlatform,
394
401
  };
395
402
  }
396
403
 
397
404
  export function resolveEndpointType(endpoint: EndpointDefinition) {
398
405
  if (!endpoint.type) {
399
406
  if ("langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
400
- return EndpointType.LangGraphCloud;
407
+ return EndpointType.LangGraphPlatform;
401
408
  } else {
402
409
  return EndpointType.CopilotKit;
403
410
  }
@@ -3,7 +3,7 @@ import {
3
3
  CopilotKitEndpoint,
4
4
  LangGraphAgentHandlerParams,
5
5
  RemoteActionInfoResponse,
6
- LangGraphCloudEndpoint,
6
+ LangGraphPlatformEndpoint,
7
7
  } from "./remote-actions";
8
8
  import { GraphQLContext } from "../integrations";
9
9
  import { Logger } from "pino";
@@ -15,7 +15,7 @@ import telemetry from "../telemetry-client";
15
15
  import { RemoteLangGraphEventSource } from "../../agents/langgraph/event-source";
16
16
  import { Action } from "@copilotkit/shared";
17
17
  import { LangGraphEvent } from "../../agents/langgraph/events";
18
- import { execute } from "./remote-lg-cloud-action";
18
+ import { execute } from "./remote-lg-action";
19
19
 
20
20
  export function constructLGCRemoteAction({
21
21
  endpoint,
@@ -24,7 +24,7 @@ export function constructLGCRemoteAction({
24
24
  messages,
25
25
  agentStates,
26
26
  }: {
27
- endpoint: LangGraphCloudEndpoint;
27
+ endpoint: LangGraphPlatformEndpoint;
28
28
  graphqlContext: GraphQLContext;
29
29
  logger: Logger;
30
30
  messages: Message[];
@@ -41,11 +41,11 @@ export function constructLGCRemoteAction({
41
41
  threadId,
42
42
  nodeName,
43
43
  }: LangGraphAgentHandlerParams): Promise<Observable<RuntimeEvent>> => {
44
- logger.debug({ actionName: agent.name }, "Executing LangGraph Cloud agent");
44
+ logger.debug({ actionName: agent.name }, "Executing LangGraph Platform agent");
45
45
 
46
46
  telemetry.capture("oss.runtime.remote_action_executed", {
47
47
  agentExecution: true,
48
- type: "langgraph-cloud",
48
+ type: "langgraph-platform",
49
49
  agentsAmount: endpoint.agents.length,
50
50
  hashedLgcKey: createHash("sha256").update(endpoint.langsmithApiKey).digest("hex"),
51
51
  });
@@ -82,9 +82,9 @@ export function constructLGCRemoteAction({
82
82
  } catch (error) {
83
83
  logger.error(
84
84
  { url: endpoint.deploymentUrl, status: 500, body: error.message },
85
- "Failed to execute LangGraph Cloud agent",
85
+ "Failed to execute LangGraph Platform agent",
86
86
  );
87
- throw new Error("Failed to execute LangGraph Cloud agent");
87
+ throw new Error("Failed to execute LangGraph Platform agent");
88
88
  }
89
89
  },
90
90
  }));
@@ -12,11 +12,11 @@ import {
12
12
  createHeaders,
13
13
  } from "./remote-action-constructors";
14
14
 
15
- export type EndpointDefinition = CopilotKitEndpoint | LangGraphCloudEndpoint;
15
+ export type EndpointDefinition = CopilotKitEndpoint | LangGraphPlatformEndpoint;
16
16
 
17
17
  export enum EndpointType {
18
18
  CopilotKit = "copilotKit",
19
- LangGraphCloud = "langgraph-cloud",
19
+ LangGraphPlatform = "langgraph-platform",
20
20
  }
21
21
 
22
22
  export interface BaseEndpointDefinition<TActionType extends EndpointType> {
@@ -30,17 +30,17 @@ export interface CopilotKitEndpoint extends BaseEndpointDefinition<EndpointType.
30
30
  };
31
31
  }
32
32
 
33
- export interface LangGraphCloudAgent {
33
+ export interface LangGraphPlatformAgent {
34
34
  name: string;
35
35
  description: string;
36
36
  assistantId?: string;
37
37
  }
38
38
 
39
- export interface LangGraphCloudEndpoint
40
- extends BaseEndpointDefinition<EndpointType.LangGraphCloud> {
39
+ export interface LangGraphPlatformEndpoint
40
+ extends BaseEndpointDefinition<EndpointType.LangGraphPlatform> {
41
41
  deploymentUrl: string;
42
42
  langsmithApiKey: string;
43
- agents: LangGraphCloudAgent[];
43
+ agents: LangGraphPlatformAgent[];
44
44
  }
45
45
 
46
46
  export type RemoteActionInfoResponse = {
@@ -127,7 +127,7 @@ export async function setupRemoteActions({
127
127
 
128
128
  // Remove duplicates of remoteEndpointDefinitions.url
129
129
  const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
130
- if (value.type === EndpointType.LangGraphCloud) {
130
+ if (value.type === EndpointType.LangGraphPlatform) {
131
131
  return value;
132
132
  }
133
133
  return index === self.findIndex((t: CopilotKitEndpoint) => t.url === value.url);
@@ -135,8 +135,8 @@ export async function setupRemoteActions({
135
135
 
136
136
  const result = await Promise.all(
137
137
  filtered.map(async (endpoint) => {
138
- // Check for properties that can distinguish LG cloud from other actions
139
- if (endpoint.type === EndpointType.LangGraphCloud) {
138
+ // Check for properties that can distinguish LG platform from other actions
139
+ if (endpoint.type === EndpointType.LangGraphPlatform) {
140
140
  return constructLGCRemoteAction({
141
141
  endpoint,
142
142
  messages,
@@ -3,7 +3,7 @@ import { createHash, randomUUID } from "node:crypto";
3
3
  import { parse as parsePartialJson } from "partial-json";
4
4
  import { Logger } from "pino";
5
5
  import { ActionInput } from "../../graphql/inputs/action.input";
6
- import { LangGraphCloudAgent, LangGraphCloudEndpoint } from "./remote-actions";
6
+ import { LangGraphPlatformAgent, LangGraphPlatformEndpoint } from "./remote-actions";
7
7
  import { CopilotRequestContextProperties } from "../integrations";
8
8
  import { Message, MessageType } from "../../graphql/types/converted";
9
9
  import { MessageRole } from "../../graphql/types/enums";
@@ -14,8 +14,8 @@ type State = Record<string, any>;
14
14
 
15
15
  type ExecutionAction = Pick<ActionInput, "name" | "description"> & { parameters: string };
16
16
 
17
- interface ExecutionArgs extends Omit<LangGraphCloudEndpoint, "agents"> {
18
- agent: LangGraphCloudAgent;
17
+ interface ExecutionArgs extends Omit<LangGraphPlatformEndpoint, "agents"> {
18
+ agent: LangGraphPlatformAgent;
19
19
  threadId: string;
20
20
  nodeName: string;
21
21
  messages: Message[];
@@ -25,14 +25,14 @@ interface ExecutionArgs extends Omit<LangGraphCloudEndpoint, "agents"> {
25
25
  logger: Logger;
26
26
  }
27
27
 
28
- // The following types are our own definition to the messages accepted by LangGraph cloud, enhanced with some of our extra data.
28
+ // The following types are our own definition to the messages accepted by LangGraph Platform, enhanced with some of our extra data.
29
29
  interface ToolCall {
30
30
  id: string;
31
31
  name: string;
32
32
  args: Record<string, unknown>;
33
33
  }
34
34
 
35
- type BaseLangGraphCloudMessage = Omit<
35
+ type BaseLangGraphPlatformMessage = Omit<
36
36
  Message,
37
37
  | "isResultMessage"
38
38
  | "isTextMessage"
@@ -47,19 +47,19 @@ type BaseLangGraphCloudMessage = Omit<
47
47
  type: MessageType;
48
48
  };
49
49
 
50
- interface LangGraphCloudResultMessage extends BaseLangGraphCloudMessage {
50
+ interface LangGraphPlatformResultMessage extends BaseLangGraphPlatformMessage {
51
51
  tool_call_id: string;
52
52
  name: string;
53
53
  }
54
54
 
55
- interface LangGraphCloudActionExecutionMessage extends BaseLangGraphCloudMessage {
55
+ interface LangGraphPlatformActionExecutionMessage extends BaseLangGraphPlatformMessage {
56
56
  tool_calls: ToolCall[];
57
57
  }
58
58
 
59
- type LangGraphCloudMessage =
60
- | LangGraphCloudActionExecutionMessage
61
- | LangGraphCloudResultMessage
62
- | BaseLangGraphCloudMessage;
59
+ type LangGraphPlatformMessage =
60
+ | LangGraphPlatformActionExecutionMessage
61
+ | LangGraphPlatformResultMessage
62
+ | BaseLangGraphPlatformMessage;
63
63
 
64
64
  export async function execute(args: ExecutionArgs): Promise<ReadableStream<Uint8Array>> {
65
65
  return new ReadableStream({
@@ -128,7 +128,7 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
128
128
  if (!assistantId) {
129
129
  console.error(`
130
130
  No agent found for the agent name specified in CopilotKit provider
131
- Please check your available agents or provide an agent ID in the LangGraph Cloud endpoint definition.\n
131
+ Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.\n
132
132
 
133
133
  These are the available agents: [${assistants.map((a) => `${a.name} (ID: ${a.assistant_id})`).join(", ")}]
134
134
  `);
@@ -152,6 +152,9 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
152
152
 
153
153
  let latestStateValues = {};
154
154
  let updatedState = state;
155
+ // If a manual emittance happens, it is the ultimate source of truth of state, unless a node has exited.
156
+ // Therefore, this value should either hold null, or the only edition of state that should be used.
157
+ let manuallyEmittedState = null;
155
158
  let streamInfo: {
156
159
  provider?: string;
157
160
  langGraphHost?: string;
@@ -205,33 +208,36 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
205
208
  eventType === LangGraphEventTypes.OnCustomEvent &&
206
209
  event.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState;
207
210
 
211
+ const exitingNode =
212
+ nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
213
+
214
+ // See manuallyEmittedState for explanation
215
+ if (exitingNode) {
216
+ manuallyEmittedState = null;
217
+ }
218
+
208
219
  // we only want to update the node name under certain conditions
209
220
  // since we don't need any internal node names to be sent to the frontend
210
221
  if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
211
222
  nodeName = currentNodeName;
212
-
213
- // only update state from values when entering or exiting a known node
214
- if (
215
- eventType === LangGraphEventTypes.OnChainStart ||
216
- eventType === LangGraphEventTypes.OnChainEnd
217
- ) {
218
- updatedState = latestStateValues;
219
- }
220
223
  }
221
224
 
225
+ updatedState = manuallyEmittedState ?? latestStateValues;
226
+
222
227
  if (!nodeName) {
223
228
  continue;
224
229
  }
225
230
 
226
231
  if (manuallyEmitIntermediateState) {
227
- updatedState = event.data;
232
+ // See manuallyEmittedState for explanation
233
+ manuallyEmittedState = event.data;
228
234
  emit(
229
235
  getStateSyncEvent({
230
236
  threadId,
231
237
  runId,
232
238
  agentName: agent.name,
233
239
  nodeName,
234
- state: updatedState,
240
+ state: manuallyEmittedState,
235
241
  running: true,
236
242
  active: true,
237
243
  }),
@@ -268,9 +274,6 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
268
274
  emitIntermediateStateUntilEnd = null;
269
275
  }
270
276
 
271
- const exitingNode =
272
- nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
273
-
274
277
  if (
275
278
  JSON.stringify(updatedState) !== JSON.stringify(state) ||
276
279
  prevNodeName != nodeName ||
@@ -436,7 +439,7 @@ class StreamingStateExtractor {
436
439
  // Start of Selection
437
440
  function langGraphDefaultMergeState(
438
441
  state: State,
439
- messages: LangGraphCloudMessage[],
442
+ messages: LangGraphPlatformMessage[],
440
443
  actions: ExecutionAction[],
441
444
  agentName: string,
442
445
  ): State {
@@ -446,7 +449,7 @@ function langGraphDefaultMergeState(
446
449
  }
447
450
 
448
451
  // merge with existing messages
449
- const mergedMessages: LangGraphCloudMessage[] = state.messages || [];
452
+ const mergedMessages: LangGraphPlatformMessage[] = state.messages || [];
450
453
  const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
451
454
  const existingToolCallResults = new Set<string>();
452
455
 
@@ -512,7 +515,7 @@ function langGraphDefaultMergeState(
512
515
  }
513
516
 
514
517
  // try to auto-correct and log alignment issues
515
- const correctedMessages: LangGraphCloudMessage[] = [];
518
+ const correctedMessages: LangGraphPlatformMessage[] = [];
516
519
 
517
520
  for (let i = 0; i < mergedMessages.length; i++) {
518
521
  const currentMessage = mergedMessages[i];
@@ -583,7 +586,7 @@ function langGraphDefaultMergeState(
583
586
  };
584
587
  }
585
588
 
586
- function formatMessages(messages: Message[]): LangGraphCloudMessage[] {
589
+ function formatMessages(messages: Message[]): LangGraphPlatformMessage[] {
587
590
  return messages.map((message) => {
588
591
  if (message.isTextMessage() && message.role === "assistant") {
589
592
  return message;
@@ -606,7 +609,7 @@ function formatMessages(messages: Message[]): LangGraphCloudMessage[] {
606
609
  tool_calls: [toolCall],
607
610
  role: MessageRole.assistant,
608
611
  id: message.id,
609
- } satisfies LangGraphCloudActionExecutionMessage;
612
+ } satisfies LangGraphPlatformActionExecutionMessage;
610
613
  }
611
614
  if (message.isResultMessage()) {
612
615
  return {
@@ -616,7 +619,7 @@ function formatMessages(messages: Message[]): LangGraphCloudMessage[] {
616
619
  tool_call_id: message.actionExecutionId,
617
620
  name: message.actionName,
618
621
  role: MessageRole.tool,
619
- } satisfies LangGraphCloudResultMessage;
622
+ } satisfies LangGraphPlatformResultMessage;
620
623
  }
621
624
 
622
625
  throw new Error(`Unknown message type ${message.type}`);
@@ -1,5 +1,5 @@
1
1
  import { TelemetryClient } from "@copilotkit/shared";
2
- import { EndpointType, LangGraphCloudEndpoint } from "./runtime/remote-actions";
2
+ import { EndpointType, LangGraphPlatformEndpoint } from "./runtime/remote-actions";
3
3
  import { createHash } from "node:crypto";
4
4
  import { CopilotRuntime, resolveEndpointType } from "./runtime/copilot-runtime";
5
5
  import { RuntimeInstanceCreatedInfo } from "@copilotkit/shared/src/telemetry/events";
@@ -25,9 +25,9 @@ export function getRuntimeInstanceTelemetryInfo(
25
25
  };
26
26
  }
27
27
 
28
- if (endpointType === EndpointType.LangGraphCloud) {
28
+ if (endpointType === EndpointType.LangGraphPlatform) {
29
29
  // When type is resolved, recreating a const with casting of type
30
- const ep = endpoint as LangGraphCloudEndpoint;
30
+ const ep = endpoint as LangGraphPlatformEndpoint;
31
31
  info = {
32
32
  ...info,
33
33
  agentsAmount: ep.agents.length,
@@ -1,4 +1,4 @@
1
- import { Action } from "@copilotkit/shared";
1
+ import { Action, randomId } from "@copilotkit/shared";
2
2
  import {
3
3
  of,
4
4
  concat,
@@ -158,6 +158,17 @@ export class RuntimeEventSource {
158
158
  this.callback = callback;
159
159
  }
160
160
 
161
+ sendErrorMessageToChat() {
162
+ const errorMessage = "❌ An error occurred. Please try again.";
163
+ if (!this.callback) {
164
+ this.stream(async (eventStream$) => {
165
+ eventStream$.sendTextMessage(randomId(), errorMessage);
166
+ });
167
+ } else {
168
+ this.eventStream$.sendTextMessage(randomId(), errorMessage);
169
+ }
170
+ }
171
+
161
172
  processRuntimeEvents({
162
173
  serverSideActions,
163
174
  guardrailsResult$,
@@ -169,6 +180,7 @@ export class RuntimeEventSource {
169
180
  }) {
170
181
  this.callback(this.eventStream$).catch((error) => {
171
182
  console.error("Error in event source callback", error);
183
+ this.sendErrorMessageToChat();
172
184
  });
173
185
  return this.eventStream$.pipe(
174
186
  // mark tools for server side execution