@langchain/langgraph-checkpoint 0.0.9 → 0.0.11

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
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.maxChannelVersion = exports.compareChannelVersions = exports.BaseCheckpointSaver = exports.copyCheckpoint = exports.emptyCheckpoint = exports.deepCopy = void 0;
3
+ exports.WRITES_IDX_MAP = exports.maxChannelVersion = exports.compareChannelVersions = exports.BaseCheckpointSaver = exports.copyCheckpoint = exports.emptyCheckpoint = exports.deepCopy = void 0;
4
4
  const id_js_1 = require("./id.cjs");
5
+ const types_js_1 = require("./serde/types.cjs");
5
6
  const jsonplus_js_1 = require("./serde/jsonplus.cjs");
6
7
  function deepCopy(obj) {
7
8
  if (typeof obj !== "object" || obj === null) {
@@ -85,3 +86,14 @@ function maxChannelVersion(...versions) {
85
86
  });
86
87
  }
87
88
  exports.maxChannelVersion = maxChannelVersion;
89
+ /**
90
+ * Mapping from error type to error index.
91
+ * Regular writes just map to their index in the list of writes being saved.
92
+ * Special writes (e.g. errors) map to negative indices, to avoid those writes from
93
+ * conflicting with regular writes.
94
+ * Each Checkpointer implementation should use this mapping in put_writes.
95
+ */
96
+ exports.WRITES_IDX_MAP = {
97
+ [types_js_1.ERROR]: -1,
98
+ [types_js_1.SCHEDULED]: -2,
99
+ };
package/dist/base.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { RunnableConfig } from "@langchain/core/runnables";
2
2
  import { SerializerProtocol } from "./serde/base.js";
3
3
  import type { PendingWrite, CheckpointPendingWrite, CheckpointMetadata } from "./types.js";
4
- import type { ChannelProtocol, SendProtocol } from "./serde/types.js";
4
+ import { type ChannelProtocol, type SendProtocol } from "./serde/types.js";
5
5
  type ChannelVersion = number | string;
6
6
  export type ChannelVersions = Record<string, ChannelVersion>;
7
7
  export interface Checkpoint<N extends string = string, C extends string = string> {
@@ -78,4 +78,12 @@ export declare abstract class BaseCheckpointSaver<V extends string | number = nu
78
78
  }
79
79
  export declare function compareChannelVersions(a: ChannelVersion, b: ChannelVersion): number;
80
80
  export declare function maxChannelVersion(...versions: ChannelVersion[]): ChannelVersion;
81
+ /**
82
+ * Mapping from error type to error index.
83
+ * Regular writes just map to their index in the list of writes being saved.
84
+ * Special writes (e.g. errors) map to negative indices, to avoid those writes from
85
+ * conflicting with regular writes.
86
+ * Each Checkpointer implementation should use this mapping in put_writes.
87
+ */
88
+ export declare const WRITES_IDX_MAP: Record<string, number>;
81
89
  export {};
package/dist/base.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { uuid6 } from "./id.js";
2
+ import { ERROR, SCHEDULED, } from "./serde/types.js";
2
3
  import { JsonPlusSerializer } from "./serde/jsonplus.js";
3
4
  export function deepCopy(obj) {
4
5
  if (typeof obj !== "object" || obj === null) {
@@ -76,3 +77,14 @@ export function maxChannelVersion(...versions) {
76
77
  return compareChannelVersions(max, version) >= 0 ? max : version;
77
78
  });
78
79
  }
80
+ /**
81
+ * Mapping from error type to error index.
82
+ * Regular writes just map to their index in the list of writes being saved.
83
+ * Special writes (e.g. errors) map to negative indices, to avoid those writes from
84
+ * conflicting with regular writes.
85
+ * Each Checkpointer implementation should use this mapping in put_writes.
86
+ */
87
+ export const WRITES_IDX_MAP = {
88
+ [ERROR]: -1,
89
+ [SCHEDULED]: -2,
90
+ };
package/dist/memory.cjs CHANGED
@@ -69,7 +69,7 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
69
69
  configurable: {
70
70
  thread_id,
71
71
  checkpoint_ns,
72
- checkpoint_id,
72
+ checkpoint_id: parentCheckpointId,
73
73
  },
74
74
  };
75
75
  }
@@ -125,13 +125,13 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
125
125
  }
