@langchain/langgraph 0.0.34 → 0.1.0-rc.1

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.
Files changed (86) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +11 -15
  3. package/dist/channels/any_value.cjs +3 -1
  4. package/dist/channels/any_value.d.ts +1 -1
  5. package/dist/channels/any_value.js +3 -1
  6. package/dist/channels/base.cjs +28 -15
  7. package/dist/channels/base.d.ts +14 -4
  8. package/dist/channels/base.js +26 -13
  9. package/dist/channels/binop.cjs +2 -1
  10. package/dist/channels/binop.d.ts +1 -1
  11. package/dist/channels/binop.js +2 -1
  12. package/dist/channels/dynamic_barrier_value.cjs +30 -18
  13. package/dist/channels/dynamic_barrier_value.d.ts +2 -1
  14. package/dist/channels/dynamic_barrier_value.js +30 -18
  15. package/dist/channels/ephemeral_value.cjs +3 -1
  16. package/dist/channels/ephemeral_value.d.ts +1 -1
  17. package/dist/channels/ephemeral_value.js +3 -1
  18. package/dist/channels/last_value.cjs +3 -2
  19. package/dist/channels/last_value.d.ts +1 -1
  20. package/dist/channels/last_value.js +3 -2
  21. package/dist/channels/named_barrier_value.cjs +14 -6
  22. package/dist/channels/named_barrier_value.d.ts +2 -1
  23. package/dist/channels/named_barrier_value.js +15 -7
  24. package/dist/channels/topic.cjs +10 -11
  25. package/dist/channels/topic.d.ts +1 -1
  26. package/dist/channels/topic.js +10 -11
  27. package/dist/checkpoint/sqlite.cjs +14 -170
  28. package/dist/checkpoint/sqlite.d.ts +1 -14
  29. package/dist/checkpoint/sqlite.js +1 -166
  30. package/dist/constants.cjs +17 -1
  31. package/dist/constants.d.ts +7 -0
  32. package/dist/constants.js +16 -0
  33. package/dist/errors.cjs +21 -1
  34. package/dist/errors.d.ts +8 -0
  35. package/dist/errors.js +18 -0
  36. package/dist/graph/graph.cjs +6 -3
  37. package/dist/graph/graph.d.ts +7 -3
  38. package/dist/graph/graph.js +7 -4
  39. package/dist/graph/index.d.ts +1 -1
  40. package/dist/graph/state.cjs +9 -8
  41. package/dist/graph/state.d.ts +1 -1
  42. package/dist/graph/state.js +9 -8
  43. package/dist/prebuilt/react_agent_executor.d.ts +1 -1
  44. package/dist/pregel/algo.cjs +391 -0
  45. package/dist/pregel/algo.d.ts +35 -0
  46. package/dist/pregel/algo.js +381 -0
  47. package/dist/pregel/debug.cjs +155 -9
  48. package/dist/pregel/debug.d.ts +40 -2
  49. package/dist/pregel/debug.js +147 -7
  50. package/dist/pregel/index.cjs +286 -512
  51. package/dist/pregel/index.d.ts +66 -65
  52. package/dist/pregel/index.js +285 -506
  53. package/dist/pregel/io.cjs +2 -2
  54. package/dist/pregel/io.d.ts +5 -4
  55. package/dist/pregel/io.js +2 -2
  56. package/dist/pregel/loop.cjs +432 -0
  57. package/dist/pregel/loop.d.ts +83 -0
  58. package/dist/pregel/loop.js +425 -0
  59. package/dist/pregel/types.d.ts +56 -4
  60. package/dist/pregel/utils.cjs +48 -0
  61. package/dist/pregel/utils.d.ts +10 -0
  62. package/dist/pregel/utils.js +41 -0
  63. package/dist/pregel/write.cjs +3 -1
  64. package/dist/pregel/write.js +3 -1
  65. package/dist/utils.cjs +21 -1
  66. package/dist/utils.d.ts +4 -0
  67. package/dist/utils.js +18 -0
  68. package/dist/web.cjs +6 -7
  69. package/dist/web.d.ts +2 -4
  70. package/dist/web.js +1 -2
  71. package/package.json +6 -12
  72. package/dist/checkpoint/base.cjs +0 -66
  73. package/dist/checkpoint/base.d.ts +0 -73
  74. package/dist/checkpoint/base.js +0 -57
  75. package/dist/checkpoint/id.cjs +0 -8
  76. package/dist/checkpoint/id.d.ts +0 -1
  77. package/dist/checkpoint/id.js +0 -4
  78. package/dist/checkpoint/index.cjs +0 -9
  79. package/dist/checkpoint/index.d.ts +0 -2
  80. package/dist/checkpoint/index.js +0 -2
  81. package/dist/checkpoint/memory.cjs +0 -82
  82. package/dist/checkpoint/memory.d.ts +0 -10
  83. package/dist/checkpoint/memory.js +0 -78
  84. package/dist/serde/base.cjs +0 -8
  85. package/dist/serde/base.d.ts +0 -12
  86. package/dist/serde/base.js +0 -5
