@langchain/langgraph-checkpoint-mongodb 0.1.0 → 1.0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @langchain/langgraph-checkpoint-mongodb
2
2
 
3
+ ## 1.0.0
4
+
5
+ ### Major Changes
6
+
7
+ - 1e1ecbb: This release updates the package for compatibility with LangGraph v1.0. See the [v1.0 release notes](https://docs.langchain.com/oss/javascript/releases/langgraph-v1) for details on what's new.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [1e1ecbb]
12
+ - @langchain/langgraph-checkpoint@1.0.0
13
+
14
+ ## 0.1.1
15
+
16
+ ### Patch Changes
17
+
18
+ - 11c7807: Add support for @langchain/core 1.0.0-alpha
19
+
3
20
  ## 0.1.0
4
21
 
5
22
  ### Minor Changes
@@ -0,0 +1,25 @@
1
+ //#region rolldown:runtime
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+
23
+ //#endregion
24
+
25
+ exports.__toESM = __toESM;
package/dist/index.cjs CHANGED
@@ -1,242 +1,168 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MongoDBSaver = void 0;
4
- const langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
+ const __langchain_langgraph_checkpoint = require_rolldown_runtime.__toESM(require("@langchain/langgraph-checkpoint"));
3
+
4
+ //#region src/index.ts
5
5
  /**
6
- * A LangGraph checkpoint saver backed by a MongoDB database.
7
- */
8
- class MongoDBSaver extends langgraph_checkpoint_1.BaseCheckpointSaver {
9
- constructor({ client, dbName, checkpointCollectionName, checkpointWritesCollectionName, }, serde) {
10
- super(serde);
11
- Object.defineProperty(this, "client", {
12
- enumerable: true,
13
- configurable: true,
14
- writable: true,
15
- value: void 0
16
- });
17
- Object.defineProperty(this, "db", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: void 0
22
- });
23
- Object.defineProperty(this, "checkpointCollectionName", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: "checkpoints"
28
- });
29
- Object.defineProperty(this, "checkpointWritesCollectionName", {
30
- enumerable: true,
31
- configurable: true,
32
- writable: true,
33
- value: "checkpoint_writes"
34
- });
35
- this.client = client;
36
- this.db = this.client.db(dbName);
37
- this.checkpointCollectionName =
38
- checkpointCollectionName ?? this.checkpointCollectionName;
39
- this.checkpointWritesCollectionName =
40
- checkpointWritesCollectionName ?? this.checkpointWritesCollectionName;
41
- }
42
- /**
43
- * Retrieves a checkpoint from the MongoDB database based on the
44
- * provided config. If the config contains a "checkpoint_id" key, the checkpoint with
45
- * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
46
- * for the given thread ID is retrieved.
47
- */
48
- async getTuple(config) {
49
- const { thread_id, checkpoint_ns = "", checkpoint_id, } = config.configurable ?? {};
50
- let query;
51
- if (checkpoint_id) {
52
- query = {
53
- thread_id,
54
- checkpoint_ns,
55
- checkpoint_id,
56
- };
57
- }
58
- else {
59
- query = { thread_id, checkpoint_ns };
60
- }
61
- const result = await this.db
62
- .collection(this.checkpointCollectionName)
63
- .find(query)
64
- .sort("checkpoint_id", -1)
65
- .limit(1)
66
- .toArray();
67
- if (result.length === 0) {
68
- return undefined;
69
- }
70
- const doc = result[0];
71
- const configurableValues = {
72
- thread_id,
73
- checkpoint_ns,
74
- checkpoint_id: doc.checkpoint_id,
75
- };
76
- const checkpoint = (await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8")));
77
- const serializedWrites = await this.db
78
- .collection(this.checkpointWritesCollectionName)
79
- .find(configurableValues)
80
- .toArray();
81
- const pendingWrites = await Promise.all(serializedWrites.map(async (serializedWrite) => {
82
- return [
83
- serializedWrite.task_id,
84
- serializedWrite.channel,
85
- await this.serde.loadsTyped(serializedWrite.type, serializedWrite.value.value("utf8")),
86
- ];
87
- }));
88
- return {
89
- config: { configurable: configurableValues },
90
- checkpoint,
91
- pendingWrites,
92
- metadata: (await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8"))),
93
- parentConfig: doc.parent_checkpoint_id != null
94
- ? {
95
- configurable: {
96
- thread_id,
97
- checkpoint_ns,
98
- checkpoint_id: doc.parent_checkpoint_id,
99
- },
100
- }
101
- : undefined,
102
- };
103
- }
104
- /**
105
- * Retrieve a list of checkpoint tuples from the MongoDB database based
106
- * on the provided config. The checkpoints are ordered by checkpoint ID
107
- * in descending order (newest first).
108
- */
109
- async *list(config, options) {
110
- const { limit, before, filter } = options ?? {};
111
- const query = {};
112
- if (config?.configurable?.thread_id) {
113
- query.thread_id = config.configurable.thread_id;
114
- }
115
- if (config?.configurable?.checkpoint_ns !== undefined &&
116
- config?.configurable?.checkpoint_ns !== null) {
117
- query.checkpoint_ns = config.configurable.checkpoint_ns;
118
- }
119
- if (filter) {
120
- Object.entries(filter).forEach(([key, value]) => {
121
- query[`metadata.${key}`] = value;
122
- });
123
- }
124
- if (before) {
125
- query.checkpoint_id = { $lt: before.configurable?.checkpoint_id };
126
- }
127
- let result = this.db
128
- .collection(this.checkpointCollectionName)
129
- .find(query)
130
- .sort("checkpoint_id", -1);
131
- if (limit !== undefined) {
132
- result = result.limit(limit);
133
- }
134
- for await (const doc of result) {
135
- const checkpoint = (await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8")));
136
- const metadata = (await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8")));
137
- yield {
138
- config: {
139
- configurable: {
140
- thread_id: doc.thread_id,
141
- checkpoint_ns: doc.checkpoint_ns,
142
- checkpoint_id: doc.checkpoint_id,
143
- },
144
- },
145
- checkpoint,
146
- metadata,
147
- parentConfig: doc.parent_checkpoint_id
148
- ? {
149
- configurable: {
150
- thread_id: doc.thread_id,
151
- checkpoint_ns: doc.checkpoint_ns,
152
- checkpoint_id: doc.parent_checkpoint_id,
153
- },
154
- }
155
- : undefined,
156
- };
157
- }
158
- }
159
- /**
160
- * Saves a checkpoint to the MongoDB database. The checkpoint is associated
161
- * with the provided config and its parent config (if any).
162
- */
163
- async put(config, checkpoint, metadata) {
164
- const thread_id = config.configurable?.thread_id;
165
- const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
166
- const checkpoint_id = checkpoint.id;
167
- if (thread_id === undefined) {
168
- throw new Error(`The provided config must contain a configurable field with a "thread_id" field.`);
169
- }
170
- const [[checkpointType, serializedCheckpoint], [metadataType, serializedMetadata],] = await Promise.all([
171
- this.serde.dumpsTyped(checkpoint),
172
- this.serde.dumpsTyped(metadata),
173
- ]);
174
- if (checkpointType !== metadataType) {
175
- throw new Error("Mismatched checkpoint and metadata types.");
176
- }
177
- const doc = {
178
- parent_checkpoint_id: config.configurable?.checkpoint_id,
179
- type: checkpointType,
180
- checkpoint: serializedCheckpoint,
181
- metadata: serializedMetadata,
182
- };
183
- const upsertQuery = {
184
- thread_id,
185
- checkpoint_ns,
186
- checkpoint_id,
187
- };
188
- await this.db
189
- .collection(this.checkpointCollectionName)
190
- .updateOne(upsertQuery, { $set: doc }, { upsert: true });
191
- return {
192
- configurable: {
193
- thread_id,
194
- checkpoint_ns,
195
- checkpoint_id,
196
- },
197
- };
198
- }
199
- /**
200
- * Saves intermediate writes associated with a checkpoint to the MongoDB database.
201
- */
202
- async putWrites(config, writes, taskId) {
203
- const thread_id = config.configurable?.thread_id;
204
- const checkpoint_ns = config.configurable?.checkpoint_ns;
205
- const checkpoint_id = config.configurable?.checkpoint_id;
206
- if (thread_id === undefined ||
207
- checkpoint_ns === undefined ||
208
- checkpoint_id === undefined) {
209
- throw new Error(`The provided config must contain a configurable field with "thread_id", "checkpoint_ns" and "checkpoint_id" fields.`);
210
- }
211
- const operations = await Promise.all(writes.map(async ([channel, value], idx) => {
212
- const upsertQuery = {
213
- thread_id,
214
- checkpoint_ns,
215
- checkpoint_id,
216
- task_id: taskId,
217
- idx,
218
- };
219
- const [type, serializedValue] = await this.serde.dumpsTyped(value);
220
- return {
221
- updateOne: {
222
- filter: upsertQuery,
223
- update: { $set: { channel, type, value: serializedValue } },
224
- upsert: true,
225
- },
226
- };
227
- }));
228
- await this.db
229
- .collection(this.checkpointWritesCollectionName)
230
- .bulkWrite(operations);
231
- }
232
- async deleteThread(threadId) {
233
- await this.db
234
- .collection(this.checkpointCollectionName)
235
- .deleteMany({ thread_id: threadId });
236
- await this.db
237
- .collection(this.checkpointWritesCollectionName)
238
- .deleteMany({ thread_id: threadId });
239
- }
240
- }
6
+ * A LangGraph checkpoint saver backed by a MongoDB database.
7
+ */
8
+ var MongoDBSaver = class extends __langchain_langgraph_checkpoint.BaseCheckpointSaver {
9
+ client;
10
+ db;
11
+ checkpointCollectionName = "checkpoints";
12
+ checkpointWritesCollectionName = "checkpoint_writes";
13
+ constructor({ client, dbName, checkpointCollectionName, checkpointWritesCollectionName }, serde) {
14
+ super(serde);
15
+ this.client = client;
16
+ this.db = this.client.db(dbName);
17
+ this.checkpointCollectionName = checkpointCollectionName ?? this.checkpointCollectionName;
18
+ this.checkpointWritesCollectionName = checkpointWritesCollectionName ?? this.checkpointWritesCollectionName;
19
+ }
20
+ /**
21
+ * Retrieves a checkpoint from the MongoDB database based on the
22
+ * provided config. If the config contains a "checkpoint_id" key, the checkpoint with
23
+ * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
24
+ * for the given thread ID is retrieved.
25
+ */
26
+ async getTuple(config) {
27
+ const { thread_id, checkpoint_ns = "", checkpoint_id } = config.configurable ?? {};
28
+ let query;
29
+ if (checkpoint_id) query = {
30
+ thread_id,
31
+ checkpoint_ns,
32
+ checkpoint_id
33
+ };
34
+ else query = {
35
+ thread_id,
36
+ checkpoint_ns
37
+ };
38
+ const result = await this.db.collection(this.checkpointCollectionName).find(query).sort("checkpoint_id", -1).limit(1).toArray();
39
+ if (result.length === 0) return void 0;
40
+ const doc = result[0];
41
+ const configurableValues = {
42
+ thread_id,
43
+ checkpoint_ns,
44
+ checkpoint_id: doc.checkpoint_id
45
+ };
46
+ const checkpoint = await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8"));
47
+ const serializedWrites = await this.db.collection(this.checkpointWritesCollectionName).find(configurableValues).toArray();
48
+ const pendingWrites = await Promise.all(serializedWrites.map(async (serializedWrite) => {
49
+ return [
50
+ serializedWrite.task_id,
51
+ serializedWrite.channel,
52
+ await this.serde.loadsTyped(serializedWrite.type, serializedWrite.value.value("utf8"))
53
+ ];
54
+ }));
55
+ return {
56
+ config: { configurable: configurableValues },
57
+ checkpoint,
58
+ pendingWrites,
59
+ metadata: await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8")),
60
+ parentConfig: doc.parent_checkpoint_id != null ? { configurable: {
61
+ thread_id,
62
+ checkpoint_ns,
63
+ checkpoint_id: doc.parent_checkpoint_id
64
+ } } : void 0
65
+ };
66
+ }
67
+ /**
68
+ * Retrieve a list of checkpoint tuples from the MongoDB database based
69
+ * on the provided config. The checkpoints are ordered by checkpoint ID
70
+ * in descending order (newest first).
71
+ */
72
+ async *list(config, options) {
73
+ const { limit, before, filter } = options ?? {};
74
+ const query = {};
75
+ if (config?.configurable?.thread_id) query.thread_id = config.configurable.thread_id;
76
+ if (config?.configurable?.checkpoint_ns !== void 0 && config?.configurable?.checkpoint_ns !== null) query.checkpoint_ns = config.configurable.checkpoint_ns;
77
+ if (filter) Object.entries(filter).forEach(([key, value]) => {
78
+ query[`metadata.${key}`] = value;
79
+ });
80
+ if (before) query.checkpoint_id = { $lt: before.configurable?.checkpoint_id };
81
+ let result = this.db.collection(this.checkpointCollectionName).find(query).sort("checkpoint_id", -1);
82
+ if (limit !== void 0) result = result.limit(limit);
83
+ for await (const doc of result) {
84
+ const checkpoint = await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8"));
85
+ const metadata = await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8"));
86
+ yield {
87
+ config: { configurable: {
88
+ thread_id: doc.thread_id,
89
+ checkpoint_ns: doc.checkpoint_ns,
90
+ checkpoint_id: doc.checkpoint_id
91
+ } },
92
+ checkpoint,
93
+ metadata,
94
+ parentConfig: doc.parent_checkpoint_id ? { configurable: {
95
+ thread_id: doc.thread_id,
96
+ checkpoint_ns: doc.checkpoint_ns,
97
+ checkpoint_id: doc.parent_checkpoint_id
98
+ } } : void 0
99
+ };
100
+ }
101
+ }
102
+ /**
103
+ * Saves a checkpoint to the MongoDB database. The checkpoint is associated
104
+ * with the provided config and its parent config (if any).
105
+ */
106
+ async put(config, checkpoint, metadata) {
107
+ const thread_id = config.configurable?.thread_id;
108
+ const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
109
+ const checkpoint_id = checkpoint.id;
110
+ if (thread_id === void 0) throw new Error(`The provided config must contain a configurable field with a "thread_id" field.`);
111
+ const [[checkpointType, serializedCheckpoint], [metadataType, serializedMetadata]] = await Promise.all([this.serde.dumpsTyped(checkpoint), this.serde.dumpsTyped(metadata)]);
112
+ if (checkpointType !== metadataType) throw new Error("Mismatched checkpoint and metadata types.");
113
+ const doc = {
114
+ parent_checkpoint_id: config.configurable?.checkpoint_id,
115
+ type: checkpointType,
116
+ checkpoint: serializedCheckpoint,
117
+ metadata: serializedMetadata
118
+ };
119
+ const upsertQuery = {
120
+ thread_id,
121
+ checkpoint_ns,
122
+ checkpoint_id
123
+ };
124
+ await this.db.collection(this.checkpointCollectionName).updateOne(upsertQuery, { $set: doc }, { upsert: true });
125
+ return { configurable: {
126
+ thread_id,
127
+ checkpoint_ns,
128
+ checkpoint_id
129
+ } };
130
+ }
131
+ /**
132
+ * Saves intermediate writes associated with a checkpoint to the MongoDB database.
133
+ */
134
+ async putWrites(config, writes, taskId) {
135
+ const thread_id = config.configurable?.thread_id;
136
+ const checkpoint_ns = config.configurable?.checkpoint_ns;
137
+ const checkpoint_id = config.configurable?.checkpoint_id;
138
+ if (thread_id === void 0 || checkpoint_ns === void 0 || checkpoint_id === void 0) throw new Error(`The provided config must contain a configurable field with "thread_id", "checkpoint_ns" and "checkpoint_id" fields.`);
139
+ const operations = await Promise.all(writes.map(async ([channel, value], idx) => {
140
+ const upsertQuery = {
141
+ thread_id,
142
+ checkpoint_ns,
143
+ checkpoint_id,
144
+ task_id: taskId,
145
+ idx
146
+ };
147
+ const [type, serializedValue] = await this.serde.dumpsTyped(value);
148
+ return { updateOne: {
149
+ filter: upsertQuery,
150
+ update: { $set: {
151
+ channel,
152
+ type,
153
+ value: serializedValue
154
+ } },
155
+ upsert: true
156
+ } };
157
+ }));
158
+ await this.db.collection(this.checkpointWritesCollectionName).bulkWrite(operations);
159
+ }
160
+ async deleteThread(threadId) {
161
+ await this.db.collection(this.checkpointCollectionName).deleteMany({ thread_id: threadId });
162
+ await this.db.collection(this.checkpointWritesCollectionName).deleteMany({ thread_id: threadId });
163
+ }
164
+ };
165
+
166
+ //#endregion
241
167
  exports.MongoDBSaver = MongoDBSaver;
242
- //# sourceMappingURL=index.js.map
168
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["BaseCheckpointSaver","pendingWrites: CheckpointPendingWrite[]","query: Record<string, unknown>"],"sources":["../src/index.ts"],"sourcesContent":["import { type MongoClient, type Db as MongoDatabase } from \"mongodb\";\nimport type { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n type Checkpoint,\n type CheckpointListOptions,\n type CheckpointTuple,\n type SerializerProtocol,\n type PendingWrite,\n type CheckpointMetadata,\n CheckpointPendingWrite,\n} from \"@langchain/langgraph-checkpoint\";\n\nexport type MongoDBSaverParams = {\n client: MongoClient;\n dbName?: string;\n checkpointCollectionName?: string;\n checkpointWritesCollectionName?: string;\n};\n\n/**\n * A LangGraph checkpoint saver backed by a MongoDB database.\n */\nexport class MongoDBSaver extends BaseCheckpointSaver {\n protected client: MongoClient;\n\n protected db: MongoDatabase;\n\n checkpointCollectionName = \"checkpoints\";\n\n checkpointWritesCollectionName = \"checkpoint_writes\";\n\n constructor(\n {\n client,\n dbName,\n checkpointCollectionName,\n checkpointWritesCollectionName,\n }: MongoDBSaverParams,\n serde?: SerializerProtocol\n ) {\n super(serde);\n this.client = client;\n this.db = this.client.db(dbName);\n this.checkpointCollectionName =\n checkpointCollectionName ?? this.checkpointCollectionName;\n this.checkpointWritesCollectionName =\n checkpointWritesCollectionName ?? this.checkpointWritesCollectionName;\n }\n\n /**\n * Retrieves a checkpoint from the MongoDB database based on the\n * provided config. If the config contains a \"checkpoint_id\" key, the checkpoint with\n * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint\n * for the given thread ID is retrieved.\n */\n async getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined> {\n const {\n thread_id,\n checkpoint_ns = \"\",\n checkpoint_id,\n } = config.configurable ?? {};\n let query;\n if (checkpoint_id) {\n query = {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n };\n } else {\n query = { thread_id, checkpoint_ns };\n }\n const result = await this.db\n .collection(this.checkpointCollectionName)\n .find(query)\n .sort(\"checkpoint_id\", -1)\n .limit(1)\n .toArray();\n if (result.length === 0) {\n return undefined;\n }\n const doc = result[0];\n const configurableValues = {\n thread_id,\n checkpoint_ns,\n checkpoint_id: doc.checkpoint_id,\n };\n const checkpoint = (await this.serde.loadsTyped(\n doc.type,\n doc.checkpoint.value(\"utf8\")\n )) as Checkpoint;\n const serializedWrites = await this.db\n .collection(this.checkpointWritesCollectionName)\n .find(configurableValues)\n .toArray();\n const pendingWrites: CheckpointPendingWrite[] = await Promise.all(\n serializedWrites.map(async (serializedWrite) => {\n return [\n serializedWrite.task_id,\n serializedWrite.channel,\n await this.serde.loadsTyped(\n serializedWrite.type,\n serializedWrite.value.value(\"utf8\")\n ),\n ] as CheckpointPendingWrite;\n })\n );\n return {\n config: { configurable: configurableValues },\n checkpoint,\n pendingWrites,\n metadata: (await this.serde.loadsTyped(\n doc.type,\n doc.metadata.value(\"utf8\")\n )) as CheckpointMetadata,\n parentConfig:\n doc.parent_checkpoint_id != null\n ? {\n configurable: {\n thread_id,\n checkpoint_ns,\n checkpoint_id: doc.parent_checkpoint_id,\n },\n }\n : undefined,\n };\n }\n\n /**\n * Retrieve a list of checkpoint tuples from the MongoDB database based\n * on the provided config. The checkpoints are ordered by checkpoint ID\n * in descending order (newest first).\n */\n async *list(\n config: RunnableConfig,\n options?: CheckpointListOptions\n ): AsyncGenerator<CheckpointTuple> {\n const { limit, before, filter } = options ?? {};\n const query: Record<string, unknown> = {};\n\n if (config?.configurable?.thread_id) {\n query.thread_id = config.configurable.thread_id;\n }\n\n if (\n config?.configurable?.checkpoint_ns !== undefined &&\n config?.configurable?.checkpoint_ns !== null\n ) {\n query.checkpoint_ns = config.configurable.checkpoint_ns;\n }\n\n if (filter) {\n Object.entries(filter).forEach(([key, value]) => {\n query[`metadata.${key}`] = value;\n });\n }\n\n if (before) {\n query.checkpoint_id = { $lt: before.configurable?.checkpoint_id };\n }\n\n let result = this.db\n .collection(this.checkpointCollectionName)\n .find(query)\n .sort(\"checkpoint_id\", -1);\n\n if (limit !== undefined) {\n result = result.limit(limit);\n }\n\n for await (const doc of result) {\n const checkpoint = (await this.serde.loadsTyped(\n doc.type,\n doc.checkpoint.value(\"utf8\")\n )) as Checkpoint;\n const metadata = (await this.serde.loadsTyped(\n doc.type,\n doc.metadata.value(\"utf8\")\n )) as CheckpointMetadata;\n\n yield {\n config: {\n configurable: {\n thread_id: doc.thread_id,\n checkpoint_ns: doc.checkpoint_ns,\n checkpoint_id: doc.checkpoint_id,\n },\n },\n checkpoint,\n metadata,\n parentConfig: doc.parent_checkpoint_id\n ? {\n configurable: {\n thread_id: doc.thread_id,\n checkpoint_ns: doc.checkpoint_ns,\n checkpoint_id: doc.parent_checkpoint_id,\n },\n }\n : undefined,\n };\n }\n }\n\n /**\n * Saves a checkpoint to the MongoDB database. The checkpoint is associated\n * with the provided config and its parent config (if any).\n */\n async put(\n config: RunnableConfig,\n checkpoint: Checkpoint,\n metadata: CheckpointMetadata\n ): Promise<RunnableConfig> {\n const thread_id = config.configurable?.thread_id;\n const checkpoint_ns = config.configurable?.checkpoint_ns ?? \"\";\n const checkpoint_id = checkpoint.id;\n if (thread_id === undefined) {\n throw new Error(\n `The provided config must contain a configurable field with a \"thread_id\" field.`\n );\n }\n const [\n [checkpointType, serializedCheckpoint],\n [metadataType, serializedMetadata],\n ] = await Promise.all([\n this.serde.dumpsTyped(checkpoint),\n this.serde.dumpsTyped(metadata),\n ]);\n\n if (checkpointType !== metadataType) {\n throw new Error(\"Mismatched checkpoint and metadata types.\");\n }\n const doc = {\n parent_checkpoint_id: config.configurable?.checkpoint_id,\n type: checkpointType,\n checkpoint: serializedCheckpoint,\n metadata: serializedMetadata,\n };\n const upsertQuery = {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n };\n await this.db\n .collection(this.checkpointCollectionName)\n .updateOne(upsertQuery, { $set: doc }, { upsert: true });\n\n return {\n configurable: {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n },\n };\n }\n\n /**\n * Saves intermediate writes associated with a checkpoint to the MongoDB database.\n */\n async putWrites(\n config: RunnableConfig,\n writes: PendingWrite[],\n taskId: string\n ): Promise<void> {\n const thread_id = config.configurable?.thread_id;\n const checkpoint_ns = config.configurable?.checkpoint_ns;\n const checkpoint_id = config.configurable?.checkpoint_id;\n if (\n thread_id === undefined ||\n checkpoint_ns === undefined ||\n checkpoint_id === undefined\n ) {\n throw new Error(\n `The provided config must contain a configurable field with \"thread_id\", \"checkpoint_ns\" and \"checkpoint_id\" fields.`\n );\n }\n\n const operations = await Promise.all(\n writes.map(async ([channel, value], idx) => {\n const upsertQuery = {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n task_id: taskId,\n idx,\n };\n\n const [type, serializedValue] = await this.serde.dumpsTyped(value);\n\n return {\n updateOne: {\n filter: upsertQuery,\n update: { $set: { channel, type, value: serializedValue } },\n upsert: true,\n },\n };\n })\n );\n\n await this.db\n .collection(this.checkpointWritesCollectionName)\n .bulkWrite(operations);\n }\n\n async deleteThread(threadId: string) {\n await this.db\n .collection(this.checkpointCollectionName)\n .deleteMany({ thread_id: threadId });\n\n await this.db\n .collection(this.checkpointWritesCollectionName)\n .deleteMany({ thread_id: threadId });\n }\n}\n"],"mappings":";;;;;;;AAuBA,IAAa,eAAb,cAAkCA,qDAAoB;CACpD,AAAU;CAEV,AAAU;CAEV,2BAA2B;CAE3B,iCAAiC;CAEjC,YACE,EACE,QACA,QACA,0BACA,kCAEF,OACA;AACA,QAAM;AACN,OAAK,SAAS;AACd,OAAK,KAAK,KAAK,OAAO,GAAG;AACzB,OAAK,2BACH,4BAA4B,KAAK;AACnC,OAAK,iCACH,kCAAkC,KAAK;;;;;;;;CAS3C,MAAM,SAAS,QAA8D;EAC3E,MAAM,EACJ,WACA,gBAAgB,IAChB,kBACE,OAAO,gBAAgB;EAC3B,IAAI;AACJ,MAAI,cACF,SAAQ;GACN;GACA;GACA;;MAGF,SAAQ;GAAE;GAAW;;EAEvB,MAAM,SAAS,MAAM,KAAK,GACvB,WAAW,KAAK,0BAChB,KAAK,OACL,KAAK,i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;GAGF,MAAM,CAAC,MAAM,mBAAmB,MAAM,KAAK,MAAM,WAAW;AAE5D,UAAO,EACL,WAAW;IACT,QAAQ;IACR,QAAQ,EAAE,MAAM;KAAE;KAAS;KAAM,OAAO;;IACxC,QAAQ;;;AAMhB,QAAM,KAAK,GACR,WAAW,KAAK,gCAChB,UAAU;;CAGf,MAAM,aAAa,UAAkB;AACnC,QAAM,KAAK,GACR,WAAW,KAAK,0BAChB,WAAW,EAAE,WAAW;AAE3B,QAAM,KAAK,GACR,WAAW,KAAK,gCAChB,WAAW,EAAE,WAAW"}
@@ -0,0 +1,52 @@
1
+ import { Db, MongoClient } from "mongodb";
2
+ import { RunnableConfig } from "@langchain/core/runnables";
3
+ import { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointMetadata, CheckpointTuple, PendingWrite, SerializerProtocol } from "@langchain/langgraph-checkpoint";
4
+
5
+ //#region src/index.d.ts
6
+ type MongoDBSaverParams = {
7
+ client: MongoClient;
8
+ dbName?: string;
9
+ checkpointCollectionName?: string;
10
+ checkpointWritesCollectionName?: string;
11
+ };
12
+ /**
13
+ * A LangGraph checkpoint saver backed by a MongoDB database.
14
+ */
15
+ declare class MongoDBSaver extends BaseCheckpointSaver {
16
+ protected client: MongoClient;
17
+ protected db: Db;
18
+ checkpointCollectionName: string;
19
+ checkpointWritesCollectionName: string;
20
+ constructor({
21
+ client,
22
+ dbName,
23
+ checkpointCollectionName,
24
+ checkpointWritesCollectionName
25
+ }: MongoDBSaverParams, serde?: SerializerProtocol);
26
+ /**
27
+ * Retrieves a checkpoint from the MongoDB database based on the
28
+ * provided config. If the config contains a "checkpoint_id" key, the checkpoint with
29
+ * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
30
+ * for the given thread ID is retrieved.
31
+ */
32
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
33
+ /**
34
+ * Retrieve a list of checkpoint tuples from the MongoDB database based
35
+ * on the provided config. The checkpoints are ordered by checkpoint ID
36
+ * in descending order (newest first).
37
+ */
38
+ list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
39
+ /**
40
+ * Saves a checkpoint to the MongoDB database. The checkpoint is associated
41
+ * with the provided config and its parent config (if any).
42
+ */
43
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
44
+ /**
45
+ * Saves intermediate writes associated with a checkpoint to the MongoDB database.
46
+ */
47
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
48
+ deleteThread(threadId: string): Promise<void>;
49
+ }
50
+ //#endregion
51
+ export { MongoDBSaver, MongoDBSaverParams };
52
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","names":["MongoClient","Db","MongoDatabase","RunnableConfig","BaseCheckpointSaver","Checkpoint","CheckpointListOptions","CheckpointTuple","SerializerProtocol","PendingWrite","CheckpointMetadata","MongoDBSaverParams","MongoDBSaver","client","dbName","checkpointCollectionName","checkpointWritesCollectionName","Promise","AsyncGenerator"],"sources":["../src/index.d.ts"],"sourcesContent":["import { type MongoClient, type Db as MongoDatabase } from \"mongodb\";\nimport type { RunnableConfig } from \"@langchain/core/runnables\";\nimport { BaseCheckpointSaver, type Checkpoint, type CheckpointListOptions, type CheckpointTuple, type SerializerProtocol, type PendingWrite, type CheckpointMetadata } from \"@langchain/langgraph-checkpoint\";\nexport type MongoDBSaverParams = {\n client: MongoClient;\n dbName?: string;\n checkpointCollectionName?: string;\n checkpointWritesCollectionName?: string;\n};\n/**\n * A LangGraph checkpoint saver backed by a MongoDB database.\n */\nexport declare class MongoDBSaver extends BaseCheckpointSaver {\n protected client: MongoClient;\n protected db: MongoDatabase;\n checkpointCollectionName: string;\n checkpointWritesCollectionName: string;\n constructor({ client, dbName, checkpointCollectionName, checkpointWritesCollectionName }: MongoDBSaverParams, serde?: SerializerProtocol);\n /**\n * Retrieves a checkpoint from the MongoDB database based on the\n * provided config. If the config contains a \"checkpoint_id\" key, the checkpoint with\n * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint\n * for the given thread ID is retrieved.\n */\n getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;\n /**\n * Retrieve a list of checkpoint tuples from the MongoDB database based\n * on the provided config. The checkpoints are ordered by checkpoint ID\n * in descending order (newest first).\n */\n list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;\n /**\n * Saves a checkpoint to the MongoDB database. The checkpoint is associated\n * with the provided config and its parent config (if any).\n */\n put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;\n /**\n * Saves intermediate writes associated with a checkpoint to the MongoDB database.\n */\n putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;\n deleteThread(threadId: string): Promise<void>;\n}\n"],"mappings":";;;;;KAGYW,kBAAAA;UACAX;EADAW,MAAAA,CAAAA,EAAAA,MAAAA;EASSC,wBAAY,CAAA,EAAA,MAAA;EAAA,8BAAA,CAAA,EAAA,MAAA;;;;;AAKCG,cALbH,YAAAA,SAAqBR,mBAAAA,CAKRW;YAA0BC,MAAAA,EAJtChB,WAIsCgB;YAAkCL,EAAAA,EAH5ET,EAG4ES;0BAA4BH,EAAAA,MAAAA;gCAOrGL,EAAAA,MAAAA;aAAyBI,CAAAA;IAAAA,MAAAA;IAAAA,MAAAA;IAAAA,wBAAAA;IAAAA;EAAAA,CAAAA,EAPgDI,kBAOhDJ,EAAAA,KAAAA,CAAAA,EAP4EC,kBAO5ED;;;;;;;UAWFF,CAAAA,MAAAA,EAXvBF,cAWuBE,CAAAA,EAXNY,OAWMZ,CAXEE,eAWFF,GAAAA,SAAAA,CAAAA;;;;;;MAImCY,CAAAA,MAAAA,EAT9Dd,cAS8Dc,EAAAA,OAAAA,CAAAA,EATpCX,qBASoCW,CAAAA,EATZC,cASYD,CATGV,eASHU,CAAAA;;;;;cAJ/Dd,4BAA4BE,sBAAsBK,qBAAqBO,QAAQd;;;;oBAIzEA,wBAAwBM,iCAAiCQ;kCAC3CA"}
package/dist/index.d.ts CHANGED
@@ -1,42 +1,52 @@
1
- import { type MongoClient, type Db as MongoDatabase } from "mongodb";
2
- import type { RunnableConfig } from "@langchain/core/runnables";
3
- import { BaseCheckpointSaver, type Checkpoint, type CheckpointListOptions, type CheckpointTuple, type SerializerProtocol, type PendingWrite, type CheckpointMetadata } from "@langchain/langgraph-checkpoint";
4
- export type MongoDBSaverParams = {
5
- client: MongoClient;
6
- dbName?: string;
7
- checkpointCollectionName?: string;
8
- checkpointWritesCollectionName?: string;
1
+ import { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointMetadata, CheckpointTuple, PendingWrite, SerializerProtocol } from "@langchain/langgraph-checkpoint";
2
+ import { Db, MongoClient } from "mongodb";
3
+ import { RunnableConfig } from "@langchain/core/runnables";
4
+
5
+ //#region src/index.d.ts
6
+ type MongoDBSaverParams = {
7
+ client: MongoClient;
8
+ dbName?: string;
9
+ checkpointCollectionName?: string;
10
+ checkpointWritesCollectionName?: string;
9
11
  };
10
12
  /**
11
13
  * A LangGraph checkpoint saver backed by a MongoDB database.
12
14
  */
13
- export declare class MongoDBSaver extends BaseCheckpointSaver {
14
- protected client: MongoClient;
15
- protected db: MongoDatabase;
16
- checkpointCollectionName: string;
17
- checkpointWritesCollectionName: string;
18
- constructor({ client, dbName, checkpointCollectionName, checkpointWritesCollectionName, }: MongoDBSaverParams, serde?: SerializerProtocol);
19
- /**
20
- * Retrieves a checkpoint from the MongoDB database based on the
21
- * provided config. If the config contains a "checkpoint_id" key, the checkpoint with
22
- * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
23
- * for the given thread ID is retrieved.
24
- */
25
- getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
26
- /**
27
- * Retrieve a list of checkpoint tuples from the MongoDB database based
28
- * on the provided config. The checkpoints are ordered by checkpoint ID
29
- * in descending order (newest first).
30
- */
31
- list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
32
- /**
33
- * Saves a checkpoint to the MongoDB database. The checkpoint is associated
34
- * with the provided config and its parent config (if any).
35
- */
36
- put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
37
- /**
38
- * Saves intermediate writes associated with a checkpoint to the MongoDB database.
39
- */
40
- putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
41
- deleteThread(threadId: string): Promise<void>;
15
+ declare class MongoDBSaver extends BaseCheckpointSaver {
16
+ protected client: MongoClient;
17
+ protected db: Db;
18
+ checkpointCollectionName: string;
19
+ checkpointWritesCollectionName: string;
20
+ constructor({
21
+ client,
22
+ dbName,
23
+ checkpointCollectionName,
24
+ checkpointWritesCollectionName
25
+ }: MongoDBSaverParams, serde?: SerializerProtocol);
26
+ /**
27
+ * Retrieves a checkpoint from the MongoDB database based on the
28
+ * provided config. If the config contains a "checkpoint_id" key, the checkpoint with
29
+ * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
30
+ * for the given thread ID is retrieved.
31
+ */
32
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
33
+ /**
34
+ * Retrieve a list of checkpoint tuples from the MongoDB database based
35
+ * on the provided config. The checkpoints are ordered by checkpoint ID
36
+ * in descending order (newest first).
37
+ */
38
+ list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
39
+ /**
40
+ * Saves a checkpoint to the MongoDB database. The checkpoint is associated
41
+ * with the provided config and its parent config (if any).
42
+ */
43
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
44
+ /**
45
+ * Saves intermediate writes associated with a checkpoint to the MongoDB database.
46
+ */
47
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
48
+ deleteThread(threadId: string): Promise<void>;
42
49
  }
50
+ //#endregion
51
+ export { MongoDBSaver, MongoDBSaverParams };
52
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":["MongoClient","Db","MongoDatabase","RunnableConfig","BaseCheckpointSaver","Checkpoint","CheckpointListOptions","CheckpointTuple","SerializerProtocol","PendingWrite","CheckpointMetadata","MongoDBSaverParams","MongoDBSaver","client","dbName","checkpointCollectionName","checkpointWritesCollectionName","Promise","AsyncGenerator"],"sources":["../src/index.d.ts"],"sourcesContent":["import { type MongoClient, type Db as MongoDatabase } from \"mongodb\";\nimport type { RunnableConfig } from \"@langchain/core/runnables\";\nimport { BaseCheckpointSaver, type Checkpoint, type CheckpointListOptions, type CheckpointTuple, type SerializerProtocol, type PendingWrite, type CheckpointMetadata } from \"@langchain/langgraph-checkpoint\";\nexport type MongoDBSaverParams = {\n client: MongoClient;\n dbName?: string;\n checkpointCollectionName?: string;\n checkpointWritesCollectionName?: string;\n};\n/**\n * A LangGraph checkpoint saver backed by a MongoDB database.\n */\nexport declare class MongoDBSaver extends BaseCheckpointSaver {\n protected client: MongoClient;\n protected db: MongoDatabase;\n checkpointCollectionName: string;\n checkpointWritesCollectionName: string;\n constructor({ client, dbName, checkpointCollectionName, checkpointWritesCollectionName }: MongoDBSaverParams, serde?: SerializerProtocol);\n /**\n * Retrieves a checkpoint from the MongoDB database based on the\n * provided config. If the config contains a \"checkpoint_id\" key, the checkpoint with\n * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint\n * for the given thread ID is retrieved.\n */\n getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;\n /**\n * Retrieve a list of checkpoint tuples from the MongoDB database based\n * on the provided config. The checkpoints are ordered by checkpoint ID\n * in descending order (newest first).\n */\n list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;\n /**\n * Saves a checkpoint to the MongoDB database. The checkpoint is associated\n * with the provided config and its parent config (if any).\n */\n put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;\n /**\n * Saves intermediate writes associated with a checkpoint to the MongoDB database.\n */\n putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;\n deleteThread(threadId: string): Promise<void>;\n}\n"],"mappings":";;;;;KAGYW,kBAAAA;UACAX;EADAW,MAAAA,CAAAA,EAAAA,MAAAA;EASSC,wBAAY,CAAA,EAAA,MAAA;EAAA,8BAAA,CAAA,EAAA,MAAA;;;;;AAKCG,cALbH,YAAAA,SAAqBR,mBAAAA,CAKRW;YAA0BC,MAAAA,EAJtChB,WAIsCgB;YAAkCL,EAAAA,EAH5ET,EAG4ES;0BAA4BH,EAAAA,MAAAA;gCAOrGL,EAAAA,MAAAA;aAAyBI,CAAAA;IAAAA,MAAAA;IAAAA,MAAAA;IAAAA,wBAAAA;IAAAA;EAAAA,CAAAA,EAPgDI,kBAOhDJ,EAAAA,KAAAA,CAAAA,EAP4EC,kBAO5ED;;;;;;;UAWFF,CAAAA,MAAAA,EAXvBF,cAWuBE,CAAAA,EAXNY,OAWMZ,CAXEE,eAWFF,GAAAA,SAAAA,CAAAA;;;;;;MAImCY,CAAAA,MAAAA,EAT9Dd,cAS8Dc,EAAAA,OAAAA,CAAAA,EATpCX,qBASoCW,CAAAA,EATZC,cASYD,CATGV,eASHU,CAAAA;;;;;cAJ/Dd,4BAA4BE,sBAAsBK,qBAAqBO,QAAQd;;;;oBAIzEA,wBAAwBM,iCAAiCQ;kCAC3CA"}
package/dist/index.js CHANGED
@@ -1,238 +1,167 @@
1
- import { BaseCheckpointSaver, } from "@langchain/langgraph-checkpoint";
1
+ import { BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
2
+
3
+ //#region src/index.ts
2
4
  /**
3
- * A LangGraph checkpoint saver backed by a MongoDB database.
4
- */
5
- export class MongoDBSaver extends BaseCheckpointSaver {
6
- constructor({ client, dbName, checkpointCollectionName, checkpointWritesCollectionName, }, serde) {
7
- super(serde);
8
- Object.defineProperty(this, "client", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: void 0
13
- });
14
- Object.defineProperty(this, "db", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: void 0
19
- });
20
- Object.defineProperty(this, "checkpointCollectionName", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: "checkpoints"
25
- });
26
- Object.defineProperty(this, "checkpointWritesCollectionName", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: "checkpoint_writes"
31
- });
32
- this.client = client;
33
- this.db = this.client.db(dbName);
34
- this.checkpointCollectionName =
35
- checkpointCollectionName ?? this.checkpointCollectionName;
36
- this.checkpointWritesCollectionName =
37
- checkpointWritesCollectionName ?? this.checkpointWritesCollectionName;
38
- }
39
- /**
40
- * Retrieves a checkpoint from the MongoDB database based on the
41
- * provided config. If the config contains a "checkpoint_id" key, the checkpoint with
42
- * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
43
- * for the given thread ID is retrieved.
44
- */
45
- async getTuple(config) {
46
- const { thread_id, checkpoint_ns = "", checkpoint_id, } = config.configurable ?? {};
47
- let query;
48
- if (checkpoint_id) {
49
- query = {
50
- thread_id,
51
- checkpoint_ns,
52
- checkpoint_id,
53
- };
54
- }
55
- else {
56
- query = { thread_id, checkpoint_ns };
57
- }
58
- const result = await this.db
59
- .collection(this.checkpointCollectionName)
60
- .find(query)
61
- .sort("checkpoint_id", -1)
62
- .limit(1)
63
- .toArray();
64
- if (result.length === 0) {
65
- return undefined;
66
- }
67
- const doc = result[0];
68
- const configurableValues = {
69
- thread_id,
70
- checkpoint_ns,
71
- checkpoint_id: doc.checkpoint_id,
72
- };
73
- const checkpoint = (await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8")));
74
- const serializedWrites = await this.db
75
- .collection(this.checkpointWritesCollectionName)
76
- .find(configurableValues)
77
- .toArray();
78
- const pendingWrites = await Promise.all(serializedWrites.map(async (serializedWrite) => {
79
- return [
80
- serializedWrite.task_id,
81
- serializedWrite.channel,
82
- await this.serde.loadsTyped(serializedWrite.type, serializedWrite.value.value("utf8")),
83
- ];
84
- }));
85
- return {
86
- config: { configurable: configurableValues },
87
- checkpoint,
88
- pendingWrites,
89
- metadata: (await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8"))),
90
- parentConfig: doc.parent_checkpoint_id != null
91
- ? {
92
- configurable: {
93
- thread_id,
94
- checkpoint_ns,
95
- checkpoint_id: doc.parent_checkpoint_id,
96
- },
97
- }
98
- : undefined,
99
- };
100
- }
101
- /**
102
- * Retrieve a list of checkpoint tuples from the MongoDB database based
103
- * on the provided config. The checkpoints are ordered by checkpoint ID
104
- * in descending order (newest first).
105
- */
106
- async *list(config, options) {
107
- const { limit, before, filter } = options ?? {};
108
- const query = {};
109
- if (config?.configurable?.thread_id) {
110
- query.thread_id = config.configurable.thread_id;
111
- }
112
- if (config?.configurable?.checkpoint_ns !== undefined &&
113
- config?.configurable?.checkpoint_ns !== null) {
114
- query.checkpoint_ns = config.configurable.checkpoint_ns;
115
- }
116
- if (filter) {
117
- Object.entries(filter).forEach(([key, value]) => {
118
- query[`metadata.${key}`] = value;
119
- });
120
- }
121
- if (before) {
122
- query.checkpoint_id = { $lt: before.configurable?.checkpoint_id };
123
- }
124
- let result = this.db
125
- .collection(this.checkpointCollectionName)
126
- .find(query)
127
- .sort("checkpoint_id", -1);
128
- if (limit !== undefined) {
129
- result = result.limit(limit);
130
- }
131
- for await (const doc of result) {
132
- const checkpoint = (await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8")));
133
- const metadata = (await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8")));
134
- yield {
135
- config: {
136
- configurable: {
137
- thread_id: doc.thread_id,
138
- checkpoint_ns: doc.checkpoint_ns,
139
- checkpoint_id: doc.checkpoint_id,
140
- },
141
- },
142
- checkpoint,
143
- metadata,
144
- parentConfig: doc.parent_checkpoint_id
145
- ? {
146
- configurable: {
147
- thread_id: doc.thread_id,
148
- checkpoint_ns: doc.checkpoint_ns,
149
- checkpoint_id: doc.parent_checkpoint_id,
150
- },
151
- }
152
- : undefined,
153
- };
154
- }
155
- }
156
- /**
157
- * Saves a checkpoint to the MongoDB database. The checkpoint is associated
158
- * with the provided config and its parent config (if any).
159
- */
160
- async put(config, checkpoint, metadata) {
161
- const thread_id = config.configurable?.thread_id;
162
- const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
163
- const checkpoint_id = checkpoint.id;
164
- if (thread_id === undefined) {
165
- throw new Error(`The provided config must contain a configurable field with a "thread_id" field.`);
166
- }
167
- const [[checkpointType, serializedCheckpoint], [metadataType, serializedMetadata],] = await Promise.all([
168
- this.serde.dumpsTyped(checkpoint),
169
- this.serde.dumpsTyped(metadata),
170
- ]);
171
- if (checkpointType !== metadataType) {
172
- throw new Error("Mismatched checkpoint and metadata types.");
173
- }
174
- const doc = {
175
- parent_checkpoint_id: config.configurable?.checkpoint_id,
176
- type: checkpointType,
177
- checkpoint: serializedCheckpoint,
178
- metadata: serializedMetadata,
179
- };
180
- const upsertQuery = {
181
- thread_id,
182
- checkpoint_ns,
183
- checkpoint_id,
184
- };
185
- await this.db
186
- .collection(this.checkpointCollectionName)
187
- .updateOne(upsertQuery, { $set: doc }, { upsert: true });
188
- return {
189
- configurable: {
190
- thread_id,
191
- checkpoint_ns,
192
- checkpoint_id,
193
- },
194
- };
195
- }
196
- /**
197
- * Saves intermediate writes associated with a checkpoint to the MongoDB database.
198
- */
199
- async putWrites(config, writes, taskId) {
200
- const thread_id = config.configurable?.thread_id;
201
- const checkpoint_ns = config.configurable?.checkpoint_ns;
202
- const checkpoint_id = config.configurable?.checkpoint_id;
203
- if (thread_id === undefined ||
204
- checkpoint_ns === undefined ||
205
- checkpoint_id === undefined) {
206
- throw new Error(`The provided config must contain a configurable field with "thread_id", "checkpoint_ns" and "checkpoint_id" fields.`);
207
- }
208
- const operations = await Promise.all(writes.map(async ([channel, value], idx) => {
209
- const upsertQuery = {
210
- thread_id,
211
- checkpoint_ns,
212
- checkpoint_id,
213
- task_id: taskId,
214
- idx,
215
- };
216
- const [type, serializedValue] = await this.serde.dumpsTyped(value);
217
- return {
218
- updateOne: {
219
- filter: upsertQuery,
220
- update: { $set: { channel, type, value: serializedValue } },
221
- upsert: true,
222
- },
223
- };
224
- }));
225
- await this.db
226
- .collection(this.checkpointWritesCollectionName)
227
- .bulkWrite(operations);
228
- }
229
- async deleteThread(threadId) {
230
- await this.db
231
- .collection(this.checkpointCollectionName)
232
- .deleteMany({ thread_id: threadId });
233
- await this.db
234
- .collection(this.checkpointWritesCollectionName)
235
- .deleteMany({ thread_id: threadId });
236
- }
237
- }
5
+ * A LangGraph checkpoint saver backed by a MongoDB database.
6
+ */
7
+ var MongoDBSaver = class extends BaseCheckpointSaver {
8
+ client;
9
+ db;
10
+ checkpointCollectionName = "checkpoints";
11
+ checkpointWritesCollectionName = "checkpoint_writes";
12
+ constructor({ client, dbName, checkpointCollectionName, checkpointWritesCollectionName }, serde) {
13
+ super(serde);
14
+ this.client = client;
15
+ this.db = this.client.db(dbName);
16
+ this.checkpointCollectionName = checkpointCollectionName ?? this.checkpointCollectionName;
17
+ this.checkpointWritesCollectionName = checkpointWritesCollectionName ?? this.checkpointWritesCollectionName;
18
+ }
19
+ /**
20
+ * Retrieves a checkpoint from the MongoDB database based on the
21
+ * provided config. If the config contains a "checkpoint_id" key, the checkpoint with
22
+ * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint
23
+ * for the given thread ID is retrieved.
24
+ */
25
+ async getTuple(config) {
26
+ const { thread_id, checkpoint_ns = "", checkpoint_id } = config.configurable ?? {};
27
+ let query;
28
+ if (checkpoint_id) query = {
29
+ thread_id,
30
+ checkpoint_ns,
31
+ checkpoint_id
32
+ };
33
+ else query = {
34
+ thread_id,
35
+ checkpoint_ns
36
+ };
37
+ const result = await this.db.collection(this.checkpointCollectionName).find(query).sort("checkpoint_id", -1).limit(1).toArray();
38
+ if (result.length === 0) return void 0;
39
+ const doc = result[0];
40
+ const configurableValues = {
41
+ thread_id,
42
+ checkpoint_ns,
43
+ checkpoint_id: doc.checkpoint_id
44
+ };
45
+ const checkpoint = await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8"));
46
+ const serializedWrites = await this.db.collection(this.checkpointWritesCollectionName).find(configurableValues).toArray();
47
+ const pendingWrites = await Promise.all(serializedWrites.map(async (serializedWrite) => {
48
+ return [
49
+ serializedWrite.task_id,
50
+ serializedWrite.channel,
51
+ await this.serde.loadsTyped(serializedWrite.type, serializedWrite.value.value("utf8"))
52
+ ];
53
+ }));
54
+ return {
55
+ config: { configurable: configurableValues },
56
+ checkpoint,
57
+ pendingWrites,
58
+ metadata: await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8")),
59
+ parentConfig: doc.parent_checkpoint_id != null ? { configurable: {
60
+ thread_id,
61
+ checkpoint_ns,
62
+ checkpoint_id: doc.parent_checkpoint_id
63
+ } } : void 0
64
+ };
65
+ }
66
+ /**
67
+ * Retrieve a list of checkpoint tuples from the MongoDB database based
68
+ * on the provided config. The checkpoints are ordered by checkpoint ID
69
+ * in descending order (newest first).
70
+ */
71
+ async *list(config, options) {
72
+ const { limit, before, filter } = options ?? {};
73
+ const query = {};
74
+ if (config?.configurable?.thread_id) query.thread_id = config.configurable.thread_id;
75
+ if (config?.configurable?.checkpoint_ns !== void 0 && config?.configurable?.checkpoint_ns !== null) query.checkpoint_ns = config.configurable.checkpoint_ns;
76
+ if (filter) Object.entries(filter).forEach(([key, value]) => {
77
+ query[`metadata.${key}`] = value;
78
+ });
79
+ if (before) query.checkpoint_id = { $lt: before.configurable?.checkpoint_id };
80
+ let result = this.db.collection(this.checkpointCollectionName).find(query).sort("checkpoint_id", -1);
81
+ if (limit !== void 0) result = result.limit(limit);
82
+ for await (const doc of result) {
83
+ const checkpoint = await this.serde.loadsTyped(doc.type, doc.checkpoint.value("utf8"));
84
+ const metadata = await this.serde.loadsTyped(doc.type, doc.metadata.value("utf8"));
85
+ yield {
86
+ config: { configurable: {
87
+ thread_id: doc.thread_id,
88
+ checkpoint_ns: doc.checkpoint_ns,
89
+ checkpoint_id: doc.checkpoint_id
90
+ } },
91
+ checkpoint,
92
+ metadata,
93
+ parentConfig: doc.parent_checkpoint_id ? { configurable: {
94
+ thread_id: doc.thread_id,
95
+ checkpoint_ns: doc.checkpoint_ns,
96
+ checkpoint_id: doc.parent_checkpoint_id
97
+ } } : void 0
98
+ };
99
+ }
100
+ }
101
+ /**
102
+ * Saves a checkpoint to the MongoDB database. The checkpoint is associated
103
+ * with the provided config and its parent config (if any).
104
+ */
105
+ async put(config, checkpoint, metadata) {
106
+ const thread_id = config.configurable?.thread_id;
107
+ const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
108
+ const checkpoint_id = checkpoint.id;
109
+ if (thread_id === void 0) throw new Error(`The provided config must contain a configurable field with a "thread_id" field.`);
110
+ const [[checkpointType, serializedCheckpoint], [metadataType, serializedMetadata]] = await Promise.all([this.serde.dumpsTyped(checkpoint), this.serde.dumpsTyped(metadata)]);
111
+ if (checkpointType !== metadataType) throw new Error("Mismatched checkpoint and metadata types.");
112
+ const doc = {
113
+ parent_checkpoint_id: config.configurable?.checkpoint_id,
114
+ type: checkpointType,
115
+ checkpoint: serializedCheckpoint,
116
+ metadata: serializedMetadata
117
+ };
118
+ const upsertQuery = {
119
+ thread_id,
120
+ checkpoint_ns,
121
+ checkpoint_id
122
+ };
123
+ await this.db.collection(this.checkpointCollectionName).updateOne(upsertQuery, { $set: doc }, { upsert: true });
124
+ return { configurable: {
125
+ thread_id,
126
+ checkpoint_ns,
127
+ checkpoint_id
128
+ } };
129
+ }
130
+ /**
131
+ * Saves intermediate writes associated with a checkpoint to the MongoDB database.
132
+ */
133
+ async putWrites(config, writes, taskId) {
134
+ const thread_id = config.configurable?.thread_id;
135
+ const checkpoint_ns = config.configurable?.checkpoint_ns;
136
+ const checkpoint_id = config.configurable?.checkpoint_id;
137
+ if (thread_id === void 0 || checkpoint_ns === void 0 || checkpoint_id === void 0) throw new Error(`The provided config must contain a configurable field with "thread_id", "checkpoint_ns" and "checkpoint_id" fields.`);
138
+ const operations = await Promise.all(writes.map(async ([channel, value], idx) => {
139
+ const upsertQuery = {
140
+ thread_id,
141
+ checkpoint_ns,
142
+ checkpoint_id,
143
+ task_id: taskId,
144
+ idx
145
+ };
146
+ const [type, serializedValue] = await this.serde.dumpsTyped(value);
147
+ return { updateOne: {
148
+ filter: upsertQuery,
149
+ update: { $set: {
150
+ channel,
151
+ type,
152
+ value: serializedValue
153
+ } },
154
+ upsert: true
155
+ } };
156
+ }));
157
+ await this.db.collection(this.checkpointWritesCollectionName).bulkWrite(operations);
158
+ }
159
+ async deleteThread(threadId) {
160
+ await this.db.collection(this.checkpointCollectionName).deleteMany({ thread_id: threadId });
161
+ await this.db.collection(this.checkpointWritesCollectionName).deleteMany({ thread_id: threadId });
162
+ }
163
+ };
164
+
165
+ //#endregion
166
+ export { MongoDBSaver };
238
167
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,mBAAmB,GAQpB,MAAM,iCAAiC,CAAC;AASzC;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,mBAAmB;IASnD,YACE,EACE,MAAM,EACN,MAAM,EACN,wBAAwB,EACxB,8BAA8B,GACX,EACrB,KAA0B;QAE1B,KAAK,CAAC,KAAK,CAAC,CAAC;QAjBL;;;;;WAAoB;QAEpB;;;;;WAAkB;QAE5B;;;;mBAA2B,aAAa;WAAC;QAEzC;;;;mBAAiC,mBAAmB;WAAC;QAYnD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC;QACjC,IAAI,CAAC,wBAAwB;YAC3B,wBAAw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EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,eAAe,EAAE,EAAE;oBAC3D,MAAM,EAAE,IAAI;iBACb;aACF,CAAC;QACJ,CAAC,CAAC,CACH,CAAC;QAEF,MAAM,IAAI,CAAC,EAAE;aACV,UAAU,CAAC,IAAI,CAAC,8BAA8B,CAAC;aAC/C,SAAS,CAAC,UAAU,CAAC,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,QAAgB;QACjC,MAAM,IAAI,CAAC,EAAE;aACV,UAAU,CAAC,IAAI,CAAC,wBAAwB,CAAC;aACzC,UAAU,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;QAEvC,MAAM,IAAI,CAAC,EAAE;aACV,UAAU,CAAC,IAAI,CAAC,8BAA8B,CAAC;aAC/C,UAAU,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;IACzC,CAAC;CACF"}
1
+ {"version":3,"file":"index.js","names":["pendingWrites: CheckpointPendingWrite[]","query: Record<string, unknown>"],"sources":["../src/index.ts"],"sourcesContent":["import { type MongoClient, type Db as MongoDatabase } from \"mongodb\";\nimport type { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n type Checkpoint,\n type CheckpointListOptions,\n type CheckpointTuple,\n type SerializerProtocol,\n type PendingWrite,\n type CheckpointMetadata,\n CheckpointPendingWrite,\n} from \"@langchain/langgraph-checkpoint\";\n\nexport type MongoDBSaverParams = {\n client: MongoClient;\n dbName?: string;\n checkpointCollectionName?: string;\n checkpointWritesCollectionName?: string;\n};\n\n/**\n * A LangGraph checkpoint saver backed by a MongoDB database.\n */\nexport class MongoDBSaver extends BaseCheckpointSaver {\n protected client: MongoClient;\n\n protected db: MongoDatabase;\n\n checkpointCollectionName = \"checkpoints\";\n\n checkpointWritesCollectionName = \"checkpoint_writes\";\n\n constructor(\n {\n client,\n dbName,\n checkpointCollectionName,\n checkpointWritesCollectionName,\n }: MongoDBSaverParams,\n serde?: SerializerProtocol\n ) {\n super(serde);\n this.client = client;\n this.db = this.client.db(dbName);\n this.checkpointCollectionName =\n checkpointCollectionName ?? this.checkpointCollectionName;\n this.checkpointWritesCollectionName =\n checkpointWritesCollectionName ?? this.checkpointWritesCollectionName;\n }\n\n /**\n * Retrieves a checkpoint from the MongoDB database based on the\n * provided config. If the config contains a \"checkpoint_id\" key, the checkpoint with\n * the matching thread ID and checkpoint ID is retrieved. Otherwise, the latest checkpoint\n * for the given thread ID is retrieved.\n */\n async getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined> {\n const {\n thread_id,\n checkpoint_ns = \"\",\n checkpoint_id,\n } = config.configurable ?? {};\n let query;\n if (checkpoint_id) {\n query = {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n };\n } else {\n query = { thread_id, checkpoint_ns };\n }\n const result = await this.db\n .collection(this.checkpointCollectionName)\n .find(query)\n .sort(\"checkpoint_id\", -1)\n .limit(1)\n .toArray();\n if (result.length === 0) {\n return undefined;\n }\n const doc = result[0];\n const configurableValues = {\n thread_id,\n checkpoint_ns,\n checkpoint_id: doc.checkpoint_id,\n };\n const checkpoint = (await this.serde.loadsTyped(\n doc.type,\n doc.checkpoint.value(\"utf8\")\n )) as Checkpoint;\n const serializedWrites = await this.db\n .collection(this.checkpointWritesCollectionName)\n .find(configurableValues)\n .toArray();\n const pendingWrites: CheckpointPendingWrite[] = await Promise.all(\n serializedWrites.map(async (serializedWrite) => {\n return [\n serializedWrite.task_id,\n serializedWrite.channel,\n await this.serde.loadsTyped(\n serializedWrite.type,\n serializedWrite.value.value(\"utf8\")\n ),\n ] as CheckpointPendingWrite;\n })\n );\n return {\n config: { configurable: configurableValues },\n checkpoint,\n pendingWrites,\n metadata: (await this.serde.loadsTyped(\n doc.type,\n doc.metadata.value(\"utf8\")\n )) as CheckpointMetadata,\n parentConfig:\n doc.parent_checkpoint_id != null\n ? {\n configurable: {\n thread_id,\n checkpoint_ns,\n checkpoint_id: doc.parent_checkpoint_id,\n },\n }\n : undefined,\n };\n }\n\n /**\n * Retrieve a list of checkpoint tuples from the MongoDB database based\n * on the provided config. The checkpoints are ordered by checkpoint ID\n * in descending order (newest first).\n */\n async *list(\n config: RunnableConfig,\n options?: CheckpointListOptions\n ): AsyncGenerator<CheckpointTuple> {\n const { limit, before, filter } = options ?? {};\n const query: Record<string, unknown> = {};\n\n if (config?.configurable?.thread_id) {\n query.thread_id = config.configurable.thread_id;\n }\n\n if (\n config?.configurable?.checkpoint_ns !== undefined &&\n config?.configurable?.checkpoint_ns !== null\n ) {\n query.checkpoint_ns = config.configurable.checkpoint_ns;\n }\n\n if (filter) {\n Object.entries(filter).forEach(([key, value]) => {\n query[`metadata.${key}`] = value;\n });\n }\n\n if (before) {\n query.checkpoint_id = { $lt: before.configurable?.checkpoint_id };\n }\n\n let result = this.db\n .collection(this.checkpointCollectionName)\n .find(query)\n .sort(\"checkpoint_id\", -1);\n\n if (limit !== undefined) {\n result = result.limit(limit);\n }\n\n for await (const doc of result) {\n const checkpoint = (await this.serde.loadsTyped(\n doc.type,\n doc.checkpoint.value(\"utf8\")\n )) as Checkpoint;\n const metadata = (await this.serde.loadsTyped(\n doc.type,\n doc.metadata.value(\"utf8\")\n )) as CheckpointMetadata;\n\n yield {\n config: {\n configurable: {\n thread_id: doc.thread_id,\n checkpoint_ns: doc.checkpoint_ns,\n checkpoint_id: doc.checkpoint_id,\n },\n },\n checkpoint,\n metadata,\n parentConfig: doc.parent_checkpoint_id\n ? {\n configurable: {\n thread_id: doc.thread_id,\n checkpoint_ns: doc.checkpoint_ns,\n checkpoint_id: doc.parent_checkpoint_id,\n },\n }\n : undefined,\n };\n }\n }\n\n /**\n * Saves a checkpoint to the MongoDB database. The checkpoint is associated\n * with the provided config and its parent config (if any).\n */\n async put(\n config: RunnableConfig,\n checkpoint: Checkpoint,\n metadata: CheckpointMetadata\n ): Promise<RunnableConfig> {\n const thread_id = config.configurable?.thread_id;\n const checkpoint_ns = config.configurable?.checkpoint_ns ?? \"\";\n const checkpoint_id = checkpoint.id;\n if (thread_id === undefined) {\n throw new Error(\n `The provided config must contain a configurable field with a \"thread_id\" field.`\n );\n }\n const [\n [checkpointType, serializedCheckpoint],\n [metadataType, serializedMetadata],\n ] = await Promise.all([\n this.serde.dumpsTyped(checkpoint),\n this.serde.dumpsTyped(metadata),\n ]);\n\n if (checkpointType !== metadataType) {\n throw new Error(\"Mismatched checkpoint and metadata types.\");\n }\n const doc = {\n parent_checkpoint_id: config.configurable?.checkpoint_id,\n type: checkpointType,\n checkpoint: serializedCheckpoint,\n metadata: serializedMetadata,\n };\n const upsertQuery = {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n };\n await this.db\n .collection(this.checkpointCollectionName)\n .updateOne(upsertQuery, { $set: doc }, { upsert: true });\n\n return {\n configurable: {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n },\n };\n }\n\n /**\n * Saves intermediate writes associated with a checkpoint to the MongoDB database.\n */\n async putWrites(\n config: RunnableConfig,\n writes: PendingWrite[],\n taskId: string\n ): Promise<void> {\n const thread_id = config.configurable?.thread_id;\n const checkpoint_ns = config.configurable?.checkpoint_ns;\n const checkpoint_id = config.configurable?.checkpoint_id;\n if (\n thread_id === undefined ||\n checkpoint_ns === undefined ||\n checkpoint_id === undefined\n ) {\n throw new Error(\n `The provided config must contain a configurable field with \"thread_id\", \"checkpoint_ns\" and \"checkpoint_id\" fields.`\n );\n }\n\n const operations = await Promise.all(\n writes.map(async ([channel, value], idx) => {\n const upsertQuery = {\n thread_id,\n checkpoint_ns,\n checkpoint_id,\n task_id: taskId,\n idx,\n };\n\n const [type, serializedValue] = await this.serde.dumpsTyped(value);\n\n return {\n updateOne: {\n filter: upsertQuery,\n update: { $set: { channel, type, value: serializedValue } },\n upsert: true,\n },\n };\n })\n );\n\n await this.db\n .collection(this.checkpointWritesCollectionName)\n .bulkWrite(operations);\n }\n\n async deleteThread(threadId: string) {\n await this.db\n .collection(this.checkpointCollectionName)\n .deleteMany({ thread_id: threadId });\n\n await this.db\n .collection(this.checkpointWritesCollectionName)\n .deleteMany({ thread_id: threadId });\n }\n}\n"],"mappings":";;;;;;AAuBA,IAAa,eAAb,cAAkC,oBAAoB;CACpD,AAAU;CAEV,AAAU;CAEV,2BAA2B;CAE3B,iCAAiC;CAEjC,YACE,EACE,QACA,QACA,0BACA,kCAEF,OACA;AACA,QAAM;AACN,OAAK,SAAS;AACd,OAAK,KAAK,KAAK,OAAO,GAAG;AACzB,OAAK,2BACH,4BAA4B,KAAK;AACnC,OAAK,iCACH,kCAAkC,KAAK;;;;;;;;CAS3C,MAAM,SAAS,QAA8D;EAC3E,MAAM,EACJ,WACA,gBAAgB,IAChB,kBACE,OAAO,gBAAgB;EAC3B,IAAI;AACJ,MAAI,cACF,SAAQ;GACN;GACA;GACA;;MAGF,SAAQ;GAAE;GAAW;;EAEvB,MAAM,SAAS,MAAM,KAAK,GACvB,WAAW,KAAK,0BAChB,KAAK,OACL,KAAK,iBAAiB,IACtB,MAAM,GACN;AACH,MAAI,OAAO,WAAW,EACpB,QAAO;EAET,MAAM,MAAM,OAAO;EACnB,MAAM,qBAAqB;GACzB;GACA;GACA,eAAe,IAAI;;EAErB,MAAM,aAAc,MAAM,KAAK,MAAM,WACnC,IAAI,MACJ,IAAI,WAAW,MAAM;EAEvB,MAAM,mBAAmB,MAAM,KAAK,GACjC,WAAW,KAAK,gCAChB,KAAK,oBACL;EACH,MAAMA,gBAA0C,MAAM,QAAQ,IAC5D,iBAAiB,IAAI,OAAO,oBAAoB;AAC9C,UAAO;IACL,gBAAgB;IAChB,gBAAgB;IAChB,MAAM,KAAK,MAAM,WACf,gBAAgB,MAChB,gBAAgB,MAAM,MAAM;;;AAKpC,SAAO;GACL,QAAQ,EAAE,cAAc;GACxB;GACA;GACA,UAAW,MAAM,KAAK,MAAM,WAC1B,IAAI,MACJ,IAAI,SAAS,MAAM;GAErB,cACE,IAAI,wBAAwB,OACxB,EACE,cAAc;IACZ;IACA;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I,mBAAmB,aACrB,OAAM,IAAI,MAAM;EAElB,MAAM,MAAM;GACV,sBAAsB,OAAO,cAAc;GAC3C,MAAM;GACN,YAAY;GACZ,UAAU;;EAEZ,MAAM,cAAc;GAClB;GACA;GACA;;AAEF,QAAM,KAAK,GACR,WAAW,KAAK,0BAChB,UAAU,aAAa,EAAE,MAAM,OAAO,EAAE,QAAQ;AAEnD,SAAO,EACL,cAAc;GACZ;GACA;GACA;;;;;;CAQN,MAAM,UACJ,QACA,QACA,QACe;EACf,MAAM,YAAY,OAAO,cAAc;EACvC,MAAM,gBAAgB,OAAO,cAAc;EAC3C,MAAM,gBAAgB,OAAO,cAAc;AAC3C,MACE,cAAc,UACd,kBAAkB,UAClB,kBAAkB,OAElB,OAAM,IAAI,MACR;EAIJ,MAAM,aAAa,MAAM,QAAQ,IAC/B,OAAO,IAAI,OAAO,CAAC,SAAS,QAAQ,QAAQ;GAC1C,MAAM,cAAc;IAClB;IACA;IACA;IACA,SAAS;IACT;;GAGF,MAAM,CAAC,MAAM,mBAAmB,MAAM,KAAK,MAAM,WAAW;AAE5D,UAAO,EACL,WAAW;IACT,QAAQ;IACR,QAAQ,EAAE,MAAM;KAAE;KAAS;KAAM,OAAO;;IACxC,QAAQ;;;AAMhB,QAAM,KAAK,GACR,WAAW,KAAK,gCAChB,UAAU;;CAGf,MAAM,aAAa,UAAkB;AACnC,QAAM,KAAK,GACR,WAAW,KAAK,0BAChB,WAAW,EAAE,WAAW;AAE3B,QAAM,KAAK,GACR,WAAW,KAAK,gCAChB,WAAW,EAAE,WAAW"}
package/package.json CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-checkpoint-mongodb",
3
- "version": "0.1.0",
3
+ "version": "1.0.0",
4
4
  "description": "LangGraph",
5
5
  "type": "module",
6
6
  "engines": {
7
7
  "node": ">=18"
8
8
  },
9
- "main": "./index.js",
10
- "types": "./index.d.ts",
9
+ "main": "./dist/index.js",
10
+ "types": "./dist/index.d.ts",
11
11
  "repository": {
12
12
  "type": "git",
13
13
  "url": "git@github.com:langchain-ai/langgraphjs.git"
14
14
  },
15
15
  "scripts": {
16
16
  "build": "yarn turbo:command build:internal --filter=@langchain/langgraph-checkpoint-mongodb",
17
- "build:internal": "yarn clean && yarn lc_build --create-entrypoints --pre --tree-shaking",
17
+ "build:internal": "yarn workspace @langchain/build compile @langchain/langgraph-checkpoint-mongodb",
18
18
  "clean": "rm -rf dist/ dist-cjs/ .turbo/",
19
19
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
20
20
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
21
21
  "lint": "yarn lint:eslint && yarn lint:dpdm",
22
22
  "lint:fix": "yarn lint:eslint --fix && yarn lint:dpdm",
23
- "prepack": "yarn build",
23
+ "prepublish": "yarn build",
24
24
  "test": "vitest run",
25
25
  "test:watch": "vitest watch",
26
26
  "test:int": "vitest run --mode int",
@@ -33,11 +33,11 @@
33
33
  "mongodb": "^6.8.0"
34
34
  },
35
35
  "peerDependencies": {
36
- "@langchain/core": ">=0.2.31 <0.4.0",
37
- "@langchain/langgraph-checkpoint": "^0.1.0"
36
+ "@langchain/core": "^1.0.1",
37
+ "@langchain/langgraph-checkpoint": "^1.0.0"
38
38
  },
39
39
  "devDependencies": {
40
- "@langchain/langgraph-checkpoint": "0.1.0",
40
+ "@langchain/langgraph-checkpoint": "1.0.0",
41
41
  "@langchain/scripts": ">=0.1.3 <0.2.0",
42
42
  "@tsconfig/recommended": "^1.0.3",
43
43
  "@types/better-sqlite3": "^7.6.12",
@@ -53,7 +53,6 @@
53
53
  "eslint-plugin-no-instanceof": "^1.0.1",
54
54
  "eslint-plugin-prettier": "^4.2.1",
55
55
  "prettier": "^2.8.3",
56
- "release-it": "^19.0.2",
57
56
  "rollup": "^4.37.0",
58
57
  "tsx": "^4.19.3",
59
58
  "typescript": "^4.9.5 || ^5.4.5",
@@ -65,21 +64,20 @@
65
64
  },
66
65
  "exports": {
67
66
  ".": {
68
- "types": {
69
- "import": "./index.d.ts",
70
- "require": "./index.d.cts",
71
- "default": "./index.d.ts"
67
+ "input": "./src/index.ts",
68
+ "typedoc": "./src/index.ts",
69
+ "import": {
70
+ "types": "./dist/index.d.ts",
71
+ "default": "./dist/index.js"
72
72
  },
73
- "import": "./index.js",
74
- "require": "./index.cjs"
73
+ "require": {
74
+ "types": "./dist/index.d.cts",
75
+ "default": "./dist/index.cjs"
76
+ }
75
77
  },
76
78
  "./package.json": "./package.json"
77
79
  },
78
80
  "files": [
79
- "dist/",
80
- "index.cjs",
81
- "index.js",
82
- "index.d.ts",
83
- "index.d.cts"
81
+ "dist/"
84
82
  ]
85
83
  }
package/index.cjs DELETED
@@ -1 +0,0 @@
1
- module.exports = require('./dist/index.cjs');
package/index.d.cts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/index.js'
package/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from './dist/index.js'
package/index.js DELETED
@@ -1 +0,0 @@
1
- export * from './dist/index.js'