@langchain/langgraph-api 0.0.25 → 0.0.27
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/dist/api/threads.mjs +13 -5
- package/dist/schemas.mjs +5 -0
- package/dist/storage/ops.mjs +24 -6
- package/package.json +4 -4
package/dist/api/threads.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { zValidator } from "@hono/zod-validator";
|
|
2
2
|
import { Hono } from "hono";
|
|
3
3
|
import { v4 as uuid4 } from "uuid";
|
|
4
|
-
import * as schemas from "../schemas.mjs";
|
|
5
|
-
import { Threads } from "../storage/ops.mjs";
|
|
6
4
|
import { z } from "zod";
|
|
5
|
+
import * as schemas from "../schemas.mjs";
|
|
7
6
|
import { stateSnapshotToThreadState } from "../state.mjs";
|
|
7
|
+
import { Threads } from "../storage/ops.mjs";
|
|
8
8
|
import { jsonExtra } from "../utils/hono.mjs";
|
|
9
9
|
const api = new Hono();
|
|
10
10
|
// Threads Routes
|
|
@@ -21,19 +21,27 @@ api.post("/threads/search", zValidator("json", schemas.ThreadSearchRequest), asy
|
|
|
21
21
|
// Search Threads
|
|
22
22
|
const payload = c.req.valid("json");
|
|
23
23
|
const result = [];
|
|
24
|
+
let total = 0;
|
|
24
25
|
for await (const item of Threads.search({
|
|
25
26
|
status: payload.status,
|
|
26
27
|
values: payload.values,
|
|
27
28
|
metadata: payload.metadata,
|
|
28
29
|
limit: payload.limit ?? 10,
|
|
29
30
|
offset: payload.offset ?? 0,
|
|
31
|
+
sort_by: payload.sort_by ?? "created_at",
|
|
32
|
+
sort_order: payload.sort_order ?? "desc",
|
|
30
33
|
}, c.var.auth)) {
|
|
31
34
|
result.push({
|
|
32
|
-
...item,
|
|
33
|
-
created_at: item.created_at.toISOString(),
|
|
34
|
-
updated_at: item.updated_at.toISOString(),
|
|
35
|
+
...item.thread,
|
|
36
|
+
created_at: item.thread.created_at.toISOString(),
|
|
37
|
+
updated_at: item.thread.updated_at.toISOString(),
|
|
35
38
|
});
|
|
39
|
+
// Only set total if it's the first item
|
|
40
|
+
if (total === 0) {
|
|
41
|
+
total = item.total;
|
|
42
|
+
}
|
|
36
43
|
}
|
|
44
|
+
c.res.headers.set("X-Pagination-Total", total.toString());
|
|
37
45
|
return jsonExtra(c, result);
|
|
38
46
|
});
|
|
39
47
|
api.get("/threads/:thread_id/state", zValidator("param", z.object({ thread_id: z.string().uuid() })), zValidator("query", z.object({ subgraphs: schemas.coercedBoolean.optional() })), async (c) => {
|
package/dist/schemas.mjs
CHANGED
|
@@ -287,6 +287,11 @@ export const ThreadSearchRequest = z
|
|
|
287
287
|
.gte(0)
|
|
288
288
|
.describe("Offset to start from.")
|
|
289
289
|
.optional(),
|
|
290
|
+
sort_by: z
|
|
291
|
+
.enum(["thread_id", "status", "created_at", "updated_at"])
|
|
292
|
+
.describe("Sort by field.")
|
|
293
|
+
.optional(),
|
|
294
|
+
sort_order: z.enum(["asc", "desc"]).describe("Sort order.").optional(),
|
|
290
295
|
})
|
|
291
296
|
.describe("Payload for listing threads.");
|
|
292
297
|
export const Thread = z.object({
|
package/dist/storage/ops.mjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { HTTPException } from "hono/http-exception";
|
|
2
2
|
import { v4 as uuid4, v5 as uuid5 } from "uuid";
|
|
3
|
+
import { handleAuthEvent, isAuthMatching } from "../auth/custom.mjs";
|
|
4
|
+
import { getLangGraphCommand } from "../command.mjs";
|
|
3
5
|
import { getGraph, NAMESPACE_GRAPH } from "../graph/load.mjs";
|
|
4
|
-
import { checkpointer } from "./checkpoint.mjs";
|
|
5
|
-
import { store } from "./store.mjs";
|
|
6
6
|
import { logger } from "../logging.mjs";
|
|
7
7
|
import { serializeError } from "../utils/serde.mjs";
|
|
8
|
+
import { checkpointer } from "./checkpoint.mjs";
|
|
8
9
|
import { FileSystemPersistence } from "./persist.mjs";
|
|
9
|
-
import {
|
|
10
|
-
import { handleAuthEvent, isAuthMatching } from "../auth/custom.mjs";
|
|
10
|
+
import { store } from "./store.mjs";
|
|
11
11
|
export const conn = new FileSystemPersistence(".langgraphjs_ops.json", () => ({
|
|
12
12
|
runs: {},
|
|
13
13
|
threads: {},
|
|
@@ -374,9 +374,27 @@ export class Threads {
|
|
|
374
374
|
return false;
|
|
375
375
|
return true;
|
|
376
376
|
})
|
|
377
|
-
.sort((a, b) =>
|
|
377
|
+
.sort((a, b) => {
|
|
378
|
+
const sortBy = options.sort_by ?? "created_at";
|
|
379
|
+
const sortOrder = options.sort_order ?? "desc";
|
|
380
|
+
if (sortBy === "created_at" || sortBy === "updated_at") {
|
|
381
|
+
const aTime = a[sortBy].getTime();
|
|
382
|
+
const bTime = b[sortBy].getTime();
|
|
383
|
+
return sortOrder === "desc" ? bTime - aTime : aTime - bTime;
|
|
384
|
+
}
|
|
385
|
+
if (sortBy === "thread_id" || sortBy === "status") {
|
|
386
|
+
const aVal = a[sortBy];
|
|
387
|
+
const bVal = b[sortBy];
|
|
388
|
+
return sortOrder === "desc"
|
|
389
|
+
? bVal.localeCompare(aVal)
|
|
390
|
+
: aVal.localeCompare(bVal);
|
|
391
|
+
}
|
|
392
|
+
return 0;
|
|
393
|
+
});
|
|
394
|
+
// Calculate total count before pagination
|
|
395
|
+
const total = filtered.length;
|
|
378
396
|
for (const thread of filtered.slice(options.offset, options.offset + options.limit)) {
|
|
379
|
-
yield thread;
|
|
397
|
+
yield { thread, total };
|
|
380
398
|
}
|
|
381
399
|
});
|
|
382
400
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@langchain/langgraph-api",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.27",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": "^18.19.0 || >=20.16.0"
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"winston": "^3.17.0",
|
|
44
44
|
"winston-console-format": "^1.0.8",
|
|
45
45
|
"zod": "^3.23.8",
|
|
46
|
-
"@langchain/langgraph-ui": "0.0.
|
|
46
|
+
"@langchain/langgraph-ui": "0.0.27"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
49
49
|
"@langchain/core": "^0.3.42",
|
|
50
50
|
"@langchain/langgraph": "^0.2.57",
|
|
51
51
|
"@langchain/langgraph-checkpoint": "^0.0.16",
|
|
52
|
-
"@langchain/langgraph-sdk": "^0.0.
|
|
52
|
+
"@langchain/langgraph-sdk": "^0.0.70",
|
|
53
53
|
"typescript": "^5.5.4"
|
|
54
54
|
},
|
|
55
55
|
"peerDependenciesMeta": {
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@langchain/langgraph-sdk": "^0.0.
|
|
61
|
+
"@langchain/langgraph-sdk": "^0.0.70",
|
|
62
62
|
"@types/babel__code-frame": "^7.0.6",
|
|
63
63
|
"@types/react": "^19.0.8",
|
|
64
64
|
"@types/react-dom": "^19.0.3",
|