import { UseStreamReturn } from "./use-stream.cjs"; import { BaseMessage } from "@langchain/core/messages"; import { AssembledToolCall, AudioMedia, Channel, ChannelProjectionOptions, Event, FileMedia, ImageMedia, InferStateType, InferToolCalls, MessageMetadata, SubagentDiscoverySnapshot, SubgraphDiscoverySnapshot, SubmissionQueueEntry, SubmissionQueueSnapshot, VideoMedia } from "@langchain/langgraph-sdk/stream"; //#region src/selectors.d.ts /** * Selector hooks don't need to carry `InterruptType` / * `ConfigurableType` — they only ever read state. Accepting a * `StateType`-parameterised stream (with the other two generics * widened to `any`) lets callers keep their full * `useStream()` handle * without re-declaring the interrupt / configurable shapes at every * selector call site. */ type StreamHandle = UseStreamReturn; /** * What a selector hook can be targeted at. Callers can pass any of: * - `undefined` — root namespace (cheap: served by the always-on root store) * - a {@link SubagentDiscoverySnapshot} — the snapshot returned by `stream.subagents.get(...)` * - a {@link SubgraphDiscoverySnapshot} — the snapshot returned by `stream.subgraphs.get(...)` * - an explicit `{ namespace: string[] }` — any other namespaced scope * - a raw `string[]` — escape hatch identical to the object form */ type SelectorTarget = undefined | null | readonly string[] | { namespace: readonly string[]; } | SubagentDiscoverySnapshot | SubgraphDiscoverySnapshot; type AnyStream = UseStreamReturn; /** * Subscribe to a scoped `messages` stream. Pass `stream` and * optionally a subagent/subgraph snapshot (or any namespaced target). * * Contract: * - At the root (no target) this returns `stream.messages` directly * — no extra subscription is opened. `stream.messages` is the * live merge of `messages`-channel token deltas and * `values.messages` snapshots (see * {@link UseStreamReturn.messages}), so token-by-token * streaming here depends on the backend emitting `messages` * channel events. Backends that only emit `values` updates will * render full turns at once rather than streaming. * - For any other namespace, the mount triggers a ref-counted * `messages` subscription scoped to that namespace. Unmounting * the last component that watches this namespace closes the * subscription automatically. * * Messages are always `BaseMessage` class instances from * `@langchain/core/messages`. */ declare function useMessages(stream: AnyStream, target?: SelectorTarget): BaseMessage[]; /** * Subscribe to a scoped `tools` (tool-call) stream. Same target and * lifecycle rules as {@link useMessages}; at the root this just returns * `stream.toolCalls`. * * The optional generic `T` can be passed to narrow the type of * assembled tool calls on the returned array. Accepts either: * - an agent brand (`typeof agent`) — union is derived from the * agent's declared tools via {@link InferToolCalls}; * - an array of LangGraph tools (`typeof tools`) — union is derived * from {@link InferToolCalls} (parallel to {@link ToolCallsFromTools}). * * When omitted, returns the plain `AssembledToolCall[]` union used by * the controller. */ declare function useToolCalls(stream: AnyStream, target?: SelectorTarget): AssembledToolCall[]; declare function useToolCalls(stream: AnyStream, target?: SelectorTarget): InferToolCalls[]; /** * Subscribe to a scoped `values` stream — most-recent state payload * for a namespace. Equivalent to reading `stream.values` at the root. * * When the payload carries a `messages` array, it is coerced to * `BaseMessage` instances to keep parity with the root projection. * * Typing: * - **Root** (`useValues(stream)`): returns the `StateType` declared * on the parent `useStream()` — no explicit * generic required. Non-nullable because the root snapshot always * carries `values` (falling back to `initialValues ?? {}`). * - **Scoped** (`useValues(stream, target)`): the scoped payload can * have a different shape than the root state (e.g. a subagent * returning its own substate). Callers should annotate the * expected shape explicitly: `useValues(stream, sub)`. * Defaults to `unknown` when not annotated. */ declare function useValues(stream: StreamHandle): StateType; /** * Explicit-generic override. Accepts: * - an agent brand or compiled graph (unwrapped via * {@link InferStateType}); * - a plain state shape (returned as-is). * * The root-call form is non-nullable (the root snapshot is always * present); the scoped form returns `T | undefined` because a * projection may not have emitted a payload yet. */ declare function useValues(stream: AnyStream): InferStateType; declare function useValues(stream: AnyStream, target: SelectorTarget, options?: { messagesKey?: string; }): T | undefined; /** * Subscribe to a `custom:` stream extension — most-recent * payload emitted by the transformer, scoped to the target namespace. */ declare function useExtension(stream: AnyStream, name: string, target?: SelectorTarget): T | undefined; /** * Raw-events escape hatch. Subscribes to one or more channels at a * namespace and returns a bounded buffer of raw protocol events. * Prefer {@link useMessages} / {@link useToolCalls} / {@link useValues} * for the common cases. */ /** * Subscribe to a scoped audio-media stream. Returns an array of * {@link AudioMedia} handles, one per message containing at least one * `AudioBlock` in the target namespace. * * Each handle is yielded on its first matching `content-block-start`, * exposes `.partialBytes` for live access, settles `.blob` / * `.objectURL` / `.transcript` on `message-finish`, and surfaces * fail-loud errors via `.error`. * * Pair with {@link useMediaURL} to turn a handle into an `