@langchain/langgraph 1.0.7 → 1.0.12
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/package.json +7 -7
- package/CHANGELOG.md +0 -286
- package/dist/_virtual/rolldown_runtime.cjs +0 -25
- package/dist/channels/any_value.cjs +0 -46
- package/dist/channels/any_value.cjs.map +0 -1
- package/dist/channels/any_value.d.cts +0 -24
- package/dist/channels/any_value.d.cts.map +0 -1
- package/dist/channels/any_value.d.ts +0 -24
- package/dist/channels/any_value.d.ts.map +0 -1
- package/dist/channels/any_value.js +0 -46
- package/dist/channels/any_value.js.map +0 -1
- package/dist/channels/base.cjs +0 -102
- package/dist/channels/base.cjs.map +0 -1
- package/dist/channels/base.d.cts +0 -79
- package/dist/channels/base.d.cts.map +0 -1
- package/dist/channels/base.d.ts +0 -79
- package/dist/channels/base.d.ts.map +0 -1
- package/dist/channels/base.js +0 -97
- package/dist/channels/base.js.map +0 -1
- package/dist/channels/binop.cjs +0 -49
- package/dist/channels/binop.cjs.map +0 -1
- package/dist/channels/binop.d.cts +0 -22
- package/dist/channels/binop.d.cts.map +0 -1
- package/dist/channels/binop.d.ts +0 -22
- package/dist/channels/binop.d.ts.map +0 -1
- package/dist/channels/binop.js +0 -49
- package/dist/channels/binop.js.map +0 -1
- package/dist/channels/dynamic_barrier_value.cjs +0 -76
- package/dist/channels/dynamic_barrier_value.cjs.map +0 -1
- package/dist/channels/dynamic_barrier_value.d.cts +0 -42
- package/dist/channels/dynamic_barrier_value.d.cts.map +0 -1
- package/dist/channels/dynamic_barrier_value.d.ts +0 -42
- package/dist/channels/dynamic_barrier_value.d.ts.map +0 -1
- package/dist/channels/dynamic_barrier_value.js +0 -76
- package/dist/channels/dynamic_barrier_value.js.map +0 -1
- package/dist/channels/ephemeral_value.cjs +0 -46
- package/dist/channels/ephemeral_value.cjs.map +0 -1
- package/dist/channels/ephemeral_value.d.cts +0 -22
- package/dist/channels/ephemeral_value.d.cts.map +0 -1
- package/dist/channels/ephemeral_value.d.ts +0 -22
- package/dist/channels/ephemeral_value.d.ts.map +0 -1
- package/dist/channels/ephemeral_value.js +0 -46
- package/dist/channels/ephemeral_value.js.map +0 -1
- package/dist/channels/index.cjs +0 -21
- package/dist/channels/index.d.cts +0 -9
- package/dist/channels/index.d.ts +0 -9
- package/dist/channels/index.js +0 -10
- package/dist/channels/last_value.cjs +0 -98
- package/dist/channels/last_value.cjs.map +0 -1
- package/dist/channels/last_value.d.cts +0 -44
- package/dist/channels/last_value.d.cts.map +0 -1
- package/dist/channels/last_value.d.ts +0 -44
- package/dist/channels/last_value.d.ts.map +0 -1
- package/dist/channels/last_value.js +0 -97
- package/dist/channels/last_value.js.map +0 -1
- package/dist/channels/named_barrier_value.cjs +0 -118
- package/dist/channels/named_barrier_value.cjs.map +0 -1
- package/dist/channels/named_barrier_value.d.cts +0 -46
- package/dist/channels/named_barrier_value.d.cts.map +0 -1
- package/dist/channels/named_barrier_value.d.ts +0 -46
- package/dist/channels/named_barrier_value.d.ts.map +0 -1
- package/dist/channels/named_barrier_value.js +0 -116
- package/dist/channels/named_barrier_value.js.map +0 -1
- package/dist/channels/topic.cjs +0 -65
- package/dist/channels/topic.cjs.map +0 -1
- package/dist/channels/topic.d.cts +0 -32
- package/dist/channels/topic.d.cts.map +0 -1
- package/dist/channels/topic.d.ts +0 -32
- package/dist/channels/topic.d.ts.map +0 -1
- package/dist/channels/topic.js +0 -65
- package/dist/channels/topic.js.map +0 -1
- package/dist/constants.cjs +0 -406
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -285
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.ts +0 -285
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -362
- package/dist/constants.js.map +0 -1
- package/dist/errors.cjs +0 -163
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -81
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.ts +0 -81
- package/dist/errors.d.ts.map +0 -1
- package/dist/errors.js +0 -146
- package/dist/errors.js.map +0 -1
- package/dist/func/index.cjs +0 -301
- package/dist/func/index.cjs.map +0 -1
- package/dist/func/index.d.cts +0 -293
- package/dist/func/index.d.cts.map +0 -1
- package/dist/func/index.d.ts +0 -293
- package/dist/func/index.d.ts.map +0 -1
- package/dist/func/index.js +0 -298
- package/dist/func/index.js.map +0 -1
- package/dist/func/types.d.cts +0 -64
- package/dist/func/types.d.cts.map +0 -1
- package/dist/func/types.d.ts +0 -64
- package/dist/func/types.d.ts.map +0 -1
- package/dist/graph/annotation.cjs +0 -101
- package/dist/graph/annotation.cjs.map +0 -1
- package/dist/graph/annotation.d.cts +0 -116
- package/dist/graph/annotation.d.cts.map +0 -1
- package/dist/graph/annotation.d.ts +0 -116
- package/dist/graph/annotation.d.ts.map +0 -1
- package/dist/graph/annotation.js +0 -99
- package/dist/graph/annotation.js.map +0 -1
- package/dist/graph/graph.cjs +0 -423
- package/dist/graph/graph.cjs.map +0 -1
- package/dist/graph/graph.d.cts +0 -132
- package/dist/graph/graph.d.cts.map +0 -1
- package/dist/graph/graph.d.ts +0 -132
- package/dist/graph/graph.d.ts.map +0 -1
- package/dist/graph/graph.js +0 -420
- package/dist/graph/graph.js.map +0 -1
- package/dist/graph/index.cjs +0 -5
- package/dist/graph/index.js +0 -7
- package/dist/graph/message.cjs +0 -99
- package/dist/graph/message.cjs.map +0 -1
- package/dist/graph/message.d.cts +0 -40
- package/dist/graph/message.d.cts.map +0 -1
- package/dist/graph/message.d.ts +0 -40
- package/dist/graph/message.d.ts.map +0 -1
- package/dist/graph/message.js +0 -95
- package/dist/graph/message.js.map +0 -1
- package/dist/graph/messages_annotation.cjs +0 -110
- package/dist/graph/messages_annotation.cjs.map +0 -1
- package/dist/graph/messages_annotation.d.cts +0 -112
- package/dist/graph/messages_annotation.d.cts.map +0 -1
- package/dist/graph/messages_annotation.d.ts +0 -112
- package/dist/graph/messages_annotation.d.ts.map +0 -1
- package/dist/graph/messages_annotation.js +0 -107
- package/dist/graph/messages_annotation.js.map +0 -1
- package/dist/graph/state.cjs +0 -501
- package/dist/graph/state.cjs.map +0 -1
- package/dist/graph/state.d.cts +0 -236
- package/dist/graph/state.d.cts.map +0 -1
- package/dist/graph/state.d.ts +0 -236
- package/dist/graph/state.d.ts.map +0 -1
- package/dist/graph/state.js +0 -499
- package/dist/graph/state.js.map +0 -1
- package/dist/graph/zod/index.cjs +0 -10
- package/dist/graph/zod/index.d.cts +0 -3
- package/dist/graph/zod/index.d.ts +0 -3
- package/dist/graph/zod/index.js +0 -5
- package/dist/graph/zod/meta.cjs +0 -145
- package/dist/graph/zod/meta.cjs.map +0 -1
- package/dist/graph/zod/meta.d.cts +0 -116
- package/dist/graph/zod/meta.d.cts.map +0 -1
- package/dist/graph/zod/meta.d.ts +0 -116
- package/dist/graph/zod/meta.d.ts.map +0 -1
- package/dist/graph/zod/meta.js +0 -141
- package/dist/graph/zod/meta.js.map +0 -1
- package/dist/graph/zod/plugin.cjs +0 -41
- package/dist/graph/zod/plugin.cjs.map +0 -1
- package/dist/graph/zod/plugin.js +0 -41
- package/dist/graph/zod/plugin.js.map +0 -1
- package/dist/graph/zod/schema.cjs +0 -99
- package/dist/graph/zod/schema.cjs.map +0 -1
- package/dist/graph/zod/schema.d.cts +0 -38
- package/dist/graph/zod/schema.d.cts.map +0 -1
- package/dist/graph/zod/schema.d.ts +0 -38
- package/dist/graph/zod/schema.d.ts.map +0 -1
- package/dist/graph/zod/schema.js +0 -94
- package/dist/graph/zod/schema.js.map +0 -1
- package/dist/graph/zod/zod-registry.cjs +0 -43
- package/dist/graph/zod/zod-registry.cjs.map +0 -1
- package/dist/graph/zod/zod-registry.d.cts +0 -51
- package/dist/graph/zod/zod-registry.d.cts.map +0 -1
- package/dist/graph/zod/zod-registry.d.ts +0 -51
- package/dist/graph/zod/zod-registry.d.ts.map +0 -1
- package/dist/graph/zod/zod-registry.js +0 -41
- package/dist/graph/zod/zod-registry.js.map +0 -1
- package/dist/hash.cjs +0 -271
- package/dist/hash.cjs.map +0 -1
- package/dist/hash.js +0 -269
- package/dist/hash.js.map +0 -1
- package/dist/index.cjs +0 -112
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -26
- package/dist/index.d.ts +0 -26
- package/dist/index.js +0 -22
- package/dist/index.js.map +0 -1
- package/dist/interrupt.cjs +0 -82
- package/dist/interrupt.cjs.map +0 -1
- package/dist/interrupt.d.cts +0 -58
- package/dist/interrupt.d.cts.map +0 -1
- package/dist/interrupt.d.ts +0 -58
- package/dist/interrupt.d.ts.map +0 -1
- package/dist/interrupt.js +0 -81
- package/dist/interrupt.js.map +0 -1
- package/dist/prebuilt/agentName.cjs +0 -153
- package/dist/prebuilt/agentName.cjs.map +0 -1
- package/dist/prebuilt/agentName.d.cts +0 -42
- package/dist/prebuilt/agentName.d.cts.map +0 -1
- package/dist/prebuilt/agentName.d.ts +0 -42
- package/dist/prebuilt/agentName.d.ts.map +0 -1
- package/dist/prebuilt/agentName.js +0 -152
- package/dist/prebuilt/agentName.js.map +0 -1
- package/dist/prebuilt/agent_executor.cjs +0 -44
- package/dist/prebuilt/agent_executor.cjs.map +0 -1
- package/dist/prebuilt/agent_executor.d.cts +0 -58
- package/dist/prebuilt/agent_executor.d.cts.map +0 -1
- package/dist/prebuilt/agent_executor.d.ts +0 -58
- package/dist/prebuilt/agent_executor.d.ts.map +0 -1
- package/dist/prebuilt/agent_executor.js +0 -44
- package/dist/prebuilt/agent_executor.js.map +0 -1
- package/dist/prebuilt/chat_agent_executor.cjs +0 -68
- package/dist/prebuilt/chat_agent_executor.cjs.map +0 -1
- package/dist/prebuilt/chat_agent_executor.d.cts +0 -23
- package/dist/prebuilt/chat_agent_executor.d.cts.map +0 -1
- package/dist/prebuilt/chat_agent_executor.d.ts +0 -23
- package/dist/prebuilt/chat_agent_executor.d.ts.map +0 -1
- package/dist/prebuilt/chat_agent_executor.js +0 -67
- package/dist/prebuilt/chat_agent_executor.js.map +0 -1
- package/dist/prebuilt/index.cjs +0 -15
- package/dist/prebuilt/index.d.cts +0 -8
- package/dist/prebuilt/index.d.ts +0 -8
- package/dist/prebuilt/index.js +0 -8
- package/dist/prebuilt/interrupt.d.cts +0 -61
- package/dist/prebuilt/interrupt.d.cts.map +0 -1
- package/dist/prebuilt/interrupt.d.ts +0 -61
- package/dist/prebuilt/interrupt.d.ts.map +0 -1
- package/dist/prebuilt/react_agent_executor.cjs +0 -344
- package/dist/prebuilt/react_agent_executor.cjs.map +0 -1
- package/dist/prebuilt/react_agent_executor.d.cts +0 -230
- package/dist/prebuilt/react_agent_executor.d.cts.map +0 -1
- package/dist/prebuilt/react_agent_executor.d.ts +0 -230
- package/dist/prebuilt/react_agent_executor.d.ts.map +0 -1
- package/dist/prebuilt/react_agent_executor.js +0 -342
- package/dist/prebuilt/react_agent_executor.js.map +0 -1
- package/dist/prebuilt/tool_executor.cjs +0 -48
- package/dist/prebuilt/tool_executor.cjs.map +0 -1
- package/dist/prebuilt/tool_executor.d.cts +0 -42
- package/dist/prebuilt/tool_executor.d.cts.map +0 -1
- package/dist/prebuilt/tool_executor.d.ts +0 -42
- package/dist/prebuilt/tool_executor.d.ts.map +0 -1
- package/dist/prebuilt/tool_executor.js +0 -47
- package/dist/prebuilt/tool_executor.js.map +0 -1
- package/dist/prebuilt/tool_node.cjs +0 -248
- package/dist/prebuilt/tool_node.cjs.map +0 -1
- package/dist/prebuilt/tool_node.d.cts +0 -182
- package/dist/prebuilt/tool_node.d.cts.map +0 -1
- package/dist/prebuilt/tool_node.d.ts +0 -182
- package/dist/prebuilt/tool_node.d.ts.map +0 -1
- package/dist/prebuilt/tool_node.js +0 -246
- package/dist/prebuilt/tool_node.js.map +0 -1
- package/dist/pregel/algo.cjs +0 -573
- package/dist/pregel/algo.cjs.map +0 -1
- package/dist/pregel/algo.d.cts +0 -13
- package/dist/pregel/algo.d.cts.map +0 -1
- package/dist/pregel/algo.d.ts +0 -13
- package/dist/pregel/algo.d.ts.map +0 -1
- package/dist/pregel/algo.js +0 -567
- package/dist/pregel/algo.js.map +0 -1
- package/dist/pregel/call.cjs +0 -53
- package/dist/pregel/call.cjs.map +0 -1
- package/dist/pregel/call.js +0 -50
- package/dist/pregel/call.js.map +0 -1
- package/dist/pregel/debug.cjs +0 -175
- package/dist/pregel/debug.cjs.map +0 -1
- package/dist/pregel/debug.js +0 -169
- package/dist/pregel/debug.js.map +0 -1
- package/dist/pregel/index.cjs +0 -1170
- package/dist/pregel/index.cjs.map +0 -1
- package/dist/pregel/index.d.cts +0 -546
- package/dist/pregel/index.d.cts.map +0 -1
- package/dist/pregel/index.d.ts +0 -546
- package/dist/pregel/index.d.ts.map +0 -1
- package/dist/pregel/index.js +0 -1168
- package/dist/pregel/index.js.map +0 -1
- package/dist/pregel/io.cjs +0 -140
- package/dist/pregel/io.cjs.map +0 -1
- package/dist/pregel/io.js +0 -135
- package/dist/pregel/io.js.map +0 -1
- package/dist/pregel/loop.cjs +0 -548
- package/dist/pregel/loop.cjs.map +0 -1
- package/dist/pregel/loop.js +0 -547
- package/dist/pregel/loop.js.map +0 -1
- package/dist/pregel/messages.cjs +0 -108
- package/dist/pregel/messages.cjs.map +0 -1
- package/dist/pregel/messages.js +0 -107
- package/dist/pregel/messages.js.map +0 -1
- package/dist/pregel/read.cjs +0 -152
- package/dist/pregel/read.cjs.map +0 -1
- package/dist/pregel/read.d.cts +0 -51
- package/dist/pregel/read.d.cts.map +0 -1
- package/dist/pregel/read.d.ts +0 -51
- package/dist/pregel/read.d.ts.map +0 -1
- package/dist/pregel/read.js +0 -150
- package/dist/pregel/read.js.map +0 -1
- package/dist/pregel/remote.cjs +0 -349
- package/dist/pregel/remote.cjs.map +0 -1
- package/dist/pregel/remote.d.cts +0 -123
- package/dist/pregel/remote.d.cts.map +0 -1
- package/dist/pregel/remote.d.ts +0 -123
- package/dist/pregel/remote.d.ts.map +0 -1
- package/dist/pregel/remote.js +0 -348
- package/dist/pregel/remote.js.map +0 -1
- package/dist/pregel/retry.cjs +0 -92
- package/dist/pregel/retry.cjs.map +0 -1
- package/dist/pregel/retry.js +0 -92
- package/dist/pregel/retry.js.map +0 -1
- package/dist/pregel/runnable_types.d.cts +0 -49
- package/dist/pregel/runnable_types.d.cts.map +0 -1
- package/dist/pregel/runnable_types.d.ts +0 -49
- package/dist/pregel/runnable_types.d.ts.map +0 -1
- package/dist/pregel/runner.cjs +0 -228
- package/dist/pregel/runner.cjs.map +0 -1
- package/dist/pregel/runner.js +0 -228
- package/dist/pregel/runner.js.map +0 -1
- package/dist/pregel/stream.cjs +0 -199
- package/dist/pregel/stream.cjs.map +0 -1
- package/dist/pregel/stream.js +0 -196
- package/dist/pregel/stream.js.map +0 -1
- package/dist/pregel/types.cjs +0 -27
- package/dist/pregel/types.cjs.map +0 -1
- package/dist/pregel/types.d.cts +0 -453
- package/dist/pregel/types.d.cts.map +0 -1
- package/dist/pregel/types.d.ts +0 -453
- package/dist/pregel/types.d.ts.map +0 -1
- package/dist/pregel/types.js +0 -25
- package/dist/pregel/types.js.map +0 -1
- package/dist/pregel/utils/config.cjs +0 -122
- package/dist/pregel/utils/config.cjs.map +0 -1
- package/dist/pregel/utils/config.d.cts +0 -36
- package/dist/pregel/utils/config.d.cts.map +0 -1
- package/dist/pregel/utils/config.d.ts +0 -36
- package/dist/pregel/utils/config.d.ts.map +0 -1
- package/dist/pregel/utils/config.js +0 -115
- package/dist/pregel/utils/config.js.map +0 -1
- package/dist/pregel/utils/index.cjs +0 -103
- package/dist/pregel/utils/index.cjs.map +0 -1
- package/dist/pregel/utils/index.d.cts +0 -51
- package/dist/pregel/utils/index.d.cts.map +0 -1
- package/dist/pregel/utils/index.d.ts +0 -51
- package/dist/pregel/utils/index.d.ts.map +0 -1
- package/dist/pregel/utils/index.js +0 -97
- package/dist/pregel/utils/index.js.map +0 -1
- package/dist/pregel/utils/subgraph.cjs +0 -19
- package/dist/pregel/utils/subgraph.cjs.map +0 -1
- package/dist/pregel/utils/subgraph.js +0 -17
- package/dist/pregel/utils/subgraph.js.map +0 -1
- package/dist/pregel/validate.cjs +0 -45
- package/dist/pregel/validate.cjs.map +0 -1
- package/dist/pregel/validate.js +0 -44
- package/dist/pregel/validate.js.map +0 -1
- package/dist/pregel/write.cjs +0 -97
- package/dist/pregel/write.cjs.map +0 -1
- package/dist/pregel/write.d.cts +0 -35
- package/dist/pregel/write.d.cts.map +0 -1
- package/dist/pregel/write.d.ts +0 -35
- package/dist/pregel/write.d.ts.map +0 -1
- package/dist/pregel/write.js +0 -95
- package/dist/pregel/write.js.map +0 -1
- package/dist/remote.cjs +0 -3
- package/dist/remote.d.cts +0 -2
- package/dist/remote.d.ts +0 -2
- package/dist/remote.js +0 -3
- package/dist/setup/async_local_storage.cjs +0 -12
- package/dist/setup/async_local_storage.cjs.map +0 -1
- package/dist/setup/async_local_storage.js +0 -11
- package/dist/setup/async_local_storage.js.map +0 -1
- package/dist/utils.cjs +0 -88
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts +0 -32
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.ts +0 -32
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -81
- package/dist/utils.js.map +0 -1
- package/dist/web.cjs +0 -96
- package/dist/web.d.cts +0 -23
- package/dist/web.d.ts +0 -23
- package/dist/web.js +0 -15
- package/dist/writer.cjs +0 -15
- package/dist/writer.cjs.map +0 -1
- package/dist/writer.d.cts +0 -7
- package/dist/writer.d.cts.map +0 -1
- package/dist/writer.d.ts +0 -7
- package/dist/writer.d.ts.map +0 -1
- package/dist/writer.js +0 -14
- package/dist/writer.js.map +0 -1
package/dist/func/index.js
DELETED
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import { LastValue } from "../channels/last_value.js";
|
|
2
|
-
import { CONFIG_KEY_PREVIOUS_STATE, END, PREVIOUS, START, TAG_HIDDEN } from "../constants.js";
|
|
3
|
-
import { RunnableCallable, isAsyncGeneratorFunction, isGeneratorFunction } from "../utils.js";
|
|
4
|
-
import { ChannelWrite, PASSTHROUGH } from "../pregel/write.js";
|
|
5
|
-
import { PregelNode } from "../pregel/read.js";
|
|
6
|
-
import { call, getRunnableForEntrypoint } from "../pregel/call.js";
|
|
7
|
-
import { Pregel } from "../pregel/index.js";
|
|
8
|
-
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
9
|
-
import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
|
|
10
|
-
|
|
11
|
-
//#region src/func/index.ts
|
|
12
|
-
/**
|
|
13
|
-
* Define a LangGraph task using the `task` function.
|
|
14
|
-
*
|
|
15
|
-
* Tasks can only be called from within an {@link entrypoint} or from within a StateGraph.
|
|
16
|
-
* A task can be called like a regular function with the following differences:
|
|
17
|
-
*
|
|
18
|
-
* - When a checkpointer is enabled, the function inputs and outputs must be serializable.
|
|
19
|
-
* - The wrapped function can only be called from within an entrypoint or StateGraph.
|
|
20
|
-
* - Calling the function produces a promise. This makes it easy to parallelize tasks.
|
|
21
|
-
*
|
|
22
|
-
* @typeParam ArgsT - The type of arguments the task function accepts
|
|
23
|
-
* @typeParam OutputT - The type of value the task function returns
|
|
24
|
-
* @param optionsOrName - Either an {@link TaskOptions} object, or a string for the name of the task
|
|
25
|
-
* @param func - The function that executes this task
|
|
26
|
-
* @returns A proxy function that accepts the same arguments as the original and always returns the result as a Promise
|
|
27
|
-
*
|
|
28
|
-
* @example basic example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* const addOne = task("add", async (a: number) => a + 1);
|
|
31
|
-
*
|
|
32
|
-
* const workflow = entrypoint("example", async (numbers: number[]) => {
|
|
33
|
-
* const promises = numbers.map(n => addOne(n));
|
|
34
|
-
* const results = await Promise.all(promises);
|
|
35
|
-
* return results;
|
|
36
|
-
* });
|
|
37
|
-
*
|
|
38
|
-
* // Call the entrypoint
|
|
39
|
-
* await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]
|
|
40
|
-
* ```
|
|
41
|
-
*
|
|
42
|
-
* @example using a retry policy
|
|
43
|
-
* ```typescript
|
|
44
|
-
* const addOne = task({
|
|
45
|
-
* name: "add",
|
|
46
|
-
* retry: { maxAttempts: 3 }
|
|
47
|
-
* },
|
|
48
|
-
* async (a: number) => a + 1
|
|
49
|
-
* );
|
|
50
|
-
*
|
|
51
|
-
* const workflow = entrypoint("example", async (numbers: number[]) => {
|
|
52
|
-
* const promises = numbers.map(n => addOne(n));
|
|
53
|
-
* const results = await Promise.all(promises);
|
|
54
|
-
* return results;
|
|
55
|
-
* });
|
|
56
|
-
* ```
|
|
57
|
-
* @category Functional API
|
|
58
|
-
*/
|
|
59
|
-
function task(optionsOrName, func) {
|
|
60
|
-
const options = typeof optionsOrName === "string" ? {
|
|
61
|
-
name: optionsOrName,
|
|
62
|
-
retry: void 0,
|
|
63
|
-
cachePolicy: void 0
|
|
64
|
-
} : optionsOrName;
|
|
65
|
-
const { name, retry } = options;
|
|
66
|
-
if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) throw new Error("Generators are disallowed as tasks. For streaming responses, use config.write.");
|
|
67
|
-
const cachePolicy = options.cachePolicy ?? ("cache" in options ? options.cache : void 0);
|
|
68
|
-
let cache;
|
|
69
|
-
if (typeof cachePolicy === "boolean") cache = cachePolicy ? {} : void 0;
|
|
70
|
-
else cache = cachePolicy;
|
|
71
|
-
return (...args) => {
|
|
72
|
-
return call({
|
|
73
|
-
func,
|
|
74
|
-
name,
|
|
75
|
-
retry,
|
|
76
|
-
cache
|
|
77
|
-
}, ...args);
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Define a LangGraph workflow using the `entrypoint` function.
|
|
82
|
-
*
|
|
83
|
-
* ### Function signature
|
|
84
|
-
*
|
|
85
|
-
* The wrapped function must accept at most **two parameters**. The first parameter
|
|
86
|
-
* is the input to the function. The second (optional) parameter is a
|
|
87
|
-
* {@link LangGraphRunnableConfig} object. If you wish to pass multiple parameters to
|
|
88
|
-
* the function, you can pass them as an object.
|
|
89
|
-
*
|
|
90
|
-
* ### Helper functions
|
|
91
|
-
*
|
|
92
|
-
* #### Streaming
|
|
93
|
-
* To write data to the "custom" stream, use the {@link getWriter} function, or the
|
|
94
|
-
* {@link LangGraphRunnableConfig.writer} property.
|
|
95
|
-
*
|
|
96
|
-
* #### State management
|
|
97
|
-
* The {@link getPreviousState} function can be used to access the previous state
|
|
98
|
-
* that was returned from the last invocation of the entrypoint on the same thread id.
|
|
99
|
-
*
|
|
100
|
-
* If you wish to save state other than the return value, you can use the
|
|
101
|
-
* {@link entrypoint.final} function.
|
|
102
|
-
*
|
|
103
|
-
* @typeParam InputT - The type of input the entrypoint accepts
|
|
104
|
-
* @typeParam OutputT - The type of output the entrypoint produces
|
|
105
|
-
* @param optionsOrName - Either an {@link EntrypointOptions} object, or a string for the name of the entrypoint
|
|
106
|
-
* @param func - The function that executes this entrypoint
|
|
107
|
-
* @returns A {@link Pregel} instance that can be run to execute the workflow
|
|
108
|
-
*
|
|
109
|
-
* @example Using entrypoint and tasks
|
|
110
|
-
* ```typescript
|
|
111
|
-
* import { task, entrypoint } from "@langchain/langgraph";
|
|
112
|
-
* import { MemorySaver } from "@langchain/langgraph-checkpoint";
|
|
113
|
-
* import { interrupt, Command } from "@langchain/langgraph";
|
|
114
|
-
*
|
|
115
|
-
* const composeEssay = task("compose", async (topic: string) => {
|
|
116
|
-
* await new Promise(r => setTimeout(r, 1000)); // Simulate slow operation
|
|
117
|
-
* return `An essay about ${topic}`;
|
|
118
|
-
* });
|
|
119
|
-
*
|
|
120
|
-
* const reviewWorkflow = entrypoint({
|
|
121
|
-
* name: "review",
|
|
122
|
-
* checkpointer: new MemorySaver()
|
|
123
|
-
* }, async (topic: string) => {
|
|
124
|
-
* const essay = await composeEssay(topic);
|
|
125
|
-
* const humanReview = await interrupt({
|
|
126
|
-
* question: "Please provide a review",
|
|
127
|
-
* essay
|
|
128
|
-
* });
|
|
129
|
-
* return {
|
|
130
|
-
* essay,
|
|
131
|
-
* review: humanReview
|
|
132
|
-
* };
|
|
133
|
-
* });
|
|
134
|
-
*
|
|
135
|
-
* // Example configuration for the workflow
|
|
136
|
-
* const config = {
|
|
137
|
-
* configurable: {
|
|
138
|
-
* thread_id: "some_thread"
|
|
139
|
-
* }
|
|
140
|
-
* };
|
|
141
|
-
*
|
|
142
|
-
* // Topic for the essay
|
|
143
|
-
* const topic = "cats";
|
|
144
|
-
*
|
|
145
|
-
* // Stream the workflow to generate the essay and await human review
|
|
146
|
-
* for await (const result of reviewWorkflow.stream(topic, config)) {
|
|
147
|
-
* console.log(result);
|
|
148
|
-
* }
|
|
149
|
-
*
|
|
150
|
-
* // Example human review provided after the interrupt
|
|
151
|
-
* const humanReview = "This essay is great.";
|
|
152
|
-
*
|
|
153
|
-
* // Resume the workflow with the provided human review
|
|
154
|
-
* for await (const result of reviewWorkflow.stream(new Command({ resume: humanReview }), config)) {
|
|
155
|
-
* console.log(result);
|
|
156
|
-
* }
|
|
157
|
-
* ```
|
|
158
|
-
*
|
|
159
|
-
* @example Accessing the previous return value
|
|
160
|
-
* ```typescript
|
|
161
|
-
* import { entrypoint, getPreviousState } from "@langchain/langgraph";
|
|
162
|
-
* import { MemorySaver } from "@langchain/langgraph-checkpoint";
|
|
163
|
-
*
|
|
164
|
-
* const accumulator = entrypoint({
|
|
165
|
-
* name: "accumulator",
|
|
166
|
-
* checkpointer: new MemorySaver()
|
|
167
|
-
* }, async (input: string) => {
|
|
168
|
-
* const previous = getPreviousState<number>();
|
|
169
|
-
* return previous !== undefined ? `${previous } ${input}` : input;
|
|
170
|
-
* });
|
|
171
|
-
*
|
|
172
|
-
* const config = {
|
|
173
|
-
* configurable: {
|
|
174
|
-
* thread_id: "some_thread"
|
|
175
|
-
* }
|
|
176
|
-
* };
|
|
177
|
-
* await accumulator.invoke("hello", config); // returns "hello"
|
|
178
|
-
* await accumulator.invoke("world", config); // returns "hello world"
|
|
179
|
-
* ```
|
|
180
|
-
*
|
|
181
|
-
* @example Using entrypoint.final to save a value
|
|
182
|
-
* ```typescript
|
|
183
|
-
* import { entrypoint, getPreviousState } from "@langchain/langgraph";
|
|
184
|
-
* import { MemorySaver } from "@langchain/langgraph-checkpoint";
|
|
185
|
-
*
|
|
186
|
-
* const myWorkflow = entrypoint({
|
|
187
|
-
* name: "accumulator",
|
|
188
|
-
* checkpointer: new MemorySaver()
|
|
189
|
-
* }, async (num: number) => {
|
|
190
|
-
* const previous = getPreviousState<number>();
|
|
191
|
-
*
|
|
192
|
-
* // This will return the previous value to the caller, saving
|
|
193
|
-
* // 2 * num to the checkpoint, which will be used in the next invocation
|
|
194
|
-
* // for the `previous` parameter.
|
|
195
|
-
* return entrypoint.final({
|
|
196
|
-
* value: previous ?? 0,
|
|
197
|
-
* save: 2 * num
|
|
198
|
-
* });
|
|
199
|
-
* });
|
|
200
|
-
*
|
|
201
|
-
* const config = {
|
|
202
|
-
* configurable: {
|
|
203
|
-
* thread_id: "some_thread"
|
|
204
|
-
* }
|
|
205
|
-
* };
|
|
206
|
-
*
|
|
207
|
-
* await myWorkflow.invoke(3, config); // 0 (previous was undefined)
|
|
208
|
-
* await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)
|
|
209
|
-
* ```
|
|
210
|
-
* @category Functional API
|
|
211
|
-
*/
|
|
212
|
-
const entrypoint = function entrypoint$1(optionsOrName, func) {
|
|
213
|
-
const { name, checkpointer, store, cache } = typeof optionsOrName === "string" ? {
|
|
214
|
-
name: optionsOrName,
|
|
215
|
-
checkpointer: void 0,
|
|
216
|
-
store: void 0
|
|
217
|
-
} : optionsOrName;
|
|
218
|
-
if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) throw new Error("Generators are disallowed as entrypoints. For streaming responses, use config.write.");
|
|
219
|
-
const streamMode = "updates";
|
|
220
|
-
const bound = getRunnableForEntrypoint(name, func);
|
|
221
|
-
function isEntrypointFinal(value) {
|
|
222
|
-
return typeof value === "object" && value !== null && "__lg_type" in value && value.__lg_type === "__pregel_final";
|
|
223
|
-
}
|
|
224
|
-
const pluckReturnValue = new RunnableCallable({
|
|
225
|
-
name: "pluckReturnValue",
|
|
226
|
-
func: (value) => {
|
|
227
|
-
return isEntrypointFinal(value) ? value.value : value;
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
const pluckSaveValue = new RunnableCallable({
|
|
231
|
-
name: "pluckSaveValue",
|
|
232
|
-
func: (value) => {
|
|
233
|
-
return isEntrypointFinal(value) ? value.save : value;
|
|
234
|
-
}
|
|
235
|
-
});
|
|
236
|
-
const entrypointNode = new PregelNode({
|
|
237
|
-
bound,
|
|
238
|
-
triggers: [START],
|
|
239
|
-
channels: [START],
|
|
240
|
-
writers: [new ChannelWrite([{
|
|
241
|
-
channel: END,
|
|
242
|
-
value: PASSTHROUGH,
|
|
243
|
-
mapper: pluckReturnValue
|
|
244
|
-
}, {
|
|
245
|
-
channel: PREVIOUS,
|
|
246
|
-
value: PASSTHROUGH,
|
|
247
|
-
mapper: pluckSaveValue
|
|
248
|
-
}], [TAG_HIDDEN])]
|
|
249
|
-
});
|
|
250
|
-
return new Pregel({
|
|
251
|
-
name,
|
|
252
|
-
checkpointer,
|
|
253
|
-
nodes: { [name]: entrypointNode },
|
|
254
|
-
channels: {
|
|
255
|
-
[START]: new EphemeralValue(),
|
|
256
|
-
[END]: new LastValue(),
|
|
257
|
-
[PREVIOUS]: new LastValue()
|
|
258
|
-
},
|
|
259
|
-
inputChannels: START,
|
|
260
|
-
outputChannels: END,
|
|
261
|
-
streamChannels: END,
|
|
262
|
-
streamMode,
|
|
263
|
-
store,
|
|
264
|
-
cache
|
|
265
|
-
});
|
|
266
|
-
};
|
|
267
|
-
entrypoint.final = function final({ value, save }) {
|
|
268
|
-
return {
|
|
269
|
-
value,
|
|
270
|
-
save,
|
|
271
|
-
__lg_type: "__pregel_final"
|
|
272
|
-
};
|
|
273
|
-
};
|
|
274
|
-
/**
|
|
275
|
-
* A helper utility function for use with the functional API that returns the previous
|
|
276
|
-
* state from the checkpoint from the last invocation of the current thread.
|
|
277
|
-
*
|
|
278
|
-
* This function allows workflows to access state that was saved in previous runs
|
|
279
|
-
* using {@link entrypoint.final}.
|
|
280
|
-
*
|
|
281
|
-
* @typeParam StateT - The type of the state that was previously saved
|
|
282
|
-
* @returns The previous saved state from the last invocation of the current thread
|
|
283
|
-
*
|
|
284
|
-
* @example
|
|
285
|
-
* ```typescript
|
|
286
|
-
* const previousState = getPreviousState<{ counter: number }>();
|
|
287
|
-
* const newCount = (previousState?.counter ?? 0) + 1;
|
|
288
|
-
* ```
|
|
289
|
-
* @category Functional API
|
|
290
|
-
*/
|
|
291
|
-
function getPreviousState() {
|
|
292
|
-
const config = AsyncLocalStorageProviderSingleton.getRunnableConfig();
|
|
293
|
-
return config.configurable?.[CONFIG_KEY_PREVIOUS_STATE];
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
//#endregion
|
|
297
|
-
export { entrypoint, getPreviousState, task };
|
|
298
|
-
//# sourceMappingURL=index.js.map
|
package/dist/func/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["cache: CachePolicy | undefined","entrypoint","config: LangGraphRunnableConfig"],"sources":["../../src/func/index.ts"],"sourcesContent":["import {\n BaseCache,\n BaseCheckpointSaver,\n BaseStore,\n} from \"@langchain/langgraph-checkpoint\";\nimport { AsyncLocalStorageProviderSingleton } from \"@langchain/core/singletons\";\nimport { Pregel } from \"../pregel/index.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport {\n CONFIG_KEY_PREVIOUS_STATE,\n END,\n PREVIOUS,\n START,\n TAG_HIDDEN,\n} from \"../constants.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport { call, getRunnableForEntrypoint } from \"../pregel/call.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { LastValue } from \"../channels/last_value.js\";\nimport {\n EntrypointFinal,\n EntrypointReturnT,\n EntrypointFinalSaveT,\n EntrypointFunc,\n TaskFunc,\n} from \"./types.js\";\nimport { LangGraphRunnableConfig } from \"../pregel/runnable_types.js\";\nimport {\n RunnableCallable,\n isAsyncGeneratorFunction,\n isGeneratorFunction,\n} from \"../utils.js\";\nimport { ChannelWrite, PASSTHROUGH } from \"../pregel/write.js\";\n\n/**\n * Options for the {@link task} function\n */\nexport interface TaskOptions {\n /**\n * The name of the task, analogous to the node name in {@link StateGraph}.\n */\n name: string;\n /**\n * The retry policy for the task. Configures how many times and under what conditions\n * the task should be retried if it fails.\n */\n retry?: RetryPolicy;\n\n /**\n * The cache policy for the task. Configures how the task should be cached.\n */\n cachePolicy?: CachePolicy;\n}\n\n/**\n * Define a LangGraph task using the `task` function.\n *\n * Tasks can only be called from within an {@link entrypoint} or from within a StateGraph.\n * A task can be called like a regular function with the following differences:\n *\n * - When a checkpointer is enabled, the function inputs and outputs must be serializable.\n * - The wrapped function can only be called from within an entrypoint or StateGraph.\n * - Calling the function produces a promise. This makes it easy to parallelize tasks.\n *\n * @typeParam ArgsT - The type of arguments the task function accepts\n * @typeParam OutputT - The type of value the task function returns\n * @param optionsOrName - Either an {@link TaskOptions} object, or a string for the name of the task\n * @param func - The function that executes this task\n * @returns A proxy function that accepts the same arguments as the original and always returns the result as a Promise\n *\n * @example basic example\n * ```typescript\n * const addOne = task(\"add\", async (a: number) => a + 1);\n *\n * const workflow = entrypoint(\"example\", async (numbers: number[]) => {\n * const promises = numbers.map(n => addOne(n));\n * const results = await Promise.all(promises);\n * return results;\n * });\n *\n * // Call the entrypoint\n * await workflow.invoke([1, 2, 3]); // Returns [2, 3, 4]\n * ```\n *\n * @example using a retry policy\n * ```typescript\n * const addOne = task({\n * name: \"add\",\n * retry: { maxAttempts: 3 }\n * },\n * async (a: number) => a + 1\n * );\n *\n * const workflow = entrypoint(\"example\", async (numbers: number[]) => {\n * const promises = numbers.map(n => addOne(n));\n * const results = await Promise.all(promises);\n * return results;\n * });\n * ```\n * @category Functional API\n */\nexport function task<ArgsT extends unknown[], OutputT>(\n optionsOrName: TaskOptions | string,\n func: TaskFunc<ArgsT, OutputT>\n): (...args: ArgsT) => Promise<OutputT> {\n const options =\n typeof optionsOrName === \"string\"\n ? { name: optionsOrName, retry: undefined, cachePolicy: undefined }\n : optionsOrName;\n\n const { name, retry } = options;\n if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) {\n throw new Error(\n \"Generators are disallowed as tasks. For streaming responses, use config.write.\"\n );\n }\n\n const cachePolicy =\n options.cachePolicy ??\n // `cache` was mistakingly used as an alias for `cachePolicy` in v0.3.x,\n // TODO: remove in 1.x\n (\"cache\" in options ? (options.cache as CachePolicy) : undefined);\n\n let cache: CachePolicy | undefined;\n if (typeof cachePolicy === \"boolean\") {\n cache = cachePolicy ? {} : undefined;\n } else {\n cache = cachePolicy;\n }\n\n return (...args: ArgsT) => {\n return call({ func, name, retry, cache }, ...args);\n };\n}\n\n/**\n * Options for the {@link entrypoint} function\n */\nexport type EntrypointOptions = {\n /**\n * The name of the {@link entrypoint}, analogous to the node name in {@link StateGraph}.\n * This name is used for logging, debugging, and checkpoint identification.\n */\n name: string;\n /**\n * The checkpointer for the {@link entrypoint}. Used to save and restore state between\n * invocations of the workflow.\n */\n checkpointer?: BaseCheckpointSaver;\n /**\n * The store for the {@link entrypoint}. Used to persist data across workflow runs.\n */\n store?: BaseStore;\n\n /**\n * The cache for the {@link entrypoint}. Used to cache values between workflow runs.\n */\n cache?: BaseCache;\n};\n\n/**\n * Type declaration for the entrypoint function with its properties\n * @category Functional API\n */\nexport interface EntrypointFunction {\n <InputT, OutputT>(\n optionsOrName: EntrypointOptions | string,\n func: EntrypointFunc<InputT, OutputT>\n ): Pregel<\n Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>,\n {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n },\n Record<string, unknown>,\n InputT,\n EntrypointReturnT<OutputT>,\n // Because the update type is an return type union of tasks + entrypoint,\n // thus we can't type it properly.\n any, // eslint-disable-line @typescript-eslint/no-explicit-any\n Awaited<EntrypointReturnT<OutputT>>\n >;\n\n /**\n * A helper utility for use with the functional API that returns a value to the caller,\n * as well as a separate state value to persist to the checkpoint. This allows workflows\n * to maintain state between runs while returning different values to the caller.\n *\n * @typeParam ValueT - The type of the value to return to the caller\n * @typeParam SaveT - The type of the state to save to the checkpoint\n * @param options.value - The value to return to the caller\n * @param options.save - The value to save to the checkpoint\n * @returns An object with the value and save properties\n *\n * @example\n * ```typescript\n * return entrypoint.final({\n * value: \"result for caller\",\n * save: { counter: currentCount + 1 }\n * });\n * ```\n */\n final<ValueT, SaveT>(options: {\n value?: ValueT;\n save?: SaveT;\n }): EntrypointFinal<ValueT, SaveT>;\n}\n\n/**\n * Define a LangGraph workflow using the `entrypoint` function.\n *\n * ### Function signature\n *\n * The wrapped function must accept at most **two parameters**. The first parameter\n * is the input to the function. The second (optional) parameter is a\n * {@link LangGraphRunnableConfig} object. If you wish to pass multiple parameters to\n * the function, you can pass them as an object.\n *\n * ### Helper functions\n *\n * #### Streaming\n * To write data to the \"custom\" stream, use the {@link getWriter} function, or the\n * {@link LangGraphRunnableConfig.writer} property.\n *\n * #### State management\n * The {@link getPreviousState} function can be used to access the previous state\n * that was returned from the last invocation of the entrypoint on the same thread id.\n *\n * If you wish to save state other than the return value, you can use the\n * {@link entrypoint.final} function.\n *\n * @typeParam InputT - The type of input the entrypoint accepts\n * @typeParam OutputT - The type of output the entrypoint produces\n * @param optionsOrName - Either an {@link EntrypointOptions} object, or a string for the name of the entrypoint\n * @param func - The function that executes this entrypoint\n * @returns A {@link Pregel} instance that can be run to execute the workflow\n *\n * @example Using entrypoint and tasks\n * ```typescript\n * import { task, entrypoint } from \"@langchain/langgraph\";\n * import { MemorySaver } from \"@langchain/langgraph-checkpoint\";\n * import { interrupt, Command } from \"@langchain/langgraph\";\n *\n * const composeEssay = task(\"compose\", async (topic: string) => {\n * await new Promise(r => setTimeout(r, 1000)); // Simulate slow operation\n * return `An essay about ${topic}`;\n * });\n *\n * const reviewWorkflow = entrypoint({\n * name: \"review\",\n * checkpointer: new MemorySaver()\n * }, async (topic: string) => {\n * const essay = await composeEssay(topic);\n * const humanReview = await interrupt({\n * question: \"Please provide a review\",\n * essay\n * });\n * return {\n * essay,\n * review: humanReview\n * };\n * });\n *\n * // Example configuration for the workflow\n * const config = {\n * configurable: {\n * thread_id: \"some_thread\"\n * }\n * };\n *\n * // Topic for the essay\n * const topic = \"cats\";\n *\n * // Stream the workflow to generate the essay and await human review\n * for await (const result of reviewWorkflow.stream(topic, config)) {\n * console.log(result);\n * }\n *\n * // Example human review provided after the interrupt\n * const humanReview = \"This essay is great.\";\n *\n * // Resume the workflow with the provided human review\n * for await (const result of reviewWorkflow.stream(new Command({ resume: humanReview }), config)) {\n * console.log(result);\n * }\n * ```\n *\n * @example Accessing the previous return value\n * ```typescript\n * import { entrypoint, getPreviousState } from \"@langchain/langgraph\";\n * import { MemorySaver } from \"@langchain/langgraph-checkpoint\";\n *\n * const accumulator = entrypoint({\n * name: \"accumulator\",\n * checkpointer: new MemorySaver()\n * }, async (input: string) => {\n * const previous = getPreviousState<number>();\n * return previous !== undefined ? `${previous } ${input}` : input;\n * });\n *\n * const config = {\n * configurable: {\n * thread_id: \"some_thread\"\n * }\n * };\n * await accumulator.invoke(\"hello\", config); // returns \"hello\"\n * await accumulator.invoke(\"world\", config); // returns \"hello world\"\n * ```\n *\n * @example Using entrypoint.final to save a value\n * ```typescript\n * import { entrypoint, getPreviousState } from \"@langchain/langgraph\";\n * import { MemorySaver } from \"@langchain/langgraph-checkpoint\";\n *\n * const myWorkflow = entrypoint({\n * name: \"accumulator\",\n * checkpointer: new MemorySaver()\n * }, async (num: number) => {\n * const previous = getPreviousState<number>();\n *\n * // This will return the previous value to the caller, saving\n * // 2 * num to the checkpoint, which will be used in the next invocation\n * // for the `previous` parameter.\n * return entrypoint.final({\n * value: previous ?? 0,\n * save: 2 * num\n * });\n * });\n *\n * const config = {\n * configurable: {\n * thread_id: \"some_thread\"\n * }\n * };\n *\n * await myWorkflow.invoke(3, config); // 0 (previous was undefined)\n * await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)\n * ```\n * @category Functional API\n */\nexport const entrypoint = function entrypoint<InputT, OutputT>(\n optionsOrName: EntrypointOptions | string,\n func: EntrypointFunc<InputT, OutputT>\n) {\n const { name, checkpointer, store, cache } =\n typeof optionsOrName === \"string\"\n ? { name: optionsOrName, checkpointer: undefined, store: undefined }\n : optionsOrName;\n if (isAsyncGeneratorFunction(func) || isGeneratorFunction(func)) {\n throw new Error(\n \"Generators are disallowed as entrypoints. For streaming responses, use config.write.\"\n );\n }\n const streamMode = \"updates\";\n const bound = getRunnableForEntrypoint(name, func);\n\n // Helper to check if a value is an EntrypointFinal\n function isEntrypointFinal(\n value: unknown\n ): value is EntrypointFinal<unknown, unknown> {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"__lg_type\" in value &&\n value.__lg_type === \"__pregel_final\"\n );\n }\n\n // Helper function to pluck the return value from EntrypointFinal or passthrough\n const pluckReturnValue = new RunnableCallable({\n name: \"pluckReturnValue\",\n func: (value: unknown) => {\n return isEntrypointFinal(value) ? value.value : value;\n },\n });\n\n // Helper function to pluck the save value from EntrypointFinal or passthrough\n const pluckSaveValue = new RunnableCallable({\n name: \"pluckSaveValue\",\n func: (value: unknown) => {\n return isEntrypointFinal(value) ? value.save : value;\n },\n });\n\n const entrypointNode = new PregelNode<InputT, EntrypointReturnT<OutputT>>({\n bound,\n triggers: [START],\n channels: [START],\n writers: [\n new ChannelWrite(\n [\n { channel: END, value: PASSTHROUGH, mapper: pluckReturnValue },\n { channel: PREVIOUS, value: PASSTHROUGH, mapper: pluckSaveValue },\n ],\n [TAG_HIDDEN]\n ),\n ],\n });\n\n return new Pregel<\n Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, // node types\n {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n }, // channel types\n Record<string, unknown>, // configurable types\n InputT, // input type\n EntrypointReturnT<OutputT> // output type\n >({\n name,\n checkpointer,\n nodes: {\n [name]: entrypointNode,\n },\n channels: {\n [START]: new EphemeralValue<InputT>(),\n [END]: new LastValue<EntrypointReturnT<OutputT>>(),\n [PREVIOUS]: new LastValue<EntrypointFinalSaveT<OutputT>>(),\n },\n inputChannels: START,\n outputChannels: END,\n streamChannels: END,\n streamMode,\n store,\n cache,\n });\n} as EntrypointFunction;\n\n// documented by the EntrypointFunction interface\nentrypoint.final = function final<ValueT, SaveT>({\n value,\n save,\n}: {\n value?: ValueT;\n save?: SaveT;\n}): EntrypointFinal<ValueT, SaveT> {\n return { value, save, __lg_type: \"__pregel_final\" };\n};\n\n/**\n * A helper utility function for use with the functional API that returns the previous\n * state from the checkpoint from the last invocation of the current thread.\n *\n * This function allows workflows to access state that was saved in previous runs\n * using {@link entrypoint.final}.\n *\n * @typeParam StateT - The type of the state that was previously saved\n * @returns The previous saved state from the last invocation of the current thread\n *\n * @example\n * ```typescript\n * const previousState = getPreviousState<{ counter: number }>();\n * const newCount = (previousState?.counter ?? 0) + 1;\n * ```\n * @category Functional API\n */\nexport function getPreviousState<StateT>(): StateT {\n const config: LangGraphRunnableConfig =\n AsyncLocalStorageProviderSingleton.getRunnableConfig();\n return config.configurable?.[CONFIG_KEY_PREVIOUS_STATE] as StateT;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqGA,SAAgB,KACd,eACA,MACsC;CACtC,MAAM,UACJ,OAAO,kBAAkB,WACrB;EAAE,MAAM;EAAe,OAAO;EAAW,aAAa;KACtD;CAEN,MAAM,EAAE,MAAM,UAAU;AACxB,KAAI,yBAAyB,SAAS,oBAAoB,MACxD,OAAM,IAAI,MACR;CAIJ,MAAM,cACJ,QAAQ,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AAW,IAAI;;EAElB,eAAe;EACf,gBAAgB;EAChB,gBAAgB;EAChB;EACA;EACA;;;AAKJ,WAAW,QAAQ,SAAS,MAAqB,EAC/C,OACA,QAIiC;AACjC,QAAO;EAAE;EAAO;EAAM,WAAW;;;;;;;;;;;;;;;;;;;;AAoBnC,SAAgB,mBAAmC;CACjD,MAAMC,SACJ,mCAAmC;AACrC,QAAO,OAAO,eAAe"}
|
package/dist/func/types.d.cts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { LangGraphRunnableConfig } from "../pregel/runnable_types.cjs";
|
|
2
|
-
|
|
3
|
-
//#region src/func/types.d.ts
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Allows the entrypoint function to return a value to the caller, as well as a separate state value to persist to the checkpoint
|
|
7
|
-
*/
|
|
8
|
-
type EntrypointFinal<ValueT, SaveT> = {
|
|
9
|
-
/**
|
|
10
|
-
* The value to return to the caller
|
|
11
|
-
*/
|
|
12
|
-
value?: ValueT;
|
|
13
|
-
/**
|
|
14
|
-
* The value to save to the checkpoint
|
|
15
|
-
*/
|
|
16
|
-
save?: SaveT;
|
|
17
|
-
__lg_type: "__pregel_final";
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Checks if a value is an EntrypointFinal - use this instead of `instanceof`, as value may have been deserialized
|
|
21
|
-
* @param value The value to check
|
|
22
|
-
* @returns Whether the value is an EntrypointFinal
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The return type of an entrypoint function.
|
|
27
|
-
*/
|
|
28
|
-
type EntrypointReturnT<OutputT> = OutputT extends EntrypointFinal<infer ValueT, unknown> | Promise<EntrypointFinal<infer ValueT, unknown>> ? ValueT : OutputT;
|
|
29
|
-
/**
|
|
30
|
-
* The value to be saved when a function returns an EntrypointFinal.
|
|
31
|
-
*/
|
|
32
|
-
type EntrypointFinalSaveT<OutputT> = OutputT extends EntrypointFinal<unknown, infer SaveT> | Promise<EntrypointFinal<unknown, infer SaveT>> ? SaveT : OutputT;
|
|
33
|
-
/**
|
|
34
|
-
* The value to be returned when a function returns an EntrypointFinal.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Checks if an AsyncGenerator exists in the ES target/lib that we're compiling to.
|
|
39
|
-
*
|
|
40
|
-
* This is necessary because `tsc --init` targets ES2016 by default, which doesn't include AsyncGenerators.
|
|
41
|
-
*
|
|
42
|
-
* This works because when `skipLibCheck` is true (and it is in the default `tsconfig.json` created by `tsc --init`),
|
|
43
|
-
* TypeScript will replace any unresolved library types with `any`. So, when `AsyncGenerator` doesn't exist, this checks
|
|
44
|
-
* if `any` extends `object`, which it doesn't. When that happens, this type resolves to the `false` literal, and we can
|
|
45
|
-
* use it in the type predicates below to skip over the AsyncGenerator-specific logic.
|
|
46
|
-
*
|
|
47
|
-
* If we didn't have this, then the types below would be checking if the user's function extends `any` in place of the
|
|
48
|
-
* `AsyncGenerator` type, and the type predicate would branch to `never`, disallowing any valid function from being passed
|
|
49
|
-
* to `task` or `entrypoint`.
|
|
50
|
-
*/
|
|
51
|
-
type AsyncGeneratorExists = AsyncGenerator<unknown, unknown, unknown> extends object ? true : false;
|
|
52
|
-
/**
|
|
53
|
-
* Matches valid function signatures for entrypoints. Disallows generator functions.
|
|
54
|
-
*/
|
|
55
|
-
type EntrypointFunc<InputT, OutputT> = [OutputT] extends never ? (input: InputT, config: LangGraphRunnableConfig) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist
|
|
56
|
-
? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT;
|
|
57
|
-
/**
|
|
58
|
-
* Matches valid function signatures for tasks. Disallows generator functions.
|
|
59
|
-
*/
|
|
60
|
-
type TaskFunc<ArgsT extends unknown[], OutputT> = [OutputT] extends [never] ? (...args: ArgsT) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist
|
|
61
|
-
? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<unknown, unknown, unknown> ? never : (...args: ArgsT) => OutputT : OutputT extends Generator<unknown, unknown, unknown> ? never : (...args: ArgsT) => OutputT;
|
|
62
|
-
//#endregion
|
|
63
|
-
export { EntrypointFinal, EntrypointFinalSaveT, EntrypointFunc, EntrypointReturnT, TaskFunc };
|
|
64
|
-
//# sourceMappingURL=types.d.cts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":["LangGraphRunnableConfig","EntrypointFinal","ValueT","SaveT","isEntrypointFinal","EntrypointReturnT","OutputT","Promise","EntrypointFinalSaveT","EntrypointFinalValueT","AsyncGeneratorExists","AsyncGenerator","EntrypointFunc","InputT","Generator","TaskFunc","ArgsT"],"sources":["../../src/func/types.d.ts"],"sourcesContent":["import { LangGraphRunnableConfig } from \"../pregel/runnable_types.js\";\n/**\n * Allows the entrypoint function to return a value to the caller, as well as a separate state value to persist to the checkpoint\n */\nexport type EntrypointFinal<ValueT, SaveT> = {\n /**\n * The value to return to the caller\n */\n value?: ValueT;\n /**\n * The value to save to the checkpoint\n */\n save?: SaveT;\n __lg_type: \"__pregel_final\";\n};\n/**\n * Checks if a value is an EntrypointFinal - use this instead of `instanceof`, as value may have been deserialized\n * @param value The value to check\n * @returns Whether the value is an EntrypointFinal\n */\nexport declare function isEntrypointFinal<ValueT, SaveT>(value: unknown): value is EntrypointFinal<ValueT, SaveT>;\n/**\n * The return type of an entrypoint function.\n */\nexport type EntrypointReturnT<OutputT> = OutputT extends EntrypointFinal<infer ValueT, unknown> | Promise<EntrypointFinal<infer ValueT, unknown>> ? ValueT : OutputT;\n/**\n * The value to be saved when a function returns an EntrypointFinal.\n */\nexport type EntrypointFinalSaveT<OutputT> = OutputT extends EntrypointFinal<unknown, infer SaveT> | Promise<EntrypointFinal<unknown, infer SaveT>> ? SaveT : OutputT;\n/**\n * The value to be returned when a function returns an EntrypointFinal.\n */\nexport type EntrypointFinalValueT<OutputT> = OutputT extends EntrypointFinal<infer ValueT, infer SaveT> | Promise<EntrypointFinal<infer ValueT, infer SaveT>> ? EntrypointFinal<ValueT, SaveT> : OutputT;\n/**\n * Checks if an AsyncGenerator exists in the ES target/lib that we're compiling to.\n *\n * This is necessary because `tsc --init` targets ES2016 by default, which doesn't include AsyncGenerators.\n *\n * This works because when `skipLibCheck` is true (and it is in the default `tsconfig.json` created by `tsc --init`),\n * TypeScript will replace any unresolved library types with `any`. So, when `AsyncGenerator` doesn't exist, this checks\n * if `any` extends `object`, which it doesn't. When that happens, this type resolves to the `false` literal, and we can\n * use it in the type predicates below to skip over the AsyncGenerator-specific logic.\n *\n * If we didn't have this, then the types below would be checking if the user's function extends `any` in place of the\n * `AsyncGenerator` type, and the type predicate would branch to `never`, disallowing any valid function from being passed\n * to `task` or `entrypoint`.\n */\ntype AsyncGeneratorExists = AsyncGenerator<unknown, unknown, unknown> extends object ? true : false;\n/**\n * Matches valid function signatures for entrypoints. Disallows generator functions.\n */\nexport type EntrypointFunc<InputT, OutputT> = [OutputT] extends never ? (input: InputT, config: LangGraphRunnableConfig) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist\n ? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT;\n/**\n * Matches valid function signatures for tasks. Disallows generator functions.\n */\nexport type TaskFunc<ArgsT extends unknown[], OutputT> = [OutputT] extends [\n never\n] ? (...args: ArgsT) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist\n ? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<un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
5
|
-
/**
|
|
6
|
-
* Allows the entrypoint function to return a value to the caller, as well as a separate state value to persist to the checkpoint
|
|
7
|
-
*/
|
|
8
|
-
type EntrypointFinal<ValueT, SaveT> = {
|
|
9
|
-
/**
|
|
10
|
-
* The value to return to the caller
|
|
11
|
-
*/
|
|
12
|
-
value?: ValueT;
|
|
13
|
-
/**
|
|
14
|
-
* The value to save to the checkpoint
|
|
15
|
-
*/
|
|
16
|
-
save?: SaveT;
|
|
17
|
-
__lg_type: "__pregel_final";
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* Checks if a value is an EntrypointFinal - use this instead of `instanceof`, as value may have been deserialized
|
|
21
|
-
* @param value The value to check
|
|
22
|
-
* @returns Whether the value is an EntrypointFinal
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The return type of an entrypoint function.
|
|
27
|
-
*/
|
|
28
|
-
type EntrypointReturnT<OutputT> = OutputT extends EntrypointFinal<infer ValueT, unknown> | Promise<EntrypointFinal<infer ValueT, unknown>> ? ValueT : OutputT;
|
|
29
|
-
/**
|
|
30
|
-
* The value to be saved when a function returns an EntrypointFinal.
|
|
31
|
-
*/
|
|
32
|
-
type EntrypointFinalSaveT<OutputT> = OutputT extends EntrypointFinal<unknown, infer SaveT> | Promise<EntrypointFinal<unknown, infer SaveT>> ? SaveT : OutputT;
|
|
33
|
-
/**
|
|
34
|
-
* The value to be returned when a function returns an EntrypointFinal.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Checks if an AsyncGenerator exists in the ES target/lib that we're compiling to.
|
|
39
|
-
*
|
|
40
|
-
* This is necessary because `tsc --init` targets ES2016 by default, which doesn't include AsyncGenerators.
|
|
41
|
-
*
|
|
42
|
-
* This works because when `skipLibCheck` is true (and it is in the default `tsconfig.json` created by `tsc --init`),
|
|
43
|
-
* TypeScript will replace any unresolved library types with `any`. So, when `AsyncGenerator` doesn't exist, this checks
|
|
44
|
-
* if `any` extends `object`, which it doesn't. When that happens, this type resolves to the `false` literal, and we can
|
|
45
|
-
* use it in the type predicates below to skip over the AsyncGenerator-specific logic.
|
|
46
|
-
*
|
|
47
|
-
* If we didn't have this, then the types below would be checking if the user's function extends `any` in place of the
|
|
48
|
-
* `AsyncGenerator` type, and the type predicate would branch to `never`, disallowing any valid function from being passed
|
|
49
|
-
* to `task` or `entrypoint`.
|
|
50
|
-
*/
|
|
51
|
-
type AsyncGeneratorExists = AsyncGenerator<unknown, unknown, unknown> extends object ? true : false;
|
|
52
|
-
/**
|
|
53
|
-
* Matches valid function signatures for entrypoints. Disallows generator functions.
|
|
54
|
-
*/
|
|
55
|
-
type EntrypointFunc<InputT, OutputT> = [OutputT] extends never ? (input: InputT, config: LangGraphRunnableConfig) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist
|
|
56
|
-
? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT;
|
|
57
|
-
/**
|
|
58
|
-
* Matches valid function signatures for tasks. Disallows generator functions.
|
|
59
|
-
*/
|
|
60
|
-
type TaskFunc<ArgsT extends unknown[], OutputT> = [OutputT] extends [never] ? (...args: ArgsT) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist
|
|
61
|
-
? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<unknown, unknown, unknown> ? never : (...args: ArgsT) => OutputT : OutputT extends Generator<unknown, unknown, unknown> ? never : (...args: ArgsT) => OutputT;
|
|
62
|
-
//#endregion
|
|
63
|
-
export { EntrypointFinal, EntrypointFinalSaveT, EntrypointFunc, EntrypointReturnT, TaskFunc };
|
|
64
|
-
//# sourceMappingURL=types.d.ts.map
|
package/dist/func/types.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":["LangGraphRunnableConfig","EntrypointFinal","ValueT","SaveT","isEntrypointFinal","EntrypointReturnT","OutputT","Promise","EntrypointFinalSaveT","EntrypointFinalValueT","AsyncGeneratorExists","AsyncGenerator","EntrypointFunc","InputT","Generator","TaskFunc","ArgsT"],"sources":["../../src/func/types.d.ts"],"sourcesContent":["import { LangGraphRunnableConfig } from \"../pregel/runnable_types.js\";\n/**\n * Allows the entrypoint function to return a value to the caller, as well as a separate state value to persist to the checkpoint\n */\nexport type EntrypointFinal<ValueT, SaveT> = {\n /**\n * The value to return to the caller\n */\n value?: ValueT;\n /**\n * The value to save to the checkpoint\n */\n save?: SaveT;\n __lg_type: \"__pregel_final\";\n};\n/**\n * Checks if a value is an EntrypointFinal - use this instead of `instanceof`, as value may have been deserialized\n * @param value The value to check\n * @returns Whether the value is an EntrypointFinal\n */\nexport declare function isEntrypointFinal<ValueT, SaveT>(value: unknown): value is EntrypointFinal<ValueT, SaveT>;\n/**\n * The return type of an entrypoint function.\n */\nexport type EntrypointReturnT<OutputT> = OutputT extends EntrypointFinal<infer ValueT, unknown> | Promise<EntrypointFinal<infer ValueT, unknown>> ? ValueT : OutputT;\n/**\n * The value to be saved when a function returns an EntrypointFinal.\n */\nexport type EntrypointFinalSaveT<OutputT> = OutputT extends EntrypointFinal<unknown, infer SaveT> | Promise<EntrypointFinal<unknown, infer SaveT>> ? SaveT : OutputT;\n/**\n * The value to be returned when a function returns an EntrypointFinal.\n */\nexport type EntrypointFinalValueT<OutputT> = OutputT extends EntrypointFinal<infer ValueT, infer SaveT> | Promise<EntrypointFinal<infer ValueT, infer SaveT>> ? EntrypointFinal<ValueT, SaveT> : OutputT;\n/**\n * Checks if an AsyncGenerator exists in the ES target/lib that we're compiling to.\n *\n * This is necessary because `tsc --init` targets ES2016 by default, which doesn't include AsyncGenerators.\n *\n * This works because when `skipLibCheck` is true (and it is in the default `tsconfig.json` created by `tsc --init`),\n * TypeScript will replace any unresolved library types with `any`. So, when `AsyncGenerator` doesn't exist, this checks\n * if `any` extends `object`, which it doesn't. When that happens, this type resolves to the `false` literal, and we can\n * use it in the type predicates below to skip over the AsyncGenerator-specific logic.\n *\n * If we didn't have this, then the types below would be checking if the user's function extends `any` in place of the\n * `AsyncGenerator` type, and the type predicate would branch to `never`, disallowing any valid function from being passed\n * to `task` or `entrypoint`.\n */\ntype AsyncGeneratorExists = AsyncGenerator<unknown, unknown, unknown> extends object ? true : false;\n/**\n * Matches valid function signatures for entrypoints. Disallows generator functions.\n */\nexport type EntrypointFunc<InputT, OutputT> = [OutputT] extends never ? (input: InputT, config: LangGraphRunnableConfig) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist\n ? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT : OutputT extends Generator<unknown, unknown, unknown> ? never : (input: InputT, config: LangGraphRunnableConfig) => OutputT;\n/**\n * Matches valid function signatures for tasks. Disallows generator functions.\n */\nexport type TaskFunc<ArgsT extends unknown[], OutputT> = [OutputT] extends [\n never\n] ? (...args: ArgsT) => never : AsyncGeneratorExists extends true // only check if it may be an AsyncGenerator when those actually exist\n ? OutputT extends AsyncGenerator<unknown, unknown, unknown> ? never : OutputT extends Generator<unknown, unknown, unknown> ? never : (...args: ArgsT) => OutputT : OutputT extends Generator<unknown, unknown, unknown> ? never : (...args: ArgsT) => OutputT;\nexport {};\n"],"mappings":";;;;;;AAIA;AAA2B,KAAfC,eAAe,CAAA,MAAA,EAAA,KAAA,CAAA,GAAA;;;;EAoBfI,KAAAA,CAAAA,EAhBAH,MAgBAG;EAAiB;;;MAA6EJ,CAAAA,EAZ/FE,KAY+FF;WAARM,EAAAA,gBAAAA;;;;AAIlG;;;;;;;AAA6JD,KAJjJD,iBAIiJC,CAAAA,OAAAA,CAAAA,GAJpHA,OAIoHA,SAJpGL,eAIoGK,CAAAA,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QW,EAAAA,GAPoSL,OAOpSK;;;;AAAuIL,KAH9IS,QAG8IT,CAAAA,cAAAA,OAAAA,EAAAA,EAAAA,OAAAA,CAAAA,GAAAA,CAHhGA,OAGgGA,CAAAA,SAAAA,MAAUA,QAAgBQ,IAAAA,EADtKE,KACsKF,EAAAA,GAAAA,KAAAA,GADpJJ,oBACoJI,SAAAA,IAAAA,CAAAA;AAAAA,EAAjLR,OAA0OU,SAA1NL,cAA0NK,CAAAA,OAAAA,EAAAA,OAAAA,EAAAA,OAAAA,CAAAA,GAAAA,KAAAA,GAAtKV,OAAsKU,SAAtJF,SAAsJE,CAAAA,OAAAA,EAAAA,OAAAA,EAAAA,OAAAA,CAAAA,GAAAA,KAAAA,GAAAA,CAAAA,GAAAA,IAAAA,EAA7FA,KAA6FA,EAAAA,GAAnFV,OAAmFU,GAAzEV,OAAyEU,SAAzDF,SAAyDE,CAAAA,OAAAA,EAAAA,OAAAA,EAAAA,OAAAA,CAAAA,GAAAA,KAAAA,GAAAA,CAAAA,GAAAA,IAAAA,EAAAA,KAAAA,EAAAA,GAAUV,OAAVU"}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
const require_binop = require('../channels/binop.cjs');
|
|
2
|
-
const require_last_value = require('../channels/last_value.cjs');
|
|
3
|
-
|
|
4
|
-
//#region src/graph/annotation.ts
|
|
5
|
-
/**
|
|
6
|
-
* Should not be instantiated directly. See {@link Annotation}.
|
|
7
|
-
*/
|
|
8
|
-
var AnnotationRoot = class {
|
|
9
|
-
lc_graph_name = "AnnotationRoot";
|
|
10
|
-
spec;
|
|
11
|
-
constructor(s) {
|
|
12
|
-
this.spec = s;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Helper that instantiates channels within a StateGraph state.
|
|
17
|
-
*
|
|
18
|
-
* Can be used as a field in an {@link Annotation.Root} wrapper in one of two ways:
|
|
19
|
-
* 1. **Directly**: Creates a channel that stores the most recent value returned from a node.
|
|
20
|
-
* 2. **With a reducer**: Creates a channel that applies the reducer on a node's return value.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```ts
|
|
24
|
-
* import { StateGraph, Annotation } from "@langchain/langgraph";
|
|
25
|
-
*
|
|
26
|
-
* // Define a state with a single string key named "currentOutput"
|
|
27
|
-
* const SimpleAnnotation = Annotation.Root({
|
|
28
|
-
* currentOutput: Annotation<string>,
|
|
29
|
-
* });
|
|
30
|
-
*
|
|
31
|
-
* const graphBuilder = new StateGraph(SimpleAnnotation);
|
|
32
|
-
*
|
|
33
|
-
* // A node in the graph that returns an object with a "currentOutput" key
|
|
34
|
-
* // replaces the value in the state. You can get the state type as shown below:
|
|
35
|
-
* const myNode = (state: typeof SimpleAnnotation.State) => {
|
|
36
|
-
* return {
|
|
37
|
-
* currentOutput: "some_new_value",
|
|
38
|
-
* };
|
|
39
|
-
* }
|
|
40
|
-
*
|
|
41
|
-
* const graph = graphBuilder
|
|
42
|
-
* .addNode("myNode", myNode)
|
|
43
|
-
* ...
|
|
44
|
-
* .compile();
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* import { type BaseMessage, AIMessage } from "@langchain/core/messages";
|
|
50
|
-
* import { StateGraph, Annotation } from "@langchain/langgraph";
|
|
51
|
-
*
|
|
52
|
-
* // Define a state with a single key named "messages" that will
|
|
53
|
-
* // combine a returned BaseMessage or arrays of BaseMessages
|
|
54
|
-
* const AnnotationWithReducer = Annotation.Root({
|
|
55
|
-
* messages: Annotation<BaseMessage[]>({
|
|
56
|
-
* // Different types are allowed for updates
|
|
57
|
-
* reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => {
|
|
58
|
-
* if (Array.isArray(right)) {
|
|
59
|
-
* return left.concat(right);
|
|
60
|
-
* }
|
|
61
|
-
* return left.concat([right]);
|
|
62
|
-
* },
|
|
63
|
-
* default: () => [],
|
|
64
|
-
* }),
|
|
65
|
-
* });
|
|
66
|
-
*
|
|
67
|
-
* const graphBuilder = new StateGraph(AnnotationWithReducer);
|
|
68
|
-
*
|
|
69
|
-
* // A node in the graph that returns an object with a "messages" key
|
|
70
|
-
* // will update the state by combining the existing value with the returned one.
|
|
71
|
-
* const myNode = (state: typeof AnnotationWithReducer.State) => {
|
|
72
|
-
* return {
|
|
73
|
-
* messages: [new AIMessage("Some new response")],
|
|
74
|
-
* };
|
|
75
|
-
* };
|
|
76
|
-
*
|
|
77
|
-
* const graph = graphBuilder
|
|
78
|
-
* .addNode("myNode", myNode)
|
|
79
|
-
* ...
|
|
80
|
-
* .compile();
|
|
81
|
-
* ```
|
|
82
|
-
* @namespace
|
|
83
|
-
* @property Root
|
|
84
|
-
* Helper function that instantiates a StateGraph state. See {@link Annotation} for usage.
|
|
85
|
-
*/
|
|
86
|
-
const Annotation = function(annotation) {
|
|
87
|
-
if (annotation) return getChannel(annotation);
|
|
88
|
-
else return new require_last_value.LastValue();
|
|
89
|
-
};
|
|
90
|
-
Annotation.Root = (sd) => new AnnotationRoot(sd);
|
|
91
|
-
function getChannel(reducer) {
|
|
92
|
-
if (typeof reducer === "object" && reducer && "reducer" in reducer && reducer.reducer) return new require_binop.BinaryOperatorAggregate(reducer.reducer, reducer.default);
|
|
93
|
-
if (typeof reducer === "object" && reducer && "value" in reducer && reducer.value) return new require_binop.BinaryOperatorAggregate(reducer.value, reducer.default);
|
|
94
|
-
return new require_last_value.LastValue();
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
//#endregion
|
|
98
|
-
exports.Annotation = Annotation;
|
|
99
|
-
exports.AnnotationRoot = AnnotationRoot;
|
|
100
|
-
exports.getChannel = getChannel;
|
|
101
|
-
//# sourceMappingURL=annotation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"annotation.cjs","names":["Annotation: AnnotationFunction","LastValue","BinaryOperatorAggregate"],"sources":["../../src/graph/annotation.ts"],"sourcesContent":["import { RunnableLike } from \"../pregel/runnable_types.js\";\nimport { BaseChannel } from \"../channels/base.js\";\nimport { BinaryOperator, BinaryOperatorAggregate } from \"../channels/binop.js\";\nimport { LastValue } from \"../channels/last_value.js\";\n\nexport type SingleReducer<ValueType, UpdateType = ValueType> =\n | {\n reducer: BinaryOperator<ValueType, UpdateType>;\n default?: () => ValueType;\n }\n | {\n /**\n * @deprecated Use `reducer` instead\n */\n value: BinaryOperator<ValueType, UpdateType>;\n default?: () => ValueType;\n }\n | null;\n\nexport interface StateDefinition {\n [key: string]: BaseChannel | (() => BaseChannel);\n}\n\ntype ExtractValueType<C> = C extends BaseChannel\n ? C[\"ValueType\"]\n : C extends () => BaseChannel\n ? ReturnType<C>[\"ValueType\"]\n : never;\n\ntype ExtractUpdateType<C> = C extends BaseChannel\n ? C[\"UpdateType\"]\n : C extends () => BaseChannel\n ? ReturnType<C>[\"UpdateType\"]\n : never;\n\nexport type StateType<SD extends StateDefinition> = {\n [key in keyof SD]: ExtractValueType<SD[key]>;\n};\n\nexport type UpdateType<SD extends StateDefinition> = {\n [key in keyof SD]?: ExtractUpdateType<SD[key]>;\n};\n\nexport type NodeType<SD extends StateDefinition> = RunnableLike<\n StateType<SD>,\n UpdateType<SD> | Partial<StateType<SD>>\n>;\n\n/** @ignore */\nexport interface AnnotationFunction {\n <ValueType>(): LastValue<ValueType>;\n <ValueType, UpdateType = ValueType>(\n annotation: SingleReducer<ValueType, UpdateType>\n ): BinaryOperatorAggregate<ValueType, UpdateType>;\n Root: <S extends StateDefinition>(sd: S) => AnnotationRoot<S>;\n}\n\n/**\n * Should not be instantiated directly. See {@link Annotation}.\n */\nexport class AnnotationRoot<SD extends StateDefinition> {\n lc_graph_name = \"AnnotationRoot\";\n\n declare State: StateType<SD>;\n\n declare Update: UpdateType<SD>;\n\n declare Node: NodeType<SD>;\n\n spec: SD;\n\n constructor(s: SD) {\n this.spec = s;\n }\n}\n\n/**\n * Helper that instantiates channels within a StateGraph state.\n *\n * Can be used as a field in an {@link Annotation.Root} wrapper in one of two ways:\n * 1. **Directly**: Creates a channel that stores the most recent value returned from a node.\n * 2. **With a reducer**: Creates a channel that applies the reducer on a node's return value.\n *\n * @example\n * ```ts\n * import { StateGraph, Annotation } from \"@langchain/langgraph\";\n *\n * // Define a state with a single string key named \"currentOutput\"\n * const SimpleAnnotation = Annotation.Root({\n * currentOutput: Annotation<string>,\n * });\n *\n * const graphBuilder = new StateGraph(SimpleAnnotation);\n *\n * // A node in the graph that returns an object with a \"currentOutput\" key\n * // replaces the value in the state. You can get the state type as shown below:\n * const myNode = (state: typeof SimpleAnnotation.State) => {\n * return {\n * currentOutput: \"some_new_value\",\n * };\n * }\n *\n * const graph = graphBuilder\n * .addNode(\"myNode\", myNode)\n * ...\n * .compile();\n * ```\n *\n * @example\n * ```ts\n * import { type BaseMessage, AIMessage } from \"@langchain/core/messages\";\n * import { StateGraph, Annotation } from \"@langchain/langgraph\";\n *\n * // Define a state with a single key named \"messages\" that will\n * // combine a returned BaseMessage or arrays of BaseMessages\n * const AnnotationWithReducer = Annotation.Root({\n * messages: Annotation<BaseMessage[]>({\n * // Different types are allowed for updates\n * reducer: (left: BaseMessage[], right: BaseMessage | BaseMessage[]) => {\n * if (Array.isArray(right)) {\n * return left.concat(right);\n * }\n * return left.concat([right]);\n * },\n * default: () => [],\n * }),\n * });\n *\n * const graphBuilder = new StateGraph(AnnotationWithReducer);\n *\n * // A node in the graph that returns an object with a \"messages\" key\n * // will update the state by combining the existing value with the returned one.\n * const myNode = (state: typeof AnnotationWithReducer.State) => {\n * return {\n * messages: [new AIMessage(\"Some new response\")],\n * };\n * };\n *\n * const graph = graphBuilder\n * .addNode(\"myNode\", myNode)\n * ...\n * .compile();\n * ```\n * @namespace\n * @property Root\n * Helper function that instantiates a StateGraph state. See {@link Annotation} for usage.\n */\nexport const Annotation: AnnotationFunction = function <\n ValueType,\n UpdateType = ValueType\n>(\n annotation?: SingleReducer<ValueType, UpdateType>\n): BaseChannel<ValueType, UpdateType> {\n if (annotation) {\n return getChannel<ValueType, UpdateType>(annotation);\n } else {\n // @ts-expect-error - Annotation without reducer\n return new LastValue<ValueType>();\n }\n} as AnnotationFunction;\n\nAnnotation.Root = <S extends StateDefinition>(sd: S) => new AnnotationRoot(sd);\n\nexport function getChannel<V, U = V>(\n reducer: SingleReducer<V, U>\n): BaseChannel<V, U> {\n if (\n typeof reducer === \"object\" &&\n reducer &&\n \"reducer\" in reducer &&\n reducer.reducer\n ) {\n return new BinaryOperatorAggregate(reducer.reducer, reducer.default);\n }\n if (\n typeof reducer === \"object\" &&\n reducer &&\n \"value\" in reducer &&\n reducer.value\n ) {\n return new BinaryOperatorAggregate(reducer.value, reducer.default);\n }\n // @ts-expect-error - Annotation without reducer\n return new LastValue<V>();\n}\n"],"mappings":";;;;;;;AA4DA,IAAa,iBAAb,MAAwD;CACtD,gBAAgB;CAQhB;CAEA,YAAY,GAAO;AACjB,OAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EhB,MAAaA,aAAiC,SAI5C,YACoC;AACpC,KAAI,WACF,QAAO,WAAkC;KAGzC,QAAO,IAAIC;;AAIf,WAAW,QAAmC,OAAU,IAAI,eAAe;AAE3E,SAAgB,WACd,SACmB;AACnB,KACE,OAAO,YAAY,YACnB,WACA,aAAa,WACb,QAAQ,QAER,QAAO,IAAIC,sCAAwB,QAAQ,SAAS,QAAQ;AAE9D,KACE,OAAO,YAAY,YACnB,WACA,WAAW,WACX,QAAQ,MAER,QAAO,IAAIA,sCAAwB,QAAQ,OAAO,QAAQ;AAG5D,QAAO,IAAID"}
|