@langchain/langgraph-checkpoint 0.0.3 → 0.0.4

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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseCheckpointSaver = exports.copyCheckpoint = exports.emptyCheckpoint = exports.deepCopy = void 0;
3
+ exports.maxChannelVersion = exports.compareChannelVersions = exports.BaseCheckpointSaver = exports.copyCheckpoint = exports.emptyCheckpoint = exports.deepCopy = void 0;
4
4
  const id_js_1 = require("./id.cjs");
5
5
  const jsonplus_js_1 = require("./serde/jsonplus.cjs");
6
6
  function deepCopy(obj) {
@@ -63,7 +63,25 @@ class BaseCheckpointSaver {
63
63
  * as long as they are monotonically increasing.
64
64
  */
65
65
  getNextVersion(current, _channel) {
66
- return current !== undefined ? current + 1 : 1;
66
+ if (typeof current === "string") {
67
+ throw new Error("Please override this method to use string versions.");
68
+ }
69
+ return (current !== undefined && typeof current === "number" ? current + 1 : 1);
67
70
  }
68
71
  }
69
72
  exports.BaseCheckpointSaver = BaseCheckpointSaver;
73
+ function compareChannelVersions(a, b) {
74
+ if (typeof a === "number" && typeof b === "number") {
75
+ return Math.sign(a - b);
76
+ }
77
+ return String(a).localeCompare(String(b));
78
+ }
79
+ exports.compareChannelVersions = compareChannelVersions;
80
+ function maxChannelVersion(...versions) {
81
+ return versions.reduce((max, version, idx) => {
82
+ if (idx === 0)
83
+ return version;
84
+ return compareChannelVersions(max, version) >= 0 ? max : version;
85
+ });
86
+ }
87
+ exports.maxChannelVersion = maxChannelVersion;
package/dist/base.d.ts CHANGED
@@ -2,7 +2,8 @@ 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
4
  import type { ChannelProtocol, SendProtocol } from "./serde/types.js";
5
- export type ChannelVersions = Record<string, string | number>;
5
+ type ChannelVersion = number | string;
6
+ export type ChannelVersions = Record<string, ChannelVersion>;
6
7
  export interface Checkpoint<N extends string = string, C extends string = string> {
7
8
  /**
8
9
  * Version number
@@ -23,11 +24,11 @@ export interface Checkpoint<N extends string = string, C extends string = string
23
24
  /**
24
25
  * @default {}
25
26
  */
26
- channel_versions: Record<C, number>;
27
+ channel_versions: Record<C, ChannelVersion>;
27
28
  /**
28
29
  * @default {}
29
30
  */
30
- versions_seen: Record<N, Record<C, number>>;
31
+ versions_seen: Record<N, Record<C, ChannelVersion>>;
31
32
  /**
32
33
  * List of packets sent to nodes but not yet processed.
33
34
  * Cleared by the next checkpoint.
@@ -36,8 +37,8 @@ export interface Checkpoint<N extends string = string, C extends string = string
36
37
  }
37
38
  export interface ReadonlyCheckpoint extends Readonly<Checkpoint> {
38
39
  readonly channel_values: Readonly<Record<string, unknown>>;
39
- readonly channel_versions: Readonly<Record<string, number>>;
40
- readonly versions_seen: Readonly<Record<string, Readonly<Record<string, number>>>>;
40
+ readonly channel_versions: Readonly<Record<string, ChannelVersion>>;
41
+ readonly versions_seen: Readonly<Record<string, Readonly<Record<string, ChannelVersion>>>>;
41
42
  }
42
43
  export declare function deepCopy<T>(obj: T): T;
43
44
  /** @hidden */
@@ -56,7 +57,7 @@ export type CheckpointListOptions = {
56
57
  before?: RunnableConfig;
57
58
  filter?: Record<string, any>;
58
59
  };
59
- export declare abstract class BaseCheckpointSaver<V = number> {
60
+ export declare abstract class BaseCheckpointSaver<V extends string | number = number> {
60
61
  serde: SerializerProtocol;
61
62
  constructor(serde?: SerializerProtocol);
62
63
  get(config: RunnableConfig): Promise<Checkpoint | undefined>;
@@ -73,5 +74,8 @@ export declare abstract class BaseCheckpointSaver<V = number> {
73
74
  * Default is to use integer versions, incrementing by 1. If you override, you can use str/int/float versions,
74
75
  * as long as they are monotonically increasing.
75
76
  */
76
- getNextVersion(current: V | undefined, _channel: ChannelProtocol): number;
77
+ getNextVersion(current: V | undefined, _channel: ChannelProtocol): V;
77
78
  }
79
+ export declare function compareChannelVersions(a: ChannelVersion, b: ChannelVersion): number;
80
+ export declare function maxChannelVersion(...versions: ChannelVersion[]): ChannelVersion;
81
+ export {};
package/dist/base.js CHANGED
@@ -57,6 +57,22 @@ export class BaseCheckpointSaver {
57
57
  * as long as they are monotonically increasing.
58
58
  */
59
59
  getNextVersion(current, _channel) {
60
- return current !== undefined ? current + 1 : 1;
60
+ if (typeof current === "string") {
61
+ throw new Error("Please override this method to use string versions.");
62
+ }
63
+ return (current !== undefined && typeof current === "number" ? current + 1 : 1);
64
+ }
65
+ }
66
+ export function compareChannelVersions(a, b) {
67
+ if (typeof a === "number" && typeof b === "number") {
68
+ return Math.sign(a - b);
61
69
  }
70
+ return String(a).localeCompare(String(b));
71
+ }
72
+ export function maxChannelVersion(...versions) {
73
+ return versions.reduce((max, version, idx) => {
74
+ if (idx === 0)
75
+ return version;
76
+ return compareChannelVersions(max, version) >= 0 ? max : version;
77
+ });
62
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-checkpoint",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "Library with base interfaces for LangGraph checkpoint savers.",
5
5
  "type": "module",
6
6
  "engines": {