@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
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  copilotRuntimeNodeHttpEndpoint
3
- } from "../../../chunk-ODCQ3OFD.mjs";
3
+ } from "../../../chunk-6LFPAZDL.mjs";
4
4
  import "../../../chunk-OS5YD32G.mjs";
5
5
  import "../../../chunk-5BIEM2UU.mjs";
6
6
  import "../../../chunk-RTFJTJMA.mjs";
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "publishConfig": {
10
10
  "access": "public"
11
11
  },
12
- "version": "1.5.18-next.0",
12
+ "version": "1.5.18-next.2",
13
13
  "sideEffects": false,
14
14
  "main": "./dist/index.js",
15
15
  "module": "./dist/index.mjs",
@@ -58,7 +58,7 @@
58
58
  "rxjs": "^7.8.1",
59
59
  "type-graphql": "2.0.0-rc.1",
60
60
  "zod": "^3.23.3",
61
- "@copilotkit/shared": "1.5.18-next.0"
61
+ "@copilotkit/shared": "1.5.18-next.2"
62
62
  },
63
63
  "keywords": [
64
64
  "copilotkit",
@@ -13,7 +13,12 @@ export class StateResolver {
13
13
  const agent = agents.find((agent) => agent.name === data.agentName);
14
14
 
15
15
  if (!agent) {
16
- throw new Error("Agent not found");
16
+ return {
17
+ threadId: data.threadId || "",
18
+ threadExists: false,
19
+ state: JSON.stringify({}),
20
+ messages: JSON.stringify([]),
21
+ };
17
22
  }
18
23
 
19
24
  const state = await ctx._copilotkit.runtime.loadAgentState(ctx, data.threadId, data.agentName);
@@ -359,9 +359,13 @@ please use an LLM adapter instead.`,
359
359
  });
360
360
  if (!response.ok) {
361
361
  if (response.status === 404) {
362
- throw new CopilotKitApiDiscoveryError();
362
+ throw new CopilotKitApiDiscoveryError({ url: fetchUrl });
363
363
  }
364
- throw new ResolvedCopilotKitError({ status: response.status, isRemoteEndpoint: true });
364
+ throw new ResolvedCopilotKitError({
365
+ status: response.status,
366
+ url: fetchUrl,
367
+ isRemoteEndpoint: true,
368
+ });
365
369
  }
366
370
 
367
371
  const data: InfoResponse = await response.json();
@@ -415,7 +419,7 @@ please use an LLM adapter instead.`,
415
419
 
416
420
  if (Object.keys(state).length === 0) {
417
421
  return {
418
- threadId,
422
+ threadId: threadId || "",
419
423
  threadExists: false,
420
424
  state: JSON.stringify({}),
421
425
  messages: JSON.stringify([]),
@@ -424,7 +428,7 @@ please use an LLM adapter instead.`,
424
428
  const { messages, ...stateWithoutMessages } = state;
425
429
  const copilotkitMessages = langchainMessagesToCopilotKit(messages);
426
430
  return {
427
- threadId,
431
+ threadId: threadId || "",
428
432
  threadExists: true,
429
433
  state: JSON.stringify(stateWithoutMessages),
430
434
  messages: JSON.stringify(copilotkitMessages),
@@ -434,9 +438,9 @@ please use an LLM adapter instead.`,
434
438
  agentWithEndpoint.endpoint.type === EndpointType.CopilotKit ||
435
439
  !("type" in agentWithEndpoint.endpoint)
436
440
  ) {
437
- const response = await fetch(
438
- `${(agentWithEndpoint.endpoint as CopilotKitEndpoint).url}/agents/state`,
439
- {
441
+ const fetchUrl = `${(agentWithEndpoint.endpoint as CopilotKitEndpoint).url}/agents/state`;
442
+ try {
443
+ const response = await fetch(fetchUrl, {
440
444
  method: "POST",
441
445
  headers,
442
446
  body: JSON.stringify({
@@ -444,15 +448,31 @@ please use an LLM adapter instead.`,
444
448
  threadId,
445
449
  name: agentName,
446
450
  }),
447
- },
448
- );
449
- const data: LoadAgentStateResponse = await response.json();
451
+ });
452
+ if (!response.ok) {
453
+ if (response.status === 404) {
454
+ throw new CopilotKitApiDiscoveryError({ url: fetchUrl });
455
+ }
456
+ throw new ResolvedCopilotKitError({
457
+ status: response.status,
458
+ url: fetchUrl,
459
+ isRemoteEndpoint: true,
460
+ });
461
+ }
450
462
 
451
- return {
452
- ...data,
453
- state: JSON.stringify(data.state),
454
- messages: JSON.stringify(data.messages),
455
- };
463
+ const data: LoadAgentStateResponse = await response.json();
464
+
465
+ return {
466
+ ...data,
467
+ state: JSON.stringify(data.state),
468
+ messages: JSON.stringify(data.messages),
469
+ };
470
+ } catch (error) {
471
+ if (error instanceof CopilotKitError) {
472
+ throw error;
473
+ }
474
+ throw new CopilotKitLowLevelError({ error, url: fetchUrl });
475
+ }
456
476
  } else {
457
477
  throw new Error(`Unknown endpoint type: ${(agentWithEndpoint.endpoint as any).type}`);
458
478
  }
@@ -17,6 +17,7 @@ import { Action } from "@copilotkit/shared";
17
17
  import { LangGraphEvent } from "../../agents/langgraph/events";
18
18
  import { execute } from "./remote-lg-action";
19
19
  import { CopilotKitError, CopilotKitLowLevelError } from "@copilotkit/shared";
20
+ import { CopilotKitApiDiscoveryError, ResolvedCopilotKitError } from "@copilotkit/shared";
20
21
 
21
22
  export function constructLGCRemoteAction({
22
23
  endpoint,
@@ -146,7 +147,14 @@ export function constructRemoteActions({
146
147
  { url, status: response.status, body: await response.text() },
147
148
  "Failed to execute remote action",
148
149
  );
149
- return "Failed to execute remote action";
150
+ if (response.status === 404) {
151
+ throw new CopilotKitApiDiscoveryError({ url: fetchUrl });
152
+ }
153
+ throw new ResolvedCopilotKitError({
154
+ status: response.status,
155
+ url: fetchUrl,
156
+ isRemoteEndpoint: true,
157
+ });
150
158
  }
151
159
 
152
160
  const requestResult = await response.json();
@@ -221,7 +229,14 @@ export function constructRemoteActions({
221
229
  { url, status: response.status, body: await response.text() },
222
230
  "Failed to execute remote agent",
223
231
  );
224
- throw new Error("Failed to execute remote agent");
232
+ if (response.status === 404) {
233
+ throw new CopilotKitApiDiscoveryError({ url: fetchUrl });
234
+ }
235
+ throw new ResolvedCopilotKitError({
236
+ status: response.status,
237
+ url: fetchUrl,
238
+ isRemoteEndpoint: true,
239
+ });
225
240
  }
226
241
 
227
242
  const eventSource = new RemoteLangGraphEventSource();
@@ -103,7 +103,11 @@ async function fetchRemoteInfo({
103
103
  { url, status: response.status, body: await response.text() },
104
104
  "Failed to fetch actions from url",
105
105
  );
106
- throw new ResolvedCopilotKitError({ status: response.status, isRemoteEndpoint: true });
106
+ throw new ResolvedCopilotKitError({
107
+ status: response.status,
108
+ url: fetchUrl,
109
+ isRemoteEndpoint: true,
110
+ });
107
111
  }
108
112
 
109
113
  const json = await response.json();
@@ -271,7 +271,7 @@ async function streamEvents(controller: ReadableStreamDefaultController, args: E
271
271
  }
272
272
 
273
273
  const event = chunk.data;
274
- const currentNodeName = event.name;
274
+ const currentNodeName = event.metadata.langgraph_node;
275
275
  const eventType = event.event;
276
276
  const runId = event.metadata.run_id;
277
277
  externalRunId = runId;