@langchain/langgraph-checkpoint 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.
Files changed (121) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/_virtual/rolldown_runtime.cjs +25 -0
  3. package/dist/base.cjs +74 -88
  4. package/dist/base.cjs.map +1 -0
  5. package/dist/base.d.cts +95 -0
  6. package/dist/base.d.cts.map +1 -0
  7. package/dist/base.d.ts +79 -73
  8. package/dist/base.d.ts.map +1 -0
  9. package/dist/base.js +69 -80
  10. package/dist/base.js.map +1 -1
  11. package/dist/cache/base.cjs +17 -21
  12. package/dist/cache/base.cjs.map +1 -0
  13. package/dist/cache/base.d.cts +43 -0
  14. package/dist/cache/base.d.cts.map +1 -0
  15. package/dist/cache/base.d.ts +41 -36
  16. package/dist/cache/base.d.ts.map +1 -0
  17. package/dist/cache/base.js +16 -16
  18. package/dist/cache/base.js.map +1 -1
  19. package/dist/cache/index.cjs +2 -19
  20. package/dist/cache/index.js +4 -3
  21. package/dist/cache/memory.cjs +53 -58
  22. package/dist/cache/memory.cjs.map +1 -0
  23. package/dist/cache/memory.d.cts +19 -0
  24. package/dist/cache/memory.d.cts.map +1 -0
  25. package/dist/cache/memory.d.ts +18 -13
  26. package/dist/cache/memory.d.ts.map +1 -0
  27. package/dist/cache/memory.js +52 -53
  28. package/dist/cache/memory.js.map +1 -1
  29. package/dist/id.cjs +12 -16
  30. package/dist/id.cjs.map +1 -0
  31. package/dist/id.d.cts +10 -0
  32. package/dist/id.d.cts.map +1 -0
  33. package/dist/id.d.ts +10 -2
  34. package/dist/id.d.ts.map +1 -0
  35. package/dist/id.js +10 -12
  36. package/dist/id.js.map +1 -1
  37. package/dist/index.cjs +36 -27
  38. package/dist/index.d.cts +12 -0
  39. package/dist/index.d.ts +12 -8
  40. package/dist/index.js +12 -9
  41. package/dist/memory.cjs +194 -268
  42. package/dist/memory.cjs.map +1 -0
  43. package/dist/memory.d.cts +22 -0
  44. package/dist/memory.d.cts.map +1 -0
  45. package/dist/memory.d.ts +19 -12
  46. package/dist/memory.d.ts.map +1 -0
  47. package/dist/memory.js +193 -263
  48. package/dist/memory.js.map +1 -1
  49. package/dist/serde/base.d.cts +10 -0
  50. package/dist/serde/base.d.cts.map +1 -0
  51. package/dist/serde/base.d.ts +9 -3
  52. package/dist/serde/base.d.ts.map +1 -0
  53. package/dist/serde/jsonplus.cjs +92 -141
  54. package/dist/serde/jsonplus.cjs.map +1 -0
  55. package/dist/serde/jsonplus.js +90 -136
  56. package/dist/serde/jsonplus.js.map +1 -1
  57. package/dist/serde/types.cjs +15 -9
  58. package/dist/serde/types.cjs.map +1 -0
  59. package/dist/serde/types.d.cts +55 -0
  60. package/dist/serde/types.d.cts.map +1 -0
  61. package/dist/serde/types.d.ts +53 -47
  62. package/dist/serde/types.d.ts.map +1 -0
  63. package/dist/serde/types.js +9 -5
  64. package/dist/serde/types.js.map +1 -1
  65. package/dist/serde/utils/fast-safe-stringify/index.cjs +88 -208
  66. package/dist/serde/utils/fast-safe-stringify/index.cjs.map +1 -0
  67. package/dist/serde/utils/fast-safe-stringify/index.js +87 -205
  68. package/dist/serde/utils/fast-safe-stringify/index.js.map +1 -1
  69. package/dist/store/base.cjs +200 -209
  70. package/dist/store/base.cjs.map +1 -0
  71. package/dist/store/base.d.cts +392 -0
  72. package/dist/store/base.d.cts.map +1 -0
  73. package/dist/store/base.d.ts +336 -332
  74. package/dist/store/base.d.ts.map +1 -0
  75. package/dist/store/base.js +198 -204
  76. package/dist/store/base.js.map +1 -1
  77. package/dist/store/batch.cjs +116 -147
  78. package/dist/store/batch.cjs.map +1 -0
  79. package/dist/store/batch.d.cts +49 -0
  80. package/dist/store/batch.d.cts.map +1 -0
  81. package/dist/store/batch.d.ts +48 -40
  82. package/dist/store/batch.d.ts.map +1 -0
  83. package/dist/store/batch.js +116 -143
  84. package/dist/store/batch.js.map +1 -1
  85. package/dist/store/memory.cjs +262 -363
  86. package/dist/store/memory.cjs.map +1 -0
  87. package/dist/store/memory.d.cts +64 -0
  88. package/dist/store/memory.d.cts.map +1 -0
  89. package/dist/store/memory.d.ts +30 -24
  90. package/dist/store/memory.d.ts.map +1 -0
  91. package/dist/store/memory.js +261 -358
  92. package/dist/store/memory.js.map +1 -1
  93. package/dist/store/utils.cjs +141 -249
  94. package/dist/store/utils.cjs.map +1 -0
  95. package/dist/store/utils.js +140 -245
  96. package/dist/store/utils.js.map +1 -1
  97. package/dist/types.d.cts +35 -0
  98. package/dist/types.d.cts.map +1 -0
  99. package/dist/types.d.ts +29 -28
  100. package/dist/types.d.ts.map +1 -0
  101. package/package.json +16 -18
  102. package/dist/cache/index.d.ts +0 -2
  103. package/dist/cache/index.js.map +0 -1
  104. package/dist/index.js.map +0 -1
  105. package/dist/serde/base.cjs +0 -3
  106. package/dist/serde/base.js +0 -2
  107. package/dist/serde/base.js.map +0 -1
  108. package/dist/serde/jsonplus.d.ts +0 -7
  109. package/dist/serde/utils/fast-safe-stringify/index.d.ts +0 -1
  110. package/dist/store/index.cjs +0 -20
  111. package/dist/store/index.d.ts +0 -3
  112. package/dist/store/index.js +0 -4
  113. package/dist/store/index.js.map +0 -1
  114. package/dist/store/utils.d.ts +0 -26
  115. package/dist/types.cjs +0 -3
  116. package/dist/types.js +0 -2
  117. package/dist/types.js.map +0 -1
  118. package/index.cjs +0 -1
  119. package/index.d.cts +0 -1
  120. package/index.d.ts +0 -1
  121. package/index.js +0 -1
