import { ... } from "@langchain/langgraph-sdk/stream";Convenience: given the raw assembled message + the role captured
from message-start, produce a BaseMessage with the same id.
Produce a BaseMessage class instance from an in-progress or
finished assembled message. Safe to call repeatedly across deltas —
each call returns a new instance whose content reflects the
currently-observed blocks.
Ref-counted, thread-aware projection registry.
Owns the spec.key → (store, runtime) mapping for one
StreamController. Lifecycle:
acquire(spec) → +1 ref, returns { store, release }. The
first acquire opens the projection's runtime; subsequent
acquires for the same key share both the store and the
runtime.release() → -1 ref. When the last consumer releases,
the entry is removed and its runtime disposed.bind(thread) → swap or detach the underlying thread; every
live entry's runtime is recreated against the new thread,
keeping the same store identity.dispose() → tear everything down (idempotent). Safe to
call multiple times.The registry is intentionally not generic over a state shape —
different consumers can hold projections producing different
snapshot types, so the registry keys everything as unknown and
lets acquire reapply the caller's T at the boundary.
Coordinates one thread's protocol-v2 stream and exposes stable observable projections for framework bindings.
The controller owns the root subscription, lazily binds scoped projections through ChannelRegistry, and normalizes protocol events into class-message, tool-call, discovery, interrupt, and queue stores.
Typed error thrown through media.stream / rejected from
media.blob / media.objectURL when a handle fails before its
message completes. Carries the bytes accumulated up to the failure
point on partialBytes for callers that want to salvage or diagnose.
Handle returned by ChannelRegistry.acquire. Framework bindings
use store as the reactivity source and must call release() when
the consumer tears down.
Agent-server branch: caller points useStream at an assistant on a
LangGraph-Platform-compatible server. Discriminated against
CustomAdapterOptions by transport being absent or a string.
Assembled view of a single tool call lifecycle (tool-started →
optional tool-output-delta → tool-finished | tool-error).
Mirrors the in-process ToolCallStream interface so that remote
consumers get the same ergonomics.
Custom-adapter branch: caller brings their own
AgentServerAdapter. Discriminated against
AgentServerOptions by transport being an adapter instance.
Metadata tracked per message id. Surfaced to applications via
useMessageMetadata(stream, messageId).
A projection spec describes a single logical subscription managed
by the ChannelRegistry. Framework bindings don't construct
these directly — the per-kind factory functions in
stream/projections/ emit them.
Read-only fan-out of the StreamController's always-on root subscription. Projections that only need a subset of the root pump's channels at the root namespace can attach here instead of opening a second server subscription.
Always-on root snapshot surfaced by StreamController.rootStore.
Populated by a single multi-channel subscription at the thread root
(values, lifecycle, input, messages, tools). Every app
pays for this — selector hooks for scoped projections layer on top.
Lightweight discovery record for a subagent running inside the thread.
Populated eagerly from the root subscription (tools + lifecycle
channels). Content projections (messages, toolCalls, custom
extensions) are opened lazily via selector hooks, keyed on
namespace.
Lightweight discovery record for a subgraph running inside the thread.
Queued submission entry mirrored from the server-side run queue.
Surfaces the deferred submission to UI consumers via StreamController.queueStore.
Options common to both transport branches of framework useStream APIs.
Public v1 name for TransportAdapter plus optional high-level
capabilities. Renamed to reflect that this interface now denotes the
full agent-server protocol contract (not merely wire transport):
any object that satisfies it can back a useStream call. See
plan-custom-transport.md §4 for the rollout.
The extra optional methods let adapters surface thread state and
history without the framework needing to issue a parallel HTTP
request — useStream.hydrate() calls getState?() when present
and falls back to client.threads.getState otherwise. Adapters
that don't know how to produce these values can simply omit them.
The legacy TransportAdapter export is retained for back-compat and
resolves to the same structural type; new code should prefer
AgentServerAdapter.
Minimal interface matching the structure of AgentTypeConfig from @langchain/langgraph. This allows type inference from ReactAgent without requiring the langchain dependency.
Shared surface across every media handle returned by MediaAssembler.
The handle is live while its parent message is active:
partialBytes is a snapshot of all bytes received so far.stream is a lazy, single-consumer byte stream (see
accessor docstring).blob / objectURL settle on message-finish.error becomes set if the handle terminates in any of the
MediaAssemblyErrorKind failure modes.Minimal interface matching the structure of a CompiledSubAgent from deepagents. Used for structural type matching without importing deepagents.
Minimal interface matching the structure of DeepAgentTypeConfig from deepagents. Extends AgentTypeConfigLike to include subagent type information.
Shared surface across every media handle returned by MediaAssembler.
The handle is live while its parent message is active:
partialBytes is a snapshot of all bytes received so far.stream is a lazy, single-consumer byte stream (see
accessor docstring).blob / objectURL settle on message-finish.error becomes set if the handle terminates in any of the
MediaAssemblyErrorKind failure modes.Shared surface across every media handle returned by MediaAssembler.
The handle is live while its parent message is active:
partialBytes is a snapshot of all bytes received so far.stream is a lazy, single-consumer byte stream (see
accessor docstring).blob / objectURL settle on message-finish.error becomes set if the handle terminates in any of the
MediaAssemblyErrorKind failure modes.Dispatch callbacks receive a freshly-started handle on its first
matching content-block-start. Exactly one callback fires per
(messageId, blockType) pair.
Dispatch callbacks receive a freshly-started handle on its first
matching content-block-start. Exactly one callback fires per
(messageId, blockType) pair.
Shared surface across every media handle returned by MediaAssembler.
The handle is live while its parent message is active:
partialBytes is a snapshot of all bytes received so far.stream is a lazy, single-consumer byte stream (see
accessor docstring).blob / objectURL settle on message-finish.error becomes set if the handle terminates in any of the
MediaAssemblyErrorKind failure modes.Minimal interface matching the structure of a SubAgent from deepagents. Used for structural type matching without importing deepagents.
Represents a tool call that initiated a subagent.
Transport abstraction implemented by concrete client transports such as WebSocket or SSE adapters.
In the thread-centric protocol, transports are bound to a specific thread at construction time — the thread ID is part of the connection URL.
Shared surface across every media handle returned by MediaAssembler.
The handle is live while its parent message is active:
partialBytes is a snapshot of all bytes received so far.stream is a lazy, single-consumer byte stream (see
accessor docstring).blob / objectURL settle on message-finish.error becomes set if the handle terminates in any of the
MediaAssemblyErrorKind failure modes.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.
Infer the subagent → state map from a DeepAgent brand. Non-brands collapse to DefaultSubagentStates.
Infer the discriminated union of tool call shapes from an input that
may be an agent brand, an array of LangGraph tools, or a direct
DefaultToolCall shape.
See InferToolCallsFromUi for the full resolution table.
Read-only map exposed via MessageMetadataTracker.store.
Minimal observable store backing every framework binding.
The shape is intentionally tiny:
subscribe(listener) → unsubscribe lines up with React's
useSyncExternalStore.getSnapshot() returns a referentially-stable value for
unchanged state so React can bail out of renders.subscribe + getSnapshot in
their own reactivity primitive (shallowRef / writable /
signal) in ~10 lines.Snapshot identity matters: a listener is only useful if
getSnapshot() returns a different reference when state changes.
Callers MUST pass a freshly-constructed value to setState;
mutating the previous snapshot in place will break React's bail-out
and cause infinite re-renders.
Read-only snapshot of the queue. The queue store hands this out directly; consumers must not mutate the array.
Anything with a namespace can be passed to selector hooks as a
scope target. Both SubagentDiscoverySnapshot and
SubgraphDiscoverySnapshot satisfy this; callers can also
hand-build { namespace: [...] } objects.
High-level outcome of a single tool call.
Options accepted by framework useStream APIs. Discriminated on the
shape of transport:
"sse" / "websocket") -> agent-server branch
(AgentServerOptions); supply assistantId + apiUrl.Widen an update type so its messages field also accepts
@langchain/core 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.
Default subagent state map used when no specific subagent types are provided. Maps any string key to Record<string, unknown>.
Default tool call type when no specific tool definitions are provided.
Extract the AgentTypeConfig from an agent-like type.
Extract the DeepAgentTypeConfig from a DeepAgent-like type.
Helper type to extract middleware from a SubAgent definition. Handles both mutable and readonly middleware arrays.
Extract tool calls type from an agent's tools. Converts the tools array to a discriminated union of tool calls.
This handles both tuple types (e.g., readonly [Tool1, Tool2]) and
array-of-union types (e.g., readonly (Tool1 | Tool2)[]) which is how
createAgent captures tool types.
Infer the Bag type from an agent, defaulting to the provided Bag.
Currently returns the provided Bag for all types. Can be extended in the future to extract Bag from agent types.
Extract the Subagents array type from a DeepAgent.
Infer the node names from a compiled graph.
Extracts the ~NodeType phantom property from CompiledGraph instances,
providing a union of all node names defined in the graph.
Helper type to extract a subagent by name from a DeepAgent.
Extract all subagent names as a string union from a DeepAgent.
Infer the state type for a specific subagent by extracting and merging its middleware state schemas, plus the base agent state (messages).
Check if a type is agent-like (has ~agentTypes phantom property).
This property is present on ReactAgent instances created with createAgent.
Check if a type is a DeepAgent (has ~deepAgentTypes phantom property).
This property is present on DeepAgent instances created with createDeepAgent.
Kinds of failure that can terminate a media handle prematurely.
"message-error" — the upstream message emitted an error event
before completion."stream-closed" — the transport stream closed before
message-finish arrived (thread closed, transport dropped, etc.)."fetch-failed" — the block was url-sourced and the lazy
fetch() rejected (CORS, 404, 5xx, network).Block types this assembler knows how to reassemble into media handles.
Create a map of subagent names to their state types.
This is useful for type-safe getSubagentsByType calls.
Infer a tool call type from a single tool.
Works with tools created via tool() from @langchain/core/tools.
For DynamicStructuredTool, this extracts the input type from the _call method, which is the most reliable source as it's the pre-computed input type.
Legacy alias shared by the framework bindings. Unwraps a compiled graph or agent brand into its state shape.