@langchain/langgraph-checkpoint 0.0.1 → 0.0.3

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/README.md CHANGED
@@ -81,7 +81,6 @@ const checkpoint = {
81
81
  }
82
82
  },
83
83
  pending_sends: [],
84
- current_tasks: {}
85
84
  }
86
85
 
87
86
  // store checkpoint
package/dist/base.cjs CHANGED
@@ -16,6 +16,7 @@ function deepCopy(obj) {
16
16
  return newObj;
17
17
  }
18
18
  exports.deepCopy = deepCopy;
19
+ /** @hidden */
19
20
  function emptyCheckpoint() {
20
21
  return {
21
22
  v: 1,
@@ -28,6 +29,7 @@ function emptyCheckpoint() {
28
29
  };
29
30
  }
30
31
  exports.emptyCheckpoint = emptyCheckpoint;
32
+ /** @hidden */
31
33
  function copyCheckpoint(checkpoint) {
32
34
  return {
33
35
  v: checkpoint.v,
package/dist/base.d.ts CHANGED
@@ -40,7 +40,9 @@ export interface ReadonlyCheckpoint extends Readonly<Checkpoint> {
40
40
  readonly versions_seen: Readonly<Record<string, Readonly<Record<string, number>>>>;
41
41
  }
42
42
  export declare function deepCopy<T>(obj: T): T;
43
+ /** @hidden */
43
44
  export declare function emptyCheckpoint(): Checkpoint;
45
+ /** @hidden */
44
46
  export declare function copyCheckpoint(checkpoint: ReadonlyCheckpoint): Checkpoint;
45
47
  export interface CheckpointTuple {
46
48
  config: RunnableConfig;
package/dist/base.js CHANGED
@@ -12,6 +12,7 @@ export function deepCopy(obj) {
12
12
  }
13
13
  return newObj;
14
14
  }
15
+ /** @hidden */
15
16
  export function emptyCheckpoint() {
16
17
  return {
17
18
  v: 1,
@@ -23,6 +24,7 @@ export function emptyCheckpoint() {
23
24
  pending_sends: [],
24
25
  };
25
26
  }
27
+ /** @hidden */
26
28
  export function copyCheckpoint(checkpoint) {
27
29
  return {
28
30
  v: checkpoint.v,
package/dist/memory.cjs CHANGED
@@ -39,22 +39,22 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
39
39
  await this.serde.loadsTyped("json", value),
40
40
  ];
41
41
  }));
42
- const parentConfig = parentCheckpointId !== undefined
43
- ? {
44
- configurable: {
45
- thread_id,
46
- checkpoint_ns,
47
- checkpoint_id,
48
- },
49
- }
50
- : undefined;
51
- return {
42
+ const checkpointTuple = {
52
43
  config,
53
44
  checkpoint: (await this.serde.loadsTyped("json", checkpoint)),
54
45
  metadata: (await this.serde.loadsTyped("json", metadata)),
55
46
  pendingWrites,
56
- parentConfig,
57
47
  };
48
+ if (parentCheckpointId !== undefined) {
49
+ checkpointTuple.parentConfig = {
50
+ configurable: {
51
+ thread_id,
52
+ checkpoint_ns,
53
+ checkpoint_id,
54
+ },
55
+ };
56
+ }
57
+ return checkpointTuple;
58
58
  }
59
59
  }
60
60
  else {
@@ -73,16 +73,7 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
73
73
  await this.serde.loadsTyped("json", value),
74
74
  ];
75
75
  }));
