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 StreamTransformer>> = T extends readonly [] ? Record : T extends readonly [() => StreamTransformer, ...infer Rest extends ReadonlyArray<() => StreamTransformer>] ? P & InferStreamExtensions : Record; /** Extract the literal `name` string from a tool type. */ type ToolNameOf = T extends { name: infer N extends string; } ? N : string; /** Extract the parsed input type from a tool type. */ type ToolInputOf = T extends DynamicStructuredTool ? SchemaInputT : T extends StructuredToolInterface ? SchemaInputT : unknown; /** Extract the return/output type from a tool type. */ type ToolOutputOf = T extends DynamicStructuredTool ? ToolOutputT : T extends StructuredToolInterface ? 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 = { [K in keyof TTools]: ToolCallStream, ToolInputOf, ToolOutputOf> }[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`. */ type AgentRunStream, TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TExtensions extends Record = Record> = GraphRunStream & { /** Tool call streams from the native ToolCallTransformer. */toolCalls: AsyncIterable>; }; interface ToolCallProjection { toolCalls: AsyncIterable; } /** * 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; //#endregion export { AgentRunStream, InferStreamExtensions, ToolCallStreamUnion, createToolCallTransformer }; //# sourceMappingURL=stream.d.ts.map