package/dist/utils.js CHANGED
@@ -81,3 +81,21 @@ export class RunnableCallable extends Runnable {
81
81
  return returnValue;
82
82
  }
83
83
  }
84
+ export function* prefixGenerator(generator, prefix) {
85
+ if (prefix === undefined) {
86
+ yield* generator;
87
+ }
88
+ else {
89
+ for (const value of generator) {
90
+ yield [prefix, value];
91
+ }
92
+ }
93
+ }
94
+ // https://github.com/tc39/proposal-array-from-async
95
+ export async function gatherIterator(i) {
96
+ const out = [];
97
+ for await (const item of await i) {
98
+ out.push(item);
99
+ }
100
+ return out;
101
+ }
package/dist/web.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Send = exports.EmptyChannelError = exports.InvalidUpdateError = exports.GraphValueError = exports.GraphRecursionError = exports.BaseCheckpointSaver = exports.emptyCheckpoint = exports.copyCheckpoint = exports.MemorySaver = exports.Annotation = exports.messagesStateReducer = exports.MessageGraph = exports.StateGraph = exports.START = exports.Graph = exports.END = void 0;
3
+ exports.BaseCheckpointSaver = exports.emptyCheckpoint = exports.copyCheckpoint = exports.MemorySaver = exports.Send = exports.EmptyChannelError = exports.InvalidUpdateError = exports.GraphValueError = exports.GraphRecursionError = exports.Annotation = exports.messagesStateReducer = exports.MessageGraph = exports.StateGraph = exports.START = exports.Graph = exports.END = void 0;
4
4
  var index_js_1 = require("./graph/index.cjs");
5
5
  Object.defineProperty(exports, "END", { enumerable: true, get: function () { return index_js_1.END; } });
6
6
  Object.defineProperty(exports, "Graph", { enumerable: true, get: function () { return index_js_1.Graph; } });