76
- const parentConfig = parentCheckpointId !== undefined
77
- ? {
78
- configurable: {
79
- thread_id,
80
- checkpoint_ns,
81
- checkpoint_id: parentCheckpointId,
82
- },
83
- }
84
- : undefined;
85
- return {
76
+ const checkpointTuple = {
86
77
  config: {
87
78
  configurable: {
88
79
  thread_id,
@@ -93,8 +84,17 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
93
84
  checkpoint: (await this.serde.loadsTyped("json", checkpoint)),
94
85
  metadata: (await this.serde.loadsTyped("json", metadata)),
95
86
  pendingWrites,
96
- parentConfig,
97
87
  };
88
+ if (parentCheckpointId !== undefined) {
89
+ checkpointTuple.parentConfig = {
90
+ configurable: {
91
+ thread_id,
92
+ checkpoint_ns,
93
+ checkpoint_id: parentCheckpointId,
94
+ },
95
+ };
96
+ }
97
+ return checkpointTuple;
98
98
  }
99
99
  }
100
100
  return undefined;
@@ -133,7 +133,7 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
133
133
  await this.serde.loadsTyped("json", value),
134
134
  ];
135
135
  }));
136
- yield {
136
+ const checkpointTuple = {
137
137
  config: {
138
138
  configurable: {
139
139
  thread_id: threadId,
@@ -144,16 +144,17 @@ class MemorySaver extends base_js_1.BaseCheckpointSaver {
144
144
  checkpoint: (await this.serde.loadsTyped("json", checkpoint)),
145
145
  metadata,
146
146
  pendingWrites,
147
- parentConfig: parentCheckpointId
148
- ? {
149
- configurable: {
150
- thread_id: threadId,
151
- checkpoint_ns: checkpointNamespace,
152
- checkpoint_id: parentCheckpointId,
153
- },
154
- }
155
- : undefined,
156
147
  };
148
+ if (parentCheckpointId !== undefined) {
149
+ checkpointTuple.parentConfig = {
150
+ configurable: {
151
+ thread_id: threadId,
152
+ checkpoint_ns: checkpointNamespace,
153
+ checkpoint_id: parentCheckpointId,
154
+ },
155
+ };
156
+ }
157
+ yield checkpointTuple;
157
158
  }
158
159
  }
159
160
  }
package/dist/memory.js CHANGED
@@ -36,22 +36,22 @@ export class MemorySaver extends BaseCheckpointSaver {
36
36
  await this.serde.loadsTyped("json", value),
37
37
  ];
38
38
  }));
39
- const parentConfig = parentCheckpointId !== undefined
40
- ? {
41
- configurable: {
42
- thread_id,
43
- checkpoint_ns,
44
- checkpoint_id,
45
- },
46
- }
47
- : undefined;
48
- return {
39
+ const checkpointTuple = {
49
40
  config,
50
41
  checkpoint: (await this.serde.loadsTyped("json", checkpoint)),
51
42
  metadata: (await this.serde.loadsTyped("json", metadata)),
52
43
  pendingWrites,
53
- parentConfig,
54
44
  };
45
+ if (parentCheckpointId !== undefined) {
46
+ checkpointTuple.parentConfig = {
47
+ configurable: {
48
+ thread_id,
49
+ checkpoint_ns,
50
+ checkpoint_id,
51
+ },
52
+ };
53
+ }
54
+ return checkpointTuple;
55
55
  }
56
56
  }
57
57
  else {
@@ -70,16 +70,7 @@ export class MemorySaver extends BaseCheckpointSaver {
70
70
  await this.serde.loadsTyped("json", value),
71
71
  ];
72
72
  }));
73
- const parentConfig = parentCheckpointId !== undefined
74
- ? {
75
- configurable: {
76
- thread_id,
77
- checkpoint_ns,
78
- checkpoint_id: parentCheckpointId,
79
- },
80
- }
81
- : undefined;
82
- return {
73
+ const checkpointTuple = {
83
74
  config: {
84
75
  configurable: {
85
76
  thread_id,
@@ -90,8 +81,17 @@ export class MemorySaver extends BaseCheckpointSaver {
90
81
  checkpoint: (await this.serde.loadsTyped("json", checkpoint)),
91
82
  metadata: (await this.serde.loadsTyped("json", metadata)),
92
83
  pendingWrites,
93
- parentConfig,
94
84
  };
85
+ if (parentCheckpointId !== undefined) {
86
+ checkpointTuple.parentConfig = {
87
+ configurable: {
88
+ thread_id,
89
+ checkpoint_ns,
90
+ checkpoint_id: parentCheckpointId,
91
+ },
92
+ };
93
+ }
94
+ return checkpointTuple;
95
95
  }
96
96
  }
97
97
  return undefined;
@@ -130,7 +130,7 @@ export class MemorySaver extends BaseCheckpointSaver {
130
130
  await this.serde.loadsTyped("json", value),
131
131
  ];
132
132
  }));
