Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tame-humans-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@langchain/langgraph": patch
---

Allow defining types for interrupt and custom events upfront
18 changes: 13 additions & 5 deletions libs/langgraph/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ const COMMAND_SYMBOL = Symbol.for("langgraph.command");
* @see {@link Command}
* @internal
*/
export class CommandInstance {
[COMMAND_SYMBOL]: true;
export class CommandInstance<
Resume = unknown,
Update extends Record<string, unknown> = Record<string, unknown>,
Nodes extends string = string
> {
[COMMAND_SYMBOL]: CommandParams<Resume, Update, Nodes>;

constructor(args: CommandParams<Resume, Update, Nodes>) {
this[COMMAND_SYMBOL] = args;
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -329,7 +337,7 @@ export class Command<
Resume = unknown,
Update extends Record<string, unknown> = Record<string, unknown>,
Nodes extends string = string
> extends CommandInstance {
> extends CommandInstance<Resume, Update, Nodes> {
readonly lg_name = "Command";

lc_direct_tool_output = true;
Expand Down Expand Up @@ -364,8 +372,8 @@ export class Command<

static PARENT = "__parent__";

constructor(args: CommandParams<Resume, Update, Nodes>) {
super();
constructor(args: Omit<CommandParams<Resume, Update, Nodes>, "lg_name">) {
super(args);
this.resume = args.resume;
this.graph = args.graph;
this.update = args.update;
Expand Down
18 changes: 9 additions & 9 deletions libs/langgraph/src/graph/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
Graph as DrawableGraph,
} from "@langchain/core/runnables/graph";
import { All, BaseCheckpointSaver } from "@langchain/langgraph-checkpoint";
import { z } from "zod";
import { z } from "zod/v4";
import { validate as isUuid } from "uuid";
import type {
RunnableLike,
Expand Down Expand Up @@ -581,7 +581,10 @@ export class CompiledGraph<
InputType = any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
OutputType = any,
NodeReturnType = unknown
NodeReturnType = unknown,
CommandType = unknown,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
StreamCustomType = any
> extends Pregel<
Record<N | typeof START, PregelNode<State, Update>>,
Record<N | typeof START | typeof END | string, BaseChannel>,
Expand All @@ -591,7 +594,9 @@ export class CompiledGraph<
OutputType,
InputType,
OutputType,
NodeReturnType
NodeReturnType,
CommandType,
StreamCustomType
> {
declare NodeType: N;

Expand Down Expand Up @@ -694,12 +699,7 @@ export class CompiledGraph<
const xray = config?.xray;
const graph = new DrawableGraph();
const startNodes: Record<string, DrawableGraphNode> = {
[START]: graph.addNode(
{
schema: z.any(),
},
START
),
[START]: graph.addNode({ schema: z.any() }, START),
};
const endNodes: Record<string, DrawableGraphNode> = {};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
1 change: 0 additions & 1 deletion libs/langgraph/src/graph/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export {
type StateGraphArgs,
StateGraph,
CompiledStateGraph,
typedNode,
} from "./state.js";
export {
MessageGraph,
Expand Down
Loading
Loading