@langchain/langgraph 0.1.0-rc.0 → 0.1.0
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 +1 -1
- package/dist/channels/base.cjs +20 -15
- package/dist/channels/base.d.ts +2 -3
- package/dist/channels/base.js +18 -13
- package/dist/checkpoint/sqlite.cjs +14 -199
- package/dist/checkpoint/sqlite.d.ts +1 -16
- package/dist/checkpoint/sqlite.js +1 -195
- package/dist/graph/graph.d.ts +1 -1
- package/dist/graph/message.d.ts +0 -3
- package/dist/graph/messages_annotation.cjs +12 -0
- package/dist/graph/messages_annotation.d.ts +4 -0
- package/dist/graph/messages_annotation.js +9 -0
- package/dist/graph/state.cjs +2 -1
- package/dist/graph/state.d.ts +1 -1
- package/dist/graph/state.js +2 -1
- package/dist/index.cjs +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/prebuilt/react_agent_executor.d.ts +3 -3
- package/dist/prebuilt/tool_node.d.ts +3 -3
- package/dist/pregel/algo.cjs +112 -105
- package/dist/pregel/algo.d.ts +8 -5
- package/dist/pregel/algo.js +109 -102
- package/dist/pregel/debug.cjs +9 -12
- package/dist/pregel/debug.d.ts +3 -2
- package/dist/pregel/debug.js +6 -10
- package/dist/pregel/index.cjs +92 -26
- package/dist/pregel/index.d.ts +41 -3
- package/dist/pregel/index.js +90 -24
- package/dist/pregel/io.d.ts +1 -1
- package/dist/pregel/loop.cjs +13 -9
- package/dist/pregel/loop.d.ts +1 -2
- package/dist/pregel/loop.js +8 -4
- package/dist/pregel/types.d.ts +5 -2
- package/dist/pregel/utils.cjs +25 -10
- package/dist/pregel/utils.d.ts +8 -1
- package/dist/pregel/utils.js +22 -9
- package/dist/web.cjs +6 -7
- package/dist/web.d.ts +1 -4
- package/dist/web.js +1 -2
- package/package.json +12 -12
- package/dist/checkpoint/base.cjs +0 -75
- package/dist/checkpoint/base.d.ts +0 -78
- package/dist/checkpoint/base.js +0 -66
- package/dist/checkpoint/id.cjs +0 -20
- package/dist/checkpoint/id.d.ts +0 -2
- package/dist/checkpoint/id.js +0 -15
- package/dist/checkpoint/index.cjs +0 -9
- package/dist/checkpoint/index.d.ts +0 -3
- package/dist/checkpoint/index.js +0 -2
- package/dist/checkpoint/memory.cjs +0 -195
- package/dist/checkpoint/memory.d.ts +0 -13
- package/dist/checkpoint/memory.js +0 -191
- package/dist/checkpoint/serde/types.cjs +0 -2
- package/dist/checkpoint/serde/types.d.ts +0 -40
- package/dist/checkpoint/serde/types.js +0 -1
- package/dist/checkpoint/types.cjs +0 -2
- package/dist/checkpoint/types.d.ts +0 -28
- package/dist/checkpoint/types.js +0 -1
- package/dist/serde/base.cjs +0 -8
- package/dist/serde/base.d.ts +0 -12
- package/dist/serde/base.js +0 -5
package/LICENSE
CHANGED
package/dist/channels/base.cjs
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createCheckpoint = exports.emptyChannels = exports.BaseChannel = void 0;
|
|
4
|
-
const
|
|
5
|
-
const id_js_1 = require("../checkpoint/id.cjs");
|
|
4
|
+
const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
|
|
6
5
|
const errors_js_1 = require("../errors.cjs");
|
|
7
6
|
class BaseChannel {
|
|
8
7
|
constructor() {
|
|
@@ -42,28 +41,34 @@ function emptyChannels(channels, checkpoint) {
|
|
|
42
41
|
exports.emptyChannels = emptyChannels;
|
|
43
42
|
function createCheckpoint(checkpoint, channels, step) {
|
|
44
43
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
44
|
+
let values;
|
|
45
|
+
if (channels === undefined) {
|
|
46
|
+
values = checkpoint.channel_values;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
values = {};
|
|
50
|
+
for (const k of Object.keys(channels)) {
|
|
51
|
+
try {
|
|
52
|
+
values[k] = channels[k].checkpoint();
|
|
53
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
54
54
|
}
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error.name === errors_js_1.EmptyChannelError.unminifiable_name) {
|
|
57
|
+
// no-op
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
throw error; // Rethrow unexpected errors
|
|
61
|
+
}
|
|
57
62
|
}
|
|
58
63
|
}
|
|
59
64
|
}
|
|
60
65
|
return {
|
|
61
66
|
v: 1,
|
|
62
|
-
id: (0,
|
|
67
|
+
id: (0, langgraph_checkpoint_1.uuid6)(step),
|
|
63
68
|
ts: new Date().toISOString(),
|
|
64
69
|
channel_values: values,
|
|
65
70
|
channel_versions: { ...checkpoint.channel_versions },
|
|
66
|
-
versions_seen: (0,
|
|
71
|
+
versions_seen: (0, langgraph_checkpoint_1.deepCopy)(checkpoint.versions_seen),
|
|
67
72
|
pending_sends: checkpoint.pending_sends ?? [],
|
|
68
73
|
};
|
|
69
74
|
}
|
package/dist/channels/base.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { ReadonlyCheckpoint } from "
|
|
2
|
-
import { Checkpoint } from "../checkpoint/index.js";
|
|
1
|
+
import { ReadonlyCheckpoint, Checkpoint } from "@langchain/langgraph-checkpoint";
|
|
3
2
|
export declare abstract class BaseChannel<ValueType = unknown, UpdateType = unknown, CheckpointType = unknown> {
|
|
4
3
|
ValueType: ValueType;
|
|
5
4
|
UpdateType: UpdateType;
|
|
@@ -52,4 +51,4 @@ export declare abstract class BaseChannel<ValueType = unknown, UpdateType = unkn
|
|
|
52
51
|
consume(): boolean;
|
|
53
52
|
}
|
|
54
53
|
export declare function emptyChannels<Cc extends Record<string, BaseChannel>>(channels: Cc, checkpoint: ReadonlyCheckpoint): Cc;
|
|
55
|
-
export declare function createCheckpoint<ValueType>(checkpoint: ReadonlyCheckpoint, channels: Record<string, BaseChannel<ValueType
|
|
54
|
+
export declare function createCheckpoint<ValueType>(checkpoint: ReadonlyCheckpoint, channels: Record<string, BaseChannel<ValueType>> | undefined, step: number): Checkpoint;
|
package/dist/channels/base.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { deepCopy } from "
|
|
2
|
-
import { uuid6 } from "../checkpoint/id.js";
|
|
1
|
+
import { deepCopy, uuid6, } from "@langchain/langgraph-checkpoint";
|
|
3
2
|
import { EmptyChannelError } from "../errors.js";
|
|
4
3
|
export class BaseChannel {
|
|
5
4
|
constructor() {
|
|
@@ -37,18 +36,24 @@ export function emptyChannels(channels, checkpoint) {
|
|
|
37
36
|
}
|
|
38
37
|
export function createCheckpoint(checkpoint, channels, step) {
|
|
39
38
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
39
|
+
let values;
|
|
40
|
+
if (channels === undefined) {
|
|
41
|
+
values = checkpoint.channel_values;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
values = {};
|
|
45
|
+
for (const k of Object.keys(channels)) {
|
|
46
|
+
try {
|
|
47
|
+
values[k] = channels[k].checkpoint();
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
49
|
}
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error.name === EmptyChannelError.unminifiable_name) {
|
|
52
|
+
// no-op
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
throw error; // Rethrow unexpected errors
|
|
56
|
+
}
|
|
52
57
|
}
|
|
53
58
|
}
|
|
54
59
|
}
|
|
@@ -1,202 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports
|
|
7
|
-
const better_sqlite3_1 = __importDefault(require("better-sqlite3"));
|
|
8
|
-
const base_js_1 = require("./base.cjs");
|
|
9
|
-
class SqliteSaver extends base_js_1.BaseCheckpointSaver {
|
|
10
|
-
constructor(db, serde) {
|
|
11
|
-
super(serde);
|
|
12
|
-
Object.defineProperty(this, "db", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "isSetup", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: void 0
|
|
23
|
-
});
|
|
24
|
-
this.db = db;
|
|
25
|
-
this.isSetup = false;
|
|
26
|
-
}
|
|
27
|
-
static fromConnString(connStringOrLocalPath) {
|
|
28
|
-
return new SqliteSaver(new better_sqlite3_1.default(connStringOrLocalPath));
|
|
29
|
-
}
|
|
30
|
-
setup() {
|
|
31
|
-
if (this.isSetup) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
|
-
this.db.pragma("journal_mode=WAL");
|
|
35
|
-
this.db.exec(`
|
|
36
|
-
CREATE TABLE IF NOT EXISTS checkpoints (
|
|
37
|
-
thread_id TEXT NOT NULL,
|
|
38
|
-
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
39
|
-
checkpoint_id TEXT NOT NULL,
|
|
40
|
-
parent_checkpoint_id TEXT,
|
|
41
|
-
type TEXT,
|
|
42
|
-
checkpoint BLOB,
|
|
43
|
-
metadata BLOB,
|
|
44
|
-
PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id)
|
|
45
|
-
);`);
|
|
46
|
-
this.db.exec(`
|
|
47
|
-
CREATE TABLE IF NOT EXISTS writes (
|
|
48
|
-
thread_id TEXT NOT NULL,
|
|
49
|
-
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
50
|
-
checkpoint_id TEXT NOT NULL,
|
|
51
|
-
task_id TEXT NOT NULL,
|
|
52
|
-
idx INTEGER NOT NULL,
|
|
53
|
-
channel TEXT NOT NULL,
|
|
54
|
-
type TEXT,
|
|
55
|
-
value BLOB,
|
|
56
|
-
PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id, task_id, idx)
|
|
57
|
-
);`);
|
|
58
|
-
this.isSetup = true;
|
|
59
|
-
}
|
|
60
|
-
async getTuple(config) {
|
|
61
|
-
this.setup();
|
|
62
|
-
const { thread_id, checkpoint_ns = "", checkpoint_id, } = config.configurable ?? {};
|
|
63
|
-
let row;
|
|
64
|
-
if (checkpoint_id) {
|
|
65
|
-
row = this.db
|
|
66
|
-
.prepare(`SELECT thread_id, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata FROM checkpoints WHERE thread_id = ? AND checkpoint_ns = ? AND checkpoint_id = ?`)
|
|
67
|
-
.get(thread_id, checkpoint_ns, checkpoint_id);
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
row = this.db
|
|
71
|
-
.prepare(`SELECT thread_id, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata FROM checkpoints WHERE thread_id = ? AND checkpoint_ns = ? ORDER BY checkpoint_id DESC LIMIT 1`)
|
|
72
|
-
.get(thread_id, checkpoint_ns);
|
|
73
|
-
}
|
|
74
|
-
if (row === undefined) {
|
|
75
|
-
return undefined;
|
|
76
|
-
}
|
|
77
|
-
let finalConfig = config;
|
|
78
|
-
if (!checkpoint_id) {
|
|
79
|
-
finalConfig = {
|
|
80
|
-
configurable: {
|
|
81
|
-
thread_id: row.thread_id,
|
|
82
|
-
checkpoint_ns,
|
|
83
|
-
checkpoint_id: row.checkpoint_id,
|
|
84
|
-
},
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if (finalConfig.configurable?.thread_id === undefined ||
|
|
88
|
-
finalConfig.configurable?.checkpoint_id === undefined) {
|
|
89
|
-
throw new Error("Missing thread_id or checkpoint_id");
|
|
90
|
-
}
|
|
91
|
-
// find any pending writes
|
|
92
|
-
const pendingWritesRows = this.db
|
|
93
|
-
.prepare(`SELECT task_id, channel, type, value FROM writes WHERE thread_id = ? AND checkpoint_ns = ? AND checkpoint_id = ?`)
|
|
94
|
-
.all(finalConfig.configurable.thread_id.toString(), checkpoint_ns, finalConfig.configurable.checkpoint_id.toString());
|
|
95
|
-
const pendingWrites = await Promise.all(pendingWritesRows.map(async (row) => {
|
|
96
|
-
return [
|
|
97
|
-
row.task_id,
|
|
98
|
-
row.channel,
|
|
99
|
-
await this.serde.parse(row.value ?? ""),
|
|
100
|
-
];
|
|
101
|
-
}));
|
|
102
|
-
return {
|
|
103
|
-
config: finalConfig,
|
|
104
|
-
checkpoint: (await this.serde.parse(row.checkpoint)),
|
|
105
|
-
metadata: (await this.serde.parse(row.metadata)),
|
|
106
|
-
parentConfig: row.parent_checkpoint_id
|
|
107
|
-
? {
|
|
108
|
-
configurable: {
|
|
109
|
-
thread_id: row.thread_id,
|
|
110
|
-
checkpoint_ns,
|
|
111
|
-
checkpoint_id: row.parent_checkpoint_id,
|
|
112
|
-
},
|
|
113
|
-
}
|
|
114
|
-
: undefined,
|
|
115
|
-
pendingWrites,
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
async *list(config, options) {
|
|
119
|
-
const { limit, before } = options ?? {};
|
|
120
|
-
this.setup();
|
|
121
|
-
const thread_id = config.configurable?.thread_id;
|
|
122
|
-
let sql = `SELECT thread_id, checkpoint_ns, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata FROM checkpoints WHERE thread_id = ? ${before ? "AND checkpoint_id < ?" : ""} ORDER BY checkpoint_id DESC`;
|
|
123
|
-
if (limit) {
|
|
124
|
-
sql += ` LIMIT ${limit}`;
|
|
125
|
-
}
|
|
126
|
-
const args = [thread_id, before?.configurable?.checkpoint_id].filter(Boolean);
|
|
127
|
-
const rows = this.db
|
|
128
|
-
.prepare(sql)
|
|
129
|
-
.all(...args);
|
|
130
|
-
if (rows) {
|
|
131
|
-
for (const row of rows) {
|
|
132
|
-
yield {
|
|
133
|
-
config: {
|
|
134
|
-
configurable: {
|
|
135
|
-
thread_id: row.thread_id,
|
|
136
|
-
checkpoint_ns: row.checkpoint_ns,
|
|
137
|
-
checkpoint_id: row.checkpoint_id,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
checkpoint: (await this.serde.parse(row.checkpoint)),
|
|
141
|
-
metadata: (await this.serde.parse(row.metadata)),
|
|
142
|
-
parentConfig: row.parent_checkpoint_id
|
|
143
|
-
? {
|
|
144
|
-
configurable: {
|
|
145
|
-
thread_id: row.thread_id,
|
|
146
|
-
checkpoint_ns: row.checkpoint_ns,
|
|
147
|
-
checkpoint_id: row.parent_checkpoint_id,
|
|
148
|
-
},
|
|
149
|
-
}
|
|
150
|
-
: undefined,
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
async put(config, checkpoint, metadata) {
|
|
156
|
-
this.setup();
|
|
157
|
-
const row = [
|
|
158
|
-
config.configurable?.thread_id?.toString(),
|
|
159
|
-
config.configurable?.checkpoint_ns,
|
|
160
|
-
checkpoint.id,
|
|
161
|
-
config.configurable?.checkpoint_id,
|
|
162
|
-
"Checkpoint",
|
|
163
|
-
this.serde.stringify(checkpoint),
|
|
164
|
-
this.serde.stringify(metadata),
|
|
165
|
-
];
|
|
166
|
-
this.db
|
|
167
|
-
.prepare(`INSERT OR REPLACE INTO checkpoints (thread_id, checkpoint_ns, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata) VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
168
|
-
.run(...row);
|
|
169
|
-
return {
|
|
170
|
-
configurable: {
|
|
171
|
-
thread_id: config.configurable?.thread_id,
|
|
172
|
-
checkpoint_ns: config.configurable?.checkpoint_ns,
|
|
173
|
-
checkpoint_id: checkpoint.id,
|
|
174
|
-
},
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
async putWrites(config, writes, taskId) {
|
|
178
|
-
this.setup();
|
|
179
|
-
const stmt = this.db.prepare(`
|
|
180
|
-
INSERT OR REPLACE INTO writes
|
|
181
|
-
(thread_id, checkpoint_ns, checkpoint_id, task_id, idx, channel, type, value)
|
|
182
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
183
|
-
`);
|
|
184
|
-
const transaction = this.db.transaction((rows) => {
|
|
185
|
-
for (const row of rows) {
|
|
186
|
-
stmt.run(...row);
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
const rows = writes.map((write, idx) => [
|
|
190
|
-
config.configurable?.thread_id,
|
|
191
|
-
config.configurable?.checkpoint_ns,
|
|
192
|
-
config.configurable?.checkpoint_id,
|
|
193
|
-
taskId,
|
|
194
|
-
idx,
|
|
195
|
-
write[0],
|
|
196
|
-
"Checkpoint",
|
|
197
|
-
this.serde.stringify(write[1]),
|
|
198
|
-
]);
|
|
199
|
-
transaction(rows);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.SqliteSaver = SqliteSaver;
|
|
17
|
+
__exportStar(require("@langchain/langgraph-checkpoint-sqlite"), exports);
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { RunnableConfig } from "@langchain/core/runnables";
|
|
3
|
-
import { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointTuple } from "./base.js";
|
|
4
|
-
import { SerializerProtocol } from "../serde/base.js";
|
|
5
|
-
import type { PendingWrite, CheckpointMetadata } from "../checkpoint/types.js";
|
|
6
|
-
export declare class SqliteSaver extends BaseCheckpointSaver {
|
|
7
|
-
db: DatabaseType;
|
|
8
|
-
protected isSetup: boolean;
|
|
9
|
-
constructor(db: DatabaseType, serde?: SerializerProtocol<Checkpoint>);
|
|
10
|
-
static fromConnString(connStringOrLocalPath: string): SqliteSaver;
|
|
11
|
-
protected setup(): void;
|
|
12
|
-
getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
|
|
13
|
-
list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
|
|
14
|
-
put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
|
|
15
|
-
putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
|
|
16
|
-
}
|
|
1
|
+
export * from "@langchain/langgraph-checkpoint-sqlite";
|
|
@@ -1,195 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BaseCheckpointSaver, } from "./base.js";
|
|
3
|
-
export class SqliteSaver extends BaseCheckpointSaver {
|
|
4
|
-
constructor(db, serde) {
|
|
5
|
-
super(serde);
|
|
6
|
-
Object.defineProperty(this, "db", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
configurable: true,
|
|
9
|
-
writable: true,
|
|
10
|
-
value: void 0
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(this, "isSetup", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: void 0
|
|
17
|
-
});
|
|
18
|
-
this.db = db;
|
|
19
|
-
this.isSetup = false;
|
|
20
|
-
}
|
|
21
|
-
static fromConnString(connStringOrLocalPath) {
|
|
22
|
-
return new SqliteSaver(new Database(connStringOrLocalPath));
|
|
23
|
-
}
|
|
24
|
-
setup() {
|
|
25
|
-
if (this.isSetup) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
this.db.pragma("journal_mode=WAL");
|
|
29
|
-
this.db.exec(`
|
|
30
|
-
CREATE TABLE IF NOT EXISTS checkpoints (
|
|
31
|
-
thread_id TEXT NOT NULL,
|
|
32
|
-
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
33
|
-
checkpoint_id TEXT NOT NULL,
|
|
34
|
-
parent_checkpoint_id TEXT,
|
|
35
|
-
type TEXT,
|
|
36
|
-
checkpoint BLOB,
|
|
37
|
-
metadata BLOB,
|
|
38
|
-
PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id)
|
|
39
|
-
);`);
|
|
40
|
-
this.db.exec(`
|
|
41
|
-
CREATE TABLE IF NOT EXISTS writes (
|
|
42
|
-
thread_id TEXT NOT NULL,
|
|
43
|
-
checkpoint_ns TEXT NOT NULL DEFAULT '',
|
|
44
|
-
checkpoint_id TEXT NOT NULL,
|
|
45
|
-
task_id TEXT NOT NULL,
|
|
46
|
-
idx INTEGER NOT NULL,
|
|
47
|
-
channel TEXT NOT NULL,
|
|
48
|
-
type TEXT,
|
|
49
|
-
value BLOB,
|
|
50
|
-
PRIMARY KEY (thread_id, checkpoint_ns, checkpoint_id, task_id, idx)
|
|
51
|
-
);`);
|
|
52
|
-
this.isSetup = true;
|
|
53
|
-
}
|
|
54
|
-
async getTuple(config) {
|
|
55
|
-
this.setup();
|
|
56
|
-
const { thread_id, checkpoint_ns = "", checkpoint_id, } = config.configurable ?? {};
|
|
57
|
-
let row;
|
|
58
|
-
if (checkpoint_id) {
|
|
59
|
-
row = this.db
|
|
60
|
-
.prepare(`SELECT thread_id, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata FROM checkpoints WHERE thread_id = ? AND checkpoint_ns = ? AND checkpoint_id = ?`)
|
|
61
|
-
.get(thread_id, checkpoint_ns, checkpoint_id);
|
|
62
|
-
}
|
|
63
|
-
else {
|
|
64
|
-
row = this.db
|
|
65
|
-
.prepare(`SELECT thread_id, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata FROM checkpoints WHERE thread_id = ? AND checkpoint_ns = ? ORDER BY checkpoint_id DESC LIMIT 1`)
|
|
66
|
-
.get(thread_id, checkpoint_ns);
|
|
67
|
-
}
|
|
68
|
-
if (row === undefined) {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
let finalConfig = config;
|
|
72
|
-
if (!checkpoint_id) {
|
|
73
|
-
finalConfig = {
|
|
74
|
-
configurable: {
|
|
75
|
-
thread_id: row.thread_id,
|
|
76
|
-
checkpoint_ns,
|
|
77
|
-
checkpoint_id: row.checkpoint_id,
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
if (finalConfig.configurable?.thread_id === undefined ||
|
|
82
|
-
finalConfig.configurable?.checkpoint_id === undefined) {
|
|
83
|
-
throw new Error("Missing thread_id or checkpoint_id");
|
|
84
|
-
}
|
|
85
|
-
// find any pending writes
|
|
86
|
-
const pendingWritesRows = this.db
|
|
87
|
-
.prepare(`SELECT task_id, channel, type, value FROM writes WHERE thread_id = ? AND checkpoint_ns = ? AND checkpoint_id = ?`)
|
|
88
|
-
.all(finalConfig.configurable.thread_id.toString(), checkpoint_ns, finalConfig.configurable.checkpoint_id.toString());
|
|
89
|
-
const pendingWrites = await Promise.all(pendingWritesRows.map(async (row) => {
|
|
90
|
-
return [
|
|
91
|
-
row.task_id,
|
|
92
|
-
row.channel,
|
|
93
|
-
await this.serde.parse(row.value ?? ""),
|
|
94
|
-
];
|
|
95
|
-
}));
|
|
96
|
-
return {
|
|
97
|
-
config: finalConfig,
|
|
98
|
-
checkpoint: (await this.serde.parse(row.checkpoint)),
|
|
99
|
-
metadata: (await this.serde.parse(row.metadata)),
|
|
100
|
-
parentConfig: row.parent_checkpoint_id
|
|
101
|
-
? {
|
|
102
|
-
configurable: {
|
|
103
|
-
thread_id: row.thread_id,
|
|
104
|
-
checkpoint_ns,
|
|
105
|
-
checkpoint_id: row.parent_checkpoint_id,
|
|
106
|
-
},
|
|
107
|
-
}
|
|
108
|
-
: undefined,
|
|
109
|
-
pendingWrites,
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
async *list(config, options) {
|
|
113
|
-
const { limit, before } = options ?? {};
|
|
114
|
-
this.setup();
|
|
115
|
-
const thread_id = config.configurable?.thread_id;
|
|
116
|
-
let sql = `SELECT thread_id, checkpoint_ns, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata FROM checkpoints WHERE thread_id = ? ${before ? "AND checkpoint_id < ?" : ""} ORDER BY checkpoint_id DESC`;
|
|
117
|
-
if (limit) {
|
|
118
|
-
sql += ` LIMIT ${limit}`;
|
|
119
|
-
}
|
|
120
|
-
const args = [thread_id, before?.configurable?.checkpoint_id].filter(Boolean);
|
|
121
|
-
const rows = this.db
|
|
122
|
-
.prepare(sql)
|
|
123
|
-
.all(...args);
|
|
124
|
-
if (rows) {
|
|
125
|
-
for (const row of rows) {
|
|
126
|
-
yield {
|
|
127
|
-
config: {
|
|
128
|
-
configurable: {
|
|
129
|
-
thread_id: row.thread_id,
|
|
130
|
-
checkpoint_ns: row.checkpoint_ns,
|
|
131
|
-
checkpoint_id: row.checkpoint_id,
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
checkpoint: (await this.serde.parse(row.checkpoint)),
|
|
135
|
-
metadata: (await this.serde.parse(row.metadata)),
|
|
136
|
-
parentConfig: row.parent_checkpoint_id
|
|
137
|
-
? {
|
|
138
|
-
configurable: {
|
|
139
|
-
thread_id: row.thread_id,
|
|
140
|
-
checkpoint_ns: row.checkpoint_ns,
|
|
141
|
-
checkpoint_id: row.parent_checkpoint_id,
|
|
142
|
-
},
|
|
143
|
-
}
|
|
144
|
-
: undefined,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
async put(config, checkpoint, metadata) {
|
|
150
|
-
this.setup();
|
|
151
|
-
const row = [
|
|
152
|
-
config.configurable?.thread_id?.toString(),
|
|
153
|
-
config.configurable?.checkpoint_ns,
|
|
154
|
-
checkpoint.id,
|
|
155
|
-
config.configurable?.checkpoint_id,
|
|
156
|
-
"Checkpoint",
|
|
157
|
-
this.serde.stringify(checkpoint),
|
|
158
|
-
this.serde.stringify(metadata),
|
|
159
|
-
];
|
|
160
|
-
this.db
|
|
161
|
-
.prepare(`INSERT OR REPLACE INTO checkpoints (thread_id, checkpoint_ns, checkpoint_id, parent_checkpoint_id, type, checkpoint, metadata) VALUES (?, ?, ?, ?, ?, ?, ?)`)
|
|
162
|
-
.run(...row);
|
|
163
|
-
return {
|
|
164
|
-
configurable: {
|
|
165
|
-
thread_id: config.configurable?.thread_id,
|
|
166
|
-
checkpoint_ns: config.configurable?.checkpoint_ns,
|
|
167
|
-
checkpoint_id: checkpoint.id,
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
async putWrites(config, writes, taskId) {
|
|
172
|
-
this.setup();
|
|
173
|
-
const stmt = this.db.prepare(`
|
|
174
|
-
INSERT OR REPLACE INTO writes
|
|
175
|
-
(thread_id, checkpoint_ns, checkpoint_id, task_id, idx, channel, type, value)
|
|
176
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
|
177
|
-
`);
|
|
178
|
-
const transaction = this.db.transaction((rows) => {
|
|
179
|
-
for (const row of rows) {
|
|
180
|
-
stmt.run(...row);
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
const rows = writes.map((write, idx) => [
|
|
184
|
-
config.configurable?.thread_id,
|
|
185
|
-
config.configurable?.checkpoint_ns,
|
|
186
|
-
config.configurable?.checkpoint_id,
|
|
187
|
-
taskId,
|
|
188
|
-
idx,
|
|
189
|
-
write[0],
|
|
190
|
-
"Checkpoint",
|
|
191
|
-
this.serde.stringify(write[1]),
|
|
192
|
-
]);
|
|
193
|
-
transaction(rows);
|
|
194
|
-
}
|
|
195
|
-
}
|
|
1
|
+
export * from "@langchain/langgraph-checkpoint-sqlite";
|
package/dist/graph/graph.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Runnable, RunnableConfig, RunnableLike } from "@langchain/core/runnables";
|
|
2
2
|
import { Graph as RunnableGraph } from "@langchain/core/runnables/graph";
|
|
3
|
+
import { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
|
|
3
4
|
import { PregelNode } from "../pregel/read.js";
|
|
4
5
|
import { Pregel } from "../pregel/index.js";
|
|
5
6
|
import type { PregelParams } from "../pregel/types.js";
|
|
6
|
-
import { BaseCheckpointSaver } from "../checkpoint/base.js";
|
|
7
7
|
import { BaseChannel } from "../channels/base.js";
|
|
8
8
|
import { All } from "../pregel/types.js";
|
|
9
9
|
import { Send } from "../constants.js";
|
package/dist/graph/message.d.ts
CHANGED
|
@@ -5,7 +5,4 @@ export declare function messagesStateReducer(left: BaseMessage[], right: Message
|
|
|
5
5
|
export declare class MessageGraph extends StateGraph<BaseMessage[], BaseMessage[], Messages> {
|
|
6
6
|
constructor();
|
|
7
7
|
}
|
|
8
|
-
export interface MessagesState {
|
|
9
|
-
messages: BaseMessage[];
|
|
10
|
-
}
|
|
11
8
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.MessagesAnnotation = void 0;
|
|
5
|
+
const annotation_js_1 = require("./annotation.cjs");
|
|
6
|
+
const message_js_1 = require("./message.cjs");
|
|
7
|
+
exports.MessagesAnnotation = annotation_js_1.Annotation.Root({
|
|
8
|
+
messages: (0, annotation_js_1.Annotation)({
|
|
9
|
+
reducer: message_js_1.messagesStateReducer,
|
|
10
|
+
default: () => [],
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/* __LC_ALLOW_ENTRYPOINT_SIDE_EFFECTS__ */
|
|
2
|
+
import { Annotation } from "./annotation.js";
|
|
3
|
+
import { messagesStateReducer } from "./message.js";
|
|
4
|
+
export const MessagesAnnotation = Annotation.Root({
|
|
5
|
+
messages: Annotation({
|
|
6
|
+
reducer: messagesStateReducer,
|
|
7
|
+
default: () => [],
|
|
8
|
+
}),
|
|
9
|
+
});
|
package/dist/graph/state.cjs
CHANGED
|
@@ -155,7 +155,8 @@ class CompiledStateGraph extends graph_js_1.CompiledGraph {
|
|
|
155
155
|
return write_js_1.SKIP_WRITE;
|
|
156
156
|
}
|
|
157
157
|
else if (typeof input !== "object" || Array.isArray(input)) {
|
|
158
|
-
|
|
158
|
+
const typeofInput = Array.isArray(input) ? "array" : typeof input;
|
|
159
|
+
throw new errors_js_1.InvalidUpdateError(`Expected object, got ${typeofInput}`);
|
|
159
160
|
}
|
|
160
161
|
else {
|
|
161
162
|
return key in input ? input[key] : write_js_1.SKIP_WRITE;
|
package/dist/graph/state.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Runnable, RunnableConfig, RunnableLike } from "@langchain/core/runnables";
|
|
2
|
+
import { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
|
|
2
3
|
import { BaseChannel } from "../channels/base.js";
|
|
3
4
|
import { END, CompiledGraph, Graph, START, Branch } from "./graph.js";
|
|
4
|
-
import { BaseCheckpointSaver } from "../checkpoint/base.js";
|
|
5
5
|
import { All } from "../pregel/types.js";
|
|
6
6
|
import { AnnotationRoot, SingleReducer, StateDefinition, StateType, UpdateType } from "./annotation.js";
|
|
7
7
|
export type ChannelReducers<Channels extends object> = {
|
package/dist/graph/state.js
CHANGED
|
@@ -151,7 +151,8 @@ export class CompiledStateGraph extends CompiledGraph {
|
|
|
151
151
|
return SKIP_WRITE;
|
|
152
152
|
}
|
|
153
153
|
else if (typeof input !== "object" || Array.isArray(input)) {
|
|
154
|
-
|
|
154
|
+
const typeofInput = Array.isArray(input) ? "array" : typeof input;
|
|
155
|
+
throw new InvalidUpdateError(`Expected object, got ${typeofInput}`);
|
|
155
156
|
}
|
|
156
157
|
else {
|
|
157
158
|
return key in input ? input[key] : SKIP_WRITE;
|
package/dist/index.cjs
CHANGED
|
@@ -15,7 +15,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
16
|
};
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.MessagesAnnotation = void 0;
|
|
18
19
|
const async_local_storage_js_1 = require("./setup/async_local_storage.cjs");
|
|
19
20
|
// Initialize global async local storage instance for tracing
|
|
20
21
|
(0, async_local_storage_js_1.initializeAsyncLocalStorageSingleton)();
|
|
21
22
|
__exportStar(require("./web.cjs"), exports);
|
|
23
|
+
var messages_annotation_js_1 = require("./graph/messages_annotation.cjs");
|
|
24
|
+
Object.defineProperty(exports, "MessagesAnnotation", { enumerable: true, get: function () { return messages_annotation_js_1.MessagesAnnotation; } });
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,3 +3,4 @@ import { initializeAsyncLocalStorageSingleton } from "./setup/async_local_storag
|
|
|
3
3
|
// Initialize global async local storage instance for tracing
|
|
4
4
|
initializeAsyncLocalStorageSingleton();
|
|
5
5
|
export * from "./web.js";
|
|
6
|
+
export { MessagesAnnotation } from "./graph/messages_annotation.js";
|