agi 0.2.2 → 0.3.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,824 @@
1
+ /**
2
+ * Result types for task execution
3
+ */
4
+ /**
5
+ * Task execution metadata and performance metrics
6
+ */
7
+ interface TaskMetadata {
8
+ /** Unique task identifier */
9
+ taskId: string | number;
10
+ /** Session ID */
11
+ sessionId: string;
12
+ /** Execution time in seconds */
13
+ duration: number;
14
+ /** Task cost in USD (not yet provided by API) */
15
+ cost: number;
16
+ /** Task completion timestamp */
17
+ timestamp: Date;
18
+ /** Number of steps executed */
19
+ steps: number;
20
+ /** Whether task succeeded */
21
+ success: boolean;
22
+ }
23
+ /**
24
+ * Result of task execution
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const result = await session.runTask("Find flights...");
29
+ * console.log(result.data);
30
+ * console.log(`Duration: ${result.metadata.duration}s`);
31
+ * console.log(`Steps: ${result.metadata.steps}`);
32
+ * ```
33
+ */
34
+ interface TaskResult<T = unknown> {
35
+ /** Task output data */
36
+ data: T;
37
+ /** Execution metadata */
38
+ metadata: TaskMetadata;
39
+ }
40
+
41
+ /**
42
+ * Screenshot handling with image data and metadata
43
+ */
44
+ /**
45
+ * Browser screenshot with decoded image data and metadata
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const screenshot = await session.screenshot();
50
+ * await screenshot.save("page.png");
51
+ * console.log(`Size: ${screenshot.width}x${screenshot.height}`);
52
+ * console.log(`URL: ${screenshot.url}`);
53
+ * ```
54
+ */
55
+ declare class Screenshot {
56
+ readonly data: Buffer;
57
+ readonly format: 'png' | 'jpg';
58
+ readonly timestamp: Date;
59
+ readonly width: number;
60
+ readonly height: number;
61
+ readonly url: string;
62
+ readonly title: string;
63
+ constructor(data: Buffer, format: 'png' | 'jpg', timestamp: Date, width: number, height: number, url: string, title: string);
64
+ /**
65
+ * Save screenshot to file
66
+ *
67
+ * @param path - File path to save to (e.g., "screenshot.png")
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const screenshot = await session.screenshot();
72
+ * await screenshot.save("amazon.png");
73
+ * ```
74
+ */
75
+ save(path: string): Promise<void>;
76
+ /**
77
+ * Create Screenshot from base64 data URL
78
+ *
79
+ * @param base64Data - Base64-encoded data URL (e.g., "data:image/jpeg;base64,...")
80
+ * @param url - Current page URL
81
+ * @param title - Current page title
82
+ * @param timestamp - Screenshot timestamp (defaults to now)
83
+ * @returns Screenshot instance with decoded image data
84
+ */
85
+ static fromBase64(base64Data: string, url: string, title: string, timestamp?: Date): Screenshot;
86
+ /**
87
+ * Extract width and height from image data
88
+ *
89
+ * @param data - Raw image bytes
90
+ * @param format - Image format (png, jpg)
91
+ * @returns Tuple of (width, height)
92
+ */
93
+ private static getImageDimensions;
94
+ }
95
+
96
+ /**
97
+ * Type definitions for AGI SDK
98
+ */
99
+
100
+ type SnapshotMode = 'none' | 'memory' | 'filesystem';
101
+ type SessionStatus = 'ready' | 'running' | 'waiting_for_input' | 'paused' | 'finished' | 'error';
102
+ type EventType = 'step' | 'thought' | 'question' | 'done' | 'error' | 'log' | 'paused' | 'resumed' | 'heartbeat' | 'user';
103
+ type MessageType = 'THOUGHT' | 'QUESTION' | 'USER' | 'DONE' | 'ERROR' | 'LOG';
104
+ interface AGIClientOptions {
105
+ /** API key for authentication */
106
+ apiKey: string;
107
+ /** Base URL for API (default: https://api.agi.tech) */
108
+ baseUrl?: string;
109
+ /** Request timeout in milliseconds (default: 60000) */
110
+ timeout?: number;
111
+ /** Maximum number of retries (default: 3) */
112
+ maxRetries?: number;
113
+ }
114
+ interface CreateSessionOptions {
115
+ /** Webhook URL for session event notifications */
116
+ webhookUrl?: string;
117
+ /** Task goal (optional, can be set later via sendMessage) */
118
+ goal?: string;
119
+ /** Maximum number of agent steps (default: 100) */
120
+ maxSteps?: number;
121
+ /** Environment UUID to restore from */
122
+ restoreFromEnvironmentId?: string;
123
+ }
124
+ interface SessionResponse {
125
+ /** Session UUID */
126
+ sessionId: string;
127
+ /** VNC URL for browser access */
128
+ vncUrl?: string;
129
+ /** Agent service URL (desktop mode) */
130
+ agentUrl?: string;
131
+ /** Agent name */
132
+ agentName: string;
133
+ /** Session status */
134
+ status: SessionStatus;
135
+ /** Session creation timestamp */
136
+ createdAt: string;
137
+ /** Environment UUID for restore */
138
+ environmentId?: string;
139
+ /** Task goal */
140
+ goal?: string;
141
+ }
142
+ interface ExecuteStatusResponse {
143
+ /** Current execution status */
144
+ status: SessionStatus;
145
+ }
146
+ interface MessageResponse {
147
+ /** Message ID */
148
+ id: number;
149
+ /** Message type */
150
+ type: MessageType;
151
+ /** Message content */
152
+ content: string | Record<string, unknown> | Array<Record<string, unknown>>;
153
+ /** ISO timestamp */
154
+ timestamp: string;
155
+ /** Additional metadata */
156
+ metadata?: Record<string, unknown>;
157
+ }
158
+ interface MessagesResponse {
159
+ /** List of messages */
160
+ messages: MessageResponse[];
161
+ /** Current execution status */
162
+ status: string;
163
+ /** Whether agent is connected */
164
+ hasAgent: boolean;
165
+ }
166
+ interface SSEEvent {
167
+ /** Event ID */
168
+ id?: string;
169
+ /** Event type */
170
+ event: EventType;
171
+ /** Event data */
172
+ data: Record<string, unknown>;
173
+ }
174
+ interface NavigateResponse {
175
+ /** Current URL after navigation */
176
+ currentUrl: string;
177
+ }
178
+ interface ScreenshotResponse {
179
+ /** Base64-encoded JPEG data URL */
180
+ screenshot: string;
181
+ /** Current page URL */
182
+ url: string;
183
+ /** Current page title */
184
+ title: string;
185
+ }
186
+ interface SuccessResponse {
187
+ /** Operation success */
188
+ success: boolean;
189
+ /** Success message */
190
+ message: string;
191
+ }
192
+ interface DeleteResponse {
193
+ /** Operation success */
194
+ success: boolean;
195
+ /** Whether resource was deleted */
196
+ deleted: boolean;
197
+ /** Response message */
198
+ message: string;
199
+ }
200
+ interface MessageOptions {
201
+ /** Optional starting URL */
202
+ startUrl?: string;
203
+ /** Optional configuration updates */
204
+ configUpdates?: Record<string, unknown>;
205
+ }
206
+ interface RunTaskOptions {
207
+ /** Optional starting URL */
208
+ startUrl?: string;
209
+ /** Optional configuration updates */
210
+ configUpdates?: Record<string, unknown>;
211
+ /** Maximum time to wait for task completion in milliseconds (default: 600000 = 10 min) */
212
+ timeout?: number;
213
+ /** Polling interval in milliseconds (default: 3000 = 3s) */
214
+ pollInterval?: number;
215
+ }
216
+ interface StreamOptions {
217
+ /** Event types to filter */
218
+ eventTypes?: EventType[];
219
+ /** Sanitize event data */
220
+ sanitize?: boolean;
221
+ /** Include historical events */
222
+ includeHistory?: boolean;
223
+ }
224
+
225
+ /**
226
+ * Session context manager for high-level API
227
+ */
228
+
229
+ /**
230
+ * High-level session context manager with automatic cleanup
231
+ *
232
+ * Use with `await using` for automatic session deletion:
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * await using session = client.session('agi-0');
237
+ * const result = await session.runTask('Find flights...');
238
+ * // Session automatically deleted
239
+ * ```
240
+ */
241
+ declare class SessionContext {
242
+ private readonly client;
243
+ private readonly agentName;
244
+ private readonly createOptions?;
245
+ sessionId?: string;
246
+ vncUrl?: string;
247
+ agentUrl?: string;
248
+ constructor(client: AGIClient, agentName?: string, createOptions?: {
249
+ webhookUrl?: string;
250
+ goal?: string;
251
+ maxSteps?: number;
252
+ restoreFromEnvironmentId?: string;
253
+ } | undefined);
254
+ /**
255
+ * Automatic cleanup via explicit resource management
256
+ */
257
+ [Symbol.asyncDispose](): Promise<void>;
258
+ /**
259
+ * Ensure session is created
260
+ */
261
+ private ensureSession;
262
+ /**
263
+ * Run a task and wait for completion using HTTP polling
264
+ *
265
+ * This method uses HTTP polling instead of SSE streaming for better reliability
266
+ * with long-running tasks and network instability.
267
+ *
268
+ * @param task - Natural language task description
269
+ * @param options - Task execution options
270
+ * @returns TaskResult with data and execution metadata
271
+ *
272
+ * @example
273
+ * ```typescript
274
+ * const result = await session.runTask(
275
+ * 'Find cheapest iPhone 15 Pro',
276
+ * { timeout: 300000, pollInterval: 2000 } // 5 min timeout, 2s polling
277
+ * );
278
+ * console.log(result.data);
279
+ * console.log(`Took ${result.metadata.duration}s, ${result.metadata.steps} steps`);
280
+ * ```
281
+ */
282
+ runTask(task: string, options?: {
283
+ startUrl?: string;
284
+ timeout?: number;
285
+ pollInterval?: number;
286
+ }): Promise<TaskResult>;
287
+ /**
288
+ * Send a message to the agent
289
+ *
290
+ * @param message - Message content
291
+ * @param options - Message options
292
+ * @returns SuccessResponse confirming message was sent
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * await session.sendMessage('Find flights from SFO to JFK under $450');
297
+ * ```
298
+ */
299
+ sendMessage(message: string, options?: {
300
+ startUrl?: string;
301
+ configUpdates?: Record<string, unknown>;
302
+ }): Promise<SuccessResponse>;
303
+ /**
304
+ * Get current execution status
305
+ *
306
+ * @returns ExecuteStatusResponse with status
307
+ *
308
+ * @example
309
+ * ```typescript
310
+ * const status = await session.getStatus();
311
+ * console.log(status.status);
312
+ * ```
313
+ */
314
+ getStatus(): Promise<ExecuteStatusResponse>;
315
+ /**
316
+ * Get messages from the session
317
+ *
318
+ * @param afterId - Return messages with ID > afterId (for polling)
319
+ * @param sanitize - Filter out system messages, prompts, and images
320
+ * @returns MessagesResponse with messages list and status
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * const messages = await session.getMessages(0);
325
+ * for (const msg of messages.messages) {
326
+ * console.log(`[${msg.type}] ${msg.content}`);
327
+ * }
328
+ * ```
329
+ */
330
+ getMessages(afterId?: number, sanitize?: boolean): Promise<MessagesResponse>;
331
+ /**
332
+ * Stream real-time events from the session via Server-Sent Events
333
+ *
334
+ * @param options - Stream options
335
+ * @yields SSEEvent objects
336
+ *
337
+ * @example
338
+ * ```typescript
339
+ * for await (const event of session.streamEvents()) {
340
+ * if (event.event === 'thought') {
341
+ * console.log('Agent:', event.data);
342
+ * }
343
+ * if (event.event === 'done') {
344
+ * console.log('Result:', event.data);
345
+ * break;
346
+ * }
347
+ * }
348
+ * ```
349
+ */
350
+ streamEvents(options?: {
351
+ eventTypes?: string[];
352
+ sanitize?: boolean;
353
+ includeHistory?: boolean;
354
+ }): AsyncGenerator<SSEEvent>;
355
+ /**
356
+ * Pause task execution
357
+ *
358
+ * @returns SuccessResponse confirming pause
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * await session.pause();
363
+ * ```
364
+ */
365
+ pause(): Promise<SuccessResponse>;
366
+ /**
367
+ * Resume paused task
368
+ *
369
+ * @returns SuccessResponse confirming resume
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * await session.resume();
374
+ * ```
375
+ */
376
+ resume(): Promise<SuccessResponse>;
377
+ /**
378
+ * Cancel task execution
379
+ *
380
+ * @returns SuccessResponse confirming cancellation
381
+ *
382
+ * @example
383
+ * ```typescript
384
+ * await session.cancel();
385
+ * ```
386
+ */
387
+ cancel(): Promise<SuccessResponse>;
388
+ /**
389
+ * Navigate browser to URL
390
+ *
391
+ * @param url - URL to navigate to
392
+ * @returns NavigateResponse with current URL
393
+ *
394
+ * @example
395
+ * ```typescript
396
+ * await session.navigate('https://amazon.com');
397
+ * ```
398
+ */
399
+ navigate(url: string): Promise<NavigateResponse>;
400
+ /**
401
+ * Get browser screenshot
402
+ *
403
+ * @returns Screenshot with decoded image data and save() method
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * const screenshot = await session.screenshot();
408
+ * await screenshot.save('page.png');
409
+ * console.log(`Size: ${screenshot.width}x${screenshot.height}`);
410
+ * ```
411
+ */
412
+ screenshot(): Promise<Screenshot>;
413
+ }
414
+
415
+ /**
416
+ * HTTP client for AGI API with fetch and SSE support
417
+ */
418
+
419
+ interface RequestOptions {
420
+ json?: unknown;
421
+ query?: Record<string, string>;
422
+ headers?: Record<string, string>;
423
+ }
424
+ declare class HTTPClient {
425
+ private readonly apiKey;
426
+ private readonly baseUrl;
427
+ private readonly timeout;
428
+ private readonly maxRetries;
429
+ constructor(options: AGIClientOptions);
430
+ /**
431
+ * Make an HTTP request with retries and error handling
432
+ */
433
+ request<T>(method: string, path: string, options?: RequestOptions): Promise<T>;
434
+ /**
435
+ * Stream Server-Sent Events from an endpoint
436
+ */
437
+ streamEvents(path: string, query?: Record<string, string>): AsyncGenerator<SSEEvent>;
438
+ private pendingEvents;
439
+ private buildUrl;
440
+ private buildHeaders;
441
+ private handleErrorResponse;
442
+ private sleep;
443
+ }
444
+
445
+ /**
446
+ * Sessions API resource
447
+ */
448
+
449
+ /**
450
+ * Sessions API resource providing all session-related operations
451
+ */
452
+ declare class SessionsResource {
453
+ private readonly http;
454
+ constructor(http: HTTPClient);
455
+ /**
456
+ * Create a new agent session
457
+ *
458
+ * @param agentName - Agent model to use (e.g., "agi-0", "agi-0-fast", "agi-1")
459
+ * @param options - Session creation options
460
+ * @returns SessionResponse with session_id, vnc_url, status, etc.
461
+ *
462
+ * @example
463
+ * ```typescript
464
+ * const session = await client.sessions.create('agi-0', {
465
+ * webhookUrl: 'https://yourapp.com/webhook',
466
+ * maxSteps: 200
467
+ * });
468
+ * ```
469
+ */
470
+ create(agentName?: string, options?: {
471
+ webhookUrl?: string;
472
+ goal?: string;
473
+ maxSteps?: number;
474
+ restoreFromEnvironmentId?: string;
475
+ }): Promise<SessionResponse>;
476
+ /**
477
+ * List all sessions for the authenticated user
478
+ *
479
+ * @returns Array of SessionResponse objects
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * const sessions = await client.sessions.list();
484
+ * for (const session of sessions) {
485
+ * console.log(`${session.sessionId}: ${session.status}`);
486
+ * }
487
+ * ```
488
+ */
489
+ list(): Promise<SessionResponse[]>;
490
+ /**
491
+ * Get details for a specific session
492
+ *
493
+ * @param sessionId - Session UUID
494
+ * @returns SessionResponse with session details
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * const session = await client.sessions.get('session-uuid');
499
+ * console.log(session.status);
500
+ * ```
501
+ */
502
+ get(sessionId: string): Promise<SessionResponse>;
503
+ /**
504
+ * Delete a session and cleanup its resources
505
+ *
506
+ * @param sessionId - Session UUID
507
+ * @param saveSnapshotMode - Snapshot mode: "none", "memory", or "filesystem"
508
+ * @returns DeleteResponse confirming deletion
509
+ *
510
+ * @example
511
+ * ```typescript
512
+ * await client.sessions.delete('session-uuid', 'filesystem');
513
+ * ```
514
+ */
515
+ delete(sessionId: string, saveSnapshotMode?: SnapshotMode): Promise<DeleteResponse>;
516
+ /**
517
+ * Delete all sessions for the authenticated user
518
+ *
519
+ * @returns DeleteResponse with count of deleted sessions
520
+ *
521
+ * @example
522
+ * ```typescript
523
+ * const result = await client.sessions.deleteAll();
524
+ * console.log(result.message);
525
+ * ```
526
+ */
527
+ deleteAll(): Promise<DeleteResponse>;
528
+ /**
529
+ * Send a message to the agent to start a task or respond to questions
530
+ *
531
+ * @param sessionId - Session UUID
532
+ * @param message - Message content (task instruction or response)
533
+ * @param options - Message options
534
+ * @returns SuccessResponse confirming message was sent
535
+ *
536
+ * @example
537
+ * ```typescript
538
+ * await client.sessions.sendMessage(
539
+ * 'session-uuid',
540
+ * 'Find flights from SFO to JFK under $450'
541
+ * );
542
+ * ```
543
+ */
544
+ sendMessage(sessionId: string, message: string, options?: {
545
+ startUrl?: string;
546
+ configUpdates?: Record<string, unknown>;
547
+ }): Promise<SuccessResponse>;
548
+ /**
549
+ * Get the current execution status of a session
550
+ *
551
+ * @param sessionId - Session UUID
552
+ * @returns ExecuteStatusResponse with status
553
+ *
554
+ * @example
555
+ * ```typescript
556
+ * const status = await client.sessions.getStatus('session-uuid');
557
+ * if (status.status === 'finished') {
558
+ * console.log('Task completed!');
559
+ * }
560
+ * ```
561
+ */
562
+ getStatus(sessionId: string): Promise<ExecuteStatusResponse>;
563
+ /**
564
+ * Poll for messages and updates from the agent
565
+ *
566
+ * @param sessionId - Session UUID
567
+ * @param afterId - Return messages with ID > afterId (for polling)
568
+ * @param sanitize - Filter out system messages, prompts, and images
569
+ * @returns MessagesResponse with messages list and status
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * const messages = await client.sessions.getMessages('session-uuid', 0);
574
+ * for (const msg of messages.messages) {
575
+ * console.log(`[${msg.type}] ${msg.content}`);
576
+ * }
577
+ * ```
578
+ */
579
+ getMessages(sessionId: string, afterId?: number, sanitize?: boolean): Promise<MessagesResponse>;
580
+ /**
581
+ * Stream real-time events from the session via Server-Sent Events
582
+ *
583
+ * @param sessionId - Session UUID
584
+ * @param options - Stream options
585
+ * @yields SSEEvent objects
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * for await (const event of client.sessions.streamEvents('session-uuid')) {
590
+ * if (event.event === 'thought') {
591
+ * console.log('Agent:', event.data);
592
+ * }
593
+ * if (event.event === 'done') {
594
+ * console.log('Result:', event.data);
595
+ * break;
596
+ * }
597
+ * }
598
+ * ```
599
+ */
600
+ streamEvents(sessionId: string, options?: {
601
+ eventTypes?: string[];
602
+ sanitize?: boolean;
603
+ includeHistory?: boolean;
604
+ }): AsyncGenerator<SSEEvent>;
605
+ /**
606
+ * Temporarily pause task execution
607
+ *
608
+ * @param sessionId - Session UUID
609
+ * @returns SuccessResponse confirming pause
610
+ *
611
+ * @example
612
+ * ```typescript
613
+ * await client.sessions.pause('session-uuid');
614
+ * ```
615
+ */
616
+ pause(sessionId: string): Promise<SuccessResponse>;
617
+ /**
618
+ * Resume a paused task
619
+ *
620
+ * @param sessionId - Session UUID
621
+ * @returns SuccessResponse confirming resume
622
+ *
623
+ * @example
624
+ * ```typescript
625
+ * await client.sessions.resume('session-uuid');
626
+ * ```
627
+ */
628
+ resume(sessionId: string): Promise<SuccessResponse>;
629
+ /**
630
+ * Cancel task execution
631
+ *
632
+ * @param sessionId - Session UUID
633
+ * @returns SuccessResponse confirming cancellation
634
+ *
635
+ * @example
636
+ * ```typescript
637
+ * await client.sessions.cancel('session-uuid');
638
+ * ```
639
+ */
640
+ cancel(sessionId: string): Promise<SuccessResponse>;
641
+ /**
642
+ * Navigate the browser to a specific URL
643
+ *
644
+ * @param sessionId - Session UUID
645
+ * @param url - URL to navigate to
646
+ * @returns NavigateResponse with current URL
647
+ *
648
+ * @example
649
+ * ```typescript
650
+ * await client.sessions.navigate('session-uuid', 'https://amazon.com');
651
+ * ```
652
+ */
653
+ navigate(sessionId: string, url: string): Promise<NavigateResponse>;
654
+ /**
655
+ * Get a screenshot of the browser
656
+ *
657
+ * @param sessionId - Session UUID
658
+ * @returns ScreenshotResponse with base64-encoded image, URL, and title
659
+ *
660
+ * @example
661
+ * ```typescript
662
+ * const screenshot = await client.sessions.screenshot('session-uuid');
663
+ * console.log(screenshot.url);
664
+ * ```
665
+ */
666
+ screenshot(sessionId: string): Promise<ScreenshotResponse>;
667
+ }
668
+
669
+ /**
670
+ * Main AGI API client
671
+ */
672
+
673
+ /**
674
+ * Official TypeScript/JavaScript client for the AGI.tech API
675
+ *
676
+ * The AGIClient provides access to the AGI API for creating and managing
677
+ * AI agent sessions that can perform complex web tasks.
678
+ *
679
+ * @example
680
+ * Simple usage with context manager (recommended):
681
+ * ```typescript
682
+ * import { AGIClient } from 'agi-sdk';
683
+ *
684
+ * const client = new AGIClient({ apiKey: 'your_api_key' });
685
+ *
686
+ * await using session = client.session('agi-0');
687
+ * const result = await session.runTask('Find cheapest iPhone 15 on Amazon');
688
+ * console.log(result.data);
689
+ * console.log(`Duration: ${result.metadata.duration}s`);
690
+ * ```
691
+ *
692
+ * @example
693
+ * Advanced usage with low-level API:
694
+ * ```typescript
695
+ * const session = await client.sessions.create('agi-0', {
696
+ * webhookUrl: 'https://yourapp.com/webhook'
697
+ * });
698
+ *
699
+ * await client.sessions.sendMessage(session.sessionId, 'Find flights...');
700
+ *
701
+ * for await (const event of client.sessions.streamEvents(session.sessionId)) {
702
+ * if (event.event === 'thought') {
703
+ * console.log('Agent:', event.data);
704
+ * }
705
+ * if (event.event === 'done') {
706
+ * break;
707
+ * }
708
+ * }
709
+ *
710
+ * await client.sessions.delete(session.sessionId);
711
+ * ```
712
+ */
713
+ declare class AGIClient {
714
+ private readonly http;
715
+ /** Sessions resource for low-level API access */
716
+ readonly sessions: SessionsResource;
717
+ /**
718
+ * Create a new AGI client
719
+ *
720
+ * @param options - Client configuration options
721
+ *
722
+ * @example
723
+ * ```typescript
724
+ * // With explicit API key
725
+ * const client = new AGIClient({ apiKey: 'your_api_key' });
726
+ *
727
+ * // With custom base URL
728
+ * const client = new AGIClient({
729
+ * apiKey: 'your_api_key',
730
+ * baseUrl: 'https://custom-api.example.com',
731
+ * timeout: 120000,
732
+ * });
733
+ * ```
734
+ */
735
+ constructor(options: AGIClientOptions);
736
+ /**
737
+ * Create a session context manager for easy session lifecycle management (recommended)
738
+ *
739
+ * This is the recommended way to use the SDK. The context manager automatically
740
+ * creates and deletes the session using `await using` syntax.
741
+ *
742
+ * @param agentName - Agent model to use (e.g., "agi-0", "agi-0-fast", "agi-1")
743
+ * @param options - Session creation options
744
+ * @returns SessionContext manager
745
+ *
746
+ * @example
747
+ * ```typescript
748
+ * // Simple usage
749
+ * await using session = client.session('agi-0');
750
+ * const result = await session.runTask('Find flights SFO→JFK under $450');
751
+ * console.log(result.data);
752
+ * // Session automatically deleted
753
+ *
754
+ * // With options
755
+ * await using session = client.session('agi-0', {
756
+ * webhookUrl: 'https://yourapp.com/webhook',
757
+ * maxSteps: 200
758
+ * });
759
+ * const result = await session.runTask('Research company XYZ');
760
+ * ```
761
+ */
762
+ session(agentName?: string, options?: {
763
+ webhookUrl?: string;
764
+ goal?: string;
765
+ maxSteps?: number;
766
+ restoreFromEnvironmentId?: string;
767
+ }): SessionContext;
768
+ }
769
+
770
+ /**
771
+ * Error classes for AGI SDK
772
+ */
773
+ /**
774
+ * Base error class for all AGI API errors
775
+ */
776
+ declare class AGIError extends Error {
777
+ readonly statusCode?: number | undefined;
778
+ readonly response?: unknown | undefined;
779
+ constructor(message: string, statusCode?: number | undefined, response?: unknown | undefined);
780
+ }
781
+ /**
782
+ * Authentication error (401)
783
+ */
784
+ declare class AuthenticationError extends AGIError {
785
+ constructor(message: string, response?: unknown);
786
+ }
787
+ /**
788
+ * Not found error (404)
789
+ */
790
+ declare class NotFoundError extends AGIError {
791
+ constructor(message: string, response?: unknown);
792
+ }
793
+ /**
794
+ * Rate limit error (429)
795
+ */
796
+ declare class RateLimitError extends AGIError {
797
+ constructor(message: string, response?: unknown);
798
+ }
799
+ /**
800
+ * Agent execution error (task failed)
801
+ */
802
+ declare class AgentExecutionError extends AGIError {
803
+ constructor(message: string, response?: unknown);
804
+ }
805
+ /**
806
+ * Validation error (422)
807
+ */
808
+ declare class ValidationError extends AGIError {
809
+ constructor(message: string, response?: unknown);
810
+ }
811
+ /**
812
+ * Permission error (403)
813
+ */
814
+ declare class PermissionError extends AGIError {
815
+ constructor(message: string, response?: unknown);
816
+ }
817
+ /**
818
+ * API error (5xx server errors)
819
+ */
820
+ declare class APIError extends AGIError {
821
+ constructor(message: string, statusCode?: number, response?: unknown);
822
+ }
823
+
824
+ export { AGIClient, type AGIClientOptions, AGIError, APIError, AgentExecutionError, AuthenticationError, type CreateSessionOptions, type DeleteResponse, type EventType, type ExecuteStatusResponse, type MessageOptions, type MessageResponse, type MessageType, type MessagesResponse, type NavigateResponse, NotFoundError, PermissionError, RateLimitError, type RunTaskOptions, type SSEEvent, Screenshot, type ScreenshotResponse, SessionContext, type SessionResponse, type SessionStatus, SessionsResource, type SnapshotMode, type StreamOptions, type SuccessResponse, type TaskMetadata, type TaskResult, ValidationError };