@langchain/langgraph 1.2.1 → 1.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/channels/any_value.cjs +3 -4
- package/dist/channels/any_value.cjs.map +1 -1
- package/dist/channels/any_value.js +1 -2
- package/dist/channels/any_value.js.map +1 -1
- package/dist/channels/base.cjs +2 -3
- package/dist/channels/base.cjs.map +1 -1
- package/dist/channels/base.js +1 -2
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/binop.cjs +4 -5
- package/dist/channels/binop.cjs.map +1 -1
- package/dist/channels/binop.js +1 -2
- package/dist/channels/binop.js.map +1 -1
- package/dist/channels/dynamic_barrier_value.cjs +4 -5
- package/dist/channels/dynamic_barrier_value.cjs.map +1 -1
- package/dist/channels/dynamic_barrier_value.js +1 -2
- package/dist/channels/dynamic_barrier_value.js.map +1 -1
- package/dist/channels/ephemeral_value.cjs +3 -4
- package/dist/channels/ephemeral_value.cjs.map +1 -1
- package/dist/channels/ephemeral_value.js +1 -2
- package/dist/channels/ephemeral_value.js.map +1 -1
- package/dist/channels/index.cjs +11 -12
- package/dist/channels/index.js +1 -2
- package/dist/channels/last_value.cjs +3 -4
- package/dist/channels/last_value.cjs.map +1 -1
- package/dist/channels/last_value.js +1 -2
- package/dist/channels/last_value.js.map +1 -1
- package/dist/channels/named_barrier_value.cjs +3 -4
- package/dist/channels/named_barrier_value.cjs.map +1 -1
- package/dist/channels/named_barrier_value.js +1 -2
- package/dist/channels/named_barrier_value.js.map +1 -1
- package/dist/channels/topic.cjs +3 -4
- package/dist/channels/topic.cjs.map +1 -1
- package/dist/channels/topic.js +1 -2
- package/dist/channels/topic.js.map +1 -1
- package/dist/channels/untracked_value.cjs +3 -4
- package/dist/channels/untracked_value.cjs.map +1 -1
- package/dist/channels/untracked_value.js +1 -2
- package/dist/channels/untracked_value.js.map +1 -1
- package/dist/constants.cjs +4 -9
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.js +5 -7
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs +1 -2
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.js +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +9 -10
- package/dist/func/index.cjs.map +1 -1
- package/dist/func/index.js +1 -2
- package/dist/func/index.js.map +1 -1
- package/dist/graph/annotation.cjs +3 -4
- package/dist/graph/annotation.cjs.map +1 -1
- package/dist/graph/annotation.js +1 -2
- package/dist/graph/annotation.js.map +1 -1
- package/dist/graph/graph.cjs +23 -24
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.js +16 -17
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.cjs +6 -6
- package/dist/graph/index.js +7 -8
- package/dist/graph/message.cjs +4 -5
- package/dist/graph/message.cjs.map +1 -1
- package/dist/graph/message.js +1 -2
- package/dist/graph/message.js.map +1 -1
- package/dist/graph/messages_annotation.cjs +4 -5
- package/dist/graph/messages_annotation.cjs.map +1 -1
- package/dist/graph/messages_annotation.d.ts +0 -1
- package/dist/graph/messages_annotation.d.ts.map +1 -1
- package/dist/graph/messages_annotation.js +1 -2
- package/dist/graph/messages_annotation.js.map +1 -1
- package/dist/graph/messages_reducer.cjs +2 -3
- package/dist/graph/messages_reducer.cjs.map +1 -1
- package/dist/graph/messages_reducer.js +2 -3
- package/dist/graph/messages_reducer.js.map +1 -1
- package/dist/graph/state.cjs +24 -25
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.js +10 -11
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/types.cjs +4 -5
- package/dist/graph/types.cjs.map +1 -1
- package/dist/graph/types.js +2 -3
- package/dist/graph/types.js.map +1 -1
- package/dist/graph/zod/index.cjs +5 -6
- package/dist/graph/zod/index.d.cts +0 -1
- package/dist/graph/zod/index.d.ts +0 -1
- package/dist/graph/zod/index.js +1 -2
- package/dist/graph/zod/meta.cjs +4 -5
- package/dist/graph/zod/meta.cjs.map +1 -1
- package/dist/graph/zod/meta.js +2 -3
- package/dist/graph/zod/meta.js.map +1 -1
- package/dist/graph/zod/plugin.cjs +2 -3
- package/dist/graph/zod/plugin.cjs.map +1 -1
- package/dist/graph/zod/plugin.js +2 -3
- package/dist/graph/zod/plugin.js.map +1 -1
- package/dist/graph/zod/schema.cjs +5 -6
- package/dist/graph/zod/schema.cjs.map +1 -1
- package/dist/graph/zod/schema.js +4 -5
- package/dist/graph/zod/schema.js.map +1 -1
- package/dist/graph/zod/zod-registry.cjs +2 -3
- package/dist/graph/zod/zod-registry.cjs.map +1 -1
- package/dist/graph/zod/zod-registry.js +1 -2
- package/dist/graph/zod/zod-registry.js.map +1 -1
- package/dist/hash.cjs +1 -2
- package/dist/hash.cjs.map +1 -1
- package/dist/hash.js +1 -1
- package/dist/index.cjs +60 -61
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -2
- package/dist/index.js.map +1 -1
- package/dist/interrupt.cjs +7 -8
- package/dist/interrupt.cjs.map +1 -1
- package/dist/interrupt.js +5 -6
- package/dist/interrupt.js.map +1 -1
- package/dist/prebuilt/agentName.cjs +1 -2
- package/dist/prebuilt/agentName.cjs.map +1 -1
- package/dist/prebuilt/agentName.js +1 -2
- package/dist/prebuilt/agentName.js.map +1 -1
- package/dist/prebuilt/agent_executor.cjs +4 -5
- package/dist/prebuilt/agent_executor.cjs.map +1 -1
- package/dist/prebuilt/agent_executor.d.ts +0 -1
- package/dist/prebuilt/agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/agent_executor.js +1 -2
- package/dist/prebuilt/agent_executor.js.map +1 -1
- package/dist/prebuilt/chat_agent_executor.cjs +4 -5
- package/dist/prebuilt/chat_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/chat_agent_executor.js +1 -2
- package/dist/prebuilt/chat_agent_executor.js.map +1 -1
- package/dist/prebuilt/index.cjs +8 -9
- package/dist/prebuilt/index.js +1 -2
- package/dist/prebuilt/react_agent_executor.cjs +8 -9
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.ts +0 -2
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.js +1 -2
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/prebuilt/tool_executor.cjs +1 -2
- package/dist/prebuilt/tool_executor.cjs.map +1 -1
- package/dist/prebuilt/tool_executor.js +1 -2
- package/dist/prebuilt/tool_executor.js.map +1 -1
- package/dist/prebuilt/tool_node.cjs +4 -5
- package/dist/prebuilt/tool_node.cjs.map +1 -1
- package/dist/prebuilt/tool_node.js +1 -2
- package/dist/prebuilt/tool_node.js.map +1 -1
- package/dist/pregel/algo.cjs +30 -31
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.d.ts +0 -5
- package/dist/pregel/algo.d.ts.map +1 -1
- package/dist/pregel/algo.js +23 -24
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/call.cjs +5 -6
- package/dist/pregel/call.cjs.map +1 -1
- package/dist/pregel/call.js +2 -3
- package/dist/pregel/call.js.map +1 -1
- package/dist/pregel/debug.cjs +10 -11
- package/dist/pregel/debug.cjs.map +1 -1
- package/dist/pregel/debug.js +8 -9
- package/dist/pregel/debug.js.map +1 -1
- package/dist/pregel/index.cjs +47 -48
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.js +28 -29
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/io.cjs +7 -8
- package/dist/pregel/io.cjs.map +1 -1
- package/dist/pregel/io.js +5 -6
- package/dist/pregel/io.js.map +1 -1
- package/dist/pregel/loop.cjs +29 -30
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +20 -21
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/messages.cjs +4 -5
- package/dist/pregel/messages.cjs.map +1 -1
- package/dist/pregel/messages.js +4 -5
- package/dist/pregel/messages.js.map +1 -1
- package/dist/pregel/read.cjs +4 -5
- package/dist/pregel/read.cjs.map +1 -1
- package/dist/pregel/read.d.ts +0 -1
- package/dist/pregel/read.d.ts.map +1 -1
- package/dist/pregel/read.js +1 -2
- package/dist/pregel/read.js.map +1 -1
- package/dist/pregel/remote.cjs +9 -10
- package/dist/pregel/remote.cjs.map +1 -1
- package/dist/pregel/remote.d.ts +0 -2
- package/dist/pregel/remote.d.ts.map +1 -1
- package/dist/pregel/remote.js +7 -8
- package/dist/pregel/remote.js.map +1 -1
- package/dist/pregel/retry.cjs +8 -14
- package/dist/pregel/retry.cjs.map +1 -1
- package/dist/pregel/retry.js +4 -10
- package/dist/pregel/retry.js.map +1 -1
- package/dist/pregel/runner.cjs +8 -9
- package/dist/pregel/runner.cjs.map +1 -1
- package/dist/pregel/runner.js +4 -5
- package/dist/pregel/runner.js.map +1 -1
- package/dist/pregel/stream.cjs +3 -4
- package/dist/pregel/stream.cjs.map +1 -1
- package/dist/pregel/stream.d.ts +0 -1
- package/dist/pregel/stream.js +3 -4
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/types.cjs +1 -2
- package/dist/pregel/types.cjs.map +1 -1
- package/dist/pregel/types.js +1 -1
- package/dist/pregel/types.js.map +1 -1
- package/dist/pregel/utils/config.cjs +6 -7
- package/dist/pregel/utils/config.cjs.map +1 -1
- package/dist/pregel/utils/config.js +6 -7
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/pregel/utils/index.cjs +2 -3
- package/dist/pregel/utils/index.cjs.map +1 -1
- package/dist/pregel/utils/index.js +1 -2
- package/dist/pregel/utils/index.js.map +1 -1
- package/dist/pregel/utils/subgraph.cjs +1 -2
- package/dist/pregel/utils/subgraph.cjs.map +1 -1
- package/dist/pregel/utils/subgraph.js +1 -1
- package/dist/pregel/validate.cjs +4 -5
- package/dist/pregel/validate.cjs.map +1 -1
- package/dist/pregel/validate.js +2 -3
- package/dist/pregel/validate.js.map +1 -1
- package/dist/pregel/write.cjs +5 -8
- package/dist/pregel/write.cjs.map +1 -1
- package/dist/pregel/write.js +2 -5
- package/dist/pregel/write.js.map +1 -1
- package/dist/remote.cjs +3 -4
- package/dist/remote.js +1 -2
- package/dist/setup/async_local_storage.cjs +1 -2
- package/dist/setup/async_local_storage.cjs.map +1 -1
- package/dist/setup/async_local_storage.js +1 -2
- package/dist/setup/async_local_storage.js.map +1 -1
- package/dist/state/adapter.cjs +2 -3
- package/dist/state/adapter.cjs.map +1 -1
- package/dist/state/adapter.js +1 -2
- package/dist/state/adapter.js.map +1 -1
- package/dist/state/index.cjs +8 -8
- package/dist/state/index.d.ts +1 -2
- package/dist/state/index.js +7 -8
- package/dist/state/prebuilt/index.cjs +1 -1
- package/dist/state/prebuilt/index.js +2 -3
- package/dist/state/prebuilt/messages.cjs +3 -4
- package/dist/state/prebuilt/messages.cjs.map +1 -1
- package/dist/state/prebuilt/messages.js +3 -7
- package/dist/state/prebuilt/messages.js.map +1 -1
- package/dist/state/schema.cjs +16 -12
- package/dist/state/schema.cjs.map +1 -1
- package/dist/state/schema.d.cts.map +1 -1
- package/dist/state/schema.d.ts +0 -1
- package/dist/state/schema.d.ts.map +1 -1
- package/dist/state/schema.js +8 -4
- package/dist/state/schema.js.map +1 -1
- package/dist/state/types.cjs +1 -2
- package/dist/state/types.cjs.map +1 -1
- package/dist/state/types.js +1 -1
- package/dist/state/values/index.cjs +2 -2
- package/dist/state/values/index.js +3 -4
- package/dist/state/values/reduced.cjs +1 -2
- package/dist/state/values/reduced.cjs.map +1 -1
- package/dist/state/values/reduced.js +1 -1
- package/dist/state/values/reduced.js.map +1 -1
- package/dist/state/values/untracked.cjs +1 -2
- package/dist/state/values/untracked.cjs.map +1 -1
- package/dist/state/values/untracked.js +1 -1
- package/dist/state/values/untracked.js.map +1 -1
- package/dist/utils.cjs +2 -3
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.js +1 -2
- package/dist/utils.js.map +1 -1
- package/dist/web.cjs +58 -59
- package/dist/web.d.ts +0 -3
- package/dist/web.js +1 -2
- package/dist/writer.cjs +1 -2
- package/dist/writer.cjs.map +1 -1
- package/dist/writer.js +1 -2
- package/dist/writer.js.map +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const require_errors = require(
|
|
2
|
-
const require_base = require(
|
|
3
|
-
|
|
1
|
+
const require_errors = require("../errors.cjs");
|
|
2
|
+
const require_base = require("./base.cjs");
|
|
4
3
|
//#region src/channels/named_barrier_value.ts
|
|
5
4
|
const areSetsEqual = (a, b) => a.size === b.size && [...a].every((value) => b.has(value));
|
|
6
5
|
/**
|
|
@@ -108,9 +107,9 @@ var NamedBarrierValueAfterFinish = class NamedBarrierValueAfterFinish extends re
|
|
|
108
107
|
return this.finished && !!this.names && areSetsEqual(this.names, this.seen);
|
|
109
108
|
}
|
|
110
109
|
};
|
|
111
|
-
|
|
112
110
|
//#endregion
|
|
113
111
|
exports.NamedBarrierValue = NamedBarrierValue;
|
|
114
112
|
exports.NamedBarrierValueAfterFinish = NamedBarrierValueAfterFinish;
|
|
115
113
|
exports.areSetsEqual = areSetsEqual;
|
|
114
|
+
|
|
116
115
|
//# sourceMappingURL=named_barrier_value.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"named_barrier_value.cjs","names":["BaseChannel","InvalidUpdateError","EmptyChannelError"],"sources":["../../src/channels/named_barrier_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\nexport const areSetsEqual = <T>(a: Set<T>, b: Set<T>) =>\n a.size === b.size && [...a].every((value) => b.has(value));\n\n/**\n * A channel that waits until all named values are received before making the value available.\n *\n * This ensures that if node N and node M both write to channel C, the value of C will not be updated\n * until N and M have completed updating.\n */\nexport class NamedBarrierValue<Value> extends BaseChannel<\n void,\n Value,\n Value[]\n> {\n lc_graph_name = \"NamedBarrierValue\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n }\n\n fromCheckpoint(checkpoint?: Value[]) {\n const empty = new NamedBarrierValue<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint);\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName)) {\n if (!this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n }\n } else {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n // If we have not yet seen all the node names we want to wait for,\n // throw an error to prevent continuing.\n get(): void {\n if (!areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): Value[] {\n return [...this.seen];\n }\n\n consume(): boolean {\n if (this.seen && this.names && areSetsEqual(this.seen, this.names)) {\n this.seen = new Set<Value>();\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n\n/**\n * A channel that waits until all named values are received before making the value ready to be made available.\n * It is only made available after finish() is called.\n * @internal\n */\nexport class NamedBarrierValueAfterFinish<Value> extends BaseChannel<\n void,\n Value,\n [Value[], boolean]\n> {\n lc_graph_name = \"NamedBarrierValueAfterFinish\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n finished: boolean;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n this.finished = false;\n }\n\n fromCheckpoint(checkpoint?: [Value[], boolean]) {\n const empty = new NamedBarrierValueAfterFinish<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n const [seen, finished] = checkpoint;\n empty.seen = new Set(seen);\n empty.finished = finished;\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName) && !this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n } else if (!this.names.has(nodeName)) {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n get(): void {\n if (!this.finished || !areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): [Value[], boolean] {\n return [[...this.seen], this.finished];\n }\n\n consume(): boolean {\n if (\n this.finished &&\n this.seen &&\n this.names &&\n areSetsEqual(this.seen, this.names)\n ) {\n this.seen = new Set<Value>();\n this.finished = false;\n return true;\n }\n return false;\n }\n\n finish(): boolean {\n if (!this.finished && !!this.names && areSetsEqual(this.names, this.seen)) {\n this.finished = true;\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return this.finished && !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"named_barrier_value.cjs","names":["BaseChannel","InvalidUpdateError","EmptyChannelError"],"sources":["../../src/channels/named_barrier_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\nexport const areSetsEqual = <T>(a: Set<T>, b: Set<T>) =>\n a.size === b.size && [...a].every((value) => b.has(value));\n\n/**\n * A channel that waits until all named values are received before making the value available.\n *\n * This ensures that if node N and node M both write to channel C, the value of C will not be updated\n * until N and M have completed updating.\n */\nexport class NamedBarrierValue<Value> extends BaseChannel<\n void,\n Value,\n Value[]\n> {\n lc_graph_name = \"NamedBarrierValue\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n }\n\n fromCheckpoint(checkpoint?: Value[]) {\n const empty = new NamedBarrierValue<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint);\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName)) {\n if (!this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n }\n } else {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n // If we have not yet seen all the node names we want to wait for,\n // throw an error to prevent continuing.\n get(): void {\n if (!areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): Value[] {\n return [...this.seen];\n }\n\n consume(): boolean {\n if (this.seen && this.names && areSetsEqual(this.seen, this.names)) {\n this.seen = new Set<Value>();\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n\n/**\n * A channel that waits until all named values are received before making the value ready to be made available.\n * It is only made available after finish() is called.\n * @internal\n */\nexport class NamedBarrierValueAfterFinish<Value> extends BaseChannel<\n void,\n Value,\n [Value[], boolean]\n> {\n lc_graph_name = \"NamedBarrierValueAfterFinish\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n finished: boolean;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n this.finished = false;\n }\n\n fromCheckpoint(checkpoint?: [Value[], boolean]) {\n const empty = new NamedBarrierValueAfterFinish<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n const [seen, finished] = checkpoint;\n empty.seen = new Set(seen);\n empty.finished = finished;\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName) && !this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n } else if (!this.names.has(nodeName)) {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n get(): void {\n if (!this.finished || !areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): [Value[], boolean] {\n return [[...this.seen], this.finished];\n }\n\n consume(): boolean {\n if (\n this.finished &&\n this.seen &&\n this.names &&\n areSetsEqual(this.seen, this.names)\n ) {\n this.seen = new Set<Value>();\n this.finished = false;\n return true;\n }\n return false;\n }\n\n finish(): boolean {\n if (!this.finished && !!this.names && areSetsEqual(this.names, this.seen)) {\n this.finished = true;\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return this.finished && !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n"],"mappings":";;;AAGA,MAAa,gBAAmB,GAAW,MACzC,EAAE,SAAS,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,UAAU,EAAE,IAAI,MAAM,CAAC;;;;;;;AAQ5D,IAAa,oBAAb,MAAa,0BAAiCA,aAAAA,YAI5C;CACA,gBAAgB;CAEhB;CAEA;CAEA,YAAY,OAAmB;AAC7B,SAAO;AACP,OAAK,QAAQ;AACb,OAAK,uBAAO,IAAI,KAAY;;CAG9B,eAAe,YAAsB;EACnC,MAAM,QAAQ,IAAI,kBAAyB,KAAK,MAAM;AACtD,MAAI,OAAO,eAAe,YACxB,OAAM,OAAO,IAAI,IAAI,WAAW;AAElC,SAAO;;CAGT,OAAO,QAA0B;EAC/B,IAAI,UAAU;AACd,OAAK,MAAM,YAAY,OACrB,KAAI,KAAK,MAAM,IAAI,SAAS;OACtB,CAAC,KAAK,KAAK,IAAI,SAAS,EAAE;AAC5B,SAAK,KAAK,IAAI,SAAS;AACvB,cAAU;;QAGZ,OAAM,IAAIC,eAAAA,mBACR,SAAS,KAAK,UAAU,SAAS,CAAC,gBAAgB,KAAK,UACrD,KAAK,MACN,GACF;AAGL,SAAO;;CAKT,MAAY;AACV,MAAI,CAAC,aAAa,KAAK,OAAO,KAAK,KAAK,CACtC,OAAM,IAAIC,eAAAA,mBAAmB;;CAKjC,aAAsB;AACpB,SAAO,CAAC,GAAG,KAAK,KAAK;;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,QAAK,uBAAO,IAAI,KAAY;AAC5B,QAAK,WAAW;AAChB,UAAO;;AAET,SAAO;;CAGT,SAAkB;AAChB,MAAI,CAAC,KAAK,YAAY,CAAC,CAAC,KAAK,SAAS,aAAa,KAAK,OAAO,KAAK,KAAK,EAAE;AACzE,QAAK,WAAW;AAChB,UAAO;;AAET,SAAO;;CAGT,cAAuB;AACrB,SAAO,KAAK,YAAY,CAAC,CAAC,KAAK,SAAS,aAAa,KAAK,OAAO,KAAK,KAAK"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
|
|
2
2
|
import { BaseChannel } from "./base.js";
|
|
3
|
-
|
|
4
3
|
//#region src/channels/named_barrier_value.ts
|
|
5
4
|
const areSetsEqual = (a, b) => a.size === b.size && [...a].every((value) => b.has(value));
|
|
6
5
|
/**
|
|
@@ -108,7 +107,7 @@ var NamedBarrierValueAfterFinish = class NamedBarrierValueAfterFinish extends Ba
|
|
|
108
107
|
return this.finished && !!this.names && areSetsEqual(this.names, this.seen);
|
|
109
108
|
}
|
|
110
109
|
};
|
|
111
|
-
|
|
112
110
|
//#endregion
|
|
113
111
|
export { NamedBarrierValue, NamedBarrierValueAfterFinish, areSetsEqual };
|
|
112
|
+
|
|
114
113
|
//# sourceMappingURL=named_barrier_value.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"named_barrier_value.js","names":[],"sources":["../../src/channels/named_barrier_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\nexport const areSetsEqual = <T>(a: Set<T>, b: Set<T>) =>\n a.size === b.size && [...a].every((value) => b.has(value));\n\n/**\n * A channel that waits until all named values are received before making the value available.\n *\n * This ensures that if node N and node M both write to channel C, the value of C will not be updated\n * until N and M have completed updating.\n */\nexport class NamedBarrierValue<Value> extends BaseChannel<\n void,\n Value,\n Value[]\n> {\n lc_graph_name = \"NamedBarrierValue\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n }\n\n fromCheckpoint(checkpoint?: Value[]) {\n const empty = new NamedBarrierValue<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint);\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName)) {\n if (!this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n }\n } else {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n // If we have not yet seen all the node names we want to wait for,\n // throw an error to prevent continuing.\n get(): void {\n if (!areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): Value[] {\n return [...this.seen];\n }\n\n consume(): boolean {\n if (this.seen && this.names && areSetsEqual(this.seen, this.names)) {\n this.seen = new Set<Value>();\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n\n/**\n * A channel that waits until all named values are received before making the value ready to be made available.\n * It is only made available after finish() is called.\n * @internal\n */\nexport class NamedBarrierValueAfterFinish<Value> extends BaseChannel<\n void,\n Value,\n [Value[], boolean]\n> {\n lc_graph_name = \"NamedBarrierValueAfterFinish\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n finished: boolean;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n this.finished = false;\n }\n\n fromCheckpoint(checkpoint?: [Value[], boolean]) {\n const empty = new NamedBarrierValueAfterFinish<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n const [seen, finished] = checkpoint;\n empty.seen = new Set(seen);\n empty.finished = finished;\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName) && !this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n } else if (!this.names.has(nodeName)) {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n get(): void {\n if (!this.finished || !areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): [Value[], boolean] {\n return [[...this.seen], this.finished];\n }\n\n consume(): boolean {\n if (\n this.finished &&\n this.seen &&\n this.names &&\n areSetsEqual(this.seen, this.names)\n ) {\n this.seen = new Set<Value>();\n this.finished = false;\n return true;\n }\n return false;\n }\n\n finish(): boolean {\n if (!this.finished && !!this.names && areSetsEqual(this.names, this.seen)) {\n this.finished = true;\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return this.finished && !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"named_barrier_value.js","names":[],"sources":["../../src/channels/named_barrier_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\nexport const areSetsEqual = <T>(a: Set<T>, b: Set<T>) =>\n a.size === b.size && [...a].every((value) => b.has(value));\n\n/**\n * A channel that waits until all named values are received before making the value available.\n *\n * This ensures that if node N and node M both write to channel C, the value of C will not be updated\n * until N and M have completed updating.\n */\nexport class NamedBarrierValue<Value> extends BaseChannel<\n void,\n Value,\n Value[]\n> {\n lc_graph_name = \"NamedBarrierValue\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n }\n\n fromCheckpoint(checkpoint?: Value[]) {\n const empty = new NamedBarrierValue<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint);\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName)) {\n if (!this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n }\n } else {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n // If we have not yet seen all the node names we want to wait for,\n // throw an error to prevent continuing.\n get(): void {\n if (!areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): Value[] {\n return [...this.seen];\n }\n\n consume(): boolean {\n if (this.seen && this.names && areSetsEqual(this.seen, this.names)) {\n this.seen = new Set<Value>();\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n\n/**\n * A channel that waits until all named values are received before making the value ready to be made available.\n * It is only made available after finish() is called.\n * @internal\n */\nexport class NamedBarrierValueAfterFinish<Value> extends BaseChannel<\n void,\n Value,\n [Value[], boolean]\n> {\n lc_graph_name = \"NamedBarrierValueAfterFinish\";\n\n names: Set<Value>; // Names of nodes that we want to wait for.\n\n seen: Set<Value>;\n\n finished: boolean;\n\n constructor(names: Set<Value>) {\n super();\n this.names = names;\n this.seen = new Set<Value>();\n this.finished = false;\n }\n\n fromCheckpoint(checkpoint?: [Value[], boolean]) {\n const empty = new NamedBarrierValueAfterFinish<Value>(this.names);\n if (typeof checkpoint !== \"undefined\") {\n const [seen, finished] = checkpoint;\n empty.seen = new Set(seen);\n empty.finished = finished;\n }\n return empty as this;\n }\n\n update(values: Value[]): boolean {\n let updated = false;\n for (const nodeName of values) {\n if (this.names.has(nodeName) && !this.seen.has(nodeName)) {\n this.seen.add(nodeName);\n updated = true;\n } else if (!this.names.has(nodeName)) {\n throw new InvalidUpdateError(\n `Value ${JSON.stringify(nodeName)} not in names ${JSON.stringify(\n this.names\n )}`\n );\n }\n }\n return updated;\n }\n\n get(): void {\n if (!this.finished || !areSetsEqual(this.names, this.seen)) {\n throw new EmptyChannelError();\n }\n return undefined;\n }\n\n checkpoint(): [Value[], boolean] {\n return [[...this.seen], this.finished];\n }\n\n consume(): boolean {\n if (\n this.finished &&\n this.seen &&\n this.names &&\n areSetsEqual(this.seen, this.names)\n ) {\n this.seen = new Set<Value>();\n this.finished = false;\n return true;\n }\n return false;\n }\n\n finish(): boolean {\n if (!this.finished && !!this.names && areSetsEqual(this.names, this.seen)) {\n this.finished = true;\n return true;\n }\n return false;\n }\n\n isAvailable(): boolean {\n return this.finished && !!this.names && areSetsEqual(this.names, this.seen);\n }\n}\n"],"mappings":";;;AAGA,MAAa,gBAAmB,GAAW,MACzC,EAAE,SAAS,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,UAAU,EAAE,IAAI,MAAM,CAAC;;;;;;;AAQ5D,IAAa,oBAAb,MAAa,0BAAiC,YAI5C;CACA,gBAAgB;CAEhB;CAEA;CAEA,YAAY,OAAmB;AAC7B,SAAO;AACP,OAAK,QAAQ;AACb,OAAK,uBAAO,IAAI,KAAY;;CAG9B,eAAe,YAAsB;EACnC,MAAM,QAAQ,IAAI,kBAAyB,KAAK,MAAM;AACtD,MAAI,OAAO,eAAe,YACxB,OAAM,OAAO,IAAI,IAAI,WAAW;AAElC,SAAO;;CAGT,OAAO,QAA0B;EAC/B,IAAI,UAAU;AACd,OAAK,MAAM,YAAY,OACrB,KAAI,KAAK,MAAM,IAAI,SAAS;OACtB,CAAC,KAAK,KAAK,IAAI,SAAS,EAAE;AAC5B,SAAK,KAAK,IAAI,SAAS;AACvB,cAAU;;QAGZ,OAAM,IAAI,mBACR,SAAS,KAAK,UAAU,SAAS,CAAC,gBAAgB,KAAK,UACrD,KAAK,MACN,GACF;AAGL,SAAO;;CAKT,MAAY;AACV,MAAI,CAAC,aAAa,KAAK,OAAO,KAAK,KAAK,CACtC,OAAM,IAAI,mBAAmB;;CAKjC,a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K,MAAM,EACnC;AACA,QAAK,uBAAO,IAAI,KAAY;AAC5B,QAAK,WAAW;AAChB,UAAO;;AAET,SAAO;;CAGT,SAAkB;AAChB,MAAI,CAAC,KAAK,YAAY,CAAC,CAAC,KAAK,SAAS,aAAa,KAAK,OAAO,KAAK,KAAK,EAAE;AACzE,QAAK,WAAW;AAChB,UAAO;;AAET,SAAO;;CAGT,cAAuB;AACrB,SAAO,KAAK,YAAY,CAAC,CAAC,KAAK,SAAS,aAAa,KAAK,OAAO,KAAK,KAAK"}
|
package/dist/channels/topic.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const require_errors = require(
|
|
2
|
-
const require_base = require(
|
|
3
|
-
|
|
1
|
+
const require_errors = require("../errors.cjs");
|
|
2
|
+
const require_base = require("./base.cjs");
|
|
4
3
|
//#region src/channels/topic.ts
|
|
5
4
|
/**
|
|
6
5
|
* A configurable PubSub Topic.
|
|
@@ -59,7 +58,7 @@ var Topic = class Topic extends require_base.BaseChannel {
|
|
|
59
58
|
return this.values.length !== 0;
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
|
-
|
|
63
61
|
//#endregion
|
|
64
62
|
exports.Topic = Topic;
|
|
63
|
+
|
|
65
64
|
//# sourceMappingURL=topic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic.cjs","names":["BaseChannel","EmptyChannelError"],"sources":["../../src/channels/topic.ts"],"sourcesContent":["import { EmptyChannelError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n/**\n * A configurable PubSub Topic.\n */\nexport class Topic<Value> extends BaseChannel<\n Array<Value>,\n Value | Value[],\n [Value[], Value[]]\n> {\n lc_graph_name = \"Topic\";\n\n unique = false;\n\n accumulate = false;\n\n seen: Set<Value>;\n\n values: Value[];\n\n constructor(fields?: {\n /**\n * Whether to only add unique values to the topic. If `true`, only unique values (using reference equality) will be added to the topic.\n */\n unique?: boolean;\n /**\n * Whether to accumulate values across steps. If `false`, the channel will be emptied after each step.\n */\n accumulate?: boolean;\n }) {\n super();\n\n this.unique = fields?.unique ?? this.unique;\n this.accumulate = fields?.accumulate ?? this.accumulate;\n // State\n this.seen = new Set<Value>();\n this.values = [];\n }\n\n public fromCheckpoint(checkpoint?: [Value[], Value[]]) {\n const empty = new Topic<Value>({\n unique: this.unique,\n accumulate: this.accumulate,\n });\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint[0]);\n // eslint-disable-next-line prefer-destructuring\n empty.values = checkpoint[1];\n }\n return empty as this;\n }\n\n public update(values: Array<Value | Value[]>): boolean {\n let updated = false;\n if (!this.accumulate) {\n updated = this.values.length > 0;\n this.values = [];\n }\n const flatValues = values.flat() as Value[];\n if (flatValues.length > 0) {\n if (this.unique) {\n for (const value of flatValues) {\n if (!this.seen.has(value)) {\n updated = true;\n this.seen.add(value);\n this.values.push(value);\n }\n }\n } else {\n updated = true;\n this.values.push(...flatValues);\n }\n }\n return updated;\n }\n\n public get(): Array<Value> {\n if (this.values.length === 0) {\n throw new EmptyChannelError();\n }\n return this.values;\n }\n\n public checkpoint(): [Value[], Value[]] {\n return [[...this.seen], this.values];\n }\n\n isAvailable(): boolean {\n return this.values.length !== 0;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"topic.cjs","names":["BaseChannel","EmptyChannelError"],"sources":["../../src/channels/topic.ts"],"sourcesContent":["import { EmptyChannelError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n/**\n * A configurable PubSub Topic.\n */\nexport class Topic<Value> extends BaseChannel<\n Array<Value>,\n Value | Value[],\n [Value[], Value[]]\n> {\n lc_graph_name = \"Topic\";\n\n unique = false;\n\n accumulate = false;\n\n seen: Set<Value>;\n\n values: Value[];\n\n constructor(fields?: {\n /**\n * Whether to only add unique values to the topic. If `true`, only unique values (using reference equality) will be added to the topic.\n */\n unique?: boolean;\n /**\n * Whether to accumulate values across steps. If `false`, the channel will be emptied after each step.\n */\n accumulate?: boolean;\n }) {\n super();\n\n this.unique = fields?.unique ?? this.unique;\n this.accumulate = fields?.accumulate ?? this.accumulate;\n // State\n this.seen = new Set<Value>();\n this.values = [];\n }\n\n public fromCheckpoint(checkpoint?: [Value[], Value[]]) {\n const empty = new Topic<Value>({\n unique: this.unique,\n accumulate: this.accumulate,\n });\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint[0]);\n // eslint-disable-next-line prefer-destructuring\n empty.values = checkpoint[1];\n }\n return empty as this;\n }\n\n public update(values: Array<Value | Value[]>): boolean {\n let updated = false;\n if (!this.accumulate) {\n updated = this.values.length > 0;\n this.values = [];\n }\n const flatValues = values.flat() as Value[];\n if (flatValues.length > 0) {\n if (this.unique) {\n for (const value of flatValues) {\n if (!this.seen.has(value)) {\n updated = true;\n this.seen.add(value);\n this.values.push(value);\n }\n }\n } else {\n updated = true;\n this.values.push(...flatValues);\n }\n }\n return updated;\n }\n\n public get(): Array<Value> {\n if (this.values.length === 0) {\n throw new EmptyChannelError();\n }\n return this.values;\n }\n\n public checkpoint(): [Value[], Value[]] {\n return [[...this.seen], this.values];\n }\n\n isAvailable(): boolean {\n return this.values.length !== 0;\n }\n}\n"],"mappings":";;;;;;AAMA,IAAa,QAAb,MAAa,cAAqBA,aAAAA,YAIhC;CACA,gBAAgB;CAEhB,SAAS;CAET,aAAa;CAEb;CAEA;CAEA,YAAY,QAST;AACD,SAAO;AAEP,OAAK,SAAS,QAAQ,UAAU,KAAK;AACrC,OAAK,aAAa,QAAQ,cAAc,KAAK;AAE7C,OAAK,uBAAO,IAAI,KAAY;AAC5B,OAAK,SAAS,EAAE;;CAGlB,eAAsB,YAAiC;EACrD,MAAM,QAAQ,IAAI,MAAa;GAC7B,QAAQ,KAAK;GACb,YAAY,KAAK;GAClB,CAAC;AACF,MAAI,OAAO,eAAe,aAAa;AACrC,SAAM,OAAO,IAAI,IAAI,WAAW,GAAG;AAEnC,SAAM,SAAS,WAAW;;AAE5B,SAAO;;CAGT,OAAc,QAAyC;EACrD,IAAI,UAAU;AACd,MAAI,CAAC,KAAK,YAAY;AACpB,aAAU,KAAK,OAAO,SAAS;AAC/B,QAAK,SAAS,EAAE;;EAElB,MAAM,aAAa,OAAO,MAAM;AAChC,MAAI,WAAW,SAAS,EACtB,KAAI,KAAK;QACF,MAAM,SAAS,WAClB,KAAI,CAAC,KAAK,KAAK,IAAI,MAAM,EAAE;AACzB,cAAU;AACV,SAAK,KAAK,IAAI,MAAM;AACpB,SAAK,OAAO,KAAK,MAAM;;SAGtB;AACL,aAAU;AACV,QAAK,OAAO,KAAK,GAAG,WAAW;;AAGnC,SAAO;;CAGT,MAA2B;AACzB,MAAI,KAAK,OAAO,WAAW,EACzB,OAAM,IAAIC,eAAAA,mBAAmB;AAE/B,SAAO,KAAK;;CAGd,aAAwC;AACtC,SAAO,CAAC,CAAC,GAAG,KAAK,KAAK,EAAE,KAAK,OAAO;;CAGtC,cAAuB;AACrB,SAAO,KAAK,OAAO,WAAW"}
|
package/dist/channels/topic.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EmptyChannelError } from "../errors.js";
|
|
2
2
|
import { BaseChannel } from "./base.js";
|
|
3
|
-
|
|
4
3
|
//#region src/channels/topic.ts
|
|
5
4
|
/**
|
|
6
5
|
* A configurable PubSub Topic.
|
|
@@ -59,7 +58,7 @@ var Topic = class Topic extends BaseChannel {
|
|
|
59
58
|
return this.values.length !== 0;
|
|
60
59
|
}
|
|
61
60
|
};
|
|
62
|
-
|
|
63
61
|
//#endregion
|
|
64
62
|
export { Topic };
|
|
63
|
+
|
|
65
64
|
//# sourceMappingURL=topic.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"topic.js","names":[],"sources":["../../src/channels/topic.ts"],"sourcesContent":["import { EmptyChannelError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n/**\n * A configurable PubSub Topic.\n */\nexport class Topic<Value> extends BaseChannel<\n Array<Value>,\n Value | Value[],\n [Value[], Value[]]\n> {\n lc_graph_name = \"Topic\";\n\n unique = false;\n\n accumulate = false;\n\n seen: Set<Value>;\n\n values: Value[];\n\n constructor(fields?: {\n /**\n * Whether to only add unique values to the topic. If `true`, only unique values (using reference equality) will be added to the topic.\n */\n unique?: boolean;\n /**\n * Whether to accumulate values across steps. If `false`, the channel will be emptied after each step.\n */\n accumulate?: boolean;\n }) {\n super();\n\n this.unique = fields?.unique ?? this.unique;\n this.accumulate = fields?.accumulate ?? this.accumulate;\n // State\n this.seen = new Set<Value>();\n this.values = [];\n }\n\n public fromCheckpoint(checkpoint?: [Value[], Value[]]) {\n const empty = new Topic<Value>({\n unique: this.unique,\n accumulate: this.accumulate,\n });\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint[0]);\n // eslint-disable-next-line prefer-destructuring\n empty.values = checkpoint[1];\n }\n return empty as this;\n }\n\n public update(values: Array<Value | Value[]>): boolean {\n let updated = false;\n if (!this.accumulate) {\n updated = this.values.length > 0;\n this.values = [];\n }\n const flatValues = values.flat() as Value[];\n if (flatValues.length > 0) {\n if (this.unique) {\n for (const value of flatValues) {\n if (!this.seen.has(value)) {\n updated = true;\n this.seen.add(value);\n this.values.push(value);\n }\n }\n } else {\n updated = true;\n this.values.push(...flatValues);\n }\n }\n return updated;\n }\n\n public get(): Array<Value> {\n if (this.values.length === 0) {\n throw new EmptyChannelError();\n }\n return this.values;\n }\n\n public checkpoint(): [Value[], Value[]] {\n return [[...this.seen], this.values];\n }\n\n isAvailable(): boolean {\n return this.values.length !== 0;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"topic.js","names":[],"sources":["../../src/channels/topic.ts"],"sourcesContent":["import { EmptyChannelError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n/**\n * A configurable PubSub Topic.\n */\nexport class Topic<Value> extends BaseChannel<\n Array<Value>,\n Value | Value[],\n [Value[], Value[]]\n> {\n lc_graph_name = \"Topic\";\n\n unique = false;\n\n accumulate = false;\n\n seen: Set<Value>;\n\n values: Value[];\n\n constructor(fields?: {\n /**\n * Whether to only add unique values to the topic. If `true`, only unique values (using reference equality) will be added to the topic.\n */\n unique?: boolean;\n /**\n * Whether to accumulate values across steps. If `false`, the channel will be emptied after each step.\n */\n accumulate?: boolean;\n }) {\n super();\n\n this.unique = fields?.unique ?? this.unique;\n this.accumulate = fields?.accumulate ?? this.accumulate;\n // State\n this.seen = new Set<Value>();\n this.values = [];\n }\n\n public fromCheckpoint(checkpoint?: [Value[], Value[]]) {\n const empty = new Topic<Value>({\n unique: this.unique,\n accumulate: this.accumulate,\n });\n if (typeof checkpoint !== \"undefined\") {\n empty.seen = new Set(checkpoint[0]);\n // eslint-disable-next-line prefer-destructuring\n empty.values = checkpoint[1];\n }\n return empty as this;\n }\n\n public update(values: Array<Value | Value[]>): boolean {\n let updated = false;\n if (!this.accumulate) {\n updated = this.values.length > 0;\n this.values = [];\n }\n const flatValues = values.flat() as Value[];\n if (flatValues.length > 0) {\n if (this.unique) {\n for (const value of flatValues) {\n if (!this.seen.has(value)) {\n updated = true;\n this.seen.add(value);\n this.values.push(value);\n }\n }\n } else {\n updated = true;\n this.values.push(...flatValues);\n }\n }\n return updated;\n }\n\n public get(): Array<Value> {\n if (this.values.length === 0) {\n throw new EmptyChannelError();\n }\n return this.values;\n }\n\n public checkpoint(): [Value[], Value[]] {\n return [[...this.seen], this.values];\n }\n\n isAvailable(): boolean {\n return this.values.length !== 0;\n }\n}\n"],"mappings":";;;;;;AAMA,IAAa,QAAb,MAAa,cAAqB,YAIhC;CACA,gBAAgB;CAEhB,SAAS;CAET,aAAa;CAEb;CAEA;CAEA,YAAY,QAST;AACD,SAAO;AAEP,OAAK,SAAS,QAAQ,UAAU,KAAK;AACrC,OAAK,aAAa,QAAQ,cAAc,KAAK;AAE7C,OAAK,uBAAO,IAAI,KAAY;AAC5B,OAAK,SAAS,EAAE;;CAGlB,eAAsB,YAAiC;EACrD,MAAM,QAAQ,IAAI,MAAa;GAC7B,QAAQ,KAAK;GACb,YAAY,KAAK;GAClB,CAAC;AACF,MAAI,OAAO,eAAe,aAAa;AACrC,SAAM,OAAO,IAAI,IAAI,WAAW,GAAG;AAEnC,SAAM,SAAS,WAAW;;AAE5B,SAAO;;CAGT,OAAc,QAAyC;EACrD,IAAI,UAAU;AACd,MAAI,CAAC,KAAK,YAAY;AACpB,aAAU,KAAK,OAAO,SAAS;AAC/B,QAAK,SAAS,EAAE;;EAElB,MAAM,aAAa,OAAO,MAAM;AAChC,MAAI,WAAW,SAAS,EACtB,KAAI,KAAK;QACF,MAAM,SAAS,WAClB,KAAI,CAAC,KAAK,KAAK,IAAI,MAAM,EAAE;AACzB,cAAU;AACV,SAAK,KAAK,IAAI,MAAM;AACpB,SAAK,OAAO,KAAK,MAAM;;SAGtB;AACL,aAAU;AACV,QAAK,OAAO,KAAK,GAAG,WAAW;;AAGnC,SAAO;;CAGT,MAA2B;AACzB,MAAI,KAAK,OAAO,WAAW,EACzB,OAAM,IAAI,mBAAmB;AAE/B,SAAO,KAAK;;CAGd,aAAwC;AACtC,SAAO,CAAC,CAAC,GAAG,KAAK,KAAK,EAAE,KAAK,OAAO;;CAGtC,cAAuB;AACrB,SAAO,KAAK,OAAO,WAAW"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
const require_errors = require(
|
|
2
|
-
const require_base = require(
|
|
3
|
-
|
|
1
|
+
const require_errors = require("../errors.cjs");
|
|
2
|
+
const require_base = require("./base.cjs");
|
|
4
3
|
//#region src/channels/untracked_value.ts
|
|
5
4
|
const MISSING = Symbol.for("langgraph.channel.missing");
|
|
6
5
|
/**
|
|
@@ -77,7 +76,7 @@ var UntrackedValueChannel = class UntrackedValueChannel extends require_base.Bas
|
|
|
77
76
|
return this._value !== MISSING;
|
|
78
77
|
}
|
|
79
78
|
};
|
|
80
|
-
|
|
81
79
|
//#endregion
|
|
82
80
|
exports.UntrackedValueChannel = UntrackedValueChannel;
|
|
81
|
+
|
|
83
82
|
//# sourceMappingURL=untracked_value.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"untracked_value.cjs","names":["BaseChannel","InvalidUpdateError","EmptyChannelError"],"sources":["../../src/channels/untracked_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n// Sentinel value for missing/unset\nconst MISSING = Symbol.for(\"langgraph.channel.missing\");\n\n/**\n * Stores the last value received, never checkpointed.\n *\n * This channel stores values during graph execution but does NOT persist\n * the value to checkpoints. On restoration from a checkpoint, the value\n * will be reset to empty (or the initial value if provided).\n *\n * Useful for transient state like:\n * - Database connections\n * - Temporary caches\n * - Runtime-only configuration\n *\n * @internal\n */\nexport class UntrackedValueChannel<Value> extends BaseChannel<\n Value,\n Value,\n undefined\n> {\n lc_graph_name = \"UntrackedValue\";\n\n /**\n * If true, throws an error when multiple values are received in a single step.\n * If false, stores the last value received.\n */\n guard: boolean;\n\n /**\n * The current value. MISSING sentinel indicates no value has been set.\n */\n private _value: Value | typeof MISSING = MISSING;\n\n /**\n * Optional factory function for the initial value.\n */\n private initialValueFactory?: () => Value;\n\n constructor(options?: {\n guard?: boolean;\n initialValueFactory?: () => Value;\n }) {\n super();\n this.guard = options?.guard ?? true;\n this.initialValueFactory = options?.initialValueFactory;\n if (this.initialValueFactory) {\n this._value = this.initialValueFactory();\n }\n }\n\n /**\n * Return a new channel, ignoring the checkpoint since we don't persist.\n * The initial value (if any) is restored.\n */\n fromCheckpoint(_checkpoint?: undefined): this {\n const empty = new UntrackedValueChannel<Value>({\n guard: this.guard,\n initialValueFactory: this.initialValueFactory,\n });\n return empty as this;\n }\n\n /**\n * Update the channel with the given values.\n * If guard is true, throws if more than one value is received.\n */\n update(values: Value[]): boolean {\n if (values.length === 0) {\n return false;\n }\n\n if (values.length !== 1 && this.guard) {\n throw new InvalidUpdateError(\n \"UntrackedValue(guard=true) can receive only one value per step. \" +\n \"Use guard=false if you want to store any one of multiple values.\",\n { lc_error_code: \"INVALID_CONCURRENT_GRAPH_UPDATE\" }\n );\n }\n\n this._value = values[values.length - 1];\n return true;\n }\n\n /**\n * Get the current value.\n * @throws EmptyChannelError if no value has been set.\n */\n get(): Value {\n if (this._value === MISSING) {\n throw new EmptyChannelError();\n }\n return this._value;\n }\n\n /**\n * Always returns undefined - untracked values are never checkpointed.\n */\n checkpoint(): undefined {\n return undefined;\n }\n\n /**\n * Return true if a value has been set.\n */\n isAvailable(): boolean {\n return this._value !== MISSING;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"untracked_value.cjs","names":["BaseChannel","InvalidUpdateError","EmptyChannelError"],"sources":["../../src/channels/untracked_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n// Sentinel value for missing/unset\nconst MISSING = Symbol.for(\"langgraph.channel.missing\");\n\n/**\n * Stores the last value received, never checkpointed.\n *\n * This channel stores values during graph execution but does NOT persist\n * the value to checkpoints. On restoration from a checkpoint, the value\n * will be reset to empty (or the initial value if provided).\n *\n * Useful for transient state like:\n * - Database connections\n * - Temporary caches\n * - Runtime-only configuration\n *\n * @internal\n */\nexport class UntrackedValueChannel<Value> extends BaseChannel<\n Value,\n Value,\n undefined\n> {\n lc_graph_name = \"UntrackedValue\";\n\n /**\n * If true, throws an error when multiple values are received in a single step.\n * If false, stores the last value received.\n */\n guard: boolean;\n\n /**\n * The current value. MISSING sentinel indicates no value has been set.\n */\n private _value: Value | typeof MISSING = MISSING;\n\n /**\n * Optional factory function for the initial value.\n */\n private initialValueFactory?: () => Value;\n\n constructor(options?: {\n guard?: boolean;\n initialValueFactory?: () => Value;\n }) {\n super();\n this.guard = options?.guard ?? true;\n this.initialValueFactory = options?.initialValueFactory;\n if (this.initialValueFactory) {\n this._value = this.initialValueFactory();\n }\n }\n\n /**\n * Return a new channel, ignoring the checkpoint since we don't persist.\n * The initial value (if any) is restored.\n */\n fromCheckpoint(_checkpoint?: undefined): this {\n const empty = new UntrackedValueChannel<Value>({\n guard: this.guard,\n initialValueFactory: this.initialValueFactory,\n });\n return empty as this;\n }\n\n /**\n * Update the channel with the given values.\n * If guard is true, throws if more than one value is received.\n */\n update(values: Value[]): boolean {\n if (values.length === 0) {\n return false;\n }\n\n if (values.length !== 1 && this.guard) {\n throw new InvalidUpdateError(\n \"UntrackedValue(guard=true) can receive only one value per step. \" +\n \"Use guard=false if you want to store any one of multiple values.\",\n { lc_error_code: \"INVALID_CONCURRENT_GRAPH_UPDATE\" }\n );\n }\n\n this._value = values[values.length - 1];\n return true;\n }\n\n /**\n * Get the current value.\n * @throws EmptyChannelError if no value has been set.\n */\n get(): Value {\n if (this._value === MISSING) {\n throw new EmptyChannelError();\n }\n return this._value;\n }\n\n /**\n * Always returns undefined - untracked values are never checkpointed.\n */\n checkpoint(): undefined {\n return undefined;\n }\n\n /**\n * Return true if a value has been set.\n */\n isAvailable(): boolean {\n return this._value !== MISSING;\n }\n}\n"],"mappings":";;;AAIA,MAAM,UAAU,OAAO,IAAI,4BAA4B;;;;;;;;;;;;;;;AAgBvD,IAAa,wBAAb,MAAa,8BAAqCA,aAAAA,YAIhD;CACA,gBAAgB;;;;;CAMhB;;;;CAKA,SAAyC;;;;CAKzC;CAEA,YAAY,SAGT;AACD,SAAO;AACP,OAAK,QAAQ,SAAS,SAAS;AAC/B,OAAK,sBAAsB,SAAS;AACpC,MAAI,KAAK,oBACP,MAAK,SAAS,KAAK,qBAAqB;;;;;;CAQ5C,eAAe,aAA+B;AAK5C,SAJc,IAAI,sBAA6B;GAC7C,OAAO,KAAK;GACZ,qBAAqB,KAAK;GAC3B,CAAC;;;;;;CAQJ,OAAO,QAA0B;AAC/B,MAAI,OAAO,WAAW,EACpB,QAAO;AAGT,MAAI,OAAO,WAAW,KAAK,KAAK,MAC9B,OAAM,IAAIC,eAAAA,mBACR,oIAEA,EAAE,eAAe,mCAAmC,CACrD;AAGH,OAAK,SAAS,OAAO,OAAO,SAAS;AACrC,SAAO;;;;;;CAOT,MAAa;AACX,MAAI,KAAK,WAAW,QAClB,OAAM,IAAIC,eAAAA,mBAAmB;AAE/B,SAAO,KAAK;;;;;CAMd,aAAwB;;;;CAOxB,cAAuB;AACrB,SAAO,KAAK,WAAW"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EmptyChannelError, InvalidUpdateError } from "../errors.js";
|
|
2
2
|
import { BaseChannel } from "./base.js";
|
|
3
|
-
|
|
4
3
|
//#region src/channels/untracked_value.ts
|
|
5
4
|
const MISSING = Symbol.for("langgraph.channel.missing");
|
|
6
5
|
/**
|
|
@@ -77,7 +76,7 @@ var UntrackedValueChannel = class UntrackedValueChannel extends BaseChannel {
|
|
|
77
76
|
return this._value !== MISSING;
|
|
78
77
|
}
|
|
79
78
|
};
|
|
80
|
-
|
|
81
79
|
//#endregion
|
|
82
80
|
export { UntrackedValueChannel };
|
|
81
|
+
|
|
83
82
|
//# sourceMappingURL=untracked_value.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"untracked_value.js","names":[],"sources":["../../src/channels/untracked_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n// Sentinel value for missing/unset\nconst MISSING = Symbol.for(\"langgraph.channel.missing\");\n\n/**\n * Stores the last value received, never checkpointed.\n *\n * This channel stores values during graph execution but does NOT persist\n * the value to checkpoints. On restoration from a checkpoint, the value\n * will be reset to empty (or the initial value if provided).\n *\n * Useful for transient state like:\n * - Database connections\n * - Temporary caches\n * - Runtime-only configuration\n *\n * @internal\n */\nexport class UntrackedValueChannel<Value> extends BaseChannel<\n Value,\n Value,\n undefined\n> {\n lc_graph_name = \"UntrackedValue\";\n\n /**\n * If true, throws an error when multiple values are received in a single step.\n * If false, stores the last value received.\n */\n guard: boolean;\n\n /**\n * The current value. MISSING sentinel indicates no value has been set.\n */\n private _value: Value | typeof MISSING = MISSING;\n\n /**\n * Optional factory function for the initial value.\n */\n private initialValueFactory?: () => Value;\n\n constructor(options?: {\n guard?: boolean;\n initialValueFactory?: () => Value;\n }) {\n super();\n this.guard = options?.guard ?? true;\n this.initialValueFactory = options?.initialValueFactory;\n if (this.initialValueFactory) {\n this._value = this.initialValueFactory();\n }\n }\n\n /**\n * Return a new channel, ignoring the checkpoint since we don't persist.\n * The initial value (if any) is restored.\n */\n fromCheckpoint(_checkpoint?: undefined): this {\n const empty = new UntrackedValueChannel<Value>({\n guard: this.guard,\n initialValueFactory: this.initialValueFactory,\n });\n return empty as this;\n }\n\n /**\n * Update the channel with the given values.\n * If guard is true, throws if more than one value is received.\n */\n update(values: Value[]): boolean {\n if (values.length === 0) {\n return false;\n }\n\n if (values.length !== 1 && this.guard) {\n throw new InvalidUpdateError(\n \"UntrackedValue(guard=true) can receive only one value per step. \" +\n \"Use guard=false if you want to store any one of multiple values.\",\n { lc_error_code: \"INVALID_CONCURRENT_GRAPH_UPDATE\" }\n );\n }\n\n this._value = values[values.length - 1];\n return true;\n }\n\n /**\n * Get the current value.\n * @throws EmptyChannelError if no value has been set.\n */\n get(): Value {\n if (this._value === MISSING) {\n throw new EmptyChannelError();\n }\n return this._value;\n }\n\n /**\n * Always returns undefined - untracked values are never checkpointed.\n */\n checkpoint(): undefined {\n return undefined;\n }\n\n /**\n * Return true if a value has been set.\n */\n isAvailable(): boolean {\n return this._value !== MISSING;\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"untracked_value.js","names":[],"sources":["../../src/channels/untracked_value.ts"],"sourcesContent":["import { EmptyChannelError, InvalidUpdateError } from \"../errors.js\";\nimport { BaseChannel } from \"./base.js\";\n\n// Sentinel value for missing/unset\nconst MISSING = Symbol.for(\"langgraph.channel.missing\");\n\n/**\n * Stores the last value received, never checkpointed.\n *\n * This channel stores values during graph execution but does NOT persist\n * the value to checkpoints. On restoration from a checkpoint, the value\n * will be reset to empty (or the initial value if provided).\n *\n * Useful for transient state like:\n * - Database connections\n * - Temporary caches\n * - Runtime-only configuration\n *\n * @internal\n */\nexport class UntrackedValueChannel<Value> extends BaseChannel<\n Value,\n Value,\n undefined\n> {\n lc_graph_name = \"UntrackedValue\";\n\n /**\n * If true, throws an error when multiple values are received in a single step.\n * If false, stores the last value received.\n */\n guard: boolean;\n\n /**\n * The current value. MISSING sentinel indicates no value has been set.\n */\n private _value: Value | typeof MISSING = MISSING;\n\n /**\n * Optional factory function for the initial value.\n */\n private initialValueFactory?: () => Value;\n\n constructor(options?: {\n guard?: boolean;\n initialValueFactory?: () => Value;\n }) {\n super();\n this.guard = options?.guard ?? true;\n this.initialValueFactory = options?.initialValueFactory;\n if (this.initialValueFactory) {\n this._value = this.initialValueFactory();\n }\n }\n\n /**\n * Return a new channel, ignoring the checkpoint since we don't persist.\n * The initial value (if any) is restored.\n */\n fromCheckpoint(_checkpoint?: undefined): this {\n const empty = new UntrackedValueChannel<Value>({\n guard: this.guard,\n initialValueFactory: this.initialValueFactory,\n });\n return empty as this;\n }\n\n /**\n * Update the channel with the given values.\n * If guard is true, throws if more than one value is received.\n */\n update(values: Value[]): boolean {\n if (values.length === 0) {\n return false;\n }\n\n if (values.length !== 1 && this.guard) {\n throw new InvalidUpdateError(\n \"UntrackedValue(guard=true) can receive only one value per step. \" +\n \"Use guard=false if you want to store any one of multiple values.\",\n { lc_error_code: \"INVALID_CONCURRENT_GRAPH_UPDATE\" }\n );\n }\n\n this._value = values[values.length - 1];\n return true;\n }\n\n /**\n * Get the current value.\n * @throws EmptyChannelError if no value has been set.\n */\n get(): Value {\n if (this._value === MISSING) {\n throw new EmptyChannelError();\n }\n return this._value;\n }\n\n /**\n * Always returns undefined - untracked values are never checkpointed.\n */\n checkpoint(): undefined {\n return undefined;\n }\n\n /**\n * Return true if a value has been set.\n */\n isAvailable(): boolean {\n return this._value !== MISSING;\n }\n}\n"],"mappings":";;;AAIA,MAAM,UAAU,OAAO,IAAI,4BAA4B;;;;;;;;;;;;;;;AAgBvD,IAAa,wBAAb,MAAa,8BAAqC,YAIhD;CACA,gBAAgB;;;;;CAMhB;;;;CAKA,SAAyC;;;;CAKzC;CAEA,YAAY,SAGT;AACD,SAAO;AACP,OAAK,QAAQ,SAAS,SAAS;AAC/B,OAAK,sBAAsB,SAAS;AACpC,MAAI,KAAK,oBACP,MAAK,SAAS,KAAK,qBAAqB;;;;;;CAQ5C,eAAe,aAA+B;AAK5C,SAJc,IAAI,sBAA6B;GAC7C,OAAO,KAAK;GACZ,qBAAqB,KAAK;GAC3B,CAAC;;;;;;CAQJ,OAAO,QAA0B;AAC/B,MAAI,OAAO,WAAW,EACpB,QAAO;AAGT,MAAI,OAAO,WAAW,KAAK,KAAK,MAC9B,OAAM,IAAI,mBACR,oIAEA,EAAE,eAAe,mCAAmC,CACrD;AAGH,OAAK,SAAS,OAAO,OAAO,SAAS;AACrC,SAAO;;;;;;CAOT,MAAa;AACX,MAAI,KAAK,WAAW,QAClB,OAAM,IAAI,mBAAmB;AAE/B,SAAO,KAAK;;;;;CAMd,aAAwB;;;;CAOxB,cAAuB;AACrB,SAAO,KAAK,WAAW"}
|
package/dist/constants.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
//#region src/constants.ts
|
|
3
2
|
/** Special reserved node name denoting the start of a graph. */
|
|
4
3
|
const START = "__start__";
|
|
@@ -67,8 +66,6 @@ const RESERVED = [
|
|
|
67
66
|
CONFIG_KEY_CHECKPOINT_NS,
|
|
68
67
|
CONFIG_KEY_CHECKPOINT_ID
|
|
69
68
|
];
|
|
70
|
-
const CHECKPOINT_NAMESPACE_SEPARATOR = "|";
|
|
71
|
-
const CHECKPOINT_NAMESPACE_END = ":";
|
|
72
69
|
/**
|
|
73
70
|
* Symbol used internally to identify Command instances.
|
|
74
71
|
* Exported to support cross-version type compatibility.
|
|
@@ -197,7 +194,7 @@ var Overwrite = class {
|
|
|
197
194
|
}
|
|
198
195
|
static isInstance(value) {
|
|
199
196
|
if (!value || typeof value !== "object") return false;
|
|
200
|
-
if (
|
|
197
|
+
if ("__overwrite__" in value) return true;
|
|
201
198
|
if ("lg_name" in value && value.lg_name === "Overwrite") return true;
|
|
202
199
|
return false;
|
|
203
200
|
}
|
|
@@ -219,7 +216,7 @@ var Overwrite = class {
|
|
|
219
216
|
* @internal
|
|
220
217
|
*/
|
|
221
218
|
function _getOverwriteValue(value) {
|
|
222
|
-
if (typeof value === "object" && value !== null &&
|
|
219
|
+
if (typeof value === "object" && value !== null && "__overwrite__" in value) return [true, value[OVERWRITE]];
|
|
223
220
|
return [false, void 0];
|
|
224
221
|
}
|
|
225
222
|
/**
|
|
@@ -252,7 +249,7 @@ function _isOverwriteValue(value) {
|
|
|
252
249
|
*/
|
|
253
250
|
function isInterrupted(values) {
|
|
254
251
|
if (!values || typeof values !== "object") return false;
|
|
255
|
-
if (!(
|
|
252
|
+
if (!("__interrupt__" in values)) return false;
|
|
256
253
|
return Array.isArray(values[INTERRUPT]);
|
|
257
254
|
}
|
|
258
255
|
/**
|
|
@@ -436,11 +433,8 @@ function _deserializeCommandSendObjectGraph(x, seen = /* @__PURE__ */ new Map())
|
|
|
436
433
|
}
|
|
437
434
|
return x;
|
|
438
435
|
}
|
|
439
|
-
|
|
440
436
|
//#endregion
|
|
441
437
|
exports.CACHE_NS_WRITES = CACHE_NS_WRITES;
|
|
442
|
-
exports.CHECKPOINT_NAMESPACE_END = CHECKPOINT_NAMESPACE_END;
|
|
443
|
-
exports.CHECKPOINT_NAMESPACE_SEPARATOR = CHECKPOINT_NAMESPACE_SEPARATOR;
|
|
444
438
|
exports.COMMAND_SYMBOL = COMMAND_SYMBOL;
|
|
445
439
|
exports.CONFIG_KEY_ABORT_SIGNALS = CONFIG_KEY_ABORT_SIGNALS;
|
|
446
440
|
exports.CONFIG_KEY_CALL = CONFIG_KEY_CALL;
|
|
@@ -486,4 +480,5 @@ exports._isSend = _isSend;
|
|
|
486
480
|
exports._isSendInterface = _isSendInterface;
|
|
487
481
|
exports.isCommand = isCommand;
|
|
488
482
|
exports.isInterrupted = isInterrupted;
|
|
483
|
+
|
|
489
484
|
//# sourceMappingURL=constants.cjs.map
|
package/dist/constants.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\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 cache namespaces */\nexport const CACHE_NS_WRITES = \"__pregel_ns_writes\";\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// this one is part of public API\nexport const CONFIG_KEY_CHECKPOINT_MAP = \"checkpoint_map\";\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 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];\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\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 * 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<Node extends string = string, Args = any>\n implements SendInterface<Node, Args>\n{\n lg_name = \"Send\";\n\n public node: Node;\n\n public args: Args;\n\n constructor(node: Node, args: Args) {\n this.node = node;\n this.args = _deserializeCommandSendObjectGraph(args) as Args;\n }\n\n toJSON() {\n return { lg_name: this.lg_name, node: this.node, args: this.args };\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\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 (isCommand(x) && !(x instanceof Command)) {\n result = new Command(x);\n seen.set(x, result);\n // eslint-disable-next-line no-instanceof/no-instanceof\n } else if (_isSendInterface(x) && !(x instanceof Send)) {\n result = new Send(x.node, x.args);\n seen.set(x, result);\n } else if (isCommand(x) || _isSend(x)) {\n result = x;\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":";;;AAGA,MAAa,QAAQ;;AAErB,MAAa,MAAM;AACnB,MAAa,QAAQ;AACrB,MAAa,OAAO;AACpB,MAAa,QAAQ;;AAGrB,MAAa,kBAAkB;AAE/B,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,2BA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AACjC,QAAK,IAAI,GAAG,OAAO;aACV,UAAU,EAAE,IAAI,QAAQ,EAAE,EAAE;AACrC,YAAS;AACT,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,CAC1C,CAAC,OAAmC,OAClC,mCAAmC,OAAO,KAAK;;AAIrD,SAAO;;AAET,QAAO"}
|
|
1
|
+
{"version":3,"file":"constants.cjs","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import { PendingWrite } from \"@langchain/langgraph-checkpoint\";\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 cache namespaces */\nexport const CACHE_NS_WRITES = \"__pregel_ns_writes\";\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// this one is part of public API\nexport const CONFIG_KEY_CHECKPOINT_MAP = \"checkpoint_map\";\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 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];\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\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 * 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<Node extends string = string, Args = any>\n implements SendInterface<Node, Args>\n{\n lg_name = \"Send\";\n\n public node: Node;\n\n public args: Args;\n\n constructor(node: Node, args: Args) {\n this.node = node;\n this.args = _deserializeCommandSendObjectGraph(args) as Args;\n }\n\n toJSON() {\n return { lg_name: this.lg_name, node: this.node, args: this.args };\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\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 (isCommand(x) && !(x instanceof Command)) {\n result = new Command(x);\n seen.set(x, result);\n // eslint-disable-next-line no-instanceof/no-instanceof\n } else if (_isSendInterface(x) && !(x instanceof Send)) {\n result = new Send(x.node, x.args);\n seen.set(x, result);\n } else if (isCommand(x) || _isSend(x)) {\n result = x;\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":";;AAGA,MAAa,QAAQ;;AAErB,MAAa,MAAM;AACnB,MAAa,QAAQ;AACrB,MAAa,OAAO;AACpB,MAAa,QAAQ;;AAGrB,MAAa,kBAAkB;AAE/B,MAAa,kBAAkB;;AAE/B,MAAa,kBAAkB;AAC/B,MAAa,kBAAkB;AAC/B,MAAa,0BA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aAEO,UAAU,EAAE,IAAI,EAAE,aAAa,UAAU;AAClD,YAAS,IAAI,QAAQ,EAAE;AACvB,QAAK,IAAI,GAAG,OAAO;aAEV,iBAAiB,EAAE,IAAI,EAAE,aAAa,OAAO;AACtD,YAAS,IAAI,KAAK,EAAE,MAAM,EAAE,KAAK;AACjC,QAAK,IAAI,GAAG,OAAO;aACV,UAAU,EAAE,IAAI,QAAQ,EAAE,EAAE;AACrC,YAAS;AACT,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"}
|
package/dist/constants.js
CHANGED
|
@@ -66,8 +66,6 @@ const RESERVED = [
|
|
|
66
66
|
CONFIG_KEY_CHECKPOINT_NS,
|
|
67
67
|
CONFIG_KEY_CHECKPOINT_ID
|
|
68
68
|
];
|
|
69
|
-
const CHECKPOINT_NAMESPACE_SEPARATOR = "|";
|
|
70
|
-
const CHECKPOINT_NAMESPACE_END = ":";
|
|
71
69
|
/**
|
|
72
70
|
* Symbol used internally to identify Command instances.
|
|
73
71
|
* Exported to support cross-version type compatibility.
|
|
@@ -196,7 +194,7 @@ var Overwrite = class {
|
|
|
196
194
|
}
|
|
197
195
|
static isInstance(value) {
|
|
198
196
|
if (!value || typeof value !== "object") return false;
|
|
199
|
-
if (
|
|
197
|
+
if ("__overwrite__" in value) return true;
|
|
200
198
|
if ("lg_name" in value && value.lg_name === "Overwrite") return true;
|
|
201
199
|
return false;
|
|
202
200
|
}
|
|
@@ -218,7 +216,7 @@ var Overwrite = class {
|
|
|
218
216
|
* @internal
|
|
219
217
|
*/
|
|
220
218
|
function _getOverwriteValue(value) {
|
|
221
|
-
if (typeof value === "object" && value !== null &&
|
|
219
|
+
if (typeof value === "object" && value !== null && "__overwrite__" in value) return [true, value[OVERWRITE]];
|
|
222
220
|
return [false, void 0];
|
|
223
221
|
}
|
|
224
222
|
/**
|
|
@@ -251,7 +249,7 @@ function _isOverwriteValue(value) {
|
|
|
251
249
|
*/
|
|
252
250
|
function isInterrupted(values) {
|
|
253
251
|
if (!values || typeof values !== "object") return false;
|
|
254
|
-
if (!(
|
|
252
|
+
if (!("__interrupt__" in values)) return false;
|
|
255
253
|
return Array.isArray(values[INTERRUPT]);
|
|
256
254
|
}
|
|
257
255
|
/**
|
|
@@ -435,7 +433,7 @@ function _deserializeCommandSendObjectGraph(x, seen = /* @__PURE__ */ new Map())
|
|
|
435
433
|
}
|
|
436
434
|
return x;
|
|
437
435
|
}
|
|
438
|
-
|
|
439
436
|
//#endregion
|
|
440
|
-
export { CACHE_NS_WRITES,
|
|
437
|
+
export { CACHE_NS_WRITES, COMMAND_SYMBOL, CONFIG_KEY_ABORT_SIGNALS, CONFIG_KEY_CALL, CONFIG_KEY_CHECKPOINTER, CONFIG_KEY_CHECKPOINT_ID, CONFIG_KEY_CHECKPOINT_MAP, CONFIG_KEY_CHECKPOINT_NS, CONFIG_KEY_DURABILITY, CONFIG_KEY_NODE_FINISHED, CONFIG_KEY_PREVIOUS_STATE, CONFIG_KEY_READ, CONFIG_KEY_RESUME_MAP, CONFIG_KEY_RESUMING, CONFIG_KEY_SCRATCHPAD, CONFIG_KEY_SEND, CONFIG_KEY_STREAM, CONFIG_KEY_TASK_ID, COPY, Command, CommandInstance, END, ERROR, INPUT, INTERRUPT, NO_WRITES, NULL_TASK_ID, Overwrite, PREVIOUS, PULL, PUSH, RESERVED, RESUME, RETURN, SELF, START, Send, TAG_HIDDEN, TAG_NOSTREAM, TASKS, _getOverwriteValue, _isOverwriteValue, _isSend, _isSendInterface, isCommand, isInterrupted };
|
|
438
|
+
|
|
441
439
|
//# sourceMappingURL=constants.js.map
|