@copilotkit/runtime 1.3.16-mme-lgc-langgraph-package.11 → 1.3.16-mme-revert-rxjs-changes.10

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 (71) hide show
  1. package/CHANGELOG.md +33 -95
  2. package/dist/{chunk-SMHGZXIT.mjs → chunk-3EIBEZQI.mjs} +4 -3
  3. package/dist/chunk-3EIBEZQI.mjs.map +1 -0
  4. package/dist/{chunk-TTVQTORT.mjs → chunk-4MX7GDLS.mjs} +4 -3
  5. package/dist/chunk-4MX7GDLS.mjs.map +1 -0
  6. package/dist/chunk-DFOKBSIS.mjs +1 -0
  7. package/dist/chunk-DFOKBSIS.mjs.map +1 -0
  8. package/dist/{chunk-HZ2XTQUC.mjs → chunk-UO2QXEDA.mjs} +5 -4
  9. package/dist/chunk-UO2QXEDA.mjs.map +1 -0
  10. package/dist/{chunk-BNQDVBQH.mjs → chunk-WHJ3DAYL.mjs} +251 -34
  11. package/dist/chunk-WHJ3DAYL.mjs.map +1 -0
  12. package/dist/{chunk-JTVWJUZP.mjs → chunk-YSCTOGKC.mjs} +419 -50
  13. package/dist/chunk-YSCTOGKC.mjs.map +1 -0
  14. package/dist/{copilot-runtime-8d3f40c7.d.ts → copilot-runtime-335a610d.d.ts} +10 -10
  15. package/dist/{groq-adapter-dbfba3eb.d.ts → groq-adapter-2f8fd767.d.ts} +1 -1
  16. package/dist/index.d.ts +3 -3
  17. package/dist/index.js +215 -98
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +22 -22
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/{langserve-f00629d2.d.ts → langserve-cc06e76e.d.ts} +1 -0
  22. package/dist/lib/index.d.ts +3 -3
  23. package/dist/lib/index.js +215 -98
  24. package/dist/lib/index.js.map +1 -1
  25. package/dist/lib/index.mjs +21 -21
  26. package/dist/lib/integrations/index.d.ts +3 -3
  27. package/dist/lib/integrations/index.js +153 -85
  28. package/dist/lib/integrations/index.js.map +1 -1
  29. package/dist/lib/integrations/index.mjs +5 -5
  30. package/dist/lib/integrations/nest/index.d.ts +2 -2
  31. package/dist/lib/integrations/nest/index.js +150 -82
  32. package/dist/lib/integrations/nest/index.js.map +1 -1
  33. package/dist/lib/integrations/nest/index.mjs +3 -3
  34. package/dist/lib/integrations/node-express/index.d.ts +2 -2
  35. package/dist/lib/integrations/node-express/index.js +150 -82
  36. package/dist/lib/integrations/node-express/index.js.map +1 -1
  37. package/dist/lib/integrations/node-express/index.mjs +3 -3
  38. package/dist/lib/integrations/node-http/index.d.ts +2 -2
  39. package/dist/lib/integrations/node-http/index.js +149 -81
  40. package/dist/lib/integrations/node-http/index.js.map +1 -1
  41. package/dist/lib/integrations/node-http/index.mjs +2 -2
  42. package/dist/service-adapters/index.d.ts +3 -3
  43. package/dist/service-adapters/index.js +31 -18
  44. package/dist/service-adapters/index.js.map +1 -1
  45. package/dist/service-adapters/index.mjs +1 -2
  46. package/package.json +4 -4
  47. package/src/agents/langgraph/event-source.ts +2 -2
  48. package/src/agents/langgraph/events.ts +2 -0
  49. package/src/lib/integrations/nest/index.ts +5 -2
  50. package/src/lib/integrations/nextjs/app-router.ts +5 -2
  51. package/src/lib/integrations/nextjs/pages-router.ts +5 -2
  52. package/src/lib/integrations/node-express/index.ts +5 -2
  53. package/src/lib/integrations/node-http/index.ts +5 -2
  54. package/src/lib/runtime/copilot-runtime.ts +53 -47
  55. package/src/lib/runtime/remote-action-constructors.ts +23 -9
  56. package/src/lib/runtime/remote-actions.ts +9 -9
  57. package/src/lib/runtime/{remote-lg-cloud-action.ts → remote-lg-action.ts} +59 -33
  58. package/src/lib/telemetry-client.ts +43 -0
  59. package/src/service-adapters/events.ts +13 -1
  60. package/src/service-adapters/google/google-genai-adapter.ts +2 -2
  61. package/src/service-adapters/langchain/langchain-adapter.ts +22 -16
  62. package/src/service-adapters/openai/openai-adapter.ts +5 -0
  63. package/dist/chunk-BNQDVBQH.mjs.map +0 -1
  64. package/dist/chunk-GWP2VADN.mjs +0 -288
  65. package/dist/chunk-GWP2VADN.mjs.map +0 -1
  66. package/dist/chunk-HZ2XTQUC.mjs.map +0 -1
  67. package/dist/chunk-JTVWJUZP.mjs.map +0 -1
  68. package/dist/chunk-MXXPWWBF.mjs +0 -218
  69. package/dist/chunk-MXXPWWBF.mjs.map +0 -1
  70. package/dist/chunk-SMHGZXIT.mjs.map +0 -1
  71. package/dist/chunk-TTVQTORT.mjs.map +0 -1
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.16-mme-lgc-langgraph-package.11",
47
+ version: "1.3.16-mme-revert-rxjs-changes.10",
48
48
  sideEffects: false,
