@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/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",
@@ -147,13 +147,14 @@ __export(src_exports, {
147
147
  createContext: () => createContext,
148
148
  flattenToolCallsNoDuplicates: () => flattenToolCallsNoDuplicates,
149
149
  getCommonConfig: () => getCommonConfig,
150
- langGraphCloudEndpoint: () => langGraphCloudEndpoint
150
+ langGraphPlatformEndpoint: () => langGraphPlatformEndpoint,
151
+ resolveEndpointType: () => resolveEndpointType
151
152
  });
152
153
  module.exports = __toCommonJS(src_exports);
153
154
  var import_reflect_metadata = require("reflect-metadata");
154
155
 
155
156
  // src/lib/runtime/copilot-runtime.ts
156
- var import_shared9 = require("@copilotkit/shared");
157
+ var import_shared10 = require("@copilotkit/shared");
157
158
 
158
159
  // src/service-adapters/langchain/langserve.ts
159
160
  var import_remote = require("langchain/runnables/remote");
@@ -430,6 +431,9 @@ var OpenAIAdapter = class {
430
431
  var _a, _b;
431
432
  let mode = null;
432
433
  for await (const chunk of stream) {
434
+ if (chunk.choices.length === 0) {
435
+ continue;
436
+ }
433
437
  const toolCall = (_a = chunk.choices[0].delta.tool_calls) == null ? void 0 : _a[0];
434
438
  const content = chunk.choices[0].delta.content;
435
439
  if (mode === "message" && (toolCall == null ? void 0 : toolCall.id)) {
@@ -678,6 +682,7 @@ __name(encodeResult, "encodeResult");
678
682
 
679
683
  // src/service-adapters/langchain/langchain-adapter.ts
680
684
  var import_shared3 = require("@copilotkit/shared");
685
+ var import_promises = require("@langchain/core/callbacks/promises");
681
686
  var LangChainAdapter = class {
682
687
  options;
683
688
  /**
@@ -687,23 +692,28 @@ var LangChainAdapter = class {
687
692
  this.options = options;
688
693
  }
689
694
  async process(request) {
690
- const { eventSource, model, actions, messages, threadId, runId } = request;
691
- const result = await this.options.chainFn({
692
- messages: messages.map(convertMessageToLangChainMessage),
693
- tools: actions.map(convertActionInputToLangChainTool),
694
- model,
695
- threadId,
696
- runId
697
- });
698
- eventSource.stream(async (eventStream$) => {
699
- await streamLangChainResponse({
700
- result,
701
- eventStream$
695
+ try {
696
+ const { eventSource, model, actions, messages, runId } = request;
697
+ const threadId = request.threadId ?? (0, import_shared3.randomId)();
698
+ const result = await this.options.chainFn({
699
+ messages: messages.map(convertMessageToLangChainMessage),
700
+ tools: actions.map(convertActionInputToLangChainTool),
701
+ model,
702
+ threadId,
703
+ runId
702
704
  });
703
- });
704
- return {
705
- threadId: threadId || (0, import_shared3.randomId)()
706
- };
705
+ eventSource.stream(async (eventStream$) => {
706
+ await streamLangChainResponse({
707
+ result,
708
+ eventStream$
709
+ });
710
+ });
711
+ return {
712
+ threadId
713
+ };
714
+ } finally {
715
+ await (0, import_promises.awaitAllCallbacks)();
716
+ }
707
717
  }
708
718
  };
709
719
  __name(LangChainAdapter, "LangChainAdapter");
@@ -713,12 +723,16 @@ var import_google_gauth = require("@langchain/google-gauth");
713
723
  var GoogleGenerativeAIAdapter = class extends LangChainAdapter {
714
724
  constructor(options) {
715
725
  super({
716
- chainFn: async ({ messages, tools }) => {
726
+ chainFn: async ({ messages, tools, threadId }) => {
717
727
  const model = new import_google_gauth.ChatGoogle({
718
728
  modelName: (options == null ? void 0 : options.model) ?? "gemini-1.5-pro",
719
729
  apiVersion: "v1beta"
720
730
  }).bindTools(tools);
721
- return model.stream(messages);
731
+ return model.stream(messages, {
732
+ metadata: {
733
+ conversation_id: threadId
734
+ }
735
+ });
722
736
  }
723
737
  });
724
738
  }
@@ -1328,16 +1342,14 @@ var FilterThinkingTextBuffer = /* @__PURE__ */ __name(class FilterThinkingTextBu
1328
1342
  }, "FilterThinkingTextBuffer");
1329
1343
 
1330
1344
  // src/service-adapters/events.ts
1345
+ var import_shared9 = require("@copilotkit/shared");
1331
1346
  var import_rxjs2 = require("rxjs");
1332
1347
 
1333
1348
  // src/lib/telemetry-client.ts
1334
- var import_shared7 = require("@copilotkit/shared");
1335
- var packageJson = require_package();
1336
- var telemetryClient = new import_shared7.TelemetryClient({
1337
- packageName: packageJson.name,
1338
- packageVersion: packageJson.version
1339
- });
1340
- var telemetry_client_default = telemetryClient;
1349
+ var import_shared8 = require("@copilotkit/shared");
1350
+
1351
+ // src/lib/runtime/remote-action-constructors.ts
1352
+ var import_node_crypto2 = require("crypto");
1341
1353
 
1342
1354
  // src/agents/langgraph/event-source.ts
1343
1355
  var import_rxjs = require("rxjs");
@@ -1354,6 +1366,8 @@ var LangGraphEventTypes;
1354
1366
  LangGraphEventTypes2["OnToolStart"] = "on_tool_start";
1355
1367
  LangGraphEventTypes2["OnToolEnd"] = "on_tool_end";
1356
1368
  LangGraphEventTypes2["OnCopilotKitStateSync"] = "on_copilotkit_state_sync";
1369
+ LangGraphEventTypes2["OnCopilotKitEmitMessage"] = "on_copilotkit_emit_message";
1370
+ LangGraphEventTypes2["OnCopilotKitEmitToolCall"] = "on_copilotkit_emit_tool_call";
1357
1371
  LangGraphEventTypes2["OnCustomEvent"] = "on_custom_event";
1358
1372
  })(LangGraphEventTypes || (LangGraphEventTypes = {}));
1359
1373
  var CustomEventNames;
@@ -1365,7 +1379,7 @@ var CustomEventNames;
1365
1379
  })(CustomEventNames || (CustomEventNames = {}));
