@astralform/js 0.2.2 → 1.0.0

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/dist/index.d.ts CHANGED
@@ -1,510 +1,513 @@
1
+ interface AgentIdentity {
2
+ name: string;
3
+ displayName?: string | null;
4
+ avatarUrl?: string | null;
5
+ description?: string | null;
6
+ }
7
+ type TaskStatus = "pending" | "in_progress" | "completed" | "deleted";
8
+ interface TodoItem {
9
+ id: number;
10
+ subject: string;
11
+ status: TaskStatus;
12
+ description?: string | null;
13
+ activeForm?: string | null;
14
+ owner?: string | null;
15
+ blockedBy?: number[] | null;
16
+ blocks?: number[] | null;
17
+ priority?: number | null;
18
+ }
19
+ interface TodoUpdatePayload {
20
+ todos: TodoItem[];
21
+ }
22
+ interface TitleGeneratedPayload {
23
+ title: string;
24
+ }
25
+ interface SubagentStartPayload {
26
+ agent: AgentIdentity;
27
+ taskCallId?: string | null;
28
+ }
29
+ interface SubagentStopPayload {
30
+ agent: AgentIdentity;
31
+ taskCallId?: string | null;
32
+ }
33
+ interface ContextWarningPayload {
34
+ /** Known values: "info" | "warning" | "critical". Typed as string for forward compat. */
35
+ severity: string;
36
+ utilizationPct: number;
37
+ remainingTokens: number;
38
+ windowTokens: number;
39
+ inputTokens: number;
40
+ message: string;
41
+ }
42
+ interface ContextUpdatePayload {
43
+ phase?: string | null;
44
+ updatedAt?: number | null;
45
+ context: Record<string, unknown>;
46
+ }
1
47
  /**
2
- * BlockBuilder pure rendering engine. Zero default behavior.
3
- *
4
- * Clients register handlers that map events to blocks.
5
- * Both live streaming and restore go through the same engine.
6
- *
7
- * import { BlockBuilder, standardHandlers } from "@astralform/js";
8
- * const builder = new BlockBuilder();
9
- * builder.registerHandlers(standardHandlers);
48
+ * A single memory entry returned by ``memory_recall``. Backend may add
49
+ * fields over time, so the shape is intentionally open-ended.
10
50
  */
