Overview
The@standardagents/react package provides React hooks and components for building UIs that connect to AgentBuilder threads. It handles real-time message streaming, custom event listening, and workblock transformation for tool visualization.
Key Features
- Real-time WebSocket updates for live message streaming
- Context-based architecture with
ThreadProvider - Workblock transformation for UI-friendly tool displays
- Custom event system for backend-to-frontend communication
- File uploads and attachments for sending images to the LLM
- TypeScript support with full type definitions
- Works with any React framework (Next.js, Remix, Vite, etc.)
Installation
npm
pnpm
yarn
Quick Start
Core Providers
AgentBuilderProvider
Root provider that configures the API endpoint for all child components.| Prop | Type | Required | Description |
|---|---|---|---|
config.endpoint | string | Yes | The API endpoint URL |
children | ReactNode | Yes | Child components |
ThreadProvider
Establishes a WebSocket connection to a specific thread and provides context for child components.| Prop | Type | Default | Description |
|---|---|---|---|
threadId | string | Required | The thread ID to connect to |
preload | boolean | true | Fetch existing messages on mount |
live | boolean | true | Enable WebSocket for live updates |
useWorkblocks | boolean | false | Transform tool calls into workblocks |
depth | number | 0 | Max message depth (0 = top-level only) |
includeSilent | boolean | false | Include silent messages |
endpoint | string | - | Override endpoint from AgentBuilderProvider |
Hooks
useThread
Hook to access the full thread context. Must be used within aThreadProvider.
Method Reference
sendMessage
Send a message to the thread. Automatically includes any pending attachments and clears them after sending.sendMessage(), an optimistic message with attachment previews is shown immediately. The real message replaces it when confirmed by the server via WebSocket.
addAttachment
Queue file(s) to be sent with the next message. Files are NOT uploaded immediately - they’re held locally with preview URLs and sent inline (base64) whensendMessage() is called.
Use this for images/files that should be sent directly to the LLM.
removeAttachment
Remove a pending attachment before sending.clearAttachments
Remove all pending attachments.addFiles
Upload files to the thread’s filesystem. Files are uploaded immediately and stored persistently. Use this for documents/files that should be stored on the thread but NOT sent directly to the LLM.removeFile
Remove a pending file upload (cannot remove already committed files).File URL Helpers
stopExecution
Stop the current agent execution.deleteMessage
Delete a message from the thread. The message is optimistically removed from the UI immediately. If the server request fails, the message is restored.onEvent / subscribeToEvent
Subscribe to custom events emitted by the agent.addFiles vs addAttachment
| Feature | addFiles() | addAttachment() |
|---|---|---|
| Purpose | Filesystem storage | Send to LLM |
| Upload timing | Immediate | On sendMessage() |
| Storage | Thread filesystem (persistent) | Inline base64 |
| Image processing | None (raw storage) | Server-side resize/optimize |
| Use case | Documents, persistent files | Chat images to LLM |
Real-time File Synchronization
Thefiles array from useThread() automatically stays synchronized with the server. When files are added, modified, or deleted on the thread (by the agent, tools, or other clients), the files array updates in real-time via WebSocket.
File Events
The SDK listens for three file-related events:| Event | Description |
|---|---|
file_created | A new file was added to the thread filesystem |
file_updated | An existing file was modified |
file_deleted | A file was removed from the thread filesystem |
Custom File Event Handling
You can also subscribe to these events directly for custom handling:How It Works
- Initial load: When
ThreadProvidermounts, it fetches the current file list from the server - Live updates: WebSocket events update the
filesarray as changes occur - Optimistic UI: Local uploads via
addFiles()appear immediately as “uploading” then transition to “committed” - Deduplication: Server files take priority over local pending files with the same path
useThread Return Value
Full ThreadContextValue:| Property | Type | Description |
|---|---|---|
threadId | string | The current thread ID |
messages | Message[] | All messages in the thread |
workblocks | ThreadMessage[] | Messages transformed to workblocks (if useWorkblocks is true) |
loading | boolean | Whether messages are loading (alias: isLoading) |
error | Error | null | Any error that occurred |
status | ConnectionStatus | WebSocket connection status (alias: connectionStatus) |
options | ThreadProviderOptions | Options passed to the provider |
sendMessage | (payload) => Promise<Message> | Send a message (auto-includes attachments) |
stopExecution | () => Promise<void> | Stop current execution |
deleteMessage | (messageId: string) => Promise<void> | Delete a message (optimistic UI) |
onEvent | <T>(type, listener) => () => void | Subscribe to custom events |
files | ThreadFile[] | All files (pending uploads + committed) |
addFiles | (files) => void | Upload files to filesystem |
removeFile | (id) => void | Remove a pending file |
getFileUrl | (file) => string | Get file URL |
getThumbnailUrl | (file) => string | Get thumbnail URL |
getPreviewUrl | (file) => string | null | Get preview URL |
attachments | PendingAttachment[] | Pending attachments for next message |
addAttachment | (files) => void | Add attachment(s) for next message |
removeAttachment | (id) => void | Remove a pending attachment |
clearAttachments | () => void | Clear all pending attachments |
useThreadId
Returns the current thread ID from context.Custom Events
Listen for custom events emitted by the backend usingonEvent from useThread():
emitThreadEvent():
Workblocks
Workblocks are a UI-friendly transformation of tool calls. WhenuseWorkblocks: true, consecutive assistant messages with tool calls are grouped into workblocks.
- Raw Messages
- Transformed Workblocks
WorkMessage Type
Rendering Workblocks
TypeScript Support
The package is written in TypeScript and includes full type definitions.Message Type
Complete Example
View Complete Chat Interface Example with Image Attachments
View Complete Chat Interface Example with Image Attachments
Next Steps
Core Concepts
Learn about agents, prompts, and tools
API Reference
Detailed API documentation
Builder Package
Backend framework documentation
Examples
Browse example implementations