//#region src/errors.ts
/** @category Errors */
var BaseLangGraphError = class extends Error {
	lc_error_code;
	constructor(message, fields) {
		let finalMessage = message ?? "";
		if (fields?.lc_error_code) finalMessage = `${finalMessage}\n\nTroubleshooting URL: https://docs.langchain.com/oss/javascript/langgraph/${fields.lc_error_code}/\n`;
		super(finalMessage);
		this.lc_error_code = fields?.lc_error_code;
	}
};
var GraphBubbleUp = class extends BaseLangGraphError {
	get is_bubble_up() {
		return true;
	}
};
var GraphRecursionError = class extends BaseLangGraphError {
	constructor(message, fields) {
		super(message, fields);
		this.name = "GraphRecursionError";
	}
	static get unminifiable_name() {
		return "GraphRecursionError";
	}
};
var GraphValueError = class extends BaseLangGraphError {
	constructor(message, fields) {
		super(message, fields);
		this.name = "GraphValueError";
	}
	static get unminifiable_name() {
		return "GraphValueError";
	}
};
/**
* Raised when a graph run exits early due to a drain request.
*
* This indicates the graph stopped cooperatively at a superstep boundary
* because {@link RunControl#requestDrain} was called (e.g., in response to
* SIGTERM). The checkpoint is saved and the run can be resumed later.
*/
var GraphDrained = class extends GraphBubbleUp {
	reason;
	constructor(reason = "shutdown", fields) {
		super(`Graph drained: ${reason}`, fields);
		this.name = "GraphDrained";
		this.reason = reason;
	}
	static get unminifiable_name() {
		return "GraphDrained";
	}
};
function isGraphDrained(e) {
	return e !== void 0 && e.name === GraphDrained.unminifiable_name;
}
var GraphInterrupt = class extends GraphBubbleUp {
	interrupts;
	constructor(interrupts, fields) {
		super(JSON.stringify(interrupts, null, 2), fields);
		this.name = "GraphInterrupt";
		this.interrupts = interrupts ?? [];
	}
	static get unminifiable_name() {
		return "GraphInterrupt";
	}
};
/** Raised by a node to interrupt execution. */
var NodeInterrupt = class extends GraphInterrupt {
	constructor(message, fields) {
		super([{ value: message }], fields);
		this.name = "NodeInterrupt";
	}
	static get unminifiable_name() {
		return "NodeInterrupt";
	}
};
/**
* Failure context passed to a node-level error handler.
*
* A node-level error handler is registered via
* `StateGraph.addNode(name, fn, { errorHandler })`. The handler runs ONLY after
* the failing node's {@link RetryPolicy} is exhausted, so retry and handling
* stay decoupled. The handler receives the failed node's name and the thrown
* error via a `NodeError` instance, can return a state update, and can route to
* a recovery branch via `new Command({ goto })` (saga / compensation flows).
*
* @example
* ```ts
* import { NodeError } from "@langchain/langgraph";
*
* function handler(state: State, error: NodeError) {
*   return new Command({
*     update: { status: `recovered from ${error.node}: ${error.error.message}` },
*     goto: "finalize",
*   });
* }
* ```
*/
var NodeError = class {
	/** Name of the node whose execution failed. */
	node;
	/** Error thrown by the failed node. */
	error;
	constructor(node, error) {
		this.node = node;
		this.error = error;
	}
	static get unminifiable_name() {
		return "NodeError";
	}
};
/**
* Type guard that checks whether a value is a {@link NodeError}.
*/
function isNodeError(e) {
	return e != null && typeof e === "object" && e.constructor != null && e.constructor.unminifiable_name === NodeError.unminifiable_name;
}
var ParentCommand = class extends GraphBubbleUp {
	command;
	constructor(command) {
		super();
		this.name = "ParentCommand";
		this.command = command;
	}
	static get unminifiable_name() {
		return "ParentCommand";
	}
};
function isParentCommand(e) {
	return e !== void 0 && e.name === ParentCommand.unminifiable_name;
}
function isGraphBubbleUp(e) {
	return e !== void 0 && e.is_bubble_up === true;
}
function isGraphInterrupt(e) {
	return e !== void 0 && [GraphInterrupt.unminifiable_name, NodeInterrupt.unminifiable_name].includes(e.name);
}
/**
* Raised when a node invocation exceeds one of its configured timeouts.
*
* Does **not** extend {@link GraphBubbleUp} (so it flows through the normal node
* error path) and is intentionally treated as retryable by the default retry
* policy — its message/name do not match the default `retryOn` blocklist, so a
* configured {@link RetryPolicy} will retry it (see langchain-ai/langgraph#7659).
*
* Both {@link NodeTimeoutError.runTimeout} and {@link NodeTimeoutError.idleTimeout}
* reflect the configured policy at the time of the failure (each `undefined` if
* not configured). {@link NodeTimeoutError.kind} and {@link NodeTimeoutError.timeout}
* identify which one fired.
*
* @category Errors
*/
var NodeTimeoutError = class extends BaseLangGraphError {
	/** Name of the node/task that timed out. */
	node;
	/** Which timeout fired: a hard `"run"` cap or a progress-resetting `"idle"` cap. */
	kind;
	/** The value (ms) of the timeout that fired (`runTimeout` or `idleTimeout`). */
	timeout;
	/** Elapsed time (ms) since the attempt started, at the moment the timeout fired. */
	elapsed;
	/** Configured run timeout (ms), if any. */
	runTimeout;
	/** Configured idle timeout (ms), if any. */
	idleTimeout;
	constructor(fields, errorFields) {
		const { node, elapsed, kind, runTimeout, idleTimeout } = fields;
		let message;
		let timeout;
		if (kind === "idle") {
			if (idleTimeout === void 0) throw new Error("idleTimeout is required when kind='idle'");
			timeout = idleTimeout;
			message = `Node "${node}" exceeded its idle timeout of ${idleTimeout}ms without making progress (elapsed: ${elapsed}ms).`;
		} else {
			if (runTimeout === void 0) throw new Error("runTimeout is required when kind='run'");
			timeout = runTimeout;
			message = `Node "${node}" exceeded its run timeout of ${runTimeout}ms (elapsed: ${elapsed}ms).`;
		}
		super(message, errorFields);
		this.name = "NodeTimeoutError";
		this.node = node;
		this.kind = kind;
		this.timeout = timeout;
		this.elapsed = elapsed;
		this.runTimeout = runTimeout;
		this.idleTimeout = idleTimeout;
	}
	static get unminifiable_name() {
		return "NodeTimeoutError";
	}
};
function isNodeTimeoutError(e) {
	return e !== void 0 && e.name === NodeTimeoutError.unminifiable_name;
}
var EmptyInputError = class extends BaseLangGraphError {
	constructor(message, fields) {
		super(message, fields);
		this.name = "EmptyInputError";
	}
	static get unminifiable_name() {
		return "EmptyInputError";
	}
};
var EmptyChannelError = class extends BaseLangGraphError {
	constructor(message, fields) {
		const prevLimit = Error.stackTraceLimit;
		Error.stackTraceLimit = 0;
		super(message, fields);
		Error.stackTraceLimit = prevLimit;
		this.name = "EmptyChannelError";
	}
	static get unminifiable_name() {
		return "EmptyChannelError";
	}
};
var InvalidUpdateError = class extends BaseLangGraphError {
	constructor(message, fields) {
		super(message, fields);
		this.name = "InvalidUpdateError";
	}
	static get unminifiable_name() {
		return "InvalidUpdateError";
	}
};
/**
* @deprecated This exception type is no longer thrown.
*/
var MultipleSubgraphsError = class extends BaseLangGraphError {
	constructor(message, fields) {
		super(message, fields);
		this.name = "MultipleSubgraphError";
	}
	static get unminifiable_name() {
		return "MultipleSubgraphError";
	}
};
var UnreachableNodeError = class extends BaseLangGraphError {
	constructor(message, fields) {
		super(message, fields);
		this.name = "UnreachableNodeError";
	}
	static get unminifiable_name() {
		return "UnreachableNodeError";
	}
};
/**
* Exception raised when an error occurs in the remote graph.
*/
var RemoteException = class extends BaseLangGraphError {
	constructor(message, fields) {
		super(message, fields);
		this.name = "RemoteException";
	}
	static get unminifiable_name() {
		return "RemoteException";
	}
};
/**
* Error thrown when invalid input is provided to a StateGraph.
*
* This typically means that the input to the StateGraph constructor or builder
* did not match the required types. A valid input should be a
* StateDefinition, an Annotation.Root, or a Zod schema.
*
* @example
* // Example of incorrect usage:
* try {
*   new StateGraph({ foo: "bar" }); // Not a valid input
* } catch (err) {
*   if (err instanceof StateGraphInputError) {
*     console.error(err.message);
*   }
* }
*/
var StateGraphInputError = class extends BaseLangGraphError {
	/**
	* Create a new StateGraphInputError.
	* @param message - Optional custom error message.
	* @param fields - Optional additional error fields.
	*/
	constructor(message, fields) {
		super(message, fields);
		this.name = "StateGraphInputError";
		this.message = "Invalid StateGraph input. Make sure to pass a valid StateDefinition, Annotation.Root, or Zod schema.";
	}
	/**
	* The unminifiable (static, human-readable) error name for this error class.
	*/
	static get unminifiable_name() {
		return "StateGraphInputError";
	}
};
/**
* Used for subgraph detection.
*/
const getSubgraphsSeenSet = () => {
	if (globalThis[Symbol.for("LG_CHECKPOINT_SEEN_NS_SET")] === void 0) globalThis[Symbol.for("LG_CHECKPOINT_SEEN_NS_SET")] = /* @__PURE__ */ new Set();
	return globalThis[Symbol.for("LG_CHECKPOINT_SEEN_NS_SET")];
};
//#endregion
exports.BaseLangGraphError = BaseLangGraphError;
exports.EmptyChannelError = EmptyChannelError;
exports.EmptyInputError = EmptyInputError;
exports.GraphBubbleUp = GraphBubbleUp;
exports.GraphDrained = GraphDrained;
exports.GraphInterrupt = GraphInterrupt;
exports.GraphRecursionError = GraphRecursionError;
exports.GraphValueError = GraphValueError;
exports.InvalidUpdateError = InvalidUpdateError;
exports.MultipleSubgraphsError = MultipleSubgraphsError;
exports.NodeError = NodeError;
exports.NodeInterrupt = NodeInterrupt;
exports.NodeTimeoutError = NodeTimeoutError;
exports.ParentCommand = ParentCommand;
exports.RemoteException = RemoteException;
exports.StateGraphInputError = StateGraphInputError;
exports.UnreachableNodeError = UnreachableNodeError;
exports.getSubgraphsSeenSet = getSubgraphsSeenSet;
exports.isGraphBubbleUp = isGraphBubbleUp;
exports.isGraphDrained = isGraphDrained;
exports.isGraphInterrupt = isGraphInterrupt;
exports.isNodeError = isNodeError;
exports.isNodeTimeoutError = isNodeTimeoutError;
exports.isParentCommand = isParentCommand;

//# sourceMappingURL=errors.cjs.map