126
126
  async *list(config, options) {
127
127
  // eslint-disable-next-line prefer-const
128
- let { before, limit } = options ?? {};
128
+ let { before, limit, filter } = options ?? {};
129
129
  const threadIds = config.configurable?.thread_id
130
130
  ? [config.configurable?.thread_id]
131
131
  : Object.keys(this.storage);
132
132
  const configCheckpointNamespace = config.configurable?.checkpoint_ns;
133
133
  for (const threadId of threadIds) {
134
- for (const checkpointNamespace of Object.keys(this.storage[threadId])) {
134
+ for (const checkpointNamespace of Object.keys(this.storage[threadId] ?? {})) {
135
135
  if (configCheckpointNamespace !== undefined &&
136
136
  checkpointNamespace !== configCheckpointNamespace) {
137
137
  continue;
@@ -147,6 +147,10 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
147
147
  }
148
148
  // Parse metadata
149
149
  const metadata = (await this.serde.loadsTyped("json", metadataStr));
150
+ if (filter &&
151
+ !Object.entries(filter).every(([key, value]) => metadata[key] === value)) {
152
+ continue;
153
+ }
150
154
  // Limit search results
151
155
  if (limit !== undefined) {
152
156
  if (limit <= 0)
package/dist/memory.js CHANGED
@@ -66,7 +66,7 @@ export class MemorySaver extends BaseCheckpointSaver {
66
66
  configurable: {
67
67
  thread_id,
68
68
  checkpoint_ns,
69
- checkpoint_id,
69
+ checkpoint_id: parentCheckpointId,
70
70
  },
71
71
  };
72
72
  }
@@ -122,13 +122,13 @@ export class MemorySaver extends BaseCheckpointSaver {
122
122
  }
123
123
  async *list(config, options) {
124
124
  // eslint-disable-next-line prefer-const
125
- let { before, limit } = options ?? {};
125
+ let { before, limit, filter } = options ?? {};
126
126
  const threadIds = config.configurable?.thread_id
127
127
  ? [config.configurable?.thread_id]
128
128
  : Object.keys(this.storage);
129
129
  const configCheckpointNamespace = config.configurable?.checkpoint_ns;
130
130
  for (const threadId of threadIds) {
131
- for (const checkpointNamespace of Object.keys(this.storage[threadId])) {
131
+ for (const checkpointNamespace of Object.keys(this.storage[threadId] ?? {})) {
132
132
  if (configCheckpointNamespace !== undefined &&
133
133
  checkpointNamespace !== configCheckpointNamespace) {
134
134
  continue;
@@ -144,6 +144,10 @@ export class MemorySaver extends BaseCheckpointSaver {
144
144
  }
145
145
  // Parse metadata
146
146
  const metadata = (await this.serde.loadsTyped("json", metadataStr));
147
+ if (filter &&
148
+ !Object.entries(filter).every(([key, value]) => metadata[key] === value)) {
149
+ continue;
150
+ }
147
151
  // Limit search results
148
152
  if (limit !== undefined) {
149
153
  if (limit <= 0)
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TASKS = void 0;
3
+ exports.SCHEDULED = exports.ERROR = exports.TASKS = void 0;
4
4
  exports.TASKS = "__pregel_tasks";
5
+ exports.ERROR = "__error__";
6
+ exports.SCHEDULED = "__scheduled__";
@@ -1,4 +1,6 @@
1
1
  export declare const TASKS = "__pregel_tasks";
2
+ export declare const ERROR = "__error__";
3
+ export declare const SCHEDULED = "__scheduled__";
2
4
  export interface ChannelProtocol<ValueType = unknown, UpdateType = unknown, CheckpointType = unknown> {
3
5
  ValueType: ValueType;
4
6
  UpdateType: UpdateType;
@@ -1 +1,3 @@
1
1
  export const TASKS = "__pregel_tasks";
2
+ export const ERROR = "__error__";
3
+ export const SCHEDULED = "__scheduled__";
@@ -1,7 +1,42 @@
1
1
  "use strict";
2
2
  /* eslint-disable @typescript-eslint/no-explicit-any */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.BaseStore = void 0;
4
+ exports.BaseStore = exports.InvalidNamespaceError = void 0;
5
+ /**
6
+ * Error thrown when an invalid namespace is provided.
7
+ */
8
+ class InvalidNamespaceError extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "InvalidNamespaceError";
12
+ }
13
+ }
14
+ exports.InvalidNamespaceError = InvalidNamespaceError;
15
+ /**
16
+ * Validates the provided namespace.
17
+ * @param namespace The namespace to validate.
18
+ * @throws {InvalidNamespaceError} If the namespace is invalid.
19
+ */
20
+ function validateNamespace(namespace) {
21
+ if (namespace.length === 0) {
22
+ throw new InvalidNamespaceError("Namespace cannot be empty.");
23
+ }
24
+ for (const label of namespace) {
25
+ if (typeof label !== "string") {
26
+ throw new InvalidNamespaceError(`Invalid namespace label '${label}' found in ${namespace}. Namespace labels ` +
27
+ `must be strings, but got ${typeof label}.`);
28
+ }
29
+ if (label.includes(".")) {
30
+ throw new InvalidNamespaceError(`Invalid namespace label '${label}' found in ${namespace}. Namespace labels cannot contain periods ('.').`);
31
+ }
32
+ if (label === "") {
33
+ throw new InvalidNamespaceError(`Namespace labels cannot be empty strings. Got ${label} in ${namespace}`);
34
+ }
35
+ }
36
+ if (namespace[0] === "langgraph") {
37
+ throw new InvalidNamespaceError(`Root label for namespace cannot be "langgraph". Got: ${namespace}`);
38
+ }
39
+ }
5
40
  /**
6
41
  * Abstract base class for key-value stores.
7
42
  */
@@ -44,6 +79,7 @@ class BaseStore {
44
79
  * @param value Object containing the item's data.
45
80
  */
46
81
  async put(namespace, key, value) {
82
+ validateNamespace(namespace);
47
83
  await this.batch([{ namespace, key, value }]);
48
84
  }
49
85
  /**
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Error thrown when an invalid namespace is provided.
3
+ */
4
+ export declare class InvalidNamespaceError extends Error {
5
+ constructor(message: string);
6
+ }
1
7
  /**
2
8
  * Represents a stored item with metadata.
3
9
  */
@@ -1,4 +1,38 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /**
3
+ * Error thrown when an invalid namespace is provided.
4
+ */
5
+ export class InvalidNamespaceError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "InvalidNamespaceError";
9
+ }
10
+ }
11
+ /**
12
+ * Validates the provided namespace.
13
+ * @param namespace The namespace to validate.
14
+ * @throws {InvalidNamespaceError} If the namespace is invalid.
15
+ */
16
+ function validateNamespace(namespace) {
17
+ if (namespace.length === 0) {
18
+ throw new InvalidNamespaceError("Namespace cannot be empty.");
19
+ }
20
+ for (const label of namespace) {
21
+ if (typeof label !== "string") {
22
+ throw new InvalidNamespaceError(`Invalid namespace label '${label}' found in ${namespace}. Namespace labels ` +
23
+ `must be strings, but got ${typeof label}.`);
24
+ }
25
+ if (label.includes(".")) {
26
+ throw new InvalidNamespaceError(`Invalid namespace label '${label}' found in ${namespace}. Namespace labels cannot contain periods ('.').`);
27
+ }
28
+ if (label === "") {
29
+ throw new InvalidNamespaceError(`Namespace labels cannot be empty strings. Got ${label} in ${namespace}`);
30
+ }
31
+ }
32
+ if (namespace[0] === "langgraph") {
33
+ throw new InvalidNamespaceError(`Root label for namespace cannot be "langgraph". Got: ${namespace}`);
34
+ }
35
+ }
2
36
  /**
3
37
  * Abstract base class for key-value stores.
4
38
  */
@@ -41,6 +75,7 @@ export class BaseStore {
41
75
  * @param value Object containing the item's data.
42
76
  */
43
77
  async put(namespace, key, value) {
78
+ validateNamespace(namespace);
44
79
  await this.batch([{ namespace, key, value }]);
45
80
  }
46
81
  /**
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemoryStore = void 0;
3
+ exports.MemoryStore = exports.InMemoryStore = void 0;
4
4
  const base_js_1 = require("./base.cjs");
5
- class MemoryStore extends base_js_1.BaseStore {
5
+ class InMemoryStore extends base_js_1.BaseStore {
6
6
  constructor() {
7
7
  super(...arguments);
8
8
  Object.defineProperty(this, "data", {
@@ -113,4 +113,8 @@ class MemoryStore extends base_js_1.BaseStore {
113
113
  throw new Error(`Unsupported match type: ${matchType}`);
114
114
  }
115
115
  }
116
+ exports.InMemoryStore = InMemoryStore;
117
+ /** @deprecated Alias for InMemoryStore */
118
+ class MemoryStore extends InMemoryStore {
119
+ }
116
120
  exports.MemoryStore = MemoryStore;
@@ -1,5 +1,5 @@
1
1
  import { BaseStore, type OperationResults, type Operation } from "./base.js";
2
- export declare class MemoryStore extends BaseStore {
2
+ export declare class InMemoryStore extends BaseStore {
3
3
  private data;
4
4
  batch<Op extends Operation[]>(operations: Op): Promise<OperationResults<Op>>;
5
5
  private getOperation;
@@ -8,3 +8,6 @@ export declare class MemoryStore extends BaseStore {
8
8
  private listNamespacesOperation;
9
9
  private doesMatch;
10
10
  }
11
+ /** @deprecated Alias for InMemoryStore */
12
+ export declare class MemoryStore extends InMemoryStore {
13
+ }
@@ -1,5 +1,5 @@
1
1
  import { BaseStore, } from "./base.js";
2
- export class MemoryStore extends BaseStore {
2
+ export class InMemoryStore extends BaseStore {
3
3
  constructor() {
4
4
  super(...arguments);
5
5
  Object.defineProperty(this, "data", {
@@ -110,3 +110,6 @@ export class MemoryStore extends BaseStore {
110
110
  throw new Error(`Unsupported match type: ${matchType}`);
111
111
  }
112
112
  }
113
+ /** @deprecated Alias for InMemoryStore */
114
+ export class MemoryStore extends InMemoryStore {
115
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-checkpoint",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Library with base interfaces for LangGraph checkpoint savers.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -58,7 +58,7 @@
58
58
  "jest-environment-node": "^29.6.4",
59
59
  "prettier": "^2.8.3",
60
60
  "release-it": "^17.6.0",
61
- "rollup": "^4.5.2",
61
+ "rollup": "^4.23.0",
62
62
  "ts-jest": "^29.1.0",
63
63
  "tsx": "^4.7.0",
64
64
  "typescript": "^4.9.5 || ^5.4.5"