package/dist/memory.cjs CHANGED
@@ -1,273 +1,199 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemorySaver = void 0;
4
- const base_js_1 = require("./base.cjs");
5
- const types_js_1 = require("./serde/types.cjs");
1
+ const require_types = require('./serde/types.cjs');
2
+ const require_base = require('./base.cjs');
3
+
4
+ //#region src/memory.ts
6
5
  function _generateKey(threadId, checkpointNamespace, checkpointId) {
7
- return JSON.stringify([threadId, checkpointNamespace, checkpointId]);
6
+ return JSON.stringify([
7
+ threadId,
8
+ checkpointNamespace,
9
+ checkpointId
10
+ ]);
8
11
  }
9
12
  function _parseKey(key) {
10
- const [threadId, checkpointNamespace, checkpointId] = JSON.parse(key);
11
- return { threadId, checkpointNamespace, checkpointId };
12
- }
13
- class MemorySaver extends base_js_1.BaseCheckpointSaver {
14
- constructor(serde) {
15
- super(serde);
16
- // thread ID -> checkpoint namespace -> checkpoint ID -> checkpoint mapping
17
- Object.defineProperty(this, "storage", {
18
- enumerable: true,
19
- configurable: true,
20
- writable: true,
21
- value: {}
22
- });
23
- Object.defineProperty(this, "writes", {
24
- enumerable: true,
25
- configurable: true,
26
- writable: true,
27
- value: {}
28
- });
29
- }
30
- async _migratePendingSends(mutableCheckpoint, threadId, checkpointNs, parentCheckpointId) {
31
- const deseriablizableCheckpoint = mutableCheckpoint;
32
- const parentKey = _generateKey(threadId, checkpointNs, parentCheckpointId);
33
- const pendingSends = await Promise.all(Object.values(this.writes[parentKey] ?? {})
34
- .filter(([_taskId, channel]) => channel === types_js_1.TASKS)
35
- .map(async ([_taskId, _channel, writes]) => await this.serde.loadsTyped("json", writes)));
36
- deseriablizableCheckpoint.channel_values ??= {};
37
- deseriablizableCheckpoint.channel_values[types_js_1.TASKS] = pendingSends;
38
- deseriablizableCheckpoint.channel_versions ??= {};
39
- deseriablizableCheckpoint.channel_versions[types_js_1.TASKS] =
40
- Object.keys(deseriablizableCheckpoint.channel_versions).length > 0
41
- ? (0, base_js_1.maxChannelVersion)(...Object.values(deseriablizableCheckpoint.channel_versions))
42
- : this.getNextVersion(undefined);
43
- }
44
- async getTuple(config) {
45
- const thread_id = config.configurable?.thread_id;
46
- const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
47
- let checkpoint_id = (0, base_js_1.getCheckpointId)(config);
48
- if (checkpoint_id) {
49
- const saved = this.storage[thread_id]?.[checkpoint_ns]?.[checkpoint_id];
50
- if (saved !== undefined) {
51
- const [checkpoint, metadata, parentCheckpointId] = saved;
52
- const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);
53
- const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
54
- if (deserializedCheckpoint.v < 4 && parentCheckpointId !== undefined) {
55
- await this._migratePendingSends(deserializedCheckpoint, thread_id, checkpoint_ns, parentCheckpointId);
56
- }
57
- const pendingWrites = await Promise.all(Object.values(this.writes[key] || {}).map(async ([taskId, channel, value]) => {
58
- return [
59
- taskId,
60
- channel,
61
- await this.serde.loadsTyped("json", value),
62
- ];
63
- }));
64
- const checkpointTuple = {
65
- config,
66
- checkpoint: deserializedCheckpoint,
67
- metadata: (await this.serde.loadsTyped("json", metadata)),
68
- pendingWrites,
69
- };
70
- if (parentCheckpointId !== undefined) {
71
- checkpointTuple.parentConfig = {
72
- configurable: {
73
- thread_id,
74
- checkpoint_ns,
75
- checkpoint_id: parentCheckpointId,
76
- },
77
- };
78
- }
79
- return checkpointTuple;
80
- }
81
- }
82
- else {
83
- const checkpoints = this.storage[thread_id]?.[checkpoint_ns];
84
- if (checkpoints !== undefined) {
85
- // eslint-disable-next-line prefer-destructuring
86
- checkpoint_id = Object.keys(checkpoints).sort((a, b) => b.localeCompare(a))[0];
87
- const saved = checkpoints[checkpoint_id];
88
- const [checkpoint, metadata, parentCheckpointId] = saved;
89
- const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);
90
- const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
91
- if (deserializedCheckpoint.v < 4 && parentCheckpointId !== undefined) {
92
- await this._migratePendingSends(deserializedCheckpoint, thread_id, checkpoint_ns, parentCheckpointId);
93
- }
94
- const pendingWrites = await Promise.all(Object.values(this.writes[key] || {}).map(async ([taskId, channel, value]) => {
95
- return [
96
- taskId,
97
- channel,
98
- await this.serde.loadsTyped("json", value),
99
- ];
100
- }));
101
- const checkpointTuple = {
102
- config: {
103
- configurable: {
104
- thread_id,
105
- checkpoint_id,
106
- checkpoint_ns,
107
- },
108
- },
109
- checkpoint: deserializedCheckpoint,
110
- metadata: (await this.serde.loadsTyped("json", metadata)),
111
- pendingWrites,
112
- };
113
- if (parentCheckpointId !== undefined) {
114
- checkpointTuple.parentConfig = {
115
- configurable: {
116
- thread_id,
117
- checkpoint_ns,
118
- checkpoint_id: parentCheckpointId,
119
- },
120
- };
121
- }
122
- return checkpointTuple;
123
- }
124
- }
125
- return undefined;
126
- }
127
- async *list(config, options) {
128
- // eslint-disable-next-line prefer-const
129
- let { before, limit, filter } = options ?? {};
130
- const threadIds = config.configurable?.thread_id
131
- ? [config.configurable?.thread_id]
132
- : Object.keys(this.storage);
133
- const configCheckpointNamespace = config.configurable?.checkpoint_ns;
134
- const configCheckpointId = config.configurable?.checkpoint_id;
135
- for (const threadId of threadIds) {
136
- for (const checkpointNamespace of Object.keys(this.storage[threadId] ?? {})) {
137
- if (configCheckpointNamespace !== undefined &&
138
- checkpointNamespace !== configCheckpointNamespace) {
139
- continue;
140
- }
141
- const checkpoints = this.storage[threadId]?.[checkpointNamespace] ?? {};
142
- const sortedCheckpoints = Object.entries(checkpoints).sort((a, b) => b[0].localeCompare(a[0]));
143
- for (const [checkpointId, [checkpoint, metadataStr, parentCheckpointId],] of sortedCheckpoints) {
144
- // Filter by checkpoint ID from config
145
- if (configCheckpointId && checkpointId !== configCheckpointId) {
146
- continue;
147
- }
148
- // Filter by checkpoint ID from before config
149
- if (before &&
150
- before.configurable?.checkpoint_id &&
151
- checkpointId >= before.configurable.checkpoint_id) {
152
- continue;
153
- }
154
- // Parse metadata
155
- const metadata = (await this.serde.loadsTyped("json", metadataStr));
156
- if (filter &&
157
- !Object.entries(filter).every(([key, value]) => metadata[key] === value)) {
158
- continue;
159
- }
160
- // Limit search results
161
- if (limit !== undefined) {
162
- if (limit <= 0)
163
- break;
164
- limit -= 1;
165
- }
166
- const key = _generateKey(threadId, checkpointNamespace, checkpointId);
167
- const writes = Object.values(this.writes[key] || {});
168
- const pendingWrites = await Promise.all(writes.map(async ([taskId, channel, value]) => {
169
- return [
170
- taskId,
171
- channel,
172
- await this.serde.loadsTyped("json", value),
173
- ];
174
- }));
175
- const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
176
- if (deserializedCheckpoint.v < 4 &&
177
- parentCheckpointId !== undefined) {
178
- await this._migratePendingSends(deserializedCheckpoint, threadId, checkpointNamespace, parentCheckpointId);
179
- }
180
- const checkpointTuple = {
181
- config: {
182
- configurable: {
183
- thread_id: threadId,
184
- checkpoint_ns: checkpointNamespace,
185
- checkpoint_id: checkpointId,
186
- },
187
- },
188
- checkpoint: deserializedCheckpoint,
189
- metadata,
190
- pendingWrites,
191
- };
192
- if (parentCheckpointId !== undefined) {
193
- checkpointTuple.parentConfig = {
194
- configurable: {
195
- thread_id: threadId,
196
- checkpoint_ns: checkpointNamespace,
197
- checkpoint_id: parentCheckpointId,
198
- },
199
- };
200
- }
201
- yield checkpointTuple;
202
- }
203
- }
204
- }
205
- }
206
- async put(config, checkpoint, metadata) {
207
- const preparedCheckpoint = (0, base_js_1.copyCheckpoint)(checkpoint);
208
- const threadId = config.configurable?.thread_id;
209
- const checkpointNamespace = config.configurable?.checkpoint_ns ?? "";
210
- if (threadId === undefined) {
211
- throw new Error(`Failed to put checkpoint. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property.`);
212
- }
213
- if (!this.storage[threadId]) {
214
- this.storage[threadId] = {};
215
- }
216
- if (!this.storage[threadId][checkpointNamespace]) {
217
- this.storage[threadId][checkpointNamespace] = {};
218
- }
219
- const [[, serializedCheckpoint], [, serializedMetadata]] = await Promise.all([
220
- this.serde.dumpsTyped(preparedCheckpoint),
221
- this.serde.dumpsTyped(metadata),
222
- ]);
223
- this.storage[threadId][checkpointNamespace][checkpoint.id] = [
224
- serializedCheckpoint,
225
- serializedMetadata,
226
- config.configurable?.checkpoint_id, // parent
227
- ];
228
- return {
229
- configurable: {
230
- thread_id: threadId,
231
- checkpoint_ns: checkpointNamespace,
232
- checkpoint_id: checkpoint.id,
233
- },
234
- };
235
- }
236
- async putWrites(config, writes, taskId) {
237
- const threadId = config.configurable?.thread_id;
238
- const checkpointNamespace = config.configurable?.checkpoint_ns;
239
- const checkpointId = config.configurable?.checkpoint_id;
240
- if (threadId === undefined) {
241
- throw new Error(`Failed to put writes. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property`);
242
- }
243
- if (checkpointId === undefined) {
244
- throw new Error(`Failed to put writes. The passed RunnableConfig is missing a required "checkpoint_id" field in its "configurable" property.`);
245
- }
246
- const outerKey = _generateKey(threadId, checkpointNamespace, checkpointId);
247
- const outerWrites_ = this.writes[outerKey];
248
- if (this.writes[outerKey] === undefined) {
249
- this.writes[outerKey] = {};
250
- }
251
- await Promise.all(writes.map(async ([channel, value], idx) => {
252
- const [, serializedValue] = await this.serde.dumpsTyped(value);
253
- const innerKey = [
254
- taskId,
255
- base_js_1.WRITES_IDX_MAP[channel] || idx,
256
- ];
257
- const innerKeyStr = `${innerKey[0]},${innerKey[1]}`;
258
- if (innerKey[1] >= 0 && outerWrites_ && innerKeyStr in outerWrites_) {
259
- return;
260
- }
261
- this.writes[outerKey][innerKeyStr] = [taskId, channel, serializedValue];
262
- }));
263
- }
264
- async deleteThread(threadId) {
265
- delete this.storage[threadId];
266
- for (const key of Object.keys(this.writes)) {
267
- if (_parseKey(key).threadId === threadId)
268
- delete this.writes[key];
269
- }
270
- }
13
+ const [threadId, checkpointNamespace, checkpointId] = JSON.parse(key);
14
+ return {
15
+ threadId,
16
+ checkpointNamespace,
17
+ checkpointId
18
+ };
271
19
  }
