import { ClientTool, DynamicStructuredTool, ServerTool, StructuredToolInterface } from "@langchain/core/tools"; import { ChatModelStream, GraphRunStream, LifecycleCause, StreamTransformer, ToolCallStream } from "@langchain/langgraph"; //#region src/agents/transformers/types.d.ts /** * Infers the merged extensions shape from a tuple of stream transformer * factories. * * 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 nested named-agent execution surfaced on `run.subagents`. * * A subagent is a nested `createAgent` run whose `lc_agent_name` differs from * its parent's — e.g. a `createAgent({ name })` invoked inside a tool body. The * handle exposes scoped projections (`messages`, `toolCalls`, nested * `subagents`) plus the resolved {@link name}, the {@link cause} that triggered * it, and the subagent's final {@link output} state. * * This is a self-contained handle (no subclass of `SubgraphRunStream`): its * projections are produced by per-subagent transformer instances that * {@link createSubagentTransformer} drives directly. * * @typeParam TValues - Shape of the subagent's final output state. * @typeParam TTools - Tuple of tools the subagent may call, used to type * {@link toolCalls}. */ interface SubagentRunStream, TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[]> { /** The subagent's `lc_agent_name` (set by `createAgent({ name })`). */ readonly name: string; /** * The tool call that dispatched this subagent, as * `{ type: "toolCall", tool_call_id }`, or `undefined` when the originating * tool call could not be recovered (e.g. it was not triggered from a tool). */ readonly cause: LifecycleCause | undefined; /** Resolves with the subagent's final state once it completes. */ readonly output: Promise; /** Per-message chat-model token streams scoped to this subagent. */ readonly messages: AsyncIterable>; /** The subagent's own tool-call streams. */ readonly toolCalls: AsyncIterable>; /** Nested subagents this subagent dispatches from its own tools. */ readonly subagents: AsyncIterable; } /** * 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 TExtensions - Shape of `run.extensions` produced by user-supplied * stream transformer factories. Derived via * `InferStreamExtensions`. */ type AgentRunStream, TTools extends readonly (ClientTool | ServerTool)[] = readonly (ClientTool | ServerTool)[], TExtensions extends Record = Record> = GraphRunStream & { /** Tool call streams from the native ToolCallTransformer. */toolCalls: AsyncIterable>; /** * Named subagent runs dispatched from tools, surfaced by the native * {@link createSubagentTransformer}. Each yielded {@link SubagentRunStream} * is a nested `createAgent` run whose `lc_agent_name` differs from this * agent's — for example a `createAgent({ name })` invoked inside a tool body. * Unlike `run.subgraphs` (which also yields the agent's own internal nodes), * `run.subagents` only yields real named-agent invocations. */ subagents: AsyncIterable>; }; //#endregion export { AgentRunStream, InferStreamExtensions, SubagentRunStream, ToolCallStreamUnion }; //# sourceMappingURL=types.d.ts.map