49
49
  main: "./dist/index.js",
50
50
  module: "./dist/index.mjs",
@@ -142,12 +142,13 @@ __export(lib_exports, {
142
142
  createContext: () => createContext,
143
143
  flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
144
144
  getCommonConfig: () => getCommonConfig,
145
- langGraphCloudEndpoint: () => langGraphCloudEndpoint
145
+ langGraphPlatformEndpoint: () => langGraphPlatformEndpoint,
146
+ resolveEndpointType: () => resolveEndpointType
146
147
  });
147
148
  module.exports = __toCommonJS(lib_exports);
148
149
 
149
150
  // src/lib/runtime/copilot-runtime.ts
150
- var import_shared8 = require("@copilotkit/shared");
151
+ var import_shared9 = require("@copilotkit/shared");
151
152
 
152
153
  // src/service-adapters/langchain/langserve.ts
153
154
  var import_remote = require("langchain/runnables/remote");
@@ -424,6 +425,9 @@ var OpenAIAdapter = class {
424
425
  var _a, _b;
425
426
  let mode = null;
426
427
  for await (const chunk of stream) {
428
+ if (chunk.choices.length === 0) {
429
+ continue;
430
+ }
427
431
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
428
432
  const content = chunk.choices[0].delta.content;
429
433
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
@@ -672,6 +676,7 @@ __name(encodeResult, "encodeResult");
672
676
 
673
677
  // src/service-adapters/langchain/langchain-adapter.ts
674
678
  var import_shared3 = require("@copilotkit/shared");
679
+ var import_promises = require("@langchain/core/callbacks/promises");
675
680
  var LangChainAdapter = class {
676
681
  options;
677
682
  /**
@@ -681,23 +686,28 @@ var LangChainAdapter = class {
681
686
  this.options = options;
682
687
  }
683
688
  async process(request) {
684
- const { eventSource, model, actions, messages, threadId, runId } = request;
685
- const result = await this.options.chainFn({
686
- messages: messages.map(convertMessageToLangChainMessage),
687
- tools: actions.map(convertActionInputToLangChainTool),
688
- model,
689
- threadId,
690
- runId
691
- });
692
- eventSource.stream(async (eventStream$) => {
693
- await streamLangChainResponse({
694
- result,
695
- eventStream$
689
+ try {
690
+ const { eventSource, model, actions, messages, runId } = request;
691
+ const threadId = request.threadId ?? (0, import_shared3.randomId)();
692
+ const result = await this.options.chainFn({
693
+ messages: messages.map(convertMessageToLangChainMessage),
694
+ tools: actions.map(convertActionInputToLangChainTool),
695
+ model,
696
+ threadId,
697
+ runId
696
698
  });
697
- });
698
- return {
699
- threadId: threadId || (0, import_shared3.randomId)()
700
- };
699
+ eventSource.stream(async (eventStream$) => {
700
+ await streamLangChainResponse({
701
+ result,
702
+ eventStream$
703
+ });
704
+ });
705
+ return {
706
+ threadId
707
+ };
708
+ } finally {
709
+ await (0, import_promises.awaitAllCallbacks)();
710
+ }
701
711
  }
702
712
  };
703
713
  __name(LangChainAdapter, "LangChainAdapter");
@@ -707,12 +717,16 @@ var import_google_gauth = require("@langchain/google-gauth");
707
717
  var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
708
718
  constructor(options) {
709
719
  super({
710
- chainFn: async ({ messages, tools }) => {
720
+ chainFn: async ({ messages, tools, threadId }) => {
711
721
  const model = new import_google_gauth.ChatGoogle({
712
722
  modelName: (options == null ? void 0 : options.model) ?? "gemini-1.5-pro",
713
723
  apiVersion: "v1beta"
714
724
  }).bindTools(tools);
715
- return model.stream(messages);
725
+ return model.stream(messages, {
726
+ metadata: {
727
+ conversation_id: threadId
728
+ }
729
+ });
716
730
  }
717
731
  });
718
732
  }
@@ -1058,16 +1072,14 @@ var GroqAdapter = class {
1058
1072
  __name(GroqAdapter, "GroqAdapter");
1059
1073
 
1060
1074
  // src/service-adapters/events.ts
1075
+ var import_shared8 = require("@copilotkit/shared");
1061
1076
  var import_rxjs2 = require("rxjs");
1062
1077
 
1063
1078
  // src/lib/telemetry-client.ts
1064
- var import_shared6 = require("@copilotkit/shared");
1065
- var packageJson = require_package();
1066
- var telemetryClient = new import_shared6.TelemetryClient({
1067
- packageName: packageJson.name,
1068
- packageVersion: packageJson.version
1069
- });
1070
- var telemetry_client_default = telemetryClient;
1079
+ var import_shared7 = require("@copilotkit/shared");
1080
+
1081
+ // src/lib/runtime/remote-action-constructors.ts
1082
+ var import_node_crypto2 = require("crypto");
1071
1083
 
1072
1084
  // src/agents/langgraph/event-source.ts
1073
1085
  var import_rxjs = require("rxjs");
@@ -1084,6 +1096,8 @@ var LangGraphEventTypes;
1084
1096
  LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
1085
1097
  LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
1086
1098
  LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
1099
+ LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
1100
+ LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
1087
1101
  LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
1088
1102
  })(LangGraphEventTypes || (LangGraphEventTypes = {}));
1089
1103
  var CustomEventNames;
@@ -1095,7 +1109,7 @@ var CustomEventNames;
1095
1109
  })(CustomEventNames || (CustomEventNames = {}));
1096
1110
 
1097
1111
  // src/agents/langgraph/event-source.ts
1098
- var import_shared7 = require("@copilotkit/shared");
1112
+ var import_shared6 = require("@copilotkit/shared");
1099
1113
  var RemoteLangGraphEventSource = class {
1100
1114
  eventStream$ = new import_rxjs.ReplaySubject();
1101
1115
  shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
@@ -1121,7 +1135,7 @@ var RemoteLangGraphEventSource = class {
1121
1135
  acc.content = null;
1122
1136
  }
1123
1137
  const toolCallChunks = (
1124
- // @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
1138
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
1125
1139
  ((_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)
1126
1140
  );
1127
1141
  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);
@@ -1281,7 +1295,7 @@ var RemoteLangGraphEventSource = class {
1281
1295
  type: RuntimeEventTypes.ActionExecutionEnd
1282
1296
  });
1283
1297
  }
1284
- const messageId = (0, import_shared7.randomId)();
1298
+ const messageId = (0, import_shared6.randomId)();
1285
1299
  events.push({
1286
1300
  type: RuntimeEventTypes.TextMessageStart,
1287
1301
  messageId
@@ -1299,7 +1313,7 @@ var RemoteLangGraphEventSource = class {
1299
1313
  };
1300
1314
  __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
1301
1315
 
1302
- // src/lib/runtime/remote-lg-cloud-action.ts
1316
+ // src/lib/runtime/remote-lg-action.ts
1303
1317
  var import_langgraph_sdk = require("@langchain/langgraph-sdk");
1304
1318
  var import_node_crypto = require("crypto");
1305
1319
  var import_partial_json = require("partial-json");
@@ -1340,7 +1354,7 @@ var CopilotRequestType;
1340
1354
  description: "The type of Copilot request"
1341
1355
  });
1342
1356
 
1343
- // src/lib/runtime/remote-lg-cloud-action.ts
1357
+ // src/lib/runtime/remote-lg-action.ts
1344
1358
  async function execute(args) {
1345
1359
  return new ReadableStream({
1346
1360
  async start(controller) {
@@ -1354,6 +1368,7 @@ async function execute(args) {
1354
1368
  }
1355
1369
  __name(execute, "execute");
1356
1370
  async function streamEvents(controller, args) {
1371
+ var _a, _b, _c, _d, _e, _f;
1357
1372
  const { deploymentUrl, langsmithApiKey, threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions, logger: logger2 } = args;
1358
1373
  let nodeName = initialNodeName;
1359
1374
  let state = initialState;
@@ -1403,7 +1418,7 @@ async function streamEvents(controller, args) {
1403
1418
  if (!assistantId) {
1404
1419
  console.error(`
1405
1420
  No agent found for the agent name specified in CopilotKit provider
1406
- Please check your available agents or provide an agent ID in the LangGraph Cloud endpoint definition.
1421
+ Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
1407
1422
 
1408
1423
 
1409
1424
  These are the available agents: [${assistants.map((a) => `${a.name} (ID: ${a.assistant_id})`).join(", ")}]
@@ -1427,7 +1442,14 @@ async function streamEvents(controller, args) {
1427
1442
  const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
1428
1443
  let latestStateValues = {};
1429
1444
  let updatedState = state;
1445
+ let manuallyEmittedState = null;
1446
+ let streamInfo = {
1447
+ hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
1448
+ };
1430
1449
  try {
1450
+ telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
1451
+ hashedLgcKey: streamInfo.hashedLgcKey
1452
+ });
1431
1453
  for await (const chunk of streamResponse2) {
1432
1454
  if (![
1433
1455
  "events",
@@ -1449,26 +1471,37 @@ async function streamEvents(controller, args) {
1449
1471
  const runId = event.metadata.run_id;
1450
1472
  externalRunId = runId;
1451
1473
  const metadata = event.metadata;
1474
+ if (((_b = (_a = event.data) == null ? void 0 : _a.output) == null ? void 0 : _b.model) != null && ((_d = (_c = event.data) == null ? void 0 : _c.output) == null ? void 0 : _d.model) != "") {
1475
+ streamInfo.provider = (_f = (_e = event.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
1476
+ }
1477
+ if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
1478
+ streamInfo.langGraphHost = metadata.langgraph_host;
1479
+ }
1480
+ if (metadata.langgraph_version != null && metadata.langgraph_version != "") {
1481
+ streamInfo.langGraphVersion = metadata.langgraph_version;
1482
+ }
1452
1483
  shouldExit = shouldExit || eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitExit;
1453
1484
  const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
1454
1485
  const manuallyEmitIntermediateState = eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState;
1486
+ const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
1487
+ if (exitingNode) {
1488
+ manuallyEmittedState = null;
1489
+ }
1455
1490
  if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
1456
1491
  nodeName = currentNodeName;
1457
- if (eventType === LangGraphEventTypes.OnChainStart || eventType === LangGraphEventTypes.OnChainEnd) {
1458
- updatedState = latestStateValues;
1459
- }
1460
1492
  }
1493
+ updatedState = manuallyEmittedState ?? latestStateValues;
1461
1494
  if (!nodeName) {
1462
1495
  continue;
1463
1496
  }
1464
1497
  if (manuallyEmitIntermediateState) {
1465
- updatedState = event.data;
1498
+ manuallyEmittedState = event.data;
1466
1499
  emit(getStateSyncEvent({
1467
1500
  threadId,
1468
1501
  runId,
1469
1502
  agentName: agent.name,
1470
1503
  nodeName,
1471
- state: updatedState,
1504
+ state: manuallyEmittedState,
1472
1505
  running: true,
1473
1506
  active: true
1474
1507
  }));
@@ -1492,7 +1525,6 @@ async function streamEvents(controller, args) {
1492
1525
  if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === LangGraphEventTypes.OnChainEnd) {
1493
1526
  emitIntermediateStateUntilEnd = null;
1494
1527
  }
1495
- const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
1496
1528
  if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
1497
1529
  state = updatedState;
1498
1530
  prevNodeName = nodeName;
@@ -1511,6 +1543,7 @@ async function streamEvents(controller, args) {
1511
1543
  state = await client.threads.getState(threadId);
1512
1544
  const isEndNode = state.next.length === 0;
1513
1545
  nodeName = Object.keys(state.metadata.writes)[0];
1546
+ telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
1514
1547
  emit(getStateSyncEvent({
1515
1548
  threadId,
1516
1549
  runId: externalRunId,
@@ -1757,8 +1790,13 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
1757
1790
  var _a;
1758
1791
  logger2.debug({
1759
1792
  actionName: agent.name
1760
- }, "Executing LangGraph Cloud agent");
1761
- telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
1793
+ }, "Executing LangGraph Platform agent");
1794
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {
1795
+ agentExecution: true,
1796
+ type: "langgraph-platform",
1797
+ agentsAmount: endpoint.agents.length,
1798
+ hashedLgcKey: (0, import_node_crypto2.createHash)("sha256").update(endpoint.langsmithApiKey).digest("hex")
1799
+ });
1762
1800
  let state = {};
1763
1801
  if (agentStates) {
1764
1802
  const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
@@ -1791,8 +1829,8 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
1791
1829
  url: endpoint.deploymentUrl,
1792
1830
  status: 500,
1793
1831
  body: error.message
1794
- }, "Failed to execute LangGraph Cloud agent");
1795
- throw new Error("Failed to execute LangGraph Cloud agent");
1832
+ }, "Failed to execute LangGraph Platform agent");
1833
+ throw new Error("Failed to execute LangGraph Platform agent");
1796
1834
  }
1797
1835
  }
1798
1836
  }));
@@ -1812,7 +1850,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1812
1850
  args
1813
1851
  }, "Executing remote action");
1814
1852
  const headers = createHeaders(onBeforeRequest, graphqlContext);
1815
- telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
1853
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {
1854
+ agentExecution: false,
1855
+ type: "self-hosted",
1856
+ agentsAmount: json["agents"].length
1857
+ });
1816
1858
  try {
1817
1859
  const response = await fetch(`${url}/actions/execute`, {
1818
1860
  method: "POST",
@@ -1858,7 +1900,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
1858
1900
  actionName: agent.name
1859
1901
  }, "Executing remote agent");
1860
1902
  const headers = createHeaders(onBeforeRequest, graphqlContext);
1861
- telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
1903
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {
1904
+ agentExecution: true,
1905
+ type: "self-hosted",
1906
+ agentsAmount: json["agents"].length
1907
+ });
1862
1908
  let state = {};
1863
1909
  if (agentStates) {
1864
1910
  const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
@@ -1966,7 +2012,7 @@ __name(createHeaders, "createHeaders");
1966
2012
  var EndpointType;
1967
2013
  (function(EndpointType2) {
1968
2014
  EndpointType2["CopilotKit"] = "copilotKit";
1969
- EndpointType2["LangGraphCloud"] = "langgraph-cloud";
2015
+ EndpointType2["LangGraphPlatform"] = "langgraph-platform";
1970
2016
  })(EndpointType || (EndpointType = {}));
1971
2017
  function isLangGraphAgentAction(action) {
1972
2018
  if (!action) {
@@ -2024,13 +2070,13 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
2024
2070
  remoteEndpointDefinitions
2025
2071
  }, "Fetching from remote endpoints");
2026
2072
  const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
2027
- if (value.type === "langgraph-cloud") {
2073
+ if (value.type === "langgraph-platform") {
2028
2074
  return value;
2029
2075
  }
2030
2076
  return index === self.findIndex((t) => t.url === value.url);
2031
2077
  });
2032
2078
  const result = await Promise.all(filtered.map(async (endpoint) => {
2033
- if (endpoint.type === "langgraph-cloud") {
2079
+ if (endpoint.type === "langgraph-platform") {
2034
2080
  return constructLGCRemoteAction({
2035
2081
  endpoint,
2036
2082
  messages,
@@ -2069,6 +2115,53 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
2069
2115
  }
2070
2116
  __name(setupRemoteActions, "setupRemoteActions");
2071
2117
 
2118
+ // src/lib/telemetry-client.ts
2119
+ var import_node_crypto3 = require("crypto");
2120
+ var packageJson = require_package();
2121
+ var telemetryClient = new import_shared7.TelemetryClient({
2122
+ packageName: packageJson.name,
2123
+ packageVersion: packageJson.version
2124
+ });
2125
+ function getRuntimeInstanceTelemetryInfo(runtime) {
2126
+ const endpointsInfo = runtime.remoteEndpointDefinitions.reduce((acc, endpoint) => {
2127
+ let info = {
2128
+ ...acc
2129
+ };
2130
+ const endpointType = resolveEndpointType(endpoint);
2131
+ if (!info.endpointTypes.includes(endpointType)) {
2132
+ info = {
2133
+ ...info,
2134
+ endpointTypes: [
2135
+ ...info.endpointTypes,
2136
+ endpointType
2137
+ ]
2138
+ };
2139
+ }
2140
+ if (endpointType === EndpointType.LangGraphPlatform) {
2141
+ const ep = endpoint;
2142
+ info = {
2143
+ ...info,
2144
+ agentsAmount: ep.agents.length,
2145
+ hashedKey: (0, import_node_crypto3.createHash)("sha256").update(ep.langsmithApiKey).digest("hex")
2146
+ };
2147
+ }
2148
+ return info;
2149
+ }, {
2150
+ endpointTypes: [],
2151
+ agentsAmount: null,
2152
+ hashedKey: null
2153
+ });
2154
+ return {
2155
+ actionsAmount: runtime.actions.length,
2156
+ endpointsAmount: runtime.remoteEndpointDefinitions.length,
2157
+ endpointTypes: endpointsInfo.endpointTypes,
2158
+ agentsAmount: endpointsInfo.agentsAmount,
2159
+ hashedLgcKey: endpointsInfo.hashedKey
2160
+ };
2161
+ }
2162
+ __name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
2163
+ var telemetry_client_default = telemetryClient;
2164
+
2072
2165
  // src/service-adapters/events.ts
2073
2166
  var RuntimeEventTypes;
2074
2167
  (function(RuntimeEventTypes2) {
@@ -2159,9 +2252,20 @@ var RuntimeEventSource = class {
2159
2252
  async stream(callback) {
2160
2253
  this.callback = callback;
2161
2254
  }
2255
+ sendErrorMessageToChat() {
2256
+ const errorMessage = "\u274C An error occurred. Please try again.";
2257
+ if (!this.callback) {
2258
+ this.stream(async (eventStream$) => {
2259
+ eventStream$.sendTextMessage((0, import_shared8.randomId)(), errorMessage);
2260
+ });
2261
+ } else {
2262
+ this.eventStream$.sendTextMessage((0, import_shared8.randomId)(), errorMessage);
2263
+ }
2264
+ }
2162
2265
  processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
2163
2266
  this.callback(this.eventStream$).catch((error) => {
2164
2267
  console.error("Error in event source callback", error);
2268
+ this.sendErrorMessageToChat();
2165
2269
  });
2166
2270
  return this.eventStream$.pipe(
2167
2271
  // mark tools for server side execution
@@ -2404,37 +2508,37 @@ var CopilotRuntime = class {
2404
2508
  const remoteChain = new RemoteChain(chain);
2405
2509
  this.langserve.push(remoteChain.toAction());
2406
2510
  }
2407
- this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
2511
+ this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) ?? (params == null ? void 0 : params.remoteActions) ?? [];
2408
2512
  this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
2409
2513
  this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
2410
2514
  }
2411
2515
  async processRuntimeRequest(request) {
2412
2516
  var _a;
2413
2517
  const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, agentSession, url } = request;
2414
- if (agentSession) {
2415
- return this.processAgentRequest(request);
2416
- }
2417
- const messages = rawMessages.filter((message) => !message.agentStateMessage);
2418
- const inputMessages = convertGqlInputToMessages(messages);
2419
- const serverSideActions = await this.getServerSideActions(request);
2420
- const serverSideActionsInput = serverSideActions.map((action) => ({
2421
- name: action.name,
2422
- description: action.description,
2423
- jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters))
2424
- }));
2425
- const actionInputs = flattenToolCallsNoDuplicates([
2426
- ...serverSideActionsInput,
2427
- ...clientSideActionsInput
2428
- ]);
2429
- await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
2430
- threadId,
2431
- runId,
2432
- inputMessages,
2433
- properties: graphqlContext.properties,
2434
- url
2435
- }));
2518
+ const eventSource = new RuntimeEventSource();
2436
2519
  try {
2437
- const eventSource = new RuntimeEventSource();
2520
+ if (agentSession) {
2521
+ return await this.processAgentRequest(request);
2522
+ }
2523
+ const messages = rawMessages.filter((message) => !message.agentStateMessage);
2524
+ const inputMessages = convertGqlInputToMessages(messages);
2525
+ const serverSideActions = await this.getServerSideActions(request);
2526
+ const serverSideActionsInput = serverSideActions.map((action) => ({
2527
+ name: action.name,
2528
+ description: action.description,
2529
+ jsonSchema: JSON.stringify((0, import_shared9.actionParametersToJsonSchema)(action.parameters))
2530
+ }));
2531
+ const actionInputs = flattenToolCallsNoDuplicates([
2532
+ ...serverSideActionsInput,
2533
+ ...clientSideActionsInput
2534
+ ]);
2535
+ await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
2536
+ threadId,
2537
+ runId,
2538
+ inputMessages,
2539
+ properties: graphqlContext.properties,
2540
+ url
2541
+ }));
2438
2542
  const result = await serviceAdapter.process({
2439
2543
  messages: inputMessages,
2440
2544
  actions: actionInputs,
@@ -2467,7 +2571,14 @@ var CopilotRuntime = class {
2467
2571
  };
2468
2572
  } catch (error) {
2469
2573
  console.error("Error getting response:", error);
2470
- throw error;
2574
+ eventSource.sendErrorMessageToChat();
2575
+ return {
2576
+ threadId: threadId || (0, import_shared9.randomId)(),
2577
+ runId: runId || (0, import_shared9.randomId)(),
2578
+ eventSource,
2579
+ serverSideActions: [],
2580
+ actionInputsWithoutAgents: []
2581
+ };
2471
2582
  }
2472
2583
  }
2473
2584
  async processAgentRequest(request) {
@@ -2483,7 +2594,7 @@ var CopilotRuntime = class {
2483
2594
  const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
2484
2595
  name: action.name,
2485
2596
  description: action.description,
2486
- jsonSchema: JSON.stringify((0, import_shared8.actionParametersToJsonSchema)(action.parameters))
2597
+ jsonSchema: JSON.stringify((0, import_shared9.actionParametersToJsonSchema)(action.parameters))
2487
2598
  }));
2488
2599
  const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
2489
2600
  ...serverSideActionsInput,
@@ -2547,7 +2658,7 @@ var CopilotRuntime = class {
2547
2658
  }
2548
2659
  const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
2549
2660
  ...endpoint,
2550
- type: this.resolveEndpointType(endpoint)
2661
+ type: resolveEndpointType(endpoint)
2551
2662
  }));
2552
2663
  const remoteActions = await setupRemoteActions({
2553
2664
  remoteEndpointDefinitions,
@@ -2566,12 +2677,6 @@ var CopilotRuntime = class {
2566
2677
  ...remoteActions
2567
2678
  ];
2568
2679
  }
2569
- resolveEndpointType(endpoint) {
2570
- if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
2571
- return EndpointType.LangGraphCloud;
2572
- }
2573
- return endpoint.type;
2574
- }
2575
2680
  };
2576
2681
  __name(CopilotRuntime, "CopilotRuntime");
2577
2682
  function flattenToolCallsNoDuplicates(toolsByPriority) {
@@ -2593,13 +2698,24 @@ function copilotKitEndpoint(config2) {
2593
2698
  };
2594
2699
  }
2595
2700
  __name(copilotKitEndpoint, "copilotKitEndpoint");
2596
- function langGraphCloudEndpoint(config2) {
2701
+ function langGraphPlatformEndpoint(config2) {
2597
2702
  return {
2598
2703
  ...config2,
2599
- type: EndpointType.LangGraphCloud
2704
+ type: EndpointType.LangGraphPlatform
2600
2705
  };
2601
2706
  }
2602
- __name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
2707
+ __name(langGraphPlatformEndpoint, "langGraphPlatformEndpoint");
2708
+ function resolveEndpointType(endpoint) {
2709
+ if (!endpoint.type) {
2710
+ if ("langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
2711
+ return EndpointType.LangGraphPlatform;
2712
+ } else {
2713
+ return EndpointType.CopilotKit;
2714
+ }
2715
+ }
2716
+ return endpoint.type;
2717
+ }
2718
+ __name(resolveEndpointType, "resolveEndpointType");
2603
2719
 
2604
2720
  // src/lib/integrations/shared.ts
2605
2721
  var import_type_graphql16 = require("type-graphql");
@@ -3613,7 +3729,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
3613
3729
  __name(UnknownErrorResponse, "UnknownErrorResponse");
3614
3730
 
3615
3731
  // src/graphql/resolvers/copilot.resolver.ts
3616
- var import_shared9 = require("@copilotkit/shared");
3732
+ var import_shared10 = require("@copilotkit/shared");
3617
3733
  function _ts_decorate14(decorators, target, key, desc) {
3618
3734
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3619
3735
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -3730,7 +3846,7 @@ var CopilotResolver = class {
3730
3846
  rejectOutputMessagesPromise = reject;
3731
3847
  });
3732
3848
  logger2.debug("Processing");
3733
- const { eventSource, threadId = (0, import_shared9.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
3849
+ const { eventSource, threadId = (0, import_shared10.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
3734
3850
  serviceAdapter,
3735
3851
  messages: data.messages,
3736
3852
  actions: data.frontend.actions,
@@ -3775,7 +3891,7 @@ var CopilotResolver = class {
3775
3891
  });
3776
3892
  outputMessages = [
3777
3893
  (0, import_class_transformer2.plainToInstance)(TextMessage, {
3778
- id: (0, import_shared9.randomId)(),
3894
+ id: (0, import_shared10.randomId)(),
3779
3895
  createdAt: /* @__PURE__ */ new Date(),
3780
3896
  content: result.reason,
3781
3897
  role: MessageRole.assistant
@@ -3938,7 +4054,7 @@ var CopilotResolver = class {
3938
4054
  result: event.result
3939
4055
  }, "Action execution result event received");
3940
4056
  pushMessage({
3941
- id: (0, import_shared9.randomId)(),
4057
+ id: (0, import_shared10.randomId)(),
3942
4058
  status: new SuccessMessageStatus(),
3943
4059
  createdAt: /* @__PURE__ */ new Date(),
3944
4060
  actionExecutionId: event.actionExecutionId,
@@ -3946,7 +4062,7 @@ var CopilotResolver = class {
3946
4062
  result: event.result
3947
4063
  });
3948
4064
  outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
3949
- id: (0, import_shared9.randomId)(),
4065
+ id: (0, import_shared10.randomId)(),
3950
4066
  createdAt: /* @__PURE__ */ new Date(),
3951
4067
  actionExecutionId: event.actionExecutionId,
3952
4068
  actionName: event.actionName,
@@ -3958,7 +4074,7 @@ var CopilotResolver = class {
3958
4074
  event
3959
4075
  }, "Agent message event received");
3960
4076
  pushMessage({
3961
- id: (0, import_shared9.randomId)(),
4077
+ id: (0, import_shared10.randomId)(),
3962
4078
  status: new SuccessMessageStatus(),
3963
4079
  threadId: event.threadId,
3964
4080
  agentName: event.agentName,
@@ -3971,7 +4087,7 @@ var CopilotResolver = class {
3971
4087
  createdAt: /* @__PURE__ */ new Date()
3972
4088
  });
3973
4089
  outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
3974
- id: (0, import_shared9.randomId)(),
4090
+ id: (0, import_shared10.randomId)(),
3975
4091
  threadId: event.threadId,
3976
4092
  agentName: event.agentName,
3977
4093
  nodeName: event.nodeName,
@@ -4159,7 +4275,7 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
4159
4275
  _copilotkit: options.properties._copilotkit
4160
4276
  });
4161
4277
  }
