@astralform/js 0.1.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.
@@ -0,0 +1,526 @@
1
+ interface AstralformConfig {
2
+ apiKey: string;
3
+ baseURL?: string;
4
+ userId: string;
5
+ fetch?: typeof globalThis.fetch;
6
+ }
7
+ interface MessageStartEvent {
8
+ type: "message_start";
9
+ message_id: string;
10
+ conversation_id: string;
11
+ model_display_name?: string;
12
+ agent_name?: string;
13
+ agent_display_name?: string;
14
+ }
15
+ interface ContentBlockDeltaEvent {
16
+ type: "content_block_delta";
17
+ index: number;
18
+ delta: {
19
+ type: "text_delta";
20
+ text: string;
21
+ };
22
+ }
23
+ interface ToolUseStartEvent {
24
+ type: "tool_use_start";
25
+ index: number;
26
+ call_id: string;
27
+ tool: string;
28
+ display_name?: string;
29
+ description?: string;
30
+ arguments: Record<string, unknown>;
31
+ is_client_tool: boolean;
32
+ }
33
+ interface ToolUseEndEvent {
34
+ type: "tool_use_end";
35
+ call_id: string;
36
+ tool: string;
37
+ }
38
+ interface AgentStartEvent {
39
+ type: "agent_start";
40
+ agent_name: string;
41
+ agent_display_name?: string;
42
+ avatar_url?: string;
43
+ }
44
+ interface AgentEndEvent {
45
+ type: "agent_end";
46
+ agent_name: string;
47
+ }
48
+ interface SubagentStartEvent {
49
+ type: "subagent_start";
50
+ agent_name: string;
51
+ display_name: string;
52
+ tool_call_id: string;
53
+ avatar_url?: string;
54
+ description?: string;
55
+ }
56
+ interface SubagentContentDeltaEvent {
57
+ type: "subagent_content_delta";
58
+ agent_name: string;
59
+ tool_call_id: string;
60
+ delta: {
61
+ type: "text_delta";
62
+ text: string;
63
+ };
64
+ }
65
+ interface SubagentUpdateEvent {
66
+ type: "subagent_update";
67
+ agent_name: string;
68
+ display_name: string;
69
+ tool_call_id: string;
70
+ }
71
+ interface SubagentEndEvent {
72
+ type: "subagent_end";
73
+ agent_name: string;
74
+ display_name: string;
75
+ tool_call_id: string;
76
+ }
77
+ interface ThinkingDeltaEvent {
78
+ type: "thinking_delta";
79
+ delta: {
80
+ type: "thinking";
81
+ text: string;
82
+ };
83
+ }
84
+ interface ThinkingCompleteEvent {
85
+ type: "thinking_complete";
86
+ }
87
+ interface SourcesEvent {
88
+ type: "sources";
89
+ sources: Array<{
90
+ title: string;
91
+ url: string;
92
+ }>;
93
+ }
94
+ interface CapsuleOutputEvent {
95
+ type: "capsule_output";
96
+ tool_name: string;
97
+ agent_name: string;
98
+ command?: string;
99
+ output: string;
100
+ duration_ms?: number;
101
+ }
102
+ interface TodoUpdateEvent {
103
+ type: "todo_update";
104
+ todos: TodoItem[];
105
+ }
106
+ interface MessageStopEvent {
107
+ type: "message_stop";
108
+ stop_reason: "end_turn" | "tool_use";
109
+ title?: string;
110
+ }
111
+ interface SSEErrorEvent {
112
+ type: "error";
113
+ code: string;
114
+ message: string;
115
+ }
116
+ interface SubagentToolUseEvent {
117
+ type: "subagent_tool_use";
118
+ agent_name: string;
119
+ tool: string;
120
+ tool_call_id: string;
121
+ result?: string;
122
+ }
123
+ interface AssetCreatedEvent {
124
+ type: "asset_created";
125
+ asset_id: string;
126
+ name: string;
127
+ url: string;
128
+ media_type: string;
129
+ size_bytes: number;
130
+ }
131
+ interface RetryEvent {
132
+ type: "retry";
133
+ attempt: number;
134
+ max_attempts: number;
135
+ delay_seconds: number;
136
+ }
137
+ type SSEEvent = MessageStartEvent | ContentBlockDeltaEvent | ToolUseStartEvent | ToolUseEndEvent | AgentStartEvent | AgentEndEvent | SubagentStartEvent | SubagentContentDeltaEvent | SubagentUpdateEvent | SubagentEndEvent | SubagentToolUseEvent | ThinkingDeltaEvent | ThinkingCompleteEvent | SourcesEvent | CapsuleOutputEvent | TodoUpdateEvent | MessageStopEvent | AssetCreatedEvent | RetryEvent | SSEErrorEvent;
138
+ type ChatEvent = {
139
+ type: "connected";
140
+ } | {
141
+ type: "chunk";
142
+ text: string;
143
+ } | {
144
+ type: "tool_call";
145
+ request: ToolCallRequest;
146
+ } | {
147
+ type: "tool_executing";
148
+ name: string;
149
+ } | {
150
+ type: "tool_completed";
151
+ name: string;
152
+ result: string;
153
+ } | {
154
+ type: "tool_end";
155
+ callId: string;
156
+ toolName: string;
157
+ } | {
158
+ type: "agent_start";
159
+ agentName: string;
160
+ agentDisplayName?: string;
161
+ avatarUrl?: string;
162
+ } | {
163
+ type: "agent_end";
164
+ agentName: string;
165
+ } | {
166
+ type: "thinking_delta";
167
+ text: string;
168
+ } | {
169
+ type: "thinking_complete";
170
+ } | {
171
+ type: "subagent_start";
172
+ agentName: string;
173
+ displayName: string;
174
+ toolCallId: string;
175
+ avatarUrl?: string;
176
+ description?: string;
177
+ } | {
178
+ type: "subagent_chunk";
179
+ agentName: string;
180
+ toolCallId: string;
181
+ text: string;
182
+ } | {
183
+ type: "subagent_update";
184
+ agentName: string;
185
+ displayName: string;
186
+ toolCallId: string;
187
+ } | {
188
+ type: "subagent_end";
189
+ agentName: string;
190
+ displayName: string;
191
+ toolCallId: string;
192
+ } | {
193
+ type: "sources";
194
+ sources: Array<{
195
+ title: string;
196
+ url: string;
197
+ }>;
198
+ } | {
199
+ type: "capsule_output";
200
+ toolName: string;
201
+ agentName: string;
202
+ command?: string;
203
+ output: string;
204
+ durationMs?: number;
205
+ } | {
206
+ type: "todo_update";
207
+ todos: TodoItem[];
208
+ } | {
209
+ type: "complete";
210
+ content: string;
211
+ conversationId: string;
212
+ messageId: string;
213
+ title?: string;
214
+ } | {
215
+ type: "subagent_tool_use";
216
+ agentName: string;
217
+ toolName: string;
218
+ toolCallId: string;
219
+ result?: string;
220
+ } | {
221
+ type: "asset_created";
222
+ assetId: string;
223
+ name: string;
224
+ url: string;
225
+ mediaType: string;
226
+ sizeBytes: number;
227
+ } | {
228
+ type: "retry";
229
+ attempt: number;
230
+ maxAttempts: number;
231
+ delaySeconds: number;
232
+ } | {
233
+ type: "model_info";
234
+ name: string;
235
+ } | {
236
+ type: "error";
237
+ error: Error;
238
+ } | {
239
+ type: "disconnected";
240
+ };
241
+ interface Conversation {
242
+ id: string;
243
+ title: string;
244
+ messageCount: number;
245
+ createdAt: string;
246
+ updatedAt: string;
247
+ }
248
+ interface Message {
249
+ id: string;
250
+ conversationId: string;
251
+ role: "user" | "assistant" | "system";
252
+ content: string;
253
+ parentId?: string;
254
+ status: "sending" | "streaming" | "complete" | "error";
255
+ createdAt: string;
256
+ toolCalls?: ToolCallRequest[];
257
+ }
258
+ interface ProjectStatus {
259
+ isReady: boolean;
260
+ llmConfigured: boolean;
261
+ llmProvider?: string;
262
+ llmModel?: string;
263
+ message: string;
264
+ }
265
+ interface AgentInfo {
266
+ name: string;
267
+ displayName: string;
268
+ description: string;
269
+ isOrchestrator: boolean;
270
+ isEnabled: boolean;
271
+ avatarUrl?: string;
272
+ }
273
+ interface SkillInfo {
274
+ name: string;
275
+ displayName: string;
276
+ description: string;
277
+ isEnabled: boolean;
278
+ }
279
+ interface SubagentState {
280
+ agentName: string;
281
+ displayName: string;
282
+ avatarUrl?: string;
283
+ description?: string;
284
+ content: string;
285
+ isActive: boolean;
286
+ }
287
+ interface ToolState {
288
+ toolName: string;
289
+ displayName?: string;
290
+ description?: string;
291
+ arguments?: Record<string, unknown>;
292
+ callId: string;
293
+ status: "calling" | "executing" | "completed";
294
+ isClientTool: boolean;
295
+ }
296
+ interface CapsuleOutput {
297
+ toolName: string;
298
+ agentName: string;
299
+ command?: string;
300
+ output: string;
301
+ durationMs?: number;
302
+ }
303
+ interface Source {
304
+ title: string;
305
+ url: string;
306
+ }
307
+ interface TodoItem {
308
+ content: string;
309
+ status: "pending" | "in_progress" | "completed";
310
+ id?: string;
311
+ }
312
+ interface JobCreateResponse {
313
+ job_id: string;
314
+ conversation_id: string;
315
+ message_id: string;
316
+ status: string;
317
+ }
318
+ interface ChatStreamRequest {
319
+ message?: string;
320
+ conversation_id?: string;
321
+ mcp_manifest?: ToolDefinition[];
322
+ enabled_mcp?: string[];
323
+ continue_from_message?: string;
324
+ resend_from?: string;
325
+ upload_ids?: string[];
326
+ agent_name?: string;
327
+ }
328
+ interface ToolResultRequest {
329
+ conversation_id: string;
330
+ message_id: string;
331
+ tool_results: ToolResult[];
332
+ }
333
+ interface ToolResult {
334
+ call_id: string;
335
+ tool_name: string;
336
+ result: string;
337
+ is_error: boolean;
338
+ }
339
+ interface ToolDefinition {
340
+ name: string;
341
+ description: string;
342
+ parameters: Record<string, unknown>;
343
+ }
344
+ interface ToolCallRequest {
345
+ callId: string;
346
+ toolName: string;
347
+ displayName?: string;
348
+ description?: string;
349
+ arguments: Record<string, unknown>;
350
+ isClientTool: boolean;
351
+ }
352
+ interface StreamJobSSEOptions {
353
+ url: string;
354
+ headers: Record<string, string>;
355
+ signal?: AbortSignal;
356
+ fetchFn: typeof globalThis.fetch;
357
+ }
358
+ interface ChatStreamEvent {
359
+ event: string;
360
+ data: string;
361
+ }
362
+ interface SendOptions {
363
+ conversationId?: string;
364
+ enabledClientTools?: string[];
365
+ uploadIds?: string[];
366
+ agentName?: string;
367
+ }
368
+ interface ConversationAsset {
369
+ id: string;
370
+ kind: "upload" | "output";
371
+ originalName: string;
372
+ mediaType: string;
373
+ sizeBytes: number;
374
+ workspacePath?: string;
375
+ sourceMessageId?: string;
376
+ agentName?: string;
377
+ createdAt: string;
378
+ }
379
+
380
+ declare class AstralformClient {
381
+ private readonly apiKey;
382
+ private readonly baseURL;
383
+ private readonly userId;
384
+ private readonly fetchFn;
385
+ constructor(config: AstralformConfig);
386
+ private get headers();
387
+ private request;
388
+ private get;
389
+ private post;
390
+ private del;
391
+ private handleError;
392
+ getHealth(): Promise<{
393
+ status: string;
394
+ version: string;
395
+ ollama_connected: boolean;
396
+ }>;
397
+ getProjectStatus(): Promise<ProjectStatus>;
398
+ getConversations(limit?: number, offset?: number): Promise<Conversation[]>;
399
+ getMessages(conversationId: string): Promise<Message[]>;
400
+ deleteConversation(id: string): Promise<void>;
401
+ getAgents(): Promise<AgentInfo[]>;
402
+ getSkills(): Promise<SkillInfo[]>;
403
+ submitToolResult(request: ToolResultRequest): Promise<void>;
404
+ private mapAsset;
405
+ uploadFile(conversationId: string, file: Blob, filename?: string): Promise<ConversationAsset>;
406
+ listUploads(conversationId: string): Promise<ConversationAsset[]>;
407
+ listOutputs(conversationId: string): Promise<ConversationAsset[]>;
408
+ createJob(request: ChatStreamRequest): Promise<JobCreateResponse>;
409
+ streamJobEvents(jobId: string, afterSeq?: number, signal?: AbortSignal): AsyncGenerator<ChatStreamEvent>;
410
+ cancelJob(jobId: string): Promise<void>;
411
+ }
412
+
413
+ interface ChatStorage {
414
+ fetchConversations(): Promise<Conversation[]>;
415
+ fetchConversation(id: string): Promise<Conversation | null>;
416
+ createConversation(id: string, title: string): Promise<Conversation>;
417
+ updateConversationTitle(id: string, title: string): Promise<void>;
418
+ deleteConversation(id: string): Promise<void>;
419
+ fetchMessages(conversationId: string): Promise<Message[]>;
420
+ addMessage(message: Message, conversationId: string): Promise<void>;
421
+ updateMessageStatus(id: string, status: Message["status"]): Promise<void>;
422
+ deleteMessage(id: string): Promise<void>;
423
+ }
424
+ declare class InMemoryStorage implements ChatStorage {
425
+ private conversations;
426
+ private messages;
427
+ fetchConversations(): Promise<Conversation[]>;
428
+ fetchConversation(id: string): Promise<Conversation | null>;
429
+ createConversation(id: string, title: string): Promise<Conversation>;
430
+ updateConversationTitle(id: string, title: string): Promise<void>;
431
+ deleteConversation(id: string): Promise<void>;
432
+ fetchMessages(conversationId: string): Promise<Message[]>;
433
+ addMessage(message: Message, conversationId: string): Promise<void>;
434
+ updateMessageStatus(id: string, status: Message["status"]): Promise<void>;
435
+ deleteMessage(id: string): Promise<void>;
436
+ }
437
+
438
+ type ToolHandler = (args: Record<string, unknown>) => Promise<string>;
439
+ declare class ToolRegistry {
440
+ private tools;
441
+ registerTool(name: string, description: string, inputSchema: Record<string, unknown>, handler: ToolHandler): void;
442
+ unregisterTool(name: string): boolean;
443
+ hasTool(name: string): boolean;
444
+ executeTool(request: ToolCallRequest): Promise<ToolResult>;
445
+ getManifest(): ToolDefinition[];
446
+ getToolNames(): string[];
447
+ clear(): void;
448
+ }
449
+
450
+ type ChatEventHandler = (event: ChatEvent) => void;
451
+ declare class ChatSession {
452
+ readonly client: AstralformClient;
453
+ readonly toolRegistry: ToolRegistry;
454
+ readonly storage: ChatStorage;
455
+ conversationId: string | null;
456
+ conversations: Conversation[];
457
+ messages: Message[];
458
+ streamingContent: string;
459
+ isStreaming: boolean;
460
+ executingTool: string | null;
461
+ projectStatus: ProjectStatus | null;
462
+ agents: AgentInfo[];
463
+ skills: SkillInfo[];
464
+ enabledClientTools: Set<string>;
465
+ modelDisplayName: string | null;
466
+ thinkingContent: string;
467
+ isThinking: boolean;
468
+ activeSubagents: Map<string, SubagentState>;
469
+ sources: Source[];
470
+ capsuleOutputs: CapsuleOutput[];
471
+ todos: TodoItem[];
472
+ activeTools: Map<string, ToolState>;
473
+ private handlers;
474
+ private abortController;
475
+ constructor(config: AstralformConfig, storage?: ChatStorage);
476
+ on(handler: ChatEventHandler): () => void;
477
+ private emit;
478
+ connect(): Promise<void>;
479
+ send(content: string, options?: SendOptions): Promise<void>;
480
+ resendFromCheckpoint(messageId: string, newContent: string): Promise<void>;
481
+ private processStream;
482
+ /** Last received sequence number for resumable reconnection */
483
+ private lastSeq;
484
+ /** Current job ID for cancellation */
485
+ private currentJobId;
486
+ private consumeJobStream;
487
+ private executeClientTools;
488
+ private completeStream;
489
+ disconnect(): void;
490
+ createNewConversation(): Promise<string>;
491
+ switchConversation(id: string): Promise<void>;
492
+ deleteConversation(id: string): Promise<void>;
493
+ toggleClientTool(name: string): boolean;
494
+ }
495
+
496
+ declare class AstralformError extends Error {
497
+ code: string;
498
+ constructor(message: string, code: string);
499
+ }
500
+ declare class AuthenticationError extends AstralformError {
501
+ constructor(message?: string);
502
+ }
503
+ declare class RateLimitError extends AstralformError {
504
+ constructor(message?: string);
505
+ }
506
+ declare class LLMNotConfiguredError extends AstralformError {
507
+ constructor(message?: string);
508
+ }
509
+ declare class ServerError extends AstralformError {
510
+ constructor(message?: string);
511
+ }
512
+ declare class ConnectionError extends AstralformError {
513
+ constructor(message?: string);
514
+ }
515
+ declare class StreamAbortedError extends AstralformError {
516
+ constructor(message?: string);
517
+ }
518
+
519
+ declare function generateId(): string;
520
+
521
+ /**
522
+ * GET-based SSE stream for job events.
523
+ */
524
+ declare function streamJobSSE(options: StreamJobSSEOptions): AsyncGenerator<ChatStreamEvent>;
525
+
526
+ export { type AgentEndEvent, type AgentInfo, type AgentStartEvent, AstralformClient, type AstralformConfig, AstralformError, AuthenticationError, type CapsuleOutput, type CapsuleOutputEvent, type ChatEvent, ChatSession, type ChatStorage, type ChatStreamEvent, type ChatStreamRequest, ConnectionError, type ContentBlockDeltaEvent, type Conversation, type ConversationAsset, 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 SubagentContentDeltaEvent, type SubagentEndEvent, type SubagentStartEvent, type SubagentState, type SubagentToolUseEvent, type ThinkingCompleteEvent, type ThinkingDeltaEvent, type TodoItem, type TodoUpdateEvent, type ToolCallRequest, type ToolDefinition, type ToolHandler, ToolRegistry, type ToolResult, type ToolResultRequest, type ToolState, type ToolUseEndEvent, type ToolUseStartEvent, generateId, streamJobSSE };