1366
1380
 
1367
1381
  // src/agents/langgraph/event-source.ts
1368
- var import_shared8 = require("@copilotkit/shared");
1382
+ var import_shared7 = require("@copilotkit/shared");
1369
1383
  var RemoteLangGraphEventSource = class {
1370
1384
  eventStream$ = new import_rxjs.ReplaySubject();
1371
1385
  shouldEmitToolCall(shouldEmitToolCalls, toolCallName) {
@@ -1391,7 +1405,7 @@ var RemoteLangGraphEventSource = class {
1391
1405
  acc.content = null;
1392
1406
  }
1393
1407
  const toolCallChunks = (
1394
- // @ts-expect-error -- LangGraph Cloud implementation stores data outside of kwargs
1408
+ // @ts-expect-error -- LangGraph Platform implementation stores data outside of kwargs
1395
1409
  ((_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)
1396
1410
  );
1397
1411
  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);
@@ -1551,7 +1565,7 @@ var RemoteLangGraphEventSource = class {
1551
1565
  type: RuntimeEventTypes.ActionExecutionEnd
1552
1566
  });
1553
1567
  }
1554
- const messageId = (0, import_shared8.randomId)();
1568
+ const messageId = (0, import_shared7.randomId)();
1555
1569
  events.push({
1556
1570
  type: RuntimeEventTypes.TextMessageStart,
1557
1571
  messageId
@@ -1569,7 +1583,7 @@ var RemoteLangGraphEventSource = class {
1569
1583
  };
1570
1584
  __name(RemoteLangGraphEventSource, "RemoteLangGraphEventSource");
1571
1585
 
1572
- // src/lib/runtime/remote-lg-cloud-action.ts
1586
+ // src/lib/runtime/remote-lg-action.ts
1573
1587
  var import_langgraph_sdk = require("@langchain/langgraph-sdk");
1574
1588
  var import_node_crypto = require("crypto");
1575
1589
  var import_partial_json = require("partial-json");
@@ -1610,7 +1624,7 @@ var CopilotRequestType;
1610
1624
  description: "The type of Copilot request"
1611
1625
  });
1612
1626
 