20
+ var MemorySaver = class extends require_base.BaseCheckpointSaver {
21
+ storage = {};
22
+ writes = {};
23
+ constructor(serde) {
24
+ super(serde);
25
+ }
26
+ /** @internal */
27
+ async _migratePendingSends(mutableCheckpoint, threadId, checkpointNs, parentCheckpointId) {
28
+ const deseriablizableCheckpoint = mutableCheckpoint;
29
+ const parentKey = _generateKey(threadId, checkpointNs, parentCheckpointId);
30
+ const pendingSends = await Promise.all(Object.values(this.writes[parentKey] ?? {}).filter(([_taskId, channel]) => channel === require_types.TASKS).map(async ([_taskId, _channel, writes]) => await this.serde.loadsTyped("json", writes)));
31
+ deseriablizableCheckpoint.channel_values ??= {};
32
+ deseriablizableCheckpoint.channel_values[require_types.TASKS] = pendingSends;
33
+ deseriablizableCheckpoint.channel_versions ??= {};
34
+ deseriablizableCheckpoint.channel_versions[require_types.TASKS] = Object.keys(deseriablizableCheckpoint.channel_versions).length > 0 ? require_base.maxChannelVersion(...Object.values(deseriablizableCheckpoint.channel_versions)) : this.getNextVersion(void 0);
35
+ }
36
+ async getTuple(config) {
37
+ const thread_id = config.configurable?.thread_id;
38
+ const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
39
+ let checkpoint_id = require_base.getCheckpointId(config);
40
+ if (checkpoint_id) {
41
+ const saved = this.storage[thread_id]?.[checkpoint_ns]?.[checkpoint_id];
42
+ if (saved !== void 0) {
43
+ const [checkpoint, metadata, parentCheckpointId] = saved;
44
+ const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);
45
+ const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
46
+ if (deserializedCheckpoint.v < 4 && parentCheckpointId !== void 0) await this._migratePendingSends(deserializedCheckpoint, thread_id, checkpoint_ns, parentCheckpointId);
47
+ const pendingWrites = await Promise.all(Object.values(this.writes[key] || {}).map(async ([taskId, channel, value]) => {
48
+ return [
49
+ taskId,
50
+ channel,
51
+ await this.serde.loadsTyped("json", value)
52
+ ];
53
+ }));
54
+ const checkpointTuple = {
55
+ config,
56
+ checkpoint: deserializedCheckpoint,
57
+ metadata: await this.serde.loadsTyped("json", metadata),
58
+ pendingWrites
59
+ };
60
+ if (parentCheckpointId !== void 0) checkpointTuple.parentConfig = { configurable: {
61
+ thread_id,
62
+ checkpoint_ns,
63
+ checkpoint_id: parentCheckpointId
64
+ } };
65
+ return checkpointTuple;
66
+ }
67
+ } else {
68
+ const checkpoints = this.storage[thread_id]?.[checkpoint_ns];
69
+ if (checkpoints !== void 0) {
70
+ checkpoint_id = Object.keys(checkpoints).sort((a, b) => b.localeCompare(a))[0];
71
+ const saved = checkpoints[checkpoint_id];
72
+ const [checkpoint, metadata, parentCheckpointId] = saved;
73
+ const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);
74
+ const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
75
+ if (deserializedCheckpoint.v < 4 && parentCheckpointId !== void 0) await this._migratePendingSends(deserializedCheckpoint, thread_id, checkpoint_ns, parentCheckpointId);
76
+ const pendingWrites = await Promise.all(Object.values(this.writes[key] || {}).map(async ([taskId, channel, value]) => {
77
+ return [
78
+ taskId,
79
+ channel,
80
+ await this.serde.loadsTyped("json", value)
81
+ ];
82
+ }));
83
+ const checkpointTuple = {
84
+ config: { configurable: {
85
+ thread_id,
86
+ checkpoint_id,
87
+ checkpoint_ns
88
+ } },
89
+ checkpoint: deserializedCheckpoint,
90
+ metadata: await this.serde.loadsTyped("json", metadata),
91
+ pendingWrites
92
+ };
93
+ if (parentCheckpointId !== void 0) checkpointTuple.parentConfig = { configurable: {
94
+ thread_id,
95
+ checkpoint_ns,
96
+ checkpoint_id: parentCheckpointId
97
+ } };
98
+ return checkpointTuple;
99
+ }
100
+ }
101
+ return void 0;
102
+ }
103
+ async *list(config, options) {
104
+ let { before, limit, filter } = options ?? {};
105
+ const threadIds = config.configurable?.thread_id ? [config.configurable?.thread_id] : Object.keys(this.storage);
106
+ const configCheckpointNamespace = config.configurable?.checkpoint_ns;
107
+ const configCheckpointId = config.configurable?.checkpoint_id;
108
+ for (const threadId of threadIds) for (const checkpointNamespace of Object.keys(this.storage[threadId] ?? {})) {
109
+ if (configCheckpointNamespace !== void 0 && checkpointNamespace !== configCheckpointNamespace) continue;
110
+ const checkpoints = this.storage[threadId]?.[checkpointNamespace] ?? {};
111
+ const sortedCheckpoints = Object.entries(checkpoints).sort((a, b) => b[0].localeCompare(a[0]));
112
+ for (const [checkpointId, [checkpoint, metadataStr, parentCheckpointId]] of sortedCheckpoints) {
113
+ if (configCheckpointId && checkpointId !== configCheckpointId) continue;
114
+ if (before && before.configurable?.checkpoint_id && checkpointId >= before.configurable.checkpoint_id) continue;
115
+ const metadata = await this.serde.loadsTyped("json", metadataStr);
116
+ if (filter && !Object.entries(filter).every(([key$1, value]) => metadata[key$1] === value)) continue;
117
+ if (limit !== void 0) {
118
+ if (limit <= 0) break;
119
+ limit -= 1;
120
+ }
121
+ const key = _generateKey(threadId, checkpointNamespace, checkpointId);
122
+ const writes = Object.values(this.writes[key] || {});
123
+ const pendingWrites = await Promise.all(writes.map(async ([taskId, channel, value]) => {
124
+ return [
125
+ taskId,
126
+ channel,
127
+ await this.serde.loadsTyped("json", value)
128
+ ];
129
+ }));
130
+ const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
131
+ if (deserializedCheckpoint.v < 4 && parentCheckpointId !== void 0) await this._migratePendingSends(deserializedCheckpoint, threadId, checkpointNamespace, parentCheckpointId);
132
+ const checkpointTuple = {
133
+ config: { configurable: {
134
+ thread_id: threadId,
135
+ checkpoint_ns: checkpointNamespace,
136
+ checkpoint_id: checkpointId
137
+ } },
138
+ checkpoint: deserializedCheckpoint,
139
+ metadata,
140
+ pendingWrites
141
+ };
142
+ if (parentCheckpointId !== void 0) checkpointTuple.parentConfig = { configurable: {
143
+ thread_id: threadId,
144
+ checkpoint_ns: checkpointNamespace,
145
+ checkpoint_id: parentCheckpointId
146
+ } };
147
+ yield checkpointTuple;
148
+ }
149
+ }
150
+ }
151
+ async put(config, checkpoint, metadata) {
152
+ const preparedCheckpoint = require_base.copyCheckpoint(checkpoint);
153
+ const threadId = config.configurable?.thread_id;
154
+ const checkpointNamespace = config.configurable?.checkpoint_ns ?? "";
155
+ if (threadId === void 0) throw new Error(`Failed to put checkpoint. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property.`);
156
+ if (!this.storage[threadId]) this.storage[threadId] = {};
157
+ if (!this.storage[threadId][checkpointNamespace]) this.storage[threadId][checkpointNamespace] = {};
158
+ const [[, serializedCheckpoint], [, serializedMetadata]] = await Promise.all([this.serde.dumpsTyped(preparedCheckpoint), this.serde.dumpsTyped(metadata)]);
159
+ this.storage[threadId][checkpointNamespace][checkpoint.id] = [
160
+ serializedCheckpoint,
161
+ serializedMetadata,
162
+ config.configurable?.checkpoint_id
163
+ ];
164
+ return { configurable: {
165
+ thread_id: threadId,
166
+ checkpoint_ns: checkpointNamespace,
167
+ checkpoint_id: checkpoint.id
168
+ } };
169
+ }
170
+ async putWrites(config, writes, taskId) {
171
+ const threadId = config.configurable?.thread_id;
172
+ const checkpointNamespace = config.configurable?.checkpoint_ns;
173
+ const checkpointId = config.configurable?.checkpoint_id;
174
+ if (threadId === void 0) throw new Error(`Failed to put writes. The passed RunnableConfig is missing a required "thread_id" field in its "configurable" property`);
175
+ if (checkpointId === void 0) throw new Error(`Failed to put writes. The passed RunnableConfig is missing a required "checkpoint_id" field in its "configurable" property.`);
176
+ const outerKey = _generateKey(threadId, checkpointNamespace, checkpointId);
177
+ const outerWrites_ = this.writes[outerKey];
178
+ if (this.writes[outerKey] === void 0) this.writes[outerKey] = {};
179
+ await Promise.all(writes.map(async ([channel, value], idx) => {
180
+ const [, serializedValue] = await this.serde.dumpsTyped(value);
181
+ const innerKey = [taskId, require_base.WRITES_IDX_MAP[channel] || idx];
182
+ const innerKeyStr = `${innerKey[0]},${innerKey[1]}`;
183
+ if (innerKey[1] >= 0 && outerWrites_ && innerKeyStr in outerWrites_) return;
184
+ this.writes[outerKey][innerKeyStr] = [
185
+ taskId,
186
+ channel,
187
+ serializedValue
188
+ ];
189
+ }));
190
+ }
191
+ async deleteThread(threadId) {
192
+ delete this.storage[threadId];
193
+ for (const key of Object.keys(this.writes)) if (_parseKey(key).threadId === threadId) delete this.writes[key];
194
+ }
195
+ };
196
+
197
+ //#endregion
272
198
  exports.MemorySaver = MemorySaver;
