@langchain/langgraph 1.3.7 → 1.4.0
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/channels/base.cjs +78 -2
- package/dist/channels/base.cjs.map +1 -1
- package/dist/channels/base.d.cts +35 -2
- package/dist/channels/base.d.cts.map +1 -1
- package/dist/channels/base.d.ts +35 -2
- package/dist/channels/base.d.ts.map +1 -1
- package/dist/channels/base.js +77 -4
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/delta.cjs +136 -0
- package/dist/channels/delta.cjs.map +1 -0
- package/dist/channels/delta.d.cts +99 -0
- package/dist/channels/delta.d.cts.map +1 -0
- package/dist/channels/delta.d.ts +99 -0
- package/dist/channels/delta.d.ts.map +1 -0
- package/dist/channels/delta.js +136 -0
- package/dist/channels/delta.js.map +1 -0
- package/dist/channels/index.cjs +5 -0
- package/dist/channels/index.d.cts +3 -2
- package/dist/channels/index.d.ts +3 -2
- package/dist/channels/index.js +3 -2
- package/dist/constants.cjs +62 -4
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +33 -2
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.ts +33 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +59 -5
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs +128 -0
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +86 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.ts +86 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +123 -1
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +9 -2
- package/dist/func/index.cjs.map +1 -1
- package/dist/func/index.d.cts +14 -0
- package/dist/func/index.d.cts.map +1 -1
- package/dist/func/index.d.ts +14 -0
- package/dist/func/index.d.ts.map +1 -1
- package/dist/func/index.js +9 -2
- package/dist/func/index.js.map +1 -1
- package/dist/graph/graph.cjs +44 -7
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.d.cts +24 -2
- package/dist/graph/graph.d.cts.map +1 -1
- package/dist/graph/graph.d.ts +24 -2
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/graph/graph.js +44 -7
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.d.ts +3 -3
- package/dist/graph/messages_reducer.cjs +55 -0
- package/dist/graph/messages_reducer.cjs.map +1 -1
- package/dist/graph/messages_reducer.d.cts +28 -1
- package/dist/graph/messages_reducer.d.cts.map +1 -1
- package/dist/graph/messages_reducer.d.ts +28 -1
- package/dist/graph/messages_reducer.d.ts.map +1 -1
- package/dist/graph/messages_reducer.js +56 -2
- package/dist/graph/messages_reducer.js.map +1 -1
- package/dist/graph/state.cjs +174 -7
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.d.cts +193 -17
- package/dist/graph/state.d.cts.map +1 -1
- package/dist/graph/state.d.ts +193 -17
- package/dist/graph/state.d.ts.map +1 -1
- package/dist/graph/state.js +175 -8
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/schema.cjs +5 -0
- package/dist/graph/zod/schema.cjs.map +1 -1
- package/dist/graph/zod/schema.d.cts.map +1 -1
- package/dist/graph/zod/schema.d.ts.map +1 -1
- package/dist/graph/zod/schema.js +5 -0
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/index.cjs +11 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -8
- package/dist/index.d.ts +11 -8
- package/dist/index.js +5 -3
- package/dist/index.js.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.cts +1 -1
- package/dist/pregel/algo.cjs +182 -21
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.d.cts +1 -1
- package/dist/pregel/algo.d.cts.map +1 -1
- package/dist/pregel/algo.d.ts +1 -1
- package/dist/pregel/algo.d.ts.map +1 -1
- package/dist/pregel/algo.js +185 -25
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/call.cjs +2 -1
- package/dist/pregel/call.cjs.map +1 -1
- package/dist/pregel/call.js +2 -1
- package/dist/pregel/call.js.map +1 -1
- package/dist/pregel/index.cjs +15 -3
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.d.cts.map +1 -1
- package/dist/pregel/index.d.ts.map +1 -1
- package/dist/pregel/index.js +17 -5
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +362 -41
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +365 -44
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages-v2.cjs +1 -1
- package/dist/pregel/messages-v2.js +1 -1
- package/dist/pregel/messages.cjs +1 -1
- package/dist/pregel/messages.js +1 -1
- package/dist/pregel/read.cjs +15 -5
- package/dist/pregel/read.cjs.map +1 -1
- package/dist/pregel/read.d.cts +9 -0
- package/dist/pregel/read.d.cts.map +1 -1
- package/dist/pregel/read.d.ts +9 -0
- package/dist/pregel/read.d.ts.map +1 -1
- package/dist/pregel/read.js +15 -5
- package/dist/pregel/read.js.map +1 -1
- package/dist/pregel/remote-run-stream.cjs +107 -0
- package/dist/pregel/remote-run-stream.cjs.map +1 -0
- package/dist/pregel/remote-run-stream.d.cts +33 -0
- package/dist/pregel/remote-run-stream.d.cts.map +1 -0
- package/dist/pregel/remote-run-stream.d.ts +33 -0
- package/dist/pregel/remote-run-stream.d.ts.map +1 -0
- package/dist/pregel/remote-run-stream.js +107 -0
- package/dist/pregel/remote-run-stream.js.map +1 -0
- package/dist/pregel/remote.cjs +61 -1
- package/dist/pregel/remote.cjs.map +1 -1
- package/dist/pregel/remote.d.cts +17 -0
- package/dist/pregel/remote.d.cts.map +1 -1
- package/dist/pregel/remote.d.ts +17 -0
- package/dist/pregel/remote.d.ts.map +1 -1
- package/dist/pregel/remote.js +61 -1
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/replay.cjs +62 -0
- package/dist/pregel/replay.cjs.map +1 -0
- package/dist/pregel/replay.js +62 -0
- package/dist/pregel/replay.js.map +1 -0
- package/dist/pregel/retry.cjs +8 -6
- package/dist/pregel/retry.cjs.map +1 -1
- package/dist/pregel/retry.js +8 -6
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runnable_types.d.cts +20 -0
- package/dist/pregel/runnable_types.d.cts.map +1 -1
- package/dist/pregel/runnable_types.d.ts +20 -0
- package/dist/pregel/runnable_types.d.ts.map +1 -1
- package/dist/pregel/runner.cjs +48 -7
- package/dist/pregel/runner.cjs.map +1 -1
- package/dist/pregel/runner.js +50 -9
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/runtime.cjs +64 -0
- package/dist/pregel/runtime.cjs.map +1 -0
- package/dist/pregel/runtime.d.cts +57 -0
- package/dist/pregel/runtime.d.cts.map +1 -0
- package/dist/pregel/runtime.d.ts +57 -0
- package/dist/pregel/runtime.d.ts.map +1 -0
- package/dist/pregel/runtime.js +64 -0
- package/dist/pregel/runtime.js.map +1 -0
- package/dist/pregel/stream.cjs +2 -0
- package/dist/pregel/stream.cjs.map +1 -1
- package/dist/pregel/stream.js +2 -0
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/timeout.cjs +216 -0
- package/dist/pregel/timeout.cjs.map +1 -0
- package/dist/pregel/timeout.js +216 -0
- package/dist/pregel/timeout.js.map +1 -0
- package/dist/pregel/types.cjs +3 -1
- package/dist/pregel/types.cjs.map +1 -1
- package/dist/pregel/types.d.cts +13 -0
- package/dist/pregel/types.d.cts.map +1 -1
- package/dist/pregel/types.d.ts +14 -1
- package/dist/pregel/types.d.ts.map +1 -1
- package/dist/pregel/types.js +3 -1
- package/dist/pregel/types.js.map +1 -1
- package/dist/pregel/utils/config.cjs +3 -1
- package/dist/pregel/utils/config.cjs.map +1 -1
- package/dist/pregel/utils/config.d.cts.map +1 -1
- package/dist/pregel/utils/config.d.ts.map +1 -1
- package/dist/pregel/utils/config.js +3 -1
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +1 -0
- package/dist/pregel/utils/index.cjs.map +1 -1
- package/dist/pregel/utils/index.d.cts +6 -1
- package/dist/pregel/utils/index.d.cts.map +1 -1
- package/dist/pregel/utils/index.d.ts +6 -1
- package/dist/pregel/utils/index.d.ts.map +1 -1
- package/dist/pregel/utils/index.js +1 -0
- package/dist/pregel/utils/index.js.map +1 -1
- package/dist/pregel/utils/timeout.cjs +34 -0
- package/dist/pregel/utils/timeout.cjs.map +1 -0
- package/dist/pregel/utils/timeout.d.cts +45 -0
- package/dist/pregel/utils/timeout.d.cts.map +1 -0
- package/dist/pregel/utils/timeout.d.ts +45 -0
- package/dist/pregel/utils/timeout.d.ts.map +1 -0
- package/dist/pregel/utils/timeout.js +34 -0
- package/dist/pregel/utils/timeout.js.map +1 -0
- package/dist/web.cjs +11 -0
- package/dist/web.d.cts +11 -8
- package/dist/web.d.ts +11 -8
- package/dist/web.js +5 -3
- package/package.json +5 -5
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { BaseChannel } from "./base.cjs";
|
|
2
|
+
import { OverwriteValue } from "../constants.cjs";
|
|
3
|
+
import { CheckpointPendingWrite, DeltaSnapshot } from "@langchain/langgraph-checkpoint";
|
|
4
|
+
|
|
5
|
+
//#region src/channels/delta.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A batch reducer for use with {@link DeltaChannel}.
|
|
8
|
+
*
|
|
9
|
+
* Receives the current accumulated value and a batch of writes in one call,
|
|
10
|
+
* returning the new accumulated value:
|
|
11
|
+
* `reducer(state, [write1, write2, ...]) -> newState`.
|
|
12
|
+
*
|
|
13
|
+
* Reducers must be deterministic and batching-invariant (associative across
|
|
14
|
+
* folds): applying two consecutive write batches separately must produce the
|
|
15
|
+
* same state as applying their concatenation once:
|
|
16
|
+
*
|
|
17
|
+
* ```text
|
|
18
|
+
* reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* This lets LangGraph replay checkpointed writes in larger batches than they
|
|
22
|
+
* were originally produced without changing reconstructed state. If your
|
|
23
|
+
* reducer is not associative, use {@link BinaryOperatorAggregate} instead —
|
|
24
|
+
* `DeltaChannel` is not a drop-in replacement for every reducer.
|
|
25
|
+
*/
|
|
26
|
+
type DeltaReducer<ValueType, UpdateType = unknown> = (state: ValueType, writes: UpdateType[]) => ValueType;
|
|
27
|
+
type OverwriteOrValue<ValueType, UpdateType> = OverwriteValue<ValueType> | UpdateType;
|
|
28
|
+
/**
|
|
29
|
+
* Reducer channel that stores only a sentinel in checkpoint blobs and
|
|
30
|
+
* reconstructs state by replaying ancestor writes through the reducer.
|
|
31
|
+
*
|
|
32
|
+
* `DeltaChannel` avoids re-serializing the full accumulated value at every
|
|
33
|
+
* step. Instead of writing the value into `channel_values`, the channel is
|
|
34
|
+
* omitted entirely and its state is reconstructed on read by walking the
|
|
35
|
+
* ancestor chain and replaying the per-step writes through the reducer (see
|
|
36
|
+
* {@link BaseCheckpointSaver.getDeltaChannelHistory}).
|
|
37
|
+
*
|
|
38
|
+
* Snapshot cadence is driven by two counters: a per-channel update count and
|
|
39
|
+
* the total supersteps since the last snapshot. A full {@link DeltaSnapshot}
|
|
40
|
+
* blob is written when EITHER the update count reaches `snapshotFrequency` OR
|
|
41
|
+
* the supersteps count reaches the system-wide
|
|
42
|
+
* `DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT` bound (default 5000), bounding replay
|
|
43
|
+
* depth even for channels that stop receiving writes.
|
|
44
|
+
*
|
|
45
|
+
* @remarks Beta. The API and on-disk representation may change in future
|
|
46
|
+
* releases. Threads written with `DeltaChannel` today are expected to remain
|
|
47
|
+
* readable, but the surrounding contract (`getDeltaChannelHistory`, the
|
|
48
|
+
* `DeltaSnapshot` blob shape, the `counters_since_delta_snapshot` metadata
|
|
49
|
+
* field) is not yet stable.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { Annotation } from "@langchain/langgraph";
|
|
54
|
+
* import { DeltaChannel, messagesDeltaReducer } from "@langchain/langgraph";
|
|
55
|
+
*
|
|
56
|
+
* const State = Annotation.Root({
|
|
57
|
+
* messages: Annotation<BaseMessage[]>({
|
|
58
|
+
* reducer: () => [], // ignored; DeltaChannel is supplied below
|
|
59
|
+
* }),
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare class DeltaChannel<ValueType = unknown, UpdateType = unknown> extends BaseChannel<ValueType, OverwriteOrValue<ValueType, UpdateType>, undefined> {
|
|
64
|
+
lc_graph_name: string;
|
|
65
|
+
/** `undefined` represents the Python `MISSING` sentinel (empty channel). */
|
|
66
|
+
value: ValueType | undefined;
|
|
67
|
+
reducer: DeltaReducer<ValueType, UpdateType>;
|
|
68
|
+
snapshotFrequency: number;
|
|
69
|
+
initialValueFactory: () => ValueType;
|
|
70
|
+
constructor(reducer: DeltaReducer<ValueType, UpdateType>, options?: {
|
|
71
|
+
snapshotFrequency?: number;
|
|
72
|
+
initialValueFactory?: () => ValueType;
|
|
73
|
+
});
|
|
74
|
+
fromCheckpoint(checkpoint?: undefined | DeltaSnapshot | ValueType): this;
|
|
75
|
+
/**
|
|
76
|
+
* Apply ancestor writes oldest-to-newest via a single reducer call.
|
|
77
|
+
*
|
|
78
|
+
* If any write is an Overwrite, the last one in the sequence acts as the
|
|
79
|
+
* reset point: its value becomes the new base and only writes after it are
|
|
80
|
+
* passed to the reducer.
|
|
81
|
+
*/
|
|
82
|
+
replayWrites(writes: CheckpointPendingWrite[]): void;
|
|
83
|
+
update(values: OverwriteOrValue<ValueType, UpdateType>[]): boolean;
|
|
84
|
+
get(): ValueType;
|
|
85
|
+
/**
|
|
86
|
+
* Always returns `undefined` (the Python `MISSING` sentinel). Snapshot
|
|
87
|
+
* decisions live in `createCheckpoint`, which has the channel version and
|
|
88
|
+
* writes a {@link DeltaSnapshot} directly into `channel_values`. For
|
|
89
|
+
* non-snapshot steps the channel does not appear in `channel_values`;
|
|
90
|
+
* reconstruction walks ancestor writes via the saver's
|
|
91
|
+
* `getDeltaChannelHistory`.
|
|
92
|
+
*/
|
|
93
|
+
checkpoint(): undefined;
|
|
94
|
+
isAvailable(): boolean;
|
|
95
|
+
equals(other: BaseChannel): boolean;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { DeltaChannel, DeltaReducer };
|
|
99
|
+
//# sourceMappingURL=delta.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delta.d.cts","names":[],"sources":["../../src/channels/delta.ts"],"mappings":";;;;;;;AAiCA;;;;;;;;;;;;;;;;;AAGe;KAHH,YAAA,qCACV,KAAA,EAAO,SAAA,EACP,MAAA,EAAQ,UAAA,OACL,SAAA;AAAA,KAEA,gBAAA,0BACD,cAAA,CAAe,SAAA,IACf,UAAA;;;;;;;;;;;;;AA2CJ;;;;;;;;;;;;;;;;;;;;;;;cAAa,YAAA,oDAGH,WAAA,CACR,SAAA,EACA,gBAAA,CAAiB,SAAA,EAAW,UAAA;EAG5B,aAAA;EALmB;EAQnB,KAAA,EAAO,SAAA;EAEP,OAAA,EAAS,YAAA,CAAa,SAAA,EAAW,UAAA;EAEjC,iBAAA;EAEA,mBAAA,QAA2B,SAAA;EAE3B,WAAA,CACE,OAAA,EAAS,YAAA,CAAa,SAAA,EAAW,UAAA,GACjC,OAAA;IACE,iBAAA;IACA,mBAAA,SAA4B,SAAA;EAAA;EAiBzB,cAAA,CAAe,UAAA,eAAyB,aAAA,GAAgB,SAAA;EA7B/D;;;;;;;EAmDO,YAAA,CAAa,MAAA,EAAQ,sBAAA;EAqBrB,MAAA,CAAO,MAAA,EAAQ,gBAAA,CAAiB,SAAA,EAAW,UAAA;EAsC3C,GAAA,CAAA,GAAO,SAAA;EArGH;;;;;;;;EAoHJ,UAAA,CAAA;EAIP,WAAA,CAAA;EAIA,MAAA,CAAO,KAAA,EAAO,WAAA;AAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { BaseChannel } from "./base.js";
|
|
2
|
+
import { OverwriteValue } from "../constants.js";
|
|
3
|
+
import { CheckpointPendingWrite, DeltaSnapshot } from "@langchain/langgraph-checkpoint";
|
|
4
|
+
|
|
5
|
+
//#region src/channels/delta.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* A batch reducer for use with {@link DeltaChannel}.
|
|
8
|
+
*
|
|
9
|
+
* Receives the current accumulated value and a batch of writes in one call,
|
|
10
|
+
* returning the new accumulated value:
|
|
11
|
+
* `reducer(state, [write1, write2, ...]) -> newState`.
|
|
12
|
+
*
|
|
13
|
+
* Reducers must be deterministic and batching-invariant (associative across
|
|
14
|
+
* folds): applying two consecutive write batches separately must produce the
|
|
15
|
+
* same state as applying their concatenation once:
|
|
16
|
+
*
|
|
17
|
+
* ```text
|
|
18
|
+
* reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* This lets LangGraph replay checkpointed writes in larger batches than they
|
|
22
|
+
* were originally produced without changing reconstructed state. If your
|
|
23
|
+
* reducer is not associative, use {@link BinaryOperatorAggregate} instead —
|
|
24
|
+
* `DeltaChannel` is not a drop-in replacement for every reducer.
|
|
25
|
+
*/
|
|
26
|
+
type DeltaReducer<ValueType, UpdateType = unknown> = (state: ValueType, writes: UpdateType[]) => ValueType;
|
|
27
|
+
type OverwriteOrValue<ValueType, UpdateType> = OverwriteValue<ValueType> | UpdateType;
|
|
28
|
+
/**
|
|
29
|
+
* Reducer channel that stores only a sentinel in checkpoint blobs and
|
|
30
|
+
* reconstructs state by replaying ancestor writes through the reducer.
|
|
31
|
+
*
|
|
32
|
+
* `DeltaChannel` avoids re-serializing the full accumulated value at every
|
|
33
|
+
* step. Instead of writing the value into `channel_values`, the channel is
|
|
34
|
+
* omitted entirely and its state is reconstructed on read by walking the
|
|
35
|
+
* ancestor chain and replaying the per-step writes through the reducer (see
|
|
36
|
+
* {@link BaseCheckpointSaver.getDeltaChannelHistory}).
|
|
37
|
+
*
|
|
38
|
+
* Snapshot cadence is driven by two counters: a per-channel update count and
|
|
39
|
+
* the total supersteps since the last snapshot. A full {@link DeltaSnapshot}
|
|
40
|
+
* blob is written when EITHER the update count reaches `snapshotFrequency` OR
|
|
41
|
+
* the supersteps count reaches the system-wide
|
|
42
|
+
* `DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT` bound (default 5000), bounding replay
|
|
43
|
+
* depth even for channels that stop receiving writes.
|
|
44
|
+
*
|
|
45
|
+
* @remarks Beta. The API and on-disk representation may change in future
|
|
46
|
+
* releases. Threads written with `DeltaChannel` today are expected to remain
|
|
47
|
+
* readable, but the surrounding contract (`getDeltaChannelHistory`, the
|
|
48
|
+
* `DeltaSnapshot` blob shape, the `counters_since_delta_snapshot` metadata
|
|
49
|
+
* field) is not yet stable.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```typescript
|
|
53
|
+
* import { Annotation } from "@langchain/langgraph";
|
|
54
|
+
* import { DeltaChannel, messagesDeltaReducer } from "@langchain/langgraph";
|
|
55
|
+
*
|
|
56
|
+
* const State = Annotation.Root({
|
|
57
|
+
* messages: Annotation<BaseMessage[]>({
|
|
58
|
+
* reducer: () => [], // ignored; DeltaChannel is supplied below
|
|
59
|
+
* }),
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
declare class DeltaChannel<ValueType = unknown, UpdateType = unknown> extends BaseChannel<ValueType, OverwriteOrValue<ValueType, UpdateType>, undefined> {
|
|
64
|
+
lc_graph_name: string;
|
|
65
|
+
/** `undefined` represents the Python `MISSING` sentinel (empty channel). */
|
|
66
|
+
value: ValueType | undefined;
|
|
67
|
+
reducer: DeltaReducer<ValueType, UpdateType>;
|
|
68
|
+
snapshotFrequency: number;
|
|
69
|
+
initialValueFactory: () => ValueType;
|
|
70
|
+
constructor(reducer: DeltaReducer<ValueType, UpdateType>, options?: {
|
|
71
|
+
snapshotFrequency?: number;
|
|
72
|
+
initialValueFactory?: () => ValueType;
|
|
73
|
+
});
|
|
74
|
+
fromCheckpoint(checkpoint?: undefined | DeltaSnapshot | ValueType): this;
|
|
75
|
+
/**
|
|
76
|
+
* Apply ancestor writes oldest-to-newest via a single reducer call.
|
|
77
|
+
*
|
|
78
|
+
* If any write is an Overwrite, the last one in the sequence acts as the
|
|
79
|
+
* reset point: its value becomes the new base and only writes after it are
|
|
80
|
+
* passed to the reducer.
|
|
81
|
+
*/
|
|
82
|
+
replayWrites(writes: CheckpointPendingWrite[]): void;
|
|
83
|
+
update(values: OverwriteOrValue<ValueType, UpdateType>[]): boolean;
|
|
84
|
+
get(): ValueType;
|
|
85
|
+
/**
|
|
86
|
+
* Always returns `undefined` (the Python `MISSING` sentinel). Snapshot
|
|
87
|
+
* decisions live in `createCheckpoint`, which has the channel version and
|
|
88
|
+
* writes a {@link DeltaSnapshot} directly into `channel_values`. For
|
|
89
|
+
* non-snapshot steps the channel does not appear in `channel_values`;
|
|
90
|
+
* reconstruction walks ancestor writes via the saver's
|
|
91
|
+
* `getDeltaChannelHistory`.
|
|
92
|
+
*/
|
|
93
|
+
checkpoint(): undefined;
|
|
94
|
+
isAvailable(): boolean;
|
|
95
|
+
equals(other: BaseChannel): boolean;
|
|
96
|
+
}
|
|
97
|
+
//#endregion
|
|
98
|
+
export { DeltaChannel, DeltaReducer };
|
|
99
|
+
//# sourceMappingURL=delta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delta.d.ts","names":[],"sources":["../../src/channels/delta.ts"],"mappings":";;;;;;;AAiCA;;;;;;;;;;;;;;;;;AAGe;KAHH,YAAA,qCACV,KAAA,EAAO,SAAA,EACP,MAAA,EAAQ,UAAA,OACL,SAAA;AAAA,KAEA,gBAAA,0BACD,cAAA,CAAe,SAAA,IACf,UAAA;;;;;;;;;;;;;AA2CJ;;;;;;;;;;;;;;;;;;;;;;;cAAa,YAAA,oDAGH,WAAA,CACR,SAAA,EACA,gBAAA,CAAiB,SAAA,EAAW,UAAA;EAG5B,aAAA;EALmB;EAQnB,KAAA,EAAO,SAAA;EAEP,OAAA,EAAS,YAAA,CAAa,SAAA,EAAW,UAAA;EAEjC,iBAAA;EAEA,mBAAA,QAA2B,SAAA;EAE3B,WAAA,CACE,OAAA,EAAS,YAAA,CAAa,SAAA,EAAW,UAAA,GACjC,OAAA;IACE,iBAAA;IACA,mBAAA,SAA4B,SAAA;EAAA;EAiBzB,cAAA,CAAe,UAAA,eAAyB,aAAA,GAAgB,SAAA;EA7B/D;;;;;;;EAmDO,YAAA,CAAa,MAAA,EAAQ,sBAAA;EAqBrB,MAAA,CAAO,MAAA,EAAQ,gBAAA,CAAiB,SAAA,EAAW,UAAA;EAsC3C,GAAA,CAAA,GAAO,SAAA;EArGH;;;;;;;;EAoHJ,UAAA,CAAA;EAIP,WAAA,CAAA;EAIA,MAAA,CAAO,KAAA,EAAO,WAAA;AAAA"}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { _getOverwriteValue, _isOverwriteValue } from "../constants.js";
|
|
2
|
+
import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
|
|
3
|
+
import { BaseChannel } from "./base.js";
|
|
4
|
+
import { isDeltaSnapshot } from "@langchain/langgraph-checkpoint";
|
|
5
|
+
//#region src/channels/delta.ts
|
|
6
|
+
const isDeltaChannel = (value) => {
|
|
7
|
+
return value != null && value.lc_graph_name === "DeltaChannel";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Reducer channel that stores only a sentinel in checkpoint blobs and
|
|
11
|
+
* reconstructs state by replaying ancestor writes through the reducer.
|
|
12
|
+
*
|
|
13
|
+
* `DeltaChannel` avoids re-serializing the full accumulated value at every
|
|
14
|
+
* step. Instead of writing the value into `channel_values`, the channel is
|
|
15
|
+
* omitted entirely and its state is reconstructed on read by walking the
|
|
16
|
+
* ancestor chain and replaying the per-step writes through the reducer (see
|
|
17
|
+
* {@link BaseCheckpointSaver.getDeltaChannelHistory}).
|
|
18
|
+
*
|
|
19
|
+
* Snapshot cadence is driven by two counters: a per-channel update count and
|
|
20
|
+
* the total supersteps since the last snapshot. A full {@link DeltaSnapshot}
|
|
21
|
+
* blob is written when EITHER the update count reaches `snapshotFrequency` OR
|
|
22
|
+
* the supersteps count reaches the system-wide
|
|
23
|
+
* `DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT` bound (default 5000), bounding replay
|
|
24
|
+
* depth even for channels that stop receiving writes.
|
|
25
|
+
*
|
|
26
|
+
* @remarks Beta. The API and on-disk representation may change in future
|
|
27
|
+
* releases. Threads written with `DeltaChannel` today are expected to remain
|
|
28
|
+
* readable, but the surrounding contract (`getDeltaChannelHistory`, the
|
|
29
|
+
* `DeltaSnapshot` blob shape, the `counters_since_delta_snapshot` metadata
|
|
30
|
+
* field) is not yet stable.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* import { Annotation } from "@langchain/langgraph";
|
|
35
|
+
* import { DeltaChannel, messagesDeltaReducer } from "@langchain/langgraph";
|
|
36
|
+
*
|
|
37
|
+
* const State = Annotation.Root({
|
|
38
|
+
* messages: Annotation<BaseMessage[]>({
|
|
39
|
+
* reducer: () => [], // ignored; DeltaChannel is supplied below
|
|
40
|
+
* }),
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
var DeltaChannel = class DeltaChannel extends BaseChannel {
|
|
45
|
+
lc_graph_name = "DeltaChannel";
|
|
46
|
+
/** `undefined` represents the Python `MISSING` sentinel (empty channel). */
|
|
47
|
+
value;
|
|
48
|
+
reducer;
|
|
49
|
+
snapshotFrequency;
|
|
50
|
+
initialValueFactory;
|
|
51
|
+
constructor(reducer, options) {
|
|
52
|
+
super();
|
|
53
|
+
const snapshotFrequency = options?.snapshotFrequency ?? 1e3;
|
|
54
|
+
if (!Number.isInteger(snapshotFrequency) || snapshotFrequency <= 0) throw new Error(`snapshotFrequency must be a positive integer, got ${snapshotFrequency}`);
|
|
55
|
+
this.reducer = reducer;
|
|
56
|
+
this.snapshotFrequency = snapshotFrequency;
|
|
57
|
+
this.initialValueFactory = options?.initialValueFactory ?? (() => []);
|
|
58
|
+
this.value = void 0;
|
|
59
|
+
}
|
|
60
|
+
fromCheckpoint(checkpoint) {
|
|
61
|
+
const empty = new DeltaChannel(this.reducer, {
|
|
62
|
+
snapshotFrequency: this.snapshotFrequency,
|
|
63
|
+
initialValueFactory: this.initialValueFactory
|
|
64
|
+
});
|
|
65
|
+
if (checkpoint === void 0) empty.value = this.initialValueFactory();
|
|
66
|
+
else if (isDeltaSnapshot(checkpoint)) empty.value = checkpoint.value;
|
|
67
|
+
else empty.value = checkpoint;
|
|
68
|
+
return empty;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Apply ancestor writes oldest-to-newest via a single reducer call.
|
|
72
|
+
*
|
|
73
|
+
* If any write is an Overwrite, the last one in the sequence acts as the
|
|
74
|
+
* reset point: its value becomes the new base and only writes after it are
|
|
75
|
+
* passed to the reducer.
|
|
76
|
+
*/
|
|
77
|
+
replayWrites(writes) {
|
|
78
|
+
const values = writes.map((w) => w[2]);
|
|
79
|
+
if (values.length === 0) return;
|
|
80
|
+
let base = this.value;
|
|
81
|
+
let start = 0;
|
|
82
|
+
for (let i = 0; i < values.length; i += 1) {
|
|
83
|
+
const [isOverwrite, overwriteValue] = _getOverwriteValue(values[i]);
|
|
84
|
+
if (isOverwrite) {
|
|
85
|
+
base = overwriteValue !== void 0 && overwriteValue !== null ? overwriteValue : this.initialValueFactory();
|
|
86
|
+
start = i + 1;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
const remaining = values.slice(start);
|
|
90
|
+
this.value = remaining.length > 0 ? this.reducer(base, remaining) : base;
|
|
91
|
+
}
|
|
92
|
+
update(values) {
|
|
93
|
+
if (values.length === 0) return false;
|
|
94
|
+
let overwriteIdx;
|
|
95
|
+
for (let i = 0; i < values.length; i += 1) if (_isOverwriteValue(values[i])) {
|
|
96
|
+
if (overwriteIdx !== void 0) throw new InvalidUpdateError("Can receive only one Overwrite value per step.");
|
|
97
|
+
overwriteIdx = i;
|
|
98
|
+
}
|
|
99
|
+
if (overwriteIdx !== void 0) {
|
|
100
|
+
const [, overwriteValue] = _getOverwriteValue(values[overwriteIdx]);
|
|
101
|
+
const base = overwriteValue !== void 0 && overwriteValue !== null ? overwriteValue : this.initialValueFactory();
|
|
102
|
+
const remaining = values.slice(overwriteIdx + 1);
|
|
103
|
+
this.value = remaining.length > 0 ? this.reducer(base, remaining) : base;
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
const base = this.value === void 0 ? this.initialValueFactory() : this.value;
|
|
107
|
+
this.value = this.reducer(base, values);
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
get() {
|
|
111
|
+
if (this.value === void 0) throw new EmptyChannelError();
|
|
112
|
+
return this.value;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Always returns `undefined` (the Python `MISSING` sentinel). Snapshot
|
|
116
|
+
* decisions live in `createCheckpoint`, which has the channel version and
|
|
117
|
+
* writes a {@link DeltaSnapshot} directly into `channel_values`. For
|
|
118
|
+
* non-snapshot steps the channel does not appear in `channel_values`;
|
|
119
|
+
* reconstruction walks ancestor writes via the saver's
|
|
120
|
+
* `getDeltaChannelHistory`.
|
|
121
|
+
*/
|
|
122
|
+
checkpoint() {}
|
|
123
|
+
isAvailable() {
|
|
124
|
+
return this.value !== void 0;
|
|
125
|
+
}
|
|
126
|
+
equals(other) {
|
|
127
|
+
if (this === other) return true;
|
|
128
|
+
if (!isDeltaChannel(other)) return false;
|
|
129
|
+
if (this.snapshotFrequency !== other.snapshotFrequency) return false;
|
|
130
|
+
return this.reducer === other.reducer;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
//#endregion
|
|
134
|
+
export { DeltaChannel };
|
|
135
|
+
|
|
136
|
+
//# sourceMappingURL=delta.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delta.js","names":[],"sources":["../../src/channels/delta.ts"],"sourcesContent":["import {\n type CheckpointPendingWrite,\n DeltaSnapshot,\n isDeltaSnapshot,\n} from \"@langchain/langgraph-checkpoint\";\nimport {\n _getOverwriteValue,\n _isOverwriteValue,\n type OverwriteValue,\n} from \"../constants.js\";\nimport { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n/**\n * A batch reducer for use with {@link DeltaChannel}.\n *\n * Receives the current accumulated value and a batch of writes in one call,\n * returning the new accumulated value:\n * `reducer(state, [write1, write2, ...]) -> newState`.\n *\n * Reducers must be deterministic and batching-invariant (associative across\n * folds): applying two consecutive write batches separately must produce the\n * same state as applying their concatenation once:\n *\n * ```text\n * reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))\n * ```\n *\n * This lets LangGraph replay checkpointed writes in larger batches than they\n * were originally produced without changing reconstructed state. If your\n * reducer is not associative, use {@link BinaryOperatorAggregate} instead —\n * `DeltaChannel` is not a drop-in replacement for every reducer.\n */\nexport type DeltaReducer<ValueType, UpdateType = unknown> = (\n state: ValueType,\n writes: UpdateType[]\n) => ValueType;\n\ntype OverwriteOrValue<ValueType, UpdateType> =\n | OverwriteValue<ValueType>\n | UpdateType;\n\nconst isDeltaChannel = (\n value: BaseChannel\n): value is DeltaChannel<unknown, unknown> => {\n return value != null && value.lc_graph_name === \"DeltaChannel\";\n};\n\n/**\n * Reducer channel that stores only a sentinel in checkpoint blobs and\n * reconstructs state by replaying ancestor writes through the reducer.\n *\n * `DeltaChannel` avoids re-serializing the full accumulated value at every\n * step. Instead of writing the value into `channel_values`, the channel is\n * omitted entirely and its state is reconstructed on read by walking the\n * ancestor chain and replaying the per-step writes through the reducer (see\n * {@link BaseCheckpointSaver.getDeltaChannelHistory}).\n *\n * Snapshot cadence is driven by two counters: a per-channel update count and\n * the total supersteps since the last snapshot. A full {@link DeltaSnapshot}\n * blob is written when EITHER the update count reaches `snapshotFrequency` OR\n * the supersteps count reaches the system-wide\n * `DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT` bound (default 5000), bounding replay\n * depth even for channels that stop receiving writes.\n *\n * @remarks Beta. The API and on-disk representation may change in future\n * releases. Threads written with `DeltaChannel` today are expected to remain\n * readable, but the surrounding contract (`getDeltaChannelHistory`, the\n * `DeltaSnapshot` blob shape, the `counters_since_delta_snapshot` metadata\n * field) is not yet stable.\n *\n * @example\n * ```typescript\n * import { Annotation } from \"@langchain/langgraph\";\n * import { DeltaChannel, messagesDeltaReducer } from \"@langchain/langgraph\";\n *\n * const State = Annotation.Root({\n * messages: Annotation<BaseMessage[]>({\n * reducer: () => [], // ignored; DeltaChannel is supplied below\n * }),\n * });\n * ```\n */\nexport class DeltaChannel<\n ValueType = unknown,\n UpdateType = unknown,\n> extends BaseChannel<\n ValueType,\n OverwriteOrValue<ValueType, UpdateType>,\n undefined\n> {\n lc_graph_name = \"DeltaChannel\";\n\n /** `undefined` represents the Python `MISSING` sentinel (empty channel). */\n value: ValueType | undefined;\n\n reducer: DeltaReducer<ValueType, UpdateType>;\n\n snapshotFrequency: number;\n\n initialValueFactory: () => ValueType;\n\n constructor(\n reducer: DeltaReducer<ValueType, UpdateType>,\n options?: {\n snapshotFrequency?: number;\n initialValueFactory?: () => ValueType;\n }\n ) {\n super();\n const snapshotFrequency = options?.snapshotFrequency ?? 1000;\n if (!Number.isInteger(snapshotFrequency) || snapshotFrequency <= 0) {\n throw new Error(\n `snapshotFrequency must be a positive integer, got ${snapshotFrequency}`\n );\n }\n this.reducer = reducer;\n this.snapshotFrequency = snapshotFrequency;\n this.initialValueFactory =\n options?.initialValueFactory ?? (() => [] as ValueType);\n this.value = undefined;\n }\n\n public fromCheckpoint(checkpoint?: undefined | DeltaSnapshot | ValueType) {\n const empty = new DeltaChannel<ValueType, UpdateType>(this.reducer, {\n snapshotFrequency: this.snapshotFrequency,\n initialValueFactory: this.initialValueFactory,\n });\n if (checkpoint === undefined) {\n empty.value = this.initialValueFactory();\n } else if (isDeltaSnapshot(checkpoint)) {\n empty.value = checkpoint.value as ValueType;\n } else {\n empty.value = checkpoint as ValueType;\n }\n return empty as this;\n }\n\n /**\n * Apply ancestor writes oldest-to-newest via a single reducer call.\n *\n * If any write is an Overwrite, the last one in the sequence acts as the\n * reset point: its value becomes the new base and only writes after it are\n * passed to the reducer.\n */\n public replayWrites(writes: CheckpointPendingWrite[]): void {\n const values = writes.map((w) => w[2]);\n if (values.length === 0) return;\n let base = this.value as ValueType;\n let start = 0;\n for (let i = 0; i < values.length; i += 1) {\n const [isOverwrite, overwriteValue] = _getOverwriteValue<ValueType>(\n values[i]\n );\n if (isOverwrite) {\n base =\n overwriteValue !== undefined && overwriteValue !== null\n ? overwriteValue\n : this.initialValueFactory();\n start = i + 1;\n }\n }\n const remaining = values.slice(start) as UpdateType[];\n this.value = remaining.length > 0 ? this.reducer(base, remaining) : base;\n }\n\n public update(values: OverwriteOrValue<ValueType, UpdateType>[]): boolean {\n if (values.length === 0) return false;\n\n let overwriteIdx: number | undefined;\n for (let i = 0; i < values.length; i += 1) {\n if (_isOverwriteValue<ValueType>(values[i])) {\n if (overwriteIdx !== undefined) {\n throw new InvalidUpdateError(\n \"Can receive only one Overwrite value per step.\"\n );\n }\n overwriteIdx = i;\n }\n }\n\n if (overwriteIdx !== undefined) {\n const [, overwriteValue] = _getOverwriteValue<ValueType>(\n values[overwriteIdx]\n );\n const base =\n overwriteValue !== undefined && overwriteValue !== null\n ? overwriteValue\n : this.initialValueFactory();\n // Treat Overwrite as a hard reset: drop everything up to and including\n // the overwrite, keeping only writes that follow it. This mirrors\n // `replayWrites` so reconstruction from a checkpoint reproduces the live\n // state even when a plain write precedes the Overwrite in the same step.\n const remaining = values.slice(overwriteIdx + 1) as UpdateType[];\n this.value = remaining.length > 0 ? this.reducer(base, remaining) : base;\n return true;\n }\n\n const base =\n this.value === undefined ? this.initialValueFactory() : this.value;\n this.value = this.reducer(base, values as UpdateType[]);\n return true;\n }\n\n public get(): ValueType {\n if (this.value === undefined) {\n throw new EmptyChannelError();\n }\n return this.value;\n }\n\n /**\n * Always returns `undefined` (the Python `MISSING` sentinel). Snapshot\n * decisions live in `createCheckpoint`, which has the channel version and\n * writes a {@link DeltaSnapshot} directly into `channel_values`. For\n * non-snapshot steps the channel does not appear in `channel_values`;\n * reconstruction walks ancestor writes via the saver's\n * `getDeltaChannelHistory`.\n */\n public checkpoint(): undefined {\n return undefined;\n }\n\n isAvailable(): boolean {\n return this.value !== undefined;\n }\n\n equals(other: BaseChannel): boolean {\n if (this === other) return true;\n if (!isDeltaChannel(other)) return false;\n if (this.snapshotFrequency !== other.snapshotFrequency) return false;\n return this.reducer === other.reducer;\n }\n}\n"],"mappings":";;;;;AA0CA,MAAM,kBACJ,UAC4C;AAC5C,QAAO,SAAS,QAAQ,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsClD,IAAa,eAAb,MAAa,qBAGH,YAIR;CACA,gBAAgB;;CAGhB;CAEA;CAEA;CAEA;CAEA,YACE,SACA,SAIA;AACA,SAAO;EACP,MAAM,oBAAoB,SAAS,qBAAqB;AACxD,MAAI,CAAC,OAAO,UAAU,kBAAkB,IAAI,qBAAqB,EAC/D,OAAM,IAAI,MACR,qDAAqD,oBACtD;AAEH,OAAK,UAAU;AACf,OAAK,oBAAoB;AACzB,OAAK,sBACH,SAAS,8BAA8B,EAAE;AAC3C,OAAK,QAAQ,KAAA;;CAGf,eAAsB,YAAoD;EACxE,MAAM,QAAQ,IAAI,aAAoC,KAAK,SAAS;GAClE,mBAAmB,KAAK;GACxB,qBAAqB,KAAK;GAC3B,CAAC;AACF,MAAI,eAAe,KAAA,EACjB,OAAM,QAAQ,KAAK,qBAAqB;WAC/B,gBAAgB,WAAW,CACpC,OAAM,QAAQ,WAAW;MAEzB,OAAM,QAAQ;AAEhB,SAAO;;;;;;;;;CAUT,aAAoB,QAAwC;EAC1D,MAAM,SAAS,OAAO,KAAK,MAAM,EAAE,GAAG;AACtC,MAAI,OAAO,WAAW,EAAG;EACzB,IAAI,OAAO,KAAK;EAChB,IAAI,QAAQ;AACZ,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;GACzC,MAAM,CAAC,aAAa,kBAAkB,mBACpC,OAAO,GACR;AACD,OAAI,aAAa;AACf,WACE,mBAAmB,KAAA,KAAa,mBAAmB,OAC/C,iBACA,KAAK,qBAAqB;AAChC,YAAQ,IAAI;;;EAGhB,MAAM,YAAY,OAAO,MAAM,MAAM;AACrC,OAAK,QAAQ,UAAU,SAAS,IAAI,KAAK,QAAQ,MAAM,UAAU,GAAG;;CAGtE,OAAc,QAA4D;AACxE,MAAI,OAAO,WAAW,EAAG,QAAO;EAEhC,IAAI;AACJ,OAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,EACtC,KAAI,kBAA6B,OAAO,GAAG,EAAE;AAC3C,OAAI,iBAAiB,KAAA,EACnB,OAAM,IAAI,mBACR,iDACD;AAEH,kBAAe;;AAInB,MAAI,iBAAiB,KAAA,GAAW;GAC9B,MAAM,GAAG,kBAAkB,mBACzB,OAAO,cACR;GACD,MAAM,OACJ,mBAAmB,KAAA,KAAa,mBAAmB,OAC/C,iBACA,KAAK,qBAAqB;GAKhC,MAAM,YAAY,OAAO,MAAM,eAAe,EAAE;AAChD,QAAK,QAAQ,UAAU,SAAS,IAAI,KAAK,QAAQ,MAAM,UAAU,GAAG;AACpE,UAAO;;EAGT,MAAM,OACJ,KAAK,UAAU,KAAA,IAAY,KAAK,qBAAqB,GAAG,KAAK;AAC/D,OAAK,QAAQ,KAAK,QAAQ,MAAM,OAAuB;AACvD,SAAO;;CAGT,MAAwB;AACtB,MAAI,KAAK,UAAU,KAAA,EACjB,OAAM,IAAI,mBAAmB;AAE/B,SAAO,KAAK;;;;;;;;;;CAWd,aAA+B;CAI/B,cAAuB;AACrB,SAAO,KAAK,UAAU,KAAA;;CAGxB,OAAO,OAA6B;AAClC,MAAI,SAAS,MAAO,QAAO;AAC3B,MAAI,CAAC,eAAe,MAAM,CAAE,QAAO;AACnC,MAAI,KAAK,sBAAsB,MAAM,kBAAmB,QAAO;AAC/D,SAAO,KAAK,YAAY,MAAM"}
|
package/dist/channels/index.cjs
CHANGED
|
@@ -5,12 +5,14 @@ const require_last_value = require("./last_value.cjs");
|
|
|
5
5
|
const require_topic = require("./topic.cjs");
|
|
6
6
|
const require_ephemeral_value = require("./ephemeral_value.cjs");
|
|
7
7
|
const require_named_barrier_value = require("./named_barrier_value.cjs");
|
|
8
|
+
const require_delta = require("./delta.cjs");
|
|
8
9
|
const require_any_value = require("./any_value.cjs");
|
|
9
10
|
const require_dynamic_barrier_value = require("./dynamic_barrier_value.cjs");
|
|
10
11
|
const require_untracked_value = require("./untracked_value.cjs");
|
|
11
12
|
exports.AnyValue = require_any_value.AnyValue;
|
|
12
13
|
exports.BaseChannel = require_base.BaseChannel;
|
|
13
14
|
exports.BinaryOperatorAggregate = require_binop.BinaryOperatorAggregate;
|
|
15
|
+
exports.DeltaChannel = require_delta.DeltaChannel;
|
|
14
16
|
exports.DynamicBarrierValue = require_dynamic_barrier_value.DynamicBarrierValue;
|
|
15
17
|
exports.EphemeralValue = require_ephemeral_value.EphemeralValue;
|
|
16
18
|
exports.LastValue = require_last_value.LastValue;
|
|
@@ -19,5 +21,8 @@ exports.NamedBarrierValue = require_named_barrier_value.NamedBarrierValue;
|
|
|
19
21
|
exports.NamedBarrierValueAfterFinish = require_named_barrier_value.NamedBarrierValueAfterFinish;
|
|
20
22
|
exports.Topic = require_topic.Topic;
|
|
21
23
|
exports.UntrackedValueChannel = require_untracked_value.UntrackedValueChannel;
|
|
24
|
+
exports.channelsFromCheckpoint = require_base.channelsFromCheckpoint;
|
|
22
25
|
exports.createCheckpoint = require_base.createCheckpoint;
|
|
26
|
+
exports.deltaChannelsToSnapshot = require_base.deltaChannelsToSnapshot;
|
|
23
27
|
exports.empty = require_base.emptyChannels;
|
|
28
|
+
exports.isDeltaChannel = require_base.isDeltaChannel;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BaseChannel, createCheckpoint, emptyChannels } from "./base.cjs";
|
|
1
|
+
import { BaseChannel, channelsFromCheckpoint, createCheckpoint, deltaChannelsToSnapshot, emptyChannels, isDeltaChannel } from "./base.cjs";
|
|
2
|
+
import { DeltaChannel, DeltaReducer } from "./delta.cjs";
|
|
2
3
|
import { BinaryOperator, BinaryOperatorAggregate } from "./binop.cjs";
|
|
3
4
|
import { AnyValue } from "./any_value.cjs";
|
|
4
5
|
import { LastValue, LastValueAfterFinish } from "./last_value.cjs";
|
|
@@ -7,4 +8,4 @@ import { EphemeralValue } from "./ephemeral_value.cjs";
|
|
|
7
8
|
import { NamedBarrierValue, NamedBarrierValueAfterFinish } from "./named_barrier_value.cjs";
|
|
8
9
|
import { Topic } from "./topic.cjs";
|
|
9
10
|
import { UntrackedValueChannel } from "./untracked_value.cjs";
|
|
10
|
-
export { AnyValue, BaseChannel, type BinaryOperator, BinaryOperatorAggregate, DynamicBarrierValue, EphemeralValue, LastValue, LastValueAfterFinish, NamedBarrierValue, NamedBarrierValueAfterFinish, Topic, UntrackedValueChannel, type WaitForNames, createCheckpoint, emptyChannels as empty };
|
|
11
|
+
export { AnyValue, BaseChannel, type BinaryOperator, BinaryOperatorAggregate, DeltaChannel, type DeltaReducer, DynamicBarrierValue, EphemeralValue, LastValue, LastValueAfterFinish, NamedBarrierValue, NamedBarrierValueAfterFinish, Topic, UntrackedValueChannel, type WaitForNames, channelsFromCheckpoint, createCheckpoint, deltaChannelsToSnapshot, emptyChannels as empty, isDeltaChannel };
|
package/dist/channels/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BaseChannel, createCheckpoint, emptyChannels } from "./base.js";
|
|
1
|
+
import { BaseChannel, channelsFromCheckpoint, createCheckpoint, deltaChannelsToSnapshot, emptyChannels, isDeltaChannel } from "./base.js";
|
|
2
|
+
import { DeltaChannel, DeltaReducer } from "./delta.js";
|
|
2
3
|
import { BinaryOperator, BinaryOperatorAggregate } from "./binop.js";
|
|
3
4
|
import { AnyValue } from "./any_value.js";
|
|
4
5
|
import { LastValue, LastValueAfterFinish } from "./last_value.js";
|
|
@@ -7,4 +8,4 @@ import { EphemeralValue } from "./ephemeral_value.js";
|
|
|
7
8
|
import { NamedBarrierValue, NamedBarrierValueAfterFinish } from "./named_barrier_value.js";
|
|
8
9
|
import { Topic } from "./topic.js";
|
|
9
10
|
import { UntrackedValueChannel } from "./untracked_value.js";
|
|
10
|
-
export { AnyValue, BaseChannel, type BinaryOperator, BinaryOperatorAggregate, DynamicBarrierValue, EphemeralValue, LastValue, LastValueAfterFinish, NamedBarrierValue, NamedBarrierValueAfterFinish, Topic, UntrackedValueChannel, type WaitForNames, createCheckpoint, emptyChannels as empty };
|
|
11
|
+
export { AnyValue, BaseChannel, type BinaryOperator, BinaryOperatorAggregate, DeltaChannel, type DeltaReducer, DynamicBarrierValue, EphemeralValue, LastValue, LastValueAfterFinish, NamedBarrierValue, NamedBarrierValueAfterFinish, Topic, UntrackedValueChannel, type WaitForNames, channelsFromCheckpoint, createCheckpoint, deltaChannelsToSnapshot, emptyChannels as empty, isDeltaChannel };
|
package/dist/channels/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { BaseChannel, createCheckpoint, emptyChannels } from "./base.js";
|
|
1
|
+
import { BaseChannel, channelsFromCheckpoint, createCheckpoint, deltaChannelsToSnapshot, emptyChannels, isDeltaChannel } from "./base.js";
|
|
2
2
|
import { BinaryOperatorAggregate } from "./binop.js";
|
|
3
3
|
import { LastValue, LastValueAfterFinish } from "./last_value.js";
|
|
4
4
|
import { Topic } from "./topic.js";
|
|
5
5
|
import { EphemeralValue } from "./ephemeral_value.js";
|
|
6
6
|
import { NamedBarrierValue, NamedBarrierValueAfterFinish } from "./named_barrier_value.js";
|
|
7
|
+
import { DeltaChannel } from "./delta.js";
|
|
7
8
|
import { AnyValue } from "./any_value.js";
|
|
8
9
|
import { DynamicBarrierValue } from "./dynamic_barrier_value.js";
|
|
9
10
|
import { UntrackedValueChannel } from "./untracked_value.js";
|
|
10
|
-
export { AnyValue, BaseChannel, BinaryOperatorAggregate, DynamicBarrierValue, EphemeralValue, LastValue, LastValueAfterFinish, NamedBarrierValue, NamedBarrierValueAfterFinish, Topic, UntrackedValueChannel, createCheckpoint, emptyChannels as empty };
|
|
11
|
+
export { AnyValue, BaseChannel, BinaryOperatorAggregate, DeltaChannel, DynamicBarrierValue, EphemeralValue, LastValue, LastValueAfterFinish, NamedBarrierValue, NamedBarrierValueAfterFinish, Topic, UntrackedValueChannel, channelsFromCheckpoint, createCheckpoint, deltaChannelsToSnapshot, emptyChannels as empty, isDeltaChannel };
|
package/dist/constants.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const require_timeout = require("./pregel/utils/timeout.cjs");
|
|
1
2
|
//#region src/constants.ts
|
|
2
3
|
/** Special reserved node name denoting the start of a graph. */
|
|
3
4
|
const START = "__start__";
|
|
@@ -6,8 +7,36 @@ const END = "__end__";
|
|
|
6
7
|
const INPUT = "__input__";
|
|
7
8
|
const COPY = "__copy__";
|
|
8
9
|
const ERROR = "__error__";
|
|
10
|
+
/**
|
|
11
|
+
* Special reserved write key recording the name of the node whose execution
|
|
12
|
+
* failed, so node-level error handlers see the same failure provenance after a
|
|
13
|
+
* checkpoint resume. Value format in pending writes:
|
|
14
|
+
* `[taskId, ERROR_SOURCE_NODE, nodeName: string]`.
|
|
15
|
+
*/
|
|
16
|
+
const ERROR_SOURCE_NODE = "__error_source_node__";
|
|
9
17
|
/** Special reserved cache namespaces */
|
|
10
18
|
const CACHE_NS_WRITES = "__pregel_ns_writes";
|
|
19
|
+
/**
|
|
20
|
+
* System-wide upper bound on how many supersteps a {@link DeltaChannel} may go
|
|
21
|
+
* without writing a {@link DeltaSnapshot} blob. Once a channel's
|
|
22
|
+
* supersteps-since-snapshot counter reaches this value, a snapshot is forced
|
|
23
|
+
* even if the channel's own `snapshotFrequency` has not been reached — this
|
|
24
|
+
* prevents unbounded ancestor walks on threads where a delta channel exists
|
|
25
|
+
* but is no longer being updated.
|
|
26
|
+
*
|
|
27
|
+
* Overridable via the `LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT`
|
|
28
|
+
* environment variable. Read lazily so test/runtime overrides take effect.
|
|
29
|
+
*
|
|
30
|
+
* @remarks Beta.
|
|
31
|
+
*/
|
|
32
|
+
function getDeltaMaxSuperstepsSinceSnapshot() {
|
|
33
|
+
const raw = typeof process !== "undefined" ? process.env?.LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT : void 0;
|
|
34
|
+
if (raw !== void 0 && raw !== "") {
|
|
35
|
+
const parsed = Number.parseInt(raw, 10);
|
|
36
|
+
if (Number.isFinite(parsed) && parsed > 0) return parsed;
|
|
37
|
+
}
|
|
38
|
+
return 5e3;
|
|
39
|
+
}
|
|
11
40
|
const CONFIG_KEY_SEND = "__pregel_send";
|
|
12
41
|
/** config key containing function used to call a node (push task) */
|
|
13
42
|
const CONFIG_KEY_CALL = "__pregel_call";
|
|
@@ -25,7 +54,14 @@ const CONFIG_KEY_DURABILITY = "__pregel_durability";
|
|
|
25
54
|
const CONFIG_KEY_CHECKPOINT_ID = "checkpoint_id";
|
|
26
55
|
const CONFIG_KEY_CHECKPOINT_NS = "checkpoint_ns";
|
|
27
56
|
const CONFIG_KEY_NODE_FINISHED = "__pregel_node_finished";
|
|
57
|
+
/**
|
|
58
|
+
* Config key holding a {@link NodeError} (failed source node + error) for the
|
|
59
|
+
* current node-level error handler invocation. Injected when an error handler
|
|
60
|
+
* task is prepared after the failing node's retry policy is exhausted.
|
|
61
|
+
*/
|
|
62
|
+
const CONFIG_KEY_NODE_ERROR = "__pregel_node_error";
|
|
28
63
|
const CONFIG_KEY_CHECKPOINT_MAP = "checkpoint_map";
|
|
64
|
+
const CONFIG_KEY_REPLAY_STATE = "__pregel_replay_state";
|
|
29
65
|
const CONFIG_KEY_ABORT_SIGNALS = "__pregel_abort_signals";
|
|
30
66
|
/** Special channel reserved for graph interrupts */
|
|
31
67
|
const INTERRUPT = "__interrupt__";
|
|
@@ -50,6 +86,7 @@ const RESERVED = [
|
|
|
50
86
|
INTERRUPT,
|
|
51
87
|
RESUME,
|
|
52
88
|
ERROR,
|
|
89
|
+
ERROR_SOURCE_NODE,
|
|
53
90
|
NO_WRITES,
|
|
54
91
|
CONFIG_KEY_SEND,
|
|
55
92
|
CONFIG_KEY_READ,
|
|
@@ -64,7 +101,8 @@ const RESERVED = [
|
|
|
64
101
|
CONFIG_KEY_PREVIOUS_STATE,
|
|
65
102
|
CONFIG_KEY_CHECKPOINT_MAP,
|
|
66
103
|
CONFIG_KEY_CHECKPOINT_NS,
|
|
67
|
-
CONFIG_KEY_CHECKPOINT_ID
|
|
104
|
+
CONFIG_KEY_CHECKPOINT_ID,
|
|
105
|
+
CONFIG_KEY_REPLAY_STATE
|
|
68
106
|
];
|
|
69
107
|
/**
|
|
70
108
|
* Symbol used internally to identify Command instances.
|
|
@@ -122,6 +160,14 @@ function _isSendInterface(x) {
|
|
|
122
160
|
* });
|
|
123
161
|
* };
|
|
124
162
|
*
|
|
163
|
+
* @remarks
|
|
164
|
+
* A per-task timeout can be supplied via the third argument's `timeout` option
|
|
165
|
+
* to override the target node's configured timeout for this specific pushed task:
|
|
166
|
+
*
|
|
167
|
+
* ```typescript
|
|
168
|
+
* new Send("generate_joke", { subjects: [subject] }, { timeout: { idleTimeout: 5000 } });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
125
171
|
* const graph = new StateGraph(ChainState)
|
|
126
172
|
* .addNode("generate_joke", (state) => ({
|
|
127
173
|
* jokes: [`Joke about ${state.subjects}`],
|
|
@@ -141,15 +187,23 @@ var Send = class {
|
|
|
141
187
|
lg_name = "Send";
|
|
142
188
|
node;
|
|
143
189
|
args;
|
|
144
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Optional per-task timeout policy that overrides the target node's timeout
|
|
192
|
+
* for this specific pushed task. A bare number is treated as a hard
|
|
193
|
+
* `runTimeout` (in milliseconds).
|
|
194
|
+
*/
|
|
195
|
+
timeout;
|
|
196
|
+
constructor(node, args, options) {
|
|
145
197
|
this.node = node;
|
|
146
198
|
this.args = _deserializeCommandSendObjectGraph(args);
|
|
199
|
+
this.timeout = require_timeout.coerceTimeoutPolicy(options?.timeout);
|
|
147
200
|
}
|
|
148
201
|
toJSON() {
|
|
149
202
|
return {
|
|
150
203
|
lg_name: this.lg_name,
|
|
151
204
|
node: this.node,
|
|
152
|
-
args: this.args
|
|
205
|
+
args: this.args,
|
|
206
|
+
timeout: this.timeout
|
|
153
207
|
};
|
|
154
208
|
}
|
|
155
209
|
};
|
|
@@ -423,7 +477,7 @@ function _deserializeCommandSendObjectGraph(x, seen = /* @__PURE__ */ new Map())
|
|
|
423
477
|
result = new Command(x);
|
|
424
478
|
seen.set(x, result);
|
|
425
479
|
} else if (_isSendInterface(x)) {
|
|
426
|
-
result = new Send(x.node, x.args);
|
|
480
|
+
result = new Send(x.node, x.args, x.timeout !== void 0 ? { timeout: x.timeout } : void 0);
|
|
427
481
|
seen.set(x, result);
|
|
428
482
|
} else if ("lc_serializable" in x && x.lc_serializable) {
|
|
429
483
|
result = x;
|
|
@@ -447,9 +501,11 @@ exports.CONFIG_KEY_CHECKPOINT_ID = CONFIG_KEY_CHECKPOINT_ID;
|
|
|
447
501
|
exports.CONFIG_KEY_CHECKPOINT_MAP = CONFIG_KEY_CHECKPOINT_MAP;
|
|
448
502
|
exports.CONFIG_KEY_CHECKPOINT_NS = CONFIG_KEY_CHECKPOINT_NS;
|
|
449
503
|
exports.CONFIG_KEY_DURABILITY = CONFIG_KEY_DURABILITY;
|
|
504
|
+
exports.CONFIG_KEY_NODE_ERROR = CONFIG_KEY_NODE_ERROR;
|
|
450
505
|
exports.CONFIG_KEY_NODE_FINISHED = CONFIG_KEY_NODE_FINISHED;
|
|
451
506
|
exports.CONFIG_KEY_PREVIOUS_STATE = CONFIG_KEY_PREVIOUS_STATE;
|
|
452
507
|
exports.CONFIG_KEY_READ = CONFIG_KEY_READ;
|
|
508
|
+
exports.CONFIG_KEY_REPLAY_STATE = CONFIG_KEY_REPLAY_STATE;
|
|
453
509
|
exports.CONFIG_KEY_RESUME_MAP = CONFIG_KEY_RESUME_MAP;
|
|
454
510
|
exports.CONFIG_KEY_RESUMING = CONFIG_KEY_RESUMING;
|
|
455
511
|
exports.CONFIG_KEY_SCRATCHPAD = CONFIG_KEY_SCRATCHPAD;
|
|
@@ -461,6 +517,7 @@ exports.Command = Command;
|
|
|
461
517
|
exports.CommandInstance = CommandInstance;
|
|
462
518
|
exports.END = END;
|
|
463
519
|
exports.ERROR = ERROR;
|
|
520
|
+
exports.ERROR_SOURCE_NODE = ERROR_SOURCE_NODE;
|
|
464
521
|
exports.INPUT = INPUT;
|
|
465
522
|
exports.INTERRUPT = INTERRUPT;
|
|
466
523
|
exports.NO_WRITES = NO_WRITES;
|
|
@@ -482,6 +539,7 @@ exports._getOverwriteValue = _getOverwriteValue;
|
|
|
482
539
|
exports._isOverwriteValue = _isOverwriteValue;
|
|
483
540
|
exports._isSend = _isSend;
|
|
484
541
|
exports._isSendInterface = _isSendInterface;
|
|
542
|
+
exports.getDeltaMaxSuperstepsSinceSnapshot = getDeltaMaxSuperstepsSinceSnapshot;
|
|
485
543
|
exports.isCommand = isCommand;
|
|
486
544
|
exports.isInterrupted = isInterrupted;
|
|
487
545
|
|