@langchain/langgraph 1.0.0-alpha.0 → 1.0.0-alpha.1
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 +31 -0
- package/dist/channels/any_value.cjs +46 -0
- package/dist/channels/any_value.cjs.map +1 -0
- package/dist/channels/any_value.d.cts +0 -2
- package/dist/channels/any_value.d.cts.map +1 -1
- package/dist/channels/any_value.d.ts +0 -2
- package/dist/channels/any_value.d.ts.map +1 -1
- package/dist/channels/any_value.js +46 -0
- package/dist/channels/any_value.js.map +1 -0
- package/dist/channels/base.cjs +3 -7
- package/dist/channels/base.cjs.map +1 -1
- package/dist/channels/base.d.cts +8 -2
- package/dist/channels/base.d.cts.map +1 -1
- package/dist/channels/base.d.ts +7 -2
- package/dist/channels/base.d.ts.map +1 -1
- package/dist/channels/base.js +3 -7
- package/dist/channels/base.js.map +1 -1
- package/dist/channels/dynamic_barrier_value.cjs +76 -0
- package/dist/channels/dynamic_barrier_value.cjs.map +1 -0
- package/dist/channels/dynamic_barrier_value.d.cts +0 -1
- package/dist/channels/dynamic_barrier_value.d.cts.map +1 -1
- package/dist/channels/dynamic_barrier_value.d.ts +0 -1
- package/dist/channels/dynamic_barrier_value.d.ts.map +1 -1
- package/dist/channels/dynamic_barrier_value.js +76 -0
- package/dist/channels/dynamic_barrier_value.js.map +1 -0
- package/dist/channels/ephemeral_value.cjs +0 -2
- package/dist/channels/ephemeral_value.cjs.map +1 -1
- package/dist/channels/ephemeral_value.d.cts +0 -1
- package/dist/channels/ephemeral_value.d.cts.map +1 -1
- package/dist/channels/ephemeral_value.d.ts +0 -1
- package/dist/channels/ephemeral_value.d.ts.map +1 -1
- package/dist/channels/ephemeral_value.js +0 -2
- package/dist/channels/ephemeral_value.js.map +1 -1
- package/dist/channels/index.cjs +19 -0
- package/dist/channels/index.d.cts +9 -0
- package/dist/channels/index.d.ts +9 -0
- package/dist/channels/index.js +7 -1
- package/dist/channels/last_value.cjs +0 -1
- package/dist/channels/last_value.cjs.map +1 -1
- package/dist/channels/last_value.d.cts +14 -2
- package/dist/channels/last_value.d.cts.map +1 -1
- package/dist/channels/last_value.d.ts +14 -2
- package/dist/channels/last_value.d.ts.map +1 -1
- package/dist/channels/last_value.js +0 -1
- package/dist/channels/last_value.js.map +1 -1
- package/dist/channels/named_barrier_value.cjs +1 -1
- package/dist/channels/named_barrier_value.cjs.map +1 -1
- package/dist/channels/named_barrier_value.d.cts +15 -2
- package/dist/channels/named_barrier_value.d.cts.map +1 -1
- package/dist/channels/named_barrier_value.d.ts +15 -2
- package/dist/channels/named_barrier_value.d.ts.map +1 -1
- package/dist/channels/named_barrier_value.js +1 -2
- package/dist/channels/named_barrier_value.js.map +1 -1
- package/dist/channels/topic.cjs +1 -1
- package/dist/channels/topic.cjs.map +1 -1
- package/dist/channels/topic.d.cts +7 -1
- package/dist/channels/topic.d.cts.map +1 -1
- package/dist/channels/topic.d.ts +7 -1
- package/dist/channels/topic.d.ts.map +1 -1
- package/dist/channels/topic.js +1 -1
- package/dist/channels/topic.js.map +1 -1
- package/dist/constants.cjs +4 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +5 -4
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.ts +5 -4
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +4 -1
- package/dist/constants.js.map +1 -1
- package/dist/errors.cjs +2 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.cts +2 -1
- package/dist/errors.d.cts.map +1 -1
- package/dist/errors.d.ts +2 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +2 -1
- package/dist/errors.js.map +1 -1
- package/dist/func/index.cjs +3 -0
- package/dist/func/index.cjs.map +1 -1
- package/dist/func/index.d.cts +5 -1
- package/dist/func/index.d.cts.map +1 -1
- package/dist/func/index.d.ts +5 -1
- package/dist/func/index.d.ts.map +1 -1
- package/dist/func/index.js +3 -0
- package/dist/func/index.js.map +1 -1
- package/dist/graph/annotation.d.cts +1 -1
- package/dist/graph/annotation.d.ts +1 -1
- package/dist/graph/graph.cjs +5 -5
- package/dist/graph/graph.cjs.map +1 -1
- package/dist/graph/graph.d.cts +4 -2
- package/dist/graph/graph.d.cts.map +1 -1
- package/dist/graph/graph.d.ts +4 -2
- package/dist/graph/graph.d.ts.map +1 -1
- package/dist/graph/graph.js +1 -1
- package/dist/graph/graph.js.map +1 -1
- package/dist/graph/index.js +1 -1
- package/dist/graph/messages_annotation.d.cts +1 -1
- package/dist/graph/messages_annotation.d.cts.map +1 -1
- package/dist/graph/messages_annotation.d.ts +1 -1
- package/dist/graph/state.cjs +15 -18
- package/dist/graph/state.cjs.map +1 -1
- package/dist/graph/state.d.cts +40 -25
- package/dist/graph/state.d.cts.map +1 -1
- package/dist/graph/state.d.ts +39 -24
- package/dist/graph/state.d.ts.map +1 -1
- package/dist/graph/state.js +17 -19
- package/dist/graph/state.js.map +1 -1
- package/dist/graph/zod/plugin.cjs +1 -1
- package/dist/graph/zod/plugin.js +3 -3
- package/dist/graph/zod/plugin.js.map +1 -1
- package/dist/graph/zod/zod-registry.d.cts.map +1 -1
- package/dist/graph/zod/zod-registry.d.ts.map +1 -1
- package/dist/index.cjs +3 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/interrupt.cjs +1 -1
- package/dist/interrupt.cjs.map +1 -1
- package/dist/interrupt.js +1 -1
- package/dist/interrupt.js.map +1 -1
- package/dist/prebuilt/agent_executor.d.cts +1 -1
- package/dist/prebuilt/agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/agent_executor.d.ts +1 -1
- package/dist/prebuilt/agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.cjs +1 -1
- package/dist/prebuilt/react_agent_executor.cjs.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.cts +5 -5
- package/dist/prebuilt/react_agent_executor.d.cts.map +1 -1
- package/dist/prebuilt/react_agent_executor.d.ts +4 -4
- package/dist/prebuilt/react_agent_executor.d.ts.map +1 -1
- package/dist/prebuilt/react_agent_executor.js +1 -1
- package/dist/prebuilt/react_agent_executor.js.map +1 -1
- package/dist/pregel/algo.cjs +36 -6
- package/dist/pregel/algo.cjs.map +1 -1
- package/dist/pregel/algo.d.cts +1 -1
- package/dist/pregel/algo.d.cts.map +1 -1
- package/dist/pregel/algo.d.ts +1 -1
- package/dist/pregel/algo.d.ts.map +1 -1
- package/dist/pregel/algo.js +37 -7
- package/dist/pregel/algo.js.map +1 -1
- package/dist/pregel/index.cjs +8 -4
- package/dist/pregel/index.cjs.map +1 -1
- package/dist/pregel/index.d.cts +8 -6
- package/dist/pregel/index.d.cts.map +1 -1
- package/dist/pregel/index.d.ts +8 -6
- package/dist/pregel/index.d.ts.map +1 -1
- package/dist/pregel/index.js +8 -4
- package/dist/pregel/index.js.map +1 -1
- package/dist/pregel/loop.cjs +7 -4
- package/dist/pregel/loop.cjs.map +1 -1
- package/dist/pregel/loop.js +7 -4
- package/dist/pregel/loop.js.map +1 -1
- package/dist/pregel/remote.d.cts +2 -2
- package/dist/pregel/remote.d.cts.map +1 -1
- package/dist/pregel/remote.d.ts +2 -2
- package/dist/pregel/remote.d.ts.map +1 -1
- package/dist/pregel/runnable_types.d.cts +34 -10
- package/dist/pregel/runnable_types.d.cts.map +1 -1
- package/dist/pregel/runnable_types.d.ts +34 -10
- package/dist/pregel/runnable_types.d.ts.map +1 -1
- package/dist/pregel/stream.cjs +3 -3
- package/dist/pregel/stream.cjs.map +1 -1
- package/dist/pregel/stream.js +3 -3
- package/dist/pregel/stream.js.map +1 -1
- package/dist/pregel/types.cjs.map +1 -1
- package/dist/pregel/types.d.cts +10 -7
- package/dist/pregel/types.d.cts.map +1 -1
- package/dist/pregel/types.d.ts +10 -7
- package/dist/pregel/types.d.ts.map +1 -1
- package/dist/pregel/types.js.map +1 -1
- package/dist/pregel/utils/config.cjs +1 -0
- package/dist/pregel/utils/config.cjs.map +1 -1
- package/dist/pregel/utils/config.js +1 -0
- package/dist/pregel/utils/config.js.map +1 -1
- package/dist/ui/stream.cjs.map +1 -1
- package/dist/ui/stream.js.map +1 -1
- package/dist/web.cjs +4 -5
- package/dist/web.d.cts +8 -8
- package/dist/web.d.ts +8 -8
- package/dist/web.js +3 -3
- package/dist/writer.cjs +15 -0
- package/dist/writer.cjs.map +1 -0
- package/dist/writer.d.cts +5 -0
- package/dist/writer.d.cts.map +1 -0
- package/dist/writer.d.ts +5 -0
- package/dist/writer.d.ts.map +1 -0
- package/dist/writer.js +14 -0
- package/dist/writer.js.map +1 -0
- package/package.json +18 -8
package/dist/errors.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
|
|
2
2
|
//#region src/errors.ts
|
|
3
|
+
/** @category Errors */
|
|
3
4
|
var BaseLangGraphError = class extends Error {
|
|
4
5
|
lc_error_code;
|
|
5
6
|
constructor(message, fields) {
|
|
6
7
|
let finalMessage = message ?? "";
|
|
7
|
-
if (fields?.lc_error_code) finalMessage = `${finalMessage}\n\nTroubleshooting URL: https://langchain
|
|
8
|
+
if (fields?.lc_error_code) finalMessage = `${finalMessage}\n\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${fields.lc_error_code}/\n`;
|
|
8
9
|
super(finalMessage);
|
|
9
10
|
this.lc_error_code = fields?.lc_error_code;
|
|
10
11
|
}
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?:\n | \"GRAPH_RECURSION_LIMIT\"\n | \"INVALID_CONCURRENT_GRAPH_UPDATE\"\n | \"INVALID_GRAPH_NODE_RETURN_VALUE\"\n | \"MULTIPLE_SUBGRAPHS\"\n | \"UNREACHABLE_NODE\";\n};\n\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\nexport class BaseLangGraphError extends Error {\n lc_error_code?: string;\n\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n let finalMessage = message ?? \"\";\n if (fields?.lc_error_code) {\n finalMessage = `${finalMessage}\\n\\nTroubleshooting URL: https://langchain
|
|
1
|
+
{"version":3,"file":"errors.cjs","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?:\n | \"GRAPH_RECURSION_LIMIT\"\n | \"INVALID_CONCURRENT_GRAPH_UPDATE\"\n | \"INVALID_GRAPH_NODE_RETURN_VALUE\"\n | \"MISSING_CHECKPOINTER\"\n | \"MULTIPLE_SUBGRAPHS\"\n | \"UNREACHABLE_NODE\";\n};\n\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\n/** @category Errors */\nexport class BaseLangGraphError extends Error {\n lc_error_code?: string;\n\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n let finalMessage = message ?? \"\";\n if (fields?.lc_error_code) {\n finalMessage = `${finalMessage}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${fields.lc_error_code}/\\n`;\n }\n super(finalMessage);\n this.lc_error_code = fields?.lc_error_code;\n }\n}\n\nexport class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up() {\n return true;\n }\n}\n\nexport class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphRecursionError\";\n }\n\n static get unminifiable_name() {\n return \"GraphRecursionError\";\n }\n}\n\nexport class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphValueError\";\n }\n\n static get unminifiable_name() {\n return \"GraphValueError\";\n }\n}\n\nexport class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields) {\n super(JSON.stringify(interrupts, null, 2), fields);\n this.name = \"GraphInterrupt\";\n this.interrupts = interrupts ?? [];\n }\n\n static get unminifiable_name() {\n return \"GraphInterrupt\";\n }\n}\n\n/** Raised by a node to interrupt execution. */\nexport class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields) {\n super([{ value: message }], fields);\n this.name = \"NodeInterrupt\";\n }\n\n static get unminifiable_name() {\n return \"NodeInterrupt\";\n }\n}\n\nexport class ParentCommand extends GraphBubbleUp {\n command: Command;\n\n constructor(command: Command) {\n super();\n this.name = \"ParentCommand\";\n this.command = command;\n }\n\n static get unminifiable_name() {\n return \"ParentCommand\";\n }\n}\n\nexport function isParentCommand(e?: unknown): e is ParentCommand {\n return (\n e !== undefined &&\n (e as ParentCommand).name === ParentCommand.unminifiable_name\n );\n}\n\nexport function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp {\n return e !== undefined && (e as GraphBubbleUp).is_bubble_up === true;\n}\n\nexport function isGraphInterrupt(e?: unknown): e is GraphInterrupt {\n return (\n e !== undefined &&\n [\n GraphInterrupt.unminifiable_name,\n NodeInterrupt.unminifiable_name,\n ].includes((e as Error).name)\n );\n}\n\nexport class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"EmptyInputError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyInputError\";\n }\n}\n\nexport class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"EmptyChannelError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyChannelError\";\n }\n}\n\nexport class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"InvalidUpdateError\";\n }\n\n static get unminifiable_name() {\n return \"InvalidUpdateError\";\n }\n}\n\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"MultipleSubgraphError\";\n }\n\n static get unminifiable_name() {\n return \"MultipleSubgraphError\";\n }\n}\n\nexport class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"UnreachableNodeError\";\n }\n\n static get unminifiable_name() {\n return \"UnreachableNodeError\";\n }\n}\n\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"RemoteException\";\n }\n\n static get unminifiable_name() {\n return \"RemoteException\";\n }\n}\n\n/**\n * Used for subgraph detection.\n */\nexport const getSubgraphsSeenSet = () => {\n if (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] === undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] = new Set();\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")];\n};\n"],"mappings":";;;AAgBA,IAAa,qBAAb,cAAwC,MAAM;CAC5C;CAEA,YAAY,SAAkB,QAAmC;EAC/D,IAAI,eAAe,WAAW;AAC9B,MAAI,QAAQ,cACV,gBAAe,GAAG,aAAa,+EAA+E,OAAO,cAAc;AAErI,QAAM;AACN,OAAK,gBAAgB,QAAQ;;;AAIjC,IAAa,gBAAb,cAAmC,mBAAmB;CACpD,IAAI,eAAe;AACjB,SAAO;;;AAIX,IAAa,sBAAb,cAAyC,mBAAmB;CAC1D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,iBAAb,cAAoC,cAAc;CAChD;CAEA,YAAY,YAA0B,QAAmC;AACvE,QAAM,KAAK,UAAU,YAAY,MAAM,IAAI;AAC3C,OAAK,OAAO;AACZ,OAAK,aAAa,cAAc;;CAGlC,WAAW,oBAAoB;AAC7B,SAAO;;;;AAKX,IAAa,gBAAb,cAAmC,eAAe;CAEhD,YAAY,SAAc,QAAmC;AAC3D,QAAM,CAAC,EAAE,OAAO,YAAY;AAC5B,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,gBAAb,cAAmC,cAAc;CAC/C;CAEA,YAAY,SAAkB;AAC5B;AACA,OAAK,OAAO;AACZ,OAAK,UAAU;;CAGjB,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,SAAgB,gBAAgB,GAAiC;AAC/D,QACE,MAAM,UACL,EAAoB,SAAS,cAAc;;AAIhD,SAAgB,gBAAgB,GAAiC;AAC/D,QAAO,MAAM,UAAc,EAAoB,iBAAiB;;AAGlE,SAAgB,iBAAiB,GAAkC;AACjE,QACE,MAAM,UACN,CACE,eAAe,mBACf,cAAc,mBACd,SAAU,EAAY;;AAI5B,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,oBAAb,cAAuC,mBAAmB;CACxD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,qBAAb,cAAwC,mBAAmB;CACzD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,IAAa,yBAAb,cAA4C,mBAAmB;CAC7D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,uBAAb,cAA0C,mBAAmB;CAC3D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,MAAa,4BAA4B;AACvC,KAEG,WAAmB,OAAO,IAAI,kCAAkC,OAGjE,CAAC,WAAmB,OAAO,IAAI,gDAAgC,IAAI;AAGrE,QAAQ,WAAmB,OAAO,IAAI"}
|
package/dist/errors.d.cts
CHANGED
|
@@ -4,9 +4,10 @@ import { Command, Interrupt } from "./constants.cjs";
|
|
|
4
4
|
// When editing, make sure to update the index found here:
|
|
5
5
|
// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/
|
|
6
6
|
type BaseLangGraphErrorFields = {
|
|
7
|
-
lc_error_code?: "GRAPH_RECURSION_LIMIT" | "INVALID_CONCURRENT_GRAPH_UPDATE" | "INVALID_GRAPH_NODE_RETURN_VALUE" | "MULTIPLE_SUBGRAPHS" | "UNREACHABLE_NODE";
|
|
7
|
+
lc_error_code?: "GRAPH_RECURSION_LIMIT" | "INVALID_CONCURRENT_GRAPH_UPDATE" | "INVALID_GRAPH_NODE_RETURN_VALUE" | "MISSING_CHECKPOINTER" | "MULTIPLE_SUBGRAPHS" | "UNREACHABLE_NODE";
|
|
8
8
|
};
|
|
9
9
|
// TODO: Merge with base LangChain error class when we drop support for core@0.2.0
|
|
10
|
+
/** @category Errors */
|
|
10
11
|
declare class BaseLangGraphError extends Error {
|
|
11
12
|
lc_error_code?: string;
|
|
12
13
|
constructor(message?: string, fields?: BaseLangGraphErrorFields);
|
package/dist/errors.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.cts","names":["Command","Interrupt","BaseLangGraphErrorFields","BaseLangGraphError","Error","GraphBubbleUp","GraphRecursionError","GraphValueError","GraphInterrupt","NodeInterrupt","ParentCommand","isParentCommand","isGraphBubbleUp","isGraphInterrupt","EmptyInputError","EmptyChannelError","InvalidUpdateError","MultipleSubgraphsError","UnreachableNodeError","RemoteException","getSubgraphsSeenSet"],"sources":["../src/errors.d.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?: \"GRAPH_RECURSION_LIMIT\" | \"INVALID_CONCURRENT_GRAPH_UPDATE\" | \"INVALID_GRAPH_NODE_RETURN_VALUE\" | \"MULTIPLE_SUBGRAPHS\" | \"UNREACHABLE_NODE\";\n};\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\nexport declare class BaseLangGraphError extends Error {\n lc_error_code?: string;\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n}\nexport declare class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up(): boolean;\n}\nexport declare class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/** Raised by a node to interrupt execution. */\nexport declare class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class ParentCommand extends GraphBubbleUp {\n command: Command;\n constructor(command: Command);\n static get unminifiable_name(): string;\n}\nexport declare function isParentCommand(e?: unknown): e is ParentCommand;\nexport declare function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp;\nexport declare function isGraphInterrupt(e?: unknown): e is GraphInterrupt;\nexport declare class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport declare class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport declare class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Used for subgraph detection.\n */\nexport declare const getSubgraphsSeenSet: () => any;\n"],"mappings":";;;;;AAGYE,KAAAA,wBAAAA,GAAwB;
|
|
1
|
+
{"version":3,"file":"errors.d.cts","names":["Command","Interrupt","BaseLangGraphErrorFields","BaseLangGraphError","Error","GraphBubbleUp","GraphRecursionError","GraphValueError","GraphInterrupt","NodeInterrupt","ParentCommand","isParentCommand","isGraphBubbleUp","isGraphInterrupt","EmptyInputError","EmptyChannelError","InvalidUpdateError","MultipleSubgraphsError","UnreachableNodeError","RemoteException","getSubgraphsSeenSet"],"sources":["../src/errors.d.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?: \"GRAPH_RECURSION_LIMIT\" | \"INVALID_CONCURRENT_GRAPH_UPDATE\" | \"INVALID_GRAPH_NODE_RETURN_VALUE\" | \"MISSING_CHECKPOINTER\" | \"MULTIPLE_SUBGRAPHS\" | \"UNREACHABLE_NODE\";\n};\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\n/** @category Errors */\nexport declare class BaseLangGraphError extends Error {\n lc_error_code?: string;\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n}\nexport declare class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up(): boolean;\n}\nexport declare class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/** Raised by a node to interrupt execution. */\nexport declare class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class ParentCommand extends GraphBubbleUp {\n command: Command;\n constructor(command: Command);\n static get unminifiable_name(): string;\n}\nexport declare function isParentCommand(e?: unknown): e is ParentCommand;\nexport declare function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp;\nexport declare function isGraphInterrupt(e?: unknown): e is GraphInterrupt;\nexport declare class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport declare class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport declare class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Used for subgraph detection.\n */\nexport declare const getSubgraphsSeenSet: () => any;\n"],"mappings":";;;;;AAGYE,KAAAA,wBAAAA,GAAwB;EAKfC,aAAAA,CAAAA,EAAAA,uBAAkB,GAAA,iCAAA,GAAA,iCAAA,GAAA,sBAAA,GAAA,oBAAA,GAAA,kBAAA;CAAA;;;cAAlBA,kBAAAA,SAA2BC,KAAAA;EAI3BC,aAAAA,CAAAA,EAAa,MAAA;EAGbC,WAAAA,CAAAA,OAAmB,CAAnBA,EAAmB,MAAA,EAAA,MAAA,CAAA,EALGJ,wBAKH;;AACGA,cAJtBG,aAAAA,SAAsBF,kBAAAA,CAIAD;MADMC,YAAAA,CAAAA,CAAAA,EAAAA,OAAAA;;AAI5BI,cAJAD,mBAAAA,SAA4BH,kBAAAA,CAIb;EAAA,WAAA,CAAA,OAAA,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAHOD,wBAGP;aACOA,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;cADtBK,eAAAA,SAAwBJ,kBAAAA;EAIxBK,WAAAA,CAAAA,OAAc,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAHQN,wBAGR;EAAA,WAAA,iBAAA,CAAA,CAAA,EAAA,MAAA;;AAEND,cAFRO,cAAAA,SAAuBH,aAAAA,CAEfJ;YAAsBC,EADnCD,SACmCC,EAAAA;aAFPG,CAAAA,UAAAA,CAAAA,EAEfJ,SAFeI,EAAAA,EAAAA,MAAAA,CAAAA,EAEOH,wBAFPG;;AAM5C;;AAEuCH,cAFlBO,aAAAA,SAAsBD,cAAAA,CAEJN;;qCAAAA;EAGlBQ,WAAAA,iBAAa,CAAA,CAAA,EAAA,MAAA;;AACrBV,cADQU,aAAAA,SAAsBL,aAAAA,CAC9BL;SACYA,EADZA,OACYA;aAFkBK,CAAAA,OAAAA,EAElBL,OAFkBK;;AAK3C;AACwBO,iBADAD,eAAAA,CACmCN,CAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,CAAAA,IADAK,aACAL;AACnCQ,iBADAD,eAAAA,CACoCJ,CAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,CAAAA,IADDH,aACCG;AACvCM,iBADGD,gBAAAA,CACY,CAAA,CAAA,EAAA,OAAA,CAAA,EAAA,CAAA,IADwBL,cACxB;AAAA,cAAfM,eAAAA,SAAwBX,kBAAAA,CAAT;aACOD,CAAAA,OAAAA,CAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EAAAA,wBAAAA;aADEC,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;AAIxBY,cAAAA,iBAAAA,SAA0BZ,kBAAAA,CAAT;EAAA,WAAA,CAAA,OAAA,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EACKD,wBADL;aACKA,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;cAGtBc,kBAAAA,SAA2Bb,kBAAAA;EAA3Ba,WAAAA,CAAAA,OAAkB,CAAlBA,EAAkB,MAAA,EAAA,MAAA,CAAA,EACId,wBADJ;EAAA,WAAA,iBAAA,CAAA,CAAA,EAAA,MAAA;;;;AAOvC;AAA2C,cAAtBe,sBAAAA,SAA+Bd,kBAAAA,CAAT;aACAD,CAAAA,OAAAA,CAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EAAAA,wBAAAA;aADSC,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;AAI/Be,cAAAA,oBAAAA,SAA6Bf,kBAAAA,CAAT;EAAA,WAAA,CAAA,OAAA,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EACED,wBADF;aACEA,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;;AAM3C;;AAC2CA,cADtBiB,eAAAA,SAAwBhB,kBAAAA,CACFD;aADEC,CAAAA,OAAAA,CAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EACFD,wBADEC;;AAO7C;;;;cAAqBiB"}
|
package/dist/errors.d.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { Command, Interrupt } from "./constants.js";
|
|
|
4
4
|
// When editing, make sure to update the index found here:
|
|
5
5
|
// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/
|
|
6
6
|
type BaseLangGraphErrorFields = {
|
|
7
|
-
lc_error_code?: "GRAPH_RECURSION_LIMIT" | "INVALID_CONCURRENT_GRAPH_UPDATE" | "INVALID_GRAPH_NODE_RETURN_VALUE" | "MULTIPLE_SUBGRAPHS" | "UNREACHABLE_NODE";
|
|
7
|
+
lc_error_code?: "GRAPH_RECURSION_LIMIT" | "INVALID_CONCURRENT_GRAPH_UPDATE" | "INVALID_GRAPH_NODE_RETURN_VALUE" | "MISSING_CHECKPOINTER" | "MULTIPLE_SUBGRAPHS" | "UNREACHABLE_NODE";
|
|
8
8
|
};
|
|
9
9
|
// TODO: Merge with base LangChain error class when we drop support for core@0.2.0
|
|
10
|
+
/** @category Errors */
|
|
10
11
|
declare class BaseLangGraphError extends Error {
|
|
11
12
|
lc_error_code?: string;
|
|
12
13
|
constructor(message?: string, fields?: BaseLangGraphErrorFields);
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.d.ts","names":["Command","Interrupt","BaseLangGraphErrorFields","BaseLangGraphError","Error","GraphBubbleUp","GraphRecursionError","GraphValueError","GraphInterrupt","NodeInterrupt","ParentCommand","isParentCommand","isGraphBubbleUp","isGraphInterrupt","EmptyInputError","EmptyChannelError","InvalidUpdateError","MultipleSubgraphsError","UnreachableNodeError","RemoteException","getSubgraphsSeenSet"],"sources":["../src/errors.d.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?: \"GRAPH_RECURSION_LIMIT\" | \"INVALID_CONCURRENT_GRAPH_UPDATE\" | \"INVALID_GRAPH_NODE_RETURN_VALUE\" | \"MULTIPLE_SUBGRAPHS\" | \"UNREACHABLE_NODE\";\n};\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\nexport declare class BaseLangGraphError extends Error {\n lc_error_code?: string;\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n}\nexport declare class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up(): boolean;\n}\nexport declare class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/** Raised by a node to interrupt execution. */\nexport declare class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class ParentCommand extends GraphBubbleUp {\n command: Command;\n constructor(command: Command);\n static get unminifiable_name(): string;\n}\nexport declare function isParentCommand(e?: unknown): e is ParentCommand;\nexport declare function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp;\nexport declare function isGraphInterrupt(e?: unknown): e is GraphInterrupt;\nexport declare class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport declare class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport declare class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Used for subgraph detection.\n */\nexport declare const getSubgraphsSeenSet: () => any;\n"],"mappings":";;;;;AAGYE,KAAAA,wBAAAA,GAAwB;
|
|
1
|
+
{"version":3,"file":"errors.d.ts","names":["Command","Interrupt","BaseLangGraphErrorFields","BaseLangGraphError","Error","GraphBubbleUp","GraphRecursionError","GraphValueError","GraphInterrupt","NodeInterrupt","ParentCommand","isParentCommand","isGraphBubbleUp","isGraphInterrupt","EmptyInputError","EmptyChannelError","InvalidUpdateError","MultipleSubgraphsError","UnreachableNodeError","RemoteException","getSubgraphsSeenSet"],"sources":["../src/errors.d.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?: \"GRAPH_RECURSION_LIMIT\" | \"INVALID_CONCURRENT_GRAPH_UPDATE\" | \"INVALID_GRAPH_NODE_RETURN_VALUE\" | \"MISSING_CHECKPOINTER\" | \"MULTIPLE_SUBGRAPHS\" | \"UNREACHABLE_NODE\";\n};\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\n/** @category Errors */\nexport declare class BaseLangGraphError extends Error {\n lc_error_code?: string;\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n}\nexport declare class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up(): boolean;\n}\nexport declare class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/** Raised by a node to interrupt execution. */\nexport declare class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class ParentCommand extends GraphBubbleUp {\n command: Command;\n constructor(command: Command);\n static get unminifiable_name(): string;\n}\nexport declare function isParentCommand(e?: unknown): e is ParentCommand;\nexport declare function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp;\nexport declare function isGraphInterrupt(e?: unknown): e is GraphInterrupt;\nexport declare class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport declare class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\nexport declare class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport declare class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields);\n static get unminifiable_name(): string;\n}\n/**\n * Used for subgraph detection.\n */\nexport declare const getSubgraphsSeenSet: () => any;\n"],"mappings":";;;;;AAGYE,KAAAA,wBAAAA,GAAwB;EAKfC,aAAAA,CAAAA,EAAAA,uBAAkB,GAAA,iCAAA,GAAA,iCAAA,GAAA,sBAAA,GAAA,oBAAA,GAAA,kBAAA;CAAA;;;cAAlBA,kBAAAA,SAA2BC,KAAAA;EAI3BC,aAAAA,CAAAA,EAAa,MAAA;EAGbC,WAAAA,CAAAA,OAAmB,CAAnBA,EAAmB,MAAA,EAAA,MAAA,CAAA,EALGJ,wBAKH;;AACGA,cAJtBG,aAAAA,SAAsBF,kBAAAA,CAIAD;MADMC,YAAAA,CAAAA,CAAAA,EAAAA,OAAAA;;AAI5BI,cAJAD,mBAAAA,SAA4BH,kBAAAA,CAIb;EAAA,WAAA,CAAA,OAAA,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAHOD,wBAGP;aACOA,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;cADtBK,eAAAA,SAAwBJ,kBAAAA;EAIxBK,WAAAA,CAAAA,OAAc,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAHQN,wBAGR;EAAA,WAAA,iBAAA,CAAA,CAAA,EAAA,MAAA;;AAEND,cAFRO,cAAAA,SAAuBH,aAAAA,CAEfJ;YAAsBC,EADnCD,SACmCC,EAAAA;aAFPG,CAAAA,UAAAA,CAAAA,EAEfJ,SAFeI,EAAAA,EAAAA,MAAAA,CAAAA,EAEOH,wBAFPG;;AAM5C;;AAEuCH,cAFlBO,aAAAA,SAAsBD,cAAAA,CAEJN;;qCAAAA;EAGlBQ,WAAAA,iBAAa,CAAA,CAAA,EAAA,MAAA;;AACrBV,cADQU,aAAAA,SAAsBL,aAAAA,CAC9BL;SACYA,EADZA,OACYA;aAFkBK,CAAAA,OAAAA,EAElBL,OAFkBK;;AAK3C;AACwBO,iBADAD,eAAAA,CACmCN,CAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,CAAAA,IADAK,aACAL;AACnCQ,iBADAD,eAAAA,CACoCJ,CAAAA,CAAAA,EAAAA,OAAAA,CAAAA,EAAAA,CAAAA,IADDH,aACCG;AACvCM,iBADGD,gBAAAA,CACY,CAAA,CAAA,EAAA,OAAA,CAAA,EAAA,CAAA,IADwBL,cACxB;AAAA,cAAfM,eAAAA,SAAwBX,kBAAAA,CAAT;aACOD,CAAAA,OAAAA,CAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EAAAA,wBAAAA;aADEC,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;AAIxBY,cAAAA,iBAAAA,SAA0BZ,kBAAAA,CAAT;EAAA,WAAA,CAAA,OAAA,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EACKD,wBADL;aACKA,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;cAGtBc,kBAAAA,SAA2Bb,kBAAAA;EAA3Ba,WAAAA,CAAAA,OAAkB,CAAlBA,EAAkB,MAAA,EAAA,MAAA,CAAA,EACId,wBADJ;EAAA,WAAA,iBAAA,CAAA,CAAA,EAAA,MAAA;;;;AAOvC;AAA2C,cAAtBe,sBAAAA,SAA+Bd,kBAAAA,CAAT;aACAD,CAAAA,OAAAA,CAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EAAAA,wBAAAA;aADSC,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;AAI/Be,cAAAA,oBAAAA,SAA6Bf,kBAAAA,CAAT;EAAA,WAAA,CAAA,OAAA,CAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EACED,wBADF;aACEA,iBAAAA,CAAAA,CAAAA,EAAAA,MAAAA;;;AAM3C;;AAC2CA,cADtBiB,eAAAA,SAAwBhB,kBAAAA,CACFD;aADEC,CAAAA,OAAAA,CAAAA,EAAAA,MAAAA,EAAAA,MAAAA,CAAAA,EACFD,wBADEC;;AAO7C;;;;cAAqBiB"}
|
package/dist/errors.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
//#region src/errors.ts
|
|
2
|
+
/** @category Errors */
|
|
2
3
|
var BaseLangGraphError = class extends Error {
|
|
3
4
|
lc_error_code;
|
|
4
5
|
constructor(message, fields) {
|
|
5
6
|
let finalMessage = message ?? "";
|
|
6
|
-
if (fields?.lc_error_code) finalMessage = `${finalMessage}\n\nTroubleshooting URL: https://langchain
|
|
7
|
+
if (fields?.lc_error_code) finalMessage = `${finalMessage}\n\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${fields.lc_error_code}/\n`;
|
|
7
8
|
super(finalMessage);
|
|
8
9
|
this.lc_error_code = fields?.lc_error_code;
|
|
9
10
|
}
|
package/dist/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?:\n | \"GRAPH_RECURSION_LIMIT\"\n | \"INVALID_CONCURRENT_GRAPH_UPDATE\"\n | \"INVALID_GRAPH_NODE_RETURN_VALUE\"\n | \"MULTIPLE_SUBGRAPHS\"\n | \"UNREACHABLE_NODE\";\n};\n\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\nexport class BaseLangGraphError extends Error {\n lc_error_code?: string;\n\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n let finalMessage = message ?? \"\";\n if (fields?.lc_error_code) {\n finalMessage = `${finalMessage}\\n\\nTroubleshooting URL: https://langchain
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../src/errors.ts"],"sourcesContent":["import { Command, Interrupt } from \"./constants.js\";\n\n// When editing, make sure to update the index found here:\n// https://langchain-ai.github.io/langgraphjs/troubleshooting/errors/\nexport type BaseLangGraphErrorFields = {\n lc_error_code?:\n | \"GRAPH_RECURSION_LIMIT\"\n | \"INVALID_CONCURRENT_GRAPH_UPDATE\"\n | \"INVALID_GRAPH_NODE_RETURN_VALUE\"\n | \"MISSING_CHECKPOINTER\"\n | \"MULTIPLE_SUBGRAPHS\"\n | \"UNREACHABLE_NODE\";\n};\n\n// TODO: Merge with base LangChain error class when we drop support for core@0.2.0\n/** @category Errors */\nexport class BaseLangGraphError extends Error {\n lc_error_code?: string;\n\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n let finalMessage = message ?? \"\";\n if (fields?.lc_error_code) {\n finalMessage = `${finalMessage}\\n\\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${fields.lc_error_code}/\\n`;\n }\n super(finalMessage);\n this.lc_error_code = fields?.lc_error_code;\n }\n}\n\nexport class GraphBubbleUp extends BaseLangGraphError {\n get is_bubble_up() {\n return true;\n }\n}\n\nexport class GraphRecursionError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphRecursionError\";\n }\n\n static get unminifiable_name() {\n return \"GraphRecursionError\";\n }\n}\n\nexport class GraphValueError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"GraphValueError\";\n }\n\n static get unminifiable_name() {\n return \"GraphValueError\";\n }\n}\n\nexport class GraphInterrupt extends GraphBubbleUp {\n interrupts: Interrupt[];\n\n constructor(interrupts?: Interrupt[], fields?: BaseLangGraphErrorFields) {\n super(JSON.stringify(interrupts, null, 2), fields);\n this.name = \"GraphInterrupt\";\n this.interrupts = interrupts ?? [];\n }\n\n static get unminifiable_name() {\n return \"GraphInterrupt\";\n }\n}\n\n/** Raised by a node to interrupt execution. */\nexport class NodeInterrupt extends GraphInterrupt {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n constructor(message: any, fields?: BaseLangGraphErrorFields) {\n super([{ value: message }], fields);\n this.name = \"NodeInterrupt\";\n }\n\n static get unminifiable_name() {\n return \"NodeInterrupt\";\n }\n}\n\nexport class ParentCommand extends GraphBubbleUp {\n command: Command;\n\n constructor(command: Command) {\n super();\n this.name = \"ParentCommand\";\n this.command = command;\n }\n\n static get unminifiable_name() {\n return \"ParentCommand\";\n }\n}\n\nexport function isParentCommand(e?: unknown): e is ParentCommand {\n return (\n e !== undefined &&\n (e as ParentCommand).name === ParentCommand.unminifiable_name\n );\n}\n\nexport function isGraphBubbleUp(e?: unknown): e is GraphBubbleUp {\n return e !== undefined && (e as GraphBubbleUp).is_bubble_up === true;\n}\n\nexport function isGraphInterrupt(e?: unknown): e is GraphInterrupt {\n return (\n e !== undefined &&\n [\n GraphInterrupt.unminifiable_name,\n NodeInterrupt.unminifiable_name,\n ].includes((e as Error).name)\n );\n}\n\nexport class EmptyInputError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"EmptyInputError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyInputError\";\n }\n}\n\nexport class EmptyChannelError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"EmptyChannelError\";\n }\n\n static get unminifiable_name() {\n return \"EmptyChannelError\";\n }\n}\n\nexport class InvalidUpdateError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"InvalidUpdateError\";\n }\n\n static get unminifiable_name() {\n return \"InvalidUpdateError\";\n }\n}\n\n/**\n * @deprecated This exception type is no longer thrown.\n */\nexport class MultipleSubgraphsError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"MultipleSubgraphError\";\n }\n\n static get unminifiable_name() {\n return \"MultipleSubgraphError\";\n }\n}\n\nexport class UnreachableNodeError extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"UnreachableNodeError\";\n }\n\n static get unminifiable_name() {\n return \"UnreachableNodeError\";\n }\n}\n\n/**\n * Exception raised when an error occurs in the remote graph.\n */\nexport class RemoteException extends BaseLangGraphError {\n constructor(message?: string, fields?: BaseLangGraphErrorFields) {\n super(message, fields);\n this.name = \"RemoteException\";\n }\n\n static get unminifiable_name() {\n return \"RemoteException\";\n }\n}\n\n/**\n * Used for subgraph detection.\n */\nexport const getSubgraphsSeenSet = () => {\n if (\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] === undefined\n ) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")] = new Set();\n }\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return (globalThis as any)[Symbol.for(\"LG_CHECKPOINT_SEEN_NS_SET\")];\n};\n"],"mappings":";;AAgBA,IAAa,qBAAb,cAAwC,MAAM;CAC5C;CAEA,YAAY,SAAkB,QAAmC;EAC/D,IAAI,eAAe,WAAW;AAC9B,MAAI,QAAQ,cACV,gBAAe,GAAG,aAAa,+EAA+E,OAAO,cAAc;AAErI,QAAM;AACN,OAAK,gBAAgB,QAAQ;;;AAIjC,IAAa,gBAAb,cAAmC,mBAAmB;CACpD,IAAI,eAAe;AACjB,SAAO;;;AAIX,IAAa,sBAAb,cAAyC,mBAAmB;CAC1D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,iBAAb,cAAoC,cAAc;CAChD;CAEA,YAAY,YAA0B,QAAmC;AACvE,QAAM,KAAK,UAAU,YAAY,MAAM,IAAI;AAC3C,OAAK,OAAO;AACZ,OAAK,aAAa,cAAc;;CAGlC,WAAW,oBAAoB;AAC7B,SAAO;;;;AAKX,IAAa,gBAAb,cAAmC,eAAe;CAEhD,YAAY,SAAc,QAAmC;AAC3D,QAAM,CAAC,EAAE,OAAO,YAAY;AAC5B,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,gBAAb,cAAmC,cAAc;CAC/C;CAEA,YAAY,SAAkB;AAC5B;AACA,OAAK,OAAO;AACZ,OAAK,UAAU;;CAGjB,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,SAAgB,gBAAgB,GAAiC;AAC/D,QACE,MAAM,UACL,EAAoB,SAAS,cAAc;;AAIhD,SAAgB,gBAAgB,GAAiC;AAC/D,QAAO,MAAM,UAAc,EAAoB,iBAAiB;;AAGlE,SAAgB,iBAAiB,GAAkC;AACjE,QACE,MAAM,UACN,CACE,eAAe,mBACf,cAAc,mBACd,SAAU,EAAY;;AAI5B,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,oBAAb,cAAuC,mBAAmB;CACxD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,qBAAb,cAAwC,mBAAmB;CACzD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,IAAa,yBAAb,cAA4C,mBAAmB;CAC7D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;AAIX,IAAa,uBAAb,cAA0C,mBAAmB;CAC3D,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,IAAa,kBAAb,cAAqC,mBAAmB;CACtD,YAAY,SAAkB,QAAmC;AAC/D,QAAM,SAAS;AACf,OAAK,OAAO;;CAGd,WAAW,oBAAoB;AAC7B,SAAO;;;;;;AAOX,MAAa,4BAA4B;AACvC,KAEG,WAAmB,OAAO,IAAI,kCAAkC,OAGjE,CAAC,WAAmB,OAAO,IAAI,gDAAgC,IAAI;AAGrE,QAAQ,WAAmB,OAAO,IAAI"}
|
package/dist/func/index.cjs
CHANGED
|
@@ -55,6 +55,7 @@ const __langchain_core_singletons = require_rolldown_runtime.__toESM(require("@l
|
|
|
55
55
|
* return results;
|
|
56
56
|
* });
|
|
57
57
|
* ```
|
|
58
|
+
* @category Functional API
|
|
58
59
|
*/
|
|
59
60
|
function task(optionsOrName, func) {
|
|
60
61
|
const options = typeof optionsOrName === "string" ? {
|
|
@@ -207,6 +208,7 @@ function task(optionsOrName, func) {
|
|
|
207
208
|
* await myWorkflow.invoke(3, config); // 0 (previous was undefined)
|
|
208
209
|
* await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)
|
|
209
210
|
* ```
|
|
211
|
+
* @category Functional API
|
|
210
212
|
*/
|
|
211
213
|
const entrypoint = function entrypoint$1(optionsOrName, func) {
|
|
212
214
|
const { name, checkpointer, store, cache } = typeof optionsOrName === "string" ? {
|
|
@@ -285,6 +287,7 @@ entrypoint.final = function final({ value, save }) {
|
|
|
285
287
|
* const previousState = getPreviousState<{ counter: number }>();
|
|
286
288
|
* const newCount = (previousState?.counter ?? 0) + 1;
|
|
287
289
|
* ```
|
|
290
|
+
* @category Functional API
|
|
288
291
|
*/
|
|
289
292
|
function getPreviousState() {
|
|
290
293
|
const config = __langchain_core_singletons.AsyncLocalStorageProviderSingleton.getRunnableConfig();
|
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 */\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 */\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 */\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 */\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,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,UAAW,QAAQ,QAAwB;CAEzD,IAAIC;AACJ,KAAI,OAAO,gBAAgB,UACzB,SAAQ,cAAc,KAAK;KAE3B,SAAQ;AAGV,SAAQ,GAAG,SAAgB;AACzB,SAAOC,kBAAK;GAAE;GAAM;GAAM;GAAO;KAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgNjD,MAAa,aAAa,SAASC,aACjC,eACA,MACA;CACA,MAAM,EAAE,MAAM,cAAc,OAAO,UACjC,OAAO,kBAAkB,WACrB;EAAE,MAAM;EAAe,cAAc;EAAW,OAAO;KACvD;AACN,KAAIJ,uCAAyB,SAASC,kCAAoB,MACxD,OAAM,IAAI,MACR;CAGJ,MAAM,aAAa;CACnB,MAAM,QAAQI,sCAAyB,MAAM;CAG7C,SAAS,kBACP,OAC4C;AAC5C,SACE,OAAO,UAAU,YACjB,UAAU,QACV,eAAe,SACf,MAAM,cAAc;;CAKxB,MAAM,mBAAmB,IAAIC,+BAAiB;EAC5C,MAAM;EACN,OAAO,UAAmB;AACxB,UAAO,kBAAkB,SAAS,MAAM,QAAQ;;;CAKpD,MAAM,iBAAiB,IAAIA,+BAAiB;EAC1C,MAAM;EACN,OAAO,UAAmB;AACxB,UAAO,kBAAkB,SAAS,MAAM,OAAO;;;CAInD,MAAM,iBAAiB,IAAIC,wBAA+C;EACxE;EACA,UAAU,CAACC;EACX,UAAU,CAACA;EACX,SAAS,CACP,IAAIC,2BACF,CACE;GAAE,SAASC;GAAK,OAAOC;GAAa,QAAQ;KAC5C;GAAE,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;;;;;;;;;;;;;;;;;;;AAmBnC,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 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,KAAIA,uCAAyB,SAASC,kCAAoB,MACxD,OAAM,IAAI,MACR;CAIJ,MAAM,cACJ,QAAQ,gBAGP,WAAW,UAAW,QAAQ,QAAwB;CAEzD,IAAIC;AACJ,KAAI,OAAO,gBAAgB,UACzB,SAAQ,cAAc,KAAK;KAE3B,SAAQ;AAGV,SAAQ,GAAG,SAAgB;AACzB,SAAOC,kBAAK;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,KAAIJ,uCAAyB,SAASC,kCAAoB,MACxD,OAAM,IAAI,MACR;CAGJ,MAAM,aAAa;CACnB,MAAM,QAAQI,sCAAyB,MAAM;CAG7C,SAAS,kBACP,OAC4C;AAC5C,SACE,OAAO,UAAU,YACjB,UAAU,QACV,eAAe,SACf,MAAM,cAAc;;CAKxB,MAAM,mBAAmB,IAAIC,+BAAiB;EAC5C,MAAM;EACN,OAAO,UAAmB;AACxB,UAAO,kBAAkB,SAAS,MAAM,QAAQ;;;CAKpD,MAAM,iBAAiB,IAAIA,+BAAiB;EAC1C,MAAM;EACN,OAAO,UAAmB;AACxB,UAAO,kBAAkB,SAAS,MAAM,OAAO;;;CAInD,MAAM,iBAAiB,IAAIC,wBAA+C;EACxE;EACA,UAAU,CAACC;EACX,UAAU,CAACA;EACX,SAAS,CACP,IAAIC,2BACF,CACE;GAAE,SAASC;GAAK,OAAOC;GAAa,QAAQ;KAC5C;GAAE,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"}
|
package/dist/func/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { LastValue } from "../channels/last_value.cjs";
|
|
2
|
+
import { EphemeralValue } from "../channels/ephemeral_value.cjs";
|
|
2
3
|
import { CachePolicy, RetryPolicy } from "../pregel/utils/index.cjs";
|
|
3
4
|
import { PregelNode } from "../pregel/read.cjs";
|
|
4
5
|
import { END, PREVIOUS, START } from "../constants.cjs";
|
|
5
6
|
import { Pregel } from "../pregel/index.cjs";
|
|
6
|
-
import { EphemeralValue } from "../channels/ephemeral_value.cjs";
|
|
7
7
|
import { EntrypointFinal, EntrypointFinalSaveT, EntrypointFunc, EntrypointReturnT, TaskFunc } from "./types.cjs";
|
|
8
8
|
import { BaseCache, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
|
|
9
9
|
|
|
@@ -72,6 +72,7 @@ interface TaskOptions {
|
|
|
72
72
|
* return results;
|
|
73
73
|
* });
|
|
74
74
|
* ```
|
|
75
|
+
* @category Functional API
|
|
75
76
|
*/
|
|
76
77
|
declare function task<ArgsT extends unknown[], OutputT>(optionsOrName: TaskOptions | string, func: TaskFunc<ArgsT, OutputT>): (...args: ArgsT) => Promise<OutputT>;
|
|
77
78
|
/**
|
|
@@ -99,6 +100,7 @@ type EntrypointOptions = {
|
|
|
99
100
|
};
|
|
100
101
|
/**
|
|
101
102
|
* Type declaration for the entrypoint function with its properties
|
|
103
|
+
* @category Functional API
|
|
102
104
|
*/
|
|
103
105
|
interface EntrypointFunction {
|
|
104
106
|
<InputT, OutputT>(optionsOrName: EntrypointOptions | string, func: EntrypointFunc<InputT, OutputT>): Pregel<Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, {
|
|
@@ -265,6 +267,7 @@ interface EntrypointFunction {
|
|
|
265
267
|
* await myWorkflow.invoke(3, config); // 0 (previous was undefined)
|
|
266
268
|
* await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)
|
|
267
269
|
* ```
|
|
270
|
+
* @category Functional API
|
|
268
271
|
*/
|
|
269
272
|
declare const entrypoint: EntrypointFunction;
|
|
270
273
|
/**
|
|
@@ -282,6 +285,7 @@ declare const entrypoint: EntrypointFunction;
|
|
|
282
285
|
* const previousState = getPreviousState<{ counter: number }>();
|
|
283
286
|
* const newCount = (previousState?.counter ?? 0) + 1;
|
|
284
287
|
* ```
|
|
288
|
+
* @category Functional API
|
|
285
289
|
*/
|
|
286
290
|
declare function getPreviousState<StateT>(): StateT;
|
|
287
291
|
//#endregion
|
|
@@ -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 */\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 */\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 */\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 */\nexport declare function getPreviousState<StateT>(): StateT;\n"],"mappings":";;;;;;;;;;;;;AAWA;AAA4B,UAAXiB,WAAAA,CAAW;;;;EA6DJC,IAAAA,EAAAA,MAAI;EAAA;;;;OAA8EF,CAAAA,EApD9FN,WAoD8FM;;;;gBAhDxFP;AAoDlB;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqKA;AAiBA;;;;iBAjNwBS,sDAAsDD,4BAA4BD,SAASG,OAAOC,qBAAqBD,UAAUE,QAAQD;;;;KAIrJE,iBAAAA;;;;;;;;;;iBAUOrB;;;;UAIPC;;;;UAIAF;;;;;UAKKuB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqIXC,YAAYN;;;;;;;;;;;;;;;;;iBAiBTO,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 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"}
|
package/dist/func/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { LastValue } from "../channels/last_value.js";
|
|
2
|
+
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
2
3
|
import { CachePolicy, RetryPolicy } from "../pregel/utils/index.js";
|
|
3
4
|
import { PregelNode } from "../pregel/read.js";
|
|
4
5
|
import { END, PREVIOUS, START } from "../constants.js";
|
|
5
6
|
import { Pregel } from "../pregel/index.js";
|
|
6
|
-
import { EphemeralValue } from "../channels/ephemeral_value.js";
|
|
7
7
|
import { EntrypointFinal, EntrypointFinalSaveT, EntrypointFunc, EntrypointReturnT, TaskFunc } from "./types.js";
|
|
8
8
|
import { BaseCache, BaseCheckpointSaver, BaseStore } from "@langchain/langgraph-checkpoint";
|
|
9
9
|
|
|
@@ -72,6 +72,7 @@ interface TaskOptions {
|
|
|
72
72
|
* return results;
|
|
73
73
|
* });
|
|
74
74
|
* ```
|
|
75
|
+
* @category Functional API
|
|
75
76
|
*/
|
|
76
77
|
declare function task<ArgsT extends unknown[], OutputT>(optionsOrName: TaskOptions | string, func: TaskFunc<ArgsT, OutputT>): (...args: ArgsT) => Promise<OutputT>;
|
|
77
78
|
/**
|
|
@@ -99,6 +100,7 @@ type EntrypointOptions = {
|
|
|
99
100
|
};
|
|
100
101
|
/**
|
|
101
102
|
* Type declaration for the entrypoint function with its properties
|
|
103
|
+
* @category Functional API
|
|
102
104
|
*/
|
|
103
105
|
interface EntrypointFunction {
|
|
104
106
|
<InputT, OutputT>(optionsOrName: EntrypointOptions | string, func: EntrypointFunc<InputT, OutputT>): Pregel<Record<string, PregelNode<InputT, EntrypointReturnT<OutputT>>>, {
|
|
@@ -265,6 +267,7 @@ interface EntrypointFunction {
|
|
|
265
267
|
* await myWorkflow.invoke(3, config); // 0 (previous was undefined)
|
|
266
268
|
* await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)
|
|
267
269
|
* ```
|
|
270
|
+
* @category Functional API
|
|
268
271
|
*/
|
|
269
272
|
declare const entrypoint: EntrypointFunction;
|
|
270
273
|
/**
|
|
@@ -282,6 +285,7 @@ declare const entrypoint: EntrypointFunction;
|
|
|
282
285
|
* const previousState = getPreviousState<{ counter: number }>();
|
|
283
286
|
* const newCount = (previousState?.counter ?? 0) + 1;
|
|
284
287
|
* ```
|
|
288
|
+
* @category Functional API
|
|
285
289
|
*/
|
|
286
290
|
declare function getPreviousState<StateT>(): StateT;
|
|
287
291
|
//#endregion
|
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 */\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 */\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 */\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 */\nexport declare function getPreviousState<StateT>(): StateT;\n"],"mappings":";;;;;;;;;;;;;AAWA;AAA4B,UAAXiB,WAAAA,CAAW;;;;EA6DJC,IAAAA,EAAAA,MAAI;EAAA;;;;OAA8EF,CAAAA,EApD9FN,WAoD8FM;;;;gBAhDxFP;AAoDlB;;;;;;AAuBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqKA;AAiBA;;;;iBAjNwBS,sDAAsDD,4BAA4BD,SAASG,OAAOC,qBAAqBD,UAAUE,QAAQD;;;;KAIrJE,iBAAAA;;;;;;;;;;iBAUOrB;;;;UAIPC;;;;UAIAF;;;;;UAKKuB,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqIXC,YAAYN;;;;;;;;;;;;;;;;;iBAiBTO,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 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"}
|
package/dist/func/index.js
CHANGED
|
@@ -54,6 +54,7 @@ import { AsyncLocalStorageProviderSingleton } from "@langchain/core/singletons";
|
|
|
54
54
|
* return results;
|
|
55
55
|
* });
|
|
56
56
|
* ```
|
|
57
|
+
* @category Functional API
|
|
57
58
|
*/
|
|
58
59
|
function task(optionsOrName, func) {
|
|
59
60
|
const options = typeof optionsOrName === "string" ? {
|
|
@@ -206,6 +207,7 @@ function task(optionsOrName, func) {
|
|
|
206
207
|
* await myWorkflow.invoke(3, config); // 0 (previous was undefined)
|
|
207
208
|
* await myWorkflow.invoke(1, config); // 6 (previous was 3 * 2 from the previous invocation)
|
|
208
209
|
* ```
|
|
210
|
+
* @category Functional API
|
|
209
211
|
*/
|
|
210
212
|
const entrypoint = function entrypoint$1(optionsOrName, func) {
|
|
211
213
|
const { name, checkpointer, store, cache } = typeof optionsOrName === "string" ? {
|
|
@@ -284,6 +286,7 @@ entrypoint.final = function final({ value, save }) {
|
|
|
284
286
|
* const previousState = getPreviousState<{ counter: number }>();
|
|
285
287
|
* const newCount = (previousState?.counter ?? 0) + 1;
|
|
286
288
|
* ```
|
|
289
|
+
* @category Functional API
|
|
287
290
|
*/
|
|
288
291
|
function getPreviousState() {
|
|
289
292
|
const config = AsyncLocalStorageProviderSingleton.getRunnableConfig();
|