@astralform/js 0.2.1 → 0.2.3

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.cts CHANGED
@@ -13,6 +13,7 @@ interface UserBlock {
13
13
  type: "user";
14
14
  id: string;
15
15
  content: string;
16
+ createdAt?: number;
16
17
  }
17
18
  interface TextBlock {
18
19
  type: "text";
@@ -64,13 +65,66 @@ interface ToolBlock {
64
65
  durationMs?: number;
65
66
  result?: string;
66
67
  }
68
+ interface CapsuleBlock {
69
+ type: "capsule";
70
+ id: string;
71
+ callId: string;
72
+ toolName: string;
73
+ command?: string;
74
+ output: string;
75
+ durationMs?: number;
76
+ isActive: boolean;
77
+ }
78
+ interface AssetBlock {
79
+ type: "asset";
80
+ id: string;
81
+ assetId: string;
82
+ name: string;
83
+ url: string;
84
+ mediaType: string;
85
+ sizeBytes: number;
86
+ }
87
+ interface TodoBlock {
88
+ type: "todo";
89
+ id: string;
90
+ todos: {
91
+ content: string;
92
+ status: string;
93
+ }[];
94
+ }
95
+ interface EditorBlock {
96
+ type: "editor";
97
+ id: string;
98
+ callId: string;
99
+ path: string;
100
+ language: string;
101
+ content: string;
102
+ isStreaming: boolean;
103
+ }
67
104
  interface ErrorBlock {
68
105
  type: "error";
69
106
  id: string;
70
107
  message: string;
71
108
  }
72
- type Block = UserBlock | TextBlock | ThinkingBlock | AgentBlock | SubagentBlock | ToolBlock | ErrorBlock;
73
- type EventHandler = (event: ChatEvent, builder: BlockBuilder) => void;
109
+ interface DesktopStreamBlock {
110
+ type: "desktop_stream";
111
+ id: string;
112
+ url: string;
113
+ authKey: string;
114
+ sandboxId: string;
115
+ }
116
+ interface AttachmentBlock {
117
+ type: "attachment";
118
+ id: string;
119
+ files: {
120
+ name: string;
121
+ path: string;
122
+ mediaType: string;
123
+ sizeBytes: number;
124
+ }[];
125
+ }
126
+ type Block = UserBlock | TextBlock | ThinkingBlock | AgentBlock | SubagentBlock | ToolBlock | CapsuleBlock | AssetBlock | TodoBlock | EditorBlock | DesktopStreamBlock | AttachmentBlock | ErrorBlock;
127
+ type EventHandler$1 = (event: ChatEvent, builder: BlockBuilder) => void;
74
128
  declare class BlockBuilder {
75
129
  private _blocks;
76
130
  private _handlers;
@@ -78,8 +132,10 @@ declare class BlockBuilder {
78
132
  activeTextId: string | null;
79
133
  activeThinkingId: string | null;
80
134
  thinkingStartMs: number | null;
81
- on(eventType: string, handler: EventHandler | null): void;
82
- registerHandlers(handlers: Record<string, EventHandler | null>): void;
135
+ activeEditorId: string | null;
136
+ activeTodoId: string | null;
137
+ on(eventType: string, handler: EventHandler$1 | null): void;
138
+ registerHandlers(handlers: Record<string, EventHandler$1 | null>): void;
83
139
  processEvent(event: ChatEvent): void;
84
140
  getBlocks(): Block[];
85
141
  reset(): void;
@@ -103,9 +159,47 @@ interface AstralformConfig {
103
159
  userId: string;
104
160
  fetch?: typeof globalThis.fetch;
105
161
  }
162
+ declare const ChatEventType: {
163
+ readonly Connected: "connected";
164
+ readonly BlocksChanged: "blocks_changed";
165
+ readonly UserMessage: "user_message";
166
+ readonly TitleGenerated: "title_generated";
167
+ readonly ModelInfo: "model_info";
168
+ readonly Chunk: "chunk";
169
+ readonly ToolCall: "tool_call";
170
+ readonly ToolExecuting: "tool_executing";
171
+ readonly ToolProgress: "tool_progress";
172
+ readonly ToolCompleted: "tool_completed";
173
+ readonly ToolEnd: "tool_end";
174
+ readonly AgentStart: "agent_start";
175
+ readonly AgentEnd: "agent_end";
176
+ readonly ThinkingDelta: "thinking_delta";
177
+ readonly ThinkingComplete: "thinking_complete";
178
+ readonly SubagentStart: "subagent_start";
179
+ readonly SubagentChunk: "subagent_chunk";
180
+ readonly SubagentUpdate: "subagent_update";
181
+ readonly SubagentEnd: "subagent_end";
182
+ readonly SubagentToolUse: "subagent_tool_use";
183
+ readonly CapsuleOutput: "capsule_output";
184
+ readonly CapsuleOutputChunk: "capsule_output_chunk";
185
+ readonly AssetCreated: "asset_created";
186
+ readonly TodoUpdate: "todo_update";
187
+ readonly EditorContentStart: "editor_content_start";
188
+ readonly EditorContentDelta: "editor_content_delta";
189
+ readonly EditorContentEnd: "editor_content_end";
190
+ readonly Complete: "complete";
191
+ readonly Error: "error";
192
+ readonly Disconnected: "disconnected";
193
+ readonly Retry: "retry";
194
+ readonly ContextUpdate: "context_update";
195
+ readonly DesktopStream: "desktop_stream";
196
+ readonly AttachmentStaged: "attachment_staged";
197
+ readonly WorkspaceReady: "workspace_ready";
198
+ };
106
199
  interface UserMessageEvent {
107
200
  type: "user_message";
108
201
  content: string;
202
+ created_at?: number;
109
203
  }
110
204
  interface TitleGeneratedEvent {
111
205
  type: "title_generated";
@@ -151,6 +245,23 @@ interface ToolUseEndEvent {
151
245
  }[];
152
246
  duration_ms?: number;
153
247
  }
248
+ interface ToolExecutingEvent {
249
+ type: "tool_executing";
250
+ call_id: string;
251
+ tool: string;
252
+ }
253
+ interface ToolProgressEvent {
254
+ type: "tool_progress";
255
+ call_id: string;
256
+ tool: string;
257
+ index: number;
258
+ total: number;
259
+ item: {
260
+ title: string;
261
+ url: string;
262
+ snippet?: string;
263
+ };
264
+ }
154
265
  interface AgentStartEvent {
155
266
  type: "agent_start";
156
267
  agent_name: string;
@@ -200,13 +311,6 @@ interface ThinkingDeltaEvent {
200
311
  interface ThinkingCompleteEvent {
201
312
  type: "thinking_complete";
202
313
  }
203
- interface SourcesEvent {
204
- type: "sources";
205
- sources: Array<{
206
- title: string;
207
- url: string;
208
- }>;
209
- }
210
314
  interface CapsuleOutputEvent {
211
315
  type: "capsule_output";
212
316
  tool_name: string;
@@ -253,29 +357,6 @@ interface AssetCreatedEvent {
253
357
  media_type: string;
254
358
  size_bytes: number;
255
359
  }
256
- interface TimelineEntrySSEEvent {
257
- type: "timeline_entry";
258
- id: string;
259
- status: "started" | "completed";
260
- kind?: string;
261
- agent_name?: string;
262
- tool_name?: string;
263
- display_name?: string;
264
- tool_category?: string;
265
- viewer?: string;
266
- call_id?: string;
267
- detail?: string;
268
- started_at?: number;
269
- duration_ms?: number;
270
- output_summary?: string;
271
- sources?: Array<{
272
- title: string;
273
- url: string;
274
- snippet?: string;
275
- }>;
276
- parent_id?: string;
277
- structured_output?: Record<string, unknown>;
278
- }
279
360
  interface EditorContentStartEvent {
280
361
  type: "editor_content_start";
281
362
  call_id: string;
@@ -298,12 +379,39 @@ interface RetryEvent {
298
379
  max_attempts: number;
299
380
  delay_seconds: number;
300
381
  }
301
- type SSEEvent = MessageStartEvent | UserMessageEvent | TitleGeneratedEvent | ContentBlockDeltaEvent | ToolUseStartEvent | ToolUseEndEvent | AgentStartEvent | AgentEndEvent | SubagentStartEvent | SubagentContentDeltaEvent | SubagentUpdateEvent | SubagentEndEvent | SubagentToolUseEvent | ThinkingDeltaEvent | ThinkingCompleteEvent | SourcesEvent | CapsuleOutputEvent | CapsuleOutputChunkEvent | TodoUpdateEvent | MessageStopEvent | AssetCreatedEvent | TimelineEntrySSEEvent | EditorContentStartEvent | EditorContentDeltaEvent | EditorContentEndEvent | RetryEvent | SSEErrorEvent;
382
+ interface ContextUpdateEvent {
383
+ type: "context_update";
384
+ context: Record<string, unknown>;
385
+ phase?: string;
386
+ updated_at?: number;
387
+ }
388
+ interface DesktopStreamEvent {
389
+ type: "desktop_stream";
390
+ url: string;
391
+ auth_key: string;
392
+ sandbox_id: string;
393
+ }
394
+ interface AttachmentStagedEvent {
395
+ type: "attachment_staged";
396
+ files: {
397
+ name: string;
398
+ path: string;
399
+ media_type: string;
400
+ size_bytes: number;
401
+ }[];
402
+ }
403
+ interface WorkspaceReadyEvent {
404
+ type: "workspace_ready";
405
+ conversation_id: string;
406
+ sandbox_id: string;
407
+ }
408
+ 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 | ContextUpdateEvent | DesktopStreamEvent | AttachmentStagedEvent | WorkspaceReadyEvent | SSEErrorEvent;
302
409
  type ChatEvent = {
303
410
  type: "connected";
304
411
  } | {
305
412
  type: "user_message";
306
413
  content: string;
414
+ createdAt?: number;
307
415
  } | {
308
416
  type: "title_generated";
309
417
  title: string;
@@ -316,10 +424,22 @@ type ChatEvent = {
316
424
  } | {
317
425
  type: "tool_executing";
318
426
  name: string;
427
+ call_id?: string;
319
428
  } | {
320
429
  type: "tool_completed";
321
430
  name: string;
322
431
  result: string;
432
+ } | {
433
+ type: "tool_progress";
434
+ callId: string;
435
+ tool: string;
436
+ index: number;
437
+ total: number;
438
+ item: {
439
+ title: string;
440
+ url: string;
441
+ snippet?: string;
442
+ };
323
443
  } | {
324
444
  type: "tool_end";
325
445
  callId: string;
@@ -366,12 +486,6 @@ type ChatEvent = {
366
486
  agentName: string;
367
487
  displayName: string;
368
488
  toolCallId: string;
369
- } | {
370
- type: "sources";
371
- sources: Array<{
372
- title: string;
373
- url: string;
374
- }>;
375
489
  } | {
376
490
  type: "capsule_output";
377
491
  toolName: string;
@@ -415,27 +529,10 @@ type ChatEvent = {
415
529
  maxAttempts: number;
416
530
  delaySeconds: number;
417
531
  } | {
418
- type: "timeline_entry";
419
- id: string;
420
- status: "started" | "completed";
421
- kind?: string;
422
- agent_name?: string;
423
- tool_name?: string;
424
- display_name?: string;
425
- tool_category?: string;
426
- viewer?: string;
427
- call_id?: string;
428
- detail?: string;
429
- started_at?: number;
430
- duration_ms?: number;
431
- output_summary?: string;
432
- sources?: Array<{
433
- title: string;
434
- url: string;
435
- snippet?: string;
436
- }>;
437
- parent_id?: string;
438
- structured_output?: Record<string, unknown>;
532
+ type: "context_update";
533
+ context: Record<string, unknown>;
534
+ phase?: string;
535
+ updatedAt?: number;
439
536
  } | {
440
537
  type: "editor_content_start";
441
538
  callId: string;
@@ -449,6 +546,23 @@ type ChatEvent = {
449
546
  } | {
450
547
  type: "editor_content_end";
451
548
  callId: string;
549
+ } | {
550
+ type: "desktop_stream";
551
+ url: string;
552
+ authKey: string;
553
+ sandboxId: string;
554
+ } | {
555
+ type: "attachment_staged";
556
+ files: {
557
+ name: string;
558
+ path: string;
559
+ mediaType: string;
560
+ sizeBytes: number;
561
+ }[];
562
+ } | {
563
+ type: "workspace_ready";
564
+ conversationId: string;
565
+ sandboxId: string;
452
566
  } | {
453
567
  type: "model_info";
454
568
  name: string;
@@ -591,7 +705,7 @@ interface ConversationEvent {
591
705
  event: string;
592
706
  data: Record<string, unknown>;
593
707
  }
594
- interface SendOptions {
708
+ interface SendOptions$1 {
595
709
  conversationId?: string;
596
710
  enabledClientTools?: string[];
597
711
  uploadIds?: string[];
@@ -618,8 +732,8 @@ declare class AstralformClient {
618
732
  constructor(config: AstralformConfig);
619
733
  private get headers();
620
734
  private request;
621
- private get;
622
- private post;
735
+ get<T>(path: string): Promise<T>;
736
+ post<T>(path: string, body: unknown): Promise<T>;
623
737
  private del;
624
738
  private handleError;
625
739
  getHealth(): Promise<{
@@ -701,7 +815,6 @@ declare class ChatSession {
701
815
  thinkingContent: string;
702
816
  isThinking: boolean;
703
817
  activeSubagents: Map<string, SubagentState>;
704
- sources: Source[];
705
818
  capsuleOutputs: CapsuleOutput[];
706
819
  todos: TodoItem[];
707
820
  activeTools: Map<string, ToolState>;
@@ -711,7 +824,7 @@ declare class ChatSession {
711
824
  on(handler: ChatEventHandler): () => void;
712
825
  private emit;
713
826
  connect(): Promise<void>;
714
- send(content: string, options?: SendOptions): Promise<void>;
827
+ send(content: string, options?: SendOptions$1): Promise<void>;
715
828
  resendFromCheckpoint(messageId: string, newContent: string, options?: {
716
829
  enableSearch?: boolean;
717
830
  }): Promise<void>;
@@ -720,7 +833,7 @@ declare class ChatSession {
720
833
  /** Last received sequence number for resumable reconnection */
721
834
  private lastSeq;
722
835
  /** Current job ID for cancellation */
723
- private currentJobId;
836
+ currentJobId: string | null;
724
837
  private consumeJobStream;
725
838
  /**
726
839
  * Shared event consumption loop used by both consumeJobStream and reconnectToJob.
@@ -744,6 +857,10 @@ declare class ChatSession {
744
857
  * Does NOT reset BlockBuilder — caller controls reset.
745
858
  */
746
859
  reconnectToJob(jobId: string): Promise<void>;
860
+ /** Detach from the SSE stream without cancelling the job.
861
+ * The backend job keeps running — caller can reconnect later. */
862
+ detach(): void;
863
+ /** Stop the job and disconnect (explicit user action). */
747
864
  disconnect(): void;
748
865
  createNewConversation(): Promise<string>;
749
866
  switchConversation(id: string, jobId?: string): Promise<void>;
@@ -762,7 +879,7 @@ declare class ChatSession {
762
879
  * builder.registerHandlers(standardHandlers);
763
880
  */
764
881
 
765
- declare const standardHandlers: Record<string, EventHandler>;
882
+ declare const standardHandlers: Record<string, EventHandler$1>;
766
883
 
767
884
  declare class AstralformError extends Error {
768
885
  code: string;
@@ -794,4 +911,77 @@ declare function generateId(): string;
794
911
  */
795
912
  declare function streamJobSSE(options: StreamJobSSEOptions): AsyncGenerator<ChatStreamEvent>;
796
913
 
797
- export { type AgentBlock, type AgentEndEvent, type AgentInfo, type AgentStartEvent, AstralformClient, type AstralformConfig, AstralformError, AuthenticationError, type Block, BlockBuilder, type CapsuleOutput, type CapsuleOutputChunkEvent, type CapsuleOutputEvent, type ChatEvent, ChatSession, type ChatStorage, type ChatStreamEvent, type ChatStreamRequest, ConnectionError, type ContentBlockDeltaEvent, type Conversation, type ConversationAsset, type ConversationEvent, type ErrorBlock, type 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, type SourcesEvent, StreamAbortedError, type StreamJobSSEOptions, type SubagentBlock, type SubagentContentDeltaEvent, type SubagentEndEvent, type SubagentStartEvent, type SubagentState, type SubagentToolUseEvent, type TextBlock, type ThinkingBlock, type ThinkingCompleteEvent, type ThinkingDeltaEvent, type TodoItem, type TodoUpdateEvent, type ToolBlock, type ToolCallRequest, type ToolDefinition, type ToolHandler, ToolRegistry, type ToolResult, type ToolResultRequest, type ToolState, type ToolUseEndEvent, type ToolUseStartEvent, type UserBlock, generateId, standardHandlers, streamJobSSE };
914
+ /**
915
+ * StreamManager — high-level conversation lifecycle coordinator.
916
+ *
917
+ * Sits on top of ChatSession and manages the state machine for
918
+ * multi-conversation SSE streaming. Framework-agnostic: emits
919
+ * callbacks instead of writing to any state management library.
920
+ *
921
+ * import { ChatSession, StreamManager } from "@astralform/js";
922
+ * const session = new ChatSession({ ... });
923
+ * const manager = new StreamManager(session);
924
+ * manager.on("blocksChanged", (convId, blocks) => { ... });
925
+ * await manager.send("Hello");
926
+ */
927
+
928
+ type StreamState = "idle" | "streaming" | "restoring" | "detached";
929
+ interface SendOptions {
930
+ enableSearch?: boolean;
931
+ agentName?: string;
932
+ uploadIds?: string[];
933
+ }
934
+ type StreamManagerEvent = {
935
+ type: "stateChange";
936
+ state: StreamState;
937
+ conversationId: string | null;
938
+ } | {
939
+ type: "blocksChanged";
940
+ conversationId: string;
941
+ blocks: Block[];
942
+ } | {
943
+ type: "conversationChanged";
944
+ conversationId: string | null;
945
+ } | {
946
+ type: "backgroundJobsChanged";
947
+ jobs: ReadonlyMap<string, string>;
948
+ } | {
949
+ type: "event";
950
+ conversationId: string | null;
951
+ event: ChatEvent;
952
+ } | {
953
+ type: "versionsReady";
954
+ conversationId: string;
955
+ count: number;
956
+ };
957
+ type EventHandler = (event: StreamManagerEvent) => void;
958
+ declare class StreamManager {
959
+ private session;
960
+ private _state;
961
+ private _activeConversationId;
962
+ private _backgroundJobs;
963
+ private handlers;
964
+ private unsub;
965
+ constructor(session: ChatSession);
966
+ get state(): StreamState;
967
+ get activeConversationId(): string | null;
968
+ get backgroundJobs(): ReadonlyMap<string, string>;
969
+ on(handler: EventHandler): () => void;
970
+ private emit;
971
+ private setState;
972
+ private attach;
973
+ private onSessionEvent;
974
+ send(content: string, options?: SendOptions): Promise<void>;
975
+ regenerate(): Promise<void>;
976
+ switchTo(conversationId: string): Promise<void>;
977
+ createConversation(): Promise<string>;
978
+ deleteConversation(id: string): Promise<void>;
979
+ stop(): void;
980
+ destroy(): void;
981
+ private prepareUserBlock;
982
+ private finalizeStream;
983
+ private restore;
984
+ private setActiveConversation;
985
+ }
986
+
987
+ export { type AgentBlock, type AgentEndEvent, type AgentInfo, type AgentStartEvent, type AssetBlock, AstralformClient, type AstralformConfig, AstralformError, type AttachmentBlock, type AttachmentStagedEvent, 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 DesktopStreamBlock, type DesktopStreamEvent, 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, type WorkspaceReadyEvent, generateId, standardHandlers, streamJobSSE };