import { DefaultToolCall, InferToolOutput, ToolCallFromTool } from "../types.messages.cjs";
import { AssembledToolCall } from "../client/stream/handles/tools.cjs";
import { AgentTypeConfigLike, CompiledSubAgentLike, DeepAgentTypeConfigLike, DefaultSubagentStates, ExtractAgentConfig, ExtractDeepAgentConfig, ExtractSubAgentMiddleware, InferAgentToolCalls, InferDeepAgentSubagents, InferSubagentByName, InferSubagentNames, InferSubagentState, IsAgentLike, IsDeepAgentLike, SubAgentLike, SubagentStateMap, SubagentToolCall } from "../ui/types.cjs";
import { InferBag, InferNodeNames, InferStateType as InferStateType$1, InferSubagentStates as InferSubagentStates$1, InferToolCalls as InferToolCalls$1 } from "../ui/stream/index.cjs";
import { BaseMessage } from "@langchain/core/messages";

//#region src/stream/types-inference.d.ts
/** @internal Map a {@link ToolCallFromTool} message shape to {@link AssembledToolCall}. */
type AssembledToolCallFromToolCall<TCall extends {
  name: string;
  args: Record<string, unknown>;
}, TOutput = unknown> = TCall extends {
  name: infer N;
  args: infer A;
} ? N extends string ? A extends Record<string, any> ? AssembledToolCall<N, A, TOutput> : never : never : never;
/**
 * Infer the streaming {@link AssembledToolCall} handle for a single
 * LangChain tool.
 *
 * Parallel to {@link ToolCallFromTool} for message-level tool calls —
 * use this when a component receives one entry from `stream.toolCalls`
 * and you know which tool definition it came from.
 *
 * @example
 * ```ts
 * const searchWeb = tool(/* ... *\/);
 *
 * function SearchWebCall({ toolCall }: {
 *   toolCall: AssembledToolCallFromTool<typeof searchWeb>;
 * }) {
 *   // toolCall.name is "search_web", args/input are schema-inferred
 * }
 *
 * v1 framework packages (`@langchain/react`, `@langchain/vue`, etc.) re-export
 * this type as {@link ToolCallFromTool}. {@link AssembledToolCall.output} is
 * `null` until the call succeeds; use {@link status} / {@link error} for UI.
 * ```
 */
type AssembledToolCallFromTool<T> = AssembledToolCallFromToolCall<ToolCallFromTool<T>, InferToolOutput<T>>;
/** @internal Resolve a tool definition's registered name. */
type ToolNameOf<T> = T extends {
  name: infer N extends string;
} ? N : T extends {
  tool: {
    name: infer N extends string;
  };
} ? N : never;
/** @internal Look up the return type of a tool in a tuple by its `name`. */
type MatchedToolOutput<Tools extends readonly unknown[], N extends string> = Tools extends readonly [infer First, ...infer Rest] ? ToolNameOf<First> extends N ? InferToolOutput<First> : MatchedToolOutput<Rest, N> : unknown;
/**
 * @internal Bridge a message-level tool-call shape from {@link InferToolCallsFromUi}
 * to a streaming {@link AssembledToolCall}, resolving `output` from the agent's
 * declared tool list.
 */
type AssembledFromMessageToolCall<TC extends {
  name: string;
  args: Record<string, unknown>;
}, Tools extends readonly unknown[]> = TC extends {
  name: infer N;
} ? N extends string ? AssembledToolCallFromToolCall<TC, MatchedToolOutput<Tools, N>> : AssembledToolCall : AssembledToolCall;
/**
 * Unwrap the state shape from a compiled graph, a create-agent brand,
 * or a plain type. Used by `useStream<T>()` to resolve `T = typeof
 * agent` into the state the `values`/`messages` projections observe.
 *
 * Structurally identical to the legacy
 * `@langchain/langgraph-sdk/ui` helper of the same name; kept here as
 * a framework-facing re-export so bindings can import from the
 * stream subpath without needing the UI module.
 */
type InferStateType<T> = InferStateType$1<T>;
/**
 * Infer the discriminated union of {@link AssembledToolCall} handles
 * from an agent brand, an array of LangChain tools, or fall back to the
 * untyped default handle.
 *
 * Pass `typeof agent` or `typeof tools` and narrow on `name` / `args`
 * (aliases for `input`) in tool-call UI components.
 */
type InferToolCalls<T> = T extends readonly unknown[] ? AssembledToolCallFromTool<T[number]> : ExtractAgentConfig<T>["Tools"] extends infer Tools extends readonly unknown[] ? InferToolCalls$1<T> extends infer TC ? TC extends {
  name: string;
  args: Record<string, unknown>;
} ? AssembledFromMessageToolCall<TC, Tools> : AssembledToolCall : AssembledToolCall : AssembledToolCall;
/**
 * Infer the subagent → state map from a DeepAgent brand. Non-brands
 * collapse to {@link DefaultSubagentStates}.
 */
type InferSubagentStates<T> = InferSubagentStates$1<T>;
/**
 * Widen an update type so its `messages` field also accepts
 * `@langchain/core` {@link BaseMessage} class instances (single or
 * array). Framework bindings apply this to `submit()` so callers can
 * write `stream.submit({ messages: [new HumanMessage("hi")] })`.
 *
 * Port of the legacy `AcceptBaseMessages<T>` helper; the public name
 * matches the v1 spec in `plan-types.md` §8.
 */
type WidenUpdateMessages<T> = T extends Record<string, unknown> ? { [K in keyof T]: K extends "messages" ? T[K] | BaseMessage | BaseMessage[] : T[K] } : T;
//#endregion
export { AssembledToolCallFromTool, InferStateType, InferSubagentStates, InferToolCalls, WidenUpdateMessages };
//# sourceMappingURL=types-inference.d.cts.map