133
- yield {
133
+ const checkpointTuple = {
134
134
  config: {
135
135
  configurable: {
136
136
  thread_id: threadId,
@@ -141,16 +141,17 @@ export class MemorySaver extends BaseCheckpointSaver {
141
141
  checkpoint: (await this.serde.loadsTyped("json", checkpoint)),
142
142
  metadata,
143
143
  pendingWrites,
144
- parentConfig: parentCheckpointId
145
- ? {
146
- configurable: {
147
- thread_id: threadId,
148
- checkpoint_ns: checkpointNamespace,
149
- checkpoint_id: parentCheckpointId,
150
- },
151
- }
152
- : undefined,
153
144
  };
145
+ if (parentCheckpointId !== undefined) {
146
+ checkpointTuple.parentConfig = {
147
+ configurable: {
148
+ thread_id: threadId,
149
+ checkpoint_ns: checkpointNamespace,
150
+ checkpoint_id: parentCheckpointId,
151
+ },
152
+ };
153
+ }
154
+ yield checkpointTuple;
154
155
  }
155
156
  }
156
157
  }
@@ -4,9 +4,58 @@ exports.JsonPlusSerializer = void 0;
4
4
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
5
  /* eslint-disable no-instanceof/no-instanceof */
6
6
  const load_1 = require("@langchain/core/load");
7
+ function isLangChainSerializable(value) {
8
+ return (typeof value.lc_serializable === "boolean" && Array.isArray(value.lc_id));
9
+ }
10
+ function isLangChainSerializedObject(value) {
11
+ return (value !== null &&
12
+ value.lc === 1 &&
13
+ value.type === "constructor" &&
14
+ Array.isArray(value.id));
15
+ }
16
+ const _serialize = (value, seen = new WeakSet()) => {
17
+ const defaultValue = _default("", value);
18
+ if (defaultValue === null) {
19
+ return "null";
20
+ }
21
+ else if (typeof defaultValue === "string") {
22
+ return JSON.stringify(defaultValue);
23
+ }
24
+ else if (typeof defaultValue === "number" ||
25
+ typeof defaultValue === "boolean") {
26
+ return defaultValue.toString();
27
+ }
28
+ else if (typeof defaultValue === "object") {
29
+ if (seen.has(defaultValue)) {
30
+ throw new TypeError("Circular reference detected");
31
+ }
32
+ seen.add(defaultValue);
33
+ if (Array.isArray(defaultValue)) {
34
+ const result = `[${defaultValue
35
+ .map((item) => _serialize(item, seen))
36
+ .join(",")}]`;
37
+ seen.delete(defaultValue);
38
+ return result;
39
+ }
40
+ else if (isLangChainSerializable(defaultValue)) {
41
+ return JSON.stringify(defaultValue);
42
+ }
43
+ else {
44
+ const entries = Object.entries(defaultValue).map(([k, v]) => `${JSON.stringify(k)}:${_serialize(v, seen)}`);
45
+ const result = `{${entries.join(",")}}`;
46
+ seen.delete(defaultValue);
47
+ return result;
48
+ }
49
+ }
50
+ // Only be reached for functions or symbols
51
+ return JSON.stringify(defaultValue);
52
+ };
7
53
  async function _reviver(value) {
8
54
  if (value && typeof value === "object") {
9
- if (value.lc === 2 &&
55
+ if (value.lc === 2 && value.type === "undefined") {
56
+ return undefined;
57
+ }
58
+ else if (value.lc === 2 &&
10
59
  value.type === "constructor" &&
11
60
  Array.isArray(value.id)) {
12
61
  try {
@@ -39,7 +88,7 @@ async function _reviver(value) {
39
88
  return value;
40
89
  }
41
90
  }
42
- else if (value.lc === 1) {
91
+ else if (isLangChainSerializedObject(value)) {
43
92
  return (0, load_1.load)(JSON.stringify(value));
44
93
  }
45
94
  else if (Array.isArray(value)) {
@@ -62,13 +111,19 @@ constructor, method, args, kwargs) {
62
111
  lc: 2,
63
112
  type: "constructor",
64
113
  id: [constructor.name],
65
- method,
114
+ method: method ?? null,
66
115
  args: args ?? [],
67
116
  kwargs: kwargs ?? {},
68
117
  };
69
118
  }
70
119
  function _default(_key, obj) {
71
- if (obj instanceof Set || obj instanceof Map) {
120
+ if (obj === undefined) {
121
+ return {
122
+ lc: 2,
123
+ type: "undefined",
124
+ };
125
+ }
126
+ else if (obj instanceof Set || obj instanceof Map) {
72
127
  return _encodeConstructorArgs(obj.constructor, undefined, [
73
128
  Array.from(obj),
74
129
  ]);
@@ -85,24 +140,8 @@ function _default(_key, obj) {
85
140
  }
86
141
  class JsonPlusSerializer {
87
142
  _dumps(obj) {
88
- const jsonString = JSON.stringify(obj, (key, value) => {
89
- if (value && typeof value === "object") {
90
- if (Array.isArray(value)) {
91
- // Handle arrays
92
- return value.map((item) => _default(key, item));
93
- }
94
- else {
95
- // Handle objects
96
- const serialized = {};
97
- for (const [k, v] of Object.entries(value)) {
98
- serialized[k] = _default(k, v);
99
- }
100
- return serialized;
101
- }
102
- }
103
- return _default(key, value);
104
- });
105
- return new TextEncoder().encode(jsonString);
143
+ const encoder = new TextEncoder();
144
+ return encoder.encode(_serialize(obj));
106
145
  }
107
146
  dumpsTyped(obj) {
108
147
  if (obj instanceof Uint8Array) {
@@ -1,9 +1,58 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  /* eslint-disable no-instanceof/no-instanceof */
3
3
  import { load } from "@langchain/core/load";
4
+ function isLangChainSerializable(value) {
5
+ return (typeof value.lc_serializable === "boolean" && Array.isArray(value.lc_id));
6
+ }
7
+ function isLangChainSerializedObject(value) {
8
+ return (value !== null &&
9
+ value.lc === 1 &&
10
+ value.type === "constructor" &&
11
+ Array.isArray(value.id));
12
+ }
13
+ const _serialize = (value, seen = new WeakSet()) => {
14
+ const defaultValue = _default("", value);
15
+ if (defaultValue === null) {
16
+ return "null";
17
+ }
18
+ else if (typeof defaultValue === "string") {
19
+ return JSON.stringify(defaultValue);
20
+ }
21
+ else if (typeof defaultValue === "number" ||
22
+ typeof defaultValue === "boolean") {
23
+ return defaultValue.toString();
24
+ }
25
+ else if (typeof defaultValue === "object") {
26
+ if (seen.has(defaultValue)) {
27
+ throw new TypeError("Circular reference detected");
28
+ }
29
+ seen.add(defaultValue);
30
+ if (Array.isArray(defaultValue)) {
31
+ const result = `[${defaultValue
32
+ .map((item) => _serialize(item, seen))
33
+ .join(",")}]`;
34
+ seen.delete(defaultValue);
35
+ return result;
36
+ }
37
+ else if (isLangChainSerializable(defaultValue)) {
38
+ return JSON.stringify(defaultValue);
39
+ }
40
+ else {
41
+ const entries = Object.entries(defaultValue).map(([k, v]) => `${JSON.stringify(k)}:${_serialize(v, seen)}`);
42
+ const result = `{${entries.join(",")}}`;
43
+ seen.delete(defaultValue);
44
+ return result;
45
+ }
46
+ }
47
+ // Only be reached for functions or symbols
48
+ return JSON.stringify(defaultValue);
49
+ };
4
50
  async function _reviver(value) {
5
51
  if (value && typeof value === "object") {
6
- if (value.lc === 2 &&
52
+ if (value.lc === 2 && value.type === "undefined") {
53
+ return undefined;
54
+ }
55
+ else if (value.lc === 2 &&
7
56
  value.type === "constructor" &&
8
57
  Array.isArray(value.id)) {
9
58
  try {
@@ -36,7 +85,7 @@ async function _reviver(value) {
36
85
  return value;
37
86
  }
38
87
  }
39
- else if (value.lc === 1) {
88
+ else if (isLangChainSerializedObject(value)) {
40
89
  return load(JSON.stringify(value));
41
90
  }
42
91
  else if (Array.isArray(value)) {
@@ -59,13 +108,19 @@ constructor, method, args, kwargs) {
59
108
  lc: 2,
60
109
  type: "constructor",
61
110
  id: [constructor.name],
62
- method,
111
+ method: method ?? null,
63
112
  args: args ?? [],
64
113
  kwargs: kwargs ?? {},
65
114
  };
66
115
  }
67
116
  function _default(_key, obj) {
68
- if (obj instanceof Set || obj instanceof Map) {
117
+ if (obj === undefined) {
118
+ return {
119
+ lc: 2,
120
+ type: "undefined",
121
+ };
122
+ }
123
+ else if (obj instanceof Set || obj instanceof Map) {
69
124
  return _encodeConstructorArgs(obj.constructor, undefined, [
70
125
  Array.from(obj),
71
126
  ]);
@@ -82,24 +137,8 @@ function _default(_key, obj) {
82
137
  }
83
138
  export class JsonPlusSerializer {
84
139
  _dumps(obj) {
85
- const jsonString = JSON.stringify(obj, (key, value) => {
86
- if (value && typeof value === "object") {
87
- if (Array.isArray(value)) {
88
- // Handle arrays
89
- return value.map((item) => _default(key, item));
90
- }
91
- else {
92
- // Handle objects
93
- const serialized = {};
94
- for (const [k, v] of Object.entries(value)) {
95
- serialized[k] = _default(k, v);
96
- }
97
- return serialized;
98
- }
99
- }
100
- return _default(key, value);
101
- });
102
- return new TextEncoder().encode(jsonString);
140
+ const encoder = new TextEncoder();
141
+ return encoder.encode(_serialize(obj));
103
142
  }
104
143
  dumpsTyped(obj) {
105
144
  if (obj instanceof Uint8Array) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph-checkpoint",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Library with base interfaces for LangGraph checkpoint savers.",
5
5
  "type": "module",
6
6
  "engines": {
@@ -14,7 +14,8 @@
14
14
  },
15
15
  "scripts": {
16
16
  "build": "yarn turbo:command build:internal --filter=@langchain/langgraph-checkpoint",
17
- "build:internal": "yarn lc_build --create-entrypoints --pre --tree-shaking",
17
+ "build:internal": "yarn clean && yarn lc_build --create-entrypoints --pre --tree-shaking",
18
+ "clean": "rm -rf dist/ dist-cjs/ .turbo/",
18
19
  "lint:eslint": "NODE_OPTIONS=--max-old-space-size=4096 eslint --cache --ext .ts,.js src/",
19
20
  "lint:dpdm": "dpdm --exit-code circular:1 --no-warning --no-tree src/*.ts src/**/*.ts",
20
21
  "lint": "yarn lint:eslint && yarn lint:dpdm",
@@ -37,7 +38,7 @@
37
38
  },
38
39
  "devDependencies": {
39
40
  "@jest/globals": "^29.5.0",
40
- "@langchain/scripts": ">=0.1.0 <0.2.0",
41
+ "@langchain/scripts": ">=0.1.2 <0.2.0",
41
42
  "@swc/core": "^1.3.90",
42
43
  "@swc/jest": "^0.2.29",
43
44
  "@tsconfig/recommended": "^1.0.3",