agentxjs 2.9.0-dev-20260317023622 → 2.9.0-dev-20260317030407
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/README.md +73 -401
- package/dist/index.d.ts +6 -22
- package/dist/index.js +60 -115
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/AgentHandle.ts +1 -1
- package/src/LocalClient.ts +12 -15
- package/src/RemoteClient.ts +11 -14
- package/src/index.ts +0 -1
- package/src/namespaces/images.ts +49 -2
- package/src/types.ts +5 -20
package/README.md
CHANGED
|
@@ -1,458 +1,130 @@
|
|
|
1
1
|
# agentxjs
|
|
2
2
|
|
|
3
|
-
Client SDK for building AI agent applications. Supports local, remote, and server modes through a unified
|
|
3
|
+
Client SDK for building AI agent applications. Supports local, remote, and server modes through a unified API.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Install
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
```bash
|
|
8
|
+
bun add agentxjs @agentxjs/node-platform @agentxjs/mono-driver
|
|
9
|
+
```
|
|
8
10
|
|
|
9
|
-
|
|
11
|
+
## Quick Start
|
|
10
12
|
|
|
11
13
|
```typescript
|
|
12
14
|
import { createAgentX } from "agentxjs";
|
|
13
15
|
import { nodePlatform } from "@agentxjs/node-platform";
|
|
14
16
|
import { createMonoDriver } from "@agentxjs/mono-driver";
|
|
15
17
|
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const ax = createAgentX(nodePlatform({
|
|
19
|
+
createDriver: (config) => createMonoDriver({
|
|
20
|
+
...config,
|
|
21
|
+
apiKey: process.env.ANTHROPIC_API_KEY,
|
|
22
|
+
options: { provider: "anthropic" },
|
|
23
|
+
}),
|
|
24
|
+
}));
|
|
23
25
|
|
|
26
|
+
// Create agent and chat
|
|
24
27
|
const agent = await ax.chat.create({
|
|
25
|
-
name: "
|
|
26
|
-
|
|
28
|
+
name: "Assistant",
|
|
29
|
+
systemPrompt: "You are a helpful assistant.",
|
|
27
30
|
});
|
|
28
31
|
|
|
29
32
|
ax.on("text_delta", (e) => process.stdout.write(e.data.text));
|
|
30
33
|
await agent.send("Hello!");
|
|
31
34
|
```
|
|
32
35
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
Connects to a running AgentX server. Same API surface.
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
import { createAgentX } from "agentxjs";
|
|
39
|
-
|
|
40
|
-
const ax = createAgentX();
|
|
41
|
-
const client = await ax.connect("ws://localhost:5200");
|
|
42
|
-
|
|
43
|
-
const agent = await client.chat.create({
|
|
44
|
-
name: "My Assistant",
|
|
45
|
-
embody: { systemPrompt: "You are a helpful assistant." },
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
client.on("text_delta", (e) => process.stdout.write(e.data.text));
|
|
49
|
-
await agent.send("Hello!");
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
### Server Mode
|
|
53
|
-
|
|
54
|
-
Start an AgentX WebSocket server for remote clients.
|
|
55
|
-
|
|
56
|
-
```typescript
|
|
57
|
-
import { createAgentX } from "agentxjs";
|
|
58
|
-
import { nodePlatform } from "@agentxjs/node-platform";
|
|
59
|
-
|
|
60
|
-
const ax = createAgentX(nodePlatform({ createDriver }));
|
|
61
|
-
const server = await ax.serve({ port: 5200 });
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## API Reference
|
|
65
|
-
|
|
66
|
-
### `createAgentX(config?): AgentXBuilder`
|
|
67
|
-
|
|
68
|
-
Creates an AgentX builder. Synchronous — returns immediately.
|
|
69
|
-
|
|
70
|
-
- **With config** (PlatformConfig): Local mode + `connect()` + `serve()`
|
|
71
|
-
- **Without config**: Only `connect()` available
|
|
72
|
-
|
|
73
|
-
### AgentX Interface
|
|
74
|
-
|
|
75
|
-
```typescript
|
|
76
|
-
interface AgentX {
|
|
77
|
-
readonly connected: boolean;
|
|
78
|
-
readonly events: EventBus;
|
|
79
|
-
|
|
80
|
-
// Conversation management
|
|
81
|
-
readonly chat: ChatNamespace;
|
|
82
|
-
|
|
83
|
-
// Prototype registry — reusable agent templates
|
|
84
|
-
readonly prototype: PrototypeNamespace;
|
|
85
|
-
|
|
86
|
-
// Low-level subsystems
|
|
87
|
-
readonly runtime: RuntimeNamespace;
|
|
88
|
-
|
|
89
|
-
// LLM provider management (system-level)
|
|
90
|
-
readonly provider: LLMNamespace;
|
|
91
|
-
|
|
92
|
-
// Universal RPC
|
|
93
|
-
rpc<T = unknown>(method: string, params?: unknown): Promise<T>;
|
|
94
|
-
|
|
95
|
-
// Event subscription
|
|
96
|
-
on<T extends string>(type: T, handler: BusEventHandler): Unsubscribe;
|
|
97
|
-
onAny(handler: BusEventHandler): Unsubscribe;
|
|
98
|
-
subscribe(sessionId: string): void;
|
|
99
|
-
|
|
100
|
-
// Error handling
|
|
101
|
-
onError(handler: (error: AgentXError) => void): Unsubscribe;
|
|
102
|
-
|
|
103
|
-
// Lifecycle
|
|
104
|
-
disconnect(): Promise<void>;
|
|
105
|
-
dispose(): Promise<void>;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
interface AgentXBuilder extends AgentX {
|
|
109
|
-
connect(serverUrl: string, options?: ConnectOptions): Promise<AgentX>;
|
|
110
|
-
serve(config?: ServeConfig): Promise<AgentXServer>;
|
|
111
|
-
}
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### ChatNamespace
|
|
36
|
+
## Core API
|
|
115
37
|
|
|
116
|
-
|
|
38
|
+
### ChatNamespace — Conversation Management
|
|
117
39
|
|
|
118
40
|
```typescript
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
get(id: string): Promise<AgentHandle | null>;
|
|
123
|
-
}
|
|
41
|
+
const agent = await ax.chat.create({ name, model?, systemPrompt?, mcpServers? });
|
|
42
|
+
const agent = await ax.chat.get(imageId);
|
|
43
|
+
const list = await ax.chat.list();
|
|
124
44
|
```
|
|
125
45
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
### AgentHandle
|
|
129
|
-
|
|
130
|
-
Returned by `chat.create()` and `chat.get()`. A live reference to a conversation with agent operations.
|
|
46
|
+
### AgentHandle — Live Agent Reference
|
|
131
47
|
|
|
132
48
|
```typescript
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
send(content: string | unknown[]): Promise<MessageSendResponse>;
|
|
140
|
-
interrupt(): Promise<BaseResponse>;
|
|
141
|
-
history(): Promise<Message[]>;
|
|
142
|
-
present(options?: PresentationOptions): Promise<Presentation>;
|
|
143
|
-
update(updates: { name?, description?, embody?, customData? }): Promise<void>;
|
|
144
|
-
delete(): Promise<void>;
|
|
145
|
-
}
|
|
49
|
+
await agent.send("Hello!"); // Send message
|
|
50
|
+
await agent.interrupt(); // Interrupt response
|
|
51
|
+
await agent.history(); // Get message history
|
|
52
|
+
const pres = await agent.present({ onUpdate }); // Create Presentation
|
|
53
|
+
await agent.update({ name, systemPrompt }); // Update config
|
|
54
|
+
await agent.delete(); // Delete agent
|
|
146
55
|
```
|
|
147
56
|
|
|
148
|
-
###
|
|
57
|
+
### Presentation — UI State Management
|
|
149
58
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
```typescript
|
|
153
|
-
interface PrototypeNamespace {
|
|
154
|
-
create(params: { containerId, name, description?, contextId?, embody?, customData? }): Promise<PrototypeCreateResponse>;
|
|
155
|
-
get(prototypeId: string): Promise<PrototypeGetResponse>;
|
|
156
|
-
list(containerId?: string): Promise<PrototypeListResponse>;
|
|
157
|
-
update(prototypeId: string, updates: { name?, description?, contextId?, embody?, customData? }): Promise<PrototypeUpdateResponse>;
|
|
158
|
-
delete(prototypeId: string): Promise<BaseResponse>;
|
|
159
|
-
}
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
```typescript
|
|
163
|
-
// Register a prototype
|
|
164
|
-
const res = await ax.prototype.create({
|
|
165
|
-
containerId: "default",
|
|
166
|
-
name: "Code Reviewer",
|
|
167
|
-
embody: { model: "claude-sonnet-4-6", systemPrompt: "You review code." },
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
// Create conversation from prototype
|
|
171
|
-
const agent = await ax.chat.create({ prototypeId: res.record.prototypeId });
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
### Runtime Namespace (low-level)
|
|
175
|
-
|
|
176
|
-
For advanced use cases, access `ax.runtime.*` for direct subsystem operations:
|
|
177
|
-
|
|
178
|
-
**container**:
|
|
179
|
-
|
|
180
|
-
- `create(containerId: string): Promise<ContainerCreateResponse>`
|
|
181
|
-
- `get(containerId: string): Promise<ContainerGetResponse>`
|
|
182
|
-
- `list(): Promise<ContainerListResponse>`
|
|
183
|
-
|
|
184
|
-
**image**:
|
|
185
|
-
|
|
186
|
-
- `create(params: { containerId, name?, description?, contextId?, embody?, customData? }): Promise<ImageCreateResponse>`
|
|
187
|
-
- `get(imageId: string): Promise<ImageGetResponse>`
|
|
188
|
-
- `list(containerId?: string): Promise<ImageListResponse>`
|
|
189
|
-
- `update(imageId: string, updates: { name?, description?, embody?, customData? }): Promise<ImageUpdateResponse>`
|
|
190
|
-
- `delete(imageId: string): Promise<BaseResponse>`
|
|
191
|
-
- `getMessages(imageId: string): Promise<Message[]>`
|
|
192
|
-
|
|
193
|
-
**agent**:
|
|
194
|
-
|
|
195
|
-
- `create(params: { imageId, agentId? }): Promise<AgentCreateResponse>`
|
|
196
|
-
- `get(agentId: string): Promise<AgentGetResponse>`
|
|
197
|
-
- `list(containerId?: string): Promise<AgentListResponse>`
|
|
198
|
-
- `destroy(agentId: string): Promise<BaseResponse>`
|
|
199
|
-
|
|
200
|
-
**session** (all methods accept imageId — server auto-creates agent if needed):
|
|
201
|
-
|
|
202
|
-
- `send(imageId: string, content: string | unknown[]): Promise<MessageSendResponse>`
|
|
203
|
-
- `interrupt(imageId: string): Promise<BaseResponse>`
|
|
204
|
-
- `getMessages(imageId: string): Promise<Message[]>`
|
|
205
|
-
- `truncateAfter(imageId: string, messageId: string): Promise<BaseResponse>` — delete messages after a point (for rewind)
|
|
206
|
-
|
|
207
|
-
**present**:
|
|
208
|
-
|
|
209
|
-
- `create(instanceId: string, options?: PresentationOptions): Promise<Presentation>`
|
|
210
|
-
|
|
211
|
-
**llm**:
|
|
212
|
-
|
|
213
|
-
- `create(params: { containerId, name, vendor, protocol, apiKey, baseUrl?, model? }): Promise<LLMProviderCreateResponse>`
|
|
214
|
-
- `get(id: string): Promise<LLMProviderGetResponse>`
|
|
215
|
-
- `list(containerId: string): Promise<LLMProviderListResponse>`
|
|
216
|
-
- `update(id: string, updates: { name?, apiKey?, baseUrl?, model? }): Promise<LLMProviderUpdateResponse>`
|
|
217
|
-
- `delete(id: string): Promise<BaseResponse>`
|
|
218
|
-
- `setDefault(id: string): Promise<BaseResponse>`
|
|
219
|
-
- `getDefault(containerId: string): Promise<LLMProviderDefaultResponse>`
|
|
220
|
-
|
|
221
|
-
**prototype**:
|
|
222
|
-
|
|
223
|
-
- `create(params: { containerId, name, description?, contextId?, embody?, customData? }): Promise<PrototypeCreateResponse>`
|
|
224
|
-
- `get(prototypeId: string): Promise<PrototypeGetResponse>`
|
|
225
|
-
- `list(containerId?: string): Promise<PrototypeListResponse>`
|
|
226
|
-
- `update(prototypeId: string, updates: { name?, description?, contextId?, embody?, customData? }): Promise<PrototypeUpdateResponse>`
|
|
227
|
-
- `delete(prototypeId: string): Promise<BaseResponse>`
|
|
228
|
-
|
|
229
|
-
Each LLM provider has a **vendor** (who provides the service — `anthropic`, `openai`, `deepseek`, `ollama`) and a **protocol** (API format — `anthropic` or `openai`). These are separate dimensions: e.g., Deepseek uses vendor `"deepseek"` with protocol `"openai"`.
|
|
230
|
-
|
|
231
|
-
### Embodiment
|
|
232
|
-
|
|
233
|
-
Runtime configuration for an agent's "body":
|
|
234
|
-
|
|
235
|
-
```typescript
|
|
236
|
-
interface Embodiment {
|
|
237
|
-
model?: string; // LLM model name
|
|
238
|
-
systemPrompt?: string; // System prompt
|
|
239
|
-
mcpServers?: Record<string, McpServerConfig>; // MCP tool servers
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
Model priority: `embody.model > container default provider > environment variable`.
|
|
244
|
-
|
|
245
|
-
### Universal RPC
|
|
246
|
-
|
|
247
|
-
Transport-agnostic JSON-RPC entry point. Works in all modes — local dispatches to CommandHandler, remote forwards via WebSocket.
|
|
248
|
-
|
|
249
|
-
```typescript
|
|
250
|
-
// Equivalent to ax.runtime.container.create("default")
|
|
251
|
-
await ax.rpc("container.create", { containerId: "default" });
|
|
252
|
-
|
|
253
|
-
// Equivalent to ax.runtime.image.list()
|
|
254
|
-
const { records } = await ax.rpc<{ records: ImageRecord[] }>("image.list");
|
|
255
|
-
|
|
256
|
-
// Prototype operations via RPC
|
|
257
|
-
await ax.rpc("prototype.create", { containerId: "default", name: "My Agent" });
|
|
258
|
-
const { records } = await ax.rpc<{ records: PrototypeRecord[] }>("prototype.list", {});
|
|
259
|
-
|
|
260
|
-
// Useful for custom transport (e.g. Cloudflare Workers/DO)
|
|
261
|
-
const response = await ax.rpc(request.method, request.params);
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Error Handling
|
|
265
|
-
|
|
266
|
-
AgentX has two layers of error handling, serving different purposes:
|
|
267
|
-
|
|
268
|
-
| Layer | Purpose | Who uses it | How errors arrive |
|
|
269
|
-
| ----- | ------- | ----------- | ----------------- |
|
|
270
|
-
| **Presentation** | Show errors to end users in chat | UI developers | `ErrorConversation` in `state.conversations` |
|
|
271
|
-
| **`ax.onError`** | Programmatic monitoring & alerting | Platform operators | `AgentXError` callback |
|
|
272
|
-
|
|
273
|
-
Most applications only need the Presentation layer. `ax.onError` is for advanced scenarios like Sentry integration or custom circuit-breaker logic.
|
|
274
|
-
|
|
275
|
-
#### Presentation Errors (recommended)
|
|
276
|
-
|
|
277
|
-
When an LLM call fails (e.g., 403 Forbidden, network timeout), the error automatically appears in `state.conversations` as an `ErrorConversation`:
|
|
59
|
+
The recommended way to build chat UIs. Aggregates stream events into structured state.
|
|
278
60
|
|
|
279
61
|
```typescript
|
|
280
62
|
const pres = await agent.present({
|
|
281
63
|
onUpdate: (state) => {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
renderAssistantMessage(conv);
|
|
287
|
-
} else if (conv.role === "error") {
|
|
288
|
-
// LLM errors show up here automatically
|
|
289
|
-
renderErrorMessage(conv.message);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
});
|
|
294
|
-
```
|
|
295
|
-
|
|
296
|
-
The flow is fully automatic — no extra code needed:
|
|
297
|
-
|
|
298
|
-
```
|
|
299
|
-
LLM API fails → Driver emits error → Engine creates ErrorConversation
|
|
300
|
-
→ Presentation state updates → onUpdate fires → UI renders error
|
|
301
|
-
```
|
|
302
|
-
|
|
303
|
-
`state.streaming` resets to `null` and `state.status` returns to `"idle"`, so the UI naturally stops showing loading indicators.
|
|
304
|
-
|
|
305
|
-
#### `ax.onError` (advanced)
|
|
306
|
-
|
|
307
|
-
For monitoring, logging, or custom recovery logic. Receives structured `AgentXError` from all layers (driver, persistence, connection). Independent of Presentation — fires even without a Presentation instance.
|
|
308
|
-
|
|
309
|
-
```typescript
|
|
310
|
-
ax.onError((error) => {
|
|
311
|
-
reportToSentry(error);
|
|
312
|
-
console.error(`[${error.category}] ${error.code}: ${error.message}`);
|
|
313
|
-
});
|
|
314
|
-
```
|
|
315
|
-
|
|
316
|
-
**AgentXError properties:**
|
|
317
|
-
|
|
318
|
-
| Property | Type | Description |
|
|
319
|
-
| ------------- | -------- | ------------------------------------ |
|
|
320
|
-
| `code` | string | `DRIVER_ERROR`, `CIRCUIT_OPEN`, `PERSISTENCE_FAILED`, `CONNECTION_FAILED` |
|
|
321
|
-
| `category` | string | `"driver"` \| `"persistence"` \| `"connection"` \| `"runtime"` |
|
|
322
|
-
| `recoverable` | boolean | Whether the caller should retry |
|
|
323
|
-
| `context` | object | `{ agentId?, sessionId?, imageId? }` |
|
|
324
|
-
| `cause` | Error? | Original error |
|
|
325
|
-
|
|
326
|
-
**Built-in circuit breaker:** After 5 consecutive driver failures, the circuit opens and rejects new requests for 30s. This is automatic — no code required.
|
|
327
|
-
|
|
328
|
-
### Stream Events
|
|
329
|
-
|
|
330
|
-
| Event | Data | Description |
|
|
331
|
-
| ------------------ | -------------------------- | ---------------------- |
|
|
332
|
-
| `message_start` | `{ messageId, model }` | Response begins |
|
|
333
|
-
| `text_delta` | `{ text }` | Incremental text chunk |
|
|
334
|
-
| `tool_use_start` | `{ toolCallId, toolName }` | Tool call begins |
|
|
335
|
-
| `input_json_delta` | `{ partialJson }` | Incremental tool input |
|
|
336
|
-
| `tool_result` | `{ toolCallId, result }` | Tool execution result |
|
|
337
|
-
| `message_stop` | `{ stopReason }` | Response complete |
|
|
338
|
-
| `error` | `{ message }` | Error during streaming |
|
|
339
|
-
|
|
340
|
-
> **Note:** If you use the Presentation API, you don't need to handle the `error` stream event — it is automatically converted to an `ErrorConversation` in `state.conversations`.
|
|
341
|
-
|
|
342
|
-
### Presentation API
|
|
343
|
-
|
|
344
|
-
High-level UI state management. Aggregates raw stream events into structured conversation state — the recommended way to build chat UIs.
|
|
345
|
-
|
|
346
|
-
```typescript
|
|
347
|
-
const pres = await agent.present({
|
|
348
|
-
onUpdate: (state) => {
|
|
349
|
-
// state.conversations — completed messages (user, assistant, and error)
|
|
350
|
-
// state.streaming — current streaming response (or null)
|
|
351
|
-
// state.status — "idle" | "thinking" | "responding" | "executing"
|
|
64
|
+
// state.conversations — all messages (user, assistant, error)
|
|
65
|
+
// state.status — "idle" | "submitted" | "thinking" | "responding" | "executing"
|
|
66
|
+
// state.workspace — { files: FileTreeEntry[] } | null
|
|
67
|
+
// state.metrics — token usage and context tracking
|
|
352
68
|
renderUI(state);
|
|
353
69
|
},
|
|
354
70
|
});
|
|
355
71
|
|
|
356
72
|
await pres.send("What is the weather?");
|
|
357
|
-
|
|
358
|
-
pres.
|
|
73
|
+
await pres.rewind(2); // Rewind to index (runtime-level operation)
|
|
74
|
+
await pres.editAndResend(2, "New question"); // Edit and resend
|
|
359
75
|
```
|
|
360
76
|
|
|
361
|
-
####
|
|
77
|
+
#### Workspace Operations
|
|
362
78
|
|
|
363
|
-
|
|
364
|
-
| ------ | ----------- |
|
|
365
|
-
| `send(content)` | Send a message. Accepts `string` or `UserContentPart[]` (text + files/images) |
|
|
366
|
-
| `interrupt()` | Interrupt the current streaming response |
|
|
367
|
-
| `rewind(index)` | Rewind conversation to a specific index, removing all messages after it. Truncates server-side history too |
|
|
368
|
-
| `editAndResend(index, content)` | Rewind to `index`, then send new content. For "edit & resend" UI |
|
|
369
|
-
| `reset()` | Clear all local state |
|
|
370
|
-
| `getState()` | Get current `PresentationState` |
|
|
371
|
-
| `onUpdate(handler)` | Subscribe to state changes. Returns unsubscribe function |
|
|
372
|
-
| `onError(handler)` | Subscribe to errors. Returns unsubscribe function |
|
|
373
|
-
| `dispose()` | Cleanup subscriptions |
|
|
374
|
-
|
|
375
|
-
#### Sending Files
|
|
79
|
+
When an agent has a workspace, file operations and real-time file tree are available:
|
|
376
80
|
|
|
377
81
|
```typescript
|
|
378
|
-
|
|
379
|
-
await pres.
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
{ type: "text", text: "Please analyze this data" },
|
|
384
|
-
{ type: "file", data: base64Data, mediaType: "text/csv", filename: "sales.csv" },
|
|
385
|
-
]);
|
|
82
|
+
if (pres.workspace) {
|
|
83
|
+
const content = await pres.workspace.read("src/index.ts");
|
|
84
|
+
await pres.workspace.write("output.txt", "Hello");
|
|
85
|
+
const entries = await pres.workspace.list("src");
|
|
86
|
+
}
|
|
386
87
|
|
|
387
|
-
//
|
|
388
|
-
await pres.send([
|
|
389
|
-
{ type: "text", text: "What's in this image?" },
|
|
390
|
-
{ type: "image", data: base64Data, mediaType: "image/png", name: "screenshot.png" },
|
|
391
|
-
]);
|
|
88
|
+
// File tree auto-updates in state.workspace.files
|
|
392
89
|
```
|
|
393
90
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
| File Type | Behavior |
|
|
397
|
-
| --------- | -------- |
|
|
398
|
-
| Images (`image/*`) | Passed directly to LLM |
|
|
399
|
-
| PDF (`application/pdf`) | Passed directly (Claude/Gemini only, others throw `UnsupportedMediaTypeError`) |
|
|
400
|
-
| Text files (`text/*`, `application/json`, `application/xml`) | Auto-extracted to inline text with `<file>` tags |
|
|
401
|
-
| Other | Throws `UnsupportedMediaTypeError` |
|
|
402
|
-
|
|
403
|
-
#### Conversation Rewind / Edit & Resend
|
|
91
|
+
### Runtime Namespace (Advanced)
|
|
404
92
|
|
|
405
93
|
```typescript
|
|
406
|
-
//
|
|
94
|
+
// Image operations
|
|
95
|
+
ax.runtime.image.create(config) // Create image
|
|
96
|
+
ax.runtime.image.get(imageId) // Get image
|
|
97
|
+
ax.runtime.image.list() // List images
|
|
98
|
+
ax.runtime.image.update(imageId, upd) // Update image
|
|
99
|
+
ax.runtime.image.delete(imageId) // Delete image
|
|
100
|
+
ax.runtime.image.getMessages(imageId) // Get message history
|
|
101
|
+
ax.runtime.image.run(imageId) // Start agent from image
|
|
102
|
+
ax.runtime.image.stop(imageId) // Stop agent
|
|
407
103
|
|
|
408
|
-
//
|
|
409
|
-
|
|
104
|
+
// Session operations
|
|
105
|
+
ax.runtime.session.send(imageId, content) // Send message
|
|
106
|
+
ax.runtime.session.interrupt(imageId) // Interrupt
|
|
107
|
+
ax.runtime.session.getMessages(imageId) // Get messages
|
|
410
108
|
|
|
411
|
-
//
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
// Works with files too
|
|
415
|
-
await pres.editAndResend(2, [
|
|
416
|
-
{ type: "text", text: "Analyze with different instructions" },
|
|
417
|
-
{ type: "file", data: base64, mediaType: "text/csv", filename: "data.csv" },
|
|
418
|
-
]);
|
|
109
|
+
// LLM provider management
|
|
110
|
+
ax.runtime.llm.create({ name, vendor, protocol, apiKey })
|
|
111
|
+
ax.runtime.llm.setDefault(id)
|
|
419
112
|
```
|
|
420
113
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
**`state.conversations`** contains an array of:
|
|
424
|
-
|
|
425
|
-
| `role` | Type | Blocks |
|
|
426
|
-
| ------ | ---- | ------ |
|
|
427
|
-
| `"user"` | `UserConversation` | `TextBlock`, `FileBlock`, `ImageBlock` |
|
|
428
|
-
| `"assistant"` | `AssistantConversation` | `TextBlock`, `ToolBlock`, `ImageBlock` |
|
|
429
|
-
| `"error"` | `ErrorConversation` | `message: string` |
|
|
430
|
-
|
|
431
|
-
**Block types:**
|
|
114
|
+
### Error Handling
|
|
432
115
|
|
|
433
116
|
```typescript
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
117
|
+
// Presentation: errors appear as ErrorConversation in state.conversations
|
|
118
|
+
// Advanced: programmatic error handling
|
|
119
|
+
ax.onError((error) => {
|
|
120
|
+
console.error(`[${error.category}] ${error.code}: ${error.message}`);
|
|
121
|
+
});
|
|
438
122
|
```
|
|
439
123
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
**`state.status`** — `"idle"` | `"thinking"` | `"responding"` | `"executing"`.
|
|
443
|
-
|
|
444
|
-
#### Custom State Management
|
|
124
|
+
## Modes
|
|
445
125
|
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
let state = createInitialState();
|
|
452
|
-
state = addUserConversation(state, "Hello");
|
|
453
|
-
state = addUserConversation(state, [
|
|
454
|
-
{ type: "text", text: "Check this file" },
|
|
455
|
-
{ type: "file", data: base64, mediaType: "text/csv", filename: "data.csv" },
|
|
456
|
-
]);
|
|
457
|
-
state = presentationReducer(state, event); // pure function
|
|
458
|
-
```
|
|
126
|
+
| Mode | Setup | Use Case |
|
|
127
|
+
|------|-------|----------|
|
|
128
|
+
| Local | `createAgentX(nodePlatform({ createDriver }))` | CLI tools, single-user |
|
|
129
|
+
| Remote | `ax.connect("ws://...")` | Web apps, multi-tenant |
|
|
130
|
+
| Server | `ax.serve({ port: 5200 })` | Backend service |
|
package/dist/index.d.ts
CHANGED
|
@@ -511,30 +511,15 @@ interface ImageNamespace {
|
|
|
511
511
|
* Get message history for an image
|
|
512
512
|
*/
|
|
513
513
|
getMessages(imageId: string): Promise<Message[]>;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Agent operations namespace
|
|
517
|
-
*/
|
|
518
|
-
interface InstanceNamespace {
|
|
519
|
-
/**
|
|
520
|
-
* Create a new agent
|
|
521
|
-
*/
|
|
522
|
-
create(params: {
|
|
523
|
-
imageId: string;
|
|
524
|
-
instanceId?: string;
|
|
525
|
-
}): Promise<InstanceCreateResponse>;
|
|
526
|
-
/**
|
|
527
|
-
* Get agent by ID
|
|
528
|
-
*/
|
|
529
|
-
get(instanceId: string): Promise<InstanceGetResponse>;
|
|
530
514
|
/**
|
|
531
|
-
*
|
|
515
|
+
* Run an agent from this image.
|
|
516
|
+
* Reuses existing running agent if available.
|
|
532
517
|
*/
|
|
533
|
-
|
|
518
|
+
run(imageId: string): Promise<InstanceCreateResponse>;
|
|
534
519
|
/**
|
|
535
|
-
*
|
|
520
|
+
* Stop the agent for this image.
|
|
536
521
|
*/
|
|
537
|
-
|
|
522
|
+
stop(imageId: string): Promise<BaseResponse>;
|
|
538
523
|
}
|
|
539
524
|
/**
|
|
540
525
|
* Session operations namespace (messaging)
|
|
@@ -633,7 +618,6 @@ interface PresentationNamespace {
|
|
|
633
618
|
*/
|
|
634
619
|
interface RuntimeNamespace {
|
|
635
620
|
readonly image: ImageNamespace;
|
|
636
|
-
readonly instance: InstanceNamespace;
|
|
637
621
|
readonly session: SessionNamespace;
|
|
638
622
|
readonly present: PresentationNamespace;
|
|
639
623
|
readonly llm: LLMNamespace;
|
|
@@ -856,4 +840,4 @@ interface PlatformConfig {
|
|
|
856
840
|
*/
|
|
857
841
|
declare function createAgentX(config?: PlatformConfig): AgentXBuilder;
|
|
858
842
|
|
|
859
|
-
export { type AgentConfig, type AgentHandle, type AgentX, type AgentXBuilder, type AgentXServer, type AssistantConversation, type BaseResponse, type Block, type ChatNamespace, type ConnectOptions, type Conversation, type ErrorConversation, type FileBlock, type ImageBlock, type ImageCreateResponse, type ImageGetResponse, type ImageListResponse, type ImageNamespace, type ImageRecord, type ImageUpdateResponse, type InstanceCreateResponse, type InstanceGetResponse, type InstanceInfo, type InstanceListResponse, type
|
|
843
|
+
export { type AgentConfig, type AgentHandle, type AgentX, type AgentXBuilder, type AgentXServer, type AssistantConversation, type BaseResponse, type Block, type ChatNamespace, type ConnectOptions, type Conversation, type ErrorConversation, type FileBlock, type ImageBlock, type ImageCreateResponse, type ImageGetResponse, type ImageListResponse, type ImageNamespace, type ImageRecord, type ImageUpdateResponse, type InstanceCreateResponse, type InstanceGetResponse, type InstanceInfo, type InstanceListResponse, type LLMNamespace, type LLMProviderCreateResponse, type LLMProviderDefaultResponse, type LLMProviderGetResponse, type LLMProviderListResponse, type LLMProviderUpdateResponse, type MaybeAsync, type MessageSendResponse, type PlatformConfig, Presentation, type PresentationErrorHandler, type PresentationMetrics, type PresentationNamespace, type PresentationOptions, type PresentationState, type PresentationUpdateHandler, type RuntimeNamespace, type ServeConfig, type SessionNamespace, type TextBlock, type ThinkingBlock, type ToolBlock, type UserConversation, addUserConversation, createAgentX, createInitialState, initialMetrics, initialPresentationState, messagesToConversations, presentationReducer };
|