@langchain/langgraph-checkpoint 0.0.6 → 0.0.8-rc.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.
@@ -0,0 +1,222 @@
1
+ "use strict";
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.stringify = void 0;
6
+ // Stringify that can handle circular references.
7
+ // Inlined due to ESM import issues
8
+ // Source: https://www.npmjs.com/package/fast-safe-stringify
9
+ var LIMIT_REPLACE_NODE = "[...]";
10
+ var CIRCULAR_REPLACE_NODE = "[Circular]";
11
+ var arr = [];
12
+ var replacerStack = [];
13
+ function defaultOptions() {
14
+ return {
15
+ depthLimit: Number.MAX_SAFE_INTEGER,
16
+ edgesLimit: Number.MAX_SAFE_INTEGER,
17
+ };
18
+ }
19
+ // Regular stringify
20
+ function stringify(obj, replacer, spacer, options) {
21
+ if (typeof options === "undefined") {
22
+ options = defaultOptions();
23
+ }
24
+ decirc(obj, "", 0, [], undefined, 0, options);
25
+ var res;
26
+ try {
27
+ if (replacerStack.length === 0) {
28
+ res = JSON.stringify(obj, replacer, spacer);
29
+ }
30
+ else {
31
+ res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
32
+ }
33
+ }
34
+ catch (_) {
35
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
36
+ }
37
+ finally {
38
+ while (arr.length !== 0) {
39
+ var part = arr.pop();
40
+ if (part.length === 4) {
41
+ Object.defineProperty(part[0], part[1], part[3]);
42
+ }
43
+ else {
44
+ part[0][part[1]] = part[2];
45
+ }
46
+ }
47
+ }
48
+ return res;
49
+ }
50
+ exports.stringify = stringify;
51
+ function setReplace(replace, val, k, parent) {
52
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
53
+ if (propertyDescriptor.get !== undefined) {
54
+ if (propertyDescriptor.configurable) {
55
+ Object.defineProperty(parent, k, { value: replace });
56
+ arr.push([parent, k, val, propertyDescriptor]);
57
+ }
58
+ else {
59
+ replacerStack.push([val, k, replace]);
60
+ }
61
+ }
62
+ else {
63
+ parent[k] = replace;
64
+ arr.push([parent, k, val]);
65
+ }
66
+ }
67
+ function decirc(val, k, edgeIndex, stack, parent, depth, options) {
68
+ depth += 1;
69
+ var i;
70
+ if (typeof val === "object" && val !== null) {
71
+ for (i = 0; i < stack.length; i++) {
72
+ if (stack[i] === val) {
73
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
74
+ return;
75
+ }
76
+ }
77
+ if (typeof options.depthLimit !== "undefined" &&
78
+ depth > options.depthLimit) {
79
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
80
+ return;
81
+ }
82
+ if (typeof options.edgesLimit !== "undefined" &&
83
+ edgeIndex + 1 > options.edgesLimit) {
84
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
85
+ return;
86
+ }
87
+ stack.push(val);
88
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
89
+ if (Array.isArray(val)) {
90
+ for (i = 0; i < val.length; i++) {
91
+ decirc(val[i], i, i, stack, val, depth, options);
92
+ }
93
+ }
94
+ else {
95
+ var keys = Object.keys(val);
96
+ for (i = 0; i < keys.length; i++) {
97
+ var key = keys[i];
98
+ decirc(val[key], key, i, stack, val, depth, options);
99
+ }
100
+ }
101
+ stack.pop();
102
+ }
103
+ }
104
+ // Stable-stringify
105
+ function compareFunction(a, b) {
106
+ if (a < b) {
107
+ return -1;
108
+ }
109
+ if (a > b) {
110
+ return 1;
111
+ }
112
+ return 0;
113
+ }
114
+ function deterministicStringify(obj, replacer, spacer, options) {
115
+ if (typeof options === "undefined") {
116
+ options = defaultOptions();
117
+ }
118
+ var tmp = deterministicDecirc(obj, "", 0, [], undefined, 0, options) || obj;
119
+ var res;
120
+ try {
121
+ if (replacerStack.length === 0) {
122
+ res = JSON.stringify(tmp, replacer, spacer);
123
+ }
124
+ else {
125
+ res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
126
+ }
127
+ }
128
+ catch (_) {
129
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
130
+ }
131
+ finally {
132
+ // Ensure that we restore the object as it was.
133
+ while (arr.length !== 0) {
134
+ var part = arr.pop();
135
+ if (part.length === 4) {
136
+ Object.defineProperty(part[0], part[1], part[3]);
137
+ }
138
+ else {
139
+ part[0][part[1]] = part[2];
140
+ }
141
+ }
142
+ }
143
+ return res;
144
+ }
145
+ function deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {
146
+ depth += 1;
147
+ var i;
148
+ if (typeof val === "object" && val !== null) {
149
+ for (i = 0; i < stack.length; i++) {
150
+ if (stack[i] === val) {
151
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
152
+ return;
153
+ }
154
+ }
155
+ try {
156
+ if (typeof val.toJSON === "function") {
157
+ return;
158
+ }
159
+ }
160
+ catch (_) {
161
+ return;
162
+ }
163
+ if (typeof options.depthLimit !== "undefined" &&
164
+ depth > options.depthLimit) {
165
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
166
+ return;
167
+ }
168
+ if (typeof options.edgesLimit !== "undefined" &&
169
+ edgeIndex + 1 > options.edgesLimit) {
170
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
171
+ return;
172
+ }
173
+ stack.push(val);
174
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
175
+ if (Array.isArray(val)) {
176
+ for (i = 0; i < val.length; i++) {
177
+ deterministicDecirc(val[i], i, i, stack, val, depth, options);
178
+ }
179
+ }
180
+ else {
181
+ // Create a temporary object in the required way
182
+ var tmp = {};
183
+ var keys = Object.keys(val).sort(compareFunction);
184
+ for (i = 0; i < keys.length; i++) {
185
+ var key = keys[i];
186
+ deterministicDecirc(val[key], key, i, stack, val, depth, options);
187
+ tmp[key] = val[key];
188
+ }
189
+ if (typeof parent !== "undefined") {
190
+ arr.push([parent, k, val]);
191
+ parent[k] = tmp;
192
+ }
193
+ else {
194
+ return tmp;
195
+ }
196
+ }
197
+ stack.pop();
198
+ }
199
+ }
200
+ // wraps replacer function to handle values we couldn't replace
201
+ // and mark them as replaced value
202
+ function replaceGetterValues(replacer) {
203
+ replacer =
204
+ typeof replacer !== "undefined"
205
+ ? replacer
206
+ : function (k, v) {
207
+ return v;
208
+ };
209
+ return function (key, val) {
210
+ if (replacerStack.length > 0) {
211
+ for (var i = 0; i < replacerStack.length; i++) {
212
+ var part = replacerStack[i];
213
+ if (part[1] === key && part[0] === val) {
214
+ val = part[2];
215
+ replacerStack.splice(i, 1);
216
+ break;
217
+ }
218
+ }
219
+ }
220
+ return replacer.call(this, key, val);
221
+ };
222
+ }
@@ -0,0 +1 @@
1
+ export declare function stringify(obj: any, replacer?: any, spacer?: any, options?: any): string;
@@ -0,0 +1,218 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ // Stringify that can handle circular references.
4
+ // Inlined due to ESM import issues
5
+ // Source: https://www.npmjs.com/package/fast-safe-stringify
6
+ var LIMIT_REPLACE_NODE = "[...]";
7
+ var CIRCULAR_REPLACE_NODE = "[Circular]";
8
+ var arr = [];
9
+ var replacerStack = [];
10
+ function defaultOptions() {
11
+ return {
12
+ depthLimit: Number.MAX_SAFE_INTEGER,
13
+ edgesLimit: Number.MAX_SAFE_INTEGER,
14
+ };
15
+ }
16
+ // Regular stringify
17
+ export function stringify(obj, replacer, spacer, options) {
18
+ if (typeof options === "undefined") {
19
+ options = defaultOptions();
20
+ }
21
+ decirc(obj, "", 0, [], undefined, 0, options);
22
+ var res;
23
+ try {
24
+ if (replacerStack.length === 0) {
25
+ res = JSON.stringify(obj, replacer, spacer);
26
+ }
27
+ else {
28
+ res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
29
+ }
30
+ }
31
+ catch (_) {
32
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
33
+ }
34
+ finally {
35
+ while (arr.length !== 0) {
36
+ var part = arr.pop();
37
+ if (part.length === 4) {
38
+ Object.defineProperty(part[0], part[1], part[3]);
39
+ }
40
+ else {
41
+ part[0][part[1]] = part[2];
42
+ }
43
+ }
44
+ }
45
+ return res;
46
+ }
47
+ function setReplace(replace, val, k, parent) {
48
+ var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
49
+ if (propertyDescriptor.get !== undefined) {
50
+ if (propertyDescriptor.configurable) {
51
+ Object.defineProperty(parent, k, { value: replace });
52
+ arr.push([parent, k, val, propertyDescriptor]);
53
+ }
54
+ else {
55
+ replacerStack.push([val, k, replace]);
56
+ }
57
+ }
58
+ else {
59
+ parent[k] = replace;
60
+ arr.push([parent, k, val]);
61
+ }
62
+ }
63
+ function decirc(val, k, edgeIndex, stack, parent, depth, options) {
64
+ depth += 1;
65
+ var i;
66
+ if (typeof val === "object" && val !== null) {
67
+ for (i = 0; i < stack.length; i++) {
68
+ if (stack[i] === val) {
69
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
70
+ return;
71
+ }
72
+ }
73
+ if (typeof options.depthLimit !== "undefined" &&
74
+ depth > options.depthLimit) {
75
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
76
+ return;
77
+ }
78
+ if (typeof options.edgesLimit !== "undefined" &&
79
+ edgeIndex + 1 > options.edgesLimit) {
80
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
81
+ return;
82
+ }
83
+ stack.push(val);
84
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
85
+ if (Array.isArray(val)) {
86
+ for (i = 0; i < val.length; i++) {
87
+ decirc(val[i], i, i, stack, val, depth, options);
88
+ }
89
+ }
90
+ else {
91
+ var keys = Object.keys(val);
92
+ for (i = 0; i < keys.length; i++) {
93
+ var key = keys[i];
94
+ decirc(val[key], key, i, stack, val, depth, options);
95
+ }
96
+ }
97
+ stack.pop();
98
+ }
99
+ }
100
+ // Stable-stringify
101
+ function compareFunction(a, b) {
102
+ if (a < b) {
103
+ return -1;
104
+ }
105
+ if (a > b) {
106
+ return 1;
107
+ }
108
+ return 0;
109
+ }
110
+ function deterministicStringify(obj, replacer, spacer, options) {
111
+ if (typeof options === "undefined") {
112
+ options = defaultOptions();
113
+ }
114
+ var tmp = deterministicDecirc(obj, "", 0, [], undefined, 0, options) || obj;
115
+ var res;
116
+ try {
117
+ if (replacerStack.length === 0) {
118
+ res = JSON.stringify(tmp, replacer, spacer);
119
+ }
120
+ else {
121
+ res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
122
+ }
123
+ }
124
+ catch (_) {
125
+ return JSON.stringify("[unable to serialize, circular reference is too complex to analyze]");
126
+ }
127
+ finally {
128
+ // Ensure that we restore the object as it was.
129
+ while (arr.length !== 0) {
130
+ var part = arr.pop();
131
+ if (part.length === 4) {
132
+ Object.defineProperty(part[0], part[1], part[3]);
133
+ }
134
+ else {
135
+ part[0][part[1]] = part[2];
136
+ }
137
+ }
138
+ }
139
+ return res;
140
+ }
141
+ function deterministicDecirc(val, k, edgeIndex, stack, parent, depth, options) {
142
+ depth += 1;
143
+ var i;
144
+ if (typeof val === "object" && val !== null) {
145
+ for (i = 0; i < stack.length; i++) {
146
+ if (stack[i] === val) {
147
+ setReplace(CIRCULAR_REPLACE_NODE, val, k, parent);
148
+ return;
149
+ }
150
+ }
151
+ try {
152
+ if (typeof val.toJSON === "function") {
153
+ return;
154
+ }
155
+ }
156
+ catch (_) {
157
+ return;
158
+ }
159
+ if (typeof options.depthLimit !== "undefined" &&
160
+ depth > options.depthLimit) {
161
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
162
+ return;
163
+ }
164
+ if (typeof options.edgesLimit !== "undefined" &&
165
+ edgeIndex + 1 > options.edgesLimit) {
166
+ setReplace(LIMIT_REPLACE_NODE, val, k, parent);
167
+ return;
168
+ }
169
+ stack.push(val);
170
+ // Optimize for Arrays. Big arrays could kill the performance otherwise!
171
+ if (Array.isArray(val)) {
172
+ for (i = 0; i < val.length; i++) {
173
+ deterministicDecirc(val[i], i, i, stack, val, depth, options);
174
+ }
175
+ }
176
+ else {
177
+ // Create a temporary object in the required way
178
+ var tmp = {};
179
+ var keys = Object.keys(val).sort(compareFunction);
180
+ for (i = 0; i < keys.length; i++) {
181
+ var key = keys[i];
182
+ deterministicDecirc(val[key], key, i, stack, val, depth, options);
183
+ tmp[key] = val[key];
184
+ }
185
+ if (typeof parent !== "undefined") {
186
+ arr.push([parent, k, val]);
187
+ parent[k] = tmp;
188
+ }
189
+ else {
190
+ return tmp;
191
+ }
192
+ }
193
+ stack.pop();
194
+ }
195
+ }
196
+ // wraps replacer function to handle values we couldn't replace
197
+ // and mark them as replaced value
198
+ function replaceGetterValues(replacer) {
199
+ replacer =
200
+ typeof replacer !== "undefined"
201
+ ? replacer
202
+ : function (k, v) {
203
+ return v;
204
+ };
205
+ return function (key, val) {
206
+ if (replacerStack.length > 0) {
207
+ for (var i = 0; i < replacerStack.length; i++) {
208
+ var part = replacerStack[i];
209
+ if (part[1] === key && part[0] === val) {
210
+ val = part[2];
211
+ replacerStack.splice(i, 1);
212
+ break;
213
+ }
214
+ }
215
+ }
216
+ return replacer.call(this, key, val);
217
+ };
218
+ }
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.BaseStore = void 0;
5
+ /**
6
+ * Abstract base class for key-value stores.
7
+ */
8
+ class BaseStore {
9
+ // convenience methods
10
+ /**
11
+ * Retrieve a single item.
12
+ * @param namespace Hierarchical path for the item.
13
+ * @param id Unique identifier within the namespace.
14
+ * @returns A promise that resolves to the retrieved item or null if not found.
15
+ */
16
+ async get(namespace, id) {
17
+ const batchResult = await this.batch([{ namespace, id }]);
18
+ return batchResult[0];
19
+ }
20
+ /**
21
+ * Search for items within a namespace prefix.
22
+ * @param namespacePrefix Hierarchical path prefix to search within.
23
+ * @param options Search options.
24
+ * @param options.filter Key-value pairs to filter results.
25
+ * @param options.limit Maximum number of items to return (default: 10).
26
+ * @param options.offset Number of items to skip before returning results (default: 0).
27
+ * @returns A promise that resolves to a list of items matching the search criteria.
28
+ */
29
+ async search(namespacePrefix, options) {
30
+ const optionsWithDefaults = {
31
+ limit: 10,
32
+ offset: 0,
33
+ ...(options || {}),
34
+ };
35
+ const batchResults = await this.batch([
36
+ { namespacePrefix, ...optionsWithDefaults },
37
+ ]);
38
+ return batchResults[0];
39
+ }
40
+ /**
41
+ * Store or update an item.
42
+ * @param namespace Hierarchical path for the item.
43
+ * @param id Unique identifier within the namespace.
44
+ * @param value Object containing the item's data.
45
+ */
46
+ async put(namespace, id, value) {
47
+ await this.batch([{ namespace, id, value }]);
48
+ }
49
+ /**
50
+ * Delete an item.
51
+ * @param namespace Hierarchical path for the item.
52
+ * @param id Unique identifier within the namespace.
53
+ */
54
+ async delete(namespace, id) {
55
+ await this.batch([{ namespace, id, value: null }]);
56
+ }
57
+ /**
58
+ * List and filter namespaces in the store.
59
+ * @param options Options for listing namespaces.
60
+ * @param options.prefix Filter namespaces that start with this path.
61
+ * @param options.suffix Filter namespaces that end with this path.
62
+ * @param options.maxDepth Return namespaces up to this depth in the hierarchy.
63
+ * @param options.limit Maximum number of namespaces to return (default 100).
64
+ * @param options.offset Number of namespaces to skip for pagination (default 0).
65
+ * @returns A promise that resolves to a list of namespace arrays that match the criteria.
66
+ */
67
+ async listNamespaces(options) {
68
+ const { prefix, suffix, maxDepth, limit = 100, offset = 0 } = options;
69
+ const matchConditions = [];
70
+ if (prefix) {
71
+ matchConditions.push({ matchType: "prefix", path: prefix });
72
+ }
73
+ if (suffix) {
74
+ matchConditions.push({ matchType: "suffix", path: suffix });
75
+ }
76
+ const op = {
77
+ matchConditions: matchConditions.length > 0 ? matchConditions : undefined,
78
+ maxDepth,
79
+ limit,
80
+ offset,
81
+ };
82
+ const batchResults = await this.batch([op]);
83
+ return batchResults[0];
84
+ }
85
+ /**
86
+ * Stop the store. No-op if not implemented.
87
+ */
88
+ stop() {
89
+ // no-op if not implemented.
90
+ }
91
+ /**
92
+ * Start the store. No-op if not implemented.
93
+ */
94
+ start() {
95
+ // no-op if not implemented.
96
+ }
97
+ }
98
+ exports.BaseStore = BaseStore;