@langchain/langgraph-cli 0.0.8 → 0.0.10
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/LICENSE +21 -93
- package/dist/cli/build.mjs +1 -1
- package/dist/cli/cli.mjs +0 -0
- package/dist/cli/dev.mjs +3 -3
- package/dist/cli/dev.python.mjs +1 -1
- package/dist/cli/docker.mjs +1 -1
- package/dist/cli/up.mjs +1 -1
- package/dist/{logging.mjs → utils/logging.mjs} +0 -4
- package/package.json +16 -32
- package/dist/api/assistants.mjs +0 -144
- package/dist/api/runs.mjs +0 -239
- package/dist/api/store.mjs +0 -83
- package/dist/api/threads.mjs +0 -143
- package/dist/cli/dev.node.entrypoint.mjs +0 -42
- package/dist/cli/dev.node.mjs +0 -35
- package/dist/cli/utils/ipc/client.mjs +0 -47
- package/dist/graph/load.hooks.mjs +0 -17
- package/dist/graph/load.mjs +0 -72
- package/dist/graph/load.utils.mjs +0 -50
- package/dist/graph/parser/parser.mjs +0 -308
- package/dist/graph/parser/parser.worker.mjs +0 -7
- package/dist/graph/parser/schema/types.mjs +0 -1607
- package/dist/graph/parser/schema/types.template.mts +0 -83
- package/dist/preload.mjs +0 -3
- package/dist/queue.mjs +0 -93
- package/dist/schemas.mjs +0 -407
- package/dist/server.mjs +0 -74
- package/dist/state.mjs +0 -32
- package/dist/storage/checkpoint.mjs +0 -127
- package/dist/storage/ops.mjs +0 -792
- package/dist/storage/persist.mjs +0 -69
- package/dist/storage/store.mjs +0 -41
- package/dist/stream.mjs +0 -215
- package/dist/utils/abort.mjs +0 -8
- package/dist/utils/error.mjs +0 -1
- package/dist/utils/hono.mjs +0 -27
- package/dist/utils/importMap.mjs +0 -55
- package/dist/utils/runnableConfig.mjs +0 -45
- package/dist/utils/serde.mjs +0 -20
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { MemorySaver, } from "@langchain/langgraph";
|
|
2
|
-
import { FileSystemPersistence } from "./persist.mjs";
|
|
3
|
-
const EXCLUDED_KEYS = ["checkpoint_ns", "checkpoint_id", "run_id", "thread_id"];
|
|
4
|
-
const textDecoder = new TextDecoder();
|
|
5
|
-
const textEncoder = new TextEncoder();
|
|
6
|
-
const WriteKey = {
|
|
7
|
-
serialize: (key) => {
|
|
8
|
-
return JSON.stringify(key);
|
|
9
|
-
},
|
|
10
|
-
deserialize: (key) => {
|
|
11
|
-
const [threadId, checkpointNamespace, checkpointId] = JSON.parse(key);
|
|
12
|
-
return [threadId, checkpointNamespace, checkpointId];
|
|
13
|
-
},
|
|
14
|
-
};
|
|
15
|
-
const conn = new FileSystemPersistence(".langgraphjs_api.checkpointer.json", () => ({
|
|
16
|
-
storage: {},
|
|
17
|
-
writes: {},
|
|
18
|
-
}));
|
|
19
|
-
class InMemorySaver extends MemorySaver {
|
|
20
|
-
async initialize(cwd) {
|
|
21
|
-
await conn.initialize(cwd);
|
|
22
|
-
await conn.with(({ storage, writes }) => {
|
|
23
|
-
this.storage = storage;
|
|
24
|
-
this.writes = writes;
|
|
25
|
-
});
|
|
26
|
-
return conn;
|
|
27
|
-
}
|
|
28
|
-
clear() {
|
|
29
|
-
// { [threadId: string]: { [checkpointNs: string]: { [checkpointId]: [checkpoint, metadata, parentId] } }}
|
|
30
|
-
this.storage = {};
|
|
31
|
-
// { [WriteKey]: CheckpointPendingWrite[] }
|
|
32
|
-
this.writes = {};
|
|
33
|
-
}
|
|
34
|
-
// Patch every method that has access to this.storage or this.writes
|
|
35
|
-
// to also persist the changes to the filesystem in a non-blocking manner
|
|
36
|
-
async getTuple(...args) {
|
|
37
|
-
return await conn.with(() => super.getTuple(...args));
|
|
38
|
-
}
|
|
39
|
-
async *list(...args) {
|
|
40
|
-
yield* conn.withGenerator(super.list(...args));
|
|
41
|
-
}
|
|
42
|
-
async putWrites(...args) {
|
|
43
|
-
return await conn.with(() => super.putWrites(...args));
|
|
44
|
-
}
|
|
45
|
-
async put(config, checkpoint, metadata) {
|
|
46
|
-
return await conn.with(() => super.put(config, checkpoint, {
|
|
47
|
-
...Object.fromEntries(Object.entries(config.configurable ?? {}).filter(([key]) => !key.startsWith("__") && !EXCLUDED_KEYS.includes(key))),
|
|
48
|
-
...config.metadata,
|
|
49
|
-
...metadata,
|
|
50
|
-
}));
|
|
51
|
-
}
|
|
52
|
-
async delete(threadId, runId) {
|
|
53
|
-
if (this.storage[threadId] == null)
|
|
54
|
-
return;
|
|
55
|
-
return await conn.with(() => {
|
|
56
|
-
if (runId != null) {
|
|
57
|
-
const writeKeysToDelete = [];
|
|
58
|
-
for (const ns of Object.keys(this.storage[threadId])) {
|
|
59
|
-
for (const id of Object.keys(this.storage[threadId][ns])) {
|
|
60
|
-
const [_checkpoint, metadata, _parentId] = this.storage[threadId][ns][id];
|
|
61
|
-
const jsonMetadata = JSON.parse(textDecoder.decode(metadata));
|
|
62
|
-
if (jsonMetadata.run_id === runId) {
|
|
63
|
-
delete this.storage[threadId][ns][id];
|
|
64
|
-
writeKeysToDelete.push(WriteKey.serialize([threadId, ns, id]));
|
|
65
|
-
if (Object.keys(this.storage[threadId][ns]).length === 0) {
|
|
66
|
-
delete this.storage[threadId][ns];
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
for (const key of writeKeysToDelete) {
|
|
72
|
-
delete this.writes[key];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
delete this.storage[threadId];
|
|
77
|
-
// delete all writes for this thread
|
|
78
|
-
const writeKeys = Object.keys(this.writes);
|
|
79
|
-
for (const key of writeKeys) {
|
|
80
|
-
const [writeThreadId] = WriteKey.deserialize(key);
|
|
81
|
-
if (writeThreadId === threadId)
|
|
82
|
-
delete this.writes[key];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
async copy(threadId, newThreadId) {
|
|
88
|
-
return await conn.with(() => {
|
|
89
|
-
// copy storage over
|
|
90
|
-
const newThreadCheckpoints = {};
|
|
91
|
-
for (const oldNs of Object.keys(this.storage[threadId] ?? {})) {
|
|
92
|
-
const newNs = oldNs.replace(threadId, newThreadId);
|
|
93
|
-
for (const oldId of Object.keys(this.storage[threadId][oldNs])) {
|
|
94
|
-
const newId = oldId.replace(threadId, newThreadId);
|
|
95
|
-
const [checkpoint, metadata, oldParentId] = this.storage[threadId][oldNs][oldId];
|
|
96
|
-
const newParentId = oldParentId?.replace(threadId, newThreadId);
|
|
97
|
-
const rawMetadata = textDecoder
|
|
98
|
-
.decode(metadata)
|
|
99
|
-
.replaceAll(threadId, newThreadId);
|
|
100
|
-
newThreadCheckpoints[newNs] ??= {};
|
|
101
|
-
newThreadCheckpoints[newNs][newId] = [
|
|
102
|
-
checkpoint,
|
|
103
|
-
textEncoder.encode(rawMetadata),
|
|
104
|
-
newParentId,
|
|
105
|
-
];
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
this.storage[newThreadId] = newThreadCheckpoints;
|
|
109
|
-
// copy writes over (if any)
|
|
110
|
-
const outerKeys = [];
|
|
111
|
-
for (const keyJson of Object.keys(this.writes)) {
|
|
112
|
-
const key = WriteKey.deserialize(keyJson);
|
|
113
|
-
if (key[0] === threadId)
|
|
114
|
-
outerKeys.push(keyJson);
|
|
115
|
-
}
|
|
116
|
-
for (const keyJson of outerKeys) {
|
|
117
|
-
const [_threadId, checkpointNamespace, checkpointId] = WriteKey.deserialize(keyJson);
|
|
118
|
-
this.writes[WriteKey.serialize([newThreadId, checkpointNamespace, checkpointId])] = structuredClone(this.writes[keyJson]);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
toJSON() {
|
|
123
|
-
// Prevent serialization of internal state
|
|
124
|
-
return "[InMemorySaver]";
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
export const checkpointer = new InMemorySaver();
|