273
- //# sourceMappingURL=memory.js.map
199
+ //# sourceMappingURL=memory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.cjs","names":["BaseCheckpointSaver","TASKS","maxChannelVersion","getCheckpointId","deserializedCheckpoint: Checkpoint","pendingWrites: CheckpointPendingWrite[]","checkpointTuple: CheckpointTuple","key","preparedCheckpoint: Partial<Checkpoint>","copyCheckpoint","innerKey: [string, number]","WRITES_IDX_MAP"],"sources":["../src/memory.ts"],"sourcesContent":["import type { RunnableConfig } from \"@langchain/core/runnables\";\nimport {\n BaseCheckpointSaver,\n Checkpoint,\n CheckpointListOptions,\n CheckpointTuple,\n copyCheckpoint,\n getCheckpointId,\n maxChannelVersion,\n WRITES_IDX_MAP,\n} from \"./base.js\";\nimport { SerializerProtocol } from \"./serde/base.js\";\nimport {\n CheckpointMetadata,\n CheckpointPendingWrite,\n PendingWrite,\n} from \"./types.js\";\nimport { TASKS } from \"./serde/types.js\";\n\nfunction _generateKey(\n threadId: string,\n checkpointNamespace: string,\n checkpointId: string\n) {\n return JSON.stringify([threadId, checkpointNamespace, checkpointId]);\n}\n\nfunction _parseKey(key: string) {\n const [threadId, checkpointNamespace, checkpointId] = JSON.parse(key);\n return { threadId, checkpointNamespace, checkpointId };\n}\n\nexport class MemorySaver extends BaseCheckpointSaver {\n // thread ID -> checkpoint namespace -> checkpoint ID -> checkpoint mapping\n storage: Record<\n string,\n Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>\n > = {};\n\n writes: Record<string, Record<string, [string, string, Uint8Array]>> = {};\n\n constructor(serde?: SerializerProtocol) {\n super(serde);\n }\n\n /** @internal */\n async _migratePendingSends(\n mutableCheckpoint: Checkpoint,\n threadId: string,\n checkpointNs: string,\n parentCheckpointId: string\n ) {\n const deseriablizableCheckpoint = mutableCheckpoint;\n const parentKey = _generateKey(threadId, checkpointNs, parentCheckpointId);\n\n const pendingSends = await Promise.all(\n Object.values(this.writes[parentKey] ?? {})\n .filter(([_taskId, channel]) => channel === TASKS)\n .map(\n async ([_taskId, _channel, writes]) =>\n await this.serde.loadsTyped(\"json\", writes)\n )\n );\n\n deseriablizableCheckpoint.channel_values ??= {};\n deseriablizableCheckpoint.channel_values[TASKS] = pendingSends;\n\n deseriablizableCheckpoint.channel_versions ??= {};\n deseriablizableCheckpoint.channel_versions[TASKS] =\n Object.keys(deseriablizableCheckpoint.channel_versions).length > 0\n ? maxChannelVersion(\n ...Object.values(deseriablizableCheckpoint.channel_versions)\n )\n : this.getNextVersion(undefined);\n }\n\n async getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined> {\n const thread_id = config.configurable?.thread_id;\n const checkpoint_ns = config.configurable?.checkpoint_ns ?? \"\";\n let checkpoint_id = getCheckpointId(config);\n\n if (checkpoint_id) {\n const saved = this.storage[thread_id]?.[checkpoint_ns]?.[checkpoint_id];\n if (saved !== undefined) {\n const [checkpoint, metadata, parentCheckpointId] = saved;\n const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);\n const deserializedCheckpoint: Checkpoint = await this.serde.loadsTyped(\n \"json\",\n checkpoint\n );\n\n if (deserializedCheckpoint.v < 4 && parentCheckpointId !== undefined) {\n await this._migratePendingSends(\n deserializedCheckpoint,\n thread_id,\n checkpoint_ns,\n parentCheckpointId\n );\n }\n\n const pendingWrites: CheckpointPendingWrite[] = await Promise.all(\n Object.values(this.writes[key] || {}).map(\n async ([taskId, channel, value]) => {\n return [\n taskId,\n channel,\n await this.serde.loadsTyped(\"json\", value),\n ];\n }\n )\n );\n const checkpointTuple: CheckpointTuple = {\n config,\n checkpoint: deserializedCheckpoint,\n metadata: (await this.serde.loadsTyped(\n \"json\",\n metadata\n )) as CheckpointMetadata,\n pendingWrites,\n };\n if (parentCheckpointId !== undefined) {\n checkpointTuple.parentConfig = {\n configurable: {\n thread_id,\n checkpoint_ns,\n checkpoint_id: parentCheckpointId,\n },\n };\n }\n return checkpointTuple;\n }\n } else {\n const checkpoints = this.storage[thread_id]?.[checkpoint_ns];\n if (checkpoints !== undefined) {\n // eslint-disable-next-line prefer-destructuring\n checkpoint_id = Object.keys(checkpoints).sort((a, b) =>\n b.localeCompare(a)\n )[0];\n const saved = checkpoints[checkpoint_id];\n const [checkpoint, metadata, parentCheckpointId] = saved;\n const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);\n const deserializedCheckpoint: Checkpoint = await this.serde.loadsTyped(\n \"json\",\n checkpoint\n );\n\n if (deserializedCheckpoint.v < 4 && parentCheckpointId !== undefined) {\n await this._migratePendingSends(\n deserializedCheckpoint,\n thread_id,\n checkpoint_ns,\n parentCheckpointId\n );\n }\n\n const pendingWrites: CheckpointPendingWrite[] = await Promise.all(\n Object.values(this.writes[key] || {}).map(\n async ([taskId, channel, value]) => {\n return [\n taskId,\n channel,\n await this.serde.loadsTyped(\"json\", value),\n ];\n }\n )\n );\n const checkpointTuple: CheckpointTuple = {\n config: {\n configurable: {\n thread_id,\n checkpoint_id,\n checkpoint_ns,\n },\n },\n checkpoint: deserializedCheckpoint,\n metadata: (await this.serde.loadsTyped(\n \"json\",\n metadata\n )) as CheckpointMetadata,\n pendingWrites,\n };\n if (parentCheckpointId !== undefined) {\n checkpointTuple.parentConfig = {\n configurable: {\n thread_id,\n checkpoint_ns,\n checkpoint_id: parentCheckpointId,\n },\n };\n }\n return checkpointTuple;\n }\n }\n\n return undefined;\n }\n\n async *list(\n config: RunnableConfig,\n options?: CheckpointListOptions\n ): AsyncGenerator<CheckpointTuple> {\n // eslint-disable-next-line prefer-const\n let { before, limit, filter } = options ?? {};\n const threadIds = config.configurable?.thread_id\n ? [config.configurable?.thread_id]\n : Object.keys(this.storage);\n const configCheckpointNamespace = config.configurable?.checkpoint_ns;\n const configCheckpointId = config.configurable?.checkpoint_id;\n\n for (const threadId of threadIds) {\n for (const checkpointNamespace of Object.keys(\n this.storage[threadId] ?? {}\n )) {\n if (\n configCheckpointNamespace !== undefined &&\n checkpointNamespace !== configCheckpointNamespace\n ) {\n continue;\n }\n const checkpoints = this.storage[threadId]?.[checkpointNamespace] ?? {};\n const sortedCheckpoints = Object.entries(checkpoints).sort((a, b) =>\n b[0].localeCompare(a[0])\n );\n\n for (const [\n checkpointId,\n [checkpoint, metadataStr, parentCheckpointId],\n ] of sortedCheckpoints) {\n // Filter by checkpoint ID from config\n if (configCheckpointId && checkpointId !== configCheckpointId) {\n continue;\n }\n\n // Filter by checkpoint ID from before config\n if (\n before &&\n before.configurable?.checkpoint_id &&\n checkpointId >= before.configurable.checkpoint_id\n ) {\n continue;\n }\n\n // Parse metadata\n const metadata = (await this.serde.loadsTyped(\n \"json\",\n metadataStr\n )) as CheckpointMetadata;\n\n if (\n filter &&\n !Object.entries(filter).every(\n ([key, value]) =>\n (metadata as unknown as Record<string, unknown>)[key] === value\n )\n ) {\n continue;\n }\n\n // Limit search results\n if (limit !== undefined) {\n if (limit <= 0) break;\n limit -= 1;\n }\n\n const key = _generateKey(threadId, checkpointNamespace, checkpointId);\n const writes = Object.values(this.writes[key] || {});\n\n const pendingWrites: CheckpointPendingWrite[] = await Promise.all(\n writes.map(async ([taskId, channel, value]) => {\n return [\n taskId,\n channel,\n await this.serde.loadsTyped(\"json\", value),\n ];\n })\n );\n\n const deserializedCheckpoint = await this.serde.loadsTyped(\n \"json\",\n checkpoint\n );\n\n if (\n deserializedCheckpoint.v < 4 &&\n parentCheckpointId !== undefined\n ) {\n await this._migratePendingSends(\n deserializedCheckpoint,\n threadId,\n checkpointNamespace,\n parentCheckpointId\n );\n }\n\n const checkpointTuple: CheckpointTuple = {\n config: {\n configurable: {\n thread_id: threadId,\n checkpoint_ns: checkpointNamespace,\n checkpoint_id: checkpointId,\n },\n },\n checkpoint: deserializedCheckpoint,\n metadata,\n pendingWrites,\n };\n if (parentCheckpointId !== undefined) {\n checkpointTuple.parentConfig = {\n configurable: {\n thread_id: threadId,\n checkpoint_ns: checkpointNamespace,\n checkpoint_id: parentCheckpointId,\n },\n };\n }\n yield checkpointTuple;\n }\n }\n }\n }\n\n async put(\n config: RunnableConfig,\n checkpoint: Checkpoint,\n metadata: CheckpointMetadata\n ): Promise<RunnableConfig> {\n const preparedCheckpoint: Partial<Checkpoint> = copyCheckpoint(checkpoint);\n const threadId = config.configurable?.thread_id;\n const checkpointNamespace = config.configurable?.checkpoint_ns ?? \"\";\n if (threadId === undefined) {\n throw new Error(\n `Failed to put checkpoint. The passed RunnableConfig is missing a required \"thread_id\" field in its \"configurable\" property.`\n );\n }\n\n if (!this.storage[threadId]) {\n this.storage[threadId] = {};\n }\n if (!this.storage[threadId][checkpointNamespace]) {\n this.storage[threadId][checkpointNamespace] = {};\n }\n\n const [[, serializedCheckpoint], [, serializedMetadata]] =\n await Promise.all([\n this.serde.dumpsTyped(preparedCheckpoint),\n this.serde.dumpsTyped(metadata),\n ]);\n\n this.storage[threadId][checkpointNamespace][checkpoint.id] = [\n serializedCheckpoint,\n serializedMetadata,\n config.configurable?.checkpoint_id, // parent\n ];\n\n return {\n configurable: {\n thread_id: threadId,\n checkpoint_ns: checkpointNamespace,\n checkpoint_id: checkpoint.id,\n },\n };\n }\n\n async putWrites(\n config: RunnableConfig,\n writes: PendingWrite[],\n taskId: string\n ): Promise<void> {\n const threadId = config.configurable?.thread_id;\n const checkpointNamespace = config.configurable?.checkpoint_ns;\n const checkpointId = config.configurable?.checkpoint_id;\n if (threadId === undefined) {\n throw new Error(\n `Failed to put writes. The passed RunnableConfig is missing a required \"thread_id\" field in its \"configurable\" property`\n );\n }\n if (checkpointId === undefined) {\n throw new Error(\n `Failed to put writes. The passed RunnableConfig is missing a required \"checkpoint_id\" field in its \"configurable\" property.`\n );\n }\n const outerKey = _generateKey(threadId, checkpointNamespace, checkpointId);\n const outerWrites_ = this.writes[outerKey];\n if (this.writes[outerKey] === undefined) {\n this.writes[outerKey] = {};\n }\n\n await Promise.all(\n writes.map(async ([channel, value], idx) => {\n const [, serializedValue] = await this.serde.dumpsTyped(value);\n const innerKey: [string, number] = [\n taskId,\n WRITES_IDX_MAP[channel] || idx,\n ];\n const innerKeyStr = `${innerKey[0]},${innerKey[1]}`;\n if (innerKey[1] >= 0 && outerWrites_ && innerKeyStr in outerWrites_) {\n return;\n }\n this.writes[outerKey][innerKeyStr] = [taskId, channel, serializedValue];\n })\n );\n }\n\n async deleteThread(threadId: string): Promise<void> {\n delete this.storage[threadId];\n for (const key of Object.keys(this.writes)) {\n if (_parseKey(key).threadId === threadId) delete this.writes[key];\n }\n }\n}\n"],"mappings":";;;;AAmBA,SAAS,aACP,UACA,qBACA,cACA;AACA,QAAO,KAAK,UAAU;EAAC;EAAU;EAAqB;;;AAGxD,SAAS,UAAU,KAAa;CAC9B,MAAM,CAAC,UAAU,qBAAqB,gBAAgB,KAAK,MAAM;AACjE,QAAO;EAAE;EAAU;EAAqB;;;AAG1C,IAAa,cAAb,cAAiCA,iCAAoB;CAEnD,UAGI;CAEJ,SAAuE;CAEvE,YAAY,OAA4B;AACtC,QAAM;;;CAIR,MAAM,qBACJ,mBACA,UACA,cACA,oBACA;EACA,MAAM,4BAA4B;EAClC,MAAM,YAAY,aAAa,UAAU,cAAc;EAEvD,MAAM,eAAe,MAAM,QAAQ,IACjC,OAAO,OAAO,KAAK,OAAO,cAAc,IACrC,QAAQ,CAAC,SAAS,aAAa,YAAYC,qBAC3C,IACC,OAAO,CAAC,SAAS,UAAU,YACzB,MAAM,KAAK,MAAM,WAAW,QAAQ;AAI5C,4BAA0B,mBAAmB;AAC7C,4BAA0B,eAAeA,uBAAS;AAElD,4BAA0B,qBAAqB;AAC/C,4BAA0B,iBAAiBA,uBACzC,OAAO,KAAK,0BAA0B,kBAAkB,SAAS,IAC7DC,+BACE,GAAG,OAAO,OAAO,0BAA0B,qBAE7C,KAAK,eAAe;;CAG5B,MAAM,SAAS,QAA8D;EAC3E,MAAM,YAAY,OAAO,cAAc;EACvC,MAAM,gBAAgB,OAAO,cAAc,iBAAiB;EAC5D,IAAI,gBAAgBC,6BAAgB;AAEpC,MAAI,eAAe;GACjB,MAAM,QAAQ,KAAK,QAAQ,aAAa,iBAAiB;AACzD,OAAI,UAAU,QAAW;IACvB,MAAM,CAAC,YAAY,UAAU,sBAAsB;IACnD,MAAM,MAAM,aA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AG,mBAAmB,MAAM,KAAK,MAAM,WAAW;GACxD,MAAMC,WAA6B,CACjC,QACAC,4BAAe,YAAY;GAE7B,MAAM,cAAc,GAAG,SAAS,GAAG,GAAG,SAAS;AAC/C,OAAI,SAAS,MAAM,KAAK,gBAAgB,eAAe,aACrD;AAEF,QAAK,OAAO,UAAU,eAAe;IAAC;IAAQ;IAAS;;;;CAK7D,MAAM,aAAa,UAAiC;AAClD,SAAO,KAAK,QAAQ;AACpB,OAAK,MAAM,OAAO,OAAO,KAAK,KAAK,QACjC,KAAI,UAAU,KAAK,aAAa,SAAU,QAAO,KAAK,OAAO"}
@@ -0,0 +1,22 @@
1
+ import { SerializerProtocol } from "./serde/base.cjs";
2
+ import { CheckpointMetadata, PendingWrite } from "./types.cjs";
3
+ import { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointTuple } from "./base.cjs";
4
+ import { RunnableConfig } from "@langchain/core/runnables";
5
+
6
+ //#region src/memory.d.ts
7
+ declare class MemorySaver extends BaseCheckpointSaver {
8
+ // thread ID -> checkpoint namespace -> checkpoint ID -> checkpoint mapping
9
+ storage: Record<string, Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>>;
10
+ writes: Record<string, Record<string, [string, string, Uint8Array]>>;
11
+ constructor(serde?: SerializerProtocol);
12
+ /** @internal */
13
+ _migratePendingSends(mutableCheckpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string): Promise<void>;
14
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
15
+ list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
16
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
17
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
18
+ deleteThread(threadId: string): Promise<void>;
19
+ }
20
+ //#endregion
21
+ export { MemorySaver };
22
+ //# sourceMappingURL=memory.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.cts","names":["RunnableConfig","BaseCheckpointSaver","Checkpoint","CheckpointListOptions","CheckpointTuple","SerializerProtocol","CheckpointMetadata","PendingWrite","MemorySaver","Uint8Array","Record","Promise","AsyncGenerator"],"sources":["../src/memory.d.ts"],"sourcesContent":["import type { RunnableConfig } from \"@langchain/core/runnables\";\nimport { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointTuple } from \"./base.js\";\nimport { SerializerProtocol } from \"./serde/base.js\";\nimport { CheckpointMetadata, PendingWrite } from \"./types.js\";\nexport declare class MemorySaver extends BaseCheckpointSaver {\n // thread ID -> checkpoint namespace -> checkpoint ID -> checkpoint mapping\n storage: Record<string, Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>>;\n writes: Record<string, Record<string, [string, string, Uint8Array]>>;\n constructor(serde?: SerializerProtocol);\n /** @internal */\n _migratePendingSends(mutableCheckpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string): Promise<void>;\n getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;\n list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;\n put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;\n putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;\n deleteThread(threadId: string): Promise<void>;\n}\n"],"mappings":";;;;;;cAIqBQ,WAAAA,SAAoBP,mBAAAA;;EAApBO,OAAAA,EAERE,MAFmB,CAAA,MAAA,EAEJA,MAFI,CAAA,MAAA,EAEWA,MAFX,CAAA,MAAA,EAAA,CAE2BD,UAF3B,EAEuCA,UAFvC,EAAA,MAAA,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;EAAA,MAAA,EAGpBC,MAHoB,CAAA,MAAA,EAGLA,MAHK,CAAA,MAAA,EAAA,CAAA,MAAA,EAAA,MAAA,EAG2BD,UAH3B,CAAA,CAAA,CAAA;aAE2BA,CAAAA,KAAAA,CAAAA,EAEnCJ,kBAFmCI;;sBAAhBC,CAAAA,iBAAAA,EAICR,UAJDQ,EAAAA,QAAAA,EAAAA,MAAAA,EAAAA,YAAAA,EAAAA,MAAAA,EAAAA,kBAAAA,EAAAA,MAAAA,CAAAA,EAIkFC,OAJlFD,CAAAA,IAAAA,CAAAA;UAAfA,CAAAA,MAAAA,EAKPV,cALOU,CAAAA,EAKUC,OALVD,CAKkBN,eALlBM,GAAAA,SAAAA,CAAAA;MAAfA,CAAAA,MAAAA,EAMIV,cANJU,EAAAA,OAAAA,CAAAA,EAM8BP,qBAN9BO,CAAAA,EAMsDE,cANtDF,CAMqEN,eANrEM,CAAAA;KAC8CD,CAAAA,MAAAA,EAM3CT,cAN2CS,EAAAA,UAAAA,EAMfP,UANeO,EAAAA,QAAAA,EAMOH,kBANPG,CAAAA,EAM4BE,OAN5BF,CAMoCT,cANpCS,CAAAA;WAAhCC,CAAAA,MAAAA,EAOLV,cAPKU,EAAAA,MAAAA,EAOmBH,YAPnBG,EAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EAOoDC,OAPpDD,CAAAA,IAAAA,CAAAA;cAAfA,CAAAA,QAAAA,EAAAA,MAAAA,CAAAA,EAQwBC,OARxBD,CAAAA,IAAAA,CAAAA"}
package/dist/memory.d.ts CHANGED
@@ -1,15 +1,22 @@
1
- import type { RunnableConfig } from "@langchain/core/runnables";
2
- import { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointTuple } from "./base.js";
3
1
  import { SerializerProtocol } from "./serde/base.js";