@@ -9,12 +9,6 @@ Object.defineProperty(exports, "StateGraph", { enumerable: true, get: function (
9
9
  Object.defineProperty(exports, "MessageGraph", { enumerable: true, get: function () { return index_js_1.MessageGraph; } });
10
10
  Object.defineProperty(exports, "messagesStateReducer", { enumerable: true, get: function () { return index_js_1.messagesStateReducer; } });
11
11
  Object.defineProperty(exports, "Annotation", { enumerable: true, get: function () { return index_js_1.Annotation; } });
12
- var memory_js_1 = require("./checkpoint/memory.cjs");
13
- Object.defineProperty(exports, "MemorySaver", { enumerable: true, get: function () { return memory_js_1.MemorySaver; } });
14
- var base_js_1 = require("./checkpoint/base.cjs");
15
- Object.defineProperty(exports, "copyCheckpoint", { enumerable: true, get: function () { return base_js_1.copyCheckpoint; } });
16
- Object.defineProperty(exports, "emptyCheckpoint", { enumerable: true, get: function () { return base_js_1.emptyCheckpoint; } });
17
- Object.defineProperty(exports, "BaseCheckpointSaver", { enumerable: true, get: function () { return base_js_1.BaseCheckpointSaver; } });
18
12
  var errors_js_1 = require("./errors.cjs");
19
13
  Object.defineProperty(exports, "GraphRecursionError", { enumerable: true, get: function () { return errors_js_1.GraphRecursionError; } });
20
14
  Object.defineProperty(exports, "GraphValueError", { enumerable: true, get: function () { return errors_js_1.GraphValueError; } });
@@ -22,3 +16,8 @@ Object.defineProperty(exports, "InvalidUpdateError", { enumerable: true, get: fu
22
16
  Object.defineProperty(exports, "EmptyChannelError", { enumerable: true, get: function () { return errors_js_1.EmptyChannelError; } });
23
17
  var constants_js_1 = require("./constants.cjs");
24
18
  Object.defineProperty(exports, "Send", { enumerable: true, get: function () { return constants_js_1.Send; } });
19
+ var langgraph_checkpoint_1 = require("@langchain/langgraph-checkpoint");
20
+ Object.defineProperty(exports, "MemorySaver", { enumerable: true, get: function () { return langgraph_checkpoint_1.MemorySaver; } });
21
+ Object.defineProperty(exports, "copyCheckpoint", { enumerable: true, get: function () { return langgraph_checkpoint_1.copyCheckpoint; } });
22
+ Object.defineProperty(exports, "emptyCheckpoint", { enumerable: true, get: function () { return langgraph_checkpoint_1.emptyCheckpoint; } });
23
+ Object.defineProperty(exports, "BaseCheckpointSaver", { enumerable: true, get: function () { return langgraph_checkpoint_1.BaseCheckpointSaver; } });
package/dist/web.d.ts CHANGED
@@ -1,6 +1,4 @@
1
- export { END, Graph, type StateGraphArgs, START, StateGraph, type CompiledStateGraph, MessageGraph, messagesStateReducer, Annotation, type StateType, type UpdateType, } from "./graph/index.js";
2
- export { MemorySaver } from "./checkpoint/memory.js";
3
- export { type Checkpoint, type CheckpointMetadata, type CheckpointTuple, copyCheckpoint, emptyCheckpoint, BaseCheckpointSaver, } from "./checkpoint/base.js";
1
+ export { END, Graph, type StateGraphArgs, START, StateGraph, type CompiledStateGraph, MessageGraph, messagesStateReducer, Annotation, type StateType, type UpdateType, type CompiledGraph, } from "./graph/index.js";
4
2
  export { GraphRecursionError, GraphValueError, InvalidUpdateError, EmptyChannelError, } from "./errors.js";
5
- export { type SerializerProtocol } from "./serde/base.js";
6
3
  export { Send } from "./constants.js";
4
+ export { MemorySaver, type Checkpoint, type CheckpointMetadata, type CheckpointTuple, copyCheckpoint, emptyCheckpoint, BaseCheckpointSaver, } from "@langchain/langgraph-checkpoint";
package/dist/web.js CHANGED
@@ -1,5 +1,4 @@
1
1
  export { END, Graph, START, StateGraph, MessageGraph, messagesStateReducer, Annotation, } from "./graph/index.js";
2
- export { MemorySaver } from "./checkpoint/memory.js";
3
- export { copyCheckpoint, emptyCheckpoint, BaseCheckpointSaver, } from "./checkpoint/base.js";
4
2
  export { GraphRecursionError, GraphValueError, InvalidUpdateError, EmptyChannelError, } from "./errors.js";
5
3
  export { Send } from "./constants.js";
4
+ export { MemorySaver, copyCheckpoint, emptyCheckpoint, BaseCheckpointSaver, } from "@langchain/langgraph-checkpoint";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph",
3
- "version": "0.0.34",
3
+ "version": "0.1.0-rc.1",
4
4
  "description": "LangGraph",
5
5
  "type": "module",
6
6
  "engines": {
@@ -31,6 +31,9 @@
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
33
  "@langchain/core": ">=0.2.20 <0.3.0",
34
+ "@langchain/langgraph-checkpoint": "0.0.0",
35
+ "@langchain/langgraph-checkpoint-sqlite": "0.0.0",
36
+ "double-ended-queue": "^2.1.0-0",
34
37
  "uuid": "^10.0.0",
35
38
  "zod": "^3.23.8"
36
39
  },
@@ -39,16 +42,15 @@
39
42
  "@langchain/anthropic": "^0.2.12",
40
43
  "@langchain/community": "^0.2.25",
41
44
  "@langchain/openai": "^0.2.4",
42
- "@langchain/scripts": "^0.0.19",
45
+ "@langchain/scripts": "^0.0.22",
43
46
  "@swc/core": "^1.3.90",
44
47
  "@swc/jest": "^0.2.29",
45
48
  "@tsconfig/recommended": "^1.0.3",
46
- "@types/better-sqlite3": "^7.6.9",
49
+ "@types/double-ended-queue": "^2",
47
50
  "@types/uuid": "^10",
48
51
  "@typescript-eslint/eslint-plugin": "^6.12.0",
49
52
  "@typescript-eslint/parser": "^6.12.0",
50
53
  "@xenova/transformers": "^2.17.2",
51
- "better-sqlite3": "^9.5.0",
52
54
  "cheerio": "1.0.0-rc.12",
53
55
  "dotenv": "^16.3.1",
54
56
  "dpdm": "^3.12.0",
@@ -70,14 +72,6 @@
70
72
  "typescript": "^4.9.5 || ^5.4.5",
71
73
  "zod-to-json-schema": "^3.22.4"
72
74
  },
73
- "peerDependencies": {
74
- "better-sqlite3": "^9.5.0"
75
- },
76
- "peerDependenciesMeta": {
77
- "better-sqlite3": {
78
- "optional": true
79
- }
80
- },
81
75
  "publishConfig": {
82
76
  "access": "public",
83
77
  "registry": "https://registry.npmjs.org/"
@@ -1,66 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseCheckpointSaver = exports.copyCheckpoint = exports.emptyCheckpoint = exports.deepCopy = exports.getVersionSeen = exports.getChannelVersion = void 0;
4
- const base_js_1 = require("../serde/base.cjs");
5
- const id_js_1 = require("./id.cjs");
6
- function getChannelVersion(checkpoint, channel) {
7
- return checkpoint.channel_versions[channel] ?? 0;
8
- }
9
- exports.getChannelVersion = getChannelVersion;
10
- function getVersionSeen(checkpoint, node, channel) {
11
- return checkpoint.versions_seen[node]?.[channel] ?? 0;
12
- }
13
- exports.getVersionSeen = getVersionSeen;
14
- function deepCopy(obj) {
15
- if (typeof obj !== "object" || obj === null) {
16
- return obj;
17
- }
18
- const newObj = Array.isArray(obj) ? [] : {};
19
- for (const key in obj) {
20
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
21
- newObj[key] = deepCopy(obj[key]);
22
- }
23
- }
24
- return newObj;
25
- }
26
- exports.deepCopy = deepCopy;
27
- function emptyCheckpoint() {
28
- return {
29
- v: 1,
30
- id: (0, id_js_1.uuid6)(-2),
31
- ts: new Date().toISOString(),
32
- channel_values: {},
33
- channel_versions: {},
34
- versions_seen: {},
35
- pending_sends: [],
36
- };
37
- }
38
- exports.emptyCheckpoint = emptyCheckpoint;
39
- function copyCheckpoint(checkpoint) {
40
- return {
41
- v: checkpoint.v,
42
- id: checkpoint.id,
43
- ts: checkpoint.ts,
44
- channel_values: { ...checkpoint.channel_values },
45
- channel_versions: { ...checkpoint.channel_versions },
46
- versions_seen: deepCopy(checkpoint.versions_seen),
47
- pending_sends: [...checkpoint.pending_sends],
48
- };
49
- }
50
- exports.copyCheckpoint = copyCheckpoint;
51
- class BaseCheckpointSaver {
52
- constructor(serde) {
53
- Object.defineProperty(this, "serde", {
54
- enumerable: true,
55
- configurable: true,
56
- writable: true,
57
- value: base_js_1.DefaultSerializer
58
- });
59
- this.serde = serde || this.serde;
60
- }
61
- async get(config) {
62
- const value = await this.getTuple(config);
63
- return value ? value.checkpoint : undefined;
64
- }
65
- }
66
- exports.BaseCheckpointSaver = BaseCheckpointSaver;
@@ -1,73 +0,0 @@
1
- import { RunnableConfig } from "@langchain/core/runnables";
2
- import { SerializerProtocol } from "../serde/base.js";
3
- import { SendInterface } from "../constants.js";
4
- export interface CheckpointMetadata {
5
- source: "input" | "loop" | "update";
6
- /**
7
- * The source of the checkpoint.
8
- * - "input": The checkpoint was created from an input to invoke/stream/batch.
9
- * - "loop": The checkpoint was created from inside the pregel loop.
10
- * - "update": The checkpoint was created from a manual state update. */
11
- step: number;
12
- /**
13
- * The step number of the checkpoint.
14
- * -1 for the first "input" checkpoint.
15
- * 0 for the first "loop" checkpoint.
16
- * ... for the nth checkpoint afterwards. */
17
- writes: Record<string, unknown> | null;
18
- }
19
- export interface Checkpoint<N extends string = string, C extends string = string> {
20
- /**
21
- * Version number
22
- */
23
- v: number;
24
- /**
25
- * Checkpoint ID {uuid6}
26
- */
27
- id: string;
28
- /**
29
- * Timestamp {new Date().toISOString()}
30
- */
31
- ts: string;
32
- /**
33
- * @default {}
34
- */
35
- channel_values: Record<C, unknown>;
36
- /**
37
- * @default {}
38
- */
39
- channel_versions: Record<C, number>;
40
- /**
41
- * @default {}
42
- */
43
- versions_seen: Record<N, Record<C, number>>;
44
- /**
45
- * List of packets sent to nodes but not yet processed.
46
- * Cleared by the next checkpoint.
47
- */
48
- pending_sends: SendInterface[];
49
- }
50
- export interface ReadonlyCheckpoint extends Readonly<Checkpoint> {
51
- readonly channel_values: Readonly<Record<string, unknown>>;
52
- readonly channel_versions: Readonly<Record<string, number>>;
53
- readonly versions_seen: Readonly<Record<string, Readonly<Record<string, number>>>>;
54
- }
55
- export declare function getChannelVersion(checkpoint: ReadonlyCheckpoint, channel: string): number;
56
- export declare function getVersionSeen(checkpoint: ReadonlyCheckpoint, node: string, channel: string): number;
57
- export declare function deepCopy<T>(obj: T): T;
58
- export declare function emptyCheckpoint(): Checkpoint;
59
- export declare function copyCheckpoint(checkpoint: ReadonlyCheckpoint): Checkpoint;
60
- export interface CheckpointTuple {
61
- config: RunnableConfig;
62
- checkpoint: Checkpoint;
63
- metadata?: CheckpointMetadata;
64
- parentConfig?: RunnableConfig;
65
- }
66
- export declare abstract class BaseCheckpointSaver {
67
- serde: SerializerProtocol<unknown>;
68
- constructor(serde?: SerializerProtocol<unknown>);
69
- get(config: RunnableConfig): Promise<Checkpoint | undefined>;
70
- abstract getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
71
- abstract list(config: RunnableConfig, limit?: number, before?: RunnableConfig): AsyncGenerator<CheckpointTuple>;
72
- abstract put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
73
- }
@@ -1,57 +0,0 @@
1
- import { DefaultSerializer } from "../serde/base.js";
2
- import { uuid6 } from "./id.js";
3
- export function getChannelVersion(checkpoint, channel) {
4
- return checkpoint.channel_versions[channel] ?? 0;
5
- }
6
- export function getVersionSeen(checkpoint, node, channel) {
7
- return checkpoint.versions_seen[node]?.[channel] ?? 0;
8
- }
9
- export function deepCopy(obj) {
10
- if (typeof obj !== "object" || obj === null) {
11
- return obj;
12
- }
13
- const newObj = Array.isArray(obj) ? [] : {};
14
- for (const key in obj) {
15
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
16
- newObj[key] = deepCopy(obj[key]);
17
- }
18
- }
19
- return newObj;
20
- }
21
- export function emptyCheckpoint() {
22
- return {
23
- v: 1,
24
- id: uuid6(-2),
25
- ts: new Date().toISOString(),
26
- channel_values: {},
27
- channel_versions: {},
28
- versions_seen: {},
29
- pending_sends: [],
30
- };
31
- }
32
- export function copyCheckpoint(checkpoint) {
33
- return {
34
- v: checkpoint.v,
35
- id: checkpoint.id,
36
- ts: checkpoint.ts,
37
- channel_values: { ...checkpoint.channel_values },
38
- channel_versions: { ...checkpoint.channel_versions },
39
- versions_seen: deepCopy(checkpoint.versions_seen),
40
- pending_sends: [...checkpoint.pending_sends],
41
- };
42
- }
43
- export class BaseCheckpointSaver {
44
- constructor(serde) {
45
- Object.defineProperty(this, "serde", {
46
- enumerable: true,
47
- configurable: true,
48
- writable: true,
49
- value: DefaultSerializer
50
- });
51
- this.serde = serde || this.serde;
52
- }
53
- async get(config) {
54
- const value = await this.getTuple(config);
55
- return value ? value.checkpoint : undefined;
56
- }
57
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uuid6 = void 0;
4
- const uuid_1 = require("uuid");
5
- function uuid6(clockseq) {
6
- return (0, uuid_1.v6)({ clockseq });
7
- }
8
- exports.uuid6 = uuid6;
@@ -1 +0,0 @@
1
- export declare function uuid6(clockseq: number): string;
@@ -1,4 +0,0 @@
1
- import { v6 } from "uuid";
2
- export function uuid6(clockseq) {
3
- return v6({ clockseq });
4
- }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseCheckpointSaver = exports.emptyCheckpoint = exports.copyCheckpoint = exports.MemorySaver = void 0;
4
- var memory_js_1 = require("./memory.cjs");
5
- Object.defineProperty(exports, "MemorySaver", { enumerable: true, get: function () { return memory_js_1.MemorySaver; } });
6
- var base_js_1 = require("./base.cjs");
7
- Object.defineProperty(exports, "copyCheckpoint", { enumerable: true, get: function () { return base_js_1.copyCheckpoint; } });
8
- Object.defineProperty(exports, "emptyCheckpoint", { enumerable: true, get: function () { return base_js_1.emptyCheckpoint; } });
9
- Object.defineProperty(exports, "BaseCheckpointSaver", { enumerable: true, get: function () { return base_js_1.BaseCheckpointSaver; } });
@@ -1,2 +0,0 @@
1
- export { MemorySaver } from "./memory.js";
2
- export { type Checkpoint, type CheckpointMetadata, copyCheckpoint, emptyCheckpoint, BaseCheckpointSaver, } from "./base.js";
@@ -1,2 +0,0 @@
1
- export { MemorySaver } from "./memory.js";
2
- export { copyCheckpoint, emptyCheckpoint, BaseCheckpointSaver, } from "./base.js";
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MemorySaver = void 0;
4
- const base_js_1 = require("./base.cjs");
5
- class MemorySaver extends base_js_1.BaseCheckpointSaver {
6
- constructor(serde) {
7
- super(serde);
8
- Object.defineProperty(this, "storage", {
9
- enumerable: true,
10
- configurable: true,
11
- writable: true,
12
- value: void 0
13
- });
14
- this.storage = {};
15
- }
16
- async getTuple(config) {
17
- const thread_id = config.configurable?.thread_id;
18
- const checkpoint_id = config.configurable?.checkpoint_id;
19
- const checkpoints = this.storage[thread_id];
20
- if (checkpoint_id) {
21
- const checkpoint = checkpoints[checkpoint_id];
22
- if (checkpoint) {
23
- return {
24
- config,
25
- checkpoint: (await this.serde.parse(checkpoint[0])),
26
- metadata: (await this.serde.parse(checkpoint[1])),
27
- };
28
- }
29
- }
30
- else {
31
- if (checkpoints) {
32
- const maxThreadTs = Object.keys(checkpoints).sort((a, b) => b.localeCompare(a))[0];
33
- const checkpoint = checkpoints[maxThreadTs];
34
- return {
35
- config: { configurable: { thread_id, checkpoint_id: maxThreadTs } },
36
- checkpoint: (await this.serde.parse(checkpoint[0])),
37
- metadata: (await this.serde.parse(checkpoint[1])),
38
- };
39
- }
40
- }
41
- return undefined;
42
- }
43
- async *list(config, limit, before) {
44
- const thread_id = config.configurable?.thread_id;
45
- const checkpoints = this.storage[thread_id] ?? {};
46
- // sort in desc order
47
- for (const [checkpoint_id, checkpoint] of Object.entries(checkpoints)
48
- .filter((c) => before ? c[0] < before.configurable?.checkpoint_id : true)
49
- .sort((a, b) => b[0].localeCompare(a[0]))
50
- .slice(0, limit)) {
51
- yield {
52
- config: { configurable: { thread_id, checkpoint_id } },
53
- checkpoint: (await this.serde.parse(checkpoint[0])),
54
- metadata: (await this.serde.parse(checkpoint[1])),
55
- };
56
- }
57
- }
58
- async put(config, checkpoint, metadata) {
59
- const thread_id = config.configurable?.thread_id;
60
- if (this.storage[thread_id]) {
61
- this.storage[thread_id][checkpoint.id] = [
62
- this.serde.stringify(checkpoint),
63
- this.serde.stringify(metadata),
64
- ];
65
- }
66
- else {
67
- this.storage[thread_id] = {
68
- [checkpoint.id]: [
69
- this.serde.stringify(checkpoint),
70
- this.serde.stringify(metadata),
71
- ],
72
- };
73
- }
74
- return {
75
- configurable: {
76
- thread_id,
77
- checkpoint_id: checkpoint.id,
78
- },
79
- };
80
- }
81
- }
82
- exports.MemorySaver = MemorySaver;
@@ -1,10 +0,0 @@
1
- import { RunnableConfig } from "@langchain/core/runnables";
2
- import { BaseCheckpointSaver, Checkpoint, CheckpointMetadata, CheckpointTuple } from "./base.js";
3
- import { SerializerProtocol } from "../serde/base.js";
4
- export declare class MemorySaver extends BaseCheckpointSaver {
5
- storage: Record<string, Record<string, [string, string]>>;
6
- constructor(serde?: SerializerProtocol<unknown>);
7
- getTuple(config: RunnableConfig): Promise<CheckpointTuple | undefined>;
8
- list(config: RunnableConfig, limit?: number, before?: RunnableConfig): AsyncGenerator<CheckpointTuple>;
9
- put(config: RunnableConfig, checkpoint: Checkpoint, metadata: CheckpointMetadata): Promise<RunnableConfig>;
10
- }
@@ -1,78 +0,0 @@
1
- import { BaseCheckpointSaver, } from "./base.js";
2
- export class MemorySaver extends BaseCheckpointSaver {
3
- constructor(serde) {
4
- super(serde);
5
- Object.defineProperty(this, "storage", {
6
- enumerable: true,
7
- configurable: true,
8
- writable: true,
9
- value: void 0
10
- });
11
- this.storage = {};
12
- }
13
- async getTuple(config) {
14
- const thread_id = config.configurable?.thread_id;
15
- const checkpoint_id = config.configurable?.checkpoint_id;
16
- const checkpoints = this.storage[thread_id];
17
- if (checkpoint_id) {
18
- const checkpoint = checkpoints[checkpoint_id];
19
- if (checkpoint) {
20
- return {
21
- config,
22
- checkpoint: (await this.serde.parse(checkpoint[0])),
23
- metadata: (await this.serde.parse(checkpoint[1])),
24
- };
25
- }
26
- }
27
- else {
28
- if (checkpoints) {
29
- const maxThreadTs = Object.keys(checkpoints).sort((a, b) => b.localeCompare(a))[0];
30
- const checkpoint = checkpoints[maxThreadTs];
31
- return {
32
- config: { configurable: { thread_id, checkpoint_id: maxThreadTs } },
33
- checkpoint: (await this.serde.parse(checkpoint[0])),
34
- metadata: (await this.serde.parse(checkpoint[1])),
35
- };
36
- }
37
- }
38
- return undefined;
39
- }
40
- async *list(config, limit, before) {
41
- const thread_id = config.configurable?.thread_id;
42
- const checkpoints = this.storage[thread_id] ?? {};
43
- // sort in desc order
44
- for (const [checkpoint_id, checkpoint] of Object.entries(checkpoints)
45
- .filter((c) => before ? c[0] < before.configurable?.checkpoint_id : true)
46
- .sort((a, b) => b[0].localeCompare(a[0]))
47
- .slice(0, limit)) {
48
- yield {
49
- config: { configurable: { thread_id, checkpoint_id } },
50
- checkpoint: (await this.serde.parse(checkpoint[0])),
51
- metadata: (await this.serde.parse(checkpoint[1])),
52
- };
53
- }
54
- }
55
- async put(config, checkpoint, metadata) {
56
- const thread_id = config.configurable?.thread_id;
57
- if (this.storage[thread_id]) {
58
- this.storage[thread_id][checkpoint.id] = [
59
- this.serde.stringify(checkpoint),
60
- this.serde.stringify(metadata),
61
- ];
62
- }
63
- else {
64
- this.storage[thread_id] = {
65
- [checkpoint.id]: [
66
- this.serde.stringify(checkpoint),
67
- this.serde.stringify(metadata),
68
- ],
69
- };
70
- }
71
- return {
72
- configurable: {
73
- thread_id,
74
- checkpoint_id: checkpoint.id,
75
- },
76
- };
77
- }
78
- }
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultSerializer = void 0;
4
- const load_1 = require("@langchain/core/load");
5
- exports.DefaultSerializer = {
6
- stringify: JSON.stringify,
7
- parse: load_1.load,
8
- };
@@ -1,12 +0,0 @@
1
- import { load } from "@langchain/core/load";
2
- export interface SerializerProtocol<D> {
3
- stringify(obj: D): string;
4
- parse(data: string): Promise<D>;
5
- }
6
- export declare const DefaultSerializer: {
7
- stringify: {
8
- (value: any, replacer?: ((this: any, key: string, value: any) => any) | undefined, space?: string | number | undefined): string;
9
- (value: any, replacer?: (string | number)[] | null | undefined, space?: string | number | undefined): string;
10
- };
11
- parse: typeof load;
12
- };
@@ -1,5 +0,0 @@
1
- import { load } from "@langchain/core/load";
2
- export const DefaultSerializer = {
3
- stringify: JSON.stringify,
4
- parse: load,
5
- };