@langchain/langgraph 1.0.0-alpha.4 → 1.0.0-alpha.5
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/CHANGELOG.md +7 -0
- package/dist/constants.cjs +1 -0
- package/dist/constants.js +1 -1
- package/dist/func/index.cjs.map +1 -1
- package/dist/func/index.d.cts +2 -2
- package/dist/func/index.d.cts.map +1 -1
- package/dist/func/index.d.ts +2 -2
- package/dist/func/index.d.ts.map +1 -1
- package/dist/func/index.js.map +1 -1
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.d.cts +14 -15
- package/dist/graph/graph.d.cts.map +1 -1
- package/dist/graph/graph.d.ts +14 -15
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.cjs +1 -0
- package/dist/graph/index.js +1 -0
- package/dist/graph/message.d.cts +2 -2
- package/dist/graph/message.d.cts.map +1 -1
- package/dist/prebuilt/agent_executor.d.cts +5 -5
- package/dist/prebuilt/agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.cts +3 -3
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
- package/dist/pregel/index.cjs +3 -2
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.d.cts +7 -6
- package/dist/pregel/index.d.cts.map +1 -1
- package/dist/pregel/index.d.ts +7 -6
- package/dist/pregel/index.d.ts.map +1 -1
- package/dist/pregel/index.js +3 -2
- package/dist/pregel/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @langchain/langgraph
|
|
2
2
|
|
|
3
|
+
## 1.0.0-alpha.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b6d6701: fix(@langchain/langgraph): export missing `CommandParams` symbol
|
|
8
|
+
- d5be09c: fix(@langchain/langgraph): export missing `CommandInstance` symbol
|
|
9
|
+
|
|
3
10
|
## 1.0.0-alpha.4
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/dist/constants.cjs
CHANGED
|
@@ -380,6 +380,7 @@ exports.CONFIG_KEY_STREAM = CONFIG_KEY_STREAM;
|
|
|
380
380
|
exports.CONFIG_KEY_TASK_ID = CONFIG_KEY_TASK_ID;
|
|
381
381
|
exports.COPY = COPY;
|
|
382
382
|
exports.Command = Command;
|
|
383
|
+
exports.CommandInstance = CommandInstance;
|
|
383
384
|
exports.END = END;
|
|
384
385
|
exports.ERROR = ERROR;
|
|
385
386
|
exports.INPUT = INPUT;
|
package/dist/constants.js
CHANGED
|
@@ -358,5 +358,5 @@ function _deserializeCommandSendObjectGraph(x, seen = /* @__PURE__ */ new Map())
|
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
//#endregion
|
|
361
|
-
export { CACHE_NS_WRITES, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, 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, END, ERROR, INPUT, INTERRUPT, NO_WRITES, NULL_TASK_ID, PREVIOUS, PULL, PUSH, RESERVED, RESUME, RETURN, SELF, START, Send, TAG_HIDDEN, TAG_NOSTREAM, TASKS, _isSend, _isSendInterface, isCommand, isInterrupted };
|
|
361
|
+
export { CACHE_NS_WRITES, CHECKPOINT_NAMESPACE_END, CHECKPOINT_NAMESPACE_SEPARATOR, 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, PREVIOUS, PULL, PUSH, RESERVED, RESUME, RETURN, SELF, START, Send, TAG_HIDDEN, TAG_NOSTREAM, TASKS, _isSend, _isSendInterface, isCommand, isInterrupted };
|
|
362
362
|
//# sourceMappingURL=constants.js.map
|
package/dist/func/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["isAsyncGeneratorFunction","isGeneratorFunction","cache: CachePolicy | undefined","call","entrypoint","getRunnableForEntrypoint","RunnableCallable","PregelNode","START","ChannelWrite","END","PASSTHROUGH","PREVIOUS","TAG_HIDDEN","Pregel","EphemeralValue","LastValue","config: LangGraphRunnableConfig","AsyncLocalStorageProviderSingleton","CONFIG_KEY_PREVIOUS_STATE"],"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 value - The value to return to the caller\n * @param 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;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E,SAASC;GAAU,OAAOD;GAAa,QAAQ;MAEnD,CAACE;;AAKP,QAAO,IAAIC,4BAUT;EACA;EACA;EACA,OAAO,GACJ,OAAO;EAEV,UAAU;IACPN,0BAAQ,IAAIO;IACZL,wBAAM,IAAIM;IACVJ,6BAAW,IAAII;;EAElB,eAAeR;EACf,gBAAgBE;EAChB,gBAAgBA;EAChB;EACA;EACA;;;AAKJ,WAAW,QAAQ,SAAS,MAAqB,EAC/C,OACA,QAIiC;AACjC,QAAO;EAAE;EAAO;EAAM,WAAW;;;;;;;;;;;;;;;;;;;;AAoBnC,SAAgB,mBAAmC;CACjD,MAAMO,SACJC,+DAAmC;AACrC,QAAO,OAAO,eAAeC"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["isAsyncGeneratorFunction","isGeneratorFunction","cache: CachePolicy | undefined","call","entrypoint","getRunnableForEntrypoint","RunnableCallable","PregelNode","START","ChannelWrite","END","PASSTHROUGH","PREVIOUS","TAG_HIDDEN","Pregel","EphemeralValue","LastValue","config: LangGraphRunnableConfig","AsyncLocalStorageProviderSingleton","CONFIG_KEY_PREVIOUS_STATE"],"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,KAAIA,uCAAyB,SAASC,kCAAoB,MACxD,OAAM,IAAI,MACR;CAIJ,MAAM,cACJ,QAAQ,gBAGP,WAAW,UAA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IACVJ,6BAAW,IAAII;;EAElB,eAAeR;EACf,gBAAgBE;EAChB,gBAAgBA;EAChB;EACA;EACA;;;AAKJ,WAAW,QAAQ,SAAS,MAAqB,EAC/C,OACA,QAIiC;AACjC,QAAO;EAAE;EAAO;EAAM,WAAW;;;;;;;;;;;;;;;;;;;;AAoBnC,SAAgB,mBAAmC;CACjD,MAAMO,SACJC,+DAAmC;AACrC,QAAO,OAAO,eAAeC"}
|
package/dist/func/index.d.cts
CHANGED
|
@@ -120,8 +120,8 @@ interface EntrypointFunction {
|
|
|
120
120
|
*
|
|
121
121
|
* @typeParam ValueT - The type of the value to return to the caller
|
|
122
122
|
* @typeParam SaveT - The type of the state to save to the checkpoint
|
|
123
|
-
* @param value - The value to return to the caller
|
|
124
|
-
* @param save - The value to save to the checkpoint
|
|
123
|
+
* @param options.value - The value to return to the caller
|
|
124
|
+
* @param options.save - The value to save to the checkpoint
|
|
125
125
|
* @returns An object with the value and save properties
|
|
126
126
|
*
|
|
127
127
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":["BaseCache","BaseCheckpointSaver","BaseStore","Pregel","PregelNode","END","PREVIOUS","START","EphemeralValue","CachePolicy","RetryPolicy","LastValue","EntrypointFinal","EntrypointReturnT","EntrypointFinalSaveT","EntrypointFunc","TaskFunc","TaskOptions","task","ArgsT","OutputT","Promise","EntrypointOptions","EntrypointFunction","InputT","Record","Awaited","ValueT","SaveT","entrypoint","getPreviousState","StateT"],"sources":["../../src/func/index.d.ts"],"sourcesContent":["import { BaseCache, BaseCheckpointSaver, BaseStore } from \"@langchain/langgraph-checkpoint\";\nimport { Pregel } from \"../pregel/index.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport { END, PREVIOUS, START } from \"../constants.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { LastValue } from \"../channels/last_value.js\";\nimport { EntrypointFinal, EntrypointReturnT, EntrypointFinalSaveT, EntrypointFunc, TaskFunc } from \"./types.js\";\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 * The cache policy for the task. Configures how the task should be cached.\n */\n cachePolicy?: CachePolicy;\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 declare function task<ArgsT extends unknown[], OutputT>(optionsOrName: TaskOptions | string, func: TaskFunc<ArgsT, OutputT>): (...args: ArgsT) => Promise<OutputT>;\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 * The cache for the {@link entrypoint}. Used to cache values between workflow runs.\n */\n cache?: BaseCache;\n};\n/**\n * Type declaration for the entrypoint function with its properties\n * @category Functional API\n */\nexport interface EntrypointFunction {\n <InputT, OutputT>(optionsOrName: EntrypointOptions | string, func: EntrypointFunc<InputT, OutputT>): Pregel<Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n }, Record<string, unknown>, InputT, 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 * 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 value - The value to return to the caller\n * @param 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 * 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 declare const entrypoint: EntrypointFunction;\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 declare function getPreviousState<StateT>(): StateT;\n"],"mappings":";;;;;;;;;;;;;AAWA;AAA4B,UAAXiB,WAAAA,CAAW;;;;EA8DJC,IAAAA,EAAAA,MAAI;EAAA;;;;OAA8EF,CAAAA,EArD9FN,WAqD8FM;;;;gBAjDxFP;AAqDlB;;;;;;AAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsKA;AAkBA;;;;;iBApNwBS,sDAAsDD,4BAA4BD,SAASG,OAAOC,qBAAqBD,UAAUE,QAAQD;;;;KAIrJE,iBAAAA;;;;;;;;;;iBAUOrB;;;;UAIPC;;;;UAIAF;;;;;;UAMKuB,kBAAAA;mCACoBD,kCAAkCP,eAAeS,QAAQJ,WAAWjB,OAAOsB,eAAerB,WAAWoB,QAAQX,kBAAkBO;KAC3Jb,KAAAA,GAAQC,eAAegB;KACvBnB,GAAAA,GAAMM,UAAUE,kBAAkBO;KAClCd,QAAAA,GAAWK,UAAUG,qBAAqBM;KAC5CK,yBAAyBD,QAAQX,kBAAkBO;;;;;EAItDM,QAAQb,kBAAkBO;;;;;;;;;;;;;;;;;;;;;YAqBdO;WACDC;MACPhB,gBAAgBe,QAAQC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsIXC,YAAYN;;;;;;;;;;;;;;;;;;iBAkBTO,4BAA4BC"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["BaseCache","BaseCheckpointSaver","BaseStore","Pregel","PregelNode","END","PREVIOUS","START","EphemeralValue","CachePolicy","RetryPolicy","LastValue","EntrypointFinal","EntrypointReturnT","EntrypointFinalSaveT","EntrypointFunc","TaskFunc","TaskOptions","task","ArgsT","OutputT","Promise","EntrypointOptions","EntrypointFunction","InputT","Record","Awaited","ValueT","SaveT","entrypoint","getPreviousState","StateT"],"sources":["../../src/func/index.d.ts"],"sourcesContent":["import { BaseCache, BaseCheckpointSaver, BaseStore } from \"@langchain/langgraph-checkpoint\";\nimport { Pregel } from \"../pregel/index.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport { END, PREVIOUS, START } from \"../constants.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { LastValue } from \"../channels/last_value.js\";\nimport { EntrypointFinal, EntrypointReturnT, EntrypointFinalSaveT, EntrypointFunc, TaskFunc } from \"./types.js\";\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 * The cache policy for the task. Configures how the task should be cached.\n */\n cachePolicy?: CachePolicy;\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 declare function task<ArgsT extends unknown[], OutputT>(optionsOrName: TaskOptions | string, func: TaskFunc<ArgsT, OutputT>): (...args: ArgsT) => Promise<OutputT>;\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 * The cache for the {@link entrypoint}. Used to cache values between workflow runs.\n */\n cache?: BaseCache;\n};\n/**\n * Type declaration for the entrypoint function with its properties\n * @category Functional API\n */\nexport interface EntrypointFunction {\n <InputT, OutputT>(optionsOrName: EntrypointOptions | string, func: EntrypointFunc<InputT, OutputT>): Pregel<Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n }, Record<string, unknown>, InputT, 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 * 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 * 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 declare const entrypoint: EntrypointFunction;\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 declare function getPreviousState<StateT>(): StateT;\n"],"mappings":";;;;;;;;;;;;;AAWA;AAA4B,UAAXiB,WAAAA,CAAW;;;;EA8DJC,IAAAA,EAAAA,MAAI;EAAA;;;;OAA8EF,CAAAA,EArD9FN,WAqD8FM;;;;gBAjDxFP;AAqDlB;;;;;;AAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsKA;AAkBA;;;;;iBApNwBS,sDAAsDD,4BAA4BD,SAASG,OAAOC,qBAAqBD,UAAUE,QAAQD;;;;KAIrJE,iBAAAA;;;;;;;;;;iBAUOrB;;;;UAIPC;;;;UAIAF;;;;;;UAMKuB,kBAAAA;mCACoBD,kCAAkCP,eAAeS,QAAQJ,WAAWjB,OAAOsB,eAAerB,WAAWoB,QAAQX,kBAAkBO;KAC3Jb,KAAAA,GAAQC,eAAegB;KACvBnB,GAAAA,GAAMM,UAAUE,kBAAkBO;KAClCd,QAAAA,GAAWK,UAAUG,qBAAqBM;KAC5CK,yBAAyBD,QAAQX,kBAAkBO;;;;;EAItDM,QAAQb,kBAAkBO;;;;;;;;;;;;;;;;;;;;;YAqBdO;WACDC;MACPhB,gBAAgBe,QAAQC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsIXC,YAAYN;;;;;;;;;;;;;;;;;;iBAkBTO,4BAA4BC"}
|
package/dist/func/index.d.ts
CHANGED
|
@@ -120,8 +120,8 @@ interface EntrypointFunction {
|
|
|
120
120
|
*
|
|
121
121
|
* @typeParam ValueT - The type of the value to return to the caller
|
|
122
122
|
* @typeParam SaveT - The type of the state to save to the checkpoint
|
|
123
|
-
* @param value - The value to return to the caller
|
|
124
|
-
* @param save - The value to save to the checkpoint
|
|
123
|
+
* @param options.value - The value to return to the caller
|
|
124
|
+
* @param options.save - The value to save to the checkpoint
|
|
125
125
|
* @returns An object with the value and save properties
|
|
126
126
|
*
|
|
127
127
|
* @example
|
package/dist/func/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["BaseCache","BaseCheckpointSaver","BaseStore","Pregel","PregelNode","END","PREVIOUS","START","EphemeralValue","CachePolicy","RetryPolicy","LastValue","EntrypointFinal","EntrypointReturnT","EntrypointFinalSaveT","EntrypointFunc","TaskFunc","TaskOptions","task","ArgsT","OutputT","Promise","EntrypointOptions","EntrypointFunction","InputT","Record","Awaited","ValueT","SaveT","entrypoint","getPreviousState","StateT"],"sources":["../../src/func/index.d.ts"],"sourcesContent":["import { BaseCache, BaseCheckpointSaver, BaseStore } from \"@langchain/langgraph-checkpoint\";\nimport { Pregel } from \"../pregel/index.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport { END, PREVIOUS, START } from \"../constants.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { LastValue } from \"../channels/last_value.js\";\nimport { EntrypointFinal, EntrypointReturnT, EntrypointFinalSaveT, EntrypointFunc, TaskFunc } from \"./types.js\";\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 * The cache policy for the task. Configures how the task should be cached.\n */\n cachePolicy?: CachePolicy;\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 declare function task<ArgsT extends unknown[], OutputT>(optionsOrName: TaskOptions | string, func: TaskFunc<ArgsT, OutputT>): (...args: ArgsT) => Promise<OutputT>;\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 * The cache for the {@link entrypoint}. Used to cache values between workflow runs.\n */\n cache?: BaseCache;\n};\n/**\n * Type declaration for the entrypoint function with its properties\n * @category Functional API\n */\nexport interface EntrypointFunction {\n <InputT, OutputT>(optionsOrName: EntrypointOptions | string, func: EntrypointFunc<InputT, OutputT>): Pregel<Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n }, Record<string, unknown>, InputT, 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 * 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 value - The value to return to the caller\n * @param 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 * 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 declare const entrypoint: EntrypointFunction;\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 declare function getPreviousState<StateT>(): StateT;\n"],"mappings":";;;;;;;;;;;;;AAWA;AAA4B,UAAXiB,WAAAA,CAAW;;;;EA8DJC,IAAAA,EAAAA,MAAI;EAAA;;;;OAA8EF,CAAAA,EArD9FN,WAqD8FM;;;;gBAjDxFP;AAqDlB;;;;;;AAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsKA;AAkBA;;;;;iBApNwBS,sDAAsDD,4BAA4BD,SAASG,OAAOC,qBAAqBD,UAAUE,QAAQD;;;;KAIrJE,iBAAAA;;;;;;;;;;iBAUOrB;;;;UAIPC;;;;UAIAF;;;;;;UAMKuB,kBAAAA;mCACoBD,kCAAkCP,eAAeS,QAAQJ,WAAWjB,OAAOsB,eAAerB,WAAWoB,QAAQX,kBAAkBO;KAC3Jb,KAAAA,GAAQC,eAAegB;KACvBnB,GAAAA,GAAMM,UAAUE,kBAAkBO;KAClCd,QAAAA,GAAWK,UAAUG,qBAAqBM;KAC5CK,yBAAyBD,QAAQX,kBAAkBO;;;;;EAItDM,QAAQb,kBAAkBO;;;;;;;;;;;;;;;;;;;;;YAqBdO;WACDC;MACPhB,gBAAgBe,QAAQC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsIXC,YAAYN;;;;;;;;;;;;;;;;;;iBAkBTO,4BAA4BC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["BaseCache","BaseCheckpointSaver","BaseStore","Pregel","PregelNode","END","PREVIOUS","START","EphemeralValue","CachePolicy","RetryPolicy","LastValue","EntrypointFinal","EntrypointReturnT","EntrypointFinalSaveT","EntrypointFunc","TaskFunc","TaskOptions","task","ArgsT","OutputT","Promise","EntrypointOptions","EntrypointFunction","InputT","Record","Awaited","ValueT","SaveT","entrypoint","getPreviousState","StateT"],"sources":["../../src/func/index.d.ts"],"sourcesContent":["import { BaseCache, BaseCheckpointSaver, BaseStore } from \"@langchain/langgraph-checkpoint\";\nimport { Pregel } from \"../pregel/index.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport { END, PREVIOUS, START } from \"../constants.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport type { CachePolicy, RetryPolicy } from \"../pregel/utils/index.js\";\nimport { LastValue } from \"../channels/last_value.js\";\nimport { EntrypointFinal, EntrypointReturnT, EntrypointFinalSaveT, EntrypointFunc, TaskFunc } from \"./types.js\";\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 * The cache policy for the task. Configures how the task should be cached.\n */\n cachePolicy?: CachePolicy;\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 declare function task<ArgsT extends unknown[], OutputT>(optionsOrName: TaskOptions | string, func: TaskFunc<ArgsT, OutputT>): (...args: ArgsT) => Promise<OutputT>;\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 * The cache for the {@link entrypoint}. Used to cache values between workflow runs.\n */\n cache?: BaseCache;\n};\n/**\n * Type declaration for the entrypoint function with its properties\n * @category Functional API\n */\nexport interface EntrypointFunction {\n <InputT, OutputT>(optionsOrName: EntrypointOptions | string, func: EntrypointFunc<InputT, OutputT>): Pregel<Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, {\n [START]: EphemeralValue<InputT>;\n [END]: LastValue<EntrypointReturnT<OutputT>>;\n [PREVIOUS]: LastValue<EntrypointFinalSaveT<OutputT>>;\n }, Record<string, unknown>, InputT, 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 * 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 * 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 declare const entrypoint: EntrypointFunction;\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 declare function getPreviousState<StateT>(): StateT;\n"],"mappings":";;;;;;;;;;;;;AAWA;AAA4B,UAAXiB,WAAAA,CAAW;;;;EA8DJC,IAAAA,EAAAA,MAAI;EAAA;;;;OAA8EF,CAAAA,EArD9FN,WAqD8FM;;;;gBAjDxFP;AAqDlB;;;;;;AAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsKA;AAkBA;;;;;iBApNwBS,sDAAsDD,4BAA4BD,SAASG,OAAOC,qBAAqBD,UAAUE,QAAQD;;;;KAIrJE,iBAAAA;;;;;;;;;;iBAUOrB;;;;UAIPC;;;;UAIAF;;;;;;UAMKuB,kBAAAA;mCACoBD,kCAAkCP,eAAeS,QAAQJ,WAAWjB,OAAOsB,eAAerB,WAAWoB,QAAQX,kBAAkBO;KAC3Jb,KAAAA,GAAQC,eAAegB;KACvBnB,GAAAA,GAAMM,UAAUE,kBAAkBO;KAClCd,QAAAA,GAAWK,UAAUG,qBAAqBM;KAC5CK,yBAAyBD,QAAQX,kBAAkBO;;;;;EAItDM,QAAQb,kBAAkBO;;;;;;;;;;;;;;;;;;;;;YAqBdO;WACDC;MACPhB,gBAAgBe,QAAQC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAsIXC,YAAYN;;;;;;;;;;;;;;;;;;iBAkBTO,4BAA4BC"}
|
package/dist/func/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 value - The value to return to the caller\n * @param 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,gBAGP,WAAW,UAAW,QAAQ,QAAwB;CAEzD,IAAIA;AACJ,KAAI,OAAO,gBAAgB,UACzB,SAAQ,cAAc,KAAK;KAE3B,SAAQ;AAGV,SAAQ,GAAG,SAAgB;AACzB,SAAO,KAAK;GAAE;GAAM;GAAM;GAAO;KAAS,GAAG;;;;;;;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mC;CACjD,MAAMC,SACJ,mCAAmC;AACrC,QAAO,OAAO,eAAe"}
|
|
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,gBAGP,WAAW,UAAW,QAAQ,QAAwB;CAEzD,IAAIA;AACJ,KAAI,OAAO,gBAAgB,UACzB,SAAQ,cAAc,KAAK;KAE3B,SAAQ;AAGV,SAAQ,GAAG,SAAgB;AACzB,SAAO,KAAK;GAAE;GAAM;GAAM;GAAO;KAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkNjD,MAAa,aAAa,SAASC,aACjC,eACA,MACA;CACA,MAAM,EAAE,MAAM,cAAc,OAAO,UACjC,OAAO,kBAAkB,WACrB;EAAE,MAAM;EAAe,cAAc;EAAW,OAAO;KACvD;AACN,KAAI,yBAAyB,SAAS,oBAAoB,MACxD,OAAM,IAAI,MACR;CAGJ,MAAM,aAAa;CACnB,MAAM,QAAQ,yBAAyB,MAAM;CAG7C,SAAS,kBACP,OAC4C;AAC5C,SACE,OAAO,UAAU,YACjB,UAAU,QACV,eAAe,SACf,MAAM,cAAc;;CAKxB,MAAM,mBAAmB,IAAI,iBAAiB;EAC5C,MAAM;EACN,OAAO,UAAmB;AACxB,UAAO,kBAAkB,SAAS,MAAM,QAAQ;;;CAKpD,MAAM,iBAAiB,IAAI,iBAAiB;EAC1C,MAAM;EACN,OAAO,UAAmB;AACxB,UAAO,kBAAkB,SAAS,MAAM,OAAO;;;CAInD,MAAM,iBAAiB,IAAI,WAA+C;EACxE;EACA,UAAU,CAAC;EACX,UAAU,CAAC;EACX,SAAS,CACP,IAAI,aACF,CACE;GAAE,SAAS;GAAK,OAAO;GAAa,QAAQ;KAC5C;GAAE,SAAS;GAAU,OAAO;GAAa,QAAQ;MAEnD,CAAC;;AAKP,QAAO,IAAI,OAUT;EACA;EACA;EACA,OAAO,GACJ,OAAO;EAEV,UAAU;IACP,QAAQ,IAAI;IACZ,MAAM,IAAI;IACV,WAAW,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/graph/graph.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"graph.cjs","names":["Runnable","ChannelWrite","RunnableCallable","e: any","NodeInterrupt","destinations: (string | Send)[]","_isSend","END","InvalidUpdateError","args","CHECKPOINT_NAMESPACE_SEPARATOR","CHECKPOINT_NAMESPACE_END","isPregelLike","START","options: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >","EphemeralValue","name","UnreachableNodeError","Pregel","PregelNode","PASSTHROUGH","TAG_HIDDEN","Channel","DrawableGraph","startNodes: Record<string, DrawableGraphNode>","z","endNodes: Record<string, DrawableGraphNode>","subgraphs: Record<string, CompiledGraph<any>>","gatherIterator","defaultEnds: Record<string, string>","gatherIteratorSync"],"sources":["../../src/graph/graph.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport {\n _coerceToRunnable,\n Runnable,\n RunnableConfig,\n RunnableInterface,\n RunnableIOSchema,\n type RunnableLike as LangChainRunnableLike,\n} from \"@langchain/core/runnables\";\nimport {\n Node as DrawableGraphNode,\n Graph as DrawableGraph,\n} from \"@langchain/core/runnables/graph\";\nimport { All, BaseCheckpointSaver } from \"@langchain/langgraph-checkpoint\";\nimport { z } from \"zod/v4\";\nimport { validate as isUuid } from \"uuid\";\nimport type {\n RunnableLike,\n LangGraphRunnableConfig,\n} from \"../pregel/runnable_types.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport { Channel, Pregel } from \"../pregel/index.js\";\nimport type { PregelParams } from \"../pregel/types.js\";\nimport { BaseChannel } from \"../channels/base.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport { ChannelWrite, PASSTHROUGH } from \"../pregel/write.js\";\nimport {\n _isSend,\n CHECKPOINT_NAMESPACE_END,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n END,\n Send,\n START,\n TAG_HIDDEN,\n} from \"../constants.js\";\nimport {\n gatherIterator,\n gatherIteratorSync,\n RunnableCallable,\n} from \"../utils.js\";\nimport {\n InvalidUpdateError,\n NodeInterrupt,\n UnreachableNodeError,\n} from \"../errors.js\";\nimport { StateDefinition, StateType } from \"./annotation.js\";\nimport { isPregelLike } from \"../pregel/utils/subgraph.js\";\n\nexport interface BranchOptions<\n IO,\n N extends string,\n CallOptions extends LangGraphRunnableConfig = LangGraphRunnableConfig\n> {\n source: N;\n path: RunnableLike<IO, BranchPathReturnValue, CallOptions>;\n pathMap?: Record<string, N | typeof END> | (N | typeof END)[];\n}\n\nexport type BranchPathReturnValue =\n | string\n | Send\n | (string | Send)[]\n | Promise<string | Send | (string | Send)[]>;\n\ntype NodeAction<S, U, C extends StateDefinition> = RunnableLike<\n S,\n U extends object ? U & Record<string, any> : U, // eslint-disable-line @typescript-eslint/no-explicit-any\n LangGraphRunnableConfig<StateType<C>>\n>;\n\nexport class Branch<\n IO,\n N extends string,\n CallOptions extends LangGraphRunnableConfig = LangGraphRunnableConfig\n> {\n path: Runnable<IO, BranchPathReturnValue, CallOptions>;\n\n ends?: Record<string, N | typeof END>;\n\n constructor(options: Omit<BranchOptions<IO, N, CallOptions>, \"source\">) {\n if (Runnable.isRunnable(options.path)) {\n this.path = options.path as Runnable<\n IO,\n BranchPathReturnValue,\n CallOptions\n >;\n } else {\n this.path = _coerceToRunnable(\n options.path as LangChainRunnableLike<\n IO,\n BranchPathReturnValue,\n CallOptions\n >\n ).withConfig({ runName: `Branch` } as CallOptions);\n }\n this.ends = Array.isArray(options.pathMap)\n ? options.pathMap.reduce((acc, n) => {\n acc[n] = n;\n return acc;\n }, {} as Record<string, N | typeof END>)\n : options.pathMap;\n }\n\n run(\n writer: (\n dests: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => Runnable | void | Promise<void>,\n reader?: (config: CallOptions) => IO\n ) {\n return ChannelWrite.registerWriter(\n new RunnableCallable({\n name: \"<branch_run>\",\n trace: false,\n func: async (input: IO, config: CallOptions) => {\n try {\n return await this._route(input, config, writer, reader);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n // Detect & warn if NodeInterrupt is thrown in a conditional edge\n if (e.name === NodeInterrupt.unminifiable_name) {\n console.warn(\n \"[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.\\n\" +\n \"NodeInterrupt should only be thrown inside a node, not in edge conditions.\"\n );\n }\n throw e;\n }\n },\n })\n );\n }\n\n async _route(\n input: IO,\n config: CallOptions,\n writer: (\n dests: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => Runnable | void | Promise<void>,\n reader?: (config: CallOptions) => IO\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<Runnable | any> {\n let result = await this.path.invoke(\n reader ? reader(config) : input,\n config\n );\n if (!Array.isArray(result)) {\n result = [result];\n }\n\n let destinations: (string | Send)[];\n if (this.ends) {\n destinations = result.map((r) => (_isSend(r) ? r : this.ends![r]));\n } else {\n destinations = result;\n }\n if (destinations.some((dest) => !dest)) {\n throw new Error(\"Branch condition returned unknown or null destination\");\n }\n if (destinations.filter(_isSend).some((packet) => packet.node === END)) {\n throw new InvalidUpdateError(\"Cannot send a packet to the END node\");\n }\n const writeResult = await writer(destinations, config);\n return writeResult ?? input;\n }\n}\n\nexport type NodeSpec<RunInput, RunOutput> = {\n runnable: Runnable<RunInput, RunOutput>;\n metadata?: Record<string, unknown>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subgraphs?: Pregel<any, any>[];\n ends?: string[];\n defer?: boolean;\n};\n\nexport type AddNodeOptions<Nodes extends string = string> = {\n metadata?: Record<string, unknown>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subgraphs?: Pregel<any, any>[];\n ends?: Nodes[];\n defer?: boolean;\n};\n\nexport class Graph<\n N extends string = typeof START | typeof END,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput = any,\n NodeSpecType extends NodeSpec<RunInput, RunOutput> = NodeSpec<\n RunInput,\n RunOutput\n >,\n C extends StateDefinition = StateDefinition\n> {\n nodes: Record<N, NodeSpecType>;\n\n edges: Set<[N | typeof START, N | typeof END]>;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n branches: Record<string, Record<string, Branch<RunInput, N, any>>>;\n\n entryPoint?: string;\n\n compiled = false;\n\n constructor() {\n this.nodes = {} as Record<N, NodeSpecType>;\n this.edges = new Set();\n this.branches = {};\n }\n\n protected warnIfCompiled(message: string): void {\n if (this.compiled) {\n console.warn(message);\n }\n }\n\n get allEdges(): Set<[string, string]> {\n return this.edges;\n }\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n nodes:\n | Record<K, NodeAction<NodeInput, NodeOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ][]\n ): Graph<N | K, RunInput, RunOutput>;\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ): Graph<N | K, RunInput, RunOutput>;\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n ...args:\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ]\n | [\n nodes:\n | Record<K, NodeAction<NodeInput, NodeOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ][]\n ]\n ): Graph<N | K, RunInput, RunOutput> {\n function isMutlipleNodes(\n args: unknown[]\n ): args is [\n nodes:\n | Record<K, NodeAction<NodeInput, RunOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, RunOutput, C>,\n options?: AddNodeOptions\n ][],\n options?: AddNodeOptions\n ] {\n return args.length >= 1 && typeof args[0] !== \"string\";\n }\n\n const nodes = (\n isMutlipleNodes(args) // eslint-disable-line no-nested-ternary\n ? Array.isArray(args[0])\n ? args[0]\n : Object.entries(args[0])\n : [[args[0], args[1], args[2]]]\n ) as [K, NodeAction<NodeInput, RunOutput, C>, AddNodeOptions][];\n\n if (nodes.length === 0) {\n throw new Error(\"No nodes provided in `addNode`\");\n }\n\n for (const [key, action, options] of nodes) {\n for (const reservedChar of [\n CHECKPOINT_NAMESPACE_SEPARATOR,\n CHECKPOINT_NAMESPACE_END,\n ]) {\n if (key.includes(reservedChar)) {\n throw new Error(\n `\"${reservedChar}\" is a reserved character and is not allowed in node names.`\n );\n }\n }\n this.warnIfCompiled(\n `Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (key in this.nodes) {\n throw new Error(`Node \\`${key}\\` already present.`);\n }\n if (key === END) {\n throw new Error(`Node \\`${key}\\` is reserved.`);\n }\n\n const runnable = _coerceToRunnable<RunInput, RunOutput>(\n // Account for arbitrary state due to Send API\n action as RunnableLike<RunInput, RunOutput>\n );\n\n this.nodes[key as unknown as N] = {\n runnable,\n metadata: options?.metadata,\n subgraphs: isPregelLike(runnable) ? [runnable] : options?.subgraphs,\n ends: options?.ends,\n } as NodeSpecType;\n }\n\n return this as Graph<N | K, RunInput, RunOutput, NodeSpecType>;\n }\n\n addEdge(startKey: N | typeof START, endKey: N | typeof END): this {\n this.warnIfCompiled(\n `Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (startKey === END) {\n throw new Error(\"END cannot be a start node\");\n }\n if (endKey === START) {\n throw new Error(\"START cannot be an end node\");\n }\n if (\n Array.from(this.edges).some(([start]) => start === startKey) &&\n !(\"channels\" in this)\n ) {\n throw new Error(\n `Already found path for ${startKey}. For multiple edges, use StateGraph.`\n );\n }\n\n this.edges.add([startKey, endKey]);\n\n return this;\n }\n\n addConditionalEdges(\n source: BranchOptions<RunInput, N, LangGraphRunnableConfig<StateType<C>>>\n ): this;\n\n addConditionalEdges(\n source: N,\n path: RunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >,\n pathMap?: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >[\"pathMap\"]\n ): this;\n\n addConditionalEdges(\n source:\n | N\n | BranchOptions<RunInput, N, LangGraphRunnableConfig<StateType<C>>>,\n path?: RunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >,\n pathMap?: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >[\"pathMap\"]\n ): this {\n const options: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n > = typeof source === \"object\" ? source : { source, path: path!, pathMap };\n\n this.warnIfCompiled(\n \"Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n if (!Runnable.isRunnable(options.path)) {\n const pathDisplayValues = Array.isArray(options.pathMap)\n ? options.pathMap.join(\",\")\n : Object.keys(options.pathMap ?? {}).join(\",\");\n options.path = _coerceToRunnable(\n options.path as LangChainRunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >\n ).withConfig({\n runName: `Branch<${options.source}${\n pathDisplayValues !== \"\" ? `,${pathDisplayValues}` : \"\"\n }>`.slice(0, 63),\n });\n }\n // find a name for condition\n const name =\n options.path.getName() === \"RunnableLambda\"\n ? \"condition\"\n : options.path.getName();\n // validate condition\n if (this.branches[options.source] && this.branches[options.source][name]) {\n throw new Error(\n `Condition \\`${name}\\` already present for node \\`${source}\\``\n );\n }\n // save it\n this.branches[options.source] ??= {};\n this.branches[options.source][name] = new Branch(options);\n return this;\n }\n\n /**\n * @deprecated use `addEdge(START, key)` instead\n */\n setEntryPoint(key: N): this {\n this.warnIfCompiled(\n \"Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n\n return this.addEdge(START, key);\n }\n\n /**\n * @deprecated use `addEdge(key, END)` instead\n */\n setFinishPoint(key: N): this {\n this.warnIfCompiled(\n \"Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n\n return this.addEdge(key, END);\n }\n\n compile({\n checkpointer,\n interruptBefore,\n interruptAfter,\n name,\n }: {\n checkpointer?: BaseCheckpointSaver | false;\n interruptBefore?: N[] | All;\n interruptAfter?: N[] | All;\n name?: string;\n } = {}): CompiledGraph<N> {\n // validate the graph\n this.validate([\n ...(Array.isArray(interruptBefore) ? interruptBefore : []),\n ...(Array.isArray(interruptAfter) ? interruptAfter : []),\n ]);\n\n // create empty compiled graph\n const compiled = new CompiledGraph({\n builder: this,\n checkpointer,\n interruptAfter,\n interruptBefore,\n autoValidate: false,\n nodes: {} as Record<N | typeof START, PregelNode<RunInput, RunOutput>>,\n channels: {\n [START]: new EphemeralValue(),\n [END]: new EphemeralValue(),\n } as Record<N | typeof START | typeof END | string, BaseChannel>,\n inputChannels: START,\n outputChannels: END,\n streamChannels: [] as N[],\n streamMode: \"values\",\n name,\n });\n\n // attach nodes, edges and branches\n for (const [key, node] of Object.entries<NodeSpec<RunInput, RunOutput>>(\n this.nodes\n )) {\n compiled.attachNode(key as N, node);\n }\n for (const [start, end] of this.edges) {\n compiled.attachEdge(start, end);\n }\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const [name, branch] of Object.entries(branches)) {\n compiled.attachBranch(start as N, name, branch);\n }\n }\n\n return compiled.validate();\n }\n\n validate(interrupt?: string[]): void {\n // assemble sources\n const allSources = new Set([...this.allEdges].map(([src, _]) => src));\n for (const [start] of Object.entries(this.branches)) {\n allSources.add(start);\n }\n\n // validate sources\n for (const source of allSources) {\n if (source !== START && !(source in this.nodes)) {\n throw new Error(`Found edge starting at unknown node \\`${source}\\``);\n }\n }\n\n // assemble targets\n const allTargets = new Set([...this.allEdges].map(([_, target]) => target));\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const branch of Object.values(branches)) {\n if (branch.ends != null) {\n for (const end of Object.values(branch.ends)) {\n allTargets.add(end);\n }\n } else {\n allTargets.add(END);\n for (const node of Object.keys(this.nodes)) {\n if (node !== start) {\n allTargets.add(node);\n }\n }\n }\n }\n }\n for (const node of Object.values<NodeSpecType>(this.nodes)) {\n for (const target of node.ends ?? []) {\n allTargets.add(target);\n }\n }\n // validate targets\n for (const node of Object.keys(this.nodes)) {\n if (!allTargets.has(node)) {\n throw new UnreachableNodeError(\n [\n `Node \\`${node}\\` is not reachable.`,\n \"\",\n \"If you are returning Command objects from your node,\",\n 'make sure you are passing names of potential destination nodes as an \"ends\" array',\n 'into \".addNode(..., { ends: [\"node1\", \"node2\"] })\".',\n ].join(\"\\n\"),\n {\n lc_error_code: \"UNREACHABLE_NODE\",\n }\n );\n }\n }\n for (const target of allTargets) {\n if (target !== END && !(target in this.nodes)) {\n throw new Error(`Found edge ending at unknown node \\`${target}\\``);\n }\n }\n\n // validate interrupts\n if (interrupt) {\n for (const node of interrupt) {\n if (!(node in this.nodes)) {\n throw new Error(`Interrupt node \\`${node}\\` is not present`);\n }\n }\n }\n\n this.compiled = true;\n }\n}\n\nexport class CompiledGraph<\n N extends string,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n State = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Update = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ContextType extends Record<string, any> = Record<string, any>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n InputType = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n OutputType = any,\n NodeReturnType = unknown,\n CommandType = unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n StreamCustomType = any\n> extends Pregel<\n Record<N | typeof START, PregelNode<State, Update>>,\n Record<N | typeof START | typeof END | string, BaseChannel>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ContextType & Record<string, any>,\n InputType,\n OutputType,\n InputType,\n OutputType,\n NodeReturnType,\n CommandType,\n StreamCustomType\n> {\n declare NodeType: N;\n\n declare \"~NodeReturnType\": NodeReturnType;\n\n declare RunInput: State;\n\n declare RunOutput: Update;\n\n builder: Graph<N, State, Update>;\n\n constructor({\n builder,\n ...rest\n }: { builder: Graph<N, State, Update> } & PregelParams<\n Record<N | typeof START, PregelNode<State, Update>>,\n Record<N | typeof START | typeof END | string, BaseChannel>\n >) {\n super(rest);\n this.builder = builder;\n }\n\n attachNode(key: N, node: NodeSpec<State, Update>): void {\n this.channels[key] = new EphemeralValue();\n this.nodes[key] = new PregelNode({\n channels: [],\n triggers: [],\n metadata: node.metadata,\n subgraphs: node.subgraphs,\n ends: node.ends,\n })\n .pipe(node.runnable)\n .pipe(\n new ChannelWrite([{ channel: key, value: PASSTHROUGH }], [TAG_HIDDEN])\n );\n (this.streamChannels as N[]).push(key);\n }\n\n attachEdge(start: N | typeof START, end: N | typeof END): void {\n if (end === END) {\n if (start === START) {\n throw new Error(\"Cannot have an edge from START to END\");\n }\n this.nodes[start].writers.push(\n new ChannelWrite([{ channel: END, value: PASSTHROUGH }], [TAG_HIDDEN])\n );\n } else {\n this.nodes[end].triggers.push(start);\n (this.nodes[end].channels as string[]).push(start);\n }\n }\n\n attachBranch(\n start: N | typeof START,\n name: string,\n branch: Branch<State, N>\n ) {\n // add hidden start node\n if (start === START && !this.nodes[START]) {\n this.nodes[START] = Channel.subscribeTo(START, { tags: [TAG_HIDDEN] });\n }\n\n // attach branch writer\n this.nodes[start].pipe(\n branch.run((dests) => {\n const writes = dests.map((dest) => {\n if (_isSend(dest)) {\n return dest;\n }\n return {\n channel: dest === END ? END : `branch:${start}:${name}:${dest}`,\n value: PASSTHROUGH,\n };\n });\n return new ChannelWrite(writes, [TAG_HIDDEN]);\n })\n );\n\n // attach branch readers\n const ends = branch.ends\n ? Object.values(branch.ends)\n : (Object.keys(this.nodes) as N[]);\n for (const end of ends) {\n if (end !== END) {\n const channelName = `branch:${start}:${name}:${end}`;\n (this.channels as Record<string, BaseChannel>)[channelName] =\n new EphemeralValue();\n this.nodes[end].triggers.push(channelName);\n (this.nodes[end].channels as string[]).push(channelName);\n }\n }\n }\n\n /**\n * Returns a drawable representation of the computation graph.\n */\n override async getGraphAsync(\n config?: RunnableConfig & { xray?: boolean | number }\n ): Promise<DrawableGraph> {\n const xray = config?.xray;\n const graph = new DrawableGraph();\n const startNodes: Record<string, DrawableGraphNode> = {\n [START]: graph.addNode({ schema: z.any() }, START),\n };\n const endNodes: Record<string, DrawableGraphNode> = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let subgraphs: Record<string, CompiledGraph<any>> = {};\n if (xray) {\n subgraphs = Object.fromEntries(\n (await gatherIterator(this.getSubgraphsAsync())).filter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x): x is [string, CompiledGraph<any>] => isCompiledGraph(x[1])\n )\n );\n }\n\n function addEdge(\n start: string,\n end: string,\n label?: string,\n conditional = false\n ) {\n if (end === END && endNodes[END] === undefined) {\n endNodes[END] = graph.addNode({ schema: z.any() }, END);\n }\n if (startNodes[start] === undefined) {\n return;\n }\n if (endNodes[end] === undefined) {\n throw new Error(`End node ${end} not found!`);\n }\n return graph.addEdge(\n startNodes[start],\n endNodes[end],\n label !== end ? label : undefined,\n conditional\n );\n }\n\n for (const [key, nodeSpec] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>\n ][]) {\n const displayKey = _escapeMermaidKeywords(key);\n const node = nodeSpec.runnable;\n const metadata = nodeSpec.metadata ?? {};\n if (\n this.interruptBefore?.includes(key) &&\n this.interruptAfter?.includes(key)\n ) {\n metadata.__interrupt = \"before,after\";\n } else if (this.interruptBefore?.includes(key)) {\n metadata.__interrupt = \"before\";\n } else if (this.interruptAfter?.includes(key)) {\n metadata.__interrupt = \"after\";\n }\n if (xray) {\n const newXrayValue = typeof xray === \"number\" ? xray - 1 : xray;\n const drawableSubgraph =\n subgraphs[key] !== undefined\n ? await subgraphs[key].getGraphAsync({\n ...config,\n xray: newXrayValue,\n })\n : node.getGraph(config);\n\n drawableSubgraph.trimFirstNode();\n drawableSubgraph.trimLastNode();\n\n if (Object.keys(drawableSubgraph.nodes).length > 1) {\n const [e, s] = graph.extend(drawableSubgraph, displayKey);\n if (e === undefined) {\n throw new Error(\n `Could not extend subgraph \"${key}\" due to missing entrypoint.`\n );\n }\n\n // TODO: Remove default name once we stop supporting core 0.2.0\n // eslint-disable-next-line no-inner-declarations\n function _isRunnableInterface(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thing: any\n ): thing is RunnableInterface {\n return thing ? thing.lc_runnable : false;\n }\n // eslint-disable-next-line no-inner-declarations\n function _nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n ): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (_isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch (error) {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n }\n // TODO: Remove casts when we stop supporting core 0.2.0\n if (s !== undefined) {\n startNodes[displayKey] = {\n name: _nodeDataStr(s.id, s.data),\n ...s,\n } as DrawableGraphNode;\n }\n endNodes[displayKey] = {\n name: _nodeDataStr(e.id, e.data),\n ...e,\n } as DrawableGraphNode;\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n }\n const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (b > a) {\n return 1;\n } else {\n return 0;\n }\n });\n for (const [start, end] of sortedEdges) {\n addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));\n }\n for (const [start, branches] of Object.entries(this.builder.branches)) {\n const defaultEnds: Record<string, string> = {\n ...Object.fromEntries(\n Object.keys(this.builder.nodes)\n .filter((k) => k !== start)\n .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])\n ),\n [END]: END,\n };\n for (const branch of Object.values(branches)) {\n let ends;\n if (branch.ends !== undefined) {\n ends = branch.ends;\n } else {\n ends = defaultEnds;\n }\n for (const [label, end] of Object.entries(ends)) {\n addEdge(\n _escapeMermaidKeywords(start),\n _escapeMermaidKeywords(end),\n label,\n true\n );\n }\n }\n }\n for (const [key, node] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>\n ][]) {\n if (node.ends !== undefined) {\n for (const end of node.ends) {\n addEdge(\n _escapeMermaidKeywords(key),\n _escapeMermaidKeywords(end),\n undefined,\n true\n );\n }\n }\n }\n return graph;\n }\n\n /**\n * Returns a drawable representation of the computation graph.\n *\n * @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.\n */\n override getGraph(\n config?: RunnableConfig & { xray?: boolean | number }\n ): DrawableGraph {\n const xray = config?.xray;\n const graph = new DrawableGraph();\n const startNodes: Record<string, DrawableGraphNode> = {\n [START]: graph.addNode(\n {\n schema: z.any(),\n },\n START\n ),\n };\n const endNodes: Record<string, DrawableGraphNode> = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let subgraphs: Record<string, CompiledGraph<any>> = {};\n if (xray) {\n subgraphs = Object.fromEntries(\n gatherIteratorSync(this.getSubgraphs()).filter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x): x is [string, CompiledGraph<any>] => isCompiledGraph(x[1])\n )\n );\n }\n\n function addEdge(\n start: string,\n end: string,\n label?: string,\n conditional = false\n ) {\n if (end === END && endNodes[END] === undefined) {\n endNodes[END] = graph.addNode({ schema: z.any() }, END);\n }\n return graph.addEdge(\n startNodes[start],\n endNodes[end],\n label !== end ? label : undefined,\n conditional\n );\n }\n\n for (const [key, nodeSpec] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>\n ][]) {\n const displayKey = _escapeMermaidKeywords(key);\n const node = nodeSpec.runnable;\n const metadata = nodeSpec.metadata ?? {};\n if (\n this.interruptBefore?.includes(key) &&\n this.interruptAfter?.includes(key)\n ) {\n metadata.__interrupt = \"before,after\";\n } else if (this.interruptBefore?.includes(key)) {\n metadata.__interrupt = \"before\";\n } else if (this.interruptAfter?.includes(key)) {\n metadata.__interrupt = \"after\";\n }\n if (xray) {\n const newXrayValue = typeof xray === \"number\" ? xray - 1 : xray;\n const drawableSubgraph =\n subgraphs[key] !== undefined\n ? subgraphs[key].getGraph({\n ...config,\n xray: newXrayValue,\n })\n : node.getGraph(config);\n drawableSubgraph.trimFirstNode();\n drawableSubgraph.trimLastNode();\n if (Object.keys(drawableSubgraph.nodes).length > 1) {\n const [e, s] = graph.extend(drawableSubgraph, displayKey);\n if (e === undefined) {\n throw new Error(\n `Could not extend subgraph \"${key}\" due to missing entrypoint.`\n );\n }\n\n // TODO: Remove default name once we stop supporting core 0.2.0\n // eslint-disable-next-line no-inner-declarations\n function _isRunnableInterface(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thing: any\n ): thing is RunnableInterface {\n return thing ? thing.lc_runnable : false;\n }\n // eslint-disable-next-line no-inner-declarations\n function _nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n ): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (_isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch (error) {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n }\n // TODO: Remove casts when we stop supporting core 0.2.0\n if (s !== undefined) {\n startNodes[displayKey] = {\n name: _nodeDataStr(s.id, s.data),\n ...s,\n } as DrawableGraphNode;\n }\n endNodes[displayKey] = {\n name: _nodeDataStr(e.id, e.data),\n ...e,\n } as DrawableGraphNode;\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n }\n const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (b > a) {\n return 1;\n } else {\n return 0;\n }\n });\n for (const [start, end] of sortedEdges) {\n addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));\n }\n for (const [start, branches] of Object.entries(this.builder.branches)) {\n const defaultEnds: Record<string, string> = {\n ...Object.fromEntries(\n Object.keys(this.builder.nodes)\n .filter((k) => k !== start)\n .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])\n ),\n [END]: END,\n };\n for (const branch of Object.values(branches)) {\n let ends;\n if (branch.ends !== undefined) {\n ends = branch.ends;\n } else {\n ends = defaultEnds;\n }\n for (const [label, end] of Object.entries(ends)) {\n addEdge(\n _escapeMermaidKeywords(start),\n _escapeMermaidKeywords(end),\n label,\n true\n );\n }\n }\n }\n return graph;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isCompiledGraph(x: unknown): x is CompiledGraph<any> {\n return (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (x as CompiledGraph<any>).attachNode === \"function\" &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (x as CompiledGraph<any>).attachEdge === \"function\"\n );\n}\n\nfunction _escapeMermaidKeywords(key: string) {\n if (key === \"subgraph\") {\n return `\"${key}\"`;\n }\n return key;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsEA,IAAa,SAAb,MAIE;CACA;CAEA;CAEA,YAAY,SAA4D;AACtE,MAAIA,oCAAS,WAAW,QAAQ,MAC9B,MAAK,OAAO,QAAQ;MAMpB,MAAK,yDACH,QAAQ,MAKR,WAAW,EAAE,SAAS;AAE1B,OAAK,OAAO,MAAM,QAAQ,QAAQ,WAC9B,QAAQ,QAAQ,QAAQ,KAAK,MAAM;AACjC,OAAI,KAAK;AACT,UAAO;KACN,MACH,QAAQ;;CAGd,IACE,QAIA,QACA;AACA,SAAOC,2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BAAuB,QACvB,uBAAuB,MACvB,OACA;;;AAKR,SAAO;;;AAKX,SAAS,gBAAgB,GAAqC;AAC5D,QAEE,OAAQ,EAAyB,eAAe,cAEhD,OAAQ,EAAyB,eAAe;;AAIpD,SAAS,uBAAuB,KAAa;AAC3C,KAAI,QAAQ,WACV,QAAO,IAAI,IAAI;AAEjB,QAAO"}
|
|
1
|
+
{"version":3,"file":"graph.cjs","names":["Runnable","ChannelWrite","RunnableCallable","e: any","NodeInterrupt","destinations: (string | Send)[]","_isSend","END","InvalidUpdateError","args","CHECKPOINT_NAMESPACE_SEPARATOR","CHECKPOINT_NAMESPACE_END","isPregelLike","START","options: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >","EphemeralValue","name","UnreachableNodeError","Pregel","PregelNode","PASSTHROUGH","TAG_HIDDEN","Channel","DrawableGraph","startNodes: Record<string, DrawableGraphNode>","z","endNodes: Record<string, DrawableGraphNode>","subgraphs: Record<string, CompiledGraph<any>>","gatherIterator","defaultEnds: Record<string, string>","gatherIteratorSync"],"sources":["../../src/graph/graph.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport {\n _coerceToRunnable,\n Runnable,\n RunnableConfig,\n RunnableInterface,\n RunnableIOSchema,\n type RunnableLike as LangChainRunnableLike,\n} from \"@langchain/core/runnables\";\nimport {\n Node as DrawableGraphNode,\n Graph as DrawableGraph,\n} from \"@langchain/core/runnables/graph\";\nimport { All, BaseCheckpointSaver } from \"@langchain/langgraph-checkpoint\";\nimport { z } from \"zod/v4\";\nimport { validate as isUuid } from \"uuid\";\nimport type {\n RunnableLike,\n LangGraphRunnableConfig,\n} from \"../pregel/runnable_types.js\";\nimport { PregelNode } from \"../pregel/read.js\";\nimport { Channel, Pregel } from \"../pregel/index.js\";\nimport type { PregelParams } from \"../pregel/types.js\";\nimport { BaseChannel } from \"../channels/base.js\";\nimport { EphemeralValue } from \"../channels/ephemeral_value.js\";\nimport { ChannelWrite, PASSTHROUGH } from \"../pregel/write.js\";\nimport {\n _isSend,\n CHECKPOINT_NAMESPACE_END,\n CHECKPOINT_NAMESPACE_SEPARATOR,\n END,\n Send,\n START,\n TAG_HIDDEN,\n} from \"../constants.js\";\nimport {\n gatherIterator,\n gatherIteratorSync,\n RunnableCallable,\n} from \"../utils.js\";\nimport {\n InvalidUpdateError,\n NodeInterrupt,\n UnreachableNodeError,\n} from \"../errors.js\";\nimport { StateDefinition, StateType } from \"./annotation.js\";\nimport { isPregelLike } from \"../pregel/utils/subgraph.js\";\n\nexport interface BranchOptions<\n IO,\n N extends string,\n CallOptions extends LangGraphRunnableConfig = LangGraphRunnableConfig\n> {\n source: N;\n path: RunnableLike<IO, BranchPathReturnValue, CallOptions>;\n pathMap?: Record<string, N | typeof END> | (N | typeof END)[];\n}\n\nexport type BranchPathReturnValue =\n | string\n | Send\n | (string | Send)[]\n | Promise<string | Send | (string | Send)[]>;\n\ntype NodeAction<S, U, C extends StateDefinition> = RunnableLike<\n S,\n U extends object ? U & Record<string, any> : U, // eslint-disable-line @typescript-eslint/no-explicit-any\n LangGraphRunnableConfig<StateType<C>>\n>;\n\nexport class Branch<\n IO,\n N extends string,\n CallOptions extends LangGraphRunnableConfig = LangGraphRunnableConfig\n> {\n path: Runnable<IO, BranchPathReturnValue, CallOptions>;\n\n ends?: Record<string, N | typeof END>;\n\n constructor(options: Omit<BranchOptions<IO, N, CallOptions>, \"source\">) {\n if (Runnable.isRunnable(options.path)) {\n this.path = options.path as Runnable<\n IO,\n BranchPathReturnValue,\n CallOptions\n >;\n } else {\n this.path = _coerceToRunnable(\n options.path as LangChainRunnableLike<\n IO,\n BranchPathReturnValue,\n CallOptions\n >\n ).withConfig({ runName: `Branch` } as CallOptions);\n }\n this.ends = Array.isArray(options.pathMap)\n ? options.pathMap.reduce((acc, n) => {\n acc[n] = n;\n return acc;\n }, {} as Record<string, N | typeof END>)\n : options.pathMap;\n }\n\n run(\n writer: (\n dests: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => Runnable | void | Promise<void>,\n reader?: (config: CallOptions) => IO\n ) {\n return ChannelWrite.registerWriter(\n new RunnableCallable({\n name: \"<branch_run>\",\n trace: false,\n func: async (input: IO, config: CallOptions) => {\n try {\n return await this._route(input, config, writer, reader);\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n // Detect & warn if NodeInterrupt is thrown in a conditional edge\n if (e.name === NodeInterrupt.unminifiable_name) {\n console.warn(\n \"[WARN]: 'NodeInterrupt' thrown in conditional edge. This is likely a bug in your graph implementation.\\n\" +\n \"NodeInterrupt should only be thrown inside a node, not in edge conditions.\"\n );\n }\n throw e;\n }\n },\n })\n );\n }\n\n async _route(\n input: IO,\n config: CallOptions,\n writer: (\n dests: (string | Send)[],\n config: LangGraphRunnableConfig\n ) => Runnable | void | Promise<void>,\n reader?: (config: CallOptions) => IO\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ): Promise<Runnable | any> {\n let result = await this.path.invoke(\n reader ? reader(config) : input,\n config\n );\n if (!Array.isArray(result)) {\n result = [result];\n }\n\n let destinations: (string | Send)[];\n if (this.ends) {\n destinations = result.map((r) => (_isSend(r) ? r : this.ends![r]));\n } else {\n destinations = result;\n }\n if (destinations.some((dest) => !dest)) {\n throw new Error(\"Branch condition returned unknown or null destination\");\n }\n if (destinations.filter(_isSend).some((packet) => packet.node === END)) {\n throw new InvalidUpdateError(\"Cannot send a packet to the END node\");\n }\n const writeResult = await writer(destinations, config);\n return writeResult ?? input;\n }\n}\n\nexport type NodeSpec<RunInput, RunOutput> = {\n runnable: Runnable<RunInput, RunOutput>;\n metadata?: Record<string, unknown>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subgraphs?: Pregel<any, any>[];\n ends?: string[];\n defer?: boolean;\n};\n\nexport type AddNodeOptions<Nodes extends string = string> = {\n metadata?: Record<string, unknown>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n subgraphs?: Pregel<any, any>[];\n ends?: Nodes[];\n defer?: boolean;\n};\n\nexport class Graph<\n N extends string = typeof START | typeof END,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunInput = any,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n RunOutput = any,\n NodeSpecType extends NodeSpec<RunInput, RunOutput> = NodeSpec<\n RunInput,\n RunOutput\n >,\n C extends StateDefinition = StateDefinition\n> {\n nodes: Record<N, NodeSpecType>;\n\n edges: Set<[N | typeof START, N | typeof END]>;\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n branches: Record<string, Record<string, Branch<RunInput, N, any>>>;\n\n entryPoint?: string;\n\n compiled = false;\n\n constructor() {\n this.nodes = {} as Record<N, NodeSpecType>;\n this.edges = new Set();\n this.branches = {};\n }\n\n protected warnIfCompiled(message: string): void {\n if (this.compiled) {\n console.warn(message);\n }\n }\n\n get allEdges(): Set<[string, string]> {\n return this.edges;\n }\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n nodes:\n | Record<K, NodeAction<NodeInput, NodeOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ][]\n ): Graph<N | K, RunInput, RunOutput>;\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ): Graph<N | K, RunInput, RunOutput>;\n\n addNode<K extends string, NodeInput = RunInput, NodeOutput = RunOutput>(\n ...args:\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ]\n | [\n nodes:\n | Record<K, NodeAction<NodeInput, NodeOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, NodeOutput, C>,\n options?: AddNodeOptions\n ][]\n ]\n ): Graph<N | K, RunInput, RunOutput> {\n function isMutlipleNodes(\n args: unknown[]\n ): args is [\n nodes:\n | Record<K, NodeAction<NodeInput, RunOutput, C>>\n | [\n key: K,\n action: NodeAction<NodeInput, RunOutput, C>,\n options?: AddNodeOptions\n ][],\n options?: AddNodeOptions\n ] {\n return args.length >= 1 && typeof args[0] !== \"string\";\n }\n\n const nodes = (\n isMutlipleNodes(args) // eslint-disable-line no-nested-ternary\n ? Array.isArray(args[0])\n ? args[0]\n : Object.entries(args[0])\n : [[args[0], args[1], args[2]]]\n ) as [K, NodeAction<NodeInput, RunOutput, C>, AddNodeOptions][];\n\n if (nodes.length === 0) {\n throw new Error(\"No nodes provided in `addNode`\");\n }\n\n for (const [key, action, options] of nodes) {\n for (const reservedChar of [\n CHECKPOINT_NAMESPACE_SEPARATOR,\n CHECKPOINT_NAMESPACE_END,\n ]) {\n if (key.includes(reservedChar)) {\n throw new Error(\n `\"${reservedChar}\" is a reserved character and is not allowed in node names.`\n );\n }\n }\n this.warnIfCompiled(\n `Adding a node to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (key in this.nodes) {\n throw new Error(`Node \\`${key}\\` already present.`);\n }\n if (key === END) {\n throw new Error(`Node \\`${key}\\` is reserved.`);\n }\n\n const runnable = _coerceToRunnable<RunInput, RunOutput>(\n // Account for arbitrary state due to Send API\n action as RunnableLike<RunInput, RunOutput>\n );\n\n this.nodes[key as unknown as N] = {\n runnable,\n metadata: options?.metadata,\n subgraphs: isPregelLike(runnable) ? [runnable] : options?.subgraphs,\n ends: options?.ends,\n } as NodeSpecType;\n }\n\n return this as Graph<N | K, RunInput, RunOutput, NodeSpecType>;\n }\n\n addEdge(startKey: N | typeof START, endKey: N | typeof END): this {\n this.warnIfCompiled(\n `Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.`\n );\n\n if (startKey === END) {\n throw new Error(\"END cannot be a start node\");\n }\n if (endKey === START) {\n throw new Error(\"START cannot be an end node\");\n }\n if (\n Array.from(this.edges).some(([start]) => start === startKey) &&\n !(\"channels\" in this)\n ) {\n throw new Error(\n `Already found path for ${startKey}. For multiple edges, use StateGraph.`\n );\n }\n\n this.edges.add([startKey, endKey]);\n\n return this;\n }\n\n addConditionalEdges(\n source: BranchOptions<RunInput, N, LangGraphRunnableConfig<StateType<C>>>\n ): this;\n\n addConditionalEdges(\n source: N,\n path: RunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >,\n pathMap?: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >[\"pathMap\"]\n ): this;\n\n addConditionalEdges(\n source:\n | N\n | BranchOptions<RunInput, N, LangGraphRunnableConfig<StateType<C>>>,\n path?: RunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >,\n pathMap?: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n >[\"pathMap\"]\n ): this {\n const options: BranchOptions<\n RunInput,\n N,\n LangGraphRunnableConfig<StateType<C>>\n > = typeof source === \"object\" ? source : { source, path: path!, pathMap };\n\n this.warnIfCompiled(\n \"Adding an edge to a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n if (!Runnable.isRunnable(options.path)) {\n const pathDisplayValues = Array.isArray(options.pathMap)\n ? options.pathMap.join(\",\")\n : Object.keys(options.pathMap ?? {}).join(\",\");\n options.path = _coerceToRunnable(\n options.path as LangChainRunnableLike<\n RunInput,\n BranchPathReturnValue,\n LangGraphRunnableConfig<StateType<C>>\n >\n ).withConfig({\n runName: `Branch<${options.source}${\n pathDisplayValues !== \"\" ? `,${pathDisplayValues}` : \"\"\n }>`.slice(0, 63),\n });\n }\n // find a name for condition\n const name =\n options.path.getName() === \"RunnableLambda\"\n ? \"condition\"\n : options.path.getName();\n // validate condition\n if (this.branches[options.source] && this.branches[options.source][name]) {\n throw new Error(\n `Condition \\`${name}\\` already present for node \\`${source}\\``\n );\n }\n // save it\n this.branches[options.source] ??= {};\n this.branches[options.source][name] = new Branch(options);\n return this;\n }\n\n /**\n * @deprecated use `addEdge(START, key)` instead\n */\n setEntryPoint(key: N): this {\n this.warnIfCompiled(\n \"Setting the entry point of a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n\n return this.addEdge(START, key);\n }\n\n /**\n * @deprecated use `addEdge(key, END)` instead\n */\n setFinishPoint(key: N): this {\n this.warnIfCompiled(\n \"Setting a finish point of a graph that has already been compiled. This will not be reflected in the compiled graph.\"\n );\n\n return this.addEdge(key, END);\n }\n\n compile({\n checkpointer,\n interruptBefore,\n interruptAfter,\n name,\n }: {\n checkpointer?: BaseCheckpointSaver | false;\n interruptBefore?: N[] | All;\n interruptAfter?: N[] | All;\n name?: string;\n } = {}): CompiledGraph<N> {\n // validate the graph\n this.validate([\n ...(Array.isArray(interruptBefore) ? interruptBefore : []),\n ...(Array.isArray(interruptAfter) ? interruptAfter : []),\n ]);\n\n // create empty compiled graph\n const compiled = new CompiledGraph({\n builder: this,\n checkpointer,\n interruptAfter,\n interruptBefore,\n autoValidate: false,\n nodes: {} as Record<N | typeof START, PregelNode<RunInput, RunOutput>>,\n channels: {\n [START]: new EphemeralValue(),\n [END]: new EphemeralValue(),\n } as Record<N | typeof START | typeof END | string, BaseChannel>,\n inputChannels: START,\n outputChannels: END,\n streamChannels: [] as N[],\n streamMode: \"values\",\n name,\n });\n\n // attach nodes, edges and branches\n for (const [key, node] of Object.entries<NodeSpec<RunInput, RunOutput>>(\n this.nodes\n )) {\n compiled.attachNode(key as N, node);\n }\n for (const [start, end] of this.edges) {\n compiled.attachEdge(start, end);\n }\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const [name, branch] of Object.entries(branches)) {\n compiled.attachBranch(start as N, name, branch);\n }\n }\n\n return compiled.validate();\n }\n\n validate(interrupt?: string[]): void {\n // assemble sources\n const allSources = new Set([...this.allEdges].map(([src, _]) => src));\n for (const [start] of Object.entries(this.branches)) {\n allSources.add(start);\n }\n\n // validate sources\n for (const source of allSources) {\n if (source !== START && !(source in this.nodes)) {\n throw new Error(`Found edge starting at unknown node \\`${source}\\``);\n }\n }\n\n // assemble targets\n const allTargets = new Set([...this.allEdges].map(([_, target]) => target));\n for (const [start, branches] of Object.entries(this.branches)) {\n for (const branch of Object.values(branches)) {\n if (branch.ends != null) {\n for (const end of Object.values(branch.ends)) {\n allTargets.add(end);\n }\n } else {\n allTargets.add(END);\n for (const node of Object.keys(this.nodes)) {\n if (node !== start) {\n allTargets.add(node);\n }\n }\n }\n }\n }\n for (const node of Object.values<NodeSpecType>(this.nodes)) {\n for (const target of node.ends ?? []) {\n allTargets.add(target);\n }\n }\n // validate targets\n for (const node of Object.keys(this.nodes)) {\n if (!allTargets.has(node)) {\n throw new UnreachableNodeError(\n [\n `Node \\`${node}\\` is not reachable.`,\n \"\",\n \"If you are returning Command objects from your node,\",\n 'make sure you are passing names of potential destination nodes as an \"ends\" array',\n 'into \".addNode(..., { ends: [\"node1\", \"node2\"] })\".',\n ].join(\"\\n\"),\n {\n lc_error_code: \"UNREACHABLE_NODE\",\n }\n );\n }\n }\n for (const target of allTargets) {\n if (target !== END && !(target in this.nodes)) {\n throw new Error(`Found edge ending at unknown node \\`${target}\\``);\n }\n }\n\n // validate interrupts\n if (interrupt) {\n for (const node of interrupt) {\n if (!(node in this.nodes)) {\n throw new Error(`Interrupt node \\`${node}\\` is not present`);\n }\n }\n }\n\n this.compiled = true;\n }\n}\n\nexport class CompiledGraph<\n N extends string,\n State = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n Update = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n ContextType extends Record<string, any> = Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any\n InputType = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n OutputType = any, // eslint-disable-line @typescript-eslint/no-explicit-any\n NodeReturnType = unknown,\n CommandType = unknown,\n StreamCustomType = any // eslint-disable-line @typescript-eslint/no-explicit-any\n> extends Pregel<\n Record<N | typeof START, PregelNode<State, Update>>,\n Record<N | typeof START | typeof END | string, BaseChannel>,\n ContextType & Record<string, any>, // eslint-disable-line @typescript-eslint/no-explicit-any\n InputType,\n OutputType,\n InputType,\n OutputType,\n NodeReturnType,\n CommandType,\n StreamCustomType\n> {\n declare \"~NodeType\": N;\n\n declare \"~NodeReturnType\": NodeReturnType;\n\n declare \"~RunInput\": Update;\n\n declare \"~RunOutput\": State;\n\n builder: Graph<N, State, Update>;\n\n constructor({\n builder,\n ...rest\n }: { builder: Graph<N, State, Update> } & PregelParams<\n Record<N | typeof START, PregelNode<State, Update>>,\n Record<N | typeof START | typeof END | string, BaseChannel>\n >) {\n super(rest);\n this.builder = builder;\n }\n\n attachNode(key: N, node: NodeSpec<State, Update>): void {\n this.channels[key] = new EphemeralValue();\n this.nodes[key] = new PregelNode({\n channels: [],\n triggers: [],\n metadata: node.metadata,\n subgraphs: node.subgraphs,\n ends: node.ends,\n })\n .pipe(node.runnable)\n .pipe(\n new ChannelWrite([{ channel: key, value: PASSTHROUGH }], [TAG_HIDDEN])\n );\n (this.streamChannels as N[]).push(key);\n }\n\n attachEdge(start: N | typeof START, end: N | typeof END): void {\n if (end === END) {\n if (start === START) {\n throw new Error(\"Cannot have an edge from START to END\");\n }\n this.nodes[start].writers.push(\n new ChannelWrite([{ channel: END, value: PASSTHROUGH }], [TAG_HIDDEN])\n );\n } else {\n this.nodes[end].triggers.push(start);\n (this.nodes[end].channels as string[]).push(start);\n }\n }\n\n attachBranch(\n start: N | typeof START,\n name: string,\n branch: Branch<State, N>\n ) {\n // add hidden start node\n if (start === START && !this.nodes[START]) {\n this.nodes[START] = Channel.subscribeTo(START, { tags: [TAG_HIDDEN] });\n }\n\n // attach branch writer\n this.nodes[start].pipe(\n branch.run((dests) => {\n const writes = dests.map((dest) => {\n if (_isSend(dest)) {\n return dest;\n }\n return {\n channel: dest === END ? END : `branch:${start}:${name}:${dest}`,\n value: PASSTHROUGH,\n };\n });\n return new ChannelWrite(writes, [TAG_HIDDEN]);\n })\n );\n\n // attach branch readers\n const ends = branch.ends\n ? Object.values(branch.ends)\n : (Object.keys(this.nodes) as N[]);\n for (const end of ends) {\n if (end !== END) {\n const channelName = `branch:${start}:${name}:${end}`;\n (this.channels as Record<string, BaseChannel>)[channelName] =\n new EphemeralValue();\n this.nodes[end].triggers.push(channelName);\n (this.nodes[end].channels as string[]).push(channelName);\n }\n }\n }\n\n /**\n * Returns a drawable representation of the computation graph.\n */\n override async getGraphAsync(\n config?: RunnableConfig & { xray?: boolean | number }\n ): Promise<DrawableGraph> {\n const xray = config?.xray;\n const graph = new DrawableGraph();\n const startNodes: Record<string, DrawableGraphNode> = {\n [START]: graph.addNode({ schema: z.any() }, START),\n };\n const endNodes: Record<string, DrawableGraphNode> = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let subgraphs: Record<string, CompiledGraph<any>> = {};\n if (xray) {\n subgraphs = Object.fromEntries(\n (await gatherIterator(this.getSubgraphsAsync())).filter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x): x is [string, CompiledGraph<any>] => isCompiledGraph(x[1])\n )\n );\n }\n\n function addEdge(\n start: string,\n end: string,\n label?: string,\n conditional = false\n ) {\n if (end === END && endNodes[END] === undefined) {\n endNodes[END] = graph.addNode({ schema: z.any() }, END);\n }\n if (startNodes[start] === undefined) {\n return;\n }\n if (endNodes[end] === undefined) {\n throw new Error(`End node ${end} not found!`);\n }\n return graph.addEdge(\n startNodes[start],\n endNodes[end],\n label !== end ? label : undefined,\n conditional\n );\n }\n\n for (const [key, nodeSpec] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>\n ][]) {\n const displayKey = _escapeMermaidKeywords(key);\n const node = nodeSpec.runnable;\n const metadata = nodeSpec.metadata ?? {};\n if (\n this.interruptBefore?.includes(key) &&\n this.interruptAfter?.includes(key)\n ) {\n metadata.__interrupt = \"before,after\";\n } else if (this.interruptBefore?.includes(key)) {\n metadata.__interrupt = \"before\";\n } else if (this.interruptAfter?.includes(key)) {\n metadata.__interrupt = \"after\";\n }\n if (xray) {\n const newXrayValue = typeof xray === \"number\" ? xray - 1 : xray;\n const drawableSubgraph =\n subgraphs[key] !== undefined\n ? await subgraphs[key].getGraphAsync({\n ...config,\n xray: newXrayValue,\n })\n : node.getGraph(config);\n\n drawableSubgraph.trimFirstNode();\n drawableSubgraph.trimLastNode();\n\n if (Object.keys(drawableSubgraph.nodes).length > 1) {\n const [e, s] = graph.extend(drawableSubgraph, displayKey);\n if (e === undefined) {\n throw new Error(\n `Could not extend subgraph \"${key}\" due to missing entrypoint.`\n );\n }\n\n // TODO: Remove default name once we stop supporting core 0.2.0\n // eslint-disable-next-line no-inner-declarations\n function _isRunnableInterface(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thing: any\n ): thing is RunnableInterface {\n return thing ? thing.lc_runnable : false;\n }\n // eslint-disable-next-line no-inner-declarations\n function _nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n ): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (_isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch (error) {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n }\n // TODO: Remove casts when we stop supporting core 0.2.0\n if (s !== undefined) {\n startNodes[displayKey] = {\n name: _nodeDataStr(s.id, s.data),\n ...s,\n } as DrawableGraphNode;\n }\n endNodes[displayKey] = {\n name: _nodeDataStr(e.id, e.data),\n ...e,\n } as DrawableGraphNode;\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n }\n const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (b > a) {\n return 1;\n } else {\n return 0;\n }\n });\n for (const [start, end] of sortedEdges) {\n addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));\n }\n for (const [start, branches] of Object.entries(this.builder.branches)) {\n const defaultEnds: Record<string, string> = {\n ...Object.fromEntries(\n Object.keys(this.builder.nodes)\n .filter((k) => k !== start)\n .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])\n ),\n [END]: END,\n };\n for (const branch of Object.values(branches)) {\n let ends;\n if (branch.ends !== undefined) {\n ends = branch.ends;\n } else {\n ends = defaultEnds;\n }\n for (const [label, end] of Object.entries(ends)) {\n addEdge(\n _escapeMermaidKeywords(start),\n _escapeMermaidKeywords(end),\n label,\n true\n );\n }\n }\n }\n for (const [key, node] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>\n ][]) {\n if (node.ends !== undefined) {\n for (const end of node.ends) {\n addEdge(\n _escapeMermaidKeywords(key),\n _escapeMermaidKeywords(end),\n undefined,\n true\n );\n }\n }\n }\n return graph;\n }\n\n /**\n * Returns a drawable representation of the computation graph.\n *\n * @deprecated Use getGraphAsync instead. The async method will be the default in the next minor core release.\n */\n override getGraph(\n config?: RunnableConfig & { xray?: boolean | number }\n ): DrawableGraph {\n const xray = config?.xray;\n const graph = new DrawableGraph();\n const startNodes: Record<string, DrawableGraphNode> = {\n [START]: graph.addNode(\n {\n schema: z.any(),\n },\n START\n ),\n };\n const endNodes: Record<string, DrawableGraphNode> = {};\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n let subgraphs: Record<string, CompiledGraph<any>> = {};\n if (xray) {\n subgraphs = Object.fromEntries(\n gatherIteratorSync(this.getSubgraphs()).filter(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (x): x is [string, CompiledGraph<any>] => isCompiledGraph(x[1])\n )\n );\n }\n\n function addEdge(\n start: string,\n end: string,\n label?: string,\n conditional = false\n ) {\n if (end === END && endNodes[END] === undefined) {\n endNodes[END] = graph.addNode({ schema: z.any() }, END);\n }\n return graph.addEdge(\n startNodes[start],\n endNodes[end],\n label !== end ? label : undefined,\n conditional\n );\n }\n\n for (const [key, nodeSpec] of Object.entries(this.builder.nodes) as [\n N,\n NodeSpec<State, Update>\n ][]) {\n const displayKey = _escapeMermaidKeywords(key);\n const node = nodeSpec.runnable;\n const metadata = nodeSpec.metadata ?? {};\n if (\n this.interruptBefore?.includes(key) &&\n this.interruptAfter?.includes(key)\n ) {\n metadata.__interrupt = \"before,after\";\n } else if (this.interruptBefore?.includes(key)) {\n metadata.__interrupt = \"before\";\n } else if (this.interruptAfter?.includes(key)) {\n metadata.__interrupt = \"after\";\n }\n if (xray) {\n const newXrayValue = typeof xray === \"number\" ? xray - 1 : xray;\n const drawableSubgraph =\n subgraphs[key] !== undefined\n ? subgraphs[key].getGraph({\n ...config,\n xray: newXrayValue,\n })\n : node.getGraph(config);\n drawableSubgraph.trimFirstNode();\n drawableSubgraph.trimLastNode();\n if (Object.keys(drawableSubgraph.nodes).length > 1) {\n const [e, s] = graph.extend(drawableSubgraph, displayKey);\n if (e === undefined) {\n throw new Error(\n `Could not extend subgraph \"${key}\" due to missing entrypoint.`\n );\n }\n\n // TODO: Remove default name once we stop supporting core 0.2.0\n // eslint-disable-next-line no-inner-declarations\n function _isRunnableInterface(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thing: any\n ): thing is RunnableInterface {\n return thing ? thing.lc_runnable : false;\n }\n // eslint-disable-next-line no-inner-declarations\n function _nodeDataStr(\n id: string | undefined,\n data: RunnableInterface | RunnableIOSchema\n ): string {\n if (id !== undefined && !isUuid(id)) {\n return id;\n } else if (_isRunnableInterface(data)) {\n try {\n let dataStr = data.getName();\n dataStr = dataStr.startsWith(\"Runnable\")\n ? dataStr.slice(\"Runnable\".length)\n : dataStr;\n return dataStr;\n } catch (error) {\n return data.getName();\n }\n } else {\n return data.name ?? \"UnknownSchema\";\n }\n }\n // TODO: Remove casts when we stop supporting core 0.2.0\n if (s !== undefined) {\n startNodes[displayKey] = {\n name: _nodeDataStr(s.id, s.data),\n ...s,\n } as DrawableGraphNode;\n }\n endNodes[displayKey] = {\n name: _nodeDataStr(e.id, e.data),\n ...e,\n } as DrawableGraphNode;\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n } else {\n // TODO: Remove when we stop supporting core 0.2.0\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n const newNode = graph.addNode(node, displayKey, metadata);\n startNodes[displayKey] = newNode;\n endNodes[displayKey] = newNode;\n }\n }\n const sortedEdges = [...this.builder.allEdges].sort(([a], [b]) => {\n if (a < b) {\n return -1;\n } else if (b > a) {\n return 1;\n } else {\n return 0;\n }\n });\n for (const [start, end] of sortedEdges) {\n addEdge(_escapeMermaidKeywords(start), _escapeMermaidKeywords(end));\n }\n for (const [start, branches] of Object.entries(this.builder.branches)) {\n const defaultEnds: Record<string, string> = {\n ...Object.fromEntries(\n Object.keys(this.builder.nodes)\n .filter((k) => k !== start)\n .map((k) => [_escapeMermaidKeywords(k), _escapeMermaidKeywords(k)])\n ),\n [END]: END,\n };\n for (const branch of Object.values(branches)) {\n let ends;\n if (branch.ends !== undefined) {\n ends = branch.ends;\n } else {\n ends = defaultEnds;\n }\n for (const [label, end] of Object.entries(ends)) {\n addEdge(\n _escapeMermaidKeywords(start),\n _escapeMermaidKeywords(end),\n label,\n true\n );\n }\n }\n }\n return graph;\n }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction isCompiledGraph(x: unknown): x is CompiledGraph<any> {\n return (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (x as CompiledGraph<any>).attachNode === \"function\" &&\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n typeof (x as CompiledGraph<any>).attachEdge === \"function\"\n );\n}\n\nfunction _escapeMermaidKeywords(key: string) {\n if (key === \"subgraph\") {\n return `\"${key}\"`;\n }\n return key;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAsEA,IAAa,SAAb,MAIE;CACA;CAEA;CAEA,YAAY,SAA4D;AACtE,MAAIA,oCAAS,WAAW,QAAQ,MAC9B,MAAK,OAAO,QAAQ;MAMpB,MAAK,yDACH,QAAQ,MAKR,WAAW,EAAE,SAAS;AAE1B,OAAK,OAAO,MAAM,QAAQ,QAAQ,WAC9B,QAAQ,QAAQ,QAAQ,KAAK,MAAM;AACjC,OAAI,KAAK;AACT,UAAO;KACN,MACH,QAAQ;;CAGd,IACE,QAIA,QACA;AACA,SAAOC,2BAAa,eAClB,IAAIC,+BAAiB;GACnB,MAAM;GACN,OAAO;GACP,MAAM,OAAO,OAAW,WAAwB;AAC9C,QAAI;AACF,YAAO,MAAM,KAAK,OAAO,OAAO,QAAQ,QAAQ;aAEzCC,GAAQ;AAEf,SAAI,EAAE,SAASC,6BAAc,kBAC3B,SAAQ,KACN;AAIJ,WAAM;;;;;CAOhB,MAAM,OACJ,OACA,QACA,QAIA,QAEyB;EACzB,IAAI,SAAS,MAAM,KAAK,KAAK,OAC3B,SAAS,OAAO,UAAU,OAC1B;AAEF,MAAI,CAAC,MAAM,QAAQ,QACjB,UAAS,CAAC;EAGZ,IAAIC;AACJ,MAAI,KAAK,KACP,gBAAe,OAAO,KAAK,MAAOC,0BAAQ,KAAK,IAAI,KAAK,KAAM;MAE9D,gBAAe;AAEjB,MAAI,aAAa,MAAM,SAAS,CAAC,MAC/B,OAAM,IAAI,MAAM;AAElB,MAAI,aAAa,OAAOA,2BAAS,MAAM,WAAW,OAAO,SAASC,uBAChE,OAAM,IAAIC,kCAAmB;EAE/B,MAAM,cAAc,MAAM,OAAO,cAAc;AAC/C,SAAO,eAAe;;;AAqB1B,IAAa,QAAb,MAWE;CACA;CAEA;CAGA;C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