@copilotkit/runtime 1.5.18-next.0 → 1.5.18-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/{chunk-ODCQ3OFD.mjs → chunk-6LFPAZDL.mjs} +79 -28
  3. package/dist/chunk-6LFPAZDL.mjs.map +1 -0
  4. package/dist/{chunk-26Q5XHVQ.mjs → chunk-BMKRXGMW.mjs} +2 -2
  5. package/dist/{chunk-EQFWYZKN.mjs → chunk-BNJW4KHS.mjs} +2 -2
  6. package/dist/{chunk-QGFYSFTM.mjs → chunk-KZ3RUNSQ.mjs} +2 -2
  7. package/dist/index.js +98 -47
  8. package/dist/index.js.map +1 -1
  9. package/dist/index.mjs +4 -4
  10. package/dist/lib/index.js +98 -47
  11. package/dist/lib/index.js.map +1 -1
  12. package/dist/lib/index.mjs +4 -4
  13. package/dist/lib/integrations/index.js +7 -2
  14. package/dist/lib/integrations/index.js.map +1 -1
  15. package/dist/lib/integrations/index.mjs +4 -4
  16. package/dist/lib/integrations/nest/index.js +7 -2
  17. package/dist/lib/integrations/nest/index.js.map +1 -1
  18. package/dist/lib/integrations/nest/index.mjs +2 -2
  19. package/dist/lib/integrations/node-express/index.js +7 -2
  20. package/dist/lib/integrations/node-express/index.js.map +1 -1
  21. package/dist/lib/integrations/node-express/index.mjs +2 -2
  22. package/dist/lib/integrations/node-http/index.js +7 -2
  23. package/dist/lib/integrations/node-http/index.js.map +1 -1
  24. package/dist/lib/integrations/node-http/index.mjs +1 -1
  25. package/package.json +2 -2
  26. package/src/graphql/resolvers/state.resolver.ts +6 -1
  27. package/src/lib/runtime/copilot-runtime.ts +35 -15
  28. package/src/lib/runtime/remote-action-constructors.ts +17 -2
  29. package/src/lib/runtime/remote-actions.ts +5 -1
  30. package/src/lib/runtime/remote-lg-action.ts +1 -1
  31. package/dist/chunk-ODCQ3OFD.mjs.map +0 -1
  32. /package/dist/{chunk-26Q5XHVQ.mjs.map → chunk-BMKRXGMW.mjs.map} +0 -0
  33. /package/dist/{chunk-EQFWYZKN.mjs.map → chunk-BNJW4KHS.mjs.map} +0 -0
  34. /package/dist/{chunk-QGFYSFTM.mjs.map → chunk-KZ3RUNSQ.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @copilotkit/runtime
2
2
 
3
+ ## 1.5.18-next.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 38d3ac2: - fix: add additional info the our error messages
8
+ - Updated dependencies [38d3ac2]
9
+ - @copilotkit/shared@1.5.18-next.2
10
+
11
+ ## 1.5.18-next.1
12
+
13
+ ### Patch Changes
14
+
15
+ - a6e46a9: - fix: use langgraph metadata to get node name
16
+ - @copilotkit/shared@1.5.18-next.1
17
+
3
18
  ## 1.5.18-next.0
4
19
 
5
20
  ### Patch Changes
@@ -39,7 +39,7 @@ var require_package = __commonJS({
39
39
  publishConfig: {
40
40
  access: "public"
41
41
  },
42
- version: "1.5.18-next.0",
42
+ version: "1.5.18-next.2",
43
43
  sideEffects: false,
44
44
  main: "./dist/index.js",
45
45
  module: "./dist/index.mjs",
@@ -1840,7 +1840,7 @@ async function streamEvents(controller, args) {
1840
1840
  continue;
1841
1841
  }
1842
1842
  const event = chunk.data;
1843
- const currentNodeName = event.name;
1843
+ const currentNodeName = event.metadata.langgraph_node;
1844
1844
  const eventType = event.event;
1845
1845
  const runId = event.metadata.run_id;
1846
1846
  externalRunId = runId;
@@ -2191,6 +2191,7 @@ __name(copilotkitMessagesToLangChain, "copilotkitMessagesToLangChain");
2191
2191
 
2192
2192
  // src/lib/runtime/remote-action-constructors.ts
2193
2193
  import { CopilotKitError, CopilotKitLowLevelError } from "@copilotkit/shared";
2194
+ import { CopilotKitApiDiscoveryError, ResolvedCopilotKitError } from "@copilotkit/shared";
2194
2195
  function constructLGCRemoteAction({ endpoint, graphqlContext, logger: logger2, messages, agentStates }) {
2195
2196
  const agents = endpoint.agents.map((agent) => ({
2196
2197
  name: agent.name,
@@ -2291,7 +2292,16 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2291
2292
  status: response.status,
2292
2293
  body: await response.text()
2293
2294
  }, "Failed to execute remote action");
2294
- return "Failed to execute remote action";
2295
+ if (response.status === 404) {
2296
+ throw new CopilotKitApiDiscoveryError({
2297
+ url: fetchUrl
2298
+ });
2299
+ }
2300
+ throw new ResolvedCopilotKitError({
2301
+ status: response.status,
2302
+ url: fetchUrl,
2303
+ isRemoteEndpoint: true
2304
+ });
2295
2305
  }
2296
2306
  const requestResult = await response.json();
2297
2307
  const result = requestResult["result"];
@@ -2364,7 +2374,16 @@ function constructRemoteActions({ json, url, onBeforeRequest, graphqlContext, lo
2364
2374
  status: response.status,
2365
2375
  body: await response.text()
2366
2376
  }, "Failed to execute remote agent");
2367
- throw new Error("Failed to execute remote agent");
2377
+ if (response.status === 404) {
2378
+ throw new CopilotKitApiDiscoveryError({
2379
+ url: fetchUrl
2380
+ });
2381
+ }
2382
+ throw new ResolvedCopilotKitError({
2383
+ status: response.status,
2384
+ url: fetchUrl,
2385
+ isRemoteEndpoint: true
2386
+ });
2368
2387
  }
2369
2388
  const eventSource = new RemoteLangGraphEventSource();
2370
2389
  streamResponse(response.body, eventSource.eventStream$);
@@ -2447,7 +2466,7 @@ function createHeaders(onBeforeRequest, graphqlContext) {
2447
2466
  __name(createHeaders, "createHeaders");
2448
2467
 
2449
2468
  // src/lib/runtime/remote-actions.ts
2450
- import { CopilotKitLowLevelError as CopilotKitLowLevelError2, ResolvedCopilotKitError, CopilotKitError as CopilotKitError2 } from "@copilotkit/shared";
2469
+ import { CopilotKitLowLevelError as CopilotKitLowLevelError2, ResolvedCopilotKitError as ResolvedCopilotKitError2, CopilotKitError as CopilotKitError2 } from "@copilotkit/shared";
2451
2470
  var EndpointType;
2452
2471
  (function(EndpointType2) {
2453
2472
  EndpointType2["CopilotKit"] = "copilotKit";
@@ -2481,8 +2500,9 @@ async function fetchRemoteInfo({ url, onBeforeRequest, graphqlContext, logger: l
2481
2500
  status: response.status,
2482
2501
  body: await response.text()
2483
2502
  }, "Failed to fetch actions from url");
2484
- throw new ResolvedCopilotKitError({
2503
+ throw new ResolvedCopilotKitError2({
2485
2504
  status: response.status,
2505
+ url: fetchUrl,
2486
2506
  isRemoteEndpoint: true
2487
2507
  });
2488
2508
  }
@@ -2559,7 +2579,7 @@ __name(setupRemoteActions, "setupRemoteActions");
2559
2579
  import { createHash as createHash3 } from "crypto";
2560
2580
 
2561
2581
  // src/lib/runtime/copilot-runtime.ts
2562
- import { actionParametersToJsonSchema, ResolvedCopilotKitError as ResolvedCopilotKitError2, CopilotKitApiDiscoveryError, randomId as randomId2, CopilotKitError as CopilotKitError3, CopilotKitLowLevelError as CopilotKitLowLevelError3, CopilotKitAgentDiscoveryError, CopilotKitMisuseError } from "@copilotkit/shared";
2582
+ import { actionParametersToJsonSchema, ResolvedCopilotKitError as ResolvedCopilotKitError3, CopilotKitApiDiscoveryError as CopilotKitApiDiscoveryError2, randomId as randomId2, CopilotKitError as CopilotKitError3, CopilotKitLowLevelError as CopilotKitLowLevelError3, CopilotKitAgentDiscoveryError, CopilotKitMisuseError } from "@copilotkit/shared";
2563
2583
 
2564
2584
  // src/service-adapters/conversion.ts
2565
2585
  import { plainToInstance } from "class-transformer";
@@ -2750,10 +2770,13 @@ please use an LLM adapter instead.`
2750
2770
  });
2751
2771
  if (!response.ok) {
2752
2772
  if (response.status === 404) {
2753
- throw new CopilotKitApiDiscoveryError();
2773
+ throw new CopilotKitApiDiscoveryError2({
2774
+ url: fetchUrl
2775
+ });
2754
2776
  }
2755
- throw new ResolvedCopilotKitError2({
2777
+ throw new ResolvedCopilotKitError3({
2756
2778
  status: response.status,
2779
+ url: fetchUrl,
2757
2780
  isRemoteEndpoint: true
2758
2781
  });
2759
2782
  }
@@ -2805,7 +2828,7 @@ please use an LLM adapter instead.`
2805
2828
  }
2806
2829
  if (Object.keys(state).length === 0) {
2807
2830
  return {
2808
- threadId,
2831
+ threadId: threadId || "",
2809
2832
  threadExists: false,
2810
2833
  state: JSON.stringify({}),
2811
2834
  messages: JSON.stringify([])
@@ -2814,28 +2837,51 @@ please use an LLM adapter instead.`
2814
2837
  const { messages, ...stateWithoutMessages } = state;
2815
2838
  const copilotkitMessages = langchainMessagesToCopilotKit(messages);
2816
2839
  return {
2817
- threadId,
2840
+ threadId: threadId || "",
2818
2841
  threadExists: true,
2819
2842
  state: JSON.stringify(stateWithoutMessages),
2820
2843
  messages: JSON.stringify(copilotkitMessages)
2821
2844
  };
2822
2845
  }
2823
2846
  } else if (agentWithEndpoint.endpoint.type === EndpointType.CopilotKit || !("type" in agentWithEndpoint.endpoint)) {
2824
- const response = await fetch(`${agentWithEndpoint.endpoint.url}/agents/state`, {
2825
- method: "POST",
2826
- headers,
2827
- body: JSON.stringify({
2828
- properties: graphqlContext.properties,
2829
- threadId,
2830
- name: agentName
2831
- })
2832
- });
2833
- const data = await response.json();
2834
- return {
2835
- ...data,
2836
- state: JSON.stringify(data.state),
2837
- messages: JSON.stringify(data.messages)
2838
- };
2847
+ const fetchUrl = `${agentWithEndpoint.endpoint.url}/agents/state`;
2848
+ try {
2849
+ const response = await fetch(fetchUrl, {
2850
+ method: "POST",
2851
+ headers,
2852
+ body: JSON.stringify({
2853
+ properties: graphqlContext.properties,
2854
+ threadId,
2855
+ name: agentName
2856
+ })
2857
+ });
2858
+ if (!response.ok) {
2859
+ if (response.status === 404) {
2860
+ throw new CopilotKitApiDiscoveryError2({
2861
+ url: fetchUrl
2862
+ });
2863
+ }
2864
+ throw new ResolvedCopilotKitError3({
2865
+ status: response.status,
2866
+ url: fetchUrl,
2867
+ isRemoteEndpoint: true
2868
+ });
2869
+ }
2870
+ const data = await response.json();
2871
+ return {
2872
+ ...data,
2873
+ state: JSON.stringify(data.state),
2874
+ messages: JSON.stringify(data.messages)
2875
+ };
2876
+ } catch (error) {
2877
+ if (error instanceof CopilotKitError3) {
2878
+ throw error;
2879
+ }
2880
+ throw new CopilotKitLowLevelError3({
2881
+ error,
2882
+ url: fetchUrl
2883
+ });
2884
+ }
2839
2885
  } else {
2840
2886
  throw new Error(`Unknown endpoint type: ${agentWithEndpoint.endpoint.type}`);
2841
2887
  }
@@ -4051,7 +4097,12 @@ var StateResolver = class {
4051
4097
  const agents = await ctx._copilotkit.runtime.discoverAgentsFromEndpoints(ctx);
4052
4098
  const agent = agents.find((agent2) => agent2.name === data.agentName);
4053
4099
  if (!agent) {
4054
- throw new Error("Agent not found");
4100
+ return {
4101
+ threadId: data.threadId || "",
4102
+ threadExists: false,
4103
+ state: JSON.stringify({}),
4104
+ messages: JSON.stringify([])
4105
+ };
4055
4106
  }
4056
4107
  const state = await ctx._copilotkit.runtime.loadAgentState(ctx, data.threadId, data.agentName);
4057
4108
  return state;
@@ -4193,4 +4244,4 @@ export {
4193
4244
  getCommonConfig,
4194
4245
  copilotRuntimeNodeHttpEndpoint
4195
4246
  };
4196
- //# sourceMappingURL=chunk-ODCQ3OFD.mjs.map
4247
+ //# sourceMappingURL=chunk-6LFPAZDL.mjs.map