Skip to main content

Overview

The @standardagents/client package provides the core client library for Standard Agents. It’s a framework-agnostic foundation that @standardagents/react and @standardagents/vue build upon.

Key Features

  • HTTP client for all API operations
  • WebSocket connection management with auto-reconnection
  • File upload handling with thumbnail generation
  • Utility functions for workblocks and attachments
  • Zero framework dependencies

Installation

npm
pnpm
yarn
Most users should use @standardagents/react or @standardagents/vue instead, which re-export everything from this package with additional framework-specific features.

AgentBuilderClient

HTTP client for all Standard Agents API operations.

Methods

Configuration

ThreadSessionStore

ThreadSessionStore owns one thread session in @standardagents/client. It has no framework dependency. Each Vue or React provider owns a separate store. Authorized subscriptions remain separate.
getSnapshot() returns a stable snapshot until the next state change. It contains messages, committed files, run status, connection status, loading flags, pagination flags, and an error. subscribeEvents() receives custom thread event envelopes. Event data defaults to unknown. The store owns message upserts, chunks, optimistic sends, deletion rollback, and file events. It merges the newest message page after each reconnect. Recovery reads preserve existing messages and operation errors. Session epochs reject stale reads and command completions. File snapshots retain lifecycle events received during the read. An empty selection stays idle. stop() cancels the connection lifecycle. start() resumes a stopped store. dispose() removes its subscriptions. loadOlderMessages() loads an older page through a complete workblock boundary. loadMessagesByIds() loads explicit references. refresh() requests an explicit newest-page reconciliation. No method schedules a refresh timer. Vue refs and React’s useSyncExternalStore adapt this state for rendering. Framework adapters own upload queues, pending attachments, and display grouping.

Wire protocol

@standardagents/client/protocol defines the shared socket frames. Durable Objects, client adapters, and the admin UI import this module. It covers messages, custom thread events, logs, registry activity, files, KV changes, and effects. Chunk and run-status types reuse @standardagents/spec definitions. Portable message and attachment fields extend the spec declarations. Serialized attachment columns and optimistic preview URLs remain Builder extensions. Builder-specific frames remain runtime extensions. Existing frame names remain available from the client package root. Registry activity frames carry only changed fields. An omitted execution-state field retains its previous value. isLogStreamEvent() checks log-channel envelopes at the JSON boundary. Log patches retain an unknown payload by default. LogWebSocketCallbacks.onQueuedTools receives log_queued_tools frames.

ThreadConnectionManager

Manages WebSocket connections with automatic reconnection and heartbeat.

Connection features

  • Recovery uses exponential backoff with jitter.
  • Quiet sockets send stream_ping protocol keepalives.
  • onReconnected({ initial }) runs after each accepted open.
  • Repeated pre-open failures consult the application’s auth gate.
  • Disconnect invalidates pending sockets and auth decisions.

Options

FileUploadManager

Handles file uploads with thumbnail generation and progress tracking.

Features

  • Thumbnail generation: Automatic for image files
  • Progress tracking: Callbacks for upload progress
  • Deferred uploads: Returns pending refs before upload completes

Utility Functions

transformToWorkblocks

Groups tool calls with their results for UI rendering.

parseAttachments

Extract attachment references from message content.

Image Processing

File Helpers

Type Exports

The package exports all types needed for building clients:

Key Types

Message:
PendingAttachment:
AttachmentRef:
ConnectionStatus:

Authentication

The client reads auth tokens from localStorage:
You can also pass the token directly to the client:

Building Custom Integrations

Use @standardagents/client directly when:
  • Building for a framework without an official SDK
  • Creating custom tooling or CLI applications
  • Building server-side integrations
  • Needing fine-grained control over connections

Next Steps

React SDK

Full-featured React hooks and components

Vue SDK

Vue 3 composables and components

WebSocket API

WebSocket protocol documentation

REST API

REST API reference

Reconnect recovery

ThreadConnectionManager calls onReconnected({ initial }) after each successful open. The first open has initial: true. SDK providers read the newest message page on subsequent opens. When preload is enabled, a snapshot after the first socket open closes the initial subscription gap. reconcileMessages(current, snapshot, baseline, hasMore?) preserves mutations received during the read. hasMore: false marks a complete history snapshot.

Shared HTTP transport

Pass a fetch-compatible function as the second constructor argument. HTTP requests and WebSocket ticket requests will use this transport.

Shared live connections

LiveConnection owns one authorized subscription’s recovery. Its socket factory can use mintWebSocketUrl() with the application’s fetch transport. The lifecycle owns jittered backoff, quiet stream_ping keepalives, stale-socket guards, and auth gating. AuthReconnectSupervisor shares one auth probe across application channels. Registry, message, and privileged log subscriptions remain separate. AgentBuilderClient.connectLogWebSocket() connects to /threads/:id/logs. That subscription requires log-read authorization. A LiveConnection accepts a socket factory or a LiveConnectionUrlSource with a url(signal) function. URL sources resolve ticket exchange before socket construction. A retired URL result cannot create a socket. Existing raw-socket factories remain supported. Socket factories and URL sources receive an AbortSignal. SDK and admin adapters forward it to ticket exchange. Disconnect aborts that signal. The raw message and log connection methods accept signal in their options.