@astralform/js 0.2.1 → 0.2.2
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.cjs +488 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +192 -71
- package/dist/index.d.ts +192 -71
- package/dist/index.js +486 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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,49 @@ 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
|
+
type Block = UserBlock | TextBlock | ThinkingBlock | AgentBlock | SubagentBlock | ToolBlock | CapsuleBlock | AssetBlock | TodoBlock | EditorBlock | ErrorBlock;
|
|
110
|
+
type EventHandler$1 = (event: ChatEvent, builder: BlockBuilder) => void;
|
|
74
111
|
declare class BlockBuilder {
|
|
75
112
|
private _blocks;
|
|
76
113
|
private _handlers;
|
|
@@ -78,8 +115,10 @@ declare class BlockBuilder {
|
|
|
78
115
|
activeTextId: string | null;
|
|
79
116
|
activeThinkingId: string | null;
|
|
80
117
|
thinkingStartMs: number | null;
|
|
81
|
-
|
|
82
|
-
|
|
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;
|
|
83
122
|
processEvent(event: ChatEvent): void;
|
|
84
123
|
getBlocks(): Block[];
|
|
85
124
|
reset(): void;
|
|
@@ -103,9 +142,43 @@ interface AstralformConfig {
|
|
|
103
142
|
userId: string;
|
|
104
143
|
fetch?: typeof globalThis.fetch;
|
|
105
144
|
}
|
|
145
|
+
declare const ChatEventType: {
|
|
146
|
+
readonly Connected: "connected";
|
|
147
|
+
readonly BlocksChanged: "blocks_changed";
|
|
148
|
+
readonly UserMessage: "user_message";
|
|
149
|
+
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";
|
|
161
|
+
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";
|
|
168
|
+
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";
|
|
177
|
+
};
|
|
106
178
|
interface UserMessageEvent {
|
|
107
179
|
type: "user_message";
|
|
108
180
|
content: string;
|
|
181
|
+
created_at?: number;
|
|
109
182
|
}
|
|
110
183
|
interface TitleGeneratedEvent {
|
|
111
184
|
type: "title_generated";
|
|
@@ -151,6 +224,23 @@ interface ToolUseEndEvent {
|
|
|
151
224
|
}[];
|
|
152
225
|
duration_ms?: number;
|
|
153
226
|
}
|
|
227
|
+
interface ToolExecutingEvent {
|
|
228
|
+
type: "tool_executing";
|
|
229
|
+
call_id: string;
|
|
230
|
+
tool: string;
|
|
231
|
+
}
|
|
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
|
+
};
|
|
243
|
+
}
|
|
154
244
|
interface AgentStartEvent {
|
|
155
245
|
type: "agent_start";
|
|
156
246
|
agent_name: string;
|
|
@@ -200,13 +290,6 @@ interface ThinkingDeltaEvent {
|
|
|
200
290
|
interface ThinkingCompleteEvent {
|
|
201
291
|
type: "thinking_complete";
|
|
202
292
|
}
|
|
203
|
-
interface SourcesEvent {
|
|
204
|
-
type: "sources";
|
|
205
|
-
sources: Array<{
|
|
206
|
-
title: string;
|
|
207
|
-
url: string;
|
|
208
|
-
}>;
|
|
209
|
-
}
|
|
210
293
|
interface CapsuleOutputEvent {
|
|
211
294
|
type: "capsule_output";
|
|
212
295
|
tool_name: string;
|
|
@@ -253,29 +336,6 @@ interface AssetCreatedEvent {
|
|
|
253
336
|
media_type: string;
|
|
254
337
|
size_bytes: number;
|
|
255
338
|
}
|
|
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
339
|
interface EditorContentStartEvent {
|
|
280
340
|
type: "editor_content_start";
|
|
281
341
|
call_id: string;
|
|
@@ -298,12 +358,13 @@ interface RetryEvent {
|
|
|
298
358
|
max_attempts: number;
|
|
299
359
|
delay_seconds: number;
|
|
300
360
|
}
|
|
301
|
-
type SSEEvent = MessageStartEvent | UserMessageEvent | TitleGeneratedEvent | ContentBlockDeltaEvent | ToolUseStartEvent | ToolUseEndEvent | AgentStartEvent | AgentEndEvent | SubagentStartEvent | SubagentContentDeltaEvent | SubagentUpdateEvent | SubagentEndEvent | SubagentToolUseEvent | ThinkingDeltaEvent | ThinkingCompleteEvent |
|
|
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;
|
|
302
362
|
type ChatEvent = {
|
|
303
363
|
type: "connected";
|
|
304
364
|
} | {
|
|
305
365
|
type: "user_message";
|
|
306
366
|
content: string;
|
|
367
|
+
createdAt?: number;
|
|
307
368
|
} | {
|
|
308
369
|
type: "title_generated";
|
|
309
370
|
title: string;
|
|
@@ -316,10 +377,22 @@ type ChatEvent = {
|
|
|
316
377
|
} | {
|
|
317
378
|
type: "tool_executing";
|
|
318
379
|
name: string;
|
|
380
|
+
call_id?: string;
|
|
319
381
|
} | {
|
|
320
382
|
type: "tool_completed";
|
|
321
383
|
name: string;
|
|
322
384
|
result: string;
|
|
385
|
+
} | {
|
|
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
|
+
};
|
|
323
396
|
} | {
|
|
324
397
|
type: "tool_end";
|
|
325
398
|
callId: string;
|
|
@@ -366,12 +439,6 @@ type ChatEvent = {
|
|
|
366
439
|
agentName: string;
|
|
367
440
|
displayName: string;
|
|
368
441
|
toolCallId: string;
|
|
369
|
-
} | {
|
|
370
|
-
type: "sources";
|
|
371
|
-
sources: Array<{
|
|
372
|
-
title: string;
|
|
373
|
-
url: string;
|
|
374
|
-
}>;
|
|
375
442
|
} | {
|
|
376
443
|
type: "capsule_output";
|
|
377
444
|
toolName: string;
|
|
@@ -414,28 +481,6 @@ type ChatEvent = {
|
|
|
414
481
|
attempt: number;
|
|
415
482
|
maxAttempts: number;
|
|
416
483
|
delaySeconds: number;
|
|
417
|
-
} | {
|
|
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>;
|
|
439
484
|
} | {
|
|
440
485
|
type: "editor_content_start";
|
|
441
486
|
callId: string;
|
|
@@ -591,7 +636,7 @@ interface ConversationEvent {
|
|
|
591
636
|
event: string;
|
|
592
637
|
data: Record<string, unknown>;
|
|
593
638
|
}
|
|
594
|
-
interface SendOptions {
|
|
639
|
+
interface SendOptions$1 {
|
|
595
640
|
conversationId?: string;
|
|
596
641
|
enabledClientTools?: string[];
|
|
597
642
|
uploadIds?: string[];
|
|
@@ -618,8 +663,8 @@ declare class AstralformClient {
|
|
|
618
663
|
constructor(config: AstralformConfig);
|
|
619
664
|
private get headers();
|
|
620
665
|
private request;
|
|
621
|
-
|
|
622
|
-
|
|
666
|
+
get<T>(path: string): Promise<T>;
|
|
667
|
+
post<T>(path: string, body: unknown): Promise<T>;
|
|
623
668
|
private del;
|
|
624
669
|
private handleError;
|
|
625
670
|
getHealth(): Promise<{
|
|
@@ -701,7 +746,6 @@ declare class ChatSession {
|
|
|
701
746
|
thinkingContent: string;
|
|
702
747
|
isThinking: boolean;
|
|
703
748
|
activeSubagents: Map<string, SubagentState>;
|
|
704
|
-
sources: Source[];
|
|
705
749
|
capsuleOutputs: CapsuleOutput[];
|
|
706
750
|
todos: TodoItem[];
|
|
707
751
|
activeTools: Map<string, ToolState>;
|
|
@@ -711,7 +755,7 @@ declare class ChatSession {
|
|
|
711
755
|
on(handler: ChatEventHandler): () => void;
|
|
712
756
|
private emit;
|
|
713
757
|
connect(): Promise<void>;
|
|
714
|
-
send(content: string, options?: SendOptions): Promise<void>;
|
|
758
|
+
send(content: string, options?: SendOptions$1): Promise<void>;
|
|
715
759
|
resendFromCheckpoint(messageId: string, newContent: string, options?: {
|
|
716
760
|
enableSearch?: boolean;
|
|
717
761
|
}): Promise<void>;
|
|
@@ -720,7 +764,7 @@ declare class ChatSession {
|
|
|
720
764
|
/** Last received sequence number for resumable reconnection */
|
|
721
765
|
private lastSeq;
|
|
722
766
|
/** Current job ID for cancellation */
|
|
723
|
-
|
|
767
|
+
currentJobId: string | null;
|
|
724
768
|
private consumeJobStream;
|
|
725
769
|
/**
|
|
726
770
|
* Shared event consumption loop used by both consumeJobStream and reconnectToJob.
|
|
@@ -744,6 +788,10 @@ declare class ChatSession {
|
|
|
744
788
|
* Does NOT reset BlockBuilder — caller controls reset.
|
|
745
789
|
*/
|
|
746
790
|
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. */
|
|
793
|
+
detach(): void;
|
|
794
|
+
/** Stop the job and disconnect (explicit user action). */
|
|
747
795
|
disconnect(): void;
|
|
748
796
|
createNewConversation(): Promise<string>;
|
|
749
797
|
switchConversation(id: string, jobId?: string): Promise<void>;
|
|
@@ -762,7 +810,7 @@ declare class ChatSession {
|
|
|
762
810
|
* builder.registerHandlers(standardHandlers);
|
|
763
811
|
*/
|
|
764
812
|
|
|
765
|
-
declare const standardHandlers: Record<string, EventHandler>;
|
|
813
|
+
declare const standardHandlers: Record<string, EventHandler$1>;
|
|
766
814
|
|
|
767
815
|
declare class AstralformError extends Error {
|
|
768
816
|
code: string;
|
|
@@ -794,4 +842,77 @@ declare function generateId(): string;
|
|
|
794
842
|
*/
|
|
795
843
|
declare function streamJobSSE(options: StreamJobSSEOptions): AsyncGenerator<ChatStreamEvent>;
|
|
796
844
|
|
|
797
|
-
|
|
845
|
+
/**
|
|
846
|
+
* StreamManager — high-level conversation lifecycle coordinator.
|
|
847
|
+
*
|
|
848
|
+
* Sits on top of ChatSession and manages the state machine for
|
|
849
|
+
* multi-conversation SSE streaming. Framework-agnostic: emits
|
|
850
|
+
* callbacks instead of writing to any state management library.
|
|
851
|
+
*
|
|
852
|
+
* import { ChatSession, StreamManager } from "@astralform/js";
|
|
853
|
+
* const session = new ChatSession({ ... });
|
|
854
|
+
* const manager = new StreamManager(session);
|
|
855
|
+
* manager.on("blocksChanged", (convId, blocks) => { ... });
|
|
856
|
+
* await manager.send("Hello");
|
|
857
|
+
*/
|
|
858
|
+
|
|
859
|
+
type StreamState = "idle" | "streaming" | "restoring" | "detached";
|
|
860
|
+
interface SendOptions {
|
|
861
|
+
enableSearch?: boolean;
|
|
862
|
+
agentName?: string;
|
|
863
|
+
uploadIds?: string[];
|
|
864
|
+
}
|
|
865
|
+
type StreamManagerEvent = {
|
|
866
|
+
type: "stateChange";
|
|
867
|
+
state: StreamState;
|
|
868
|
+
conversationId: string | null;
|
|
869
|
+
} | {
|
|
870
|
+
type: "blocksChanged";
|
|
871
|
+
conversationId: string;
|
|
872
|
+
blocks: Block[];
|
|
873
|
+
} | {
|
|
874
|
+
type: "conversationChanged";
|
|
875
|
+
conversationId: string | null;
|
|
876
|
+
} | {
|
|
877
|
+
type: "backgroundJobsChanged";
|
|
878
|
+
jobs: ReadonlyMap<string, string>;
|
|
879
|
+
} | {
|
|
880
|
+
type: "event";
|
|
881
|
+
conversationId: string | null;
|
|
882
|
+
event: ChatEvent;
|
|
883
|
+
} | {
|
|
884
|
+
type: "versionsReady";
|
|
885
|
+
conversationId: string;
|
|
886
|
+
count: number;
|
|
887
|
+
};
|
|
888
|
+
type EventHandler = (event: StreamManagerEvent) => void;
|
|
889
|
+
declare class StreamManager {
|
|
890
|
+
private session;
|
|
891
|
+
private _state;
|
|
892
|
+
private _activeConversationId;
|
|
893
|
+
private _backgroundJobs;
|
|
894
|
+
private handlers;
|
|
895
|
+
private unsub;
|
|
896
|
+
constructor(session: ChatSession);
|
|
897
|
+
get state(): StreamState;
|
|
898
|
+
get activeConversationId(): string | null;
|
|
899
|
+
get backgroundJobs(): ReadonlyMap<string, string>;
|
|
900
|
+
on(handler: EventHandler): () => void;
|
|
901
|
+
private emit;
|
|
902
|
+
private setState;
|
|
903
|
+
private attach;
|
|
904
|
+
private onSessionEvent;
|
|
905
|
+
send(content: string, options?: SendOptions): Promise<void>;
|
|
906
|
+
regenerate(): Promise<void>;
|
|
907
|
+
switchTo(conversationId: string): Promise<void>;
|
|
908
|
+
createConversation(): Promise<string>;
|
|
909
|
+
deleteConversation(id: string): Promise<void>;
|
|
910
|
+
stop(): void;
|
|
911
|
+
destroy(): void;
|
|
912
|
+
private prepareUserBlock;
|
|
913
|
+
private finalizeStream;
|
|
914
|
+
private restore;
|
|
915
|
+
private setActiveConversation;
|
|
916
|
+
}
|
|
917
|
+
|
|
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 };
|