1613
- // src/lib/runtime/remote-lg-cloud-action.ts
1627
+ // src/lib/runtime/remote-lg-action.ts
1614
1628
  async function execute(args) {
1615
1629
  return new ReadableStream({
1616
1630
  async start(controller) {
@@ -1624,6 +1638,7 @@ async function execute(args) {
1624
1638
  }
1625
1639
  __name(execute, "execute");
1626
1640
  async function streamEvents(controller, args) {
1641
+ var _a, _b, _c, _d, _e, _f;
1627
1642
  const { deploymentUrl, langsmithApiKey, threadId: agrsInitialThreadId, agent, nodeName: initialNodeName, state: initialState, messages, actions, logger: logger2 } = args;
1628
1643
  let nodeName = initialNodeName;
1629
1644
  let state = initialState;
@@ -1673,7 +1688,7 @@ async function streamEvents(controller, args) {
1673
1688
  if (!assistantId) {
1674
1689
  console.error(`
1675
1690
  No agent found for the agent name specified in CopilotKit provider
1676
- Please check your available agents or provide an agent ID in the LangGraph Cloud endpoint definition.
1691
+ Please check your available agents or provide an agent ID in the LangGraph Platform endpoint definition.
1677
1692
 
1678
1693
 
1679
1694
  These are the available agents: [${assistants.map((a) => `${a.name} (ID: ${a.assistant_id})`).join(", ")}]
@@ -1697,7 +1712,14 @@ async function streamEvents(controller, args) {
1697
1712
  const emit = /* @__PURE__ */ __name((message) => controller.enqueue(new TextEncoder().encode(message)), "emit");
1698
1713
  let latestStateValues = {};
1699
1714
  let updatedState = state;
1715
+ let manuallyEmittedState = null;
1716
+ let streamInfo = {
1717
+ hashedLgcKey: (0, import_node_crypto.createHash)("sha256").update(langsmithApiKey).digest("hex")
1718
+ };
1700
1719
  try {
1720
+ telemetry_client_default.capture("oss.runtime.agent_execution_stream_started", {
1721
+ hashedLgcKey: streamInfo.hashedLgcKey
1722
+ });
1701
1723
  for await (const chunk of streamResponse2) {
1702
1724
  if (![
1703
1725
  "events",
@@ -1719,26 +1741,37 @@ async function streamEvents(controller, args) {
1719
1741
  const runId = event.metadata.run_id;
1720
1742
  externalRunId = runId;
1721
1743
  const metadata = event.metadata;
1744
+ 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) != "") {
1745
+ streamInfo.provider = (_f = (_e = event.data) == null ? void 0 : _e.output) == null ? void 0 : _f.model;
1746
+ }
1747
+ if (metadata.langgraph_host != null && metadata.langgraph_host != "") {
1748
+ streamInfo.langGraphHost = metadata.langgraph_host;
1749
+ }
1750
+ if (metadata.langgraph_version != null && metadata.langgraph_version != "") {
1751
+ streamInfo.langGraphVersion = metadata.langgraph_version;
1752
+ }
1722
1753
  shouldExit = shouldExit || eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitExit;
1723
1754
  const emitIntermediateState = metadata["copilotkit:emit-intermediate-state"];
1724
1755
  const manuallyEmitIntermediateState = eventType === LangGraphEventTypes.OnCustomEvent && event.name === CustomEventNames.CopilotKitManuallyEmitIntermediateState;
1756
+ const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
1757
+ if (exitingNode) {
1758
+ manuallyEmittedState = null;
1759
+ }
1725
1760
  if (graphInfo["nodes"].some((node) => node.id === currentNodeName)) {
1726
1761
  nodeName = currentNodeName;
1727
- if (eventType === LangGraphEventTypes.OnChainStart || eventType === LangGraphEventTypes.OnChainEnd) {
1728
- updatedState = latestStateValues;
1729
- }
1730
1762
  }
1763
+ updatedState = manuallyEmittedState ?? latestStateValues;
1731
1764
  if (!nodeName) {
1732
1765
  continue;
1733
1766
  }
1734
1767
  if (manuallyEmitIntermediateState) {
1735
- updatedState = event.data;
1768
+ manuallyEmittedState = event.data;
1736
1769
  emit(getStateSyncEvent({
1737
1770
  threadId,
1738
1771
  runId,
1739
1772
  agentName: agent.name,
1740
1773
  nodeName,
1741
- state: updatedState,
1774
+ state: manuallyEmittedState,
1742
1775
  running: true,
1743
1776
  active: true
1744
1777
  }));
@@ -1762,7 +1795,6 @@ async function streamEvents(controller, args) {
1762
1795
  if (!emitIntermediateState && currentNodeName === emitIntermediateStateUntilEnd && eventType === LangGraphEventTypes.OnChainEnd) {
1763
1796
  emitIntermediateStateUntilEnd = null;
1764
1797
  }
1765
- const exitingNode = nodeName === currentNodeName && eventType === LangGraphEventTypes.OnChainEnd;
1766
1798
  if (JSON.stringify(updatedState) !== JSON.stringify(state) || prevNodeName != nodeName || exitingNode) {
1767
1799
  state = updatedState;
1768
1800
  prevNodeName = nodeName;
@@ -1781,6 +1813,7 @@ async function streamEvents(controller, args) {
1781
1813
  state = await client.threads.getState(threadId);
1782
1814
  const isEndNode = state.next.length === 0;
1783
1815
  nodeName = Object.keys(state.metadata.writes)[0];
1816
+ telemetry_client_default.capture("oss.runtime.agent_execution_stream_ended", streamInfo);
1784
1817
  emit(getStateSyncEvent({
1785
1818
  threadId,
1786
1819
  runId: externalRunId,
@@ -2027,8 +2060,13 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
2027
2060
  var _a;
2028
2061
  logger2.debug({
2029
2062
  actionName: agent.name
2030
- }, "Executing LangGraph Cloud agent");
2031
- telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
2063
+ }, "Executing LangGraph Platform agent");
2064
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {
2065
+ agentExecution: true,
2066
+ type: "langgraph-platform",
2067
+ agentsAmount: endpoint.agents.length,
2068
+ hashedLgcKey: (0, import_node_crypto2.createHash)("sha256").update(endpoint.langsmithApiKey).digest("hex")
2069
+ });
2032
2070
  let state = {};
2033
2071
  if (agentStates) {
2034
2072
  const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
@@ -2061,8 +2099,8 @@ function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, m
2061
2099
  url: endpoint.deploymentUrl,
2062
2100
  status: 500,
2063
2101
  body: error.message
2064
- }, "Failed to execute LangGraph Cloud agent");
2065
- throw new Error("Failed to execute LangGraph Cloud agent");
2102
+ }, "Failed to execute LangGraph Platform agent");
2103
+ throw new Error("Failed to execute LangGraph Platform agent");
2066
2104
  }
2067
2105
  }
2068
2106
  }));
@@ -2082,7 +2120,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2082
2120
  args
2083
2121
  }, "Executing remote action");
2084
2122
  const headers = createHeaders(onBeforeRequest, graphqlContext);
2085
- telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
2123
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {
2124
+ agentExecution: false,
2125
+ type: "self-hosted",
2126
+ agentsAmount: json["agents"].length
2127
+ });
2086
2128
  try {
2087
2129
  const response = await fetch(`${url}/actions/execute`, {
2088
2130
  method: "POST",
@@ -2128,7 +2170,11 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2128
2170
  actionName: agent.name
2129
2171
  }, "Executing remote agent");
2130
2172
  const headers = createHeaders(onBeforeRequest, graphqlContext);
2131
- telemetry_client_default.capture("oss.runtime.remote_action_executed", {});
2173
+ telemetry_client_default.capture("oss.runtime.remote_action_executed", {
2174
+ agentExecution: true,
2175
+ type: "self-hosted",
2176
+ agentsAmount: json["agents"].length
2177
+ });
2132
2178
  let state = {};
2133
2179
  if (agentStates) {
2134
2180
  const jsonState = (_a = agentStates.find((state2) => state2.agentName === name)) == null ? void 0 : _a.state;
@@ -2236,7 +2282,7 @@ __name(createHeaders, "createHeaders");
2236
2282
  var EndpointType;
2237
2283
  (function(EndpointType2) {
2238
2284
  EndpointType2["CopilotKit"] = "copilotKit";
2239
- EndpointType2["LangGraphCloud"] = "langgraph-cloud";
2285
+ EndpointType2["LangGraphPlatform"] = "langgraph-platform";
2240
2286
  })(EndpointType || (EndpointType = {}));
2241
2287
  function isLangGraphAgentAction(action) {
2242
2288
  if (!action) {
@@ -2294,13 +2340,13 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
2294
2340
  remoteEndpointDefinitions
2295
2341
  }, "Fetching from remote endpoints");
2296
2342
  const filtered = remoteEndpointDefinitions.filter((value, index, self) => {
2297
- if (value.type === "langgraph-cloud") {
2343
+ if (value.type === "langgraph-platform") {
2298
2344
  return value;
2299
2345
  }
2300
2346
  return index === self.findIndex((t) => t.url === value.url);
2301
2347
  });
2302
2348
  const result = await Promise.all(filtered.map(async (endpoint) => {
2303
- if (endpoint.type === "langgraph-cloud") {
2349
+ if (endpoint.type === "langgraph-platform") {
2304
2350
  return constructLGCRemoteAction({
2305
2351
  endpoint,
2306
2352
  messages,
@@ -2339,6 +2385,53 @@ async function setupRemoteActions({ remoteEndpointDefinitions, graphqlContext, m
2339
2385
  }
2340
2386
  __name(setupRemoteActions, "setupRemoteActions");
2341
2387
 
2388
+ // src/lib/telemetry-client.ts
2389
+ var import_node_crypto3 = require("crypto");
2390
+ var packageJson = require_package();
2391
+ var telemetryClient = new import_shared8.TelemetryClient({
2392
+ packageName: packageJson.name,
2393
+ packageVersion: packageJson.version
2394
+ });
2395
+ function getRuntimeInstanceTelemetryInfo(runtime) {
2396
+ const endpointsInfo = runtime.remoteEndpointDefinitions.reduce((acc, endpoint) => {
2397
+ let info = {
2398
+ ...acc
2399
+ };
2400
+ const endpointType = resolveEndpointType(endpoint);
2401
+ if (!info.endpointTypes.includes(endpointType)) {
2402
+ info = {
2403
+ ...info,
2404
+ endpointTypes: [
2405
+ ...info.endpointTypes,
2406
+ endpointType
2407
+ ]
2408
+ };
2409
+ }
2410
+ if (endpointType === EndpointType.LangGraphPlatform) {
2411
+ const ep = endpoint;
2412
+ info = {
2413
+ ...info,
2414
+ agentsAmount: ep.agents.length,
2415
+ hashedKey: (0, import_node_crypto3.createHash)("sha256").update(ep.langsmithApiKey).digest("hex")
2416
+ };
2417
+ }
2418
+ return info;
2419
+ }, {
2420
+ endpointTypes: [],
2421
+ agentsAmount: null,
2422
+ hashedKey: null
2423
+ });
2424
+ return {
2425
+ actionsAmount: runtime.actions.length,
2426
+ endpointsAmount: runtime.remoteEndpointDefinitions.length,
2427
+ endpointTypes: endpointsInfo.endpointTypes,
2428
+ agentsAmount: endpointsInfo.agentsAmount,
2429
+ hashedLgcKey: endpointsInfo.hashedKey
2430
+ };
2431
+ }
2432
+ __name(getRuntimeInstanceTelemetryInfo, "getRuntimeInstanceTelemetryInfo");
2433
+ var telemetry_client_default = telemetryClient;
2434
+
2342
2435
  // src/service-adapters/events.ts
2343
2436
  var RuntimeEventTypes;
2344
2437
  (function(RuntimeEventTypes2) {
@@ -2429,9 +2522,20 @@ var RuntimeEventSource = class {
2429
2522
  async stream(callback) {
2430
2523
  this.callback = callback;
2431
2524
  }
2525
+ sendErrorMessageToChat() {
2526
+ const errorMessage = "\u274C An error occurred. Please try again.";
2527
+ if (!this.callback) {
2528
+ this.stream(async (eventStream$) => {
2529
+ eventStream$.sendTextMessage((0, import_shared9.randomId)(), errorMessage);
2530
+ });
2531
+ } else {
2532
+ this.eventStream$.sendTextMessage((0, import_shared9.randomId)(), errorMessage);
2533
+ }
2534
+ }
2432
2535
  processRuntimeEvents({ serverSideActions, guardrailsResult$, actionInputsWithoutAgents }) {
2433
2536
  this.callback(this.eventStream$).catch((error) => {
2434
2537
  console.error("Error in event source callback", error);
2538
+ this.sendErrorMessageToChat();
2435
2539
  });
2436
2540
  return this.eventStream$.pipe(
2437
2541
  // mark tools for server side execution
@@ -2674,37 +2778,37 @@ var CopilotRuntime = class {
2674
2778
  const remoteChain = new RemoteChain(chain);
2675
2779
  this.langserve.push(remoteChain.toAction());
2676
2780
  }
2677
- this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) || [];
2781
+ this.remoteEndpointDefinitions = (params == null ? void 0 : params.remoteEndpoints) ?? (params == null ? void 0 : params.remoteActions) ?? [];
2678
2782
  this.onBeforeRequest = (_a = params == null ? void 0 : params.middleware) == null ? void 0 : _a.onBeforeRequest;
2679
2783
  this.onAfterRequest = (_b = params == null ? void 0 : params.middleware) == null ? void 0 : _b.onAfterRequest;
2680
2784
  }
2681
2785
  async processRuntimeRequest(request) {
2682
2786
  var _a;
2683
2787
  const { serviceAdapter, messages: rawMessages, actions: clientSideActionsInput, threadId, runId, outputMessagesPromise, graphqlContext, forwardedParameters, agentSession, url } = request;
2684
- if (agentSession) {
2685
- return this.processAgentRequest(request);
2686
- }
2687
- const messages = rawMessages.filter((message) => !message.agentStateMessage);
2688
- const inputMessages = convertGqlInputToMessages(messages);
2689
- const serverSideActions = await this.getServerSideActions(request);
2690
- const serverSideActionsInput = serverSideActions.map((action) => ({
2691
- name: action.name,
2692
- description: action.description,
2693
- jsonSchema: JSON.stringify((0, import_shared9.actionParametersToJsonSchema)(action.parameters))
2694
- }));
2695
- const actionInputs = flattenToolCallsNoDuplicates([
2696
- ...serverSideActionsInput,
2697
- ...clientSideActionsInput
2698
- ]);
2699
- await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
2700
- threadId,
2701
- runId,
2702
- inputMessages,
2703
- properties: graphqlContext.properties,
2704
- url
2705
- }));
2788
+ const eventSource = new RuntimeEventSource();
2706
2789
  try {
2707
- const eventSource = new RuntimeEventSource();
2790
+ if (agentSession) {
2791
+ return await this.processAgentRequest(request);
2792
+ }
2793
+ const messages = rawMessages.filter((message) => !message.agentStateMessage);
2794
+ const inputMessages = convertGqlInputToMessages(messages);
2795
+ const serverSideActions = await this.getServerSideActions(request);
2796
+ const serverSideActionsInput = serverSideActions.map((action) => ({
2797
+ name: action.name,
2798
+ description: action.description,
2799
+ jsonSchema: JSON.stringify((0, import_shared10.actionParametersToJsonSchema)(action.parameters))
2800
+ }));
2801
+ const actionInputs = flattenToolCallsNoDuplicates([
2802
+ ...serverSideActionsInput,
2803
+ ...clientSideActionsInput
2804
+ ]);
2805
+ await ((_a = this.onBeforeRequest) == null ? void 0 : _a.call(this, {
2806
+ threadId,
2807
+ runId,
2808
+ inputMessages,
2809
+ properties: graphqlContext.properties,
2810
+ url
2811
+ }));
2708
2812
  const result = await serviceAdapter.process({
2709
2813
  messages: inputMessages,
2710
2814
  actions: actionInputs,
@@ -2737,7 +2841,14 @@ var CopilotRuntime = class {
2737
2841
  };
2738
2842
  } catch (error) {
2739
2843
  console.error("Error getting response:", error);
2740
- throw error;
2844
+ eventSource.sendErrorMessageToChat();
2845
+ return {
2846
+ threadId: threadId || (0, import_shared10.randomId)(),
2847
+ runId: runId || (0, import_shared10.randomId)(),
2848
+ eventSource,
2849
+ serverSideActions: [],
2850
+ actionInputsWithoutAgents: []
2851
+ };
2741
2852
  }
2742
2853
  }
2743
2854
  async processAgentRequest(request) {
@@ -2753,7 +2864,7 @@ var CopilotRuntime = class {
2753
2864
  const serverSideActionsInput = serverSideActions.filter((action) => !isLangGraphAgentAction(action)).map((action) => ({
2754
2865
  name: action.name,
2755
2866
  description: action.description,
2756
- jsonSchema: JSON.stringify((0, import_shared9.actionParametersToJsonSchema)(action.parameters))
2867
+ jsonSchema: JSON.stringify((0, import_shared10.actionParametersToJsonSchema)(action.parameters))
2757
2868
  }));
2758
2869
  const actionInputsWithoutAgents = flattenToolCallsNoDuplicates([
2759
2870
  ...serverSideActionsInput,
@@ -2817,7 +2928,7 @@ var CopilotRuntime = class {
2817
2928
  }
2818
2929
  const remoteEndpointDefinitions = this.remoteEndpointDefinitions.map((endpoint) => ({
2819
2930
  ...endpoint,
2820
- type: this.resolveEndpointType(endpoint)
2931
+ type: resolveEndpointType(endpoint)
2821
2932
  }));
2822
2933
  const remoteActions = await setupRemoteActions({
2823
2934
  remoteEndpointDefinitions,
@@ -2836,12 +2947,6 @@ var CopilotRuntime = class {
2836
2947
  ...remoteActions
2837
2948
  ];
2838
2949
  }
2839
- resolveEndpointType(endpoint) {
2840
- if (!endpoint.type && "langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
2841
- return EndpointType.LangGraphCloud;
2842
- }
2843
- return endpoint.type;
2844
- }
2845
2950
  };
2846
2951
  __name(CopilotRuntime, "CopilotRuntime");
2847
2952
  function flattenToolCallsNoDuplicates(toolsByPriority) {
@@ -2863,13 +2968,24 @@ function copilotKitEndpoint(config2) {
2863
2968
  };
2864
2969
  }
2865
2970
  __name(copilotKitEndpoint, "copilotKitEndpoint");
2866
- function langGraphCloudEndpoint(config2) {
2971
+ function langGraphPlatformEndpoint(config2) {
2867
2972
  return {
2868
2973
  ...config2,
2869
- type: EndpointType.LangGraphCloud
2974
+ type: EndpointType.LangGraphPlatform
2870
2975
  };
2871
2976
  }
2872
- __name(langGraphCloudEndpoint, "langGraphCloudEndpoint");
2977
+ __name(langGraphPlatformEndpoint, "langGraphPlatformEndpoint");
2978
+ function resolveEndpointType(endpoint) {
2979
+ if (!endpoint.type) {
2980
+ if ("langsmithApiKey" in endpoint && "deploymentUrl" in endpoint && "agents" in endpoint) {
2981
+ return EndpointType.LangGraphPlatform;
2982
+ } else {
2983
+ return EndpointType.CopilotKit;
2984
+ }
2985
+ }
2986
+ return endpoint.type;
2987
+ }
2988
+ __name(resolveEndpointType, "resolveEndpointType");
2873
2989
 
2874
2990
  // src/lib/integrations/shared.ts
2875
2991
  var import_type_graphql16 = require("type-graphql");
@@ -3883,7 +3999,7 @@ var UnknownErrorResponse = class extends FailedResponseStatus {
3883
3999
  __name(UnknownErrorResponse, "UnknownErrorResponse");
3884
4000
 
3885
4001
  // src/graphql/resolvers/copilot.resolver.ts
3886
- var import_shared10 = require("@copilotkit/shared");
4002
+ var import_shared11 = require("@copilotkit/shared");
3887
4003
  function _ts_decorate14(decorators, target, key, desc) {
3888
4004
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3889
4005
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4000,7 +4116,7 @@ var CopilotResolver = class {
4000
4116
  rejectOutputMessagesPromise = reject;
4001
4117
  });
4002
4118
  logger2.debug("Processing");
4003
- const { eventSource, threadId = (0, import_shared10.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
4119
+ const { eventSource, threadId = (0, import_shared11.randomId)(), runId, serverSideActions, actionInputsWithoutAgents } = await copilotRuntime.processRuntimeRequest({
4004
4120
  serviceAdapter,
4005
4121
  messages: data.messages,
4006
4122
  actions: data.frontend.actions,
@@ -4045,7 +4161,7 @@ var CopilotResolver = class {
4045
4161
  });
4046
4162
  outputMessages = [
4047
4163
  (0, import_class_transformer2.plainToInstance)(TextMessage, {
4048
- id: (0, import_shared10.randomId)(),
4164
+ id: (0, import_shared11.randomId)(),
4049
4165
  createdAt: /* @__PURE__ */ new Date(),
4050
4166
  content: result.reason,
4051
4167
  role: MessageRole.assistant
@@ -4208,7 +4324,7 @@ var CopilotResolver = class {
4208
4324
  result: event.result
4209
4325
  }, "Action execution result event received");
4210
4326
  pushMessage({
4211
- id: (0, import_shared10.randomId)(),
4327
+ id: (0, import_shared11.randomId)(),
4212
4328
  status: new SuccessMessageStatus(),
4213
4329
  createdAt: /* @__PURE__ */ new Date(),
4214
4330
  actionExecutionId: event.actionExecutionId,
@@ -4216,7 +4332,7 @@ var CopilotResolver = class {
4216
4332
  result: event.result
4217
4333
  });
4218
4334
  outputMessages.push((0, import_class_transformer2.plainToInstance)(ResultMessage, {
4219
- id: (0, import_shared10.randomId)(),
4335
+ id: (0, import_shared11.randomId)(),
4220
4336
  createdAt: /* @__PURE__ */ new Date(),
4221
4337
  actionExecutionId: event.actionExecutionId,
4222
4338
  actionName: event.actionName,
@@ -4228,7 +4344,7 @@ var CopilotResolver = class {
4228
4344
  event
4229
4345
  }, "Agent message event received");
4230
4346
  pushMessage({
4231
- id: (0, import_shared10.randomId)(),
4347
+ id: (0, import_shared11.randomId)(),
4232
4348
  status: new SuccessMessageStatus(),
4233
4349
  threadId: event.threadId,
4234
4350
  agentName: event.agentName,
@@ -4241,7 +4357,7 @@ var CopilotResolver = class {
4241
4357
  createdAt: /* @__PURE__ */ new Date()
4242
4358
  });
4243
4359
  outputMessages.push((0, import_class_transformer2.plainToInstance)(AgentStateMessage, {
4244
- id: (0, import_shared10.randomId)(),
4360
+ id: (0, import_shared11.randomId)(),
4245
4361
  threadId: event.threadId,
4246
4362
  agentName: event.agentName,
4247
4363
  nodeName: event.nodeName,
@@ -4429,7 +4545,7 @@ function copilotRuntimeNextJSAppRouterEndpoint(options) {
4429
4545
  _copilotkit: options.properties._copilotkit
4430
4546
  });
4431
4547
  }
4432
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4548
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4433
4549
  const logger2 = commonConfig.logging;
4434
4550
  logger2.debug("Creating NextJS App Router endpoint");
4435
4551
  const yoga = (0, import_graphql_yoga2.createYoga)({
@@ -4468,7 +4584,7 @@ function copilotRuntimeNextJSPagesRouterEndpoint(options) {
4468
4584
  _copilotkit: options.properties._copilotkit
4469
4585
  });
4470
4586
  }
4471
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4587
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4472
4588
  const logger2 = commonConfig.logging;
4473
4589
  logger2.debug("Creating NextJS Pages Router endpoint");
4474
4590
  const yoga = (0, import_graphql_yoga3.createYoga)({
@@ -4494,7 +4610,7 @@ function copilotRuntimeNodeHttpEndpoint(options) {
4494
4610
  _copilotkit: options.properties._copilotkit
4495
4611
  });
4496
4612
  }
4497
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4613
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4498
4614
  const logger2 = commonConfig.logging;
4499
4615
  logger2.debug("Creating Node HTTP endpoint");
4500
4616
  const yoga = (0, import_graphql_yoga4.createYoga)({
@@ -4512,7 +4628,7 @@ function copilotRuntimeNodeExpressEndpoint(options) {
4512
4628
  framework: "node-express"
4513
4629
  }
4514
4630
  });
4515
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4631
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4516
4632
  return copilotRuntimeNodeHttpEndpoint(options);
4517
4633
  }
4518
4634
  __name(copilotRuntimeNodeExpressEndpoint, "copilotRuntimeNodeExpressEndpoint");
@@ -4524,7 +4640,7 @@ function copilotRuntimeNestEndpoint(options) {
4524
4640
  framework: "nest"
4525
4641
  }
4526
4642
  });
4527
- telemetry_client_default.capture("oss.runtime.instance_created", {});
4643
+ telemetry_client_default.capture("oss.runtime.instance_created", getRuntimeInstanceTelemetryInfo(options.runtime));
4528
4644
  return copilotRuntimeNodeHttpEndpoint(options);
4529
4645
  }
4530
4646
  __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
@@ -4553,6 +4669,7 @@ __name(copilotRuntimeNestEndpoint, "copilotRuntimeNestEndpoint");
4553
4669
  createContext,
4554
4670
  flattenToolCallsNoDuplicates,
4555
4671
  getCommonConfig,
4556
- langGraphCloudEndpoint
4672
+ langGraphPlatformEndpoint,
4673
+ resolveEndpointType
4557
4674
  });
4558
4675
  //# sourceMappingURL=index.js.map