npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@standardagents/client

v0.15.3

Published

Framework-agnostic client for Standard Agents

Readme

@standardagents/client

Framework-agnostic client library for Standard Agents - provides HTTP/WebSocket communication, connection management, and shared utilities used by @standardagents/react and @standardagents/vue.

Installation

npm install @standardagents/client
# or
pnpm add @standardagents/client
# or
yarn add @standardagents/client

Note: Most users should use @standardagents/react or @standardagents/vue instead. This package is for advanced use cases or building custom framework integrations.

Quick Start

import { AgentBuilderClient, ThreadConnectionManager } from '@standardagents/client'

// Create a client
const client = new AgentBuilderClient('https://api.example.com')

// Fetch messages from a thread
const messages = await client.getMessages('thread-123')

// Send a message
await client.sendMessage('thread-123', {
  role: 'user',
  content: 'Hello!',
})

// Connect to live updates with automatic reconnection
const connection = new ThreadConnectionManager(client, 'thread-123', {
  onStatusChange: (status) => console.log('Status:', status),
  onMessage: (event) => console.log('New message:', event.data),
  onChunk: (event) => console.log('Streaming chunk:', event.chunk),
  onEvent: (event) => console.log('Custom event:', event.eventType, event.data),
})

connection.connect()

Authentication

The client reads the authentication token from localStorage using the key agentbuilder_auth_token:

// Set the token before making requests
localStorage.setItem('agentbuilder_auth_token', 'your-token-here')

All API requests and WebSocket connections will automatically include this token.

API Reference

AgentBuilderClient

HTTP client for the Standard Agents API.

Constructor

const client = new AgentBuilderClient(endpoint: string)

Methods

getEndpoint(): string

Returns the configured endpoint URL.

createThread(payload): Promise<Thread>

Create a new thread.

const thread = await client.createThread({
  agent_id: 'my-agent',
  user_id: 'user-123', // optional
})
getThread(threadId): Promise<Thread>

Get thread metadata.

const thread = await client.getThread('thread-123')
getMessages(threadId, options?): Promise<Message[]>

Fetch messages from a thread.

const messages = await client.getMessages('thread-123', {
  limit: 50,
  offset: 0,
  depth: 0,
  includeSilent: false,
})

Use getMessagesPage() when you need pagination metadata, or pass ids to hydrate specific messages. includeWorkblocks expands requested tool-call messages to the complete workblock they belong to.

sendMessage(threadId, payload): Promise<Message>

Send a message to a thread.

const message = await client.sendMessage('thread-123', {
  role: 'user',
  content: 'Hello!',
  silent: false, // optional
})
stopExecution(threadId): Promise<void>

Cancel an in-flight execution.

await client.stopExecution('thread-123')
connectMessageWebSocket(threadId, callbacks?, options?): WebSocket

Create a WebSocket connection for streaming messages.

const ws = client.connectMessageWebSocket('thread-123', {
  onOpen: () => console.log('Connected'),
  onMessage: (event) => console.log('Message:', event),
  onChunk: (event) => console.log('Chunk:', event),
  onError: (event) => console.error('Error:', event),
  onClose: (event) => console.log('Closed:', event),
}, {
  includeSilent: false,
  depth: 0,
})
connectLogWebSocket(threadId, callbacks?): WebSocket

Create a WebSocket connection for log events and custom events.

const ws = client.connectLogWebSocket('thread-123', {
  onOpen: () => console.log('Connected'),
  onLog: (event) => console.log('Log:', event),
  onCustom: (event) => console.log('Custom:', event),
  onStopped: (event) => console.log('Stopped:', event),
  onClose: (event) => console.log('Closed:', event),
})

ThreadConnectionManager

Manages WebSocket connections with automatic reconnection and heartbeat.

Constructor

const manager = new ThreadConnectionManager(
  client: AgentBuilderClient,
  threadId: string,
  callbacks?: ThreadConnectionCallbacks,
  options?: ThreadConnectionOptions
)

Callbacks:

  • onStatusChange?: (status: ConnectionStatus) => void - Called when connection status changes
  • onMessage?: (event: MessageDataEvent) => void - Called when a complete message is received
  • onChunk?: (event: MessageChunkEvent) => void - Called when a streaming chunk is received
  • onEvent?: (event: ThreadEvent) => void - Called when a custom event is received
  • onError?: (error: Error | Event) => void - Called on connection errors

Options:

  • depth?: number - Message depth level (default: 0)
  • includeSilent?: boolean - Include silent messages (default: false)
  • maxReconnectDelay?: number - Max reconnection delay in ms (default: 30000)
  • heartbeatInterval?: number - Heartbeat interval in ms (default: 30000)

Methods

connect(): void

Establish the WebSocket connection.

disconnect(): void

Close the connection and stop reconnection attempts.

getStatus(): ConnectionStatus

Returns the current connection status: 'connecting' | 'connected' | 'reconnecting' | 'disconnected'

getThreadId(): string

Returns the thread ID.

updateCallbacks(callbacks): void

Update callbacks after construction.

updateOptions(options): void

Update options after construction.

Reconnection Behavior

The connection manager automatically reconnects on unexpected disconnections using exponential backoff:

  • Initial delay: 1 second
  • Doubles each attempt: 1s, 2s, 4s, 8s, 16s
  • Maximum delay: 30 seconds (configurable)
  • Resets to 1s after successful connection

transformToWorkblocks(messages): ThreadMessage[]

Groups tool calls with their results into workblock structures for easier UI rendering.

import { transformToWorkblocks } from '@standardagents/client'

const messages = await client.getMessages('thread-123')
const workblocks = transformToWorkblocks(messages)

// Each workblock contains:
// - type: 'workblock'
// - workItems: array of tool calls and results
// - log_ids: log IDs for LLM requests represented by the block
// - status: 'pending' | 'completed'

Types

import type {
  Message,
  WorkMessage,
  WorkItem,
  ThreadMessage,
  Thread,
  SendMessagePayload,
  GetMessagesOptions,
  CreateThreadPayload,
  ConnectionStatus,
  ThreadConnectionCallbacks,
  ThreadConnectionOptions,
} from '@standardagents/client'

Message Types

interface Message {
  id: string
  role: 'user' | 'assistant' | 'system' | 'tool'
  content: string | null
  created_at: number // microseconds
  reasoning_content?: string | null
  silent?: boolean
  depth?: number
  tool_calls?: string // JSON string
  tool_call_id?: string
}

interface WorkMessage {
  type: 'workblock'
  id: string
  content: string | null
  reasoning_content?: string | null
  status: 'pending' | 'completed'
  workItems: WorkItem[]
  log_ids?: string[]
  created_at: number
  depth?: number
}

interface WorkItem {
  id: string
  type: 'tool_call' | 'tool_result'
  name: string
  input?: string
  content?: string
  status: 'success' | 'error' | null
  tool_call_id?: string
  log_id?: string | null
}

type ThreadMessage = Message | WorkMessage

Local Development

# Install dependencies
pnpm install

# Build package
pnpm build

# Watch mode
pnpm dev

# Type check
pnpm typecheck

# Run tests
pnpm test