@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.
- package/CHANGELOG.md +16 -0
- package/dist/api/assistants.mjs +16 -11
- package/dist/api/meta.mjs +24 -17
- package/dist/api/runs.mjs +19 -19
- package/dist/api/store.mjs +1 -1
- package/dist/api/threads.mjs +19 -14
- package/dist/auth/custom.d.mts +1 -4
- package/dist/auth/custom.mjs +1 -34
- package/dist/auth/index.d.mts +3 -0
- package/dist/auth/index.mjs +33 -0
- package/dist/experimental/embed.d.mts +1 -1
- package/dist/graph/api.d.mts +1 -0
- package/dist/graph/api.mjs +2 -0
- package/dist/graph/load.d.mts +4 -1
- package/dist/graph/load.mjs +12 -5
- package/dist/http/middleware.mjs +14 -10
- package/dist/loopback.d.mts +2 -1
- package/dist/queue.d.mts +2 -1
- package/dist/queue.mjs +10 -11
- package/dist/schemas.d.mts +141 -118
- package/dist/schemas.mjs +25 -0
- package/dist/server.d.mts +16 -13
- package/dist/server.mjs +27 -8
- package/dist/state.d.mts +1 -1
- package/dist/storage/context.d.mts +3 -0
- package/dist/storage/context.mjs +11 -0
- package/dist/storage/ops.d.mts +62 -202
- package/dist/storage/ops.mjs +187 -94
- package/dist/storage/types.d.mts +288 -0
- package/dist/storage/types.mjs +1 -0
- package/dist/stream.d.mts +1 -1
- package/dist/utils/runnableConfig.d.mts +1 -1
- package/dist/webhook.d.mts +1 -1
- package/package.json +16 -4
package/dist/http/middleware.mjs
CHANGED
|
@@ -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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
allowMethods
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
package/dist/loopback.d.mts
CHANGED
|
@@ -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
|
-
|
|
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
|
|
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
|
|
58
|
+
await ops.runs.stream.publish({ runId, resumable, event, data });
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
catch (error) {
|
|
63
|
-
await
|
|
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
|
|
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
|
|
98
|
+
await ops.runs.setStatus(run.run_id, "error");
|
|
100
99
|
}
|
|
101
100
|
finally {
|
|
102
101
|
if (temporary) {
|
|
103
|
-
await
|
|
102
|
+
await ops.threads.delete(run.thread_id, undefined);
|
|
104
103
|
}
|
|
105
104
|
else {
|
|
106
|
-
await
|
|
105
|
+
await ops.threads.setStatus(run.thread_id, { checkpoint, exception });
|
|
107
106
|
}
|
|
108
107
|
if (webhook) {
|
|
109
108
|
await callWebhook({
|