import { ClientTool, DynamicStructuredTool, ServerTool, StructuredToolInterface } from "@langchain/core/tools";
import { GraphRunStream, Namespace, NativeStreamTransformer, StreamTransformer, ToolCallStream } from "@langchain/langgraph";

//#region src/agents/stream.d.ts
/**
 * Infers the merged extensions shape from a tuple of stream transformer
 * factories. Mirrors `InferExtensions` from `@langchain/langgraph`, which
 * is not exported from the package's public surface.
 *
 * Given `[() => StreamTransformer<{ a: number }>, () => StreamTransformer<{ b: string }>]`,
 * produces `{ a: number } & { b: string }`.
 */
type InferStreamExtensions<T extends ReadonlyArray<() => StreamTransformer<any>>> = T extends readonly [] ? Record<string, never> : T extends readonly [() => StreamTransformer<infer P>, ...infer Rest extends ReadonlyArray<() => StreamTransformer<any>>] ? P & InferStreamExtensions<Rest> : Record<string, unknown>;
/** Extract the literal `name` string from a tool type. */
type ToolNameOf<T> = T extends {
  name: infer N extends string;
} ? N : string;
/** Extract the parsed input type from a tool type. */
type ToolInputOf<T> = T extends DynamicStructuredTool<any, any, infer SchemaInputT, any, any, any> ? SchemaInputT : T extends StructuredToolInterface<any, infer SchemaInputT, any> ? SchemaInputT : unknown;
/** Extract the return/output type from a tool type. */
type ToolOutputOf<T> = T extends DynamicStructuredTool<any, any, any, infer ToolOutputT, any, any> ? ToolOutputT : T extends StructuredToolInterface<any, any, infer ToolOutputT> ? ToolOutputT : unknown;
/**
 * Discriminated union of {@link ToolCallStream} variants, one per tool
 * in `TTools`.  Enables TypeScript to narrow `.input` and `.output`
 * when the consumer checks `call.name === "someToolName"`.
 *
 * Falls back to `ToolCallStream` (untyped) when the tools tuple is a
 * plain `(ClientTool | ServerTool)[]` without literal name types.
 */
type ToolCallStreamUnion<TTools extends readonly (ClientTool | ServerTool)[]> = { [K in keyof TTools]: ToolCallStream<ToolNameOf<TTools[K]>, ToolInputOf<TTools[K]>, ToolOutputOf<TTools[K]>> }[number];
/**
 * A {@link GraphRunStream} with native agent-level projections assigned
 * directly on the instance by `createGraphRunStream` (via `__native`
 * transformers).
 *
 * This is a pure type overlay — no runtime subclass exists.  Use the
 * `AgentRunStream` type when you need to describe the return type of
 * `streamEvents(..., { version: "v3" })`.
 *
 * @typeParam TValues - Shape of the graph's state values.
 * @typeParam TTools - Tuple of tools registered on the agent, used to type
 *   the per-tool `toolCalls` discriminated union.
 * @typeParam TMiddleware - Tuple of middleware registered on the agent, used
 *   to type the per-middleware `middleware` event union.
 * @typeParam TExtensions - Shape of `run.extensions` produced by user-supplied
 *   stream transformer factories. Derived via
 *   `InferExtensions<TStreamTransformers>`.
 */
type AgentRunStream<TValues = Record<string, unknown>, TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TExtensions extends Record<string, unknown> = Record<string, unknown>> = GraphRunStream<TValues, TExtensions> & {
  /** Tool call streams from the native ToolCallTransformer. */toolCalls: AsyncIterable<ToolCallStreamUnion<TTools>>;
};
interface ToolCallProjection {
  toolCalls: AsyncIterable<ToolCallStream>;
}
/**
 * Creates a native transformer that correlates `tools` channel events
 * into per-call {@link ToolCallStream} objects.
 *
 * Marked `__native: true` — projection keys land directly on the
 * `GraphRunStream` instance as `run.toolCalls`.
 */
declare function createToolCallTransformer(path: Namespace): () => NativeStreamTransformer<ToolCallProjection>;
//#endregion
export { AgentRunStream, InferStreamExtensions, ToolCallStreamUnion, createToolCallTransformer };
//# sourceMappingURL=stream.d.cts.map