@langchain/langgraph-checkpoint 0.1.1 → 1.0.1

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 (120) hide show
  1. package/dist/base.cjs +73 -88
  2. package/dist/base.cjs.map +1 -0
  3. package/dist/base.d.cts +94 -0
  4. package/dist/base.d.cts.map +1 -0
  5. package/dist/base.d.ts +78 -73
  6. package/dist/base.d.ts.map +1 -0
  7. package/dist/base.js +68 -80
  8. package/dist/base.js.map +1 -1
  9. package/dist/cache/base.cjs +16 -21
  10. package/dist/cache/base.cjs.map +1 -0
  11. package/dist/cache/base.d.cts +43 -0
  12. package/dist/cache/base.d.cts.map +1 -0
  13. package/dist/cache/base.d.ts +41 -36
  14. package/dist/cache/base.d.ts.map +1 -0
  15. package/dist/cache/base.js +15 -16
  16. package/dist/cache/base.js.map +1 -1
  17. package/dist/cache/index.cjs +2 -19
  18. package/dist/cache/index.js +3 -3
  19. package/dist/cache/memory.cjs +50 -58
  20. package/dist/cache/memory.cjs.map +1 -0
  21. package/dist/cache/memory.d.cts +19 -0
  22. package/dist/cache/memory.d.cts.map +1 -0
  23. package/dist/cache/memory.d.ts +18 -13
  24. package/dist/cache/memory.d.ts.map +1 -0
  25. package/dist/cache/memory.js +49 -53
  26. package/dist/cache/memory.js.map +1 -1
  27. package/dist/id.cjs +10 -16
  28. package/dist/id.cjs.map +1 -0
  29. package/dist/id.d.cts +6 -0
  30. package/dist/id.d.cts.map +1 -0
  31. package/dist/id.d.ts +6 -2
  32. package/dist/id.d.ts.map +1 -0
  33. package/dist/id.js +9 -12
  34. package/dist/id.js.map +1 -1
  35. package/dist/index.cjs +36 -27
  36. package/dist/index.d.cts +12 -0
  37. package/dist/index.d.ts +12 -8
  38. package/dist/index.js +11 -9
  39. package/dist/memory.cjs +191 -268
  40. package/dist/memory.cjs.map +1 -0
  41. package/dist/memory.d.cts +21 -0
  42. package/dist/memory.d.cts.map +1 -0
  43. package/dist/memory.d.ts +18 -12
  44. package/dist/memory.d.ts.map +1 -0
  45. package/dist/memory.js +190 -263
  46. package/dist/memory.js.map +1 -1
  47. package/dist/serde/base.d.cts +8 -0
  48. package/dist/serde/base.d.cts.map +1 -0
  49. package/dist/serde/base.d.ts +7 -3
  50. package/dist/serde/base.d.ts.map +1 -0
  51. package/dist/serde/jsonplus.cjs +90 -141
  52. package/dist/serde/jsonplus.cjs.map +1 -0
  53. package/dist/serde/jsonplus.js +89 -136
  54. package/dist/serde/jsonplus.js.map +1 -1
  55. package/dist/serde/types.cjs +14 -9
  56. package/dist/serde/types.cjs.map +1 -0
  57. package/dist/serde/types.d.cts +52 -0
  58. package/dist/serde/types.d.cts.map +1 -0
  59. package/dist/serde/types.d.ts +50 -47
  60. package/dist/serde/types.d.ts.map +1 -0
  61. package/dist/serde/types.js +9 -5
  62. package/dist/serde/types.js.map +1 -1
  63. package/dist/serde/utils/fast-safe-stringify/index.cjs +87 -208
  64. package/dist/serde/utils/fast-safe-stringify/index.cjs.map +1 -0
  65. package/dist/serde/utils/fast-safe-stringify/index.js +87 -205
  66. package/dist/serde/utils/fast-safe-stringify/index.js.map +1 -1
  67. package/dist/store/base.cjs +199 -209
  68. package/dist/store/base.cjs.map +1 -0
  69. package/dist/store/base.d.cts +391 -0
  70. package/dist/store/base.d.cts.map +1 -0
  71. package/dist/store/base.d.ts +335 -332
  72. package/dist/store/base.d.ts.map +1 -0
  73. package/dist/store/base.js +198 -204
  74. package/dist/store/base.js.map +1 -1
  75. package/dist/store/batch.cjs +114 -147
  76. package/dist/store/batch.cjs.map +1 -0
  77. package/dist/store/batch.d.cts +46 -0
  78. package/dist/store/batch.d.cts.map +1 -0
  79. package/dist/store/batch.d.ts +45 -40
  80. package/dist/store/batch.d.ts.map +1 -0
  81. package/dist/store/batch.js +114 -143
  82. package/dist/store/batch.js.map +1 -1
  83. package/dist/store/memory.cjs +256 -363
  84. package/dist/store/memory.cjs.map +1 -0
  85. package/dist/store/memory.d.cts +62 -0
  86. package/dist/store/memory.d.cts.map +1 -0
  87. package/dist/store/memory.d.ts +28 -24
  88. package/dist/store/memory.d.ts.map +1 -0
  89. package/dist/store/memory.js +255 -358
  90. package/dist/store/memory.js.map +1 -1
  91. package/dist/store/utils.cjs +137 -249
  92. package/dist/store/utils.cjs.map +1 -0
  93. package/dist/store/utils.js +137 -245
  94. package/dist/store/utils.js.map +1 -1
  95. package/dist/types.d.cts +35 -0
  96. package/dist/types.d.cts.map +1 -0
  97. package/dist/types.d.ts +29 -28
  98. package/dist/types.d.ts.map +1 -0
  99. package/package.json +33 -34
  100. package/CHANGELOG.md +0 -19
  101. package/dist/cache/index.d.ts +0 -2
  102. package/dist/cache/index.js.map +0 -1
  103. package/dist/index.js.map +0 -1
  104. package/dist/serde/base.cjs +0 -3
  105. package/dist/serde/base.js +0 -2
  106. package/dist/serde/base.js.map +0 -1
  107. package/dist/serde/jsonplus.d.ts +0 -7
  108. package/dist/serde/utils/fast-safe-stringify/index.d.ts +0 -1
  109. package/dist/store/index.cjs +0 -20
  110. package/dist/store/index.d.ts +0 -3
  111. package/dist/store/index.js +0 -4
  112. package/dist/store/index.js.map +0 -1
  113. package/dist/store/utils.d.ts +0 -26
  114. package/dist/types.cjs +0 -3
  115. package/dist/types.js +0 -2
  116. package/dist/types.js.map +0 -1
  117. package/index.cjs +0 -1
  118. package/index.d.cts +0 -1
  119. package/index.d.ts +0 -1
  120. package/index.js +0 -1