4
2
  import { CheckpointMetadata, PendingWrite } from "./types.js";
5
- export declare class MemorySaver extends BaseCheckpointSaver {
6
- storage: Record<string, Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>>;
7
- writes: Record<string, Record<string, [string, string, Uint8Array]>>;
8
- constructor(serde?: SerializerProtocol);
9
- _migratePendingSends(mutableCheckpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string): Promise<void>;
10
- getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
11
- list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
12
- put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
13
- putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
14
- deleteThread(threadId: string): Promise<void>;
3
+ import { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointTuple } from "./base.js";
4
+ import { RunnableConfig } from "@langchain/core/runnables";
5
+
6
+ //#region src/memory.d.ts
7
+ declare class MemorySaver extends BaseCheckpointSaver {
8
+ // thread ID -> checkpoint namespace -> checkpoint ID -> checkpoint mapping
9
+ storage: Record<string, Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>>;
10
+ writes: Record<string, Record<string, [string, string, Uint8Array]>>;
11
+ constructor(serde?: SerializerProtocol);
12
+ /** @internal */
13
+ _migratePendingSends(mutableCheckpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string): Promise<void>;
14
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
15
+ list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
16
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
17
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
18
+ deleteThread(threadId: string): Promise<void>;
15
19
  }
20
+ //#endregion
21
+ export { MemorySaver };
22
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","names":["RunnableConfig","BaseCheckpointSaver","Checkpoint","CheckpointListOptions","CheckpointTuple","SerializerProtocol","CheckpointMetadata","PendingWrite","MemorySaver","Uint8Array","Record","Promise","AsyncGenerator"],"sources":["../src/memory.d.ts"],"sourcesContent":["import type { RunnableConfig } from \"@langchain/core/runnables\";\nimport { BaseCheckpointSaver, Checkpoint, CheckpointListOptions, CheckpointTuple } from \"./base.js\";\nimport { SerializerProtocol } from \"./serde/base.js\";\nimport { CheckpointMetadata, PendingWrite } from \"./types.js\";\nexport declare class MemorySaver extends BaseCheckpointSaver {\n // thread ID -> checkpoint namespace -> checkpoint ID -> checkpoint mapping\n storage: Record<string, Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>>;\n writes: Record<string, Record<string, [string, string, Uint8Array]>>;\n constructor(serde?: SerializerProtocol);\n /** @internal */\n _migratePendingSends(mutableCheckpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string): Promise<void>;\n getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;\n list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;\n put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;\n putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;\n deleteThread(threadId: string): Promise<void>;\n}\n"],"mappings":";;;;;;cAIqBQ,WAAAA,SAAoBP,mBAAAA;;EAApBO,OAAAA,EAERE,MAFmB,CAAA,MAAA,EAEJA,MAFI,CAAA,MAAA,EAEWA,MAFX,CAAA,MAAA,EAAA,CAE2BD,UAF3B,EAEuCA,UAFvC,EAAA,MAAA,GAAA,SAAA,CAAA,CAAA,CAAA,CAAA;EAAA,MAAA,EAGpBC,MAHoB,CAAA,MAAA,EAGLA,MAHK,CAAA,MAAA,EAAA,CAAA,MAAA,EAAA,MAAA,EAG2BD,UAH3B,CAAA,CAAA,CAAA;aAE2BA,CAAAA,KAAAA,CAAAA,EAEnCJ,kBAFmCI;;sBAAhBC,CAAAA,iBAAAA,EAICR,UAJDQ,EAAAA,QAAAA,EAAAA,MAAAA,EAAAA,YAAAA,EAAAA,MAAAA,EAAAA,kBAAAA,EAAAA,MAAAA,CAAAA,EAIkFC,OAJlFD,CAAAA,IAAAA,CAAAA;UAAfA,CAA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