@copilotkit/runtime 1.3.12-fix-tool-call-dynamic-parameters.0 → 1.3.12-lgc-alpha-1.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 (56) hide show
  1. package/CHANGELOG.md +3 -4
  2. package/dist/{chunk-SIMJ6TZU.mjs → chunk-6B3NPPSR.mjs} +2 -2
  3. package/dist/{chunk-OSJXQNII.mjs → chunk-6HXQC7IT.mjs} +36 -9
  4. package/dist/chunk-6HXQC7IT.mjs.map +1 -0
  5. package/dist/{chunk-24WEOOFX.mjs → chunk-7MQDBRXJ.mjs} +2 -2
  6. package/dist/{chunk-AOYYOKTP.mjs → chunk-E6ZFCM3B.mjs} +561 -133
  7. package/dist/chunk-E6ZFCM3B.mjs.map +1 -0
  8. package/dist/{chunk-UYORVPCQ.mjs → chunk-TM7ZRU3M.mjs} +2 -2
  9. package/dist/{chunk-ZEHCLFJ2.mjs → chunk-V7SK6QZN.mjs} +6 -9
  10. package/dist/chunk-V7SK6QZN.mjs.map +1 -0
  11. package/dist/{chunk-HKLL7TTP.mjs → chunk-XMDH5MKI.mjs} +2 -2
  12. package/dist/{copilot-runtime-df3527ad.d.ts → copilot-runtime-aba7d4b4.d.ts} +27 -5
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.js +638 -186
  15. package/dist/index.js.map +1 -1
  16. package/dist/index.mjs +13 -9
  17. package/dist/index.mjs.map +1 -1
  18. package/dist/lib/index.d.ts +1 -1
  19. package/dist/lib/index.js +638 -186
  20. package/dist/lib/index.js.map +1 -1
  21. package/dist/lib/index.mjs +13 -9
  22. package/dist/lib/integrations/index.d.ts +2 -2
  23. package/dist/lib/integrations/index.js +5 -4
  24. package/dist/lib/integrations/index.js.map +1 -1
  25. package/dist/lib/integrations/index.mjs +5 -5
  26. package/dist/lib/integrations/nest/index.d.ts +1 -1
  27. package/dist/lib/integrations/nest/index.js +5 -4
  28. package/dist/lib/integrations/nest/index.js.map +1 -1
  29. package/dist/lib/integrations/nest/index.mjs +3 -3
  30. package/dist/lib/integrations/node-express/index.d.ts +1 -1
  31. package/dist/lib/integrations/node-express/index.js +5 -4
  32. package/dist/lib/integrations/node-express/index.js.map +1 -1
  33. package/dist/lib/integrations/node-express/index.mjs +3 -3
  34. package/dist/lib/integrations/node-http/index.d.ts +1 -1
  35. package/dist/lib/integrations/node-http/index.js +5 -4
  36. package/dist/lib/integrations/node-http/index.js.map +1 -1
  37. package/dist/lib/integrations/node-http/index.mjs +2 -2
  38. package/dist/service-adapters/index.js +5 -8
  39. package/dist/service-adapters/index.js.map +1 -1
  40. package/dist/service-adapters/index.mjs +2 -2
  41. package/package.json +7 -6
  42. package/src/agents/langgraph/event-source.ts +22 -67
  43. package/src/lib/runtime/copilot-runtime.ts +58 -11
  44. package/src/lib/runtime/remote-action-constructors.ts +283 -0
  45. package/src/lib/runtime/remote-actions.ts +65 -159
  46. package/src/lib/runtime/remote-lg-cloud-action.ts +441 -0
  47. package/src/service-adapters/events.ts +1 -5
  48. package/src/service-adapters/langchain/utils.ts +5 -10
  49. package/dist/chunk-AOYYOKTP.mjs.map +0 -1
  50. package/dist/chunk-OSJXQNII.mjs.map +0 -1
  51. package/dist/chunk-ZEHCLFJ2.mjs.map +0 -1
  52. package/src/service-adapters/langchain/utils.test.ts +0 -169
  53. /package/dist/{chunk-SIMJ6TZU.mjs.map → chunk-6B3NPPSR.mjs.map} +0 -0
  54. /package/dist/{chunk-24WEOOFX.mjs.map → chunk-7MQDBRXJ.mjs.map} +0 -0
  55. /package/dist/{chunk-UYORVPCQ.mjs.map → chunk-TM7ZRU3M.mjs.map} +0 -0
  56. /package/dist/{chunk-HKLL7TTP.mjs.map → chunk-XMDH5MKI.mjs.map} +0 -0
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.3.12-fix-tool-call-dynamic-parameters.0",
47
+ version: "1.3.12-lgc-alpha-1.0",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -77,16 +77,16 @@ var require_package = __commonJS({
77
77
  "ts-node": "^10.9.2",
78
78
  tsconfig: "workspace:*",
79
79
  tsup: "^6.7.0",
80
- typescript: "^5.2.3",
81
- "zod-to-json-schema": "^3.23.5"
80
+ typescript: "^5.2.3"
82
81
  },
83
82
  dependencies: {
84
83
  "@anthropic-ai/sdk": "^0.27.3",
85
84
  "@copilotkit/shared": "workspace:*",
85
+ "@langchain/google-gauth": "^0.1.0",
86
86
  "@graphql-yoga/plugin-defer-stream": "^3.3.1",
87
87
  "@langchain/community": "^0.0.53",
88
88
  "@langchain/core": "^0.3.13",
89
- "@langchain/google-gauth": "^0.1.0",
89
+ "@langchain/langgraph-sdk": "^0.0.16",
90
90
  "@langchain/openai": "^0.0.28",
91
91
  "class-transformer": "^0.5.1",
92
92
  express: "^4.19.2",
@@ -96,6 +96,7 @@ var require_package = __commonJS({
96
96
  "groq-sdk": "^0.5.0",
97
97
  langchain: "^0.3.3",
98
98
  openai: "^4.50.0",
99
+ "partial-json": "^0.1.7",
99
100
  pino: "^9.2.0",
100
101
  "pino-pretty": "^11.2.1",
101
102
  "reflect-metadata": "^0.2.2",
@@ -131,6 +132,7 @@ __export(lib_exports, {
131
132
  UnifyAdapter: () => UnifyAdapter,
132
133
  buildSchema: () => buildSchema,
133
134
  config: () => config,
135
+ copilotKitEndpoint: () => copilotKitEndpoint,
134
136
  copilotRuntimeNestEndpoint: () => copilotRuntimeNestEndpoint,
135
137
  copilotRuntimeNextJSAppRouterEndpoint: () => copilotRuntimeNextJSAppRouterEndpoint,
136
138
  copilotRuntimeNextJSPagesRouterEndpoint: () => copilotRuntimeNextJSPagesRouterEndpoint,
@@ -138,7 +140,8 @@ __export(lib_exports, {
138
140
  copilotRuntimeNodeHttpEndpoint: () => copilotRuntimeNodeHttpEndpoint,
139
141
  createContext: () => createContext,
140
142
  flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
141
- getCommonConfig: () => getCommonConfig
143
+ getCommonConfig: () => getCommonConfig,
144
+ langGraphCloudEndpoint: () => langGraphCloudEndpoint
142
145
  });
143
146
  module.exports = __toCommonJS(lib_exports);
144
147
 
@@ -494,27 +497,24 @@ __name(convertMessageToLangChainMessage, "convertMessageToLangChainMessage");
494
497
  function convertJsonSchemaToZodSchema(jsonSchema, required) {
495
498
  if (jsonSchema.type === "object") {
496
499
  const spec = {};
497
- if (!jsonSchema.properties || !Object.keys(jsonSchema.properties).length) {
498
- return !required ? import_zod.z.object(spec).optional() : import_zod.z.object(spec);
499
- }
500
500
  for (const [key, value] of Object.entries(jsonSchema.properties)) {
501
501
  spec[key] = convertJsonSchemaToZodSchema(value, jsonSchema.required ? jsonSchema.required.includes(key) : false);
502
502
  }
503
503
  let schema = import_zod.z.object(spec);
504
- return required ? schema : schema.optional();
504
+ return !required ? schema.optional() : schema;
505
505
  } else if (jsonSchema.type === "string") {
506
506
  let schema = import_zod.z.string().describe(jsonSchema.description);
507
- return required ? schema : schema.optional();
507
+ return !required ? schema.optional() : schema;
508
508
  } else if (jsonSchema.type === "number") {
509
509
  let schema = import_zod.z.number().describe(jsonSchema.description);
510
- return required ? schema : schema.optional();
510
+ return !required ? schema.optional() : schema;
511
511
  } else if (jsonSchema.type === "boolean") {
512
512
  let schema = import_zod.z.boolean().describe(jsonSchema.description);
513
- return required ? schema : schema.optional();
513
+ return !required ? schema.optional() : schema;
514
514
  } else if (jsonSchema.type === "array") {
515
515
  let itemSchema = convertJsonSchemaToZodSchema(jsonSchema.items, true);
516
516
  let schema = import_zod.z.array(itemSchema);
517
- return required ? schema : schema.optional();
517
+ return !required ? schema.optional() : schema;
518
518
  }
519
519
  }
520
520
  __name(convertJsonSchemaToZodSchema, "convertJsonSchemaToZodSchema");
@@ -1068,50 +1068,6 @@ var LangGraphEventTypes;
1068
1068
  var import_shared7 = require("@copilotkit/shared");
1069
1069
  var RemoteLangGraphEventSource = class {
1070
1070
  eventStream$ = new import_rxjs.ReplaySubject();
1071
- async streamResponse(response) {
1072
- const reader = response.body.getReader();
1073
- const decoder = new TextDecoder();
1074
- let buffer = [];
1075
- const eventStream$ = this.eventStream$;
1076
- function flushBuffer() {
1077
- const currentBuffer = buffer.join("");
1078
- if (currentBuffer.trim().length === 0) {
1079
- return;
1080
- }
1081
- const parts = currentBuffer.split("\n");
1082
- if (parts.length === 0) {
1083
- return;
1084
- }
1085
- const lastPartIsComplete = currentBuffer.endsWith("\n");
1086
- buffer = [];
1087
- if (!lastPartIsComplete) {
1088
- buffer.push(parts.pop());
1089
- }
1090
- parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
1091
- eventStream$.next(JSON.parse(part));
1092
- });
1093
- }
1094
- __name(flushBuffer, "flushBuffer");
1095
- try {
1096
- while (true) {
1097
- const { done, value } = await reader.read();
1098
- if (!done) {
1099
- buffer.push(decoder.decode(value, {
1100
- stream: true
1101
- }));
1102
- }
1103
- flushBuffer();
1104
- if (done) {
1105
- break;
1106
- }
1107
- }
1108
- } catch (error) {
1109
- console.error("Error in stream", error);
1110
- eventStream$.error(error);
1111
- return;
1112
- }
1113
- eventStream$.complete();
1114
- }
1115
1071
  shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
1116
1072
  if (typeof shouldEmitToolCalls === "boolean") {
1117
1073
  return shouldEmitToolCalls;
@@ -1134,20 +1090,25 @@ var RemoteLangGraphEventSource = class {
1134
1090
  } else {
1135
1091
  acc.content = null;
1136
1092
  }
1137
- if ((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) {
1093
+ const toolCallChunks = (
1094
+ // @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
1095
+ ((_h = (_g = (_f = event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.kwargs) == null ? void 0 : _h.tool_call_chunks) ?? ((_j = (_i = event.data) == null ? void 0 : _i.chunk) == null ? void 0 : _j.tool_call_chunks)
1096
+ );
1097
+ const toolCallMessageId = ((_m = (_l = (_k = event.data) == null ? void 0 : _k.chunk) == null ? void 0 : _l.kwargs) == null ? void 0 : _m.id) ?? ((_o = (_n = event.data) == null ? void 0 : _n.chunk) == null ? void 0 : _o.id);
1098
+ if (toolCallChunks && toolCallChunks.length > 0) {
1138
1099
  acc.prevToolCallMessageId = acc.toolCallMessageId;
1139
- acc.toolCallMessageId = (_i = event.data.chunk.kwargs) == null ? void 0 : _i.id;
1140
- if ((_j = event.data.chunk.kwargs.tool_call_chunks[0]) == null ? void 0 : _j.name) {
1141
- acc.toolCallName = event.data.chunk.kwargs.tool_call_chunks[0].name;
1100
+ acc.toolCallMessageId = toolCallMessageId;
1101
+ if ((_p = toolCallChunks[0]) == null ? void 0 : _p.name) {
1102
+ acc.toolCallName = toolCallChunks[0].name;
1142
1103
  }
1143
- if ((_k = event.data.chunk.kwargs.tool_call_chunks[0]) == null ? void 0 : _k.id) {
1144
- acc.toolCallId = event.data.chunk.kwargs.tool_call_chunks[0].id;
1104
+ if ((_q = toolCallChunks[0]) == null ? void 0 : _q.id) {
1105
+ acc.toolCallId = toolCallChunks[0].id;
1145
1106
  }
1146
1107
  acc.prevMessageId = acc.messageId;
1147
- acc.messageId = (_n = (_m = (_l = event.data) == null ? void 0 : _l.chunk) == null ? void 0 : _m.kwargs) == null ? void 0 : _n.id;
1108
+ acc.messageId = toolCallMessageId;
1148
1109
  } else if (acc.content && acc.content != "") {
1149
1110
  acc.prevMessageId = acc.messageId;
1150
- acc.messageId = (_q = (_p = (_o = event.data) == null ? void 0 : _o.chunk) == null ? void 0 : _p.kwargs) == null ? void 0 : _q.id;
1111
+ acc.messageId = toolCallMessageId;
1151
1112
  } else {
1152
1113
  acc.prevToolCallMessageId = acc.toolCallMessageId;
1153
1114
  acc.prevMessageId = acc.messageId;
@@ -1172,7 +1133,7 @@ var RemoteLangGraphEventSource = class {
1172
1133
  prevMessageId: null,
1173
1134
  content: null
1174
1135
  }), (0, import_rxjs.mergeMap)((eventWithState) => {
1175
- var _a, _b, _c, _d, _e;
1136
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1176
1137
  const events = [];
1177
1138
  let shouldEmitMessages = true;
1178
1139
  let shouldEmitToolCalls = false;
@@ -1255,7 +1216,8 @@ var RemoteLangGraphEventSource = class {
1255
1216
  });
1256
1217
  }
1257
1218
  }
1258
- const args = (_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args;
1219
+ const args = ((_e = (_d = (_c = (_b = (_a = eventWithState.event.data) == null ? void 0 : _a.chunk) == null ? void 0 : _b.kwargs) == null ? void 0 : _c.tool_call_chunks) == null ? void 0 : _d[0]) == null ? void 0 : _e.args) ?? // @ts-expect-error -- sdf
1220
+ ((_i = (_h = (_g = (_f = eventWithState.event.data) == null ? void 0 : _f.chunk) == null ? void 0 : _g.tool_call_chunks) == null ? void 0 : _h[0]) == null ? void 0 : _i.args);
1259
1221
  const content = eventWithState.content;
1260
1222
  if (args) {
1261
1223
  if (this.shouldEmitToolCall(shouldEmitToolCalls, eventWithState.toolCallName)) {
@@ -1306,70 +1268,446 @@ var RemoteLangGraphEventSource = class {
1306
1268
  };
1307
1269
  __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
1308
1270
 
1309
- // src/lib/runtime/remote-actions.ts
1310
- function isLangGraphAgentAction(action) {
1311
- if (!action) {
1312
- return false;
1313
- }
1314
- return typeof action.langGraphAgentHandler === "function";
1271
+ // src/lib/runtime/remote-lg-cloud-action.ts
1272
+ var import_langgraph_sdk = require("@langchain/langgraph-sdk");
1273
+ var import_node_crypto = require("crypto");
1274
+ var import_partial_json = require("partial-json");
1275
+
1276
+ // src/graphql/types/enums.ts
1277
+ var import_type_graphql = require("type-graphql");
1278
+ var MessageRole;
1279
+ (function(MessageRole2) {
1280
+ MessageRole2["user"] = "user";
1281
+ MessageRole2["assistant"] = "assistant";
1282
+ MessageRole2["system"] = "system";
1283
+ })(MessageRole || (MessageRole = {}));
1284
+ var ActionExecutionScope;
1285
+ (function(ActionExecutionScope2) {
1286
+ ActionExecutionScope2["server"] = "server";
1287
+ ActionExecutionScope2["client"] = "client";
1288
+ ActionExecutionScope2["passThrough"] = "passThrough";
1289
+ })(ActionExecutionScope || (ActionExecutionScope = {}));
1290
+ var CopilotRequestType;
1291
+ (function(CopilotRequestType2) {
1292
+ CopilotRequestType2["Chat"] = "Chat";
1293
+ CopilotRequestType2["Task"] = "Task";
1294
+ CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
1295
+ CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
1296
+ CopilotRequestType2["Suggestion"] = "Suggestion";
1297
+ })(CopilotRequestType || (CopilotRequestType = {}));
1298
+ (0, import_type_graphql.registerEnumType)(MessageRole, {
1299
+ name: "MessageRole",
1300
+ description: "The role of the message"
1301
+ });
1302
+ (0, import_type_graphql.registerEnumType)(ActionExecutionScope, {
1303
+ name: "ActionExecutionScope",
1304
+ description: "The scope of the action"
1305
+ });
1306
+ (0, import_type_graphql.registerEnumType)(CopilotRequestType, {
1307
+ name: "CopilotRequestType",
1308
+ description: "The type of Copilot request"
1309
+ });
1310
+
1311
+ // src/lib/runtime/remote-lg-cloud-action.ts
1312
+ async function execute(args) {
1313
+ return new ReadableStream({
1314
+ async start(controller) {
1315
+ try {
1316
+ await streamEvents(controller, args);
1317
+ controller.close();
1318
+ } catch (err) {
1319
+ }
1320
+ }
1321
+ });
1315
1322
  }
1316
- __name(isLangGraphAgentAction, "isLangGraphAgentAction");
1317
- function createHeaders(onBeforeRequest, graphqlContext) {
1318
- const headers = {
1319
- "Content-Type": "application/json"
1323
+ __name(execute, "execute");
1324
+ async function streamEvents(controller, args) {
1325
+ const { deploymentUrl, langsmithApiKey, threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions } = args;
1326
+ let nodeName = initialNodeName;
1327
+ let state = initialState;
1328
+ const { name, assistantId: initialAssistantId } = agent;
1329
+ const client = new import_langgraph_sdk.Client({
1330
+ apiUrl: deploymentUrl,
1331
+ apiKey: langsmithApiKey
1332
+ });
1333
+ let initialThreadId = agrsInitialThreadId;
1334
+ const wasInitiatedWithExistingThread = !!initialThreadId;
1335
+ if (initialThreadId && initialThreadId.startsWith("ck-")) {
1336
+ initialThreadId = initialThreadId.substring(3);
1337
+ }
1338
+ const assistants = await client.assistants.search();
1339
+ const retrievedAssistant = assistants.find((a) => a.name === name);
1340
+ const threadId = initialThreadId ?? (0, import_node_crypto.randomUUID)();
1341
+ if (initialThreadId === threadId) {
1342
+ await client.threads.get(threadId);
1343
+ } else {
1344
+ await client.threads.create({
1345
+ threadId
1346
+ });
1347
+ }
1348
+ let agentState = {
1349
+ values: {}
1320
1350
  };
1321
- if (onBeforeRequest) {
1322
- const { headers: additionalHeaders } = onBeforeRequest({
1323
- ctx: graphqlContext
1351
+ if (wasInitiatedWithExistingThread) {
1352
+ agentState = await client.threads.getState(threadId);
1353
+ }
1354
+ const agentStateValues = agentState.values;
1355
+ state.messages = agentStateValues.messages;
1356
+ const mode = wasInitiatedWithExistingThread && nodeName != "__end__" ? "continue" : "start";
1357
+ state = langGraphDefaultMergeState(state, formatMessages(messages), actions);
1358
+ if (mode === "continue") {
1359
+ await client.threads.updateState(threadId, {
1360
+ values: state,
1361
+ asNode: nodeName
1324
1362
  });
1325
- if (additionalHeaders) {
1326
- Object.assign(headers, additionalHeaders);
1363
+ }
1364
+ const assistantId = initialAssistantId ?? retrievedAssistant.assistant_id;
1365
+ const graphInfo = await client.assistants.getGraph(assistantId);
1366
+ const streamInput = mode === "start" ? state : null;
1367
+ let streamingStateExtractor = new StreamingStateExtractor([]);
1368
+ let prevNodeName = null;
1369
+ let emitIntermediateStateUntilEnd = null;
1370
+ let shouldExit = null;
1371
+ let externalRunId = null;
1372
+ const streamResponse2 = client.runs.stream(threadId, assistantId, {
1373
+ input: streamInput,
1374
+ streamMode: [
1375
+ "events",
1376
+ "values"
1377
+ ]
1378
+ });
1379
+ const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
1380
+ let latestStateValues = {};
1381
+ for await (const chunk of streamResponse2) {
1382
+ if (![
1383
+ "events",
1384
+ "values"
1385
+ ].includes(chunk.event))
1386
+ continue;
1387
+ if (chunk.event === "values") {
1388
+ latestStateValues = chunk.data;
1389
+ continue;
1390
+ }
1391
+ const event = chunk.data;
1392
+ const currentNodeName = event.name;
1393
+ const eventType = event.event;
1394
+ const runId = event.metadata.run_id;
1395
+ externalRunId = runId;
1396
+ const metadata = event.metadata;
1397
+ shouldExit = shouldExit != null ? shouldExit : metadata["copilotkit:exit"];
1398
+ const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
1399
+ const forceEmitIntermediateState = metadata["copilotkit:force-emit-intermediate-state"];
1400
+ const manuallyEmitMessage = metadata["copilotkit:manually-emit-messages"];
1401
+ const manuallyEmitToolCall = metadata["copilotkit:manually-emit-tool-calls"];
1402
+ if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
1403
+ nodeName = currentNodeName;
1404
+ }
1405
+ if (!nodeName) {
1406
+ continue;
1407
+ }
1408
+ if (forceEmitIntermediateState) {
1409
+ if (eventType === "on_chain_end") {
1410
+ state = event.data.output;
1411
+ emit(getStateSyncEvent({
1412
+ threadId,
1413
+ runId,
1414
+ agentName: agent.name,
1415
+ nodeName,
1416
+ state: event.data.output,
1417
+ running: true,
1418
+ active: true
1419
+ }));
1420
+ }
1421
+ continue;
1422
+ }
1423
+ if (manuallyEmitMessage) {
1424
+ if (eventType === "on_chain_end") {
1425
+ state = event.data.output;
1426
+ emit(JSON.stringify({
1427
+ event: "on_copilotkit_emit_message",
1428
+ message: event.data.output,
1429
+ messageId: (0, import_node_crypto.randomUUID)(),
1430
+ role: MessageRole.assistant
1431
+ }) + "\n");
1432
+ }
1433
+ continue;
1434
+ }
1435
+ if (manuallyEmitToolCall) {
1436
+ if (eventType === "on_chain_end") {
1437
+ state = event.data.output;
1438
+ emit(JSON.stringify({
1439
+ event: "on_copilotkit_emit_tool_call",
1440
+ name: event.data.output.name,
1441
+ args: event.data.output.args,
1442
+ id: event.data.output.id
1443
+ }) + "\n");
1444
+ }
1445
+ continue;
1446
+ }
1447
+ if (emitIntermediateState && emitIntermediateStateUntilEnd == null) {
1448
+ emitIntermediateStateUntilEnd = nodeName;
1327
1449
  }
1450
+ if (emitIntermediateState && eventType === "on_chat_model_start") {
1451
+ streamingStateExtractor = new StreamingStateExtractor(emitIntermediateState);
1452
+ }
1453
+ let updatedState = latestStateValues;
1454
+ if (emitIntermediateState && eventType === "on_chat_model_stream") {
1455
+ streamingStateExtractor.bufferToolCalls(event);
1456
+ }
1457
+ if (emitIntermediateStateUntilEnd !== null) {
1458
+ updatedState = {
1459
+ ...updatedState,
1460
+ ...streamingStateExtractor.extractState()
1461
+ };
1462
+ }
1463
+ if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === "on_chain_end") {
1464
+ emitIntermediateStateUntilEnd = null;
1465
+ }
1466
+ const exitingNode = nodeName === currentNodeName && eventType === "on_chain_end";
1467
+ if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
1468
+ state = updatedState;
1469
+ prevNodeName = nodeName;
1470
+ emit(getStateSyncEvent({
1471
+ threadId,
1472
+ runId,
1473
+ agentName: agent.name,
1474
+ nodeName,
1475
+ state,
1476
+ running: true,
1477
+ active: !exitingNode
1478
+ }));
1479
+ }
1480
+ emit(JSON.stringify(event) + "\n");
1328
1481
  }
1329
- return headers;
1482
+ state = await client.threads.getState(threadId);
1483
+ const isEndNode = state.next.length === 0;
1484
+ nodeName = Object.keys(state.metadata.writes)[0];
1485
+ emit(getStateSyncEvent({
1486
+ threadId,
1487
+ runId: externalRunId,
1488
+ agentName: agent.name,
1489
+ nodeName: isEndNode ? "__end__" : nodeName,
1490
+ state: state.values,
1491
+ running: !shouldExit,
1492
+ active: false
1493
+ }));
1494
+ return Promise.resolve();
1330
1495
  }
1331
- __name(createHeaders, "createHeaders");
1332
- async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
1333
- logger2.debug({
1334
- url
1335
- }, "Fetching actions from url");
1336
- const headers = createHeaders(onBeforeRequest, graphqlContext);
1337
- try {
1338
- const response = await fetch(`${url}/info`, {
1339
- method: "POST",
1340
- headers,
1341
- body: JSON.stringify({
1342
- properties: graphqlContext.properties,
1343
- frontendUrl
1344
- })
1345
- });
1346
- if (!response.ok) {
1347
- logger2.error({
1348
- url,
1349
- status: response.status,
1350
- body: await response.text()
1351
- }, "Failed to fetch actions from url");
1496
+ __name(streamEvents, "streamEvents");
1497
+ function getStateSyncEvent({ threadId, runId, agentName, nodeName, state, running, active }) {
1498
+ const stateWithoutMessages = Object.keys(state).reduce((acc, key) => {
1499
+ if (key !== "messages") {
1500
+ acc[key] = state[key];
1501
+ }
1502
+ return acc;
1503
+ }, {});
1504
+ return JSON.stringify({
1505
+ event: "on_copilotkit_state_sync",
1506
+ thread_id: threadId,
1507
+ run_id: runId,
1508
+ agent_name: agentName,
1509
+ node_name: nodeName,
1510
+ active,
1511
+ state: stateWithoutMessages,
1512
+ running,
1513
+ role: "assistant"
1514
+ }) + "\n";
1515
+ }
1516
+ __name(getStateSyncEvent, "getStateSyncEvent");
1517
+ var StreamingStateExtractor = /* @__PURE__ */ __name(class StreamingStateExtractor2 {
1518
+ emitIntermediateState;
1519
+ toolCallBuffer;
1520
+ currentToolCall;
1521
+ previouslyParsableState;
1522
+ constructor(emitIntermediateState) {
1523
+ this.emitIntermediateState = emitIntermediateState;
1524
+ this.toolCallBuffer = {};
1525
+ this.currentToolCall = null;
1526
+ this.previouslyParsableState = {};
1527
+ }
1528
+ bufferToolCalls(event) {
1529
+ if (event.data.chunk.tool_call_chunks.length > 0) {
1530
+ const chunk = event.data.chunk.tool_call_chunks[0];
1531
+ if (chunk.name !== null) {
1532
+ this.currentToolCall = chunk.name;
1533
+ this.toolCallBuffer[this.currentToolCall] = chunk.args;
1534
+ } else if (this.currentToolCall !== null) {
1535
+ this.toolCallBuffer[this.currentToolCall] += chunk.args;
1536
+ }
1537
+ }
1538
+ }
1539
+ getEmitStateConfig(currentToolName) {
1540
+ for (const config2 of this.emitIntermediateState) {
1541
+ const stateKey = config2["state_key"];
1542
+ const tool = config2["tool"];
1543
+ const toolArgument = config2["tool_argument"];
1544
+ if (currentToolName === tool) {
1545
+ return [
1546
+ toolArgument,
1547
+ stateKey
1548
+ ];
1549
+ }
1550
+ }
1551
+ return [
1552
+ null,
1553
+ null
1554
+ ];
1555
+ }
1556
+ extractState() {
1557
+ const state = {};
1558
+ for (const [key, value] of Object.entries(this.toolCallBuffer)) {
1559
+ const [argumentName, stateKey] = this.getEmitStateConfig(key);
1560
+ if (stateKey === null) {
1561
+ continue;
1562
+ }
1563
+ let parsedValue;
1564
+ try {
1565
+ parsedValue = (0, import_partial_json.parse)(value);
1566
+ } catch (error) {
1567
+ if (key in this.previouslyParsableState) {
1568
+ parsedValue = this.previouslyParsableState[key];
1569
+ } else {
1570
+ continue;
1571
+ }
1572
+ }
1573
+ this.previouslyParsableState[key] = parsedValue;
1574
+ if (!argumentName) {
1575
+ state[stateKey] = parsedValue;
1576
+ } else {
1577
+ state[stateKey] = parsedValue[argumentName];
1578
+ }
1579
+ }
1580
+ return state;
1581
+ }
1582
+ }, "StreamingStateExtractor");
1583
+ function langGraphDefaultMergeState(state, messages, actions) {
1584
+ if (messages.length > 0 && "role" in messages[0] && messages[0].role === "system") {
1585
+ messages = messages.slice(1);
1586
+ }
1587
+ const mergedMessages = state.messages || [];
1588
+ const existingMessageIds = new Set(mergedMessages.map((message) => message.id));
1589
+ for (const message of messages) {
1590
+ if (!existingMessageIds.has(message.id)) {
1591
+ mergedMessages.push(message);
1592
+ }
1593
+ }
1594
+ return deepMerge(state, {
1595
+ messages: mergedMessages,
1596
+ copilotkit: {
1597
+ actions
1598
+ }
1599
+ });
1600
+ }
1601
+ __name(langGraphDefaultMergeState, "langGraphDefaultMergeState");
1602
+ function deepMerge(obj1, obj2) {
1603
+ let result = {
1604
+ ...obj1
1605
+ };
1606
+ for (let key in obj2) {
1607
+ if (typeof obj2[key] === "object" && !Array.isArray(obj2[key])) {
1608
+ if (obj1[key]) {
1609
+ result[key] = deepMerge(obj1[key], obj2[key]);
1610
+ } else {
1611
+ result[key] = {
1612
+ ...obj2[key]
1613
+ };
1614
+ }
1615
+ } else {
1616
+ result[key] = obj2[key];
1617
+ }
1618
+ }
1619
+ return result;
1620
+ }
1621
+ __name(deepMerge, "deepMerge");
1622
+ function formatMessages(messages) {
1623
+ return messages.map((message) => {
1624
+ if ("content" in message) {
1625
+ return message;
1626
+ }
1627
+ if ("arguments" in message) {
1628
+ const toolCall = {
1629
+ name: message["name"],
1630
+ args: message["arguments"],
1631
+ id: message["id"]
1632
+ };
1352
1633
  return {
1353
- actions: [],
1354
- agents: []
1634
+ ...message,
1635
+ content: "",
1636
+ tool_calls: [
1637
+ toolCall
1638
+ ],
1639
+ role: message["role"] ?? MessageRole.assistant
1355
1640
  };
1356
1641
  }
1357
- const json = await response.json();
1358
- logger2.debug({
1359
- json
1360
- }, "Fetched actions from url");
1361
- return json;
1362
- } catch (error) {
1363
- logger2.error({
1364
- error: error.message ? error.message : error + ""
1365
- }, "Failed to fetch actions from url");
1366
- return {
1367
- actions: [],
1368
- agents: []
1369
- };
1370
- }
1642
+ if ("actionExecutionId" in message) {
1643
+ return {
1644
+ ...message,
1645
+ content: message["result"],
1646
+ name: message["actionName"],
1647
+ tool_call_id: message["actionExecutionId"],
1648
+ role: message["role"] ?? MessageRole.user
1649
+ };
1650
+ }
1651
+ return message;
1652
+ });
1371
1653
  }
1372
- __name(fetchRemoteInfo, "fetchRemoteInfo");
1654
+ __name(formatMessages, "formatMessages");
1655
+
1656
+ // src/lib/runtime/remote-action-constructors.ts
1657
+ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
1658
+ const agents = endpoint.agents.map((agent) => ({
1659
+ name: agent.name,
1660
+ description: agent.description,
1661
+ parameters: [],
1662
+ handler: async (_args) => {
1663
+ },
1664
+ langGraphAgentHandler: async ({ name, actionInputsWithoutAgents, threadId, nodeName }) => {
1665
+ var _a;
1666
+ logger2.debug({
1667
+ actionName: agent.name
1668
+ }, "Executing LangGraph Cloud agent");
1669
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
1670
+ let state = {};
1671
+ if (agentStates) {
1672
+ const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
1673
+ if (jsonState) {
1674
+ state = JSON.parse(jsonState);
1675
+ }
1676
+ }
1677
+ try {
1678
+ const response = await execute({
1679
+ deploymentUrl: endpoint.deploymentUrl,
1680
+ langsmithApiKey: endpoint.langsmithApiKey,
1681
+ agent,
1682
+ threadId,
1683
+ nodeName,
1684
+ messages,
1685
+ state,
1686
+ properties: graphqlContext.properties,
1687
+ actions: actionInputsWithoutAgents.map((action) => ({
1688
+ name: action.name,
1689
+ description: action.description,
1690
+ parameters: JSON.parse(action.jsonSchema)
1691
+ }))
1692
+ });
1693
+ const eventSource = new RemoteLangGraphEventSource();
1694
+ streamResponse(response, eventSource.eventStream$);
1695
+ return eventSource.processLangGraphEvents();
1696
+ } catch (error) {
1697
+ logger2.error({
1698
+ url: endpoint.deploymentUrl,
1699
+ status: 500,
1700
+ body: error.message
1701
+ }, "Failed to execute LangGraph Cloud agent");
1702
+ throw new Error("Failed to execute LangGraph Cloud agent");
1703
+ }
1704
+ }
1705
+ }));
1706
+ return [
1707
+ ...agents
1708
+ ];
1709
+ }
1710
+ __name(constructLGCRemoteAction, "constructLGCRemoteAction");
1373
1711
  function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, logger: logger2, messages, agentStates }) {
1374
1712
  const actions = json["actions"].map((action) => ({
1375
1713
  name: action.name,
@@ -1461,7 +1799,7 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1461
1799
  throw new Error("Failed to execute remote agent");
1462
1800
  }
1463
1801
  const eventSource = new RemoteLangGraphEventSource();
1464
- eventSource.streamResponse(response);
1802
+ streamResponse(response.body, eventSource.eventStream$);
1465
1803
  return eventSource.processLangGraphEvents();
1466
1804
  }
1467
1805
  }));
@@ -1471,34 +1809,165 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1471
1809
  ];
1472
1810
  }
1473
1811
  __name(constructRemoteActions, "constructRemoteActions");
1474
- async function setupRemoteActions({ remoteActionDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
1812
+ async function streamResponse(response, eventStream$) {
1813
+ const reader = response.getReader();
1814
+ const decoder = new TextDecoder();
1815
+ let buffer = [];
1816
+ function flushBuffer() {
1817
+ const currentBuffer = buffer.join("");
1818
+ if (currentBuffer.trim().length === 0) {
1819
+ return;
1820
+ }
1821
+ const parts = currentBuffer.split("\n");
1822
+ if (parts.length === 0) {
1823
+ return;
1824
+ }
1825
+ const lastPartIsComplete = currentBuffer.endsWith("\n");
1826
+ buffer = [];
1827
+ if (!lastPartIsComplete) {
1828
+ buffer.push(parts.pop());
1829
+ }
1830
+ parts.map((part) => part.trim()).filter((part) => part != "").forEach((part) => {
1831
+ eventStream$.next(JSON.parse(part));
1832
+ });
1833
+ }
1834
+ __name(flushBuffer, "flushBuffer");
1835
+ try {
1836
+ while (true) {
1837
+ const { done, value } = await reader.read();
1838
+ if (!done) {
1839
+ buffer.push(decoder.decode(value, {
1840
+ stream: true
1841
+ }));
1842
+ }
1843
+ flushBuffer();
1844
+ if (done) {
1845
+ break;
1846
+ }
1847
+ }
1848
+ } catch (error) {
1849
+ console.error("Error in stream", error);
1850
+ eventStream$.error(error);
1851
+ return;
1852
+ }
1853
+ eventStream$.complete();
1854
+ }
1855
+ __name(streamResponse, "streamResponse");
1856
+ function createHeaders(onBeforeRequest, graphqlContext) {
1857
+ const headers = {
1858
+ "Content-Type": "application/json"
1859
+ };
1860
+ if (onBeforeRequest) {
1861
+ const { headers: additionalHeaders } = onBeforeRequest({
1862
+ ctx: graphqlContext
1863
+ });
1864
+ if (additionalHeaders) {
1865
+ Object.assign(headers, additionalHeaders);
1866
+ }
1867
+ }
1868
+ return headers;
1869
+ }
1870
+ __name(createHeaders, "createHeaders");
1871
+
1872
+ // src/lib/runtime/remote-actions.ts
1873
+ var EndpointType;
1874
+ (function(EndpointType2) {
1875
+ EndpointType2["CopilotKit"] = "copilotKit";
1876
+ EndpointType2["LangGraphCloud"] = "langgraph-cloud";
1877
+ })(EndpointType || (EndpointType = {}));
1878
+ function isLangGraphAgentAction(action) {
1879
+ if (!action) {
1880
+ return false;
1881
+ }
1882
+ return typeof action.langGraphAgentHandler === "function";
1883
+ }
1884
+ __name(isLangGraphAgentAction, "isLangGraphAgentAction");
1885
+ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: logger2, frontendUrl }) {
1886
+ logger2.debug({
1887
+ url
1888
+ }, "Fetching actions from url");
1889
+ const headers = createHeaders(onBeforeRequest, graphqlContext);
1890
+ try {
1891
+ const response = await fetch(`${url}/info`, {
1892
+ method: "POST",
1893
+ headers,
1894
+ body: JSON.stringify({
1895
+ properties: graphqlContext.properties,
1896
+ frontendUrl
1897
+ })
1898
+ });
1899
+ if (!response.ok) {
1900
+ logger2.error({
1901
+ url,
1902
+ status: response.status,
1903
+ body: await response.text()
1904
+ }, "Failed to fetch actions from url");
1905
+ return {
1906
+ actions: [],
1907
+ agents: []
1908
+ };
1909
+ }
1910
+ const json = await response.json();
1911
+ logger2.debug({
1912
+ json
1913
+ }, "Fetched actions from url");
1914
+ return json;
1915
+ } catch (error) {
1916
+ logger2.error({
1917
+ error: error.message ? error.message : error + ""
1918
+ }, "Failed to fetch actions from url");
1919
+ return {
1920
+ actions: [],
1921
+ agents: []
1922
+ };
1923
+ }
1924
+ }
1925
+ __name(fetchRemoteInfo, "fetchRemoteInfo");
1926
+ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, messages, agentStates, frontendUrl }) {
1475
1927
  const logger2 = graphqlContext.logger.child({
1476
1928
  component: "remote-actions.fetchRemoteActions"
1477
1929
  });
1478
1930
  logger2.debug({
1479
- remoteActionDefinitions
1480
- }, "Fetching remote actions");
1481
- const filtered = remoteActionDefinitions.filter((value, index, self) => index === self.findIndex((t) => t.url === value.url));
1482
- const result = await Promise.all(filtered.map(async (actionDefinition) => {
1931
+ remoteEndpointDefinitions
1932
+ }, "Fetching from remote endpoints");
1933
+ const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
1934
+ if (value.type === "langgraph-cloud") {
1935
+ return value;
1936
+ }
1937
+ return index === self.findIndex((t) => t.url === value.url);
1938
+ });
1939
+ const result = await Promise.all(filtered.map(async (endpoint) => {
1940
+ if (endpoint.type === "langgraph-cloud") {
1941
+ return constructLGCRemoteAction({
1942
+ endpoint,
1943
+ messages,
1944
+ graphqlContext,
1945
+ logger: logger2.child({
1946
+ component: "remote-actions.constructLGCRemoteAction",
1947
+ endpoint
1948
+ }),
1949
+ agentStates
1950
+ });
1951
+ }
1483
1952
  const json = await fetchRemoteInfo({
1484
- url: actionDefinition.url,
1485
- onBeforeRequest: actionDefinition.onBeforeRequest,
1953
+ url: endpoint.url,
1954
+ onBeforeRequest: endpoint.onBeforeRequest,
1486
1955
  graphqlContext,
1487
1956
  logger: logger2.child({
1488
1957
  component: "remote-actions.fetchActionsFromUrl",
1489
- actionDefinition
1958
+ endpoint
1490
1959
  }),
1491
1960
  frontendUrl
1492
1961
  });
1493
1962
  return constructRemoteActions({
1494
1963
  json,
1495
1964
  messages,
1496
- url: actionDefinition.url,
1497
- onBeforeRequest: actionDefinition.onBeforeRequest,
1965
+ url: endpoint.url,
1966
+ onBeforeRequest: endpoint.onBeforeRequest,
1498
1967
  graphqlContext,
1499
1968
  logger: logger2.child({
1500
1969
  component: "remote-actions.constructActions",
1501
- actionDefinition
1970
+ endpoint
1502
1971
  }),
1503
1972
  agentStates
1504
1973
  });
@@ -1662,13 +2131,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
1662
2131
  }
1663
2132
  let args = [];
1664
2133
  if (actionArguments) {
1665
- try {
1666
- args = JSON.parse(actionArguments);
1667
- } catch (e) {
1668
- console.warn("Action argument unparsable", {
1669
- actionArguments
1670
- });
1671
- }
2134
+ args = JSON.parse(actionArguments);
1672
2135
  }
1673
2136
  if (isLangGraphAgentAction(action)) {
1674
2137
  eventStream$.sendActionExecutionResult(actionExecutionId, action.name, `${action.name} agent started`);
@@ -1696,7 +2159,7 @@ async function executeAction(eventStream$, guardrailsResult$, action, actionArgu
1696
2159
  __name(executeAction, "executeAction");
1697
2160
 
1698
2161
  // src/graphql/types/base/index.ts
1699
- var import_type_graphql = require("type-graphql");
2162
+ var import_type_graphql2 = require("type-graphql");
1700
2163
  function _ts_decorate(decorators, target, key, desc) {
1701
2164
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1702
2165
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -1719,15 +2182,15 @@ var BaseMessageInput = class {
1719
2182
  };
1720
2183
  __name(BaseMessageInput, "BaseMessageInput");
1721
2184
  _ts_decorate([
1722
- (0, import_type_graphql.Field)(() => String),
2185
+ (0, import_type_graphql2.Field)(() => String),
1723
2186
  _ts_metadata("design:type", String)
1724
2187
  ], BaseMessageInput.prototype, "id", void 0);
1725
2188
  _ts_decorate([
1726
- (0, import_type_graphql.Field)(() => Date),
2189
+ (0, import_type_graphql2.Field)(() => Date),
1727
2190
  _ts_metadata("design:type", typeof Date === "undefined" ? Object : Date)
1728
2191
  ], BaseMessageInput.prototype, "createdAt", void 0);
1729
2192
  BaseMessageInput = _ts_decorate([
1730
- (0, import_type_graphql.InputType)()
2193
+ (0, import_type_graphql2.InputType)()
1731
2194
  ], BaseMessageInput);
1732
2195
 
1733
2196
  // src/graphql/types/converted/index.ts
@@ -1831,7 +2294,7 @@ __name(convertGqlInputToMessages, "convertGqlInputToMessages");
1831
2294
  var import_rxjs3 = require("rxjs");
1832
2295
  var CopilotRuntime = class {
1833
2296
  actions;
1834
- remoteActionDefinitions;
2297
+ remoteEndpointDefinitions;
1835
2298
  langserve = [];
1836
2299
  onBeforeRequest;
1837
2300
  onAfterRequest;
@@ -1842,7 +2305,7 @@ var CopilotRuntime = class {
1842
2305
  const remoteChain = new RemoteChain(chain);
1843
2306
  this.langserve.push(remoteChain.toAction());
1844
2307
  }
1845
- this.remoteActionDefinitions = (params == null ? void 0 : params.remoteActions) || [];
2308
+ this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
1846
2309
  this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
1847
2310
  this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
1848
2311
  }
@@ -1911,7 +2374,7 @@ var CopilotRuntime = class {
1911
2374
  async processAgentRequest(request) {
1912
2375
  var _a;
1913
2376
  const { messages: rawMessages, outputMessagesPromise, graphqlContext, agentSession } = request;
1914
- const { threadId = (0, import_shared8.randomId)(), agentName, nodeName } = agentSession;
2377
+ const { threadId, agentName, nodeName } = agentSession;
1915
2378
  const serverSideActions = await this.getServerSideActions(request);
1916
2379
  const messages = convertGqlInputToMessages(rawMessages);
1917
2380
  const agent = serverSideActions.find((action) => action.name === agentName && isLangGraphAgentAction(action));
@@ -1983,8 +2446,12 @@ var CopilotRuntime = class {
1983
2446
  console.error("Error loading langserve chain:", error);
1984
2447
  }
1985
2448
  }
2449
+ const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
2450
+ ...endpoint,
2451
+ type: this.resolveEndpointType(endpoint)
2452
+ }));
1986
2453
  const remoteActions = await setupRemoteActions({
1987
- remoteActionDefinitions: this.remoteActionDefinitions,
2454
+ remoteEndpointDefinitions,
1988
2455
  graphqlContext,
1989
2456
  messages: inputMessages,
1990
2457
  agentStates,
@@ -2000,6 +2467,12 @@ var CopilotRuntime = class {
2000
2467
  ...remoteActions
2001
2468
  ];
2002
2469
  }
2470
+ resolveEndpointType(endpoint) {
2471
+ if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
2472
+ return EndpointType.LangGraphCloud;
2473
+ }
2474
+ return endpoint.type;
2475
+ }
2003
2476
  };
2004
2477
  __name(CopilotRuntime, "CopilotRuntime");
2005
2478
  function flattenToolCallsNoDuplicates(toolsByPriority) {
@@ -2014,6 +2487,20 @@ function flattenToolCallsNoDuplicates(toolsByPriority) {
2014
2487
  return allTools;
2015
2488
  }
2016
2489
  __name(flattenToolCallsNoDuplicates, "flattenToolCallsNoDuplicates");
2490
+ function copilotKitEndpoint(config2) {
2491
+ return {
2492
+ ...config2,
2493
+ type: EndpointType.CopilotKit
2494
+ };
2495
+ }
2496
+ __name(copilotKitEndpoint, "copilotKitEndpoint");
2497
+ function langGraphCloudEndpoint(config2) {
2498
+ return {
2499
+ ...config2,
2500
+ type: EndpointType.LangGraphCloud
2501
+ };
2502
+ }
2503
+ __name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
2017
2504
 
2018
2505
  // src/lib/integrations/shared.ts
2019
2506
  var import_type_graphql16 = require("type-graphql");
@@ -2027,43 +2514,6 @@ var import_type_graphql11 = require("type-graphql");
2027
2514
 
2028
2515
  // src/graphql/inputs/message.input.ts
2029
2516
  var import_type_graphql3 = require("type-graphql");
2030
-
2031
- // src/graphql/types/enums.ts
2032
- var import_type_graphql2 = require("type-graphql");
2033
- var MessageRole;
2034
- (function(MessageRole2) {
2035
- MessageRole2["user"] = "user";
2036
- MessageRole2["assistant"] = "assistant";
2037
- MessageRole2["system"] = "system";
2038
- })(MessageRole || (MessageRole = {}));
2039
- var ActionExecutionScope;
2040
- (function(ActionExecutionScope2) {
2041
- ActionExecutionScope2["server"] = "server";
2042
- ActionExecutionScope2["client"] = "client";
2043
- ActionExecutionScope2["passThrough"] = "passThrough";
2044
- })(ActionExecutionScope || (ActionExecutionScope = {}));
2045
- var CopilotRequestType;
2046
- (function(CopilotRequestType2) {
2047
- CopilotRequestType2["Chat"] = "Chat";
2048
- CopilotRequestType2["Task"] = "Task";
2049
- CopilotRequestType2["TextareaCompletion"] = "TextareaCompletion";
2050
- CopilotRequestType2["TextareaPopover"] = "TextareaPopover";
2051
- CopilotRequestType2["Suggestion"] = "Suggestion";
2052
- })(CopilotRequestType || (CopilotRequestType = {}));
2053
- (0, import_type_graphql2.registerEnumType)(MessageRole, {
2054
- name: "MessageRole",
2055
- description: "The role of the message"
2056
- });
2057
- (0, import_type_graphql2.registerEnumType)(ActionExecutionScope, {
2058
- name: "ActionExecutionScope",
2059
- description: "The scope of the action"
2060
- });
2061
- (0, import_type_graphql2.registerEnumType)(CopilotRequestType, {
2062
- name: "CopilotRequestType",
2063
- description: "The type of Copilot request"
2064
- });
2065
-
2066
- // src/graphql/inputs/message.input.ts
2067
2517
  function _ts_decorate2(decorators, target, key, desc) {
2068
2518
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
2069
2519
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3720,6 +4170,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
3720
4170
  UnifyAdapter,
3721
4171
  buildSchema,
3722
4172
  config,
4173
+ copilotKitEndpoint,
3723
4174
  copilotRuntimeNestEndpoint,
3724
4175
  copilotRuntimeNextJSAppRouterEndpoint,
3725
4176
  copilotRuntimeNextJSPagesRouterEndpoint,
@@ -3727,6 +4178,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
3727
4178
  copilotRuntimeNodeHttpEndpoint,
3728
4179
  createContext,
3729
4180
  flattenToolCallsNoDuplicates,
3730
- getCommonConfig
4181
+ getCommonConfig,
4182
+ langGraphCloudEndpoint
3731
4183
  });
3732
4184
  //# sourceMappingURL=index.js.map