@langchain/langgraph 1.4.2 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channels/delta.cjs +8 -9
- package/dist/channels/delta.cjs.map +1 -1
- package/dist/channels/delta.d.cts.map +1 -1
- package/dist/channels/delta.d.ts.map +1 -1
- package/dist/channels/delta.js +8 -9
- package/dist/channels/delta.js.map +1 -1
- package/dist/constants.cjs +10 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +10 -1
- package/dist/constants.js.map +1 -1
- package/dist/graph/messages_reducer.cjs +12 -4
- package/dist/graph/messages_reducer.cjs.map +1 -1
- package/dist/graph/messages_reducer.d.cts +8 -3
- package/dist/graph/messages_reducer.d.cts.map +1 -1
- package/dist/graph/messages_reducer.d.ts +8 -3
- package/dist/graph/messages_reducer.d.ts.map +1 -1
- package/dist/graph/messages_reducer.js +12 -4
- package/dist/graph/messages_reducer.js.map +1 -1
- package/dist/index.cjs +3 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/pregel/algo.cjs +20 -3
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.js +20 -3
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/debug.cjs +25 -1
- package/dist/pregel/debug.cjs.map +1 -1
- package/dist/pregel/debug.js +25 -1
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +8 -1
- 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 +9 -2
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +19 -1
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +20 -2
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages-v2.cjs +1 -0
- package/dist/pregel/messages-v2.cjs.map +1 -1
- package/dist/pregel/messages-v2.js +1 -0
- package/dist/pregel/messages-v2.js.map +1 -1
- package/dist/pregel/utils/config.cjs +106 -9
- 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 +107 -11
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +0 -16
- package/dist/pregel/utils/index.cjs.map +1 -1
- package/dist/pregel/utils/index.js +1 -16
- package/dist/pregel/utils/index.js.map +1 -1
- package/dist/state/index.cjs +1 -0
- package/dist/state/index.d.ts +2 -1
- package/dist/state/index.js +1 -0
- package/dist/state/prebuilt/index.d.ts +1 -1
- package/dist/state/prebuilt/messages.cjs +25 -0
- package/dist/state/prebuilt/messages.cjs.map +1 -1
- package/dist/state/prebuilt/messages.d.cts +18 -1
- package/dist/state/prebuilt/messages.d.cts.map +1 -1
- package/dist/state/prebuilt/messages.d.ts +18 -1
- package/dist/state/prebuilt/messages.d.ts.map +1 -1
- package/dist/state/prebuilt/messages.js +31 -4
- package/dist/state/prebuilt/messages.js.map +1 -1
- package/dist/state/schema.cjs +14 -6
- package/dist/state/schema.cjs.map +1 -1
- package/dist/state/schema.d.cts +7 -4
- package/dist/state/schema.d.cts.map +1 -1
- package/dist/state/schema.d.ts +7 -4
- package/dist/state/schema.d.ts.map +1 -1
- package/dist/state/schema.js +14 -6
- package/dist/state/schema.js.map +1 -1
- package/dist/state/values/delta.cjs +77 -0
- package/dist/state/values/delta.cjs.map +1 -0
- package/dist/state/values/delta.d.cts +152 -0
- package/dist/state/values/delta.d.cts.map +1 -0
- package/dist/state/values/delta.d.ts +152 -0
- package/dist/state/values/delta.d.ts.map +1 -0
- package/dist/state/values/delta.js +77 -0
- package/dist/state/values/delta.js.map +1 -0
- package/dist/state/values/index.cjs +1 -0
- package/dist/state/values/index.d.ts +3 -0
- package/dist/state/values/index.js +1 -0
- package/dist/stream/transformers/lifecycle.cjs +93 -2
- package/dist/stream/transformers/lifecycle.cjs.map +1 -1
- package/dist/stream/transformers/lifecycle.js +93 -2
- package/dist/stream/transformers/lifecycle.js.map +1 -1
- package/dist/web.cjs +3 -0
- package/dist/web.d.cts +3 -2
- package/dist/web.d.ts +3 -2
- package/dist/web.js +3 -2
- package/package.json +4 -4
package/dist/channels/delta.cjs
CHANGED
|
@@ -91,16 +91,15 @@ var DeltaChannel = class DeltaChannel extends require_base.BaseChannel {
|
|
|
91
91
|
}
|
|
92
92
|
update(values) {
|
|
93
93
|
if (values.length === 0) return false;
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
let overwriteValue;
|
|
95
|
+
let hasOverwrite = false;
|
|
96
|
+
for (const value of values) if (require_constants._isOverwriteValue(value)) {
|
|
97
|
+
if (hasOverwrite) throw new require_errors.InvalidUpdateError("Can receive only one Overwrite value per step.");
|
|
98
|
+
hasOverwrite = true;
|
|
99
|
+
[, overwriteValue] = require_constants._getOverwriteValue(value);
|
|
98
100
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
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;
|
|
101
|
+
if (hasOverwrite) {
|
|
102
|
+
this.value = overwriteValue !== void 0 && overwriteValue !== null ? overwriteValue : this.initialValueFactory();
|
|
104
103
|
return true;
|
|
105
104
|
}
|
|
106
105
|
const base = this.value === void 0 ? this.initialValueFactory() : this.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"delta.cjs","names":["BaseChannel","_getOverwriteValue","_isOverwriteValue","InvalidUpdateError","EmptyChannelError"],"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,qBAGHA,aAAAA,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;gEACf,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;EACz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ClC,MAAI,SAAS,MAAO,QAAO;AAC3B,MAAI,CAAC,eAAe,MAAM,CAAE,QAAO;AACnC,MAAI,KAAK,sBAAsB,MAAM,kBAAmB,QAAO;AAC/D,SAAO,KAAK,YAAY,MAAM"}
|
|
1
|
+
{"version":3,"file":"delta.cjs","names":["BaseChannel","_getOverwriteValue","_isOverwriteValue","InvalidUpdateError","EmptyChannelError"],"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 overwriteValue: ValueType | undefined;\n let hasOverwrite = false;\n for (const value of values) {\n if (_isOverwriteValue<ValueType>(value)) {\n if (hasOverwrite) {\n throw new InvalidUpdateError(\n \"Can receive only one Overwrite value per step.\"\n );\n }\n hasOverwrite = true;\n [, overwriteValue] = _getOverwriteValue<ValueType>(value);\n }\n }\n\n if (hasOverwrite) {\n // An Overwrite wins the entire super-step: every sibling write (before\n // AND after) is discarded, mirroring `BinaryOperatorAggregate` — hence\n // only one Overwrite per step. The loop force-snapshots channels that saw\n // an Overwrite, so reconstruction seeds from this value without replaying.\n this.value =\n overwriteValue !== undefined && overwriteValue !== null\n ? overwriteValue\n : this.initialValueFactory();\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,qBAGHA,aAAAA,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;gEACf,WAAW,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ClC,MAAI,SAAS,MAAO,QAAO;AAC3B,MAAI,CAAC,eAAe,MAAM,CAAE,QAAO;AACnC,MAAI,KAAK,sBAAsB,MAAM,kBAAmB,QAAO;AAC/D,SAAO,KAAK,YAAY,MAAM"}
|
|
@@ -1 +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;
|
|
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;;;;;;;;;;;;;;;;;;;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,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;
|
|
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;EAmC3C,GAAA,CAAA,GAAO,SAAA;EAlGH;;;;;;;;EAiHJ,UAAA,CAAA;EAIP,WAAA,CAAA;EAIA,MAAA,CAAO,KAAA,EAAO,WAAA;AAAA"}
|
package/dist/channels/delta.js
CHANGED
|
@@ -91,16 +91,15 @@ var DeltaChannel = class DeltaChannel extends BaseChannel {
|
|
|
91
91
|
}
|
|
92
92
|
update(values) {
|
|
93
93
|
if (values.length === 0) return false;
|
|
94
|
-
let
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
94
|
+
let overwriteValue;
|
|
95
|
+
let hasOverwrite = false;
|
|
96
|
+
for (const value of values) if (_isOverwriteValue(value)) {
|
|
97
|
+
if (hasOverwrite) throw new InvalidUpdateError("Can receive only one Overwrite value per step.");
|
|
98
|
+
hasOverwrite = true;
|
|
99
|
+
[, overwriteValue] = _getOverwriteValue(value);
|
|
98
100
|
}
|
|
99
|
-
if (
|
|
100
|
-
|
|
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;
|
|
101
|
+
if (hasOverwrite) {
|
|
102
|
+
this.value = overwriteValue !== void 0 && overwriteValue !== null ? overwriteValue : this.initialValueFactory();
|
|
104
103
|
return true;
|
|
105
104
|
}
|
|
106
105
|
const base = this.value === void 0 ? this.initialValueFactory() : this.value;
|
|
@@ -1 +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;;;;;;;;;;;;;;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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"}
|
|
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 overwriteValue: ValueType | undefined;\n let hasOverwrite = false;\n for (const value of values) {\n if (_isOverwriteValue<ValueType>(value)) {\n if (hasOverwrite) {\n throw new InvalidUpdateError(\n \"Can receive only one Overwrite value per step.\"\n );\n }\n hasOverwrite = true;\n [, overwriteValue] = _getOverwriteValue<ValueType>(value);\n }\n }\n\n if (hasOverwrite) {\n // An Overwrite wins the entire super-step: every sibling write (before\n // AND after) is discarded, mirroring `BinaryOperatorAggregate` — hence\n // only one Overwrite per step. The loop force-snapshots channels that saw\n // an Overwrite, so reconstruction seeds from this value without replaying.\n this.value =\n overwriteValue !== undefined && overwriteValue !== null\n ? overwriteValue\n : this.initialValueFactory();\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,k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C,IAAI;EACJ,IAAI,eAAe;AACnB,OAAK,MAAM,SAAS,OAClB,KAAI,kBAA6B,MAAM,EAAE;AACvC,OAAI,aACF,OAAM,IAAI,mBACR,iDACD;AAEH,kBAAe;AACf,MAAG,kBAAkB,mBAA8B,MAAM;;AAI7D,MAAI,cAAc;AAKhB,QAAK,QACH,mBAAmB,KAAA,KAAa,mBAAmB,OAC/C,iBACA,KAAK,qBAAqB;AAChC,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/constants.cjs
CHANGED
|
@@ -262,6 +262,11 @@ var Overwrite = class {
|
|
|
262
262
|
*
|
|
263
263
|
* - If the value is an Overwrite instance (preferred API), return its `.value`.
|
|
264
264
|
* - If the value is a wire-format object ({ [OVERWRITE]: value }), extract it.
|
|
265
|
+
* - If the value is the discriminator form ({ type: OVERWRITE, value }) that
|
|
266
|
+
* results from JSON-serializing a typed `Overwrite` in another runtime (e.g.
|
|
267
|
+
* a Python dataclass routed through the LangGraph API server, where the typed
|
|
268
|
+
* instance is erased), extract it. Keeps Overwrite semantics intact across
|
|
269
|
+
* cross-runtime JSON boundaries.
|
|
265
270
|
* - Otherwise, returns undefined.
|
|
266
271
|
*
|
|
267
272
|
* @template ValueType - The expected type of the Overwrite value.
|
|
@@ -270,7 +275,11 @@ var Overwrite = class {
|
|
|
270
275
|
* @internal
|
|
271
276
|
*/
|
|
272
277
|
function _getOverwriteValue(value) {
|
|
273
|
-
if (typeof value === "object" && value !== null
|
|
278
|
+
if (typeof value === "object" && value !== null) {
|
|
279
|
+
if ("__overwrite__" in value) return [true, value[OVERWRITE]];
|
|
280
|
+
const rec = value;
|
|
281
|
+
if (rec.type === "__overwrite__" && "value" in rec) return [true, rec.value];
|
|
282
|
+
}
|
|
274
283
|
return [false, void 0];
|
|
275
284
|
}
|
|
276
285
|
/**
|
package/dist/constants.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","names":["coerceTimeoutPolicy"],"sources":["../src/constants.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n coerceTimeoutPolicy,\n type TimeoutPolicy,\n} from \"./pregel/utils/timeout.js\";\n\n/** Special reserved node name denoting the start of a graph. */\nexport const START = \"__start__\";\n/** Special reserved node name denoting the end of a graph. */\nexport const END = \"__end__\";\nexport const INPUT = \"__input__\";\nexport const COPY = \"__copy__\";\nexport const ERROR = \"__error__\";\n/**\n * Special reserved write key recording the name of the node whose execution\n * failed, so node-level error handlers see the same failure provenance after a\n * checkpoint resume. Value format in pending writes:\n * `[taskId, ERROR_SOURCE_NODE, nodeName: string]`.\n */\nexport const ERROR_SOURCE_NODE = \"__error_source_node__\";\n\n/** Special reserved cache namespaces */\nexport const CACHE_NS_WRITES = \"__pregel_ns_writes\";\n\n/**\n * System-wide upper bound on how many supersteps a {@link DeltaChannel} may go\n * without writing a {@link DeltaSnapshot} blob. Once a channel's\n * supersteps-since-snapshot counter reaches this value, a snapshot is forced\n * even if the channel's own `snapshotFrequency` has not been reached — this\n * prevents unbounded ancestor walks on threads where a delta channel exists\n * but is no longer being updated.\n *\n * Overridable via the `LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT`\n * environment variable. Read lazily so test/runtime overrides take effect.\n *\n * @remarks Beta.\n */\nexport function getDeltaMaxSuperstepsSinceSnapshot(): number {\n const raw =\n typeof process !== \"undefined\"\n ? process.env?.LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT\n : undefined;\n if (raw !== undefined && raw !== \"\") {\n const parsed = Number.parseInt(raw, 10);\n if (Number.isFinite(parsed) && parsed > 0) return parsed;\n }\n return 5000;\n}\n\nexport const CONFIG_KEY_SEND = \"__pregel_send\";\n/** config key containing function used to call a node (push task) */\nexport const CONFIG_KEY_CALL = \"__pregel_call\";\nexport const CONFIG_KEY_READ = \"__pregel_read\";\nexport const CONFIG_KEY_CHECKPOINTER = \"__pregel_checkpointer\";\nexport const CONFIG_KEY_RESUMING = \"__pregel_resuming\";\nexport const CONFIG_KEY_TASK_ID = \"__pregel_task_id\";\nexport const CONFIG_KEY_STREAM = \"__pregel_stream\";\nexport const CONFIG_KEY_RESUME_VALUE = \"__pregel_resume_value\";\nexport const CONFIG_KEY_RESUME_MAP = \"__pregel_resume_map\";\nexport const CONFIG_KEY_SCRATCHPAD = \"__pregel_scratchpad\";\n/** config key containing state from previous invocation of graph for the given thread */\nexport const CONFIG_KEY_PREVIOUS_STATE = \"__pregel_previous\";\nexport const CONFIG_KEY_DURABILITY = \"__pregel_durability\";\nexport const CONFIG_KEY_CHECKPOINT_ID = \"checkpoint_id\";\nexport const CONFIG_KEY_CHECKPOINT_NS = \"checkpoint_ns\";\n\nexport const CONFIG_KEY_NODE_FINISHED = \"__pregel_node_finished\";\n\n/**\n * Config key holding a {@link NodeError} (failed source node + error) for the\n * current node-level error handler invocation. Injected when an error handler\n * task is prepared after the failing node's retry policy is exhausted.\n */\nexport const CONFIG_KEY_NODE_ERROR = \"__pregel_node_error\";\n\n// this one is part of public API\nexport const CONFIG_KEY_CHECKPOINT_MAP = \"checkpoint_map\";\n\nexport const CONFIG_KEY_REPLAY_STATE = \"__pregel_replay_state\";\n\nexport const CONFIG_KEY_ABORT_SIGNALS = \"__pregel_abort_signals\";\n\n/** Special channel reserved for graph interrupts */\nexport const INTERRUPT = \"__interrupt__\";\n/** Special channel reserved for graph resume */\nexport const RESUME = \"__resume__\";\n/** Special channel reserved for cases when a task exits without any writes */\nexport const NO_WRITES = \"__no_writes__\";\n/** Special channel reserved for graph return */\nexport const RETURN = \"__return__\";\n/** Special channel reserved for graph previous state */\nexport const PREVIOUS = \"__previous__\";\nexport const RUNTIME_PLACEHOLDER = \"__pregel_runtime_placeholder__\";\nexport const RECURSION_LIMIT_DEFAULT = 25;\n\nexport const TAG_HIDDEN = \"langsmith:hidden\";\nexport const TAG_NOSTREAM = \"langsmith:nostream\";\nexport const SELF = \"__self__\";\n\nexport const TASKS = \"__pregel_tasks\";\nexport const PUSH = \"__pregel_push\";\nexport const PULL = \"__pregel_pull\";\n\nexport const TASK_NAMESPACE = \"6ba7b831-9dad-11d1-80b4-00c04fd430c8\";\nexport const NULL_TASK_ID = \"00000000-0000-0000-0000-000000000000\";\n\nexport const RESERVED = [\n TAG_HIDDEN,\n INPUT,\n INTERRUPT,\n RESUME,\n ERROR,\n ERROR_SOURCE_NODE,\n NO_WRITES,\n\n // reserved config.configurable keys\n CONFIG_KEY_SEND,\n CONFIG_KEY_READ,\n CONFIG_KEY_CHECKPOINTER,\n CONFIG_KEY_DURABILITY,\n CONFIG_KEY_STREAM,\n CONFIG_KEY_RESUMING,\n CONFIG_KEY_TASK_ID,\n CONFIG_KEY_CALL,\n CONFIG_KEY_RESUME_VALUE,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_PREVIOUS_STATE,\n CONFIG_KEY_CHECKPOINT_MAP,\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_CHECKPOINT_ID,\n CONFIG_KEY_REPLAY_STATE,\n];\n\nexport const CHECKPOINT_NAMESPACE_SEPARATOR = \"|\";\nexport const CHECKPOINT_NAMESPACE_END = \":\";\n\n/**\n * Symbol used internally to identify Command instances.\n * Exported to support cross-version type compatibility.\n * @internal\n */\nexport const COMMAND_SYMBOL = Symbol.for(\"langgraph.command\");\n\n/**\n * Instance of a {@link Command} class.\n *\n * This is used to avoid IntelliSense suggesting public fields\n * of {@link Command} class when a plain object is expected.\n *\n * @see {@link Command}\n * @internal\n */\nexport class CommandInstance<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> {\n [COMMAND_SYMBOL]: CommandParams<Resume, Update, Nodes>;\n\n constructor(args: CommandParams<Resume, Update, Nodes>) {\n this[COMMAND_SYMBOL] = args;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SendInterface<Node extends string = string, Args = any> {\n node: Node;\n args: Args;\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task.\n */\n timeout?: TimeoutPolicy;\n}\n\n/** Keyword options for {@link Send}. */\nexport type SendOptions = {\n /**\n * Per-task timeout policy overriding the target node's timeout for this\n * pushed task. A bare number is treated as `runTimeout` (milliseconds).\n */\n timeout?: number | TimeoutPolicy;\n};\n\nexport function _isSendInterface(x: unknown): x is SendInterface {\n const operation = x as SendInterface;\n return (\n operation !== null &&\n operation !== undefined &&\n typeof operation.node === \"string\" &&\n operation.args !== undefined\n );\n}\n\n/**\n *\n * A message or packet to send to a specific node in the graph.\n *\n * The `Send` class is used within a `StateGraph`'s conditional edges to\n * dynamically invoke a node with a custom state at the next step.\n *\n * Importantly, the sent state can differ from the core graph's state,\n * allowing for flexible and dynamic workflow management.\n *\n * One such example is a \"map-reduce\" workflow where your graph invokes\n * the same node multiple times in parallel with different states,\n * before aggregating the results back into the main graph's state.\n *\n * @example\n * ```typescript\n * import { Annotation, Send, StateGraph } from \"@langchain/langgraph\";\n *\n * const ChainState = Annotation.Root({\n * subjects: Annotation<string[]>,\n * jokes: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * }),\n * });\n *\n * const continueToJokes = async (state: typeof ChainState.State) => {\n * return state.subjects.map((subject) => {\n * return new Send(\"generate_joke\", { subjects: [subject] });\n * });\n * };\n *\n * @remarks\n * A per-task timeout can be supplied via the third argument's `timeout` option\n * to override the target node's configured timeout for this specific pushed task:\n *\n * ```typescript\n * new Send(\"generate_joke\", { subjects: [subject] }, { timeout: { idleTimeout: 5000 } });\n * ```\n *\n * const graph = new StateGraph(ChainState)\n * .addNode(\"generate_joke\", (state) => ({\n * jokes: [`Joke about ${state.subjects}`],\n * }))\n * .addConditionalEdges(\"__start__\", continueToJokes)\n * .addEdge(\"generate_joke\", \"__end__\")\n * .compile();\n *\n * const res = await graph.invoke({ subjects: [\"cats\", \"dogs\"] });\n * console.log(res);\n *\n * // Invoking with two subjects results in a generated joke for each\n * // { subjects: [\"cats\", \"dogs\"], jokes: [`Joke about cats`, `Joke about dogs`] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Send<\n Node extends string = string,\n Args = any,\n> implements SendInterface<Node, Args> {\n lg_name = \"Send\";\n\n public node: Node;\n\n public args: Args;\n\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task. A bare number is treated as a hard\n * `runTimeout` (in milliseconds).\n */\n public timeout?: TimeoutPolicy;\n\n constructor(node: Node, args: Args, options?: SendOptions) {\n this.node = node;\n this.args = _deserializeCommandSendObjectGraph(args) as Args;\n this.timeout = coerceTimeoutPolicy(options?.timeout);\n }\n\n toJSON() {\n return {\n lg_name: this.lg_name,\n node: this.node,\n args: this.args,\n timeout: this.timeout,\n };\n }\n}\n\nexport function _isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n\nexport const OVERWRITE = \"__overwrite__\";\n\n/**\n * An object representing a direct overwrite of a value for a channel.\n * Used to signal that the channel value should be replaced with the given value,\n * bypassing any reducer or binary operator logic.\n *\n * @template ValueType - The type of the value being overwritten.\n * @property {ValueType} [OVERWRITE] - The value to directly set.\n *\n * @example\n * const overwriteObj: OverwriteValue<number> = { __overwrite__: 123 };\n */\nexport interface OverwriteValue<ValueType> {\n [OVERWRITE]: ValueType;\n}\n\n/**\n * Bypass a reducer and write the wrapped value directly to a\n * {@link BinaryOperatorAggregate} channel.\n *\n * Receiving multiple `Overwrite` values for the same channel in a single\n * super-step will raise an {@link InvalidUpdateError}.\n *\n * @example\n * ```typescript\n * import { Annotation, StateGraph, Overwrite } from \"@langchain/langgraph\";\n *\n * const State = Annotation.Root({\n * messages: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * default: () => [],\n * }),\n * });\n *\n * const replaceMessages = (_state: typeof State.State) => {\n * return { messages: new Overwrite([\"replacement\"]) };\n * };\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Overwrite<ValueType = any> implements OverwriteValue<ValueType> {\n lg_name = \"Overwrite\";\n\n readonly [OVERWRITE]: ValueType;\n\n constructor(value: ValueType) {\n this[OVERWRITE] = value;\n }\n\n get value(): ValueType {\n return this[OVERWRITE];\n }\n\n toJSON() {\n return { [OVERWRITE]: this[OVERWRITE] };\n }\n\n static isInstance<ValueType>(value: unknown): value is Overwrite<ValueType> {\n if (!value || typeof value !== \"object\") return false;\n if (OVERWRITE in value) return true;\n if (\"lg_name\" in value && value.lg_name === \"Overwrite\") return true;\n return false;\n }\n}\n\n/**\n * Helper function to detect and extract the value from an Overwrite wrapper,\n * supporting both the Overwrite class instance and the serialized object format.\n *\n * Use to check if a provided value represents an Overwrite: returns the\n * unwrapped value if so, or undefined otherwise.\n *\n * - If the value is an Overwrite instance (preferred API), return its `.value`.\n * - If the value is a wire-format object ({ [OVERWRITE]: value }), extract it.\n * - Otherwise, returns undefined.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns The unwrapped value if value is an Overwrite, or undefined otherwise.\n * @internal\n */\nexport function _getOverwriteValue<ValueType>(\n value: unknown\n): [true, ValueType] | [false, undefined] {\n if (typeof value === \"object\" && value !== null && OVERWRITE in value) {\n return [true, (value as Record<string, ValueType>)[OVERWRITE]];\n }\n return [false, undefined];\n}\n\n/**\n * Type guard to check if a value is an Overwrite value -- either the class\n * instance or the wire format object.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns `true` if the value is an Overwrite value, `false` otherwise.\n * @internal\n */\nexport function _isOverwriteValue<ValueType>(\n value: unknown\n): value is OverwriteValue<ValueType> {\n return _getOverwriteValue<ValueType>(value)[0];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Interrupt<Value = any> = {\n id?: string;\n value?: Value;\n};\n\n/**\n * Checks if the given graph invoke / stream chunk contains interrupt.\n *\n * @example\n * ```ts\n * import { INTERRUPT, isInterrupted } from \"@langchain/langgraph\";\n *\n * const values = await graph.invoke({ foo: \"bar\" });\n * if (isInterrupted<string>(values)) {\n * const interrupt = values[INTERRUPT][0].value;\n * }\n * ```\n *\n * @param values - The values to check.\n * @returns `true` if the values contain an interrupt, `false` otherwise.\n */\nexport function isInterrupted<Value = unknown>(\n values: unknown\n): values is { [INTERRUPT]: Interrupt<Value>[] } {\n if (!values || typeof values !== \"object\") return false;\n if (!(INTERRUPT in values)) return false;\n return Array.isArray(values[INTERRUPT]);\n}\n\nexport type CommandParams<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> = {\n /**\n * A discriminator field used to identify the type of object. Must be populated when serializing.\n *\n * Optional because it's not required to specify this when directly constructing a {@link Command}\n * object.\n */\n lg_name?: \"Command\";\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - `Send` object (to execute a node with the input provided)\n * - sequence of `Send` objects\n */\n goto?:\n | Nodes\n | SendInterface<Nodes> // eslint-disable-line @typescript-eslint/no-explicit-any\n | (Nodes | SendInterface<Nodes>)[]; // eslint-disable-line @typescript-eslint/no-explicit-any\n};\n\n/**\n * One or more commands to update the graph's state and send messages to nodes.\n * Can be used to combine routing logic with state updates in lieu of conditional edges\n *\n * @example\n * ```ts\n * import { Annotation, Command } from \"@langchain/langgraph\";\n *\n * // Define graph state\n * const StateAnnotation = Annotation.Root({\n * foo: Annotation<string>,\n * });\n *\n * // Define the nodes\n * const nodeA = async (_state: typeof StateAnnotation.State) => {\n * console.log(\"Called A\");\n * // this is a replacement for a real conditional edge function\n * const goto = Math.random() > .5 ? \"nodeB\" : \"nodeC\";\n * // note how Command allows you to BOTH update the graph state AND route to the next node\n * return new Command({\n * // this is the state update\n * update: {\n * foo: \"a\",\n * },\n * // this is a replacement for an edge\n * goto,\n * });\n * };\n *\n * // Nodes B and C are unchanged\n * const nodeB = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called B\");\n * return {\n * foo: state.foo + \"|b\",\n * };\n * }\n *\n * const nodeC = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called C\");\n * return {\n * foo: state.foo + \"|c\",\n * };\n * }\n * \n * import { StateGraph } from \"@langchain/langgraph\";\n\n * // NOTE: there are no edges between nodes A, B and C!\n * const graph = new StateGraph(StateAnnotation)\n * .addNode(\"nodeA\", nodeA, {\n * ends: [\"nodeB\", \"nodeC\"],\n * })\n * .addNode(\"nodeB\", nodeB)\n * .addNode(\"nodeC\", nodeC)\n * .addEdge(\"__start__\", \"nodeA\")\n * .compile();\n * \n * await graph.invoke({ foo: \"\" });\n *\n * // Randomly oscillates between\n * // { foo: 'a|c' } and { foo: 'a|b' }\n * ```\n */\nexport class Command<\n Resume = unknown,\n Update extends Record<string, unknown> = Record<string, unknown>,\n Nodes extends string = string,\n> extends CommandInstance<Resume, Update, Nodes> {\n readonly lg_name = \"Command\";\n\n lc_direct_tool_output = true;\n\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state as a result of executing the node that is returning the command.\n * Written to the state as if the node had simply returned this value instead of the Command object.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)\n * - sequence of {@link Send} objects\n */\n goto?: Nodes | Send<Nodes> | (Nodes | Send<Nodes>)[] = [];\n\n static PARENT = \"__parent__\";\n\n constructor(args: Omit<CommandParams<Resume, Update, Nodes>, \"lg_name\">) {\n super(args);\n this.resume = args.resume;\n this.graph = args.graph;\n this.update = args.update;\n if (args.goto) {\n type ValidArg = Nodes | Send<Nodes, Update>;\n\n this.goto = Array.isArray(args.goto)\n ? (_deserializeCommandSendObjectGraph(args.goto) as ValidArg[])\n : [_deserializeCommandSendObjectGraph(args.goto) as ValidArg];\n }\n }\n\n /**\n * Convert the update field to a list of {@link PendingWrite} tuples\n * @returns List of {@link PendingWrite} tuples of the form `[channelKey, value]`.\n * @internal\n */\n _updateAsTuples(): PendingWrite[] {\n if (\n this.update &&\n typeof this.update === \"object\" &&\n !Array.isArray(this.update)\n ) {\n return Object.entries(this.update);\n } else if (\n Array.isArray(this.update) &&\n this.update.every(\n (t): t is [string, unknown] =>\n Array.isArray(t) && t.length === 2 && typeof t[0] === \"string\"\n )\n ) {\n return this.update;\n } else {\n return [[\"__root__\", this.update]];\n }\n }\n\n toJSON() {\n let serializedGoto;\n if (typeof this.goto === \"string\") {\n serializedGoto = this.goto;\n } else if (_isSend(this.goto)) {\n serializedGoto = this.goto.toJSON();\n } else {\n serializedGoto = this.goto?.map((innerGoto) => {\n if (typeof innerGoto === \"string\") {\n return innerGoto;\n } else {\n return innerGoto.toJSON();\n }\n });\n }\n return {\n lg_name: this.lg_name,\n update: this.update,\n resume: this.resume,\n goto: serializedGoto,\n };\n }\n}\n\n/**\n * A type guard to check if the given value is a {@link Command}.\n *\n * Useful for type narrowing when working with the {@link Command} object.\n *\n * @param x - The value to check.\n * @returns `true` if the value is a {@link Command}, `false` otherwise.\n */\nexport function isCommand(x: unknown): x is Command {\n if (typeof x !== \"object\") {\n return false;\n }\n\n if (x === null || x === undefined) {\n return false;\n }\n\n if (\"lg_name\" in x && x.lg_name === \"Command\") {\n return true;\n }\n\n return false;\n}\n\nfunction isPlainObject(value: object): value is Record<string, unknown> {\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Reconstructs Command and Send objects from a deeply nested tree of anonymous objects\n * matching their interfaces.\n *\n * This is only exported for testing purposes. It is NOT intended to be used outside of\n * the Command and Send classes.\n *\n * @internal\n *\n * @param x - The command send tree to convert.\n * @param seen - A map of seen objects to avoid infinite loops.\n * @returns The converted command send tree.\n */\nexport function _deserializeCommandSendObjectGraph(\n x: unknown,\n seen: Map<object, unknown> = new Map()\n): unknown {\n if (x !== undefined && x !== null && typeof x === \"object\") {\n // If we've already processed this object, return the transformed version\n if (seen.has(x)) {\n return seen.get(x);\n }\n\n let result: unknown;\n\n if (Array.isArray(x)) {\n // Create the array first, then populate it\n result = [];\n // Add to seen map before processing elements to handle self-references\n seen.set(x, result);\n\n // Now populate the array\n x.forEach((item, index) => {\n (result as unknown[])[index] = _deserializeCommandSendObjectGraph(\n item,\n seen\n );\n });\n // eslint-disable-next-line no-instanceof/no-instanceof\n } else if (x instanceof Command || x instanceof Send || !isPlainObject(x)) {\n result = x;\n seen.set(x, result);\n } else if (isCommand(x)) {\n result = new Command(x);\n seen.set(x, result);\n } else if (_isSendInterface(x)) {\n result = new Send(\n x.node,\n x.args,\n x.timeout !== undefined ? { timeout: x.timeout } : undefined\n );\n seen.set(x, result);\n } else if (\"lc_serializable\" in x && x.lc_serializable) {\n result = x;\n seen.set(x, result);\n } else {\n // Create empty object first\n result = {};\n // Add to seen map before processing properties to handle self-references\n seen.set(x, result);\n\n // Now populate the object\n for (const [key, value] of Object.entries(x)) {\n (result as Record<string, unknown>)[key] =\n _deserializeCommandSendObjectGraph(value, seen);\n }\n }\n\n return result;\n }\n return x;\n}\n"],"mappings":";;;AAOA,MAAa,QAAQ;;AAErB,MAAa,MAAM;AACnB,MAAa,QAAQ;AACrB,MAAa,OAAO;AACpB,MAAa,QAAQ;;;;;;;AAOrB,MAAa,oBAAoB;;AAGjC,MAAa,kBAAkB;;;;;;;;;;;;;;AAe/B,SAAgB,qCAA6C;CAC3D,MAAM,MACJ,OAAO,YAAY,cACf,QAAQ,KAAK,gDACb,KAAA;AACN,KAAI,QAAQ,KAAA,KAAa,QAAQ,IAAI;EACnC,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;AACvC,MAAI,OAAO,SAAS,OAAO,IAAI,SAAS,EAAG,QAAO;;AAEpD,QAAO;;AAGT,MAAa,kBAAkB;;AAE/B,MAAa,kBAAkB;AAC/B,MAAa,kBAAkB;AAC/B,MAAa,0BAA0B;AACvC,MAAa,sBAAsB;AACnC,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AACjC,MAAa,0BAA0B;AACvC,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;;AAErC,MAAa,4BAA4B;AACzC,MAAa,wBAAwB;AACrC,MAAa,2BAA2B;AACxC,MAAa,2BAA2B;AAExC,MAAa,2BAA2B;;;;;;AAOxC,MAAa,wBAAwB;AAGrC,MAAa,4BAA4B;AAEzC,MAAa,0BAA0B;AAEvC,MAAa,2BAA2B;;AAGxC,MAAa,YAAY;;AAEzB,MAAa,SAAS;;AAEtB,MAAa,YAAY;;AAEzB,MAAa,SAAS;;AAEtB,MAAa,WAAW;AAIxB,MAAa,aAAa;AAC1B,MAAa,eAAe;AAC5B,MAAa,OAAO;AAEpB,MAAa,QAAQ;AACrB,M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YAAY,KAAA,IAAY,EAAE,SAAS,EAAE,SAAS,GAAG,KAAA,EACpD;AACD,QAAK,IAAI,GAAG,OAAO;aACV,qBAAqB,KAAK,EAAE,iBAAiB;AACtD,YAAS;AACT,QAAK,IAAI,GAAG,OAAO;SACd;AAEL,YAAS,EAAE;AAEX,QAAK,IAAI,GAAG,OAAO;AAGnB,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,EAAE,CACzC,QAAmC,OAClC,mCAAmC,OAAO,KAAK;;AAIrD,SAAO;;AAET,QAAO"}
|
|
1
|
+
{"version":3,"file":"constants.cjs","names":["coerceTimeoutPolicy"],"sources":["../src/constants.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n coerceTimeoutPolicy,\n type TimeoutPolicy,\n} from \"./pregel/utils/timeout.js\";\n\n/** Special reserved node name denoting the start of a graph. */\nexport const START = \"__start__\";\n/** Special reserved node name denoting the end of a graph. */\nexport const END = \"__end__\";\nexport const INPUT = \"__input__\";\nexport const COPY = \"__copy__\";\nexport const ERROR = \"__error__\";\n/**\n * Special reserved write key recording the name of the node whose execution\n * failed, so node-level error handlers see the same failure provenance after a\n * checkpoint resume. Value format in pending writes:\n * `[taskId, ERROR_SOURCE_NODE, nodeName: string]`.\n */\nexport const ERROR_SOURCE_NODE = \"__error_source_node__\";\n\n/** Special reserved cache namespaces */\nexport const CACHE_NS_WRITES = \"__pregel_ns_writes\";\n\n/**\n * System-wide upper bound on how many supersteps a {@link DeltaChannel} may go\n * without writing a {@link DeltaSnapshot} blob. Once a channel's\n * supersteps-since-snapshot counter reaches this value, a snapshot is forced\n * even if the channel's own `snapshotFrequency` has not been reached — this\n * prevents unbounded ancestor walks on threads where a delta channel exists\n * but is no longer being updated.\n *\n * Overridable via the `LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT`\n * environment variable. Read lazily so test/runtime overrides take effect.\n *\n * @remarks Beta.\n */\nexport function getDeltaMaxSuperstepsSinceSnapshot(): number {\n const raw =\n typeof process !== \"undefined\"\n ? process.env?.LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT\n : undefined;\n if (raw !== undefined && raw !== \"\") {\n const parsed = Number.parseInt(raw, 10);\n if (Number.isFinite(parsed) && parsed > 0) return parsed;\n }\n return 5000;\n}\n\nexport const CONFIG_KEY_SEND = \"__pregel_send\";\n/** config key containing function used to call a node (push task) */\nexport const CONFIG_KEY_CALL = \"__pregel_call\";\nexport const CONFIG_KEY_READ = \"__pregel_read\";\nexport const CONFIG_KEY_CHECKPOINTER = \"__pregel_checkpointer\";\nexport const CONFIG_KEY_RESUMING = \"__pregel_resuming\";\nexport const CONFIG_KEY_TASK_ID = \"__pregel_task_id\";\nexport const CONFIG_KEY_STREAM = \"__pregel_stream\";\nexport const CONFIG_KEY_RESUME_VALUE = \"__pregel_resume_value\";\nexport const CONFIG_KEY_RESUME_MAP = \"__pregel_resume_map\";\nexport const CONFIG_KEY_SCRATCHPAD = \"__pregel_scratchpad\";\n/** config key containing state from previous invocation of graph for the given thread */\nexport const CONFIG_KEY_PREVIOUS_STATE = \"__pregel_previous\";\nexport const CONFIG_KEY_DURABILITY = \"__pregel_durability\";\nexport const CONFIG_KEY_CHECKPOINT_ID = \"checkpoint_id\";\nexport const CONFIG_KEY_CHECKPOINT_NS = \"checkpoint_ns\";\n\nexport const CONFIG_KEY_NODE_FINISHED = \"__pregel_node_finished\";\n\n/**\n * Config key holding a {@link NodeError} (failed source node + error) for the\n * current node-level error handler invocation. Injected when an error handler\n * task is prepared after the failing node's retry policy is exhausted.\n */\nexport const CONFIG_KEY_NODE_ERROR = \"__pregel_node_error\";\n\n// this one is part of public API\nexport const CONFIG_KEY_CHECKPOINT_MAP = \"checkpoint_map\";\n\nexport const CONFIG_KEY_REPLAY_STATE = \"__pregel_replay_state\";\n\nexport const CONFIG_KEY_ABORT_SIGNALS = \"__pregel_abort_signals\";\n\n/** Special channel reserved for graph interrupts */\nexport const INTERRUPT = \"__interrupt__\";\n/** Special channel reserved for graph resume */\nexport const RESUME = \"__resume__\";\n/** Special channel reserved for cases when a task exits without any writes */\nexport const NO_WRITES = \"__no_writes__\";\n/** Special channel reserved for graph return */\nexport const RETURN = \"__return__\";\n/** Special channel reserved for graph previous state */\nexport const PREVIOUS = \"__previous__\";\nexport const RUNTIME_PLACEHOLDER = \"__pregel_runtime_placeholder__\";\nexport const RECURSION_LIMIT_DEFAULT = 25;\n\nexport const TAG_HIDDEN = \"langsmith:hidden\";\nexport const TAG_NOSTREAM = \"langsmith:nostream\";\nexport const SELF = \"__self__\";\n\nexport const TASKS = \"__pregel_tasks\";\nexport const PUSH = \"__pregel_push\";\nexport const PULL = \"__pregel_pull\";\n\nexport const TASK_NAMESPACE = \"6ba7b831-9dad-11d1-80b4-00c04fd430c8\";\nexport const NULL_TASK_ID = \"00000000-0000-0000-0000-000000000000\";\n\nexport const RESERVED = [\n TAG_HIDDEN,\n INPUT,\n INTERRUPT,\n RESUME,\n ERROR,\n ERROR_SOURCE_NODE,\n NO_WRITES,\n\n // reserved config.configurable keys\n CONFIG_KEY_SEND,\n CONFIG_KEY_READ,\n CONFIG_KEY_CHECKPOINTER,\n CONFIG_KEY_DURABILITY,\n CONFIG_KEY_STREAM,\n CONFIG_KEY_RESUMING,\n CONFIG_KEY_TASK_ID,\n CONFIG_KEY_CALL,\n CONFIG_KEY_RESUME_VALUE,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_PREVIOUS_STATE,\n CONFIG_KEY_CHECKPOINT_MAP,\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_CHECKPOINT_ID,\n CONFIG_KEY_REPLAY_STATE,\n];\n\nexport const CHECKPOINT_NAMESPACE_SEPARATOR = \"|\";\nexport const CHECKPOINT_NAMESPACE_END = \":\";\n\n/**\n * Symbol used internally to identify Command instances.\n * Exported to support cross-version type compatibility.\n * @internal\n */\nexport const COMMAND_SYMBOL = Symbol.for(\"langgraph.command\");\n\n/**\n * Instance of a {@link Command} class.\n *\n * This is used to avoid IntelliSense suggesting public fields\n * of {@link Command} class when a plain object is expected.\n *\n * @see {@link Command}\n * @internal\n */\nexport class CommandInstance<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> {\n [COMMAND_SYMBOL]: CommandParams<Resume, Update, Nodes>;\n\n constructor(args: CommandParams<Resume, Update, Nodes>) {\n this[COMMAND_SYMBOL] = args;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SendInterface<Node extends string = string, Args = any> {\n node: Node;\n args: Args;\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task.\n */\n timeout?: TimeoutPolicy;\n}\n\n/** Keyword options for {@link Send}. */\nexport type SendOptions = {\n /**\n * Per-task timeout policy overriding the target node's timeout for this\n * pushed task. A bare number is treated as `runTimeout` (milliseconds).\n */\n timeout?: number | TimeoutPolicy;\n};\n\nexport function _isSendInterface(x: unknown): x is SendInterface {\n const operation = x as SendInterface;\n return (\n operation !== null &&\n operation !== undefined &&\n typeof operation.node === \"string\" &&\n operation.args !== undefined\n );\n}\n\n/**\n *\n * A message or packet to send to a specific node in the graph.\n *\n * The `Send` class is used within a `StateGraph`'s conditional edges to\n * dynamically invoke a node with a custom state at the next step.\n *\n * Importantly, the sent state can differ from the core graph's state,\n * allowing for flexible and dynamic workflow management.\n *\n * One such example is a \"map-reduce\" workflow where your graph invokes\n * the same node multiple times in parallel with different states,\n * before aggregating the results back into the main graph's state.\n *\n * @example\n * ```typescript\n * import { Annotation, Send, StateGraph } from \"@langchain/langgraph\";\n *\n * const ChainState = Annotation.Root({\n * subjects: Annotation<string[]>,\n * jokes: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * }),\n * });\n *\n * const continueToJokes = async (state: typeof ChainState.State) => {\n * return state.subjects.map((subject) => {\n * return new Send(\"generate_joke\", { subjects: [subject] });\n * });\n * };\n *\n * @remarks\n * A per-task timeout can be supplied via the third argument's `timeout` option\n * to override the target node's configured timeout for this specific pushed task:\n *\n * ```typescript\n * new Send(\"generate_joke\", { subjects: [subject] }, { timeout: { idleTimeout: 5000 } });\n * ```\n *\n * const graph = new StateGraph(ChainState)\n * .addNode(\"generate_joke\", (state) => ({\n * jokes: [`Joke about ${state.subjects}`],\n * }))\n * .addConditionalEdges(\"__start__\", continueToJokes)\n * .addEdge(\"generate_joke\", \"__end__\")\n * .compile();\n *\n * const res = await graph.invoke({ subjects: [\"cats\", \"dogs\"] });\n * console.log(res);\n *\n * // Invoking with two subjects results in a generated joke for each\n * // { subjects: [\"cats\", \"dogs\"], jokes: [`Joke about cats`, `Joke about dogs`] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Send<\n Node extends string = string,\n Args = any,\n> implements SendInterface<Node, Args> {\n lg_name = \"Send\";\n\n public node: Node;\n\n public args: Args;\n\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task. A bare number is treated as a hard\n * `runTimeout` (in milliseconds).\n */\n public timeout?: TimeoutPolicy;\n\n constructor(node: Node, args: Args, options?: SendOptions) {\n this.node = node;\n this.args = _deserializeCommandSendObjectGraph(args) as Args;\n this.timeout = coerceTimeoutPolicy(options?.timeout);\n }\n\n toJSON() {\n return {\n lg_name: this.lg_name,\n node: this.node,\n args: this.args,\n timeout: this.timeout,\n };\n }\n}\n\nexport function _isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n\nexport const OVERWRITE = \"__overwrite__\";\n\n/**\n * An object representing a direct overwrite of a value for a channel.\n * Used to signal that the channel value should be replaced with the given value,\n * bypassing any reducer or binary operator logic.\n *\n * @template ValueType - The type of the value being overwritten.\n * @property {ValueType} [OVERWRITE] - The value to directly set.\n *\n * @example\n * const overwriteObj: OverwriteValue<number> = { __overwrite__: 123 };\n */\nexport interface OverwriteValue<ValueType> {\n [OVERWRITE]: ValueType;\n}\n\n/**\n * Bypass a reducer and write the wrapped value directly to a\n * {@link BinaryOperatorAggregate} channel.\n *\n * Receiving multiple `Overwrite` values for the same channel in a single\n * super-step will raise an {@link InvalidUpdateError}.\n *\n * @example\n * ```typescript\n * import { Annotation, StateGraph, Overwrite } from \"@langchain/langgraph\";\n *\n * const State = Annotation.Root({\n * messages: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * default: () => [],\n * }),\n * });\n *\n * const replaceMessages = (_state: typeof State.State) => {\n * return { messages: new Overwrite([\"replacement\"]) };\n * };\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Overwrite<ValueType = any> implements OverwriteValue<ValueType> {\n lg_name = \"Overwrite\";\n\n readonly [OVERWRITE]: ValueType;\n\n constructor(value: ValueType) {\n this[OVERWRITE] = value;\n }\n\n get value(): ValueType {\n return this[OVERWRITE];\n }\n\n toJSON() {\n return { [OVERWRITE]: this[OVERWRITE] };\n }\n\n static isInstance<ValueType>(value: unknown): value is Overwrite<ValueType> {\n if (!value || typeof value !== \"object\") return false;\n if (OVERWRITE in value) return true;\n if (\"lg_name\" in value && value.lg_name === \"Overwrite\") return true;\n return false;\n }\n}\n\n/**\n * Helper function to detect and extract the value from an Overwrite wrapper,\n * supporting both the Overwrite class instance and the serialized object format.\n *\n * Use to check if a provided value represents an Overwrite: returns the\n * unwrapped value if so, or undefined otherwise.\n *\n * - If the value is an Overwrite instance (preferred API), return its `.value`.\n * - If the value is a wire-format object ({ [OVERWRITE]: value }), extract it.\n * - If the value is the discriminator form ({ type: OVERWRITE, value }) that\n * results from JSON-serializing a typed `Overwrite` in another runtime (e.g.\n * a Python dataclass routed through the LangGraph API server, where the typed\n * instance is erased), extract it. Keeps Overwrite semantics intact across\n * cross-runtime JSON boundaries.\n * - Otherwise, returns undefined.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns The unwrapped value if value is an Overwrite, or undefined otherwise.\n * @internal\n */\nexport function _getOverwriteValue<ValueType>(\n value: unknown\n): [true, ValueType] | [false, undefined] {\n if (typeof value === \"object\" && value !== null) {\n if (OVERWRITE in value) {\n return [true, (value as Record<string, ValueType>)[OVERWRITE]];\n }\n const rec = value as Record<string, unknown>;\n if (rec.type === OVERWRITE && \"value\" in rec) {\n return [true, rec.value as ValueType];\n }\n }\n return [false, undefined];\n}\n\n/**\n * Type guard to check if a value is an Overwrite value -- either the class\n * instance or the wire format object.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns `true` if the value is an Overwrite value, `false` otherwise.\n * @internal\n */\nexport function _isOverwriteValue<ValueType>(\n value: unknown\n): value is OverwriteValue<ValueType> {\n return _getOverwriteValue<ValueType>(value)[0];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Interrupt<Value = any> = {\n id?: string;\n value?: Value;\n};\n\n/**\n * Checks if the given graph invoke / stream chunk contains interrupt.\n *\n * @example\n * ```ts\n * import { INTERRUPT, isInterrupted } from \"@langchain/langgraph\";\n *\n * const values = await graph.invoke({ foo: \"bar\" });\n * if (isInterrupted<string>(values)) {\n * const interrupt = values[INTERRUPT][0].value;\n * }\n * ```\n *\n * @param values - The values to check.\n * @returns `true` if the values contain an interrupt, `false` otherwise.\n */\nexport function isInterrupted<Value = unknown>(\n values: unknown\n): values is { [INTERRUPT]: Interrupt<Value>[] } {\n if (!values || typeof values !== \"object\") return false;\n if (!(INTERRUPT in values)) return false;\n return Array.isArray(values[INTERRUPT]);\n}\n\nexport type CommandParams<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> = {\n /**\n * A discriminator field used to identify the type of object. Must be populated when serializing.\n *\n * Optional because it's not required to specify this when directly constructing a {@link Command}\n * object.\n */\n lg_name?: \"Command\";\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - `Send` object (to execute a node with the input provided)\n * - sequence of `Send` objects\n */\n goto?:\n | Nodes\n | SendInterface<Nodes> // eslint-disable-line @typescript-eslint/no-explicit-any\n | (Nodes | SendInterface<Nodes>)[]; // eslint-disable-line @typescript-eslint/no-explicit-any\n};\n\n/**\n * One or more commands to update the graph's state and send messages to nodes.\n * Can be used to combine routing logic with state updates in lieu of conditional edges\n *\n * @example\n * ```ts\n * import { Annotation, Command } from \"@langchain/langgraph\";\n *\n * // Define graph state\n * const StateAnnotation = Annotation.Root({\n * foo: Annotation<string>,\n * });\n *\n * // Define the nodes\n * const nodeA = async (_state: typeof StateAnnotation.State) => {\n * console.log(\"Called A\");\n * // this is a replacement for a real conditional edge function\n * const goto = Math.random() > .5 ? \"nodeB\" : \"nodeC\";\n * // note how Command allows you to BOTH update the graph state AND route to the next node\n * return new Command({\n * // this is the state update\n * update: {\n * foo: \"a\",\n * },\n * // this is a replacement for an edge\n * goto,\n * });\n * };\n *\n * // Nodes B and C are unchanged\n * const nodeB = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called B\");\n * return {\n * foo: state.foo + \"|b\",\n * };\n * }\n *\n * const nodeC = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called C\");\n * return {\n * foo: state.foo + \"|c\",\n * };\n * }\n * \n * import { StateGraph } from \"@langchain/langgraph\";\n\n * // NOTE: there are no edges between nodes A, B and C!\n * const graph = new StateGraph(StateAnnotation)\n * .addNode(\"nodeA\", nodeA, {\n * ends: [\"nodeB\", \"nodeC\"],\n * })\n * .addNode(\"nodeB\", nodeB)\n * .addNode(\"nodeC\", nodeC)\n * .addEdge(\"__start__\", \"nodeA\")\n * .compile();\n * \n * await graph.invoke({ foo: \"\" });\n *\n * // Randomly oscillates between\n * // { foo: 'a|c' } and { foo: 'a|b' }\n * ```\n */\nexport class Command<\n Resume = unknown,\n Update extends Record<string, unknown> = Record<string, unknown>,\n Nodes extends string = string,\n> extends CommandInstance<Resume, Update, Nodes> {\n readonly lg_name = \"Command\";\n\n lc_direct_tool_output = true;\n\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state as a result of executing the node that is returning the command.\n * Written to the state as if the node had simply returned this value instead of the Command object.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)\n * - sequence of {@link Send} objects\n */\n goto?: Nodes | Send<Nodes> | (Nodes | Send<Nodes>)[] = [];\n\n static PARENT = \"__parent__\";\n\n constructor(args: Omit<CommandParams<Resume, Update, Nodes>, \"lg_name\">) {\n super(args);\n this.resume = args.resume;\n this.graph = args.graph;\n this.update = args.update;\n if (args.goto) {\n type ValidArg = Nodes | Send<Nodes, Update>;\n\n this.goto = Array.isArray(args.goto)\n ? (_deserializeCommandSendObjectGraph(args.goto) as ValidArg[])\n : [_deserializeCommandSendObjectGraph(args.goto) as ValidArg];\n }\n }\n\n /**\n * Convert the update field to a list of {@link PendingWrite} tuples\n * @returns List of {@link PendingWrite} tuples of the form `[channelKey, value]`.\n * @internal\n */\n _updateAsTuples(): PendingWrite[] {\n if (\n this.update &&\n typeof this.update === \"object\" &&\n !Array.isArray(this.update)\n ) {\n return Object.entries(this.update);\n } else if (\n Array.isArray(this.update) &&\n this.update.every(\n (t): t is [string, unknown] =>\n Array.isArray(t) && t.length === 2 && typeof t[0] === \"string\"\n )\n ) {\n return this.update;\n } else {\n return [[\"__root__\", this.update]];\n }\n }\n\n toJSON() {\n let serializedGoto;\n if (typeof this.goto === \"string\") {\n serializedGoto = this.goto;\n } else if (_isSend(this.goto)) {\n serializedGoto = this.goto.toJSON();\n } else {\n serializedGoto = this.goto?.map((innerGoto) => {\n if (typeof innerGoto === \"string\") {\n return innerGoto;\n } else {\n return innerGoto.toJSON();\n }\n });\n }\n return {\n lg_name: this.lg_name,\n update: this.update,\n resume: this.resume,\n goto: serializedGoto,\n };\n }\n}\n\n/**\n * A type guard to check if the given value is a {@link Command}.\n *\n * Useful for type narrowing when working with the {@link Command} object.\n *\n * @param x - The value to check.\n * @returns `true` if the value is a {@link Command}, `false` otherwise.\n */\nexport function isCommand(x: unknown): x is Command {\n if (typeof x !== \"object\") {\n return false;\n }\n\n if (x === null || x === undefined) {\n return false;\n }\n\n if (\"lg_name\" in x && x.lg_name === \"Command\") {\n return true;\n }\n\n return false;\n}\n\nfunction isPlainObject(value: object): value is Record<string, unknown> {\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Reconstructs Command and Send objects from a deeply nested tree of anonymous objects\n * matching their interfaces.\n *\n * This is only exported for testing purposes. It is NOT intended to be used outside of\n * the Command and Send classes.\n *\n * @internal\n *\n * @param x - The command send tree to convert.\n * @param seen - A map of seen objects to avoid infinite loops.\n * @returns The converted command send tree.\n */\nexport function _deserializeCommandSendObjectGraph(\n x: unknown,\n seen: Map<object, unknown> = new Map()\n): unknown {\n if (x !== undefined && x !== null && typeof x === \"object\") {\n // If we've already processed this object, return the transformed version\n if (seen.has(x)) {\n return seen.get(x);\n }\n\n let result: unknown;\n\n if (Array.isArray(x)) {\n // Create the array first, then populate it\n result = [];\n // Add to seen map before processing elements to handle self-references\n seen.set(x, result);\n\n // Now populate the array\n x.forEach((item, index) => {\n (result as unknown[])[index] = _deserializeCommandSendObjectGraph(\n item,\n seen\n );\n });\n // eslint-disable-next-line no-instanceof/no-instanceof\n } else if (x instanceof Command || x instanceof Send || !isPlainObject(x)) {\n result = x;\n seen.set(x, result);\n } else if (isCommand(x)) {\n result = new Command(x);\n seen.set(x, result);\n } else if (_isSendInterface(x)) {\n result = new Send(\n x.node,\n x.args,\n x.timeout !== undefined ? { timeout: x.timeout } : undefined\n );\n seen.set(x, result);\n } else if (\"lc_serializable\" in x && x.lc_serializable) {\n result = x;\n seen.set(x, result);\n } else {\n // Create empty object first\n result = {};\n // Add to seen map before processing properties to handle self-references\n seen.set(x, result);\n\n // Now populate the object\n for (const [key, value] of Object.entries(x)) {\n (result as Record<string, unknown>)[key] =\n _deserializeCommandSendObjectGraph(value, seen);\n }\n }\n\n return result;\n }\n return x;\n}\n"],"mappings":";;;AAOA,MAAa,QAAQ;;AAErB,MAAa,MAAM;AACnB,MAAa,QAAQ;AACrB,MAAa,OAAO;AACpB,MAAa,QAAQ;;;;;;;AAOrB,MAAa,oBAAoB;;AAGjC,MAAa,kBAAkB;;;;;;;;;;;;;;AAe/B,SAAgB,qCAA6C;CAC3D,MAAM,MACJ,OAAO,YAAY,cACf,QAAQ,KAAK,gDACb,KAAA;AACN,KAAI,QAAQ,KAAA,KAAa,QAAQ,IAAI;EACnC,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;AACvC,MAAI,OAAO,SAAS,OAAO,IAAI,SAAS,EAAG,QAAO;;AAEpD,QAAO;;AAGT,MAAa,kBAAkB;;AAE/B,MAAa,kBAAkB;AAC/B,MAAa,kBAAkB;AAC/B,MAAa,0BAA0B;AACvC,MAAa,sBAAsB;AACnC,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AACjC,MAAa,0BAA0B;AACvC,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;;AAErC,MAAa,4BAA4B;AACzC,MAAa,wBAAwB;AACrC,MAAa,2BAA2B;AACxC,MAAa,2BAA2B;AAExC,MAAa,2BAA2B;;;;;;AAOxC,MAAa,wBAAwB;AAGrC,MAAa,4BAA4B;AAEzC,MAAa,0BAA0B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|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;cAOa,KAAA;AAAb;AAAA,cAEa,GAAA;;cA0EA,SAAA;;cAQA,QAAA;;;;AA8Jb;;cA5Ga,cAAA;;;;;;;;;;cAWA,eAAA,4BAEF,MAAA;EAAA,CAGR,cAAA,GAAiB,aAAA,CAAc,MAAA,EAAQ,MAAA,EAAQ,KAAA;EAEhD,WAAA,CAAY,IAAA,EAAM,aAAA,CAAc,MAAA,EAAQ,MAAA,EAAQ,KAAA;AAAA;AAAA,UAMjC,aAAA;EACf,IAAA,EAAM,IAAA;EACN,IAAA,EAAM,IAAA;EAqFK;;;;EAhFX,OAAA,GAAU,aAAA;AAAA;;KAIA,WAAA;EAwFH;;;;EAnFP,OAAA,YAAmB,aAAA;AAAA;;;;;;;;;;;;;AA0GrB;;;;;AAaA;;;;;;;;;AA4BA;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA/Ea,IAAA,sDAGA,aAAA,CAAc,IAAA,EAAM,IAAA;EAC/B,OAAA;EAEO,IAAA,EAAM,IAAA;EAEN,IAAA,EAAM,IAAA;EAwF0C;;;;
|
|
1
|
+
{"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;;;cAOa,KAAA;AAAb;AAAA,cAEa,GAAA;;cA0EA,SAAA;;cAQA,QAAA;;;;AA8Jb;;cA5Ga,cAAA;;;;;;;;;;cAWA,eAAA,4BAEF,MAAA;EAAA,CAGR,cAAA,GAAiB,aAAA,CAAc,MAAA,EAAQ,MAAA,EAAQ,KAAA;EAEhD,WAAA,CAAY,IAAA,EAAM,aAAA,CAAc,MAAA,EAAQ,MAAA,EAAQ,KAAA;AAAA;AAAA,UAMjC,aAAA;EACf,IAAA,EAAM,IAAA;EACN,IAAA,EAAM,IAAA;EAqFK;;;;EAhFX,OAAA,GAAU,aAAA;AAAA;;KAIA,WA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;;;;;;;;;;;;;;;;;;cA9Ga,OAAA,kCAEI,MAAA,oBAA0B,MAAA,0DAEjC,eAAA,CAAgB,MAAA,EAAQ,MAAA,EAAQ,KAAA;EAAA,SAC/B,OAAA;EAET,qBAAA;;;;;;;EAQA,KAAA;;;;;EAMA,MAAA,GAAS,MAAA;;;;EAKT,MAAA,GAAS,MAAA;;;;;;;;EAST,IAAA,GAAO,KAAA,GAAQ,IAAA,CAAK,KAAA,KAAU,KAAA,GAAQ,IAAA,CAAK,KAAA;EAAA,OAEpC,MAAA;EAEP,WAAA,CAAY,IAAA,EAAM,IAAA,CAAK,aAAA,CAAc,MAAA,EAAQ,MAAA,EAAQ,KAAA;;;;;;EAmBrD,eAAA,CAAA,GAAmB,YAAA;EAoBnB,MAAA,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;iBAgCc,SAAA,CAAU,CAAA,YAAa,CAAA,IAAK,OAAA"}
|
package/dist/constants.js
CHANGED
|
@@ -262,6 +262,11 @@ var Overwrite = class {
|
|
|
262
262
|
*
|
|
263
263
|
* - If the value is an Overwrite instance (preferred API), return its `.value`.
|
|
264
264
|
* - If the value is a wire-format object ({ [OVERWRITE]: value }), extract it.
|
|
265
|
+
* - If the value is the discriminator form ({ type: OVERWRITE, value }) that
|
|
266
|
+
* results from JSON-serializing a typed `Overwrite` in another runtime (e.g.
|
|
267
|
+
* a Python dataclass routed through the LangGraph API server, where the typed
|
|
268
|
+
* instance is erased), extract it. Keeps Overwrite semantics intact across
|
|
269
|
+
* cross-runtime JSON boundaries.
|
|
265
270
|
* - Otherwise, returns undefined.
|
|
266
271
|
*
|
|
267
272
|
* @template ValueType - The expected type of the Overwrite value.
|
|
@@ -270,7 +275,11 @@ var Overwrite = class {
|
|
|
270
275
|
* @internal
|
|
271
276
|
*/
|
|
272
277
|
function _getOverwriteValue(value) {
|
|
273
|
-
if (typeof value === "object" && value !== null
|
|
278
|
+
if (typeof value === "object" && value !== null) {
|
|
279
|
+
if ("__overwrite__" in value) return [true, value[OVERWRITE]];
|
|
280
|
+
const rec = value;
|
|
281
|
+
if (rec.type === "__overwrite__" && "value" in rec) return [true, rec.value];
|
|
282
|
+
}
|
|
274
283
|
return [false, void 0];
|
|
275
284
|
}
|
|
276
285
|
/**
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n coerceTimeoutPolicy,\n type TimeoutPolicy,\n} from \"./pregel/utils/timeout.js\";\n\n/** Special reserved node name denoting the start of a graph. */\nexport const START = \"__start__\";\n/** Special reserved node name denoting the end of a graph. */\nexport const END = \"__end__\";\nexport const INPUT = \"__input__\";\nexport const COPY = \"__copy__\";\nexport const ERROR = \"__error__\";\n/**\n * Special reserved write key recording the name of the node whose execution\n * failed, so node-level error handlers see the same failure provenance after a\n * checkpoint resume. Value format in pending writes:\n * `[taskId, ERROR_SOURCE_NODE, nodeName: string]`.\n */\nexport const ERROR_SOURCE_NODE = \"__error_source_node__\";\n\n/** Special reserved cache namespaces */\nexport const CACHE_NS_WRITES = \"__pregel_ns_writes\";\n\n/**\n * System-wide upper bound on how many supersteps a {@link DeltaChannel} may go\n * without writing a {@link DeltaSnapshot} blob. Once a channel's\n * supersteps-since-snapshot counter reaches this value, a snapshot is forced\n * even if the channel's own `snapshotFrequency` has not been reached — this\n * prevents unbounded ancestor walks on threads where a delta channel exists\n * but is no longer being updated.\n *\n * Overridable via the `LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT`\n * environment variable. Read lazily so test/runtime overrides take effect.\n *\n * @remarks Beta.\n */\nexport function getDeltaMaxSuperstepsSinceSnapshot(): number {\n const raw =\n typeof process !== \"undefined\"\n ? process.env?.LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT\n : undefined;\n if (raw !== undefined && raw !== \"\") {\n const parsed = Number.parseInt(raw, 10);\n if (Number.isFinite(parsed) && parsed > 0) return parsed;\n }\n return 5000;\n}\n\nexport const CONFIG_KEY_SEND = \"__pregel_send\";\n/** config key containing function used to call a node (push task) */\nexport const CONFIG_KEY_CALL = \"__pregel_call\";\nexport const CONFIG_KEY_READ = \"__pregel_read\";\nexport const CONFIG_KEY_CHECKPOINTER = \"__pregel_checkpointer\";\nexport const CONFIG_KEY_RESUMING = \"__pregel_resuming\";\nexport const CONFIG_KEY_TASK_ID = \"__pregel_task_id\";\nexport const CONFIG_KEY_STREAM = \"__pregel_stream\";\nexport const CONFIG_KEY_RESUME_VALUE = \"__pregel_resume_value\";\nexport const CONFIG_KEY_RESUME_MAP = \"__pregel_resume_map\";\nexport const CONFIG_KEY_SCRATCHPAD = \"__pregel_scratchpad\";\n/** config key containing state from previous invocation of graph for the given thread */\nexport const CONFIG_KEY_PREVIOUS_STATE = \"__pregel_previous\";\nexport const CONFIG_KEY_DURABILITY = \"__pregel_durability\";\nexport const CONFIG_KEY_CHECKPOINT_ID = \"checkpoint_id\";\nexport const CONFIG_KEY_CHECKPOINT_NS = \"checkpoint_ns\";\n\nexport const CONFIG_KEY_NODE_FINISHED = \"__pregel_node_finished\";\n\n/**\n * Config key holding a {@link NodeError} (failed source node + error) for the\n * current node-level error handler invocation. Injected when an error handler\n * task is prepared after the failing node's retry policy is exhausted.\n */\nexport const CONFIG_KEY_NODE_ERROR = \"__pregel_node_error\";\n\n// this one is part of public API\nexport const CONFIG_KEY_CHECKPOINT_MAP = \"checkpoint_map\";\n\nexport const CONFIG_KEY_REPLAY_STATE = \"__pregel_replay_state\";\n\nexport const CONFIG_KEY_ABORT_SIGNALS = \"__pregel_abort_signals\";\n\n/** Special channel reserved for graph interrupts */\nexport const INTERRUPT = \"__interrupt__\";\n/** Special channel reserved for graph resume */\nexport const RESUME = \"__resume__\";\n/** Special channel reserved for cases when a task exits without any writes */\nexport const NO_WRITES = \"__no_writes__\";\n/** Special channel reserved for graph return */\nexport const RETURN = \"__return__\";\n/** Special channel reserved for graph previous state */\nexport const PREVIOUS = \"__previous__\";\nexport const RUNTIME_PLACEHOLDER = \"__pregel_runtime_placeholder__\";\nexport const RECURSION_LIMIT_DEFAULT = 25;\n\nexport const TAG_HIDDEN = \"langsmith:hidden\";\nexport const TAG_NOSTREAM = \"langsmith:nostream\";\nexport const SELF = \"__self__\";\n\nexport const TASKS = \"__pregel_tasks\";\nexport const PUSH = \"__pregel_push\";\nexport const PULL = \"__pregel_pull\";\n\nexport const TASK_NAMESPACE = \"6ba7b831-9dad-11d1-80b4-00c04fd430c8\";\nexport const NULL_TASK_ID = \"00000000-0000-0000-0000-000000000000\";\n\nexport const RESERVED = [\n TAG_HIDDEN,\n INPUT,\n INTERRUPT,\n RESUME,\n ERROR,\n ERROR_SOURCE_NODE,\n NO_WRITES,\n\n // reserved config.configurable keys\n CONFIG_KEY_SEND,\n CONFIG_KEY_READ,\n CONFIG_KEY_CHECKPOINTER,\n CONFIG_KEY_DURABILITY,\n CONFIG_KEY_STREAM,\n CONFIG_KEY_RESUMING,\n CONFIG_KEY_TASK_ID,\n CONFIG_KEY_CALL,\n CONFIG_KEY_RESUME_VALUE,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_PREVIOUS_STATE,\n CONFIG_KEY_CHECKPOINT_MAP,\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_CHECKPOINT_ID,\n CONFIG_KEY_REPLAY_STATE,\n];\n\nexport const CHECKPOINT_NAMESPACE_SEPARATOR = \"|\";\nexport const CHECKPOINT_NAMESPACE_END = \":\";\n\n/**\n * Symbol used internally to identify Command instances.\n * Exported to support cross-version type compatibility.\n * @internal\n */\nexport const COMMAND_SYMBOL = Symbol.for(\"langgraph.command\");\n\n/**\n * Instance of a {@link Command} class.\n *\n * This is used to avoid IntelliSense suggesting public fields\n * of {@link Command} class when a plain object is expected.\n *\n * @see {@link Command}\n * @internal\n */\nexport class CommandInstance<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> {\n [COMMAND_SYMBOL]: CommandParams<Resume, Update, Nodes>;\n\n constructor(args: CommandParams<Resume, Update, Nodes>) {\n this[COMMAND_SYMBOL] = args;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SendInterface<Node extends string = string, Args = any> {\n node: Node;\n args: Args;\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task.\n */\n timeout?: TimeoutPolicy;\n}\n\n/** Keyword options for {@link Send}. */\nexport type SendOptions = {\n /**\n * Per-task timeout policy overriding the target node's timeout for this\n * pushed task. A bare number is treated as `runTimeout` (milliseconds).\n */\n timeout?: number | TimeoutPolicy;\n};\n\nexport function _isSendInterface(x: unknown): x is SendInterface {\n const operation = x as SendInterface;\n return (\n operation !== null &&\n operation !== undefined &&\n typeof operation.node === \"string\" &&\n operation.args !== undefined\n );\n}\n\n/**\n *\n * A message or packet to send to a specific node in the graph.\n *\n * The `Send` class is used within a `StateGraph`'s conditional edges to\n * dynamically invoke a node with a custom state at the next step.\n *\n * Importantly, the sent state can differ from the core graph's state,\n * allowing for flexible and dynamic workflow management.\n *\n * One such example is a \"map-reduce\" workflow where your graph invokes\n * the same node multiple times in parallel with different states,\n * before aggregating the results back into the main graph's state.\n *\n * @example\n * ```typescript\n * import { Annotation, Send, StateGraph } from \"@langchain/langgraph\";\n *\n * const ChainState = Annotation.Root({\n * subjects: Annotation<string[]>,\n * jokes: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * }),\n * });\n *\n * const continueToJokes = async (state: typeof ChainState.State) => {\n * return state.subjects.map((subject) => {\n * return new Send(\"generate_joke\", { subjects: [subject] });\n * });\n * };\n *\n * @remarks\n * A per-task timeout can be supplied via the third argument's `timeout` option\n * to override the target node's configured timeout for this specific pushed task:\n *\n * ```typescript\n * new Send(\"generate_joke\", { subjects: [subject] }, { timeout: { idleTimeout: 5000 } });\n * ```\n *\n * const graph = new StateGraph(ChainState)\n * .addNode(\"generate_joke\", (state) => ({\n * jokes: [`Joke about ${state.subjects}`],\n * }))\n * .addConditionalEdges(\"__start__\", continueToJokes)\n * .addEdge(\"generate_joke\", \"__end__\")\n * .compile();\n *\n * const res = await graph.invoke({ subjects: [\"cats\", \"dogs\"] });\n * console.log(res);\n *\n * // Invoking with two subjects results in a generated joke for each\n * // { subjects: [\"cats\", \"dogs\"], jokes: [`Joke about cats`, `Joke about dogs`] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Send<\n Node extends string = string,\n Args = any,\n> implements SendInterface<Node, Args> {\n lg_name = \"Send\";\n\n public node: Node;\n\n public args: Args;\n\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task. A bare number is treated as a hard\n * `runTimeout` (in milliseconds).\n */\n public timeout?: TimeoutPolicy;\n\n constructor(node: Node, args: Args, options?: SendOptions) {\n this.node = node;\n this.args = _deserializeCommandSendObjectGraph(args) as Args;\n this.timeout = coerceTimeoutPolicy(options?.timeout);\n }\n\n toJSON() {\n return {\n lg_name: this.lg_name,\n node: this.node,\n args: this.args,\n timeout: this.timeout,\n };\n }\n}\n\nexport function _isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n\nexport const OVERWRITE = \"__overwrite__\";\n\n/**\n * An object representing a direct overwrite of a value for a channel.\n * Used to signal that the channel value should be replaced with the given value,\n * bypassing any reducer or binary operator logic.\n *\n * @template ValueType - The type of the value being overwritten.\n * @property {ValueType} [OVERWRITE] - The value to directly set.\n *\n * @example\n * const overwriteObj: OverwriteValue<number> = { __overwrite__: 123 };\n */\nexport interface OverwriteValue<ValueType> {\n [OVERWRITE]: ValueType;\n}\n\n/**\n * Bypass a reducer and write the wrapped value directly to a\n * {@link BinaryOperatorAggregate} channel.\n *\n * Receiving multiple `Overwrite` values for the same channel in a single\n * super-step will raise an {@link InvalidUpdateError}.\n *\n * @example\n * ```typescript\n * import { Annotation, StateGraph, Overwrite } from \"@langchain/langgraph\";\n *\n * const State = Annotation.Root({\n * messages: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * default: () => [],\n * }),\n * });\n *\n * const replaceMessages = (_state: typeof State.State) => {\n * return { messages: new Overwrite([\"replacement\"]) };\n * };\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Overwrite<ValueType = any> implements OverwriteValue<ValueType> {\n lg_name = \"Overwrite\";\n\n readonly [OVERWRITE]: ValueType;\n\n constructor(value: ValueType) {\n this[OVERWRITE] = value;\n }\n\n get value(): ValueType {\n return this[OVERWRITE];\n }\n\n toJSON() {\n return { [OVERWRITE]: this[OVERWRITE] };\n }\n\n static isInstance<ValueType>(value: unknown): value is Overwrite<ValueType> {\n if (!value || typeof value !== \"object\") return false;\n if (OVERWRITE in value) return true;\n if (\"lg_name\" in value && value.lg_name === \"Overwrite\") return true;\n return false;\n }\n}\n\n/**\n * Helper function to detect and extract the value from an Overwrite wrapper,\n * supporting both the Overwrite class instance and the serialized object format.\n *\n * Use to check if a provided value represents an Overwrite: returns the\n * unwrapped value if so, or undefined otherwise.\n *\n * - If the value is an Overwrite instance (preferred API), return its `.value`.\n * - If the value is a wire-format object ({ [OVERWRITE]: value }), extract it.\n * - Otherwise, returns undefined.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns The unwrapped value if value is an Overwrite, or undefined otherwise.\n * @internal\n */\nexport function _getOverwriteValue<ValueType>(\n value: unknown\n): [true, ValueType] | [false, undefined] {\n if (typeof value === \"object\" && value !== null && OVERWRITE in value) {\n return [true, (value as Record<string, ValueType>)[OVERWRITE]];\n }\n return [false, undefined];\n}\n\n/**\n * Type guard to check if a value is an Overwrite value -- either the class\n * instance or the wire format object.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns `true` if the value is an Overwrite value, `false` otherwise.\n * @internal\n */\nexport function _isOverwriteValue<ValueType>(\n value: unknown\n): value is OverwriteValue<ValueType> {\n return _getOverwriteValue<ValueType>(value)[0];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Interrupt<Value = any> = {\n id?: string;\n value?: Value;\n};\n\n/**\n * Checks if the given graph invoke / stream chunk contains interrupt.\n *\n * @example\n * ```ts\n * import { INTERRUPT, isInterrupted } from \"@langchain/langgraph\";\n *\n * const values = await graph.invoke({ foo: \"bar\" });\n * if (isInterrupted<string>(values)) {\n * const interrupt = values[INTERRUPT][0].value;\n * }\n * ```\n *\n * @param values - The values to check.\n * @returns `true` if the values contain an interrupt, `false` otherwise.\n */\nexport function isInterrupted<Value = unknown>(\n values: unknown\n): values is { [INTERRUPT]: Interrupt<Value>[] } {\n if (!values || typeof values !== \"object\") return false;\n if (!(INTERRUPT in values)) return false;\n return Array.isArray(values[INTERRUPT]);\n}\n\nexport type CommandParams<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> = {\n /**\n * A discriminator field used to identify the type of object. Must be populated when serializing.\n *\n * Optional because it's not required to specify this when directly constructing a {@link Command}\n * object.\n */\n lg_name?: \"Command\";\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - `Send` object (to execute a node with the input provided)\n * - sequence of `Send` objects\n */\n goto?:\n | Nodes\n | SendInterface<Nodes> // eslint-disable-line @typescript-eslint/no-explicit-any\n | (Nodes | SendInterface<Nodes>)[]; // eslint-disable-line @typescript-eslint/no-explicit-any\n};\n\n/**\n * One or more commands to update the graph's state and send messages to nodes.\n * Can be used to combine routing logic with state updates in lieu of conditional edges\n *\n * @example\n * ```ts\n * import { Annotation, Command } from \"@langchain/langgraph\";\n *\n * // Define graph state\n * const StateAnnotation = Annotation.Root({\n * foo: Annotation<string>,\n * });\n *\n * // Define the nodes\n * const nodeA = async (_state: typeof StateAnnotation.State) => {\n * console.log(\"Called A\");\n * // this is a replacement for a real conditional edge function\n * const goto = Math.random() > .5 ? \"nodeB\" : \"nodeC\";\n * // note how Command allows you to BOTH update the graph state AND route to the next node\n * return new Command({\n * // this is the state update\n * update: {\n * foo: \"a\",\n * },\n * // this is a replacement for an edge\n * goto,\n * });\n * };\n *\n * // Nodes B and C are unchanged\n * const nodeB = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called B\");\n * return {\n * foo: state.foo + \"|b\",\n * };\n * }\n *\n * const nodeC = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called C\");\n * return {\n * foo: state.foo + \"|c\",\n * };\n * }\n * \n * import { StateGraph } from \"@langchain/langgraph\";\n\n * // NOTE: there are no edges between nodes A, B and C!\n * const graph = new StateGraph(StateAnnotation)\n * .addNode(\"nodeA\", nodeA, {\n * ends: [\"nodeB\", \"nodeC\"],\n * })\n * .addNode(\"nodeB\", nodeB)\n * .addNode(\"nodeC\", nodeC)\n * .addEdge(\"__start__\", \"nodeA\")\n * .compile();\n * \n * await graph.invoke({ foo: \"\" });\n *\n * // Randomly oscillates between\n * // { foo: 'a|c' } and { foo: 'a|b' }\n * ```\n */\nexport class Command<\n Resume = unknown,\n Update extends Record<string, unknown> = Record<string, unknown>,\n Nodes extends string = string,\n> extends CommandInstance<Resume, Update, Nodes> {\n readonly lg_name = \"Command\";\n\n lc_direct_tool_output = true;\n\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state as a result of executing the node that is returning the command.\n * Written to the state as if the node had simply returned this value instead of the Command object.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)\n * - sequence of {@link Send} objects\n */\n goto?: Nodes | Send<Nodes> | (Nodes | Send<Nodes>)[] = [];\n\n static PARENT = \"__parent__\";\n\n constructor(args: Omit<CommandParams<Resume, Update, Nodes>, \"lg_name\">) {\n super(args);\n this.resume = args.resume;\n this.graph = args.graph;\n this.update = args.update;\n if (args.goto) {\n type ValidArg = Nodes | Send<Nodes, Update>;\n\n this.goto = Array.isArray(args.goto)\n ? (_deserializeCommandSendObjectGraph(args.goto) as ValidArg[])\n : [_deserializeCommandSendObjectGraph(args.goto) as ValidArg];\n }\n }\n\n /**\n * Convert the update field to a list of {@link PendingWrite} tuples\n * @returns List of {@link PendingWrite} tuples of the form `[channelKey, value]`.\n * @internal\n */\n _updateAsTuples(): PendingWrite[] {\n if (\n this.update &&\n typeof this.update === \"object\" &&\n !Array.isArray(this.update)\n ) {\n return Object.entries(this.update);\n } else if (\n Array.isArray(this.update) &&\n this.update.every(\n (t): t is [string, unknown] =>\n Array.isArray(t) && t.length === 2 && typeof t[0] === \"string\"\n )\n ) {\n return this.update;\n } else {\n return [[\"__root__\", this.update]];\n }\n }\n\n toJSON() {\n let serializedGoto;\n if (typeof this.goto === \"string\") {\n serializedGoto = this.goto;\n } else if (_isSend(this.goto)) {\n serializedGoto = this.goto.toJSON();\n } else {\n serializedGoto = this.goto?.map((innerGoto) => {\n if (typeof innerGoto === \"string\") {\n return innerGoto;\n } else {\n return innerGoto.toJSON();\n }\n });\n }\n return {\n lg_name: this.lg_name,\n update: this.update,\n resume: this.resume,\n goto: serializedGoto,\n };\n }\n}\n\n/**\n * A type guard to check if the given value is a {@link Command}.\n *\n * Useful for type narrowing when working with the {@link Command} object.\n *\n * @param x - The value to check.\n * @returns `true` if the value is a {@link Command}, `false` otherwise.\n */\nexport function isCommand(x: unknown): x is Command {\n if (typeof x !== \"object\") {\n return false;\n }\n\n if (x === null || x === undefined) {\n return false;\n }\n\n if (\"lg_name\" in x && x.lg_name === \"Command\") {\n return true;\n }\n\n return false;\n}\n\nfunction isPlainObject(value: object): value is Record<string, unknown> {\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Reconstructs Command and Send objects from a deeply nested tree of anonymous objects\n * matching their interfaces.\n *\n * This is only exported for testing purposes. It is NOT intended to be used outside of\n * the Command and Send classes.\n *\n * @internal\n *\n * @param x - The command send tree to convert.\n * @param seen - A map of seen objects to avoid infinite loops.\n * @returns The converted command send tree.\n */\nexport function _deserializeCommandSendObjectGraph(\n x: unknown,\n seen: Map<object, unknown> = new Map()\n): unknown {\n if (x !== undefined && x !== null && typeof x === \"object\") {\n // If we've already processed this object, return the transformed version\n if (seen.has(x)) {\n return seen.get(x);\n }\n\n let result: unknown;\n\n if (Array.isArray(x)) {\n // Create the array first, then populate it\n result = [];\n // Add to seen map before processing elements to handle self-references\n seen.set(x, result);\n\n // Now populate the array\n x.forEach((item, index) => {\n (result as unknown[])[index] = _deserializeCommandSendObjectGraph(\n item,\n seen\n );\n });\n // eslint-disable-next-line no-instanceof/no-instanceof\n } else if (x instanceof Command || x instanceof Send || !isPlainObject(x)) {\n result = x;\n seen.set(x, result);\n } else if (isCommand(x)) {\n result = new Command(x);\n seen.set(x, result);\n } else if (_isSendInterface(x)) {\n result = new Send(\n x.node,\n x.args,\n x.timeout !== undefined ? { timeout: x.timeout } : undefined\n );\n seen.set(x, result);\n } else if (\"lc_serializable\" in x && x.lc_serializable) {\n result = x;\n seen.set(x, result);\n } else {\n // Create empty object first\n result = {};\n // Add to seen map before processing properties to handle self-references\n seen.set(x, result);\n\n // Now populate the object\n for (const [key, value] of Object.entries(x)) {\n (result as Record<string, unknown>)[key] =\n _deserializeCommandSendObjectGraph(value, seen);\n }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AG,OAAO;AAGnB,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,EAAE,CACzC,QAAmC,OAClC,mCAAmC,OAAO,KAAK;;AAIrD,SAAO;;AAET,QAAO"}
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\nimport {\n coerceTimeoutPolicy,\n type TimeoutPolicy,\n} from \"./pregel/utils/timeout.js\";\n\n/** Special reserved node name denoting the start of a graph. */\nexport const START = \"__start__\";\n/** Special reserved node name denoting the end of a graph. */\nexport const END = \"__end__\";\nexport const INPUT = \"__input__\";\nexport const COPY = \"__copy__\";\nexport const ERROR = \"__error__\";\n/**\n * Special reserved write key recording the name of the node whose execution\n * failed, so node-level error handlers see the same failure provenance after a\n * checkpoint resume. Value format in pending writes:\n * `[taskId, ERROR_SOURCE_NODE, nodeName: string]`.\n */\nexport const ERROR_SOURCE_NODE = \"__error_source_node__\";\n\n/** Special reserved cache namespaces */\nexport const CACHE_NS_WRITES = \"__pregel_ns_writes\";\n\n/**\n * System-wide upper bound on how many supersteps a {@link DeltaChannel} may go\n * without writing a {@link DeltaSnapshot} blob. Once a channel's\n * supersteps-since-snapshot counter reaches this value, a snapshot is forced\n * even if the channel's own `snapshotFrequency` has not been reached — this\n * prevents unbounded ancestor walks on threads where a delta channel exists\n * but is no longer being updated.\n *\n * Overridable via the `LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT`\n * environment variable. Read lazily so test/runtime overrides take effect.\n *\n * @remarks Beta.\n */\nexport function getDeltaMaxSuperstepsSinceSnapshot(): number {\n const raw =\n typeof process !== \"undefined\"\n ? process.env?.LANGGRAPH_DELTA_MAX_SUPERSTEPS_SINCE_SNAPSHOT\n : undefined;\n if (raw !== undefined && raw !== \"\") {\n const parsed = Number.parseInt(raw, 10);\n if (Number.isFinite(parsed) && parsed > 0) return parsed;\n }\n return 5000;\n}\n\nexport const CONFIG_KEY_SEND = \"__pregel_send\";\n/** config key containing function used to call a node (push task) */\nexport const CONFIG_KEY_CALL = \"__pregel_call\";\nexport const CONFIG_KEY_READ = \"__pregel_read\";\nexport const CONFIG_KEY_CHECKPOINTER = \"__pregel_checkpointer\";\nexport const CONFIG_KEY_RESUMING = \"__pregel_resuming\";\nexport const CONFIG_KEY_TASK_ID = \"__pregel_task_id\";\nexport const CONFIG_KEY_STREAM = \"__pregel_stream\";\nexport const CONFIG_KEY_RESUME_VALUE = \"__pregel_resume_value\";\nexport const CONFIG_KEY_RESUME_MAP = \"__pregel_resume_map\";\nexport const CONFIG_KEY_SCRATCHPAD = \"__pregel_scratchpad\";\n/** config key containing state from previous invocation of graph for the given thread */\nexport const CONFIG_KEY_PREVIOUS_STATE = \"__pregel_previous\";\nexport const CONFIG_KEY_DURABILITY = \"__pregel_durability\";\nexport const CONFIG_KEY_CHECKPOINT_ID = \"checkpoint_id\";\nexport const CONFIG_KEY_CHECKPOINT_NS = \"checkpoint_ns\";\n\nexport const CONFIG_KEY_NODE_FINISHED = \"__pregel_node_finished\";\n\n/**\n * Config key holding a {@link NodeError} (failed source node + error) for the\n * current node-level error handler invocation. Injected when an error handler\n * task is prepared after the failing node's retry policy is exhausted.\n */\nexport const CONFIG_KEY_NODE_ERROR = \"__pregel_node_error\";\n\n// this one is part of public API\nexport const CONFIG_KEY_CHECKPOINT_MAP = \"checkpoint_map\";\n\nexport const CONFIG_KEY_REPLAY_STATE = \"__pregel_replay_state\";\n\nexport const CONFIG_KEY_ABORT_SIGNALS = \"__pregel_abort_signals\";\n\n/** Special channel reserved for graph interrupts */\nexport const INTERRUPT = \"__interrupt__\";\n/** Special channel reserved for graph resume */\nexport const RESUME = \"__resume__\";\n/** Special channel reserved for cases when a task exits without any writes */\nexport const NO_WRITES = \"__no_writes__\";\n/** Special channel reserved for graph return */\nexport const RETURN = \"__return__\";\n/** Special channel reserved for graph previous state */\nexport const PREVIOUS = \"__previous__\";\nexport const RUNTIME_PLACEHOLDER = \"__pregel_runtime_placeholder__\";\nexport const RECURSION_LIMIT_DEFAULT = 25;\n\nexport const TAG_HIDDEN = \"langsmith:hidden\";\nexport const TAG_NOSTREAM = \"langsmith:nostream\";\nexport const SELF = \"__self__\";\n\nexport const TASKS = \"__pregel_tasks\";\nexport const PUSH = \"__pregel_push\";\nexport const PULL = \"__pregel_pull\";\n\nexport const TASK_NAMESPACE = \"6ba7b831-9dad-11d1-80b4-00c04fd430c8\";\nexport const NULL_TASK_ID = \"00000000-0000-0000-0000-000000000000\";\n\nexport const RESERVED = [\n TAG_HIDDEN,\n INPUT,\n INTERRUPT,\n RESUME,\n ERROR,\n ERROR_SOURCE_NODE,\n NO_WRITES,\n\n // reserved config.configurable keys\n CONFIG_KEY_SEND,\n CONFIG_KEY_READ,\n CONFIG_KEY_CHECKPOINTER,\n CONFIG_KEY_DURABILITY,\n CONFIG_KEY_STREAM,\n CONFIG_KEY_RESUMING,\n CONFIG_KEY_TASK_ID,\n CONFIG_KEY_CALL,\n CONFIG_KEY_RESUME_VALUE,\n CONFIG_KEY_SCRATCHPAD,\n CONFIG_KEY_PREVIOUS_STATE,\n CONFIG_KEY_CHECKPOINT_MAP,\n CONFIG_KEY_CHECKPOINT_NS,\n CONFIG_KEY_CHECKPOINT_ID,\n CONFIG_KEY_REPLAY_STATE,\n];\n\nexport const CHECKPOINT_NAMESPACE_SEPARATOR = \"|\";\nexport const CHECKPOINT_NAMESPACE_END = \":\";\n\n/**\n * Symbol used internally to identify Command instances.\n * Exported to support cross-version type compatibility.\n * @internal\n */\nexport const COMMAND_SYMBOL = Symbol.for(\"langgraph.command\");\n\n/**\n * Instance of a {@link Command} class.\n *\n * This is used to avoid IntelliSense suggesting public fields\n * of {@link Command} class when a plain object is expected.\n *\n * @see {@link Command}\n * @internal\n */\nexport class CommandInstance<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> {\n [COMMAND_SYMBOL]: CommandParams<Resume, Update, Nodes>;\n\n constructor(args: CommandParams<Resume, Update, Nodes>) {\n this[COMMAND_SYMBOL] = args;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport interface SendInterface<Node extends string = string, Args = any> {\n node: Node;\n args: Args;\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task.\n */\n timeout?: TimeoutPolicy;\n}\n\n/** Keyword options for {@link Send}. */\nexport type SendOptions = {\n /**\n * Per-task timeout policy overriding the target node's timeout for this\n * pushed task. A bare number is treated as `runTimeout` (milliseconds).\n */\n timeout?: number | TimeoutPolicy;\n};\n\nexport function _isSendInterface(x: unknown): x is SendInterface {\n const operation = x as SendInterface;\n return (\n operation !== null &&\n operation !== undefined &&\n typeof operation.node === \"string\" &&\n operation.args !== undefined\n );\n}\n\n/**\n *\n * A message or packet to send to a specific node in the graph.\n *\n * The `Send` class is used within a `StateGraph`'s conditional edges to\n * dynamically invoke a node with a custom state at the next step.\n *\n * Importantly, the sent state can differ from the core graph's state,\n * allowing for flexible and dynamic workflow management.\n *\n * One such example is a \"map-reduce\" workflow where your graph invokes\n * the same node multiple times in parallel with different states,\n * before aggregating the results back into the main graph's state.\n *\n * @example\n * ```typescript\n * import { Annotation, Send, StateGraph } from \"@langchain/langgraph\";\n *\n * const ChainState = Annotation.Root({\n * subjects: Annotation<string[]>,\n * jokes: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * }),\n * });\n *\n * const continueToJokes = async (state: typeof ChainState.State) => {\n * return state.subjects.map((subject) => {\n * return new Send(\"generate_joke\", { subjects: [subject] });\n * });\n * };\n *\n * @remarks\n * A per-task timeout can be supplied via the third argument's `timeout` option\n * to override the target node's configured timeout for this specific pushed task:\n *\n * ```typescript\n * new Send(\"generate_joke\", { subjects: [subject] }, { timeout: { idleTimeout: 5000 } });\n * ```\n *\n * const graph = new StateGraph(ChainState)\n * .addNode(\"generate_joke\", (state) => ({\n * jokes: [`Joke about ${state.subjects}`],\n * }))\n * .addConditionalEdges(\"__start__\", continueToJokes)\n * .addEdge(\"generate_joke\", \"__end__\")\n * .compile();\n *\n * const res = await graph.invoke({ subjects: [\"cats\", \"dogs\"] });\n * console.log(res);\n *\n * // Invoking with two subjects results in a generated joke for each\n * // { subjects: [\"cats\", \"dogs\"], jokes: [`Joke about cats`, `Joke about dogs`] }\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Send<\n Node extends string = string,\n Args = any,\n> implements SendInterface<Node, Args> {\n lg_name = \"Send\";\n\n public node: Node;\n\n public args: Args;\n\n /**\n * Optional per-task timeout policy that overrides the target node's timeout\n * for this specific pushed task. A bare number is treated as a hard\n * `runTimeout` (in milliseconds).\n */\n public timeout?: TimeoutPolicy;\n\n constructor(node: Node, args: Args, options?: SendOptions) {\n this.node = node;\n this.args = _deserializeCommandSendObjectGraph(args) as Args;\n this.timeout = coerceTimeoutPolicy(options?.timeout);\n }\n\n toJSON() {\n return {\n lg_name: this.lg_name,\n node: this.node,\n args: this.args,\n timeout: this.timeout,\n };\n }\n}\n\nexport function _isSend(x: unknown): x is Send {\n // eslint-disable-next-line no-instanceof/no-instanceof\n return x instanceof Send;\n}\n\nexport const OVERWRITE = \"__overwrite__\";\n\n/**\n * An object representing a direct overwrite of a value for a channel.\n * Used to signal that the channel value should be replaced with the given value,\n * bypassing any reducer or binary operator logic.\n *\n * @template ValueType - The type of the value being overwritten.\n * @property {ValueType} [OVERWRITE] - The value to directly set.\n *\n * @example\n * const overwriteObj: OverwriteValue<number> = { __overwrite__: 123 };\n */\nexport interface OverwriteValue<ValueType> {\n [OVERWRITE]: ValueType;\n}\n\n/**\n * Bypass a reducer and write the wrapped value directly to a\n * {@link BinaryOperatorAggregate} channel.\n *\n * Receiving multiple `Overwrite` values for the same channel in a single\n * super-step will raise an {@link InvalidUpdateError}.\n *\n * @example\n * ```typescript\n * import { Annotation, StateGraph, Overwrite } from \"@langchain/langgraph\";\n *\n * const State = Annotation.Root({\n * messages: Annotation<string[]>({\n * reducer: (a, b) => a.concat(b),\n * default: () => [],\n * }),\n * });\n *\n * const replaceMessages = (_state: typeof State.State) => {\n * return { messages: new Overwrite([\"replacement\"]) };\n * };\n * ```\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport class Overwrite<ValueType = any> implements OverwriteValue<ValueType> {\n lg_name = \"Overwrite\";\n\n readonly [OVERWRITE]: ValueType;\n\n constructor(value: ValueType) {\n this[OVERWRITE] = value;\n }\n\n get value(): ValueType {\n return this[OVERWRITE];\n }\n\n toJSON() {\n return { [OVERWRITE]: this[OVERWRITE] };\n }\n\n static isInstance<ValueType>(value: unknown): value is Overwrite<ValueType> {\n if (!value || typeof value !== \"object\") return false;\n if (OVERWRITE in value) return true;\n if (\"lg_name\" in value && value.lg_name === \"Overwrite\") return true;\n return false;\n }\n}\n\n/**\n * Helper function to detect and extract the value from an Overwrite wrapper,\n * supporting both the Overwrite class instance and the serialized object format.\n *\n * Use to check if a provided value represents an Overwrite: returns the\n * unwrapped value if so, or undefined otherwise.\n *\n * - If the value is an Overwrite instance (preferred API), return its `.value`.\n * - If the value is a wire-format object ({ [OVERWRITE]: value }), extract it.\n * - If the value is the discriminator form ({ type: OVERWRITE, value }) that\n * results from JSON-serializing a typed `Overwrite` in another runtime (e.g.\n * a Python dataclass routed through the LangGraph API server, where the typed\n * instance is erased), extract it. Keeps Overwrite semantics intact across\n * cross-runtime JSON boundaries.\n * - Otherwise, returns undefined.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns The unwrapped value if value is an Overwrite, or undefined otherwise.\n * @internal\n */\nexport function _getOverwriteValue<ValueType>(\n value: unknown\n): [true, ValueType] | [false, undefined] {\n if (typeof value === \"object\" && value !== null) {\n if (OVERWRITE in value) {\n return [true, (value as Record<string, ValueType>)[OVERWRITE]];\n }\n const rec = value as Record<string, unknown>;\n if (rec.type === OVERWRITE && \"value\" in rec) {\n return [true, rec.value as ValueType];\n }\n }\n return [false, undefined];\n}\n\n/**\n * Type guard to check if a value is an Overwrite value -- either the class\n * instance or the wire format object.\n *\n * @template ValueType - The expected type of the Overwrite value.\n * @param value - The value to check (may be anything).\n * @returns `true` if the value is an Overwrite value, `false` otherwise.\n * @internal\n */\nexport function _isOverwriteValue<ValueType>(\n value: unknown\n): value is OverwriteValue<ValueType> {\n return _getOverwriteValue<ValueType>(value)[0];\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Interrupt<Value = any> = {\n id?: string;\n value?: Value;\n};\n\n/**\n * Checks if the given graph invoke / stream chunk contains interrupt.\n *\n * @example\n * ```ts\n * import { INTERRUPT, isInterrupted } from \"@langchain/langgraph\";\n *\n * const values = await graph.invoke({ foo: \"bar\" });\n * if (isInterrupted<string>(values)) {\n * const interrupt = values[INTERRUPT][0].value;\n * }\n * ```\n *\n * @param values - The values to check.\n * @returns `true` if the values contain an interrupt, `false` otherwise.\n */\nexport function isInterrupted<Value = unknown>(\n values: unknown\n): values is { [INTERRUPT]: Interrupt<Value>[] } {\n if (!values || typeof values !== \"object\") return false;\n if (!(INTERRUPT in values)) return false;\n return Array.isArray(values[INTERRUPT]);\n}\n\nexport type CommandParams<\n Resume = unknown,\n Update = Record<string, unknown>,\n Nodes extends string = string,\n> = {\n /**\n * A discriminator field used to identify the type of object. Must be populated when serializing.\n *\n * Optional because it's not required to specify this when directly constructing a {@link Command}\n * object.\n */\n lg_name?: \"Command\";\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - `Send` object (to execute a node with the input provided)\n * - sequence of `Send` objects\n */\n goto?:\n | Nodes\n | SendInterface<Nodes> // eslint-disable-line @typescript-eslint/no-explicit-any\n | (Nodes | SendInterface<Nodes>)[]; // eslint-disable-line @typescript-eslint/no-explicit-any\n};\n\n/**\n * One or more commands to update the graph's state and send messages to nodes.\n * Can be used to combine routing logic with state updates in lieu of conditional edges\n *\n * @example\n * ```ts\n * import { Annotation, Command } from \"@langchain/langgraph\";\n *\n * // Define graph state\n * const StateAnnotation = Annotation.Root({\n * foo: Annotation<string>,\n * });\n *\n * // Define the nodes\n * const nodeA = async (_state: typeof StateAnnotation.State) => {\n * console.log(\"Called A\");\n * // this is a replacement for a real conditional edge function\n * const goto = Math.random() > .5 ? \"nodeB\" : \"nodeC\";\n * // note how Command allows you to BOTH update the graph state AND route to the next node\n * return new Command({\n * // this is the state update\n * update: {\n * foo: \"a\",\n * },\n * // this is a replacement for an edge\n * goto,\n * });\n * };\n *\n * // Nodes B and C are unchanged\n * const nodeB = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called B\");\n * return {\n * foo: state.foo + \"|b\",\n * };\n * }\n *\n * const nodeC = async (state: typeof StateAnnotation.State) => {\n * console.log(\"Called C\");\n * return {\n * foo: state.foo + \"|c\",\n * };\n * }\n * \n * import { StateGraph } from \"@langchain/langgraph\";\n\n * // NOTE: there are no edges between nodes A, B and C!\n * const graph = new StateGraph(StateAnnotation)\n * .addNode(\"nodeA\", nodeA, {\n * ends: [\"nodeB\", \"nodeC\"],\n * })\n * .addNode(\"nodeB\", nodeB)\n * .addNode(\"nodeC\", nodeC)\n * .addEdge(\"__start__\", \"nodeA\")\n * .compile();\n * \n * await graph.invoke({ foo: \"\" });\n *\n * // Randomly oscillates between\n * // { foo: 'a|c' } and { foo: 'a|b' }\n * ```\n */\nexport class Command<\n Resume = unknown,\n Update extends Record<string, unknown> = Record<string, unknown>,\n Nodes extends string = string,\n> extends CommandInstance<Resume, Update, Nodes> {\n readonly lg_name = \"Command\";\n\n lc_direct_tool_output = true;\n\n /**\n * Graph to send the command to. Supported values are:\n * - None: the current graph (default)\n * - The specific name of the graph to send the command to\n * - {@link Command.PARENT}: closest parent graph (only supported when returned from a node in a subgraph)\n */\n graph?: string;\n\n /**\n * Update to apply to the graph's state as a result of executing the node that is returning the command.\n * Written to the state as if the node had simply returned this value instead of the Command object.\n */\n update?: Update | [string, unknown][];\n\n /**\n * Value to resume execution with. To be used together with {@link interrupt}.\n */\n resume?: Resume;\n\n /**\n * Can be one of the following:\n * - name of the node to navigate to next (any node that belongs to the specified `graph`)\n * - sequence of node names to navigate to next\n * - {@link Send} object (to execute a node with the exact input provided in the {@link Send} object)\n * - sequence of {@link Send} objects\n */\n goto?: Nodes | Send<Nodes> | (Nodes | Send<Nodes>)[] = [];\n\n static PARENT = \"__parent__\";\n\n constructor(args: Omit<CommandParams<Resume, Update, Nodes>, \"lg_name\">) {\n super(args);\n this.resume = args.resume;\n this.graph = args.graph;\n this.update = args.update;\n if (args.goto) {\n type ValidArg = Nodes | Send<Nodes, Update>;\n\n this.goto = Array.isArray(args.goto)\n ? (_deserializeCommandSendObjectGraph(args.goto) as ValidArg[])\n : [_deserializeCommandSendObjectGraph(args.goto) as ValidArg];\n }\n }\n\n /**\n * Convert the update field to a list of {@link PendingWrite} tuples\n * @returns List of {@link PendingWrite} tuples of the form `[channelKey, value]`.\n * @internal\n */\n _updateAsTuples(): PendingWrite[] {\n if (\n this.update &&\n typeof this.update === \"object\" &&\n !Array.isArray(this.update)\n ) {\n return Object.entries(this.update);\n } else if (\n Array.isArray(this.update) &&\n this.update.every(\n (t): t is [string, unknown] =>\n Array.isArray(t) && t.length === 2 && typeof t[0] === \"string\"\n )\n ) {\n return this.update;\n } else {\n return [[\"__root__\", this.update]];\n }\n }\n\n toJSON() {\n let serializedGoto;\n if (typeof this.goto === \"string\") {\n serializedGoto = this.goto;\n } else if (_isSend(this.goto)) {\n serializedGoto = this.goto.toJSON();\n } else {\n serializedGoto = this.goto?.map((innerGoto) => {\n if (typeof innerGoto === \"string\") {\n return innerGoto;\n } else {\n return innerGoto.toJSON();\n }\n });\n }\n return {\n lg_name: this.lg_name,\n update: this.update,\n resume: this.resume,\n goto: serializedGoto,\n };\n }\n}\n\n/**\n * A type guard to check if the given value is a {@link Command}.\n *\n * Useful for type narrowing when working with the {@link Command} object.\n *\n * @param x - The value to check.\n * @returns `true` if the value is a {@link Command}, `false` otherwise.\n */\nexport function isCommand(x: unknown): x is Command {\n if (typeof x !== \"object\") {\n return false;\n }\n\n if (x === null || x === undefined) {\n return false;\n }\n\n if (\"lg_name\" in x && x.lg_name === \"Command\") {\n return true;\n }\n\n return false;\n}\n\nfunction isPlainObject(value: object): value is Record<string, unknown> {\n const prototype = Object.getPrototypeOf(value);\n return prototype === Object.prototype || prototype === null;\n}\n\n/**\n * Reconstructs Command and Send objects from a deeply nested tree of anonymous objects\n * matching their interfaces.\n *\n * This is only exported for testing purposes. It is NOT intended to be used outside of\n * the Command and Send classes.\n *\n * @internal\n *\n * @param x - The command send tree to convert.\n * @param seen - A map of seen objects to avoid infinite loops.\n * @returns The converted command send tree.\n */\nexport function _deserializeCommandSendObjectGraph(\n x: unknown,\n seen: Map<object, unknown> = new Map()\n): unknown {\n if (x !== undefined && x !== null && typeof x === \"object\") {\n // If we've already processed this object, return the transformed version\n if (seen.has(x)) {\n return seen.get(x);\n }\n\n let result: unknown;\n\n if (Array.isArray(x)) {\n // Create the array first, then populate it\n result = [];\n // Add to seen map before processing elements to handle self-references\n seen.set(x, result);\n\n // Now populate the array\n x.forEach((item, index) => {\n (result as unknown[])[index] = _deserializeCommandSendObjectGraph(\n item,\n seen\n );\n });\n // eslint-disable-next-line no-instanceof/no-instanceof\n } else if (x instanceof Command || x instanceof Send || !isPlainObject(x)) {\n result = x;\n seen.set(x, result);\n } else if (isCommand(x)) {\n result = new Command(x);\n seen.set(x, result);\n } else if (_isSendInterface(x)) {\n result = new Send(\n x.node,\n x.args,\n x.timeout !== undefined ? { timeout: x.timeout } : undefined\n );\n seen.set(x, result);\n } else if (\"lc_serializable\" in x && x.lc_serializable) {\n result = x;\n seen.set(x, result);\n } else {\n // Create empty object first\n result = {};\n // Add to seen map before processing properties to handle self-references\n seen.set(x, result);\n\n // Now populate the object\n for (const [key, value] of Object.entries(x)) {\n (result as Record<string, unknown>)[key] =\n _deserializeCommandSendObjectGraph(value, seen);\n }\n }\n\n return result;\n }\n return x;\n}\n"],"mappings":";;;AAOA,MAAa,QAAQ;;AAErB,MAAa,MAAM;AACnB,MAAa,QAAQ;AACrB,MAAa,OAAO;AACpB,MAAa,QAAQ;;;;;;;AAOrB,MAAa,oBAAoB;;AAGjC,MAAa,kBAAkB;;;;;;;;;;;;;;AAe/B,SAAgB,qCAA6C;CAC3D,MAAM,MACJ,OAAO,YAAY,cACf,QAAQ,KAAK,gDACb,KAAA;AACN,KAAI,QAAQ,KAAA,KAAa,QAAQ,IAAI;EACnC,MAAM,SAAS,OAAO,SAAS,KAAK,GAAG;AACvC,MAAI,OAAO,SAAS,OAAO,IAAI,SAAS,EAAG,QAAO;;AAEpD,QAAO;;AAGT,MAAa,kBAAkB;;AAE/B,MAAa,kBAAkB;AAC/B,MAAa,kBAAkB;AAC/B,MAAa,0BAA0B;AACvC,MAAa,sBAAsB;AACnC,MAAa,qBAAqB;AAClC,MAAa,oBAAoB;AACjC,MAAa,0BAA0B;AACvC,MAAa,wBAAwB;AACrC,MAAa,wBAAwB;;AAErC,MAAa,4BAA4B;AACzC,MAAa,wBAAwB;AACrC,MAAa,2BAA2B;AACxC,MAAa,2BAA2B;AAExC,MAAa,2BAA2B;;;;;;AAOxC,MAAa,wBAAwB;AAGrC,MAAa,4BAA4B;AAEzC,MAAa,0BAA0B;AAEvC,MAAa,2BAA2B;;AAGxC,MAAa,YAAY;;AAEzB,MAAa,SAAS;;AAEtB,MAAa,YAAY;;AAEzB,MAAa,SAAS;;AAEtB,MAAa,WAAW;AAIxB,MAAa,aAAa;AAC1B,MAAa,eAAe;AAC5B,MAAa,OAAO;AAEpB,MAAa,QAAQ;AACrB,MAAa,OAAO;AACp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GAAG,OAAO;aACV,iBAAiB,EAAE,EAAE;AAC9B,YAAS,IAAI,KACX,EAAE,MACF,EAAE,MACF,EAAE,YAAY,KAAA,IAAY,EAAE,SAAS,EAAE,SAAS,GAAG,KAAA,EACpD;AACD,QAAK,IAAI,GAAG,OAAO;aACV,qBAAqB,KAAK,EAAE,iBAAiB;AACtD,YAAS;AACT,QAAK,IAAI,GAAG,OAAO;SACd;AAEL,YAAS,EAAE;AAEX,QAAK,IAAI,GAAG,OAAO;AAGnB,QAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,EAAE,CACzC,QAAmC,OAClC,mCAAmC,OAAO,KAAK;;AAIrD,SAAO;;AAET,QAAO"}
|
|
@@ -86,11 +86,16 @@ function messagesStateReducer(left, right) {
|
|
|
86
86
|
* This reducer is batching-invariant, as required by `DeltaChannel`:
|
|
87
87
|
* `reducer(reducer(state, xs), ys) === reducer(state, xs.concat(ys))`.
|
|
88
88
|
*
|
|
89
|
+
* A `RemoveMessage` carrying the {@link REMOVE_ALL_MESSAGES} sentinel id
|
|
90
|
+
* clears all messages accumulated so far (prior state plus earlier writes in
|
|
91
|
+
* the same batch) and keeps only the messages that follow it, mirroring
|
|
92
|
+
* {@link messagesStateReducer}. Clearing happens in the same single linear
|
|
93
|
+
* pass, so the batching-invariant still holds.
|
|
94
|
+
*
|
|
89
95
|
* Raw object / string inputs are coerced to typed `BaseMessage` objects so
|
|
90
96
|
* that HTTP-driven graphs work without a separate coercion step. This is not
|
|
91
|
-
* full {@link messagesStateReducer} parity — `
|
|
92
|
-
*
|
|
93
|
-
* handled here.
|
|
97
|
+
* full {@link messagesStateReducer} parity — unknown-id `RemoveMessage`
|
|
98
|
+
* errors and missing-id UUID assignment are not handled here.
|
|
94
99
|
*
|
|
95
100
|
* @param state - The current accumulated list of messages.
|
|
96
101
|
* @param writes - Batch of writes, each a single message-like or an array.
|
|
@@ -117,7 +122,10 @@ function messagesDeltaReducer(state, writes) {
|
|
|
117
122
|
const result = [...stateMsgs];
|
|
118
123
|
for (const msg of msgs) {
|
|
119
124
|
const mid = msg.id;
|
|
120
|
-
if (mid
|
|
125
|
+
if (_langchain_core_messages.RemoveMessage.isInstance(msg) && mid === "__remove_all__") {
|
|
126
|
+
result.length = 0;
|
|
127
|
+
index.clear();
|
|
128
|
+
} else if (mid == null) result.push(msg);
|
|
121
129
|
else if (_langchain_core_messages.RemoveMessage.isInstance(msg)) {
|
|
122
130
|
if (index.has(mid)) {
|
|
123
131
|
result[index.get(mid)] = null;
|