11
-
12
- interface UserBlock {
13
- type: "user";
51
+ interface MemoryRecord {
14
52
  id: string;
15
53
  content: string;
16
- createdAt?: number;
54
+ [key: string]: unknown;
17
55
  }
18
- interface TextBlock {
19
- type: "text";
20
- id: string;
21
- content: string;
22
- isStreaming: boolean;
56
+ interface MemoryRecallPayload {
57
+ memories: MemoryRecord[];
23
58
  }
24
- interface ThinkingBlock {
25
- type: "thinking";
26
- id: string;
27
- content: string;
28
- isActive: boolean;
29
- durationMs?: number;
59
+ interface MemoryUpdatePayload {
60
+ /** Known values: "created" | "updated" | "deleted". Typed as string for forward compat. */
61
+ action: string;
62
+ memoryId?: string | null;
63
+ key?: string | null;
64
+ namespace?: string | null;
30
65
  }
31
- interface AgentBlock {
32
- type: "agent";
33
- id: string;
34
- agentName: string;
35
- displayName?: string;
36
- avatarUrl?: string;
66
+ interface DesktopStreamPayload {
67
+ url: string;
68
+ sandboxId?: string | null;
37
69
  }
38
- interface SubagentBlock {
39
- type: "subagent";
40
- id: string;
41
- agentName: string;
42
- displayName: string;
43
- toolCallId: string;
44
- avatarUrl?: string;
45
- description?: string;
46
- content: string;
47
- isActive: boolean;
70
+ interface AttachmentStagedPayload {
71
+ attachmentId: string;
72
+ filename: string;
73
+ contentType?: string | null;
74
+ sizeBytes?: number | null;
48
75
  }
49
- interface ToolBlock {
50
- type: "tool";
51
- id: string;
52
- callId: string;
76
+ interface WorkspaceReadyPayload {
77
+ sandboxId: string;
78
+ workspacePath?: string | null;
79
+ }
80
+ interface AssetCreatedPayload {
81
+ assetId: string;
82
+ filename: string;
83
+ url?: string | null;
84
+ contentType?: string | null;
85
+ }
86
+ interface ToolApprovalRequestedPayload {
53
87
  toolName: string;
54
- displayName?: string;
55
- description?: string;
56
- arguments?: Record<string, unknown>;
57
- status: string;
58
- iconUrl?: string;
59
- toolCategory?: string;
60
- sources?: {
61
- title: string;
62
- url: string;
63
- snippet?: string;
64
- }[];
65
- durationMs?: number;
66
- result?: string;
67
- }
68
- interface CapsuleBlock {
69
- type: "capsule";
70
- id: string;
71
88
  callId: string;
72
- toolName: string;
73
- command?: string;
74
- output: string;
75
- durationMs?: number;
76
- isActive: boolean;
89
+ arguments: Record<string, unknown>;
90
+ riskLevel?: string | null;
91
+ reason?: string | null;
77
92
  }
78
- interface AssetBlock {
79
- type: "asset";
80
- id: string;
81
- assetId: string;
82
- name: string;
83
- url: string;
84
- mediaType: string;
85
- sizeBytes: number;
93
+ interface ToolApprovalGrantedPayload {
94
+ toolName: string;
95
+ callId: string;
86
96
  }
87
- interface TodoBlock {
88
- type: "todo";
89
- id: string;
90
- todos: {
91
- content: string;
92
- status: string;
93
- }[];
97
+ interface ToolPermissionDeniedPayload {
98
+ toolName: string;
99
+ callId: string;
100
+ reason?: string | null;
101
+ /** Known values: "hook" | "rule" | "user" | "timeout" | "circuit_breaker". */
102
+ deniedBy?: string | null;
94
103
  }
95
- interface EditorBlock {
96
- type: "editor";
97
- id: string;
104
+ interface ToolHarnessWarningPayload {
105
+ toolName: string;
98
106
  callId: string;
99
- path: string;
100
- language: string;
101
- content: string;
102
- isStreaming: boolean;
107
+ message?: string | null;
108
+ details?: Record<string, unknown> | null;
103
109
  }
104
- interface ErrorBlock {
105
- type: "error";
106
- id: string;
107
- message: string;
110
+ interface UserUnavailablePayload {
111
+ consecutiveTimeouts: number;
112
+ toolName?: string | null;
108
113
  }
109
- type Block = UserBlock | TextBlock | ThinkingBlock | AgentBlock | SubagentBlock | ToolBlock | CapsuleBlock | AssetBlock | TodoBlock | EditorBlock | ErrorBlock;
110
- type EventHandler$1 = (event: ChatEvent, builder: BlockBuilder) => void;
111
- declare class BlockBuilder {
112
- private _blocks;
113
- private _handlers;
114
- private _onChange;
115
- activeTextId: string | null;
116
- activeThinkingId: string | null;
117
- thinkingStartMs: number | null;
118
- activeEditorId: string | null;
119
- activeTodoId: string | null;
120
- on(eventType: string, handler: EventHandler$1 | null): void;
121
- registerHandlers(handlers: Record<string, EventHandler$1 | null>): void;
122
- processEvent(event: ChatEvent): void;
123
- getBlocks(): Block[];
124
- reset(): void;
125
- setOnChange(fn: (() => void) | null): void;
126
- addBlock(block: Block): void;
127
- updateBlock<T extends Block["type"]>(id: string, updater: (block: Extract<Block, {
128
- type: T;
129
- }>) => Extract<Block, {
130
- type: T;
131
- }>): void;
132
- /** Update any block by id with a partial update (type-loose for handlers). */
133
- patchBlock(id: string, patch: Partial<Block>): void;
134
- findBlock(predicate: (b: Block) => boolean): Block | undefined;
135
- nextId(): string;
136
- private _notify;
114
+ interface PromptSuggestionPayload {
115
+ suggestions: string[];
137
116
  }
138
117
 
139
- interface AstralformConfig {
140
- apiKey: string;
118
+ interface AstralformBaseConfig {
119
+ /** Override the default API origin. Defaults to https://api.astralform.ai. */
141
120
  baseURL?: string;
142
- userId: string;
121
+ /** Supply a custom fetch (SSR, testing, custom interceptors). */
143
122
  fetch?: typeof globalThis.fetch;
144
123
  }
124
+ interface AstralformApiKeyConfig extends AstralformBaseConfig {
125
+ /** Project API key (`sk_live_...` or `sk_test_...`). */
126
+ apiKey: string;
127
+ /**
128
+ * The customer's own identifier for the end user making this call.
129
+ * Sent as the `X-End-User-ID` header. Required in API-key mode.
130
+ */
131
+ userId: string;
132
+ }
133
+ interface AstralformUserTokenConfig extends AstralformBaseConfig {
134
+ /**
135
+ * OIDC access token issued by the Astralform Identity Provider.
136
+ * Expect this to be short-lived; use `client.updateAccessToken()` after
137
+ * refreshing to hot-swap without re-instantiating the client.
138
+ */
139
+ accessToken: string;
140
+ /**
141
+ * Active project context. Sent as the `X-Project-ID` header. The backend
142
+ * verifies the token's developer has access to this project on every
143
+ * request; switching projects is a local `updateProjectId()` call.
144
+ *
145
+ * Optional so a pre-pick client (right after login, before the user has
146
+ * chosen a team/project) can still call account-scoped discovery routes
147
+ * like `listTeams()` / `listProjects(teamId)`. Project-scoped calls
148
+ * (conversations, messages, chat) will error out until one is set.
149
+ */
150
+ projectId?: string;
151
+ /**
152
+ * Optional end-user override — lets a developer acting under a user
153
+ * token impersonate a downstream end-user identity for testing
154
+ * purposes. When set, sent alongside `X-Project-ID` as `X-End-User-ID`
155
+ * so memory, rate limits, and conversations scope to the specified
156
+ * end-user rather than the developer themselves.
157
+ *
158
+ * Use `client.updateEndUserId()` to rotate at runtime.
159
+ */
160
+ endUserId?: string;
161
+ }
162
+ type AstralformConfig = AstralformApiKeyConfig | AstralformUserTokenConfig;
145
163
  declare const ChatEventType: {
146
164
  readonly Connected: "connected";
147
- readonly BlocksChanged: "blocks_changed";
165
+ readonly Disconnected: "disconnected";
166
+ readonly MessageStart: "message_start";
167
+ readonly MessageStop: "message_stop";
168
+ readonly BlockStart: "block_start";
169
+ readonly BlockDelta: "block_delta";
170
+ readonly BlockStop: "block_stop";
171
+ readonly Stall: "stall";
172
+ readonly Retry: "retry";
173
+ readonly Error: "error";
174
+ readonly Keepalive: "keepalive";
148
175
  readonly UserMessage: "user_message";
149
176
  readonly TitleGenerated: "title_generated";
150
- readonly ModelInfo: "model_info";
151
- readonly Chunk: "chunk";
152
- readonly ToolCall: "tool_call";
153
- readonly ToolExecuting: "tool_executing";
154
- readonly ToolProgress: "tool_progress";
155
- readonly ToolCompleted: "tool_completed";
156
- readonly ToolEnd: "tool_end";
157
- readonly AgentStart: "agent_start";
158
- readonly AgentEnd: "agent_end";
159
- readonly ThinkingDelta: "thinking_delta";
160
- readonly ThinkingComplete: "thinking_complete";
177
+ readonly TodoUpdate: "todo_update";
178
+ readonly ContextUpdate: "context_update";
161
179
  readonly SubagentStart: "subagent_start";
162
- readonly SubagentChunk: "subagent_chunk";
163
- readonly SubagentUpdate: "subagent_update";
164
- readonly SubagentEnd: "subagent_end";
165
- readonly SubagentToolUse: "subagent_tool_use";
166
- readonly CapsuleOutput: "capsule_output";
167
- readonly CapsuleOutputChunk: "capsule_output_chunk";
180
+ readonly SubagentStop: "subagent_stop";
181
+ readonly ContextWarning: "context_warning";
182
+ readonly MemoryRecall: "memory_recall";
183
+ readonly MemoryUpdate: "memory_update";
184
+ readonly DesktopStream: "desktop_stream";
185
+ readonly AttachmentStaged: "attachment_staged";
186
+ readonly WorkspaceReady: "workspace_ready";
168
187
  readonly AssetCreated: "asset_created";
169
- readonly TodoUpdate: "todo_update";
170
- readonly EditorContentStart: "editor_content_start";
171
- readonly EditorContentDelta: "editor_content_delta";
172
- readonly EditorContentEnd: "editor_content_end";
173
- readonly Complete: "complete";
174
- readonly Error: "error";
175
- readonly Disconnected: "disconnected";
176
- readonly Retry: "retry";
188
+ readonly ToolApprovalRequested: "tool_approval_requested";
189
+ readonly ToolApprovalGranted: "tool_approval_granted";
190
+ readonly ToolPermissionDenied: "tool_permission_denied";
191
+ readonly ToolHarnessWarning: "tool_harness_warning";
192
+ readonly UserUnavailable: "user_unavailable";
193
+ readonly PromptSuggestion: "prompt_suggestion";
194
+ readonly StateChanged: "state_changed";
195
+ readonly Custom: "custom";
177
196
  };
178
- interface UserMessageEvent {
179
- type: "user_message";
180
- content: string;
181
- created_at?: number;
182
- }
183
- interface TitleGeneratedEvent {
184
- type: "title_generated";
185
- title: string;
186
- }
187
- interface MessageStartEvent {
188
- type: "message_start";
189
- message_id: string;
190
- conversation_id: string;
191
- model_display_name?: string;
192
- agent_name?: string;
193
- agent_display_name?: string;
194
- }
195
- interface ContentBlockDeltaEvent {
196
- type: "content_block_delta";
197
- index: number;
198
- delta: {
199
- type: "text_delta";
200
- text: string;
201
- };
197
+ type ChatEventTypeValue = (typeof ChatEventType)[keyof typeof ChatEventType];
198
+ type WireBlockKind = "text" | "thinking" | "tool_use";
199
+ type WireBlockStatus = "streaming" | "awaiting_client_result" | "ok" | "error" | "denied" | "cancelled";
200
+ type WireStopReason = "end_turn" | "tool_use" | "max_tokens" | "context_overflow" | "error";
201
+ interface WireTextDelta {
202
+ channel: "text";
203
+ text: string;
202
204
  }
203
- interface ToolUseStartEvent {
204
- type: "tool_use_start";
205
- index: number;
206
- call_id: string;
207
- tool: string;
208
- display_name?: string;
209
- description?: string;
210
- arguments: Record<string, unknown>;
211
- is_client_tool: boolean;
212
- tool_category?: string;
213
- icon_url?: string;
205
+ interface WireThinkingDelta {
206
+ channel: "thinking";
207
+ text: string;
214
208
  }
215
- interface ToolUseEndEvent {
216
- type: "tool_use_end";
217
- call_id: string;
218
- tool: string;
219
- result?: string;
220
- sources?: {
221
- title: string;
222
- url: string;
223
- snippet?: string;
224
- }[];
225
- duration_ms?: number;
226
- }
227
- interface ToolExecutingEvent {
228
- type: "tool_executing";
229
- call_id: string;
230
- tool: string;
209
+ interface WireSignatureDelta {
210
+ channel: "signature";
211
+ signature: string;
231
212
  }
232
- interface ToolProgressEvent {
233
- type: "tool_progress";
234
- call_id: string;
235
- tool: string;
236
- index: number;
237
- total: number;
238
- item: {
239
- title: string;
240
- url: string;
241
- snippet?: string;
242
- };
213
+ interface WireInputDelta {
214
+ channel: "input";
215
+ partial_json: string;
243
216
  }
244
- interface AgentStartEvent {
245
- type: "agent_start";
246
- agent_name: string;
247
- agent_display_name?: string;
248
- avatar_url?: string;
217
+ interface WireInputArgDelta {
218
+ channel: "input_arg";
219
+ arg_name: string;
220
+ text: string;
249
221
  }
250
- interface AgentEndEvent {
251
- type: "agent_end";
252
- agent_name: string;
222
+ interface WireOutputDelta {
223
+ channel: "output";
224
+ stream: "stdout" | "stderr" | "progress";
225
+ chunk: string;
253
226
  }
254
- interface SubagentStartEvent {
255
- type: "subagent_start";
256
- agent_name: string;
257
- display_name: string;
258
- tool_call_id: string;
259
- avatar_url?: string;
260
- description?: string;
227
+ interface WireStatusDelta {
228
+ channel: "status";
229
+ status: "executing" | "awaiting_client_result" | "awaiting_approval" | "denied";
230
+ note?: string;
261
231
  }
262
- interface SubagentContentDeltaEvent {
263
- type: "subagent_content_delta";
264
- agent_name: string;
265
- tool_call_id: string;
266
- delta: {
267
- type: "text_delta";
268
- text: string;
269
- };
232
+ type WireBlockDeltaPayload = WireTextDelta | WireThinkingDelta | WireSignatureDelta | WireInputDelta | WireInputArgDelta | WireOutputDelta | WireStatusDelta;
233
+ interface WireEnvelope {
234
+ seq: number;
235
+ ts: number;
236
+ job_id: string;
270
237
  }
271
- interface SubagentUpdateEvent {
272
- type: "subagent_update";
273
- agent_name: string;
274
- display_name: string;
275
- tool_call_id: string;
276
- }
277
- interface SubagentEndEvent {
278
- type: "subagent_end";
279
- agent_name: string;
280
- display_name: string;
281
- tool_call_id: string;
282
- }
283
- interface ThinkingDeltaEvent {
284
- type: "thinking_delta";
285
- delta: {
286
- type: "thinking";
287
- text: string;
238
+ interface WireMessageStart extends WireEnvelope {
239
+ type: "message_start";
240
+ turn_id: string;
241
+ model: string;
242
+ agent_name?: string | null;
243
+ agent_display_name?: string | null;
244
+ agent_avatar_url?: string | null;
245
+ }
246
+ interface WireBlockStart extends WireEnvelope {
247
+ type: "block_start";
248
+ turn_id: string;
249
+ path: number[];
250
+ parent_path?: number[] | null;
251
+ kind: WireBlockKind;
252
+ metadata: Record<string, unknown>;
253
+ }
254
+ interface WireBlockDelta extends WireEnvelope {
255
+ type: "block_delta";
256
+ turn_id: string;
257
+ path: number[];
258
+ delta: WireBlockDeltaPayload;
259
+ }
260
+ interface WireBlockStop extends WireEnvelope {
261
+ type: "block_stop";
262
+ turn_id: string;
263
+ path: number[];
264
+ status: WireBlockStatus;
265
+ final: Record<string, unknown>;
266
+ }
267
+ interface WireMessageStop extends WireEnvelope {
268
+ type: "message_stop";
269
+ turn_id: string;
270
+ stop_reason: WireStopReason;
271
+ usage: {
272
+ input_tokens?: number;
273
+ output_tokens?: number;
274
+ cached_tokens?: number;
288
275
  };
276
+ ttfb_ms?: number | null;
277
+ total_ms: number;
278
+ stall_count: number;
289
279
  }
290
- interface ThinkingCompleteEvent {
291
- type: "thinking_complete";
292
- }
293
- interface CapsuleOutputEvent {
294
- type: "capsule_output";
295
- tool_name: string;
296
- agent_name: string;
297
- command?: string;
298
- output: string;
299
- duration_ms?: number;
300
- call_id?: string;
301
- }
302
- interface CapsuleOutputChunkEvent {
303
- type: "capsule_output_chunk";
304
- call_id: string;
305
- stream: "stdout" | "stderr";
306
- chunk: string;
307
- }
308
- interface TodoUpdateEvent {
309
- type: "todo_update";
310
- todos: TodoItem[];
280
+ interface WireStallWarning extends WireEnvelope {
281
+ type: "stall";
282
+ since_last_event_ms: number;
283
+ stall_count: number;
311
284
  }
312
- interface MessageStopEvent {
313
- type: "message_stop";
314
- stop_reason: "end_turn" | "tool_use";
315
- title?: string;
316
- metrics?: Record<string, unknown>;
317
- job_id?: string;
285
+ interface WireRetryEvent extends WireEnvelope {
286
+ type: "retry";
287
+ attempt: number;
288
+ reason: string;
289
+ backoff_ms: number;
290
+ strategy?: string | null;
291
+ max_attempts?: number | null;
292
+ context_recovery?: Record<string, unknown> | null;
318
293
  }
319
- interface SSEErrorEvent {
294
+ interface WireErrorEvent extends WireEnvelope {
320
295
  type: "error";
321
296
  code: string;
322
297
  message: string;
323
- }
324
- interface SubagentToolUseEvent {
325
- type: "subagent_tool_use";
326
- agent_name: string;
327
- tool: string;
328
- tool_call_id: string;
329
- result?: string;
330
- }
331
- interface AssetCreatedEvent {
332
- type: "asset_created";
333
- asset_id: string;
298
+ block_path?: number[] | null;
299
+ retry_after?: number;
300
+ retry_after_sec?: number;
301
+ reset_at?: number | string;
302
+ scope?: string;
303
+ policy_id?: string;
304
+ limit?: number;
305
+ remaining?: number;
306
+ request_id?: string;
307
+ }
308
+ interface WireKeepalive extends WireEnvelope {
309
+ type: "keepalive";
310
+ since_last_event_ms: number;
311
+ }
312
+ interface WireCustomEvent extends WireEnvelope {
313
+ type: "custom";
334
314
  name: string;
335
- url: string;
336
- media_type: string;
337
- size_bytes: number;
338
- }
339
- interface EditorContentStartEvent {
340
- type: "editor_content_start";
341
- call_id: string;
342
- path: string;
343
- language: string;
344
- }
345
- interface EditorContentDeltaEvent {
346
- type: "editor_content_delta";
347
- call_id: string;
348
- path: string;
349
- delta: string;
350
- }
351
- interface EditorContentEndEvent {
352
- type: "editor_content_end";
353
- call_id: string;
315
+ data: Record<string, unknown>;
354
316
  }
355
- interface RetryEvent {
356
- type: "retry";
357
- attempt: number;
358
- max_attempts: number;
359
- delay_seconds: number;
317
+ type WireEvent = WireMessageStart | WireBlockStart | WireBlockDelta | WireBlockStop | WireMessageStop | WireStallWarning | WireRetryEvent | WireErrorEvent | WireKeepalive | WireCustomEvent;
318
+ interface TurnUsage {
319
+ inputTokens: number;
320
+ outputTokens: number;
321
+ cachedTokens: number;
360
322
  }
361
- type SSEEvent = MessageStartEvent | UserMessageEvent | TitleGeneratedEvent | ContentBlockDeltaEvent | ToolUseStartEvent | ToolUseEndEvent | ToolExecutingEvent | ToolProgressEvent | AgentStartEvent | AgentEndEvent | SubagentStartEvent | SubagentContentDeltaEvent | SubagentUpdateEvent | SubagentEndEvent | SubagentToolUseEvent | ThinkingDeltaEvent | ThinkingCompleteEvent | CapsuleOutputEvent | CapsuleOutputChunkEvent | TodoUpdateEvent | MessageStopEvent | AssetCreatedEvent | EditorContentStartEvent | EditorContentDeltaEvent | EditorContentEndEvent | RetryEvent | SSEErrorEvent;
362
- type ChatEvent = {
363
- type: "connected";
323
+ type BlockDeltaPayload = {
324
+ channel: "text";
325
+ text: string;
364
326
  } | {
365
- type: "user_message";
366
- content: string;
367
- createdAt?: number;
327
+ channel: "thinking";
328
+ text: string;
368
329
  } | {
369
- type: "title_generated";
370
- title: string;
330
+ channel: "signature";
331
+ signature: string;
371
332
  } | {
372
- type: "chunk";
333
+ channel: "input";
334
+ partialJson: string;
335
+ } | {
336
+ channel: "inputArg";
337
+ argName: string;
373
338
  text: string;
374
339
  } | {
375
- type: "tool_call";
376
- request: ToolCallRequest;
340
+ channel: "output";
341
+ stream: "stdout" | "stderr" | "progress";
342
+ chunk: string;
377
343
  } | {
378
- type: "tool_executing";
379
- name: string;
380
- call_id?: string;
344
+ channel: "status";
345
+ status: "executing" | "awaiting_client_result" | "awaiting_approval" | "denied";
346
+ note?: string;
347
+ };
348
+ type ChatEvent = {
349
+ type: "connected";
381
350
  } | {
382
- type: "tool_completed";
383
- name: string;
384
- result: string;
351
+ type: "disconnected";
385
352
  } | {
386
- type: "tool_progress";
387
- callId: string;
388
- tool: string;
389
- index: number;
390
- total: number;
391
- item: {
392
- title: string;
393
- url: string;
394
- snippet?: string;
395
- };
353
+ type: "message_start";
354
+ turnId: string;
355
+ model: string;
356
+ agentName?: string | null;
357
+ agentDisplayName?: string | null;
358
+ agentAvatarUrl?: string | null;
396
359
  } | {
397
- type: "tool_end";
398
- callId: string;
399
- toolName: string;
400
- result?: string;
401
- sources?: {
402
- title: string;
403
- url: string;
404
- snippet?: string;
405
- }[];
406
- durationMs?: number;
407
- } | {
408
- type: "agent_start";
409
- agentName: string;
410
- agentDisplayName?: string;
411
- avatarUrl?: string;
360
+ type: "message_stop";
361
+ turnId: string;
362
+ jobId: string;
363
+ stopReason: WireStopReason;
364
+ usage: TurnUsage;
365
+ ttfbMs?: number | null;
366
+ totalMs: number;
367
+ stallCount: number;
412
368
  } | {
413
- type: "agent_end";
414
- agentName: string;
369
+ type: "block_start";
370
+ turnId: string;
371
+ path: number[];
372
+ parentPath?: number[] | null;
373
+ kind: WireBlockKind;
374
+ metadata: Record<string, unknown>;
415
375
  } | {
416
- type: "thinking_delta";
417
- text: string;
376
+ type: "block_delta";
377
+ turnId: string;
378
+ path: number[];
379
+ delta: BlockDeltaPayload;
418
380
  } | {
419
- type: "thinking_complete";
381
+ type: "block_stop";
382
+ turnId: string;
383
+ path: number[];
384
+ status: WireBlockStatus;
385
+ final: Record<string, unknown>;
420
386
  } | {
421
- type: "subagent_start";
422
- agentName: string;
423
- displayName: string;
424
- toolCallId: string;
425
- avatarUrl?: string;
426
- description?: string;
387
+ type: "stall";
388
+ sinceLastEventMs: number;
389
+ stallCount: number;
427
390
  } | {
428
- type: "subagent_chunk";
429
- agentName: string;
430
- toolCallId: string;
431
- text: string;
391
+ type: "retry";
392
+ attempt: number;
393
+ reason: string;
394
+ backoffMs: number;
395
+ strategy?: string | null;
396
+ maxAttempts?: number | null;
397
+ contextRecovery?: Record<string, unknown> | null;
432
398
  } | {
433
- type: "subagent_update";
434
- agentName: string;
435
- displayName: string;
436
- toolCallId: string;
399
+ type: "error";
400
+ code: string;
401
+ message: string;
402
+ blockPath: number[] | null;
437
403
  } | {
438
- type: "subagent_end";
439
- agentName: string;
440
- displayName: string;
441
- toolCallId: string;
404
+ type: "keepalive";
405
+ sinceLastEventMs: number;
442
406
  } | {
443
- type: "capsule_output";
444
- toolName: string;
445
- agentName: string;
446
- command?: string;
447
- output: string;
448
- durationMs?: number;
449
- callId?: string;
407
+ type: "user_message";
408
+ content: string;
409
+ createdAt?: number;
450
410
  } | {
451
- type: "capsule_output_chunk";
452
- callId: string;
453
- stream: "stdout" | "stderr";
454
- chunk: string;
411
+ type: "title_generated";
412
+ title: string;
455
413
  } | {
456
414
  type: "todo_update";
457
415
  todos: TodoItem[];
458
416
  } | {
459
- type: "complete";
460
- content: string;
461
- conversationId: string;
462
- messageId: string;
463
- title?: string;
464
- metrics?: Record<string, unknown>;
465
- job_id?: string;
417
+ type: "context_update";
418
+ context: Record<string, unknown>;
419
+ phase?: string | null;
420
+ updatedAt?: number | null;
466
421
  } | {
467
- type: "subagent_tool_use";
468
- agentName: string;
469
- toolName: string;
470
- toolCallId: string;
471
- result?: string;
422
+ type: "subagent_start";
423
+ agent: AgentIdentity;
424
+ taskCallId?: string | null;
425
+ } | {
426
+ type: "subagent_stop";
427
+ agent: AgentIdentity;
428
+ taskCallId?: string | null;
429
+ } | {
430
+ type: "context_warning";
431
+ /** Known values: "info" | "warning" | "critical". Typed as string for forward compat. */
432
+ severity: string;
433
+ utilizationPct: number;
434
+ remainingTokens: number;
435
+ windowTokens: number;
436
+ inputTokens: number;
437
+ message: string;
438
+ } | {
439
+ type: "memory_recall";
440
+ memories: MemoryRecord[];
441
+ } | {
442
+ type: "memory_update";
443
+ /** Known values: "created" | "updated" | "deleted". */
444
+ action: string;
445
+ memoryId?: string | null;
446
+ key?: string | null;
447
+ namespace?: string | null;
448
+ } | {
449
+ type: "desktop_stream";
450
+ url: string;
451
+ sandboxId?: string | null;
452
+ } | {
453
+ type: "attachment_staged";
454
+ attachmentId: string;
455
+ filename: string;
456
+ contentType?: string | null;
457
+ sizeBytes?: number | null;
458
+ } | {
459
+ type: "workspace_ready";
460
+ sandboxId: string;
461
+ workspacePath?: string | null;
472
462
  } | {
473
463
  type: "asset_created";
474
464
  assetId: string;
475
- name: string;
476
- url: string;
477
- mediaType: string;
478
- sizeBytes: number;
465
+ filename: string;
466
+ url?: string | null;
467
+ contentType?: string | null;
479
468
  } | {
480
- type: "retry";
481
- attempt: number;
482
- maxAttempts: number;
483
- delaySeconds: number;
469
+ type: "tool_approval_requested";
470
+ toolName: string;
471
+ callId: string;
472
+ arguments: Record<string, unknown>;
473
+ riskLevel?: string | null;
474
+ reason?: string | null;
484
475
  } | {
485
- type: "editor_content_start";
476
+ type: "tool_approval_granted";
477
+ toolName: string;
486
478
  callId: string;
487
- path: string;
488
- language: string;
489
479
  } | {
490
- type: "editor_content_delta";
480
+ type: "tool_permission_denied";
481
+ toolName: string;
491
482
  callId: string;
492
- path: string;
493
- delta: string;
483
+ reason?: string | null;
484
+ /** Known values: "hook" | "rule" | "user" | "timeout" | "circuit_breaker". */
485
+ deniedBy?: string | null;
494
486
  } | {
495
- type: "editor_content_end";
487
+ type: "tool_harness_warning";
488
+ toolName: string;
496
489
  callId: string;
490
+ message?: string | null;
491
+ details?: Record<string, unknown> | null;
497
492
  } | {
498
- type: "model_info";
499
- name: string;
493
+ type: "user_unavailable";
494
+ consecutiveTimeouts: number;
495
+ toolName?: string | null;
500
496
  } | {
501
- type: "blocks_changed";
502
- blocks: Block[];
497
+ type: "prompt_suggestion";
498
+ suggestions: string[];
503
499
  } | {
504
- type: "error";
505
- error: Error;
500
+ type: "state_changed";
501
+ /**
502
+ * Job lifecycle state. Known values from the backend today include
503
+ * "queued" | "running" | "waiting_for_tool" | "completed" | "failed".
504
+ * Typed as string for forward compat.
505
+ */
506
+ state: string;
506
507
  } | {
507
- type: "disconnected";
508
+ type: "custom";
509
+ name: string;
510
+ data: Record<string, unknown>;
508
511
  };
509
512
  interface Conversation {
510
513
  id: string;
@@ -523,12 +526,20 @@ interface Message {
523
526
  createdAt: string;
524
527
  toolCalls?: ToolCallRequest[];
525
528
  }
529
+ interface UIComponentsConfig {
530
+ enabled: boolean;
531
+ /** Protocol slug (e.g. "a2ui"). Null when disabled. */
532
+ protocol: string | null;
533
+ /** MIME type to match against embedded resources (e.g. "application/json+a2ui"). */
534
+ mimeType: string | null;
535
+ }
526
536
  interface ProjectStatus {
527
537
  isReady: boolean;
528
538
  llmConfigured: boolean;
529
539
  llmProvider?: string;
530
540
  llmModel?: string;
531
541
  message: string;
542
+ uiComponents: UIComponentsConfig;
532
543
  }
533
544
  interface AgentInfo {
534
545
  name: string;
@@ -538,52 +549,67 @@ interface AgentInfo {
538
549
  isEnabled: boolean;
539
550
  avatarUrl?: string;
540
551
  }
552
+ interface TeamSummary {
553
+ id: string;
554
+ name: string;
555
+ slug: string;
556
+ isDefault: boolean;
557
+ /** Caller's role in this team (e.g. "owner", "admin", "member"). */
558
+ role: string;
559
+ }
560
+ interface ProjectSummary {
561
+ id: string;
562
+ name: string;
563
+ teamId: string;
564
+ createdAt: string;
565
+ updatedAt: string;
566
+ }
541
567
  interface SkillInfo {
542
568
  name: string;
543
569
  displayName: string;
544
570
  description: string;
545
571
  isEnabled: boolean;
546
572
  }
547
- interface SubagentState {
548
- agentName: string;
549
- displayName: string;
550
- avatarUrl?: string;
551
- description?: string;
552
- content: string;
553
- isActive: boolean;
554
- }
555
- interface ToolState {
556
- toolName: string;
557
- displayName?: string;
558
- description?: string;
559
- arguments?: Record<string, unknown>;
560
- callId: string;
561
- status: "calling" | "executing" | "completed";
562
- isClientTool: boolean;
563
- }
564
- interface CapsuleOutput {
565
- toolName: string;
566
- agentName: string;
567
- command?: string;
568
- output: string;
569
- durationMs?: number;
570
- callId?: string;
571
- }
572
- interface Source {
573
- title: string;
574
- url: string;
575
- }
576
- interface TodoItem {
577
- content: string;
578
- status: "pending" | "in_progress" | "completed";
579
- id?: string;
580
- }
581
573
  interface JobCreateResponse {
582
574
  job_id: string;
583
575
  conversation_id: string;
584
576
  message_id: string;
585
577
  status: string;
586
578
  }
579
+ interface JobStatus {
580
+ jobId: string;
581
+ status: string;
582
+ createdAt: string | null;
583
+ startedAt: string | null;
584
+ completedAt: string | null;
585
+ errorMessage: string | null;
586
+ inputTokens: number;
587
+ outputTokens: number;
588
+ }
589
+ interface ActiveJob {
590
+ jobId: string | null;
591
+ status: string;
592
+ }
593
+ interface JobSummary {
594
+ jobId: string;
595
+ status: string;
596
+ replacesJobId: string | null;
597
+ responseContent: Record<string, unknown> | null;
598
+ metrics: Record<string, unknown> | null;
599
+ createdAt: string | null;
600
+ }
601
+ interface FeedbackRequest {
602
+ /** 1 for thumbs up, -1 for thumbs down. */
603
+ rating: 1 | -1;
604
+ comment?: string | null;
605
+ }
606
+ interface FeedbackResponse {
607
+ id: string;
608
+ jobId: string;
609
+ rating: number;
610
+ comment: string | null;
611
+ createdAt: string;
612
+ }
587
613
  interface ChatStreamRequest {
588
614
  message?: string;
589
615
  conversation_id?: string;
@@ -594,6 +620,7 @@ interface ChatStreamRequest {
594
620
  upload_ids?: string[];
595
621
  agent_name?: string;
596
622
  enable_search?: boolean;
623
+ plan_mode?: boolean;
597
624
  }
598
625
  interface ToolResultRequest {
599
626
  conversation_id: string;
@@ -606,6 +633,14 @@ interface ToolResult {
606
633
  result: string;
607
634
  is_error: boolean;
608
635
  }
636
+ type ToolApprovalDecision = "allow" | "deny";
637
+ type ToolApprovalScope = "once" | "conversation" | "always";
638
+ interface ToolApprovalRequest {
639
+ job_id: string;
640
+ call_id: string;
641
+ decision: ToolApprovalDecision;
642
+ scope: ToolApprovalScope;
643
+ }
609
644
  interface ToolDefinition {
610
645
  name: string;
611
646
  description: string;
@@ -642,6 +677,7 @@ interface SendOptions$1 {
642
677
  uploadIds?: string[];
643
678
  agentName?: string;
644
679
  enableSearch?: boolean;
680
+ planMode?: boolean;
645
681
  }
646
682
  interface ConversationAsset {
647
683
  id: string;
@@ -656,11 +692,53 @@ interface ConversationAsset {
656
692
  }
657
693
 
658
694
  declare class AstralformClient {
659
- private readonly apiKey;
660
695
  private readonly baseURL;
661
- private readonly userId;
662
696
  private readonly fetchFn;
697
+ /**
698
+ * Auth state is mutable so callers can rotate access tokens or switch
699
+ * project context without re-instantiating the client. API-key mode is
700
+ * effectively immutable in practice but uses the same shape for uniformity.
701
+ */
702
+ private auth;
663
703
  constructor(config: AstralformConfig);
704
+ /**
705
+ * Replace the current OIDC access token without reconstructing the client.
706
+ * Use after refreshing via the host's token manager (e.g., Supabase JS SDK).
707
+ * Throws if the client was created in API-key mode.
708
+ */
709
+ updateAccessToken(accessToken: string): void;
710
+ /**
711
+ * Swap the active project for a user-token client. The backend verifies the
712
+ * current developer has access to the new project; a 403 comes back if not.
713
+ */
714
+ updateProjectId(projectId: string): void;
715
+ /**
716
+ * Set (or clear) the end-user override for user-token mode.
717
+ *
718
+ * Pass `null` or an empty string to clear — subsequent requests go
719
+ * back to scoping against the developer's own identity. Throws if
720
+ * called in API-key mode, where end-user context already travels via
721
+ * the constructor's `userId` field.
722
+ */
723
+ updateEndUserId(endUserId: string | null): void;
724
+ /** Current end-user override in user-token mode, or `null` if unset. */
725
+ get endUserId(): string | null;
726
+ /**
727
+ * Active project for user-token mode, or `null` if pre-pick (client
728
+ * was constructed without one). For API-key mode the project is baked
729
+ * into the key, so this getter returns `null` there too — use
730
+ * `authMode` to disambiguate.
731
+ */
732
+ get projectId(): string | null;
733
+ /** Which auth mode this client was constructed with. */
734
+ get authMode(): "api_key" | "user_token";
735
+ /**
736
+ * Authorization + identity headers for the current auth mode, without
737
+ * `Content-Type`. Suitable for JSON requests (paired with the JSON header
738
+ * in the `headers` getter) and for multipart uploads where the browser
739
+ * must set its own `Content-Type` boundary.
740
+ */
741
+ private get authHeaders();
664
742
  private get headers();
665
743
  private request;
666
744
  get<T>(path: string): Promise<T>;
@@ -680,13 +758,46 @@ declare class AstralformClient {
680
758
  getSkills(): Promise<SkillInfo[]>;
681
759
  getConversationEvents(conversationId: string, jobId?: string): Promise<ConversationEvent[]>;
682
760
  submitToolResult(request: ToolResultRequest): Promise<void>;
761
+ submitToolApproval(request: ToolApprovalRequest): Promise<void>;
683
762
  private mapAsset;
684
763
  uploadFile(conversationId: string, file: Blob, filename?: string): Promise<ConversationAsset>;
685
764
  listUploads(conversationId: string): Promise<ConversationAsset[]>;
686
765
  listOutputs(conversationId: string): Promise<ConversationAsset[]>;
766
+ listTeams(): Promise<TeamSummary[]>;
767
+ listProjects(teamId: string): Promise<ProjectSummary[]>;
687
768
  createJob(request: ChatStreamRequest): Promise<JobCreateResponse>;
688
769
  streamJobEvents(jobId: string, afterSeq?: number, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
689
770
  cancelJob(jobId: string): Promise<void>;
771
+ getJob(jobId: string): Promise<JobStatus>;
772
+ submitFeedback(jobId: string, request: FeedbackRequest): Promise<FeedbackResponse>;
773
+ getActiveJob(conversationId: string): Promise<ActiveJob>;
774
+ listJobs(conversationId: string): Promise<JobSummary[]>;
775
+ }
776
+
777
+ /**
778
+ * Minimal adapter contract. Frontends extend this with a `render()`
779
+ * method (or equivalent) returning their framework's view type.
780
+ */
781
+ interface ProtocolAdapter {
782
+ /** IANA-style MIME type this adapter handles (e.g. ``application/json+a2ui``). */
783
+ readonly mimeType: string;
784
+ }
785
+ /**
786
+ * MIME-keyed adapter map, generic on the adapter subtype so consumers
787
+ * can register richer shapes without casting on every read.
788
+ */
789
+ declare class ProtocolRegistry<T extends ProtocolAdapter = ProtocolAdapter> {
790
+ private adapters;
791
+ /** Register or replace the adapter for a MIME type. */
792
+ register(adapter: T): void;
793
+ /** Remove the adapter for a MIME type. No-op if not registered. */
794
+ unregister(mimeType: string): void;
795
+ /** Returns the adapter for a MIME type, or ``null`` if none is registered. */
796
+ get(mimeType: string): T | null;
797
+ has(mimeType: string): boolean;
798
+ /** Drop every adapter. Called when a session disconnects. */
799
+ clear(): void;
800
+ listMimeTypes(): string[];
690
801
  }
691
802
 
692
803
  interface ChatStorage {
@@ -727,31 +838,38 @@ declare class ToolRegistry {
727
838
  }
728
839
 
729
840
  type ChatEventHandler = (event: ChatEvent) => void;
841
+ /**
842
+ * ChatSession — translates the backend wire protocol into typed ChatEvents
843
+ * for consumers. Owns HTTP + SSE plumbing, conversation state, and the
844
+ * client-tool round-trip. Does NOT own block construction — consumers
845
+ * build their own block state from the typed events.
846
+ */
730
847
  declare class ChatSession {
731
848
  readonly client: AstralformClient;
732
849
  readonly toolRegistry: ToolRegistry;
733
850
  readonly storage: ChatStorage;
734
- readonly blockBuilder: BlockBuilder;
851
+ /**
852
+ * Pluggable UI protocol adapters. Consumers register a framework-
853
+ * specific adapter (e.g. React) for each MIME type they can render,
854
+ * typically gated on ``session.projectStatus.uiComponents.protocol``.
855
+ * ``ToolBlock``-style consumers look up the adapter for an incoming
856
+ * embedded resource and hand off rendering.
857
+ */
858
+ readonly protocols: ProtocolRegistry<ProtocolAdapter>;
735
859
  conversationId: string | null;
736
860
  conversations: Conversation[];
737
861
  messages: Message[];
738
- streamingContent: string;
739
862
  isStreaming: boolean;
740
- executingTool: string | null;
741
863
  projectStatus: ProjectStatus | null;
742
864
  agents: AgentInfo[];
743
865
  skills: SkillInfo[];
744
866
  enabledClientTools: Set<string>;
745
867
  modelDisplayName: string | null;
746
- thinkingContent: string;
747
- isThinking: boolean;
748
- activeSubagents: Map<string, SubagentState>;
749
- capsuleOutputs: CapsuleOutput[];
750
- todos: TodoItem[];
751
- activeTools: Map<string, ToolState>;
868
+ private accumulatedText;
869
+ private currentTextPath;
752
870
  private handlers;
753
871
  private abortController;
754
- constructor(config: AstralformConfig, storage?: ChatStorage, blockBuilder?: BlockBuilder);
872
+ constructor(config: AstralformConfig, storage?: ChatStorage);
755
873
  on(handler: ChatEventHandler): () => void;
756
874
  private emit;
757
875
  connect(): Promise<void>;
@@ -767,16 +885,22 @@ declare class ChatSession {
767
885
  currentJobId: string | null;
768
886
  private consumeJobStream;
769
887
  /**
770
- * Shared event consumption loop used by both consumeJobStream and reconnectToJob.
888
+ * Shared event consumption loop. Parses each wire event, updates
889
+ * minimal session state, and emits typed ChatEvents to consumers.
771
890
  */
772
891
  private consumeEventStream;
892
+ private dispatchWireEvent;
773
893
  /**
774
- * Apply a single SSE event to session state and notify consumers.
775
- * Shared between live streaming and historical event replay.
894
+ * State mutations driven by wire events. Kept separate from translation so
895
+ * the pure wire → ChatEvent mapping can live in translate.ts and be reused
896
+ * by the replay path.
897
+ *
898
+ * ``messageId`` is the server-assigned assistant message id for the current
899
+ * turn; empty in the reconnect and conversation-switch replay paths where
900
+ * messages have already been loaded from REST and shouldn't be re-pushed.
776
901
  */
777
- private applyEvent;
902
+ private applyWireSideEffects;
778
903
  private executeClientTools;
779
- private completeStream;
780
904
  /**
781
905
  * Load conversation context (messages) without replaying events.
782
906
  * Used before reconnectToJob — SSE replay handles event replay.
@@ -785,33 +909,35 @@ declare class ChatSession {
785
909
  /**
786
910
  * Reconnect to a running job's SSE stream (e.g. after page reload).
787
911
  * Replays all events from the beginning and continues live.
788
- * Does NOT reset BlockBuilder — caller controls reset.
789
912
  */
790
913
  reconnectToJob(jobId: string): Promise<void>;
791
- /** Detach from the SSE stream without cancelling the job.
792
- * The backend job keeps running — caller can reconnect later. */
914
+ /** Detach from the SSE stream without cancelling the job. */
793
915
  detach(): void;
794
916
  /** Stop the job and disconnect (explicit user action). */
795
917
  disconnect(): void;
796
918
  createNewConversation(): Promise<string>;
797
- switchConversation(id: string, jobId?: string): Promise<void>;
919
+ switchConversation(id: string, jobId?: string,
920
+ /**
921
+ * User prompt that triggered this job, if known. Emitted as a
922
+ * synthetic ``user_message`` ChatEvent right before the first
923
+ * ``message_start`` of the replay. User messages aren't persisted
924
+ * in ``job_events``, so without this the restored conversation
925
+ * would show the agent response with no visible prompt above it.
926
+ */
927
+ userMessageContent?: string): Promise<void>;
798
928
  deleteConversation(id: string): Promise<void>;
799
929
  toggleClientTool(name: string): boolean;
800
930
  }
801
931
 
802
- /**
803
- * Standard event handlers for BlockBuilder.
804
- *
805
- * These define the default event→block mapping rules. Clients import
806
- * and register them explicitly:
807
- *
808
- * import { BlockBuilder, standardHandlers } from "@astralform/js";
809
- * const builder = new BlockBuilder();
810
- * builder.registerHandlers(standardHandlers);
811
- */
812
-
813
- declare const standardHandlers: Record<string, EventHandler$1>;
814
-
932
+ interface RateLimitErrorDetails {
933
+ retryAfterSec?: number;
934
+ resetAt?: number;
935
+ scope?: string;
936
+ policyId?: string;
937
+ limit?: number;
938
+ remaining?: number;
939
+ requestId?: string;
940
+ }
815
941
  declare class AstralformError extends Error {
816
942
  code: string;
817
943
  constructor(message: string, code: string);
@@ -820,7 +946,14 @@ declare class AuthenticationError extends AstralformError {
820
946
  constructor(message?: string);
821
947
  }
822
948
  declare class RateLimitError extends AstralformError {
823
- constructor(message?: string);
949
+ readonly retryAfterSec?: number;
950
+ readonly resetAt?: number;
951
+ readonly scope?: string;
952
+ readonly policyId?: string;
953
+ readonly limit?: number;
954
+ readonly remaining?: number;
955
+ readonly requestId?: string;
956
+ constructor(message?: string, details?: RateLimitErrorDetails);
824
957
  }
825
958
  declare class LLMNotConfiguredError extends AstralformError {
826
959
  constructor(message?: string);
@@ -847,12 +980,18 @@ declare function streamJobSSE(options: StreamJobSSEOptions): AsyncGenerator<Chat
847
980
  *
848
981
  * Sits on top of ChatSession and manages the state machine for
849
982
  * multi-conversation SSE streaming. Framework-agnostic: emits
850
- * callbacks instead of writing to any state management library.
983
+ * typed events to registered handlers. Block construction is NOT
984
+ * the SDK's concern — consumers build their own block tree from
985
+ * the forwarded ``ChatEvent`` instances.
851
986
  *
852
987
  * import { ChatSession, StreamManager } from "@astralform/js";
853
988
  * const session = new ChatSession({ ... });
854
989
  * const manager = new StreamManager(session);
855
- * manager.on("blocksChanged", (convId, blocks) => { ... });
990
+ * manager.on((event) => {
991
+ * if (event.type === "event") {
992
+ * // event.event is a typed ChatEvent — dispatch to your reducer
993
+ * }
994
+ * });
856
995
  * await manager.send("Hello");
857
996
  */
858
997
 
@@ -861,15 +1000,12 @@ interface SendOptions {
861
1000
  enableSearch?: boolean;
862
1001
  agentName?: string;
863
1002
  uploadIds?: string[];
1003
+ planMode?: boolean;
864
1004
  }
865
1005
  type StreamManagerEvent = {
866
1006
  type: "stateChange";
867
1007
  state: StreamState;
868
1008
  conversationId: string | null;
869
- } | {
870
- type: "blocksChanged";
871
- conversationId: string;
872
- blocks: Block[];
873
1009
  } | {
874
1010
  type: "conversationChanged";
875
1011
  conversationId: string | null;
@@ -909,10 +1045,81 @@ declare class StreamManager {
909
1045
  deleteConversation(id: string): Promise<void>;
910
1046
  stop(): void;
911
1047
  destroy(): void;
912
- private prepareUserBlock;
913
1048
  private finalizeStream;
914
1049
  private restore;
915
1050
  private setActiveConversation;
916
1051
  }
917
1052
 
918
- export { type AgentBlock, type AgentEndEvent, type AgentInfo, type AgentStartEvent, type AssetBlock, AstralformClient, type AstralformConfig, AstralformError, AuthenticationError, type Block, BlockBuilder, type CapsuleBlock, type CapsuleOutput, type CapsuleOutputChunkEvent, type CapsuleOutputEvent, type ChatEvent, ChatEventType, ChatSession, type ChatStorage, type ChatStreamEvent, type ChatStreamRequest, ConnectionError, type ContentBlockDeltaEvent, type Conversation, type ConversationAsset, type ConversationEvent, type EditorBlock, type ErrorBlock, type EventHandler$1 as EventHandler, InMemoryStorage, type JobCreateResponse, LLMNotConfiguredError, type Message, type MessageStartEvent, type MessageStopEvent, type ProjectStatus, RateLimitError, type RetryEvent, type SSEErrorEvent, type SSEEvent, type SendOptions, ServerError, type SkillInfo, type Source, StreamAbortedError, type StreamJobSSEOptions, StreamManager, type StreamManagerEvent, type StreamState, type SubagentBlock, type SubagentContentDeltaEvent, type SubagentEndEvent, type SubagentStartEvent, type SubagentState, type SubagentToolUseEvent, type TextBlock, type ThinkingBlock, type ThinkingCompleteEvent, type ThinkingDeltaEvent, type TodoBlock, type TodoItem, type TodoUpdateEvent, type ToolBlock, type ToolCallRequest, type ToolDefinition, type ToolExecutingEvent, type ToolHandler, type ToolProgressEvent, ToolRegistry, type ToolResult, type ToolResultRequest, type ToolState, type ToolUseEndEvent, type ToolUseStartEvent, type UserBlock, generateId, standardHandlers, streamJobSSE };
1053
+ /**
1054
+ * Translate a WireBlockDeltaPayload into the consumer-facing shape. Returns
1055
+ * ``null`` for unknown channels so forward-compatible backends can add new
1056
+ * ones without breaking old clients.
1057
+ */
1058
+ declare function translateDelta(wire: WireBlockDeltaPayload): BlockDeltaPayload | null;
1059
+
1060
+ /**
1061
+ * Raw SSE event shape returned by GET /v1/conversations/{id}/events.
1062
+ * Mirrors what JobEventWriter persists to the job_events table.
1063
+ */
1064
+ interface RawSseEvent {
1065
+ seq: number;
1066
+ event: string;
1067
+ data: Record<string, unknown>;
1068
+ /** Epoch ms when the event was persisted (from job_events.created_at). */
1069
+ created_at?: number;
1070
+ }
1071
+ /**
1072
+ * Map a raw SSE event (persisted in job_events) into the SDK ChatEvent
1073
+ * format. Returns an array because some rows (malformed / ``done`` sentinels)
1074
+ * map to zero events.
1075
+ */
1076
+ declare function mapSseToChat(raw: RawSseEvent): ChatEvent[];
1077
+ /**
1078
+ * Replay persisted SSE events through the provided handler, interleaving
1079
+ * user messages from session.messages at the first message_start of each
1080
+ * turn (user messages aren't persisted in job_events).
1081
+ */
1082
+ declare function replayEvents(sseEvents: RawSseEvent[], userMessages: {
1083
+ role: string;
1084
+ content: string;
1085
+ }[], handleEvent: (event: ChatEvent) => void, addBlock: (block: {
1086
+ type: "user";
1087
+ id: string;
1088
+ content: string;
1089
+ }) => void): void;
1090
+
1091
+ /**
1092
+ * Parsed shape of an MCP-style embedded resource, as emitted by the
1093
+ * backend's UI component tools (``render_surface``, ``update_surface``).
1094
+ */
1095
+ interface EmbeddedResource {
1096
+ /** IANA-style MIME type, e.g. "application/json+a2ui". */
1097
+ mimeType: string;
1098
+ /** Opaque URI (e.g. "a2ui://surface/my-form"). */
1099
+ uri: string;
1100
+ /** Protocol-specific payload — shape depends on ``mimeType``. */
1101
+ payload: Record<string, unknown>;
1102
+ }
1103
+ /**
1104
+ * Detect whether a value is an embedded resource wrapper. The check is
1105
+ * purposely loose — any object with ``_embedded_resource: true`` is
1106
+ * accepted, which matches the MCP convention and keeps the SDK
1107
+ * forward-compatible with future protocols.
1108
+ */
1109
+ declare function isEmbeddedResource(value: unknown): value is {
1110
+ _embedded_resource: true;
1111
+ mime_type?: string;
1112
+ uri?: string;
1113
+ payload?: Record<string, unknown>;
1114
+ };
1115
+ /**
1116
+ * Parse an embedded resource from arbitrary tool output. Returns
1117
+ * ``null`` when the value isn't an embedded resource or is malformed.
1118
+ *
1119
+ * Accepts either an object (the preferred wire format) or a JSON
1120
+ * string containing one (defense in depth — some transport layers
1121
+ * historically serialized tool results before sending).
1122
+ */
1123
+ declare function parseEmbeddedResource(value: unknown): EmbeddedResource | null;
1124
+
1125
+ export { type ActiveJob, type AgentIdentity, type AgentInfo, type AssetCreatedPayload, type AstralformApiKeyConfig, AstralformClient, type AstralformConfig, AstralformError, type AstralformUserTokenConfig, type AttachmentStagedPayload, AuthenticationError, type BlockDeltaPayload, type ChatEvent, ChatEventType, type ChatEventTypeValue, ChatSession, type ChatStorage, type ChatStreamEvent, type ChatStreamRequest, ConnectionError, type ContextUpdatePayload, type ContextWarningPayload, type Conversation, type ConversationAsset, type ConversationEvent, type DesktopStreamPayload, type EmbeddedResource, type FeedbackRequest, type FeedbackResponse, InMemoryStorage, type JobCreateResponse, type JobStatus, type JobSummary, LLMNotConfiguredError, type MemoryRecallPayload, type MemoryRecord, type MemoryUpdatePayload, type Message, type ProjectStatus, type ProjectSummary, type PromptSuggestionPayload, type ProtocolAdapter, ProtocolRegistry, RateLimitError, type RateLimitErrorDetails, type RawSseEvent, type SendOptions, ServerError, type SkillInfo, StreamAbortedError, type StreamJobSSEOptions, StreamManager, type StreamManagerEvent, type StreamState, type SubagentStartPayload, type SubagentStopPayload, type TaskStatus, type TeamSummary, type TitleGeneratedPayload, type TodoItem, type TodoUpdatePayload, type ToolApprovalDecision, type ToolApprovalGrantedPayload, type ToolApprovalRequest, type ToolApprovalRequestedPayload, type ToolApprovalScope, type ToolCallRequest, type ToolDefinition, type ToolHandler, type ToolHarnessWarningPayload, type ToolPermissionDeniedPayload, ToolRegistry, type ToolResult, type ToolResultRequest, type TurnUsage, type UIComponentsConfig, type UserUnavailablePayload, type WireBlockDelta, type WireBlockDeltaPayload, type WireBlockKind, type WireBlockStart, type WireBlockStatus, type WireBlockStop, type WireCustomEvent, type WireErrorEvent, type WireEvent, type WireInputArgDelta, type WireInputDelta, type WireKeepalive, type WireMessageStart, type WireMessageStop, type WireOutputDelta, type WireRetryEvent, type WireSignatureDelta, type WireStallWarning, type WireStatusDelta, type WireStopReason, type WireTextDelta, type WireThinkingDelta, type WorkspaceReadyPayload, generateId, isEmbeddedResource, mapSseToChat, parseEmbeddedResource, replayEvents, streamJobSSE, translateDelta };