package/dist/memory.cjs CHANGED
@@ -1,273 +1,196 @@
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
+ //#region src/memory.ts
6
4
  function _generateKey(threadId, checkpointNamespace, checkpointId) {
7
- return JSON.stringify([threadId, checkpointNamespace, checkpointId]);
5
+ return JSON.stringify([
6
+ threadId,
7
+ checkpointNamespace,
8
+ checkpointId
9
+ ]);
8
10
  }
9
11
  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
- }
12
+ const [threadId, checkpointNamespace, checkpointId] = JSON.parse(key);
13
+ return {
14
+ threadId,
15
+ checkpointNamespace,
16
+ checkpointId
17
+ };
271
18
  }
19
+ var MemorySaver = class extends require_base.BaseCheckpointSaver {
20
+ storage = {};
21
+ writes = {};
22
+ constructor(serde) {
23
+ super(serde);
24
+ }
25
+ /** @internal */
26
+ async _migratePendingSends(mutableCheckpoint, threadId, checkpointNs, parentCheckpointId) {
27
+ const deseriablizableCheckpoint = mutableCheckpoint;
28
+ const parentKey = _generateKey(threadId, checkpointNs, parentCheckpointId);
29
+ 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)));
30
+ deseriablizableCheckpoint.channel_values ??= {};
31
+ deseriablizableCheckpoint.channel_values[require_types.TASKS] = pendingSends;
32
+ deseriablizableCheckpoint.channel_versions ??= {};
33
+ 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);
34
+ }
35
+ async getTuple(config) {
36
+ const thread_id = config.configurable?.thread_id;
37
+ const checkpoint_ns = config.configurable?.checkpoint_ns ?? "";
38
+ let checkpoint_id = require_base.getCheckpointId(config);
39
+ if (checkpoint_id) {
40
+ const saved = this.storage[thread_id]?.[checkpoint_ns]?.[checkpoint_id];
41
+ if (saved !== void 0) {
42
+ const [checkpoint, metadata, parentCheckpointId] = saved;
43
+ const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);
44
+ const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
45
+ if (deserializedCheckpoint.v < 4 && parentCheckpointId !== void 0) await this._migratePendingSends(deserializedCheckpoint, thread_id, checkpoint_ns, parentCheckpointId);
46
+ const pendingWrites = await Promise.all(Object.values(this.writes[key] || {}).map(async ([taskId, channel, value]) => {
47
+ return [
48
+ taskId,
49
+ channel,
50
+ await this.serde.loadsTyped("json", value)
51
+ ];
52
+ }));
53
+ const checkpointTuple = {
54
+ config,
55
+ checkpoint: deserializedCheckpoint,
56
+ metadata: await this.serde.loadsTyped("json", metadata),
57
+ pendingWrites
58
+ };
59
+ if (parentCheckpointId !== void 0) checkpointTuple.parentConfig = { configurable: {
60
+ thread_id,
61
+ checkpoint_ns,
62
+ checkpoint_id: parentCheckpointId
63
+ } };
64
+ return checkpointTuple;
65
+ }
66
+ } else {
67
+ const checkpoints = this.storage[thread_id]?.[checkpoint_ns];
68
+ if (checkpoints !== void 0) {
69
+ checkpoint_id = Object.keys(checkpoints).sort((a, b) => b.localeCompare(a))[0];
70
+ const [checkpoint, metadata, parentCheckpointId] = checkpoints[checkpoint_id];
71
+ const key = _generateKey(thread_id, checkpoint_ns, checkpoint_id);
72
+ const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
73
+ if (deserializedCheckpoint.v < 4 && parentCheckpointId !== void 0) await this._migratePendingSends(deserializedCheckpoint, thread_id, checkpoint_ns, parentCheckpointId);
74
+ const pendingWrites = await Promise.all(Object.values(this.writes[key] || {}).map(async ([taskId, channel, value]) => {
75
+ return [
76
+ taskId,
77
+ channel,
78
+ await this.serde.loadsTyped("json", value)
79
+ ];
80
+ }));
81
+ const checkpointTuple = {
82
+ config: { configurable: {
83
+ thread_id,
84
+ checkpoint_id,
85
+ checkpoint_ns
86
+ } },
87
+ checkpoint: deserializedCheckpoint,
88
+ metadata: await this.serde.loadsTyped("json", metadata),
89
+ pendingWrites
90
+ };
91
+ if (parentCheckpointId !== void 0) checkpointTuple.parentConfig = { configurable: {
92
+ thread_id,
93
+ checkpoint_ns,
94
+ checkpoint_id: parentCheckpointId
95
+ } };
96
+ return checkpointTuple;
97
+ }
98
+ }
99
+ }
100
+ async *list(config, options) {
101
+ let { before, limit, filter } = options ?? {};
102
+ const threadIds = config.configurable?.thread_id ? [config.configurable?.thread_id] : Object.keys(this.storage);
103
+ const configCheckpointNamespace = config.configurable?.checkpoint_ns;
104
+ const configCheckpointId = config.configurable?.checkpoint_id;
105
+ for (const threadId of threadIds) for (const checkpointNamespace of Object.keys(this.storage[threadId] ?? {})) {
106
+ if (configCheckpointNamespace !== void 0 && checkpointNamespace !== configCheckpointNamespace) continue;
107
+ const checkpoints = this.storage[threadId]?.[checkpointNamespace] ?? {};
108
+ const sortedCheckpoints = Object.entries(checkpoints).sort((a, b) => b[0].localeCompare(a[0]));
109
+ for (const [checkpointId, [checkpoint, metadataStr, parentCheckpointId]] of sortedCheckpoints) {
110
+ if (configCheckpointId && checkpointId !== configCheckpointId) continue;
111
+ if (before && before.configurable?.checkpoint_id && checkpointId >= before.configurable.checkpoint_id) continue;
112
+ const metadata = await this.serde.loadsTyped("json", metadataStr);
113
+ if (filter && !Object.entries(filter).every(([key, value]) => metadata[key] === value)) continue;
114
+ if (limit !== void 0) {
115
+ if (limit <= 0) break;
116
+ limit -= 1;
117
+ }
118
+ const key = _generateKey(threadId, checkpointNamespace, checkpointId);
119
+ const writes = Object.values(this.writes[key] || {});
120
+ const pendingWrites = await Promise.all(writes.map(async ([taskId, channel, value]) => {
121
+ return [
122
+ taskId,
123
+ channel,
124
+ await this.serde.loadsTyped("json", value)
125
+ ];
126
+ }));
127
+ const deserializedCheckpoint = await this.serde.loadsTyped("json", checkpoint);
128
+ if (deserializedCheckpoint.v < 4 && parentCheckpointId !== void 0) await this._migratePendingSends(deserializedCheckpoint, threadId, checkpointNamespace, parentCheckpointId);
129
+ const checkpointTuple = {
130
+ config: { configurable: {
131
+ thread_id: threadId,
132
+ checkpoint_ns: checkpointNamespace,
133
+ checkpoint_id: checkpointId
134
+ } },
135
+ checkpoint: deserializedCheckpoint,
136
+ metadata,
137
+ pendingWrites
138
+ };
139
+ if (parentCheckpointId !== void 0) checkpointTuple.parentConfig = { configurable: {
140
+ thread_id: threadId,
141
+ checkpoint_ns: checkpointNamespace,
142
+ checkpoint_id: parentCheckpointId
143
+ } };
144
+ yield checkpointTuple;
145
+ }
146
+ }
147
+ }
148
+ async put(config, checkpoint, metadata) {
149
+ const preparedCheckpoint = require_base.copyCheckpoint(checkpoint);
150
+ const threadId = config.configurable?.thread_id;
151
+ const checkpointNamespace = config.configurable?.checkpoint_ns ?? "";
152
+ 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.`);
153
+ if (!this.storage[threadId]) this.storage[threadId] = {};
154
+ if (!this.storage[threadId][checkpointNamespace]) this.storage[threadId][checkpointNamespace] = {};
155
+ const [[, serializedCheckpoint], [, serializedMetadata]] = await Promise.all([this.serde.dumpsTyped(preparedCheckpoint), this.serde.dumpsTyped(metadata)]);
156
+ this.storage[threadId][checkpointNamespace][checkpoint.id] = [
157
+ serializedCheckpoint,
158
+ serializedMetadata,
159
+ config.configurable?.checkpoint_id
160
+ ];
161
+ return { configurable: {
162
+ thread_id: threadId,
163
+ checkpoint_ns: checkpointNamespace,
164
+ checkpoint_id: checkpoint.id
165
+ } };
166
+ }
167
+ async putWrites(config, writes, taskId) {
168
+ const threadId = config.configurable?.thread_id;
169
+ const checkpointNamespace = config.configurable?.checkpoint_ns;
170
+ const checkpointId = config.configurable?.checkpoint_id;
171
+ 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`);
172
+ 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.`);
173
+ const outerKey = _generateKey(threadId, checkpointNamespace, checkpointId);
174
+ const outerWrites_ = this.writes[outerKey];
175
+ if (this.writes[outerKey] === void 0) this.writes[outerKey] = {};
176
+ await Promise.all(writes.map(async ([channel, value], idx) => {
177
+ const [, serializedValue] = await this.serde.dumpsTyped(value);
178
+ const innerKey = [taskId, require_base.WRITES_IDX_MAP[channel] || idx];
179
+ const innerKeyStr = `${innerKey[0]},${innerKey[1]}`;
180
+ if (innerKey[1] >= 0 && outerWrites_ && innerKeyStr in outerWrites_) return;
181
+ this.writes[outerKey][innerKeyStr] = [
182
+ taskId,
183
+ channel,
184
+ serializedValue
185
+ ];
186
+ }));
187
+ }
188
+ async deleteThread(threadId) {
189
+ delete this.storage[threadId];
190
+ for (const key of Object.keys(this.writes)) if (_parseKey(key).threadId === threadId) delete this.writes[key];
191
+ }
192
+ };
193
+ //#endregion
272
194
  exports.MemorySaver = MemorySaver;
273
- //# sourceMappingURL=memory.js.map
195
+
196
+ //# sourceMappingURL=memory.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.cjs","names":["BaseCheckpointSaver","TASKS","maxChannelVersion","getCheckpointId","copyCheckpoint","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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sBAAsB,OAAO,cAAc;EACjD,MAAM,eAAe,OAAO,cAAc;AAC1C,MAAI,aAAa,KAAA,EACf,OAAM,IAAI,MACR,yHACD;AAEH,MAAI,iBAAiB,KAAA,EACnB,OAAM,IAAI,MACR,8HACD;EAEH,MAAM,WAAW,aAAa,UAAU,qBAAqB,aAAa;EAC1E,MAAM,eAAe,KAAK,OAAO;AACjC,MAAI,KAAK,OAAO,cAAc,KAAA,EAC5B,MAAK,OAAO,YAAY,EAAE;AAG5B,QAAM,QAAQ,IACZ,OAAO,IAAI,OAAO,CAAC,SAAS,QAAQ,QAAQ;GAC1C,MAAM,GAAG,mBAAmB,MAAM,KAAK,MAAM,WAAW,MAAM;GAC9D,MAAM,WAA6B,CACjC,QACAC,aAAAA,eAAe,YAAY,IAC5B;GACD,MAAM,cAAc,GAAG,SAAS,GAAG,GAAG,SAAS;AAC/C,OAAI,SAAS,MAAM,KAAK,gBAAgB,eAAe,aACrD;AAEF,QAAK,OAAO,UAAU,eAAe;IAAC;IAAQ;IAAS;IAAgB;IACvE,CACH;;CAGH,MAAM,aAAa,UAAiC;AAClD,SAAO,KAAK,QAAQ;AACpB,OAAK,MAAM,OAAO,OAAO,KAAK,KAAK,OAAO,CACxC,KAAI,UAAU,IAAI,CAAC,aAAa,SAAU,QAAO,KAAK,OAAO"}
@@ -0,0 +1,21 @@
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
+ storage: Record<string, Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>>;
9
+ writes: Record<string, Record<string, [string, string, Uint8Array]>>;
10
+ constructor(serde?: SerializerProtocol);
11
+ /** @internal */
12
+ _migratePendingSends(mutableCheckpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string): Promise<void>;
13
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
14
+ list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
15
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
16
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
17
+ deleteThread(threadId: string): Promise<void>;
18
+ }
19
+ //#endregion
20
+ export { MemorySaver };
21
+ //# sourceMappingURL=memory.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.cts","names":[],"sources":["../src/memory.ts"],"mappings":";;;;;;cAgCa,WAAA,SAAoB,mBAAA;EAE/B,OAAA,EAAS,MAAA,SAEP,MAAA,SAAe,MAAA,UAAgB,UAAA,EAAY,UAAA;EAG7C,MAAA,EAAQ,MAAA,SAAe,MAAA,0BAAgC,UAAA;EAEvD,WAAA,CAAY,KAAA,GAAQ,kBAAA;;EAKd,oBAAA,CACJ,iBAAA,EAAmB,UAAA,EACnB,QAAA,UACA,YAAA,UACA,kBAAA,WAA0B,OAAA;EA0BtB,QAAA,CAAS,MAAA,EAAQ,cAAA,GAAiB,OAAA,CAAQ,eAAA;EAyHzC,IAAA,CACL,MAAA,EAAQ,cAAA,EACR,OAAA,GAAU,qBAAA,GACT,cAAA,CAAe,eAAA;EAyHZ,GAAA,CACJ,MAAA,EAAQ,cAAA,EACR,UAAA,EAAY,UAAA,EACZ,QAAA,EAAU,kBAAA,GACT,OAAA,CAAQ,cAAA;EAsCL,SAAA,CACJ,MAAA,EAAQ,cAAA,EACR,MAAA,EAAQ,YAAA,IACR,MAAA,WACC,OAAA;EAoCG,YAAA,CAAa,QAAA,WAAmB,OAAA;AAAA"}
package/dist/memory.d.ts CHANGED
@@ -1,15 +1,21 @@
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
+ storage: Record<string, Record<string, Record<string, [Uint8Array, Uint8Array, string | undefined]>>>;
9
+ writes: Record<string, Record<string, [string, string, Uint8Array]>>;
10
+ constructor(serde?: SerializerProtocol);
11
+ /** @internal */
12
+ _migratePendingSends(mutableCheckpoint: Checkpoint, threadId: string, checkpointNs: string, parentCheckpointId: string): Promise<void>;
13
+ getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
14
+ list(config: RunnableConfig, options?: CheckpointListOptions): AsyncGenerator<CheckpointTuple>;
15
+ put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
16
+ putWrites(config: RunnableConfig, writes: PendingWrite[], taskId: string): Promise<void>;
17
+ deleteThread(threadId: string): Promise<void>;
15
18
  }
19
+ //#endregion
20
+ export { MemorySaver };
21
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","names":[],"sources":["../src/memory.ts"],"mappings":";;;;;;cAgCa,WAAA,SAAoB,mBAAA;EAE/B,OAAA,EAAS,MAAA,SAEP,MAAA,SAAe,MAAA,UAAgB,UAAA,EAAY,UAAA;EAG7C,MAAA,EAAQ,MAAA,SAAe,MAAA,0BAAgC,UAAA;EAEvD,WAAA,CAAY,KAAA,GAAQ,kBAAA;;EAKd,oBAAA,CACJ,iBAAA,EAAmB,UAAA,EACnB,QAAA,UACA,YAAA,UACA,kBAAA,WAA0B,OAAA;EA0BtB,QAAA,CAAS,MAAA,EAAQ,cAAA,GAAiB,OAAA,CAAQ,eAAA;EAyHzC,IAAA,CACL,MAAA,EAAQ,cAAA,EACR,OAAA,GAAU,qBAAA,GACT,cAAA,CAAe,eAAA;EAyHZ,GAAA,CACJ,MAAA,EAAQ,cAAA,EACR,UAAA,EAAY,UAAA,EACZ,QAAA,EAAU,kBAAA,GACT,OAAA,CAAQ,cAAA;EAsCL,SAAA,CACJ,MAAA,EAAQ,cAAA,EACR,MAAA,EAAQ,YAAA,IACR,MAAA,WACC,OAAA;EAoCG,YAAA,CAAa,QAAA,WAAmB,OAAA;AAAA"}