@standardagents/client 0.1.0-dev.ffffff
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +48 -0
- package/README.md +320 -0
- package/dist/index.d.ts +476 -0
- package/dist/index.js +746 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
PROPRIETARY SOFTWARE LICENSE
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024-2025 FormKit Inc. All Rights Reserved.
|
|
4
|
+
|
|
5
|
+
UNLICENSED - DO NOT USE
|
|
6
|
+
|
|
7
|
+
This software and associated documentation files (the "Software") are the sole
|
|
8
|
+
and exclusive property of FormKit Inc. ("FormKit").
|
|
9
|
+
|
|
10
|
+
USE RESTRICTIONS
|
|
11
|
+
|
|
12
|
+
The Software is UNLICENSED and proprietary. NO PERMISSION is granted to use,
|
|
13
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
14
|
+
the Software, or to permit persons to whom the Software is furnished to do so,
|
|
15
|
+
under any circumstances, without prior written authorization from FormKit Inc.
|
|
16
|
+
|
|
17
|
+
UNAUTHORIZED USE PROHIBITED
|
|
18
|
+
|
|
19
|
+
Any use of this Software without a valid, written license agreement signed by
|
|
20
|
+
authorized officers of FormKit Inc. is strictly prohibited and constitutes
|
|
21
|
+
unauthorized use and infringement of FormKit's intellectual property rights.
|
|
22
|
+
|
|
23
|
+
LICENSING INQUIRIES
|
|
24
|
+
|
|
25
|
+
Organizations interested in licensing this Software should contact:
|
|
26
|
+
enterprise@formkit.com
|
|
27
|
+
|
|
28
|
+
A written license agreement must be executed before any use of this Software
|
|
29
|
+
is authorized.
|
|
30
|
+
|
|
31
|
+
NO WARRANTY
|
|
32
|
+
|
|
33
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
34
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
35
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
36
|
+
FORMKIT INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
37
|
+
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
38
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
39
|
+
|
|
40
|
+
GOVERNING LAW
|
|
41
|
+
|
|
42
|
+
This license shall be governed by and construed in accordance with the laws
|
|
43
|
+
of the jurisdiction in which FormKit Inc. is incorporated, without regard to
|
|
44
|
+
its conflict of law provisions.
|
|
45
|
+
|
|
46
|
+
FormKit Inc.
|
|
47
|
+
https://formkit.com
|
|
48
|
+
enterprise@formkit.com
|
package/README.md
ADDED
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
# @standardagents/client
|
|
2
|
+
|
|
3
|
+
Framework-agnostic client library for Standard Agents - provides HTTP/WebSocket communication, connection management, and shared utilities used by `@standardagents/react` and `@standardagents/vue`.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @standardagents/client
|
|
9
|
+
# or
|
|
10
|
+
pnpm add @standardagents/client
|
|
11
|
+
# or
|
|
12
|
+
yarn add @standardagents/client
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
> **Note:** Most users should use `@standardagents/react` or `@standardagents/vue` instead. This package is for advanced use cases or building custom framework integrations.
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```typescript
|
|
20
|
+
import { AgentBuilderClient, ThreadConnectionManager } from '@standardagents/client'
|
|
21
|
+
|
|
22
|
+
// Create a client
|
|
23
|
+
const client = new AgentBuilderClient('https://api.example.com')
|
|
24
|
+
|
|
25
|
+
// Fetch messages from a thread
|
|
26
|
+
const messages = await client.getMessages('thread-123')
|
|
27
|
+
|
|
28
|
+
// Send a message
|
|
29
|
+
await client.sendMessage('thread-123', {
|
|
30
|
+
role: 'user',
|
|
31
|
+
content: 'Hello!',
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
// Connect to live updates with automatic reconnection
|
|
35
|
+
const connection = new ThreadConnectionManager(client, 'thread-123', {
|
|
36
|
+
onStatusChange: (status) => console.log('Status:', status),
|
|
37
|
+
onMessage: (event) => console.log('New message:', event.data),
|
|
38
|
+
onChunk: (event) => console.log('Streaming chunk:', event.chunk),
|
|
39
|
+
onEvent: (event) => console.log('Custom event:', event.eventType, event.data),
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
connection.connect()
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Authentication
|
|
46
|
+
|
|
47
|
+
The client reads the authentication token from `localStorage` using the key `agentbuilder_auth_token`:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
// Set the token before making requests
|
|
51
|
+
localStorage.setItem('agentbuilder_auth_token', 'your-token-here')
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
All API requests and WebSocket connections will automatically include this token.
|
|
55
|
+
|
|
56
|
+
## API Reference
|
|
57
|
+
|
|
58
|
+
### `AgentBuilderClient`
|
|
59
|
+
|
|
60
|
+
HTTP client for the Standard Agents API.
|
|
61
|
+
|
|
62
|
+
#### Constructor
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const client = new AgentBuilderClient(endpoint: string)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Methods
|
|
69
|
+
|
|
70
|
+
##### `getEndpoint(): string`
|
|
71
|
+
|
|
72
|
+
Returns the configured endpoint URL.
|
|
73
|
+
|
|
74
|
+
##### `createThread(payload): Promise<Thread>`
|
|
75
|
+
|
|
76
|
+
Create a new thread.
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
const thread = await client.createThread({
|
|
80
|
+
agent_id: 'my-agent',
|
|
81
|
+
user_id: 'user-123', // optional
|
|
82
|
+
})
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
##### `getThread(threadId): Promise<Thread>`
|
|
86
|
+
|
|
87
|
+
Get thread metadata.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const thread = await client.getThread('thread-123')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
##### `getMessages(threadId, options?): Promise<Message[]>`
|
|
94
|
+
|
|
95
|
+
Fetch messages from a thread.
|
|
96
|
+
|
|
97
|
+
```typescript
|
|
98
|
+
const messages = await client.getMessages('thread-123', {
|
|
99
|
+
limit: 50,
|
|
100
|
+
offset: 0,
|
|
101
|
+
depth: 0,
|
|
102
|
+
includeSilent: false,
|
|
103
|
+
})
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
##### `sendMessage(threadId, payload): Promise<Message>`
|
|
107
|
+
|
|
108
|
+
Send a message to a thread.
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
const message = await client.sendMessage('thread-123', {
|
|
112
|
+
role: 'user',
|
|
113
|
+
content: 'Hello!',
|
|
114
|
+
silent: false, // optional
|
|
115
|
+
})
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
##### `stopExecution(threadId): Promise<void>`
|
|
119
|
+
|
|
120
|
+
Cancel an in-flight execution.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
await client.stopExecution('thread-123')
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
##### `connectMessageWebSocket(threadId, callbacks?, options?): WebSocket`
|
|
127
|
+
|
|
128
|
+
Create a WebSocket connection for streaming messages.
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
const ws = client.connectMessageWebSocket('thread-123', {
|
|
132
|
+
onOpen: () => console.log('Connected'),
|
|
133
|
+
onMessage: (event) => console.log('Message:', event),
|
|
134
|
+
onChunk: (event) => console.log('Chunk:', event),
|
|
135
|
+
onError: (event) => console.error('Error:', event),
|
|
136
|
+
onClose: (event) => console.log('Closed:', event),
|
|
137
|
+
}, {
|
|
138
|
+
includeSilent: false,
|
|
139
|
+
depth: 0,
|
|
140
|
+
})
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
##### `connectLogWebSocket(threadId, callbacks?): WebSocket`
|
|
144
|
+
|
|
145
|
+
Create a WebSocket connection for log events and custom events.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const ws = client.connectLogWebSocket('thread-123', {
|
|
149
|
+
onOpen: () => console.log('Connected'),
|
|
150
|
+
onLog: (event) => console.log('Log:', event),
|
|
151
|
+
onCustom: (event) => console.log('Custom:', event),
|
|
152
|
+
onStopped: (event) => console.log('Stopped:', event),
|
|
153
|
+
onClose: (event) => console.log('Closed:', event),
|
|
154
|
+
})
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
### `ThreadConnectionManager`
|
|
160
|
+
|
|
161
|
+
Manages WebSocket connections with automatic reconnection and heartbeat.
|
|
162
|
+
|
|
163
|
+
#### Constructor
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const manager = new ThreadConnectionManager(
|
|
167
|
+
client: AgentBuilderClient,
|
|
168
|
+
threadId: string,
|
|
169
|
+
callbacks?: ThreadConnectionCallbacks,
|
|
170
|
+
options?: ThreadConnectionOptions
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
**Callbacks:**
|
|
175
|
+
|
|
176
|
+
- `onStatusChange?: (status: ConnectionStatus) => void` - Called when connection status changes
|
|
177
|
+
- `onMessage?: (event: MessageDataEvent) => void` - Called when a complete message is received
|
|
178
|
+
- `onChunk?: (event: MessageChunkEvent) => void` - Called when a streaming chunk is received
|
|
179
|
+
- `onEvent?: (event: ThreadEvent) => void` - Called when a custom event is received
|
|
180
|
+
- `onError?: (error: Error | Event) => void` - Called on connection errors
|
|
181
|
+
|
|
182
|
+
**Options:**
|
|
183
|
+
|
|
184
|
+
- `depth?: number` - Message depth level (default: `0`)
|
|
185
|
+
- `includeSilent?: boolean` - Include silent messages (default: `false`)
|
|
186
|
+
- `maxReconnectDelay?: number` - Max reconnection delay in ms (default: `30000`)
|
|
187
|
+
- `heartbeatInterval?: number` - Heartbeat interval in ms (default: `30000`)
|
|
188
|
+
|
|
189
|
+
#### Methods
|
|
190
|
+
|
|
191
|
+
##### `connect(): void`
|
|
192
|
+
|
|
193
|
+
Establish the WebSocket connection.
|
|
194
|
+
|
|
195
|
+
##### `disconnect(): void`
|
|
196
|
+
|
|
197
|
+
Close the connection and stop reconnection attempts.
|
|
198
|
+
|
|
199
|
+
##### `getStatus(): ConnectionStatus`
|
|
200
|
+
|
|
201
|
+
Returns the current connection status: `'connecting' | 'connected' | 'reconnecting' | 'disconnected'`
|
|
202
|
+
|
|
203
|
+
##### `getThreadId(): string`
|
|
204
|
+
|
|
205
|
+
Returns the thread ID.
|
|
206
|
+
|
|
207
|
+
##### `updateCallbacks(callbacks): void`
|
|
208
|
+
|
|
209
|
+
Update callbacks after construction.
|
|
210
|
+
|
|
211
|
+
##### `updateOptions(options): void`
|
|
212
|
+
|
|
213
|
+
Update options after construction.
|
|
214
|
+
|
|
215
|
+
#### Reconnection Behavior
|
|
216
|
+
|
|
217
|
+
The connection manager automatically reconnects on unexpected disconnections using exponential backoff:
|
|
218
|
+
|
|
219
|
+
- Initial delay: 1 second
|
|
220
|
+
- Doubles each attempt: 1s, 2s, 4s, 8s, 16s
|
|
221
|
+
- Maximum delay: 30 seconds (configurable)
|
|
222
|
+
- Resets to 1s after successful connection
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
### `transformToWorkblocks(messages): ThreadMessage[]`
|
|
227
|
+
|
|
228
|
+
Groups tool calls with their results into workblock structures for easier UI rendering.
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
import { transformToWorkblocks } from '@standardagents/client'
|
|
232
|
+
|
|
233
|
+
const messages = await client.getMessages('thread-123')
|
|
234
|
+
const workblocks = transformToWorkblocks(messages)
|
|
235
|
+
|
|
236
|
+
// Each workblock contains:
|
|
237
|
+
// - type: 'workblock'
|
|
238
|
+
// - workItems: array of tool calls and results
|
|
239
|
+
// - status: 'pending' | 'completed'
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
---
|
|
243
|
+
|
|
244
|
+
## Types
|
|
245
|
+
|
|
246
|
+
```typescript
|
|
247
|
+
import type {
|
|
248
|
+
Message,
|
|
249
|
+
WorkMessage,
|
|
250
|
+
WorkItem,
|
|
251
|
+
ThreadMessage,
|
|
252
|
+
Thread,
|
|
253
|
+
SendMessagePayload,
|
|
254
|
+
GetMessagesOptions,
|
|
255
|
+
CreateThreadPayload,
|
|
256
|
+
ConnectionStatus,
|
|
257
|
+
ThreadConnectionCallbacks,
|
|
258
|
+
ThreadConnectionOptions,
|
|
259
|
+
} from '@standardagents/client'
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Message Types
|
|
263
|
+
|
|
264
|
+
```typescript
|
|
265
|
+
interface Message {
|
|
266
|
+
id: string
|
|
267
|
+
role: 'user' | 'assistant' | 'system' | 'tool'
|
|
268
|
+
content: string | null
|
|
269
|
+
created_at: number // microseconds
|
|
270
|
+
reasoning_content?: string | null
|
|
271
|
+
silent?: boolean
|
|
272
|
+
depth?: number
|
|
273
|
+
tool_calls?: string // JSON string
|
|
274
|
+
tool_call_id?: string
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
interface WorkMessage {
|
|
278
|
+
type: 'workblock'
|
|
279
|
+
id: string
|
|
280
|
+
content: string | null
|
|
281
|
+
reasoning_content?: string | null
|
|
282
|
+
status: 'pending' | 'completed'
|
|
283
|
+
workItems: WorkItem[]
|
|
284
|
+
created_at: number
|
|
285
|
+
depth?: number
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
interface WorkItem {
|
|
289
|
+
id: string
|
|
290
|
+
type: 'tool_call' | 'tool_result'
|
|
291
|
+
name: string
|
|
292
|
+
input?: string
|
|
293
|
+
content?: string
|
|
294
|
+
status: 'success' | 'error' | null
|
|
295
|
+
tool_call_id?: string
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
type ThreadMessage = Message | WorkMessage
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
---
|
|
302
|
+
|
|
303
|
+
## Local Development
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
# Install dependencies
|
|
307
|
+
pnpm install
|
|
308
|
+
|
|
309
|
+
# Build package
|
|
310
|
+
pnpm build
|
|
311
|
+
|
|
312
|
+
# Watch mode
|
|
313
|
+
pnpm dev
|
|
314
|
+
|
|
315
|
+
# Type check
|
|
316
|
+
pnpm typecheck
|
|
317
|
+
|
|
318
|
+
# Run tests
|
|
319
|
+
pnpm test
|
|
320
|
+
```
|