4162
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4278
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4163
4279
  const logger2 = commonConfig.logging;
4164
4280
  logger2.debug("Creating NextJS App Router endpoint");
4165
4281
  const yoga = (0, import_graphql_yoga2.createYoga)({
@@ -4198,7 +4314,7 @@ function copilotRuntimeNextJSPagesRouterEndpoint(options) {
4198
4314
  _copilotkit: options.properties._copilotkit
4199
4315
  });
4200
4316
  }
4201
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4317
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4202
4318
  const logger2 = commonConfig.logging;
4203
4319
  logger2.debug("Creating NextJS Pages Router endpoint");
4204
4320
  const yoga = (0, import_graphql_yoga3.createYoga)({
@@ -4224,7 +4340,7 @@ function copilotRuntimeNodeHttpEndpoint(options) {
4224
4340
  _copilotkit: options.properties._copilotkit
4225
4341
  });
4226
4342
  }
4227
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4343
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4228
4344
  const logger2 = commonConfig.logging;
4229
4345
  logger2.debug("Creating Node HTTP endpoint");
4230
4346
  const yoga = (0, import_graphql_yoga4.createYoga)({
@@ -4242,7 +4358,7 @@ function copilotRuntimeNodeExpressEndpoint(options) {
4242
4358
  framework: "node-express"
4243
4359
  }
4244
4360
  });
4245
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4361
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4246
4362
  return copilotRuntimeNodeHttpEndpoint(options);
4247
4363
  }
4248
4364
  __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
@@ -4254,7 +4370,7 @@ function copilotRuntimeNestEndpoint(options) {
4254
4370
  framework: "nest"
4255
4371
  }
4256
4372
  });
4257
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4373
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4258
4374
  return copilotRuntimeNodeHttpEndpoint(options);
4259
4375
  }
4260
4376
  __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
@@ -4278,6 +4394,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
4278
4394
  createContext,
4279
4395
  flattenToolCallsNoDuplicates,
4280
4396
  getCommonConfig,
4281
- langGraphCloudEndpoint
4397
+ langGraphPlatformEndpoint,
4398
+ resolveEndpointType
4282
4399
  });
4283
4400
  //# sourceMappingURL=index.js.map