@langchain/langgraph-api 0.0.60 → 0.0.62

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.
@@ -16,7 +16,7 @@ export const cors = (cors) => {
16
16
  return origin;
17
17
  return undefined;
18
18
  }
19
- : cors.allow_origins ?? [];
19
+ : cors.allow_origins;
20
20
  if (cors.expose_headers?.length) {
21
21
  const headersSet = new Set(cors.expose_headers.map((h) => h.toLowerCase()));
22
22
  if (!headersSet.has("content-location")) {
@@ -28,15 +28,19 @@ export const cors = (cors) => {
28
28
  cors.expose_headers.push("x-pagination-total");
29
29
  }
30
30
  }
31
- // TODO: handle `cors.allow_credentials`
32
- return honoCors({
33
- origin,
34
- maxAge: cors.max_age,
35
- allowMethods: cors.allow_methods,
36
- allowHeaders: cors.allow_headers,
37
- credentials: cors.allow_credentials,
38
- exposeHeaders: cors.expose_headers,
39
- });
31
+ const config = { origin: origin ?? "*" };
32
+ if (cors.max_age != null)
33
+ config.maxAge = cors.max_age;
34
+ if (cors.allow_methods != null)
35
+ config.allowMethods = cors.allow_methods;
36
+ if (cors.allow_headers != null)
37
+ config.allowHeaders = cors.allow_headers;
38
+ if (cors.expose_headers != null)
39
+ config.exposeHeaders = cors.expose_headers;
40
+ if (cors.allow_credentials != null) {
41
+ config.credentials = cors.allow_credentials;
42
+ }
43
+ return honoCors(config);
40
44
  };
41
45
  // This is used to match the behavior of the original LangGraph API
42
46
  // where the content-type is not being validated. Might be nice
@@ -1,3 +1,4 @@
1
1
  import { Hono } from "hono";
2
+ import type { StorageEnv } from "./storage/types.mjs";
2
3
  export declare function getLoopbackFetch(): (url: string, init?: RequestInit) => Promise<Response>;
3
- export declare const bindLoopbackFetch: (app: Hono) => void;
4
+ export declare const bindLoopbackFetch: (app: Hono<StorageEnv>) => void;
package/dist/queue.d.mts CHANGED
@@ -1 +1,2 @@
1
- export declare const queue: () => Promise<never>;
1
+ import type { Ops } from "./storage/types.mjs";
2
+ export declare const queue: (ops: Ops) => Promise<never>;
package/dist/queue.mjs CHANGED
@@ -1,4 +1,3 @@
1
- import { Runs, Threads } from "./storage/ops.mjs";
2
1
  import { streamState, } from "./stream.mjs";
3
2
  import { logError, logger } from "./logging.mjs";
4
3
  import { serializeError } from "./utils/serde.mjs";
@@ -6,16 +5,16 @@ import { callWebhook } from "./webhook.mjs";
6
5
  import { getGraph } from "./graph/load.mjs";
7
6
  const MAX_RETRY_ATTEMPTS = 3;
8
7
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
9
- export const queue = async () => {
8
+ export const queue = async (ops) => {
10
9
  while (true) {
11
- for await (const { run, attempt, signal } of Runs.next()) {
12
- await worker(run, attempt, signal);
10
+ for await (const { run, attempt, signal } of ops.runs.next()) {
11
+ await worker(ops, run, attempt, signal);
13
12
  }
14
13
  // TODO: this is very suboptimal, we should implement subscription to the run
15
14
  await sleep(1000 * Math.random());
16
15
  }
17
16
  };
18
- const worker = async (run, attempt, signal) => {
17
+ const worker = async (ops, run, attempt, signal) => {
19
18
  const startedAt = new Date();
20
19
  let endedAt = undefined;
21
20
  let checkpoint = undefined;
@@ -56,11 +55,11 @@ const worker = async (run, attempt, signal) => {
56
55
  ...(!temporary ? { onCheckpoint, onTaskResult } : undefined),
57
56
  });
58
57
  for await (const { event, data } of stream) {
59
- await Runs.Stream.publish({ runId, resumable, event, data });
58
+ await ops.runs.stream.publish({ runId, resumable, event, data });
60
59
  }
61
60
  }
62
61
  catch (error) {
63
- await Runs.Stream.publish({
62
+ await ops.runs.stream.publish({
64
63
  runId,
65
64
  resumable,
66
65
  event: "error",
@@ -78,7 +77,7 @@ const worker = async (run, attempt, signal) => {
78
77
  run_exec_ms: endedAt.valueOf() - startedAt.valueOf(),
79
78
  });
80
79
  status = "success";
81
- await Runs.setStatus(run.run_id, status);
80
+ await ops.runs.setStatus(run.run_id, status);
82
81
  }
83
82
  catch (error) {
84
83
  endedAt = new Date();
@@ -96,14 +95,14 @@ const worker = async (run, attempt, signal) => {
96
95
  },
97
96
  });
98
97
  status = "error";
99
- await Runs.setStatus(run.run_id, "error");
98
+ await ops.runs.setStatus(run.run_id, "error");
100
99
  }
101
100
  finally {
102
101
  if (temporary) {
103
- await Threads.delete(run.thread_id, undefined);
102
+ await ops.threads.delete(run.thread_id, undefined);
104
103
  }
105
104
  else {
106
- await Threads.setStatus(run.thread_id, { checkpoint, exception });
105
+ await ops.threads.setStatus(run.thread_id, { checkpoint, exception });
107
106
  }
108
107
  if (webhook) {
109
108
  await callWebhook({