@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 +2 -0
- package/dist/base.js +3 -1
- package/dist/serde/types.cjs +3 -1
- package/dist/serde/types.d.ts +2 -0
- package/dist/serde/types.js +2 -0
- package/dist/store/base.cjs +144 -58
- package/dist/store/base.d.ts +262 -54
- package/dist/store/base.js +141 -57
- package/dist/store/memory.cjs +273 -28
- package/dist/store/memory.d.ts +48 -3
- package/dist/store/memory.js +273 -28
- package/dist/store/utils.cjs +261 -0
- package/dist/store/utils.d.ts +26 -0
- package/dist/store/utils.js +254 -0
- package/dist/types.d.ts +2 -1
- package/package.json +2 -2
package/dist/base.cjs
CHANGED
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
|
};
|
package/dist/serde/types.cjs
CHANGED
|
@@ -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__";
|
package/dist/serde/types.d.ts
CHANGED
|
@@ -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;
|
package/dist/serde/types.js
CHANGED
package/dist/store/base.cjs
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
*
|
|
48
|
-
* @param
|
|
49
|
-
* @
|
|
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
|
-
|
|
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
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* @param
|
|
60
|
-
* @param options
|
|
61
|
-
* @
|
|
62
|
-
*
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
*
|
|
78
|
-
* @param
|
|
79
|
-
* @param
|
|
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
|
-
*
|
|
88
|
-
* @param
|
|
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
|
-
*
|
|
96
|
-
*
|
|
97
|
-
* @param options
|
|
98
|
-
* @
|
|
99
|
-
*
|
|
100
|
-
* @
|
|
101
|
-
*
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
*
|
|
212
|
+
* Start the store. Override if initialization is needed.
|
|
123
213
|
*/
|
|
124
|
-
|
|
125
|
-
// no-op if not implemented.
|
|
126
|
-
}
|
|
214
|
+
start() { }
|
|
127
215
|
/**
|
|
128
|
-
*
|
|
216
|
+
* Stop the store. Override if cleanup is needed.
|
|
129
217
|
*/
|
|
130
|
-
|
|
131
|
-
// no-op if not implemented.
|
|
132
|
-
}
|
|
218
|
+
stop() { }
|
|
133
219
|
}
|
|
134
220
|
exports.BaseStore = BaseStore;
|