Build browser and Node agents with TypeScript¶
The TypeScript package provides actions, typed streams, sessions, transports, serialization, and LLM client utilities for browsers and Node.js. It uses the same wire records and lifecycle statuses as the Python and C++ runtimes.
All public symbols are available from one entry point:
Choose what you want to build¶
- Run actions and stream values when work lives in the page or a Node process.
- Connect sessions and transports when an action runs in another process or language.
- Build an LLM client to create interactions, expose actions as tools, and render live or stored turns.
- Call an A11 service from a browser for a complete HTTP SSE client and Python service.
- Let a model use tools in the browser for handlers that operate on page state.
API areas¶
| Area | Primary symbols |
|---|---|
| Actions | Action, ActionRegistry, ActionSchema |
| Streams | AsyncNode, NodeMap, Chunk |
| Connections | Session, WebSocketWireStream, HttpSseClientWireStream, WebRtcWireStream |
| Data | toChunk, fromChunk, SerializationRegistry |
| LLM clients | Interaction, ToolAdapter, PresentationReducer |
| Errors | Status, StatusCode, valueOrThrow |
Open the complete TypeScript API reference
Handle statuses at boundaries¶
Runtime methods return Status or StatusOr<T> so failures can cross workers,
transports, and language boundaries without losing their code or details.
Use isOk while composing operations. Use valueOrThrow at an application
boundary where exceptions fit the surrounding framework.
const node = valueOrThrow(await AsyncNode.create('answer'));
try {
valueOrThrow(await node.finalize({text: 'Ready'}));
} catch (error) {
if (error instanceof StatusException) {
console.error(StatusCode[error.status.code], error.status.message);
}
}
Action.signal is an AbortSignal for cooperative handler cancellation.
Cancelling an action also cancels its active nested actions and sends a remote
cancellation message for calls.