@langchain/langgraph-checkpoint 0.0.12 → 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/base.cjs CHANGED
@@ -96,4 +96,6 @@ exports.maxChannelVersion = maxChannelVersion;
96
96
  exports.WRITES_IDX_MAP = {
97
97
  [types_js_1.ERROR]: -1,
98
98
  [types_js_1.SCHEDULED]: -2,
99
+ [types_js_1.INTERRUPT]: -3,
100
+ [types_js_1.RESUME]: -4,
99
101
  };
package/dist/base.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { uuid6 } from "./id.js";
2
- import { ERROR, SCHEDULED, } from "./serde/types.js";
2
+ import { ERROR, INTERRUPT, RESUME, SCHEDULED, } from "./serde/types.js";
3
3
  import { JsonPlusSerializer } from "./serde/jsonplus.js";
4
4
  export function deepCopy(obj) {
5
5
  if (typeof obj !== "object" || obj === null) {
@@ -87,4 +87,6 @@ export function maxChannelVersion(...versions) {
87
87
  export const WRITES_IDX_MAP = {
88
88
  [ERROR]: -1,
89
89
  [SCHEDULED]: -2,
90
+ [INTERRUPT]: -3,
91
+ [RESUME]: -4,
90
92
  };
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SCHEDULED = exports.ERROR = exports.TASKS = void 0;
3
+ exports.RESUME = exports.INTERRUPT = exports.SCHEDULED = exports.ERROR = exports.TASKS = void 0;
4
4
  exports.TASKS = "__pregel_tasks";
5
5
  exports.ERROR = "__error__";
6
6
  exports.SCHEDULED = "__scheduled__";
7
+ exports.INTERRUPT = "__interrupt__";
8
+ exports.RESUME = "__resume__";
@@ -1,6 +1,8 @@
1
1
  export declare const TASKS = "__pregel_tasks";
2
2
  export declare const ERROR = "__error__";
3
3
  export declare const SCHEDULED = "__scheduled__";
4
+ export declare const INTERRUPT = "__interrupt__";
5
+ export declare const RESUME = "__resume__";
4
6
  export interface ChannelProtocol<ValueType = unknown, UpdateType = unknown, CheckpointType = unknown> {
5
7
  ValueType: ValueType;
6
8
  UpdateType: UpdateType;
@@ -1,3 +1,5 @@
1
1
  export const TASKS = "__pregel_tasks";
2
2
  export const ERROR = "__error__";
3
3
  export const SCHEDULED = "__scheduled__";
4
+ export const INTERRUPT = "__interrupt__";
5
+ export const RESUME = "__resume__";
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
- /* eslint-disable @typescript-eslint/no-explicit-any */
3
2
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BaseStore = exports.InvalidNamespaceError = void 0;
3
+ exports.BaseStore = exports.tokenizePath = exports.getTextAtPath = exports.InvalidNamespaceError = void 0;
5
4
  /**
6
5
  * Error thrown when an invalid namespace is provided.
7
6
  */
@@ -38,69 +37,160 @@ function validateNamespace(namespace) {
38
37
  }
39
38
  }
40
39
  /**
41
- * Abstract base class for key-value stores.
40
+ * Utility function to get text at a specific JSON path
41
+ */
42
+ function getTextAtPath(obj, path) {
43
+ const parts = path.split(".");
44
+ let current = obj;
45
+ for (const part of parts) {
46
+ if (part.includes("[")) {
47
+ const [arrayName, indexStr] = part.split("[");
48
+ const index = indexStr.replace("]", "");
49
+ if (!current[arrayName])
50
+ return [];
51
+ if (index === "*") {
52
+ const results = [];
53
+ for (const item of current[arrayName]) {
54
+ if (typeof item === "string")
55
+ results.push(item);
56
+ }
57
+ return results;
58
+ }
59
+ const idx = parseInt(index, 10);
60
+ if (Number.isNaN(idx))
61
+ return [];
62
+ current = current[arrayName][idx];
63
+ }
64
+ else {
65
+ current = current[part];
66
+ }
67
+ if (current === undefined)
68
+ return [];
69
+ }
70
+ return typeof current === "string" ? [current] : [];
71
+ }
72
+ exports.getTextAtPath = getTextAtPath;
73
+ /**
74
+ * Tokenizes a JSON path into parts
75
+ */
76
+ function tokenizePath(path) {
77
+ return path.split(".");
78
+ }
79
+ exports.tokenizePath = tokenizePath;
80
+ /**
81
+ * Abstract base class for persistent key-value stores.
82
+ *
83
+ * Stores enable persistence and memory that can be shared across threads,
84
+ * scoped to user IDs, assistant IDs, or other arbitrary namespaces.
85
+ *
86
+ * Features:
87
+ * - Hierarchical namespaces for organization
88
+ * - Key-value storage with metadata
89
+ * - Vector similarity search (if configured)
90
+ * - Filtering and pagination
42
91
  */
43
92
  class BaseStore {
44
- // convenience methods
45
93
  /**
46
- * Retrieve a single item.
47
- * @param namespace Hierarchical path for the item.
48
- * @param key Unique identifier within the namespace.
49
- * @returns A promise that resolves to the retrieved item or null if not found.
94
+ * Retrieve a single item by its namespace and key.
95
+ *
96
+ * @param namespace Hierarchical path for the item
97
+ * @param key Unique identifier within the namespace
98
+ * @returns Promise resolving to the item or null if not found
50
99
  */
51
100
  async get(namespace, key) {
52
- const batchResult = await this.batch([{ namespace, key }]);
53
- return batchResult[0];
101
+ return (await this.batch([{ namespace, key }]))[0];
54
102
  }
55
103
  /**
56
104
  * Search for items within a namespace prefix.
57
- * @param namespacePrefix Hierarchical path prefix to search within.
58
- * @param options Search options.
59
- * @param options.filter Key-value pairs to filter results.
60
- * @param options.limit Maximum number of items to return (default: 10).
61
- * @param options.offset Number of items to skip before returning results (default: 0).
62
- * @returns A promise that resolves to a list of items matching the search criteria.
105
+ * Supports both metadata filtering and vector similarity search.
106
+ *
107
+ * @param namespacePrefix Hierarchical path prefix to search within
108
+ * @param options Search options for filtering and pagination
109
+ * @returns Promise resolving to list of matching items with relevance scores
110
+ *
111
+ * @example
112
+ * // Search with filters
113
+ * await store.search(["documents"], {
114
+ * filter: { type: "report", status: "active" },
115
+ * limit: 5,
116
+ * offset: 10
117
+ * });
118
+ *
119
+ * // Vector similarity search
120
+ * await store.search(["users", "content"], {
121
+ * query: "technical documentation about APIs",
122
+ * limit: 20
123
+ * });
63
124
  */
64
- async search(namespacePrefix, options) {
65
- const optionsWithDefaults = {
66
- limit: 10,
67
- offset: 0,
68
- ...(options || {}),
69
- };
70
- const batchResults = await this.batch([
71
- { namespacePrefix, ...optionsWithDefaults },
72
- ]);
73
- return batchResults[0];
125
+ async search(namespacePrefix, options = {}) {
126
+ const { filter, limit = 10, offset = 0, query } = options;
127
+ return (await this.batch([
128
+ {
129
+ namespacePrefix,
130
+ filter,
131
+ limit,
132
+ offset,
133
+ query,
134
+ },
135
+ ]))[0];
74
136
  }
75
137
  /**
76
138
  * Store or update an item.
77
- * @param namespace Hierarchical path for the item.
78
- * @param key Unique identifier within the namespace.
79
- * @param value Object containing the item's data.
139
+ *
140
+ * @param namespace Hierarchical path for the item
141
+ * @param key Unique identifier within the namespace
142
+ * @param value Object containing the item's data
143
+ * @param index Optional indexing configuration
144
+ *
145
+ * @example
146
+ * // Simple storage
147
+ * await store.put(["docs"], "report", { title: "Annual Report" });
148
+ *
149
+ * // With specific field indexing
150
+ * await store.put(
151
+ * ["docs"],
152
+ * "report",
153
+ * {
154
+ * title: "Q4 Report",
155
+ * chapters: [{ content: "..." }, { content: "..." }]
156
+ * },
157
+ * ["title", "chapters[*].content"]
158
+ * );
80
159
  */
81
- async put(namespace, key, value) {
160
+ async put(namespace, key, value, index) {
82
161
  validateNamespace(namespace);
83
- await this.batch([{ namespace, key, value }]);
162
+ await this.batch([{ namespace, key, value, index }]);
84
163
  }
85
164
  /**
86
- * Delete an item.
87
- * @param namespace Hierarchical path for the item.
88
- * @param key Unique identifier within the namespace.
165
+ * Delete an item from the store.
166
+ *
167
+ * @param namespace Hierarchical path for the item
168
+ * @param key Unique identifier within the namespace
89
169
  */
90
170
  async delete(namespace, key) {
91
171
  await this.batch([{ namespace, key, value: null }]);
92
172
  }
93
173
  /**
94
174
  * List and filter namespaces in the store.
95
- * @param options Options for listing namespaces.
96
- * @param options.prefix Filter namespaces that start with this path.
97
- * @param options.suffix Filter namespaces that end with this path.
98
- * @param options.maxDepth Return namespaces up to this depth in the hierarchy.
99
- * @param options.limit Maximum number of namespaces to return (default 100).
100
- * @param options.offset Number of namespaces to skip for pagination (default 0).
101
- * @returns A promise that resolves to a list of namespace arrays that match the criteria.
175
+ * Used to explore data organization and navigate the namespace hierarchy.
176
+ *
177
+ * @param options Options for listing namespaces
178
+ * @returns Promise resolving to list of namespace paths
179
+ *
180
+ * @example
181
+ * // List all namespaces under "documents"
182
+ * await store.listNamespaces({
183
+ * prefix: ["documents"],
184
+ * maxDepth: 2
185
+ * });
186
+ *
187
+ * // List namespaces ending with "v1"
188
+ * await store.listNamespaces({
189
+ * suffix: ["v1"],
190
+ * limit: 50
191
+ * });
102
192
  */
103
- async listNamespaces(options) {
193
+ async listNamespaces(options = {}) {
104
194
  const { prefix, suffix, maxDepth, limit = 100, offset = 0 } = options;
105
195
  const matchConditions = [];
106
196
  if (prefix) {
@@ -109,26 +199,22 @@ class BaseStore {
109
199
  if (suffix) {
110
200
  matchConditions.push({ matchType: "suffix", path: suffix });
111
201
  }
112
- const op = {
113
- matchConditions: matchConditions.length > 0 ? matchConditions : undefined,
114
- maxDepth,
115
- limit,
116
- offset,
117
- };
118
- const batchResults = await this.batch([op]);
119
- return batchResults[0];
202
+ return (await this.batch([
203
+ {
204
+ matchConditions: matchConditions.length ? matchConditions : undefined,
205
+ maxDepth,
206
+ limit,
207
+ offset,
208
+ },
209
+ ]))[0];
120
210
  }
121
211
  /**
122
- * Stop the store. No-op if not implemented.
212
+ * Start the store. Override if initialization is needed.
123
213
  */
124
- stop() {
125
- // no-op if not implemented.
126
- }
214
+ start() { }
127
215
  /**
128
- * Start the store. No-op if not implemented.
216
+ * Stop the store. Override if cleanup is needed.
129
217
  */
130
- start() {
131
- // no-op if not implemented.
132
- }
218
+ stop() { }
133
219
  }
134
220
  exports.BaseStore = BaseStore;